diff --git a/modules/fvad/fvad.c b/modules/fvad/fvad.c index 0e273e3..70131e1 100644 --- a/modules/fvad/fvad.c +++ b/modules/fvad/fvad.c @@ -81,20 +81,11 @@ static bool find_call(const struct call *call, void *arg) return call_audio(call) == fa->audio; } - -static int encode_update(struct aufilt_enc_st **stp, void **ctx, - const struct aufilt *af, struct aufilt_prm *prm, - const struct audio *au) +static int check_fvad_params(const struct aufilt_prm *prm) { - struct vad_enc *st; - (void)ctx; - - if (!stp || !af || !prm) + if (!prm) return EINVAL; - if (*stp) - return 0; - if (prm->ch != 1) { warning("fvad: only mono is supported\n"); return EINVAL; @@ -106,24 +97,67 @@ static int encode_update(struct aufilt_enc_st **stp, void **ctx, return EINVAL; } - st = mem_zalloc(sizeof(*st), enc_destructor); - if (!st) - return ENOMEM; + return 0; +} - st->fvad = fvad_new(); - if (!st->fvad) { - mem_deref(st); +static int init_fvad(Fvad **fvad, const struct aufilt_prm *prm) +{ + struct conf *conf = conf_cur(); + + if (!fvad || !prm) + return EINVAL; + + *fvad = fvad_new(); + if (!*fvad) { return ENOMEM; } - int err = fvad_set_sample_rate(st->fvad, prm->srate); + int err = fvad_set_sample_rate(*fvad, prm->srate); if (err < 0) { warning("fvad: sample rate %d is not supported\n", prm->srate); - mem_deref(st); return EINVAL; } + uint32_t mode = 0; + conf_get_u32(conf, "fvad_mode", &mode); + err = fvad_set_mode(*fvad, mode); + if (err < 0) { + warning("fvad: mode %d is not supported\n", + mode); + return EINVAL; + } + + return 0; +} + +static int encode_update(struct aufilt_enc_st **stp, void **ctx, + const struct aufilt *af, struct aufilt_prm *prm, + const struct audio *au) +{ + struct vad_enc *st; + (void)ctx; + + if (!stp || !af || !prm) + return EINVAL; + + if (*stp) + return 0; + + int err = check_fvad_params(prm); + if (err) + return err; + + st = mem_zalloc(sizeof(*st), enc_destructor); + if (!st) + return ENOMEM; + + err = init_fvad(&st->fvad, prm); + if (err) { + mem_deref(st); + return err; + } + if (!st->call) { struct filter_arg fa = { au, NULL }; @@ -149,33 +183,18 @@ static int decode_update(struct aufilt_dec_st **stp, void **ctx, if (*stp) return 0; - if (prm->ch != 1) { - warning("fvad: only mono is supported\n"); - return EINVAL; - } - - if (prm->fmt != AUFMT_S16LE) { - warning("fvad: only AUFMT_S16LE is supported. " - "Use the auconv module to fix this\n"); - return EINVAL; - } + int err = check_fvad_params(prm); + if (err) + return err; st = mem_zalloc(sizeof(*st), dec_destructor); if (!st) return ENOMEM; - st->fvad = fvad_new(); - if (!st->fvad) { + err = init_fvad(&st->fvad, prm); + if (err) { mem_deref(st); - return ENOMEM; - } - - int err = fvad_set_sample_rate(st->fvad, prm->srate); - if (err < 0) { - warning("fvad: sample rate %d is not supported\n", - prm->srate); - mem_deref(st); - return EINVAL; + return err; } if (!st->call) {