Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: webrtc/pc/trackmediainfomap.cc

Issue 2703783002: TrackMediaInfoMap: Allow same SSRC for send and receive side. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/pc/trackmediainfomap_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 13 matching lines...) Expand all
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*>* local_audio_track_by_ssrc,
35 std::map<uint32_t, VideoTrackInterface*>* video_track_by_ssrc) { 35 std::map<uint32_t, VideoTrackInterface*>* local_video_track_by_ssrc,
36 RTC_DCHECK(audio_track_by_ssrc->empty()); 36 std::map<uint32_t, AudioTrackInterface*>* remote_audio_track_by_ssrc,
37 RTC_DCHECK(video_track_by_ssrc->empty()); 37 std::map<uint32_t, VideoTrackInterface*>* remote_video_track_by_ssrc) {
38 RTC_DCHECK(local_audio_track_by_ssrc->empty());
39 RTC_DCHECK(local_video_track_by_ssrc->empty());
40 RTC_DCHECK(remote_audio_track_by_ssrc->empty());
41 RTC_DCHECK(remote_video_track_by_ssrc->empty());
38 // TODO(hbos): RTP senders/receivers uses a proxy to the signaling thread, and 42 // TODO(hbos): RTP senders/receivers uses a proxy to the signaling thread, and
39 // our sender/receiver implementations invokes on the worker thread. (This 43 // 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 44 // 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 45 // other threads). Is there a way to avoid thread jump(s) on a per
42 // sender/receiver, per method basis? 46 // sender/receiver, per method basis?
43 for (const rtc::scoped_refptr<RtpSenderInterface>& rtp_sender : rtp_senders) { 47 for (const rtc::scoped_refptr<RtpSenderInterface>& rtp_sender : rtp_senders) {
44 cricket::MediaType media_type = rtp_sender->media_type(); 48 cricket::MediaType media_type = rtp_sender->media_type();
45 MediaStreamTrackInterface* track = rtp_sender->track(); 49 MediaStreamTrackInterface* track = rtp_sender->track();
46 if (!track) { 50 if (!track) {
47 continue; 51 continue;
48 } 52 }
49 RTC_DCHECK_EQ(track->kind(), media_type == cricket::MEDIA_TYPE_AUDIO 53 RTC_DCHECK_EQ(track->kind(), media_type == cricket::MEDIA_TYPE_AUDIO
50 ? MediaStreamTrackInterface::kAudioKind 54 ? MediaStreamTrackInterface::kAudioKind
51 : MediaStreamTrackInterface::kVideoKind); 55 : MediaStreamTrackInterface::kVideoKind);
52 // TODO(deadbeef): |ssrc| should be removed in favor of |GetParameters|. 56 // TODO(deadbeef): |ssrc| should be removed in favor of |GetParameters|.
53 uint32_t ssrc = rtp_sender->ssrc(); 57 uint32_t ssrc = rtp_sender->ssrc();
54 if (ssrc != 0) { 58 if (ssrc != 0) {
55 if (media_type == cricket::MEDIA_TYPE_AUDIO) { 59 if (media_type == cricket::MEDIA_TYPE_AUDIO) {
56 RTC_DCHECK(audio_track_by_ssrc->find(ssrc) == 60 RTC_DCHECK(local_audio_track_by_ssrc->find(ssrc) ==
57 audio_track_by_ssrc->end()); 61 local_audio_track_by_ssrc->end());
58 (*audio_track_by_ssrc)[ssrc] = static_cast<AudioTrackInterface*>(track); 62 (*local_audio_track_by_ssrc)[ssrc] =
63 static_cast<AudioTrackInterface*>(track);
59 } else { 64 } else {
60 RTC_DCHECK(video_track_by_ssrc->find(ssrc) == 65 RTC_DCHECK(local_video_track_by_ssrc->find(ssrc) ==
61 video_track_by_ssrc->end()); 66 local_video_track_by_ssrc->end());
62 (*video_track_by_ssrc)[ssrc] = static_cast<VideoTrackInterface*>(track); 67 (*local_video_track_by_ssrc)[ssrc] =
68 static_cast<VideoTrackInterface*>(track);
63 } 69 }
64 } 70 }
65 } 71 }
66 for (const rtc::scoped_refptr<RtpReceiverInterface>& rtp_receiver : 72 for (const rtc::scoped_refptr<RtpReceiverInterface>& rtp_receiver :
67 rtp_receivers) { 73 rtp_receivers) {
68 cricket::MediaType media_type = rtp_receiver->media_type(); 74 cricket::MediaType media_type = rtp_receiver->media_type();
69 MediaStreamTrackInterface* track = rtp_receiver->track(); 75 MediaStreamTrackInterface* track = rtp_receiver->track();
70 RTC_DCHECK(track); 76 RTC_DCHECK(track);
71 RTC_DCHECK_EQ(track->kind(), media_type == cricket::MEDIA_TYPE_AUDIO 77 RTC_DCHECK_EQ(track->kind(), media_type == cricket::MEDIA_TYPE_AUDIO
72 ? MediaStreamTrackInterface::kAudioKind 78 ? MediaStreamTrackInterface::kAudioKind
73 : MediaStreamTrackInterface::kVideoKind); 79 : MediaStreamTrackInterface::kVideoKind);
74 RtpParameters params = rtp_receiver->GetParameters(); 80 RtpParameters params = rtp_receiver->GetParameters();
75 for (const RtpEncodingParameters& encoding : params.encodings) { 81 for (const RtpEncodingParameters& encoding : params.encodings) {
76 if (!encoding.ssrc) { 82 if (!encoding.ssrc) {
77 continue; 83 continue;
78 } 84 }
79 if (media_type == cricket::MEDIA_TYPE_AUDIO) { 85 if (media_type == cricket::MEDIA_TYPE_AUDIO) {
80 RTC_DCHECK(audio_track_by_ssrc->find(*encoding.ssrc) == 86 RTC_DCHECK(remote_audio_track_by_ssrc->find(*encoding.ssrc) ==
81 audio_track_by_ssrc->end()); 87 remote_audio_track_by_ssrc->end());
82 (*audio_track_by_ssrc)[*encoding.ssrc] = 88 (*remote_audio_track_by_ssrc)[*encoding.ssrc] =
83 static_cast<AudioTrackInterface*>(track); 89 static_cast<AudioTrackInterface*>(track);
84 } else { 90 } else {
85 RTC_DCHECK(video_track_by_ssrc->find(*encoding.ssrc) == 91 RTC_DCHECK(remote_video_track_by_ssrc->find(*encoding.ssrc) ==
86 video_track_by_ssrc->end()); 92 remote_video_track_by_ssrc->end());
87 (*video_track_by_ssrc)[*encoding.ssrc] = 93 (*remote_video_track_by_ssrc)[*encoding.ssrc] =
88 static_cast<VideoTrackInterface*>(track); 94 static_cast<VideoTrackInterface*>(track);
89 } 95 }
90 } 96 }
91 } 97 }
92 } 98 }
93 99
94 } // namespace 100 } // namespace
95 101
96 TrackMediaInfoMap::TrackMediaInfoMap( 102 TrackMediaInfoMap::TrackMediaInfoMap(
97 std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info, 103 std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info,
98 std::unique_ptr<cricket::VideoMediaInfo> video_media_info, 104 std::unique_ptr<cricket::VideoMediaInfo> video_media_info,
99 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, 105 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders,
100 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& rtp_receivers) 106 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& rtp_receivers)
101 : voice_media_info_(std::move(voice_media_info)), 107 : voice_media_info_(std::move(voice_media_info)),
102 video_media_info_(std::move(video_media_info)) { 108 video_media_info_(std::move(video_media_info)) {
103 std::map<uint32_t, AudioTrackInterface*> audio_track_by_ssrc; 109 std::map<uint32_t, AudioTrackInterface*> local_audio_track_by_ssrc;
104 std::map<uint32_t, VideoTrackInterface*> video_track_by_ssrc; 110 std::map<uint32_t, VideoTrackInterface*> local_video_track_by_ssrc;
105 GetAudioAndVideoTrackBySsrc(rtp_senders, rtp_receivers, &audio_track_by_ssrc, 111 std::map<uint32_t, AudioTrackInterface*> remote_audio_track_by_ssrc;
106 &video_track_by_ssrc); 112 std::map<uint32_t, VideoTrackInterface*> remote_video_track_by_ssrc;
113 GetAudioAndVideoTrackBySsrc(rtp_senders,
114 rtp_receivers,
115 &local_audio_track_by_ssrc,
116 &local_video_track_by_ssrc,
117 &remote_audio_track_by_ssrc,
118 &remote_video_track_by_ssrc);
107 if (voice_media_info_) { 119 if (voice_media_info_) {
108 for (auto& sender_info : voice_media_info_->senders) { 120 for (auto& sender_info : voice_media_info_->senders) {
109 AudioTrackInterface* associated_track = 121 AudioTrackInterface* associated_track =
110 FindValueOrNull(audio_track_by_ssrc, sender_info.ssrc()); 122 FindValueOrNull(local_audio_track_by_ssrc, sender_info.ssrc());
111 if (associated_track) { 123 if (associated_track) {
112 // One sender is associated with at most one track. 124 // One sender is associated with at most one track.
113 // One track may be associated with multiple senders. 125 // One track may be associated with multiple senders.
114 audio_track_by_sender_info_[&sender_info] = associated_track; 126 audio_track_by_sender_info_[&sender_info] = associated_track;
115 voice_infos_by_local_track_[associated_track].push_back(&sender_info); 127 voice_infos_by_local_track_[associated_track].push_back(&sender_info);
116 } 128 }
117 } 129 }
118 for (auto& receiver_info : voice_media_info_->receivers) { 130 for (auto& receiver_info : voice_media_info_->receivers) {
119 AudioTrackInterface* associated_track = 131 AudioTrackInterface* associated_track =
120 FindValueOrNull(audio_track_by_ssrc, receiver_info.ssrc()); 132 FindValueOrNull(remote_audio_track_by_ssrc, receiver_info.ssrc());
121 if (associated_track) { 133 if (associated_track) {
122 // One receiver is associated with at most one track, which is uniquely 134 // One receiver is associated with at most one track, which is uniquely
123 // associated with that receiver. 135 // associated with that receiver.
124 audio_track_by_receiver_info_[&receiver_info] = associated_track; 136 audio_track_by_receiver_info_[&receiver_info] = associated_track;
125 RTC_DCHECK(voice_info_by_remote_track_.find(associated_track) == 137 RTC_DCHECK(voice_info_by_remote_track_.find(associated_track) ==
126 voice_info_by_remote_track_.end()); 138 voice_info_by_remote_track_.end());
127 voice_info_by_remote_track_[associated_track] = &receiver_info; 139 voice_info_by_remote_track_[associated_track] = &receiver_info;
128 } 140 }
129 } 141 }
130 } 142 }
131 if (video_media_info_) { 143 if (video_media_info_) {
132 for (auto& sender_info : video_media_info_->senders) { 144 for (auto& sender_info : video_media_info_->senders) {
133 VideoTrackInterface* associated_track = 145 VideoTrackInterface* associated_track =
134 FindValueOrNull(video_track_by_ssrc, sender_info.ssrc()); 146 FindValueOrNull(local_video_track_by_ssrc, sender_info.ssrc());
135 if (associated_track) { 147 if (associated_track) {
136 // One sender is associated with at most one track. 148 // One sender is associated with at most one track.
137 // One track may be associated with multiple senders. 149 // One track may be associated with multiple senders.
138 video_track_by_sender_info_[&sender_info] = associated_track; 150 video_track_by_sender_info_[&sender_info] = associated_track;
139 video_infos_by_local_track_[associated_track].push_back(&sender_info); 151 video_infos_by_local_track_[associated_track].push_back(&sender_info);
140 } 152 }
141 } 153 }
142 for (auto& receiver_info : video_media_info_->receivers) { 154 for (auto& receiver_info : video_media_info_->receivers) {
143 VideoTrackInterface* associated_track = 155 VideoTrackInterface* associated_track =
144 FindValueOrNull(video_track_by_ssrc, receiver_info.ssrc()); 156 FindValueOrNull(remote_video_track_by_ssrc, receiver_info.ssrc());
145 if (associated_track) { 157 if (associated_track) {
146 // One receiver is associated with at most one track, which is uniquely 158 // One receiver is associated with at most one track, which is uniquely
147 // associated with that receiver. 159 // associated with that receiver.
148 video_track_by_receiver_info_[&receiver_info] = associated_track; 160 video_track_by_receiver_info_[&receiver_info] = associated_track;
149 RTC_DCHECK(video_info_by_remote_track_.find(associated_track) == 161 RTC_DCHECK(video_info_by_remote_track_.find(associated_track) ==
150 video_info_by_remote_track_.end()); 162 video_info_by_remote_track_.end());
151 video_info_by_remote_track_[associated_track] = &receiver_info; 163 video_info_by_remote_track_[associated_track] = &receiver_info;
152 } 164 }
153 } 165 }
154 } 166 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 const cricket::VideoSenderInfo& video_sender_info) const { 202 const cricket::VideoSenderInfo& video_sender_info) const {
191 return FindValueOrNull(video_track_by_sender_info_, &video_sender_info); 203 return FindValueOrNull(video_track_by_sender_info_, &video_sender_info);
192 } 204 }
193 205
194 rtc::scoped_refptr<VideoTrackInterface> TrackMediaInfoMap::GetVideoTrack( 206 rtc::scoped_refptr<VideoTrackInterface> TrackMediaInfoMap::GetVideoTrack(
195 const cricket::VideoReceiverInfo& video_receiver_info) const { 207 const cricket::VideoReceiverInfo& video_receiver_info) const {
196 return FindValueOrNull(video_track_by_receiver_info_, &video_receiver_info); 208 return FindValueOrNull(video_track_by_receiver_info_, &video_receiver_info);
197 } 209 }
198 210
199 } // namespace webrtc 211 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/pc/trackmediainfomap_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698