History

vsrc_color: switch to an AVOptions-based system.

Anton Khirnov committed 13 years ago

Commit 7bc1a881 parent 73d5d402 files · +29 −16Browse files

Unified · Split

2 files
  1. doc/filters.texi +2 −5
  2. libavfilter/vsrc_color.c +27 −11
doc/filters.texi+2−5
@@ -2315,9 +2315,6 @@ square pixels (1:1 sample aspect ratio). · 2314 unmodified lines
23152315 Provide an uniformly colored input.
23162316
23172317 It accepts the following parameters:
2318−@var{color}:@var{frame_size}:@var{frame_rate}
2319−
2320−Follows the description of the accepted parameters.
23212318
23222319 @table @option
23232320
@@ -2326,12 +2323,12 @@ Specify the color of the source. It can be the name of a color (case · 2 unmodified lines
23262323 insensitive match) or a 0xRRGGBB[AA] sequence, possibly followed by an
23272324 alpha specifier. The default value is "black".
23282325
2329−@item frame_size
2326+@item size
23302327 Specify the size of the sourced video, it may be a string of the form
23312328 @var{width}x@var{height}, or the name of a size abbreviation. The
23322329 default value is "320x240".
23332330
2334−@item frame_rate
2331+@item framerate
23352332 Specify the frame rate of the sourced video, as the number of frames
23362333 generated per second. It has to be a string in the format
23372334 @var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float
libavfilter/vsrc_color.c+27−11
@@ -36,10 +36,12 @@ · 35 unmodified lines
3636 #include "libavutil/internal.h"
3737 #include "libavutil/mathematics.h"
3838 #include "libavutil/mem.h"
39+#include "libavutil/opt.h"
3940 #include "libavutil/parseutils.h"
4041 #include "drawutils.h"
4142
4243 typedef struct {
44+ const AVClass *class;
4345 int w, h;
4446 uint8_t color[4];
4547 AVRational time_base;
@@ -47,34 +49,31 @@ typedef struct { · 1 unmodified line
4749 int line_step[4];
4850 int hsub, vsub; ///< chroma subsampling values
4951 uint64_t pts;
52+ char *color_str;
53+ char *size_str;
54+ char *framerate_str;
5055 } ColorContext;
5156
5257 static av_cold int color_init(AVFilterContext *ctx, const char *args)
5358 {
5459 ColorContext *color = ctx->priv;
55− char color_string[128] = "black";
56− char frame_size [128] = "320x240";
57− char frame_rate [128] = "25";
5860 AVRational frame_rate_q;
5961 int ret;
6062
61− if (args)
62− sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate);
63−
64− if (av_parse_video_size(&color->w, &color->h, frame_size) < 0) {
65− av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size);
63+ if (av_parse_video_size(&color->w, &color->h, color->size_str) < 0) {
64+ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", color->size_str);
6665 return AVERROR(EINVAL);
6766 }
6867
69− if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||
68+ if (av_parse_video_rate(&frame_rate_q, color->framerate_str) < 0 ||
7069 frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
71− av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate);
70+ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", color->framerate_str);
7271 return AVERROR(EINVAL);
7372 }
7473 color->time_base.num = frame_rate_q.den;
7574 color->time_base.den = frame_rate_q.num;
7675
77− if ((ret = av_parse_color(color->color, color_string, -1, ctx)) < 0)
76+ if ((ret = av_parse_color(color->color, color->color_str, -1, ctx)) < 0)
7877 return ret;
7978
8079 return 0;
@@ -160,6 +159,22 @@ static int color_request_frame(AVFilterLink *link) · 79 unmodified lines
160159 return ff_filter_frame(link, frame);
161160 }
162161
162+#define OFFSET(x) offsetof(ColorContext, x)
163+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
164+static const AVOption options[] = {
165+ { "color", "Output video color", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, .flags = FLAGS },
166+ { "size", "Output video size (wxh or an abbreviation)", OFFSET(size_str), AV_OPT_TYPE_STRING, { .str = "320x240" }, .flags = FLAGS },
167+ { "framerate", "Output video framerate", OFFSET(framerate_str), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = FLAGS },
168+ { NULL },
169+};
170+
171+static const AVClass color_class = {
172+ .class_name = "color",
173+ .item_name = av_default_item_name,
174+ .option = options,
175+ .version = LIBAVUTIL_VERSION_INT,
176+};
177+
163178 static const AVFilterPad avfilter_vsrc_color_outputs[] = {
164179 {
165180 .name = "default",
@@ -174,6 +189,7 @@ AVFilter avfilter_vsrc_color = { · 8 unmodified lines
174189 .name = "color",
175190 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]"),
176191
192+ .priv_class = &color_class,
177193 .priv_size = sizeof(ColorContext),
178194 .init = color_init,
179195 .uninit = color_uninit,

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