[FFmpeg-soc] [soc]: r423 - in libavfilter: avfiltergraph.c avfiltergraph.h filter_test.c

koorogi subversion at mplayerhq.hu
Sun Jul 15 00:26:37 CEST 2007


Author: koorogi
Date: Sun Jul 15 00:26:37 2007
New Revision: 423

Log:
Move simple filter chain loading code over to the filter graph.


Modified:
   libavfilter/avfiltergraph.c
   libavfilter/avfiltergraph.h
   libavfilter/filter_test.c

Modified: libavfilter/avfiltergraph.c
==============================================================================
--- libavfilter/avfiltergraph.c	(original)
+++ libavfilter/avfiltergraph.c	Sun Jul 15 00:26:37 2007
@@ -19,6 +19,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <string.h>
+#include <stddef.h>
+
 #include "avfilter.h"
 #include "avfiltergraph.h"
 
@@ -54,3 +57,62 @@ void avfilter_graph_add_filter(AVFilterG
     graph->filters[graph->filter_count - 1] = filter;
 }
 
+static AVFilterContext *create_filter_with_args(char *filter)
+{
+    AVFilterContext *ret;
+    char *name, *args;
+
+    name = filter;
+    if((args = strchr(filter, '='))) {
+        /* ensure we at least have a name */
+        if(args == filter)
+            return NULL;
+
+        *args ++ = 0;
+    }
+
+    av_log(NULL, AV_LOG_INFO, "creating filter \"%s\" with args \"%s\"\n",
+           name, args ? args : "(none)");
+
+    if((ret = avfilter_create_by_name(name, NULL))) {
+        if(avfilter_init_filter(ret, args)) {
+            av_log(NULL, AV_LOG_ERROR, "error initializing filter!\n");
+            avfilter_destroy(ret);
+            ret = NULL;
+        }
+    } else av_log(NULL, AV_LOG_ERROR, "error creating filter!\n");
+
+    return ret;
+}
+
+int avfilter_graph_load_chain(AVFilterGraph *graph,
+                              unsigned count, char **filter_list,
+                              AVFilterContext **first, AVFilterContext **last)
+{
+    unsigned i;
+    AVFilterContext *filters[2] = {NULL,NULL};
+
+    for(i = 0; i < count; i ++) {
+        if(!(filters[1] = create_filter_with_args(filter_list[i])))
+            goto fail;
+        if(i == 0) {
+            if(first) *first = filters[1];
+        } else {
+            if(avfilter_link(filters[0], 0, filters[1], 0)) {
+                av_log(NULL, AV_LOG_ERROR, "error linking filters!\n");
+                goto fail;
+            }
+        }
+        avfilter_graph_add_filter(graph, filters[1]);
+        filters[0] = filters[1];
+    }
+
+    if(last) *last = filters[1];
+    return 0;
+
+fail:
+    destroy_graph_filters(graph);
+    *first = *last = NULL;
+    return -1;
+}
+

Modified: libavfilter/avfiltergraph.h
==============================================================================
--- libavfilter/avfiltergraph.h	(original)
+++ libavfilter/avfiltergraph.h	Sun Jul 15 00:26:37 2007
@@ -44,4 +44,17 @@ void avfilter_destroy_graph(AVFilterGrap
  */
 void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter);
 
+/**
+ * Loads the filter graph with a simple chain described by filters.
+ * @param graph   The filter graph to load filters into
+ * @param count   The number of filters to be created
+ * @param filters_list An array of strings describing the filters to be created.
+ *                The format of each string is "name=params".
+ * @param first   If non-NULL, will be set to the first filter in the chain.
+ * @param last    If non-NULL, will be set to the last filter in the chain.
+ * @return 0 on success.  -1 on error.
+ */
+int avfilter_graph_load_chain(AVFilterGraph *graph,
+                              unsigned count, char **filter_list,
+                              AVFilterContext **first, AVFilterContext **last);
 #endif  /* FFMPEG_AVFILTER_H */

Modified: libavfilter/filter_test.c
==============================================================================
--- libavfilter/filter_test.c	(original)
+++ libavfilter/filter_test.c	Sun Jul 15 00:26:37 2007
@@ -20,48 +20,19 @@
  */
 
 #include <unistd.h>
-#include <string.h>
 
 #include "avfilter.h"
 #include "avfiltergraph.h"
 
 int64_t sdl_display(AVFilterContext *ctx);
 
-AVFilterContext *create_filter(char *argv)
-{
-    AVFilterContext *ret;
-    char *name, *args;
-
-    name = argv;
-    if((args = strchr(argv, '='))) {
-        /* ensure we at least have a name */
-        if(args == argv)
-            return NULL;
-
-        *args ++ = 0;
-    }
-
-    av_log(NULL, AV_LOG_INFO, "creating filter \"%s\" with args \"%s\"\n",
-           name, args ? args : "(none)");
-
-    if((ret = avfilter_create_by_name(name, NULL))) {
-        if(avfilter_init_filter(ret, args)) {
-            av_log(NULL, AV_LOG_ERROR, "error initializing filter!\n");
-            avfilter_destroy(ret);
-            ret = NULL;
-        }
-    } else av_log(NULL, AV_LOG_ERROR, "error creating filter!\n");
-
-    return ret;
-}
-
 int main(int argc, char **argv)
 {
     int i;
     int ret = -1;
     int64_t pts = 0, newpts;
     AVFilterGraph   *graph;
-    AVFilterContext *filters[2] = {NULL,NULL};
+    AVFilterContext *out;
 
     if(argc < 3) {
         av_log(NULL, AV_LOG_ERROR, "require at least two filters\n");
@@ -70,20 +41,11 @@ int main(int argc, char **argv)
 
     avfilter_init();
     graph = avfilter_create_graph();
-
-    for(i = 1; i < argc; i ++) {
-        if(!(filters[1] = create_filter(argv[i])))
-            goto done;
-        avfilter_graph_add_filter(graph, filters[1]);
-        if(filters[0] && avfilter_link(filters[0], 0, filters[1], 0)) {
-            av_log(NULL, AV_LOG_ERROR, "error linking filters!\n");
-            goto done;
-        }
-        filters[0] = filters[1];
-    }
+    if(avfilter_graph_load_chain(graph, argc - 1, argv + 1, NULL, &out) < 0)
+        goto done;
 
     while(pts < 5000) {
-        newpts = sdl_display(filters[1]);
+        newpts = sdl_display(out);
         usleep(newpts - pts);
         pts = newpts;
     }



More information about the FFmpeg-soc mailing list