[FFmpeg-devel] [PATCH] lavfi/testsrc: add a macro to create definition of filter class

Stefano Sabatini stefasab at gmail.com
Wed Aug 1 11:05:27 CEST 2012


The macro is similar to AVFILTER_DEFINE_MACRO, which can't be used
because the filters in the file share the same options.

Factorize.
---
 libavfilter/vsrc_testsrc.c |   37 ++++++++++++++-----------------------
 1 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index 6699aaa..3fbf472 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -68,7 +68,7 @@ typedef struct {
 
 #define OFFSET(x) offsetof(TestSourceContext, x)
 
-static const AVOption testsrc_options[]= {
+static const AVOption options[] = {
     { "size",     "set video size",     OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
     { "s",        "set video size",     OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
     { "rate",     "set video rate",     OFFSET(rate),     AV_OPT_TYPE_STRING, {.str = "25"},      0, 0 },
@@ -203,15 +203,18 @@ static int request_frame(AVFilterLink *outlink)
     return 0;
 }
 
+#define DEFINE_CLASS(fname)                     \
+    static const AVClass fname##_class = {      \
+        .class_name = #fname,                   \
+        .item_name  = av_default_item_name,     \
+        .option     = options,                  \
+        .version    = LIBAVUTIL_VERSION_INT,    \
+        .category   = AV_CLASS_CATEGORY_FILTER, \
+    }
+
 #if CONFIG_NULLSRC_FILTER
 
-static const AVClass nullsrc_class = {
-    .class_name = "nullsrc",
-    .item_name  = av_default_item_name,
-    .option     = testsrc_options,
-    .version    = LIBAVUTIL_VERSION_INT,
-    .category   = AV_CLASS_CATEGORY_FILTER,
-};
+DEFINE_CLASS(nullsrc);
 
 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { }
 
@@ -243,7 +246,7 @@ AVFilter avfilter_vsrc_nullsrc = {
 
 #if CONFIG_TESTSRC_FILTER
 
-AVFILTER_DEFINE_CLASS(testsrc);
+DEFINE_CLASS(testsrc);
 
 /**
  * Fill a rectangle with value val.
@@ -462,13 +465,7 @@ AVFilter avfilter_vsrc_testsrc = {
 
 #if CONFIG_RGBTESTSRC_FILTER
 
-static const AVClass rgbtestsrc_class = {
-    .class_name = "rgbtestsrc",
-    .item_name  = av_default_item_name,
-    .option     = testsrc_options,
-    .version    = LIBAVUTIL_VERSION_INT,
-    .category   = AV_CLASS_CATEGORY_FILTER,
-};
+DEFINE_CLASS(rgbtestsrc);
 
 #define R 0
 #define G 1
@@ -588,13 +585,7 @@ AVFilter avfilter_vsrc_rgbtestsrc = {
 
 #if CONFIG_COLOR_FILTER
 
-static const AVClass color_class = {
-    .class_name = "color",
-    .item_name  = av_default_item_name,
-    .option     = testsrc_options,
-    .version    = LIBAVUTIL_VERSION_INT,
-    .category   = AV_CLASS_CATEGORY_FILTER,
-};
+DEFINE_CLASS(color);
 
 static void color_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
 {
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list