From 5b5129a2ade0d6790ea38bd8057c83db78b4c8c7 Mon Sep 17 00:00:00 2001 From: solenberg Date: Fri, 8 Apr 2016 05:35:48 -0700 Subject: [PATCH] Replace a few calls to VoEHardware with direct calls on the ADM, in WVoMC. BUG=webrtc:4690 Review URL: https://codereview.webrtc.org/1875483002 Cr-Commit-Position: refs/heads/master@{#12293} --- webrtc/media/engine/fakewebrtcvoiceengine.h | 22 +++----------- webrtc/media/engine/webrtcvoiceengine.cc | 26 ++++++++-------- webrtc/media/engine/webrtcvoiceengine.h | 1 + .../engine/webrtcvoiceengine_unittest.cc | 30 ++++++++++++++----- 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/webrtc/media/engine/fakewebrtcvoiceengine.h b/webrtc/media/engine/fakewebrtcvoiceengine.h index b5ad81c6a9..33629160bc 100644 --- a/webrtc/media/engine/fakewebrtcvoiceengine.h +++ b/webrtc/media/engine/fakewebrtcvoiceengine.h @@ -456,22 +456,10 @@ class FakeWebRtcVoiceEngine WEBRTC_STUB(SetPlayoutDevice, (int)); WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers)); WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&)); - WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) { - recording_sample_rate_ = samples_per_sec; - return 0; - } - WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) { - *samples_per_sec = recording_sample_rate_; - return 0; - } - WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) { - playout_sample_rate_ = samples_per_sec; - return 0; - } - WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) { - *samples_per_sec = playout_sample_rate_; - return 0; - } + WEBRTC_STUB(SetRecordingSampleRate, (unsigned int samples_per_sec)); + WEBRTC_STUB_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)); + WEBRTC_STUB(SetPlayoutSampleRate, (unsigned int samples_per_sec)); + WEBRTC_STUB_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)); WEBRTC_STUB(EnableBuiltInAEC, (bool enable)); virtual bool BuiltInAECIsAvailable() const { return false; } WEBRTC_STUB(EnableBuiltInAGC, (bool enable)); @@ -729,8 +717,6 @@ class FakeWebRtcVoiceEngine webrtc::AgcModes agc_mode_ = webrtc::kAgcDefault; webrtc::AgcConfig agc_config_; int playout_fail_channel_ = -1; - int recording_sample_rate_ = -1; - int playout_sample_rate_ = -1; FakeAudioProcessing audio_processing_; }; diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc index 97e955f51e..21f12105f1 100644 --- a/webrtc/media/engine/webrtcvoiceengine.cc +++ b/webrtc/media/engine/webrtcvoiceengine.cc @@ -655,14 +655,14 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { // Android and in combination with Java based audio layer. // TODO(henrika): investigate possibility to support built-in EC also // in combination with Open SL ES audio. - const bool built_in_aec = voe_wrapper_->hw()->BuiltInAECIsAvailable(); + const bool built_in_aec = adm()->BuiltInAECIsAvailable(); if (built_in_aec) { // Built-in EC exists on this device and use_delay_agnostic_aec is not // overriding it. Enable/Disable it according to the echo_cancellation // audio option. const bool enable_built_in_aec = *options.echo_cancellation && !use_delay_agnostic_aec; - if (voe_wrapper_->hw()->EnableBuiltInAEC(enable_built_in_aec) == 0 && + if (adm()->EnableBuiltInAEC(enable_built_in_aec) == 0 && enable_built_in_aec) { // Disable internal software EC if built-in EC is enabled, // i.e., replace the software EC with the built-in EC. @@ -694,10 +694,9 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { } if (options.auto_gain_control) { - const bool built_in_agc = voe_wrapper_->hw()->BuiltInAGCIsAvailable(); + const bool built_in_agc = adm()->BuiltInAGCIsAvailable(); if (built_in_agc) { - if (voe_wrapper_->hw()->EnableBuiltInAGC(*options.auto_gain_control) == - 0 && + if (adm()->EnableBuiltInAGC(*options.auto_gain_control) == 0 && *options.auto_gain_control) { // Disable internal software AGC if built-in AGC is enabled, // i.e., replace the software AGC with the built-in AGC. @@ -741,10 +740,9 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { } if (options.noise_suppression) { - const bool built_in_ns = voe_wrapper_->hw()->BuiltInNSIsAvailable(); + const bool built_in_ns = adm()->BuiltInNSIsAvailable(); if (built_in_ns) { - if (voe_wrapper_->hw()->EnableBuiltInNS(*options.noise_suppression) == - 0 && + if (adm()->EnableBuiltInNS(*options.noise_suppression) == 0 && *options.noise_suppression) { // Disable internal software NS if built-in NS is enabled, // i.e., replace the software NS with the built-in NS. @@ -848,16 +846,14 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { if (options.recording_sample_rate) { LOG(LS_INFO) << "Recording sample rate is " << *options.recording_sample_rate; - if (voe_wrapper_->hw()->SetRecordingSampleRate( - *options.recording_sample_rate)) { + if (adm()->SetRecordingSampleRate(*options.recording_sample_rate)) { LOG_RTCERR1(SetRecordingSampleRate, *options.recording_sample_rate); } } if (options.playout_sample_rate) { LOG(LS_INFO) << "Playout sample rate is " << *options.playout_sample_rate; - if (voe_wrapper_->hw()->SetPlayoutSampleRate( - *options.playout_sample_rate)) { + if (adm()->SetPlayoutSampleRate(*options.playout_sample_rate)) { LOG_RTCERR1(SetPlayoutSampleRate, *options.playout_sample_rate); } } @@ -1078,6 +1074,12 @@ int WebRtcVoiceEngine::CreateVoEChannel() { return voe_wrapper_->base()->CreateChannel(voe_config_); } +webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { + RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); + RTC_DCHECK(adm_); + return adm_; +} + class WebRtcVoiceMediaChannel::WebRtcAudioSendStream : public AudioSource::Sink { public: diff --git a/webrtc/media/engine/webrtcvoiceengine.h b/webrtc/media/engine/webrtcvoiceengine.h index dd565038b7..0bc0933536 100644 --- a/webrtc/media/engine/webrtcvoiceengine.h +++ b/webrtc/media/engine/webrtcvoiceengine.h @@ -103,6 +103,7 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback { void StartAecDump(const std::string& filename); int CreateVoEChannel(); + webrtc::AudioDeviceModule* adm(); rtc::ThreadChecker signal_thread_checker_; rtc::ThreadChecker worker_thread_checker_; diff --git a/webrtc/media/engine/webrtcvoiceengine_unittest.cc b/webrtc/media/engine/webrtcvoiceengine_unittest.cc index 7645e9272c..f88b99ba10 100644 --- a/webrtc/media/engine/webrtcvoiceengine_unittest.cc +++ b/webrtc/media/engine/webrtcvoiceengine_unittest.cc @@ -67,6 +67,9 @@ TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { StrictMock adm; EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); EXPECT_CALL(adm, Release()).WillOnce(Return(0)); + EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); + EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); + EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); cricket::FakeWebRtcVoiceEngine voe; EXPECT_FALSE(voe.IsInited()); { @@ -93,6 +96,9 @@ class WebRtcVoiceEngineTestFake : public testing::Test { : call_(webrtc::Call::Config()), override_field_trials_(field_trials) { EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); + EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); + EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); + EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, new FakeVoEWrapper(&voe_))); send_parameters_.codecs.push_back(kPcmuCodec); @@ -2402,6 +2408,8 @@ TEST_F(WebRtcVoiceEngineTestFake, CodianSend) { TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { EXPECT_TRUE(SetupSendStream()); + EXPECT_CALL(adm_, + BuiltInAGCIsAvailable()).Times(2).WillRepeatedly(Return(false)); webrtc::AgcConfig agc_config; EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); EXPECT_EQ(0, agc_config.targetLeveldBOv); @@ -2426,16 +2434,12 @@ TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) { EXPECT_TRUE(SetupSendStream()); + EXPECT_CALL(adm_, SetRecordingSampleRate(48000)).WillOnce(Return(0)); + EXPECT_CALL(adm_, SetPlayoutSampleRate(44100)).WillOnce(Return(0)); send_parameters_.options.recording_sample_rate = rtc::Optional(48000); send_parameters_.options.playout_sample_rate = rtc::Optional(44100); EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); - - unsigned int recording_sample_rate, playout_sample_rate; - EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate)); - EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate)); - EXPECT_EQ(48000u, recording_sample_rate); - EXPECT_EQ(44100u, playout_sample_rate); } // Test that we can set the outgoing SSRC properly. @@ -2739,7 +2743,12 @@ TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) { TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_TRUE(SetupSendStream()); - + EXPECT_CALL(adm_, + BuiltInAECIsAvailable()).Times(9).WillRepeatedly(Return(false)); + EXPECT_CALL(adm_, + BuiltInAGCIsAvailable()).Times(4).WillRepeatedly(Return(false)); + EXPECT_CALL(adm_, + BuiltInNSIsAvailable()).Times(2).WillRepeatedly(Return(false)); bool ec_enabled; webrtc::EcModes ec_mode; webrtc::AecmModes aecm_mode; @@ -2937,6 +2946,13 @@ TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) { TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { EXPECT_TRUE(SetupSendStream()); + EXPECT_CALL(adm_, + BuiltInAECIsAvailable()).Times(9).WillRepeatedly(Return(false)); + EXPECT_CALL(adm_, + BuiltInAGCIsAvailable()).Times(9).WillRepeatedly(Return(false)); + EXPECT_CALL(adm_, + BuiltInNSIsAvailable()).Times(9).WillRepeatedly(Return(false)); + std::unique_ptr channel1( static_cast(engine_->CreateChannel( &call_, cricket::MediaConfig(), cricket::AudioOptions())));