[FFmpeg-devel] [PATCH] lavfi: add avfilter_get_class() and iteration callbacks
Stefano Sabatini
stefasab at gmail.com
Thu Aug 9 22:58:21 CEST 2012
Allow iteration over specific filter options.
---
libavfilter/avfilter.c | 31 +++++++++++++++++++++++++++++++
libavfilter/avfilter.h | 6 ++++++
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index c698d8a..e5935cd 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -432,13 +432,44 @@ static const char *default_filter_name(void *filter_ctx)
return ctx->name ? ctx->name : ctx->filter->name;
}
+static void *filter_child_next(void *obj, void *prev)
+{
+ AVFilterContext *ctx = obj;
+ if (!prev && ctx->filter && ctx->filter->priv_class && ctx->priv)
+ return ctx->priv;
+ return NULL;
+}
+
+static const AVClass *filter_child_class_next(const AVClass *prev)
+{
+ AVFilter **filter_ptr = NULL;
+
+ /* find the filter that corresponds to prev */
+ while (prev && (filter_ptr = av_filter_next(filter_ptr)))
+ if ((*filter_ptr)->priv_class == prev)
+ break;
+
+ /* find next filter with specific options */
+ while (*(filter_ptr = av_filter_next(filter_ptr)))
+ if ((*filter_ptr)->priv_class)
+ return (*filter_ptr)->priv_class;
+ return NULL;
+}
+
static const AVClass avfilter_class = {
.class_name = "AVFilter",
.item_name = default_filter_name,
.version = LIBAVUTIL_VERSION_INT,
.category = AV_CLASS_CATEGORY_FILTER,
+ .child_next = filter_child_next,
+ .child_class_next = filter_child_class_next,
};
+const AVClass *avfilter_get_class(void)
+{
+ return &avfilter_class;
+}
+
int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
{
AVFilterContext *ret;
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 54a0b97..07bc5a9 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -47,6 +47,10 @@ const char *avfilter_configuration(void);
*/
const char *avfilter_license(void);
+/**
+ * Get the class for the AVFilterContext struct.
+ */
+const AVClass *avfilter_get_class(void);
typedef struct AVFilterContext AVFilterContext;
typedef struct AVFilterLink AVFilterLink;
@@ -469,6 +473,8 @@ typedef struct AVFilter {
* used for providing binary data.
*/
int (*init_opaque)(AVFilterContext *ctx, const char *args, void *opaque);
+
+ const AVClass *priv_class; ///< private class, containing filter specific options
} AVFilter;
/** An instance of a filter */
--
1.7.5.4
More information about the ffmpeg-devel
mailing list