codec_ilbc.c File Reference

Translate between signed linear and Internet Low Bitrate Codec. More...

#include "asterisk.h"
#include "asterisk/translate.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "ilbc/iLBC_encode.h"
#include "ilbc/iLBC_decode.h"
#include "asterisk/slin.h"
#include "ex_ilbc.h"

Include dependency graph for codec_ilbc.c:

Go to the source code of this file.

Data Structures

struct  ilbc_coder_pvt

Defines

#define BUF_TYPE   uc
#define BUFFER_SAMPLES   8000
#define ILBC_FRAME_LEN   50
#define ILBC_MS   30
#define ILBC_SAMPLES   240
#define USE_ILBC_ENHANCER   0

Typedefs

typedef float ilbc_block
typedef unsigned char ilbc_bytes

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int ilbctolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 decode a frame and store in outbuf
static int ilbctolin_new (struct ast_trans_pvt *pvt)
static int lintoilbc_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 store a frame into a temporary buffer, for later decoding
static struct ast_framelintoilbc_frameout (struct ast_trans_pvt *pvt)
 encode the temporary buffer and generate a frame
static int lintoilbc_new (struct ast_trans_pvt *pvt)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "iLBC Coder/Decoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_translator ilbctolin
static struct ast_translator lintoilbc


Detailed Description

Translate between signed linear and Internet Low Bitrate Codec.

Definition in file codec_ilbc.c.


Define Documentation

#define BUF_TYPE   uc

Definition at line 51 of file codec_ilbc.c.

#define BUFFER_SAMPLES   8000

Definition at line 60 of file codec_ilbc.c.

#define ILBC_FRAME_LEN   50

Definition at line 58 of file codec_ilbc.c.

Referenced by ilbctolin_framein(), and lintoilbc_frameout().

#define ILBC_MS   30

Definition at line 55 of file codec_ilbc.c.

Referenced by ilbctolin_new(), and lintoilbc_new().

#define ILBC_SAMPLES   240

#define USE_ILBC_ENHANCER   0

Definition at line 54 of file codec_ilbc.c.

Referenced by ilbctolin_new().


Typedef Documentation

typedef float ilbc_block

Definition at line 50 of file codec_ilbc.c.

typedef unsigned char ilbc_bytes

Definition at line 49 of file codec_ilbc.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 247 of file codec_ilbc.c.

static void __unreg_module ( void   )  [static]

Definition at line 247 of file codec_ilbc.c.

static int ilbctolin_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
) [static]

decode a frame and store in outbuf

Definition at line 92 of file codec_ilbc.c.

References ast_debug, ast_log, BUFFER_SAMPLES, ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, ilbc_coder_pvt::dec, ast_trans_pvt::i16, iLBC_decode(), ILBC_FRAME_LEN, ILBC_SAMPLES, LOG_WARNING, NULL, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, ast_frame::samples, ast_frame::src, and tmp().

00093 {
00094    struct ilbc_coder_pvt *tmp = pvt->pvt;
00095    int plc_mode = 1; /* 1 = normal data, 0 = plc */
00096    /* Assuming there's space left, decode into the current buffer at
00097       the tail location.  Read in as many frames as there are */
00098    int x,i;
00099    int datalen = f->datalen;
00100    int16_t *dst = pvt->outbuf.i16;
00101    ilbc_block tmpf[ILBC_SAMPLES];
00102 
00103    if (!f->data.ptr && datalen) {
00104       ast_debug(1, "issue 16070, ILIB ERROR. data = NULL datalen = %d src = %s\n", datalen, f->src ? f->src : "no src set");
00105       f->datalen = 0;
00106       datalen = 0;
00107    }
00108 
00109    if (datalen == 0) { /* native PLC, set fake datalen and clear plc_mode */
00110       datalen = ILBC_FRAME_LEN;
00111       f->samples = ILBC_SAMPLES;
00112       plc_mode = 0;  /* do native plc */
00113       pvt->samples += ILBC_SAMPLES;
00114    }
00115 
00116    if (datalen % ILBC_FRAME_LEN) {
00117       ast_log(LOG_WARNING, "Huh?  An ilbc frame that isn't a multiple of 50 bytes long from %s (%d)?\n", f->src, datalen);
00118       return -1;
00119    }
00120 
00121    for (x=0; x < datalen ; x += ILBC_FRAME_LEN) {
00122       if (pvt->samples + ILBC_SAMPLES > BUFFER_SAMPLES) {
00123          ast_log(LOG_WARNING, "Out of buffer space\n");
00124          return -1;
00125       }
00126       iLBC_decode(tmpf, plc_mode ? f->data.ptr + x : NULL, &tmp->dec, plc_mode);
00127       for ( i=0; i < ILBC_SAMPLES; i++)
00128          dst[pvt->samples + i] = tmpf[i];
00129       pvt->samples += ILBC_SAMPLES;
00130       pvt->datalen += 2*ILBC_SAMPLES;
00131    }
00132    return 0;
00133 }

static int ilbctolin_new ( struct ast_trans_pvt pvt  )  [static]

Definition at line 82 of file codec_ilbc.c.

References ilbc_coder_pvt::dec, ILBC_MS, initDecode(), ast_trans_pvt::pvt, tmp(), and USE_ILBC_ENHANCER.

00083 {
00084    struct ilbc_coder_pvt *tmp = pvt->pvt;
00085 
00086    initDecode(&tmp->dec, ILBC_MS, USE_ILBC_ENHANCER);
00087 
00088    return 0;
00089 }

static int lintoilbc_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
) [static]

store a frame into a temporary buffer, for later decoding

Definition at line 136 of file codec_ilbc.c.

References ilbc_coder_pvt::buf, ast_frame::data, ast_frame::datalen, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, ast_trans_pvt::samples, and tmp().

00137 {
00138    struct ilbc_coder_pvt *tmp = pvt->pvt;
00139 
00140    /* Just add the frames to our stream */
00141    /* XXX We should look at how old the rest of our stream is, and if it
00142       is too old, then we should overwrite it entirely, otherwise we can
00143       get artifacts of earlier talk that do not belong */
00144    memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen);
00145    pvt->samples += f->samples;
00146    return 0;
00147 }

static struct ast_frame* lintoilbc_frameout ( struct ast_trans_pvt pvt  )  [static, read]

encode the temporary buffer and generate a frame

Definition at line 150 of file codec_ilbc.c.

References ast_trans_frameout(), ilbc_coder_pvt::buf, ilbc_coder_pvt::enc, iLBC_encode(), ILBC_FRAME_LEN, ILBC_SAMPLES, NULL, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, ast_trans_pvt::samples, and tmp().

00151 {
00152    struct ilbc_coder_pvt *tmp = pvt->pvt;
00153    int datalen = 0;
00154    int samples = 0;
00155 
00156    /* We can't work on anything less than a frame in size */
00157    if (pvt->samples < ILBC_SAMPLES)
00158       return NULL;
00159    while (pvt->samples >= ILBC_SAMPLES) {
00160       ilbc_block tmpf[ILBC_SAMPLES];
00161       int i;
00162 
00163       /* Encode a frame of data */
00164       for (i = 0 ; i < ILBC_SAMPLES ; i++)
00165          tmpf[i] = tmp->buf[samples + i];
00166       iLBC_encode( (ilbc_bytes*)pvt->outbuf.BUF_TYPE + datalen, tmpf, &tmp->enc);
00167 
00168       datalen += ILBC_FRAME_LEN;
00169       samples += ILBC_SAMPLES;
00170       pvt->samples -= ILBC_SAMPLES;
00171    }
00172 
00173    /* Move the data at the end of the buffer to the front */
00174    if (pvt->samples)
00175       memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
00176 
00177    return ast_trans_frameout(pvt, datalen, samples);
00178 }

static int lintoilbc_new ( struct ast_trans_pvt pvt  )  [static]

Definition at line 73 of file codec_ilbc.c.

References ilbc_coder_pvt::enc, ILBC_MS, initEncode(), ast_trans_pvt::pvt, and tmp().

00074 {
00075    struct ilbc_coder_pvt *tmp = pvt->pvt;
00076 
00077    initEncode(&tmp->enc, ILBC_MS);
00078 
00079    return 0;
00080 }

static int load_module ( void   )  [static]

Definition at line 232 of file codec_ilbc.c.

References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, and unload_module.

00233 {
00234    int res;
00235 
00236    res = ast_register_translator(&ilbctolin);
00237    res |= ast_register_translator(&lintoilbc);
00238 
00239    if (res) {
00240       unload_module();
00241       return AST_MODULE_LOAD_FAILURE;
00242    }
00243 
00244    return AST_MODULE_LOAD_SUCCESS;
00245 }

static int unload_module ( void   )  [static]

Definition at line 222 of file codec_ilbc.c.

References ast_unregister_translator().

00223 {
00224    int res;
00225 
00226    res = ast_unregister_translator(&lintoilbc);
00227    res |= ast_unregister_translator(&ilbctolin);
00228 
00229    return res;
00230 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "iLBC Coder/Decoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 247 of file codec_ilbc.c.

Definition at line 247 of file codec_ilbc.c.

struct ast_translator ilbctolin [static]

Definition at line 180 of file codec_ilbc.c.

struct ast_translator lintoilbc [static]

Definition at line 201 of file codec_ilbc.c.


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