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