hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_TRACKMEDIAINFOMAP_H_ |
| 12 | #define PC_TRACKMEDIAINFOMAP_H_ |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/mediastreaminterface.h" |
| 19 | #include "api/rtpreceiverinterface.h" |
| 20 | #include "api/rtpsenderinterface.h" |
| 21 | #include "media/base/mediachannel.h" |
| 22 | #include "rtc_base/refcount.h" |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | // Audio/video tracks and sender/receiver statistical information are associated |
| 27 | // with each other based on attachments to RTP senders/receivers. This class |
| 28 | // maps that relationship, in both directions, so that stats about a track can |
| 29 | // be retrieved on a per-attachment basis. |
| 30 | // |
| 31 | // An RTP sender/receiver sends or receives media for a set of SSRCs. The media |
| 32 | // comes from an audio/video track that is attached to it. |
| 33 | // |[Voice/Video][Sender/Receiver]Info| has statistical information for a set of |
| 34 | // SSRCs. Looking at the RTP senders and receivers uncovers the track <-> info |
| 35 | // relationships, which this class does. |
| 36 | class TrackMediaInfoMap { |
| 37 | public: |
| 38 | TrackMediaInfoMap( |
| 39 | std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info, |
| 40 | std::unique_ptr<cricket::VideoMediaInfo> video_media_info, |
| 41 | const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, |
| 42 | const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& |
| 43 | rtp_receivers); |
| 44 | |
| 45 | const cricket::VoiceMediaInfo* voice_media_info() const { |
| 46 | return voice_media_info_.get(); |
| 47 | } |
| 48 | const cricket::VideoMediaInfo* video_media_info() const { |
| 49 | return video_media_info_.get(); |
| 50 | } |
| 51 | |
| 52 | const std::vector<cricket::VoiceSenderInfo*>* GetVoiceSenderInfos( |
| 53 | const AudioTrackInterface& local_audio_track) const; |
| 54 | const cricket::VoiceReceiverInfo* GetVoiceReceiverInfo( |
| 55 | const AudioTrackInterface& remote_audio_track) const; |
| 56 | const std::vector<cricket::VideoSenderInfo*>* GetVideoSenderInfos( |
| 57 | const VideoTrackInterface& local_video_track) const; |
| 58 | const cricket::VideoReceiverInfo* GetVideoReceiverInfo( |
| 59 | const VideoTrackInterface& remote_video_track) const; |
| 60 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 61 | const cricket::VoiceSenderInfo* GetVoiceSenderInfoBySsrc(uint32_t ssrc) const; |
| 62 | const cricket::VoiceReceiverInfo* GetVoiceReceiverInfoBySsrc( |
| 63 | uint32_t ssrc) const; |
| 64 | const cricket::VideoSenderInfo* GetVideoSenderInfoBySsrc(uint32_t ssrc) const; |
| 65 | const cricket::VideoReceiverInfo* GetVideoReceiverInfoBySsrc( |
| 66 | uint32_t ssrc) const; |
| 67 | |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 68 | rtc::scoped_refptr<AudioTrackInterface> GetAudioTrack( |
| 69 | const cricket::VoiceSenderInfo& voice_sender_info) const; |
| 70 | rtc::scoped_refptr<AudioTrackInterface> GetAudioTrack( |
| 71 | const cricket::VoiceReceiverInfo& voice_receiver_info) const; |
| 72 | rtc::scoped_refptr<VideoTrackInterface> GetVideoTrack( |
| 73 | const cricket::VideoSenderInfo& video_sender_info) const; |
| 74 | rtc::scoped_refptr<VideoTrackInterface> GetVideoTrack( |
| 75 | const cricket::VideoReceiverInfo& video_receiver_info) const; |
| 76 | |
| 77 | private: |
| 78 | std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info_; |
| 79 | std::unique_ptr<cricket::VideoMediaInfo> video_media_info_; |
| 80 | // These maps map tracks (identified by a pointer) to their corresponding info |
| 81 | // object of the correct kind. One track can map to multiple info objects. |
| 82 | std::map<const AudioTrackInterface*, std::vector<cricket::VoiceSenderInfo*>> |
| 83 | voice_infos_by_local_track_; |
| 84 | std::map<const AudioTrackInterface*, cricket::VoiceReceiverInfo*> |
| 85 | voice_info_by_remote_track_; |
| 86 | std::map<const VideoTrackInterface*, std::vector<cricket::VideoSenderInfo*>> |
| 87 | video_infos_by_local_track_; |
| 88 | std::map<const VideoTrackInterface*, cricket::VideoReceiverInfo*> |
| 89 | video_info_by_remote_track_; |
| 90 | // These maps map info objects to their corresponding tracks. They are always |
| 91 | // the inverse of the maps above. One info object always maps to only one |
| 92 | // track. |
| 93 | std::map<const cricket::VoiceSenderInfo*, |
deadbeef | 804c1af | 2017-02-11 19:07:31 -0800 | [diff] [blame] | 94 | rtc::scoped_refptr<AudioTrackInterface>> |
| 95 | audio_track_by_sender_info_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 96 | std::map<const cricket::VoiceReceiverInfo*, |
deadbeef | 804c1af | 2017-02-11 19:07:31 -0800 | [diff] [blame] | 97 | rtc::scoped_refptr<AudioTrackInterface>> |
| 98 | audio_track_by_receiver_info_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 99 | std::map<const cricket::VideoSenderInfo*, |
deadbeef | 804c1af | 2017-02-11 19:07:31 -0800 | [diff] [blame] | 100 | rtc::scoped_refptr<VideoTrackInterface>> |
| 101 | video_track_by_sender_info_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 102 | std::map<const cricket::VideoReceiverInfo*, |
deadbeef | 804c1af | 2017-02-11 19:07:31 -0800 | [diff] [blame] | 103 | rtc::scoped_refptr<VideoTrackInterface>> |
| 104 | video_track_by_receiver_info_; |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 105 | // These maps map SSRCs to the corresponding voice or video info objects. |
| 106 | std::map<uint32_t, cricket::VoiceSenderInfo*> voice_info_by_sender_ssrc_; |
| 107 | std::map<uint32_t, cricket::VoiceReceiverInfo*> voice_info_by_receiver_ssrc_; |
| 108 | std::map<uint32_t, cricket::VideoSenderInfo*> video_info_by_sender_ssrc_; |
| 109 | std::map<uint32_t, cricket::VideoReceiverInfo*> video_info_by_receiver_ssrc_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace webrtc |
| 113 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 114 | #endif // PC_TRACKMEDIAINFOMAP_H_ |