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

Side by Side Diff: webrtc/media/engine/apm_helpers.cc

Issue 2681033010: Remove usage of VoEAudioProcessing from WVoE/MC. (Closed)
Patch Set: one more Created 3 years, 10 months 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
« no previous file with comments | « webrtc/media/engine/apm_helpers.h ('k') | webrtc/media/engine/apm_helpers_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/media/engine/apm_helpers.h"
12
13 #include "webrtc/base/logging.h"
14 #include "webrtc/modules/audio_device/include/audio_device.h"
15 #include "webrtc/modules/audio_processing/include/audio_processing.h"
16 #include "webrtc/voice_engine/transmit_mixer.h"
17
18 namespace webrtc {
19 namespace apm_helpers {
20
21 AgcConfig GetAgcConfig(AudioProcessing* apm) {
22 RTC_DCHECK(apm);
23 AgcConfig result;
24 result.targetLeveldBOv = apm->gain_control()->target_level_dbfs();
25 result.digitalCompressionGaindB = apm->gain_control()->compression_gain_db();
26 result.limiterEnable = apm->gain_control()->is_limiter_enabled();
27 return result;
28 }
29
30 void SetAgcConfig(AudioProcessing* apm,
31 const AgcConfig& config) {
32 RTC_DCHECK(apm);
33 GainControl* gc = apm->gain_control();
34 if (gc->set_target_level_dbfs(config.targetLeveldBOv) != 0) {
35 LOG(LS_ERROR) << "Failed to set target level: " << config.targetLeveldBOv;
36 }
37 if (gc->set_compression_gain_db(config.digitalCompressionGaindB) != 0) {
38 LOG(LS_ERROR) << "Failed to set compression gain: "
39 << config.digitalCompressionGaindB;
40 }
41 if (gc->enable_limiter(config.limiterEnable) != 0) {
42 LOG(LS_ERROR) << "Failed to set limiter on/off: " << config.limiterEnable;
43 }
44 }
45
46 void SetAgcStatus(AudioProcessing* apm,
47 AudioDeviceModule* adm,
48 bool enable,
49 AgcModes mode) {
50 RTC_DCHECK(apm);
51 RTC_DCHECK(adm);
52 #if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID)
53 RTC_DCHECK_EQ(kAgcFixedDigital, mode);
54 GainControl::Mode agc_mode = GainControl::kFixedDigital;
55 #else
56 RTC_DCHECK_EQ(kAgcAdaptiveAnalog, mode);
57 GainControl::Mode agc_mode = GainControl::kAdaptiveAnalog;
58 #endif
59 GainControl* gc = apm->gain_control();
60 if (gc->set_mode(agc_mode) != 0) {
61 LOG(LS_ERROR) << "Failed to set AGC mode: " << agc_mode;
62 return;
63 }
64 if (gc->Enable(enable) != 0) {
65 LOG(LS_ERROR) << "Failed to enable/disable AGC: " << enable;
66 return;
67 }
68 // Set AGC state in the ADM when adaptive AGC mode has been selected.
69 if (adm->SetAGC(enable && agc_mode == GainControl::kAdaptiveAnalog) != 0) {
70 LOG(LS_ERROR) << "Failed to set AGC mode in ADM: " << enable;
71 return;
72 }
73 LOG(LS_INFO) << "AGC set to " << enable << " with mode " << mode;
74 }
75
76 void SetEcStatus(AudioProcessing* apm,
77 bool enable,
78 EcModes mode) {
79 RTC_DCHECK(apm);
80 RTC_DCHECK(mode == kEcConference || mode == kEcAecm) << "mode: " << mode;
81 EchoCancellation* ec = apm->echo_cancellation();
82 EchoControlMobile* ecm = apm->echo_control_mobile();
83 if (mode == kEcConference) {
84 // Disable the AECM before enabling the AEC.
85 if (enable && ecm->is_enabled() && ecm->Enable(false) != 0) {
86 LOG(LS_ERROR) << "Failed to disable AECM.";
87 return;
88 }
89 if (ec->Enable(enable) != 0) {
90 LOG(LS_ERROR) << "Failed to enable/disable AEC: " << enable;
91 return;
92 }
93 if (ec->set_suppression_level(EchoCancellation::kHighSuppression)
94 != 0) {
95 LOG(LS_ERROR) << "Failed to set high AEC aggressiveness.";
96 return;
97 }
98 } else {
99 // Disable the AEC before enabling the AECM.
100 if (enable && ec->is_enabled() && ec->Enable(false) != 0) {
101 LOG(LS_ERROR) << "Failed to disable AEC.";
102 return;
103 }
104 if (ecm->Enable(enable) != 0) {
105 LOG(LS_ERROR) << "Failed to enable/disable AECM: " << enable;
106 return;
107 }
108 }
109 LOG(LS_INFO) << "Echo control set to " << enable << " with mode " << mode;
110 }
111
112 void SetEcMetricsStatus(AudioProcessing* apm, bool enable) {
113 RTC_DCHECK(apm);
114 if ((apm->echo_cancellation()->enable_metrics(enable) != 0) ||
115 (apm->echo_cancellation()->enable_delay_logging(enable) != 0)) {
116 LOG(LS_ERROR) << "Failed to enable/disable EC metrics: " << enable;
117 return;
118 }
119 LOG(LS_INFO) << "EC metrics set to " << enable;
120 }
121
122 void SetAecmMode(AudioProcessing* apm, bool enable) {
123 RTC_DCHECK(apm);
124 EchoControlMobile* ecm = apm->echo_control_mobile();
125 RTC_DCHECK_EQ(EchoControlMobile::kSpeakerphone, ecm->routing_mode());
126 if (ecm->enable_comfort_noise(enable) != 0) {
127 LOG(LS_ERROR) << "Failed to enable/disable CNG: " << enable;
128 return;
129 }
130 LOG(LS_INFO) << "CNG set to " << enable;
131 }
132
133 void SetNsStatus(AudioProcessing* apm, bool enable) {
134 RTC_DCHECK(apm);
135 NoiseSuppression* ns = apm->noise_suppression();
136 if (ns->set_level(NoiseSuppression::kHigh) != 0) {
137 LOG(LS_ERROR) << "Failed to set high NS level.";
138 return;
139 }
140 if (ns->Enable(enable) != 0) {
141 LOG(LS_ERROR) << "Failed to enable/disable NS: " << enable;
142 return;
143 }
144 LOG(LS_INFO) << "NS set to " << enable;
145 }
146
147 void SetTypingDetectionStatus(AudioProcessing* apm, bool enable) {
148 RTC_DCHECK(apm);
149 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
150 // Typing detection takes place in TransmitMixer::PrepareDemux() and
151 // TransmitMixer::TypingDetection(). The typing detection algorithm takes as
152 // input two booleans:
153 // 1. A signal whether a key was pressed during the audio frame.
154 // 2. Whether VAD is active or not.
155 // TransmitMixer will not even call the detector if APM has set kVadUnknown in
156 // the audio frame after near end processing, so enabling/disabling VAD is
157 // sufficient for turning typing detection on/off.
158 // TODO(solenberg): Rather than relying on a side effect, consider forcing the
159 // feature on/off in TransmitMixer.
160 VoiceDetection* vd = apm->voice_detection();
161 if (vd->Enable(enable)) {
162 LOG(LS_ERROR) << "Failed to enable/disable VAD: " << enable;
163 return;
164 }
165 if (vd->set_likelihood(VoiceDetection::kVeryLowLikelihood)) {
166 LOG(LS_ERROR) << "Failed to set low VAD likelihood.";
167 return;
168 }
169 LOG(LS_INFO) << "VAD set to " << enable << " for typing detection.";
170 #endif
171 }
172 } // namespace apm_helpers
173 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/media/engine/apm_helpers.h ('k') | webrtc/media/engine/apm_helpers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698