OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
7 #include "content/renderer/media/media_stream_audio_source.h" | 7 #include "content/renderer/media/media_stream_audio_source.h" |
8 #include "content/renderer/media/mock_media_constraint_factory.h" | 8 #include "content/renderer/media/mock_media_constraint_factory.h" |
9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
10 #include "content/renderer/media/webrtc_audio_capturer.h" | 10 #include "content/renderer/media/webrtc_audio_capturer.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // get data callback when the track is connected to the capturer but not when | 201 // get data callback when the track is connected to the capturer but not when |
202 // the track is disconnected from the capturer. | 202 // the track is disconnected from the capturer. |
203 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { | 203 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { |
204 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 204 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
205 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 205 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
206 scoped_ptr<WebRtcLocalAudioTrack> track( | 206 scoped_ptr<WebRtcLocalAudioTrack> track( |
207 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 207 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); |
208 track->Start(); | 208 track->Start(); |
209 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 209 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
210 | 210 |
211 // Connect a number of network channels to the audio track. | |
212 static const int kNumberOfNetworkChannels = 4; | |
213 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { | |
214 static_cast<webrtc::AudioTrackInterface*>( | |
215 adapter.get())->GetRenderer()->AddChannel(i); | |
216 } | |
217 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 211 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
218 base::WaitableEvent event(false, false); | 212 base::WaitableEvent event(false, false); |
219 EXPECT_CALL(*sink, FormatIsSet()); | 213 EXPECT_CALL(*sink, FormatIsSet()); |
220 EXPECT_CALL(*sink, | 214 EXPECT_CALL(*sink, |
221 CaptureData(kNumberOfNetworkChannels, | 215 CaptureData(0, |
222 0, | 216 0, |
223 0, | 217 0, |
224 _, | 218 _, |
225 false)).Times(AtLeast(1)) | 219 false)).Times(AtLeast(1)) |
226 .WillRepeatedly(SignalEvent(&event)); | 220 .WillRepeatedly(SignalEvent(&event)); |
227 track->AddSink(sink.get()); | 221 track->AddSink(sink.get()); |
228 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 222 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
229 track->RemoveSink(sink.get()); | 223 track->RemoveSink(sink.get()); |
230 | 224 |
231 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 225 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
232 capturer_->Stop(); | 226 capturer_->Stop(); |
233 } | 227 } |
234 | 228 |
235 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the | 229 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the |
236 // audio track on the fly. When the audio track is disabled, there is no data | 230 // audio track on the fly. When the audio track is disabled, there is no data |
237 // callback to the sink; when the audio track is enabled, there comes data | 231 // callback to the sink; when the audio track is enabled, there comes data |
238 // callback. | 232 // callback. |
239 // TODO(xians): Enable this test after resolving the racing issue that TSAN | 233 // TODO(xians): Enable this test after resolving the racing issue that TSAN |
240 // reports on MediaStreamTrack::enabled(); | 234 // reports on MediaStreamTrack::enabled(); |
241 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { | 235 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { |
242 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 236 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
243 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 237 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
244 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 238 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
245 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 239 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
246 scoped_ptr<WebRtcLocalAudioTrack> track( | 240 scoped_ptr<WebRtcLocalAudioTrack> track( |
247 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 241 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); |
248 track->Start(); | 242 track->Start(); |
249 static_cast<webrtc::AudioTrackInterface*>( | |
250 adapter.get())->GetRenderer()->AddChannel(0); | |
251 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 243 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
252 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); | 244 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); |
253 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 245 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
254 const media::AudioParameters params = capturer_->source_audio_parameters(); | 246 const media::AudioParameters params = capturer_->source_audio_parameters(); |
255 base::WaitableEvent event(false, false); | 247 base::WaitableEvent event(false, false); |
256 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 248 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
257 EXPECT_CALL(*sink, | 249 EXPECT_CALL(*sink, |
258 CaptureData(1, 0, 0, _, false)).Times(0); | 250 CaptureData(0, 0, 0, _, false)).Times(0); |
259 EXPECT_EQ(sink->audio_params().frames_per_buffer(), | 251 EXPECT_EQ(sink->audio_params().frames_per_buffer(), |
260 params.sample_rate() / 100); | 252 params.sample_rate() / 100); |
261 track->AddSink(sink.get()); | 253 track->AddSink(sink.get()); |
262 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); | 254 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); |
263 | 255 |
264 event.Reset(); | 256 event.Reset(); |
265 EXPECT_CALL(*sink, | 257 EXPECT_CALL(*sink, CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) |
266 CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) | |
267 .WillRepeatedly(SignalEvent(&event)); | 258 .WillRepeatedly(SignalEvent(&event)); |
268 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); | 259 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); |
269 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 260 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
270 track->RemoveSink(sink.get()); | 261 track->RemoveSink(sink.get()); |
271 | 262 |
272 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 263 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
273 capturer_->Stop(); | 264 capturer_->Stop(); |
274 track.reset(); | 265 track.reset(); |
275 } | 266 } |
276 | 267 |
277 // Create multiple audio tracks and enable/disable them, verify that the audio | 268 // Create multiple audio tracks and enable/disable them, verify that the audio |
278 // callbacks appear/disappear. | 269 // callbacks appear/disappear. |
279 // Flaky due to a data race, see http://crbug.com/295418 | 270 // Flaky due to a data race, see http://crbug.com/295418 |
280 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { | 271 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { |
281 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 272 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
282 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 273 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
283 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 274 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
284 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 275 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); |
285 track_1->Start(); | 276 track_1->Start(); |
286 static_cast<webrtc::AudioTrackInterface*>( | |
287 adapter_1.get())->GetRenderer()->AddChannel(0); | |
288 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); | 277 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); |
289 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 278 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
290 const media::AudioParameters params = capturer_->source_audio_parameters(); | 279 const media::AudioParameters params = capturer_->source_audio_parameters(); |
291 base::WaitableEvent event_1(false, false); | 280 base::WaitableEvent event_1(false, false); |
292 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); | 281 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); |
293 EXPECT_CALL(*sink_1, | 282 EXPECT_CALL(*sink_1, |
294 CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) | 283 CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) |
295 .WillRepeatedly(SignalEvent(&event_1)); | 284 .WillRepeatedly(SignalEvent(&event_1)); |
296 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), | 285 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
297 params.sample_rate() / 100); | 286 params.sample_rate() / 100); |
298 track_1->AddSink(sink_1.get()); | 287 track_1->AddSink(sink_1.get()); |
299 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 288 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
300 | 289 |
301 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 290 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
302 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 291 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
303 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 292 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
304 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); | 293 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); |
305 track_2->Start(); | 294 track_2->Start(); |
306 static_cast<webrtc::AudioTrackInterface*>( | |
307 adapter_2.get())->GetRenderer()->AddChannel(1); | |
308 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); | 295 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); |
309 | 296 |
310 // Verify both |sink_1| and |sink_2| get data. | 297 // Verify both |sink_1| and |sink_2| get data. |
311 event_1.Reset(); | 298 event_1.Reset(); |
312 base::WaitableEvent event_2(false, false); | 299 base::WaitableEvent event_2(false, false); |
313 | 300 |
314 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 301 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
315 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); | 302 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); |
316 EXPECT_CALL(*sink_1, CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) | 303 EXPECT_CALL(*sink_1, CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) |
317 .WillRepeatedly(SignalEvent(&event_1)); | 304 .WillRepeatedly(SignalEvent(&event_1)); |
318 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), | 305 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
319 params.sample_rate() / 100); | 306 params.sample_rate() / 100); |
320 EXPECT_CALL(*sink_2, CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) | 307 EXPECT_CALL(*sink_2, CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) |
321 .WillRepeatedly(SignalEvent(&event_2)); | 308 .WillRepeatedly(SignalEvent(&event_2)); |
322 EXPECT_EQ(sink_2->audio_params().frames_per_buffer(), | 309 EXPECT_EQ(sink_2->audio_params().frames_per_buffer(), |
323 params.sample_rate() / 100); | 310 params.sample_rate() / 100); |
324 track_2->AddSink(sink_2.get()); | 311 track_2->AddSink(sink_2.get()); |
325 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 312 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
326 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); | 313 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); |
327 | 314 |
328 track_1->RemoveSink(sink_1.get()); | 315 track_1->RemoveSink(sink_1.get()); |
329 track_1->Stop(); | 316 track_1->Stop(); |
330 track_1.reset(); | 317 track_1.reset(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 362 } |
376 | 363 |
377 // Start/Stop tracks and verify the capturer is correctly starting/stopping | 364 // Start/Stop tracks and verify the capturer is correctly starting/stopping |
378 // its source. | 365 // its source. |
379 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { | 366 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { |
380 base::WaitableEvent event(false, false); | 367 base::WaitableEvent event(false, false); |
381 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 368 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
382 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 369 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
383 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 370 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
384 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 371 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); |
385 static_cast<webrtc::AudioTrackInterface*>( | |
386 adapter_1.get())->GetRenderer()->AddChannel(0); | |
387 track_1->Start(); | 372 track_1->Start(); |
388 | 373 |
389 // Verify the data flow by connecting the sink to |track_1|. | 374 // Verify the data flow by connecting the sink to |track_1|. |
390 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 375 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
391 event.Reset(); | 376 event.Reset(); |
392 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); | 377 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); |
393 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) | 378 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) |
394 .Times(AnyNumber()).WillRepeatedly(Return()); | 379 .Times(AnyNumber()).WillRepeatedly(Return()); |
395 track_1->AddSink(sink.get()); | 380 track_1->AddSink(sink.get()); |
396 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 381 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
397 | 382 |
398 // Start the second audio track will not start the |capturer_source_| | 383 // Start the second audio track will not start the |capturer_source_| |
399 // since it has been started. | 384 // since it has been started. |
400 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); | 385 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); |
401 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 386 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
402 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 387 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
403 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 388 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
404 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); | 389 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); |
405 track_2->Start(); | 390 track_2->Start(); |
406 static_cast<webrtc::AudioTrackInterface*>( | |
407 adapter_2.get())->GetRenderer()->AddChannel(1); | |
408 | 391 |
409 // Stop the capturer will clear up the track lists in the capturer. | 392 // Stop the capturer will clear up the track lists in the capturer. |
410 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 393 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
411 capturer_->Stop(); | 394 capturer_->Stop(); |
412 | 395 |
413 // Adding a new track to the capturer. | 396 // Adding a new track to the capturer. |
414 track_2->AddSink(sink.get()); | 397 track_2->AddSink(sink.get()); |
415 EXPECT_CALL(*sink, FormatIsSet()).Times(0); | 398 EXPECT_CALL(*sink, FormatIsSet()).Times(0); |
416 | 399 |
417 // Stop the capturer again will not trigger stopping the source of the | 400 // Stop the capturer again will not trigger stopping the source of the |
418 // capturer again.. | 401 // capturer again.. |
419 event.Reset(); | 402 event.Reset(); |
420 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); | 403 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); |
421 capturer_->Stop(); | 404 capturer_->Stop(); |
422 } | 405 } |
423 | 406 |
424 // Create a new capturer with new source, connect it to a new audio track. | 407 // Create a new capturer with new source, connect it to a new audio track. |
425 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { | 408 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { |
426 // Setup the first audio track and start it. | 409 // Setup the first audio track and start it. |
427 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 410 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
428 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 411 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
429 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 412 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
430 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 413 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); |
431 track_1->Start(); | 414 track_1->Start(); |
432 | 415 |
433 // Connect a number of network channels to the |track_1|. | |
434 static const int kNumberOfNetworkChannelsForTrack1 = 2; | |
435 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { | |
436 static_cast<webrtc::AudioTrackInterface*>( | |
437 adapter_1.get())->GetRenderer()->AddChannel(i); | |
438 } | |
439 // Verify the data flow by connecting the |sink_1| to |track_1|. | 416 // Verify the data flow by connecting the |sink_1| to |track_1|. |
440 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 417 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
441 EXPECT_CALL(*sink_1.get(), | 418 EXPECT_CALL(*sink_1.get(), CaptureData(0, 0, 0, _, false)) |
442 CaptureData(kNumberOfNetworkChannelsForTrack1, | |
443 0, 0, _, false)) | |
444 .Times(AnyNumber()).WillRepeatedly(Return()); | 419 .Times(AnyNumber()).WillRepeatedly(Return()); |
445 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); | 420 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); |
446 track_1->AddSink(sink_1.get()); | 421 track_1->AddSink(sink_1.get()); |
447 | 422 |
448 // Create a new capturer with new source with different audio format. | 423 // Create a new capturer with new source with different audio format. |
449 MockMediaConstraintFactory constraint_factory; | 424 MockMediaConstraintFactory constraint_factory; |
450 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, | 425 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, |
451 std::string(), std::string()); | 426 std::string(), std::string()); |
452 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 427 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
453 WebRtcAudioCapturer::CreateCapturer( | 428 WebRtcAudioCapturer::CreateCapturer( |
(...skipping 10 matching lines...) Expand all Loading... |
464 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); | 439 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); |
465 new_capturer->SetCapturerSourceForTesting(new_source, new_param); | 440 new_capturer->SetCapturerSourceForTesting(new_source, new_param); |
466 | 441 |
467 // Setup the second audio track, connect it to the new capturer and start it. | 442 // Setup the second audio track, connect it to the new capturer and start it. |
468 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 443 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
469 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 444 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
470 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 445 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
471 new WebRtcLocalAudioTrack(adapter_2, new_capturer, NULL)); | 446 new WebRtcLocalAudioTrack(adapter_2, new_capturer, NULL)); |
472 track_2->Start(); | 447 track_2->Start(); |
473 | 448 |
474 // Connect a number of network channels to the |track_2|. | |
475 static const int kNumberOfNetworkChannelsForTrack2 = 3; | |
476 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { | |
477 static_cast<webrtc::AudioTrackInterface*>( | |
478 adapter_2.get())->GetRenderer()->AddChannel(i); | |
479 } | |
480 // Verify the data flow by connecting the |sink_2| to |track_2|. | 449 // Verify the data flow by connecting the |sink_2| to |track_2|. |
481 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 450 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
482 base::WaitableEvent event(false, false); | 451 base::WaitableEvent event(false, false); |
483 EXPECT_CALL(*sink_2, | 452 EXPECT_CALL(*sink_2, CaptureData(0, 0, 0, _, false)) |
484 CaptureData(kNumberOfNetworkChannelsForTrack2, 0, 0, _, false)) | |
485 .Times(AnyNumber()).WillRepeatedly(Return()); | 453 .Times(AnyNumber()).WillRepeatedly(Return()); |
486 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); | 454 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); |
487 track_2->AddSink(sink_2.get()); | 455 track_2->AddSink(sink_2.get()); |
488 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 456 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
489 | 457 |
490 // Stopping the new source will stop the second track. | 458 // Stopping the new source will stop the second track. |
491 event.Reset(); | 459 event.Reset(); |
492 EXPECT_CALL(*new_source.get(), OnStop()) | 460 EXPECT_CALL(*new_source.get(), OnStop()) |
493 .Times(1).WillOnce(SignalEvent(&event)); | 461 .Times(1).WillOnce(SignalEvent(&event)); |
494 new_capturer->Stop(); | 462 new_capturer->Stop(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 // Stopping the new source will stop the second track. | 520 // Stopping the new source will stop the second track. |
553 EXPECT_CALL(*source, OnStop()).Times(1); | 521 EXPECT_CALL(*source, OnStop()).Times(1); |
554 capturer->Stop(); | 522 capturer->Stop(); |
555 | 523 |
556 // Even though this test don't use |capturer_source_| it will be stopped | 524 // Even though this test don't use |capturer_source_| it will be stopped |
557 // during teardown of the test harness. | 525 // during teardown of the test harness. |
558 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 526 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
559 } | 527 } |
560 | 528 |
561 } // namespace content | 529 } // namespace content |
OLD | NEW |