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