diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
| commit | f7813a5324be39d13ab536c245d15dfc602a7849 (patch) | |
| tree | fad99148b88823d34a5df2f0a25881a002eb291b /ffmpeg/libavfilter/graphparser.c | |
| parent | b7a5a477b8ff4d4e3028b9dfb9a9df0a41463f92 (diff) | |
basic type mechanism working
Diffstat (limited to 'ffmpeg/libavfilter/graphparser.c')
| -rw-r--r-- | ffmpeg/libavfilter/graphparser.c | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/ffmpeg/libavfilter/graphparser.c b/ffmpeg/libavfilter/graphparser.c index 8d2fffc..7e25282 100644 --- a/ffmpeg/libavfilter/graphparser.c +++ b/ffmpeg/libavfilter/graphparser.c @@ -26,7 +26,6 @@ #include "libavutil/avstring.h" #include "libavutil/mem.h" #include "avfilter.h" -#include "avfiltergraph.h" #define WHITESPACES " \n\t" @@ -90,14 +89,14 @@ static char *parse_link_name(const char **buf, void *log_ctx) * @param filt_name the name of the filter to create * @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 + * @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) { AVFilter *filt; char inst_name[30]; - char tmp_args[256]; + char *tmp_args = NULL; int ret; snprintf(inst_name, sizeof(inst_name), "Parsed_%s_%d", filt_name, index); @@ -110,32 +109,35 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind return AVERROR(EINVAL); } - ret = avfilter_open(filt_ctx, filt, inst_name); + *filt_ctx = avfilter_graph_alloc_filter(ctx, filt, inst_name); if (!*filt_ctx) { av_log(log_ctx, AV_LOG_ERROR, "Error creating filter '%s'\n", filt_name); - return ret; - } - - if ((ret = avfilter_graph_add_filter(ctx, *filt_ctx)) < 0) { - avfilter_free(*filt_ctx); - return ret; + return AVERROR(ENOMEM); } - if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags") - && ctx->scale_sws_opts) { - snprintf(tmp_args, sizeof(tmp_args), "%s:%s", + 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 ((ret = avfilter_init_filter(*filt_ctx, args, NULL)) < 0) { + ret = avfilter_init_str(*filt_ctx, args); + if (ret < 0) { av_log(log_ctx, AV_LOG_ERROR, - "Error initializing filter '%s' with args '%s'\n", filt_name, args); - return ret; + "Error initializing filter '%s'", filt_name); + if (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; } - return 0; + av_free(tmp_args); + return ret; } /** @@ -152,7 +154,7 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind * @param index an index which is assigned to the created filter * instance, and which is supposed to be unique for each filter * instance added to the filtergraph - * @return 0 in case of success, a negative AVERROR code otherwise + * @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, void *log_ctx) @@ -436,8 +438,8 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, return 0; fail:end: - for (; graph->nb_filters > 0; graph->nb_filters--) - avfilter_free(graph->filters[graph->nb_filters - 1]); + while (graph->nb_filters) + avfilter_free(graph->filters[0]); av_freep(&graph->filters); avfilter_inout_free(&open_inputs); avfilter_inout_free(&open_outputs); @@ -449,14 +451,12 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, return ret; } +#if HAVE_INCOMPATIBLE_LIBAV_ABI || !FF_API_OLD_GRAPH_PARSE 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) @@ -504,20 +504,28 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, fail: if (ret < 0) { - for (; graph->nb_filters > 0; graph->nb_filters--) - avfilter_free(graph->filters[graph->nb_filters - 1]); + while (graph->nb_filters) + avfilter_free(graph->filters[0]); av_freep(&graph->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; -} #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, + AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr, + void *log_ctx) +{ int index = 0, ret = 0; char chr = 0; @@ -539,7 +547,7 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0) goto end; - if (filter->input_count == 1 && !curr_inputs && !index) { + if (filter->nb_inputs == 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) @@ -591,11 +599,9 @@ end: avfilter_inout_free(&curr_inputs); if (ret < 0) { - for (; graph->nb_filters > 0; graph->nb_filters--) - avfilter_free(graph->filters[graph->nb_filters - 1]); + while (graph->nb_filters) + avfilter_free(graph->filters[0]); av_freep(&graph->filters); } return ret; } - -#endif |
