blob: 63a4ed768a9684ab84b43913ffc300d553808ebb [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.orgc80d9d92012-02-06 10:11:25 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000011#include "webrtc/voice_engine/voe_audio_processing_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000013#include "webrtc/modules/audio_processing/include/audio_processing.h"
14#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
15#include "webrtc/system_wrappers/interface/logging.h"
16#include "webrtc/system_wrappers/interface/trace.h"
17#include "webrtc/voice_engine/channel.h"
18#include "webrtc/voice_engine/include/voe_errors.h"
19#include "webrtc/voice_engine/transmit_mixer.h"
20#include "webrtc/voice_engine/voice_engine_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
andrew@webrtc.org02d71742012-04-24 19:47:00 +000022// TODO(andrew): move to a common place.
andrew@webrtc.org55c0d4a2012-08-29 02:13:12 +000023#define WEBRTC_VOICE_INIT_CHECK() \
24 do { \
25 if (!_shared->statistics().Initialized()) { \
26 _shared->SetLastError(VE_NOT_INITED, kTraceError); \
27 return -1; \
28 } \
29 } while (0)
30
31#define WEBRTC_VOICE_INIT_CHECK_BOOL() \
32 do { \
33 if (!_shared->statistics().Initialized()) { \
34 _shared->SetLastError(VE_NOT_INITED, kTraceError); \
35 return false; \
36 } \
37 } while (0)
38
niklase@google.com470e71d2011-07-07 08:21:25 +000039namespace webrtc {
40
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000041#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
andrew@webrtc.org80124742012-03-08 17:54:24 +000042static const EcModes kDefaultEcMode = kEcAecm;
43#else
44static const EcModes kDefaultEcMode = kEcAec;
45#endif
46
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000047VoEAudioProcessing* VoEAudioProcessing::GetInterface(VoiceEngine* voiceEngine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000048#ifndef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000049 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000050#else
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000051 if (NULL == voiceEngine) {
52 return NULL;
53 }
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000054 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
tommi@webrtc.orga990e122012-04-26 15:28:22 +000055 s->AddRef();
56 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000057#endif
58}
59
60#ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API
tommi@webrtc.org851becd2012-04-04 14:57:19 +000061VoEAudioProcessingImpl::VoEAudioProcessingImpl(voe::SharedData* shared)
andrew@webrtc.org55c0d4a2012-08-29 02:13:12 +000062 : _isAecMode(kDefaultEcMode == kEcAec),
63 _shared(shared) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000064 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000065 "VoEAudioProcessingImpl::VoEAudioProcessingImpl() - ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +000066}
67
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000068VoEAudioProcessingImpl::~VoEAudioProcessingImpl() {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000069 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000070 "VoEAudioProcessingImpl::~VoEAudioProcessingImpl() - dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000071}
72
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000073int VoEAudioProcessingImpl::SetNsStatus(bool enable, NsModes mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000074 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000075 "SetNsStatus(enable=%d, mode=%d)", enable, mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000076#ifdef WEBRTC_VOICE_ENGINE_NR
tommi@webrtc.org851becd2012-04-04 14:57:19 +000077 if (!_shared->statistics().Initialized()) {
78 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000079 return -1;
80 }
niklase@google.com470e71d2011-07-07 08:21:25 +000081
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000082 NoiseSuppression::Level nsLevel = kDefaultNsMode;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000083 switch (mode) {
niklase@google.com470e71d2011-07-07 08:21:25 +000084 case kNsDefault:
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000085 nsLevel = kDefaultNsMode;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000086 break;
niklase@google.com470e71d2011-07-07 08:21:25 +000087 case kNsUnchanged:
tommi@webrtc.org851becd2012-04-04 14:57:19 +000088 nsLevel = _shared->audio_processing()->noise_suppression()->level();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000089 break;
niklase@google.com470e71d2011-07-07 08:21:25 +000090 case kNsConference:
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000091 nsLevel = NoiseSuppression::kHigh;
92 break;
niklase@google.com470e71d2011-07-07 08:21:25 +000093 case kNsLowSuppression:
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000094 nsLevel = NoiseSuppression::kLow;
95 break;
niklase@google.com470e71d2011-07-07 08:21:25 +000096 case kNsModerateSuppression:
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +000097 nsLevel = NoiseSuppression::kModerate;
98 break;
niklase@google.com470e71d2011-07-07 08:21:25 +000099 case kNsHighSuppression:
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000100 nsLevel = NoiseSuppression::kHigh;
101 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102 case kNsVeryHighSuppression:
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000103 nsLevel = NoiseSuppression::kVeryHigh;
104 break;
105 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000107 if (_shared->audio_processing()->noise_suppression()->
108 set_level(nsLevel) != 0) {
109 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000110 "SetNsStatus() failed to set Ns mode");
niklase@google.com470e71d2011-07-07 08:21:25 +0000111 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000112 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000113 if (_shared->audio_processing()->noise_suppression()->Enable(enable) != 0) {
114 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000115 "SetNsStatus() failed to set Ns state");
116 return -1;
117 }
118
119 return 0;
120#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000121 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000122 "SetNsStatus() Ns is not supported");
123 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000124#endif
125}
126
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000127int VoEAudioProcessingImpl::GetNsStatus(bool& enabled, NsModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000128 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000129 "GetNsStatus(enabled=?, mode=?)");
niklase@google.com470e71d2011-07-07 08:21:25 +0000130#ifdef WEBRTC_VOICE_ENGINE_NR
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000131 if (!_shared->statistics().Initialized()) {
132 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000133 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000134 }
135
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000136 enabled = _shared->audio_processing()->noise_suppression()->is_enabled();
137 NoiseSuppression::Level nsLevel =
138 _shared->audio_processing()->noise_suppression()->level();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000139
140 switch (nsLevel) {
141 case NoiseSuppression::kLow:
142 mode = kNsLowSuppression;
143 break;
144 case NoiseSuppression::kModerate:
145 mode = kNsModerateSuppression;
146 break;
147 case NoiseSuppression::kHigh:
148 mode = kNsHighSuppression;
149 break;
150 case NoiseSuppression::kVeryHigh:
151 mode = kNsVeryHighSuppression;
152 break;
153 }
154
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000155 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000156 "GetNsStatus() => enabled=% d, mode=%d", enabled, mode);
157 return 0;
158#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000159 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000160 "GetNsStatus() Ns is not supported");
161 return -1;
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000162#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000163}
164
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000165int VoEAudioProcessingImpl::SetAgcStatus(bool enable, AgcModes mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000166 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000167 "SetAgcStatus(enable=%d, mode=%d)", enable, mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000168#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000169 if (!_shared->statistics().Initialized()) {
170 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000171 return -1;
172 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000174#if defined(WEBRTC_IOS) || defined(ATA) || defined(WEBRTC_ANDROID)
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000175 if (mode == kAgcAdaptiveAnalog) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000176 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000177 "SetAgcStatus() invalid Agc mode for mobile device");
178 return -1;
179 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000180#endif
181
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000182 GainControl::Mode agcMode = kDefaultAgcMode;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000183 switch (mode) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000184 case kAgcDefault:
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000185 agcMode = kDefaultAgcMode;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000186 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000187 case kAgcUnchanged:
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000188 agcMode = _shared->audio_processing()->gain_control()->mode();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000189 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000190 case kAgcFixedDigital:
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000191 agcMode = GainControl::kFixedDigital;
192 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000193 case kAgcAdaptiveAnalog:
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000194 agcMode = GainControl::kAdaptiveAnalog;
195 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000196 case kAgcAdaptiveDigital:
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000197 agcMode = GainControl::kAdaptiveDigital;
198 break;
199 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000201 if (_shared->audio_processing()->gain_control()->set_mode(agcMode) != 0) {
202 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000203 "SetAgcStatus() failed to set Agc mode");
niklase@google.com470e71d2011-07-07 08:21:25 +0000204 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000205 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000206 if (_shared->audio_processing()->gain_control()->Enable(enable) != 0) {
207 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000208 "SetAgcStatus() failed to set Agc state");
209 return -1;
210 }
211
212 if (agcMode != GainControl::kFixedDigital) {
213 // Set Agc state in the ADM when adaptive Agc mode has been selected.
214 // Note that we also enable the ADM Agc when Adaptive Digital mode is
215 // used since we want to be able to provide the APM with updated mic
216 // levels when the user modifies the mic level manually.
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000217 if (_shared->audio_device()->SetAGC(enable) != 0) {
218 _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000219 kTraceWarning, "SetAgcStatus() failed to set Agc mode");
220 }
221 }
222
223 return 0;
224#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000225 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000226 "SetAgcStatus() Agc is not supported");
227 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000228#endif
229}
230
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000231int VoEAudioProcessingImpl::GetAgcStatus(bool& enabled, AgcModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000232 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000233 "GetAgcStatus(enabled=?, mode=?)");
niklase@google.com470e71d2011-07-07 08:21:25 +0000234#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000235 if (!_shared->statistics().Initialized()) {
236 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000237 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000238 }
239
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000240 enabled = _shared->audio_processing()->gain_control()->is_enabled();
sjlee@webrtc.orgb4c441a2013-03-25 11:12:20 +0000241 GainControl::Mode agcMode =
242 _shared->audio_processing()->gain_control()->mode();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000243
244 switch (agcMode) {
245 case GainControl::kFixedDigital:
246 mode = kAgcFixedDigital;
247 break;
248 case GainControl::kAdaptiveAnalog:
249 mode = kAgcAdaptiveAnalog;
250 break;
251 case GainControl::kAdaptiveDigital:
252 mode = kAgcAdaptiveDigital;
253 break;
254 }
255
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000256 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000257 "GetAgcStatus() => enabled=%d, mode=%d", enabled, mode);
258 return 0;
259#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000260 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000261 "GetAgcStatus() Agc is not supported");
262 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000263#endif
264}
265
pbos@webrtc.org92135212013-05-14 08:31:39 +0000266int VoEAudioProcessingImpl::SetAgcConfig(AgcConfig config) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000267 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000268 "SetAgcConfig()");
niklase@google.com470e71d2011-07-07 08:21:25 +0000269#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000270 if (!_shared->statistics().Initialized()) {
271 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000272 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000273 }
274
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000275 if (_shared->audio_processing()->gain_control()->set_target_level_dbfs(
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000276 config.targetLeveldBOv) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000277 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000278 "SetAgcConfig() failed to set target peak |level|"
279 " (or envelope) of the Agc");
280 return -1;
281 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000282 if (_shared->audio_processing()->gain_control()->set_compression_gain_db(
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000283 config.digitalCompressionGaindB) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000284 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000285 "SetAgcConfig() failed to set the range in |gain| "
286 "the digital compression stage may apply");
287 return -1;
288 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000289 if (_shared->audio_processing()->gain_control()->enable_limiter(
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000290 config.limiterEnable) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000291 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000292 "SetAgcConfig() failed to set hard limiter to the signal");
293 return -1;
294 }
295
296 return 0;
297#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000298 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000299 "SetAgcConfig() EC is not supported");
300 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000301#endif
302}
303
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000304int VoEAudioProcessingImpl::GetAgcConfig(AgcConfig& config) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000305 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000306 "GetAgcConfig(config=?)");
niklase@google.com470e71d2011-07-07 08:21:25 +0000307#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000308 if (!_shared->statistics().Initialized()) {
309 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000310 return -1;
311 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000312
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000313 config.targetLeveldBOv =
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000314 _shared->audio_processing()->gain_control()->target_level_dbfs();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000315 config.digitalCompressionGaindB =
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000316 _shared->audio_processing()->gain_control()->compression_gain_db();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000317 config.limiterEnable =
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000318 _shared->audio_processing()->gain_control()->is_limiter_enabled();
niklase@google.com470e71d2011-07-07 08:21:25 +0000319
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000320 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000321 "GetAgcConfig() => targetLeveldBOv=%u, "
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000322 "digitalCompressionGaindB=%u, limiterEnable=%d",
323 config.targetLeveldBOv,
324 config.digitalCompressionGaindB,
325 config.limiterEnable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000326
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000327 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000328#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000329 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000330 "GetAgcConfig() EC is not supported");
331 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000332#endif
333}
334
335int VoEAudioProcessingImpl::SetRxNsStatus(int channel,
336 bool enable,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000337 NsModes mode) {
andrew@webrtc.org50419b02012-11-14 19:07:54 +0000338 LOG_API3(channel, enable, mode);
andrew@webrtc.orgddcc9422012-11-06 18:39:40 +0000339#ifdef WEBRTC_VOICE_ENGINE_NR
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000340 if (!_shared->statistics().Initialized()) {
341 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000342 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000343 }
344
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000345 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
346 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000347 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000348 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000349 "SetRxNsStatus() failed to locate channel");
350 return -1;
351 }
352 return channelPtr->SetRxNsStatus(enable, mode);
353#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000354 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.orgddcc9422012-11-06 18:39:40 +0000355 "SetRxNsStatus() NS is not supported");
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000356 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000357#endif
358}
359
360int VoEAudioProcessingImpl::GetRxNsStatus(int channel,
361 bool& enabled,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000362 NsModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000363 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000364 "GetRxNsStatus(channel=%d, enable=?, mode=?)", channel);
andrew@webrtc.orgddcc9422012-11-06 18:39:40 +0000365#ifdef WEBRTC_VOICE_ENGINE_NR
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000366 if (!_shared->statistics().Initialized()) {
367 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000368 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000369 }
370
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000371 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
372 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000373 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000374 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000375 "GetRxNsStatus() failed to locate channel");
376 return -1;
377 }
378 return channelPtr->GetRxNsStatus(enabled, mode);
379#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000380 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.orgddcc9422012-11-06 18:39:40 +0000381 "GetRxNsStatus() NS is not supported");
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000382 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000383#endif
384}
385
386int VoEAudioProcessingImpl::SetRxAgcStatus(int channel,
387 bool enable,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000388 AgcModes mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000389 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000390 "SetRxAgcStatus(channel=%d, enable=%d, mode=%d)",
391 channel, (int)enable, (int)mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000392#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000393 if (!_shared->statistics().Initialized()) {
394 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000395 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000396 }
397
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000398 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
399 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000400 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000401 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000402 "SetRxAgcStatus() failed to locate channel");
403 return -1;
404 }
405 return channelPtr->SetRxAgcStatus(enable, mode);
406#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000407 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000408 "SetRxAgcStatus() Agc is not supported");
409 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000410#endif
411}
412
413int VoEAudioProcessingImpl::GetRxAgcStatus(int channel,
414 bool& enabled,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000415 AgcModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000416 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000417 "GetRxAgcStatus(channel=%d, enable=?, mode=?)", channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000418#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000419 if (!_shared->statistics().Initialized()) {
420 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000421 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000422 }
423
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000424 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
425 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000426 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000427 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000428 "GetRxAgcStatus() failed to locate channel");
429 return -1;
430 }
431 return channelPtr->GetRxAgcStatus(enabled, mode);
432#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000433 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000434 "GetRxAgcStatus() Agc is not supported");
435 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000436#endif
437}
438
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000439int VoEAudioProcessingImpl::SetRxAgcConfig(int channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000440 AgcConfig config) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000441 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000442 "SetRxAgcConfig(channel=%d)", channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000443#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000444 if (!_shared->statistics().Initialized()) {
445 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000446 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000447 }
448
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000449 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
450 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000451 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000452 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000453 "SetRxAgcConfig() failed to locate channel");
454 return -1;
455 }
456 return channelPtr->SetRxAgcConfig(config);
457#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000458 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000459 "SetRxAgcConfig() Agc is not supported");
460 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000461#endif
462}
463
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000464int VoEAudioProcessingImpl::GetRxAgcConfig(int channel, AgcConfig& config) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000465 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000466 "GetRxAgcConfig(channel=%d)", channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000467#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000468 if (!_shared->statistics().Initialized()) {
469 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000470 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000471 }
472
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000473 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
474 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000475 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000476 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000477 "GetRxAgcConfig() failed to locate channel");
478 return -1;
479 }
480 return channelPtr->GetRxAgcConfig(config);
481#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000482 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000483 "GetRxAgcConfig() Agc is not supported");
484 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000485#endif
486}
487
andrew@webrtc.org55c0d4a2012-08-29 02:13:12 +0000488bool VoEAudioProcessing::DriftCompensationSupported() {
489#if defined(WEBRTC_DRIFT_COMPENSATION_SUPPORTED)
490 return true;
491#else
492 return false;
493#endif
494}
495
496int VoEAudioProcessingImpl::EnableDriftCompensation(bool enable) {
andrew@webrtc.org50419b02012-11-14 19:07:54 +0000497 LOG_API1(enable);
andrew@webrtc.org55c0d4a2012-08-29 02:13:12 +0000498 WEBRTC_VOICE_INIT_CHECK();
499
500 if (!DriftCompensationSupported()) {
501 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
502 "Drift compensation is not supported on this platform.");
503 return -1;
504 }
505
506 EchoCancellation* aec = _shared->audio_processing()->echo_cancellation();
507 if (aec->enable_drift_compensation(enable) != 0) {
508 _shared->SetLastError(VE_APM_ERROR, kTraceError,
509 "aec->enable_drift_compensation() failed");
510 return -1;
511 }
512 return 0;
513}
514
515bool VoEAudioProcessingImpl::DriftCompensationEnabled() {
andrew@webrtc.org50419b02012-11-14 19:07:54 +0000516 LOG_API0();
andrew@webrtc.org55c0d4a2012-08-29 02:13:12 +0000517 WEBRTC_VOICE_INIT_CHECK_BOOL();
518
519 EchoCancellation* aec = _shared->audio_processing()->echo_cancellation();
520 return aec->is_drift_compensation_enabled();
521}
522
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000523int VoEAudioProcessingImpl::SetEcStatus(bool enable, EcModes mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000524 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000525 "SetEcStatus(enable=%d, mode=%d)", enable, mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000526#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000527 if (!_shared->statistics().Initialized()) {
528 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000529 return -1;
530 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000531
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000532 // AEC mode
533 if ((mode == kEcDefault) ||
534 (mode == kEcConference) ||
535 (mode == kEcAec) ||
536 ((mode == kEcUnchanged) &&
537 (_isAecMode == true))) {
538 if (enable) {
539 // Disable the AECM before enable the AEC
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000540 if (_shared->audio_processing()->echo_control_mobile()->is_enabled()) {
541 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000542 "SetEcStatus() disable AECM before enabling AEC");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000543 if (_shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000544 Enable(false) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000545 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000546 "SetEcStatus() failed to disable AECM");
547 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000548 }
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000549 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000550 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000551 if (_shared->audio_processing()->echo_cancellation()->Enable(enable) != 0) {
552 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000553 "SetEcStatus() failed to set AEC state");
554 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000555 }
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000556 if (mode == kEcConference) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000557 if (_shared->audio_processing()->echo_cancellation()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000558 set_suppression_level(EchoCancellation::kHighSuppression) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000559 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000560 "SetEcStatus() failed to set aggressiveness to high");
niklase@google.com470e71d2011-07-07 08:21:25 +0000561 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000562 }
563 } else {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000564 if (_shared->audio_processing()->echo_cancellation()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000565 set_suppression_level(
566 EchoCancellation::kModerateSuppression) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000567 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000568 "SetEcStatus() failed to set aggressiveness to moderate");
niklase@google.com470e71d2011-07-07 08:21:25 +0000569 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000570 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000571 }
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000572
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000573 _isAecMode = true;
574 } else if ((mode == kEcAecm) ||
575 ((mode == kEcUnchanged) &&
576 (_isAecMode == false))) {
577 if (enable) {
578 // Disable the AEC before enable the AECM
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000579 if (_shared->audio_processing()->echo_cancellation()->is_enabled()) {
580 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000581 "SetEcStatus() disable AEC before enabling AECM");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000582 if (_shared->audio_processing()->echo_cancellation()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000583 Enable(false) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000584 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000585 "SetEcStatus() failed to disable AEC");
586 return -1;
587 }
588 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000589 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000590 if (_shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000591 Enable(enable) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000592 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000593 "SetEcStatus() failed to set AECM state");
594 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000595 }
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000596 _isAecMode = false;
597 } else {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000598 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000599 "SetEcStatus() invalid EC mode");
niklase@google.com470e71d2011-07-07 08:21:25 +0000600 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000601 }
602
603 return 0;
604#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000605 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000606 "SetEcStatus() EC is not supported");
607 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000608#endif
609}
610
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000611int VoEAudioProcessingImpl::GetEcStatus(bool& enabled, EcModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000612 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000613 "GetEcStatus()");
niklase@google.com470e71d2011-07-07 08:21:25 +0000614#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000615 if (!_shared->statistics().Initialized()) {
616 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000617 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000618 }
619
620 if (_isAecMode == true) {
621 mode = kEcAec;
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000622 enabled = _shared->audio_processing()->echo_cancellation()->is_enabled();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000623 } else {
624 mode = kEcAecm;
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000625 enabled = _shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000626 is_enabled();
627 }
628
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000629 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000630 "GetEcStatus() => enabled=%i, mode=%i",
631 enabled, (int)mode);
632 return 0;
633#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000634 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000635 "GetEcStatus() EC is not supported");
636 return -1;
637#endif
638}
639
640void VoEAudioProcessingImpl::SetDelayOffsetMs(int offset) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000641 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000642 "SetDelayOffsetMs(offset = %d)", offset);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000643 _shared->audio_processing()->set_delay_offset_ms(offset);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000644}
645
646int VoEAudioProcessingImpl::DelayOffsetMs() {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000647 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000648 "DelayOffsetMs()");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000649 return _shared->audio_processing()->delay_offset_ms();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000650}
651
652int VoEAudioProcessingImpl::SetAecmMode(AecmModes mode, bool enableCNG) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000653 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000654 "SetAECMMode(mode = %d)", mode);
655#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000656 if (!_shared->statistics().Initialized()) {
657 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000658 return -1;
659 }
660
661 EchoControlMobile::RoutingMode aecmMode(
662 EchoControlMobile::kQuietEarpieceOrHeadset);
663
664 switch (mode) {
665 case kAecmQuietEarpieceOrHeadset:
666 aecmMode = EchoControlMobile::kQuietEarpieceOrHeadset;
667 break;
668 case kAecmEarpiece:
669 aecmMode = EchoControlMobile::kEarpiece;
670 break;
671 case kAecmLoudEarpiece:
672 aecmMode = EchoControlMobile::kLoudEarpiece;
673 break;
674 case kAecmSpeakerphone:
675 aecmMode = EchoControlMobile::kSpeakerphone;
676 break;
677 case kAecmLoudSpeakerphone:
678 aecmMode = EchoControlMobile::kLoudSpeakerphone;
679 break;
680 }
681
682
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000683 if (_shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000684 set_routing_mode(aecmMode) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000685 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000686 "SetAECMMode() failed to set AECM routing mode");
687 return -1;
688 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000689 if (_shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000690 enable_comfort_noise(enableCNG) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000691 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000692 "SetAECMMode() failed to set comfort noise state for AECM");
693 return -1;
694 }
695
696 return 0;
697#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000698 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000699 "SetAECMMode() EC is not supported");
700 return -1;
701#endif
702}
703
704int VoEAudioProcessingImpl::GetAecmMode(AecmModes& mode, bool& enabledCNG) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000705 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000706 "GetAECMMode(mode=?)");
707#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000708 if (!_shared->statistics().Initialized()) {
709 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000710 return -1;
711 }
712
713 enabledCNG = false;
714
715 EchoControlMobile::RoutingMode aecmMode =
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000716 _shared->audio_processing()->echo_control_mobile()->routing_mode();
717 enabledCNG = _shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000718 is_comfort_noise_enabled();
719
720 switch (aecmMode) {
721 case EchoControlMobile::kQuietEarpieceOrHeadset:
722 mode = kAecmQuietEarpieceOrHeadset;
723 break;
724 case EchoControlMobile::kEarpiece:
725 mode = kAecmEarpiece;
726 break;
727 case EchoControlMobile::kLoudEarpiece:
728 mode = kAecmLoudEarpiece;
729 break;
730 case EchoControlMobile::kSpeakerphone:
731 mode = kAecmSpeakerphone;
732 break;
733 case EchoControlMobile::kLoudSpeakerphone:
734 mode = kAecmLoudSpeakerphone;
735 break;
736 }
737
738 return 0;
739#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000740 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000741 "GetAECMMode() EC is not supported");
742 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000743#endif
744}
745
andrew@webrtc.org369166a2012-04-24 18:38:03 +0000746int VoEAudioProcessingImpl::EnableHighPassFilter(bool enable) {
747 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
748 "EnableHighPassFilter(%d)", enable);
749 if (_shared->audio_processing()->high_pass_filter()->Enable(enable) !=
750 AudioProcessing::kNoError) {
751 _shared->SetLastError(VE_APM_ERROR, kTraceError,
752 "HighPassFilter::Enable() failed.");
753 return -1;
754 }
755
756 return 0;
757}
758
759bool VoEAudioProcessingImpl::IsHighPassFilterEnabled() {
760 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
761 "IsHighPassFilterEnabled()");
762 return _shared->audio_processing()->high_pass_filter()->is_enabled();
763}
764
niklase@google.com470e71d2011-07-07 08:21:25 +0000765int VoEAudioProcessingImpl::RegisterRxVadObserver(
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000766 int channel,
767 VoERxVadCallback& observer) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000768 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000769 "RegisterRxVadObserver()");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000770 if (!_shared->statistics().Initialized()) {
771 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000772 return -1;
773 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000774 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
775 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000776 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000777 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000778 "RegisterRxVadObserver() failed to locate channel");
779 return -1;
780 }
781 return channelPtr->RegisterRxVadObserver(observer);
niklase@google.com470e71d2011-07-07 08:21:25 +0000782}
783
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000784int VoEAudioProcessingImpl::DeRegisterRxVadObserver(int channel) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000785 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000786 "DeRegisterRxVadObserver()");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000787 if (!_shared->statistics().Initialized()) {
788 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000789 return -1;
790 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000791 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
792 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000793 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000794 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000795 "DeRegisterRxVadObserver() failed to locate channel");
796 return -1;
797 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000798
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000799 return channelPtr->DeRegisterRxVadObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000800}
801
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000802int VoEAudioProcessingImpl::VoiceActivityIndicator(int channel) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000803 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000804 "VoiceActivityIndicator(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000805 if (!_shared->statistics().Initialized()) {
806 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000807 return -1;
808 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000809
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000810 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
811 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000812 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000813 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000814 "DeRegisterRxVadObserver() failed to locate channel");
815 return -1;
816 }
817 int activity(-1);
818 channelPtr->VoiceActivityIndicator(activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000819
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000820 return activity;
niklase@google.com470e71d2011-07-07 08:21:25 +0000821}
822
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000823int VoEAudioProcessingImpl::SetEcMetricsStatus(bool enable) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000824 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000825 "SetEcMetricsStatus(enable=%d)", enable);
bjornv@google.com0beae672011-09-28 14:08:19 +0000826#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000827 if (!_shared->statistics().Initialized()) {
828 _shared->SetLastError(VE_NOT_INITED, kTraceError);
bjornv@google.com0beae672011-09-28 14:08:19 +0000829 return -1;
830 }
831
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000832 if ((_shared->audio_processing()->echo_cancellation()->enable_metrics(enable)
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000833 != 0) ||
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000834 (_shared->audio_processing()->echo_cancellation()->enable_delay_logging(
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000835 enable) != 0)) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000836 _shared->SetLastError(VE_APM_ERROR, kTraceError,
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000837 "SetEcMetricsStatus() unable to set EC metrics mode");
bjornv@google.com0beae672011-09-28 14:08:19 +0000838 return -1;
839 }
840 return 0;
841#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000842 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000843 "SetEcStatus() EC is not supported");
bjornv@google.com0beae672011-09-28 14:08:19 +0000844 return -1;
845#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000846}
847
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000848int VoEAudioProcessingImpl::GetEcMetricsStatus(bool& enabled) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000849 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000850 "GetEcMetricsStatus(enabled=?)");
bjornv@google.com0beae672011-09-28 14:08:19 +0000851#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000852 if (!_shared->statistics().Initialized()) {
853 _shared->SetLastError(VE_NOT_INITED, kTraceError);
bjornv@google.com0beae672011-09-28 14:08:19 +0000854 return -1;
855 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000856
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000857 bool echo_mode =
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000858 _shared->audio_processing()->echo_cancellation()->are_metrics_enabled();
859 bool delay_mode = _shared->audio_processing()->echo_cancellation()->
860 is_delay_logging_enabled();
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000861
862 if (echo_mode != delay_mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000863 _shared->SetLastError(VE_APM_ERROR, kTraceError,
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000864 "GetEcMetricsStatus() delay logging and echo mode are not the same");
865 return -1;
866 }
867
868 enabled = echo_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000869
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000870 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000871 "GetEcMetricsStatus() => enabled=%d", enabled);
bjornv@google.com0beae672011-09-28 14:08:19 +0000872 return 0;
873#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000874 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000875 "SetEcStatus() EC is not supported");
bjornv@google.com0beae672011-09-28 14:08:19 +0000876 return -1;
877#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000878}
879
880int VoEAudioProcessingImpl::GetEchoMetrics(int& ERL,
881 int& ERLE,
882 int& RERL,
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000883 int& A_NLP) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000884 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000885 "GetEchoMetrics(ERL=?, ERLE=?, RERL=?, A_NLP=?)");
niklase@google.com470e71d2011-07-07 08:21:25 +0000886#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000887 if (!_shared->statistics().Initialized()) {
888 _shared->SetLastError(VE_NOT_INITED, kTraceError);
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000889 return -1;
890 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000891 if (!_shared->audio_processing()->echo_cancellation()->is_enabled()) {
892 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000893 "GetEchoMetrics() AudioProcessingModule AEC is not enabled");
894 return -1;
895 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000896
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000897 // Get Echo Metrics from Audio Processing Module.
898 EchoCancellation::Metrics echoMetrics;
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000899 if (_shared->audio_processing()->echo_cancellation()->GetMetrics(
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000900 &echoMetrics)) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000901 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000902 "GetEchoMetrics(), AudioProcessingModule metrics error");
903 return -1;
904 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000905
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000906 // Echo quality metrics.
907 ERL = echoMetrics.echo_return_loss.instant;
908 ERLE = echoMetrics.echo_return_loss_enhancement.instant;
909 RERL = echoMetrics.residual_echo_return_loss.instant;
910 A_NLP = echoMetrics.a_nlp.instant;
niklase@google.com470e71d2011-07-07 08:21:25 +0000911
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000912 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000913 "GetEchoMetrics() => ERL=%d, ERLE=%d, RERL=%d, A_NLP=%d",
914 ERL, ERLE, RERL, A_NLP);
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000915 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000916#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000917 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000918 "SetEcStatus() EC is not supported");
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000919 return -1;
920#endif
921}
922
923int VoEAudioProcessingImpl::GetEcDelayMetrics(int& delay_median,
924 int& delay_std) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000925 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000926 "GetEcDelayMetrics(median=?, std=?)");
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000927#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000928 if (!_shared->statistics().Initialized()) {
929 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000930 return -1;
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000931 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000932 if (!_shared->audio_processing()->echo_cancellation()->is_enabled()) {
933 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000934 "GetEcDelayMetrics() AudioProcessingModule AEC is not enabled");
935 return -1;
936 }
937
938 int median = 0;
939 int std = 0;
940 // Get delay-logging values from Audio Processing Module.
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000941 if (_shared->audio_processing()->echo_cancellation()->GetDelayMetrics(
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000942 &median, &std)) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000943 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000944 "GetEcDelayMetrics(), AudioProcessingModule delay-logging "
945 "error");
946 return -1;
947 }
948
949 // EC delay-logging metrics
950 delay_median = median;
951 delay_std = std;
952
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000953 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000954 "GetEcDelayMetrics() => delay_median=%d, delay_std=%d",
955 delay_median, delay_std);
956 return 0;
957#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000958 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000959 "SetEcStatus() EC is not supported");
bjornv@webrtc.org3765bd22011-10-17 08:49:23 +0000960 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000961#endif
962}
963
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000964int VoEAudioProcessingImpl::StartDebugRecording(const char* fileNameUTF8) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000965 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000966 "StartDebugRecording()");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000967 if (!_shared->statistics().Initialized()) {
968 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000969 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000970 }
971
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000972 return _shared->audio_processing()->StartDebugRecording(fileNameUTF8);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000973}
974
henrikg@webrtc.org863b5362013-12-06 16:05:17 +0000975int VoEAudioProcessingImpl::StartDebugRecording(FILE* file_handle) {
976 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
977 "StartDebugRecording()");
978 if (!_shared->statistics().Initialized()) {
979 _shared->SetLastError(VE_NOT_INITED, kTraceError);
980 return -1;
981 }
982
983 return _shared->audio_processing()->StartDebugRecording(file_handle);
984}
985
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000986int VoEAudioProcessingImpl::StopDebugRecording() {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000987 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000988 "StopDebugRecording()");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000989 if (!_shared->statistics().Initialized()) {
990 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000991 return -1;
992 }
993
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000994 return _shared->audio_processing()->StopDebugRecording();
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000995}
996
997int VoEAudioProcessingImpl::SetTypingDetectionStatus(bool enable) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000998 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +0000999 "SetTypingDetectionStatus()");
andrew@webrtc.org0851df82013-06-19 17:03:47 +00001000#if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION)
1001 NOT_SUPPORTED(_shared->statistics());
1002#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001003 if (!_shared->statistics().Initialized()) {
1004 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +00001005 return -1;
1006 }
1007
1008 // Just use the VAD state to determine if we should enable typing detection
1009 // or not
1010
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001011 if (_shared->audio_processing()->voice_detection()->Enable(enable)) {
1012 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +00001013 "SetTypingDetectionStatus() failed to set VAD state");
1014 return -1;
1015 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001016 if (_shared->audio_processing()->voice_detection()->set_likelihood(
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +00001017 VoiceDetection::kVeryLowLikelihood)) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001018 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +00001019 "SetTypingDetectionStatus() failed to set VAD likelihood to low");
1020 return -1;
1021 }
1022
1023 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001024#endif
1025}
1026
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +00001027int VoEAudioProcessingImpl::GetTypingDetectionStatus(bool& enabled) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001028 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +00001029 "GetTypingDetectionStatus()");
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001030 if (!_shared->statistics().Initialized()) {
1031 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +00001032 return -1;
1033 }
1034 // Just use the VAD state to determine if we should enable typing
1035 // detection or not
niklase@google.com470e71d2011-07-07 08:21:25 +00001036
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001037 enabled = _shared->audio_processing()->voice_detection()->is_enabled();
niklase@google.com470e71d2011-07-07 08:21:25 +00001038
andrew@webrtc.org8b111eb2012-03-06 19:50:12 +00001039 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001040}
1041
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00001042
1043int VoEAudioProcessingImpl::TimeSinceLastTyping(int &seconds) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001044 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00001045 "TimeSinceLastTyping()");
andrew@webrtc.org0851df82013-06-19 17:03:47 +00001046#if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION)
1047 NOT_SUPPORTED(_shared->statistics());
1048#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001049 if (!_shared->statistics().Initialized()) {
1050 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00001051 return -1;
1052 }
1053 // Check if typing detection is enabled
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001054 bool enabled = _shared->audio_processing()->voice_detection()->is_enabled();
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00001055 if (enabled)
1056 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001057 _shared->transmit_mixer()->TimeSinceLastTyping(seconds);
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00001058 return 0;
1059 }
1060 else
1061 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001062 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00001063 "SetTypingDetectionStatus is not enabled");
1064 return -1;
1065 }
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00001066#endif
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00001067}
1068
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +00001069int VoEAudioProcessingImpl::SetTypingDetectionParameters(int timeWindow,
1070 int costPerTyping,
1071 int reportingThreshold,
niklas.enbom@webrtc.orgf6edfef2012-05-09 13:16:12 +00001072 int penaltyDecay,
1073 int typeEventDelay) {
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001074 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +00001075 "SetTypingDetectionParameters()");
andrew@webrtc.org0851df82013-06-19 17:03:47 +00001076#if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION)
1077 NOT_SUPPORTED(_shared->statistics());
1078#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001079 if (!_shared->statistics().Initialized()) {
1080 _shared->statistics().SetLastError(VE_NOT_INITED, kTraceError);
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +00001081 return -1;
1082 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +00001083 return (_shared->transmit_mixer()->SetTypingDetectionParameters(timeWindow,
niklas.enbom@webrtc.orgf6edfef2012-05-09 13:16:12 +00001084 costPerTyping, reportingThreshold, penaltyDecay, typeEventDelay));
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +00001085#endif
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +00001086}
1087
andrew@webrtc.org02d71742012-04-24 19:47:00 +00001088void VoEAudioProcessingImpl::EnableStereoChannelSwapping(bool enable) {
andrew@webrtc.org50419b02012-11-14 19:07:54 +00001089 LOG_API1(enable);
andrew@webrtc.org02d71742012-04-24 19:47:00 +00001090 _shared->transmit_mixer()->EnableStereoChannelSwapping(enable);
1091}
1092
1093bool VoEAudioProcessingImpl::IsStereoChannelSwappingEnabled() {
andrew@webrtc.org50419b02012-11-14 19:07:54 +00001094 LOG_API0();
andrew@webrtc.org02d71742012-04-24 19:47:00 +00001095 return _shared->transmit_mixer()->IsStereoChannelSwappingEnabled();
1096}
1097
niklase@google.com470e71d2011-07-07 08:21:25 +00001098#endif // #ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API
1099
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +00001100} // namespace webrtc