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