Wed Jan 8 2020 09:50:10

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
 

Macros

#define BUFFER_SAMPLES   8000
 
#define ILBC_FRAME_LEN   50 /* apparently... */
 
#define ILBC_MS   30
 
#define ILBC_SAMPLES   240 /* 30ms at 8000 hz */
 
#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 More...
 
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 More...
 
static struct ast_framelintoilbc_frameout (struct ast_trans_pvt *pvt)
 encode the temporary buffer and generate a frame More...
 
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 = "ac1f6a56484a8820659555499174e588" , .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.

Macro Definition Documentation

#define BUFFER_SAMPLES   8000

Definition at line 49 of file codec_ilbc.c.

Referenced by ilbctolin_framein().

#define ILBC_FRAME_LEN   50 /* apparently... */

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 /* 30ms at 8000 hz */

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

static void __unreg_module ( void  )
static

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

82 {
83  struct ilbc_coder_pvt *tmp = pvt->pvt;
84  int plc_mode = 1; /* 1 = normal data, 0 = plc */
85  /* Assuming there's space left, decode into the current buffer at
86  the tail location. Read in as many frames as there are */
87  int x,i;
88  int datalen = f->datalen;
89  int16_t *dst = pvt->outbuf.i16;
90  float tmpf[ILBC_SAMPLES];
91 
92  if (!f->data.ptr && datalen) {
93  ast_log(LOG_DEBUG, "issue 16070, ILIB ERROR. data = NULL datalen = %d src = %s\n", datalen, f->src ? f->src : "no src set");
94  f->datalen = 0;
95  datalen = 0;
96  }
97 
98  if (datalen == 0) { /* native PLC, set fake datalen and clear plc_mode */
99  datalen = ILBC_FRAME_LEN;
100  f->samples = ILBC_SAMPLES;
101  plc_mode = 0; /* do native plc */
102  pvt->samples += ILBC_SAMPLES;
103  }
104 
105  if (datalen % ILBC_FRAME_LEN) {
106  ast_log(LOG_WARNING, "Huh? An ilbc frame that isn't a multiple of 50 bytes long from %s (%d)?\n", f->src, datalen);
107  return -1;
108  }
109 
110  for (x=0; x < datalen ; x += ILBC_FRAME_LEN) {
111  if (pvt->samples + ILBC_SAMPLES > BUFFER_SAMPLES) {
112  ast_log(LOG_WARNING, "Out of buffer space\n");
113  return -1;
114  }
115  iLBC_decode(tmpf, plc_mode ? f->data.ptr + x : NULL, &tmp->dec, plc_mode);
116  for ( i=0; i < ILBC_SAMPLES; i++)
117  dst[pvt->samples + i] = tmpf[i];
118  pvt->samples += ILBC_SAMPLES;
119  pvt->datalen += 2*ILBC_SAMPLES;
120  }
121  return 0;
122 }
int datalen
actual space used in outbuf
Definition: translate.h:140
union ast_trans_pvt::@213 outbuf
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
void * pvt
Definition: translate.h:141
#define LOG_DEBUG
Definition: logger.h:122
int16_t * i16
Definition: translate.h:145
const char * src
Definition: frame.h:158
#define ILBC_SAMPLES
Definition: codec_ilbc.c:48
int datalen
Definition: frame.h:148
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ILBC_FRAME_LEN
Definition: codec_ilbc.c:47
iLBC_Dec_Inst_t dec
Definition: codec_ilbc.c:57
#define BUFFER_SAMPLES
Definition: codec_ilbc.c:49
union ast_frame::@172 data
int samples
Definition: frame.h:150
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.

72 {
73  struct ilbc_coder_pvt *tmp = pvt->pvt;
74 
75  initDecode(&tmp->dec, ILBC_MS, USE_ILBC_ENHANCER);
76 
77  return 0;
78 }
void * pvt
Definition: translate.h:141
#define ILBC_MS
Definition: codec_ilbc.c:44
iLBC_Dec_Inst_t dec
Definition: codec_ilbc.c:57
#define USE_ILBC_ENHANCER
Definition: codec_ilbc.c:43
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_trans_pvt::samples, and ast_frame::samples.

126 {
127  struct ilbc_coder_pvt *tmp = pvt->pvt;
128 
129  /* Just add the frames to our stream */
130  /* XXX We should look at how old the rest of our stream is, and if it
131  is too old, then we should overwrite it entirely, otherwise we can
132  get artifacts of earlier talk that do not belong */
133  memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen);
134  pvt->samples += f->samples;
135  return 0;
136 }
void * ptr
Definition: frame.h:160
void * pvt
Definition: translate.h:141
int datalen
Definition: frame.h:148
int16_t buf[BUFFER_SAMPLES]
Definition: codec_ilbc.c:59
union ast_frame::@172 data
int samples
Definition: frame.h:150
static struct ast_frame* lintoilbc_frameout ( struct ast_trans_pvt pvt)
static

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.

140 {
141  struct ilbc_coder_pvt *tmp = pvt->pvt;
142  int datalen = 0;
143  int samples = 0;
144 
145  /* We can't work on anything less than a frame in size */
146  if (pvt->samples < ILBC_SAMPLES)
147  return NULL;
148  while (pvt->samples >= ILBC_SAMPLES) {
149  float tmpf[ILBC_SAMPLES];
150  int i;
151 
152  /* Encode a frame of data */
153  for (i = 0 ; i < ILBC_SAMPLES ; i++)
154  tmpf[i] = tmp->buf[samples + i];
155  iLBC_encode( pvt->outbuf.uc + datalen, tmpf, &tmp->enc);
156 
157  datalen += ILBC_FRAME_LEN;
158  samples += ILBC_SAMPLES;
159  pvt->samples -= ILBC_SAMPLES;
160  }
161 
162  /* Move the data at the end of the buffer to the front */
163  if (pvt->samples)
164  memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
165 
166  return ast_trans_frameout(pvt, datalen, samples);
167 }
struct ast_frame * ast_trans_frameout(struct ast_trans_pvt *pvt, int datalen, int samples)
generic frameout function
Definition: translate.c:235
union ast_trans_pvt::@213 outbuf
iLBC_Enc_Inst_t enc
Definition: codec_ilbc.c:56
unsigned char * uc
Definition: translate.h:144
void * pvt
Definition: translate.h:141
#define ILBC_SAMPLES
Definition: codec_ilbc.c:48
int16_t buf[BUFFER_SAMPLES]
Definition: codec_ilbc.c:59
#define ILBC_FRAME_LEN
Definition: codec_ilbc.c:47
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.

63 {
64  struct ilbc_coder_pvt *tmp = pvt->pvt;
65 
66  initEncode(&tmp->enc, ILBC_MS);
67 
68  return 0;
69 }
iLBC_Enc_Inst_t enc
Definition: codec_ilbc.c:56
void * pvt
Definition: translate.h:141
#define ILBC_MS
Definition: codec_ilbc.c:44
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().

204 {
205  int res;
206 
208  if (!res)
210  else
212  if (res)
215 }
static struct ast_translator ilbctolin
Definition: codec_ilbc.c:169
static struct ast_translator lintoilbc
Definition: codec_ilbc.c:181
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:170
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
Definition: translate.c:942
static int unload_module ( void  )
static

Definition at line 193 of file codec_ilbc.c.

References ast_unregister_translator().

194 {
195  int res;
196 
199 
200  return res;
201 }
static struct ast_translator ilbctolin
Definition: codec_ilbc.c:169
static struct ast_translator lintoilbc
Definition: codec_ilbc.c:181
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
Definition: translate.c:942

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

Definition at line 217 of file codec_ilbc.c.

Definition at line 217 of file codec_ilbc.c.

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.