blob: b8fa5cefaeae460c5673992659fc12646dde2ecc [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.orgc80d9d92012-02-06 10:11:25 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org956aa7e2013-05-21 13:52:32 +000011#include "webrtc/voice_engine/voe_codec_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000013#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.com470e71d2011-07-07 08:21:25 +000019
Jelena Marusic0d266052015-05-04 14:15:32 +020020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
Jelena Marusic0d266052015-05-04 14:15:32 +020022VoECodec* VoECodec::GetInterface(VoiceEngine* voiceEngine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000023#ifndef WEBRTC_VOICE_ENGINE_CODEC_API
Jelena Marusic0d266052015-05-04 14:15:32 +020024 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000025#else
Jelena Marusic0d266052015-05-04 14:15:32 +020026 if (NULL == voiceEngine) {
27 return NULL;
28 }
29 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
30 s->AddRef();
31 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000032#endif
33}
34
35#ifdef WEBRTC_VOICE_ENGINE_CODEC_API
36
Jelena Marusic0d266052015-05-04 14:15:32 +020037VoECodecImpl::VoECodecImpl(voe::SharedData* shared) : _shared(shared) {
38 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
39 "VoECodecImpl() - ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +000040}
41
Jelena Marusic0d266052015-05-04 14:15:32 +020042VoECodecImpl::~VoECodecImpl() {
43 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
44 "~VoECodecImpl() - dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
46
Jelena Marusic0d266052015-05-04 14:15:32 +020047int VoECodecImpl::NumOfCodecs() {
48 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
49 "NumOfCodecs()");
niklase@google.com470e71d2011-07-07 08:21:25 +000050
Jelena Marusic0d266052015-05-04 14:15:32 +020051 // Number of supported codecs in the ACM
52 uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs();
niklase@google.com470e71d2011-07-07 08:21:25 +000053
Jelena Marusic0d266052015-05-04 14:15:32 +020054 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
55 "NumOfCodecs() => %u", nSupportedCodecs);
56 return (nSupportedCodecs);
niklase@google.com470e71d2011-07-07 08:21:25 +000057}
58
Jelena Marusic0d266052015-05-04 14:15:32 +020059int 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.com470e71d2011-07-07 08:21:25 +000075}
76
Jelena Marusic0d266052015-05-04 14:15:32 +020077int VoECodecImpl::SetSendCodec(int channel, const CodecInst& codec) {
78 CodecInst copyCodec;
79 ExternalToACMCodecRepresentation(copyCodec, codec);
niklase@google.com470e71d2011-07-07 08:21:25 +000080
Jelena Marusic0d266052015-05-04 14:15:32 +020081 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.com470e71d2011-07-07 08:21:25 +0000128
Jelena Marusic0d266052015-05-04 14:15:32 +0200129 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130}
131
Jelena Marusic0d266052015-05-04 14:15:32 +0200132int 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.com470e71d2011-07-07 08:21:25 +0000159}
160
Ivo Creusenadf89b72015-04-29 16:03:33 +0200161int 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 Marusic0d266052015-05-04 14:15:32 +0200173int 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.com470e71d2011-07-07 08:21:25 +0000200}
201
Jelena Marusic0d266052015-05-04 14:15:32 +0200202int 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.com470e71d2011-07-07 08:21:25 +0000206 "codec: plname=%s, plfreq=%d, pltype=%d, channels=%u, "
Jelena Marusic0d266052015-05-04 14:15:32 +0200207 "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.com470e71d2011-07-07 08:21:25 +0000222}
223
Jelena Marusic0d266052015-05-04 14:15:32 +0200224int 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.com470e71d2011-07-07 08:21:25 +0000239}
240
Jelena Marusic0d266052015-05-04 14:15:32 +0200241int 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.com470e71d2011-07-07 08:21:25 +0000273}
274
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000275int 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
292int 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 Marusic0d266052015-05-04 14:15:32 +0200310int 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.com470e71d2011-07-07 08:21:25 +0000317
Jelena Marusic0d266052015-05-04 14:15:32 +0200318 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.com470e71d2011-07-07 08:21:25 +0000329
Jelena Marusic0d266052015-05-04 14:15:32 +0200330 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.com470e71d2011-07-07 08:21:25 +0000346}
347
Jelena Marusic0d266052015-05-04 14:15:32 +0200348int 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.com470e71d2011-07-07 08:21:25 +0000354
Jelena Marusic0d266052015-05-04 14:15:32 +0200355 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.com470e71d2011-07-07 08:21:25 +0000366
Jelena Marusic0d266052015-05-04 14:15:32 +0200367 ACMVADMode vadMode;
368 int ret = channelPtr->GetVADStatus(enabled, vadMode, disabledDTX);
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
Jelena Marusic0d266052015-05-04 14:15:32 +0200370 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.com470e71d2011-07-07 08:21:25 +0000389
Jelena Marusic0d266052015-05-04 14:15:32 +0200390 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000391}
392
minyue@webrtc.orgadee8f92014-09-03 12:28:06 +0000393int VoECodecImpl::SetOpusMaxPlaybackRate(int channel, int frequency_hz) {
minyue@webrtc.org6aac93b2014-08-12 08:13:33 +0000394 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
minyue@webrtc.orgadee8f92014-09-03 12:28:06 +0000395 "SetOpusMaxPlaybackRate(channel=%d, frequency_hz=%d)", channel,
396 frequency_hz);
minyue@webrtc.org6aac93b2014-08-12 08:13:33 +0000397 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.orgadee8f92014-09-03 12:28:06 +0000405 "SetOpusMaxPlaybackRate failed to locate channel");
minyue@webrtc.org6aac93b2014-08-12 08:13:33 +0000406 return -1;
407 }
minyue@webrtc.orgadee8f92014-09-03 12:28:06 +0000408 return channelPtr->SetOpusMaxPlaybackRate(frequency_hz);
minyue@webrtc.org6aac93b2014-08-12 08:13:33 +0000409}
410
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000411int 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.com470e71d2011-07-07 08:21:25 +0000428void VoECodecImpl::ACMToExternalCodecRepresentation(CodecInst& toInst,
Jelena Marusic0d266052015-05-04 14:15:32 +0200429 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.com470e71d2011-07-07 08:21:25 +0000448 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200449 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000450}
451
452void VoECodecImpl::ExternalToACMCodecRepresentation(CodecInst& toInst,
Jelena Marusic0d266052015-05-04 14:15:32 +0200453 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.com470e71d2011-07-07 08:21:25 +0000472 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200473 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000474}
475
niklase@google.com470e71d2011-07-07 08:21:25 +0000476#endif // WEBRTC_VOICE_ENGINE_CODEC_API
477
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000478} // namespace webrtc