[FFmpeg-devel] [PATCH] lavfi/lut: duplicate class definitions for each lut variant filter

Stefano Sabatini stefasab at gmail.com
Mon Aug 13 13:45:16 CEST 2012


This is due to the design of components iteration through AVClass
child_class_next() callback, which requires that two components cannot
share the same class.
---
 libavfilter/vf_lut.c |   99 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 73 insertions(+), 26 deletions(-)

diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index a9b9e8a..4b7d305 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -76,7 +76,7 @@ typedef struct {
 
 #define OFFSET(x) offsetof(LutContext, x)
 
-static const AVOption lut_options[] = {
+static const AVOption options[] = {
     {"c0", "set component #0 expression", OFFSET(comp_expr_str[0]),  AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
     {"c1", "set component #1 expression", OFFSET(comp_expr_str[1]),  AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
     {"c2", "set component #2 expression", OFFSET(comp_expr_str[2]),  AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
@@ -91,24 +91,6 @@ static const AVOption lut_options[] = {
     {NULL},
 };
 
-AVFILTER_DEFINE_CLASS(lut);
-
-static int init(AVFilterContext *ctx, const char *args)
-{
-    LutContext *lut = ctx->priv;
-    int ret;
-
-    lut->class = &lut_class;
-    av_opt_set_defaults(lut);
-
-    lut->is_rgb = !strcmp(ctx->filter->name, "lutrgb");
-    lut->is_yuv = !strcmp(ctx->filter->name, "lutyuv");
-    if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0)
-        return ret;
-
-    return 0;
-}
-
 static av_cold void uninit(AVFilterContext *ctx)
 {
     LutContext *lut = ctx->priv;
@@ -348,32 +330,94 @@ static const AVFilterPad outputs[] = {
       .type            = AVMEDIA_TYPE_VIDEO, },
     { .name = NULL}
 };
-#define DEFINE_LUT_FILTER(name_, description_, init_)                   \
+#define DEFINE_LUT_FILTER(name_, description_)                          \
     AVFilter avfilter_vf_##name_ = {                                    \
         .name          = #name_,                                        \
         .description   = NULL_IF_CONFIG_SMALL(description_),            \
         .priv_size     = sizeof(LutContext),                            \
                                                                         \
-        .init          = init_,                                         \
+        .init          = name_##_init,                                  \
         .uninit        = uninit,                                        \
         .query_formats = query_formats,                                 \
                                                                         \
         .inputs        = inputs,                                        \
         .outputs       = outputs,                                       \
+        .priv_class    = &name_##_class,                                \
     }
 
 #if CONFIG_LUT_FILTER
-DEFINE_LUT_FILTER(lut,    "Compute and apply a lookup table to the RGB/YUV input video.", init);
+
+#define lut_options options
+AVFILTER_DEFINE_CLASS(lut);
+
+static int lut_init(AVFilterContext *ctx, const char *args)
+{
+    LutContext *lut = ctx->priv;
+    int ret;
+
+    lut->class = &lut_class;
+    av_opt_set_defaults(lut);
+
+    if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0)
+        return ret;
+
+    return 0;
+}
+
+DEFINE_LUT_FILTER(lut, "Compute and apply a lookup table to the RGB/YUV input video.");
 #endif
+
 #if CONFIG_LUTYUV_FILTER
-DEFINE_LUT_FILTER(lutyuv, "Compute and apply a lookup table to the YUV input video.",     init);
+
+#define lutyuv_options options
+AVFILTER_DEFINE_CLASS(lutyuv);
+
+static int lutyuv_init(AVFilterContext *ctx, const char *args)
+{
+    LutContext *lut = ctx->priv;
+    int ret;
+
+    lut->class = &lutyuv_class;
+    lut->is_yuv = 1;
+    av_opt_set_defaults(lut);
+
+    if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0)
+        return ret;
+
+    return 0;
+}
+
+DEFINE_LUT_FILTER(lutyuv, "Compute and apply a lookup table to the YUV input video.");
 #endif
+
 #if CONFIG_LUTRGB_FILTER
-DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input video.",     init);
+
+#define lutrgb_options options
+AVFILTER_DEFINE_CLASS(lutrgb);
+
+static int lutrgb_init(AVFilterContext *ctx, const char *args)
+{
+    LutContext *lut = ctx->priv;
+    int ret;
+
+    lut->class = &lutrgb_class;
+    lut->is_rgb = 1;
+    av_opt_set_defaults(lut);
+
+    if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0)
+        return ret;
+
+    return 0;
+}
+
+DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input video.");
 #endif
 
 #if CONFIG_NEGATE_FILTER
 
+#define negate_options options
+AVFILTER_DEFINE_CLASS(negate);
+
 static int negate_init(AVFilterContext *ctx, const char *args)
 {
     LutContext *lut = ctx->priv;
@@ -387,9 +431,12 @@ static int negate_init(AVFilterContext *ctx, const char *args)
     snprintf(lut_params, sizeof(lut_params), "c0=negval:c1=negval:c2=negval:a=%s",
              lut->negate_alpha ? "negval" : "val");
 
-    return init(ctx, lut_params);
+    lut->class = &negate_class;
+    av_opt_set_defaults(lut);
+
+    return av_set_options_string(lut, lut_params, "=", ":");
 }
 
-DEFINE_LUT_FILTER(negate, "Negate input video.", negate_init);
+DEFINE_LUT_FILTER(negate, "Negate input video.");
 
 #endif
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list