Wed Jan 27 20:02:36 2016

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

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"iLBC Coder/Decoder")
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_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
#define USE_ILBC_ENHANCER   0

Definition at line 43 of file codec_ilbc.c.

Referenced by ilbctolin_new().


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"iLBC Coder/Decoder"   
)
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_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, ilbc_coder_pvt::dec, ast_trans_pvt::i16, ILBC_FRAME_LEN, ILBC_SAMPLES, LOG_DEBUG, LOG_WARNING, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, ast_frame::samples, and ast_frame::src.

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    int datalen = f->datalen;
00089    int16_t *dst = pvt->outbuf.i16;
00090    float tmpf[ILBC_SAMPLES];
00091 
00092    if (!f->data.ptr && datalen) {
00093       ast_log(LOG_DEBUG, "issue 16070, ILIB ERROR. data = NULL datalen = %d src = %s\n", datalen, f->src ? f->src : "no src set");
00094       f->datalen = 0;
00095       datalen = 0;
00096    }
00097 
00098    if (datalen == 0) { /* native PLC, set fake datalen and clear plc_mode */
00099       datalen = ILBC_FRAME_LEN;
00100       f->samples = ILBC_SAMPLES;
00101       plc_mode = 0;  /* do native plc */
00102       pvt->samples += ILBC_SAMPLES;
00103    }
00104 
00105    if (datalen % ILBC_FRAME_LEN) {
00106       ast_log(LOG_WARNING, "Huh?  An ilbc frame that isn't a multiple of 50 bytes long from %s (%d)?\n", f->src, datalen);
00107       return -1;
00108    }
00109    
00110    for (x=0; x < datalen ; x += ILBC_FRAME_LEN) {
00111       if (pvt->samples + ILBC_SAMPLES > BUFFER_SAMPLES) {   
00112          ast_log(LOG_WARNING, "Out of buffer space\n");
00113          return -1;
00114       }     
00115       iLBC_decode(tmpf, plc_mode ? f->data.ptr + x : NULL, &tmp->dec, plc_mode);
00116       for ( i=0; i < ILBC_SAMPLES; i++)
00117          dst[pvt->samples + i] = tmpf[i];
00118       pvt->samples += ILBC_SAMPLES;
00119       pvt->datalen += 2*ILBC_SAMPLES;
00120    }
00121    return 0;
00122 }

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 125 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, and ast_trans_pvt::samples.

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

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

encode the temporary buffer and generate a frame

Definition at line 139 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.

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

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

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

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

static int unload_module ( void   )  [static]

Definition at line 193 of file codec_ilbc.c.

References ast_unregister_translator().

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


Variable Documentation

struct ast_translator ilbctolin [static]

Definition at line 169 of file codec_ilbc.c.

struct ast_translator lintoilbc [static]

Definition at line 181 of file codec_ilbc.c.


Generated on 27 Jan 2016 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1