Asterisk - The Open Source Telephony Project GIT-master-a358458
Macros | Enumerations | Functions | Variables
codec_builtin.c File Reference

Built-in supported codecs. More...

#include "asterisk.h"
#include "asterisk/ilbc.h"
#include "asterisk/logger.h"
#include "asterisk/astobj2.h"
#include "asterisk/codec.h"
#include "asterisk/format.h"
#include "asterisk/format_cache.h"
#include "asterisk/frame.h"
#include "asterisk/smoother.h"
Include dependency graph for codec_builtin.c:

Go to the source code of this file.

Macros

#define CODEC_REGISTER_AND_CACHE(codec)
 
#define CODEC_REGISTER_AND_CACHE_NAMED(fmt_name, codec)
 
#define TYPE_MASK   0x3
 

Enumerations

enum  frame_type { TYPE_HIGH , TYPE_LOW , TYPE_SILENCE , TYPE_DONTSEND }
 

Functions

int __ast_codec_register_with_format (struct ast_codec *codec, const char *format_name, struct ast_module *mod)
 
int ast_codec_builtin_init (void)
 Initialize built-in codecs within the core. More...
 
static int codec2_length (unsigned int samples)
 
static int codec2_samples (struct ast_frame *frame)
 
static int g719_length (unsigned int samples)
 
static int g719_samples (struct ast_frame *frame)
 
static int g723_len (unsigned char buf)
 
static int g723_length (unsigned int samples)
 
static int g723_samples (struct ast_frame *frame)
 
static int g726_length (unsigned int samples)
 
static int g726_samples (struct ast_frame *frame)
 
static int g729_length (unsigned int samples)
 
static int g729_samples (struct ast_frame *frame)
 
static unsigned char get_n_bits_at (unsigned char *data, int n, int bit)
 
static int gsm_length (unsigned int samples)
 
static int gsm_samples (struct ast_frame *frame)
 
static int ilbc_samples (struct ast_frame *frame)
 
static int lpc10_samples (struct ast_frame *frame)
 
static int none_length (unsigned int samples)
 
static int none_samples (struct ast_frame *frame)
 
static int opus_samples (struct ast_frame *frame)
 
static int silk_samples (struct ast_frame *frame)
 
static int siren14_length (unsigned int samples)
 
static int siren14_samples (struct ast_frame *frame)
 
static int siren7_length (unsigned int samples)
 
static int siren7_samples (struct ast_frame *frame)
 
static int slin_length (unsigned int samples)
 
static int slin_samples (struct ast_frame *frame)
 
static int speex16_samples (struct ast_frame *frame)
 
static int speex32_samples (struct ast_frame *frame)
 
static int speex8_samples (struct ast_frame *frame)
 
static int speex_get_wb_sz_at (unsigned char *data, int len, int bit)
 
static int speex_samples (unsigned char *data, int len)
 
static int ulaw_length (unsigned int samples)
 
static int ulaw_samples (struct ast_frame *frame)
 

Variables

static struct ast_codec adpcm
 
static struct ast_codec alaw
 
static struct ast_codec codec2
 
static struct ast_codec g719
 
static struct ast_codec g722
 
static struct ast_codec g723
 
static struct ast_codec g726aal2
 
static struct ast_codec g726rfc3551
 
static struct ast_codec g729a
 
static struct ast_codec gsm
 
static struct ast_codec h261
 
static struct ast_codec h263
 
static struct ast_codec h263p
 
static struct ast_codec h264
 
static struct ast_codec h265
 
static struct ast_codec ilbc
 
static struct ast_codec jpeg
 
static struct ast_codec lpc10
 
static struct ast_codec mpeg4
 
static struct ast_codec none
 
static struct ast_codec opus
 
static struct ast_codec png
 
static struct ast_codec silk12
 
static struct ast_codec silk16
 
static struct ast_codec silk24
 
static struct ast_codec silk8
 
static struct ast_codec siren14
 
static struct ast_codec siren7
 
static struct ast_codec slin12
 
static struct ast_codec slin16
 
static struct ast_codec slin192
 
static struct ast_codec slin24
 
static struct ast_codec slin32
 
static struct ast_codec slin44
 
static struct ast_codec slin48
 
static struct ast_codec slin8
 
static struct ast_codec slin96
 
static struct ast_codec speex16
 
static struct ast_codec speex32
 
static struct ast_codec speex8
 
static struct ast_codec t140
 
static struct ast_codec t140red
 
static struct ast_codec t38
 
static struct ast_codec ulaw
 
static struct ast_codec vp8
 
static struct ast_codec vp9
 

Detailed Description

Built-in supported codecs.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file codec_builtin.c.

Macro Definition Documentation

◆ CODEC_REGISTER_AND_CACHE

#define CODEC_REGISTER_AND_CACHE (   codec)

Definition at line 928 of file codec_builtin.c.

◆ CODEC_REGISTER_AND_CACHE_NAMED

#define CODEC_REGISTER_AND_CACHE_NAMED (   fmt_name,
  codec 
)

Definition at line 942 of file codec_builtin.c.

◆ TYPE_MASK

#define TYPE_MASK   0x3

Definition at line 51 of file codec_builtin.c.

Enumeration Type Documentation

◆ frame_type

enum frame_type
Enumerator
TYPE_HIGH 
TYPE_LOW 
TYPE_SILENCE 
TYPE_DONTSEND 

Definition at line 44 of file codec_builtin.c.

44 {
45 TYPE_HIGH, /* 0x0 */
46 TYPE_LOW, /* 0x1 */
47 TYPE_SILENCE, /* 0x2 */
48 TYPE_DONTSEND /* 0x3 */
49};
@ TYPE_LOW
Definition: codec_builtin.c:46
@ TYPE_SILENCE
Definition: codec_builtin.c:47
@ TYPE_HIGH
Definition: codec_builtin.c:45
@ TYPE_DONTSEND
Definition: codec_builtin.c:48

Function Documentation

◆ __ast_codec_register_with_format()

int __ast_codec_register_with_format ( struct ast_codec codec,
const char *  format_name,
struct ast_module mod 
)

Definition at line 278 of file codec.c.

279{
281 struct internal_ast_codec *codec_new;
282
283 /* Some types have specific requirements */
284 if (codec->type == AST_MEDIA_TYPE_UNKNOWN) {
285 ast_log(LOG_ERROR, "A media type must be specified for codec '%s'\n", codec->name);
286 return -1;
287 } else if (codec->type == AST_MEDIA_TYPE_AUDIO) {
288 if (!codec->sample_rate) {
289 ast_log(LOG_ERROR, "A sample rate must be specified for codec '%s' of type '%s'\n",
290 codec->name, ast_codec_media_type2str(codec->type));
291 return -1;
292 }
293 }
294
295 codec_new = ao2_find(codecs, codec, OBJ_SEARCH_OBJECT | OBJ_NOLOCK);
296 if (codec_new) {
297 ast_log(LOG_ERROR, "A codec with name '%s' of type '%s' and sample rate '%u' is already registered\n",
298 codec->name, ast_codec_media_type2str(codec->type), codec->sample_rate);
299 ao2_ref(codec_new, -1);
300 return -1;
301 }
302
303 codec_new = ao2_t_alloc_options(sizeof(*codec_new), codec_dtor,
305 if (!codec_new) {
306 ast_log(LOG_ERROR, "Could not allocate a codec with name '%s' of type '%s' and sample rate '%u'\n",
307 codec->name, ast_codec_media_type2str(codec->type), codec->sample_rate);
308 return -1;
309 }
310 codec_new->external = *codec;
311 codec_new->format_name = format_name;
312 codec_new->external.id = codec_id++;
313
314 ao2_link_flags(codecs, codec_new, OBJ_NOLOCK);
315
316 /* Once registered a codec can not be unregistered, and the module must persist until shutdown */
318
319 ast_verb(5, "Registered '%s' codec '%s' at sample rate '%u' with id '%u'\n",
320 ast_codec_media_type2str(codec->type), codec->name, codec->sample_rate, codec_new->external.id);
321
322 ao2_ref(codec_new, -1);
323
324 return 0;
325}
ast_mutex_t lock
Definition: app_sla.c:331
#define ast_log
Definition: astobj2.c:42
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
Definition: astobj2.h:1554
#define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg)
Allocate and initialize an object.
Definition: astobj2.h:402
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition: astobj2.h:1087
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
Definition: astobj2.h:1063
static int codec_id
Current identifier value for newly registered codec.
Definition: codec.c:45
static struct ao2_container * codecs
Registered codecs.
Definition: codec.c:48
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:348
static void codec_dtor(void *obj)
Definition: codec.c:264
@ AST_MEDIA_TYPE_AUDIO
Definition: codec.h:32
@ AST_MEDIA_TYPE_UNKNOWN
Definition: codec.h:31
#define LOG_ERROR
#define ast_verb(level,...)
#define SCOPED_AO2WRLOCK(varname, obj)
scoped lock specialization for ao2 write locks.
Definition: lock.h:614
#define ast_module_shutdown_ref(mod)
Prevent unload of the module before shutdown.
Definition: module.h:464
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
unsigned int sample_rate
Sample rate (number of samples carried in a second)
Definition: codec.h:52
enum ast_media_type type
Type of media this codec contains.
Definition: codec.h:50
const char * description
Brief description.
Definition: codec.h:48
const char * name
Name for this codec.
Definition: codec.h:46
unsigned int id
Internal unique identifier for this codec, set at registration time (starts at 1)
Definition: codec.h:44
const char * format_name
A format name for a default sane format using this codec.
Definition: codec.c:63
struct ast_codec external
Public codec structure. Must remain first.
Definition: codec.c:61

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_find, ao2_link_flags, ao2_ref, ao2_t_alloc_options, ast_codec_media_type2str(), ast_log, AST_MEDIA_TYPE_AUDIO, AST_MEDIA_TYPE_UNKNOWN, ast_module_shutdown_ref, ast_verb, codec_dtor(), codec_id, codecs, ast_codec::description, internal_ast_codec::external, internal_ast_codec::format_name, ast_codec::id, lock, LOG_ERROR, ast_codec::name, OBJ_NOLOCK, OBJ_SEARCH_OBJECT, S_OR, ast_codec::sample_rate, SCOPED_AO2WRLOCK, and ast_codec::type.

Referenced by __ast_codec_register().

◆ ast_codec_builtin_init()

int ast_codec_builtin_init ( void  )

Initialize built-in codecs within the core.

Return values
0success
-1failure

Definition at line 956 of file codec_builtin.c.

957{
958 int res = 0;
959
969 res |= CODEC_REGISTER_AND_CACHE_NAMED("slin12", slin12);
970 res |= CODEC_REGISTER_AND_CACHE_NAMED("slin16", slin16);
971 res |= CODEC_REGISTER_AND_CACHE_NAMED("slin24", slin24);
972 res |= CODEC_REGISTER_AND_CACHE_NAMED("slin32", slin32);
973 res |= CODEC_REGISTER_AND_CACHE_NAMED("slin44", slin44);
974 res |= CODEC_REGISTER_AND_CACHE_NAMED("slin48", slin48);
975 res |= CODEC_REGISTER_AND_CACHE_NAMED("slin96", slin96);
976 res |= CODEC_REGISTER_AND_CACHE_NAMED("slin192", slin192);
980 res |= CODEC_REGISTER_AND_CACHE_NAMED("speex16", speex16);
981 res |= CODEC_REGISTER_AND_CACHE_NAMED("speex32", speex32);
1002 res |= CODEC_REGISTER_AND_CACHE_NAMED("silk8", silk8);
1003 res |= CODEC_REGISTER_AND_CACHE_NAMED("silk12", silk12);
1004 res |= CODEC_REGISTER_AND_CACHE_NAMED("silk16", silk16);
1005 res |= CODEC_REGISTER_AND_CACHE_NAMED("silk24", silk24);
1006
1007 return res;
1008}
static struct ast_codec g722
static struct ast_codec codec2
static struct ast_codec jpeg
static struct ast_codec t38
static struct ast_codec siren7
static struct ast_codec silk16
static struct ast_codec h263p
static struct ast_codec h263
static struct ast_codec ulaw
static struct ast_codec silk24
static struct ast_codec slin16
static struct ast_codec siren14
static struct ast_codec adpcm
static struct ast_codec silk8
static struct ast_codec g723
Definition: codec_builtin.c:97
static struct ast_codec g729a
static struct ast_codec slin32
static struct ast_codec h265
static struct ast_codec lpc10
static struct ast_codec vp8
static struct ast_codec slin192
static struct ast_codec g726rfc3551
static struct ast_codec none
static struct ast_codec g719
static struct ast_codec t140
static struct ast_codec ilbc
static struct ast_codec t140red
static struct ast_codec mpeg4
static struct ast_codec slin48
static struct ast_codec speex8
static struct ast_codec g726aal2
static struct ast_codec png
static struct ast_codec slin24
#define CODEC_REGISTER_AND_CACHE(codec)
static struct ast_codec speex32
static struct ast_codec speex16
static struct ast_codec slin8
static struct ast_codec alaw
static struct ast_codec h261
static struct ast_codec slin12
static struct ast_codec vp9
static struct ast_codec opus
static struct ast_codec h264
static struct ast_codec silk12
static struct ast_codec slin96
#define CODEC_REGISTER_AND_CACHE_NAMED(fmt_name, codec)
static struct ast_codec slin44

References adpcm, alaw, codec2, CODEC_REGISTER_AND_CACHE, CODEC_REGISTER_AND_CACHE_NAMED, g719, g722, g723, g726aal2, g726rfc3551, g729a, h261, h263, h263p, h264, h265, ilbc, jpeg, lpc10, mpeg4, none, opus, png, silk12, silk16, silk24, silk8, siren14, siren7, slin12, slin16, slin192, slin24, slin32, slin44, slin48, slin8, slin96, speex16, speex32, speex8, t140, t140red, t38, ulaw, vp8, and vp9.

Referenced by asterisk_daemon().

◆ codec2_length()

static int codec2_length ( unsigned int  samples)
static

Definition at line 116 of file codec_builtin.c.

117{
118 return (samples / 160) * 6;
119}

◆ codec2_samples()

static int codec2_samples ( struct ast_frame frame)
static

Definition at line 111 of file codec_builtin.c.

112{
113 return 160 * (frame->datalen / 6);
114}

References ast_frame::datalen.

◆ g719_length()

static int g719_length ( unsigned int  samples)
static

Definition at line 736 of file codec_builtin.c.

737{
738 return (int) samples / ((float) 48000 / 8000);
739}

◆ g719_samples()

static int g719_samples ( struct ast_frame frame)
static

Definition at line 731 of file codec_builtin.c.

732{
733 return (int) frame->datalen * ((float) 48000 / 8000);
734}

References ast_frame::datalen.

◆ g723_len()

static int g723_len ( unsigned char  buf)
static

Definition at line 53 of file codec_builtin.c.

54{
56
57 switch(type) {
58 case TYPE_DONTSEND:
59 return 0;
60 break;
61 case TYPE_SILENCE:
62 return 4;
63 break;
64 case TYPE_HIGH:
65 return 24;
66 break;
67 case TYPE_LOW:
68 return 20;
69 break;
70 default:
71 ast_log(LOG_WARNING, "Badly encoded frame (%u)\n", type);
72 }
73 return -1;
74}
static const char type[]
Definition: chan_ooh323.c:109
frame_type
Definition: codec_builtin.c:44
#define TYPE_MASK
Definition: codec_builtin.c:51
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING

References ast_log, buf, LOG_WARNING, type, TYPE_DONTSEND, TYPE_HIGH, TYPE_LOW, TYPE_MASK, and TYPE_SILENCE.

Referenced by g723_samples().

◆ g723_length()

static int g723_length ( unsigned int  samples)
static

Definition at line 92 of file codec_builtin.c.

93{
94 return (samples / 240) * 20;
95}

◆ g723_samples()

static int g723_samples ( struct ast_frame frame)
static

Definition at line 76 of file codec_builtin.c.

77{
78 unsigned char *buf = frame->data.ptr;
79 int pos = 0, samples = 0, res;
80
81 while(pos < frame->datalen) {
82 res = g723_len(buf[pos]);
83 if (res <= 0)
84 break;
85 samples += 240;
86 pos += res;
87 }
88
89 return samples;
90}
static int g723_len(unsigned char buf)
Definition: codec_builtin.c:53
union ast_frame::@226 data

References buf, ast_frame::data, g723_len(), and ast_frame::ptr.

◆ g726_length()

static int g726_length ( unsigned int  samples)
static

Definition at line 227 of file codec_builtin.c.

228{
229 return samples / 2;
230}

◆ g726_samples()

static int g726_samples ( struct ast_frame frame)
static

Definition at line 222 of file codec_builtin.c.

223{
224 return frame->datalen * 2;
225}

References ast_frame::datalen.

◆ g729_length()

static int g729_length ( unsigned int  samples)
static

Definition at line 460 of file codec_builtin.c.

461{
462 return samples / 8;
463}

◆ g729_samples()

static int g729_samples ( struct ast_frame frame)
static

Definition at line 455 of file codec_builtin.c.

456{
457 return frame->datalen * 8;
458}

References ast_frame::datalen.

◆ get_n_bits_at()

static unsigned char get_n_bits_at ( unsigned char *  data,
int  n,
int  bit 
)
static

Definition at line 481 of file codec_builtin.c.

482{
483 int byte = bit / 8; /* byte containing first bit */
484 int rem = 8 - (bit % 8); /* remaining bits in first byte */
485 unsigned char ret = 0;
486
487 if (n <= 0 || n > 8)
488 return 0;
489
490 if (rem < n) {
491 ret = (data[byte] << (n - rem));
492 ret |= (data[byte + 1] >> (8 - n + rem));
493 } else {
494 ret = (data[byte] >> (rem - n));
495 }
496
497 return (ret & (0xff >> (8 - n)));
498}

Referenced by speex_get_wb_sz_at(), and speex_samples().

◆ gsm_length()

static int gsm_length ( unsigned int  samples)
static

Definition at line 202 of file codec_builtin.c.

203{
204 return (samples / 160) * 33;
205}

◆ gsm_samples()

static int gsm_samples ( struct ast_frame frame)
static

Definition at line 197 of file codec_builtin.c.

198{
199 return 160 * (frame->datalen / 33);
200}

References ast_frame::datalen.

◆ ilbc_samples()

static int ilbc_samples ( struct ast_frame frame)
static

Definition at line 644 of file codec_builtin.c.

645{
647 const unsigned int mode = attr ? attr->mode : 30;
648 const unsigned int samples_per_frame = mode * ast_format_get_sample_rate(frame->subclass.format) / 1000;
649 const unsigned int octets_per_frame = (mode == 20) ? 38 : 50;
650
651 return samples_per_frame * frame->datalen / octets_per_frame;
652}
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
struct ast_format * format
struct ast_frame_subclass subclass
Definition: ilbc.h:4
unsigned int mode
Definition: ilbc.h:5

References ast_format_get_attribute_data(), ast_format_get_sample_rate(), ast_frame::datalen, ast_frame_subclass::format, ilbc_attr::mode, and ast_frame::subclass.

◆ lpc10_samples()

static int lpc10_samples ( struct ast_frame frame)
static

Definition at line 431 of file codec_builtin.c.

432{
433 int samples = 22 * 8;
434
435 /* assumes that the RTP packet contains one LPC10 frame */
436 samples += (((char *)(frame->data.ptr))[7] & 0x1) * 8;
437
438 return samples;
439}

References ast_frame::data, and ast_frame::ptr.

◆ none_length()

static int none_length ( unsigned int  samples)
static

Definition at line 140 of file codec_builtin.c.

140 {
141 return samples;
142}

◆ none_samples()

static int none_samples ( struct ast_frame frame)
static

Definition at line 135 of file codec_builtin.c.

136{
137 return frame->datalen;
138}

References ast_frame::datalen.

◆ opus_samples()

static int opus_samples ( struct ast_frame frame)
static

Definition at line 755 of file codec_builtin.c.

756{
757 /*
758 * XXX This is likely not at all what's intended from this
759 * callback. If you have codec_opus.so loaded then this
760 * function is overridden anyway. However, since opus is
761 * variable bit rate and I cannot extract the calculation code
762 * from the opus library, I am going to punt and assume 20ms
763 * worth of samples. In testing, this has worked just fine.
764 * Pass through support doesn't seem to care about the value
765 * returned anyway.
766 */
767 return ast_format_get_sample_rate(frame->subclass.format) / 50;
768}

References ast_format_get_sample_rate(), ast_frame_subclass::format, and ast_frame::subclass.

◆ silk_samples()

static int silk_samples ( struct ast_frame frame)
static

Definition at line 869 of file codec_builtin.c.

870{
871 /* XXX This is likely not at all what's intended from this callback. However,
872 * since SILK is variable bit rate, I have no idea how to take a frame of data
873 * and determine the number of samples present. Instead, we base this on the
874 * sample rate of the codec and the expected number of samples to receive in 20ms.
875 * In testing, this has worked just fine.
876 */
877 return ast_format_get_sample_rate(frame->subclass.format) / 50;
878}

References ast_format_get_sample_rate(), ast_frame_subclass::format, and ast_frame::subclass.

◆ siren14_length()

static int siren14_length ( unsigned int  samples)
static

Definition at line 712 of file codec_builtin.c.

713{
714 return (int) samples / ((float) 32000 / 6000);;
715}

◆ siren14_samples()

static int siren14_samples ( struct ast_frame frame)
static

Definition at line 707 of file codec_builtin.c.

708{
709 return (int) frame->datalen * ((float) 32000 / 6000);
710}

References ast_frame::datalen.

◆ siren7_length()

static int siren7_length ( unsigned int  samples)
static

Definition at line 688 of file codec_builtin.c.

689{
690 return samples / (16000 / 4000);
691}

◆ siren7_samples()

static int siren7_samples ( struct ast_frame frame)
static

Definition at line 683 of file codec_builtin.c.

684{
685 return frame->datalen * (16000 / 4000);
686}

References ast_frame::datalen.

◆ slin_length()

static int slin_length ( unsigned int  samples)
static

Definition at line 282 of file codec_builtin.c.

283{
284 return samples * 2;
285}

◆ slin_samples()

static int slin_samples ( struct ast_frame frame)
static

Definition at line 277 of file codec_builtin.c.

278{
279 return frame->datalen / 2;
280}

References ast_frame::datalen.

◆ speex16_samples()

static int speex16_samples ( struct ast_frame frame)
static

Definition at line 608 of file codec_builtin.c.

609{
610 return 2 * speex_samples(frame->data.ptr, frame->datalen);
611}
static int speex_samples(unsigned char *data, int len)

References ast_frame::data, ast_frame::datalen, ast_frame::ptr, and speex_samples().

◆ speex32_samples()

static int speex32_samples ( struct ast_frame frame)
static

Definition at line 626 of file codec_builtin.c.

627{
628 return 4 * speex_samples(frame->data.ptr, frame->datalen);
629}

References ast_frame::data, ast_frame::datalen, ast_frame::ptr, and speex_samples().

◆ speex8_samples()

static int speex8_samples ( struct ast_frame frame)
static

Definition at line 590 of file codec_builtin.c.

591{
592 return speex_samples(frame->data.ptr, frame->datalen);
593}

References ast_frame::data, ast_frame::datalen, ast_frame::ptr, and speex_samples().

◆ speex_get_wb_sz_at()

static int speex_get_wb_sz_at ( unsigned char *  data,
int  len,
int  bit 
)
static

Definition at line 500 of file codec_builtin.c.

501{
502 static const int SpeexWBSubModeSz[] = {
503 4, 36, 112, 192,
504 352, 0, 0, 0 };
505 int off = bit;
506 unsigned char c;
507
508 /* skip up to two wideband frames */
509 if (((len * 8 - off) >= 5) &&
510 get_n_bits_at(data, 1, off)) {
511 c = get_n_bits_at(data, 3, off + 1);
512 off += SpeexWBSubModeSz[c];
513
514 if (((len * 8 - off) >= 5) &&
515 get_n_bits_at(data, 1, off)) {
516 c = get_n_bits_at(data, 3, off + 1);
517 off += SpeexWBSubModeSz[c];
518
519 if (((len * 8 - off) >= 5) &&
520 get_n_bits_at(data, 1, off)) {
521 ast_log(LOG_WARNING, "Encountered corrupt speex frame; too many wideband frames in a row.\n");
522 return -1;
523 }
524 }
525
526 }
527 return off - bit;
528}
static unsigned char get_n_bits_at(unsigned char *data, int n, int bit)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static struct test_val c

References ast_log, c, get_n_bits_at(), len(), and LOG_WARNING.

Referenced by speex_samples().

◆ speex_samples()

static int speex_samples ( unsigned char *  data,
int  len 
)
static

Definition at line 530 of file codec_builtin.c.

531{
532 static const int SpeexSubModeSz[] = {
533 5, 43, 119, 160,
534 220, 300, 364, 492,
535 79, 0, 0, 0,
536 0, 0, 0, 0 };
537 static const int SpeexInBandSz[] = {
538 1, 1, 4, 4,
539 4, 4, 4, 4,
540 8, 8, 16, 16,
541 32, 32, 64, 64 };
542 int bit = 0;
543 int cnt = 0;
544 int off;
545 unsigned char c;
546
547 while ((len * 8 - bit) >= 5) {
548 /* skip wideband frames */
549 off = speex_get_wb_sz_at(data, len, bit);
550 if (off < 0) {
551 ast_log(LOG_WARNING, "Had error while reading wideband frames for speex samples\n");
552 break;
553 }
554 bit += off;
555
556 if ((len * 8 - bit) < 5)
557 break;
558
559 /* get control bits */
560 c = get_n_bits_at(data, 5, bit);
561 bit += 5;
562
563 if (c == 15) {
564 /* terminator */
565 break;
566 } else if (c == 14) {
567 /* in-band signal; next 4 bits contain signal id */
568 c = get_n_bits_at(data, 4, bit);
569 bit += 4;
570 bit += SpeexInBandSz[c];
571 } else if (c == 13) {
572 /* user in-band; next 4 bits contain msg len */
573 c = get_n_bits_at(data, 4, bit);
574 bit += 4;
575 /* after which it's 5-bit signal id + c bytes of data */
576 bit += 5 + c * 8;
577 } else if (c > 8) {
578 /* unknown */
579 ast_log(LOG_WARNING, "Unknown speex control frame %d\n", c);
580 break;
581 } else {
582 /* skip number bits for submode (less the 5 control bits) */
583 bit += SpeexSubModeSz[c] - 5;
584 cnt += 160; /* new frame */
585 }
586 }
587 return cnt;
588}
static int speex_get_wb_sz_at(unsigned char *data, int len, int bit)

References ast_log, c, get_n_bits_at(), len(), LOG_WARNING, and speex_get_wb_sz_at().

Referenced by speex16_samples(), speex32_samples(), and speex8_samples().

◆ ulaw_length()

static int ulaw_length ( unsigned int  samples)
static

Definition at line 162 of file codec_builtin.c.

163{
164 return samples;
165}

◆ ulaw_samples()

static int ulaw_samples ( struct ast_frame frame)
static

Definition at line 157 of file codec_builtin.c.

158{
159 return frame->datalen;
160}

References ast_frame::datalen.

Variable Documentation

◆ adpcm

struct ast_codec adpcm
static

Definition at line 262 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ alaw

struct ast_codec alaw
static

Definition at line 182 of file codec_builtin.c.

Referenced by alaw2linear(), ast_codec_builtin_init(), and AST_TEST_DEFINE().

◆ codec2

struct ast_codec codec2
static

Definition at line 121 of file codec_builtin.c.

Referenced by ast_codec_builtin_init(), and ast_format_cap_append_by_type().

◆ g719

struct ast_codec g719
static

Definition at line 741 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g722

struct ast_codec g722
static

Definition at line 668 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g723

struct ast_codec g723
static

Definition at line 97 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g726aal2

struct ast_codec g726aal2
static

Definition at line 247 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g726rfc3551

struct ast_codec g726rfc3551
static

Definition at line 232 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g729a

struct ast_codec g729a
static

Definition at line 465 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ gsm

struct ast_codec gsm
static

Definition at line 207 of file codec_builtin.c.

◆ h261

struct ast_codec h261
static

Definition at line 795 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ h263

struct ast_codec h263
static

Definition at line 802 of file codec_builtin.c.

Referenced by ast_codec_builtin_init(), and AST_TEST_DEFINE().

◆ h263p

struct ast_codec h263p
static

Definition at line 809 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ h264

struct ast_codec h264
static

Definition at line 816 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ h265

struct ast_codec h265
static

Definition at line 823 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ ilbc

struct ast_codec ilbc
static

Definition at line 654 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ jpeg

struct ast_codec jpeg
static
Initial value:
= {
.name = "jpeg",
.description = "JPEG image",
}
@ AST_MEDIA_TYPE_IMAGE
Definition: codec.h:34

Definition at line 783 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ lpc10

struct ast_codec lpc10
static

Definition at line 441 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ mpeg4

struct ast_codec mpeg4
static

Definition at line 830 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ none

struct ast_codec none
static

Definition at line 144 of file codec_builtin.c.

Referenced by ast_codec_builtin_init(), and AST_TEST_DEFINE().

◆ opus

struct ast_codec opus
static

Definition at line 770 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ png

struct ast_codec png
static
Initial value:
= {
.name = "png",
.description = "PNG Image",
}

Definition at line 789 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ silk12

struct ast_codec silk12
static

Definition at line 892 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ silk16

struct ast_codec silk16
static

Definition at line 904 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ silk24

struct ast_codec silk24
static

Definition at line 916 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ silk8

struct ast_codec silk8
static

Definition at line 880 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ siren14

struct ast_codec siren14
static

Definition at line 717 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ siren7

struct ast_codec siren7
static

Definition at line 693 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin12

struct ast_codec slin12
static

Definition at line 303 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin16

struct ast_codec slin16
static

Definition at line 319 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin192

struct ast_codec slin192
static

Definition at line 415 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin24

struct ast_codec slin24
static

Definition at line 335 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin32

struct ast_codec slin32
static

Definition at line 351 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin44

struct ast_codec slin44
static

Definition at line 367 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin48

struct ast_codec slin48
static

Definition at line 383 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin8

struct ast_codec slin8
static

Definition at line 287 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin96

struct ast_codec slin96
static

Definition at line 399 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ speex16

struct ast_codec speex16
static

Definition at line 613 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ speex32

struct ast_codec speex32
static

Definition at line 631 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ speex8

struct ast_codec speex8
static

Definition at line 595 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ t140

struct ast_codec t140
static
Initial value:
= {
.name = "t140",
.description = "Passthrough T.140 Realtime Text",
}
@ AST_MEDIA_TYPE_TEXT
Definition: codec.h:35

Definition at line 857 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ t140red

struct ast_codec t140red
static
Initial value:
= {
.name = "red",
.description = "T.140 Realtime Text with redundancy",
}

Definition at line 851 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ t38

struct ast_codec t38
static
Initial value:
= {
.name = "t38",
.description = "T.38 UDPTL Fax",
}

Definition at line 863 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ ulaw

struct ast_codec ulaw
static

Definition at line 167 of file codec_builtin.c.

Referenced by ast_codec_builtin_init(), and AST_TEST_DEFINE().

◆ vp8

struct ast_codec vp8
static

Definition at line 837 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ vp9

struct ast_codec vp9
static

Definition at line 844 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().