summaryrefslogtreecommitdiff
path: root/libavfilter/vsrc_color.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2012-06-19 13:29:26 +0000
committerPaul B Mahol <onemda@gmail.com>2012-06-19 19:27:41 +0000
commit9e7543361cb87d2a5275b3e80a25cfe931720dd9 (patch)
treece598ece8072ce146f78cd758b83d310f584fd42 /libavfilter/vsrc_color.c
parentcabbd271a5f37042291c06b9f8bd6c641fbddfde (diff)
lavfi/color: use AVOptions
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/vsrc_color.c')
-rw-r--r--libavfilter/vsrc_color.c80
1 files changed, 65 insertions, 15 deletions
diff --git a/libavfilter/vsrc_color.c b/libavfilter/vsrc_color.c
index 112c27c4eb..555ba0fbbc 100644
--- a/libavfilter/vsrc_color.c
+++ b/libavfilter/vsrc_color.c
@@ -31,11 +31,15 @@
#include "libavutil/colorspace.h"
#include "libavutil/imgutils.h"
#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "drawutils.h"
typedef struct {
+ const AVClass *class;
int w, h;
+ char *rate_str;
+ char *color_str;
uint8_t color_rgba[4];
AVRational time_base;
uint64_t pts;
@@ -43,6 +47,26 @@ typedef struct {
FFDrawColor color;
} ColorContext;
+#define OFFSET(x) offsetof(ColorContext, x)
+
+static const AVOption color_options[]= {
+ { "size", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
+ { "s", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
+ { "rate", "set frame rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
+ { "r", "set frame rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
+ { "color", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, CHAR_MIN, CHAR_MAX },
+ { "c", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, CHAR_MIN, CHAR_MAX },
+ { NULL },
+};
+
+static const AVClass color_class = {
+ .class_name = "color",
+ .item_name = av_default_item_name,
+ .option = color_options,
+ .version = LIBAVUTIL_VERSION_INT,
+ .category = AV_CLASS_CATEGORY_FILTER,
+};
+
static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaque)
{
ColorContext *color = ctx->priv;
@@ -50,28 +74,54 @@ static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaq
char frame_size [128] = "320x240";
char frame_rate [128] = "25";
AVRational frame_rate_q;
- int ret;
+ char *colon = 0, *equal = 0;
+ int ret = 0;
- if (args)
- sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate);
+ color->class = &color_class;
- if (av_parse_video_size(&color->w, &color->h, frame_size) < 0) {
- av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size);
- return AVERROR(EINVAL);
+ if (args) {
+ colon = strrchr(args, ':');
+ equal = strrchr(args, '=');
}
- if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||
- frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
- av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate);
- return AVERROR(EINVAL);
+ if (!args || (equal && (!colon || equal < colon))) {
+ av_opt_set_defaults(color);
+ if ((ret = av_set_options_string(color, args, "=", ":")) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
+ goto end;
+ }
+ if (av_parse_video_rate(&frame_rate_q, color->rate_str) < 0 ||
+ frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", color->rate_str);
+ ret = AVERROR(EINVAL);
+ goto end;
+ }
+ if (av_parse_color(color->color_rgba, color->color_str, -1, ctx) < 0) {
+ ret = AVERROR(EINVAL);
+ goto end;
+ }
+ } else {
+ av_log(ctx, AV_LOG_WARNING, "Flat options syntax is deprecated, use key=value pairs.\n");
+ sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate);
+ if (av_parse_video_size(&color->w, &color->h, frame_size) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size);
+ return AVERROR(EINVAL);
+ }
+ if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||
+ frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate);
+ return AVERROR(EINVAL);
+ }
+ if (av_parse_color(color->color_rgba, color_string, -1, ctx) < 0)
+ return AVERROR(EINVAL);
}
+
color->time_base.num = frame_rate_q.den;
color->time_base.den = frame_rate_q.num;
- if ((ret = av_parse_color(color->color_rgba, color_string, -1, ctx)) < 0)
- return ret;
-
- return 0;
+end:
+ av_opt_free(color);
+ return ret;
}
static int query_formats(AVFilterContext *ctx)
@@ -123,7 +173,7 @@ static int color_request_frame(AVFilterLink *link)
AVFilter avfilter_vsrc_color = {
.name = "color",
- .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]."),
+ .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
.priv_size = sizeof(ColorContext),
.init = color_init,