]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/graphparser.c
FATE: allow tests to set CMP_SHIFT to pass to tiny_psnr
[ffmpeg] / libavfilter / graphparser.c
index 4266e8134d18acb5b3a38627e047aa69741d65ec..90f2936590d4c44bb71cb194c72c8598591836c6 100644 (file)
@@ -1,22 +1,22 @@
 /*
  * filter graph parser
- * copyright (c) 2008 Vitor Sessak
- * copyright (c) 2007 Bobby Bingham
+ * Copyright (c) 2008 Vitor Sessak
+ * Copyright (c) 2007 Bobby Bingham
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -26,7 +26,6 @@
 #include "libavutil/avstring.h"
 #include "avfilter.h"
 #include "avfiltergraph.h"
-#include "parseutils.h"
 
 #define WHITESPACES " \n\t"
 
@@ -37,7 +36,7 @@
  */
 static int link_filter(AVFilterContext *src, int srcpad,
                        AVFilterContext *dst, int dstpad,
-                       AVClass *log_ctx)
+                       void *log_ctx)
 {
     int ret;
     if ((ret = avfilter_link(src, srcpad, dst, dstpad))) {
@@ -56,7 +55,7 @@ static int link_filter(AVFilterContext *src, int srcpad,
  * @return a pointer (that need to be freed after use) to the name
  * between parenthesis
  */
-static char *parse_link_name(const char **buf, AVClass *log_ctx)
+static char *parse_link_name(const char **buf, void *log_ctx)
 {
     const char *start = *buf;
     char *name;
@@ -84,8 +83,8 @@ static char *parse_link_name(const char **buf, AVClass *log_ctx)
  * Create an instance of a filter, initialize and insert it in the
  * filtergraph in *ctx.
  *
+ * @param filt_ctx put here a filter context in case of successful creation and configuration, NULL otherwise.
  * @param ctx the filtergraph context
- * @param put here a filter context in case of successful creation and configuration, NULL otherwise.
  * @param index an index which is supposed to be unique for each filter instance added to the filtergraph
  * @param filt_name the name of the filter to create
  * @param args the arguments provided to the filter during its initialization
@@ -93,14 +92,14 @@ static char *parse_link_name(const char **buf, AVClass *log_ctx)
  * @return 0 in case of success, a negative AVERROR code otherwise
  */
 static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int index,
-                         const char *filt_name, const char *args, AVClass *log_ctx)
+                         const char *filt_name, const char *args, void *log_ctx)
 {
     AVFilter *filt;
     char inst_name[30];
     char tmp_args[256];
     int ret;
 
-    snprintf(inst_name, sizeof(inst_name), "Filter %d %s", index, filt_name);
+    snprintf(inst_name, sizeof(inst_name), "Parsed filter %d %s", index, filt_name);
 
     filt = avfilter_get_by_name(filt_name);
 
@@ -122,7 +121,7 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
         return ret;
     }
 
-    if (!strcmp(filt_name, "scale") && !strstr(args, "flags")) {
+    if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags")) {
         snprintf(tmp_args, sizeof(tmp_args), "%s:%s",
                  args, ctx->scale_sws_opts);
         args = tmp_args;
@@ -142,6 +141,8 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
  * corresponding filter instance which is added to graph with
  * create_filter().
  *
+ * @param filt_ctx Pointer that is set to the created and configured filter
+ *                 context on success, set to NULL on failure.
  * @param filt_ctx put here a pointer to the created filter context on
  * success, NULL otherwise
  * @param buf pointer to the buffer to parse, *buf will be updated to
@@ -152,7 +153,7 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
  * @return 0 in case of success, a negative AVERROR code otherwise
  */
 static int parse_filter(AVFilterContext **filt_ctx, const char **buf, AVFilterGraph *graph,
-                        int index, AVClass *log_ctx)
+                        int index, void *log_ctx)
 {
     char *opts = NULL;
     char *name = av_get_token(buf, "=,;[\n");
@@ -202,7 +203,7 @@ static void insert_inout(AVFilterInOut **inouts, AVFilterInOut *element)
 
 static int link_filter_inouts(AVFilterContext *filt_ctx,
                               AVFilterInOut **curr_inputs,
-                              AVFilterInOut **open_inputs, AVClass *log_ctx)
+                              AVFilterInOut **open_inputs, void *log_ctx)
 {
     int pad = filt_ctx->input_count, ret;
 
@@ -250,7 +251,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx,
 }
 
 static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
-                        AVFilterInOut **open_outputs, AVClass *log_ctx)
+                        AVFilterInOut **open_outputs, void *log_ctx)
 {
     int pad = 0;
 
@@ -285,7 +286,7 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
 
 static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
                          AVFilterInOut **open_inputs,
-                         AVFilterInOut **open_outputs, AVClass *log_ctx)
+                         AVFilterInOut **open_outputs, void *log_ctx)
 {
     int ret, pad = 0;
 
@@ -294,6 +295,12 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
         AVFilterInOut *match;
 
         AVFilterInOut *input = *curr_inputs;
+        if (!input) {
+            av_log(log_ctx, AV_LOG_ERROR,
+                   "No output pad can be associated to link label '%s'.\n",
+                   name);
+            return AVERROR(EINVAL);
+        }
         *curr_inputs = (*curr_inputs)->next;
 
         if (!name)
@@ -324,7 +331,7 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
 
 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
                          AVFilterInOut *open_inputs,
-                         AVFilterInOut *open_outputs, AVClass *log_ctx)
+                         AVFilterInOut *open_outputs, void *log_ctx)
 {
     int index = 0, ret;
     char chr = 0;
@@ -333,6 +340,7 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
 
     do {
         AVFilterContext *filter;
+        const char *filterchain = filters;
         filters += strspn(filters, WHITESPACES);
 
         if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)
@@ -360,8 +368,8 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
 
         if (chr == ';' && curr_inputs) {
             av_log(log_ctx, AV_LOG_ERROR,
-                   "Could not find a output to link when parsing \"%s\"\n",
-                   filters - 1);
+                   "Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
+                   filterchain);
             ret = AVERROR(EINVAL);
             goto fail;
         }
@@ -387,7 +395,9 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
     return 0;
 
  fail:
-    avfilter_graph_free(graph);
+    for (; graph->filter_count > 0; graph->filter_count--)
+        avfilter_free(graph->filters[graph->filter_count - 1]);
+    av_freep(&graph->filters);
     free_inout(open_inputs);
     free_inout(open_outputs);
     free_inout(curr_inputs);