| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/api/trackmediainfomap.h" | 11 #include "webrtc/pc/trackmediainfomap.h" |
| 12 | 12 |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 namespace webrtc { | 15 namespace webrtc { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 template<typename K, typename V> | 19 template <typename K, typename V> |
| 20 V FindValueOrNull(const std::map<K, V>& map, const K& key) { | 20 V FindValueOrNull(const std::map<K, V>& map, const K& key) { |
| 21 auto it = map.find(key); | 21 auto it = map.find(key); |
| 22 return (it != map.end()) ? it->second : nullptr; | 22 return (it != map.end()) ? it->second : nullptr; |
| 23 } | 23 } |
| 24 | 24 |
| 25 template<typename K, typename V> | 25 template <typename K, typename V> |
| 26 const V* FindAddressOrNull(const std::map<K, V>& map, const K& key) { | 26 const V* FindAddressOrNull(const std::map<K, V>& map, const K& key) { |
| 27 auto it = map.find(key); | 27 auto it = map.find(key); |
| 28 return (it != map.end()) ? &it->second : nullptr; | 28 return (it != map.end()) ? &it->second : nullptr; |
| 29 } | 29 } |
| 30 | 30 |
| 31 void GetAudioAndVideoTrackBySsrc( | 31 void GetAudioAndVideoTrackBySsrc( |
| 32 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, | 32 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, |
| 33 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& rtp_receivers, | 33 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& rtp_receivers, |
| 34 std::map<uint32_t, AudioTrackInterface*>* audio_track_by_ssrc, | 34 std::map<uint32_t, AudioTrackInterface*>* audio_track_by_ssrc, |
| 35 std::map<uint32_t, VideoTrackInterface*>* video_track_by_ssrc) { | 35 std::map<uint32_t, VideoTrackInterface*>* video_track_by_ssrc) { |
| 36 RTC_DCHECK(audio_track_by_ssrc->empty()); | 36 RTC_DCHECK(audio_track_by_ssrc->empty()); |
| 37 RTC_DCHECK(video_track_by_ssrc->empty()); | 37 RTC_DCHECK(video_track_by_ssrc->empty()); |
| 38 // TODO(hbos): RTP senders/receivers uses a proxy to the signaling thread, and | 38 // TODO(hbos): RTP senders/receivers uses a proxy to the signaling thread, and |
| 39 // our sender/receiver implementations invokes on the worker thread. (This | 39 // our sender/receiver implementations invokes on the worker thread. (This |
| 40 // means one thread jump if on signaling thread and two thread jumps if on any | 40 // means one thread jump if on signaling thread and two thread jumps if on any |
| 41 // other threads). Is there a way to avoid thread jump(s) on a per | 41 // other threads). Is there a way to avoid thread jump(s) on a per |
| 42 // sender/receiver, per method basis? | 42 // sender/receiver, per method basis? |
| 43 for (const rtc::scoped_refptr<RtpSenderInterface>& rtp_sender : rtp_senders) { | 43 for (const rtc::scoped_refptr<RtpSenderInterface>& rtp_sender : rtp_senders) { |
| 44 cricket::MediaType media_type = rtp_sender->media_type(); | 44 cricket::MediaType media_type = rtp_sender->media_type(); |
| 45 MediaStreamTrackInterface* track = rtp_sender->track(); | 45 MediaStreamTrackInterface* track = rtp_sender->track(); |
| 46 if (!track) { | 46 if (!track) { |
| 47 continue; | 47 continue; |
| 48 } | 48 } |
| 49 RTC_DCHECK_EQ(track->kind(), | 49 RTC_DCHECK_EQ(track->kind(), media_type == cricket::MEDIA_TYPE_AUDIO |
| 50 media_type == cricket::MEDIA_TYPE_AUDIO | 50 ? MediaStreamTrackInterface::kAudioKind |
| 51 ? MediaStreamTrackInterface::kAudioKind | 51 : MediaStreamTrackInterface::kVideoKind); |
| 52 : MediaStreamTrackInterface::kVideoKind); | |
| 53 // TODO(deadbeef): |ssrc| should be removed in favor of |GetParameters|. | 52 // TODO(deadbeef): |ssrc| should be removed in favor of |GetParameters|. |
| 54 uint32_t ssrc = rtp_sender->ssrc(); | 53 uint32_t ssrc = rtp_sender->ssrc(); |
| 55 if (ssrc != 0) { | 54 if (ssrc != 0) { |
| 56 if (media_type == cricket::MEDIA_TYPE_AUDIO) { | 55 if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
| 57 RTC_DCHECK(audio_track_by_ssrc->find(ssrc) == | 56 RTC_DCHECK(audio_track_by_ssrc->find(ssrc) == |
| 58 audio_track_by_ssrc->end()); | 57 audio_track_by_ssrc->end()); |
| 59 (*audio_track_by_ssrc)[ssrc] = static_cast<AudioTrackInterface*>(track); | 58 (*audio_track_by_ssrc)[ssrc] = static_cast<AudioTrackInterface*>(track); |
| 60 } else { | 59 } else { |
| 61 RTC_DCHECK(video_track_by_ssrc->find(ssrc) == | 60 RTC_DCHECK(video_track_by_ssrc->find(ssrc) == |
| 62 video_track_by_ssrc->end()); | 61 video_track_by_ssrc->end()); |
| 63 (*video_track_by_ssrc)[ssrc] = static_cast<VideoTrackInterface*>(track); | 62 (*video_track_by_ssrc)[ssrc] = static_cast<VideoTrackInterface*>(track); |
| 64 } | 63 } |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 for (const rtc::scoped_refptr<RtpReceiverInterface>& rtp_receiver : | 66 for (const rtc::scoped_refptr<RtpReceiverInterface>& rtp_receiver : |
| 68 rtp_receivers) { | 67 rtp_receivers) { |
| 69 cricket::MediaType media_type = rtp_receiver->media_type(); | 68 cricket::MediaType media_type = rtp_receiver->media_type(); |
| 70 MediaStreamTrackInterface* track = rtp_receiver->track(); | 69 MediaStreamTrackInterface* track = rtp_receiver->track(); |
| 71 RTC_DCHECK(track); | 70 RTC_DCHECK(track); |
| 72 RTC_DCHECK_EQ(track->kind(), | 71 RTC_DCHECK_EQ(track->kind(), media_type == cricket::MEDIA_TYPE_AUDIO |
| 73 media_type == cricket::MEDIA_TYPE_AUDIO | 72 ? MediaStreamTrackInterface::kAudioKind |
| 74 ? MediaStreamTrackInterface::kAudioKind | 73 : MediaStreamTrackInterface::kVideoKind); |
| 75 : MediaStreamTrackInterface::kVideoKind); | |
| 76 RtpParameters params = rtp_receiver->GetParameters(); | 74 RtpParameters params = rtp_receiver->GetParameters(); |
| 77 for (const RtpEncodingParameters& encoding : params.encodings) { | 75 for (const RtpEncodingParameters& encoding : params.encodings) { |
| 78 if (!encoding.ssrc) { | 76 if (!encoding.ssrc) { |
| 79 continue; | 77 continue; |
| 80 } | 78 } |
| 81 if (media_type == cricket::MEDIA_TYPE_AUDIO) { | 79 if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
| 82 RTC_DCHECK(audio_track_by_ssrc->find(*encoding.ssrc) == | 80 RTC_DCHECK(audio_track_by_ssrc->find(*encoding.ssrc) == |
| 83 audio_track_by_ssrc->end()); | 81 audio_track_by_ssrc->end()); |
| 84 (*audio_track_by_ssrc)[*encoding.ssrc] = | 82 (*audio_track_by_ssrc)[*encoding.ssrc] = |
| 85 static_cast<AudioTrackInterface*>(track); | 83 static_cast<AudioTrackInterface*>(track); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 97 | 95 |
| 98 TrackMediaInfoMap::TrackMediaInfoMap( | 96 TrackMediaInfoMap::TrackMediaInfoMap( |
| 99 std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info, | 97 std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info, |
| 100 std::unique_ptr<cricket::VideoMediaInfo> video_media_info, | 98 std::unique_ptr<cricket::VideoMediaInfo> video_media_info, |
| 101 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, | 99 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, |
| 102 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& rtp_receivers) | 100 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& rtp_receivers) |
| 103 : voice_media_info_(std::move(voice_media_info)), | 101 : voice_media_info_(std::move(voice_media_info)), |
| 104 video_media_info_(std::move(video_media_info)) { | 102 video_media_info_(std::move(video_media_info)) { |
| 105 std::map<uint32_t, AudioTrackInterface*> audio_track_by_ssrc; | 103 std::map<uint32_t, AudioTrackInterface*> audio_track_by_ssrc; |
| 106 std::map<uint32_t, VideoTrackInterface*> video_track_by_ssrc; | 104 std::map<uint32_t, VideoTrackInterface*> video_track_by_ssrc; |
| 107 GetAudioAndVideoTrackBySsrc( | 105 GetAudioAndVideoTrackBySsrc(rtp_senders, rtp_receivers, &audio_track_by_ssrc, |
| 108 rtp_senders, rtp_receivers, &audio_track_by_ssrc, &video_track_by_ssrc); | 106 &video_track_by_ssrc); |
| 109 if (voice_media_info_) { | 107 if (voice_media_info_) { |
| 110 for (auto& sender_info : voice_media_info_->senders) { | 108 for (auto& sender_info : voice_media_info_->senders) { |
| 111 AudioTrackInterface* associated_track = | 109 AudioTrackInterface* associated_track = |
| 112 FindValueOrNull(audio_track_by_ssrc, sender_info.ssrc()); | 110 FindValueOrNull(audio_track_by_ssrc, sender_info.ssrc()); |
| 113 if (associated_track) { | 111 if (associated_track) { |
| 114 // One sender is associated with at most one track. | 112 // One sender is associated with at most one track. |
| 115 // One track may be associated with multiple senders. | 113 // One track may be associated with multiple senders. |
| 116 audio_track_by_sender_info_[&sender_info] = associated_track; | 114 audio_track_by_sender_info_[&sender_info] = associated_track; |
| 117 voice_infos_by_local_track_[associated_track].push_back(&sender_info); | 115 voice_infos_by_local_track_[associated_track].push_back(&sender_info); |
| 118 } | 116 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 const cricket::VideoSenderInfo& video_sender_info) const { | 190 const cricket::VideoSenderInfo& video_sender_info) const { |
| 193 return FindValueOrNull(video_track_by_sender_info_, &video_sender_info); | 191 return FindValueOrNull(video_track_by_sender_info_, &video_sender_info); |
| 194 } | 192 } |
| 195 | 193 |
| 196 rtc::scoped_refptr<VideoTrackInterface> TrackMediaInfoMap::GetVideoTrack( | 194 rtc::scoped_refptr<VideoTrackInterface> TrackMediaInfoMap::GetVideoTrack( |
| 197 const cricket::VideoReceiverInfo& video_receiver_info) const { | 195 const cricket::VideoReceiverInfo& video_receiver_info) const { |
| 198 return FindValueOrNull(video_track_by_receiver_info_, &video_receiver_info); | 196 return FindValueOrNull(video_track_by_receiver_info_, &video_receiver_info); |
| 199 } | 197 } |
| 200 | 198 |
| 201 } // namespace webrtc | 199 } // namespace webrtc |
| OLD | NEW |