diff options
author | Alfred E. Heggestad <aeh@db.org> | 2014-02-09 11:50:07 +0100 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2014-02-09 11:50:07 +0100 |
commit | 98bf08bdcf2edd9d397f32650a8bfe62186fbecf (patch) | |
tree | ebc6ec71f44bff8c42e4eefced61948623df02fc /modules/plc | |
parent | e6ad5cf4401b860ba402d4b7b3c7c254bc87a019 (diff) |
baresip 0.4.10
Diffstat (limited to 'modules/plc')
-rw-r--r-- | modules/plc/module.mk | 11 | ||||
-rw-r--r-- | modules/plc/plc.c | 109 |
2 files changed, 120 insertions, 0 deletions
diff --git a/modules/plc/module.mk b/modules/plc/module.mk new file mode 100644 index 0000000..bc8ae4f --- /dev/null +++ b/modules/plc/module.mk @@ -0,0 +1,11 @@ +# +# module.mk +# +# Copyright (C) 2010 Creytiv.com +# + +MOD := plc +$(MOD)_SRCS += plc.c +$(MOD)_LFLAGS += "-lspandsp" + +include mk/mod.mk diff --git a/modules/plc/plc.c b/modules/plc/plc.c new file mode 100644 index 0000000..5409258 --- /dev/null +++ b/modules/plc/plc.c @@ -0,0 +1,109 @@ +/** + * @file plc.c PLC -- Packet Loss Concealment + * + * Copyright (C) 2010 Creytiv.com + */ +#include <spandsp.h> +#include <re.h> +#include <baresip.h> + + +struct plc_st { + struct aufilt_dec_st af; /* base class */ + plc_state_t plc; + size_t sampc; +}; + + +static void destructor(void *arg) +{ + struct plc_st *st = arg; + + list_unlink(&st->af.le); +} + + +static int update(struct aufilt_dec_st **stp, void **ctx, + const struct aufilt *af, struct aufilt_prm *prm) +{ + struct plc_st *st; + int err = 0; + (void)ctx; + (void)af; + + if (!stp || !prm) + return EINVAL; + + if (*stp) + return 0; + + /* XXX: add support for stereo PLC */ + if (prm->ch != 1) { + warning("plc: only mono supported (ch=%u)\n", prm->ch); + return ENOSYS; + } + + st = mem_zalloc(sizeof(*st), destructor); + if (!st) + return ENOMEM; + + if (!plc_init(&st->plc)) { + err = ENOMEM; + goto out; + } + + st->sampc = prm->srate * prm->ch * prm->ptime / 1000; + + out: + if (err) + mem_deref(st); + else + *stp = (struct aufilt_dec_st *)st; + + return err; +} + + +/* + * PLC is only valid for Decoding (RX) + * + * NOTE: sampc == 0 , means Packet loss + */ +static int decode(struct aufilt_dec_st *st, int16_t *sampv, size_t *sampc) +{ + struct plc_st *plc = (struct plc_st *)st; + + if (*sampc) + plc_rx(&plc->plc, sampv, (int)*sampc); + else + *sampc = plc_fillin(&plc->plc, sampv, (int)plc->sampc); + + return 0; +} + + +static struct aufilt plc = { + LE_INIT, "plc", NULL, NULL, update, decode +}; + + +static int module_init(void) +{ + aufilt_register(&plc); + return 0; +} + + +static int module_close(void) +{ + aufilt_unregister(&plc); + return 0; +} + + +EXPORT_SYM const struct mod_export DECL_EXPORTS(plc) = { + "plc", + "filter", + module_init, + module_close +}; |