Asterisk - The Open Source Telephony Project  GIT-master-1b41629
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"

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

Referenced by ast_codec_builtin_init().

◆ CODEC_REGISTER_AND_CACHE_NAMED

#define CODEC_REGISTER_AND_CACHE_NAMED (   fmt_name,
  codec 
)

Definition at line 914 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

◆ TYPE_MASK

#define TYPE_MASK   0x3

Definition at line 51 of file codec_builtin.c.

Referenced by g723_len().

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 };

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.

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, 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().

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 }
const char * name
Name for this codec.
Definition: codec.h:46
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
unsigned int id
Internal unique identifier for this codec, set at registration time (starts at 1) ...
Definition: codec.h:44
struct ast_codec external
Public codec structure. Must remain first.
Definition: codec.c:61
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
#define ao2_link_flags(container, obj, flags)
Definition: astobj2.h:1572
#define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg)
Allocate and initialize an object.
Definition: astobj2.h:404
#define ast_verb(level,...)
Definition: logger.h:455
static void codec_dtor(void *obj)
Definition: codec.c:263
#define SCOPED_AO2WRLOCK(varname, obj)
scoped lock specialization for ao2 write locks.
Definition: lock.h:612
#define ast_log
Definition: astobj2.c:42
static struct ao2_container * codecs
Registered codecs.
Definition: codec.c:48
ast_mutex_t lock
Definition: app_meetme.c:1091
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define LOG_ERROR
Definition: logger.h:285
const char * description
Brief description.
Definition: codec.h:48
#define ast_module_shutdown_ref(mod)
Prevent unload of the module before shutdown.
Definition: module.h:464
static int codec_id
Current identifier value for newly registered codec.
Definition: codec.c:45
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
const char * format_name
A format name for a default sane format using this codec.
Definition: codec.c:63
unsigned int sample_rate
Sample rate (number of samples carried in a second)
Definition: codec.h:52
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
enum ast_media_type type
Type of media this codec contains.
Definition: codec.h:50

◆ ast_codec_builtin_init()

int ast_codec_builtin_init ( void  )

Initialize built-in codecs within the core.

Return values
0success
-1failure

Definition at line 928 of file codec_builtin.c.

References CODEC_REGISTER_AND_CACHE, and CODEC_REGISTER_AND_CACHE_NAMED.

Referenced by asterisk_daemon().

929 {
930  int res = 0;
931 
941  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin12", slin12);
942  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin16", slin16);
943  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin24", slin24);
944  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin32", slin32);
945  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin44", slin44);
946  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin48", slin48);
947  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin96", slin96);
948  res |= CODEC_REGISTER_AND_CACHE_NAMED("slin192", slin192);
952  res |= CODEC_REGISTER_AND_CACHE_NAMED("speex16", speex16);
953  res |= CODEC_REGISTER_AND_CACHE_NAMED("speex32", speex32);
974  res |= CODEC_REGISTER_AND_CACHE_NAMED("silk8", silk8);
975  res |= CODEC_REGISTER_AND_CACHE_NAMED("silk12", silk12);
976  res |= CODEC_REGISTER_AND_CACHE_NAMED("silk16", silk16);
977  res |= CODEC_REGISTER_AND_CACHE_NAMED("silk24", silk24);
978 
979  return res;
980 }
static struct ast_codec slin8
static struct ast_codec opus
static struct ast_codec ulaw
static struct ast_codec speex8
static struct ast_codec g726aal2
static struct ast_codec slin48
static struct ast_codec silk12
static struct ast_codec none
static struct ast_codec slin44
static struct ast_codec silk24
static struct ast_codec slin16
#define CODEC_REGISTER_AND_CACHE_NAMED(fmt_name, codec)
static struct ast_codec h261
static struct ast_codec siren14
static struct ast_codec speex16
static struct ast_codec t140red
static struct ast_codec alaw
static struct ast_codec siren7
static struct ast_codec silk16
#define CODEC_REGISTER_AND_CACHE(codec)
static struct ast_codec codec2
static struct ast_codec mpeg4
static struct ast_codec g722
static struct ast_codec silk8
static struct ast_codec t38
static struct ast_codec slin192
static struct ast_codec speex32
static struct ast_codec jpeg
static struct ast_codec slin96
static struct ast_codec adpcm
static struct ast_codec g729a
static struct ast_codec h263
static struct ast_codec h264
static struct ast_codec vp8
static struct ast_codec slin32
static struct ast_codec t140
static struct ast_codec g726rfc3551
static struct ast_codec slin24
static struct ast_codec g719
static struct ast_codec h265
static struct ast_codec lpc10
static struct ast_codec png
static struct ast_codec g723
Definition: codec_builtin.c:97
static struct ast_codec vp9
static struct ast_codec slin12
static struct ast_codec h263p
static struct ast_codec ilbc

◆ 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.

References ast_frame::datalen.

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

◆ g719_length()

static int g719_length ( unsigned int  samples)
static

Definition at line 710 of file codec_builtin.c.

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

◆ g719_samples()

static int g719_samples ( struct ast_frame frame)
static

Definition at line 705 of file codec_builtin.c.

References ast_frame::datalen.

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

◆ g723_len()

static int g723_len ( unsigned char  buf)
static

Definition at line 53 of file codec_builtin.c.

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

Referenced by g723_samples().

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
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
#define TYPE_MASK
Definition: codec_builtin.c:51
frame_type
Definition: codec_builtin.c:44

◆ 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.

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

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
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
union ast_frame::@257 data

◆ 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.

References ast_frame::datalen.

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

◆ 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.

References ast_frame::datalen.

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

◆ get_n_bits_at()

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

Definition at line 462 of file codec_builtin.c.

Referenced by speex_get_wb_sz_at(), and speex_samples().

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

◆ 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.

References ast_frame::datalen.

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

◆ ilbc_samples()

static int ilbc_samples ( struct ast_frame frame)
static

Definition at line 622 of file codec_builtin.c.

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.

623 {
625  const unsigned int mode = attr ? attr->mode : 30;
626  const unsigned int samples_per_frame = mode * ast_format_get_sample_rate(frame->subclass.format) / 1000;
627  const unsigned int octets_per_frame = (mode == 20) ? 38 : 50;
628 
629  return samples_per_frame * frame->datalen / octets_per_frame;
630 }
Definition: ilbc.h:4
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
struct ast_frame_subclass subclass
unsigned int mode
Definition: ilbc.h:5
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

◆ lpc10_samples()

static int lpc10_samples ( struct ast_frame frame)
static

Definition at line 415 of file codec_builtin.c.

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

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 }
union ast_frame::@257 data

◆ 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.

References ast_frame::datalen.

135 {
136  return frame->datalen;
137 }

◆ opus_samples()

static int opus_samples ( struct ast_frame frame)
static

Definition at line 728 of file codec_builtin.c.

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

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

◆ silk_samples()

static int silk_samples ( struct ast_frame frame)
static

Definition at line 841 of file codec_builtin.c.

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

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

◆ siren14_length()

static int siren14_length ( unsigned int  samples)
static

Definition at line 687 of file codec_builtin.c.

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

◆ siren14_samples()

static int siren14_samples ( struct ast_frame frame)
static

Definition at line 682 of file codec_builtin.c.

References ast_frame::datalen.

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

◆ siren7_length()

static int siren7_length ( unsigned int  samples)
static

Definition at line 664 of file codec_builtin.c.

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

◆ siren7_samples()

static int siren7_samples ( struct ast_frame frame)
static

Definition at line 659 of file codec_builtin.c.

References ast_frame::datalen.

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

◆ 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.

References ast_frame::datalen.

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

◆ speex16_samples()

static int speex16_samples ( struct ast_frame frame)
static

Definition at line 588 of file codec_builtin.c.

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

589 {
590  return 2 * speex_samples(frame->data.ptr, frame->datalen);
591 }
static int speex_samples(unsigned char *data, int len)
union ast_frame::@257 data

◆ speex32_samples()

static int speex32_samples ( struct ast_frame frame)
static

Definition at line 605 of file codec_builtin.c.

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

606 {
607  return 4 * speex_samples(frame->data.ptr, frame->datalen);
608 }
static int speex_samples(unsigned char *data, int len)
union ast_frame::@257 data

◆ speex8_samples()

static int speex8_samples ( struct ast_frame frame)
static

Definition at line 571 of file codec_builtin.c.

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

572 {
573  return speex_samples(frame->data.ptr, frame->datalen);
574 }
static int speex_samples(unsigned char *data, int len)
union ast_frame::@257 data

◆ speex_get_wb_sz_at()

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

Definition at line 481 of file codec_builtin.c.

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

Referenced by speex_samples().

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

◆ speex_samples()

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

Definition at line 511 of file codec_builtin.c.

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

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

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

◆ 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.

References ast_frame::datalen.

157 {
158  return frame->datalen;
159 }

Variable Documentation

◆ adpcm

struct ast_codec adpcm
static

Definition at line 256 of file codec_builtin.c.

◆ alaw

struct ast_codec alaw
static

Definition at line 180 of file codec_builtin.c.

Referenced by AST_TEST_DEFINE().

◆ codec2

struct ast_codec codec2
static

Definition at line 120 of file codec_builtin.c.

Referenced by ast_format_cap_append_by_type().

◆ g719

struct ast_codec g719
static

Definition at line 715 of file codec_builtin.c.

◆ g722

struct ast_codec g722
static

Definition at line 645 of file codec_builtin.c.

◆ g723

struct ast_codec g723
static

Definition at line 97 of file codec_builtin.c.

◆ g726aal2

struct ast_codec g726aal2
static

Definition at line 242 of file codec_builtin.c.

◆ g726rfc3551

struct ast_codec g726rfc3551
static

Definition at line 228 of file codec_builtin.c.

◆ g729a

struct ast_codec g729a
static

Definition at line 448 of file codec_builtin.c.

◆ gsm

struct ast_codec gsm
static

Definition at line 204 of file codec_builtin.c.

◆ h261

struct ast_codec h261
static

Definition at line 767 of file codec_builtin.c.

◆ h263

struct ast_codec h263
static

Definition at line 774 of file codec_builtin.c.

Referenced by AST_TEST_DEFINE().

◆ h263p

struct ast_codec h263p
static

Definition at line 781 of file codec_builtin.c.

◆ h264

struct ast_codec h264
static

Definition at line 788 of file codec_builtin.c.

◆ h265

struct ast_codec h265
static

Definition at line 795 of file codec_builtin.c.

◆ ilbc

struct ast_codec ilbc
static

Definition at line 632 of file codec_builtin.c.

◆ jpeg

struct ast_codec jpeg
static
Initial value:
= {
.name = "jpeg",
.description = "JPEG image",
}

Definition at line 755 of file codec_builtin.c.

◆ lpc10

struct ast_codec lpc10
static

Definition at line 425 of file codec_builtin.c.

◆ mpeg4

struct ast_codec mpeg4
static

Definition at line 802 of file codec_builtin.c.

◆ none

struct ast_codec none
static

Definition at line 143 of file codec_builtin.c.

◆ opus

struct ast_codec opus
static

Definition at line 743 of file codec_builtin.c.

◆ png

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

Definition at line 761 of file codec_builtin.c.

◆ silk12

struct ast_codec silk12
static

Definition at line 864 of file codec_builtin.c.

◆ silk16

struct ast_codec silk16
static

Definition at line 876 of file codec_builtin.c.

◆ silk24

struct ast_codec silk24
static

Definition at line 888 of file codec_builtin.c.

◆ silk8

struct ast_codec silk8
static

Definition at line 852 of file codec_builtin.c.

◆ siren14

struct ast_codec siren14
static

Definition at line 692 of file codec_builtin.c.

◆ siren7

struct ast_codec siren7
static

Definition at line 669 of file codec_builtin.c.

◆ slin12

struct ast_codec slin12
static

Definition at line 295 of file codec_builtin.c.

◆ slin16

struct ast_codec slin16
static

Definition at line 310 of file codec_builtin.c.

◆ slin192

struct ast_codec slin192
static

Definition at line 400 of file codec_builtin.c.

◆ slin24

struct ast_codec slin24
static

Definition at line 325 of file codec_builtin.c.

◆ slin32

struct ast_codec slin32
static

Definition at line 340 of file codec_builtin.c.

◆ slin44

struct ast_codec slin44
static

Definition at line 355 of file codec_builtin.c.

◆ slin48

struct ast_codec slin48
static

Definition at line 370 of file codec_builtin.c.

◆ slin8

struct ast_codec slin8
static

Definition at line 280 of file codec_builtin.c.

◆ slin96

struct ast_codec slin96
static

Definition at line 385 of file codec_builtin.c.

◆ speex16

struct ast_codec speex16
static

Definition at line 593 of file codec_builtin.c.

◆ speex32

struct ast_codec speex32
static

Definition at line 610 of file codec_builtin.c.

◆ speex8

struct ast_codec speex8
static

Definition at line 576 of file codec_builtin.c.

◆ t140

struct ast_codec t140
static
Initial value:
= {
.name = "t140",
.description = "Passthrough T.140 Realtime Text",
}

Definition at line 829 of file codec_builtin.c.

◆ t140red

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

Definition at line 823 of file codec_builtin.c.

◆ t38

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

Definition at line 835 of file codec_builtin.c.

◆ ulaw

struct ast_codec ulaw
static

Definition at line 166 of file codec_builtin.c.

Referenced by AST_TEST_DEFINE().

◆ vp8

struct ast_codec vp8
static

Definition at line 809 of file codec_builtin.c.

◆ vp9

struct ast_codec vp9
static

Definition at line 816 of file codec_builtin.c.