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> |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 16 | #include <string> |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/mediastreaminterface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "media/base/mediachannel.h" |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 21 | #include "pc/rtpreceiver.h" |
| 22 | #include "pc/rtpsender.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "rtc_base/refcount.h" |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
| 27 | // Audio/video tracks and sender/receiver statistical information are associated |
| 28 | // with each other based on attachments to RTP senders/receivers. This class |
| 29 | // maps that relationship, in both directions, so that stats about a track can |
| 30 | // be retrieved on a per-attachment basis. |
| 31 | // |
| 32 | // An RTP sender/receiver sends or receives media for a set of SSRCs. The media |
| 33 | // comes from an audio/video track that is attached to it. |
| 34 | // |[Voice/Video][Sender/Receiver]Info| has statistical information for a set of |
| 35 | // SSRCs. Looking at the RTP senders and receivers uncovers the track <-> info |
| 36 | // relationships, which this class does. |
| 37 | class TrackMediaInfoMap { |
| 38 | public: |
| 39 | TrackMediaInfoMap( |
| 40 | std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info, |
| 41 | std::unique_ptr<cricket::VideoMediaInfo> video_media_info, |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 42 | const std::vector<rtc::scoped_refptr<RtpSenderInternal>>& rtp_senders, |
| 43 | const std::vector<rtc::scoped_refptr<RtpReceiverInternal>>& |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 44 | rtp_receivers); |
| 45 | |
| 46 | const cricket::VoiceMediaInfo* voice_media_info() const { |
| 47 | return voice_media_info_.get(); |
| 48 | } |
| 49 | const cricket::VideoMediaInfo* video_media_info() const { |
| 50 | return video_media_info_.get(); |
| 51 | } |
| 52 | |
| 53 | const std::vector<cricket::VoiceSenderInfo*>* GetVoiceSenderInfos( |
| 54 | const AudioTrackInterface& local_audio_track) const; |
| 55 | const cricket::VoiceReceiverInfo* GetVoiceReceiverInfo( |
| 56 | const AudioTrackInterface& remote_audio_track) const; |
| 57 | const std::vector<cricket::VideoSenderInfo*>* GetVideoSenderInfos( |
| 58 | const VideoTrackInterface& local_video_track) const; |
| 59 | const cricket::VideoReceiverInfo* GetVideoReceiverInfo( |
| 60 | const VideoTrackInterface& remote_video_track) const; |
| 61 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 62 | const cricket::VoiceSenderInfo* GetVoiceSenderInfoBySsrc(uint32_t ssrc) const; |
| 63 | const cricket::VoiceReceiverInfo* GetVoiceReceiverInfoBySsrc( |
| 64 | uint32_t ssrc) const; |
| 65 | const cricket::VideoSenderInfo* GetVideoSenderInfoBySsrc(uint32_t ssrc) const; |
| 66 | const cricket::VideoReceiverInfo* GetVideoReceiverInfoBySsrc( |
| 67 | uint32_t ssrc) const; |
| 68 | |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 69 | rtc::scoped_refptr<AudioTrackInterface> GetAudioTrack( |
| 70 | const cricket::VoiceSenderInfo& voice_sender_info) const; |
| 71 | rtc::scoped_refptr<AudioTrackInterface> GetAudioTrack( |
| 72 | const cricket::VoiceReceiverInfo& voice_receiver_info) const; |
| 73 | rtc::scoped_refptr<VideoTrackInterface> GetVideoTrack( |
| 74 | const cricket::VideoSenderInfo& video_sender_info) const; |
| 75 | rtc::scoped_refptr<VideoTrackInterface> GetVideoTrack( |
| 76 | const cricket::VideoReceiverInfo& video_receiver_info) const; |
| 77 | |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 78 | // TODO(hta): Remove this function, and redesign the callers not to need it. |
| 79 | // It is not going to work if a track is attached multiple times, and |
| 80 | // it is not going to work if a received track is attached as a sending |
| 81 | // track (loopback). |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 82 | absl::optional<int> GetAttachmentIdByTrack( |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 83 | const MediaStreamTrackInterface* track) const; |
| 84 | |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 85 | private: |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 86 | absl::optional<std::string> voice_mid_; |
| 87 | absl::optional<std::string> video_mid_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 88 | std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info_; |
| 89 | std::unique_ptr<cricket::VideoMediaInfo> video_media_info_; |
| 90 | // These maps map tracks (identified by a pointer) to their corresponding info |
| 91 | // object of the correct kind. One track can map to multiple info objects. |
| 92 | std::map<const AudioTrackInterface*, std::vector<cricket::VoiceSenderInfo*>> |
| 93 | voice_infos_by_local_track_; |
| 94 | std::map<const AudioTrackInterface*, cricket::VoiceReceiverInfo*> |
| 95 | voice_info_by_remote_track_; |
| 96 | std::map<const VideoTrackInterface*, std::vector<cricket::VideoSenderInfo*>> |
| 97 | video_infos_by_local_track_; |
| 98 | std::map<const VideoTrackInterface*, cricket::VideoReceiverInfo*> |
| 99 | video_info_by_remote_track_; |
| 100 | // These maps map info objects to their corresponding tracks. They are always |
| 101 | // the inverse of the maps above. One info object always maps to only one |
| 102 | // track. |
| 103 | std::map<const cricket::VoiceSenderInfo*, |
deadbeef | 804c1af | 2017-02-11 19:07:31 -0800 | [diff] [blame] | 104 | rtc::scoped_refptr<AudioTrackInterface>> |
| 105 | audio_track_by_sender_info_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 106 | std::map<const cricket::VoiceReceiverInfo*, |
deadbeef | 804c1af | 2017-02-11 19:07:31 -0800 | [diff] [blame] | 107 | rtc::scoped_refptr<AudioTrackInterface>> |
| 108 | audio_track_by_receiver_info_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 109 | std::map<const cricket::VideoSenderInfo*, |
deadbeef | 804c1af | 2017-02-11 19:07:31 -0800 | [diff] [blame] | 110 | rtc::scoped_refptr<VideoTrackInterface>> |
| 111 | video_track_by_sender_info_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 112 | std::map<const cricket::VideoReceiverInfo*, |
deadbeef | 804c1af | 2017-02-11 19:07:31 -0800 | [diff] [blame] | 113 | rtc::scoped_refptr<VideoTrackInterface>> |
| 114 | video_track_by_receiver_info_; |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 115 | // Map of tracks to attachment IDs. |
| 116 | // Necessary because senders and receivers live on the signaling thread, |
| 117 | // but the attachment IDs are needed while building stats on the networking |
| 118 | // thread, so we can't look them up in the senders/receivers without |
| 119 | // thread jumping. |
| 120 | std::map<const MediaStreamTrackInterface*, int> attachment_id_by_track_; |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 121 | // These maps map SSRCs to the corresponding voice or video info objects. |
| 122 | std::map<uint32_t, cricket::VoiceSenderInfo*> voice_info_by_sender_ssrc_; |
| 123 | std::map<uint32_t, cricket::VoiceReceiverInfo*> voice_info_by_receiver_ssrc_; |
| 124 | std::map<uint32_t, cricket::VideoSenderInfo*> video_info_by_sender_ssrc_; |
| 125 | std::map<uint32_t, cricket::VideoReceiverInfo*> video_info_by_receiver_ssrc_; |
hbos | 1f8239c | 2017-01-16 04:24:10 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | } // namespace webrtc |
| 129 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 130 | #endif // PC_TRACKMEDIAINFOMAP_H_ |