]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/graphparser.c
Merge commit '42c7c61ab25809620b8c8809b3da73e25f5bbaaf'
[ffmpeg] / libavfilter / graphparser.c
index ea0a86d51aff5e1e3aa649138b343edf8cce2316..8d2fffc1949d146a6ed5a6b696293f5423a25e60 100644 (file)
@@ -3,20 +3,20 @@
  * Copyright (c) 2008 Vitor Sessak
  * Copyright (c) 2007 Bobby Bingham
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
  *
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -100,7 +100,7 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
     char tmp_args[256];
     int ret;
 
-    snprintf(inst_name, sizeof(inst_name), "Parsed filter %d %s", index, filt_name);
+    snprintf(inst_name, sizeof(inst_name), "Parsed_%s_%d", filt_name, index);
 
     filt = avfilter_get_by_name(filt_name);
 
@@ -122,7 +122,8 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
         return ret;
     }
 
-    if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags")) {
+    if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags")
+        && ctx->scale_sws_opts) {
         snprintf(tmp_args, sizeof(tmp_args), "%s:%s",
                  args, ctx->scale_sws_opts);
         args = tmp_args;
@@ -384,7 +385,7 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
                           AVFilterInOut **inputs,
                           AVFilterInOut **outputs)
 {
-    int index = 0, ret;
+    int index = 0, ret = 0;
     char chr = 0;
 
     AVFilterInOut *curr_inputs = NULL, *open_inputs = NULL, *open_outputs = NULL;
@@ -399,18 +400,17 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
         filters += strspn(filters, WHITESPACES);
 
         if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, graph)) < 0)
-            goto fail;
-
+            goto end;
         if ((ret = parse_filter(&filter, &filters, graph, index, graph)) < 0)
-            goto fail;
+            goto end;
 
 
         if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, graph)) < 0)
-            goto fail;
+            goto end;
 
         if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
                                  graph)) < 0)
-            goto fail;
+            goto end;
 
         filters += strspn(filters, WHITESPACES);
         chr = *filters++;
@@ -425,16 +425,17 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
                "Unable to parse graph description substring: \"%s\"\n",
                filters - 1);
         ret = AVERROR(EINVAL);
-        goto fail;
+        goto end;
     }
 
     append_inout(&open_outputs, &curr_inputs);
 
+
     *inputs  = open_inputs;
     *outputs = open_outputs;
     return 0;
 
- fail:
+ fail:end:
     for (; graph->nb_filters > 0; graph->nb_filters--)
         avfilter_free(graph->filters[graph->nb_filters - 1]);
     av_freep(&graph->filters);
@@ -449,10 +450,13 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
 }
 
 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
-                         AVFilterInOut *open_inputs,
-                         AVFilterInOut *open_outputs, void *log_ctx)
+                         AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr,
+                         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)
@@ -506,7 +510,92 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
     }
     avfilter_inout_free(&inputs);
     avfilter_inout_free(&outputs);
-    avfilter_inout_free(&open_inputs);
-    avfilter_inout_free(&open_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);
     return ret;
 }
+#else
+    int index = 0, ret = 0;
+    char chr = 0;
+
+    AVFilterInOut *curr_inputs = NULL;
+    AVFilterInOut *open_inputs  = open_inputs_ptr  ? *open_inputs_ptr  : NULL;
+    AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL;
+
+    if ((ret = parse_sws_flags(&filters, graph)) < 0)
+        goto end;
+
+    do {
+        AVFilterContext *filter;
+        const char *filterchain = filters;
+        filters += strspn(filters, WHITESPACES);
+
+        if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)
+            goto end;
+
+        if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0)
+            goto end;
+
+        if (filter->input_count == 1 && !curr_inputs && !index) {
+            /* First input pad, assume it is "[in]" if not specified */
+            const char *tmp = "[in]";
+            if ((ret = parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx)) < 0)
+                goto end;
+        }
+
+        if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0)
+            goto end;
+
+        if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
+                                 log_ctx)) < 0)
+            goto end;
+
+        filters += strspn(filters, WHITESPACES);
+        chr = *filters++;
+
+        if (chr == ';' && curr_inputs) {
+            av_log(log_ctx, AV_LOG_ERROR,
+                   "Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
+                   filterchain);
+            ret = AVERROR(EINVAL);
+            goto end;
+        }
+        index++;
+    } while (chr == ',' || chr == ';');
+
+    if (chr) {
+        av_log(log_ctx, AV_LOG_ERROR,
+               "Unable to parse graph description substring: \"%s\"\n",
+               filters - 1);
+        ret = AVERROR(EINVAL);
+        goto end;
+    }
+
+    if (curr_inputs) {
+        /* Last output pad, assume it is "[out]" if not specified */
+        const char *tmp = "[out]";
+        if ((ret = parse_outputs(&tmp, &curr_inputs, &open_inputs, &open_outputs,
+                                 log_ctx)) < 0)
+            goto end;
+    }
+
+end:
+    /* 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(&curr_inputs);
+
+    if (ret < 0) {
+        for (; graph->nb_filters > 0; graph->nb_filters--)
+            avfilter_free(graph->filters[graph->nb_filters - 1]);
+        av_freep(&graph->filters);
+    }
+    return ret;
+}
+
+#endif