diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2012-12-07 01:03:02 +0400 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2012-12-07 01:31:42 +0400 |
commit | c6a216771fa2923f946f09952ff004debdecf673 (patch) | |
tree | 4725f23b76b83db8a52f4668705128155570f7d0 | |
parent | fef7b2e0bef6972d8d48df51e477af7b017d1a38 (diff) |
lavfi/tinterlace: add support to option parsing
Simplify code, and provide introspection through the AVOption system.
-rw-r--r-- | doc/filters.texi | 5 | ||||
-rw-r--r-- | libavfilter/version.h | 2 | ||||
-rw-r--r-- | libavfilter/vf_tinterlace.c | 72 |
3 files changed, 34 insertions, 45 deletions
diff --git a/doc/filters.texi b/doc/filters.texi index bce20f09fa..6f584d80d6 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -3918,8 +3918,9 @@ Perform various types of temporal field interlacing. Frames are counted starting from 1, so the first input frame is considered odd. -This filter accepts a single parameter specifying the mode. Available -modes are: +This filter accepts a single option @option{mode} specifying the mode, +which can be specified either by specyfing @code{mode=VALUE} either +specifying the value alone. Available values are: @table @samp @item merge, 0 diff --git a/libavfilter/version.h b/libavfilter/version.h index bf5f4969f0..04ae6dce8b 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MINOR 25 -#define LIBAVFILTER_VERSION_MICRO 100 +#define LIBAVFILTER_VERSION_MICRO 101 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c index 53c955bca7..e0ba11a40b 100644 --- a/libavfilter/vf_tinterlace.c +++ b/libavfilter/vf_tinterlace.c @@ -25,6 +25,7 @@ * temporal field interlace filter, ported from MPlayer/libmpcodecs */ +#include "libavutil/opt.h" #include "libavutil/imgutils.h" #include "libavutil/avassert.h" #include "avfilter.h" @@ -38,20 +39,11 @@ enum TInterlaceMode { MODE_INTERLEAVE_TOP, MODE_INTERLEAVE_BOTTOM, MODE_INTERLACEX2, -}; - -static const char *tinterlace_mode_str[] = { - "merge", - "drop_even", - "drop_odd", - "pad", - "interleave_top", - "interleave_bottom", - "interlacex2", - NULL + MODE_NB, }; typedef struct { + const AVClass *class; enum TInterlaceMode mode; ///< interlace mode selected int frame; ///< number of the output frame int vsub; ///< chroma vertical subsampling @@ -61,6 +53,24 @@ typedef struct { int black_linesize[4]; } TInterlaceContext; +#define OFFSET(x) offsetof(TInterlaceContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM + +static const AVOption tinterlace_options[] = { + {"mode", "select interlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_MERGE}, 0, MODE_NB-1, FLAGS, "mode"}, + {"merge", "merge fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_MERGE}, INT_MIN, INT_MAX, FLAGS, "mode"}, + {"drop_even", "drop even fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_DROP_EVEN}, INT_MIN, INT_MAX, FLAGS, "mode"}, + {"drop_odd", "drop odd fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_DROP_ODD}, INT_MIN, INT_MAX, FLAGS, "mode"}, + {"pad", "pad alternate lines with black", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PAD}, INT_MIN, INT_MAX, FLAGS, "mode"}, + {"interleave_top", "interleave top and bottom fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE_TOP}, INT_MIN, INT_MAX, FLAGS, "mode"}, + {"interleave_bottom", "interleave bottom and top fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE_BOTTOM}, INT_MIN, INT_MAX, FLAGS, "mode"}, + {"interlacex2", "interlace fields from two consecutive frames", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLACEX2}, INT_MIN, INT_MAX, FLAGS, "mode"}, + + {NULL} +}; + +AVFILTER_DEFINE_CLASS(tinterlace); + #define FULL_SCALE_YUVJ_FORMATS \ AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P @@ -84,36 +94,12 @@ static int query_formats(AVFilterContext *ctx) static av_cold int init(AVFilterContext *ctx, const char *args) { TInterlaceContext *tinterlace = ctx->priv; - int i; - char c; - - tinterlace->mode = MODE_MERGE; - - if (args) { - if (sscanf(args, "%d%c", (int *)&tinterlace->mode, &c) == 1) { - if (tinterlace->mode > 6) { - av_log(ctx, AV_LOG_ERROR, - "Invalid mode '%s', use an integer between 0 and 6\n", args); - return AVERROR(EINVAL); - } - - av_log(ctx, AV_LOG_WARNING, - "Using numeric constant is deprecated, use symbolic values\n"); - } else { - for (i = 0; tinterlace_mode_str[i]; i++) { - if (!strcmp(tinterlace_mode_str[i], args)) { - tinterlace->mode = i; - break; - } - } - if (!tinterlace_mode_str[i]) { - av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args); - return AVERROR(EINVAL); - } - } - } + static const char *shorthand[] = { "mode", NULL }; - return 0; + tinterlace->class = &tinterlace_class; + av_opt_set_defaults(tinterlace); + + return av_opt_set_from_string(tinterlace, args, shorthand, "=", ":"); } static av_cold void uninit(AVFilterContext *ctx) @@ -123,6 +109,7 @@ static av_cold void uninit(AVFilterContext *ctx) if (tinterlace->cur ) avfilter_unref_bufferp(&tinterlace->cur ); if (tinterlace->next) avfilter_unref_bufferp(&tinterlace->next); + av_opt_free(tinterlace); av_freep(&tinterlace->black_data[0]); } @@ -155,8 +142,8 @@ static int config_out_props(AVFilterLink *outlink) tinterlace->black_linesize[i] * h); } } - av_log(ctx, AV_LOG_VERBOSE, "mode:%s h:%d -> h:%d\n", - tinterlace_mode_str[tinterlace->mode], inlink->h, outlink->h); + av_log(ctx, AV_LOG_VERBOSE, "mode:%d h:%d -> h:%d\n", + tinterlace->mode, inlink->h, outlink->h); return 0; } @@ -373,4 +360,5 @@ AVFilter avfilter_vf_tinterlace = { .query_formats = query_formats, .inputs = tinterlace_inputs, .outputs = tinterlace_outputs, + .priv_class = &tinterlace_class, }; |