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