OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 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 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 void LocalAudioSinkAdapter::SetSink(cricket::AudioSource::Sink* sink) { | 40 void LocalAudioSinkAdapter::SetSink(cricket::AudioSource::Sink* sink) { |
41 rtc::CritScope lock(&lock_); | 41 rtc::CritScope lock(&lock_); |
42 ASSERT(!sink || !sink_); | 42 ASSERT(!sink || !sink_); |
43 sink_ = sink; | 43 sink_ = sink; |
44 } | 44 } |
45 | 45 |
46 AudioRtpSender::AudioRtpSender(AudioTrackInterface* track, | 46 AudioRtpSender::AudioRtpSender(AudioTrackInterface* track, |
47 const std::string& stream_id, | 47 const std::string& stream_id, |
48 cricket::VoiceChannel* channel, | 48 AudioProviderInterface* provider, |
49 StatsCollector* stats) | 49 StatsCollector* stats) |
50 : id_(track->id()), | 50 : id_(track->id()), |
51 stream_id_(stream_id), | 51 stream_id_(stream_id), |
52 channel_(channel), | 52 provider_(provider), |
53 stats_(stats), | 53 stats_(stats), |
54 track_(track), | 54 track_(track), |
55 cached_track_enabled_(track->enabled()), | 55 cached_track_enabled_(track->enabled()), |
56 sink_adapter_(new LocalAudioSinkAdapter()) { | 56 sink_adapter_(new LocalAudioSinkAdapter()) { |
| 57 RTC_DCHECK(provider != nullptr); |
57 track_->RegisterObserver(this); | 58 track_->RegisterObserver(this); |
58 track_->AddSink(sink_adapter_.get()); | 59 track_->AddSink(sink_adapter_.get()); |
59 } | 60 } |
60 | 61 |
61 AudioRtpSender::AudioRtpSender(AudioTrackInterface* track, | 62 AudioRtpSender::AudioRtpSender(AudioTrackInterface* track, |
62 cricket::VoiceChannel* channel, | 63 AudioProviderInterface* provider, |
63 StatsCollector* stats) | 64 StatsCollector* stats) |
64 : id_(track->id()), | 65 : id_(track->id()), |
65 stream_id_(rtc::CreateRandomUuid()), | 66 stream_id_(rtc::CreateRandomUuid()), |
66 channel_(channel), | 67 provider_(provider), |
67 stats_(stats), | 68 stats_(stats), |
68 track_(track), | 69 track_(track), |
69 cached_track_enabled_(track->enabled()), | 70 cached_track_enabled_(track->enabled()), |
70 sink_adapter_(new LocalAudioSinkAdapter()) { | 71 sink_adapter_(new LocalAudioSinkAdapter()) { |
| 72 RTC_DCHECK(provider != nullptr); |
71 track_->RegisterObserver(this); | 73 track_->RegisterObserver(this); |
72 track_->AddSink(sink_adapter_.get()); | 74 track_->AddSink(sink_adapter_.get()); |
73 } | 75 } |
74 | 76 |
75 AudioRtpSender::AudioRtpSender(cricket::VoiceChannel* channel, | 77 AudioRtpSender::AudioRtpSender(AudioProviderInterface* provider, |
76 StatsCollector* stats) | 78 StatsCollector* stats) |
77 : id_(rtc::CreateRandomUuid()), | 79 : id_(rtc::CreateRandomUuid()), |
78 stream_id_(rtc::CreateRandomUuid()), | 80 stream_id_(rtc::CreateRandomUuid()), |
79 channel_(channel), | 81 provider_(provider), |
80 stats_(stats), | 82 stats_(stats), |
81 sink_adapter_(new LocalAudioSinkAdapter()) {} | 83 sink_adapter_(new LocalAudioSinkAdapter()) {} |
82 | 84 |
83 AudioRtpSender::~AudioRtpSender() { | 85 AudioRtpSender::~AudioRtpSender() { |
84 Stop(); | 86 Stop(); |
85 } | 87 } |
86 | 88 |
87 void AudioRtpSender::OnChanged() { | 89 void AudioRtpSender::OnChanged() { |
88 TRACE_EVENT0("webrtc", "AudioRtpSender::OnChanged"); | 90 TRACE_EVENT0("webrtc", "AudioRtpSender::OnChanged"); |
89 RTC_DCHECK(!stopped_); | 91 RTC_DCHECK(!stopped_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // Keep a reference to the old track to keep it alive until we call | 125 // Keep a reference to the old track to keep it alive until we call |
124 // SetAudioSend. | 126 // SetAudioSend. |
125 rtc::scoped_refptr<AudioTrackInterface> old_track = track_; | 127 rtc::scoped_refptr<AudioTrackInterface> old_track = track_; |
126 track_ = audio_track; | 128 track_ = audio_track; |
127 if (track_) { | 129 if (track_) { |
128 cached_track_enabled_ = track_->enabled(); | 130 cached_track_enabled_ = track_->enabled(); |
129 track_->RegisterObserver(this); | 131 track_->RegisterObserver(this); |
130 track_->AddSink(sink_adapter_.get()); | 132 track_->AddSink(sink_adapter_.get()); |
131 } | 133 } |
132 | 134 |
133 // Update audio channel. | 135 // Update audio provider. |
134 if (can_send_track()) { | 136 if (can_send_track()) { |
135 SetAudioSend(); | 137 SetAudioSend(); |
136 if (stats_) { | 138 if (stats_) { |
137 stats_->AddLocalAudioTrack(track_.get(), ssrc_); | 139 stats_->AddLocalAudioTrack(track_.get(), ssrc_); |
138 } | 140 } |
139 } else if (prev_can_send_track) { | 141 } else if (prev_can_send_track) { |
140 ClearAudioSend(); | 142 cricket::AudioOptions options; |
| 143 provider_->SetAudioSend(ssrc_, false, options, nullptr); |
141 } | 144 } |
142 return true; | 145 return true; |
143 } | 146 } |
144 | 147 |
145 RtpParameters AudioRtpSender::GetParameters() const { | 148 RtpParameters AudioRtpSender::GetParameters() const { |
146 if (!channel_ || stopped_) { | 149 return provider_->GetAudioRtpSendParameters(ssrc_); |
147 return RtpParameters(); | |
148 } | |
149 return channel_->GetRtpSendParameters(ssrc_); | |
150 } | 150 } |
151 | 151 |
152 bool AudioRtpSender::SetParameters(const RtpParameters& parameters) { | 152 bool AudioRtpSender::SetParameters(const RtpParameters& parameters) { |
153 TRACE_EVENT0("webrtc", "AudioRtpSender::SetParameters"); | 153 TRACE_EVENT0("webrtc", "AudioRtpSender::SetParameters"); |
154 if (!channel_ || stopped_) { | 154 return provider_->SetAudioRtpSendParameters(ssrc_, parameters); |
155 return false; | |
156 } | |
157 return channel_->SetRtpSendParameters(ssrc_, parameters); | |
158 } | 155 } |
159 | 156 |
160 void AudioRtpSender::SetSsrc(uint32_t ssrc) { | 157 void AudioRtpSender::SetSsrc(uint32_t ssrc) { |
161 TRACE_EVENT0("webrtc", "AudioRtpSender::SetSsrc"); | 158 TRACE_EVENT0("webrtc", "AudioRtpSender::SetSsrc"); |
162 if (stopped_ || ssrc == ssrc_) { | 159 if (stopped_ || ssrc == ssrc_) { |
163 return; | 160 return; |
164 } | 161 } |
165 // If we are already sending with a particular SSRC, stop sending. | 162 // If we are already sending with a particular SSRC, stop sending. |
166 if (can_send_track()) { | 163 if (can_send_track()) { |
167 ClearAudioSend(); | 164 cricket::AudioOptions options; |
| 165 provider_->SetAudioSend(ssrc_, false, options, nullptr); |
168 if (stats_) { | 166 if (stats_) { |
169 stats_->RemoveLocalAudioTrack(track_.get(), ssrc_); | 167 stats_->RemoveLocalAudioTrack(track_.get(), ssrc_); |
170 } | 168 } |
171 } | 169 } |
172 ssrc_ = ssrc; | 170 ssrc_ = ssrc; |
173 if (can_send_track()) { | 171 if (can_send_track()) { |
174 SetAudioSend(); | 172 SetAudioSend(); |
175 if (stats_) { | 173 if (stats_) { |
176 stats_->AddLocalAudioTrack(track_.get(), ssrc_); | 174 stats_->AddLocalAudioTrack(track_.get(), ssrc_); |
177 } | 175 } |
178 } | 176 } |
179 } | 177 } |
180 | 178 |
181 void AudioRtpSender::Stop() { | 179 void AudioRtpSender::Stop() { |
182 TRACE_EVENT0("webrtc", "AudioRtpSender::Stop"); | 180 TRACE_EVENT0("webrtc", "AudioRtpSender::Stop"); |
183 // TODO(deadbeef): Need to do more here to fully stop sending packets. | 181 // TODO(deadbeef): Need to do more here to fully stop sending packets. |
184 if (stopped_) { | 182 if (stopped_) { |
185 return; | 183 return; |
186 } | 184 } |
187 if (track_) { | 185 if (track_) { |
188 track_->RemoveSink(sink_adapter_.get()); | 186 track_->RemoveSink(sink_adapter_.get()); |
189 track_->UnregisterObserver(this); | 187 track_->UnregisterObserver(this); |
190 } | 188 } |
191 if (can_send_track()) { | 189 if (can_send_track()) { |
192 ClearAudioSend(); | 190 cricket::AudioOptions options; |
| 191 provider_->SetAudioSend(ssrc_, false, options, nullptr); |
193 if (stats_) { | 192 if (stats_) { |
194 stats_->RemoveLocalAudioTrack(track_.get(), ssrc_); | 193 stats_->RemoveLocalAudioTrack(track_.get(), ssrc_); |
195 } | 194 } |
196 } | 195 } |
197 stopped_ = true; | 196 stopped_ = true; |
198 } | 197 } |
199 | 198 |
200 void AudioRtpSender::SetAudioSend() { | 199 void AudioRtpSender::SetAudioSend() { |
201 RTC_DCHECK(!stopped_ && can_send_track()); | 200 RTC_DCHECK(!stopped_ && can_send_track()); |
202 if (!channel_) { | |
203 LOG(LS_ERROR) << "SetAudioSend: No audio channel exists."; | |
204 return; | |
205 } | |
206 cricket::AudioOptions options; | 201 cricket::AudioOptions options; |
207 #if !defined(WEBRTC_CHROMIUM_BUILD) | 202 #if !defined(WEBRTC_CHROMIUM_BUILD) |
208 // TODO(tommi): Remove this hack when we move CreateAudioSource out of | 203 // TODO(tommi): Remove this hack when we move CreateAudioSource out of |
209 // PeerConnection. This is a bit of a strange way to apply local audio | 204 // PeerConnection. This is a bit of a strange way to apply local audio |
210 // options since it is also applied to all streams/channels, local or remote. | 205 // options since it is also applied to all streams/channels, local or remote. |
211 if (track_->enabled() && track_->GetSource() && | 206 if (track_->enabled() && track_->GetSource() && |
212 !track_->GetSource()->remote()) { | 207 !track_->GetSource()->remote()) { |
213 // TODO(xians): Remove this static_cast since we should be able to connect | 208 // TODO(xians): Remove this static_cast since we should be able to connect |
214 // a remote audio track to a peer connection. | 209 // a remote audio track to a peer connection. |
215 options = static_cast<LocalAudioSource*>(track_->GetSource())->options(); | 210 options = static_cast<LocalAudioSource*>(track_->GetSource())->options(); |
216 } | 211 } |
217 #endif | 212 #endif |
218 | 213 |
219 cricket::AudioSource* source = sink_adapter_.get(); | 214 cricket::AudioSource* source = sink_adapter_.get(); |
220 RTC_DCHECK(source != nullptr); | 215 ASSERT(source != nullptr); |
221 if (!channel_->SetAudioSend(ssrc_, track_->enabled(), &options, source)) { | 216 provider_->SetAudioSend(ssrc_, track_->enabled(), options, source); |
222 LOG(LS_ERROR) << "SetAudioSend: ssrc is incorrect: " << ssrc_; | |
223 } | |
224 } | |
225 | |
226 void AudioRtpSender::ClearAudioSend() { | |
227 RTC_DCHECK(ssrc_ != 0); | |
228 RTC_DCHECK(!stopped_); | |
229 if (!channel_) { | |
230 LOG(LS_WARNING) << "ClearAudioSend: No audio channel exists."; | |
231 return; | |
232 } | |
233 cricket::AudioOptions options; | |
234 if (!channel_->SetAudioSend(ssrc_, false, &options, nullptr)) { | |
235 LOG(LS_WARNING) << "ClearAudioSend: ssrc is incorrect: " << ssrc_; | |
236 } | |
237 } | 217 } |
238 | 218 |
239 VideoRtpSender::VideoRtpSender(VideoTrackInterface* track, | 219 VideoRtpSender::VideoRtpSender(VideoTrackInterface* track, |
240 const std::string& stream_id, | 220 const std::string& stream_id, |
241 cricket::VideoChannel* channel) | 221 VideoProviderInterface* provider) |
242 : id_(track->id()), | 222 : id_(track->id()), |
243 stream_id_(stream_id), | 223 stream_id_(stream_id), |
244 channel_(channel), | 224 provider_(provider), |
245 track_(track), | 225 track_(track), |
246 cached_track_enabled_(track->enabled()) { | 226 cached_track_enabled_(track->enabled()) { |
| 227 RTC_DCHECK(provider != nullptr); |
247 track_->RegisterObserver(this); | 228 track_->RegisterObserver(this); |
248 } | 229 } |
249 | 230 |
250 VideoRtpSender::VideoRtpSender(VideoTrackInterface* track, | 231 VideoRtpSender::VideoRtpSender(VideoTrackInterface* track, |
251 cricket::VideoChannel* channel) | 232 VideoProviderInterface* provider) |
252 : id_(track->id()), | 233 : id_(track->id()), |
253 stream_id_(rtc::CreateRandomUuid()), | 234 stream_id_(rtc::CreateRandomUuid()), |
254 channel_(channel), | 235 provider_(provider), |
255 track_(track), | 236 track_(track), |
256 cached_track_enabled_(track->enabled()) { | 237 cached_track_enabled_(track->enabled()) { |
| 238 RTC_DCHECK(provider != nullptr); |
257 track_->RegisterObserver(this); | 239 track_->RegisterObserver(this); |
258 } | 240 } |
259 | 241 |
260 VideoRtpSender::VideoRtpSender(cricket::VideoChannel* channel) | 242 VideoRtpSender::VideoRtpSender(VideoProviderInterface* provider) |
261 : id_(rtc::CreateRandomUuid()), | 243 : id_(rtc::CreateRandomUuid()), |
262 stream_id_(rtc::CreateRandomUuid()), | 244 stream_id_(rtc::CreateRandomUuid()), |
263 channel_(channel) {} | 245 provider_(provider) {} |
264 | 246 |
265 VideoRtpSender::~VideoRtpSender() { | 247 VideoRtpSender::~VideoRtpSender() { |
266 Stop(); | 248 Stop(); |
267 } | 249 } |
268 | 250 |
269 void VideoRtpSender::OnChanged() { | 251 void VideoRtpSender::OnChanged() { |
270 TRACE_EVENT0("webrtc", "VideoRtpSender::OnChanged"); | 252 TRACE_EVENT0("webrtc", "VideoRtpSender::OnChanged"); |
271 RTC_DCHECK(!stopped_); | 253 RTC_DCHECK(!stopped_); |
272 if (cached_track_enabled_ != track_->enabled()) { | 254 if (cached_track_enabled_ != track_->enabled()) { |
273 cached_track_enabled_ = track_->enabled(); | 255 cached_track_enabled_ = track_->enabled(); |
(...skipping 25 matching lines...) Expand all Loading... |
299 bool prev_can_send_track = can_send_track(); | 281 bool prev_can_send_track = can_send_track(); |
300 // Keep a reference to the old track to keep it alive until we call | 282 // Keep a reference to the old track to keep it alive until we call |
301 // SetVideoSend. | 283 // SetVideoSend. |
302 rtc::scoped_refptr<VideoTrackInterface> old_track = track_; | 284 rtc::scoped_refptr<VideoTrackInterface> old_track = track_; |
303 track_ = video_track; | 285 track_ = video_track; |
304 if (track_) { | 286 if (track_) { |
305 cached_track_enabled_ = track_->enabled(); | 287 cached_track_enabled_ = track_->enabled(); |
306 track_->RegisterObserver(this); | 288 track_->RegisterObserver(this); |
307 } | 289 } |
308 | 290 |
309 // Update video channel. | 291 // Update video provider. |
310 if (can_send_track()) { | 292 if (can_send_track()) { |
311 SetVideoSend(); | 293 SetVideoSend(); |
312 } else if (prev_can_send_track) { | 294 } else if (prev_can_send_track) { |
313 ClearVideoSend(); | 295 ClearVideoSend(); |
314 } | 296 } |
315 return true; | 297 return true; |
316 } | 298 } |
317 | 299 |
318 RtpParameters VideoRtpSender::GetParameters() const { | 300 RtpParameters VideoRtpSender::GetParameters() const { |
319 if (!channel_ || stopped_) { | 301 return provider_->GetVideoRtpSendParameters(ssrc_); |
320 return RtpParameters(); | |
321 } | |
322 return channel_->GetRtpSendParameters(ssrc_); | |
323 } | 302 } |
324 | 303 |
325 bool VideoRtpSender::SetParameters(const RtpParameters& parameters) { | 304 bool VideoRtpSender::SetParameters(const RtpParameters& parameters) { |
326 TRACE_EVENT0("webrtc", "VideoRtpSender::SetParameters"); | 305 TRACE_EVENT0("webrtc", "VideoRtpSender::SetParameters"); |
327 if (!channel_ || stopped_) { | 306 return provider_->SetVideoRtpSendParameters(ssrc_, parameters); |
328 return false; | |
329 } | |
330 return channel_->SetRtpSendParameters(ssrc_, parameters); | |
331 } | 307 } |
332 | 308 |
333 void VideoRtpSender::SetSsrc(uint32_t ssrc) { | 309 void VideoRtpSender::SetSsrc(uint32_t ssrc) { |
334 TRACE_EVENT0("webrtc", "VideoRtpSender::SetSsrc"); | 310 TRACE_EVENT0("webrtc", "VideoRtpSender::SetSsrc"); |
335 if (stopped_ || ssrc == ssrc_) { | 311 if (stopped_ || ssrc == ssrc_) { |
336 return; | 312 return; |
337 } | 313 } |
338 // If we are already sending with a particular SSRC, stop sending. | 314 // If we are already sending with a particular SSRC, stop sending. |
339 if (can_send_track()) { | 315 if (can_send_track()) { |
340 ClearVideoSend(); | 316 ClearVideoSend(); |
(...skipping 14 matching lines...) Expand all Loading... |
355 track_->UnregisterObserver(this); | 331 track_->UnregisterObserver(this); |
356 } | 332 } |
357 if (can_send_track()) { | 333 if (can_send_track()) { |
358 ClearVideoSend(); | 334 ClearVideoSend(); |
359 } | 335 } |
360 stopped_ = true; | 336 stopped_ = true; |
361 } | 337 } |
362 | 338 |
363 void VideoRtpSender::SetVideoSend() { | 339 void VideoRtpSender::SetVideoSend() { |
364 RTC_DCHECK(!stopped_ && can_send_track()); | 340 RTC_DCHECK(!stopped_ && can_send_track()); |
365 if (!channel_) { | |
366 LOG(LS_ERROR) << "SetVideoSend: No video channel exists."; | |
367 return; | |
368 } | |
369 cricket::VideoOptions options; | 341 cricket::VideoOptions options; |
370 VideoTrackSourceInterface* source = track_->GetSource(); | 342 VideoTrackSourceInterface* source = track_->GetSource(); |
371 if (source) { | 343 if (source) { |
372 options.is_screencast = rtc::Optional<bool>(source->is_screencast()); | 344 options.is_screencast = rtc::Optional<bool>(source->is_screencast()); |
373 options.video_noise_reduction = source->needs_denoising(); | 345 options.video_noise_reduction = source->needs_denoising(); |
374 } | 346 } |
375 RTC_DCHECK( | 347 provider_->SetVideoSend(ssrc_, track_->enabled(), &options, track_); |
376 channel_->SetVideoSend(ssrc_, track_->enabled(), &options, track_)); | |
377 } | 348 } |
378 | 349 |
379 void VideoRtpSender::ClearVideoSend() { | 350 void VideoRtpSender::ClearVideoSend() { |
380 RTC_DCHECK(ssrc_ != 0); | 351 RTC_DCHECK(ssrc_ != 0); |
381 RTC_DCHECK(!stopped_); | 352 RTC_DCHECK(provider_ != nullptr); |
382 if (!channel_) { | 353 provider_->SetVideoSend(ssrc_, false, nullptr, nullptr); |
383 LOG(LS_WARNING) << "SetVideoSend: No video channel exists."; | |
384 return; | |
385 } | |
386 // Allow SetVideoSend to fail since |enable| is false and |source| is null. | |
387 // This the normal case when the underlying media channel has already been | |
388 // deleted. | |
389 channel_->SetVideoSend(ssrc_, false, nullptr, nullptr); | |
390 } | 354 } |
391 | 355 |
392 } // namespace webrtc | 356 } // namespace webrtc |
OLD | NEW |