Translate between signed linear and LPC10 (Linear Predictor Code). More...
#include "asterisk.h"#include "asterisk/translate.h"#include "asterisk/config.h"#include "asterisk/module.h"#include "asterisk/utils.h"#include "lpc10/lpc10.h"#include "asterisk/slin.h"#include "ex_lpc10.h"
Go to the source code of this file.
Data Structures | |
| struct | lpc10_coder_pvt |
Defines | |
| #define | BUFFER_SAMPLES 8000 |
| #define | LPC10_BYTES_IN_COMPRESSED_FRAME (LPC10_BITS_IN_COMPRESSED_FRAME + 7)/8 |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static void | build_bits (unsigned char *c, INT32 *bits) |
| static void | extract_bits (INT32 *bits, unsigned char *c) |
| static int | lintolpc10_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
| static struct ast_frame * | lintolpc10_frameout (struct ast_trans_pvt *pvt) |
| static int | load_module (void) |
| static int | lpc10_dec_new (struct ast_trans_pvt *pvt) |
| static void | lpc10_destroy (struct ast_trans_pvt *arg) |
| static int | lpc10_enc_new (struct ast_trans_pvt *pvt) |
| static int | lpc10tolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
| static int | parse_config (int reload) |
| static int | reload (void) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "LPC10 2.4kbps 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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, .reload = reload, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_translator | lintolpc10 |
| static struct ast_translator | lpc10tolin |
Translate between signed linear and LPC10 (Linear Predictor Code).
Definition in file codec_lpc10.c.
| #define BUFFER_SAMPLES 8000 |
Definition at line 52 of file codec_lpc10.c.
| #define LPC10_BYTES_IN_COMPRESSED_FRAME (LPC10_BITS_IN_COMPRESSED_FRAME + 7)/8 |
Definition at line 50 of file codec_lpc10.c.
Referenced by lintolpc10_frameout(), and lpc10tolin_framein().
| static void __reg_module | ( | void | ) | [static] |
Definition at line 278 of file codec_lpc10.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 278 of file codec_lpc10.c.
| static void build_bits | ( | unsigned char * | c, | |
| INT32 * | bits | |||
| ) | [static] |
Definition at line 92 of file codec_lpc10.c.
Referenced by lintolpc10_frameout().
| static void extract_bits | ( | INT32 * | bits, | |
| unsigned char * | c | |||
| ) | [static] |
Definition at line 78 of file codec_lpc10.c.
Referenced by lpc10tolin_framein().
| static int lintolpc10_framein | ( | struct ast_trans_pvt * | pvt, | |
| struct ast_frame * | f | |||
| ) | [static] |
Definition at line 142 of file codec_lpc10.c.
References ast_log(), lpc10_coder_pvt::buf, BUFFER_SAMPLES, ast_frame::data, ast_frame::datalen, LOG_WARNING, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, and ast_trans_pvt::samples.
00143 { 00144 struct lpc10_coder_pvt *tmp = pvt->pvt; 00145 00146 /* Just add the frames to our stream */ 00147 if (pvt->samples + f->samples > BUFFER_SAMPLES) { 00148 ast_log(LOG_WARNING, "Out of buffer space\n"); 00149 return -1; 00150 } 00151 memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen); 00152 pvt->samples += f->samples; 00153 return 0; 00154 }
| static struct ast_frame* lintolpc10_frameout | ( | struct ast_trans_pvt * | pvt | ) | [static, read] |
Definition at line 156 of file codec_lpc10.c.
References ast_trans_frameout(), lpc10_coder_pvt::buf, build_bits(), lpc10_coder_pvt::enc, lpc10_coder_pvt::longer, lpc10_coder_pvt::lpc10, LPC10_BYTES_IN_COMPRESSED_FRAME, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, ast_trans_pvt::samples, and ast_trans_pvt::uc.
00157 { 00158 struct lpc10_coder_pvt *tmp = pvt->pvt; 00159 int x; 00160 int datalen = 0; /* output frame */ 00161 int samples = 0; /* output samples */ 00162 float tmpbuf[LPC10_SAMPLES_PER_FRAME]; 00163 INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; /* XXX what ??? */ 00164 /* We can't work on anything less than a frame in size */ 00165 if (pvt->samples < LPC10_SAMPLES_PER_FRAME) 00166 return NULL; 00167 while (pvt->samples >= LPC10_SAMPLES_PER_FRAME) { 00168 /* Encode a frame of data */ 00169 for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++) 00170 tmpbuf[x] = (float)tmp->buf[x + samples] / 32768.0; 00171 lpc10_encode(tmpbuf, bits, tmp->lpc10.enc); 00172 build_bits(pvt->outbuf.uc + datalen, bits); 00173 datalen += LPC10_BYTES_IN_COMPRESSED_FRAME; 00174 samples += LPC10_SAMPLES_PER_FRAME; 00175 pvt->samples -= LPC10_SAMPLES_PER_FRAME; 00176 /* Use one of the two left over bits to record if this is a 22 or 23 ms frame... 00177 important for IAX use */ 00178 tmp->longer = 1 - tmp->longer; 00179 } 00180 /* Move the data at the end of the buffer to the front */ 00181 if (pvt->samples) 00182 memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2); 00183 return ast_trans_frameout(pvt, datalen, samples); 00184 }
| static int load_module | ( | void | ) | [static] |
Definition at line 258 of file codec_lpc10.c.
References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, ast_unregister_translator(), and parse_config().
00259 { 00260 int res; 00261 00262 if (parse_config(0)) 00263 return AST_MODULE_LOAD_DECLINE; 00264 res = ast_register_translator(&lpc10tolin); 00265 if (!res) 00266 res = ast_register_translator(&lintolpc10); 00267 else 00268 ast_unregister_translator(&lpc10tolin); 00269 if (res) 00270 return AST_MODULE_LOAD_FAILURE; 00271 return AST_MODULE_LOAD_SUCCESS; 00272 }
| static int lpc10_dec_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 71 of file codec_lpc10.c.
References lpc10_coder_pvt::dec, lpc10_coder_pvt::lpc10, and ast_trans_pvt::pvt.
00072 { 00073 struct lpc10_coder_pvt *tmp = pvt->pvt; 00074 00075 return (tmp->lpc10.dec = create_lpc10_decoder_state()) ? 0 : -1; 00076 }
| static void lpc10_destroy | ( | struct ast_trans_pvt * | arg | ) | [static] |
Definition at line 187 of file codec_lpc10.c.
References ast_free, lpc10_coder_pvt::enc, lpc10_coder_pvt::lpc10, and ast_trans_pvt::pvt.
00188 { 00189 struct lpc10_coder_pvt *pvt = arg->pvt; 00190 /* Enc and DEC are both just allocated, so they can be freed */ 00191 ast_free(pvt->lpc10.enc); 00192 }
| static int lpc10_enc_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 64 of file codec_lpc10.c.
References lpc10_coder_pvt::enc, lpc10_coder_pvt::lpc10, and ast_trans_pvt::pvt.
00065 { 00066 struct lpc10_coder_pvt *tmp = pvt->pvt; 00067 00068 return (tmp->lpc10.enc = create_lpc10_encoder_state()) ? 0 : -1; 00069 }
| static int lpc10tolin_framein | ( | struct ast_trans_pvt * | pvt, | |
| struct ast_frame * | f | |||
| ) | [static] |
Definition at line 109 of file codec_lpc10.c.
References ast_log(), BUFFER_SAMPLES, ast_frame::data, ast_frame::datalen, ast_trans_pvt::datalen, lpc10_coder_pvt::dec, extract_bits(), ast_trans_pvt::i16, len(), LOG_WARNING, lpc10_coder_pvt::lpc10, LPC10_BYTES_IN_COMPRESSED_FRAME, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00110 { 00111 struct lpc10_coder_pvt *tmp = pvt->pvt; 00112 int16_t *dst = pvt->outbuf.i16; 00113 int len = 0; 00114 00115 while (len + LPC10_BYTES_IN_COMPRESSED_FRAME <= f->datalen) { 00116 int x; 00117 float tmpbuf[LPC10_SAMPLES_PER_FRAME]; 00118 INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; /* XXX see note */ 00119 if (pvt->samples + LPC10_SAMPLES_PER_FRAME > BUFFER_SAMPLES) { 00120 ast_log(LOG_WARNING, "Out of buffer space\n"); 00121 return -1; 00122 } 00123 extract_bits(bits, f->data.ptr + len); 00124 if (lpc10_decode(bits, tmpbuf, tmp->lpc10.dec)) { 00125 ast_log(LOG_WARNING, "Invalid lpc10 data\n"); 00126 return -1; 00127 } 00128 for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++) { 00129 /* Convert to a short between -1.0 and 1.0 */ 00130 dst[pvt->samples + x] = (int16_t)(32768.0 * tmpbuf[x]); 00131 } 00132 00133 pvt->samples += LPC10_SAMPLES_PER_FRAME; 00134 pvt->datalen += 2*LPC10_SAMPLES_PER_FRAME; 00135 len += LPC10_BYTES_IN_COMPRESSED_FRAME; 00136 } 00137 if (len != f->datalen) 00138 printf("Decoded %d, expected %d\n", len, f->datalen); 00139 return 0; 00140 }
| static int parse_config | ( | int | reload | ) | [static] |
Definition at line 222 of file codec_lpc10.c.
References ast_config_destroy(), ast_config_load, ast_true(), ast_variable_browse(), ast_verb, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, ast_variable::name, ast_variable::next, ast_translator::useplc, ast_variable::value, and var.
Referenced by load_module(), and reload().
00223 { 00224 struct ast_variable *var; 00225 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; 00226 struct ast_config *cfg = ast_config_load("codecs.conf", config_flags); 00227 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) 00228 return 0; 00229 for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) { 00230 if (!strcasecmp(var->name, "genericplc")) { 00231 lpc10tolin.useplc = ast_true(var->value) ? 1 : 0; 00232 ast_verb(3, "codec_lpc10: %susing generic PLC\n", 00233 lpc10tolin.useplc ? "" : "not "); 00234 } 00235 } 00236 ast_config_destroy(cfg); 00237 return 0; 00238 }
| static int reload | ( | void | ) | [static] |
Definition at line 240 of file codec_lpc10.c.
References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and parse_config().
00241 { 00242 if (parse_config(1)) 00243 return AST_MODULE_LOAD_DECLINE; 00244 return AST_MODULE_LOAD_SUCCESS; 00245 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 248 of file codec_lpc10.c.
References ast_unregister_translator().
00249 { 00250 int res; 00251 00252 res = ast_unregister_translator(&lintolpc10); 00253 res |= ast_unregister_translator(&lpc10tolin); 00254 00255 return res; 00256 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "LPC10 2.4kbps 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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 278 of file codec_lpc10.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 278 of file codec_lpc10.c.
struct ast_translator lintolpc10 [static] |
Definition at line 208 of file codec_lpc10.c.
struct ast_translator lpc10tolin [static] |
Definition at line 194 of file codec_lpc10.c.
1.6.2