[FFmpeg-soc] [soc]: r574 - in libavfilter: allfilters.h avfilter.c avfiltergraph.c avfiltergraph.h filter_test.c

koorogi subversion at mplayerhq.hu
Tue Jul 31 22:08:38 CEST 2007


Author: koorogi
Date: Tue Jul 31 22:08:38 2007
New Revision: 574

Log:
Make the filter graph just another normal filter.


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

Modified: libavfilter/allfilters.h
==============================================================================
--- libavfilter/allfilters.h	(original)
+++ libavfilter/allfilters.h	Tue Jul 31 22:08:38 2007
@@ -24,6 +24,7 @@
 extern AVFilter vsrc_dummy;
 extern AVFilter vsrc_ppm;
 extern AVFilter vf_crop;
+extern AVFilter vf_graph;
 extern AVFilter vf_passthrough;
 extern AVFilter vf_rgb2bgr;
 extern AVFilter vf_slicify;

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Tue Jul 31 22:08:38 2007
@@ -283,6 +283,7 @@ void avfilter_init(void)
     avfilter_register(&vsrc_dummy);
     avfilter_register(&vsrc_ppm);
     avfilter_register(&vf_crop);
+    avfilter_register(&vf_graph);
     avfilter_register(&vf_passthrough);
     avfilter_register(&vf_rgb2bgr);
     avfilter_register(&vf_slicify);

Modified: libavfilter/avfiltergraph.c
==============================================================================
--- libavfilter/avfiltergraph.c	(original)
+++ libavfilter/avfiltergraph.c	Tue Jul 31 22:08:38 2007
@@ -26,31 +26,24 @@
 #include "avfilter.h"
 #include "avfiltergraph.h"
 
-struct AVFilterGraph {
+typedef struct AVFilterGraph {
     unsigned filter_count;
     AVFilterContext **filters;
-};
+} GraphContext;
 
-AVFilterGraph *avfilter_create_graph(void)
+static void uninit(AVFilterContext *ctx)
 {
-    return av_mallocz(sizeof(AVFilterGraph));
-}
+    GraphContext *graph = ctx->priv;
 
-static void destroy_graph_filters(AVFilterGraph *graph)
-{
     for(; graph->filter_count > 0; graph->filter_count --)
         avfilter_destroy(graph->filters[graph->filter_count - 1]);
     av_freep(&graph->filters);
 }
 
-void avfilter_destroy_graph(AVFilterGraph *graph)
+void avfilter_graph_add_filter(AVFilterContext *graphctx, AVFilterContext *filter)
 {
-    destroy_graph_filters(graph);
-    av_free(graph);
-}
+    GraphContext *graph = graphctx->priv;
 
-void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
-{
     graph->filters = av_realloc(graph->filters,
                                 sizeof(AVFilterContext*) * ++graph->filter_count);
     graph->filters[graph->filter_count - 1] = filter;
@@ -89,7 +82,7 @@ fail:
     return NULL;
 }
 
-int avfilter_graph_load_chain(AVFilterGraph *graph,
+static int graph_load_chain(AVFilterContext *graphctx,
                               unsigned count, char **filter_list, void **opaque,
                               AVFilterContext **first, AVFilterContext **last)
 {
@@ -112,7 +105,7 @@ int avfilter_graph_load_chain(AVFilterGr
                 goto fail;
             }
         }
-        avfilter_graph_add_filter(graph, filters[1]);
+        avfilter_graph_add_filter(graphctx, filters[1]);
         filters[0] = filters[1];
     }
 
@@ -120,9 +113,68 @@ int avfilter_graph_load_chain(AVFilterGr
     return 0;
 
 fail:
-    destroy_graph_filters(graph);
+    uninit(graphctx);
     if(first) *first = NULL;
     if(last)  *last  = NULL;
     return -1;
 }
 
+static int graph_load_chain_from_string(AVFilterContext *ctx, const char *str,
+                                        AVFilterContext **first,
+                                        AVFilterContext **last)
+{
+    int count, ret = 0;
+    char **strings;
+    char *filt;
+
+    strings    = av_malloc(sizeof(char *));
+    strings[0] = av_strdup(str);
+
+    filt = strchr(strings[0], ',');
+    for(count = 1; filt; count ++) {
+        if(filt == strings[count-1]) {
+            ret = -1;
+            goto done;
+        }
+
+        strings = av_realloc(strings, sizeof(char *) * (count+1));
+        strings[count] = filt + 1;
+        *filt = '\0';
+        filt = strchr(strings[count], ',');
+    }
+
+    ret = graph_load_chain(ctx, count, strings, NULL, first, last);
+
+done:
+    av_free(strings[0]);
+    av_free(strings);
+
+    return ret;
+}
+
+static int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+    AVFilterContext **filters = opaque;
+
+    if(!args)
+        return 0;
+    if(!opaque)
+        return -1;
+
+    return graph_load_chain_from_string(ctx, args, filters, filters + 1);
+}
+
+AVFilter vf_graph =
+{
+    .name      = "graph",
+    .author    = "Bobby Bingham",
+
+    .priv_size = sizeof(GraphContext),
+
+    .init      = init,
+    .uninit    = uninit,
+
+    .inputs    = (AVFilterPad[]) {{ .name = NULL, }},
+    .outputs   = (AVFilterPad[]) {{ .name = NULL, }},
+};
+

Modified: libavfilter/avfiltergraph.h
==============================================================================
--- libavfilter/avfiltergraph.h	(original)
+++ libavfilter/avfiltergraph.h	Tue Jul 31 22:08:38 2007
@@ -24,37 +24,11 @@
 
 #include "avfilter.h"
 
-typedef struct AVFilterGraph AVFilterGraph;
-
-/**
- * Create a new filter graph
- */
-AVFilterGraph *avfilter_create_graph(void);
-
-/**
- * Destroy a filter graph, and any filters in it.
- * @param graph The filter graph to destroy
- */
-void avfilter_destroy_graph(AVFilterGraph *graph);
-
 /**
  * Add an existing filter instance to a filter graph.
  * @param graph  The filter graph
  * @param filter The filter to be added
  */
-void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter);
+void avfilter_graph_add_filter(AVFilterContext *graphctx, 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, void **opaque,
-                              AVFilterContext **first, AVFilterContext **last);
 #endif  /* FFMPEG_AVFILTER_H */

Modified: libavfilter/filter_test.c
==============================================================================
--- libavfilter/filter_test.c	(original)
+++ libavfilter/filter_test.c	Tue Jul 31 22:08:38 2007
@@ -31,21 +31,21 @@ int main(int argc, char **argv)
     int i;
     int ret = -1;
     int64_t pts = 0, newpts;
-    AVFilterGraph   *graph;
-    AVFilterContext *out;
+    AVFilterContext *graph;
+    AVFilterContext *filters[2];
 
-    if(argc < 3) {
-        av_log(NULL, AV_LOG_ERROR, "require at least two filters\n");
+    if(argc < 2) {
+        av_log(NULL, AV_LOG_ERROR, "require a list of filters\n");
         return -1;
     }
 
     avfilter_init();
-    graph = avfilter_create_graph();
-    if(avfilter_graph_load_chain(graph, argc - 1, argv + 1, NULL, NULL, &out) < 0)
+    graph = avfilter_create_by_name("graph", NULL);
+    if(avfilter_init_filter(graph, argv[1], filters) < 0)
         goto done;
 
     while(pts < 5000) {
-        newpts = sdl_display(out);
+        newpts = sdl_display(filters[1]);
         usleep(newpts - pts);
         pts = newpts;
     }
@@ -53,7 +53,7 @@ int main(int argc, char **argv)
     ret = 0;
 
 done:
-    avfilter_destroy_graph(graph);
+    avfilter_destroy(graph);
 
     return ret;
 }



More information about the FFmpeg-soc mailing list