[FFmpeg-devel] [PATCH 2/2] lavfi/avfilter: add avfilter_graph_get_filters_by_name() function
Lukasz Marek
lukasz.m.luki2 at gmail.com
Fri Apr 25 00:31:13 CEST 2014
TODO: update doc/APIChanges and bump minor.
Allows to search for filters when instance name is not known.
Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
---
libavfilter/avfilter.h | 12 ++++++++++++
libavfilter/avfiltergraph.c | 20 ++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 0cc5274..c9428b1 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -1276,6 +1276,18 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
*/
AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, const char *name);
+/**
+ * Get filter instances identified by filter name from graph.
+ *
+ * Returned array must be freed with av_free().
+ *
+ * @param graph filter graph to search through.
+ * @param name filter name (not unique in the graph).
+ * @param[out] count number of found filters. May be NULL.
+ * @return array of found filters or NULL on failure.
+ */
+AVFilterContext **avfilter_graph_get_filters_by_name(AVFilterGraph *graph, const char *name, int *count);
+
#if FF_API_AVFILTER_OPEN
/**
* Add an existing filter instance to a filter graph.
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index cfa4a44..2aaeb5f 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -31,6 +31,7 @@
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
+#include "libavutil/mem.h"
#include "libavcodec/avcodec.h" // avcodec_find_best_pix_fmt_of_2()
#include "avfilter.h"
@@ -292,6 +293,25 @@ AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, const char *nam
return NULL;
}
+AVFilterContext **avfilter_graph_get_filters_by_name(AVFilterGraph *graph, const char *name,
+ int *count)
+{
+ int i, cnt = 0;
+ AVFilterContext **filters = NULL;
+
+ for (i = 0; i < graph->nb_filters; i++)
+ if (!strcmp(name, graph->filters[i]->filter->name))
+ if (av_dynarray_add_nofree(&filters, &cnt, graph->filters[i]) < 0) {
+ av_freep(filters);
+ if (count)
+ *count = 0;
+ return NULL;
+ }
+ if (count)
+ *count = cnt;
+ return filters;
+}
+
static void sanitize_channel_layouts(void *log, AVFilterChannelLayouts *l)
{
if (!l)
--
1.9.1
More information about the ffmpeg-devel
mailing list