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