#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"
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 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_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_translator | ilbctolin |
static struct ast_translator | lintoilbc |
Definition in file codec_ilbc.c.
#define BUFFER_SAMPLES 8000 |
Definition at line 63 of file codec_ilbc.c.
#define ILBC_FRAME_LEN 50 |
Definition at line 61 of file codec_ilbc.c.
Referenced by ilbctolin_framein(), and lintoilbc_frameout().
#define ILBC_MS 30 |
#define ILBC_SAMPLES 240 |
Definition at line 62 of file codec_ilbc.c.
Referenced by ilbc_read(), ilbc_seek(), ilbc_tell(), ilbctolin_framein(), ilbctolin_sample(), and lintoilbc_frameout().
#define USE_ILBC_ENHANCER 0 |
static void __reg_module | ( | void | ) | [static] |
Definition at line 253 of file codec_ilbc.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 253 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 120 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_DEBUG, LOG_WARNING, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00121 { 00122 struct ilbc_coder_pvt *tmp = pvt->pvt; 00123 int plc_mode = 1; /* 1 = normal data, 0 = plc */ 00124 /* Assuming there's space left, decode into the current buffer at 00125 the tail location. Read in as many frames as there are */ 00126 int x,i; 00127 int16_t *dst = (int16_t *)pvt->outbuf; 00128 float tmpf[ILBC_SAMPLES]; 00129 00130 if (!f->data && f->datalen) { 00131 ast_log(LOG_DEBUG, "issue 16070, ILIB ERROR. data = NULL datalen = %d src = %s\n", f->datalen, f->src ? f->src : "no src set"); 00132 f->datalen = 0; 00133 } 00134 00135 if (f->datalen == 0) { /* native PLC, set fake f->datalen and clear plc_mode */ 00136 f->datalen = ILBC_FRAME_LEN; 00137 f->samples = ILBC_SAMPLES; 00138 plc_mode = 0; /* do native plc */ 00139 pvt->samples += ILBC_SAMPLES; 00140 } 00141 00142 if (f->datalen % ILBC_FRAME_LEN) { 00143 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); 00144 return -1; 00145 } 00146 00147 for (x=0; x < f->datalen ; x += ILBC_FRAME_LEN) { 00148 if (pvt->samples + ILBC_SAMPLES > BUFFER_SAMPLES) { 00149 ast_log(LOG_WARNING, "Out of buffer space\n"); 00150 return -1; 00151 } 00152 iLBC_decode(tmpf, plc_mode ? f->data + x : NULL, &tmp->dec, plc_mode); 00153 for ( i=0; i < ILBC_SAMPLES; i++) 00154 dst[pvt->samples + i] = tmpf[i]; 00155 pvt->samples += ILBC_SAMPLES; 00156 pvt->datalen += 2*ILBC_SAMPLES; 00157 } 00158 return 0; 00159 }
static int ilbctolin_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 81 of file codec_ilbc.c.
References ilbc_coder_pvt::dec, ILBC_MS, ast_trans_pvt::pvt, and USE_ILBC_ENHANCER.
00082 { 00083 struct ilbc_coder_pvt *tmp = pvt->pvt; 00084 00085 initDecode(&tmp->dec, ILBC_MS, USE_ILBC_ENHANCER); 00086 00087 return 0; 00088 }
static struct ast_frame* ilbctolin_sample | ( | void | ) | [static] |
Definition at line 104 of file codec_ilbc.c.
References AST_FORMAT_ILBC, AST_FRAME_VOICE, f, ILBC_SAMPLES, and ilbc_slin_ex.
00105 { 00106 static struct ast_frame f; 00107 f.frametype = AST_FRAME_VOICE; 00108 f.subclass = AST_FORMAT_ILBC; 00109 f.datalen = sizeof(ilbc_slin_ex); 00110 /* All frames are 30 ms long */ 00111 f.samples = ILBC_SAMPLES; 00112 f.mallocd = 0; 00113 f.offset = 0; 00114 f.src = __PRETTY_FUNCTION__; 00115 f.data = ilbc_slin_ex; 00116 return &f; 00117 }
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 162 of file codec_ilbc.c.
References ilbc_coder_pvt::buf, f, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00163 { 00164 struct ilbc_coder_pvt *tmp = pvt->pvt; 00165 00166 /* Just add the frames to our stream */ 00167 /* XXX We should look at how old the rest of our stream is, and if it 00168 is too old, then we should overwrite it entirely, otherwise we can 00169 get artifacts of earlier talk that do not belong */ 00170 memcpy(tmp->buf + pvt->samples, f->data, f->datalen); 00171 pvt->samples += f->samples; 00172 return 0; 00173 }
static struct ast_frame* lintoilbc_frameout | ( | struct ast_trans_pvt * | pvt | ) | [static] |
encode the temporary buffer and generate a frame
Definition at line 176 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.
00177 { 00178 struct ilbc_coder_pvt *tmp = pvt->pvt; 00179 int datalen = 0; 00180 int samples = 0; 00181 00182 /* We can't work on anything less than a frame in size */ 00183 if (pvt->samples < ILBC_SAMPLES) 00184 return NULL; 00185 while (pvt->samples >= ILBC_SAMPLES) { 00186 float tmpf[ILBC_SAMPLES]; 00187 int i; 00188 00189 /* Encode a frame of data */ 00190 for (i = 0 ; i < ILBC_SAMPLES ; i++) 00191 tmpf[i] = tmp->buf[samples + i]; 00192 iLBC_encode((unsigned char *) pvt->outbuf + datalen, tmpf, &tmp->enc); 00193 00194 datalen += ILBC_FRAME_LEN; 00195 samples += ILBC_SAMPLES; 00196 pvt->samples -= ILBC_SAMPLES; 00197 } 00198 00199 /* Move the data at the end of the buffer to the front */ 00200 if (pvt->samples) 00201 memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2); 00202 00203 return ast_trans_frameout(pvt, datalen, samples); 00204 }
static int lintoilbc_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 72 of file codec_ilbc.c.
References ilbc_coder_pvt::enc, ILBC_MS, and ast_trans_pvt::pvt.
00073 { 00074 struct ilbc_coder_pvt *tmp = pvt->pvt; 00075 00076 initEncode(&tmp->enc, ILBC_MS); 00077 00078 return 0; 00079 }
static struct ast_frame* lintoilbc_sample | ( | void | ) | [static] |
Definition at line 90 of file codec_ilbc.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, and slin_ilbc_ex.
00091 { 00092 static struct ast_frame f; 00093 f.frametype = AST_FRAME_VOICE; 00094 f.subclass = AST_FORMAT_SLINEAR; 00095 f.datalen = sizeof(slin_ilbc_ex); 00096 f.samples = sizeof(slin_ilbc_ex)/2; 00097 f.mallocd = 0; 00098 f.offset = 0; 00099 f.src = __PRETTY_FUNCTION__; 00100 f.data = slin_ilbc_ex; 00101 return &f; 00102 }
static int load_module | ( | void | ) | [static] |
Definition at line 240 of file codec_ilbc.c.
References ast_register_translator, ast_unregister_translator(), ilbctolin, and lintoilbc.
00241 { 00242 int res; 00243 00244 res = ast_register_translator(&ilbctolin); 00245 if (!res) 00246 res=ast_register_translator(&lintoilbc); 00247 else 00248 ast_unregister_translator(&ilbctolin); 00249 00250 return res; 00251 }
static int unload_module | ( | void | ) | [static] |
Definition at line 230 of file codec_ilbc.c.
References ast_unregister_translator(), ilbctolin, and lintoilbc.
00231 { 00232 int res; 00233 00234 res = ast_unregister_translator(&lintoilbc); 00235 res |= ast_unregister_translator(&ilbctolin); 00236 00237 return res; 00238 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 253 of file codec_ilbc.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 253 of file codec_ilbc.c.
struct ast_translator ilbctolin [static] |
struct ast_translator lintoilbc [static] |