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 template<typename T> | |
| 20 T* CheckedTrackCast(MediaStreamTrackInterface* track); | |
| 21 | |
| 22 template<> | |
|
hta-webrtc
2017/01/11 12:34:24
C++ ignorance: Why is there value in having the te
hbos
2017/01/11 15:55:32
Without the DCHECK I could remove this function an
| |
| 23 AudioTrackInterface* CheckedTrackCast(MediaStreamTrackInterface* track) { | |
| 24 RTC_DCHECK_EQ(track->kind(), MediaStreamTrackInterface::kAudioKind); | |
| 25 return static_cast<AudioTrackInterface*>(track); | |
| 26 } | |
| 27 | |
| 28 template<> | |
| 29 VideoTrackInterface* CheckedTrackCast(MediaStreamTrackInterface* track) { | |
| 30 RTC_DCHECK_EQ(track->kind(), MediaStreamTrackInterface::kVideoKind); | |
| 31 return static_cast<VideoTrackInterface*>(track); | |
| 32 } | |
| 33 | |
| 34 // |T|: |AudioTrackInterface| or |VideoTrackInterface|, must match with | |
| 35 // |media_type|. | |
| 36 template<typename T> | |
| 37 std::map<uint32_t, T*> GetSsrcToTrack( | |
| 38 cricket::MediaType media_type, | |
| 39 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, | |
| 40 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& | |
| 41 rtp_receivers) { | |
| 42 std::map<uint32_t, T*> ssrc_to_track; | |
| 43 for (const rtc::scoped_refptr<RtpSenderInterface>& rtp_sender : rtp_senders) { | |
| 44 if (rtp_sender->media_type() != media_type || !rtp_sender->track()) { | |
| 45 continue; | |
| 46 } | |
| 47 // TODO(deadbeef): |ssrc| should be removed in favor of |GetParameters|. | |
| 48 if (rtp_sender->ssrc() != 0) { | |
|
hta-webrtc
2017/01/11 12:34:23
Why isn't it correct to loop over all the ssrcs in
hbos
2017/01/11 15:55:32
If I understand correctly, it's because the first
| |
| 49 RTC_DCHECK(ssrc_to_track.find(rtp_sender->ssrc()) == ssrc_to_track.end()); | |
| 50 ssrc_to_track[rtp_sender->ssrc()] = CheckedTrackCast<T>( | |
| 51 rtp_sender->track()); | |
| 52 } | |
| 53 RtpParameters params = rtp_sender->GetParameters(); | |
|
Taylor Brandstetter
2017/01/10 17:29:24
Something I wanted to point out before I forget: t
hbos
2017/01/11 15:55:32
Thanks, I didn't realize [1] occurred. Ugh, but I'
Taylor Brandstetter
2017/01/11 22:12:05
Yes, if you call GetSenders you'll get proxies. Bu
| |
| 54 for (const RtpEncodingParameters& encoding : params.encodings) { | |
| 55 if (!encoding.ssrc || *encoding.ssrc == rtp_sender->ssrc()) { | |
| 56 continue; | |
| 57 } | |
| 58 RTC_DCHECK(ssrc_to_track.find(*encoding.ssrc) == ssrc_to_track.end()); | |
| 59 ssrc_to_track[*encoding.ssrc] = CheckedTrackCast<T>(rtp_sender->track()); | |
| 60 } | |
| 61 } | |
| 62 for (const rtc::scoped_refptr<RtpReceiverInterface>& rtp_receiver : | |
| 63 rtp_receivers) { | |
| 64 if (rtp_receiver->media_type() != media_type) { | |
| 65 continue; | |
| 66 } | |
| 67 RTC_DCHECK(rtp_receiver->track()); | |
| 68 RtpParameters params = rtp_receiver->GetParameters(); | |
| 69 for (const RtpEncodingParameters& encoding : params.encodings) { | |
| 70 if (!encoding.ssrc) { | |
| 71 continue; | |
| 72 } | |
| 73 RTC_DCHECK(ssrc_to_track.find(*encoding.ssrc) == ssrc_to_track.end()); | |
| 74 ssrc_to_track[*encoding.ssrc] = CheckedTrackCast<T>( | |
| 75 rtp_receiver->track()); | |
| 76 } | |
| 77 } | |
| 78 return ssrc_to_track; | |
| 79 } | |
| 80 | |
| 81 // Template in order to support both the audio and video case. | |
| 82 template<typename TrackType, typename InfoType> | |
| 83 TrackType* GetAssociatedTrack( | |
| 84 const std::map<uint32_t, TrackType*>& ssrc_to_track, | |
| 85 const InfoType& info) { | |
| 86 typename std::map<uint32_t, TrackType*>::const_iterator it = | |
| 87 ssrc_to_track.find(info.ssrc()); | |
| 88 if (it == ssrc_to_track.end()) { | |
| 89 return nullptr; | |
| 90 } | |
| 91 return it->second; | |
| 92 } | |
| 93 | |
| 94 // Template in order to support both the audio and video case. | |
| 95 template<typename TrackType, | |
| 96 typename MediaInfoType, | |
| 97 typename SenderInfoToTrackType, | |
| 98 typename LocalTrackToInfosType, | |
| 99 typename ReceiverInfoToTrackType, | |
| 100 typename RemoteTrackToInfosType> | |
| 101 void MapTracksAndInfos( | |
| 102 const std::map<uint32_t, TrackType*>& ssrc_to_track, | |
| 103 MediaInfoType* media_info, | |
| 104 SenderInfoToTrackType* sender_info_to_track, | |
| 105 LocalTrackToInfosType* local_track_to_infos, | |
| 106 ReceiverInfoToTrackType* receiver_info_to_track, | |
| 107 RemoteTrackToInfosType* remote_track_to_info) { | |
| 108 for (auto& sender_info : media_info->senders) { | |
| 109 TrackType* associated_track = GetAssociatedTrack<TrackType>( | |
| 110 ssrc_to_track, sender_info); | |
| 111 if (associated_track) { | |
| 112 // One sender is associated with at most one track. | |
| 113 // One track may be associated with multiple senders. | |
| 114 (*sender_info_to_track)[&sender_info] = associated_track; | |
| 115 (*local_track_to_infos)[associated_track].push_back(&sender_info); | |
| 116 } | |
| 117 } | |
| 118 for (auto& receiver_info : media_info->receivers) { | |
| 119 TrackType* associated_track = GetAssociatedTrack<TrackType>( | |
| 120 ssrc_to_track, receiver_info); | |
| 121 if (associated_track) { | |
| 122 // One receiver is associated with at most one track, which is uniquely | |
| 123 // associated with that receiver. | |
| 124 (*receiver_info_to_track)[&receiver_info] = associated_track; | |
| 125 RTC_DCHECK(remote_track_to_info->find(associated_track) == | |
| 126 remote_track_to_info->end()); | |
| 127 (*remote_track_to_info)[associated_track] = &receiver_info; | |
| 128 } | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 } // namespace | |
| 133 | |
| 134 TrackMediaInfoMap::TrackMediaInfoMap( | |
| 135 std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info, | |
| 136 std::unique_ptr<cricket::VideoMediaInfo> video_media_info, | |
| 137 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, | |
| 138 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& rtp_receivers) | |
| 139 : voice_media_info_(std::move(voice_media_info)), | |
| 140 video_media_info_(std::move(video_media_info)) { | |
| 141 if (voice_media_info_) { | |
| 142 std::map<uint32_t, AudioTrackInterface*> ssrc_to_audio_track = | |
| 143 GetSsrcToTrack<AudioTrackInterface>( | |
| 144 cricket::MEDIA_TYPE_AUDIO, rtp_senders, rtp_receivers); | |
| 145 MapTracksAndInfos<AudioTrackInterface>(ssrc_to_audio_track, | |
| 146 voice_media_info_.get(), | |
| 147 &voice_sender_info_to_track_, | |
| 148 &local_audio_track_to_infos_, | |
| 149 &voice_receiver_info_to_track_, | |
| 150 &remote_audio_track_to_info_); | |
| 151 } | |
| 152 if (video_media_info_) { | |
| 153 std::map<uint32_t, VideoTrackInterface*> ssrc_to_video_track = | |
| 154 GetSsrcToTrack<VideoTrackInterface>( | |
| 155 cricket::MEDIA_TYPE_VIDEO, rtp_senders, rtp_receivers); | |
| 156 MapTracksAndInfos<VideoTrackInterface>(ssrc_to_video_track, | |
| 157 video_media_info_.get(), | |
| 158 &video_sender_info_to_track_, | |
| 159 &local_video_track_to_infos_, | |
| 160 &video_receiver_info_to_track_, | |
| 161 &remote_video_track_to_info_); | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 const std::vector<cricket::VoiceSenderInfo*>* | |
| 166 TrackMediaInfoMap::GetVoiceSenderInfos( | |
| 167 const AudioTrackInterface& local_audio_track) const { | |
| 168 std::map<const AudioTrackInterface*, | |
| 169 std::vector<cricket::VoiceSenderInfo*>>::const_iterator it = | |
| 170 local_audio_track_to_infos_.find(&local_audio_track); | |
| 171 if (it == local_audio_track_to_infos_.end()) { | |
| 172 return nullptr; | |
| 173 } | |
| 174 return &it->second; | |
| 175 } | |
| 176 | |
| 177 const cricket::VoiceReceiverInfo* TrackMediaInfoMap::GetVoiceReceiverInfo( | |
| 178 const AudioTrackInterface& remote_audio_track) const { | |
| 179 std::map<const AudioTrackInterface*, | |
| 180 cricket::VoiceReceiverInfo*>::const_iterator it = | |
|
hta-webrtc
2017/01/11 12:34:23
Would "auto" be usable here? Seems that C++ alread
hbos
2017/01/11 15:55:33
Done.
| |
| 181 remote_audio_track_to_info_.find(&remote_audio_track); | |
| 182 if (it == remote_audio_track_to_info_.end()) { | |
| 183 return nullptr; | |
| 184 } | |
| 185 return it->second; | |
| 186 } | |
| 187 | |
| 188 const std::vector<cricket::VideoSenderInfo*>* | |
| 189 TrackMediaInfoMap::GetVideoSenderInfos( | |
| 190 const VideoTrackInterface& local_video_track) const { | |
| 191 std::map<const VideoTrackInterface*, | |
| 192 std::vector<cricket::VideoSenderInfo*>>::const_iterator it = | |
| 193 local_video_track_to_infos_.find(&local_video_track); | |
| 194 if (it == local_video_track_to_infos_.end()) { | |
| 195 return nullptr; | |
| 196 } | |
| 197 return &it->second; | |
| 198 } | |
| 199 | |
| 200 const cricket::VideoReceiverInfo* TrackMediaInfoMap::GetVideoReceiverInfo( | |
| 201 const VideoTrackInterface& remote_video_track) const { | |
| 202 std::map<const VideoTrackInterface*, | |
| 203 cricket::VideoReceiverInfo*>::const_iterator it = | |
| 204 remote_video_track_to_info_.find(&remote_video_track); | |
| 205 if (it == remote_video_track_to_info_.end()) { | |
| 206 return nullptr; | |
| 207 } | |
| 208 return it->second; | |
| 209 } | |
| 210 | |
| 211 rtc::scoped_refptr<AudioTrackInterface> TrackMediaInfoMap::GetAudioTrack( | |
| 212 const cricket::VoiceSenderInfo& voice_sender_info) const { | |
| 213 std::map<const cricket::VoiceSenderInfo*, | |
| 214 rtc::scoped_refptr<AudioTrackInterface>>::const_iterator it = | |
| 215 voice_sender_info_to_track_.find(&voice_sender_info); | |
| 216 if (it == voice_sender_info_to_track_.end()) { | |
| 217 return nullptr; | |
| 218 } | |
| 219 return it->second; | |
| 220 } | |
| 221 | |
| 222 rtc::scoped_refptr<AudioTrackInterface> TrackMediaInfoMap::GetAudioTrack( | |
| 223 const cricket::VoiceReceiverInfo& voice_receiver_info) const { | |
| 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 std::map<const cricket::VideoSenderInfo*, | |
| 236 rtc::scoped_refptr<VideoTrackInterface>>::const_iterator it = | |
| 237 video_sender_info_to_track_.find(&video_sender_info); | |
| 238 if (it == video_sender_info_to_track_.end()) { | |
| 239 return nullptr; | |
| 240 } | |
| 241 return it->second; | |
| 242 } | |
| 243 | |
| 244 rtc::scoped_refptr<VideoTrackInterface> TrackMediaInfoMap::GetVideoTrack( | |
| 245 const cricket::VideoReceiverInfo& video_receiver_info) const { | |
| 246 std::map<const cricket::VideoReceiverInfo*, | |
| 247 rtc::scoped_refptr<VideoTrackInterface>>::const_iterator it = | |
| 248 video_receiver_info_to_track_.find(&video_receiver_info); | |
| 249 if (it == video_receiver_info_to_track_.end()) { | |
| 250 return nullptr; | |
| 251 } | |
| 252 return it->second; | |
| 253 } | |
| 254 | |
| 255 } // namespace webrtc | |
| OLD | NEW |