aboutsummaryrefslogtreecommitdiffstats
path: root/codecs/codec_ulaw.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_ulaw.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_ulaw.c')
-rwxr-xr-xcodecs/codec_ulaw.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/codecs/codec_ulaw.c b/codecs/codec_ulaw.c
index 698733a3c..4f2b24c7d 100755
--- a/codecs/codec_ulaw.c
+++ b/codecs/codec_ulaw.c
@@ -13,6 +13,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 <asterisk/ulaw.h>
@@ -30,6 +32,8 @@ static int localusecnt = 0;
static char *tdesc = "Mu-law Coder/Decoder";
+static int useplc = 0;
+
/* Sample frame data */
#include "slin_ulaw_ex.h"
@@ -57,6 +61,7 @@ struct ulaw_decoder_pvt
char offset[AST_FRIENDLY_OFFSET]; /* Space to build offset */
short outbuf[BUFFER_SIZE]; /* Decoded signed linear values */
int tail;
+ plc_state_t plc;
};
/*
@@ -79,6 +84,7 @@ ulawtolin_new (void)
{
memset(tmp, 0, sizeof(*tmp));
tmp->tail = 0;
+ plc_init(&tmp->plc);
localusecnt++;
ast_update_use_count ();
}
@@ -130,6 +136,18 @@ ulawtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
int x;
unsigned char *b;
+ if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
+ if((tmp->tail + 160) * 2 > sizeof(tmp->outbuf)) {
+ 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;
+ }
+
if ((tmp->tail + f->datalen) * 2 > sizeof(tmp->outbuf)) {
ast_log(LOG_WARNING, "Out of buffer space\n");
return -1;
@@ -140,6 +158,8 @@ ulawtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
for (x=0;x<f->datalen;x++)
tmp->outbuf[tmp->tail + x] = AST_MULAW(b[x]);
+ if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail, f->datalen);
+
tmp->tail += f->datalen;
return 0;
}
@@ -327,6 +347,33 @@ static struct ast_translator lintoulaw = {
lintoulaw_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)
{
@@ -345,6 +392,7 @@ int
load_module (void)
{
int res;
+ parse_config();
res = ast_register_translator (&ulawtolin);
if (!res)
res = ast_register_translator (&lintoulaw);