summaryrefslogtreecommitdiff
path: root/codecs/codec_gsm.c
diff options
context:
space:
mode:
authorMark Spencer <markster@digium.com>2005-03-17 21:30:19 +0000
committerMark Spencer <markster@digium.com>2005-03-17 21:30:19 +0000
commit7082d0584eb61abbc7c8055b74d9a7955046a8ef (patch)
tree2ff53ca559c15101655e44ad4281225c8aae6685 /codecs/codec_gsm.c
parent6546acebfb807eed42c78e737eb2de158b0f26c0 (diff)
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
Diffstat (limited to 'codecs/codec_gsm.c')
-rwxr-xr-xcodecs/codec_gsm.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/codecs/codec_gsm.c b/codecs/codec_gsm.c
index 286dc4fb8..30dc2d498 100755
--- a/codecs/codec_gsm.c
+++ b/codecs/codec_gsm.c
@@ -21,6 +21,8 @@
#include <asterisk/lock.h>
#include <asterisk/translate.h>
+#include <asterisk/config.h>
+#include <asterisk/options.h>
#include <asterisk/module.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
@@ -43,6 +45,8 @@ static int localusecnt=0;
static char *tdesc = "GSM/PCM16 (signed linear) Codec Translator";
+static int useplc = 0;
+
struct ast_translator_pvt {
gsm gsm;
struct ast_frame f;
@@ -53,6 +57,7 @@ struct ast_translator_pvt {
/* Enough to store a full second */
short buf[8000];
int tail;
+ plc_state_t plc;
};
#define gsm_coder_pvt ast_translator_pvt
@@ -67,6 +72,7 @@ static struct ast_translator_pvt *gsm_new(void)
tmp = NULL;
}
tmp->tail = 0;
+ plc_init(&tmp->plc);
localusecnt++;
}
return tmp;
@@ -131,6 +137,18 @@ static int gsmtolin_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
unsigned char data[66];
int msgsm=0;
+ if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
+ if((tmp->tail + 160) > 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, 160);
+ tmp->tail += 160;
+ }
+ return 0;
+ }
+
if ((f->datalen % 33) && (f->datalen % 65)) {
ast_log(LOG_WARNING, "Huh? A GSM frame that isn't a multiple of 33 or 65 bytes long from %s (%d)?\n", f->src, f->datalen);
return -1;
@@ -171,6 +189,10 @@ static int gsmtolin_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
}
}
}
+
+ /* just add the last 20ms frame; there must have been at least one */
+ if(useplc) plc_rx(&tmp->plc, tmp->buf+tmp->tail-160, 160);
+
return 0;
}
@@ -249,6 +271,31 @@ static struct ast_translator lintogsm =
lintogsm_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;
@@ -265,6 +312,7 @@ int unload_module(void)
int load_module(void)
{
int res;
+ parse_config();
res=ast_register_translator(&gsmtolin);
if (!res)
res=ast_register_translator(&lintogsm);