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
2315Provide an uniformly colored input.2315Provide an uniformly colored input.
2316 2316
2317It accepts the following parameters:2317It accepts the following parameters:
2318@var{color}:@var{frame_size}:@var{frame_rate}
2319
2320Follows the description of the accepted parameters.
2321 2318
2322@table @option2319@table @option
2323 2320
@@ -2326,12 +2323,12 @@ Specify the color of the source. It can be the name of a color (case · 2 unmodified lines
2326insensitive match) or a 0xRRGGBB[AA] sequence, possibly followed by an2323insensitive match) or a 0xRRGGBB[AA] sequence, possibly followed by an
2327alpha specifier. The default value is "black".2324alpha specifier. The default value is "black".
2328 2325
2329@item frame_size2326@item size
2330Specify the size of the sourced video, it may be a string of the form2327Specify the size of the sourced video, it may be a string of the form
2331@var{width}x@var{height}, or the name of a size abbreviation. The2328@var{width}x@var{height}, or the name of a size abbreviation. The
2332default value is "320x240".2329default value is "320x240".
2333 2330
2334@item frame_rate2331@item framerate
2335Specify the frame rate of the sourced video, as the number of frames2332Specify the frame rate of the sourced video, as the number of frames
2336generated per second. It has to be a string in the format2333generated per second. It has to be a string in the format
2337@var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float2334@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
36#include "libavutil/internal.h"36#include "libavutil/internal.h"
37#include "libavutil/mathematics.h"37#include "libavutil/mathematics.h"
38#include "libavutil/mem.h"38#include "libavutil/mem.h"
39#include "libavutil/opt.h"
39#include "libavutil/parseutils.h"40#include "libavutil/parseutils.h"
40#include "drawutils.h"41#include "drawutils.h"
41 42
42typedef struct {43typedef struct {
44 const AVClass *class;
43 int w, h;45 int w, h;
44 uint8_t color[4];46 uint8_t color[4];
45 AVRational time_base;47 AVRational time_base;
@@ -47,34 +49,31 @@ typedef struct { · 1 unmodified line
47 int line_step[4];49 int line_step[4];
48 int hsub, vsub; ///< chroma subsampling values50 int hsub, vsub; ///< chroma subsampling values
49 uint64_t pts;51 uint64_t pts;
52 char *color_str;
53 char *size_str;
54 char *framerate_str;
50} ColorContext;55} ColorContext;
51 56
52static av_cold int color_init(AVFilterContext *ctx, const char *args)57static av_cold int color_init(AVFilterContext *ctx, const char *args)
53{58{
54 ColorContext *color = ctx->priv;59 ColorContext *color = ctx->priv;
55 char color_string[128] = "black";
56 char frame_size [128] = "320x240";
57 char frame_rate [128] = "25";
58 AVRational frame_rate_q;60 AVRational frame_rate_q;
59 int ret;61 int ret;
60 62
61 if (args)63 if (av_parse_video_size(&color->w, &color->h, color->size_str) < 0) {
62 sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate);64 av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", color->size_str);
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);
66 return AVERROR(EINVAL);65 return AVERROR(EINVAL);
67 }66 }
68 67
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 ||
70 frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {69 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);
72 return AVERROR(EINVAL);71 return AVERROR(EINVAL);
73 }72 }
74 color->time_base.num = frame_rate_q.den;73 color->time_base.num = frame_rate_q.den;
75 color->time_base.den = frame_rate_q.num;74 color->time_base.den = frame_rate_q.num;
76 75
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)
78 return ret;77 return ret;
79 78
80 return 0;79 return 0;
@@ -160,6 +159,22 @@ static int color_request_frame(AVFilterLink *link) · 79 unmodified lines
160 return ff_filter_frame(link, frame);159 return ff_filter_frame(link, frame);
161}160}
162 161
162#define OFFSET(x) offsetof(ColorContext, x)
163#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
164static 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
171static 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
163static const AVFilterPad avfilter_vsrc_color_outputs[] = {178static const AVFilterPad avfilter_vsrc_color_outputs[] = {
164 {179 {
165 .name = "default",180 .name = "default",
@@ -174,6 +189,7 @@ AVFilter avfilter_vsrc_color = { · 8 unmodified lines
174 .name = "color",189 .name = "color",
175 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]"),190 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]"),
176 191
192 .priv_class = &color_class,
177 .priv_size = sizeof(ColorContext),193 .priv_size = sizeof(ColorContext),
178 .init = color_init,194 .init = color_init,
179 .uninit = color_uninit,195 .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