| 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/rtc_media_constraints.h" | 7 #include "content/renderer/media/rtc_media_constraints.h" |
| 8 #include "content/renderer/media/webrtc_audio_capturer.h" | 8 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 9 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | 9 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
| 10 #include "content/renderer/media/webrtc_local_audio_track.h" | 10 #include "content/renderer/media/webrtc_local_audio_track.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 } // namespace | 132 } // namespace |
| 133 | 133 |
| 134 class WebRtcLocalAudioTrackTest : public ::testing::Test { | 134 class WebRtcLocalAudioTrackTest : public ::testing::Test { |
| 135 protected: | 135 protected: |
| 136 virtual void SetUp() OVERRIDE { | 136 virtual void SetUp() OVERRIDE { |
| 137 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 137 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 138 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); | 138 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); |
| 139 capturer_ = WebRtcAudioCapturer::CreateCapturer(); | 139 capturer_ = WebRtcAudioCapturer::CreateCapturer(); |
| 140 WebRtcLocalAudioSourceProvider* source_provider = | |
| 141 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 142 capturer_->audio_source_provider()); | |
| 143 source_provider->SetSinkParamsForTesting(params_); | |
| 144 capturer_source_ = new MockCapturerSource(); | 140 capturer_source_ = new MockCapturerSource(); |
| 145 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), 0)) | 141 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), 0)) |
| 146 .WillOnce(Return()); | 142 .WillOnce(Return()); |
| 147 capturer_->SetCapturerSource(capturer_source_, | 143 capturer_->SetCapturerSource(capturer_source_, |
| 148 params_.channel_layout(), | 144 params_.channel_layout(), |
| 149 params_.sample_rate()); | 145 params_.sample_rate()); |
| 150 | 146 |
| 151 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(false)) | 147 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(false)) |
| 152 .WillOnce(Return()); | 148 .WillOnce(Return()); |
| 153 | 149 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 170 // Creates a capturer and audio track, fakes its audio thread, and | 166 // Creates a capturer and audio track, fakes its audio thread, and |
| 171 // connect/disconnect the sink to the audio track on the fly, the sink should | 167 // connect/disconnect the sink to the audio track on the fly, the sink should |
| 172 // get data callback when the track is connected to the capturer but not when | 168 // get data callback when the track is connected to the capturer but not when |
| 173 // the track is disconnected from the capturer. | 169 // the track is disconnected from the capturer. |
| 174 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { | 170 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { |
| 175 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); | 171 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); |
| 176 RTCMediaConstraints constraints; | 172 RTCMediaConstraints constraints; |
| 177 scoped_refptr<WebRtcLocalAudioTrack> track = | 173 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 178 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 174 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 179 &constraints); | 175 &constraints); |
| 176 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 177 track->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 180 track->Start(); | 178 track->Start(); |
| 181 EXPECT_TRUE(track->enabled()); | 179 EXPECT_TRUE(track->enabled()); |
| 182 | 180 |
| 183 // Connect a number of network channels to the audio track. | 181 // Connect a number of network channels to the audio track. |
| 184 static const int kNumberOfNetworkChannels = 4; | 182 static const int kNumberOfNetworkChannels = 4; |
| 185 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { | 183 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { |
| 186 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 184 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
| 187 GetRenderer()->AddChannel(i); | 185 GetRenderer()->AddChannel(i); |
| 188 } | 186 } |
| 189 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 187 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 216 // callback to the sink; when the audio track is enabled, there comes data | 214 // callback to the sink; when the audio track is enabled, there comes data |
| 217 // callback. | 215 // callback. |
| 218 // TODO(xians): Enable this test after resolving the racing issue that TSAN | 216 // TODO(xians): Enable this test after resolving the racing issue that TSAN |
| 219 // reports on MediaStreamTrack::enabled(); | 217 // reports on MediaStreamTrack::enabled(); |
| 220 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { | 218 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { |
| 221 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); | 219 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); |
| 222 RTCMediaConstraints constraints; | 220 RTCMediaConstraints constraints; |
| 223 scoped_refptr<WebRtcLocalAudioTrack> track = | 221 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 224 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 222 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 225 &constraints); | 223 &constraints); |
| 224 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 225 track->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 226 track->Start(); | 226 track->Start(); |
| 227 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 227 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
| 228 GetRenderer()->AddChannel(0); | 228 GetRenderer()->AddChannel(0); |
| 229 EXPECT_TRUE(track->enabled()); | 229 EXPECT_TRUE(track->enabled()); |
| 230 EXPECT_TRUE(track->set_enabled(false)); | 230 EXPECT_TRUE(track->set_enabled(false)); |
| 231 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 231 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
| 232 new MockWebRtcAudioCapturerSink()); | 232 new MockWebRtcAudioCapturerSink()); |
| 233 const media::AudioParameters params = capturer_->audio_parameters(); | 233 const media::AudioParameters params = capturer_->audio_parameters(); |
| 234 base::WaitableEvent event(false, false); | 234 base::WaitableEvent event(false, false); |
| 235 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); | 235 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 // 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 |
| 269 // callbacks appear/disappear. | 269 // callbacks appear/disappear. |
| 270 // Flaky due to a data race, see http://crbug.com/295418 | 270 // Flaky due to a data race, see http://crbug.com/295418 |
| 271 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { | 271 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { |
| 272 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); | 272 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); |
| 273 RTCMediaConstraints constraints; | 273 RTCMediaConstraints constraints; |
| 274 scoped_refptr<WebRtcLocalAudioTrack> track_1 = | 274 scoped_refptr<WebRtcLocalAudioTrack> track_1 = |
| 275 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 275 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 276 &constraints); | 276 &constraints); |
| 277 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 278 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 277 track_1->Start(); | 279 track_1->Start(); |
| 278 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 280 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
| 279 GetRenderer()->AddChannel(0); | 281 GetRenderer()->AddChannel(0); |
| 280 EXPECT_TRUE(track_1->enabled()); | 282 EXPECT_TRUE(track_1->enabled()); |
| 281 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 283 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
| 282 new MockWebRtcAudioCapturerSink()); | 284 new MockWebRtcAudioCapturerSink()); |
| 283 const media::AudioParameters params = capturer_->audio_parameters(); | 285 const media::AudioParameters params = capturer_->audio_parameters(); |
| 284 base::WaitableEvent event_1(false, false); | 286 base::WaitableEvent event_1(false, false); |
| 285 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); | 287 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); |
| 286 EXPECT_CALL(*sink_1, | 288 EXPECT_CALL(*sink_1, |
| 287 CaptureData(1, | 289 CaptureData(1, |
| 288 params.sample_rate(), | 290 params.sample_rate(), |
| 289 params.channels(), | 291 params.channels(), |
| 290 params.sample_rate() / 100, | 292 params.sample_rate() / 100, |
| 291 0, | 293 0, |
| 292 0, | 294 0, |
| 293 false, | 295 false, |
| 294 false)).Times(AtLeast(1)) | 296 false)).Times(AtLeast(1)) |
| 295 .WillRepeatedly(SignalEvent(&event_1)); | 297 .WillRepeatedly(SignalEvent(&event_1)); |
| 296 track_1->AddSink(sink_1.get()); | 298 track_1->AddSink(sink_1.get()); |
| 297 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 299 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
| 298 | 300 |
| 299 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 301 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
| 300 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 302 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 301 &constraints); | 303 &constraints); |
| 304 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 305 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 302 track_2->Start(); | 306 track_2->Start(); |
| 303 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 307 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
| 304 GetRenderer()->AddChannel(1); | 308 GetRenderer()->AddChannel(1); |
| 305 EXPECT_TRUE(track_2->enabled()); | 309 EXPECT_TRUE(track_2->enabled()); |
| 306 | 310 |
| 307 // Verify both |sink_1| and |sink_2| get data. | 311 // Verify both |sink_1| and |sink_2| get data. |
| 308 event_1.Reset(); | 312 event_1.Reset(); |
| 309 base::WaitableEvent event_2(false, false); | 313 base::WaitableEvent event_2(false, false); |
| 310 | 314 |
| 311 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 315 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 351 |
| 348 | 352 |
| 349 // Start one track and verify the capturer is correctly starting its source. | 353 // Start one track and verify the capturer is correctly starting its source. |
| 350 // And it should be fine to not to call Stop() explicitly. | 354 // And it should be fine to not to call Stop() explicitly. |
| 351 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { | 355 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { |
| 352 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); | 356 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); |
| 353 RTCMediaConstraints constraints; | 357 RTCMediaConstraints constraints; |
| 354 scoped_refptr<WebRtcLocalAudioTrack> track = | 358 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 355 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 359 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 356 &constraints); | 360 &constraints); |
| 361 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 362 track->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 357 track->Start(); | 363 track->Start(); |
| 358 | 364 |
| 359 // When the track goes away, it will automatically stop the | 365 // When the track goes away, it will automatically stop the |
| 360 // |capturer_source_|. | 366 // |capturer_source_|. |
| 361 EXPECT_CALL(*capturer_source_.get(), Stop()); | 367 EXPECT_CALL(*capturer_source_.get(), Stop()); |
| 362 track->Stop(); | 368 track->Stop(); |
| 363 track = NULL; | 369 track = NULL; |
| 364 } | 370 } |
| 365 | 371 |
| 366 // Start/Stop tracks and verify the capturer is correctly starting/stopping | 372 // Start/Stop tracks and verify the capturer is correctly starting/stopping |
| 367 // its source. | 373 // its source. |
| 368 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { | 374 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { |
| 369 // Starting the first audio track will start the |capturer_source_|. | 375 // Starting the first audio track will start the |capturer_source_|. |
| 370 base::WaitableEvent event(false, false); | 376 base::WaitableEvent event(false, false); |
| 371 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(SignalEvent(&event)); | 377 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(SignalEvent(&event)); |
| 372 RTCMediaConstraints constraints; | 378 RTCMediaConstraints constraints; |
| 373 scoped_refptr<WebRtcLocalAudioTrack> track_1 = | 379 scoped_refptr<WebRtcLocalAudioTrack> track_1 = |
| 374 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 380 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 375 &constraints); | 381 &constraints); |
| 376 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 382 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
| 377 GetRenderer()->AddChannel(0); | 383 GetRenderer()->AddChannel(0); |
| 384 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 385 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 378 track_1->Start(); | 386 track_1->Start(); |
| 379 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 387 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 380 | 388 |
| 381 // Verify the data flow by connecting the sink to |track_1|. | 389 // Verify the data flow by connecting the sink to |track_1|. |
| 382 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 390 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
| 383 new MockWebRtcAudioCapturerSink()); | 391 new MockWebRtcAudioCapturerSink()); |
| 384 event.Reset(); | 392 event.Reset(); |
| 385 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) | 393 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) |
| 386 .Times(AnyNumber()).WillRepeatedly(Return()); | 394 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 387 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 395 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); |
| 388 track_1->AddSink(sink.get()); | 396 track_1->AddSink(sink.get()); |
| 389 | 397 |
| 390 // Start the second audio track will not start the |capturer_source_| | 398 // Start the second audio track will not start the |capturer_source_| |
| 391 // since it has been started. | 399 // since it has been started. |
| 392 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); | 400 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); |
| 393 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 401 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
| 394 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 402 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 395 &constraints); | 403 &constraints); |
| 404 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 405 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 396 track_2->Start(); | 406 track_2->Start(); |
| 397 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 407 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
| 398 GetRenderer()->AddChannel(1); | 408 GetRenderer()->AddChannel(1); |
| 399 | 409 |
| 400 // Stop the first audio track will not stop the |capturer_source_|. | 410 // Stop the first audio track will not stop the |capturer_source_|. |
| 401 EXPECT_CALL(*capturer_source_.get(), Stop()).Times(0); | 411 EXPECT_CALL(*capturer_source_.get(), Stop()).Times(0); |
| 402 track_1->RemoveSink(sink.get()); | 412 track_1->RemoveSink(sink.get()); |
| 403 track_1->Stop(); | 413 track_1->Stop(); |
| 404 track_1 = NULL; | 414 track_1 = NULL; |
| 405 | 415 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 419 } | 429 } |
| 420 | 430 |
| 421 // Set new source to the existing capturer. | 431 // Set new source to the existing capturer. |
| 422 TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { | 432 TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { |
| 423 // Setup the audio track and start the track. | 433 // Setup the audio track and start the track. |
| 424 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); | 434 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); |
| 425 RTCMediaConstraints constraints; | 435 RTCMediaConstraints constraints; |
| 426 scoped_refptr<WebRtcLocalAudioTrack> track = | 436 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 427 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 437 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 428 &constraints); | 438 &constraints); |
| 439 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 440 track->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 429 track->Start(); | 441 track->Start(); |
| 430 | 442 |
| 431 // Setting new source to the capturer and the track should still get packets. | 443 // Setting new source to the capturer and the track should still get packets. |
| 432 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); | 444 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); |
| 433 EXPECT_CALL(*capturer_source_.get(), Stop()); | 445 EXPECT_CALL(*capturer_source_.get(), Stop()); |
| 434 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)); | 446 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)); |
| 435 EXPECT_CALL(*new_source.get(), Initialize(_, capturer_.get(), 0)) | 447 EXPECT_CALL(*new_source.get(), Initialize(_, capturer_.get(), 0)) |
| 436 .WillOnce(Return()); | 448 .WillOnce(Return()); |
| 437 EXPECT_CALL(*new_source.get(), Start()).WillOnce(Return()); | 449 EXPECT_CALL(*new_source.get(), Start()).WillOnce(Return()); |
| 438 capturer_->SetCapturerSource(new_source, | 450 capturer_->SetCapturerSource(new_source, |
| 439 params_.channel_layout(), | 451 params_.channel_layout(), |
| 440 params_.sample_rate()); | 452 params_.sample_rate()); |
| 441 | 453 |
| 442 // Stop the track. | 454 // Stop the track. |
| 443 EXPECT_CALL(*new_source.get(), Stop()); | 455 EXPECT_CALL(*new_source.get(), Stop()); |
| 444 track->Stop(); | 456 track->Stop(); |
| 445 track = NULL; | 457 track = NULL; |
| 446 } | 458 } |
| 447 | 459 |
| 448 // Create a new capturer with new source, connect it to a new audio track. | 460 // Create a new capturer with new source, connect it to a new audio track. |
| 449 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { | 461 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { |
| 450 // Setup the first audio track and start it. | 462 // Setup the first audio track and start it. |
| 451 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); | 463 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); |
| 452 RTCMediaConstraints constraints; | 464 RTCMediaConstraints constraints; |
| 453 scoped_refptr<WebRtcLocalAudioTrack> track_1 = | 465 scoped_refptr<WebRtcLocalAudioTrack> track_1 = |
| 454 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 466 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
| 455 &constraints); | 467 &constraints); |
| 468 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 469 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 456 track_1->Start(); | 470 track_1->Start(); |
| 457 | 471 |
| 458 // Connect a number of network channels to the |track_1|. | 472 // Connect a number of network channels to the |track_1|. |
| 459 static const int kNumberOfNetworkChannelsForTrack1 = 2; | 473 static const int kNumberOfNetworkChannelsForTrack1 = 2; |
| 460 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { | 474 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { |
| 461 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 475 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
| 462 GetRenderer()->AddChannel(i); | 476 GetRenderer()->AddChannel(i); |
| 463 } | 477 } |
| 464 // Verify the data flow by connecting the |sink_1| to |track_1|. | 478 // Verify the data flow by connecting the |sink_1| to |track_1|. |
| 465 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 479 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
| 466 new MockWebRtcAudioCapturerSink()); | 480 new MockWebRtcAudioCapturerSink()); |
| 467 EXPECT_CALL( | 481 EXPECT_CALL( |
| 468 *sink_1.get(), | 482 *sink_1.get(), |
| 469 CaptureData( | 483 CaptureData( |
| 470 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false)) | 484 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false)) |
| 471 .Times(AnyNumber()).WillRepeatedly(Return()); | 485 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 472 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); | 486 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); |
| 473 track_1->AddSink(sink_1.get()); | 487 track_1->AddSink(sink_1.get()); |
| 474 | 488 |
| 475 // Create a new capturer with new source with different audio format. | 489 // Create a new capturer with new source with different audio format. |
| 476 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 490 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
| 477 WebRtcAudioCapturer::CreateCapturer()); | 491 WebRtcAudioCapturer::CreateCapturer()); |
| 478 WebRtcLocalAudioSourceProvider* source_provider = | |
| 479 static_cast<WebRtcLocalAudioSourceProvider*>( | |
| 480 new_capturer->audio_source_provider()); | |
| 481 source_provider->SetSinkParamsForTesting(params_); | |
| 482 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); | 492 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); |
| 483 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) | 493 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) |
| 484 .WillOnce(Return()); | 494 .WillOnce(Return()); |
| 485 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)) | 495 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)) |
| 486 .WillOnce(Return()); | 496 .WillOnce(Return()); |
| 487 new_capturer->SetCapturerSource(new_source, | 497 new_capturer->SetCapturerSource(new_source, |
| 488 media::CHANNEL_LAYOUT_MONO, | 498 media::CHANNEL_LAYOUT_MONO, |
| 489 44100); | 499 44100); |
| 490 | 500 |
| 491 // Start the audio thread used by the new source. | 501 // Start the audio thread used by the new source. |
| 492 scoped_ptr<FakeAudioThread> audio_thread(new FakeAudioThread(new_capturer)); | 502 scoped_ptr<FakeAudioThread> audio_thread(new FakeAudioThread(new_capturer)); |
| 493 audio_thread->Start(); | 503 audio_thread->Start(); |
| 494 | 504 |
| 495 // Setup the second audio track, connect it to the new capturer and start it. | 505 // Setup the second audio track, connect it to the new capturer and start it. |
| 496 EXPECT_CALL(*new_source.get(), Start()).Times(1); | 506 EXPECT_CALL(*new_source.get(), Start()).Times(1); |
| 497 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 507 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
| 498 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL, | 508 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL, |
| 499 &constraints); | 509 &constraints); |
| 510 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 511 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 500 track_2->Start(); | 512 track_2->Start(); |
| 501 | 513 |
| 502 // Connect a number of network channels to the |track_2|. | 514 // Connect a number of network channels to the |track_2|. |
| 503 static const int kNumberOfNetworkChannelsForTrack2 = 3; | 515 static const int kNumberOfNetworkChannelsForTrack2 = 3; |
| 504 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { | 516 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { |
| 505 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 517 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
| 506 GetRenderer()->AddChannel(i); | 518 GetRenderer()->AddChannel(i); |
| 507 } | 519 } |
| 508 // Verify the data flow by connecting the |sink_2| to |track_2|. | 520 // Verify the data flow by connecting the |sink_2| to |track_2|. |
| 509 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 521 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 526 audio_thread->Stop(); | 538 audio_thread->Stop(); |
| 527 audio_thread.reset(); | 539 audio_thread.reset(); |
| 528 | 540 |
| 529 // Stop the first audio track. | 541 // Stop the first audio track. |
| 530 EXPECT_CALL(*capturer_source_.get(), Stop()); | 542 EXPECT_CALL(*capturer_source_.get(), Stop()); |
| 531 track_1->Stop(); | 543 track_1->Stop(); |
| 532 track_1 = NULL; | 544 track_1 = NULL; |
| 533 } | 545 } |
| 534 | 546 |
| 535 } // namespace content | 547 } // namespace content |
| OLD | NEW |