History

avfilter/af_biquads: use ff_filter_process_command()

Paul B Mahol committed 7 years ago

Commit 015cbca1 parent dcfe3291 file · +10 −124Browse files

Unified · Split

libavfilter/af_biquads.c+10−124
@@ -503,127 +503,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) · 502 unmodified lines
503503 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
504504 char *res, int res_len, int flags)
505505 {
506− BiquadsContext *s = ctx->priv;
507506 AVFilterLink *outlink = ctx->outputs[0];
507+ int ret;
508508
509− if ((!strcmp(cmd, "frequency") || !strcmp(cmd, "f")) &&
510− (s->filter_type == equalizer ||
511− s->filter_type == lowshelf ||
512− s->filter_type == highshelf ||
513− s->filter_type == bass ||
514− s->filter_type == treble ||
515− s->filter_type == bandpass ||
516− s->filter_type == bandreject||
517− s->filter_type == lowpass ||
518− s->filter_type == highpass ||
519− s->filter_type == allpass)) {
520− double freq;
521−
522− if (sscanf(args, "%lf", &freq) != 1) {
523− av_log(ctx, AV_LOG_ERROR, "Invalid frequency value.\n");
524− return AVERROR(EINVAL);
525− }
526−
527− s->frequency = freq;
528− } else if ((!strcmp(cmd, "gain") || !strcmp(cmd, "g")) &&
529− (s->filter_type == equalizer ||
530− s->filter_type == lowshelf ||
531− s->filter_type == highshelf ||
532− s->filter_type == bass ||
533− s->filter_type == treble)) {
534− double gain;
535−
536− if (sscanf(args, "%lf", &gain) != 1) {
537− av_log(ctx, AV_LOG_ERROR, "Invalid gain value.\n");
538− return AVERROR(EINVAL);
539− }
540−
541− s->gain = av_clipd(gain, -900, 900);
542− } else if (!strcmp(cmd, "mix") || !strcmp(cmd, "m")) {
543− double mix;
544−
545− if (sscanf(args, "%lf", &mix) != 1) {
546− av_log(ctx, AV_LOG_ERROR, "Invalid mix value.\n");
547− return AVERROR(EINVAL);
548− }
549−
550− s->mix = av_clipd(mix, 0, 1);
551− } else if ((!strcmp(cmd, "width") || !strcmp(cmd, "w")) &&
552− (s->filter_type == equalizer ||
553− s->filter_type == lowshelf ||
554− s->filter_type == highshelf ||
555− s->filter_type == bass ||
556− s->filter_type == treble ||
557− s->filter_type == bandpass ||
558− s->filter_type == bandreject||
559− s->filter_type == lowpass ||
560− s->filter_type == highpass ||
561− s->filter_type == allpass)) {
562− double width;
563−
564− if (sscanf(args, "%lf", &width) != 1) {
565− av_log(ctx, AV_LOG_ERROR, "Invalid width value.\n");
566− return AVERROR(EINVAL);
567− }
568−
569− s->width = width;
570− } else if ((!strcmp(cmd, "width_type") || !strcmp(cmd, "t")) &&
571− (s->filter_type == equalizer ||
572− s->filter_type == lowshelf ||
573− s->filter_type == highshelf ||
574− s->filter_type == bass ||
575− s->filter_type == treble ||
576− s->filter_type == bandpass ||
577− s->filter_type == bandreject||
578− s->filter_type == lowpass ||
579− s->filter_type == highpass ||
580− s->filter_type == allpass)) {
581− char width_type;
582−
583− if (sscanf(args, "%c", &width_type) != 1) {
584− av_log(ctx, AV_LOG_ERROR, "Invalid width_type value.\n");
585− return AVERROR(EINVAL);
586− }
587−
588− switch (width_type) {
589− case 'h': width_type = HERTZ; break;
590− case 'q': width_type = QFACTOR; break;
591− case 'o': width_type = OCTAVE; break;
592− case 's': width_type = SLOPE; break;
593− case 'k': width_type = KHERTZ; break;
594− default:
595− av_log(ctx, AV_LOG_ERROR, "Invalid width_type value: %c\n", width_type);
596− return AVERROR(EINVAL);
597− }
598−
599− s->width_type = width_type;
600− } else if ((!strcmp(cmd, "a0") ||
601− !strcmp(cmd, "a1") ||
602− !strcmp(cmd, "a2") ||
603− !strcmp(cmd, "b0") ||
604− !strcmp(cmd, "b1") ||
605− !strcmp(cmd, "b2")) &&
606− s->filter_type == biquad) {
607− double value;
608−
609− if (sscanf(args, "%lf", &value) != 1) {
610− av_log(ctx, AV_LOG_ERROR, "Invalid biquad value.\n");
611− return AVERROR(EINVAL);
612− }
613−
614− if (!strcmp(cmd, "a0"))
615− s->a0 = value;
616− else if (!strcmp(cmd, "a1"))
617− s->a1 = value;
618− else if (!strcmp(cmd, "a2"))
619− s->a2 = value;
620− else if (!strcmp(cmd, "b0"))
621− s->b0 = value;
622− else if (!strcmp(cmd, "b1"))
623− s->b1 = value;
624− else if (!strcmp(cmd, "b2"))
625− s->b2 = value;
626− }
509+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
510+ if (ret < 0)
511+ return ret;
627512
628513 return config_filter(outlink, 0);
629514 }
@@ -654,7 +539,8 @@ static const AVFilterPad outputs[] = { · 24 unmodified lines
654539 };
655540
656541 #define OFFSET(x) offsetof(BiquadsContext, x)
657−#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
542+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
543+#define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
658544
659545 #define DEFINE_BIQUAD_FILTER(name_, description_) \
660546 AVFILTER_DEFINE_CLASS(name_); \
@@ -810,8 +696,8 @@ static const AVOption lowpass_options[] = { · 149 unmodified lines
810696 {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
811697 {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
812698 {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
813− {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
814− {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
699+ {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
700+ {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
815701 {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
816702 {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
817703 {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
@@ -834,8 +720,8 @@ static const AVOption highpass_options[] = { · 16 unmodified lines
834720 {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
835721 {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
836722 {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
837− {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
838− {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
723+ {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
724+ {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
839725 {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
840726 {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
841727 {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t