Mon Mar 19 11:30:46 2012

Asterisk developer's documentation


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"

Go to the source code of this file.

Data Structures

struct  ilbc_coder_pvt

Defines

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

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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
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 BUFFER_SAMPLES   8000

Definition at line 49 of file codec_ilbc.c.

#define ILBC_FRAME_LEN   50

Definition at line 47 of file codec_ilbc.c.

Referenced by ilbctolin_framein(), and lintoilbc_frameout().

#define ILBC_MS   30

Definition at line 44 of file codec_ilbc.c.

Referenced by ilbctolin_new(), and lintoilbc_new().

#define ILBC_SAMPLES   240

Definition at line 48 of file codec_ilbc.c.

Referenced by ilbc_read(), ilbc_sample(), ilbc_seek(), ilbc_tell(), ilbctolin_framein(), and lintoilbc_frameout().

#define USE_ILBC_ENHANCER   0

Definition at line 43 of file codec_ilbc.c.

Referenced by ilbctolin_new().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 215 of file codec_ilbc.c.

static void __unreg_module ( void   )  [static]

Definition at line 215 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 81 of file codec_ilbc.c.

References ast_log(), BUFFER_SAMPLES, ast_trans_pvt::datalen, ilbc_coder_pvt::dec, f, ast_trans_pvt::i16, ILBC_FRAME_LEN, ILBC_SAMPLES, LOG_DEBUG, LOG_WARNING, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.

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

static int ilbctolin_new ( struct ast_trans_pvt pvt  )  [static]

Definition at line 71 of file codec_ilbc.c.

References ilbc_coder_pvt::dec, ILBC_MS, ast_trans_pvt::pvt, and USE_ILBC_ENHANCER.

00072 {
00073    struct ilbc_coder_pvt *tmp = pvt->pvt;
00074 
00075    initDecode(&tmp->dec, ILBC_MS, USE_ILBC_ENHANCER);
00076 
00077    return 0;
00078 }

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 123 of file codec_ilbc.c.

References ilbc_coder_pvt::buf, f, ast_trans_pvt::pvt, and ast_trans_pvt::samples.

00124 {
00125    struct ilbc_coder_pvt *tmp = pvt->pvt;
00126 
00127    /* Just add the frames to our stream */
00128    /* XXX We should look at how old the rest of our stream is, and if it
00129       is too old, then we should overwrite it entirely, otherwise we can
00130       get artifacts of earlier talk that do not belong */
00131    memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen);
00132    pvt->samples += f->samples;
00133    return 0;
00134 }

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

encode the temporary buffer and generate a frame

Definition at line 137 of file codec_ilbc.c.

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

00138 {
00139    struct ilbc_coder_pvt *tmp = pvt->pvt;
00140    int datalen = 0;
00141    int samples = 0;
00142 
00143    /* We can't work on anything less than a frame in size */
00144    if (pvt->samples < ILBC_SAMPLES)
00145       return NULL;
00146    while (pvt->samples >= ILBC_SAMPLES) {
00147       float tmpf[ILBC_SAMPLES];
00148       int i;
00149 
00150       /* Encode a frame of data */
00151       for (i = 0 ; i < ILBC_SAMPLES ; i++)
00152          tmpf[i] = tmp->buf[samples + i];
00153       iLBC_encode( pvt->outbuf.uc + datalen, tmpf, &tmp->enc);
00154 
00155       datalen += ILBC_FRAME_LEN;
00156       samples += ILBC_SAMPLES;
00157       pvt->samples -= ILBC_SAMPLES;
00158    }
00159 
00160    /* Move the data at the end of the buffer to the front */
00161    if (pvt->samples)
00162       memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
00163 
00164    return ast_trans_frameout(pvt, datalen, samples);
00165 }

static int lintoilbc_new ( struct ast_trans_pvt pvt  )  [static]

Definition at line 62 of file codec_ilbc.c.

References ilbc_coder_pvt::enc, ILBC_MS, and ast_trans_pvt::pvt.

00063 {
00064    struct ilbc_coder_pvt *tmp = pvt->pvt;
00065 
00066    initEncode(&tmp->enc, ILBC_MS);
00067 
00068    return 0;
00069 }

static int load_module ( void   )  [static]

Definition at line 201 of file codec_ilbc.c.

References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, ast_unregister_translator(), ilbctolin, and lintoilbc.

00202 {
00203    int res;
00204 
00205    res = ast_register_translator(&ilbctolin);
00206    if (!res) 
00207       res=ast_register_translator(&lintoilbc);
00208    else
00209       ast_unregister_translator(&ilbctolin);
00210    if (res)
00211       return AST_MODULE_LOAD_FAILURE;
00212    return AST_MODULE_LOAD_SUCCESS;
00213 }

static int unload_module ( void   )  [static]

Definition at line 191 of file codec_ilbc.c.

References ast_unregister_translator(), ilbctolin, and lintoilbc.

00192 {
00193    int res;
00194 
00195    res = ast_unregister_translator(&lintoilbc);
00196    res |= ast_unregister_translator(&ilbctolin);
00197 
00198    return res;
00199 }


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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 215 of file codec_ilbc.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 215 of file codec_ilbc.c.

struct ast_translator ilbctolin [static]

Definition at line 167 of file codec_ilbc.c.

Referenced by load_module(), and unload_module().

struct ast_translator lintoilbc [static]

Definition at line 179 of file codec_ilbc.c.

Referenced by load_module(), and unload_module().


Generated on Mon Mar 19 11:30:46 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7