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 | |
| 316 | int VoEAudioProcessingImpl::SetRxNsStatus(int channel, |
| 317 | bool enable, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 318 | NsModes mode) { |
andrew@webrtc.org | ddcc942 | 2012-11-06 18:39:40 +0000 | [diff] [blame] | 319 | #ifdef WEBRTC_VOICE_ENGINE_NR |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 320 | if (!_shared->statistics().Initialized()) { |
| 321 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 322 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 323 | } |
| 324 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 325 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 326 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 327 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 328 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 329 | "SetRxNsStatus() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 330 | return -1; |
| 331 | } |
| 332 | return channelPtr->SetRxNsStatus(enable, mode); |
| 333 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 334 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 335 | "SetRxNsStatus() NS is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 336 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 337 | #endif |
| 338 | } |
| 339 | |
| 340 | int VoEAudioProcessingImpl::GetRxNsStatus(int channel, |
| 341 | bool& enabled, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 342 | NsModes& mode) { |
andrew@webrtc.org | ddcc942 | 2012-11-06 18:39:40 +0000 | [diff] [blame] | 343 | #ifdef WEBRTC_VOICE_ENGINE_NR |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 344 | if (!_shared->statistics().Initialized()) { |
| 345 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 346 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 347 | } |
| 348 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 349 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 350 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 351 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 352 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 353 | "GetRxNsStatus() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 354 | return -1; |
| 355 | } |
| 356 | return channelPtr->GetRxNsStatus(enabled, mode); |
| 357 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 358 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 359 | "GetRxNsStatus() NS is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 360 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 361 | #endif |
| 362 | } |
| 363 | |
| 364 | int VoEAudioProcessingImpl::SetRxAgcStatus(int channel, |
| 365 | bool enable, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 366 | AgcModes mode) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 367 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 368 | "SetRxAgcStatus(channel=%d, enable=%d, mode=%d)", channel, |
| 369 | (int)enable, (int)mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 370 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 371 | if (!_shared->statistics().Initialized()) { |
| 372 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 373 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 374 | } |
| 375 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 376 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 377 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 378 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 379 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 380 | "SetRxAgcStatus() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 381 | return -1; |
| 382 | } |
| 383 | return channelPtr->SetRxAgcStatus(enable, mode); |
| 384 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 385 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 386 | "SetRxAgcStatus() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 387 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 388 | #endif |
| 389 | } |
| 390 | |
| 391 | int VoEAudioProcessingImpl::GetRxAgcStatus(int channel, |
| 392 | bool& enabled, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 393 | AgcModes& mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 394 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 395 | if (!_shared->statistics().Initialized()) { |
| 396 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 397 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 398 | } |
| 399 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 400 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 401 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 402 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 403 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 404 | "GetRxAgcStatus() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 405 | return -1; |
| 406 | } |
| 407 | return channelPtr->GetRxAgcStatus(enabled, mode); |
| 408 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 409 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 410 | "GetRxAgcStatus() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 411 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 412 | #endif |
| 413 | } |
| 414 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 415 | int VoEAudioProcessingImpl::SetRxAgcConfig(int channel, AgcConfig config) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 416 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 417 | "SetRxAgcConfig(channel=%d)", channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 418 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 419 | if (!_shared->statistics().Initialized()) { |
| 420 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 421 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 422 | } |
| 423 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 424 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 425 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 426 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 427 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 428 | "SetRxAgcConfig() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 429 | return -1; |
| 430 | } |
| 431 | return channelPtr->SetRxAgcConfig(config); |
| 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 | "SetRxAgcConfig() Agc 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::GetRxAgcConfig(int channel, AgcConfig& config) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 440 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
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 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 446 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 447 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 448 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 449 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 450 | "GetRxAgcConfig() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 451 | return -1; |
| 452 | } |
| 453 | return channelPtr->GetRxAgcConfig(config); |
| 454 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 455 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 456 | "GetRxAgcConfig() Agc is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 457 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 458 | #endif |
| 459 | } |
| 460 | |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 461 | bool VoEAudioProcessing::DriftCompensationSupported() { |
| 462 | #if defined(WEBRTC_DRIFT_COMPENSATION_SUPPORTED) |
| 463 | return true; |
| 464 | #else |
| 465 | return false; |
| 466 | #endif |
| 467 | } |
| 468 | |
| 469 | int VoEAudioProcessingImpl::EnableDriftCompensation(bool enable) { |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 470 | WEBRTC_VOICE_INIT_CHECK(); |
| 471 | |
| 472 | if (!DriftCompensationSupported()) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 473 | _shared->SetLastError( |
| 474 | VE_APM_ERROR, kTraceWarning, |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 475 | "Drift compensation is not supported on this platform."); |
| 476 | return -1; |
| 477 | } |
| 478 | |
| 479 | EchoCancellation* aec = _shared->audio_processing()->echo_cancellation(); |
| 480 | if (aec->enable_drift_compensation(enable) != 0) { |
| 481 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 482 | "aec->enable_drift_compensation() failed"); |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 483 | return -1; |
| 484 | } |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | bool VoEAudioProcessingImpl::DriftCompensationEnabled() { |
andrew@webrtc.org | 55c0d4a | 2012-08-29 02:13:12 +0000 | [diff] [blame] | 489 | WEBRTC_VOICE_INIT_CHECK_BOOL(); |
| 490 | |
| 491 | EchoCancellation* aec = _shared->audio_processing()->echo_cancellation(); |
| 492 | return aec->is_drift_compensation_enabled(); |
| 493 | } |
| 494 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 495 | int VoEAudioProcessingImpl::SetEcStatus(bool enable, EcModes mode) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 496 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 497 | "SetEcStatus(enable=%d, mode=%d)", enable, mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 498 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 499 | if (!_shared->statistics().Initialized()) { |
| 500 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 501 | return -1; |
| 502 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 503 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 504 | // AEC mode |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 505 | if ((mode == kEcDefault) || (mode == kEcConference) || (mode == kEcAec) || |
| 506 | ((mode == kEcUnchanged) && (_isAecMode == true))) { |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 507 | if (enable) { |
| 508 | // Disable the AECM before enable the AEC |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 509 | if (_shared->audio_processing()->echo_control_mobile()->is_enabled()) { |
| 510 | _shared->SetLastError(VE_APM_ERROR, kTraceWarning, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 511 | "SetEcStatus() disable AECM before enabling AEC"); |
| 512 | if (_shared->audio_processing()->echo_control_mobile()->Enable(false) != |
| 513 | 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 514 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 515 | "SetEcStatus() failed to disable AECM"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 516 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 517 | } |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 518 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 519 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 520 | if (_shared->audio_processing()->echo_cancellation()->Enable(enable) != 0) { |
| 521 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 522 | "SetEcStatus() failed to set AEC state"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 523 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 524 | } |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 525 | if (mode == kEcConference) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 526 | if (_shared->audio_processing() |
| 527 | ->echo_cancellation() |
| 528 | ->set_suppression_level(EchoCancellation::kHighSuppression) != |
| 529 | 0) { |
| 530 | _shared->SetLastError( |
| 531 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 532 | "SetEcStatus() failed to set aggressiveness to high"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 533 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 534 | } |
| 535 | } else { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 536 | if (_shared->audio_processing() |
| 537 | ->echo_cancellation() |
| 538 | ->set_suppression_level(EchoCancellation::kModerateSuppression) != |
| 539 | 0) { |
| 540 | _shared->SetLastError( |
| 541 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 542 | "SetEcStatus() failed to set aggressiveness to moderate"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 543 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 544 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 545 | } |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 546 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 547 | _isAecMode = true; |
| 548 | } else if ((mode == kEcAecm) || |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 549 | ((mode == kEcUnchanged) && (_isAecMode == false))) { |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 550 | if (enable) { |
| 551 | // Disable the AEC before enable the AECM |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 552 | if (_shared->audio_processing()->echo_cancellation()->is_enabled()) { |
| 553 | _shared->SetLastError(VE_APM_ERROR, kTraceWarning, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 554 | "SetEcStatus() disable AEC before enabling AECM"); |
| 555 | if (_shared->audio_processing()->echo_cancellation()->Enable(false) != |
| 556 | 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 557 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 558 | "SetEcStatus() failed to disable AEC"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 559 | return -1; |
| 560 | } |
| 561 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 562 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 563 | if (_shared->audio_processing()->echo_control_mobile()->Enable(enable) != |
| 564 | 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 565 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 566 | "SetEcStatus() failed to set AECM state"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 567 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 568 | } |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 569 | _isAecMode = false; |
| 570 | } else { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 571 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 572 | "SetEcStatus() invalid EC mode"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 573 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | return 0; |
| 577 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 578 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 579 | "SetEcStatus() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 580 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 581 | #endif |
| 582 | } |
| 583 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 584 | int VoEAudioProcessingImpl::GetEcStatus(bool& enabled, EcModes& mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 585 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 586 | if (!_shared->statistics().Initialized()) { |
| 587 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 588 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | if (_isAecMode == true) { |
| 592 | mode = kEcAec; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 593 | enabled = _shared->audio_processing()->echo_cancellation()->is_enabled(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 594 | } else { |
| 595 | mode = kEcAecm; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 596 | enabled = _shared->audio_processing()->echo_control_mobile()->is_enabled(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 597 | } |
| 598 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 599 | return 0; |
| 600 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 601 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 602 | "GetEcStatus() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 603 | return -1; |
| 604 | #endif |
| 605 | } |
| 606 | |
| 607 | void VoEAudioProcessingImpl::SetDelayOffsetMs(int offset) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 608 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 609 | "SetDelayOffsetMs(offset = %d)", offset); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 610 | _shared->audio_processing()->set_delay_offset_ms(offset); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | int VoEAudioProcessingImpl::DelayOffsetMs() { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 614 | return _shared->audio_processing()->delay_offset_ms(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | int VoEAudioProcessingImpl::SetAecmMode(AecmModes mode, bool enableCNG) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 618 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 619 | "SetAECMMode(mode = %d)", mode); |
| 620 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 621 | if (!_shared->statistics().Initialized()) { |
| 622 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 623 | return -1; |
| 624 | } |
| 625 | |
| 626 | EchoControlMobile::RoutingMode aecmMode( |
| 627 | EchoControlMobile::kQuietEarpieceOrHeadset); |
| 628 | |
| 629 | switch (mode) { |
| 630 | case kAecmQuietEarpieceOrHeadset: |
| 631 | aecmMode = EchoControlMobile::kQuietEarpieceOrHeadset; |
| 632 | break; |
| 633 | case kAecmEarpiece: |
| 634 | aecmMode = EchoControlMobile::kEarpiece; |
| 635 | break; |
| 636 | case kAecmLoudEarpiece: |
| 637 | aecmMode = EchoControlMobile::kLoudEarpiece; |
| 638 | break; |
| 639 | case kAecmSpeakerphone: |
| 640 | aecmMode = EchoControlMobile::kSpeakerphone; |
| 641 | break; |
| 642 | case kAecmLoudSpeakerphone: |
| 643 | aecmMode = EchoControlMobile::kLoudSpeakerphone; |
| 644 | break; |
| 645 | } |
| 646 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 647 | if (_shared->audio_processing()->echo_control_mobile()->set_routing_mode( |
| 648 | aecmMode) != 0) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 649 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 650 | "SetAECMMode() failed to set AECM routing mode"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 651 | return -1; |
| 652 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 653 | if (_shared->audio_processing()->echo_control_mobile()->enable_comfort_noise( |
| 654 | enableCNG) != 0) { |
| 655 | _shared->SetLastError( |
| 656 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 657 | "SetAECMMode() failed to set comfort noise state for AECM"); |
| 658 | return -1; |
| 659 | } |
| 660 | |
| 661 | return 0; |
| 662 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 663 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 664 | "SetAECMMode() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 665 | return -1; |
| 666 | #endif |
| 667 | } |
| 668 | |
| 669 | int VoEAudioProcessingImpl::GetAecmMode(AecmModes& mode, bool& enabledCNG) { |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 670 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 671 | if (!_shared->statistics().Initialized()) { |
| 672 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 673 | return -1; |
| 674 | } |
| 675 | |
| 676 | enabledCNG = false; |
| 677 | |
| 678 | EchoControlMobile::RoutingMode aecmMode = |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 679 | _shared->audio_processing()->echo_control_mobile()->routing_mode(); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 680 | enabledCNG = _shared->audio_processing() |
| 681 | ->echo_control_mobile() |
| 682 | ->is_comfort_noise_enabled(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 683 | |
| 684 | switch (aecmMode) { |
| 685 | case EchoControlMobile::kQuietEarpieceOrHeadset: |
| 686 | mode = kAecmQuietEarpieceOrHeadset; |
| 687 | break; |
| 688 | case EchoControlMobile::kEarpiece: |
| 689 | mode = kAecmEarpiece; |
| 690 | break; |
| 691 | case EchoControlMobile::kLoudEarpiece: |
| 692 | mode = kAecmLoudEarpiece; |
| 693 | break; |
| 694 | case EchoControlMobile::kSpeakerphone: |
| 695 | mode = kAecmSpeakerphone; |
| 696 | break; |
| 697 | case EchoControlMobile::kLoudSpeakerphone: |
| 698 | mode = kAecmLoudSpeakerphone; |
| 699 | break; |
| 700 | } |
| 701 | |
| 702 | return 0; |
| 703 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 704 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 705 | "GetAECMMode() EC is not supported"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 706 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 707 | #endif |
| 708 | } |
| 709 | |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 710 | int VoEAudioProcessingImpl::EnableHighPassFilter(bool enable) { |
| 711 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 712 | "EnableHighPassFilter(%d)", enable); |
| 713 | if (_shared->audio_processing()->high_pass_filter()->Enable(enable) != |
| 714 | AudioProcessing::kNoError) { |
| 715 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 716 | "HighPassFilter::Enable() failed."); |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 717 | return -1; |
| 718 | } |
| 719 | |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | bool VoEAudioProcessingImpl::IsHighPassFilterEnabled() { |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 724 | return _shared->audio_processing()->high_pass_filter()->is_enabled(); |
| 725 | } |
| 726 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 727 | int VoEAudioProcessingImpl::RegisterRxVadObserver(int channel, |
| 728 | VoERxVadCallback& observer) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 729 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 730 | "RegisterRxVadObserver()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 731 | if (!_shared->statistics().Initialized()) { |
| 732 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 733 | return -1; |
| 734 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 735 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 736 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 737 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 738 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 739 | "RegisterRxVadObserver() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 740 | return -1; |
| 741 | } |
| 742 | return channelPtr->RegisterRxVadObserver(observer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 743 | } |
| 744 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 745 | int VoEAudioProcessingImpl::DeRegisterRxVadObserver(int channel) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 746 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 747 | "DeRegisterRxVadObserver()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 748 | if (!_shared->statistics().Initialized()) { |
| 749 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 750 | return -1; |
| 751 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 752 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 753 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 754 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 755 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 756 | "DeRegisterRxVadObserver() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 757 | return -1; |
| 758 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 759 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 760 | return channelPtr->DeRegisterRxVadObserver(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 761 | } |
| 762 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 763 | int VoEAudioProcessingImpl::VoiceActivityIndicator(int channel) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 764 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 765 | "VoiceActivityIndicator(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 766 | if (!_shared->statistics().Initialized()) { |
| 767 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 768 | return -1; |
| 769 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 770 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 771 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 772 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 773 | if (channelPtr == NULL) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 774 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 775 | "DeRegisterRxVadObserver() failed to locate channel"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 776 | return -1; |
| 777 | } |
| 778 | int activity(-1); |
| 779 | channelPtr->VoiceActivityIndicator(activity); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 780 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 781 | return activity; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 782 | } |
| 783 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 784 | int VoEAudioProcessingImpl::SetEcMetricsStatus(bool enable) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 785 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 786 | "SetEcMetricsStatus(enable=%d)", enable); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 787 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 788 | if (!_shared->statistics().Initialized()) { |
| 789 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 790 | return -1; |
| 791 | } |
| 792 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 793 | if ((_shared->audio_processing()->echo_cancellation()->enable_metrics( |
| 794 | enable) != 0) || |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 795 | (_shared->audio_processing()->echo_cancellation()->enable_delay_logging( |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 796 | enable) != 0)) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 797 | _shared->SetLastError(VE_APM_ERROR, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 798 | "SetEcMetricsStatus() unable to set EC metrics mode"); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 799 | return -1; |
| 800 | } |
| 801 | return 0; |
| 802 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 803 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 804 | "SetEcStatus() EC is not supported"); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 805 | return -1; |
| 806 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 807 | } |
| 808 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 809 | int VoEAudioProcessingImpl::GetEcMetricsStatus(bool& enabled) { |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 810 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 811 | if (!_shared->statistics().Initialized()) { |
| 812 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 813 | return -1; |
| 814 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 815 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 816 | bool echo_mode = |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 817 | _shared->audio_processing()->echo_cancellation()->are_metrics_enabled(); |
| 818 | bool delay_mode = _shared->audio_processing() |
| 819 | ->echo_cancellation() |
| 820 | ->is_delay_logging_enabled(); |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 821 | |
| 822 | if (echo_mode != delay_mode) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 823 | _shared->SetLastError( |
| 824 | VE_APM_ERROR, kTraceError, |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 825 | "GetEcMetricsStatus() delay logging and echo mode are not the same"); |
| 826 | return -1; |
| 827 | } |
| 828 | |
| 829 | enabled = echo_mode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 830 | |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 831 | return 0; |
| 832 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 833 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 834 | "SetEcStatus() EC is not supported"); |
bjornv@google.com | 0beae67 | 2011-09-28 14:08:19 +0000 | [diff] [blame] | 835 | return -1; |
| 836 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | int VoEAudioProcessingImpl::GetEchoMetrics(int& ERL, |
| 840 | int& ERLE, |
| 841 | int& RERL, |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 842 | int& A_NLP) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 843 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 844 | if (!_shared->statistics().Initialized()) { |
| 845 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 846 | return -1; |
| 847 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 848 | if (!_shared->audio_processing()->echo_cancellation()->is_enabled()) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 849 | _shared->SetLastError( |
| 850 | VE_APM_ERROR, kTraceWarning, |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 851 | "GetEchoMetrics() AudioProcessingModule AEC is not enabled"); |
| 852 | return -1; |
| 853 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 854 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 855 | // Get Echo Metrics from Audio Processing Module. |
| 856 | EchoCancellation::Metrics echoMetrics; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 857 | if (_shared->audio_processing()->echo_cancellation()->GetMetrics( |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 858 | &echoMetrics)) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 859 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1), |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 860 | "GetEchoMetrics(), AudioProcessingModule metrics error"); |
| 861 | return -1; |
| 862 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 863 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 864 | // Echo quality metrics. |
| 865 | ERL = echoMetrics.echo_return_loss.instant; |
| 866 | ERLE = echoMetrics.echo_return_loss_enhancement.instant; |
| 867 | RERL = echoMetrics.residual_echo_return_loss.instant; |
| 868 | A_NLP = echoMetrics.a_nlp.instant; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 869 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 870 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 871 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 872 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 873 | "SetEcStatus() EC is not supported"); |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 874 | return -1; |
| 875 | #endif |
| 876 | } |
| 877 | |
| 878 | int VoEAudioProcessingImpl::GetEcDelayMetrics(int& delay_median, |
bjornv@webrtc.org | cc64a9c | 2015-02-05 12:52:44 +0000 | [diff] [blame] | 879 | int& delay_std, |
| 880 | float& fraction_poor_delays) { |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 881 | #ifdef WEBRTC_VOICE_ENGINE_ECHO |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 882 | if (!_shared->statistics().Initialized()) { |
| 883 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 884 | return -1; |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 885 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 886 | if (!_shared->audio_processing()->echo_cancellation()->is_enabled()) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 887 | _shared->SetLastError( |
| 888 | VE_APM_ERROR, kTraceWarning, |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 889 | "GetEcDelayMetrics() AudioProcessingModule AEC is not enabled"); |
| 890 | return -1; |
| 891 | } |
| 892 | |
| 893 | int median = 0; |
| 894 | int std = 0; |
bjornv@webrtc.org | cc64a9c | 2015-02-05 12:52:44 +0000 | [diff] [blame] | 895 | float poor_fraction = 0; |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 896 | // Get delay-logging values from Audio Processing Module. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 897 | if (_shared->audio_processing()->echo_cancellation()->GetDelayMetrics( |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 898 | &median, &std, &poor_fraction)) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 899 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1), |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 900 | "GetEcDelayMetrics(), AudioProcessingModule delay-logging " |
| 901 | "error"); |
| 902 | return -1; |
| 903 | } |
| 904 | |
| 905 | // EC delay-logging metrics |
| 906 | delay_median = median; |
| 907 | delay_std = std; |
bjornv@webrtc.org | cc64a9c | 2015-02-05 12:52:44 +0000 | [diff] [blame] | 908 | fraction_poor_delays = poor_fraction; |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 909 | |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 910 | return 0; |
| 911 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 912 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 913 | "SetEcStatus() EC is not supported"); |
bjornv@webrtc.org | 3765bd2 | 2011-10-17 08:49:23 +0000 | [diff] [blame] | 914 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 915 | #endif |
| 916 | } |
| 917 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 918 | int VoEAudioProcessingImpl::StartDebugRecording(const char* fileNameUTF8) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 919 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 920 | "StartDebugRecording()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 921 | if (!_shared->statistics().Initialized()) { |
| 922 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 923 | return -1; |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 924 | } |
| 925 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 926 | return _shared->audio_processing()->StartDebugRecording(fileNameUTF8, -1); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 927 | } |
| 928 | |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 929 | int VoEAudioProcessingImpl::StartDebugRecording(FILE* file_handle) { |
| 930 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 931 | "StartDebugRecording()"); |
| 932 | if (!_shared->statistics().Initialized()) { |
| 933 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 934 | return -1; |
| 935 | } |
| 936 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 937 | return _shared->audio_processing()->StartDebugRecording(file_handle, -1); |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 938 | } |
| 939 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 940 | int VoEAudioProcessingImpl::StopDebugRecording() { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 941 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 942 | "StopDebugRecording()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 943 | if (!_shared->statistics().Initialized()) { |
| 944 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 945 | return -1; |
| 946 | } |
| 947 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 948 | return _shared->audio_processing()->StopDebugRecording(); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | int VoEAudioProcessingImpl::SetTypingDetectionStatus(bool enable) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 952 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 953 | "SetTypingDetectionStatus()"); |
andrew@webrtc.org | 0851df8 | 2013-06-19 17:03:47 +0000 | [diff] [blame] | 954 | #if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) |
| 955 | NOT_SUPPORTED(_shared->statistics()); |
| 956 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 957 | if (!_shared->statistics().Initialized()) { |
| 958 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 959 | return -1; |
| 960 | } |
| 961 | |
| 962 | // Just use the VAD state to determine if we should enable typing detection |
| 963 | // or not |
| 964 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 965 | if (_shared->audio_processing()->voice_detection()->Enable(enable)) { |
| 966 | _shared->SetLastError(VE_APM_ERROR, kTraceWarning, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 967 | "SetTypingDetectionStatus() failed to set VAD state"); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 968 | return -1; |
| 969 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 970 | if (_shared->audio_processing()->voice_detection()->set_likelihood( |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 971 | VoiceDetection::kVeryLowLikelihood)) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 972 | _shared->SetLastError( |
| 973 | VE_APM_ERROR, kTraceWarning, |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 974 | "SetTypingDetectionStatus() failed to set VAD likelihood to low"); |
| 975 | return -1; |
| 976 | } |
| 977 | |
| 978 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 979 | #endif |
| 980 | } |
| 981 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 982 | int VoEAudioProcessingImpl::GetTypingDetectionStatus(bool& enabled) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 983 | if (!_shared->statistics().Initialized()) { |
| 984 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 985 | return -1; |
| 986 | } |
| 987 | // Just use the VAD state to determine if we should enable typing |
| 988 | // detection or not |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 989 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 990 | enabled = _shared->audio_processing()->voice_detection()->is_enabled(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 991 | |
andrew@webrtc.org | 8b111eb | 2012-03-06 19:50:12 +0000 | [diff] [blame] | 992 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 995 | int VoEAudioProcessingImpl::TimeSinceLastTyping(int& seconds) { |
andrew@webrtc.org | 0851df8 | 2013-06-19 17:03:47 +0000 | [diff] [blame] | 996 | #if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) |
| 997 | NOT_SUPPORTED(_shared->statistics()); |
| 998 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 999 | if (!_shared->statistics().Initialized()) { |
| 1000 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1001 | return -1; |
| 1002 | } |
| 1003 | // Check if typing detection is enabled |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1004 | bool enabled = _shared->audio_processing()->voice_detection()->is_enabled(); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 1005 | if (enabled) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1006 | _shared->transmit_mixer()->TimeSinceLastTyping(seconds); |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1007 | return 0; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 1008 | } else { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1009 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 1010 | "SetTypingDetectionStatus is not enabled"); |
| 1011 | return -1; |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1012 | } |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1013 | #endif |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1016 | int VoEAudioProcessingImpl::SetTypingDetectionParameters(int timeWindow, |
| 1017 | int costPerTyping, |
| 1018 | int reportingThreshold, |
niklas.enbom@webrtc.org | f6edfef | 2012-05-09 13:16:12 +0000 | [diff] [blame] | 1019 | int penaltyDecay, |
| 1020 | int typeEventDelay) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1021 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1022 | "SetTypingDetectionParameters()"); |
andrew@webrtc.org | 0851df8 | 2013-06-19 17:03:47 +0000 | [diff] [blame] | 1023 | #if !defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) |
| 1024 | NOT_SUPPORTED(_shared->statistics()); |
| 1025 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1026 | if (!_shared->statistics().Initialized()) { |
| 1027 | _shared->statistics().SetLastError(VE_NOT_INITED, kTraceError); |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1028 | return -1; |
| 1029 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 1030 | return (_shared->transmit_mixer()->SetTypingDetectionParameters( |
| 1031 | timeWindow, costPerTyping, reportingThreshold, penaltyDecay, |
| 1032 | typeEventDelay)); |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1033 | #endif |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 1036 | void VoEAudioProcessingImpl::EnableStereoChannelSwapping(bool enable) { |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 1037 | _shared->transmit_mixer()->EnableStereoChannelSwapping(enable); |
| 1038 | } |
| 1039 | |
| 1040 | bool VoEAudioProcessingImpl::IsStereoChannelSwappingEnabled() { |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 1041 | return _shared->transmit_mixer()->IsStereoChannelSwappingEnabled(); |
| 1042 | } |
| 1043 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1044 | #endif // #ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API |
| 1045 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 1046 | } // namespace webrtc |