Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 11 #include "webrtc/api/trackmediainfomap.h" | |
| 12 | |
| 13 #include <utility> | |
| 14 | |
| 15 namespace webrtc { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 std::map<uint32_t, MediaStreamTrackInterface*> GetSsrcToTrack( | |
|
Taylor Brandstetter
2017/01/05 00:35:42
If not bundling, it's theoretically possible to us
hta-webrtc
2017/01/05 09:46:56
The ID for an SSRC (aka RTPMediaStream) should be
hbos
2017/01/05 15:27:56
I don't see where I get the transport/mid/content
Taylor Brandstetter
2017/01/11 22:12:04
Yes, this is the best you can do now. Currently "m
| |
| 20 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, | |
| 21 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& | |
| 22 rtp_receivers) { | |
| 23 std::map<uint32_t, MediaStreamTrackInterface*> ssrc_to_track; | |
| 24 for (const rtc::scoped_refptr<RtpSenderInterface>& rtp_sender : rtp_senders) { | |
| 25 if (!rtp_sender->track()) { | |
| 26 continue; | |
| 27 } | |
| 28 if (rtp_sender->ssrc() != 0) { | |
|
Taylor Brandstetter
2017/01/05 00:35:42
Could add a TODO to remove this once RtpEncodingPa
hbos
2017/01/05 15:27:56
Done.
| |
| 29 RTC_DCHECK(ssrc_to_track.find(rtp_sender->ssrc()) == ssrc_to_track.end()); | |
| 30 ssrc_to_track[rtp_sender->ssrc()] = rtp_sender->track(); | |
| 31 } | |
| 32 RtpParameters params = rtp_sender->GetParameters(); | |
| 33 for (const RtpEncodingParameters& encoding : params.encodings) { | |
| 34 if (!encoding.ssrc || *encoding.ssrc == rtp_sender->ssrc()) { | |
| 35 continue; | |
| 36 } | |
| 37 RTC_DCHECK(ssrc_to_track.find(*encoding.ssrc) == ssrc_to_track.end()); | |
| 38 ssrc_to_track[*encoding.ssrc] = rtp_sender->track(); | |
| 39 } | |
| 40 } | |
| 41 for (const rtc::scoped_refptr<RtpReceiverInterface>& rtp_receiver : | |
| 42 rtp_receivers) { | |
| 43 RTC_DCHECK(rtp_receiver->track()); | |
| 44 RtpParameters params = rtp_receiver->GetParameters(); | |
| 45 for (const RtpEncodingParameters& encoding : params.encodings) { | |
| 46 if (!encoding.ssrc) { | |
| 47 continue; | |
| 48 } | |
| 49 RTC_DCHECK(ssrc_to_track.find(*encoding.ssrc) == ssrc_to_track.end()); | |
| 50 ssrc_to_track[*encoding.ssrc] = rtp_receiver->track(); | |
| 51 } | |
| 52 } | |
| 53 return ssrc_to_track; | |
| 54 } | |
| 55 | |
| 56 template<typename T> | |
| 57 T* CheckedTrackCast(MediaStreamTrackInterface* track); | |
| 58 | |
| 59 template<> | |
| 60 AudioTrackInterface* CheckedTrackCast(MediaStreamTrackInterface* track) { | |
| 61 RTC_DCHECK_EQ(track->kind(), MediaStreamTrackInterface::kAudioKind); | |
| 62 return static_cast<AudioTrackInterface*>(track); | |
| 63 } | |
| 64 | |
| 65 template<> | |
| 66 VideoTrackInterface* CheckedTrackCast(MediaStreamTrackInterface* track) { | |
| 67 RTC_DCHECK_EQ(track->kind(), MediaStreamTrackInterface::kVideoKind); | |
| 68 return static_cast<VideoTrackInterface*>(track); | |
| 69 } | |
| 70 | |
| 71 // Template in order to support both the audio and video case. | |
| 72 template<typename TrackType, typename InfoType> | |
| 73 TrackType* GetAssociatedTrack( | |
| 74 const std::map<uint32_t, MediaStreamTrackInterface*>& ssrc_to_track, | |
| 75 const InfoType& info) { | |
| 76 std::map<uint32_t, MediaStreamTrackInterface*>::const_iterator it = | |
| 77 ssrc_to_track.find(info.ssrc()); | |
| 78 if (it == ssrc_to_track.end()) { | |
| 79 return nullptr; | |
| 80 } | |
| 81 return CheckedTrackCast<TrackType>(it->second); | |
| 82 } | |
| 83 | |
| 84 // Template in order to support both the audio and video case. | |
| 85 template<typename TrackType, | |
| 86 typename MediaInfoType, | |
| 87 typename SenderInfoToTrackType, | |
| 88 typename LocalTrackToInfosType, | |
| 89 typename ReceiverInfoToTrackType, | |
| 90 typename RemoteTrackToInfosType> | |
| 91 void MapTracksAndInfos( | |
| 92 const std::map<uint32_t, MediaStreamTrackInterface*>& ssrc_to_track, | |
| 93 MediaInfoType* media_info, | |
| 94 SenderInfoToTrackType* sender_info_to_track, | |
| 95 LocalTrackToInfosType* local_track_to_infos, | |
| 96 ReceiverInfoToTrackType* receiver_info_to_track, | |
| 97 RemoteTrackToInfosType* remote_track_to_info) { | |
| 98 for (auto& sender_info : media_info->senders) { | |
| 99 TrackType* associated_track = GetAssociatedTrack<TrackType>( | |
| 100 ssrc_to_track, sender_info); | |
| 101 if (associated_track) { | |
| 102 // One sender is associated with at most one track. | |
| 103 // One track may be associated with multiple senders. | |
| 104 (*sender_info_to_track)[&sender_info] = associated_track; | |
| 105 (*local_track_to_infos)[associated_track].push_back(&sender_info); | |
| 106 } | |
| 107 } | |
| 108 for (auto& receiver_info : media_info->receivers) { | |
| 109 TrackType* associated_track = GetAssociatedTrack<TrackType>( | |
| 110 ssrc_to_track, receiver_info); | |
| 111 if (associated_track) { | |
| 112 // One receiver is associated with at most one track, which is uniquely | |
| 113 // associated with that receiver. | |
| 114 (*receiver_info_to_track)[&receiver_info] = associated_track; | |
| 115 RTC_DCHECK(remote_track_to_info->find(associated_track) == | |
| 116 remote_track_to_info->end()); | |
| 117 (*remote_track_to_info)[associated_track] = &receiver_info; | |
| 118 } | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 } // namespace | |
| 123 | |
| 124 TrackMediaInfoMap::TrackMediaInfoMap( | |
| 125 std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info, | |
| 126 std::unique_ptr<cricket::VideoMediaInfo> video_media_info) | |
| 127 : is_initialized_(false), | |
| 128 voice_media_info_(std::move(voice_media_info)), | |
| 129 video_media_info_(std::move(video_media_info)) { | |
| 130 } | |
| 131 | |
| 132 void TrackMediaInfoMap::Initialize( | |
| 133 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, | |
| 134 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& | |
| 135 rtp_receivers) { | |
| 136 RTC_DCHECK(!is_initialized_); | |
| 137 is_initialized_ = true; | |
|
hta-webrtc
2017/01/05 09:46:56
Here's the part that is not thread-safe (but it ma
hbos
2017/01/05 15:27:56
Merged Initialize with constructor.
| |
| 138 std::map<uint32_t, MediaStreamTrackInterface*> ssrc_to_track = | |
| 139 GetSsrcToTrack(rtp_senders, rtp_receivers); | |
| 140 | |
| 141 if (voice_media_info_) { | |
| 142 MapTracksAndInfos<AudioTrackInterface>(ssrc_to_track, | |
| 143 voice_media_info_.get(), | |
| 144 &voice_sender_info_to_track_, | |
| 145 &local_audio_track_to_infos_, | |
| 146 &voice_receiver_info_to_track_, | |
| 147 &remote_audio_track_to_info_); | |
| 148 } | |
| 149 if (video_media_info_) { | |
| 150 MapTracksAndInfos<VideoTrackInterface>(ssrc_to_track, | |
| 151 video_media_info_.get(), | |
| 152 &video_sender_info_to_track_, | |
| 153 &local_video_track_to_infos_, | |
| 154 &video_receiver_info_to_track_, | |
| 155 &remote_video_track_to_info_); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 const std::vector<cricket::VoiceSenderInfo*>* | |
| 160 TrackMediaInfoMap::GetVoiceSenderInfos( | |
| 161 const AudioTrackInterface& local_audio_track) const { | |
| 162 RTC_DCHECK(is_initialized_); | |
| 163 std::map<const AudioTrackInterface*, | |
| 164 std::vector<cricket::VoiceSenderInfo*>>::const_iterator it = | |
| 165 local_audio_track_to_infos_.find(&local_audio_track); | |
| 166 if (it == local_audio_track_to_infos_.end()) { | |
| 167 return nullptr; | |
| 168 } | |
| 169 return &it->second; | |
| 170 } | |
| 171 | |
| 172 const cricket::VoiceReceiverInfo* TrackMediaInfoMap::GetVoiceReceiverInfo( | |
| 173 const AudioTrackInterface& remote_audio_track) const { | |
| 174 RTC_DCHECK(is_initialized_); | |
| 175 std::map<const AudioTrackInterface*, | |
| 176 cricket::VoiceReceiverInfo*>::const_iterator it = | |
| 177 remote_audio_track_to_info_.find(&remote_audio_track); | |
| 178 if (it == remote_audio_track_to_info_.end()) { | |
| 179 return nullptr; | |
| 180 } | |
| 181 return it->second; | |
| 182 } | |
| 183 | |
| 184 const std::vector<cricket::VideoSenderInfo*>* | |
| 185 TrackMediaInfoMap::GetVideoSenderInfos( | |
| 186 const VideoTrackInterface& local_video_track) const { | |
| 187 RTC_DCHECK(is_initialized_); | |
| 188 std::map<const VideoTrackInterface*, | |
| 189 std::vector<cricket::VideoSenderInfo*>>::const_iterator it = | |
| 190 local_video_track_to_infos_.find(&local_video_track); | |
| 191 if (it == local_video_track_to_infos_.end()) { | |
| 192 return nullptr; | |
| 193 } | |
| 194 return &it->second; | |
| 195 } | |
| 196 | |
| 197 const cricket::VideoReceiverInfo* TrackMediaInfoMap::GetVideoReceiverInfo( | |
| 198 const VideoTrackInterface& remote_video_track) const { | |
| 199 RTC_DCHECK(is_initialized_); | |
| 200 std::map<const VideoTrackInterface*, | |
| 201 cricket::VideoReceiverInfo*>::const_iterator it = | |
| 202 remote_video_track_to_info_.find(&remote_video_track); | |
| 203 if (it == remote_video_track_to_info_.end()) { | |
| 204 return nullptr; | |
| 205 } | |
| 206 return it->second; | |
| 207 } | |
| 208 | |
| 209 rtc::scoped_refptr<AudioTrackInterface> TrackMediaInfoMap::GetAudioTrack( | |
| 210 const cricket::VoiceSenderInfo& voice_sender_info) const { | |
| 211 RTC_DCHECK(is_initialized_); | |
| 212 std::map<const cricket::VoiceSenderInfo*, | |
| 213 rtc::scoped_refptr<AudioTrackInterface>>::const_iterator it = | |
| 214 voice_sender_info_to_track_.find(&voice_sender_info); | |
| 215 if (it == voice_sender_info_to_track_.end()) { | |
| 216 return nullptr; | |
| 217 } | |
| 218 return it->second; | |
| 219 } | |
| 220 | |
| 221 rtc::scoped_refptr<AudioTrackInterface> TrackMediaInfoMap::GetAudioTrack( | |
| 222 const cricket::VoiceReceiverInfo& voice_receiver_info) const { | |
| 223 RTC_DCHECK(is_initialized_); | |
| 224 std::map<const cricket::VoiceReceiverInfo*, | |
| 225 rtc::scoped_refptr<AudioTrackInterface>>::const_iterator it = | |
| 226 voice_receiver_info_to_track_.find(&voice_receiver_info); | |
| 227 if (it == voice_receiver_info_to_track_.end()) { | |
| 228 return nullptr; | |
| 229 } | |
| 230 return it->second; | |
| 231 } | |
| 232 | |
| 233 rtc::scoped_refptr<VideoTrackInterface> TrackMediaInfoMap::GetVideoTrack( | |
| 234 const cricket::VideoSenderInfo& video_sender_info) const { | |
| 235 RTC_DCHECK(is_initialized_); | |
| 236 std::map<const cricket::VideoSenderInfo*, | |
| 237 rtc::scoped_refptr<VideoTrackInterface>>::const_iterator it = | |
| 238 video_sender_info_to_track_.find(&video_sender_info); | |
| 239 if (it == video_sender_info_to_track_.end()) { | |
| 240 return nullptr; | |
| 241 } | |
| 242 return it->second; | |
| 243 } | |
| 244 | |
| 245 rtc::scoped_refptr<VideoTrackInterface> TrackMediaInfoMap::GetVideoTrack( | |
| 246 const cricket::VideoReceiverInfo& video_receiver_info) const { | |
| 247 RTC_DCHECK(is_initialized_); | |
| 248 std::map<const cricket::VideoReceiverInfo*, | |
| 249 rtc::scoped_refptr<VideoTrackInterface>>::const_iterator it = | |
| 250 video_receiver_info_to_track_.find(&video_receiver_info); | |
| 251 if (it == video_receiver_info_to_track_.end()) { | |
| 252 return nullptr; | |
| 253 } | |
| 254 return it->second; | |
| 255 } | |
| 256 | |
| 257 } // namespace webrtc | |
| OLD | NEW |