From 7082d0584eb61abbc7c8055b74d9a7955046a8ef Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Thu, 17 Mar 2005 21:30:19 +0000 Subject: Add PLC and jitter buffer and iax2 meta trunk with timestamps (bug #2532, #3400) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5192 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- codecs/codec_lpc10.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'codecs/codec_lpc10.c') diff --git a/codecs/codec_lpc10.c b/codecs/codec_lpc10.c index 4a6925949..904f0266a 100755 --- a/codecs/codec_lpc10.c +++ b/codecs/codec_lpc10.c @@ -19,6 +19,8 @@ #include #include +#include +#include #include #include #include @@ -47,6 +49,8 @@ static int localusecnt=0; static char *tdesc = "LPC10 2.4kbps (signed linear) Voice Coder"; +static int useplc = 0; + struct ast_translator_pvt { union { struct lpc10_encoder_state *enc; @@ -61,6 +65,7 @@ struct ast_translator_pvt { short buf[8000]; int tail; int longer; + plc_state_t plc; /* god only knows why I bothered to implement PLC for LPC10 :) */ }; #define lpc10_coder_pvt ast_translator_pvt @@ -92,6 +97,7 @@ static struct ast_translator_pvt *lpc10_dec_new(void) } tmp->tail = 0; tmp->longer = 0; + plc_init(&tmp->plc); localusecnt++; } return tmp; @@ -199,6 +205,19 @@ static int lpc10tolin_framein(struct ast_translator_pvt *tmp, struct ast_frame * float tmpbuf[LPC10_SAMPLES_PER_FRAME]; short *sd; INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; + + if(f->datalen == 0) { /* perform PLC with nominal framesize of LPC10_SAMPLES_PER_FRAME */ + if((tmp->tail + LPC10_SAMPLES_PER_FRAME) > sizeof(tmp->buf)/2) { + ast_log(LOG_WARNING, "Out of buffer space\n"); + return -1; + } + if(useplc) { + plc_fillin(&tmp->plc, tmp->buf+tmp->tail, LPC10_SAMPLES_PER_FRAME); + tmp->tail += LPC10_SAMPLES_PER_FRAME; + } + return 0; + } + while(len + LPC10_BYTES_IN_COMPRESSED_FRAME <= f->datalen) { if (tmp->tail + LPC10_SAMPLES_PER_FRAME < sizeof(tmp->buf)/2) { sd = tmp->buf + tmp->tail; @@ -211,6 +230,8 @@ static int lpc10tolin_framein(struct ast_translator_pvt *tmp, struct ast_frame * /* Convert to a real between -1.0 and 1.0 */ sd[x] = 32768.0 * tmpbuf[x]; } + + if(useplc) plc_rx(&tmp->plc, tmp->buf + tmp->tail, LPC10_SAMPLES_PER_FRAME); tmp->tail+=LPC10_SAMPLES_PER_FRAME; } else { @@ -326,6 +347,31 @@ static struct ast_translator lintolpc10 = lintolpc10_sample }; +static void parse_config(void) +{ + struct ast_config *cfg; + struct ast_variable *var; + if ((cfg = ast_config_load("codecs.conf"))) { + if ((var = ast_variable_browse(cfg, "plc"))) { + while (var) { + if (!strcasecmp(var->name, "genericplc")) { + useplc = ast_true(var->value) ? 1 : 0; + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "CODEC ULAW: %susing generic PLC\n", useplc ? "" : "not "); + } + var = var->next; + } + } + } +} + +int reload(void) +{ + parse_config(); + return 0; +} + + int unload_module(void) { int res; @@ -342,6 +388,7 @@ int unload_module(void) int load_module(void) { int res; + parse_config(); res=ast_register_translator(&lpc10tolin); if (!res) res=ast_register_translator(&lintolpc10); -- cgit v1.2.3