[FFmpeg-devel] [PATCH] lavfi: create Libav-API compatibility layer for avfilter_graph_parse() at the next bump

Stefano Sabatini stefasab at gmail.com
Tue Jul 2 01:48:48 CEST 2013


Add function avfilter_graph_parse_ptr() and favor it in place of
avfilter_graph_parse(), which will be restored with the old/Libav
signature at the next bump.

If HAVE_INCOMPATIBLE_LIBAV_API is enabled it will use the
Libav-compatible signature for avfilter_graph_parse().

Should address trac ticket #2672.

TODO: bump minor, update APIchanges
---
 doc/examples/filtering_audio.c |  2 +-
 doc/examples/filtering_video.c |  2 +-
 ffplay.c                       |  2 +-
 libavdevice/lavfi.c            |  2 +-
 libavfilter/avfilter.h         | 65 ++++++++++++++++++++++++++++++++----------
 libavfilter/graphparser.c      | 30 ++++++++++---------
 libavfilter/version.h          |  5 +++-
 7 files changed, 75 insertions(+), 33 deletions(-)

diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
index b6b05a2..72cf790 100644
--- a/doc/examples/filtering_audio.c
+++ b/doc/examples/filtering_audio.c
@@ -152,7 +152,7 @@ static int init_filters(const char *filters_descr)
     inputs->pad_idx    = 0;
     inputs->next       = NULL;
 
-    if ((ret = avfilter_graph_parse(filter_graph, filters_descr,
+    if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,
                                     &inputs, &outputs, NULL)) < 0)
         return ret;
 
diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_video.c
index daa3966..d3c33df 100644
--- a/doc/examples/filtering_video.c
+++ b/doc/examples/filtering_video.c
@@ -129,7 +129,7 @@ static int init_filters(const char *filters_descr)
     inputs->pad_idx    = 0;
     inputs->next       = NULL;
 
-    if ((ret = avfilter_graph_parse(filter_graph, filters_descr,
+    if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,
                                     &inputs, &outputs, NULL)) < 0)
         return ret;
 
diff --git a/ffplay.c b/ffplay.c
index 744570c..e66886e 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1737,7 +1737,7 @@ static int configure_filtergraph(AVFilterGraph *graph, const char *filtergraph,
         inputs->pad_idx     = 0;
         inputs->next        = NULL;
 
-        if ((ret = avfilter_graph_parse(graph, filtergraph, &inputs, &outputs, NULL)) < 0)
+        if ((ret = avfilter_graph_parse_ptr(graph, filtergraph, &inputs, &outputs, NULL)) < 0)
             goto fail;
     } else {
         if ((ret = avfilter_link(source_ctx, 0, sink_ctx, 0)) < 0)
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index bcfba8b..9322ce5 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -141,7 +141,7 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
     if (!(lavfi->graph = avfilter_graph_alloc()))
         FAIL(AVERROR(ENOMEM));
 
-    if ((ret = avfilter_graph_parse(lavfi->graph, lavfi->graph_str,
+    if ((ret = avfilter_graph_parse_ptr(lavfi->graph, lavfi->graph_str,
                                     &input_links, &output_links, avctx)) < 0)
         FAIL(ret);
 
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 1f7da42..aed0e33 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -1311,6 +1311,29 @@ AVFilterInOut *avfilter_inout_alloc(void);
  */
 void avfilter_inout_free(AVFilterInOut **inout);
 
+#if HAVE_INCOMPATIBLE_LIBAV_ABI
+/**
+ * Add a graph described by a string to a graph.
+ *
+ * @note The caller must provide the lists of inputs and outputs,
+ * which therefore must be known before calling the function.
+ *
+ * @note The inputs parameter describes inputs of the already existing
+ * part of the graph; i.e. from the point of view of the newly created
+ * part, they are outputs. Similarly the outputs parameter describes
+ * outputs of the already existing filters, which are provided as
+ * inputs to the parsed filters.
+ *
+ * @param graph   the filter graph where to link the parsed grap context
+ * @param filters string to be parsed
+ * @param inputs  linked list to the inputs of the graph
+ * @param outputs linked list to the outputs of the graph
+ * @return zero on success, a negative AVERROR code on error
+ */
+int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
+                         AVFilterInOut *inputs, AVFilterInOut *outputs,
+                         void *log_ctx);
+#elif FF_API_OLD_GRAPH_PARSE
 /**
  * Add a graph described by a string to a graph.
  *
@@ -1323,10 +1346,30 @@ void avfilter_inout_free(AVFilterInOut **inout);
  *                If non-NULL, *outputs is updated to contain the list of open outputs
  *                after the parsing, should be freed with avfilter_inout_free().
  * @return non negative on success, a negative AVERROR code on error
+ * @deprecated Use avfilter_graph_parse_ptr() instead.
  */
+attribute_deprecated
 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
                          AVFilterInOut **inputs, AVFilterInOut **outputs,
                          void *log_ctx);
+#endif
+
+/**
+ * Add a graph described by a string to a graph.
+ *
+ * @param graph   the filter graph where to link the parsed graph context
+ * @param filters string to be parsed
+ * @param inputs  pointer to a linked list to the inputs of the graph, may be NULL.
+ *                If non-NULL, *inputs is updated to contain the list of open inputs
+ *                after the parsing, should be freed with avfilter_inout_free().
+ * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
+ *                If non-NULL, *outputs is updated to contain the list of open outputs
+ *                after the parsing, should be freed with avfilter_inout_free().
+ * @return non negative on success, a negative AVERROR code on error
+ */
+int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,
+                             AVFilterInOut **inputs, AVFilterInOut **outputs,
+                             void *log_ctx);
 
 /**
  * Add a graph described by a string to a graph.
@@ -1341,21 +1384,13 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
  *                     caller using avfilter_inout_free().
  * @return zero on success, a negative AVERROR code on error
  *
- * @note the difference between avfilter_graph_parse2() and
- * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
- * the lists of inputs and outputs, which therefore must be known before calling
- * the function. On the other hand, avfilter_graph_parse2() \em returns the
- * inputs and outputs that are left unlinked after parsing the graph and the
- * caller then deals with them. Another difference is that in
- * avfilter_graph_parse(), the inputs parameter describes inputs of the
- * <em>already existing</em> part of the graph; i.e. from the point of view of
- * the newly created part, they are outputs. Similarly the outputs parameter
- * describes outputs of the already existing filters, which are provided as
- * inputs to the parsed filters.
- * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
- * whatsoever to already existing parts of the graph and the inputs parameter
- * will on return contain inputs of the newly parsed part of the graph.
- * Analogously the outputs parameter will contain outputs of the newly created
+ * @note This function returns the inputs and outputs that are left
+ * unlinked after parsing the graph and the caller then deals with
+ * them.
+ * @note This function makes no reference whatsoever to already
+ * existing parts of the graph and the inputs parameter will on return
+ * contain inputs of the newly parsed part of the graph.  Analogously
+ * the outputs parameter will contain outputs of the newly created
  * filters.
  */
 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index 9241cf3..d0079ad 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -447,14 +447,12 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
     return ret;
 }
 
+#if HAVE_INCOMPATIBLE_LIBAV_ABI
 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
-                         AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr,
-                         void *log_ctx)
+                         AVFilterInOut *open_inputs,
+                         AVFilterInOut *open_outputs, void *log_ctx)
 {
-#if 0
     int ret;
-    AVFilterInOut *open_inputs  = open_inputs_ptr  ? *open_inputs_ptr  : NULL;
-    AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL;
     AVFilterInOut *cur, *match, *inputs = NULL, *outputs = NULL;
 
     if ((ret = avfilter_graph_parse2(graph, filters, &inputs, &outputs)) < 0)
@@ -508,14 +506,22 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
     }
     avfilter_inout_free(&inputs);
     avfilter_inout_free(&outputs);
-    /* clear open_in/outputs only if not passed as parameters */
-    if (open_inputs_ptr) *open_inputs_ptr = open_inputs;
-    else avfilter_inout_free(&open_inputs);
-    if (open_outputs_ptr) *open_outputs_ptr = open_outputs;
-    else avfilter_inout_free(&open_outputs);
+    avfilter_inout_free(&open_inputs);
+    avfilter_inout_free(&open_outputs);
     return ret;
+#elif FF_API_OLD_GRAPH_PARSE
+int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
+                         AVFilterInOut **inputs, AVFilterInOut **outputs,
+                         void *log_ctx)
+{
+    return avfilter_graph_parse_ptr(graph, filters, inputs, outputs, log_ctx);
 }
-#else
+#endif
+
+int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,
+                         AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr,
+                         void *log_ctx)
+{
     int index = 0, ret = 0;
     char chr = 0;
 
@@ -595,5 +601,3 @@ end:
     }
     return ret;
 }
-
-#endif
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 1bc6b7e..e4dde3a 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  3
-#define LIBAVFILTER_VERSION_MINOR  77
+#define LIBAVFILTER_VERSION_MINOR  78
 #define LIBAVFILTER_VERSION_MICRO 101
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
@@ -79,5 +79,8 @@
 #ifndef FF_API_OLD_FILTER_REGISTER
 #define FF_API_OLD_FILTER_REGISTER          (LIBAVFILTER_VERSION_MAJOR < 4)
 #endif
+#ifndef FF_API_OLD_GRAPH_PARSE
+#define FF_API_OLD_GRAPH_PARSE              (LIBAVFILTER_VERSION_MAJOR < 4)
+#endif
 
 #endif /* AVFILTER_VERSION_H */
-- 
1.8.1.2



More information about the ffmpeg-devel mailing list