niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | c80d9d9 | 2012-02-06 10:11:25 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/voe_audio_processing_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pbos | ad85622 | 2015-11-27 09:48:36 -0800 | [diff] [blame] | 13 | #include "webrtc/base/logging.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 15 | #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/include/trace.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 22 | // TODO(andrew): move to a common place. |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 23 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | namespace webrtc { |
| 40 | |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 41 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
andrew@webrtc.org | 8012474 | 2012-03-08 17:54:24 +0000 | [diff] [blame] | 42 | static const EcModes kDefaultEcMode = kEcAecm; |
| 43 | #else |
| 44 | static const EcModes kDefaultEcMode = kEcAec; |
| 45 | #endif |
| 46 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 47 | VoEAudioProcessing* VoEAudioProcessing::GetInterface(VoiceEngine* voiceEngine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | #ifndef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 49 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | #else |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 51 | if (NULL == voiceEngine) { |
| 52 | return NULL; |
| 53 | } |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 54 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 55 | s->AddRef(); |
| 56 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | #endif |
| 58 | } |
| 59 | |
| 60 | #ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 61 | VoEAudioProcessingImpl::VoEAudioProcessingImpl(voe::SharedData* shared) |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 62 | : _isAecMode(kDefaultEcMode == kEcAec), _shared(shared) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 63 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 64 | "VoEAudioProcessingImpl::VoEAudioProcessingImpl() - ctor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | } |
| 66 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 67 | VoEAudioProcessingImpl::~VoEAudioProcessingImpl() { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 68 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 69 | "VoEAudioProcessingImpl::~VoEAudioProcessingImpl() - dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | } |
| 71 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 72 | int VoEAudioProcessingImpl::SetNsStatus(bool enable, NsModes mode) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 73 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 74 | "SetNsStatus(enable=%d, mode=%d)", enable, mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | #ifdef WEBRTC_VOICE_ENGINE_NR |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 76 | if (!_shared->statistics().Initialized()) { |
| 77 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 78 | return -1; |
| 79 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 81 | NoiseSuppression::Level nsLevel = kDefaultNsMode; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 82 | switch (mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | case kNsDefault: |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 84 | nsLevel = kDefaultNsMode; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 85 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | case kNsUnchanged: |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 87 | nsLevel = _shared->audio_processing()->noise_suppression()->level(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 88 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | case kNsConference: |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 90 | nsLevel = NoiseSuppression::kHigh; |
| 91 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | case kNsLowSuppression: |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 93 | nsLevel = NoiseSuppression::kLow; |
| 94 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | case kNsModerateSuppression: |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 96 | nsLevel = NoiseSuppression::kModerate; |
| 97 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | case kNsHighSuppression: |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 99 | nsLevel = NoiseSuppression::kHigh; |
| 100 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | case kNsVeryHighSuppression: |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 102 | nsLevel = NoiseSuppression::kVeryHigh; |
| 103 | break; |
| 104 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 106 | if (_shared->audio_processing()->noise_suppression()->set_level(nsLevel) != |
| 107 | 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 108 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 109 | "SetNsStatus() failed to set Ns mode"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 111 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 112 | if (_shared->audio_processing()->noise_suppression()->Enable(enable) != 0) { |
| 113 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 114 | "SetNsStatus() failed to set Ns state"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 115 | return -1; |
| 116 | } |
| 117 | |
| 118 | return 0; |
| 119 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 120 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 121 | "SetNsStatus() Ns is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 122 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | #endif |
| 124 | } |
| 125 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 126 | int VoEAudioProcessingImpl::GetNsStatus(bool& enabled, NsModes& mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | #ifdef WEBRTC_VOICE_ENGINE_NR |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 128 | if (!_shared->statistics().Initialized()) { |
| 129 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 131 | } |
| 132 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 133 | enabled = _shared->audio_processing()->noise_suppression()->is_enabled(); |
| 134 | NoiseSuppression::Level nsLevel = |
| 135 | _shared->audio_processing()->noise_suppression()->level(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 136 | |
| 137 | switch (nsLevel) { |
| 138 | case NoiseSuppression::kLow: |
| 139 | mode = kNsLowSuppression; |
| 140 | break; |
| 141 | case NoiseSuppression::kModerate: |
| 142 | mode = kNsModerateSuppression; |
| 143 | break; |
| 144 | case NoiseSuppression::kHigh: |
| 145 | mode = kNsHighSuppression; |
| 146 | break; |
| 147 | case NoiseSuppression::kVeryHigh: |
| 148 | mode = kNsVeryHighSuppression; |
| 149 | break; |
| 150 | } |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 151 | return 0; |
| 152 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 153 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 154 | "GetNsStatus() Ns is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 155 | return -1; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 156 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | } |
| 158 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 159 | int VoEAudioProcessingImpl::SetAgcStatus(bool enable, AgcModes mode) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 160 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 161 | "SetAgcStatus(enable=%d, mode=%d)", enable, mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 163 | if (!_shared->statistics().Initialized()) { |
| 164 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 165 | return -1; |
| 166 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 168 | #if defined(WEBRTC_IOS) || defined(ATA) || defined(WEBRTC_ANDROID) |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 169 | if (mode == kAgcAdaptiveAnalog) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 170 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 171 | "SetAgcStatus() invalid Agc mode for mobile device"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 172 | return -1; |
| 173 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 174 | #endif |
| 175 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 176 | GainControl::Mode agcMode = kDefaultAgcMode; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 177 | switch (mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 178 | case kAgcDefault: |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 179 | agcMode = kDefaultAgcMode; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 180 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | case kAgcUnchanged: |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 182 | agcMode = _shared->audio_processing()->gain_control()->mode(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 183 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | case kAgcFixedDigital: |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 185 | agcMode = GainControl::kFixedDigital; |
| 186 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 187 | case kAgcAdaptiveAnalog: |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 188 | agcMode = GainControl::kAdaptiveAnalog; |
| 189 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | case kAgcAdaptiveDigital: |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 191 | agcMode = GainControl::kAdaptiveDigital; |
| 192 | break; |
| 193 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 194 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 195 | if (_shared->audio_processing()->gain_control()->set_mode(agcMode) != 0) { |
| 196 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 197 | "SetAgcStatus() failed to set Agc mode"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 199 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 200 | if (_shared->audio_processing()->gain_control()->Enable(enable) != 0) { |
| 201 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 202 | "SetAgcStatus() failed to set Agc state"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 203 | return -1; |
| 204 | } |
| 205 | |
| 206 | if (agcMode != GainControl::kFixedDigital) { |
| 207 | // Set Agc state in the ADM when adaptive Agc mode has been selected. |
| 208 | // Note that we also enable the ADM Agc when Adaptive Digital mode is |
| 209 | // used since we want to be able to provide the APM with updated mic |
| 210 | // levels when the user modifies the mic level manually. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 211 | if (_shared->audio_device()->SetAGC(enable) != 0) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 212 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 213 | "SetAgcStatus() failed to set Agc mode"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 219 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 220 | "SetAgcStatus() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 221 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 222 | #endif |
| 223 | } |
| 224 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 225 | int VoEAudioProcessingImpl::GetAgcStatus(bool& enabled, AgcModes& mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 226 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 227 | if (!_shared->statistics().Initialized()) { |
| 228 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 229 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 230 | } |
| 231 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 232 | enabled = _shared->audio_processing()->gain_control()->is_enabled(); |
sjlee@webrtc.org | b4c441a | 2013-03-25 11:12:20 +0000 | [diff] [blame] | 233 | GainControl::Mode agcMode = |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 234 | _shared->audio_processing()->gain_control()->mode(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 235 | |
| 236 | switch (agcMode) { |
| 237 | case GainControl::kFixedDigital: |
| 238 | mode = kAgcFixedDigital; |
| 239 | break; |
| 240 | case GainControl::kAdaptiveAnalog: |
| 241 | mode = kAgcAdaptiveAnalog; |
| 242 | break; |
| 243 | case GainControl::kAdaptiveDigital: |
| 244 | mode = kAgcAdaptiveDigital; |
| 245 | break; |
| 246 | } |
| 247 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 248 | return 0; |
| 249 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 250 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 251 | "GetAgcStatus() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 252 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 253 | #endif |
| 254 | } |
| 255 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 256 | int VoEAudioProcessingImpl::SetAgcConfig(AgcConfig config) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 257 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 258 | "SetAgcConfig()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 259 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 260 | if (!_shared->statistics().Initialized()) { |
| 261 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 262 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 263 | } |
| 264 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 265 | if (_shared->audio_processing()->gain_control()->set_target_level_dbfs( |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 266 | config.targetLeveldBOv) != 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 267 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 268 | "SetAgcConfig() failed to set target peak |level|" |
| 269 | " (or envelope) of the Agc"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 270 | return -1; |
| 271 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 272 | if (_shared->audio_processing()->gain_control()->set_compression_gain_db( |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 273 | config.digitalCompressionGaindB) != 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 274 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 275 | "SetAgcConfig() failed to set the range in |gain| " |
| 276 | "the digital compression stage may apply"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 277 | return -1; |
| 278 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 279 | if (_shared->audio_processing()->gain_control()->enable_limiter( |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 280 | config.limiterEnable) != 0) { |
| 281 | _shared->SetLastError( |
| 282 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 283 | "SetAgcConfig() failed to set hard limiter to the signal"); |
| 284 | return -1; |
| 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 289 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 290 | "SetAgcConfig() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 291 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 292 | #endif |
| 293 | } |
| 294 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 295 | int VoEAudioProcessingImpl::GetAgcConfig(AgcConfig& config) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 296 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 297 | if (!_shared->statistics().Initialized()) { |
| 298 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 299 | return -1; |
| 300 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 301 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 302 | config.targetLeveldBOv = |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 303 | _shared->audio_processing()->gain_control()->target_level_dbfs(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 304 | config.digitalCompressionGaindB = |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 305 | _shared->audio_processing()->gain_control()->compression_gain_db(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 306 | config.limiterEnable = |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 307 | _shared->audio_processing()->gain_control()->is_limiter_enabled(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 309 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 310 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 311 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 312 | "GetAgcConfig() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 313 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 314 | #endif |
| 315 | } |
| 316 | |
| 317 | int VoEAudioProcessingImpl::SetRxNsStatus(int channel, |
| 318 | bool enable, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 319 | NsModes mode) { |
andrew@webrtc.org | ddcc942 | 2012-11-06 18:39:40 +0000 | [diff] [blame] | 320 | #ifdef WEBRTC_VOICE_ENGINE_NR |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 321 | if (!_shared->statistics().Initialized()) { |
| 322 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 323 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 324 | } |
| 325 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 326 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 327 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 328 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 329 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 330 | "SetRxNsStatus() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 331 | return -1; |
| 332 | } |
| 333 | return channelPtr->SetRxNsStatus(enable, mode); |
| 334 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 335 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 336 | "SetRxNsStatus() NS is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 337 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 338 | #endif |
| 339 | } |
| 340 | |
| 341 | int VoEAudioProcessingImpl::GetRxNsStatus(int channel, |
| 342 | bool& enabled, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 343 | NsModes& mode) { |
andrew@webrtc.org | ddcc942 | 2012-11-06 18:39:40 +0000 | [diff] [blame] | 344 | #ifdef WEBRTC_VOICE_ENGINE_NR |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 345 | if (!_shared->statistics().Initialized()) { |
| 346 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 348 | } |
| 349 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 350 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 351 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 352 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 353 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 354 | "GetRxNsStatus() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 355 | return -1; |
| 356 | } |
| 357 | return channelPtr->GetRxNsStatus(enabled, mode); |
| 358 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 359 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 360 | "GetRxNsStatus() NS is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 361 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 362 | #endif |
| 363 | } |
| 364 | |
| 365 | int VoEAudioProcessingImpl::SetRxAgcStatus(int channel, |
| 366 | bool enable, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 367 | AgcModes mode) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 368 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 369 | "SetRxAgcStatus(channel=%d, enable=%d, mode=%d)", channel, |
| 370 | (int)enable, (int)mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 371 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 372 | if (!_shared->statistics().Initialized()) { |
| 373 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 374 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 375 | } |
| 376 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 377 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 378 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 379 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 380 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 381 | "SetRxAgcStatus() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 382 | return -1; |
| 383 | } |
| 384 | return channelPtr->SetRxAgcStatus(enable, mode); |
| 385 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 386 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 387 | "SetRxAgcStatus() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 388 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 389 | #endif |
| 390 | } |
| 391 | |
| 392 | int VoEAudioProcessingImpl::GetRxAgcStatus(int channel, |
| 393 | bool& enabled, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 394 | AgcModes& mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 395 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 396 | if (!_shared->statistics().Initialized()) { |
| 397 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 398 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 399 | } |
| 400 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 401 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 402 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 403 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 404 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 405 | "GetRxAgcStatus() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 406 | return -1; |
| 407 | } |
| 408 | return channelPtr->GetRxAgcStatus(enabled, mode); |
| 409 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 410 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 411 | "GetRxAgcStatus() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 412 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 413 | #endif |
| 414 | } |
| 415 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 416 | int VoEAudioProcessingImpl::SetRxAgcConfig(int channel, AgcConfig config) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 417 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 418 | "SetRxAgcConfig(channel=%d)", channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 419 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 420 | if (!_shared->statistics().Initialized()) { |
| 421 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 422 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 423 | } |
| 424 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 425 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 426 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 427 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 428 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 429 | "SetRxAgcConfig() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 430 | return -1; |
| 431 | } |
| 432 | return channelPtr->SetRxAgcConfig(config); |
| 433 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 434 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 435 | "SetRxAgcConfig() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 436 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 437 | #endif |
| 438 | } |
| 439 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 440 | int VoEAudioProcessingImpl::GetRxAgcConfig(int channel, AgcConfig& config) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 441 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 442 | if (!_shared->statistics().Initialized()) { |
| 443 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 444 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 445 | } |
| 446 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 447 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 448 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 449 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 450 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 451 | "GetRxAgcConfig() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 452 | return -1; |
| 453 | } |
| 454 | return channelPtr->GetRxAgcConfig(config); |
| 455 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 456 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 457 | "GetRxAgcConfig() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 458 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 459 | #endif |
| 460 | } |
| 461 | |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 462 | bool VoEAudioProcessing::DriftCompensationSupported() { |
| 463 | #if defined(WEBRTC_DRIFT_COMPENSATION_SUPPORTED) |
| 464 | return true; |
| 465 | #else |
| 466 | return false; |
| 467 | #endif |
| 468 | } |
| 469 | |
| 470 | int VoEAudioProcessingImpl::EnableDriftCompensation(bool enable) { |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 471 | WEBRTC_VOICE_INIT_CHECK(); |
| 472 | |
| 473 | if (!DriftCompensationSupported()) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 474 | _shared->SetLastError( |
| 475 | VE_APM_ERROR, kTraceWarning, |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 476 | "Drift compensation is not supported on this platform."); |
| 477 | return -1; |
| 478 | } |
| 479 | |
| 480 | EchoCancellation* aec = _shared->audio_processing()->echo_cancellation(); |
| 481 | if (aec->enable_drift_compensation(enable) != 0) { |
| 482 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 483 | "aec->enable_drift_compensation() failed"); |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 484 | return -1; |
| 485 | } |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | bool VoEAudioProcessingImpl::DriftCompensationEnabled() { |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 490 | WEBRTC_VOICE_INIT_CHECK_BOOL(); |
| 491 | |
| 492 | EchoCancellation* aec = _shared->audio_processing()->echo_cancellation(); |
| 493 | return aec->is_drift_compensation_enabled(); |
| 494 | } |
| 495 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 496 | int VoEAudioProcessingImpl::SetEcStatus(bool enable, EcModes mode) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 497 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 498 | "SetEcStatus(enable=%d, mode=%d)", enable, mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 499 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 500 | if (!_shared->statistics().Initialized()) { |
| 501 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 502 | return -1; |
| 503 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 504 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 505 | // AEC mode |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 506 | if ((mode == kEcDefault) || (mode == kEcConference) || (mode == kEcAec) || |
| 507 | ((mode == kEcUnchanged) && (_isAecMode == true))) { |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 508 | if (enable) { |
| 509 | // Disable the AECM before enable the AEC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 510 | if (_shared->audio_processing()->echo_control_mobile()->is_enabled()) { |
| 511 | _shared->SetLastError(VE_APM_ERROR, kTraceWarning, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 512 | "SetEcStatus() disable AECM before enabling AEC"); |
| 513 | if (_shared->audio_processing()->echo_control_mobile()->Enable(false) != |
| 514 | 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 515 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 516 | "SetEcStatus() failed to disable AECM"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 517 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 518 | } |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 519 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 520 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 521 | if (_shared->audio_processing()->echo_cancellation()->Enable(enable) != 0) { |
| 522 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 523 | "SetEcStatus() failed to set AEC state"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 524 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 525 | } |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 526 | if (mode == kEcConference) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 527 | if (_shared->audio_processing() |
| 528 | ->echo_cancellation() |
| 529 | ->set_suppression_level(EchoCancellation::kHighSuppression) != |
| 530 | 0) { |
| 531 | _shared->SetLastError( |
| 532 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 533 | "SetEcStatus() failed to set aggressiveness to high"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 534 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 535 | } |
| 536 | } else { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 537 | if (_shared->audio_processing() |
| 538 | ->echo_cancellation() |
| 539 | ->set_suppression_level(EchoCancellation::kModerateSuppression) != |
| 540 | 0) { |
| 541 | _shared->SetLastError( |
| 542 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 543 | "SetEcStatus() failed to set aggressiveness to moderate"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 544 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 545 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 546 | } |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 547 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 548 | _isAecMode = true; |
| 549 | } else if ((mode == kEcAecm) || |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 550 | ((mode == kEcUnchanged) && (_isAecMode == false))) { |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 551 | if (enable) { |
| 552 | // Disable the AEC before enable the AECM |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 553 | if (_shared->audio_processing()->echo_cancellation()->is_enabled()) { |
| 554 | _shared->SetLastError(VE_APM_ERROR, kTraceWarning, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 555 | "SetEcStatus() disable AEC before enabling AECM"); |
| 556 | if (_shared->audio_processing()->echo_cancellation()->Enable(false) != |
| 557 | 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 558 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 559 | "SetEcStatus() failed to disable AEC"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 560 | return -1; |
| 561 | } |
| 562 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 563 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 564 | if (_shared->audio_processing()->echo_control_mobile()->Enable(enable) != |
| 565 | 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 566 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 567 | "SetEcStatus() failed to set AECM state"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 568 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 569 | } |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 570 | _isAecMode = false; |
| 571 | } else { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 572 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 573 | "SetEcStatus() invalid EC mode"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 574 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | return 0; |
| 578 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 579 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 580 | "SetEcStatus() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 581 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 582 | #endif |
| 583 | } |
| 584 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 585 | int VoEAudioProcessingImpl::GetEcStatus(bool& enabled, EcModes& mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 586 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 587 | if (!_shared->statistics().Initialized()) { |
| 588 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 589 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | if (_isAecMode == true) { |
| 593 | mode = kEcAec; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 594 | enabled = _shared->audio_processing()->echo_cancellation()->is_enabled(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 595 | } else { |
| 596 | mode = kEcAecm; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 597 | enabled = _shared->audio_processing()->echo_control_mobile()->is_enabled(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 598 | } |
| 599 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 600 | return 0; |
| 601 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 602 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 603 | "GetEcStatus() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 604 | return -1; |
| 605 | #endif |
| 606 | } |
| 607 | |
| 608 | void VoEAudioProcessingImpl::SetDelayOffsetMs(int offset) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 609 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 610 | "SetDelayOffsetMs(offset = %d)", offset); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 611 | _shared->audio_processing()->set_delay_offset_ms(offset); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | int VoEAudioProcessingImpl::DelayOffsetMs() { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 615 | return _shared->audio_processing()->delay_offset_ms(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | int VoEAudioProcessingImpl::SetAecmMode(AecmModes mode, bool enableCNG) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 619 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 620 | "SetAECMMode(mode = %d)", mode); |
| 621 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 622 | if (!_shared->statistics().Initialized()) { |
| 623 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 624 | return -1; |
| 625 | } |
| 626 | |
| 627 | EchoControlMobile::RoutingMode aecmMode( |
| 628 | EchoControlMobile::kQuietEarpieceOrHeadset); |
| 629 | |
| 630 | switch (mode) { |
| 631 | case kAecmQuietEarpieceOrHeadset: |
| 632 | aecmMode = EchoControlMobile::kQuietEarpieceOrHeadset; |
| 633 | break; |
| 634 | case kAecmEarpiece: |
| 635 | aecmMode = EchoControlMobile::kEarpiece; |
| 636 | break; |
| 637 | case kAecmLoudEarpiece: |
| 638 | aecmMode = EchoControlMobile::kLoudEarpiece; |
| 639 | break; |
| 640 | case kAecmSpeakerphone: |
| 641 | aecmMode = EchoControlMobile::kSpeakerphone; |
| 642 | break; |
| 643 | case kAecmLoudSpeakerphone: |
| 644 | aecmMode = EchoControlMobile::kLoudSpeakerphone; |
| 645 | break; |
| 646 | } |
| 647 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 648 | if (_shared->audio_processing()->echo_control_mobile()->set_routing_mode( |
| 649 | aecmMode) != 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 650 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 651 | "SetAECMMode() failed to set AECM routing mode"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 652 | return -1; |
| 653 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 654 | if (_shared->audio_processing()->echo_control_mobile()->enable_comfort_noise( |
| 655 | enableCNG) != 0) { |
| 656 | _shared->SetLastError( |
| 657 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 658 | "SetAECMMode() failed to set comfort noise state for AECM"); |
| 659 | return -1; |
| 660 | } |
| 661 | |
| 662 | return 0; |
| 663 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 664 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 665 | "SetAECMMode() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 666 | return -1; |
| 667 | #endif |
| 668 | } |
| 669 | |
| 670 | int VoEAudioProcessingImpl::GetAecmMode(AecmModes& mode, bool& enabledCNG) { |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 671 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 672 | if (!_shared->statistics().Initialized()) { |
| 673 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 674 | return -1; |
| 675 | } |
| 676 | |
| 677 | enabledCNG = false; |
| 678 | |
| 679 | EchoControlMobile::RoutingMode aecmMode = |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 680 | _shared->audio_processing()->echo_control_mobile()->routing_mode(); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 681 | enabledCNG = _shared->audio_processing() |
| 682 | ->echo_control_mobile() |
| 683 | ->is_comfort_noise_enabled(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 684 | |
| 685 | switch (aecmMode) { |
| 686 | case EchoControlMobile::kQuietEarpieceOrHeadset: |
| 687 | mode = kAecmQuietEarpieceOrHeadset; |
| 688 | break; |
| 689 | case EchoControlMobile::kEarpiece: |
| 690 | mode = kAecmEarpiece; |
| 691 | break; |
| 692 | case EchoControlMobile::kLoudEarpiece: |
| 693 | mode = kAecmLoudEarpiece; |
| 694 | break; |
| 695 | case EchoControlMobile::kSpeakerphone: |
| 696 | mode = kAecmSpeakerphone; |
| 697 | break; |
| 698 | case EchoControlMobile::kLoudSpeakerphone: |
| 699 | mode = kAecmLoudSpeakerphone; |
| 700 | break; |
| 701 | } |
| 702 | |
| 703 | return 0; |
| 704 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 705 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 706 | "GetAECMMode() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 707 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 708 | #endif |
| 709 | } |
| 710 | |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 711 | int VoEAudioProcessingImpl::EnableHighPassFilter(bool enable) { |
| 712 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 713 | "EnableHighPassFilter(%d)", enable); |
| 714 | if (_shared->audio_processing()->high_pass_filter()->Enable(enable) != |
| 715 | AudioProcessing::kNoError) { |
| 716 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 717 | "HighPassFilter::Enable() failed."); |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 718 | return -1; |
| 719 | } |
| 720 | |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | bool VoEAudioProcessingImpl::IsHighPassFilterEnabled() { |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 725 | return _shared->audio_processing()->high_pass_filter()->is_enabled(); |
| 726 | } |
| 727 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 728 | int VoEAudioProcessingImpl::RegisterRxVadObserver(int channel, |
| 729 | VoERxVadCallback& observer) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 730 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 731 | "RegisterRxVadObserver()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 732 | if (!_shared->statistics().Initialized()) { |
| 733 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 734 | return -1; |
| 735 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 736 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 737 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 738 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 739 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 740 | "RegisterRxVadObserver() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 741 | return -1; |
| 742 | } |
| 743 | return channelPtr->RegisterRxVadObserver(observer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 744 | } |
| 745 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 746 | int VoEAudioProcessingImpl::DeRegisterRxVadObserver(int channel) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 747 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 748 | "DeRegisterRxVadObserver()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 749 | if (!_shared->statistics().Initialized()) { |
| 750 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 751 | return -1; |
| 752 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 753 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 754 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 755 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 756 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 757 | "DeRegisterRxVadObserver() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 758 | return -1; |
| 759 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 760 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 761 | return channelPtr->DeRegisterRxVadObserver(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 762 | } |
| 763 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 764 | int VoEAudioProcessingImpl::VoiceActivityIndicator(int channel) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 765 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 766 | "VoiceActivityIndicator(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 767 | if (!_shared->statistics().Initialized()) { |
| 768 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 769 | return -1; |
| 770 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 771 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 772 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 773 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 774 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 775 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 776 | "DeRegisterRxVadObserver() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 777 | return -1; |
| 778 | } |
| 779 | int activity(-1); |
| 780 | channelPtr->VoiceActivityIndicator(activity); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 781 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 782 | return activity; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 783 | } |
| 784 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 785 | int VoEAudioProcessingImpl::SetEcMetricsStatus(bool enable) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 786 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 787 | "SetEcMetricsStatus(enable=%d)", enable); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 788 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 789 | if (!_shared->statistics().Initialized()) { |
| 790 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 791 | return -1; |
| 792 | } |
| 793 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 794 | if ((_shared->audio_processing()->echo_cancellation()->enable_metrics( |
| 795 | enable) != 0) || |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 796 | (_shared->audio_processing()->echo_cancellation()->enable_delay_logging( |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 797 | enable) != 0)) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 798 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 799 | "SetEcMetricsStatus() unable to set EC metrics mode"); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 800 | return -1; |
| 801 | } |
| 802 | return 0; |
| 803 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 804 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 805 | "SetEcStatus() EC is not supported"); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 806 | return -1; |
| 807 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 808 | } |
| 809 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 810 | int VoEAudioProcessingImpl::GetEcMetricsStatus(bool& enabled) { |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 811 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 812 | if (!_shared->statistics().Initialized()) { |
| 813 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 814 | return -1; |
| 815 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 816 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 817 | bool echo_mode = |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 818 | _shared->audio_processing()->echo_cancellation()->are_metrics_enabled(); |
| 819 | bool delay_mode = _shared->audio_processing() |
| 820 | ->echo_cancellation() |
| 821 | ->is_delay_logging_enabled(); |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 822 | |
| 823 | if (echo_mode != delay_mode) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 824 | _shared->SetLastError( |
| 825 | VE_APM_ERROR, kTraceError, |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 826 | "GetEcMetricsStatus() delay logging and echo mode are not the same"); |
| 827 | return -1; |
| 828 | } |
| 829 | |
| 830 | enabled = echo_mode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 831 | |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 832 | return 0; |
| 833 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 834 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 835 | "SetEcStatus() EC is not supported"); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 836 | return -1; |
| 837 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | int VoEAudioProcessingImpl::GetEchoMetrics(int& ERL, |
| 841 | int& ERLE, |
| 842 | int& RERL, |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 843 | int& A_NLP) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 844 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 845 | if (!_shared->statistics().Initialized()) { |
| 846 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 847 | return -1; |
| 848 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 849 | if (!_shared->audio_processing()->echo_cancellation()->is_enabled()) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 850 | _shared->SetLastError( |
| 851 | VE_APM_ERROR, kTraceWarning, |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 852 | "GetEchoMetrics() AudioProcessingModule AEC is not enabled"); |
| 853 | return -1; |
| 854 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 855 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 856 | // Get Echo Metrics from Audio Processing Module. |
| 857 | EchoCancellation::Metrics echoMetrics; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 858 | if (_shared->audio_processing()->echo_cancellation()->GetMetrics( |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 859 | &echoMetrics)) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 860 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1), |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 861 | "GetEchoMetrics(), AudioProcessingModule metrics error"); |
| 862 | return -1; |
| 863 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 864 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 865 | // Echo quality metrics. |
| 866 | ERL = echoMetrics.echo_return_loss.instant; |
| 867 | ERLE = echoMetrics.echo_return_loss_enhancement.instant; |
| 868 | RERL = echoMetrics.residual_echo_return_loss.instant; |
| 869 | A_NLP = echoMetrics.a_nlp.instant; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 870 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 871 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 872 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 873 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 874 | "SetEcStatus() EC is not supported"); |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 875 | return -1; |
| 876 | #endif |
| 877 | } |
| 878 | |
| 879 | int VoEAudioProcessingImpl::GetEcDelayMetrics(int& delay_median, |
bjornv@webrtc.org | cc64a9c | 2015-02-05 12:52:44 +0000 | [diff] [blame] | 880 | int& delay_std, |
| 881 | float& fraction_poor_delays) { |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 882 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 883 | if (!_shared->statistics().Initialized()) { |
| 884 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 885 | return -1; |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 886 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 887 | if (!_shared->audio_processing()->echo_cancellation()->is_enabled()) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 888 | _shared->SetLastError( |
| 889 | VE_APM_ERROR, kTraceWarning, |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 890 | "GetEcDelayMetrics() AudioProcessingModule AEC is not enabled"); |
| 891 | return -1; |
| 892 | } |
| 893 | |
| 894 | int median = 0; |
| 895 | int std = 0; |
bjornv@webrtc.org | cc64a9c | 2015-02-05 12:52:44 +0000 | [diff] [blame] | 896 | float poor_fraction = 0; |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 897 | // Get delay-logging values from Audio Processing Module. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 898 | if (_shared->audio_processing()->echo_cancellation()->GetDelayMetrics( |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 899 | &median, &std, &poor_fraction)) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 900 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1), |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 901 | "GetEcDelayMetrics(), AudioProcessingModule delay-logging " |
| 902 | "error"); |
| 903 | return -1; |
| 904 | } |
| 905 | |
| 906 | // EC delay-logging metrics |
| 907 | delay_median = median; |
| 908 | delay_std = std; |
bjornv@webrtc.org | cc64a9c | 2015-02-05 12:52:44 +0000 | [diff] [blame] | 909 | fraction_poor_delays = poor_fraction; |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 910 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 911 | return 0; |
| 912 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 913 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 914 | "SetEcStatus() EC is not supported"); |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 915 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 916 | #endif |
| 917 | } |
| 918 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 919 | int VoEAudioProcessingImpl::StartDebugRecording(const char* fileNameUTF8) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 920 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 921 | "StartDebugRecording()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 922 | if (!_shared->statistics().Initialized()) { |
| 923 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 924 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 925 | } |
| 926 | |
ivoc | a4df27b | 2015-12-19 10:14:10 -0800 | [diff] [blame^] | 927 | return _shared->audio_processing()->StartDebugRecording(fileNameUTF8); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 928 | } |
| 929 | |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 930 | int VoEAudioProcessingImpl::StartDebugRecording(FILE* file_handle) { |
| 931 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 932 | "StartDebugRecording()"); |
| 933 | if (!_shared->statistics().Initialized()) { |
| 934 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 935 | return -1; |
| 936 | } |
| 937 | |
ivoc | a4df27b | 2015-12-19 10:14:10 -0800 | [diff] [blame^] | 938 | return _shared->audio_processing()->StartDebugRecording(file_handle); |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 939 | } |
| 940 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 941 | int VoEAudioProcessingImpl::StopDebugRecording() { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 942 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 943 | "StopDebugRecording()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 944 | if (!_shared->statistics().Initialized()) { |
| 945 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 946 | return -1; |
| 947 | } |
| 948 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 949 | return _shared->audio_processing()->StopDebugRecording(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | int VoEAudioProcessingImpl::SetTypingDetectionStatus(bool enable) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 953 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 954 | "SetTypingDetectionStatus()"); |
andrew@webrtc.org | 0851df8 | 2013-06-19 17:03:47 +0000 | [diff] [blame] | 955 | #if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) |
| 956 | NOT_SUPPORTED(_shared->statistics()); |
| 957 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 958 | if (!_shared->statistics().Initialized()) { |
| 959 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 960 | return -1; |
| 961 | } |
| 962 | |
| 963 | // Just use the VAD state to determine if we should enable typing detection |
| 964 | // or not |
| 965 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 966 | if (_shared->audio_processing()->voice_detection()->Enable(enable)) { |
| 967 | _shared->SetLastError(VE_APM_ERROR, kTraceWarning, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 968 | "SetTypingDetectionStatus() failed to set VAD state"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 969 | return -1; |
| 970 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 971 | if (_shared->audio_processing()->voice_detection()->set_likelihood( |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 972 | VoiceDetection::kVeryLowLikelihood)) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 973 | _shared->SetLastError( |
| 974 | VE_APM_ERROR, kTraceWarning, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 975 | "SetTypingDetectionStatus() failed to set VAD likelihood to low"); |
| 976 | return -1; |
| 977 | } |
| 978 | |
| 979 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 980 | #endif |
| 981 | } |
| 982 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 983 | int VoEAudioProcessingImpl::GetTypingDetectionStatus(bool& enabled) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 984 | if (!_shared->statistics().Initialized()) { |
| 985 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 986 | return -1; |
| 987 | } |
| 988 | // Just use the VAD state to determine if we should enable typing |
| 989 | // detection or not |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 990 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 991 | enabled = _shared->audio_processing()->voice_detection()->is_enabled(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 992 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 993 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 996 | int VoEAudioProcessingImpl::TimeSinceLastTyping(int& seconds) { |
andrew@webrtc.org | 0851df8 | 2013-06-19 17:03:47 +0000 | [diff] [blame] | 997 | #if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) |
| 998 | NOT_SUPPORTED(_shared->statistics()); |
| 999 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1000 | if (!_shared->statistics().Initialized()) { |
| 1001 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1002 | return -1; |
| 1003 | } |
| 1004 | // Check if typing detection is enabled |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1005 | bool enabled = _shared->audio_processing()->voice_detection()->is_enabled(); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 1006 | if (enabled) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1007 | _shared->transmit_mixer()->TimeSinceLastTyping(seconds); |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1008 | return 0; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 1009 | } else { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1010 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 1011 | "SetTypingDetectionStatus is not enabled"); |
| 1012 | return -1; |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1013 | } |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1014 | #endif |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1017 | int VoEAudioProcessingImpl::SetTypingDetectionParameters(int timeWindow, |
| 1018 | int costPerTyping, |
| 1019 | int reportingThreshold, |
niklas.enbom@webrtc.org | f6edfef | 2012-05-09 13:16:12 +0000 | [diff] [blame] | 1020 | int penaltyDecay, |
| 1021 | int typeEventDelay) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1022 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1023 | "SetTypingDetectionParameters()"); |
andrew@webrtc.org | 0851df8 | 2013-06-19 17:03:47 +0000 | [diff] [blame] | 1024 | #if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) |
| 1025 | NOT_SUPPORTED(_shared->statistics()); |
| 1026 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1027 | if (!_shared->statistics().Initialized()) { |
| 1028 | _shared->statistics().SetLastError(VE_NOT_INITED, kTraceError); |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1029 | return -1; |
| 1030 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 1031 | return (_shared->transmit_mixer()->SetTypingDetectionParameters( |
| 1032 | timeWindow, costPerTyping, reportingThreshold, penaltyDecay, |
| 1033 | typeEventDelay)); |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1034 | #endif |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 1037 | void VoEAudioProcessingImpl::EnableStereoChannelSwapping(bool enable) { |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 1038 | _shared->transmit_mixer()->EnableStereoChannelSwapping(enable); |
| 1039 | } |
| 1040 | |
| 1041 | bool VoEAudioProcessingImpl::IsStereoChannelSwappingEnabled() { |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 1042 | return _shared->transmit_mixer()->IsStereoChannelSwappingEnabled(); |
| 1043 | } |
| 1044 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1045 | #endif // #ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API |
| 1046 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 1047 | } // namespace webrtc |