This is a reland of e357a4dd4e3b015f8281813f246de793589bd537 Original change's description: > Move stats ID generation from SSRC to local ID > > This generates stats IDs for Track stats (which > represents stats on the attachment of a track to > a PeerConnection) from being SSRC-based to being > based on an ID that is allocated when connecting the > track to the PC. > > This is a prerequisite to generating stats before > the PeerConnection is connected. > > Bug: webrtc:8673 > Change-Id: I82f6e521646b0c92b3af4dffb2cdee75e6dc10d4 > Reviewed-on: https://webrtc-review.googlesource.com/38360 > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org> > Reviewed-by: Henrik Boström <hbos@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#21582} TBR=solenberg@webrtc.org Bug: webrtc:8673 Change-Id: I610302efc5393919569b77e3b59aa3384a9b88a5 Reviewed-on: https://webrtc-review.googlesource.com/38842 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21589}
128 lines
5.7 KiB
C++
128 lines
5.7 KiB
C++
/*
|
|
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#ifndef PC_TRACKMEDIAINFOMAP_H_
|
|
#define PC_TRACKMEDIAINFOMAP_H_
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "api/mediastreaminterface.h"
|
|
#include "api/rtpreceiverinterface.h"
|
|
#include "api/rtpsenderinterface.h"
|
|
#include "media/base/mediachannel.h"
|
|
#include "rtc_base/refcount.h"
|
|
|
|
namespace webrtc {
|
|
|
|
// Audio/video tracks and sender/receiver statistical information are associated
|
|
// with each other based on attachments to RTP senders/receivers. This class
|
|
// maps that relationship, in both directions, so that stats about a track can
|
|
// be retrieved on a per-attachment basis.
|
|
//
|
|
// An RTP sender/receiver sends or receives media for a set of SSRCs. The media
|
|
// comes from an audio/video track that is attached to it.
|
|
// |[Voice/Video][Sender/Receiver]Info| has statistical information for a set of
|
|
// SSRCs. Looking at the RTP senders and receivers uncovers the track <-> info
|
|
// relationships, which this class does.
|
|
class TrackMediaInfoMap {
|
|
public:
|
|
TrackMediaInfoMap(
|
|
std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info,
|
|
std::unique_ptr<cricket::VideoMediaInfo> video_media_info,
|
|
const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders,
|
|
const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>&
|
|
rtp_receivers);
|
|
|
|
const cricket::VoiceMediaInfo* voice_media_info() const {
|
|
return voice_media_info_.get();
|
|
}
|
|
const cricket::VideoMediaInfo* video_media_info() const {
|
|
return video_media_info_.get();
|
|
}
|
|
|
|
const std::vector<cricket::VoiceSenderInfo*>* GetVoiceSenderInfos(
|
|
const AudioTrackInterface& local_audio_track) const;
|
|
const cricket::VoiceReceiverInfo* GetVoiceReceiverInfo(
|
|
const AudioTrackInterface& remote_audio_track) const;
|
|
const std::vector<cricket::VideoSenderInfo*>* GetVideoSenderInfos(
|
|
const VideoTrackInterface& local_video_track) const;
|
|
const cricket::VideoReceiverInfo* GetVideoReceiverInfo(
|
|
const VideoTrackInterface& remote_video_track) const;
|
|
|
|
const cricket::VoiceSenderInfo* GetVoiceSenderInfoBySsrc(uint32_t ssrc) const;
|
|
const cricket::VoiceReceiverInfo* GetVoiceReceiverInfoBySsrc(
|
|
uint32_t ssrc) const;
|
|
const cricket::VideoSenderInfo* GetVideoSenderInfoBySsrc(uint32_t ssrc) const;
|
|
const cricket::VideoReceiverInfo* GetVideoReceiverInfoBySsrc(
|
|
uint32_t ssrc) const;
|
|
|
|
rtc::scoped_refptr<AudioTrackInterface> GetAudioTrack(
|
|
const cricket::VoiceSenderInfo& voice_sender_info) const;
|
|
rtc::scoped_refptr<AudioTrackInterface> GetAudioTrack(
|
|
const cricket::VoiceReceiverInfo& voice_receiver_info) const;
|
|
rtc::scoped_refptr<VideoTrackInterface> GetVideoTrack(
|
|
const cricket::VideoSenderInfo& video_sender_info) const;
|
|
rtc::scoped_refptr<VideoTrackInterface> GetVideoTrack(
|
|
const cricket::VideoReceiverInfo& video_receiver_info) const;
|
|
|
|
// TODO(hta): Remove this function, and redesign the callers not to need it.
|
|
// It is not going to work if a track is attached multiple times, and
|
|
// it is not going to work if a received track is attached as a sending
|
|
// track (loopback).
|
|
rtc::Optional<int> GetAttachmentIdByTrack(
|
|
const MediaStreamTrackInterface* track) const;
|
|
|
|
private:
|
|
std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info_;
|
|
std::unique_ptr<cricket::VideoMediaInfo> video_media_info_;
|
|
// These maps map tracks (identified by a pointer) to their corresponding info
|
|
// object of the correct kind. One track can map to multiple info objects.
|
|
std::map<const AudioTrackInterface*, std::vector<cricket::VoiceSenderInfo*>>
|
|
voice_infos_by_local_track_;
|
|
std::map<const AudioTrackInterface*, cricket::VoiceReceiverInfo*>
|
|
voice_info_by_remote_track_;
|
|
std::map<const VideoTrackInterface*, std::vector<cricket::VideoSenderInfo*>>
|
|
video_infos_by_local_track_;
|
|
std::map<const VideoTrackInterface*, cricket::VideoReceiverInfo*>
|
|
video_info_by_remote_track_;
|
|
// These maps map info objects to their corresponding tracks. They are always
|
|
// the inverse of the maps above. One info object always maps to only one
|
|
// track.
|
|
std::map<const cricket::VoiceSenderInfo*,
|
|
rtc::scoped_refptr<AudioTrackInterface>>
|
|
audio_track_by_sender_info_;
|
|
std::map<const cricket::VoiceReceiverInfo*,
|
|
rtc::scoped_refptr<AudioTrackInterface>>
|
|
audio_track_by_receiver_info_;
|
|
std::map<const cricket::VideoSenderInfo*,
|
|
rtc::scoped_refptr<VideoTrackInterface>>
|
|
video_track_by_sender_info_;
|
|
std::map<const cricket::VideoReceiverInfo*,
|
|
rtc::scoped_refptr<VideoTrackInterface>>
|
|
video_track_by_receiver_info_;
|
|
// Map of tracks to attachment IDs.
|
|
// Necessary because senders and receivers live on the signaling thread,
|
|
// but the attachment IDs are needed while building stats on the networking
|
|
// thread, so we can't look them up in the senders/receivers without
|
|
// thread jumping.
|
|
std::map<const MediaStreamTrackInterface*, int> attachment_id_by_track_;
|
|
// These maps map SSRCs to the corresponding voice or video info objects.
|
|
std::map<uint32_t, cricket::VoiceSenderInfo*> voice_info_by_sender_ssrc_;
|
|
std::map<uint32_t, cricket::VoiceReceiverInfo*> voice_info_by_receiver_ssrc_;
|
|
std::map<uint32_t, cricket::VideoSenderInfo*> video_info_by_sender_ssrc_;
|
|
std::map<uint32_t, cricket::VideoReceiverInfo*> video_info_by_receiver_ssrc_;
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // PC_TRACKMEDIAINFOMAP_H_
|