webrtc_m130/media/engine/apm_helpers.cc
Sam Zackrisson f0d1c03c31 Add replacement interface for webrtc::GainConrol
The pointer-to-submodule interfaces are being removed.
This CL:
1) introduces AudioProcessing::Config::GainController1 with most config,
2) adds functions to APM for setting and getting analog gain,
3) creates a temporary GainControlConfigProxy to support the transition
   to the new config.
4) Moves the lock references in GainControlForExperimentalAgc and
   GainControlImpl into the GainControlConfigProxy, as it becomes the
   sole AGC object with functionality exposed to the client.

Bug: webrtc:9947, webrtc:9878
Change-Id: Ic31e15e9bb26d6497a92b77874e0b6cab21ff2b2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/126485
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27316}
2019-03-27 15:19:41 +00:00

66 lines
2.3 KiB
C++

/*
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "media/engine/apm_helpers.h"
#include "modules/audio_processing/include/audio_processing.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
namespace webrtc {
namespace apm_helpers {
void Init(AudioProcessing* apm) {
RTC_DCHECK(apm);
constexpr int kMinVolumeLevel = 0;
constexpr int kMaxVolumeLevel = 255;
AudioProcessing::Config config = apm->GetConfig();
#if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID)
config.gain_controller1.mode = config.gain_controller1.kFixedDigital;
#else
config.gain_controller1.mode = config.gain_controller1.kAdaptiveAnalog;
#endif
RTC_LOG(LS_INFO) << "Setting AGC mode to " << config.gain_controller1.mode;
// This is the initialization which used to happen in VoEBase::Init(), but
// which is not covered by the WVoE::ApplyOptions().
config.gain_controller1.analog_level_minimum = kMinVolumeLevel;
config.gain_controller1.analog_level_maximum = kMaxVolumeLevel;
apm->ApplyConfig(config);
}
void SetEcStatus(AudioProcessing* apm, bool enable, EcModes mode) {
RTC_DCHECK(apm);
RTC_DCHECK(mode == kEcConference || mode == kEcAecm) << "mode: " << mode;
AudioProcessing::Config apm_config = apm->GetConfig();
apm_config.echo_canceller.enabled = enable;
apm_config.echo_canceller.mobile_mode = (mode == kEcAecm);
apm_config.echo_canceller.legacy_moderate_suppression_level = false;
apm->ApplyConfig(apm_config);
RTC_LOG(LS_INFO) << "Echo control set to " << enable << " with mode " << mode;
}
void SetNsStatus(AudioProcessing* apm, bool enable) {
RTC_DCHECK(apm);
NoiseSuppression* ns = apm->noise_suppression();
if (ns->set_level(NoiseSuppression::kHigh) != 0) {
RTC_LOG(LS_ERROR) << "Failed to set high NS level.";
return;
}
if (ns->Enable(enable) != 0) {
RTC_LOG(LS_ERROR) << "Failed to enable/disable NS: " << enable;
return;
}
RTC_LOG(LS_INFO) << "NS set to " << enable;
}
} // namespace apm_helpers
} // namespace webrtc