Browse code

lavfi/yadif: add support to named options and options introspection

Also rename the "enable_auto" field to "deint", to match the name of the
option.

Stefano Sabatini authored on 2013/01/02 19:40:02
Showing 4 changed files
... ...
@@ -4290,10 +4290,17 @@ ffmpeg -i in.avi -vf "vflip" out.avi
4290 4290
 Deinterlace the input video ("yadif" means "yet another deinterlacing
4291 4291
 filter").
4292 4292
 
4293
-It accepts the optional parameters: @var{mode}:@var{parity}:@var{auto}.
4293
+The filter accepts parameters as a list of @var{key}=@var{value}
4294
+pairs, separated by ":". If the key of the first options is omitted,
4295
+the arguments are interpreted according to syntax
4296
+@var{mode}:@var{parity}:@var{deint}.
4297
+
4298
+The description of the accepted parameters follows.
4294 4299
 
4295
-@var{mode} specifies the interlacing mode to adopt, accepts one of the
4296
-following values:
4300
+@table @option
4301
+@item mode
4302
+Specify the interlacing mode to adopt. Accept one of the following
4303
+values:
4297 4304
 
4298 4305
 @table @option
4299 4306
 @item 0
... ...
@@ -4308,8 +4315,9 @@ like 1 but skips spatial interlacing check
4308 4308
 
4309 4309
 Default value is 0.
4310 4310
 
4311
-@var{parity} specifies the picture field parity assumed for the input
4312
-interlaced video, accepts one of the following values:
4311
+@item parity
4312
+Specify the picture field parity assumed for the input interlaced
4313
+video. Accept one of the following values:
4313 4314
 
4314 4315
 @table @option
4315 4316
 @item 0
... ...
@@ -4324,8 +4332,9 @@ Default value is -1.
4324 4324
 If interlacing is unknown or decoder does not export this information,
4325 4325
 top field first will be assumed.
4326 4326
 
4327
-@var{auto} specifies if deinterlacer should trust the interlaced flag
4328
-and only deinterlace frames marked as interlaced
4327
+@item deint
4328
+Specify which frames to deinterlace. Accept one of the following
4329
+values:
4329 4330
 
4330 4331
 @table @option
4331 4332
 @item 0
... ...
@@ -4335,6 +4344,7 @@ only deinterlace frames marked as interlaced
4335 4335
 @end table
4336 4336
 
4337 4337
 Default value is 0.
4338
+@end table
4338 4339
 
4339 4340
 @c man end VIDEO FILTERS
4340 4341
 
... ...
@@ -30,7 +30,7 @@
30 30
 
31 31
 #define LIBAVFILTER_VERSION_MAJOR  3
32 32
 #define LIBAVFILTER_VERSION_MINOR  30
33
-#define LIBAVFILTER_VERSION_MICRO 102
33
+#define LIBAVFILTER_VERSION_MICRO 103
34 34
 
35 35
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 36
                                                LIBAVFILTER_VERSION_MINOR, \
... ...
@@ -20,6 +20,7 @@
20 20
 #include "libavutil/avassert.h"
21 21
 #include "libavutil/cpu.h"
22 22
 #include "libavutil/common.h"
23
+#include "libavutil/opt.h"
23 24
 #include "libavutil/pixdesc.h"
24 25
 #include "avfilter.h"
25 26
 #include "formats.h"
... ...
@@ -231,7 +232,7 @@ static int filter_frame(AVFilterLink *link, AVFilterBufferRef *picref)
231 231
     if (!yadif->cur)
232 232
         return 0;
233 233
 
234
-    if (yadif->auto_enable && !yadif->cur->video->interlaced) {
234
+    if (yadif->deint && !yadif->cur->video->interlaced) {
235 235
         yadif->out  = avfilter_ref_buffer(yadif->cur, ~AV_PERM_WRITE);
236 236
         if (!yadif->out)
237 237
             return AVERROR(ENOMEM);
... ...
@@ -296,6 +297,18 @@ static int request_frame(AVFilterLink *link)
296 296
     return 0;
297 297
 }
298 298
 
299
+#define OFFSET(x) offsetof(YADIFContext, x)
300
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
301
+
302
+static const AVOption yadif_options[] = {
303
+    { "mode",   "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS },
304
+    { "parity", "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=-1}, -1, 1, FLAGS },
305
+    { "deint",  "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
306
+    {NULL},
307
+};
308
+
309
+AVFILTER_DEFINE_CLASS(yadif);
310
+
299 311
 static av_cold void uninit(AVFilterContext *ctx)
300 312
 {
301 313
     YADIFContext *yadif = ctx->priv;
... ...
@@ -304,6 +317,7 @@ static av_cold void uninit(AVFilterContext *ctx)
304 304
     avfilter_unref_bufferp(&yadif->cur );
305 305
     avfilter_unref_bufferp(&yadif->next);
306 306
     av_freep(&yadif->temp_line); yadif->temp_line_size = 0;
307
+    av_opt_free(yadif);
307 308
 }
308 309
 
309 310
 static int query_formats(AVFilterContext *ctx)
... ...
@@ -341,23 +355,24 @@ static int query_formats(AVFilterContext *ctx)
341 341
 static av_cold int init(AVFilterContext *ctx, const char *args)
342 342
 {
343 343
     YADIFContext *yadif = ctx->priv;
344
+    static const char *shorthand[] = { "mode", "parity", "enable", NULL };
345
+    int ret;
344 346
 
345
-    yadif->mode = 0;
346
-    yadif->parity = -1;
347
-    yadif->auto_enable = 0;
348 347
     yadif->csp = NULL;
349 348
 
350
-    if (args)
351
-        sscanf(args, "%d:%d:%d",
352
-               &yadif->mode, &yadif->parity, &yadif->auto_enable);
349
+    yadif->class = &yadif_class;
350
+    av_opt_set_defaults(yadif);
351
+
352
+    if ((ret = av_opt_set_from_string(yadif, args, shorthand, "=", ":")) < 0)
353
+        return ret;
353 354
 
354 355
     yadif->filter_line = filter_line_c;
355 356
 
356 357
     if (ARCH_X86)
357 358
         ff_yadif_init_x86(yadif);
358 359
 
359
-    av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d auto_enable:%d\n",
360
-           yadif->mode, yadif->parity, yadif->auto_enable);
360
+    av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d deint:%d\n",
361
+           yadif->mode, yadif->parity, yadif->deint);
361 362
 
362 363
     return 0;
363 364
 }
... ...
@@ -413,6 +428,7 @@ AVFilter avfilter_vf_yadif = {
413 413
     .query_formats = query_formats,
414 414
 
415 415
     .inputs    = avfilter_vf_yadif_inputs,
416
-
417 416
     .outputs   = avfilter_vf_yadif_outputs,
417
+
418
+    .priv_class = &yadif_class,
418 419
 };
... ...
@@ -23,6 +23,8 @@
23 23
 #include "avfilter.h"
24 24
 
25 25
 typedef struct YADIFContext {
26
+    const AVClass *class;
27
+
26 28
     /**
27 29
      * 0: send 1 frame for each frame
28 30
      * 1: send 1 frame for each field
... ...
@@ -44,7 +46,7 @@ typedef struct YADIFContext {
44 44
      *  0: deinterlace all frames
45 45
      *  1: only deinterlace frames marked as interlaced
46 46
      */
47
-    int auto_enable;
47
+    int deint;
48 48
 
49 49
     AVFilterBufferRef *cur;
50 50
     AVFilterBufferRef *next;