| 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_audio_device_impl.h" | 9 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 10 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | 10 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 protected: | 161 protected: |
| 162 virtual void SetUp() OVERRIDE { | 162 virtual void SetUp() OVERRIDE { |
| 163 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 163 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 164 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); | 164 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); |
| 165 capturer_ = WebRtcAudioCapturer::CreateCapturer(); | 165 capturer_ = WebRtcAudioCapturer::CreateCapturer(); |
| 166 capturer_source_ = new MockCapturerSource(capturer_.get()); | 166 capturer_source_ = new MockCapturerSource(capturer_.get()); |
| 167 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), 0)) | 167 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), 0)) |
| 168 .WillOnce(Return()); | 168 .WillOnce(Return()); |
| 169 capturer_->SetCapturerSource(capturer_source_, | 169 capturer_->SetCapturerSource(capturer_source_, |
| 170 params_.channel_layout(), | 170 params_.channel_layout(), |
| 171 params_.sample_rate()); | 171 params_.sample_rate(), |
| 172 false); |
| 172 } | 173 } |
| 173 | 174 |
| 174 media::AudioParameters params_; | 175 media::AudioParameters params_; |
| 175 scoped_refptr<MockCapturerSource> capturer_source_; | 176 scoped_refptr<MockCapturerSource> capturer_source_; |
| 176 scoped_refptr<WebRtcAudioCapturer> capturer_; | 177 scoped_refptr<WebRtcAudioCapturer> capturer_; |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 // Creates a capturer and audio track, fakes its audio thread, and | 180 // Creates a capturer and audio track, fakes its audio thread, and |
| 180 // connect/disconnect the sink to the audio track on the fly, the sink should | 181 // connect/disconnect the sink to the audio track on the fly, the sink should |
| 181 // get data callback when the track is connected to the capturer but not when | 182 // get data callback when the track is connected to the capturer but not when |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 // Setting new source to the capturer and the track should still get packets. | 454 // Setting new source to the capturer and the track should still get packets. |
| 454 scoped_refptr<MockCapturerSource> new_source( | 455 scoped_refptr<MockCapturerSource> new_source( |
| 455 new MockCapturerSource(capturer_.get())); | 456 new MockCapturerSource(capturer_.get())); |
| 456 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 457 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
| 457 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); | 458 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); |
| 458 EXPECT_CALL(*new_source.get(), OnInitialize(_, capturer_.get(), 0)) | 459 EXPECT_CALL(*new_source.get(), OnInitialize(_, capturer_.get(), 0)) |
| 459 .WillOnce(Return()); | 460 .WillOnce(Return()); |
| 460 EXPECT_CALL(*new_source.get(), OnStart()); | 461 EXPECT_CALL(*new_source.get(), OnStart()); |
| 461 capturer_->SetCapturerSource(new_source, | 462 capturer_->SetCapturerSource(new_source, |
| 462 params_.channel_layout(), | 463 params_.channel_layout(), |
| 463 params_.sample_rate()); | 464 params_.sample_rate(), |
| 465 false); |
| 464 | 466 |
| 465 // Stop the track. | 467 // Stop the track. |
| 466 EXPECT_CALL(*new_source.get(), OnStop()); | 468 EXPECT_CALL(*new_source.get(), OnStop()); |
| 467 capturer_->Stop(); | 469 capturer_->Stop(); |
| 468 } | 470 } |
| 469 | 471 |
| 470 // Create a new capturer with new source, connect it to a new audio track. | 472 // Create a new capturer with new source, connect it to a new audio track. |
| 471 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { | 473 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { |
| 472 // Setup the first audio track and start it. | 474 // Setup the first audio track and start it. |
| 473 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 475 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 497 track_1->AddSink(sink_1.get()); | 499 track_1->AddSink(sink_1.get()); |
| 498 | 500 |
| 499 // Create a new capturer with new source with different audio format. | 501 // Create a new capturer with new source with different audio format. |
| 500 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 502 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
| 501 WebRtcAudioCapturer::CreateCapturer()); | 503 WebRtcAudioCapturer::CreateCapturer()); |
| 502 scoped_refptr<MockCapturerSource> new_source( | 504 scoped_refptr<MockCapturerSource> new_source( |
| 503 new MockCapturerSource(new_capturer.get())); | 505 new MockCapturerSource(new_capturer.get())); |
| 504 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), 0)); | 506 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), 0)); |
| 505 new_capturer->SetCapturerSource(new_source, | 507 new_capturer->SetCapturerSource(new_source, |
| 506 media::CHANNEL_LAYOUT_MONO, | 508 media::CHANNEL_LAYOUT_MONO, |
| 507 44100); | 509 44100, |
| 510 false); |
| 508 | 511 |
| 509 // Setup the second audio track, connect it to the new capturer and start it. | 512 // Setup the second audio track, connect it to the new capturer and start it. |
| 510 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); | 513 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); |
| 511 EXPECT_CALL(*new_source.get(), OnStart()); | 514 EXPECT_CALL(*new_source.get(), OnStart()); |
| 512 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 515 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
| 513 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL, | 516 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL, |
| 514 &constraints); | 517 &constraints); |
| 515 static_cast<WebRtcLocalAudioSourceProvider*>( | 518 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 516 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | 519 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
| 517 track_2->Start(); | 520 track_2->Start(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 // Setup a capturer which works with a buffer size smaller than 10ms. | 556 // Setup a capturer which works with a buffer size smaller than 10ms. |
| 554 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 557 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 555 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); | 558 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); |
| 556 | 559 |
| 557 // Create a capturer with new source which works with the format above. | 560 // Create a capturer with new source which works with the format above. |
| 558 scoped_refptr<WebRtcAudioCapturer> capturer( | 561 scoped_refptr<WebRtcAudioCapturer> capturer( |
| 559 WebRtcAudioCapturer::CreateCapturer()); | 562 WebRtcAudioCapturer::CreateCapturer()); |
| 560 scoped_refptr<MockCapturerSource> source( | 563 scoped_refptr<MockCapturerSource> source( |
| 561 new MockCapturerSource(capturer.get())); | 564 new MockCapturerSource(capturer.get())); |
| 562 capturer->Initialize(-1, params.channel_layout(), params.sample_rate(), | 565 capturer->Initialize(-1, params.channel_layout(), params.sample_rate(), |
| 563 params.frames_per_buffer(), 0, std::string(), 0, 0); | 566 params.frames_per_buffer(), 0, std::string(), 0, 0, |
| 567 false); |
| 564 | 568 |
| 565 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), 0)); | 569 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), 0)); |
| 566 capturer->SetCapturerSource(source, params.channel_layout(), | 570 capturer->SetCapturerSource(source, params.channel_layout(), |
| 567 params.sample_rate()); | 571 params.sample_rate(), false); |
| 568 | 572 |
| 569 // Setup a audio track, connect it to the capturer and start it. | 573 // Setup a audio track, connect it to the capturer and start it. |
| 570 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); | 574 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); |
| 571 EXPECT_CALL(*source.get(), OnStart()); | 575 EXPECT_CALL(*source.get(), OnStart()); |
| 572 RTCMediaConstraints constraints; | 576 RTCMediaConstraints constraints; |
| 573 scoped_refptr<WebRtcLocalAudioTrack> track = | 577 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 574 WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL, | 578 WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL, |
| 575 &constraints); | 579 &constraints); |
| 576 static_cast<WebRtcLocalAudioSourceProvider*>( | 580 static_cast<WebRtcLocalAudioSourceProvider*>( |
| 577 track->audio_source_provider())->SetSinkParamsForTesting(params); | 581 track->audio_source_provider())->SetSinkParamsForTesting(params); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 593 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); | 597 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
| 594 track->AddSink(sink.get()); | 598 track->AddSink(sink.get()); |
| 595 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 599 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 596 | 600 |
| 597 // Stopping the new source will stop the second track. | 601 // Stopping the new source will stop the second track. |
| 598 EXPECT_CALL(*source, OnStop()).Times(1); | 602 EXPECT_CALL(*source, OnStop()).Times(1); |
| 599 capturer->Stop(); | 603 capturer->Stop(); |
| 600 } | 604 } |
| 601 | 605 |
| 602 } // namespace content | 606 } // namespace content |
| OLD | NEW |