History

avfilter/af_biquads: use ff_filter_process_command()

Paul B Mahol committed 7 years ago

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

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_biquads.c+10−124
@@ -503,127 +503,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) · 502 unmodified lines
503static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,503static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
504 char *res, int res_len, int flags)504 char *res, int res_len, int flags)
505{505{
506 BiquadsContext *s = ctx->priv;
507 AVFilterLink *outlink = ctx->outputs[0];506 AVFilterLink *outlink = ctx->outputs[0];
507 int ret;
508 508
509 if ((!strcmp(cmd, "frequency") || !strcmp(cmd, "f")) &&509 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
510 (s->filter_type == equalizer ||510 if (ret < 0)
511 s->filter_type == lowshelf ||511 return ret;
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 }
627 512
628 return config_filter(outlink, 0);513 return config_filter(outlink, 0);
629}514}
@@ -654,7 +539,8 @@ static const AVFilterPad outputs[] = { · 24 unmodified lines
654};539};
655 540
656#define OFFSET(x) offsetof(BiquadsContext, x)541#define OFFSET(x) offsetof(BiquadsContext, x)
657#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM542#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
658 544
659#define DEFINE_BIQUAD_FILTER(name_, description_) \545#define DEFINE_BIQUAD_FILTER(name_, description_) \
660AVFILTER_DEFINE_CLASS(name_); \546AVFILTER_DEFINE_CLASS(name_); \
@@ -810,8 +696,8 @@ static const AVOption lowpass_options[] = { · 149 unmodified lines
810 {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},696 {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
811 {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},697 {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
812 {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},698 {"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},699 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
814 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},700 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
815 {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},701 {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
816 {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},702 {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
817 {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},703 {"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
834 {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},720 {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
835 {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},721 {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
836 {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},722 {"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},723 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
838 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},724 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
839 {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},725 {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
840 {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},726 {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
841 {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},727 {"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