| 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/mock_media_constraint_factory.h" | 7 #include "content/renderer/media/mock_media_constraint_factory.h" |
| 8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
| 9 #include "content/renderer/media/webrtc_audio_capturer.h" | 9 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 10 #include "content/renderer/media/webrtc_audio_device_impl.h" | 10 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 11 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | |
| 12 #include "content/renderer/media/webrtc_local_audio_track.h" | 11 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 13 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
| 14 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
| 15 #include "media/base/audio_capturer_source.h" | 14 #include "media/base/audio_capturer_source.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 17 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 19 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 18 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 20 | 19 |
| 21 using ::testing::_; | 20 using ::testing::_; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // connect/disconnect the sink to the audio track on the fly, the sink should | 189 // connect/disconnect the sink to the audio track on the fly, the sink should |
| 191 // get data callback when the track is connected to the capturer but not when | 190 // get data callback when the track is connected to the capturer but not when |
| 192 // the track is disconnected from the capturer. | 191 // the track is disconnected from the capturer. |
| 193 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { | 192 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { |
| 194 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 193 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 195 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 194 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
| 196 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 195 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 197 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 196 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 198 scoped_ptr<WebRtcLocalAudioTrack> track( | 197 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 199 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 198 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); |
| 200 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 201 track->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 202 track->Start(); | 199 track->Start(); |
| 203 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 200 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
| 204 | 201 |
| 205 // Connect a number of network channels to the audio track. | 202 // Connect a number of network channels to the audio track. |
| 206 static const int kNumberOfNetworkChannels = 4; | 203 static const int kNumberOfNetworkChannels = 4; |
| 207 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { | 204 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { |
| 208 static_cast<webrtc::AudioTrackInterface*>( | 205 static_cast<webrtc::AudioTrackInterface*>( |
| 209 adapter.get())->GetRenderer()->AddChannel(i); | 206 adapter.get())->GetRenderer()->AddChannel(i); |
| 210 } | 207 } |
| 211 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 208 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 232 // callback. | 229 // callback. |
| 233 // TODO(xians): Enable this test after resolving the racing issue that TSAN | 230 // TODO(xians): Enable this test after resolving the racing issue that TSAN |
| 234 // reports on MediaStreamTrack::enabled(); | 231 // reports on MediaStreamTrack::enabled(); |
| 235 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { | 232 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { |
| 236 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 233 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 237 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 234 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
| 238 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 235 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 239 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 236 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 240 scoped_ptr<WebRtcLocalAudioTrack> track( | 237 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 241 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 238 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); |
| 242 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 243 track->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 244 track->Start(); | 239 track->Start(); |
| 245 static_cast<webrtc::AudioTrackInterface*>( | 240 static_cast<webrtc::AudioTrackInterface*>( |
| 246 adapter.get())->GetRenderer()->AddChannel(0); | 241 adapter.get())->GetRenderer()->AddChannel(0); |
| 247 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 242 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
| 248 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); | 243 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); |
| 249 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 244 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 250 const media::AudioParameters params = capturer_->source_audio_parameters(); | 245 const media::AudioParameters params = capturer_->source_audio_parameters(); |
| 251 base::WaitableEvent event(false, false); | 246 base::WaitableEvent event(false, false); |
| 252 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 247 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
| 253 EXPECT_CALL(*sink, | 248 EXPECT_CALL(*sink, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 273 // 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 |
| 274 // callbacks appear/disappear. | 269 // callbacks appear/disappear. |
| 275 // Flaky due to a data race, see http://crbug.com/295418 | 270 // Flaky due to a data race, see http://crbug.com/295418 |
| 276 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { | 271 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { |
| 277 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 272 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 278 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 273 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
| 279 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 274 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 280 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 275 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 281 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 276 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 282 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 277 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); |
| 283 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 284 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 285 track_1->Start(); | 278 track_1->Start(); |
| 286 static_cast<webrtc::AudioTrackInterface*>( | 279 static_cast<webrtc::AudioTrackInterface*>( |
| 287 adapter_1.get())->GetRenderer()->AddChannel(0); | 280 adapter_1.get())->GetRenderer()->AddChannel(0); |
| 288 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); | 281 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); |
| 289 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 282 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
| 290 const media::AudioParameters params = capturer_->source_audio_parameters(); | 283 const media::AudioParameters params = capturer_->source_audio_parameters(); |
| 291 base::WaitableEvent event_1(false, false); | 284 base::WaitableEvent event_1(false, false); |
| 292 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); | 285 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); |
| 293 EXPECT_CALL(*sink_1, | 286 EXPECT_CALL(*sink_1, |
| 294 CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) | 287 CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) |
| 295 .WillRepeatedly(SignalEvent(&event_1)); | 288 .WillRepeatedly(SignalEvent(&event_1)); |
| 296 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), | 289 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
| 297 params.sample_rate() / 100); | 290 params.sample_rate() / 100); |
| 298 track_1->AddSink(sink_1.get()); | 291 track_1->AddSink(sink_1.get()); |
| 299 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 292 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
| 300 | 293 |
| 301 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 294 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 302 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 295 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 303 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 296 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| 304 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); | 297 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); |
| 305 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 306 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 307 track_2->Start(); | 298 track_2->Start(); |
| 308 static_cast<webrtc::AudioTrackInterface*>( | 299 static_cast<webrtc::AudioTrackInterface*>( |
| 309 adapter_2.get())->GetRenderer()->AddChannel(1); | 300 adapter_2.get())->GetRenderer()->AddChannel(1); |
| 310 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); | 301 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); |
| 311 | 302 |
| 312 // Verify both |sink_1| and |sink_2| get data. | 303 // Verify both |sink_1| and |sink_2| get data. |
| 313 event_1.Reset(); | 304 event_1.Reset(); |
| 314 base::WaitableEvent event_2(false, false); | 305 base::WaitableEvent event_2(false, false); |
| 315 | 306 |
| 316 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 307 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 342 | 333 |
| 343 // Start one track and verify the capturer is correctly starting its source. | 334 // Start one track and verify the capturer is correctly starting its source. |
| 344 // And it should be fine to not to call Stop() explicitly. | 335 // And it should be fine to not to call Stop() explicitly. |
| 345 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { | 336 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { |
| 346 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 337 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 347 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 338 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
| 348 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 339 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 349 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 340 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 350 scoped_ptr<WebRtcLocalAudioTrack> track( | 341 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 351 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 342 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); |
| 352 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 353 track->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 354 track->Start(); | 343 track->Start(); |
| 355 | 344 |
| 356 // When the track goes away, it will automatically stop the | 345 // When the track goes away, it will automatically stop the |
| 357 // |capturer_source_|. | 346 // |capturer_source_|. |
| 358 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 347 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
| 359 capturer_->Stop(); | 348 capturer_->Stop(); |
| 360 track.reset(); | 349 track.reset(); |
| 361 } | 350 } |
| 362 | 351 |
| 363 // Start/Stop tracks and verify the capturer is correctly starting/stopping | 352 // Start/Stop tracks and verify the capturer is correctly starting/stopping |
| 364 // its source. | 353 // its source. |
| 365 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { | 354 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { |
| 366 // Starting the first audio track will start the |capturer_source_|. | 355 // Starting the first audio track will start the |capturer_source_|. |
| 367 base::WaitableEvent event(false, false); | 356 base::WaitableEvent event(false, false); |
| 368 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 357 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 369 EXPECT_CALL(*capturer_source_.get(), OnStart()).WillOnce(SignalEvent(&event)); | 358 EXPECT_CALL(*capturer_source_.get(), OnStart()).WillOnce(SignalEvent(&event)); |
| 370 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 359 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 371 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 360 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 372 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 361 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 373 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 362 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); |
| 374 static_cast<webrtc::AudioTrackInterface*>( | 363 static_cast<webrtc::AudioTrackInterface*>( |
| 375 adapter_1.get())->GetRenderer()->AddChannel(0); | 364 adapter_1.get())->GetRenderer()->AddChannel(0); |
| 376 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 377 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 378 track_1->Start(); | 365 track_1->Start(); |
| 379 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 366 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 380 | 367 |
| 381 // Verify the data flow by connecting the sink to |track_1|. | 368 // Verify the data flow by connecting the sink to |track_1|. |
| 382 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 369 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 383 event.Reset(); | 370 event.Reset(); |
| 384 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); | 371 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); |
| 385 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) | 372 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) |
| 386 .Times(AnyNumber()).WillRepeatedly(Return()); | 373 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 387 track_1->AddSink(sink.get()); | 374 track_1->AddSink(sink.get()); |
| 388 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 375 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 389 | 376 |
| 390 // Start the second audio track will not start the |capturer_source_| | 377 // Start the second audio track will not start the |capturer_source_| |
| 391 // since it has been started. | 378 // since it has been started. |
| 392 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); | 379 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); |
| 393 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 380 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 394 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 381 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 395 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 382 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| 396 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); | 383 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); |
| 397 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 398 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 399 track_2->Start(); | 384 track_2->Start(); |
| 400 static_cast<webrtc::AudioTrackInterface*>( | 385 static_cast<webrtc::AudioTrackInterface*>( |
| 401 adapter_2.get())->GetRenderer()->AddChannel(1); | 386 adapter_2.get())->GetRenderer()->AddChannel(1); |
| 402 | 387 |
| 403 // Stop the capturer will clear up the track lists in the capturer. | 388 // Stop the capturer will clear up the track lists in the capturer. |
| 404 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 389 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
| 405 capturer_->Stop(); | 390 capturer_->Stop(); |
| 406 | 391 |
| 407 // Adding a new track to the capturer. | 392 // Adding a new track to the capturer. |
| 408 track_2->AddSink(sink.get()); | 393 track_2->AddSink(sink.get()); |
| 409 EXPECT_CALL(*sink, FormatIsSet()).Times(0); | 394 EXPECT_CALL(*sink, FormatIsSet()).Times(0); |
| 410 | 395 |
| 411 // Stop the capturer again will not trigger stopping the source of the | 396 // Stop the capturer again will not trigger stopping the source of the |
| 412 // capturer again.. | 397 // capturer again.. |
| 413 event.Reset(); | 398 event.Reset(); |
| 414 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); | 399 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); |
| 415 capturer_->Stop(); | 400 capturer_->Stop(); |
| 416 } | 401 } |
| 417 | 402 |
| 418 // Create a new capturer with new source, connect it to a new audio track. | 403 // Create a new capturer with new source, connect it to a new audio track. |
| 419 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { | 404 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { |
| 420 // Setup the first audio track and start it. | 405 // Setup the first audio track and start it. |
| 421 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 406 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 422 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 407 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
| 423 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 408 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 424 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 409 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 425 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 410 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 426 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 411 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); |
| 427 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 428 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 429 track_1->Start(); | 412 track_1->Start(); |
| 430 | 413 |
| 431 // Connect a number of network channels to the |track_1|. | 414 // Connect a number of network channels to the |track_1|. |
| 432 static const int kNumberOfNetworkChannelsForTrack1 = 2; | 415 static const int kNumberOfNetworkChannelsForTrack1 = 2; |
| 433 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { | 416 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { |
| 434 static_cast<webrtc::AudioTrackInterface*>( | 417 static_cast<webrtc::AudioTrackInterface*>( |
| 435 adapter_1.get())->GetRenderer()->AddChannel(i); | 418 adapter_1.get())->GetRenderer()->AddChannel(i); |
| 436 } | 419 } |
| 437 // Verify the data flow by connecting the |sink_1| to |track_1|. | 420 // Verify the data flow by connecting the |sink_1| to |track_1|. |
| 438 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 421 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 457 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); | 440 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); |
| 458 new_capturer->SetCapturerSourceForTesting(new_source, new_param); | 441 new_capturer->SetCapturerSourceForTesting(new_source, new_param); |
| 459 | 442 |
| 460 // Setup the second audio track, connect it to the new capturer and start it. | 443 // Setup the second audio track, connect it to the new capturer and start it. |
| 461 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); | 444 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); |
| 462 EXPECT_CALL(*new_source.get(), OnStart()); | 445 EXPECT_CALL(*new_source.get(), OnStart()); |
| 463 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 446 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 464 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 447 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 465 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 448 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| 466 new WebRtcLocalAudioTrack(adapter_2, new_capturer, NULL)); | 449 new WebRtcLocalAudioTrack(adapter_2, new_capturer, NULL)); |
| 467 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 468 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | |
| 469 track_2->Start(); | 450 track_2->Start(); |
| 470 | 451 |
| 471 // Connect a number of network channels to the |track_2|. | 452 // Connect a number of network channels to the |track_2|. |
| 472 static const int kNumberOfNetworkChannelsForTrack2 = 3; | 453 static const int kNumberOfNetworkChannelsForTrack2 = 3; |
| 473 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { | 454 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { |
| 474 static_cast<webrtc::AudioTrackInterface*>( | 455 static_cast<webrtc::AudioTrackInterface*>( |
| 475 adapter_2.get())->GetRenderer()->AddChannel(i); | 456 adapter_2.get())->GetRenderer()->AddChannel(i); |
| 476 } | 457 } |
| 477 // Verify the data flow by connecting the |sink_2| to |track_2|. | 458 // Verify the data flow by connecting the |sink_2| to |track_2|. |
| 478 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 459 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); | 502 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); |
| 522 capturer->SetCapturerSourceForTesting(source, params); | 503 capturer->SetCapturerSourceForTesting(source, params); |
| 523 | 504 |
| 524 // Setup a audio track, connect it to the capturer and start it. | 505 // Setup a audio track, connect it to the capturer and start it. |
| 525 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); | 506 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); |
| 526 EXPECT_CALL(*source.get(), OnStart()); | 507 EXPECT_CALL(*source.get(), OnStart()); |
| 527 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 508 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 528 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 509 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 529 scoped_ptr<WebRtcLocalAudioTrack> track( | 510 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 530 new WebRtcLocalAudioTrack(adapter, capturer, NULL)); | 511 new WebRtcLocalAudioTrack(adapter, capturer, NULL)); |
| 531 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 532 track->audio_source_provider())->SetSinkParamsForTesting(params); | |
| 533 track->Start(); | 512 track->Start(); |
| 534 | 513 |
| 535 // Verify the data flow by connecting the |sink| to |track|. | 514 // Verify the data flow by connecting the |sink| to |track|. |
| 536 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 515 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 537 base::WaitableEvent event(false, false); | 516 base::WaitableEvent event(false, false); |
| 538 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 517 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
| 539 // Verify the sinks are getting the packets with an expecting buffer size. | 518 // Verify the sinks are getting the packets with an expecting buffer size. |
| 540 #if defined(OS_ANDROID) | 519 #if defined(OS_ANDROID) |
| 541 const int expected_buffer_size = params.sample_rate() / 100; | 520 const int expected_buffer_size = params.sample_rate() / 100; |
| 542 #else | 521 #else |
| 543 const int expected_buffer_size = params.frames_per_buffer(); | 522 const int expected_buffer_size = params.frames_per_buffer(); |
| 544 #endif | 523 #endif |
| 545 EXPECT_CALL(*sink, CaptureData( | 524 EXPECT_CALL(*sink, CaptureData( |
| 546 0, 0, 0, _, false)) | 525 0, 0, 0, _, false)) |
| 547 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); | 526 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
| 548 track->AddSink(sink.get()); | 527 track->AddSink(sink.get()); |
| 549 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 528 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 550 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); | 529 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); |
| 551 | 530 |
| 552 // Stopping the new source will stop the second track. | 531 // Stopping the new source will stop the second track. |
| 553 EXPECT_CALL(*source, OnStop()).Times(1); | 532 EXPECT_CALL(*source, OnStop()).Times(1); |
| 554 capturer->Stop(); | 533 capturer->Stop(); |
| 555 } | 534 } |
| 556 | 535 |
| 557 } // namespace content | 536 } // namespace content |
| OLD | NEW |