#include "libavutil/mem.h"
#include "avfilter.h"
-#define WHITESPACES " \n\t"
+#define WHITESPACES " \n\t\r"
/**
* Link two filters together.
(*buf)++;
name = av_get_token(buf, "]");
+ if (!name)
+ goto fail;
if (!name[0]) {
av_log(log_ctx, AV_LOG_ERROR,
* @param filt_ctx put here a filter context in case of successful creation and configuration, NULL otherwise.
* @param ctx the filtergraph context
* @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 name the name of the filter to create, can be filter name or filter_name\@id as instance name
* @param args the arguments provided to the filter during its initialization
* @param log_ctx the log context to use
* @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, void *log_ctx)
+ const char *name, const char *args, void *log_ctx)
{
AVFilter *filt;
- char inst_name[30];
+ char name2[30];
+ const char *inst_name = NULL, *filt_name = NULL;
char *tmp_args = NULL;
- int ret;
+ int ret, k;
- snprintf(inst_name, sizeof(inst_name), "Parsed_%s_%d", filt_name, index);
+ av_strlcpy(name2, name, sizeof(name2));
+
+ for (k = 0; name2[k]; k++) {
+ if (name2[k] == '@' && name[k+1]) {
+ name2[k] = 0;
+ inst_name = name;
+ filt_name = name2;
+ break;
+ }
+ }
+
+ if (!inst_name) {
+ snprintf(name2, sizeof(name2), "Parsed_%s_%d", name, index);
+ inst_name = name2;
+ filt_name = name;
+ }
filt = avfilter_get_by_name(filt_name);
return AVERROR(ENOMEM);
}
- if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags") &&
+ if (!strcmp(filt_name, "scale") && (!args || !strstr(args, "flags")) &&
ctx->scale_sws_opts) {
- tmp_args = av_asprintf("%s:%s",
- args, ctx->scale_sws_opts);
- if (!tmp_args)
- return AVERROR(ENOMEM);
- args = tmp_args;
+ if (args) {
+ tmp_args = av_asprintf("%s:%s",
+ args, ctx->scale_sws_opts);
+ if (!tmp_args)
+ return AVERROR(ENOMEM);
+ args = tmp_args;
+ } else
+ args = ctx->scale_sws_opts;
}
ret = avfilter_init_str(*filt_ctx, args);
av_log(log_ctx, AV_LOG_ERROR, " with args '%s'", args);
av_log(log_ctx, AV_LOG_ERROR, "\n");
avfilter_free(*filt_ctx);
+ *filt_ctx = NULL;
}
av_free(tmp_args);
int index, void *log_ctx)
{
char *opts = NULL;
- char *name = av_get_token(buf, "=,;[\n");
+ char *name = av_get_token(buf, "=,;[");
int ret;
if (**buf == '=') {
(*buf)++;
- opts = av_get_token(buf, "[],;\n");
+ opts = av_get_token(buf, "[],;");
}
ret = create_filter(filt_ctx, graph, index, name, opts, log_ctx);
if (p->filter_ctx) {
ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx);
- av_free(p->name);
- av_free(p);
+ av_freep(&p->name);
+ av_freep(&p);
if (ret < 0)
return ret;
} else {
av_free(name);
return ret;
}
- av_free(match->name);
- av_free(name);
- av_free(match);
- av_free(input);
+ av_freep(&match->name);
+ av_freep(&name);
+ av_freep(&match);
+ av_freep(&input);
} else {
- /* Not in the list, so add the first input as a open_output */
+ /* Not in the list, so add the first input as an open_output */
input->name = name;
insert_inout(open_outputs, input);
}
return ret;
}
-#if HAVE_INCOMPATIBLE_LIBAV_ABI || !FF_API_OLD_GRAPH_PARSE
int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
AVFilterInOut *open_inputs,
AVFilterInOut *open_outputs, void *log_ctx)
avfilter_inout_free(&open_inputs);
avfilter_inout_free(&open_outputs);
return ret;
-#else
-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);
-#endif
}
int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,