Add avfilter_graph_create_filter().
authorStefano Sabatini <stefano.sabatini-lala@poste.it>
Thu, 2 Dec 2010 20:12:27 +0000 (20:12 +0000)
committerStefano Sabatini <stefano.sabatini-lala@poste.it>
Thu, 2 Dec 2010 20:12:27 +0000 (20:12 +0000)
Originally committed as revision 25862 to svn://svn.ffmpeg.org/ffmpeg/trunk

doc/APIchanges
ffmpeg.c
ffplay.c
libavfilter/avfilter.h
libavfilter/avfiltergraph.c
libavfilter/avfiltergraph.h

index c031622..ebd5faa 100644 (file)
@@ -12,6 +12,9 @@ libavutil:   2009-03-08
 
 
 API changes, most recent first:
+2010-12-02 - r25862 - lavfi 1.67.0 - avfilter_graph_create_filter()
+  Add function avfilter_graph_create_filter() in avfiltergraph.h.
+
 2010-11-25 - r25826 - lavfi 1.65.0 - avfilter_get_video_buffer_ref_from_arrays()
   Add function avfilter_get_video_buffer_ref_from_arrays() in
   avfilter.h.
index e58e7b5..96be297 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -356,22 +356,16 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
 
     graph = avfilter_graph_alloc();
 
-    if ((ret = avfilter_open(&ist->input_video_filter, avfilter_get_by_name("buffer"), "src")) < 0)
-        return ret;
-    if ((ret = avfilter_open(&ist->output_video_filter, &ffsink, "out")) < 0)
-        return ret;
-
     snprintf(args, 255, "%d:%d:%d:%d:%d", ist->st->codec->width,
              ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE);
-    if ((ret = avfilter_init_filter(ist->input_video_filter, args, NULL)) < 0)
+    ret = avfilter_graph_create_filter(&ist->input_video_filter, avfilter_get_by_name("buffer"),
+                                       "src", args, NULL, graph);
+    if (ret < 0)
         return ret;
-    if ((ret = avfilter_init_filter(ist->output_video_filter, NULL, &ffsink_ctx)) < 0)
+    ret = avfilter_graph_create_filter(&ist->output_video_filter, &ffsink,
+                                       "out", NULL, &ffsink_ctx, graph);
+    if (ret < 0)
         return ret;
-
-    /* add input and output filters to the overall graph */
-    avfilter_graph_add_filter(graph, ist->input_video_filter);
-    avfilter_graph_add_filter(graph, ist->output_video_filter);
-
     last_filter = ist->input_video_filter;
 
     if (codec->width  != icodec->width || codec->height != icodec->height) {
@@ -379,14 +373,12 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
                  codec->width,
                  codec->height,
                  (int)av_get_int(sws_opts, "sws_flags", NULL));
-        if ((ret = avfilter_open(&filter, avfilter_get_by_name("scale"), NULL)) < 0)
-            return ret;
-        if ((ret = avfilter_init_filter(filter, args, NULL)) < 0)
+        if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
+                                                NULL, args, NULL, graph)) < 0)
             return ret;
         if ((ret = avfilter_link(last_filter, 0, filter, 0)) < 0)
             return ret;
         last_filter = filter;
-        avfilter_graph_add_filter(graph, last_filter);
     }
 
     snprintf(args, sizeof(args), "flags=0x%X", (int)av_get_int(sws_opts, "sws_flags", NULL));
index d478bcb..38a2fe1 100644 (file)
--- a/ffplay.c
+++ b/ffplay.c
@@ -1798,12 +1798,12 @@ static int video_thread(void *arg)
     snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%d", sws_flags);
     graph->scale_sws_opts = av_strdup(sws_flags_str);
 
-    if (avfilter_open(&filt_src, &input_filter,  "src") < 0) goto the_end;
-    if (avfilter_open(&filt_out, &ffsink      ,  "out") < 0) goto the_end;
-
-    if(avfilter_init_filter(filt_src, NULL, is))             goto the_end;
-    if(avfilter_init_filter(filt_out, NULL, &ffsink_ctx))    goto the_end;
-
+    if (avfilter_graph_create_filter(&filt_src, &input_filter, "src",
+                                     NULL, is, graph) < 0)
+        goto the_end;
+    if (avfilter_graph_create_filter(&filt_out, &ffsink, "out",
+                                     NULL, &ffsink_ctx, graph) < 0)
+        goto the_end;
 
     if(vfilters) {
         AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut));
@@ -1825,8 +1825,6 @@ static int video_thread(void *arg)
     } else {
         if(avfilter_link(filt_src, 0, filt_out, 0) < 0)          goto the_end;
     }
-    avfilter_graph_add_filter(graph, filt_src);
-    avfilter_graph_add_filter(graph, filt_out);
 
     if (avfilter_graph_config(graph, NULL) < 0)
         goto the_end;
index f7aaf7f..4dea653 100644 (file)
@@ -25,7 +25,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  1
-#define LIBAVFILTER_VERSION_MINOR 66
+#define LIBAVFILTER_VERSION_MINOR 67
 #define LIBAVFILTER_VERSION_MICRO  0
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
index 97dd120..8a25891 100644 (file)
@@ -53,6 +53,27 @@ int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
     return 0;
 }
 
+int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
+                                 const char *name, const char *args, void *opaque,
+                                 AVFilterGraph *graph_ctx)
+{
+    int ret;
+
+    if ((ret = avfilter_open(filt_ctx, filt, name)) < 0)
+        goto fail;
+    if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0)
+        goto fail;
+    if ((ret = avfilter_graph_add_filter(graph_ctx, *filt_ctx)) < 0)
+        goto fail;
+    return 0;
+
+fail:
+    if (*filt_ctx)
+        avfilter_free(*filt_ctx);
+    *filt_ctx = NULL;
+    return ret;
+}
+
 int ff_avfilter_graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx)
 {
     AVFilterContext *filt;
@@ -113,7 +134,7 @@ AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name)
 
 static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
 {
-    int i, j;
+    int i, j, ret;
     int scaler_count = 0;
     char inst_name[30];
 
@@ -139,17 +160,12 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
                     /* couldn't merge format lists. auto-insert scale filter */
                     snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d",
                              scaler_count++);
-                    avfilter_open(&scale, avfilter_get_by_name("scale"), inst_name);
-
                     snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts);
-                    if(!scale || scale->filter->init(scale, scale_args, NULL) ||
-                                 avfilter_insert_filter(link, scale, 0, 0)) {
-                        avfilter_free(scale);
-                        return -1;
-                    }
-
-                    if (avfilter_graph_add_filter(graph, scale) < 0)
-                        return -1;
+                    if ((ret = avfilter_graph_create_filter(&scale, avfilter_get_by_name("scale"),
+                                                            inst_name, scale_args, NULL, graph)) < 0)
+                        return ret;
+                    if ((ret = avfilter_insert_filter(link, scale, 0, 0)) < 0)
+                        return ret;
 
                     scale->filter->query_formats(scale);
                     if (((link = scale-> inputs[0]) &&
index ca369aa..74d7a12 100644 (file)
@@ -53,6 +53,23 @@ AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
 int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
 
 /**
+ * Create and add a filter instance into an existing graph.
+ * The filter instance is created from the filter filt and inited
+ * with the parameters args and opaque.
+ *
+ * In case of success put in *filt_ctx the pointer to the created
+ * filter instance, otherwise set *filt_ctx to NULL.
+ *
+ * @param name the instance name to give to the created filter instance
+ * @param graph_ctx the filter graph
+ * @return a negative AVERROR error code in case of failure, a non
+ * negative value otherwise
+ */
+int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
+                                 const char *name, const char *args, void *opaque,
+                                 AVFilterGraph *graph_ctx);
+
+/**
  * Check validity and configure all the links and formats in the graph.
  *
  * @param graphctx the filter graph