diff --git a/media/engine/apm_helpers.cc b/media/engine/apm_helpers.cc index 5c12faa050..eca3e20c4f 100644 --- a/media/engine/apm_helpers.cc +++ b/media/engine/apm_helpers.cc @@ -64,10 +64,8 @@ void SetAgcConfig(AudioProcessing* apm, } void SetAgcStatus(AudioProcessing* apm, - AudioDeviceModule* adm, bool enable) { RTC_DCHECK(apm); - RTC_DCHECK(adm); #if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID) GainControl::Mode agc_mode = GainControl::kFixedDigital; #else @@ -82,11 +80,6 @@ void SetAgcStatus(AudioProcessing* apm, RTC_LOG(LS_ERROR) << "Failed to enable/disable AGC: " << enable; return; } - // Set AGC state in the ADM when adaptive AGC mode has been selected. - if (adm->SetAGC(enable && agc_mode == GainControl::kAdaptiveAnalog) != 0) { - RTC_LOG(LS_ERROR) << "Failed to set AGC mode in ADM: " << enable; - return; - } RTC_LOG(LS_INFO) << "AGC set to " << enable << " with mode " << agc_mode; } diff --git a/media/engine/apm_helpers.h b/media/engine/apm_helpers.h index caa485f477..42465fcec0 100644 --- a/media/engine/apm_helpers.h +++ b/media/engine/apm_helpers.h @@ -16,7 +16,6 @@ namespace webrtc { class AudioProcessing; -class AudioDeviceModule; enum EcModes { kEcConference, // Conferencing default (aggressive AEC). @@ -36,7 +35,6 @@ AgcConfig GetAgcConfig(AudioProcessing* apm); void SetAgcConfig(AudioProcessing* apm, const AgcConfig& config); void SetAgcStatus(AudioProcessing* apm, - AudioDeviceModule* adm, bool enable); void SetEcStatus(AudioProcessing* apm, bool enable, diff --git a/media/engine/apm_helpers_unittest.cc b/media/engine/apm_helpers_unittest.cc index c20eb6faff..70edce23fe 100644 --- a/media/engine/apm_helpers_unittest.cc +++ b/media/engine/apm_helpers_unittest.cc @@ -39,10 +39,6 @@ struct TestHelper { const AudioProcessing* apm() const { return apm_.get(); } - test::MockAudioDeviceModule* adm() { - return &mock_audio_device_; - } - voe::TransmitMixer* transmit_mixer() { return voe_wrapper_.base()->transmit_mixer(); } @@ -117,21 +113,18 @@ TEST(ApmHelpersTest, AgcStatus_EnableDisable) { TestHelper helper; GainControl* gc = helper.apm()->gain_control(); #if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID) - apm_helpers::SetAgcStatus(helper.apm(), helper.adm(), false); + apm_helpers::SetAgcStatus(helper.apm(), false); EXPECT_FALSE(gc->is_enabled()); EXPECT_EQ(GainControl::kFixedDigital, gc->mode()); - apm_helpers::SetAgcStatus(helper.apm(), helper.adm(), true); + apm_helpers::SetAgcStatus(helper.apm(), true); EXPECT_TRUE(gc->is_enabled()); EXPECT_EQ(GainControl::kFixedDigital, gc->mode()); #else - EXPECT_CALL(*helper.adm(), SetAGC(false)).WillOnce(testing::Return(0)); - apm_helpers::SetAgcStatus(helper.apm(), helper.adm(), false); + apm_helpers::SetAgcStatus(helper.apm(), false); EXPECT_FALSE(gc->is_enabled()); EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode()); - - EXPECT_CALL(*helper.adm(), SetAGC(true)).WillOnce(testing::Return(0)); - apm_helpers::SetAgcStatus(helper.apm(), helper.adm(), true); + apm_helpers::SetAgcStatus(helper.apm(), true); EXPECT_TRUE(gc->is_enabled()); EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode()); #endif diff --git a/media/engine/webrtcvoiceengine.cc b/media/engine/webrtcvoiceengine.cc index 18cc324b25..1ebbb0fe2b 100644 --- a/media/engine/webrtcvoiceengine.cc +++ b/media/engine/webrtcvoiceengine.cc @@ -485,7 +485,7 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { << "Disabling AGC since built-in AGC will be used instead"; } } - webrtc::apm_helpers::SetAgcStatus(apm(), adm(), *options.auto_gain_control); + webrtc::apm_helpers::SetAgcStatus(apm(), *options.auto_gain_control); } if (options.tx_agc_target_dbov || options.tx_agc_digital_compression_gain || diff --git a/media/engine/webrtcvoiceengine_unittest.cc b/media/engine/webrtcvoiceengine_unittest.cc index b65241ff92..5546f1b490 100644 --- a/media/engine/webrtcvoiceengine_unittest.cc +++ b/media/engine/webrtcvoiceengine_unittest.cc @@ -124,7 +124,6 @@ void AdmSetupExpectations(webrtc::test::MockAudioDeviceModule* adm) { EXPECT_CALL(*adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); EXPECT_CALL(*adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); EXPECT_CALL(*adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); - EXPECT_CALL(*adm, SetAGC(true)).WillOnce(Return(0)); // Teardown. EXPECT_CALL(*adm, StopPlayout()).WillOnce(Return(0)); @@ -2221,7 +2220,6 @@ TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { EXPECT_CALL(adm_, BuiltInAGCIsAvailable()) .Times(1) .WillRepeatedly(Return(false)); - EXPECT_CALL(adm_, SetAGC(true)).Times(1).WillRepeatedly(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).Times(1).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, Enable(true)).Times(1).WillOnce(Return(0)); send_parameters_.options.tx_agc_target_dbov = 3; @@ -2768,7 +2766,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { SetSendParameters(send_parameters_); // Turn off AGC - EXPECT_CALL(adm_, SetAGC(false)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2777,7 +2774,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { SetSendParameters(send_parameters_); // Turn AGC back on - EXPECT_CALL(adm_, SetAGC(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2786,7 +2782,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { SetSendParameters(send_parameters_); // Turn off other options (and stereo swapping on). - EXPECT_CALL(adm_, SetAGC(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2803,7 +2798,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_FALSE(IsHighPassFilterEnabled()); // Set options again to ensure it has no impact. - EXPECT_CALL(adm_, SetAGC(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2856,7 +2850,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { parameters_options_all.options.echo_cancellation = true; parameters_options_all.options.auto_gain_control = true; parameters_options_all.options.noise_suppression = true; - EXPECT_CALL(adm_, SetAGC(true)).Times(2).WillRepeatedly(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).Times(2).WillRepeatedly(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).Times(2).WillRepeatedly(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).Times(2).WillOnce(Return(0)); @@ -2871,7 +2864,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { // unset NS cricket::AudioSendParameters parameters_options_no_ns = send_parameters_; parameters_options_no_ns.options.noise_suppression = false; - EXPECT_CALL(adm_, SetAGC(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2888,7 +2880,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { // unset AGC cricket::AudioSendParameters parameters_options_no_agc = send_parameters_; parameters_options_no_agc.options.auto_gain_control = false; - EXPECT_CALL(adm_, SetAGC(false)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2901,7 +2892,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { expected_options.noise_suppression = true; EXPECT_EQ(expected_options, channel2->options()); - EXPECT_CALL(adm_, SetAGC(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2910,7 +2900,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { EXPECT_CALL(apm_ns_, Enable(true)).WillOnce(Return(0)); EXPECT_TRUE(channel_->SetSendParameters(parameters_options_all)); - EXPECT_CALL(adm_, SetAGC(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2919,7 +2908,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { EXPECT_CALL(apm_ns_, Enable(false)).WillOnce(Return(0)); channel1->SetSend(true); - EXPECT_CALL(adm_, SetAGC(false)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); @@ -2933,7 +2921,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { send_parameters_; parameters_options_no_agc_nor_ns.options.auto_gain_control = false; parameters_options_no_agc_nor_ns.options.noise_suppression = false; - EXPECT_CALL(adm_, SetAGC(false)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); EXPECT_CALL(apm_gc_, set_mode(kDefaultAgcMode)).WillOnce(Return(0)); diff --git a/modules/audio_device/android/audio_device_template.h b/modules/audio_device/android/audio_device_template.h index 75dbaf315f..9fb72bdbbb 100644 --- a/modules/audio_device/android/audio_device_template.h +++ b/modules/audio_device/android/audio_device_template.h @@ -215,18 +215,6 @@ class AudioDeviceTemplate : public AudioDeviceGeneric { bool Recording() const override { return input_.Recording(); } - int32_t SetAGC(bool enable) override { - if (enable) { - FATAL() << "Should never be called"; - } - return -1; - } - - bool AGC() const override { - RTC_LOG(INFO) << __FUNCTION__; - return false; - } - int32_t InitSpeaker() override { RTC_LOG(INFO) << __FUNCTION__; return 0; diff --git a/modules/audio_device/audio_device_data_observer.cc b/modules/audio_device/audio_device_data_observer.cc index 823fbfed8c..5f7259d13f 100644 --- a/modules/audio_device/audio_device_data_observer.cc +++ b/modules/audio_device/audio_device_data_observer.cc @@ -165,8 +165,6 @@ class ADMWrapper : public AudioDeviceModule, public AudioTransport { int32_t StartRecording() override { return impl_->StartRecording(); } int32_t StopRecording() override { return impl_->StopRecording(); } bool Recording() const override { return impl_->Recording(); } - int32_t SetAGC(bool enable) override { return impl_->SetAGC(enable); } - bool AGC() const override { return impl_->AGC(); } int32_t InitSpeaker() override { return impl_->InitSpeaker(); } bool SpeakerIsInitialized() const override { return impl_->SpeakerIsInitialized(); diff --git a/modules/audio_device/audio_device_generic.h b/modules/audio_device/audio_device_generic.h index 2cd8874671..e7abcb37ff 100644 --- a/modules/audio_device/audio_device_generic.h +++ b/modules/audio_device/audio_device_generic.h @@ -71,10 +71,6 @@ class AudioDeviceGeneric { virtual int32_t StopRecording() = 0; virtual bool Recording() const = 0; - // Microphone Automatic Gain Control (AGC) - virtual int32_t SetAGC(bool enable) = 0; - virtual bool AGC() const = 0; - // Audio mixer initialization virtual int32_t InitSpeaker() = 0; virtual bool SpeakerIsInitialized() const = 0; diff --git a/modules/audio_device/audio_device_impl.cc b/modules/audio_device/audio_device_impl.cc index f3aceffc42..ff651d4c90 100644 --- a/modules/audio_device/audio_device_impl.cc +++ b/modules/audio_device/audio_device_impl.cc @@ -568,18 +568,6 @@ int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const { return 0; } -int32_t AudioDeviceModuleImpl::SetAGC(bool enable) { - RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECKinitialized_(); - return (audio_device_->SetAGC(enable)); -} - -bool AudioDeviceModuleImpl::AGC() const { - RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); - return audio_device_->AGC(); -} - int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) { RTC_LOG(INFO) << __FUNCTION__; CHECKinitialized_(); diff --git a/modules/audio_device/audio_device_impl.h b/modules/audio_device/audio_device_impl.h index dce6b0c8c8..9ccb4154a3 100644 --- a/modules/audio_device/audio_device_impl.h +++ b/modules/audio_device/audio_device_impl.h @@ -87,10 +87,6 @@ class AudioDeviceModuleImpl : public AudioDeviceModule { int32_t StopRecording() override; bool Recording() const override; - // Microphone Automatic Gain Control (AGC) - int32_t SetAGC(bool enable) override; - bool AGC() const override; - // Audio mixer initialization int32_t InitSpeaker() override; bool SpeakerIsInitialized() const override; diff --git a/modules/audio_device/audio_device_unittest.cc b/modules/audio_device/audio_device_unittest.cc index d7df357259..60acbbce8c 100644 --- a/modules/audio_device/audio_device_unittest.cc +++ b/modules/audio_device/audio_device_unittest.cc @@ -496,8 +496,6 @@ class AudioDeviceTest : public ::testing::Test { // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7397 for // details. EXPECT_EQ(0, audio_device_->SetStereoRecording(false)); - EXPECT_EQ(0, audio_device_->SetAGC(false)); - EXPECT_FALSE(audio_device_->AGC()); } } diff --git a/modules/audio_device/dummy/audio_device_dummy.cc b/modules/audio_device/dummy/audio_device_dummy.cc index 67ad5729f8..b7b61a72ab 100644 --- a/modules/audio_device/dummy/audio_device_dummy.cc +++ b/modules/audio_device/dummy/audio_device_dummy.cc @@ -79,10 +79,6 @@ int32_t AudioDeviceDummy::StopRecording() { return 0; } bool AudioDeviceDummy::Recording() const { return false; } -int32_t AudioDeviceDummy::SetAGC(bool enable) { return -1; } - -bool AudioDeviceDummy::AGC() const { return false; } - int32_t AudioDeviceDummy::InitSpeaker() { return -1; } bool AudioDeviceDummy::SpeakerIsInitialized() const { return false; } diff --git a/modules/audio_device/dummy/audio_device_dummy.h b/modules/audio_device/dummy/audio_device_dummy.h index 18c94fc914..d709f77691 100644 --- a/modules/audio_device/dummy/audio_device_dummy.h +++ b/modules/audio_device/dummy/audio_device_dummy.h @@ -65,10 +65,6 @@ class AudioDeviceDummy : public AudioDeviceGeneric { int32_t StopRecording() override; bool Recording() const override; - // Microphone Automatic Gain Control (AGC) - int32_t SetAGC(bool enable) override; - bool AGC() const override; - // Audio mixer initialization int32_t InitSpeaker() override; bool SpeakerIsInitialized() const override; diff --git a/modules/audio_device/dummy/file_audio_device.cc b/modules/audio_device/dummy/file_audio_device.cc index e02ec6ccb7..b9aeaa1506 100644 --- a/modules/audio_device/dummy/file_audio_device.cc +++ b/modules/audio_device/dummy/file_audio_device.cc @@ -310,14 +310,6 @@ bool FileAudioDevice::Recording() const { return _recording; } -int32_t FileAudioDevice::SetAGC(bool enable) { - return -1; -} - -bool FileAudioDevice::AGC() const { - return false; -} - int32_t FileAudioDevice::InitSpeaker() { return -1; } diff --git a/modules/audio_device/dummy/file_audio_device.h b/modules/audio_device/dummy/file_audio_device.h index f735d00e8e..1a7c78acab 100644 --- a/modules/audio_device/dummy/file_audio_device.h +++ b/modules/audio_device/dummy/file_audio_device.h @@ -85,10 +85,6 @@ class FileAudioDevice : public AudioDeviceGeneric { int32_t StopRecording() override; bool Recording() const override; - // Microphone Automatic Gain Control (AGC) - int32_t SetAGC(bool enable) override; - bool AGC() const override; - // Audio mixer initialization int32_t InitSpeaker() override; bool SpeakerIsInitialized() const override; diff --git a/modules/audio_device/include/audio_device.h b/modules/audio_device/include/audio_device.h index 377a64cb39..62b929f9db 100644 --- a/modules/audio_device/include/audio_device.h +++ b/modules/audio_device/include/audio_device.h @@ -101,9 +101,9 @@ class AudioDeviceModule : public rtc::RefCountInterface { virtual int32_t StopRecording() = 0; virtual bool Recording() const = 0; - // Microphone Automatic Gain Control (AGC) - virtual int32_t SetAGC(bool enable) = 0; - virtual bool AGC() const = 0; + // TODO(bugs.webrtc.org/7306): deprecated (to be removed). + virtual int32_t SetAGC(bool enable) { return -1; } + virtual bool AGC() const { return false; } // Audio mixer initialization virtual int32_t InitSpeaker() = 0; diff --git a/modules/audio_device/include/fake_audio_device.h b/modules/audio_device/include/fake_audio_device.h index e8e3f2cf33..834b3b724e 100644 --- a/modules/audio_device/include/fake_audio_device.h +++ b/modules/audio_device/include/fake_audio_device.h @@ -41,7 +41,6 @@ class FakeAudioDeviceModule : public AudioDeviceModule { int32_t SetRecordingDevice(uint16_t index) override { return 0; } int32_t SetRecordingDevice(WindowsDeviceType device) override { return 0; } int32_t SetStereoRecording(bool enable) override { return 0; } - int32_t SetAGC(bool enable) override { return 0; } int32_t StopRecording() override { return 0; } int32_t Terminate() override { return 0; } diff --git a/modules/audio_device/ios/audio_device_ios.h b/modules/audio_device/ios/audio_device_ios.h index 8f30889835..d97e124a56 100644 --- a/modules/audio_device/ios/audio_device_ios.h +++ b/modules/audio_device/ios/audio_device_ios.h @@ -93,8 +93,6 @@ class AudioDeviceIOS : public AudioDeviceGeneric, AudioDeviceModule::AudioLayer& audioLayer) const override; int32_t PlayoutIsAvailable(bool& available) override; int32_t RecordingIsAvailable(bool& available) override; - int32_t SetAGC(bool enable) override; - bool AGC() const override; int16_t PlayoutDevices() override; int16_t RecordingDevices() override; int32_t PlayoutDeviceName(uint16_t index, diff --git a/modules/audio_device/ios/audio_device_not_implemented_ios.mm b/modules/audio_device/ios/audio_device_not_implemented_ios.mm index 2022dddcb1..2e99aea97e 100644 --- a/modules/audio_device/ios/audio_device_not_implemented_ios.mm +++ b/modules/audio_device/ios/audio_device_not_implemented_ios.mm @@ -143,17 +143,6 @@ int32_t AudioDeviceIOS::StereoPlayout(bool& enabled) const { return 0; } -int32_t AudioDeviceIOS::SetAGC(bool enable) { - if (enable) { - RTC_NOTREACHED() << "Should never be called"; - } - return -1; -} - -bool AudioDeviceIOS::AGC() const { - return false; -} - int32_t AudioDeviceIOS::MicrophoneVolumeIsAvailable(bool& available) { available = false; return 0; diff --git a/modules/audio_device/linux/audio_device_alsa_linux.cc b/modules/audio_device/linux/audio_device_alsa_linux.cc index 1e4d1f50c8..68d3311e5e 100644 --- a/modules/audio_device/linux/audio_device_alsa_linux.cc +++ b/modules/audio_device/linux/audio_device_alsa_linux.cc @@ -90,7 +90,6 @@ AudioDeviceLinuxALSA::AudioDeviceLinuxALSA() _playing(false), _recIsInitialized(false), _playIsInitialized(false), - _AGC(false), _recordingDelay(0), _playoutDelay(0) { memset(_oldKeyState, 0, sizeof(_oldKeyState)); @@ -519,16 +518,6 @@ int32_t AudioDeviceLinuxALSA::StereoPlayout(bool& enabled) const { return 0; } -int32_t AudioDeviceLinuxALSA::SetAGC(bool enable) { - _AGC = enable; - - return 0; -} - -bool AudioDeviceLinuxALSA::AGC() const { - return _AGC; -} - int32_t AudioDeviceLinuxALSA::MicrophoneVolumeIsAvailable(bool& available) { bool wasInitialized = _mixerManager.MicrophoneIsInitialized(); @@ -1593,19 +1582,6 @@ bool AudioDeviceLinuxALSA::RecThreadProcess() { _ptrAudioBuffer->SetRecordedBuffer(_recordingBuffer, _recordingFramesIn10MS); - uint32_t currentMicLevel = 0; - uint32_t newMicLevel = 0; - - if (AGC()) { - // store current mic level in the audio buffer if AGC is enabled - if (MicrophoneVolume(currentMicLevel) == 0) { - if (currentMicLevel == 0xffffffff) - currentMicLevel = 100; - // this call does not affect the actual microphone volume - _ptrAudioBuffer->SetCurrentMicLevel(currentMicLevel); - } - } - // calculate delay _playoutDelay = 0; _recordingDelay = 0; @@ -1640,18 +1616,6 @@ bool AudioDeviceLinuxALSA::RecThreadProcess() { UnLock(); _ptrAudioBuffer->DeliverRecordedData(); Lock(); - - if (AGC()) { - newMicLevel = _ptrAudioBuffer->NewMicLevel(); - if (newMicLevel != 0) { - // The VQE will only deliver non-zero microphone levels when a - // change is needed. Set this new mic level (received from the - // observer as return value in the callback). - if (SetMicrophoneVolume(newMicLevel) == -1) - RTC_LOG(LS_WARNING) - << "the required modification of the microphone volume failed"; - } - } } } diff --git a/modules/audio_device/linux/audio_device_alsa_linux.h b/modules/audio_device/linux/audio_device_alsa_linux.h index f05547b37a..602da014a5 100644 --- a/modules/audio_device/linux/audio_device_alsa_linux.h +++ b/modules/audio_device/linux/audio_device_alsa_linux.h @@ -79,10 +79,6 @@ public: int32_t StopRecording() override; bool Recording() const override; - // Microphone Automatic Gain Control (AGC) - int32_t SetAGC(bool enable) override; - bool AGC() const override; - // Audio mixer initialization int32_t InitSpeaker() override; bool SpeakerIsInitialized() const override; @@ -191,7 +187,6 @@ private: bool _playing; bool _recIsInitialized; bool _playIsInitialized; - bool _AGC; snd_pcm_sframes_t _recordingDelay; snd_pcm_sframes_t _playoutDelay; diff --git a/modules/audio_device/linux/audio_device_pulse_linux.cc b/modules/audio_device/linux/audio_device_pulse_linux.cc index 9d3b80b857..ee3ea72329 100644 --- a/modules/audio_device/linux/audio_device_pulse_linux.cc +++ b/modules/audio_device/linux/audio_device_pulse_linux.cc @@ -49,7 +49,6 @@ AudioDeviceLinuxPulse::AudioDeviceLinuxPulse() _stopRec(false), _startPlay(false), _stopPlay(false), - _AGC(false), update_speaker_volume_at_startup_(false), _sndCardPlayDelay(0), _sndCardRecDelay(0), @@ -579,18 +578,6 @@ int32_t AudioDeviceLinuxPulse::StereoPlayout(bool& enabled) const { return 0; } -int32_t AudioDeviceLinuxPulse::SetAGC(bool enable) { - rtc::CritScope lock(&_critSect); - _AGC = enable; - - return 0; -} - -bool AudioDeviceLinuxPulse::AGC() const { - rtc::CritScope lock(&_critSect); - return _AGC; -} - int32_t AudioDeviceLinuxPulse::MicrophoneVolumeIsAvailable(bool& available) { RTC_DCHECK(thread_checker_.CalledOnValidThread()); bool wasInitialized = _mixerManager.MicrophoneIsInitialized(); @@ -1964,20 +1951,10 @@ int32_t AudioDeviceLinuxPulse::ReadRecordedData(const void* bufferData, int32_t AudioDeviceLinuxPulse::ProcessRecordedData(int8_t* bufferData, uint32_t bufferSizeInSamples, uint32_t recDelay) - RTC_EXCLUSIVE_LOCKS_REQUIRED(_critSect) { - uint32_t currentMicLevel(0); - uint32_t newMicLevel(0); + RTC_EXCLUSIVE_LOCKS_REQUIRED(_critSect) { _ptrAudioBuffer->SetRecordedBuffer(bufferData, bufferSizeInSamples); - if (AGC()) { - // Store current mic level in the audio buffer if AGC is enabled - if (MicrophoneVolume(currentMicLevel) == 0) { - // This call does not affect the actual microphone volume - _ptrAudioBuffer->SetCurrentMicLevel(currentMicLevel); - } - } - const uint32_t clockDrift(0); // TODO(andrew): this is a temporary hack, to avoid non-causal far- and // near-end signals at the AEC for PulseAudio. I think the system delay is @@ -2001,22 +1978,6 @@ int32_t AudioDeviceLinuxPulse::ProcessRecordedData(int8_t* bufferData, return -1; } - if (AGC()) { - newMicLevel = _ptrAudioBuffer->NewMicLevel(); - if (newMicLevel != 0) { - // The VQE will only deliver non-zero microphone levels when a - // change is needed. - // Set this new mic level (received from the observer as return - // value in the callback). - RTC_LOG(LS_VERBOSE) << "AGC change of volume: old=" << currentMicLevel - << " => new=" << newMicLevel; - if (SetMicrophoneVolume(newMicLevel) == -1) { - RTC_LOG(LS_WARNING) - << "the required modification of the microphone volume failed"; - } - } - } - return 0; } diff --git a/modules/audio_device/linux/audio_device_pulse_linux.h b/modules/audio_device/linux/audio_device_pulse_linux.h index 73195c790f..9aadfbe0df 100644 --- a/modules/audio_device/linux/audio_device_pulse_linux.h +++ b/modules/audio_device/linux/audio_device_pulse_linux.h @@ -141,10 +141,6 @@ public: int32_t StopRecording() override; bool Recording() const override; - // Microphone Automatic Gain Control (AGC) - int32_t SetAGC(bool enable) override; - bool AGC() const override; - // Audio mixer initialization int32_t InitSpeaker() override; bool SpeakerIsInitialized() const override; @@ -289,7 +285,6 @@ private: bool _stopRec; bool _startPlay; bool _stopPlay; - bool _AGC; bool update_speaker_volume_at_startup_; uint32_t _sndCardPlayDelay; diff --git a/modules/audio_device/mac/audio_device_mac.cc b/modules/audio_device/mac/audio_device_mac.cc index 110bfcd0d5..2fbe878419 100644 --- a/modules/audio_device/mac/audio_device_mac.cc +++ b/modules/audio_device/mac/audio_device_mac.cc @@ -132,7 +132,6 @@ AudioDeviceMac::AudioDeviceMac() _playing(false), _recIsInitialized(false), _playIsInitialized(false), - _AGC(false), _renderDeviceIsAlive(1), _captureDeviceIsAlive(1), _twoDevices(true), @@ -149,8 +148,7 @@ AudioDeviceMac::AudioDeviceMac() _paRenderBuffer(NULL), _captureBufSizeSamples(0), _renderBufSizeSamples(0), - prev_key_state_(), - get_mic_volume_counter_ms_(0) { + prev_key_state_() { RTC_LOG(LS_INFO) << __FUNCTION__ << " created"; RTC_DCHECK(&_stopEvent != NULL); @@ -337,8 +335,6 @@ AudioDeviceGeneric::InitStatus AudioDeviceMac::Init() { } } - get_mic_volume_counter_ms_ = 0; - _initialized = true; return InitStatus::OK; @@ -733,16 +729,6 @@ int32_t AudioDeviceMac::StereoPlayout(bool& enabled) const { return 0; } -int32_t AudioDeviceMac::SetAGC(bool enable) { - _AGC = enable; - - return 0; -} - -bool AudioDeviceMac::AGC() const { - return _AGC; -} - int32_t AudioDeviceMac::MicrophoneVolumeIsAvailable(bool& available) { bool wasInitialized = _mixerManager.MicrophoneIsInitialized(); @@ -2494,8 +2480,6 @@ bool AudioDeviceMac::CaptureWorkerThread() { // TODO(xians): what if the returned size is incorrect? if (size == ENGINE_REC_BUF_SIZE_IN_SAMPLES) { - uint32_t currentMicLevel(0); - uint32_t newMicLevel(0); int32_t msecOnPlaySide; int32_t msecOnRecordSide; @@ -2515,43 +2499,12 @@ bool AudioDeviceMac::CaptureWorkerThread() { // store the recorded buffer (no action will be taken if the // #recorded samples is not a full buffer) _ptrAudioBuffer->SetRecordedBuffer((int8_t*)&recordBuffer, (uint32_t)size); - - if (AGC()) { - // Use mod to ensure we check the volume on the first pass. - if (get_mic_volume_counter_ms_ % kGetMicVolumeIntervalMs == 0) { - get_mic_volume_counter_ms_ = 0; - // store current mic level in the audio buffer if AGC is enabled - if (MicrophoneVolume(currentMicLevel) == 0) { - // this call does not affect the actual microphone volume - _ptrAudioBuffer->SetCurrentMicLevel(currentMicLevel); - } - } - get_mic_volume_counter_ms_ += kBufferSizeMs; - } - _ptrAudioBuffer->SetVQEData(msecOnPlaySide, msecOnRecordSide, 0); - _ptrAudioBuffer->SetTypingStatus(KeyPressed()); // deliver recorded samples at specified sample rate, mic level etc. // to the observer using callback _ptrAudioBuffer->DeliverRecordedData(); - - if (AGC()) { - newMicLevel = _ptrAudioBuffer->NewMicLevel(); - if (newMicLevel != 0) { - // The VQE will only deliver non-zero microphone levels when - // a change is needed. - // Set this new mic level (received from the observer as return - // value in the callback). - RTC_LOG(LS_VERBOSE) << "AGC change of volume: old=" << currentMicLevel - << " => new=" << newMicLevel; - if (SetMicrophoneVolume(newMicLevel) == -1) { - RTC_LOG(LS_WARNING) - << "the required modification of the microphone volume failed"; - } - } - } } return true; diff --git a/modules/audio_device/mac/audio_device_mac.h b/modules/audio_device/mac/audio_device_mac.h index 8dece72739..5cbdae2837 100644 --- a/modules/audio_device/mac/audio_device_mac.h +++ b/modules/audio_device/mac/audio_device_mac.h @@ -107,10 +107,6 @@ class AudioDeviceMac : public AudioDeviceGeneric { virtual int32_t StopRecording(); virtual bool Recording() const; - // Microphone Automatic Gain Control (AGC) - virtual int32_t SetAGC(bool enable); - virtual bool AGC() const; - // Audio mixer initialization virtual int32_t InitSpeaker(); virtual bool SpeakerIsInitialized() const; @@ -294,7 +290,6 @@ class AudioDeviceMac : public AudioDeviceGeneric { bool _playing; bool _recIsInitialized; bool _playIsInitialized; - bool _AGC; // Atomically set varaibles int32_t _renderDeviceIsAlive; @@ -335,8 +330,6 @@ class AudioDeviceMac : public AudioDeviceGeneric { // Typing detection // 0x5c is key "9", after that comes function keys. bool prev_key_state_[0x5d]; - - int get_mic_volume_counter_ms_; }; } // namespace webrtc diff --git a/modules/audio_device/win/audio_device_core_win.cc b/modules/audio_device/win/audio_device_core_win.cc index cf7df4b5de..526d41c08f 100644 --- a/modules/audio_device/win/audio_device_core_win.cc +++ b/modules/audio_device/win/audio_device_core_win.cc @@ -417,9 +417,6 @@ AudioDeviceWindowsCore::AudioDeviceWindowsCore() _hShutdownCaptureEvent(NULL), _hRenderStartedEvent(NULL), _hCaptureStartedEvent(NULL), - _hGetCaptureVolumeThread(NULL), - _hSetCaptureVolumeThread(NULL), - _hSetCaptureVolumeEvent(NULL), _hMmTask(NULL), _initialized(false), _recording(false), @@ -428,15 +425,13 @@ AudioDeviceWindowsCore::AudioDeviceWindowsCore() _playIsInitialized(false), _speakerIsInitialized(false), _microphoneIsInitialized(false), - _AGC(false), _playBufDelay(80), _usingInputDeviceIndex(false), _usingOutputDeviceIndex(false), _inputDevice(AudioDeviceModule::kDefaultCommunicationDevice), _outputDevice(AudioDeviceModule::kDefaultCommunicationDevice), _inputDeviceIndex(0), - _outputDeviceIndex(0), - _newMicLevel(0) { + _outputDeviceIndex(0) { RTC_LOG(LS_INFO) << __FUNCTION__ << " created"; assert(_comInit.succeeded()); @@ -487,7 +482,6 @@ AudioDeviceWindowsCore::AudioDeviceWindowsCore() _hShutdownCaptureEvent = CreateEvent(NULL, TRUE, FALSE, NULL); _hRenderStartedEvent = CreateEvent(NULL, FALSE, FALSE, NULL); _hCaptureStartedEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - _hSetCaptureVolumeEvent = CreateEvent(NULL, FALSE, FALSE, NULL); _perfCounterFreq.QuadPart = 1; _perfCounterFactor = 0.0; @@ -575,11 +569,6 @@ AudioDeviceWindowsCore::~AudioDeviceWindowsCore() { _hShutdownCaptureEvent = NULL; } - if (NULL != _hSetCaptureVolumeEvent) { - CloseHandle(_hSetCaptureVolumeEvent); - _hSetCaptureVolumeEvent = NULL; - } - if (_avrtLibrary) { BOOL freeOK = FreeLibrary(_avrtLibrary); if (!freeOK) { @@ -1270,25 +1259,6 @@ int32_t AudioDeviceWindowsCore::StereoPlayout(bool& enabled) const { return 0; } -// ---------------------------------------------------------------------------- -// SetAGC -// ---------------------------------------------------------------------------- - -int32_t AudioDeviceWindowsCore::SetAGC(bool enable) { - rtc::CritScope lock(&_critSect); - _AGC = enable; - return 0; -} - -// ---------------------------------------------------------------------------- -// AGC -// ---------------------------------------------------------------------------- - -bool AudioDeviceWindowsCore::AGC() const { - rtc::CritScope lock(&_critSect); - return _AGC; -} - // ---------------------------------------------------------------------------- // MicrophoneVolumeIsAvailable // ---------------------------------------------------------------------------- @@ -2423,21 +2393,6 @@ int32_t AudioDeviceWindowsCore::StartRecording() { // Set thread priority to highest possible SetThreadPriority(_hRecThread, THREAD_PRIORITY_TIME_CRITICAL); - assert(_hGetCaptureVolumeThread == NULL); - _hGetCaptureVolumeThread = - CreateThread(NULL, 0, GetCaptureVolumeThread, this, 0, NULL); - if (_hGetCaptureVolumeThread == NULL) { - RTC_LOG(LS_ERROR) << "failed to create the volume getter thread"; - return -1; - } - - assert(_hSetCaptureVolumeThread == NULL); - _hSetCaptureVolumeThread = - CreateThread(NULL, 0, SetCaptureVolumeThread, this, 0, NULL); - if (_hSetCaptureVolumeThread == NULL) { - RTC_LOG(LS_ERROR) << "failed to create the volume setter thread"; - return -1; - } } // critScoped DWORD ret = WaitForSingleObject(_hCaptureStartedEvent, 1000); @@ -2490,24 +2445,6 @@ int32_t AudioDeviceWindowsCore::StopRecording() { } else { RTC_LOG(LS_VERBOSE) << "webrtc_core_audio_capture_thread is now closed"; } - - ret = WaitForSingleObject(_hGetCaptureVolumeThread, 2000); - if (ret != WAIT_OBJECT_0) { - // the thread did not stop as it should - RTC_LOG(LS_ERROR) << "failed to close down volume getter thread"; - err = -1; - } else { - RTC_LOG(LS_VERBOSE) << "volume getter thread is now closed"; - } - - ret = WaitForSingleObject(_hSetCaptureVolumeThread, 2000); - if (ret != WAIT_OBJECT_0) { - // the thread did not stop as it should - RTC_LOG(LS_ERROR) << "failed to close down volume setter thread"; - err = -1; - } else { - RTC_LOG(LS_VERBOSE) << "volume setter thread is now closed"; - } _Lock(); ResetEvent(_hShutdownCaptureEvent); // Must be manually reset. @@ -2523,12 +2460,6 @@ int32_t AudioDeviceWindowsCore::StopRecording() { CloseHandle(_hRecThread); _hRecThread = NULL; - CloseHandle(_hGetCaptureVolumeThread); - _hGetCaptureVolumeThread = NULL; - - CloseHandle(_hSetCaptureVolumeThread); - _hSetCaptureVolumeThread = NULL; - if (_builtInAecEnabled) { assert(_dmo != NULL); // This is necessary. Otherwise the DMO can generate garbage render @@ -2736,72 +2667,6 @@ DWORD WINAPI AudioDeviceWindowsCore::WSAPICaptureThreadPollDMO(LPVOID context) { ->DoCaptureThreadPollDMO(); } -DWORD WINAPI AudioDeviceWindowsCore::GetCaptureVolumeThread(LPVOID context) { - return reinterpret_cast(context) - ->DoGetCaptureVolumeThread(); -} - -DWORD WINAPI AudioDeviceWindowsCore::SetCaptureVolumeThread(LPVOID context) { - return reinterpret_cast(context) - ->DoSetCaptureVolumeThread(); -} - -DWORD AudioDeviceWindowsCore::DoGetCaptureVolumeThread() { - HANDLE waitObject = _hShutdownCaptureEvent; - - while (1) { - if (AGC()) { - uint32_t currentMicLevel = 0; - if (MicrophoneVolume(currentMicLevel) == 0) { - // This doesn't set the system volume, just stores it. - _Lock(); - if (_ptrAudioBuffer) { - _ptrAudioBuffer->SetCurrentMicLevel(currentMicLevel); - } - _UnLock(); - } - } - - DWORD waitResult = - WaitForSingleObject(waitObject, GET_MIC_VOLUME_INTERVAL_MS); - switch (waitResult) { - case WAIT_OBJECT_0: // _hShutdownCaptureEvent - return 0; - case WAIT_TIMEOUT: // timeout notification - break; - default: // unexpected error - RTC_LOG(LS_WARNING) << "unknown wait termination on get volume thread"; - return 1; - } - } -} - -DWORD AudioDeviceWindowsCore::DoSetCaptureVolumeThread() { - HANDLE waitArray[2] = {_hShutdownCaptureEvent, _hSetCaptureVolumeEvent}; - - while (1) { - DWORD waitResult = WaitForMultipleObjects(2, waitArray, FALSE, INFINITE); - switch (waitResult) { - case WAIT_OBJECT_0: // _hShutdownCaptureEvent - return 0; - case WAIT_OBJECT_0 + 1: // _hSetCaptureVolumeEvent - break; - default: // unexpected error - RTC_LOG(LS_WARNING) << "unknown wait termination on set volume thread"; - return 1; - } - - _Lock(); - uint32_t newMicLevel = _newMicLevel; - _UnLock(); - - if (SetMicrophoneVolume(newMicLevel) == -1) { - RTC_LOG(LS_WARNING) - << "the required modification of the microphone volume failed"; - } - } -} - // ---------------------------------------------------------------------------- // DoRenderThread // ---------------------------------------------------------------------------- @@ -3188,8 +3053,6 @@ DWORD AudioDeviceWindowsCore::DoCaptureThreadPollDMO() { break; } - // TODO(andrew): handle AGC. - if (bytesProduced > 0) { const int kSamplesProduced = bytesProduced / _recAudioFrameSize; // TODO(andrew): verify that this is always satisfied. It might @@ -3451,20 +3314,6 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread() { syncBufIndex -= _recBlockSize; sndCardRecDelay -= 10; } - - if (_AGC) { - uint32_t newMicLevel = _ptrAudioBuffer->NewMicLevel(); - if (newMicLevel != 0) { - // The VQE will only deliver non-zero microphone levels when a - // change is needed. Set this new mic level (received from the - // observer as return value in the callback). - RTC_LOG(LS_VERBOSE) << "AGC change of volume: new=" << newMicLevel; - // We store this outside of the audio buffer to avoid - // having it overwritten by the getter thread. - _newMicLevel = newMicLevel; - SetEvent(_hSetCaptureVolumeEvent); - } - } } else { // If GetBuffer returns AUDCLNT_E_BUFFER_ERROR, the thread consuming the // audio samples must wait for the next processing pass. The client diff --git a/modules/audio_device/win/audio_device_core_win.h b/modules/audio_device/win/audio_device_core_win.h index 30e767b2f2..b5c2b72d30 100644 --- a/modules/audio_device/win/audio_device_core_win.h +++ b/modules/audio_device/win/audio_device_core_win.h @@ -129,10 +129,6 @@ public: virtual int32_t StopRecording(); virtual bool Recording() const; - // Microphone Automatic Gain Control (AGC) - virtual int32_t SetAGC(bool enable); - virtual bool AGC() const; - // Audio mixer initialization virtual int32_t InitSpeaker(); virtual bool SpeakerIsInitialized() const; @@ -201,12 +197,6 @@ private: // thread functions static DWORD WINAPI WSAPIRenderThread(LPVOID context); DWORD DoRenderThread(); - static DWORD WINAPI GetCaptureVolumeThread(LPVOID context); - DWORD DoGetCaptureVolumeThread(); - - static DWORD WINAPI SetCaptureVolumeThread(LPVOID context); - DWORD DoSetCaptureVolumeThread(); - void _Lock() { _critSect.Enter(); }; void _UnLock() { _critSect.Leave(); }; @@ -274,10 +264,6 @@ private: // thread functions HANDLE _hCaptureStartedEvent; HANDLE _hShutdownCaptureEvent; - HANDLE _hGetCaptureVolumeThread; - HANDLE _hSetCaptureVolumeThread; - HANDLE _hSetCaptureVolumeEvent; - HANDLE _hMmTask; UINT _playAudioFrameSize; @@ -318,12 +304,8 @@ private: uint16_t _inputDeviceIndex; uint16_t _outputDeviceIndex; - bool _AGC; - uint16_t _playBufDelay; - uint16_t _newMicLevel; - mutable char _str[512]; }; diff --git a/pc/test/fakeaudiocapturemodule.cc b/pc/test/fakeaudiocapturemodule.cc index b54fc4b3c6..a129ae5f73 100644 --- a/pc/test/fakeaudiocapturemodule.cc +++ b/pc/test/fakeaudiocapturemodule.cc @@ -233,16 +233,6 @@ bool FakeAudioCaptureModule::Recording() const { return recording_; } -int32_t FakeAudioCaptureModule::SetAGC(bool /*enable*/) { - // No AGC but not needed since audio is pregenerated. Return success. - return 0; -} - -bool FakeAudioCaptureModule::AGC() const { - RTC_NOTREACHED(); - return 0; -} - int32_t FakeAudioCaptureModule::InitSpeaker() { // No speaker, just playing from file. Return success. return 0; diff --git a/pc/test/fakeaudiocapturemodule.h b/pc/test/fakeaudiocapturemodule.h index 7c899198b7..db346d06c8 100644 --- a/pc/test/fakeaudiocapturemodule.h +++ b/pc/test/fakeaudiocapturemodule.h @@ -90,9 +90,6 @@ class FakeAudioCaptureModule int32_t StopRecording() override; bool Recording() const override; - int32_t SetAGC(bool enable) override; - bool AGC() const override; - int32_t InitSpeaker() override; bool SpeakerIsInitialized() const override; int32_t InitMicrophone() override;