History

vf_frei0r: switch to an AVOptions-based system.

Anton Khirnov committed 13 years ago

Commit 5aa1a661 parent f13ab293 files · +108 −53Browse files

Unified · Split

3 files
  1. doc/filters.texi +37 −26
  2. libavfilter/avfilter.c +20 −3
  3. libavfilter/vf_frei0r.c +51 −24
doc/filters.texi+37−26
@@ -1118,20 +1118,22 @@ Apply a frei0r effect to the input video. · 1117 unmodified lines
11181118 To enable compilation of this filter you need to install the frei0r
11191119 header and configure Libav with --enable-frei0r.
11201120
1121−The filter supports the syntax:
1122−@example
1123−@var{filter_name}[@{:|=@}@var{param1}:@var{param2}:...:@var{paramN}]
1124−@end example
1121+This filter accepts the following options:
1122+
1123+@table @option
1124+
1125+@item filter_name
1126+The name to the frei0r effect to load. If the environment variable
1127+@env{FREI0R_PATH} is defined, the frei0r effect is searched in each one of the
1128+directories specified by the colon separated list in @env{FREIOR_PATH},
1129+otherwise in the standard frei0r paths, which are in this order:
1130+@file{HOME/.frei0r-1/lib/}, @file{/usr/local/lib/frei0r-1/},
1131+@file{/usr/lib/frei0r-1/}.
11251132
1126−@var{filter_name} is the name to the frei0r effect to load. If the
1127−environment variable @env{FREI0R_PATH} is defined, the frei0r effect
1128−is searched in each one of the directories specified by the colon
1129−separated list in @env{FREIOR_PATH}, otherwise in the standard frei0r
1130−paths, which are in this order: @file{HOME/.frei0r-1/lib/},
1131−@file{/usr/local/lib/frei0r-1/}, @file{/usr/lib/frei0r-1/}.
1133+@item filter_params
1134+A '|'-separated list of parameters to pass to the frei0r effect.
11321135
1133−@var{param1}, @var{param2}, ... , @var{paramN} specify the parameters
1134−for the frei0r effect.
1136+@end table
11351137
11361138 A frei0r effect parameter can be a boolean (whose values are specified
11371139 with "y" and "n"), a double, a color (specified by the syntax
@@ -1146,7 +1148,7 @@ effect parameter is not specified the default value is set. · 8 unmodified lines
11461148 Some examples follow:
11471149 @example
11481150 # apply the distort0r effect, set the first two double parameters
1149−frei0r=distort0r:0.5:0.01
1151+frei0r=filter_name=distort0r:filter_params=0.5|0.01
11501152
11511153 # apply the colordistance effect, takes a color as first parameter
11521154 frei0r=colordistance:0.2/0.3/0.4
@@ -1155,7 +1157,7 @@ frei0r=colordistance:0x112233 · 2 unmodified lines
11551157
11561158 # apply the perspective effect, specify the top left and top right
11571159 # image positions
1158−frei0r=perspective:0.2/0.2:0.8/0.2
1160+frei0r=perspective:0.2/0.2|0.8/0.2
11591161 @end example
11601162
11611163 For more information see:
@@ -2375,24 +2377,33 @@ Provide a frei0r source. · 1213 unmodified lines
23752377 To enable compilation of this filter you need to install the frei0r
23762378 header and configure Libav with --enable-frei0r.
23772379
2378−The source supports the syntax:
2379−@example
2380−@var{size}:@var{rate}:@var{src_name}[@{=|:@}@var{param1}:@var{param2}:...:@var{paramN}]
2381−@end example
2380+This source accepts the following options:
2381+
2382+@table @option
2383+
2384+@item size
2385+The size of the video to generate, may be a string of the form
2386+@var{width}x@var{height} or a frame size abbreviation.
23822387
2383−@var{size} is the size of the video to generate, may be a string of the
2384−form @var{width}x@var{height} or a frame size abbreviation.
2385−@var{rate} is the rate of the video to generate, may be a string of
2386−the form @var{num}/@var{den} or a frame rate abbreviation.
2387−@var{src_name} is the name to the frei0r source to load. For more
2388−information regarding frei0r and how to set the parameters read the
2389−section @ref{frei0r} in the description of the video filters.
2388+@item framerate
2389+Framerate of the generated video, may be a string of the form
2390+@var{num}/@var{den} or a frame rate abbreviation.
2391+
2392+@item filter_name
2393+The name to the frei0r source to load. For more information regarding frei0r and
2394+how to set the parameters read the section @ref{frei0r} in the description of
2395+the video filters.
2396+
2397+@item filter_params
2398+A '|'-separated list of parameters to pass to the frei0r source.
2399+
2400+@end table
23902401
23912402 Some examples follow:
23922403 @example
23932404 # generate a frei0r partik0l source with size 200x200 and framerate 10
23942405 # which is overlayed on the overlay filter main input
2395−frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay
2406+frei0r_src=size=200x200:framerate=10:filter_name=partik0l:filter_params=1234 [overlay]; [in][overlay] overlay
23962407 @end example
23972408
23982409 @section rgbtestsrc, testsrc
libavfilter/avfilter.c+20−3
@@ -487,19 +487,36 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 486 unmodified lines
487487 if (ret < 0)
488488 goto fail;
489489 #if FF_API_OLD_FILTER_OPTS
490− } else if (!strcmp(filter->filter->name, "format") ||
491− !strcmp(filter->filter->name, "noformat")) {
490+ } else if (!strcmp(filter->filter->name, "format") ||
491+ !strcmp(filter->filter->name, "noformat") ||
492+ !strcmp(filter->filter->name, "frei0r") ||
493+ !strcmp(filter->filter->name, "frei0r_src")) {
492494 /* a hack for compatibility with the old syntax
493495 * replace colons with |s */
494496 char *copy = av_strdup(args);
495497 char *p = copy;
498+ int nb_leading = 0; // number of leading colons to skip
496499
497500 if (!copy) {
498501 ret = AVERROR(ENOMEM);
499502 goto fail;
500503 }
501504
502− if (strchr(copy, ':')) {
505+ if (!strcmp(filter->filter->name, "frei0r"))
506+ nb_leading = 1;
507+ else if (!strcmp(filter->filter->name, "frei0r_src"))
508+ nb_leading = 3;
509+
510+ while (nb_leading--) {
511+ p = strchr(p, ':');
512+ if (!p) {
513+ p = copy + strlen(copy);
514+ break;
515+ }
516+ p++;
517+ }
518+
519+ if (strchr(p, ':')) {
503520 av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "
504521 "'|' to separate the list items.\n");
505522 }
libavfilter/vf_frei0r.c+51−24
@@ -35,6 +35,7 @@ · 34 unmodified lines
3535 #include "libavutil/internal.h"
3636 #include "libavutil/mathematics.h"
3737 #include "libavutil/mem.h"
38+#include "libavutil/opt.h"
3839 #include "libavutil/parseutils.h"
3940 #include "avfilter.h"
4041 #include "formats.h"
@@ -53,6 +54,7 @@ typedef void (*f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param · 12 unmodified lines
5354 typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
5455
5556 typedef struct Frei0rContext {
57+ const AVClass *class;
5658 f0r_update_f update;
5759 void *dl_handle; /* dynamic library handle */
5860 f0r_instance_t instance;
@@ -64,7 +66,11 @@ typedef struct Frei0rContext { · 5 unmodified lines
6466 f0r_construct_f construct;
6567 f0r_destruct_f destruct;
6668 f0r_deinit_f deinit;
67− char params[256];
69+
70+ char *dl_name;
71+ char *params;
72+ char *size;
73+ char *framerate;
6874
6975 /* only used by the source */
7076 int w, h;
@@ -143,7 +149,7 @@ static int set_params(AVFilterContext *ctx, const char *params) · 72 unmodified lines
143149 frei0r->get_param_info(&info, i);
144150
145151 if (*params) {
146− if (!(param = av_get_token(&params, ":")))
152+ if (!(param = av_get_token(&params, "|")))
147153 return AVERROR(ENOMEM);
148154 params++; /* skip ':' */
149155 ret = set_param(ctx, info, i, param);
@@ -222,6 +228,11 @@ static av_cold int frei0r_init(AVFilterContext *ctx, · 72 unmodified lines
222228 f0r_plugin_info_t *pi;
223229 char *path;
224230
231+ if (!dl_name) {
232+ av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n");
233+ return AVERROR(EINVAL);
234+ }
235+
225236 /* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */
226237 if ((path = av_strdup(getenv("FREI0R_PATH")))) {
227238 char *p, *ptr = NULL;
@@ -287,13 +298,8 @@ static av_cold int frei0r_init(AVFilterContext *ctx, · 59 unmodified lines
287298 static av_cold int filter_init(AVFilterContext *ctx, const char *args)
288299 {
289300 Frei0rContext *frei0r = ctx->priv;
290− char dl_name[1024], c;
291− *frei0r->params = 0;
292301
293− if (args)
294− sscanf(args, "%1023[^:=]%c%255c", dl_name, &c, frei0r->params);
295−
296− return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_FILTER);
302+ return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_FILTER);
297303 }
298304
299305 static av_cold void uninit(AVFilterContext *ctx)
@@ -306,8 +312,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 6 unmodified lines
306312 frei0r->deinit();
307313 if (frei0r->dl_handle)
308314 dlclose(frei0r->dl_handle);
309−
310− memset(frei0r, 0, sizeof(*frei0r));
311315 }
312316
313317 static int config_input_props(AVFilterLink *inlink)
@@ -368,6 +372,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 54 unmodified lines
368372 return ff_filter_frame(outlink, out);
369373 }
370374
375+#define OFFSET(x) offsetof(Frei0rContext, x)
376+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
377+static const AVOption filter_options[] = {
378+ { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
379+ { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
380+ { NULL },
381+};
382+
383+static const AVClass filter_class = {
384+ .class_name = "frei0r",
385+ .item_name = av_default_item_name,
386+ .option = filter_options,
387+ .version = LIBAVUTIL_VERSION_INT,
388+};
389+
371390 static const AVFilterPad avfilter_vf_frei0r_inputs[] = {
372391 {
373392 .name = "default",
@@ -395,6 +414,7 @@ AVFilter avfilter_vf_frei0r = { · 21 unmodified lines
395414 .uninit = uninit,
396415
397416 .priv_size = sizeof(Frei0rContext),
417+ .priv_class = &filter_class,
398418
399419 .inputs = avfilter_vf_frei0r_inputs,
400420
@@ -404,31 +424,22 @@ AVFilter avfilter_vf_frei0r = { · 3 unmodified lines
404424 static av_cold int source_init(AVFilterContext *ctx, const char *args)
405425 {
406426 Frei0rContext *frei0r = ctx->priv;
407− char dl_name[1024], c;
408− char frame_size[128] = "";
409− char frame_rate[128] = "";
410427 AVRational frame_rate_q;
411428
412− memset(frei0r->params, 0, sizeof(frei0r->params));
413−
414− if (args)
415− sscanf(args, "%127[^:]:%127[^:]:%1023[^:=]%c%255c",
416− frame_size, frame_rate, dl_name, &c, frei0r->params);
417−
418− if (av_parse_video_size(&frei0r->w, &frei0r->h, frame_size) < 0) {
419− av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", frame_size);
429+ if (av_parse_video_size(&frei0r->w, &frei0r->h, frei0r->size) < 0) {
430+ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", frei0r->size);
420431 return AVERROR(EINVAL);
421432 }
422433
423− if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||
434+ if (av_parse_video_rate(&frame_rate_q, frei0r->framerate) < 0 ||
424435 frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
425− av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", frame_rate);
436+ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", frei0r->framerate);
426437 return AVERROR(EINVAL);
427438 }
428439 frei0r->time_base.num = frame_rate_q.den;
429440 frei0r->time_base.den = frame_rate_q.num;
430441
431− return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_SOURCE);
442+ return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_SOURCE);
432443 }
433444
434445 static int source_config_props(AVFilterLink *outlink)
@@ -467,6 +478,21 @@ static int source_request_frame(AVFilterLink *outlink) · 32 unmodified lines
467478 return ff_filter_frame(outlink, frame);
468479 }
469480
481+static const AVOption src_options[] = {
482+ { "size", "Dimensions of the generated video.", OFFSET(size), AV_OPT_TYPE_STRING, { .str = "" }, .flags = FLAGS },
483+ { "framerate", NULL, OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = FLAGS },
484+ { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
485+ { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
486+ { NULL },
487+};
488+
489+static const AVClass src_class = {
490+ .class_name = "frei0r_src",
491+ .item_name = av_default_item_name,
492+ .option = src_options,
493+ .version = LIBAVUTIL_VERSION_INT,
494+};
495+
470496 static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[] = {
471497 {
472498 .name = "default",
@@ -482,6 +508,7 @@ AVFilter avfilter_vsrc_frei0r_src = { · 9 unmodified lines
482508 .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
483509
484510 .priv_size = sizeof(Frei0rContext),
511+ .priv_class = &src_class,
485512 .init = source_init,
486513 .uninit = uninit,
487514

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