#include "asterisk.h"
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include "asterisk/lock.h"
#include "asterisk/translate.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include "ilbc/iLBC_encode.h"
#include "ilbc/iLBC_decode.h"
#include "slin_ilbc_ex.h"
#include "ilbc_slin_ex.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 1 |
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 struct ast_frame * | ilbctolin_sample (void) |
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_frame * | lintoilbc_frameout (struct ast_trans_pvt *pvt) |
encode the temporary buffer and generate a frame | |
static int | lintoilbc_new (struct ast_trans_pvt *pvt) |
static struct ast_frame * | lintoilbc_sample (void) |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_translator | ilbctolin |
static struct ast_translator | lintoilbc |
Definition in file codec_ilbc.c.
#define BUFFER_SAMPLES 8000 |
Definition at line 59 of file codec_ilbc.c.
#define ILBC_FRAME_LEN 50 |
Definition at line 57 of file codec_ilbc.c.
Referenced by ilbctolin_framein(), and lintoilbc_frameout().
#define ILBC_MS 30 |
#define ILBC_SAMPLES 240 |
Definition at line 58 of file codec_ilbc.c.
Referenced by ilbc_read(), ilbc_seek(), ilbc_tell(), ilbctolin_framein(), ilbctolin_sample(), and lintoilbc_frameout().
#define USE_ILBC_ENHANCER 1 |
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 116 of file codec_ilbc.c.
References ast_log(), BUFFER_SAMPLES, ast_trans_pvt::datalen, ilbc_coder_pvt::dec, f, ILBC_FRAME_LEN, ILBC_SAMPLES, LOG_WARNING, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00117 { 00118 struct ilbc_coder_pvt *tmp = pvt->pvt; 00119 int plc_mode = 1; /* 1 = normal data, 0 = plc */ 00120 /* Assuming there's space left, decode into the current buffer at 00121 the tail location. Read in as many frames as there are */ 00122 int x,i; 00123 int16_t *dst = (int16_t *)pvt->outbuf; 00124 float tmpf[ILBC_SAMPLES]; 00125 00126 if (f->datalen == 0) { /* native PLC, set fake f->datalen and clear plc_mode */ 00127 f->datalen = ILBC_FRAME_LEN; 00128 f->samples = ILBC_SAMPLES; 00129 plc_mode = 0; /* do native plc */ 00130 pvt->samples += ILBC_SAMPLES; 00131 } 00132 00133 if (f->datalen % ILBC_FRAME_LEN) { 00134 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); 00135 return -1; 00136 } 00137 00138 for (x=0; x < f->datalen ; x += ILBC_FRAME_LEN) { 00139 if (pvt->samples + ILBC_SAMPLES > BUFFER_SAMPLES) { 00140 ast_log(LOG_WARNING, "Out of buffer space\n"); 00141 return -1; 00142 } 00143 iLBC_decode(tmpf, plc_mode ? f->data + x : NULL, &tmp->dec, plc_mode); 00144 for ( i=0; i < ILBC_SAMPLES; i++) 00145 dst[pvt->samples + i] = tmpf[i]; 00146 pvt->samples += ILBC_SAMPLES; 00147 pvt->datalen += 2*ILBC_SAMPLES; 00148 } 00149 return 0; 00150 }
static int ilbctolin_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 77 of file codec_ilbc.c.
References ilbc_coder_pvt::dec, ILBC_MS, ast_trans_pvt::pvt, and USE_ILBC_ENHANCER.
00078 { 00079 struct ilbc_coder_pvt *tmp = pvt->pvt; 00080 00081 initDecode(&tmp->dec, ILBC_MS, USE_ILBC_ENHANCER); 00082 00083 return 0; 00084 }
static struct ast_frame* ilbctolin_sample | ( | void | ) | [static] |
Definition at line 100 of file codec_ilbc.c.
References AST_FORMAT_ILBC, AST_FRAME_VOICE, f, ILBC_SAMPLES, and ilbc_slin_ex.
00101 { 00102 static struct ast_frame f; 00103 f.frametype = AST_FRAME_VOICE; 00104 f.subclass = AST_FORMAT_ILBC; 00105 f.datalen = sizeof(ilbc_slin_ex); 00106 /* All frames are 30 ms long */ 00107 f.samples = ILBC_SAMPLES; 00108 f.mallocd = 0; 00109 f.offset = 0; 00110 f.src = __PRETTY_FUNCTION__; 00111 f.data = ilbc_slin_ex; 00112 return &f; 00113 }
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 153 of file codec_ilbc.c.
References ilbc_coder_pvt::buf, f, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00154 { 00155 struct ilbc_coder_pvt *tmp = pvt->pvt; 00156 00157 /* Just add the frames to our stream */ 00158 /* XXX We should look at how old the rest of our stream is, and if it 00159 is too old, then we should overwrite it entirely, otherwise we can 00160 get artifacts of earlier talk that do not belong */ 00161 memcpy(tmp->buf + pvt->samples, f->data, f->datalen); 00162 pvt->samples += f->samples; 00163 return 0; 00164 }
static struct ast_frame* lintoilbc_frameout | ( | struct ast_trans_pvt * | pvt | ) | [static] |
encode the temporary buffer and generate a frame
Definition at line 167 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, and ast_trans_pvt::samples.
00168 { 00169 struct ilbc_coder_pvt *tmp = pvt->pvt; 00170 int datalen = 0; 00171 int samples = 0; 00172 00173 /* We can't work on anything less than a frame in size */ 00174 if (pvt->samples < ILBC_SAMPLES) 00175 return NULL; 00176 while (pvt->samples >= ILBC_SAMPLES) { 00177 float tmpf[ILBC_SAMPLES]; 00178 int i; 00179 00180 /* Encode a frame of data */ 00181 for (i = 0 ; i < ILBC_SAMPLES ; i++) 00182 tmpf[i] = tmp->buf[samples + i]; 00183 iLBC_encode((unsigned char *) pvt->outbuf + datalen, tmpf, &tmp->enc); 00184 00185 datalen += ILBC_FRAME_LEN; 00186 samples += ILBC_SAMPLES; 00187 pvt->samples -= ILBC_SAMPLES; 00188 } 00189 00190 /* Move the data at the end of the buffer to the front */ 00191 if (pvt->samples) 00192 memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2); 00193 00194 return ast_trans_frameout(pvt, datalen, samples); 00195 }
static int lintoilbc_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 68 of file codec_ilbc.c.
References ilbc_coder_pvt::enc, ILBC_MS, and ast_trans_pvt::pvt.
00069 { 00070 struct ilbc_coder_pvt *tmp = pvt->pvt; 00071 00072 initEncode(&tmp->enc, ILBC_MS); 00073 00074 return 0; 00075 }
static struct ast_frame* lintoilbc_sample | ( | void | ) | [static] |
Definition at line 86 of file codec_ilbc.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, and slin_ilbc_ex.
00087 { 00088 static struct ast_frame f; 00089 f.frametype = AST_FRAME_VOICE; 00090 f.subclass = AST_FORMAT_SLINEAR; 00091 f.datalen = sizeof(slin_ilbc_ex); 00092 f.samples = sizeof(slin_ilbc_ex)/2; 00093 f.mallocd = 0; 00094 f.offset = 0; 00095 f.src = __PRETTY_FUNCTION__; 00096 f.data = slin_ilbc_ex; 00097 return &f; 00098 }
static int load_module | ( | void | ) | [static] |
Definition at line 230 of file codec_ilbc.c.
References ast_register_translator, ast_unregister_translator(), ilbctolin, and lintoilbc.
00231 { 00232 int res; 00233 00234 res = ast_register_translator(&ilbctolin); 00235 if (!res) 00236 res=ast_register_translator(&lintoilbc); 00237 else 00238 ast_unregister_translator(&ilbctolin); 00239 00240 return res; 00241 }
static int unload_module | ( | void | ) | [static] |
Definition at line 220 of file codec_ilbc.c.
References ast_unregister_translator(), ilbctolin, and lintoilbc.
00221 { 00222 int res; 00223 00224 res = ast_unregister_translator(&lintoilbc); 00225 res |= ast_unregister_translator(&ilbctolin); 00226 00227 return res; 00228 }
struct ast_translator ilbctolin [static] |
struct ast_translator lintoilbc [static] |