Asterisk - The Open Source Telephony Project  GIT-master-a24979a
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 901 of file codec_builtin.c.

◆ CODEC_REGISTER_AND_CACHE_NAMED

#define CODEC_REGISTER_AND_CACHE_NAMED (   fmt_name,
  codec 
)

Definition at line 915 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 277 of file codec.c.

278 {
280  struct internal_ast_codec *codec_new;
281 
282  /* Some types have specific requirements */
283  if (codec->type == AST_MEDIA_TYPE_UNKNOWN) {
284  ast_log(LOG_ERROR, "A media type must be specified for codec '%s'\n", codec->name);
285  return -1;
286  } else if (codec->type == AST_MEDIA_TYPE_AUDIO) {
287  if (!codec->sample_rate) {
288  ast_log(LOG_ERROR, "A sample rate must be specified for codec '%s' of type '%s'\n",
289  codec->name, ast_codec_media_type2str(codec->type));
290  return -1;
291  }
292  }
293 
294  codec_new = ao2_find(codecs, codec, OBJ_SEARCH_OBJECT | OBJ_NOLOCK);
295  if (codec_new) {
296  ast_log(LOG_ERROR, "A codec with name '%s' of type '%s' and sample rate '%u' is already registered\n",
297  codec->name, ast_codec_media_type2str(codec->type), codec->sample_rate);
298  ao2_ref(codec_new, -1);
299  return -1;
300  }
301 
302  codec_new = ao2_t_alloc_options(sizeof(*codec_new), codec_dtor,
304  if (!codec_new) {
305  ast_log(LOG_ERROR, "Could not allocate a codec with name '%s' of type '%s' and sample rate '%u'\n",
306  codec->name, ast_codec_media_type2str(codec->type), codec->sample_rate);
307  return -1;
308  }
309  codec_new->external = *codec;
310  codec_new->format_name = format_name;
311  codec_new->external.id = codec_id++;
312 
313  ao2_link_flags(codecs, codec_new, OBJ_NOLOCK);
314 
315  /* Once registered a codec can not be unregistered, and the module must persist until shutdown */
317 
318  ast_verb(2, "Registered '%s' codec '%s' at sample rate '%u' with id '%u'\n",
319  ast_codec_media_type2str(codec->type), codec->name, codec->sample_rate, codec_new->external.id);
320 
321  ao2_ref(codec_new, -1);
322 
323  return 0;
324 }
ast_mutex_t lock
Definition: app_meetme.c:1093
#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:347
static void codec_dtor(void *obj)
Definition: codec.c:263
@ 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:612
#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 929 of file codec_builtin.c.

930 {
931  int res = 0;
932 
942  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin12", slin12);
943  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin16", slin16);
944  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin24", slin24);
945  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin32", slin32);
946  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin44", slin44);
947  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin48", slin48);
948  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin96", slin96);
949  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin192", slin192);
953  res |= CODEC_REGISTER_AND_CACHE_NAMED("speex16", speex16);
954  res |= CODEC_REGISTER_AND_CACHE_NAMED("speex32", speex32);
975  res |= CODEC_REGISTER_AND_CACHE_NAMED("silk8", silk8);
976  res |= CODEC_REGISTER_AND_CACHE_NAMED("silk12", silk12);
977  res |= CODEC_REGISTER_AND_CACHE_NAMED("silk16", silk16);
978  res |= CODEC_REGISTER_AND_CACHE_NAMED("silk24", silk24);
979 
980  return res;
981 }
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 115 of file codec_builtin.c.

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

◆ codec2_samples()

static int codec2_samples ( struct ast_frame frame)
static

Definition at line 110 of file codec_builtin.c.

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

References ast_frame::datalen.

◆ g719_length()

static int g719_length ( unsigned int  samples)
static

Definition at line 711 of file codec_builtin.c.

712 {
713  return (int) samples / ((float) 48000 / 8000);
714 }

◆ g719_samples()

static int g719_samples ( struct ast_frame frame)
static

Definition at line 706 of file codec_builtin.c.

707 {
708  return (int) frame->datalen * ((float) 48000 / 8000);
709 }

References ast_frame::datalen.

◆ g723_len()

static int g723_len ( unsigned char  buf)
static

Definition at line 53 of file codec_builtin.c.

54 {
55  enum frame_type type = buf & TYPE_MASK;
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::@254 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 223 of file codec_builtin.c.

224 {
225  return samples / 2;
226 }

◆ g726_samples()

static int g726_samples ( struct ast_frame frame)
static

Definition at line 218 of file codec_builtin.c.

219 {
220  return frame->datalen * 2;
221 }

References ast_frame::datalen.

◆ g729_length()

static int g729_length ( unsigned int  samples)
static

Definition at line 443 of file codec_builtin.c.

444 {
445  return samples / 8;
446 }

◆ g729_samples()

static int g729_samples ( struct ast_frame frame)
static

Definition at line 438 of file codec_builtin.c.

439 {
440  return frame->datalen * 8;
441 }

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 463 of file codec_builtin.c.

464 {
465  int byte = bit / 8; /* byte containing first bit */
466  int rem = 8 - (bit % 8); /* remaining bits in first byte */
467  unsigned char ret = 0;
468 
469  if (n <= 0 || n > 8)
470  return 0;
471 
472  if (rem < n) {
473  ret = (data[byte] << (n - rem));
474  ret |= (data[byte + 1] >> (8 - n + rem));
475  } else {
476  ret = (data[byte] >> (rem - n));
477  }
478 
479  return (ret & (0xff >> (8 - n)));
480 }

Referenced by speex_get_wb_sz_at(), and speex_samples().

◆ gsm_length()

static int gsm_length ( unsigned int  samples)
static

Definition at line 199 of file codec_builtin.c.

200 {
201  return (samples / 160) * 33;
202 }

◆ gsm_samples()

static int gsm_samples ( struct ast_frame frame)
static

Definition at line 194 of file codec_builtin.c.

195 {
196  return 160 * (frame->datalen / 33);
197 }

References ast_frame::datalen.

◆ ilbc_samples()

static int ilbc_samples ( struct ast_frame frame)
static

Definition at line 623 of file codec_builtin.c.

624 {
626  const unsigned int mode = attr ? attr->mode : 30;
627  const unsigned int samples_per_frame = mode * ast_format_get_sample_rate(frame->subclass.format) / 1000;
628  const unsigned int octets_per_frame = (mode == 20) ? 38 : 50;
629 
630  return samples_per_frame * frame->datalen / octets_per_frame;
631 }
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
struct ast_format * format
struct ast_frame_subclass subclass
Definition: ilbc.h:4
unsigned int mode
Definition: ilbc.h:5

◆ lpc10_samples()

static int lpc10_samples ( struct ast_frame frame)
static

Definition at line 415 of file codec_builtin.c.

416 {
417  int samples = 22 * 8;
418 
419  /* assumes that the RTP packet contains one LPC10 frame */
420  samples += (((char *)(frame->data.ptr))[7] & 0x1) * 8;
421 
422  return samples;
423 }

◆ none_length()

static int none_length ( unsigned int  samples)
static

Definition at line 139 of file codec_builtin.c.

139  {
140  return samples;
141 }

◆ none_samples()

static int none_samples ( struct ast_frame frame)
static

Definition at line 134 of file codec_builtin.c.

135 {
136  return frame->datalen;
137 }

References ast_frame::datalen.

◆ opus_samples()

static int opus_samples ( struct ast_frame frame)
static

Definition at line 729 of file codec_builtin.c.

730 {
731  /*
732  * XXX This is likely not at all what's intended from this
733  * callback. If you have codec_opus.so loaded then this
734  * function is overridden anyway. However, since opus is
735  * variable bit rate and I cannot extract the calculation code
736  * from the opus library, I am going to punt and assume 20ms
737  * worth of samples. In testing, this has worked just fine.
738  * Pass through support doesn't seem to care about the value
739  * returned anyway.
740  */
741  return ast_format_get_sample_rate(frame->subclass.format) / 50;
742 }

◆ silk_samples()

static int silk_samples ( struct ast_frame frame)
static

Definition at line 842 of file codec_builtin.c.

843 {
844  /* XXX This is likely not at all what's intended from this callback. However,
845  * since SILK is variable bit rate, I have no idea how to take a frame of data
846  * and determine the number of samples present. Instead, we base this on the
847  * sample rate of the codec and the expected number of samples to receive in 20ms.
848  * In testing, this has worked just fine.
849  */
850  return ast_format_get_sample_rate(frame->subclass.format) / 50;
851 }

◆ siren14_length()

static int siren14_length ( unsigned int  samples)
static

Definition at line 688 of file codec_builtin.c.

689 {
690  return (int) samples / ((float) 32000 / 6000);;
691 }

◆ siren14_samples()

static int siren14_samples ( struct ast_frame frame)
static

Definition at line 683 of file codec_builtin.c.

684 {
685  return (int) frame->datalen * ((float) 32000 / 6000);
686 }

References ast_frame::datalen.

◆ siren7_length()

static int siren7_length ( unsigned int  samples)
static

Definition at line 665 of file codec_builtin.c.

666 {
667  return samples / (16000 / 4000);
668 }

◆ siren7_samples()

static int siren7_samples ( struct ast_frame frame)
static

Definition at line 660 of file codec_builtin.c.

661 {
662  return frame->datalen * (16000 / 4000);
663 }

References ast_frame::datalen.

◆ slin_length()

static int slin_length ( unsigned int  samples)
static

Definition at line 275 of file codec_builtin.c.

276 {
277  return samples * 2;
278 }

◆ slin_samples()

static int slin_samples ( struct ast_frame frame)
static

Definition at line 270 of file codec_builtin.c.

271 {
272  return frame->datalen / 2;
273 }

References ast_frame::datalen.

◆ speex16_samples()

static int speex16_samples ( struct ast_frame frame)
static

Definition at line 589 of file codec_builtin.c.

590 {
591  return 2 * speex_samples(frame->data.ptr, frame->datalen);
592 }
static int speex_samples(unsigned char *data, int len)

◆ speex32_samples()

static int speex32_samples ( struct ast_frame frame)
static

Definition at line 606 of file codec_builtin.c.

607 {
608  return 4 * speex_samples(frame->data.ptr, frame->datalen);
609 }

◆ speex8_samples()

static int speex8_samples ( struct ast_frame frame)
static

Definition at line 572 of file codec_builtin.c.

573 {
574  return speex_samples(frame->data.ptr, frame->datalen);
575 }

◆ speex_get_wb_sz_at()

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

Definition at line 482 of file codec_builtin.c.

483 {
484  static const int SpeexWBSubModeSz[] = {
485  4, 36, 112, 192,
486  352, 0, 0, 0 };
487  int off = bit;
488  unsigned char c;
489 
490  /* skip up to two wideband frames */
491  if (((len * 8 - off) >= 5) &&
492  get_n_bits_at(data, 1, off)) {
493  c = get_n_bits_at(data, 3, off + 1);
494  off += SpeexWBSubModeSz[c];
495 
496  if (((len * 8 - off) >= 5) &&
497  get_n_bits_at(data, 1, off)) {
498  c = get_n_bits_at(data, 3, off + 1);
499  off += SpeexWBSubModeSz[c];
500 
501  if (((len * 8 - off) >= 5) &&
502  get_n_bits_at(data, 1, off)) {
503  ast_log(LOG_WARNING, "Encountered corrupt speex frame; too many wideband frames in a row.\n");
504  return -1;
505  }
506  }
507 
508  }
509  return off - bit;
510 }
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 512 of file codec_builtin.c.

513 {
514  static const int SpeexSubModeSz[] = {
515  5, 43, 119, 160,
516  220, 300, 364, 492,
517  79, 0, 0, 0,
518  0, 0, 0, 0 };
519  static const int SpeexInBandSz[] = {
520  1, 1, 4, 4,
521  4, 4, 4, 4,
522  8, 8, 16, 16,
523  32, 32, 64, 64 };
524  int bit = 0;
525  int cnt = 0;
526  int off;
527  unsigned char c;
528 
529  while ((len * 8 - bit) >= 5) {
530  /* skip wideband frames */
531  off = speex_get_wb_sz_at(data, len, bit);
532  if (off < 0) {
533  ast_log(LOG_WARNING, "Had error while reading wideband frames for speex samples\n");
534  break;
535  }
536  bit += off;
537 
538  if ((len * 8 - bit) < 5)
539  break;
540 
541  /* get control bits */
542  c = get_n_bits_at(data, 5, bit);
543  bit += 5;
544 
545  if (c == 15) {
546  /* terminator */
547  break;
548  } else if (c == 14) {
549  /* in-band signal; next 4 bits contain signal id */
550  c = get_n_bits_at(data, 4, bit);
551  bit += 4;
552  bit += SpeexInBandSz[c];
553  } else if (c == 13) {
554  /* user in-band; next 4 bits contain msg len */
555  c = get_n_bits_at(data, 4, bit);
556  bit += 4;
557  /* after which it's 5-bit signal id + c bytes of data */
558  bit += 5 + c * 8;
559  } else if (c > 8) {
560  /* unknown */
561  ast_log(LOG_WARNING, "Unknown speex control frame %d\n", c);
562  break;
563  } else {
564  /* skip number bits for submode (less the 5 control bits) */
565  bit += SpeexSubModeSz[c] - 5;
566  cnt += 160; /* new frame */
567  }
568  }
569  return cnt;
570 }
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().

◆ ulaw_length()

static int ulaw_length ( unsigned int  samples)
static

Definition at line 161 of file codec_builtin.c.

162 {
163  return samples;
164 }

◆ ulaw_samples()

static int ulaw_samples ( struct ast_frame frame)
static

Definition at line 156 of file codec_builtin.c.

157 {
158  return frame->datalen;
159 }

References ast_frame::datalen.

Variable Documentation

◆ adpcm

struct ast_codec adpcm
static

Definition at line 223 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ alaw

struct ast_codec alaw
static

Definition at line 161 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 115 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 711 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g722

struct ast_codec g722
static

Definition at line 623 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g723

struct ast_codec g723
static

Definition at line 92 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g726aal2

struct ast_codec g726aal2
static

Definition at line 223 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g726rfc3551

struct ast_codec g726rfc3551
static

Definition at line 223 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ g729a

struct ast_codec g729a
static

Definition at line 443 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ gsm

struct ast_codec gsm
static

Definition at line 199 of file codec_builtin.c.

◆ h261

struct ast_codec h261
static

Definition at line 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ h263

struct ast_codec h263
static

Definition at line 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init(), and AST_TEST_DEFINE().

◆ h263p

struct ast_codec h263p
static

Definition at line 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ h264

struct ast_codec h264
static

Definition at line 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ h265

struct ast_codec h265
static

Definition at line 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ ilbc

struct ast_codec ilbc
static

Definition at line 623 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 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ lpc10

struct ast_codec lpc10
static

Definition at line 415 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ mpeg4

struct ast_codec mpeg4
static

Definition at line 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ none

struct ast_codec none
static

Definition at line 139 of file codec_builtin.c.

Referenced by ast_codec_builtin_init(), and AST_TEST_DEFINE().

◆ opus

struct ast_codec opus
static

Definition at line 729 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 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ silk12

struct ast_codec silk12
static

Definition at line 842 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ silk16

struct ast_codec silk16
static

Definition at line 842 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ silk24

struct ast_codec silk24
static

Definition at line 842 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ silk8

struct ast_codec silk8
static

Definition at line 842 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ siren14

struct ast_codec siren14
static

Definition at line 688 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ siren7

struct ast_codec siren7
static

Definition at line 665 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin12

struct ast_codec slin12
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin16

struct ast_codec slin16
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin192

struct ast_codec slin192
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin24

struct ast_codec slin24
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin32

struct ast_codec slin32
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin44

struct ast_codec slin44
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin48

struct ast_codec slin48
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin8

struct ast_codec slin8
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ slin96

struct ast_codec slin96
static

Definition at line 275 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ speex16

struct ast_codec speex16
static

Definition at line 589 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ speex32

struct ast_codec speex32
static

Definition at line 606 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ speex8

struct ast_codec speex8
static

Definition at line 572 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 729 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 729 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 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ ulaw

struct ast_codec ulaw
static

Definition at line 161 of file codec_builtin.c.

Referenced by ast_codec_builtin_init(), and AST_TEST_DEFINE().

◆ vp8

struct ast_codec vp8
static

Definition at line 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ vp9

struct ast_codec vp9
static

Definition at line 729 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().