aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/avfilter.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/avfilter.c
parentfe40a9f98f599699b0989d8c8cb35cb24eb2e52f (diff)
parent129bb238430ec45a3b5f8f1d384df590ddf7b62f (diff)
downloadffmpeg-8d4e969afe6bd15143a8a511587640417b0fb6dd.tar.gz
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/avfilter.c')
-rw-r--r--libavfilter/avfilter.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 59fc0fa7c4..1ea6d8dbfe 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -538,9 +538,12 @@ static const AVClass *filter_child_class_next(const AVClass *prev)
#define OFFSET(x) offsetof(AVFilterContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM
-static const AVOption filters_common_options[] = {
+static const AVOption 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 }, .unit = "thread_type" },
{ "enable", "set enable expression", OFFSET(enable_str), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
- { NULL }
+ { NULL },
};
static const AVClass avfilter_class = {
@@ -549,10 +552,23 @@ static const AVClass avfilter_class = {
.version = LIBAVUTIL_VERSION_INT,
.category = AV_CLASS_CATEGORY_FILTER,
.child_next = filter_child_next,
- .option = filters_common_options,
.child_class_next = filter_child_class_next,
+ .option = options,
};
+static int default_execute(AVFilterContext *ctx, action_func *func, void *arg,
+ int *ret, int nb_jobs)
+{
+ int i;
+
+ for (i = 0; i < nb_jobs; i++) {
+ int r = func(ctx, arg, i, nb_jobs);
+ if (ret)
+ ret[i] = r;
+ }
+ return 0;
+}
+
AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
{
AVFilterContext *ret;
@@ -573,11 +589,17 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
goto err;
}
+ av_opt_set_defaults(ret);
if (filter->priv_class) {
*(const AVClass**)ret->priv = filter->priv_class;
av_opt_set_defaults(ret->priv);
}
+ ret->internal = av_mallocz(sizeof(*ret->internal));
+ if (!ret->internal)
+ goto err;
+ ret->internal->execute = default_execute;
+
ret->nb_inputs = avfilter_pad_count(filter->inputs);
if (ret->nb_inputs ) {
ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
@@ -614,6 +636,7 @@ err:
av_freep(&ret->output_pads);
ret->nb_outputs = 0;
av_freep(&ret->priv);
+ av_freep(&ret->internal);
av_free(ret);
return NULL;
}
@@ -681,6 +704,7 @@ void avfilter_free(AVFilterContext *filter)
av_expr_free(filter->enable);
filter->enable = NULL;
av_freep(&filter->var_values);
+ av_freep(&filter->internal);
av_free(filter);
}
@@ -772,6 +796,21 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
{
int ret = 0;
+ ret = av_opt_set_dict(ctx, options);
+ if (ret < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n");
+ return ret;
+ }
+
+ if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS &&
+ ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
+ ctx->graph->internal->thread_execute) {
+ ctx->thread_type = AVFILTER_THREAD_SLICE;
+ ctx->internal->execute = ctx->graph->internal->thread_execute;
+ } else {
+ ctx->thread_type = 0;
+ }
+
if (ctx->filter->priv_class) {
ret = av_opt_set_dict(ctx->priv, options);
if (ret < 0) {