blob: 3464ad764e2edeb976fe6964430b903a5960254d [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +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
11/*
12 * Implementation of the codec database.
13 */
14
15#include "codec_db.h"
16
17#include <string.h> /* to define NULL */
18
19#include "signal_processing_library.h"
20
21#include "neteq_error_codes.h"
22
23/*
24 * Resets the codec database.
25 */
26
27int WebRtcNetEQ_DbReset(CodecDbInst_t *inst)
28{
29 int i;
30
31 WebRtcSpl_MemSetW16((WebRtc_Word16*) inst, 0,
32 sizeof(CodecDbInst_t) / sizeof(WebRtc_Word16));
33
34 for (i = 0; i < NUM_TOTAL_CODECS; i++)
35 {
36 inst->position[i] = -1;
37 }
38
39 for (i = 0; i < NUM_CODECS; i++)
40 {
41 inst->payloadType[i] = -1;
42 }
43
44 for (i = 0; i < NUM_CNG_CODECS; i++)
45 {
46 inst->CNGpayloadType[i] = -1;
47 }
48
49 return 0;
50}
51
52/*
53 * Adds a new codec to the database.
54 */
55
56int WebRtcNetEQ_DbAdd(CodecDbInst_t *inst, enum WebRtcNetEQDecoder codec,
57 WebRtc_Word16 payloadType, FuncDecode funcDecode,
58 FuncDecode funcDecodeRCU, FuncDecodePLC funcDecodePLC,
59 FuncDecodeInit funcDecodeInit, FuncAddLatePkt funcAddLatePkt,
60 FuncGetMDinfo funcGetMDinfo, FuncGetPitchInfo funcGetPitch,
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +000061 FuncUpdBWEst funcUpdBWEst, FuncDurationEst funcDurationEst,
62 FuncGetErrorCode funcGetErrorCode, void* codec_state,
63 WebRtc_UWord16 codec_fs)
niklase@google.com470e71d2011-07-07 08:21:25 +000064{
65
66 int temp;
67 int insertCNGcodec = 0, overwriteCNGcodec = 0, CNGpos = -1;
68
69#ifndef NETEQ_RED_CODEC
70 if (codec == kDecoderRED)
71 {
72 return CODEC_DB_UNSUPPORTED_CODEC;
73 }
74#endif
75 if (((int) codec <= (int) kDecoderReservedStart) || ((int) codec
76 >= (int) kDecoderReservedEnd))
77 {
78 return CODEC_DB_UNSUPPORTED_CODEC;
79 }
80
81 if ((codec_fs != 8000)
82#ifdef NETEQ_WIDEBAND
83 &&(codec_fs!=16000)
84#endif
85#ifdef NETEQ_32KHZ_WIDEBAND
86 &&(codec_fs!=32000)
87#endif
tina.legrand@webrtc.orga7d83872012-10-18 10:00:52 +000088#if defined(NETEQ_48KHZ_WIDEBAND) || defined(NETEQ_OPUS_CODEC)
niklase@google.com470e71d2011-07-07 08:21:25 +000089 &&(codec_fs!=48000)
90#endif
91 )
92 {
93 return CODEC_DB_UNSUPPORTED_FS;
94 }
95
96 /* Ensure that the codec type is supported */
97 switch (codec)
98 {
99#ifdef NETEQ_PCM16B_CODEC
100 case kDecoderPCM16B :
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000101 case kDecoderPCM16B_2ch :
niklase@google.com470e71d2011-07-07 08:21:25 +0000102#endif
103#ifdef NETEQ_G711_CODEC
104 case kDecoderPCMu :
105 case kDecoderPCMa :
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000106 case kDecoderPCMu_2ch :
107 case kDecoderPCMa_2ch :
niklase@google.com470e71d2011-07-07 08:21:25 +0000108#endif
109#ifdef NETEQ_ILBC_CODEC
110 case kDecoderILBC :
111#endif
112#ifdef NETEQ_ISAC_CODEC
113 case kDecoderISAC :
114#endif
115#ifdef NETEQ_ISAC_SWB_CODEC
116 case kDecoderISACswb :
117#endif
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000118#ifdef NETEQ_ISAC_FB_CODEC
119 case kDecoderISACfb :
120#endif
tina.legrand@webrtc.orga7d83872012-10-18 10:00:52 +0000121#ifdef NETEQ_OPUS_CODEC
122 case kDecoderOpus :
123#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000124#ifdef NETEQ_G722_CODEC
125 case kDecoderG722 :
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000126 case kDecoderG722_2ch :
niklase@google.com470e71d2011-07-07 08:21:25 +0000127#endif
128#ifdef NETEQ_WIDEBAND
129 case kDecoderPCM16Bwb :
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000130 case kDecoderPCM16Bwb_2ch :
niklase@google.com470e71d2011-07-07 08:21:25 +0000131#endif
132#ifdef NETEQ_32KHZ_WIDEBAND
133 case kDecoderPCM16Bswb32kHz :
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000134 case kDecoderPCM16Bswb32kHz_2ch :
niklase@google.com470e71d2011-07-07 08:21:25 +0000135#endif
136#ifdef NETEQ_CNG_CODEC
137 case kDecoderCNG :
138#endif
139#ifdef NETEQ_ATEVENT_DECODE
140 case kDecoderAVT :
141#endif
142#ifdef NETEQ_RED_CODEC
143 case kDecoderRED :
144#endif
145#ifdef NETEQ_48KHZ_WIDEBAND
146 case kDecoderPCM16Bswb48kHz :
147#endif
148#ifdef NETEQ_ARBITRARY_CODEC
149 case kDecoderArbitrary:
150#endif
151#ifdef NETEQ_G729_CODEC
152 case kDecoderG729:
153#endif
154#ifdef NETEQ_G729_1_CODEC
155 case kDecoderG729_1 :
156#endif
157#ifdef NETEQ_G726_CODEC
158 case kDecoderG726_16 :
159 case kDecoderG726_24 :
160 case kDecoderG726_32 :
161 case kDecoderG726_40 :
162#endif
163#ifdef NETEQ_G722_1_CODEC
164 case kDecoderG722_1_16 :
165 case kDecoderG722_1_24 :
166 case kDecoderG722_1_32 :
167#endif
168#ifdef NETEQ_G722_1C_CODEC
169 case kDecoderG722_1C_24 :
170 case kDecoderG722_1C_32 :
171 case kDecoderG722_1C_48 :
172#endif
173#ifdef NETEQ_SPEEX_CODEC
174 case kDecoderSPEEX_8 :
175 case kDecoderSPEEX_16 :
176#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000177#ifdef NETEQ_CELT_CODEC
178 case kDecoderCELT_32 :
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000179 case kDecoderCELT_32_2ch :
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000180#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000181#ifdef NETEQ_GSMFR_CODEC
182 case kDecoderGSMFR :
183#endif
184#ifdef NETEQ_AMR_CODEC
185 case kDecoderAMR :
186#endif
187#ifdef NETEQ_AMRWB_CODEC
188 case kDecoderAMRWB :
189#endif
190 {
191 /* If we end up here, the inserted codec is supported => Do nothing */
192 break;
193 }
194 default:
195 {
196 /* If we get to this point, the inserted codec is not supported */
197 return CODEC_DB_UNSUPPORTED_CODEC;
198 }
199 }
200
201 /* Check to see if payload type is taken */
202 if (WebRtcNetEQ_DbGetCodec(inst, payloadType) > 0)
203 {
204 return CODEC_DB_PAYLOAD_TAKEN;
205 }
206
207 /* Special case for CNG codecs */
208 if (codec == kDecoderCNG)
209 {
210 /* check if this is first CNG codec to be registered */
211 if (WebRtcNetEQ_DbGetPayload(inst, codec) == CODEC_DB_NOT_EXIST2)
212 {
213 /* no other CNG codec found */
214 insertCNGcodec = 1;
215 }
216
217 /* find the appropriate insert position in CNG payload vector */
218 switch (codec_fs)
219 {
220#ifdef NETEQ_WIDEBAND
221 case 16000:
222 CNGpos = 1;
223 break;
224#endif
225#ifdef NETEQ_32KHZ_WIDEBAND
226 case 32000:
227 CNGpos = 2;
228 break;
229#endif
230#ifdef NETEQ_48KHZ_WIDEBAND
231 case 48000:
232 CNGpos = 3;
233 break;
234#endif
235 default: /* 8000 Hz case */
236 CNGpos = 0;
237 /*
238 * The 8 kHz CNG payload type is the one associated with the regular codec DB
239 * should override any other setting.
240 * Overwrite if this isn't the first CNG
241 */
242 overwriteCNGcodec = !insertCNGcodec;
243 break;
244 }
245
246 /* insert CNG payload type */
247 inst->CNGpayloadType[CNGpos] = payloadType;
248
249 }
250
251 if ((codec != kDecoderCNG) || (insertCNGcodec == 1) || (overwriteCNGcodec == 1))
252 {
253 /* Check if we have reached the maximum numbers of simultaneous codecs */
254 if (inst->nrOfCodecs == NUM_CODECS) return CODEC_DB_FULL;
255
256 /* Check that codec has not already been initialized to DB =>
257 remove it and reinitialize according to new spec */
258 if ((inst->position[codec] != -1) && (overwriteCNGcodec != 1))
259 { /* if registering multiple CNG codecs, don't remove, just overwrite */
260 WebRtcNetEQ_DbRemove(inst, codec);
261 }
262
263 if (overwriteCNGcodec == 1)
264 {
265 temp = inst->position[codec];
266 }
267 else
268 {
269 temp = inst->nrOfCodecs; /* Store this codecs position */
270 inst->position[codec] = temp;
271 inst->nrOfCodecs++;
272 }
273
274 inst->payloadType[temp] = payloadType;
275
276 /* Copy to database */
277 inst->codec_state[temp] = codec_state;
278 inst->funcDecode[temp] = funcDecode;
279 inst->funcDecodeRCU[temp] = funcDecodeRCU;
280 inst->funcAddLatePkt[temp] = funcAddLatePkt;
281 inst->funcDecodeInit[temp] = funcDecodeInit;
282 inst->funcDecodePLC[temp] = funcDecodePLC;
283 inst->funcGetMDinfo[temp] = funcGetMDinfo;
284 inst->funcGetPitch[temp] = funcGetPitch;
285 inst->funcUpdBWEst[temp] = funcUpdBWEst;
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +0000286 inst->funcDurationEst[temp] = funcDurationEst;
niklase@google.com470e71d2011-07-07 08:21:25 +0000287 inst->funcGetErrorCode[temp] = funcGetErrorCode;
288 inst->codec_fs[temp] = codec_fs;
289
290 }
291
292 return 0;
293}
294
295/*
296 * Removes a codec from the database.
297 */
298
299int WebRtcNetEQ_DbRemove(CodecDbInst_t *inst, enum WebRtcNetEQDecoder codec)
300{
301 int i;
302 int pos = -1;
303
304#ifndef NETEQ_RED_CODEC
305 if (codec == kDecoderRED)
306 {
307 return CODEC_DB_UNSUPPORTED_CODEC;
308 }
309#endif
310 if (((int) codec <= (int) kDecoderReservedStart) || ((int) codec
311 >= (int) kDecoderReservedEnd))
312 {
313 return CODEC_DB_UNSUPPORTED_CODEC;
314 }
315
316 pos = inst->position[codec];
317 if (pos == -1)
318 {
319 return CODEC_DB_NOT_EXIST4;
320 }
321 else
322 {
323 /* Remove this codec */
324 inst->position[codec] = -1;
325 for (i = pos; i < (inst->nrOfCodecs - 1); i++)
326 {
327 inst->payloadType[i] = inst->payloadType[i + 1];
328 inst->codec_state[i] = inst->codec_state[i + 1];
329 inst->funcDecode[i] = inst->funcDecode[i + 1];
330 inst->funcDecodeRCU[i] = inst->funcDecodeRCU[i + 1];
331 inst->funcAddLatePkt[i] = inst->funcAddLatePkt[i + 1];
332 inst->funcDecodeInit[i] = inst->funcDecodeInit[i + 1];
333 inst->funcDecodePLC[i] = inst->funcDecodePLC[i + 1];
334 inst->funcGetMDinfo[i] = inst->funcGetMDinfo[i + 1];
335 inst->funcGetPitch[i] = inst->funcGetPitch[i + 1];
336 inst->funcUpdBWEst[i] = inst->funcUpdBWEst[i + 1];
337 inst->funcGetErrorCode[i] = inst->funcGetErrorCode[i + 1];
338 inst->codec_fs[i] = inst->codec_fs[i + 1];
339 }
340 inst->payloadType[i] = -1;
341 inst->codec_state[i] = NULL;
342 inst->funcDecode[i] = NULL;
343 inst->funcDecodeRCU[i] = NULL;
344 inst->funcAddLatePkt[i] = NULL;
345 inst->funcDecodeInit[i] = NULL;
346 inst->funcDecodePLC[i] = NULL;
347 inst->funcGetMDinfo[i] = NULL;
348 inst->funcGetPitch[i] = NULL;
349 inst->funcUpdBWEst[i] = NULL;
350 inst->funcGetErrorCode[i] = NULL;
351 inst->codec_fs[i] = 0;
352 /* Move down all the codecs above this one */
353 for (i = 0; i < NUM_TOTAL_CODECS; i++)
354 {
355 if (inst->position[i] >= pos)
356 {
357 inst->position[i] = inst->position[i] - 1;
358 }
359 }
360 inst->nrOfCodecs--;
361
362 if (codec == kDecoderCNG)
363 {
364 /* also remove all registered CNG payload types */
365 for (i = 0; i < NUM_CNG_CODECS; i++)
366 {
367 inst->CNGpayloadType[i] = -1;
368 }
369 }
370 }
371 return 0;
372}
373
374/*
375 * Get the decoder function pointers for a codec.
376 */
377
378int WebRtcNetEQ_DbGetPtrs(CodecDbInst_t *inst, enum WebRtcNetEQDecoder codec,
379 CodecFuncInst_t *ptr_inst)
380{
381
382 int pos = inst->position[codec];
383 if ((codec <= kDecoderReservedStart) || (codec >= kDecoderReservedEnd) || (codec
384 > NUM_TOTAL_CODECS))
385 {
386 /* ERROR */
387 pos = -1;
388 }
389 if (pos >= 0)
390 {
391 ptr_inst->codec_state = inst->codec_state[pos];
392 ptr_inst->funcAddLatePkt = inst->funcAddLatePkt[pos];
393 ptr_inst->funcDecode = inst->funcDecode[pos];
394 ptr_inst->funcDecodeRCU = inst->funcDecodeRCU[pos];
395 ptr_inst->funcDecodeInit = inst->funcDecodeInit[pos];
396 ptr_inst->funcDecodePLC = inst->funcDecodePLC[pos];
397 ptr_inst->funcGetMDinfo = inst->funcGetMDinfo[pos];
398 ptr_inst->funcUpdBWEst = inst->funcUpdBWEst[pos];
399 ptr_inst->funcGetErrorCode = inst->funcGetErrorCode[pos];
400 ptr_inst->codec_fs = inst->codec_fs[pos];
401 return 0;
402 }
403 else
404 {
405 WebRtcSpl_MemSetW16((WebRtc_Word16*) ptr_inst, 0,
406 sizeof(CodecFuncInst_t) / sizeof(WebRtc_Word16));
407 return CODEC_DB_NOT_EXIST1;
408 }
409}
410
411/*
412 * Returns payload number given a codec identifier.
413 */
414
415int WebRtcNetEQ_DbGetPayload(CodecDbInst_t *inst, enum WebRtcNetEQDecoder codecID)
416{
417 if (inst->position[codecID] == -1)
418 return CODEC_DB_NOT_EXIST2;
419 else
420 return (inst->payloadType[inst->position[codecID]]);
421
422}
423
424/*
425 * Returns codec identifier given a payload number.
426 * Returns -1 if the payload type does not exist.
427 */
428
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +0000429int WebRtcNetEQ_DbGetCodec(const CodecDbInst_t *inst, int payloadType)
niklase@google.com470e71d2011-07-07 08:21:25 +0000430{
431 int i, pos;
432
433 for (i = 0; i < NUM_TOTAL_CODECS; i++)
434 {
435 pos = inst->position[i];
436 if (pos != -1)
437 {
438 if (inst->payloadType[pos] == payloadType) return i;
439 }
440 }
441
442 /* did not find payload type */
443 /* check if it's a CNG codec */
444 if (WebRtcNetEQ_DbIsCNGPayload(inst, payloadType))
445 {
446 return kDecoderCNG;
447 }
448
449 /* found no match */
450 return CODEC_DB_NOT_EXIST3;
451}
452
453/*
454 * Extracts the Payload Split information of the codec with the specified payloadType.
455 */
456
457int WebRtcNetEQ_DbGetSplitInfo(SplitInfo_t *inst, enum WebRtcNetEQDecoder codecID,
458 int codedsize)
459{
460
461 switch (codecID)
462 {
463#ifdef NETEQ_ISAC_CODEC
464 case kDecoderISAC:
465#endif
466#ifdef NETEQ_ISAC_SWB_CODEC
467 case kDecoderISACswb:
468#endif
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000469#ifdef NETEQ_ISAC_FB_CODEC
470 case kDecoderISACfb:
471#endif
tina.legrand@webrtc.orga7d83872012-10-18 10:00:52 +0000472#ifdef NETEQ_OPUS_CODEC
473 case kDecoderOpus:
474#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000475#ifdef NETEQ_ARBITRARY_CODEC
476 case kDecoderArbitrary:
477#endif
478#ifdef NETEQ_AMR_CODEC
479 case kDecoderAMR:
480#endif
481#ifdef NETEQ_AMRWB_CODEC
482 case kDecoderAMRWB:
483#endif
484#ifdef NETEQ_G726_CODEC
485 /* Treat G726 as non-splittable to simplify the implementation */
486 case kDecoderG726_16:
487 case kDecoderG726_24:
488 case kDecoderG726_32:
489 case kDecoderG726_40:
490#endif
491#ifdef NETEQ_SPEEX_CODEC
492 case kDecoderSPEEX_8:
493 case kDecoderSPEEX_16:
494#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000495#ifdef NETEQ_CELT_CODEC
496 case kDecoderCELT_32 :
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000497 case kDecoderCELT_32_2ch :
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000498#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000499#ifdef NETEQ_G729_1_CODEC
500 case kDecoderG729_1:
501#endif
502 {
503 /* These codecs' payloads are not splittable */
504 inst->deltaBytes = NO_SPLIT;
505 return 0;
506 }
507
508 /*
509 * Sample based coders are a special case.
510 * In this case, deltaTime signals the number of bytes per timestamp unit times 2
511 * in log2 domain.
512 */
513#if (defined NETEQ_G711_CODEC)
514 case kDecoderPCMu:
515 case kDecoderPCMa:
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000516 case kDecoderPCMu_2ch:
517 case kDecoderPCMa_2ch:
niklase@google.com470e71d2011-07-07 08:21:25 +0000518 {
519 inst->deltaBytes = -12;
520 inst->deltaTime = 1;
521 return 0;
522 }
523#endif
524#if (defined NETEQ_G722_CODEC)
525 case kDecoderG722:
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000526 case kDecoderG722_2ch:
niklase@google.com470e71d2011-07-07 08:21:25 +0000527 {
528 inst->deltaBytes = -14;
529 inst->deltaTime = 0;
530 return 0;
531 }
532#endif
533#if (defined NETEQ_PCM16B_CODEC)
534 case kDecoderPCM16B:
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000535 case kDecoderPCM16B_2ch:
niklase@google.com470e71d2011-07-07 08:21:25 +0000536 {
537 inst->deltaBytes = -12;
538 inst->deltaTime = 2;
539 return 0;
540 }
541#endif
542#if ((defined NETEQ_PCM16B_CODEC)&&(defined NETEQ_WIDEBAND))
543 case kDecoderPCM16Bwb:
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000544 case kDecoderPCM16Bwb_2ch:
niklase@google.com470e71d2011-07-07 08:21:25 +0000545 {
546 inst->deltaBytes = -14;
547 inst->deltaTime = 2;
548 return 0;
549 }
550#endif
551#if ((defined NETEQ_PCM16B_CODEC)&&(defined NETEQ_32KHZ_WIDEBAND))
552 case kDecoderPCM16Bswb32kHz:
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000553 case kDecoderPCM16Bswb32kHz_2ch:
niklase@google.com470e71d2011-07-07 08:21:25 +0000554 {
555 inst->deltaBytes = -18;
556 inst->deltaTime = 2;
557 return 0;
558 }
559#endif
560#if ((defined NETEQ_PCM16B_CODEC)&&(defined NETEQ_48KHZ_WIDEBAND))
561 case kDecoderPCM16Bswb48kHz:
562 {
563 inst->deltaBytes = -22;
564 inst->deltaTime = 2;
565 return 0;
566 }
567#endif
568
569 /* Splittable payloads */
570#ifdef NETEQ_G722_1_CODEC
571 case kDecoderG722_1_16:
572 {
573 inst->deltaBytes = 40;
574 inst->deltaTime = 320;
575 return 0;
576 }
577 case kDecoderG722_1_24:
578 {
579 inst->deltaBytes = 60;
580 inst->deltaTime = 320;
581 return 0;
582 }
583 case kDecoderG722_1_32:
584 {
585 inst->deltaBytes = 80;
586 inst->deltaTime = 320;
587 return 0;
588 }
589#endif
590#ifdef NETEQ_G722_1C_CODEC
591 case kDecoderG722_1C_24:
592 {
593 inst->deltaBytes = 60;
594 inst->deltaTime = 640;
595 return 0;
596 }
597 case kDecoderG722_1C_32:
598 {
599 inst->deltaBytes = 80;
600 inst->deltaTime = 640;
601 return 0;
602 }
603 case kDecoderG722_1C_48:
604 {
605 inst->deltaBytes = 120;
606 inst->deltaTime = 640;
607 return 0;
608 }
609#endif
610#ifdef NETEQ_G729_CODEC
611 case kDecoderG729:
612 {
613 inst->deltaBytes = 10;
614 inst->deltaTime = 80;
615 return 0;
616 }
617#endif
618#ifdef NETEQ_ILBC_CODEC
619 case kDecoderILBC:
620 {
621 /* Check for splitting of iLBC packets.
622 * If payload size is a multiple of 50 bytes it should be split into 30ms frames.
623 * If payload size is a multiple of 38 bytes it should be split into 20ms frames.
624 * Least common multiplier between 38 and 50 is 950, so the payload size must be less than
625 * 950 bytes in order to resolve the frames unambiguously.
626 * Currently max 12 frames in one bundle.
627 */
628 switch (codedsize)
629 {
630 case 50:
631 case 100:
632 case 150:
633 case 200:
634 case 250:
635 case 300:
636 case 350:
637 case 400:
638 case 450:
639 case 500:
640 case 550:
641 case 600:
642 {
643 inst->deltaBytes = 50;
644 inst->deltaTime = 240;
645 break;
646 }
647 case 38:
648 case 76:
649 case 114:
650 case 152:
651 case 190:
652 case 228:
653 case 266:
654 case 304:
655 case 342:
656 case 380:
657 case 418:
658 case 456:
659 {
660 inst->deltaBytes = 38;
661 inst->deltaTime = 160;
662 break;
663 }
664 default:
665 {
666 return AMBIGUOUS_ILBC_FRAME_SIZE; /* Something not supported... */
667 }
668 }
669 return 0;
670 }
671#endif
672#ifdef NETEQ_GSMFR_CODEC
673 case kDecoderGSMFR:
674 {
675 inst->deltaBytes = 33;
676 inst->deltaTime = 160;
677 return 0;
678 }
679#endif
680 default:
681 { /*Unknown codec */
682 inst->deltaBytes = NO_SPLIT;
683 return CODEC_DB_UNKNOWN_CODEC;
684 }
685 } /* end of switch */
686}
687
688/*
689 * Returns 1 if codec is multiple description, 0 otherwise.
690 * NOTE: This function is a stub, since there currently are no MD codecs.
691 */
692int WebRtcNetEQ_DbIsMDCodec(enum WebRtcNetEQDecoder codecID)
693{
694 if (0) /* Add test for MD codecs here */
695 return 1;
696 else
697 return 0;
698}
699
700/*
701 * Returns 1 if payload type is registered as a CNG codec, 0 otherwise
702 */
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +0000703int WebRtcNetEQ_DbIsCNGPayload(const CodecDbInst_t *inst, int payloadType)
niklase@google.com470e71d2011-07-07 08:21:25 +0000704{
705#ifdef NETEQ_CNG_CODEC
706 int i;
707
708 for(i=0; i<NUM_CNG_CODECS; i++)
709 {
710 if( (inst->CNGpayloadType[i] != -1) && (inst->CNGpayloadType[i] == payloadType) )
711 {
712 return 1;
713 }
714 }
715#endif
716
717 return 0;
718
719}
720
721/*
722 * Return the sample rate for the codec with the given payload type, 0 if error
723 */
724WebRtc_UWord16 WebRtcNetEQ_DbGetSampleRate(CodecDbInst_t *inst, int payloadType)
725{
726 int i;
727 CodecFuncInst_t codecInst;
728
729 /* Sanity */
730 if (inst == NULL)
731 {
732 /* return 0 Hz */
733 return 0;
734 }
735
736 /* Check among CNG payloads */
737 for (i = 0; i < NUM_CNG_CODECS; i++)
738 {
739 if ((inst->CNGpayloadType[i] != -1) && (inst->CNGpayloadType[i] == payloadType))
740 {
741 switch (i)
742 {
henrik.lundin@webrtc.orgf0effa12012-09-11 12:44:06 +0000743#ifdef NETEQ_WIDEBAND
niklase@google.com470e71d2011-07-07 08:21:25 +0000744 case 1:
745 return 16000;
henrik.lundin@webrtc.orgf0effa12012-09-11 12:44:06 +0000746#endif
747#ifdef NETEQ_32KHZ_WIDEBAND
niklase@google.com470e71d2011-07-07 08:21:25 +0000748 case 2:
749 return 32000;
henrik.lundin@webrtc.orgf0effa12012-09-11 12:44:06 +0000750#endif
751#ifdef NETEQ_48KHZ_WIDEBAND
niklase@google.com470e71d2011-07-07 08:21:25 +0000752 case 3:
753 return 48000;
henrik.lundin@webrtc.orgf0effa12012-09-11 12:44:06 +0000754#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000755 default:
756 return 8000;
757 }
758 }
759 }
760
761 /* Not a CNG payload, check the other payloads */
762 i = WebRtcNetEQ_DbGetCodec(inst, payloadType);
763 if (i >= 0)
764 {
765 if (WebRtcNetEQ_DbGetPtrs(inst, (enum WebRtcNetEQDecoder) i, &codecInst) != 0)
766 {
767 /* Unexpected error, return 0 Hz */
768 return 0;
769 }
770 return codecInst.codec_fs;
771 }
772
773 /* If we end up here, we got an error, return 0 Hz */
774 return 0;
775
776}
777