summaryrefslogtreecommitdiff
path: root/libavfilter/avfiltergraph.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-05-24 13:47:45 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-05-24 14:07:00 +0200
commit8d4e969afe6bd15143a8a511587640417b0fb6dd (patch)
tree1608095a543b1c3549f20f9ab2d9e326e6e8169e /libavfilter/avfiltergraph.c
parentfe40a9f98f599699b0989d8c8cb35cb24eb2e52f (diff)
parent129bb238430ec45a3b5f8f1d384df590ddf7b62f (diff)
Merge commit '129bb238430ec45a3b5f8f1d384df590ddf7b62f'
* commit '129bb238430ec45a3b5f8f1d384df590ddf7b62f': lavfi: add a slice threading infrastructure Conflicts: Changelog cmdutils.c doc/APIchanges libavfilter/Makefile libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/avfiltergraph.c libavfilter/internal.h libavfilter/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter/avfiltergraph.c')
-rw-r--r--libavfilter/avfiltergraph.c62
1 files changed, 53 insertions, 9 deletions
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index a9b91c3895..8c400028d8 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "config.h"
+
#include <string.h>
#include "libavutil/avassert.h"
@@ -29,33 +31,63 @@
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavcodec/avcodec.h" // avcodec_find_best_pix_fmt_of_2()
+
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
-
-#define OFFSET(x) offsetof(AVFilterGraph,x)
-
-static const AVOption options[]={
-{"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) , AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, 0 },
-{"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) , AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, 0 },
-{0}
+#include "thread.h"
+
+#define OFFSET(x) offsetof(AVFilterGraph, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+static const AVOption filtergraph_options[] = {
+ { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
+ { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
+ { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = FLAGS, .unit = "thread_type" },
+ { "threads", "Maximum number of threads", OFFSET(nb_threads),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
+ {"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) ,
+ AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
+ {"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) ,
+ AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
+ { NULL },
};
-
static const AVClass filtergraph_class = {
.class_name = "AVFilterGraph",
.item_name = av_default_item_name,
- .option = options,
.version = LIBAVUTIL_VERSION_INT,
+ .option = filtergraph_options,
.category = AV_CLASS_CATEGORY_FILTER,
};
+#if !HAVE_THREADS
+void ff_graph_thread_free(AVFilterGraph *graph)
+{
+}
+
+int ff_graph_thread_init(AVFilterGraph *graph)
+{
+ graph->thread_type = 0;
+ graph->nb_threads = 1;
+ return 0;
+}
+#endif
+
AVFilterGraph *avfilter_graph_alloc(void)
{
AVFilterGraph *ret = av_mallocz(sizeof(*ret));
if (!ret)
return NULL;
+
+ ret->internal = av_mallocz(sizeof(*ret->internal));
+ if (!ret->internal) {
+ av_freep(&ret);
+ return NULL;
+ }
+
ret->av_class = &filtergraph_class;
+ av_opt_set_defaults(ret);
+
return ret;
}
@@ -80,11 +112,15 @@ void avfilter_graph_free(AVFilterGraph **graph)
while ((*graph)->nb_filters)
avfilter_free((*graph)->filters[0]);
+ ff_graph_thread_free(*graph);
+
av_freep(&(*graph)->sink_links);
+
av_freep(&(*graph)->scale_sws_opts);
av_freep(&(*graph)->aresample_swr_opts);
av_freep(&(*graph)->resample_lavr_opts);
av_freep(&(*graph)->filters);
+ av_freep(&(*graph)->internal);
av_freep(graph);
}
@@ -143,6 +179,14 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
{
AVFilterContext **filters, *s;
+ if (graph->thread_type && !graph->internal->thread) {
+ int ret = ff_graph_thread_init(graph);
+ if (ret < 0) {
+ av_log(graph, AV_LOG_ERROR, "Error initializing threading.\n");
+ return NULL;
+ }
+ }
+
s = ff_filter_alloc(filter, name);
if (!s)
return NULL;