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_g726.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'codecs/codec_g726.c') diff --git a/codecs/codec_g726.c b/codecs/codec_g726.c index 8ac405854..80d978c80 100755 --- a/codecs/codec_g726.c +++ b/codecs/codec_g726.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include #include @@ -49,6 +51,8 @@ static int localusecnt = 0; static char *tdesc = "ITU G.726-32kbps G726 Transcoder"; +static int useplc = 0; + /* Sample frame data */ #include "slin_g726_ex.h" @@ -694,6 +698,7 @@ struct g726_decoder_pvt short outbuf[BUFFER_SIZE]; /* Decoded signed linear values */ struct g726_state g726; int tail; + plc_state_t plc; }; /* @@ -716,6 +721,7 @@ g726tolin_new (void) { memset(tmp, 0, sizeof(*tmp)); tmp->tail = 0; + plc_init(&tmp->plc); localusecnt++; g726_init_state(&tmp->g726); ast_update_use_count (); @@ -769,6 +775,18 @@ g726tolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f) unsigned char *b; int x; + if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */ + if((tmp->tail + 160) > BUFFER_SIZE) { + ast_log(LOG_WARNING, "Out of buffer space\n"); + return -1; + } + if(useplc) { + plc_fillin(&tmp->plc, tmp->outbuf+tmp->tail, 160); + tmp->tail += 160; + } + return 0; + } + b = f->data; for (x=0;xdatalen;x++) { if (tmp->tail >= BUFFER_SIZE) { @@ -783,6 +801,8 @@ g726tolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f) tmp->outbuf[tmp->tail++] = g726_decode(b[x] & 0x0f, &tmp->g726); } + if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail-f->datalen*2, f->datalen*2); + return 0; } @@ -974,6 +994,32 @@ static struct ast_translator lintog726 = { lintog726_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) { @@ -992,6 +1038,7 @@ int load_module (void) { int res; + parse_config(); res = ast_register_translator (&g726tolin); if (!res) res = ast_register_translator (&lintog726); -- cgit v1.2.3