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
1118To enable compilation of this filter you need to install the frei0r1118To enable compilation of this filter you need to install the frei0r
1119header and configure Libav with --enable-frei0r.1119header and configure Libav with --enable-frei0r.
1120 1120
1121The filter supports the syntax:1121This filter accepts the following options:
1122@example1122
1123@var{filter_name}[@{:|=@}@var{param1}:@var{param2}:...:@var{paramN}]1123@table @option
1124@end example1124
1125@item filter_name
1126The 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
1128directories specified by the colon separated list in @env{FREIOR_PATH},
1129otherwise 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/}.
1125 1132
1126@var{filter_name} is the name to the frei0r effect to load. If the1133@item filter_params
1127environment variable @env{FREI0R_PATH} is defined, the frei0r effect1134A '|'-separated list of parameters to pass to the frei0r effect.
1128is searched in each one of the directories specified by the colon
1129separated list in @env{FREIOR_PATH}, otherwise in the standard frei0r
1130paths, which are in this order: @file{HOME/.frei0r-1/lib/},
1131@file{/usr/local/lib/frei0r-1/}, @file{/usr/lib/frei0r-1/}.
1132 1135
1133@var{param1}, @var{param2}, ... , @var{paramN} specify the parameters1136@end table
1134for the frei0r effect.
1135 1137
1136A frei0r effect parameter can be a boolean (whose values are specified1138A frei0r effect parameter can be a boolean (whose values are specified
1137with "y" and "n"), a double, a color (specified by the syntax1139with "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
1146Some examples follow:1148Some examples follow:
1147@example1149@example
1148# apply the distort0r effect, set the first two double parameters1150# apply the distort0r effect, set the first two double parameters
1149frei0r=distort0r:0.5:0.011151frei0r=filter_name=distort0r:filter_params=0.5|0.01
1150 1152
1151# apply the colordistance effect, takes a color as first parameter1153# apply the colordistance effect, takes a color as first parameter
1152frei0r=colordistance:0.2/0.3/0.41154frei0r=colordistance:0.2/0.3/0.4
@@ -1155,7 +1157,7 @@ frei0r=colordistance:0x112233 · 2 unmodified lines
1155 1157
1156# apply the perspective effect, specify the top left and top right1158# apply the perspective effect, specify the top left and top right
1157# image positions1159# image positions
1158frei0r=perspective:0.2/0.2:0.8/0.21160frei0r=perspective:0.2/0.2|0.8/0.2
1159@end example1161@end example
1160 1162
1161For more information see:1163For more information see:
@@ -2375,24 +2377,33 @@ Provide a frei0r source. · 1213 unmodified lines
2375To enable compilation of this filter you need to install the frei0r2377To enable compilation of this filter you need to install the frei0r
2376header and configure Libav with --enable-frei0r.2378header and configure Libav with --enable-frei0r.
2377 2379
2378The source supports the syntax:2380This source accepts the following options:
2379@example2381
2380@var{size}:@var{rate}:@var{src_name}[@{=|:@}@var{param1}:@var{param2}:...:@var{paramN}]2382@table @option
2381@end example2383
2384@item size
2385The size of the video to generate, may be a string of the form
2386@var{width}x@var{height} or a frame size abbreviation.
2382 2387
2383@var{size} is the size of the video to generate, may be a string of the2388@item framerate
2384form @var{width}x@var{height} or a frame size abbreviation.2389Framerate of the generated video, may be a string of the form
2385@var{rate} is the rate of the video to generate, may be a string of2390@var{num}/@var{den} or a frame rate abbreviation.
2386the form @var{num}/@var{den} or a frame rate abbreviation.2391
2387@var{src_name} is the name to the frei0r source to load. For more2392@item filter_name
2388information regarding frei0r and how to set the parameters read the2393The name to the frei0r source to load. For more information regarding frei0r and
2389section @ref{frei0r} in the description of the video filters.2394how to set the parameters read the section @ref{frei0r} in the description of
2395the video filters.
2396
2397@item filter_params
2398A '|'-separated list of parameters to pass to the frei0r source.
2399
2400@end table
2390 2401
2391Some examples follow:2402Some examples follow:
2392@example2403@example
2393# generate a frei0r partik0l source with size 200x200 and framerate 102404# generate a frei0r partik0l source with size 200x200 and framerate 10
2394# which is overlayed on the overlay filter main input2405# which is overlayed on the overlay filter main input
2395frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay2406frei0r_src=size=200x200:framerate=10:filter_name=partik0l:filter_params=1234 [overlay]; [in][overlay] overlay
2396@end example2407@end example
2397 2408
2398@section rgbtestsrc, testsrc2409@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
487 if (ret < 0)487 if (ret < 0)
488 goto fail;488 goto fail;
489#if FF_API_OLD_FILTER_OPTS489#if FF_API_OLD_FILTER_OPTS
490 } else if (!strcmp(filter->filter->name, "format") ||490 } else if (!strcmp(filter->filter->name, "format") ||
491 !strcmp(filter->filter->name, "noformat")) {491 !strcmp(filter->filter->name, "noformat") ||
492 !strcmp(filter->filter->name, "frei0r") ||
493 !strcmp(filter->filter->name, "frei0r_src")) {
492 /* a hack for compatibility with the old syntax494 /* a hack for compatibility with the old syntax
493 * replace colons with |s */495 * replace colons with |s */
494 char *copy = av_strdup(args);496 char *copy = av_strdup(args);
495 char *p = copy;497 char *p = copy;
498 int nb_leading = 0; // number of leading colons to skip
496 499
497 if (!copy) {500 if (!copy) {
498 ret = AVERROR(ENOMEM);501 ret = AVERROR(ENOMEM);
499 goto fail;502 goto fail;
500 }503 }
501 504
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, ':')) {
503 av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "520 av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "
504 "'|' to separate the list items.\n");521 "'|' to separate the list items.\n");
505 }522 }
libavfilter/vf_frei0r.c+51−24
@@ -35,6 +35,7 @@ · 34 unmodified lines
35#include "libavutil/internal.h"35#include "libavutil/internal.h"
36#include "libavutil/mathematics.h"36#include "libavutil/mathematics.h"
37#include "libavutil/mem.h"37#include "libavutil/mem.h"
38#include "libavutil/opt.h"
38#include "libavutil/parseutils.h"39#include "libavutil/parseutils.h"
39#include "avfilter.h"40#include "avfilter.h"
40#include "formats.h"41#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
53typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);54typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
54 55
55typedef struct Frei0rContext {56typedef struct Frei0rContext {
57 const AVClass *class;
56 f0r_update_f update;58 f0r_update_f update;
57 void *dl_handle; /* dynamic library handle */59 void *dl_handle; /* dynamic library handle */
58 f0r_instance_t instance;60 f0r_instance_t instance;
@@ -64,7 +66,11 @@ typedef struct Frei0rContext { · 5 unmodified lines
64 f0r_construct_f construct;66 f0r_construct_f construct;
65 f0r_destruct_f destruct;67 f0r_destruct_f destruct;
66 f0r_deinit_f deinit;68 f0r_deinit_f deinit;
67 char params[256];69
70 char *dl_name;
71 char *params;
72 char *size;
73 char *framerate;
68 74
69 /* only used by the source */75 /* only used by the source */
70 int w, h;76 int w, h;
@@ -143,7 +149,7 @@ static int set_params(AVFilterContext *ctx, const char *params) · 72 unmodified lines
143 frei0r->get_param_info(&info, i);149 frei0r->get_param_info(&info, i);
144 150
145 if (*params) {151 if (*params) {
146 if (!(param = av_get_token(&params, ":")))152 if (!(param = av_get_token(&params, "|")))
147 return AVERROR(ENOMEM);153 return AVERROR(ENOMEM);
148 params++; /* skip ':' */154 params++; /* skip ':' */
149 ret = set_param(ctx, info, i, param);155 ret = set_param(ctx, info, i, param);
@@ -222,6 +228,11 @@ static av_cold int frei0r_init(AVFilterContext *ctx, · 72 unmodified lines
222 f0r_plugin_info_t *pi;228 f0r_plugin_info_t *pi;
223 char *path;229 char *path;
224 230
231 if (!dl_name) {
232 av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n");
233 return AVERROR(EINVAL);
234 }
235
225 /* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */236 /* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */
226 if ((path = av_strdup(getenv("FREI0R_PATH")))) {237 if ((path = av_strdup(getenv("FREI0R_PATH")))) {
227 char *p, *ptr = NULL;238 char *p, *ptr = NULL;
@@ -287,13 +298,8 @@ static av_cold int frei0r_init(AVFilterContext *ctx, · 59 unmodified lines
287static av_cold int filter_init(AVFilterContext *ctx, const char *args)298static av_cold int filter_init(AVFilterContext *ctx, const char *args)
288{299{
289 Frei0rContext *frei0r = ctx->priv;300 Frei0rContext *frei0r = ctx->priv;
290 char dl_name[1024], c;
291 *frei0r->params = 0;
292 301
293 if (args)302 return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_FILTER);
294 sscanf(args, "%1023[^:=]%c%255c", dl_name, &c, frei0r->params);
295
296 return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_FILTER);
297}303}
298 304
299static av_cold void uninit(AVFilterContext *ctx)305static av_cold void uninit(AVFilterContext *ctx)
@@ -306,8 +312,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 6 unmodified lines
306 frei0r->deinit();312 frei0r->deinit();
307 if (frei0r->dl_handle)313 if (frei0r->dl_handle)
308 dlclose(frei0r->dl_handle);314 dlclose(frei0r->dl_handle);
309
310 memset(frei0r, 0, sizeof(*frei0r));
311}315}
312 316
313static int config_input_props(AVFilterLink *inlink)317static int config_input_props(AVFilterLink *inlink)
@@ -368,6 +372,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 54 unmodified lines
368 return ff_filter_frame(outlink, out);372 return ff_filter_frame(outlink, out);
369}373}
370 374
375#define OFFSET(x) offsetof(Frei0rContext, x)
376#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
377static 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
383static 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
371static const AVFilterPad avfilter_vf_frei0r_inputs[] = {390static const AVFilterPad avfilter_vf_frei0r_inputs[] = {
372 {391 {
373 .name = "default",392 .name = "default",
@@ -395,6 +414,7 @@ AVFilter avfilter_vf_frei0r = { · 21 unmodified lines
395 .uninit = uninit,414 .uninit = uninit,
396 415
397 .priv_size = sizeof(Frei0rContext),416 .priv_size = sizeof(Frei0rContext),
417 .priv_class = &filter_class,
398 418
399 .inputs = avfilter_vf_frei0r_inputs,419 .inputs = avfilter_vf_frei0r_inputs,
400 420
@@ -404,31 +424,22 @@ AVFilter avfilter_vf_frei0r = { · 3 unmodified lines
404static av_cold int source_init(AVFilterContext *ctx, const char *args)424static av_cold int source_init(AVFilterContext *ctx, const char *args)
405{425{
406 Frei0rContext *frei0r = ctx->priv;426 Frei0rContext *frei0r = ctx->priv;
407 char dl_name[1024], c;
408 char frame_size[128] = "";
409 char frame_rate[128] = "";
410 AVRational frame_rate_q;427 AVRational frame_rate_q;
411 428
412 memset(frei0r->params, 0, sizeof(frei0r->params));429 if (av_parse_video_size(&frei0r->w, &frei0r->h, frei0r->size) < 0) {
413 430 av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", frei0r->size);
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);
420 return AVERROR(EINVAL);431 return AVERROR(EINVAL);
421 }432 }
422 433
423 if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||434 if (av_parse_video_rate(&frame_rate_q, frei0r->framerate) < 0 ||
424 frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {435 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);
426 return AVERROR(EINVAL);437 return AVERROR(EINVAL);
427 }438 }
428 frei0r->time_base.num = frame_rate_q.den;439 frei0r->time_base.num = frame_rate_q.den;
429 frei0r->time_base.den = frame_rate_q.num;440 frei0r->time_base.den = frame_rate_q.num;
430 441
431 return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_SOURCE);442 return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_SOURCE);
432}443}
433 444
434static int source_config_props(AVFilterLink *outlink)445static int source_config_props(AVFilterLink *outlink)
@@ -467,6 +478,21 @@ static int source_request_frame(AVFilterLink *outlink) · 32 unmodified lines
467 return ff_filter_frame(outlink, frame);478 return ff_filter_frame(outlink, frame);
468}479}
469 480
481static 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
489static 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
470static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[] = {496static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[] = {
471 {497 {
472 .name = "default",498 .name = "default",
@@ -482,6 +508,7 @@ AVFilter avfilter_vsrc_frei0r_src = { · 9 unmodified lines
482 .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),508 .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
483 509
484 .priv_size = sizeof(Frei0rContext),510 .priv_size = sizeof(Frei0rContext),
511 .priv_class = &src_class,
485 .init = source_init,512 .init = source_init,
486 .uninit = uninit,513 .uninit = uninit,
487 514

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