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