]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vsrc_color.c
http: K&R formatting cosmetics
[ffmpeg] / libavfilter / vsrc_color.c
index c0a4e1c3b2654fdbf53e1f57fe87a16a949a5e50..3b506ec422c8a56ef8ecdd504b56f13de870bc9f 100644 (file)
 #include "libavutil/internal.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/mem.h"
+#include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "drawutils.h"
 
-typedef struct {
+typedef struct ColorContext {
+    const AVClass *class;
     int w, h;
     uint8_t color[4];
     AVRational time_base;
@@ -47,34 +49,31 @@ typedef struct {
     int      line_step[4];
     int hsub, vsub;         ///< chroma subsampling values
     uint64_t pts;
+    char *color_str;
+    char *size_str;
+    char *framerate_str;
 } ColorContext;
 
-static av_cold int color_init(AVFilterContext *ctx, const char *args)
+static av_cold int color_init(AVFilterContext *ctx)
 {
     ColorContext *color = ctx->priv;
-    char color_string[128] = "black";
-    char frame_size  [128] = "320x240";
-    char frame_rate  [128] = "25";
     AVRational frame_rate_q;
     int ret;
 
-    if (args)
-        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);
+    if (av_parse_video_size(&color->w, &color->h, color->size_str) < 0) {
+        av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", color->size_str);
         return AVERROR(EINVAL);
     }
 
-    if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||
+    if (av_parse_video_rate(&frame_rate_q, color->framerate_str) < 0 ||
         frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
-        av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate);
+        av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", color->framerate_str);
         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, color_string, -1, ctx)) < 0)
+    if ((ret = av_parse_color(color->color, color->color_str, -1, ctx)) < 0)
         return ret;
 
     return 0;
@@ -146,21 +145,36 @@ static int color_config_props(AVFilterLink *inlink)
 static int color_request_frame(AVFilterLink *link)
 {
     ColorContext *color = link->src->priv;
-    AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
+    AVFrame *frame = ff_get_video_buffer(link, color->w, color->h);
 
-    if (!picref)
+    if (!frame)
         return AVERROR(ENOMEM);
 
-    picref->video->pixel_aspect = (AVRational) {1, 1};
-    picref->pts                 = color->pts++;
-    picref->pos                 = -1;
+    frame->sample_aspect_ratio = (AVRational) {1, 1};
+    frame->pts                 = color->pts++;
 
-    ff_draw_rectangle(picref->data, picref->linesize,
+    ff_draw_rectangle(frame->data, frame->linesize,
                       color->line, color->line_step, color->hsub, color->vsub,
                       0, 0, color->w, color->h);
-    return ff_filter_frame(link, picref);
+    return ff_filter_frame(link, frame);
 }
 
+#define OFFSET(x) offsetof(ColorContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption options[] = {
+    { "color",     "Output video color",                         OFFSET(color_str),     AV_OPT_TYPE_STRING, { .str = "black"   }, .flags = FLAGS },
+    { "size",      "Output video size (wxh or an abbreviation)", OFFSET(size_str),      AV_OPT_TYPE_STRING, { .str = "320x240" }, .flags = FLAGS },
+    { "framerate", "Output video framerate",                     OFFSET(framerate_str), AV_OPT_TYPE_STRING, { .str = "25"      }, .flags = FLAGS },
+    { NULL },
+};
+
+static const AVClass color_class = {
+    .class_name = "color",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 static const AVFilterPad avfilter_vsrc_color_outputs[] = {
     {
         .name          = "default",
@@ -171,10 +185,11 @@ static const AVFilterPad avfilter_vsrc_color_outputs[] = {
     { NULL }
 };
 
-AVFilter avfilter_vsrc_color = {
+AVFilter ff_vsrc_color = {
     .name        = "color",
     .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]"),
 
+    .priv_class = &color_class,
     .priv_size = sizeof(ColorContext),
     .init      = color_init,
     .uninit    = color_uninit,