[FFmpeg-cvslog] r20605 - in trunk/libavfilter: avfilter.c avfilter.h

stefano subversion
Wed Nov 25 00:47:34 CET 2009


Author: stefano
Date: Wed Nov 25 00:47:33 2009
New Revision: 20605

Log:
Implement a new registration system for filters.

Create a new static array containing pointers to the AVFilter
definitions, so that the non-constant next filter in the AVFilter
struct is not anymore required and the AVFilter definitions may be
stored in shareable memory.

Also change the signature for avfilter_register(), make it return an
int since it may fail if there is not enough space in the static array
for the registered filters.

Modified:
   trunk/libavfilter/avfilter.c
   trunk/libavfilter/avfilter.h

Modified: trunk/libavfilter/avfilter.c
==============================================================================
--- trunk/libavfilter/avfilter.c	Wed Nov 25 00:38:20 2009	(r20604)
+++ trunk/libavfilter/avfilter.c	Wed Nov 25 00:47:33 2009	(r20605)
@@ -328,33 +328,36 @@ void avfilter_draw_slice(AVFilterLink *l
     draw_slice(link, y, h);
 }
 
-AVFilter *first_avfilter = NULL;
+#define MAX_REGISTERED_AVFILTERS_NB 64
+
+static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
+
+static int next_registered_avfilter_idx = 0;
 
 AVFilter *avfilter_get_by_name(const char *name)
 {
-    AVFilter *filter;
+    int i;
 
-    for (filter = first_avfilter; filter; filter = filter->next)
-        if (!strcmp(filter->name, name))
-            return filter;
+    for (i = 0; registered_avfilters[i]; i++)
+        if (!strcmp(registered_avfilters[i]->name, name))
+            return registered_avfilters[i];
 
     return NULL;
 }
 
-void avfilter_register(AVFilter *filter)
+int avfilter_register(AVFilter *filter)
 {
-    AVFilter **p;
-    p = &first_avfilter;
-    while (*p)
-        p = &(*p)->next;
+    if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB)
+        return -1;
 
-    *p = filter;
-    filter->next = NULL;
+    registered_avfilters[next_registered_avfilter_idx++] = filter;
+    return 0;
 }
 
 void avfilter_uninit(void)
 {
-    first_avfilter = NULL;
+    memset(registered_avfilters, 0, sizeof(registered_avfilters));
+    next_registered_avfilter_idx = 0;
 }
 
 static int pad_count(const AVFilterPad *pads)

Modified: trunk/libavfilter/avfilter.h
==============================================================================
--- trunk/libavfilter/avfilter.h	Wed Nov 25 00:38:20 2009	(r20604)
+++ trunk/libavfilter/avfilter.h	Wed Nov 25 00:47:33 2009	(r20605)
@@ -25,7 +25,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  1
-#define LIBAVFILTER_VERSION_MINOR  8
+#define LIBAVFILTER_VERSION_MINOR  9
 #define LIBAVFILTER_VERSION_MICRO  0
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
@@ -581,8 +581,10 @@ void avfilter_uninit(void);
  * filter can still by instantiated with avfilter_open even if it is not
  * registered.
  * @param filter the filter to register
+ * @return 0 if the registration was succesfull, a negative value
+ * otherwise
  */
-void avfilter_register(AVFilter *filter);
+int avfilter_register(AVFilter *filter);
 
 /**
  * Gets a filter definition matching the given name.



More information about the ffmpeg-cvslog mailing list