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_codec_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 13 | #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" |
| 14 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 15 | #include "webrtc/system_wrappers/interface/trace.h" |
| 16 | #include "webrtc/voice_engine/channel.h" |
| 17 | #include "webrtc/voice_engine/include/voe_errors.h" |
| 18 | #include "webrtc/voice_engine/voice_engine_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 20 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 22 | VoECodec* VoECodec::GetInterface(VoiceEngine* voiceEngine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | #ifndef WEBRTC_VOICE_ENGINE_CODEC_API |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 24 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | #else |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 26 | if (NULL == voiceEngine) { |
| 27 | return NULL; |
| 28 | } |
| 29 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
| 30 | s->AddRef(); |
| 31 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | #endif |
| 33 | } |
| 34 | |
| 35 | #ifdef WEBRTC_VOICE_ENGINE_CODEC_API |
| 36 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 37 | VoECodecImpl::VoECodecImpl(voe::SharedData* shared) : _shared(shared) { |
| 38 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 39 | "VoECodecImpl() - ctor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 42 | VoECodecImpl::~VoECodecImpl() { |
| 43 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 44 | "~VoECodecImpl() - dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 47 | int VoECodecImpl::NumOfCodecs() { |
| 48 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 49 | "NumOfCodecs()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 51 | // Number of supported codecs in the ACM |
| 52 | uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 54 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 55 | "NumOfCodecs() => %u", nSupportedCodecs); |
| 56 | return (nSupportedCodecs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 59 | int VoECodecImpl::GetCodec(int index, CodecInst& codec) { |
| 60 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 61 | "GetCodec(index=%d, codec=?)", index); |
| 62 | CodecInst acmCodec; |
| 63 | if (AudioCodingModule::Codec(index, &acmCodec) == -1) { |
| 64 | _shared->SetLastError(VE_INVALID_LISTNR, kTraceError, |
| 65 | "GetCodec() invalid index"); |
| 66 | return -1; |
| 67 | } |
| 68 | ACMToExternalCodecRepresentation(codec, acmCodec); |
| 69 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 70 | "GetCodec() => plname=%s, pacsize=%d, plfreq=%d, pltype=%d, " |
| 71 | "channels=%d, rate=%d", |
| 72 | codec.plname, codec.pacsize, codec.plfreq, codec.pltype, |
| 73 | codec.channels, codec.rate); |
| 74 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 77 | int VoECodecImpl::SetSendCodec(int channel, const CodecInst& codec) { |
| 78 | CodecInst copyCodec; |
| 79 | ExternalToACMCodecRepresentation(copyCodec, codec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 81 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 82 | "SetSendCodec(channel=%d, codec)", channel); |
| 83 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 84 | "codec: plname=%s, pacsize=%d, plfreq=%d, pltype=%d, " |
| 85 | "channels=%d, rate=%d", |
| 86 | codec.plname, codec.pacsize, codec.plfreq, codec.pltype, |
| 87 | codec.channels, codec.rate); |
| 88 | if (!_shared->statistics().Initialized()) { |
| 89 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 90 | return -1; |
| 91 | } |
| 92 | // External sanity checks performed outside the ACM |
| 93 | if ((STR_CASE_CMP(copyCodec.plname, "L16") == 0) && |
| 94 | (copyCodec.pacsize >= 960)) { |
| 95 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 96 | "SetSendCodec() invalid L16 packet size"); |
| 97 | return -1; |
| 98 | } |
| 99 | if (!STR_CASE_CMP(copyCodec.plname, "CN") || |
| 100 | !STR_CASE_CMP(copyCodec.plname, "TELEPHONE-EVENT") || |
| 101 | !STR_CASE_CMP(copyCodec.plname, "RED")) { |
| 102 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 103 | "SetSendCodec() invalid codec name"); |
| 104 | return -1; |
| 105 | } |
| 106 | if ((copyCodec.channels != 1) && (copyCodec.channels != 2)) { |
| 107 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 108 | "SetSendCodec() invalid number of channels"); |
| 109 | return -1; |
| 110 | } |
| 111 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 112 | voe::Channel* channelPtr = ch.channel(); |
| 113 | if (channelPtr == NULL) { |
| 114 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 115 | "GetSendCodec() failed to locate channel"); |
| 116 | return -1; |
| 117 | } |
| 118 | if (!AudioCodingModule::IsCodecValid((CodecInst&)copyCodec)) { |
| 119 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 120 | "SetSendCodec() invalid codec"); |
| 121 | return -1; |
| 122 | } |
| 123 | if (channelPtr->SetSendCodec(copyCodec) != 0) { |
| 124 | _shared->SetLastError(VE_CANNOT_SET_SEND_CODEC, kTraceError, |
| 125 | "SetSendCodec() failed to set send codec"); |
| 126 | return -1; |
| 127 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 129 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 132 | int VoECodecImpl::GetSendCodec(int channel, CodecInst& codec) { |
| 133 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 134 | "GetSendCodec(channel=%d, codec=?)", channel); |
| 135 | if (!_shared->statistics().Initialized()) { |
| 136 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 137 | return -1; |
| 138 | } |
| 139 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 140 | voe::Channel* channelPtr = ch.channel(); |
| 141 | if (channelPtr == NULL) { |
| 142 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 143 | "GetSendCodec() failed to locate channel"); |
| 144 | return -1; |
| 145 | } |
| 146 | CodecInst acmCodec; |
| 147 | if (channelPtr->GetSendCodec(acmCodec) != 0) { |
| 148 | _shared->SetLastError(VE_CANNOT_GET_SEND_CODEC, kTraceError, |
| 149 | "GetSendCodec() failed to get send codec"); |
| 150 | return -1; |
| 151 | } |
| 152 | ACMToExternalCodecRepresentation(codec, acmCodec); |
| 153 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 154 | "GetSendCodec() => plname=%s, pacsize=%d, plfreq=%d, " |
| 155 | "channels=%d, rate=%d", |
| 156 | codec.plname, codec.pacsize, codec.plfreq, codec.channels, |
| 157 | codec.rate); |
| 158 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Ivo Creusen | adf89b7 | 2015-04-29 16:03:33 +0200 | [diff] [blame] | 161 | int VoECodecImpl::SetBitRate(int channel, int bitrate_bps) { |
| 162 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 163 | "SetBitRate(bitrate_bps=%d)", bitrate_bps); |
| 164 | if (!_shared->statistics().Initialized()) { |
| 165 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 166 | return -1; |
| 167 | } |
| 168 | _shared->channel_manager().GetChannel(channel).channel()->SetBitRate( |
| 169 | bitrate_bps); |
| 170 | return 0; |
| 171 | } |
| 172 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 173 | int VoECodecImpl::GetRecCodec(int channel, CodecInst& codec) { |
| 174 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 175 | "GetRecCodec(channel=%d, codec=?)", channel); |
| 176 | if (!_shared->statistics().Initialized()) { |
| 177 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 178 | return -1; |
| 179 | } |
| 180 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 181 | voe::Channel* channelPtr = ch.channel(); |
| 182 | if (channelPtr == NULL) { |
| 183 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 184 | "GetRecCodec() failed to locate channel"); |
| 185 | return -1; |
| 186 | } |
| 187 | CodecInst acmCodec; |
| 188 | if (channelPtr->GetRecCodec(acmCodec) != 0) { |
| 189 | _shared->SetLastError(VE_CANNOT_GET_REC_CODEC, kTraceError, |
| 190 | "GetRecCodec() failed to get received codec"); |
| 191 | return -1; |
| 192 | } |
| 193 | ACMToExternalCodecRepresentation(codec, acmCodec); |
| 194 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 195 | "GetRecCodec() => plname=%s, pacsize=%d, plfreq=%d, " |
| 196 | "channels=%d, rate=%d", |
| 197 | codec.plname, codec.pacsize, codec.plfreq, codec.channels, |
| 198 | codec.rate); |
| 199 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 202 | int VoECodecImpl::SetRecPayloadType(int channel, const CodecInst& codec) { |
| 203 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 204 | "SetRecPayloadType(channel=%d, codec)", channel); |
| 205 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | "codec: plname=%s, plfreq=%d, pltype=%d, channels=%u, " |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 207 | "pacsize=%d, rate=%d", |
| 208 | codec.plname, codec.plfreq, codec.pltype, codec.channels, |
| 209 | codec.pacsize, codec.rate); |
| 210 | if (!_shared->statistics().Initialized()) { |
| 211 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 212 | return -1; |
| 213 | } |
| 214 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 215 | voe::Channel* channelPtr = ch.channel(); |
| 216 | if (channelPtr == NULL) { |
| 217 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 218 | "GetRecPayloadType() failed to locate channel"); |
| 219 | return -1; |
| 220 | } |
| 221 | return channelPtr->SetRecPayloadType(codec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 224 | int VoECodecImpl::GetRecPayloadType(int channel, CodecInst& codec) { |
| 225 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 226 | "GetRecPayloadType(channel=%d, codec)", channel); |
| 227 | if (!_shared->statistics().Initialized()) { |
| 228 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 229 | return -1; |
| 230 | } |
| 231 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 232 | voe::Channel* channelPtr = ch.channel(); |
| 233 | if (channelPtr == NULL) { |
| 234 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 235 | "GetRecPayloadType() failed to locate channel"); |
| 236 | return -1; |
| 237 | } |
| 238 | return channelPtr->GetRecPayloadType(codec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 241 | int VoECodecImpl::SetSendCNPayloadType(int channel, |
| 242 | int type, |
| 243 | PayloadFrequencies frequency) { |
| 244 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 245 | "SetSendCNPayloadType(channel=%d, type=%d, frequency=%d)", |
| 246 | channel, type, frequency); |
| 247 | if (!_shared->statistics().Initialized()) { |
| 248 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 249 | return -1; |
| 250 | } |
| 251 | if (type < 96 || type > 127) { |
| 252 | // Only allow dynamic range: 96 to 127 |
| 253 | _shared->SetLastError(VE_INVALID_PLTYPE, kTraceError, |
| 254 | "SetSendCNPayloadType() invalid payload type"); |
| 255 | return -1; |
| 256 | } |
| 257 | if ((frequency != kFreq16000Hz) && (frequency != kFreq32000Hz)) { |
| 258 | // It is not possible to modify the payload type for CN/8000. |
| 259 | // We only allow modification of the CN payload type for CN/16000 |
| 260 | // and CN/32000. |
| 261 | _shared->SetLastError(VE_INVALID_PLFREQ, kTraceError, |
| 262 | "SetSendCNPayloadType() invalid payload frequency"); |
| 263 | return -1; |
| 264 | } |
| 265 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 266 | voe::Channel* channelPtr = ch.channel(); |
| 267 | if (channelPtr == NULL) { |
| 268 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 269 | "SetSendCNPayloadType() failed to locate channel"); |
| 270 | return -1; |
| 271 | } |
| 272 | return channelPtr->SetSendCNPayloadType(type, frequency); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 275 | int VoECodecImpl::SetFECStatus(int channel, bool enable) { |
| 276 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 277 | "SetCodecFECStatus(channel=%d, enable=%d)", channel, enable); |
| 278 | if (!_shared->statistics().Initialized()) { |
| 279 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 280 | return -1; |
| 281 | } |
| 282 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 283 | voe::Channel* channelPtr = ch.channel(); |
| 284 | if (channelPtr == NULL) { |
| 285 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 286 | "SetCodecFECStatus() failed to locate channel"); |
| 287 | return -1; |
| 288 | } |
| 289 | return channelPtr->SetCodecFECStatus(enable); |
| 290 | } |
| 291 | |
| 292 | int VoECodecImpl::GetFECStatus(int channel, bool& enabled) { |
| 293 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 294 | "GetCodecFECStatus(channel=%d)", channel); |
| 295 | if (!_shared->statistics().Initialized()) { |
| 296 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 297 | return -1; |
| 298 | } |
| 299 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 300 | voe::Channel* channelPtr = ch.channel(); |
| 301 | if (channelPtr == NULL) { |
| 302 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 303 | "GetFECStatus() failed to locate channel"); |
| 304 | return -1; |
| 305 | } |
| 306 | enabled = channelPtr->GetCodecFECStatus(); |
| 307 | return 0; |
| 308 | } |
| 309 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 310 | int VoECodecImpl::SetVADStatus(int channel, |
| 311 | bool enable, |
| 312 | VadModes mode, |
| 313 | bool disableDTX) { |
| 314 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 315 | "SetVADStatus(channel=%i, enable=%i, mode=%i, disableDTX=%i)", |
| 316 | channel, enable, mode, disableDTX); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 317 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 318 | if (!_shared->statistics().Initialized()) { |
| 319 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 320 | return -1; |
| 321 | } |
| 322 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 323 | voe::Channel* channelPtr = ch.channel(); |
| 324 | if (channelPtr == NULL) { |
| 325 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 326 | "SetVADStatus failed to locate channel"); |
| 327 | return -1; |
| 328 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 329 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 330 | ACMVADMode vadMode(VADNormal); |
| 331 | switch (mode) { |
| 332 | case kVadConventional: |
| 333 | vadMode = VADNormal; |
| 334 | break; |
| 335 | case kVadAggressiveLow: |
| 336 | vadMode = VADLowBitrate; |
| 337 | break; |
| 338 | case kVadAggressiveMid: |
| 339 | vadMode = VADAggr; |
| 340 | break; |
| 341 | case kVadAggressiveHigh: |
| 342 | vadMode = VADVeryAggr; |
| 343 | break; |
| 344 | } |
| 345 | return channelPtr->SetVADStatus(enable, vadMode, disableDTX); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 348 | int VoECodecImpl::GetVADStatus(int channel, |
| 349 | bool& enabled, |
| 350 | VadModes& mode, |
| 351 | bool& disabledDTX) { |
| 352 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 353 | "GetVADStatus(channel=%i)", channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 355 | if (!_shared->statistics().Initialized()) { |
| 356 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 357 | return -1; |
| 358 | } |
| 359 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 360 | voe::Channel* channelPtr = ch.channel(); |
| 361 | if (channelPtr == NULL) { |
| 362 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 363 | "GetVADStatus failed to locate channel"); |
| 364 | return -1; |
| 365 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 366 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 367 | ACMVADMode vadMode; |
| 368 | int ret = channelPtr->GetVADStatus(enabled, vadMode, disabledDTX); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 370 | if (ret != 0) { |
| 371 | _shared->SetLastError(VE_INVALID_OPERATION, kTraceError, |
| 372 | "GetVADStatus failed to get VAD mode"); |
| 373 | return -1; |
| 374 | } |
| 375 | switch (vadMode) { |
| 376 | case VADNormal: |
| 377 | mode = kVadConventional; |
| 378 | break; |
| 379 | case VADLowBitrate: |
| 380 | mode = kVadAggressiveLow; |
| 381 | break; |
| 382 | case VADAggr: |
| 383 | mode = kVadAggressiveMid; |
| 384 | break; |
| 385 | case VADVeryAggr: |
| 386 | mode = kVadAggressiveHigh; |
| 387 | break; |
| 388 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 389 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 390 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 391 | } |
| 392 | |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 393 | int VoECodecImpl::SetOpusMaxPlaybackRate(int channel, int frequency_hz) { |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 394 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 395 | "SetOpusMaxPlaybackRate(channel=%d, frequency_hz=%d)", channel, |
| 396 | frequency_hz); |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 397 | if (!_shared->statistics().Initialized()) { |
| 398 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 399 | return -1; |
| 400 | } |
| 401 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 402 | voe::Channel* channelPtr = ch.channel(); |
| 403 | if (channelPtr == NULL) { |
| 404 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 405 | "SetOpusMaxPlaybackRate failed to locate channel"); |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 406 | return -1; |
| 407 | } |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 408 | return channelPtr->SetOpusMaxPlaybackRate(frequency_hz); |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 409 | } |
| 410 | |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 411 | int VoECodecImpl::SetOpusDtx(int channel, bool enable_dtx) { |
| 412 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 413 | "SetOpusDtx(channel=%d, enable_dtx=%d)", channel, enable_dtx); |
| 414 | if (!_shared->statistics().Initialized()) { |
| 415 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 416 | return -1; |
| 417 | } |
| 418 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 419 | voe::Channel* channelPtr = ch.channel(); |
| 420 | if (channelPtr == NULL) { |
| 421 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 422 | "SetOpusDtx failed to locate channel"); |
| 423 | return -1; |
| 424 | } |
| 425 | return channelPtr->SetOpusDtx(enable_dtx); |
| 426 | } |
| 427 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 428 | void VoECodecImpl::ACMToExternalCodecRepresentation(CodecInst& toInst, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 429 | const CodecInst& fromInst) { |
| 430 | toInst = fromInst; |
| 431 | if (STR_CASE_CMP(fromInst.plname, "SILK") == 0) { |
| 432 | if (fromInst.plfreq == 12000) { |
| 433 | if (fromInst.pacsize == 320) { |
| 434 | toInst.pacsize = 240; |
| 435 | } else if (fromInst.pacsize == 640) { |
| 436 | toInst.pacsize = 480; |
| 437 | } else if (fromInst.pacsize == 960) { |
| 438 | toInst.pacsize = 720; |
| 439 | } |
| 440 | } else if (fromInst.plfreq == 24000) { |
| 441 | if (fromInst.pacsize == 640) { |
| 442 | toInst.pacsize = 480; |
| 443 | } else if (fromInst.pacsize == 1280) { |
| 444 | toInst.pacsize = 960; |
| 445 | } else if (fromInst.pacsize == 1920) { |
| 446 | toInst.pacsize = 1440; |
| 447 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 448 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 449 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | void VoECodecImpl::ExternalToACMCodecRepresentation(CodecInst& toInst, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 453 | const CodecInst& fromInst) { |
| 454 | toInst = fromInst; |
| 455 | if (STR_CASE_CMP(fromInst.plname, "SILK") == 0) { |
| 456 | if (fromInst.plfreq == 12000) { |
| 457 | if (fromInst.pacsize == 240) { |
| 458 | toInst.pacsize = 320; |
| 459 | } else if (fromInst.pacsize == 480) { |
| 460 | toInst.pacsize = 640; |
| 461 | } else if (fromInst.pacsize == 720) { |
| 462 | toInst.pacsize = 960; |
| 463 | } |
| 464 | } else if (fromInst.plfreq == 24000) { |
| 465 | if (fromInst.pacsize == 480) { |
| 466 | toInst.pacsize = 640; |
| 467 | } else if (fromInst.pacsize == 960) { |
| 468 | toInst.pacsize = 1280; |
| 469 | } else if (fromInst.pacsize == 1440) { |
| 470 | toInst.pacsize = 1920; |
| 471 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 472 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 473 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 474 | } |
| 475 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 476 | #endif // WEBRTC_VOICE_ENGINE_CODEC_API |
| 477 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 478 | } // namespace webrtc |