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