summaryrefslogtreecommitdiff
path: root/libavfilter/avfiltergraph.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-05-11 20:41:46 +0200
committerAnton Khirnov <anton@khirnov.net>2013-05-24 09:28:18 +0200
commit129bb238430ec45a3b5f8f1d384df590ddf7b62f (patch)
treeed6b4b70661ef80b06e76e624ddfde9d45f84183 /libavfilter/avfiltergraph.c
parent2a6eaeaa85d17b27ee0dd449183ec197c35c9675 (diff)
lavfi: add a slice threading infrastructure
Mostly based on libavcodec's
Diffstat (limited to 'libavfilter/avfiltergraph.c')
-rw-r--r--libavfilter/avfiltergraph.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 9e4c407b1e..e93a5bb415 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"
@@ -27,22 +29,59 @@
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/log.h"
+#include "libavutil/opt.h"
+
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
+#include "thread.h"
+
+#define OFFSET(x) offsetof(AVFilterGraph, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_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 },
+ { NULL },
+};
static const AVClass filtergraph_class = {
.class_name = "AVFilterGraph",
.item_name = av_default_item_name,
.version = LIBAVUTIL_VERSION_INT,
+ .option = filtergraph_options,
};
+#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;
}
@@ -67,9 +106,12 @@ void avfilter_graph_free(AVFilterGraph **graph)
while ((*graph)->nb_filters)
avfilter_free((*graph)->filters[0]);
+ ff_graph_thread_free(*graph);
+
av_freep(&(*graph)->scale_sws_opts);
av_freep(&(*graph)->resample_lavr_opts);
av_freep(&(*graph)->filters);
+ av_freep(&(*graph)->internal);
av_freep(graph);
}
@@ -123,6 +165,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;