aboutsummaryrefslogtreecommitdiffstats
path: root/codecs/codec_g726.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-03-17 21:30:19 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-03-17 21:30:19 +0000
commit235a6486c3ca01b9bdac577774cc90fa4f06a58f (patch)
tree2ff53ca559c15101655e44ad4281225c8aae6685 /codecs/codec_g726.c
parent98aa637d27b5ac36a35fc85b596f00d1104398e3 (diff)
Add PLC and jitter buffer and iax2 meta trunk with timestamps (bug #2532, #3400)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5192 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'codecs/codec_g726.c')
-rwxr-xr-xcodecs/codec_g726.c47
1 files changed, 47 insertions, 0 deletions
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 <asterisk/lock.h>
#include <asterisk/logger.h>
#include <asterisk/module.h>
+#include <asterisk/config.h>
+#include <asterisk/options.h>
#include <asterisk/translate.h>
#include <asterisk/channel.h>
#include <fcntl.h>
@@ -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;x<f->datalen;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);