Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: content/renderer/media/webrtc_local_audio_track_unittest.cc

Issue 99033003: Enable platform echo cancellation through the AudioRecord path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add PlatformEffects, unittests and clean up. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 class WebRtcLocalAudioTrackTest : public ::testing::Test { 160 class WebRtcLocalAudioTrackTest : public ::testing::Test {
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 media::AudioParameters::PlatformEffects effects;
169 capturer_->SetCapturerSource(capturer_source_, 170 capturer_->SetCapturerSource(capturer_source_,
170 params_.channel_layout(), 171 params_.channel_layout(),
171 params_.sample_rate()); 172 params_.sample_rate(),
173 effects);
172 } 174 }
173 175
174 media::AudioParameters params_; 176 media::AudioParameters params_;
175 scoped_refptr<MockCapturerSource> capturer_source_; 177 scoped_refptr<MockCapturerSource> capturer_source_;
176 scoped_refptr<WebRtcAudioCapturer> capturer_; 178 scoped_refptr<WebRtcAudioCapturer> capturer_;
177 }; 179 };
178 180
179 // Creates a capturer and audio track, fakes its audio thread, and 181 // 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 182 // 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 183 // get data callback when the track is connected to the capturer but not when
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 track->Start(); 453 track->Start();
452 454
453 // Setting new source to the capturer and the track should still get packets. 455 // Setting new source to the capturer and the track should still get packets.
454 scoped_refptr<MockCapturerSource> new_source( 456 scoped_refptr<MockCapturerSource> new_source(
455 new MockCapturerSource(capturer_.get())); 457 new MockCapturerSource(capturer_.get()));
456 EXPECT_CALL(*capturer_source_.get(), OnStop()); 458 EXPECT_CALL(*capturer_source_.get(), OnStop());
457 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); 459 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true));
458 EXPECT_CALL(*new_source.get(), OnInitialize(_, capturer_.get(), 0)) 460 EXPECT_CALL(*new_source.get(), OnInitialize(_, capturer_.get(), 0))
459 .WillOnce(Return()); 461 .WillOnce(Return());
460 EXPECT_CALL(*new_source.get(), OnStart()); 462 EXPECT_CALL(*new_source.get(), OnStart());
463 media::AudioParameters::PlatformEffects effects;
461 capturer_->SetCapturerSource(new_source, 464 capturer_->SetCapturerSource(new_source,
462 params_.channel_layout(), 465 params_.channel_layout(),
463 params_.sample_rate()); 466 params_.sample_rate(),
467 effects);
464 468
465 // Stop the track. 469 // Stop the track.
466 EXPECT_CALL(*new_source.get(), OnStop()); 470 EXPECT_CALL(*new_source.get(), OnStop());
467 capturer_->Stop(); 471 capturer_->Stop();
468 } 472 }
469 473
470 // Create a new capturer with new source, connect it to a new audio track. 474 // Create a new capturer with new source, connect it to a new audio track.
471 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { 475 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
472 // Setup the first audio track and start it. 476 // Setup the first audio track and start it.
473 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); 477 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
(...skipping 21 matching lines...) Expand all
495 .Times(AnyNumber()).WillRepeatedly(Return()); 499 .Times(AnyNumber()).WillRepeatedly(Return());
496 EXPECT_CALL(*sink_1.get(), OnSetFormat(_)).Times(AnyNumber()); 500 EXPECT_CALL(*sink_1.get(), OnSetFormat(_)).Times(AnyNumber());
497 track_1->AddSink(sink_1.get()); 501 track_1->AddSink(sink_1.get());
498 502
499 // Create a new capturer with new source with different audio format. 503 // Create a new capturer with new source with different audio format.
500 scoped_refptr<WebRtcAudioCapturer> new_capturer( 504 scoped_refptr<WebRtcAudioCapturer> new_capturer(
501 WebRtcAudioCapturer::CreateCapturer()); 505 WebRtcAudioCapturer::CreateCapturer());
502 scoped_refptr<MockCapturerSource> new_source( 506 scoped_refptr<MockCapturerSource> new_source(
503 new MockCapturerSource(new_capturer.get())); 507 new MockCapturerSource(new_capturer.get()));
504 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), 0)); 508 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), 0));
509 media::AudioParameters::PlatformEffects effects;
505 new_capturer->SetCapturerSource(new_source, 510 new_capturer->SetCapturerSource(new_source,
506 media::CHANNEL_LAYOUT_MONO, 511 media::CHANNEL_LAYOUT_MONO,
507 44100); 512 44100,
513 effects);
508 514
509 // Setup the second audio track, connect it to the new capturer and start it. 515 // Setup the second audio track, connect it to the new capturer and start it.
510 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); 516 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true));
511 EXPECT_CALL(*new_source.get(), OnStart()); 517 EXPECT_CALL(*new_source.get(), OnStart());
512 scoped_refptr<WebRtcLocalAudioTrack> track_2 = 518 scoped_refptr<WebRtcLocalAudioTrack> track_2 =
513 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL, 519 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL,
514 &constraints); 520 &constraints);
515 static_cast<WebRtcLocalAudioSourceProvider*>( 521 static_cast<WebRtcLocalAudioSourceProvider*>(
516 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); 522 track_2->audio_source_provider())->SetSinkParamsForTesting(params_);
517 track_2->Start(); 523 track_2->Start();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) { 558 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) {
553 // Setup a capturer which works with a buffer size smaller than 10ms. 559 // Setup a capturer which works with a buffer size smaller than 10ms.
554 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 560 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
555 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); 561 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128);
556 562
557 // Create a capturer with new source which works with the format above. 563 // Create a capturer with new source which works with the format above.
558 scoped_refptr<WebRtcAudioCapturer> capturer( 564 scoped_refptr<WebRtcAudioCapturer> capturer(
559 WebRtcAudioCapturer::CreateCapturer()); 565 WebRtcAudioCapturer::CreateCapturer());
560 scoped_refptr<MockCapturerSource> source( 566 scoped_refptr<MockCapturerSource> source(
561 new MockCapturerSource(capturer.get())); 567 new MockCapturerSource(capturer.get()));
568 media::AudioParameters::PlatformEffects effects;
562 capturer->Initialize(-1, params.channel_layout(), params.sample_rate(), 569 capturer->Initialize(-1, params.channel_layout(), params.sample_rate(),
563 params.frames_per_buffer(), 0, std::string(), 0, 0); 570 params.frames_per_buffer(), 0, std::string(), 0, 0,
571 effects);
564 572
565 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), 0)); 573 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), 0));
566 capturer->SetCapturerSource(source, params.channel_layout(), 574 capturer->SetCapturerSource(source, params.channel_layout(),
567 params.sample_rate()); 575 params.sample_rate(), effects);
568 576
569 // Setup a audio track, connect it to the capturer and start it. 577 // Setup a audio track, connect it to the capturer and start it.
570 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); 578 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true));
571 EXPECT_CALL(*source.get(), OnStart()); 579 EXPECT_CALL(*source.get(), OnStart());
572 RTCMediaConstraints constraints; 580 RTCMediaConstraints constraints;
573 scoped_refptr<WebRtcLocalAudioTrack> track = 581 scoped_refptr<WebRtcLocalAudioTrack> track =
574 WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL, 582 WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL,
575 &constraints); 583 &constraints);
576 static_cast<WebRtcLocalAudioSourceProvider*>( 584 static_cast<WebRtcLocalAudioSourceProvider*>(
577 track->audio_source_provider())->SetSinkParamsForTesting(params); 585 track->audio_source_provider())->SetSinkParamsForTesting(params);
(...skipping 15 matching lines...) Expand all
593 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); 601 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event));
594 track->AddSink(sink.get()); 602 track->AddSink(sink.get());
595 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 603 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
596 604
597 // Stopping the new source will stop the second track. 605 // Stopping the new source will stop the second track.
598 EXPECT_CALL(*source, OnStop()).Times(1); 606 EXPECT_CALL(*source, OnStop()).Times(1);
599 capturer->Stop(); 607 capturer->Stop();
600 } 608 }
601 609
602 } // namespace content 610 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698