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