aboutsummaryrefslogtreecommitdiffstats
path: root/codecs/codec_alaw.c
diff options
context:
space:
mode:
Diffstat (limited to 'codecs/codec_alaw.c')
-rwxr-xr-xcodecs/codec_alaw.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/codecs/codec_alaw.c b/codecs/codec_alaw.c
index 6ba4e1da9..6705dff21 100755
--- a/codecs/codec_alaw.c
+++ b/codecs/codec_alaw.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/alaw.h>
@@ -30,6 +32,8 @@ static int localusecnt = 0;
static char *tdesc = "A-law Coder/Decoder";
+static int useplc = 0;
+
/* Sample frame data (Mu data is okay) */
#include "slin_ulaw_ex.h"
@@ -57,6 +61,7 @@ struct alaw_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 @@ alawtolin_new (void)
{
memset(tmp, 0, sizeof(*tmp));
tmp->tail = 0;
+ plc_init(&tmp->plc);
localusecnt++;
ast_update_use_count ();
}
@@ -130,6 +136,18 @@ alawtolin_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 @@ alawtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
for (x=0;x<f->datalen;x++)
tmp->outbuf[tmp->tail + x] = AST_ALAW(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 lintoalaw = {
lintoalaw_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 (&alawtolin);
if (!res)
res = ast_register_translator (&lintoalaw);