codec_builtin.c File Reference

Built-in supported codecs. More...

#include "asterisk.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 dependency graph for codec_builtin.c:

Go to the source code of this file.

Defines

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

Enumerations

enum  frame_type { TYPE_HIGH, TYPE_LOW, TYPE_SILENCE, TYPE_DONTSEND }

Functions

int ast_codec_builtin_init (void)
 Initialize built-in codecs within the core.
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 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 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 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 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 testlaw
static struct ast_codec ulaw
static struct ast_codec vp8


Detailed Description

Built-in supported codecs.

Author:
Joshua Colp <jcolp@digium.com>

Definition in file codec_builtin.c.


Define Documentation

#define CODEC_REGISTER_AND_CACHE ( codec   ) 

Definition at line 772 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

#define CODEC_REGISTER_AND_CACHE_NAMED ( format_name,
codec   ) 

Definition at line 786 of file codec_builtin.c.

Referenced by ast_codec_builtin_init().

#define TYPE_MASK   0x3

Definition at line 48 of file codec_builtin.c.


Enumeration Type Documentation

enum frame_type

Enumerator:
TYPE_HIGH 
TYPE_LOW 
TYPE_SILENCE 
TYPE_DONTSEND 

Definition at line 41 of file codec_builtin.c.

00041                 {
00042    TYPE_HIGH,     /* 0x0 */
00043    TYPE_LOW,      /* 0x1 */
00044    TYPE_SILENCE,  /* 0x2 */
00045    TYPE_DONTSEND  /* 0x3 */
00046 };


Function Documentation

int ast_codec_builtin_init ( void   ) 

Initialize built-in codecs within the core.

Return values:
0 success
-1 failure

Definition at line 800 of file codec_builtin.c.

References CODEC_REGISTER_AND_CACHE, and CODEC_REGISTER_AND_CACHE_NAMED.

Referenced by main().

00801 {
00802    int res = 0;
00803 
00804    res |= CODEC_REGISTER_AND_CACHE(g723);
00805    res |= CODEC_REGISTER_AND_CACHE(ulaw);
00806    res |= CODEC_REGISTER_AND_CACHE(alaw);
00807    res |= CODEC_REGISTER_AND_CACHE(gsm);
00808    res |= CODEC_REGISTER_AND_CACHE(g726rfc3551);
00809    res |= CODEC_REGISTER_AND_CACHE(g726aal2);
00810    res |= CODEC_REGISTER_AND_CACHE(adpcm);
00811    res |= CODEC_REGISTER_AND_CACHE(slin8);
00812    res |= CODEC_REGISTER_AND_CACHE_NAMED("slin12", slin12);
00813    res |= CODEC_REGISTER_AND_CACHE_NAMED("slin16", slin16);
00814    res |= CODEC_REGISTER_AND_CACHE_NAMED("slin24", slin24);
00815    res |= CODEC_REGISTER_AND_CACHE_NAMED("slin32", slin32);
00816    res |= CODEC_REGISTER_AND_CACHE_NAMED("slin44", slin44);
00817    res |= CODEC_REGISTER_AND_CACHE_NAMED("slin48", slin48);
00818    res |= CODEC_REGISTER_AND_CACHE_NAMED("slin96", slin96);
00819    res |= CODEC_REGISTER_AND_CACHE_NAMED("slin192", slin192);
00820    res |= CODEC_REGISTER_AND_CACHE(lpc10);
00821    res |= CODEC_REGISTER_AND_CACHE(g729a);
00822    res |= CODEC_REGISTER_AND_CACHE(speex8);
00823    res |= CODEC_REGISTER_AND_CACHE_NAMED("speex16", speex16);
00824    res |= CODEC_REGISTER_AND_CACHE_NAMED("speex32", speex32);
00825    res |= CODEC_REGISTER_AND_CACHE(ilbc);
00826    res |= CODEC_REGISTER_AND_CACHE(g722);
00827    res |= CODEC_REGISTER_AND_CACHE(siren7);
00828    res |= CODEC_REGISTER_AND_CACHE(siren14);
00829    res |= CODEC_REGISTER_AND_CACHE(testlaw);
00830    res |= CODEC_REGISTER_AND_CACHE(g719);
00831    res |= CODEC_REGISTER_AND_CACHE(opus);
00832    res |= CODEC_REGISTER_AND_CACHE(jpeg);
00833    res |= CODEC_REGISTER_AND_CACHE(png);
00834    res |= CODEC_REGISTER_AND_CACHE(h261);
00835    res |= CODEC_REGISTER_AND_CACHE(h263);
00836    res |= CODEC_REGISTER_AND_CACHE(h263p);
00837    res |= CODEC_REGISTER_AND_CACHE(h264);
00838    res |= CODEC_REGISTER_AND_CACHE(mpeg4);
00839    res |= CODEC_REGISTER_AND_CACHE(vp8);
00840    res |= CODEC_REGISTER_AND_CACHE(t140red);
00841    res |= CODEC_REGISTER_AND_CACHE(t140);
00842    res |= CODEC_REGISTER_AND_CACHE(none);
00843 
00844    return res;
00845 }

static int g719_length ( unsigned int  samples  )  [static]

Definition at line 683 of file codec_builtin.c.

00684 {
00685    return (int) samples / ((float) 48000 / 8000);
00686 }

static int g719_samples ( struct ast_frame frame  )  [static]

Definition at line 678 of file codec_builtin.c.

References ast_frame::datalen.

00679 {
00680    return (int) frame->datalen * ((float) 48000 / 8000);
00681 }

static int g723_len ( unsigned char  buf  )  [static]

Definition at line 50 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().

00051 {
00052    enum frame_type type = buf & TYPE_MASK;
00053 
00054    switch(type) {
00055    case TYPE_DONTSEND:
00056       return 0;
00057       break;
00058    case TYPE_SILENCE:
00059       return 4;
00060       break;
00061    case TYPE_HIGH:
00062       return 24;
00063       break;
00064    case TYPE_LOW:
00065       return 20;
00066       break;
00067    default:
00068       ast_log(LOG_WARNING, "Badly encoded frame (%u)\n", type);
00069    }
00070    return -1;
00071 }

static int g723_length ( unsigned int  samples  )  [static]

Definition at line 89 of file codec_builtin.c.

00090 {
00091    return (samples / 240) * 20;
00092 }

static int g723_samples ( struct ast_frame frame  )  [static]

Definition at line 73 of file codec_builtin.c.

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

00074 {
00075    unsigned char *buf = frame->data.ptr;
00076    int pos = 0, samples = 0, res;
00077 
00078    while(pos < frame->datalen) {
00079       res = g723_len(buf[pos]);
00080       if (res <= 0)
00081          break;
00082       samples += 240;
00083       pos += res;
00084    }
00085 
00086    return samples;
00087 }

static int g726_length ( unsigned int  samples  )  [static]

Definition at line 196 of file codec_builtin.c.

00197 {
00198    return samples / 2;
00199 }

static int g726_samples ( struct ast_frame frame  )  [static]

Definition at line 191 of file codec_builtin.c.

References ast_frame::datalen.

00192 {
00193    return frame->datalen * 2;
00194 }

static int g729_length ( unsigned int  samples  )  [static]

Definition at line 407 of file codec_builtin.c.

00408 {
00409    return samples / 8;
00410 }

static int g729_samples ( struct ast_frame frame  )  [static]

Definition at line 402 of file codec_builtin.c.

References ast_frame::datalen.

00403 {
00404    return frame->datalen * 8;
00405 }

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

Definition at line 426 of file codec_builtin.c.

Referenced by speex_get_wb_sz_at(), and speex_samples().

00427 {
00428    int byte = bit / 8;       /* byte containing first bit */
00429    int rem = 8 - (bit % 8);  /* remaining bits in first byte */
00430    unsigned char ret = 0;
00431 
00432    if (n <= 0 || n > 8)
00433       return 0;
00434 
00435    if (rem < n) {
00436       ret = (data[byte] << (n - rem));
00437       ret |= (data[byte + 1] >> (8 - n + rem));
00438    } else {
00439       ret = (data[byte] >> (rem - n));
00440    }
00441 
00442    return (ret & (0xff >> (8 - n)));
00443 }

static int gsm_length ( unsigned int  samples  )  [static]

Definition at line 172 of file codec_builtin.c.

00173 {
00174    return (samples / 160) * 33;
00175 }

static int gsm_samples ( struct ast_frame frame  )  [static]

Definition at line 167 of file codec_builtin.c.

References ast_frame::datalen.

00168 {
00169    return 160 * (frame->datalen / 33);
00170 }

static int ilbc_samples ( struct ast_frame frame  )  [static]

Definition at line 586 of file codec_builtin.c.

References ast_frame::datalen.

00587 {
00588    return 240 * (frame->datalen / 50);
00589 }

static int lpc10_samples ( struct ast_frame frame  )  [static]

Definition at line 379 of file codec_builtin.c.

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

00380 {
00381    int samples = 22 * 8;
00382 
00383    /* assumes that the RTP packet contains one LPC10 frame */
00384    samples += (((char *)(frame->data.ptr))[7] & 0x1) * 8;
00385 
00386    return samples;
00387 }

static int none_length ( unsigned int  samples  )  [static]

Definition at line 112 of file codec_builtin.c.

00112                                              {
00113    return samples;
00114 }

static int none_samples ( struct ast_frame frame  )  [static]

Definition at line 107 of file codec_builtin.c.

References ast_frame::datalen.

00108 {
00109    return frame->datalen;
00110 }

static int siren14_length ( unsigned int  samples  )  [static]

Definition at line 646 of file codec_builtin.c.

00647 {
00648    return (int) samples / ((float) 32000 / 6000);;
00649 }

static int siren14_samples ( struct ast_frame frame  )  [static]

Definition at line 641 of file codec_builtin.c.

References ast_frame::datalen.

00642 {
00643    return (int) frame->datalen * ((float) 32000 / 6000);
00644 }

static int siren7_length ( unsigned int  samples  )  [static]

Definition at line 623 of file codec_builtin.c.

00624 {
00625    return samples / (16000 / 4000);
00626 }

static int siren7_samples ( struct ast_frame frame  )  [static]

Definition at line 618 of file codec_builtin.c.

References ast_frame::datalen.

00619 {
00620    return frame->datalen * (16000 / 4000);
00621 }

static int slin_length ( unsigned int  samples  )  [static]

Definition at line 248 of file codec_builtin.c.

00249 {
00250    return samples * 2;
00251 }

static int slin_samples ( struct ast_frame frame  )  [static]

Definition at line 243 of file codec_builtin.c.

References ast_frame::datalen.

00244 {
00245    return frame->datalen / 2;
00246 }

static int speex16_samples ( struct ast_frame frame  )  [static]

Definition at line 552 of file codec_builtin.c.

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

00553 {
00554    return 2 * speex_samples(frame->data.ptr, frame->datalen);
00555 }

static int speex32_samples ( struct ast_frame frame  )  [static]

Definition at line 569 of file codec_builtin.c.

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

00570 {
00571    return 4 * speex_samples(frame->data.ptr, frame->datalen);
00572 }

static int speex8_samples ( struct ast_frame frame  )  [static]

Definition at line 535 of file codec_builtin.c.

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

00536 {
00537    return speex_samples(frame->data.ptr, frame->datalen);
00538 }

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

Definition at line 445 of file codec_builtin.c.

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

Referenced by speex_samples().

00446 {
00447    static const int SpeexWBSubModeSz[] = {
00448       4, 36, 112, 192,
00449       352, 0, 0, 0 };
00450    int off = bit;
00451    unsigned char c;
00452 
00453    /* skip up to two wideband frames */
00454    if (((len * 8 - off) >= 5) &&
00455       get_n_bits_at(data, 1, off)) {
00456       c = get_n_bits_at(data, 3, off + 1);
00457       off += SpeexWBSubModeSz[c];
00458 
00459       if (((len * 8 - off) >= 5) &&
00460          get_n_bits_at(data, 1, off)) {
00461          c = get_n_bits_at(data, 3, off + 1);
00462          off += SpeexWBSubModeSz[c];
00463 
00464          if (((len * 8 - off) >= 5) &&
00465             get_n_bits_at(data, 1, off)) {
00466             ast_log(LOG_WARNING, "Encountered corrupt speex frame; too many wideband frames in a row.\n");
00467             return -1;
00468          }
00469       }
00470 
00471    }
00472    return off - bit;
00473 }

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

Definition at line 475 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().

00476 {
00477    static const int SpeexSubModeSz[] = {
00478       5, 43, 119, 160,
00479       220, 300, 364, 492,
00480       79, 0, 0, 0,
00481       0, 0, 0, 0 };
00482    static const int SpeexInBandSz[] = {
00483       1, 1, 4, 4,
00484       4, 4, 4, 4,
00485       8, 8, 16, 16,
00486       32, 32, 64, 64 };
00487    int bit = 0;
00488    int cnt = 0;
00489    int off;
00490    unsigned char c;
00491 
00492    while ((len * 8 - bit) >= 5) {
00493       /* skip wideband frames */
00494       off = speex_get_wb_sz_at(data, len, bit);
00495       if (off < 0)  {
00496          ast_log(LOG_WARNING, "Had error while reading wideband frames for speex samples\n");
00497          break;
00498       }
00499       bit += off;
00500 
00501       if ((len * 8 - bit) < 5)
00502          break;
00503 
00504       /* get control bits */
00505       c = get_n_bits_at(data, 5, bit);
00506       bit += 5;
00507 
00508       if (c == 15) {
00509          /* terminator */
00510          break;
00511       } else if (c == 14) {
00512          /* in-band signal; next 4 bits contain signal id */
00513          c = get_n_bits_at(data, 4, bit);
00514          bit += 4;
00515          bit += SpeexInBandSz[c];
00516       } else if (c == 13) {
00517          /* user in-band; next 4 bits contain msg len */
00518          c = get_n_bits_at(data, 4, bit);
00519          bit += 4;
00520          /* after which it's 5-bit signal id + c bytes of data */
00521          bit += 5 + c * 8;
00522       } else if (c > 8) {
00523          /* unknown */
00524          ast_log(LOG_WARNING, "Unknown speex control frame %d\n", c);
00525          break;
00526       } else {
00527          /* skip number bits for submode (less the 5 control bits) */
00528          bit += SpeexSubModeSz[c] - 5;
00529          cnt += 160; /* new frame */
00530       }
00531    }
00532    return cnt;
00533 }

static int ulaw_length ( unsigned int  samples  )  [static]

Definition at line 134 of file codec_builtin.c.

00135 {
00136    return samples;
00137 }

static int ulaw_samples ( struct ast_frame frame  )  [static]

Definition at line 129 of file codec_builtin.c.

References ast_frame::datalen.

00130 {
00131    return frame->datalen;
00132 }


Variable Documentation

struct ast_codec adpcm [static]

Definition at line 229 of file codec_builtin.c.

Referenced by lintoadpcm_frameout().

struct ast_codec alaw [static]

Definition at line 153 of file codec_builtin.c.

Referenced by AST_TEST_DEFINE().

struct ast_codec g719 [static]

Definition at line 688 of file codec_builtin.c.

struct ast_codec g722 [static]

Definition at line 604 of file codec_builtin.c.

struct ast_codec g723 [static]

Definition at line 94 of file codec_builtin.c.

struct ast_codec g726aal2 [static]

Definition at line 215 of file codec_builtin.c.

struct ast_codec g726rfc3551 [static]

Definition at line 201 of file codec_builtin.c.

struct ast_codec g729a [static]

Definition at line 412 of file codec_builtin.c.

struct ast_codec gsm [static]

Definition at line 177 of file codec_builtin.c.

struct ast_codec h261 [static]

Initial value:

 {
   .name = "h261",
   .description = "H.261 video",
   .type = AST_MEDIA_TYPE_VIDEO,
}

Definition at line 724 of file codec_builtin.c.

struct ast_codec h263 [static]

Initial value:

 {
   .name = "h263",
   .description = "H.263 video",
   .type = AST_MEDIA_TYPE_VIDEO,
}

Definition at line 730 of file codec_builtin.c.

Referenced by AST_TEST_DEFINE().

struct ast_codec h263p [static]

Initial value:

 {
   .name = "h263p",
   .description = "H.263+ video",
   .type = AST_MEDIA_TYPE_VIDEO,
}

Definition at line 736 of file codec_builtin.c.

struct ast_codec h264 [static]

Initial value:

 {
   .name = "h264",
   .description = "H.264 video",
   .type = AST_MEDIA_TYPE_VIDEO,
}

Definition at line 742 of file codec_builtin.c.

struct ast_codec ilbc [static]

Definition at line 591 of file codec_builtin.c.

struct ast_codec jpeg [static]

Initial value:

 {
   .name = "jpeg",
   .description = "JPEG image",
   .type = AST_MEDIA_TYPE_IMAGE,
}

Definition at line 712 of file codec_builtin.c.

struct ast_codec lpc10 [static]

Definition at line 389 of file codec_builtin.c.

struct ast_codec mpeg4 [static]

Initial value:

 {
   .name = "mpeg4",
   .description = "MPEG4 video",
   .type = AST_MEDIA_TYPE_VIDEO,
}

Definition at line 748 of file codec_builtin.c.

struct ast_codec none [static]

Definition at line 116 of file codec_builtin.c.

struct ast_codec opus [static]

Definition at line 701 of file codec_builtin.c.

struct ast_codec png [static]

Initial value:

 {
   .name = "png",
   .description = "PNG Image",
   .type = AST_MEDIA_TYPE_IMAGE,
}

Definition at line 718 of file codec_builtin.c.

struct ast_codec siren14 [static]

Definition at line 651 of file codec_builtin.c.

struct ast_codec siren7 [static]

Definition at line 628 of file codec_builtin.c.

struct ast_codec slin12 [static]

Definition at line 267 of file codec_builtin.c.

struct ast_codec slin16 [static]

Definition at line 281 of file codec_builtin.c.

struct ast_codec slin192 [static]

Definition at line 365 of file codec_builtin.c.

struct ast_codec slin24 [static]

Definition at line 295 of file codec_builtin.c.

struct ast_codec slin32 [static]

Definition at line 309 of file codec_builtin.c.

struct ast_codec slin44 [static]

Definition at line 323 of file codec_builtin.c.

struct ast_codec slin48 [static]

Definition at line 337 of file codec_builtin.c.

struct ast_codec slin8 [static]

Definition at line 253 of file codec_builtin.c.

struct ast_codec slin96 [static]

Definition at line 351 of file codec_builtin.c.

struct ast_codec speex16 [static]

Definition at line 557 of file codec_builtin.c.

struct ast_codec speex32 [static]

Definition at line 574 of file codec_builtin.c.

struct ast_codec speex8 [static]

Definition at line 540 of file codec_builtin.c.

struct ast_codec t140 [static]

Initial value:

 {
   .name = "t140",
   .description = "Passthrough T.140 Realtime Text",
   .type = AST_MEDIA_TYPE_TEXT,
}

Definition at line 766 of file codec_builtin.c.

struct ast_codec t140red [static]

Initial value:

 {
   .name = "red",
   .description = "T.140 Realtime Text with redundancy",
   .type = AST_MEDIA_TYPE_TEXT,
}

Definition at line 760 of file codec_builtin.c.

struct ast_codec testlaw [static]

Definition at line 664 of file codec_builtin.c.

struct ast_codec ulaw [static]

Definition at line 139 of file codec_builtin.c.

Referenced by AST_TEST_DEFINE().

struct ast_codec vp8 [static]

Initial value:

 {
   .name = "vp8",
   .description = "VP8 video",
   .type = AST_MEDIA_TYPE_VIDEO,
}

Definition at line 754 of file codec_builtin.c.


Generated on Thu Apr 16 06:30:14 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6