blob: a310628eec53c149475be200d8497c76dfb068c5 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:251/*
mflodman@webrtc.orgc80d9d92012-02-06 10:11:252 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:253 *
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:3211#include "webrtc/voice_engine/voe_audio_processing_impl.h"
niklase@google.com470e71d2011-07-07 08:21:2512
pbos@webrtc.org956aa7e2013-05-21 13:52:3213#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:2521
andrew@webrtc.org02d71742012-04-24 19:47:0022// TODO(andrew): move to a common place.
andrew@webrtc.org55c0d4a2012-08-29 02:13:1223#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:2539namespace webrtc {
40
sjlee@webrtc.org414fa7f2012-09-11 17:25:4641#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
andrew@webrtc.org80124742012-03-08 17:54:2442static const EcModes kDefaultEcMode = kEcAecm;
43#else
44static const EcModes kDefaultEcMode = kEcAec;
45#endif
46
andrew@webrtc.org8b111eb2012-03-06 19:50:1247VoEAudioProcessing* VoEAudioProcessing::GetInterface(VoiceEngine* voiceEngine) {
niklase@google.com470e71d2011-07-07 08:21:2548#ifndef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API
andrew@webrtc.org8b111eb2012-03-06 19:50:1249 return NULL;
niklase@google.com470e71d2011-07-07 08:21:2550#else
andrew@webrtc.org8b111eb2012-03-06 19:50:1251 if (NULL == voiceEngine) {
52 return NULL;
53 }
tommi@webrtc.org0989fb72013-02-15 15:07:3254 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
tommi@webrtc.orga990e122012-04-26 15:28:2255 s->AddRef();
56 return s;
niklase@google.com470e71d2011-07-07 08:21:2557#endif
58}
59
60#ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API
tommi@webrtc.org851becd2012-04-04 14:57:1961VoEAudioProcessingImpl::VoEAudioProcessingImpl(voe::SharedData* shared)
andrew@webrtc.org55c0d4a2012-08-29 02:13:1262 : _isAecMode(kDefaultEcMode == kEcAec),
63 _shared(shared) {
tommi@webrtc.org851becd2012-04-04 14:57:1964 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:1265 "VoEAudioProcessingImpl::VoEAudioProcessingImpl() - ctor");
niklase@google.com470e71d2011-07-07 08:21:2566}
67
andrew@webrtc.org8b111eb2012-03-06 19:50:1268VoEAudioProcessingImpl::~VoEAudioProcessingImpl() {
tommi@webrtc.org851becd2012-04-04 14:57:1969 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:1270 "VoEAudioProcessingImpl::~VoEAudioProcessingImpl() - dtor");
niklase@google.com470e71d2011-07-07 08:21:2571}
72
andrew@webrtc.org8b111eb2012-03-06 19:50:1273int VoEAudioProcessingImpl::SetNsStatus(bool enable, NsModes mode) {
tommi@webrtc.org851becd2012-04-04 14:57:1974 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:1275 "SetNsStatus(enable=%d, mode=%d)", enable, mode);
niklase@google.com470e71d2011-07-07 08:21:2576#ifdef WEBRTC_VOICE_ENGINE_NR
tommi@webrtc.org851becd2012-04-04 14:57:1977 if (!_shared->statistics().Initialized()) {
78 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:1279 return -1;
80 }
niklase@google.com470e71d2011-07-07 08:21:2581
andrew@webrtc.orgf0a90c32013-03-05 01:12:4982 NoiseSuppression::Level nsLevel = kDefaultNsMode;
andrew@webrtc.org8b111eb2012-03-06 19:50:1283 switch (mode) {
niklase@google.com470e71d2011-07-07 08:21:2584 case kNsDefault:
andrew@webrtc.orgf0a90c32013-03-05 01:12:4985 nsLevel = kDefaultNsMode;
andrew@webrtc.org8b111eb2012-03-06 19:50:1286 break;
niklase@google.com470e71d2011-07-07 08:21:2587 case kNsUnchanged:
tommi@webrtc.org851becd2012-04-04 14:57:1988 nsLevel = _shared->audio_processing()->noise_suppression()->level();
andrew@webrtc.org8b111eb2012-03-06 19:50:1289 break;
niklase@google.com470e71d2011-07-07 08:21:2590 case kNsConference:
andrew@webrtc.org8b111eb2012-03-06 19:50:1291 nsLevel = NoiseSuppression::kHigh;
92 break;
niklase@google.com470e71d2011-07-07 08:21:2593 case kNsLowSuppression:
andrew@webrtc.org8b111eb2012-03-06 19:50:1294 nsLevel = NoiseSuppression::kLow;
95 break;
niklase@google.com470e71d2011-07-07 08:21:2596 case kNsModerateSuppression:
andrew@webrtc.org8b111eb2012-03-06 19:50:1297 nsLevel = NoiseSuppression::kModerate;
98 break;
niklase@google.com470e71d2011-07-07 08:21:2599 case kNsHighSuppression:
andrew@webrtc.org8b111eb2012-03-06 19:50:12100 nsLevel = NoiseSuppression::kHigh;
101 break;
niklase@google.com470e71d2011-07-07 08:21:25102 case kNsVeryHighSuppression:
andrew@webrtc.org8b111eb2012-03-06 19:50:12103 nsLevel = NoiseSuppression::kVeryHigh;
104 break;
105 }
niklase@google.com470e71d2011-07-07 08:21:25106
tommi@webrtc.org851becd2012-04-04 14:57:19107 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:12110 "SetNsStatus() failed to set Ns mode");
niklase@google.com470e71d2011-07-07 08:21:25111 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12112 }
tommi@webrtc.org851becd2012-04-04 14:57:19113 if (_shared->audio_processing()->noise_suppression()->Enable(enable) != 0) {
114 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12115 "SetNsStatus() failed to set Ns state");
116 return -1;
117 }
118
119 return 0;
120#else
tommi@webrtc.org851becd2012-04-04 14:57:19121 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12122 "SetNsStatus() Ns is not supported");
123 return -1;
niklase@google.com470e71d2011-07-07 08:21:25124#endif
125}
126
andrew@webrtc.org8b111eb2012-03-06 19:50:12127int VoEAudioProcessingImpl::GetNsStatus(bool& enabled, NsModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19128 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12129 "GetNsStatus(enabled=?, mode=?)");
niklase@google.com470e71d2011-07-07 08:21:25130#ifdef WEBRTC_VOICE_ENGINE_NR
tommi@webrtc.org851becd2012-04-04 14:57:19131 if (!_shared->statistics().Initialized()) {
132 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25133 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12134 }
135
andrew@webrtc.orgf0a90c32013-03-05 01:12:49136 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:12139
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:19155 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12156 "GetNsStatus() => enabled=% d, mode=%d", enabled, mode);
157 return 0;
158#else
tommi@webrtc.org851becd2012-04-04 14:57:19159 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12160 "GetNsStatus() Ns is not supported");
161 return -1;
andrew@webrtc.org6f9f8172012-03-06 19:03:39162#endif
niklase@google.com470e71d2011-07-07 08:21:25163}
164
andrew@webrtc.org8b111eb2012-03-06 19:50:12165int VoEAudioProcessingImpl::SetAgcStatus(bool enable, AgcModes mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19166 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12167 "SetAgcStatus(enable=%d, mode=%d)", enable, mode);
niklase@google.com470e71d2011-07-07 08:21:25168#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19169 if (!_shared->statistics().Initialized()) {
170 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12171 return -1;
172 }
niklase@google.com470e71d2011-07-07 08:21:25173
sjlee@webrtc.org414fa7f2012-09-11 17:25:46174#if defined(WEBRTC_IOS) || defined(ATA) || defined(WEBRTC_ANDROID)
andrew@webrtc.org8b111eb2012-03-06 19:50:12175 if (mode == kAgcAdaptiveAnalog) {
tommi@webrtc.org851becd2012-04-04 14:57:19176 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12177 "SetAgcStatus() invalid Agc mode for mobile device");
178 return -1;
179 }
niklase@google.com470e71d2011-07-07 08:21:25180#endif
181
andrew@webrtc.orgf0a90c32013-03-05 01:12:49182 GainControl::Mode agcMode = kDefaultAgcMode;
andrew@webrtc.org8b111eb2012-03-06 19:50:12183 switch (mode) {
niklase@google.com470e71d2011-07-07 08:21:25184 case kAgcDefault:
andrew@webrtc.orgf0a90c32013-03-05 01:12:49185 agcMode = kDefaultAgcMode;
andrew@webrtc.org8b111eb2012-03-06 19:50:12186 break;
niklase@google.com470e71d2011-07-07 08:21:25187 case kAgcUnchanged:
andrew@webrtc.orgf0a90c32013-03-05 01:12:49188 agcMode = _shared->audio_processing()->gain_control()->mode();
andrew@webrtc.org8b111eb2012-03-06 19:50:12189 break;
niklase@google.com470e71d2011-07-07 08:21:25190 case kAgcFixedDigital:
andrew@webrtc.org8b111eb2012-03-06 19:50:12191 agcMode = GainControl::kFixedDigital;
192 break;
niklase@google.com470e71d2011-07-07 08:21:25193 case kAgcAdaptiveAnalog:
andrew@webrtc.org8b111eb2012-03-06 19:50:12194 agcMode = GainControl::kAdaptiveAnalog;
195 break;
niklase@google.com470e71d2011-07-07 08:21:25196 case kAgcAdaptiveDigital:
andrew@webrtc.org8b111eb2012-03-06 19:50:12197 agcMode = GainControl::kAdaptiveDigital;
198 break;
199 }
niklase@google.com470e71d2011-07-07 08:21:25200
tommi@webrtc.org851becd2012-04-04 14:57:19201 if (_shared->audio_processing()->gain_control()->set_mode(agcMode) != 0) {
202 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12203 "SetAgcStatus() failed to set Agc mode");
niklase@google.com470e71d2011-07-07 08:21:25204 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12205 }
tommi@webrtc.org851becd2012-04-04 14:57:19206 if (_shared->audio_processing()->gain_control()->Enable(enable) != 0) {
207 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12208 "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:19217 if (_shared->audio_device()->SetAGC(enable) != 0) {
218 _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR,
andrew@webrtc.org8b111eb2012-03-06 19:50:12219 kTraceWarning, "SetAgcStatus() failed to set Agc mode");
220 }
221 }
222
223 return 0;
224#else
tommi@webrtc.org851becd2012-04-04 14:57:19225 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12226 "SetAgcStatus() Agc is not supported");
227 return -1;
niklase@google.com470e71d2011-07-07 08:21:25228#endif
229}
230
andrew@webrtc.org8b111eb2012-03-06 19:50:12231int VoEAudioProcessingImpl::GetAgcStatus(bool& enabled, AgcModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19232 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12233 "GetAgcStatus(enabled=?, mode=?)");
niklase@google.com470e71d2011-07-07 08:21:25234#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19235 if (!_shared->statistics().Initialized()) {
236 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25237 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12238 }
239
andrew@webrtc.orgf0a90c32013-03-05 01:12:49240 enabled = _shared->audio_processing()->gain_control()->is_enabled();
sjlee@webrtc.orgb4c441a2013-03-25 11:12:20241 GainControl::Mode agcMode =
242 _shared->audio_processing()->gain_control()->mode();
andrew@webrtc.org8b111eb2012-03-06 19:50:12243
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:19256 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12257 "GetAgcStatus() => enabled=%d, mode=%d", enabled, mode);
258 return 0;
259#else
tommi@webrtc.org851becd2012-04-04 14:57:19260 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12261 "GetAgcStatus() Agc is not supported");
262 return -1;
niklase@google.com470e71d2011-07-07 08:21:25263#endif
264}
265
pbos@webrtc.org92135212013-05-14 08:31:39266int VoEAudioProcessingImpl::SetAgcConfig(AgcConfig config) {
tommi@webrtc.org851becd2012-04-04 14:57:19267 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12268 "SetAgcConfig()");
niklase@google.com470e71d2011-07-07 08:21:25269#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19270 if (!_shared->statistics().Initialized()) {
271 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25272 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12273 }
274
tommi@webrtc.org851becd2012-04-04 14:57:19275 if (_shared->audio_processing()->gain_control()->set_target_level_dbfs(
andrew@webrtc.org8b111eb2012-03-06 19:50:12276 config.targetLeveldBOv) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19277 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12278 "SetAgcConfig() failed to set target peak |level|"
279 " (or envelope) of the Agc");
280 return -1;
281 }
tommi@webrtc.org851becd2012-04-04 14:57:19282 if (_shared->audio_processing()->gain_control()->set_compression_gain_db(
andrew@webrtc.org8b111eb2012-03-06 19:50:12283 config.digitalCompressionGaindB) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19284 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12285 "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:19289 if (_shared->audio_processing()->gain_control()->enable_limiter(
andrew@webrtc.org8b111eb2012-03-06 19:50:12290 config.limiterEnable) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19291 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12292 "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:19298 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12299 "SetAgcConfig() EC is not supported");
300 return -1;
niklase@google.com470e71d2011-07-07 08:21:25301#endif
302}
303
andrew@webrtc.org8b111eb2012-03-06 19:50:12304int VoEAudioProcessingImpl::GetAgcConfig(AgcConfig& config) {
tommi@webrtc.org851becd2012-04-04 14:57:19305 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12306 "GetAgcConfig(config=?)");
niklase@google.com470e71d2011-07-07 08:21:25307#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19308 if (!_shared->statistics().Initialized()) {
309 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12310 return -1;
311 }
niklase@google.com470e71d2011-07-07 08:21:25312
andrew@webrtc.org8b111eb2012-03-06 19:50:12313 config.targetLeveldBOv =
tommi@webrtc.org851becd2012-04-04 14:57:19314 _shared->audio_processing()->gain_control()->target_level_dbfs();
andrew@webrtc.org8b111eb2012-03-06 19:50:12315 config.digitalCompressionGaindB =
tommi@webrtc.org851becd2012-04-04 14:57:19316 _shared->audio_processing()->gain_control()->compression_gain_db();
andrew@webrtc.org8b111eb2012-03-06 19:50:12317 config.limiterEnable =
tommi@webrtc.org851becd2012-04-04 14:57:19318 _shared->audio_processing()->gain_control()->is_limiter_enabled();
niklase@google.com470e71d2011-07-07 08:21:25319
tommi@webrtc.org851becd2012-04-04 14:57:19320 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25321 "GetAgcConfig() => targetLeveldBOv=%u, "
andrew@webrtc.org8b111eb2012-03-06 19:50:12322 "digitalCompressionGaindB=%u, limiterEnable=%d",
323 config.targetLeveldBOv,
324 config.digitalCompressionGaindB,
325 config.limiterEnable);
niklase@google.com470e71d2011-07-07 08:21:25326
andrew@webrtc.org8b111eb2012-03-06 19:50:12327 return 0;
niklase@google.com470e71d2011-07-07 08:21:25328#else
tommi@webrtc.org851becd2012-04-04 14:57:19329 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12330 "GetAgcConfig() EC is not supported");
331 return -1;
niklase@google.com470e71d2011-07-07 08:21:25332#endif
333}
334
335int VoEAudioProcessingImpl::SetRxNsStatus(int channel,
336 bool enable,
andrew@webrtc.org8b111eb2012-03-06 19:50:12337 NsModes mode) {
andrew@webrtc.org50419b02012-11-14 19:07:54338 LOG_API3(channel, enable, mode);
andrew@webrtc.orgddcc9422012-11-06 18:39:40339#ifdef WEBRTC_VOICE_ENGINE_NR
tommi@webrtc.org851becd2012-04-04 14:57:19340 if (!_shared->statistics().Initialized()) {
341 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25342 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12343 }
344
pbos@webrtc.org676ff1e2013-08-07 17:57:36345 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
346 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12347 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19348 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12349 "SetRxNsStatus() failed to locate channel");
350 return -1;
351 }
352 return channelPtr->SetRxNsStatus(enable, mode);
353#else
tommi@webrtc.org851becd2012-04-04 14:57:19354 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.orgddcc9422012-11-06 18:39:40355 "SetRxNsStatus() NS is not supported");
andrew@webrtc.org8b111eb2012-03-06 19:50:12356 return -1;
niklase@google.com470e71d2011-07-07 08:21:25357#endif
358}
359
360int VoEAudioProcessingImpl::GetRxNsStatus(int channel,
361 bool& enabled,
andrew@webrtc.org8b111eb2012-03-06 19:50:12362 NsModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19363 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12364 "GetRxNsStatus(channel=%d, enable=?, mode=?)", channel);
andrew@webrtc.orgddcc9422012-11-06 18:39:40365#ifdef WEBRTC_VOICE_ENGINE_NR
tommi@webrtc.org851becd2012-04-04 14:57:19366 if (!_shared->statistics().Initialized()) {
367 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25368 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12369 }
370
pbos@webrtc.org676ff1e2013-08-07 17:57:36371 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
372 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12373 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19374 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12375 "GetRxNsStatus() failed to locate channel");
376 return -1;
377 }
378 return channelPtr->GetRxNsStatus(enabled, mode);
379#else
tommi@webrtc.org851becd2012-04-04 14:57:19380 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.orgddcc9422012-11-06 18:39:40381 "GetRxNsStatus() NS is not supported");
andrew@webrtc.org8b111eb2012-03-06 19:50:12382 return -1;
niklase@google.com470e71d2011-07-07 08:21:25383#endif
384}
385
386int VoEAudioProcessingImpl::SetRxAgcStatus(int channel,
387 bool enable,
andrew@webrtc.org8b111eb2012-03-06 19:50:12388 AgcModes mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19389 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12390 "SetRxAgcStatus(channel=%d, enable=%d, mode=%d)",
391 channel, (int)enable, (int)mode);
niklase@google.com470e71d2011-07-07 08:21:25392#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19393 if (!_shared->statistics().Initialized()) {
394 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25395 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12396 }
397
pbos@webrtc.org676ff1e2013-08-07 17:57:36398 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
399 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12400 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19401 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12402 "SetRxAgcStatus() failed to locate channel");
403 return -1;
404 }
405 return channelPtr->SetRxAgcStatus(enable, mode);
406#else
tommi@webrtc.org851becd2012-04-04 14:57:19407 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12408 "SetRxAgcStatus() Agc is not supported");
409 return -1;
niklase@google.com470e71d2011-07-07 08:21:25410#endif
411}
412
413int VoEAudioProcessingImpl::GetRxAgcStatus(int channel,
414 bool& enabled,
andrew@webrtc.org8b111eb2012-03-06 19:50:12415 AgcModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19416 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12417 "GetRxAgcStatus(channel=%d, enable=?, mode=?)", channel);
niklase@google.com470e71d2011-07-07 08:21:25418#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19419 if (!_shared->statistics().Initialized()) {
420 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25421 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12422 }
423
pbos@webrtc.org676ff1e2013-08-07 17:57:36424 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
425 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12426 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19427 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12428 "GetRxAgcStatus() failed to locate channel");
429 return -1;
430 }
431 return channelPtr->GetRxAgcStatus(enabled, mode);
432#else
tommi@webrtc.org851becd2012-04-04 14:57:19433 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12434 "GetRxAgcStatus() Agc is not supported");
435 return -1;
niklase@google.com470e71d2011-07-07 08:21:25436#endif
437}
438
andrew@webrtc.org8b111eb2012-03-06 19:50:12439int VoEAudioProcessingImpl::SetRxAgcConfig(int channel,
pbos@webrtc.org92135212013-05-14 08:31:39440 AgcConfig config) {
tommi@webrtc.org851becd2012-04-04 14:57:19441 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12442 "SetRxAgcConfig(channel=%d)", channel);
niklase@google.com470e71d2011-07-07 08:21:25443#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19444 if (!_shared->statistics().Initialized()) {
445 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25446 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12447 }
448
pbos@webrtc.org676ff1e2013-08-07 17:57:36449 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
450 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12451 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19452 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12453 "SetRxAgcConfig() failed to locate channel");
454 return -1;
455 }
456 return channelPtr->SetRxAgcConfig(config);
457#else
tommi@webrtc.org851becd2012-04-04 14:57:19458 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12459 "SetRxAgcConfig() Agc is not supported");
460 return -1;
niklase@google.com470e71d2011-07-07 08:21:25461#endif
462}
463
andrew@webrtc.org8b111eb2012-03-06 19:50:12464int VoEAudioProcessingImpl::GetRxAgcConfig(int channel, AgcConfig& config) {
tommi@webrtc.org851becd2012-04-04 14:57:19465 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12466 "GetRxAgcConfig(channel=%d)", channel);
niklase@google.com470e71d2011-07-07 08:21:25467#ifdef WEBRTC_VOICE_ENGINE_AGC
tommi@webrtc.org851becd2012-04-04 14:57:19468 if (!_shared->statistics().Initialized()) {
469 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25470 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12471 }
472
pbos@webrtc.org676ff1e2013-08-07 17:57:36473 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
474 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12475 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19476 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12477 "GetRxAgcConfig() failed to locate channel");
478 return -1;
479 }
480 return channelPtr->GetRxAgcConfig(config);
481#else
tommi@webrtc.org851becd2012-04-04 14:57:19482 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12483 "GetRxAgcConfig() Agc is not supported");
484 return -1;
niklase@google.com470e71d2011-07-07 08:21:25485#endif
486}
487
andrew@webrtc.org55c0d4a2012-08-29 02:13:12488bool 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:54497 LOG_API1(enable);
andrew@webrtc.org55c0d4a2012-08-29 02:13:12498 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:54516 LOG_API0();
andrew@webrtc.org55c0d4a2012-08-29 02:13:12517 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:12523int VoEAudioProcessingImpl::SetEcStatus(bool enable, EcModes mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19524 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12525 "SetEcStatus(enable=%d, mode=%d)", enable, mode);
niklase@google.com470e71d2011-07-07 08:21:25526#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19527 if (!_shared->statistics().Initialized()) {
528 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12529 return -1;
530 }
niklase@google.com470e71d2011-07-07 08:21:25531
andrew@webrtc.org8b111eb2012-03-06 19:50:12532 // 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:19540 if (_shared->audio_processing()->echo_control_mobile()->is_enabled()) {
541 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
andrew@webrtc.org8b111eb2012-03-06 19:50:12542 "SetEcStatus() disable AECM before enabling AEC");
tommi@webrtc.org851becd2012-04-04 14:57:19543 if (_shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12544 Enable(false) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19545 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12546 "SetEcStatus() failed to disable AECM");
547 return -1;
niklase@google.com470e71d2011-07-07 08:21:25548 }
andrew@webrtc.org8b111eb2012-03-06 19:50:12549 }
niklase@google.com470e71d2011-07-07 08:21:25550 }
tommi@webrtc.org851becd2012-04-04 14:57:19551 if (_shared->audio_processing()->echo_cancellation()->Enable(enable) != 0) {
552 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12553 "SetEcStatus() failed to set AEC state");
554 return -1;
niklase@google.com470e71d2011-07-07 08:21:25555 }
andrew@webrtc.org8b111eb2012-03-06 19:50:12556 if (mode == kEcConference) {
tommi@webrtc.org851becd2012-04-04 14:57:19557 if (_shared->audio_processing()->echo_cancellation()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12558 set_suppression_level(EchoCancellation::kHighSuppression) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19559 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12560 "SetEcStatus() failed to set aggressiveness to high");
niklase@google.com470e71d2011-07-07 08:21:25561 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12562 }
563 } else {
tommi@webrtc.org851becd2012-04-04 14:57:19564 if (_shared->audio_processing()->echo_cancellation()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12565 set_suppression_level(
566 EchoCancellation::kModerateSuppression) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19567 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12568 "SetEcStatus() failed to set aggressiveness to moderate");
niklase@google.com470e71d2011-07-07 08:21:25569 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12570 }
niklase@google.com470e71d2011-07-07 08:21:25571 }
andrew@webrtc.org6f9f8172012-03-06 19:03:39572
andrew@webrtc.org8b111eb2012-03-06 19:50:12573 _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:19579 if (_shared->audio_processing()->echo_cancellation()->is_enabled()) {
580 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
andrew@webrtc.org8b111eb2012-03-06 19:50:12581 "SetEcStatus() disable AEC before enabling AECM");
tommi@webrtc.org851becd2012-04-04 14:57:19582 if (_shared->audio_processing()->echo_cancellation()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12583 Enable(false) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19584 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12585 "SetEcStatus() failed to disable AEC");
586 return -1;
587 }
588 }
niklase@google.com470e71d2011-07-07 08:21:25589 }
tommi@webrtc.org851becd2012-04-04 14:57:19590 if (_shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12591 Enable(enable) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19592 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12593 "SetEcStatus() failed to set AECM state");
594 return -1;
niklase@google.com470e71d2011-07-07 08:21:25595 }
andrew@webrtc.org8b111eb2012-03-06 19:50:12596 _isAecMode = false;
597 } else {
tommi@webrtc.org851becd2012-04-04 14:57:19598 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12599 "SetEcStatus() invalid EC mode");
niklase@google.com470e71d2011-07-07 08:21:25600 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12601 }
602
603 return 0;
604#else
tommi@webrtc.org851becd2012-04-04 14:57:19605 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12606 "SetEcStatus() EC is not supported");
607 return -1;
niklase@google.com470e71d2011-07-07 08:21:25608#endif
609}
610
andrew@webrtc.org8b111eb2012-03-06 19:50:12611int VoEAudioProcessingImpl::GetEcStatus(bool& enabled, EcModes& mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19612 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12613 "GetEcStatus()");
niklase@google.com470e71d2011-07-07 08:21:25614#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19615 if (!_shared->statistics().Initialized()) {
616 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25617 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12618 }
619
620 if (_isAecMode == true) {
621 mode = kEcAec;
tommi@webrtc.org851becd2012-04-04 14:57:19622 enabled = _shared->audio_processing()->echo_cancellation()->is_enabled();
andrew@webrtc.org8b111eb2012-03-06 19:50:12623 } else {
624 mode = kEcAecm;
tommi@webrtc.org851becd2012-04-04 14:57:19625 enabled = _shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12626 is_enabled();
627 }
628
tommi@webrtc.org851becd2012-04-04 14:57:19629 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12630 "GetEcStatus() => enabled=%i, mode=%i",
631 enabled, (int)mode);
632 return 0;
633#else
tommi@webrtc.org851becd2012-04-04 14:57:19634 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12635 "GetEcStatus() EC is not supported");
636 return -1;
637#endif
638}
639
640void VoEAudioProcessingImpl::SetDelayOffsetMs(int offset) {
tommi@webrtc.org851becd2012-04-04 14:57:19641 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12642 "SetDelayOffsetMs(offset = %d)", offset);
tommi@webrtc.org851becd2012-04-04 14:57:19643 _shared->audio_processing()->set_delay_offset_ms(offset);
andrew@webrtc.org8b111eb2012-03-06 19:50:12644}
645
646int VoEAudioProcessingImpl::DelayOffsetMs() {
tommi@webrtc.org851becd2012-04-04 14:57:19647 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12648 "DelayOffsetMs()");
tommi@webrtc.org851becd2012-04-04 14:57:19649 return _shared->audio_processing()->delay_offset_ms();
andrew@webrtc.org8b111eb2012-03-06 19:50:12650}
651
652int VoEAudioProcessingImpl::SetAecmMode(AecmModes mode, bool enableCNG) {
tommi@webrtc.org851becd2012-04-04 14:57:19653 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12654 "SetAECMMode(mode = %d)", mode);
655#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19656 if (!_shared->statistics().Initialized()) {
657 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12658 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:19683 if (_shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12684 set_routing_mode(aecmMode) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19685 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12686 "SetAECMMode() failed to set AECM routing mode");
687 return -1;
688 }
tommi@webrtc.org851becd2012-04-04 14:57:19689 if (_shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12690 enable_comfort_noise(enableCNG) != 0) {
tommi@webrtc.org851becd2012-04-04 14:57:19691 _shared->SetLastError(VE_APM_ERROR, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12692 "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:19698 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12699 "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:19705 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12706 "GetAECMMode(mode=?)");
707#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19708 if (!_shared->statistics().Initialized()) {
709 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12710 return -1;
711 }
712
713 enabledCNG = false;
714
715 EchoControlMobile::RoutingMode aecmMode =
tommi@webrtc.org851becd2012-04-04 14:57:19716 _shared->audio_processing()->echo_control_mobile()->routing_mode();
717 enabledCNG = _shared->audio_processing()->echo_control_mobile()->
andrew@webrtc.org8b111eb2012-03-06 19:50:12718 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:19740 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12741 "GetAECMMode() EC is not supported");
742 return -1;
niklase@google.com470e71d2011-07-07 08:21:25743#endif
744}
745
andrew@webrtc.org369166a2012-04-24 18:38:03746int 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:25765int VoEAudioProcessingImpl::RegisterRxVadObserver(
andrew@webrtc.org8b111eb2012-03-06 19:50:12766 int channel,
767 VoERxVadCallback& observer) {
tommi@webrtc.org851becd2012-04-04 14:57:19768 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12769 "RegisterRxVadObserver()");
tommi@webrtc.org851becd2012-04-04 14:57:19770 if (!_shared->statistics().Initialized()) {
771 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12772 return -1;
773 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36774 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
775 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12776 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19777 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12778 "RegisterRxVadObserver() failed to locate channel");
779 return -1;
780 }
781 return channelPtr->RegisterRxVadObserver(observer);
niklase@google.com470e71d2011-07-07 08:21:25782}
783
andrew@webrtc.org8b111eb2012-03-06 19:50:12784int VoEAudioProcessingImpl::DeRegisterRxVadObserver(int channel) {
tommi@webrtc.org851becd2012-04-04 14:57:19785 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12786 "DeRegisterRxVadObserver()");
tommi@webrtc.org851becd2012-04-04 14:57:19787 if (!_shared->statistics().Initialized()) {
788 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12789 return -1;
790 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36791 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
792 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12793 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19794 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12795 "DeRegisterRxVadObserver() failed to locate channel");
796 return -1;
797 }
niklase@google.com470e71d2011-07-07 08:21:25798
andrew@webrtc.org8b111eb2012-03-06 19:50:12799 return channelPtr->DeRegisterRxVadObserver();
niklase@google.com470e71d2011-07-07 08:21:25800}
801
andrew@webrtc.org8b111eb2012-03-06 19:50:12802int VoEAudioProcessingImpl::VoiceActivityIndicator(int channel) {
tommi@webrtc.org851becd2012-04-04 14:57:19803 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12804 "VoiceActivityIndicator(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19805 if (!_shared->statistics().Initialized()) {
806 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12807 return -1;
808 }
niklase@google.com470e71d2011-07-07 08:21:25809
pbos@webrtc.org676ff1e2013-08-07 17:57:36810 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
811 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.org8b111eb2012-03-06 19:50:12812 if (channelPtr == NULL) {
tommi@webrtc.org851becd2012-04-04 14:57:19813 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12814 "DeRegisterRxVadObserver() failed to locate channel");
815 return -1;
816 }
817 int activity(-1);
818 channelPtr->VoiceActivityIndicator(activity);
niklase@google.com470e71d2011-07-07 08:21:25819
andrew@webrtc.org8b111eb2012-03-06 19:50:12820 return activity;
niklase@google.com470e71d2011-07-07 08:21:25821}
822
bjornv@webrtc.org3765bd22011-10-17 08:49:23823int VoEAudioProcessingImpl::SetEcMetricsStatus(bool enable) {
tommi@webrtc.org851becd2012-04-04 14:57:19824 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23825 "SetEcMetricsStatus(enable=%d)", enable);
bjornv@google.com0beae672011-09-28 14:08:19826#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19827 if (!_shared->statistics().Initialized()) {
828 _shared->SetLastError(VE_NOT_INITED, kTraceError);
bjornv@google.com0beae672011-09-28 14:08:19829 return -1;
830 }
831
tommi@webrtc.org851becd2012-04-04 14:57:19832 if ((_shared->audio_processing()->echo_cancellation()->enable_metrics(enable)
andrew@webrtc.org8b111eb2012-03-06 19:50:12833 != 0) ||
tommi@webrtc.org851becd2012-04-04 14:57:19834 (_shared->audio_processing()->echo_cancellation()->enable_delay_logging(
andrew@webrtc.org8b111eb2012-03-06 19:50:12835 enable) != 0)) {
tommi@webrtc.org851becd2012-04-04 14:57:19836 _shared->SetLastError(VE_APM_ERROR, kTraceError,
bjornv@webrtc.org3765bd22011-10-17 08:49:23837 "SetEcMetricsStatus() unable to set EC metrics mode");
bjornv@google.com0beae672011-09-28 14:08:19838 return -1;
839 }
840 return 0;
841#else
tommi@webrtc.org851becd2012-04-04 14:57:19842 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12843 "SetEcStatus() EC is not supported");
bjornv@google.com0beae672011-09-28 14:08:19844 return -1;
845#endif
niklase@google.com470e71d2011-07-07 08:21:25846}
847
bjornv@webrtc.org3765bd22011-10-17 08:49:23848int VoEAudioProcessingImpl::GetEcMetricsStatus(bool& enabled) {
tommi@webrtc.org851becd2012-04-04 14:57:19849 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23850 "GetEcMetricsStatus(enabled=?)");
bjornv@google.com0beae672011-09-28 14:08:19851#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19852 if (!_shared->statistics().Initialized()) {
853 _shared->SetLastError(VE_NOT_INITED, kTraceError);
bjornv@google.com0beae672011-09-28 14:08:19854 return -1;
855 }
niklase@google.com470e71d2011-07-07 08:21:25856
bjornv@webrtc.org3765bd22011-10-17 08:49:23857 bool echo_mode =
tommi@webrtc.org851becd2012-04-04 14:57:19858 _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:23861
862 if (echo_mode != delay_mode) {
tommi@webrtc.org851becd2012-04-04 14:57:19863 _shared->SetLastError(VE_APM_ERROR, kTraceError,
bjornv@webrtc.org3765bd22011-10-17 08:49:23864 "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:25869
tommi@webrtc.org851becd2012-04-04 14:57:19870 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23871 "GetEcMetricsStatus() => enabled=%d", enabled);
bjornv@google.com0beae672011-09-28 14:08:19872 return 0;
873#else
tommi@webrtc.org851becd2012-04-04 14:57:19874 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12875 "SetEcStatus() EC is not supported");
bjornv@google.com0beae672011-09-28 14:08:19876 return -1;
877#endif
niklase@google.com470e71d2011-07-07 08:21:25878}
879
880int VoEAudioProcessingImpl::GetEchoMetrics(int& ERL,
881 int& ERLE,
882 int& RERL,
bjornv@webrtc.org3765bd22011-10-17 08:49:23883 int& A_NLP) {
tommi@webrtc.org851becd2012-04-04 14:57:19884 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23885 "GetEchoMetrics(ERL=?, ERLE=?, RERL=?, A_NLP=?)");
niklase@google.com470e71d2011-07-07 08:21:25886#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19887 if (!_shared->statistics().Initialized()) {
888 _shared->SetLastError(VE_NOT_INITED, kTraceError);
bjornv@webrtc.org3765bd22011-10-17 08:49:23889 return -1;
890 }
tommi@webrtc.org851becd2012-04-04 14:57:19891 if (!_shared->audio_processing()->echo_cancellation()->is_enabled()) {
892 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
bjornv@webrtc.org3765bd22011-10-17 08:49:23893 "GetEchoMetrics() AudioProcessingModule AEC is not enabled");
894 return -1;
895 }
niklase@google.com470e71d2011-07-07 08:21:25896
bjornv@webrtc.org3765bd22011-10-17 08:49:23897 // Get Echo Metrics from Audio Processing Module.
898 EchoCancellation::Metrics echoMetrics;
tommi@webrtc.org851becd2012-04-04 14:57:19899 if (_shared->audio_processing()->echo_cancellation()->GetMetrics(
andrew@webrtc.org8b111eb2012-03-06 19:50:12900 &echoMetrics)) {
tommi@webrtc.org851becd2012-04-04 14:57:19901 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23902 "GetEchoMetrics(), AudioProcessingModule metrics error");
903 return -1;
904 }
niklase@google.com470e71d2011-07-07 08:21:25905
bjornv@webrtc.org3765bd22011-10-17 08:49:23906 // 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:25911
tommi@webrtc.org851becd2012-04-04 14:57:19912 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25913 "GetEchoMetrics() => ERL=%d, ERLE=%d, RERL=%d, A_NLP=%d",
914 ERL, ERLE, RERL, A_NLP);
bjornv@webrtc.org3765bd22011-10-17 08:49:23915 return 0;
niklase@google.com470e71d2011-07-07 08:21:25916#else
tommi@webrtc.org851becd2012-04-04 14:57:19917 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12918 "SetEcStatus() EC is not supported");
bjornv@webrtc.org3765bd22011-10-17 08:49:23919 return -1;
920#endif
921}
922
923int VoEAudioProcessingImpl::GetEcDelayMetrics(int& delay_median,
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44924 int& delay_std,
925 float& fraction_poor_delays) {
tommi@webrtc.org851becd2012-04-04 14:57:19926 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44927 "GetEcDelayMetrics(median=?, std=?, fraction_poor_delays=?)");
bjornv@webrtc.org3765bd22011-10-17 08:49:23928#ifdef WEBRTC_VOICE_ENGINE_ECHO
tommi@webrtc.org851becd2012-04-04 14:57:19929 if (!_shared->statistics().Initialized()) {
930 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25931 return -1;
bjornv@webrtc.org3765bd22011-10-17 08:49:23932 }
tommi@webrtc.org851becd2012-04-04 14:57:19933 if (!_shared->audio_processing()->echo_cancellation()->is_enabled()) {
934 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
bjornv@webrtc.org3765bd22011-10-17 08:49:23935 "GetEcDelayMetrics() AudioProcessingModule AEC is not enabled");
936 return -1;
937 }
938
939 int median = 0;
940 int std = 0;
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44941 float poor_fraction = 0;
bjornv@webrtc.org3765bd22011-10-17 08:49:23942 // Get delay-logging values from Audio Processing Module.
tommi@webrtc.org851becd2012-04-04 14:57:19943 if (_shared->audio_processing()->echo_cancellation()->GetDelayMetrics(
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44944 &median, &std, &poor_fraction)) {
tommi@webrtc.org851becd2012-04-04 14:57:19945 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.org3765bd22011-10-17 08:49:23946 "GetEcDelayMetrics(), AudioProcessingModule delay-logging "
947 "error");
948 return -1;
949 }
950
951 // EC delay-logging metrics
952 delay_median = median;
953 delay_std = std;
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44954 fraction_poor_delays = poor_fraction;
bjornv@webrtc.org3765bd22011-10-17 08:49:23955
tommi@webrtc.org851becd2012-04-04 14:57:19956 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44957 "GetEcDelayMetrics() => delay_median=%d, delay_std=%d, "
958 "fraction_poor_delays=%f", delay_median, delay_std,
959 fraction_poor_delays);
bjornv@webrtc.org3765bd22011-10-17 08:49:23960 return 0;
961#else
tommi@webrtc.org851becd2012-04-04 14:57:19962 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
andrew@webrtc.org8b111eb2012-03-06 19:50:12963 "SetEcStatus() EC is not supported");
bjornv@webrtc.org3765bd22011-10-17 08:49:23964 return -1;
niklase@google.com470e71d2011-07-07 08:21:25965#endif
966}
967
andrew@webrtc.org8b111eb2012-03-06 19:50:12968int VoEAudioProcessingImpl::StartDebugRecording(const char* fileNameUTF8) {
tommi@webrtc.org851becd2012-04-04 14:57:19969 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25970 "StartDebugRecording()");
tommi@webrtc.org851becd2012-04-04 14:57:19971 if (!_shared->statistics().Initialized()) {
972 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25973 return -1;
andrew@webrtc.org8b111eb2012-03-06 19:50:12974 }
975
tommi@webrtc.org851becd2012-04-04 14:57:19976 return _shared->audio_processing()->StartDebugRecording(fileNameUTF8);
andrew@webrtc.org8b111eb2012-03-06 19:50:12977}
978
henrikg@webrtc.org863b5362013-12-06 16:05:17979int VoEAudioProcessingImpl::StartDebugRecording(FILE* file_handle) {
980 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
981 "StartDebugRecording()");
982 if (!_shared->statistics().Initialized()) {
983 _shared->SetLastError(VE_NOT_INITED, kTraceError);
984 return -1;
985 }
986
987 return _shared->audio_processing()->StartDebugRecording(file_handle);
988}
989
andrew@webrtc.org8b111eb2012-03-06 19:50:12990int VoEAudioProcessingImpl::StopDebugRecording() {
tommi@webrtc.org851becd2012-04-04 14:57:19991 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:12992 "StopDebugRecording()");
tommi@webrtc.org851becd2012-04-04 14:57:19993 if (!_shared->statistics().Initialized()) {
994 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:12995 return -1;
996 }
997
tommi@webrtc.org851becd2012-04-04 14:57:19998 return _shared->audio_processing()->StopDebugRecording();
andrew@webrtc.org8b111eb2012-03-06 19:50:12999}
1000
1001int VoEAudioProcessingImpl::SetTypingDetectionStatus(bool enable) {
tommi@webrtc.org851becd2012-04-04 14:57:191002 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:121003 "SetTypingDetectionStatus()");
andrew@webrtc.org0851df82013-06-19 17:03:471004#if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION)
1005 NOT_SUPPORTED(_shared->statistics());
1006#else
tommi@webrtc.org851becd2012-04-04 14:57:191007 if (!_shared->statistics().Initialized()) {
1008 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:121009 return -1;
1010 }
1011
1012 // Just use the VAD state to determine if we should enable typing detection
1013 // or not
1014
tommi@webrtc.org851becd2012-04-04 14:57:191015 if (_shared->audio_processing()->voice_detection()->Enable(enable)) {
1016 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
andrew@webrtc.org8b111eb2012-03-06 19:50:121017 "SetTypingDetectionStatus() failed to set VAD state");
1018 return -1;
1019 }
tommi@webrtc.org851becd2012-04-04 14:57:191020 if (_shared->audio_processing()->voice_detection()->set_likelihood(
andrew@webrtc.org8b111eb2012-03-06 19:50:121021 VoiceDetection::kVeryLowLikelihood)) {
tommi@webrtc.org851becd2012-04-04 14:57:191022 _shared->SetLastError(VE_APM_ERROR, kTraceWarning,
andrew@webrtc.org8b111eb2012-03-06 19:50:121023 "SetTypingDetectionStatus() failed to set VAD likelihood to low");
1024 return -1;
1025 }
1026
1027 return 0;
niklase@google.com470e71d2011-07-07 08:21:251028#endif
1029}
1030
andrew@webrtc.org8b111eb2012-03-06 19:50:121031int VoEAudioProcessingImpl::GetTypingDetectionStatus(bool& enabled) {
tommi@webrtc.org851becd2012-04-04 14:57:191032 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
andrew@webrtc.org8b111eb2012-03-06 19:50:121033 "GetTypingDetectionStatus()");
tommi@webrtc.org851becd2012-04-04 14:57:191034 if (!_shared->statistics().Initialized()) {
1035 _shared->SetLastError(VE_NOT_INITED, kTraceError);
andrew@webrtc.org8b111eb2012-03-06 19:50:121036 return -1;
1037 }
1038 // Just use the VAD state to determine if we should enable typing
1039 // detection or not
niklase@google.com470e71d2011-07-07 08:21:251040
tommi@webrtc.org851becd2012-04-04 14:57:191041 enabled = _shared->audio_processing()->voice_detection()->is_enabled();
niklase@google.com470e71d2011-07-07 08:21:251042
andrew@webrtc.org8b111eb2012-03-06 19:50:121043 return 0;
niklase@google.com470e71d2011-07-07 08:21:251044}
1045
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:541046
1047int VoEAudioProcessingImpl::TimeSinceLastTyping(int &seconds) {
tommi@webrtc.org851becd2012-04-04 14:57:191048 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:541049 "TimeSinceLastTyping()");
andrew@webrtc.org0851df82013-06-19 17:03:471050#if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION)
1051 NOT_SUPPORTED(_shared->statistics());
1052#else
tommi@webrtc.org851becd2012-04-04 14:57:191053 if (!_shared->statistics().Initialized()) {
1054 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:541055 return -1;
1056 }
1057 // Check if typing detection is enabled
tommi@webrtc.org851becd2012-04-04 14:57:191058 bool enabled = _shared->audio_processing()->voice_detection()->is_enabled();
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:541059 if (enabled)
1060 {
tommi@webrtc.org851becd2012-04-04 14:57:191061 _shared->transmit_mixer()->TimeSinceLastTyping(seconds);
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:541062 return 0;
1063 }
1064 else
1065 {
tommi@webrtc.org851becd2012-04-04 14:57:191066 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:541067 "SetTypingDetectionStatus is not enabled");
1068 return -1;
1069 }
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:541070#endif
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:541071}
1072
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:271073int VoEAudioProcessingImpl::SetTypingDetectionParameters(int timeWindow,
1074 int costPerTyping,
1075 int reportingThreshold,
niklas.enbom@webrtc.orgf6edfef2012-05-09 13:16:121076 int penaltyDecay,
1077 int typeEventDelay) {
tommi@webrtc.org851becd2012-04-04 14:57:191078 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:271079 "SetTypingDetectionParameters()");
andrew@webrtc.org0851df82013-06-19 17:03:471080#if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION)
1081 NOT_SUPPORTED(_shared->statistics());
1082#else
tommi@webrtc.org851becd2012-04-04 14:57:191083 if (!_shared->statistics().Initialized()) {
1084 _shared->statistics().SetLastError(VE_NOT_INITED, kTraceError);
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:271085 return -1;
1086 }
tommi@webrtc.org851becd2012-04-04 14:57:191087 return (_shared->transmit_mixer()->SetTypingDetectionParameters(timeWindow,
niklas.enbom@webrtc.orgf6edfef2012-05-09 13:16:121088 costPerTyping, reportingThreshold, penaltyDecay, typeEventDelay));
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:271089#endif
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:271090}
1091
andrew@webrtc.org02d71742012-04-24 19:47:001092void VoEAudioProcessingImpl::EnableStereoChannelSwapping(bool enable) {
andrew@webrtc.org50419b02012-11-14 19:07:541093 LOG_API1(enable);
andrew@webrtc.org02d71742012-04-24 19:47:001094 _shared->transmit_mixer()->EnableStereoChannelSwapping(enable);
1095}
1096
1097bool VoEAudioProcessingImpl::IsStereoChannelSwappingEnabled() {
andrew@webrtc.org50419b02012-11-14 19:07:541098 LOG_API0();
andrew@webrtc.org02d71742012-04-24 19:47:001099 return _shared->transmit_mixer()->IsStereoChannelSwappingEnabled();
1100}
1101
niklase@google.com470e71d2011-07-07 08:21:251102#endif // #ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API
1103
pbos@webrtc.orgd900e8b2013-07-03 15:12:261104} // namespace webrtc