Thu Apr 28 2011 17:13:54

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"
Include dependency graph for codec_ilbc.c:

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
__MODULE_INFO_SECTION 
__mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "iLBC Coder/Decoder" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
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.

Referenced by ilbctolin_framein().

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

{
   struct ilbc_coder_pvt *tmp = pvt->pvt;
   int plc_mode = 1; /* 1 = normal data, 0 = plc */
   /* Assuming there's space left, decode into the current buffer at
      the tail location.  Read in as many frames as there are */
   int x,i;
   int16_t *dst = pvt->outbuf.i16;
   float tmpf[ILBC_SAMPLES];

   if (!f->data.ptr && f->datalen) {
      ast_log(LOG_DEBUG, "issue 16070, ILIB ERROR. data = NULL datalen = %d src = %s\n", f->datalen, f->src ? f->src : "no src set");
      f->datalen = 0;
   }

   if (f->datalen == 0) { /* native PLC, set fake f->datalen and clear plc_mode */
      f->datalen = ILBC_FRAME_LEN;
      f->samples = ILBC_SAMPLES;
      plc_mode = 0;  /* do native plc */
      pvt->samples += ILBC_SAMPLES;
   }

   if (f->datalen % ILBC_FRAME_LEN) {
      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);
      return -1;
   }
   
   for (x=0; x < f->datalen ; x += ILBC_FRAME_LEN) {
      if (pvt->samples + ILBC_SAMPLES > BUFFER_SAMPLES) {   
         ast_log(LOG_WARNING, "Out of buffer space\n");
         return -1;
      }     
      iLBC_decode(tmpf, plc_mode ? f->data.ptr + x : NULL, &tmp->dec, plc_mode);
      for ( i=0; i < ILBC_SAMPLES; i++)
         dst[pvt->samples + i] = tmpf[i];
      pvt->samples += ILBC_SAMPLES;
      pvt->datalen += 2*ILBC_SAMPLES;
   }
   return 0;
}
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.

{
   struct ilbc_coder_pvt *tmp = pvt->pvt;

   initDecode(&tmp->dec, ILBC_MS, USE_ILBC_ENHANCER);

   return 0;
}
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, ast_frame::data, ast_frame::datalen, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, and ast_trans_pvt::samples.

{
   struct ilbc_coder_pvt *tmp = pvt->pvt;

   /* Just add the frames to our stream */
   /* XXX We should look at how old the rest of our stream is, and if it
      is too old, then we should overwrite it entirely, otherwise we can
      get artifacts of earlier talk that do not belong */
   memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen);
   pvt->samples += f->samples;
   return 0;
}
static struct ast_frame* lintoilbc_frameout ( struct ast_trans_pvt pvt) [static, read]

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.

{
   struct ilbc_coder_pvt *tmp = pvt->pvt;
   int datalen = 0;
   int samples = 0;

   /* We can't work on anything less than a frame in size */
   if (pvt->samples < ILBC_SAMPLES)
      return NULL;
   while (pvt->samples >= ILBC_SAMPLES) {
      float tmpf[ILBC_SAMPLES];
      int i;

      /* Encode a frame of data */
      for (i = 0 ; i < ILBC_SAMPLES ; i++)
         tmpf[i] = tmp->buf[samples + i];
      iLBC_encode( pvt->outbuf.uc + datalen, tmpf, &tmp->enc);

      datalen += ILBC_FRAME_LEN;
      samples += ILBC_SAMPLES;
      pvt->samples -= ILBC_SAMPLES;
   }

   /* Move the data at the end of the buffer to the front */
   if (pvt->samples)
      memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);

   return ast_trans_frameout(pvt, datalen, samples);
}
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.

{
   struct ilbc_coder_pvt *tmp = pvt->pvt;

   initEncode(&tmp->enc, ILBC_MS);

   return 0;
}
static int load_module ( void  ) [static]
static int unload_module ( void  ) [static]

Definition at line 191 of file codec_ilbc.c.

References ast_unregister_translator().

{
   int res;

   res = ast_unregister_translator(&lintoilbc);
   res |= ast_unregister_translator(&ilbctolin);

   return res;
}

Variable Documentation

struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "iLBC Coder/Decoder" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 215 of file codec_ilbc.c.

Definition at line 215 of file codec_ilbc.c.

struct ast_translator ilbctolin [static]

Definition at line 167 of file codec_ilbc.c.

struct ast_translator lintoilbc [static]

Definition at line 179 of file codec_ilbc.c.