[FFmpeg-cvslog] lavfi: change the filter registering system to match the other libraries

Anton Khirnov git at videolan.org
Fri Apr 12 15:14:14 CEST 2013


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Apr  3 09:20:36 2013 +0200| [fa2a34cd40d124161c748bb0f430dc63c94dd0da] | committer: Anton Khirnov

lavfi: change the filter registering system to match the other libraries

Removes an arbitrary hardcoded limit on the number of filters.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fa2a34cd40d124161c748bb0f430dc63c94dd0da
---

 avconv.c               |    1 -
 avplay.c               |    3 ---
 cmdutils.c             |    6 +++---
 doc/APIchanges         |    2 ++
 libavfilter/avfilter.c |   46 ++++++++++++++++++++++++----------------------
 libavfilter/avfilter.h |   16 ++++++++++++++++
 libavfilter/version.h  |    3 +++
 7 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/avconv.c b/avconv.c
index 6e3ee0f..658dadc 100644
--- a/avconv.c
+++ b/avconv.c
@@ -211,7 +211,6 @@ static void exit_program(void)
 
     uninit_opts();
 
-    avfilter_uninit();
     avformat_network_deinit();
 
     if (received_sigterm) {
diff --git a/avplay.c b/avplay.c
index 4b7576c..018f63d 100644
--- a/avplay.c
+++ b/avplay.c
@@ -1246,9 +1246,6 @@ static void do_exit(void)
         cur_stream = NULL;
     }
     uninit_opts();
-#if CONFIG_AVFILTER
-    avfilter_uninit();
-#endif
     avformat_network_deinit();
     if (show_status)
         printf("\n");
diff --git a/cmdutils.c b/cmdutils.c
index ff4b027..7084fae 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -1130,12 +1130,12 @@ int show_protocols(void *optctx, const char *opt, const char *arg)
 
 int show_filters(void *optctx, const char *opt, const char *arg)
 {
-    AVFilter av_unused(**filter) = NULL;
+    const AVFilter av_unused(*filter) = NULL;
 
     printf("Filters:\n");
 #if CONFIG_AVFILTER
-    while ((filter = av_filter_next(filter)) && *filter)
-        printf("%-16s %s\n", (*filter)->name, (*filter)->description);
+    while ((filter = avfilter_next(filter)))
+        printf("%-16s %s\n", filter->name, filter->description);
 #endif
     return 0;
 }
diff --git a/doc/APIchanges b/doc/APIchanges
index 106f912..4fc2022 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -24,6 +24,8 @@ API changes, most recent first:
   Add avfilter_init_dict().
   Add AVFilter.flags field and AVFILTER_FLAG_DYNAMIC_{INPUTS,OUTPUTS} flags.
   Add avfilter_pad_count() for counting filter inputs/outputs.
+  Add avfilter_next(), deprecate av_filter_next().
+  Deprecate avfilter_uninit().
 
 2013-xx-xx - lavfi 3.7.0 - avfilter.h
   Add AVFilter.priv_class for exporting filter options through the AVOptions API
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index a707c0d..199d8f9 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -267,42 +267,44 @@ int ff_poll_frame(AVFilterLink *link)
     return min;
 }
 
-#define MAX_REGISTERED_AVFILTERS_NB 64
-
-static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
-
-static int next_registered_avfilter_idx = 0;
+static AVFilter *first_filter;
 
 AVFilter *avfilter_get_by_name(const char *name)
 {
-    int i;
+    AVFilter *f = NULL;
 
-    for (i = 0; registered_avfilters[i]; i++)
-        if (!strcmp(registered_avfilters[i]->name, name))
-            return registered_avfilters[i];
+    while ((f = avfilter_next(f)))
+        if (!strcmp(f->name, name))
+            return f;
 
     return NULL;
 }
 
 int avfilter_register(AVFilter *filter)
 {
-    if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB)
-        return -1;
-
-    registered_avfilters[next_registered_avfilter_idx++] = filter;
+    AVFilter **f = &first_filter;
+    while (*f)
+        f = &(*f)->next;
+    *f = filter;
+    filter->next = NULL;
     return 0;
 }
 
+const AVFilter *avfilter_next(const AVFilter *prev)
+{
+    return prev ? prev->next : first_filter;
+}
+
+#if FF_API_OLD_FILTER_REGISTER
 AVFilter **av_filter_next(AVFilter **filter)
 {
-    return filter ? ++filter : &registered_avfilters[0];
+    return filter ? &(*filter)->next : &first_filter;
 }
 
 void avfilter_uninit(void)
 {
-    memset(registered_avfilters, 0, sizeof(registered_avfilters));
-    next_registered_avfilter_idx = 0;
 }
+#endif
 
 int avfilter_pad_count(const AVFilterPad *pads)
 {
@@ -331,15 +333,15 @@ static void *filter_child_next(void *obj, void *prev)
 
 static const AVClass *filter_child_class_next(const AVClass *prev)
 {
-    AVFilter **f = NULL;
+    AVFilter *f = NULL;
 
-    while (prev && *(f = av_filter_next(f)))
-        if ((*f)->priv_class == prev)
+    while (prev && (f = avfilter_next(f)))
+        if (f->priv_class == prev)
             break;
 
-    while (*(f = av_filter_next(f)))
-        if ((*f)->priv_class)
-            return (*f)->priv_class;
+    while ((f = avfilter_next(f)))
+        if (f->priv_class)
+            return f->priv_class;
 
     return NULL;
 }
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 73dbd88..51d0fb5 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -457,6 +457,8 @@ typedef struct AVFilter {
     int (*query_formats)(AVFilterContext *);
 
     int priv_size;      ///< size of private data to allocate for the filter
+
+    struct AVFilter *next;
 } AVFilter;
 
 /** An instance of a filter */
@@ -622,8 +624,11 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
 /** Initialize the filter system. Register all builtin filters. */
 void avfilter_register_all(void);
 
+#if FF_API_OLD_FILTER_REGISTER
 /** Uninitialize the filter system. Unregister all filters. */
+attribute_deprecated
 void avfilter_uninit(void);
+#endif
 
 /**
  * Register a filter. This is only needed if you plan to use
@@ -647,12 +652,23 @@ int avfilter_register(AVFilter *filter);
 AVFilter *avfilter_get_by_name(const char *name);
 
 /**
+ * Iterate over all registered filters.
+ * @return If prev is non-NULL, next registered filter after prev or NULL if
+ * prev is the last filter. If prev is NULL, return the first registered filter.
+ */
+const AVFilter *avfilter_next(const AVFilter *prev);
+
+#if FF_API_OLD_FILTER_REGISTER
+/**
  * If filter is NULL, returns a pointer to the first registered filter pointer,
  * if filter is non-NULL, returns the next pointer after filter.
  * If the returned pointer points to NULL, the last registered filter
  * was already reached.
+ * @deprecated use avfilter_next()
  */
+attribute_deprecated
 AVFilter **av_filter_next(AVFilter **filter);
+#endif
 
 #if FF_API_AVFILTER_OPEN
 /**
diff --git a/libavfilter/version.h b/libavfilter/version.h
index f58a9d5..36a03f7 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -64,5 +64,8 @@
 #ifndef FF_API_AVFILTER_INIT_FILTER
 #define FF_API_AVFILTER_INIT_FILTER         (LIBAVFILTER_VERSION_MAJOR < 4)
 #endif
+#ifndef FF_API_OLD_FILTER_REGISTER
+#define FF_API_OLD_FILTER_REGISTER          (LIBAVFILTER_VERSION_MAJOR < 4)
+#endif
 
 #endif /* AVFILTER_VERSION_H */



More information about the ffmpeg-cvslog mailing list