aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-04-11 23:56:39 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-04-12 00:31:44 +0200
commit86070b8e5a0e0ba087a9ce2a050c00094e29f35b (patch)
tree6e82eb3de383fa6f8756c5053d26e52fbf29f07b /libavfilter
parent9da369604ecf31d9dce2dee21ed214b8c43264c6 (diff)
parentbc1a985ba030e9861d24965d42792850b43a43ea (diff)
downloadffmpeg-86070b8e5a0e0ba087a9ce2a050c00094e29f35b.tar.gz
Merge commit 'bc1a985ba030e9861d24965d42792850b43a43ea'
* commit 'bc1a985ba030e9861d24965d42792850b43a43ea': lavfi: replace avfilter_open() with avfilter_graph_alloc_filter(). Conflicts: libavfilter/avfiltergraph.c libavfilter/internal.h libavfilter/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/avfilter.c20
-rw-r--r--libavfilter/avfilter.h26
-rw-r--r--libavfilter/avfiltergraph.c38
-rw-r--r--libavfilter/graphparser.c9
-rw-r--r--libavfilter/internal.h10
-rw-r--r--libavfilter/version.h3
6 files changed, 85 insertions, 21 deletions
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 5a99fdddd5..406537a5a6 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -490,17 +490,16 @@ static const AVClass avfilter_class = {
.child_class_next = filter_child_class_next,
};
-int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
+AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
{
AVFilterContext *ret;
- *filter_ctx = NULL;
if (!filter)
- return AVERROR(EINVAL);
+ return NULL;
ret = av_mallocz(sizeof(AVFilterContext));
if (!ret)
- return AVERROR(ENOMEM);
+ return NULL;
ret->av_class = &avfilter_class;
ret->filter = filter;
@@ -542,8 +541,7 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in
ret->input_count = ret->nb_inputs;
#endif
- *filter_ctx = ret;
- return 0;
+ return ret;
err:
av_freep(&ret->inputs);
@@ -554,8 +552,16 @@ err:
ret->nb_outputs = 0;
av_freep(&ret->priv);
av_free(ret);
- return AVERROR(ENOMEM);
+ return NULL;
+}
+
+#if FF_API_AVFILTER_OPEN
+int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
+{
+ *filter_ctx = ff_filter_alloc(filter, inst_name);
+ return *filter_ctx ? 0 : AVERROR(ENOMEM);
}
+#endif
void avfilter_free(AVFilterContext *filter)
{
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 296cc420b1..dbdcf9d210 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -817,8 +817,8 @@ void avfilter_uninit(void);
/**
* Register a filter. This is only needed if you plan to use
* avfilter_get_by_name later to lookup the AVFilter structure by name. A
- * filter can still by instantiated with avfilter_open even if it is not
- * registered.
+ * filter can still by instantiated with avfilter_graph_alloc_filter even if it
+ * is not registered.
*
* @param filter the filter to register
* @return 0 if the registration was successful, a negative value
@@ -843,6 +843,7 @@ AVFilter *avfilter_get_by_name(const char *name);
*/
AVFilter **av_filter_next(AVFilter **filter);
+#if FF_API_AVFILTER_OPEN
/**
* Create a filter instance.
*
@@ -851,8 +852,11 @@ AVFilter **av_filter_next(AVFilter **filter);
* @param filter the filter to create an instance of
* @param inst_name Name to give to the new instance. Can be NULL for none.
* @return >= 0 in case of success, a negative error code otherwise
+ * @deprecated use avfilter_graph_alloc_filter() instead
*/
+attribute_deprecated
int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
+#endif
/**
* Initialize a filter.
@@ -949,6 +953,24 @@ typedef struct AVFilterGraph {
AVFilterGraph *avfilter_graph_alloc(void);
/**
+ * Create a new filter instance in a filter graph.
+ *
+ * @param graph graph in which the new filter will be used
+ * @param filter the filter to create an instance of
+ * @param name Name to give to the new instance (will be copied to
+ * AVFilterContext.name). This may be used by the caller to identify
+ * different filters, libavfilter itself assigns no semantics to
+ * this parameter. May be NULL.
+ *
+ * @return the context of the newly created filter instance (note that it is
+ * also retrievable directly through AVFilterGraph.filters or with
+ * avfilter_graph_get_filter()) on success or NULL or failure.
+ */
+AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
+ const AVFilter *filter,
+ const char *name);
+
+/**
* Get a filter instance with name name from graph.
*
* @return the pointer to the found filter instance or NULL if it
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 28fc743b59..771c7dfda6 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -96,12 +96,14 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
{
int ret;
- if ((ret = avfilter_open(filt_ctx, filt, name)) < 0)
- goto fail;
- if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0)
- goto fail;
- if ((ret = avfilter_graph_add_filter(graph_ctx, *filt_ctx)) < 0)
+ *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name);
+ if (!*filt_ctx)
+ return AVERROR(ENOMEM);
+ if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0) {
+ graph_ctx->filters[graph_ctx->nb_filters-1] = NULL;
goto fail;
+ }
+
return 0;
fail:
@@ -116,6 +118,32 @@ void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
graph->disable_auto_convert = flags;
}
+AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
+ const AVFilter *filter,
+ const char *name)
+{
+ AVFilterContext **filters, *s;
+
+ s = ff_filter_alloc(filter, name);
+ if (!s)
+ return NULL;
+
+ filters = av_realloc(graph->filters, sizeof(*filters) * (graph->nb_filters + 1));
+ if (!filters) {
+ avfilter_free(s);
+ return NULL;
+ }
+
+ graph->filters = filters;
+ graph->filters[graph->nb_filters++] = s;
+
+#if FF_API_FOO_COUNT
+ graph->filter_count_unused = graph->nb_filters;
+#endif
+
+ return s;
+}
+
/**
* Check for the validity of graph.
*
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index 2911b06693..3af9b56021 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -109,16 +109,11 @@ 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") &&
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 0b28422f1f..6907b76a71 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -339,4 +339,14 @@ enum {
};
+/**
+ * Allocate a new filter context and return it.
+ *
+ * @param filter what filter to create an instance of
+ * @param inst_name name to give to the new filter context
+ *
+ * @return newly created filter context or NULL on failure
+ */
+AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
+
#endif /* AVFILTER_INTERNAL_H */
diff --git a/libavfilter/version.h b/libavfilter/version.h
index b2e0b5e221..f3508b7d51 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -69,5 +69,8 @@
#ifndef FF_API_ACONVERT_FILTER
#define FF_API_ACONVERT_FILTER (LIBAVFILTER_VERSION_MAJOR < 4)
#endif
+#ifndef FF_API_AVFILTER_OPEN
+#define FF_API_AVFILTER_OPEN (LIBAVFILTER_VERSION_MAJOR < 4)
+#endif
#endif /* AVFILTER_VERSION_H */