mirror of https://git.videolan.org/git/ffmpeg.git
avfilter/vf_stack: add slice threading
This commit is contained in:
parent
44095564d4
commit
631f7acc6c
|
@ -116,6 +116,29 @@ static av_cold int init(AVFilterContext *ctx)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int process_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
|
||||||
|
{
|
||||||
|
StackContext *s = ctx->priv;
|
||||||
|
AVFrame *out = arg;
|
||||||
|
AVFrame **in = s->frames;
|
||||||
|
const int start = (s->nb_inputs * job ) / nb_jobs;
|
||||||
|
const int end = (s->nb_inputs * (job+1)) / nb_jobs;
|
||||||
|
|
||||||
|
for (int i = start; i < end; i++) {
|
||||||
|
StackItem *item = &s->items[i];
|
||||||
|
|
||||||
|
for (int p = 0; p < s->nb_planes; p++) {
|
||||||
|
av_image_copy_plane(out->data[p] + out->linesize[p] * item->y[p] + item->x[p],
|
||||||
|
out->linesize[p],
|
||||||
|
in[i]->data[p],
|
||||||
|
in[i]->linesize[p],
|
||||||
|
item->linesize[p], item->height[p]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int process_frame(FFFrameSync *fs)
|
static int process_frame(FFFrameSync *fs)
|
||||||
{
|
{
|
||||||
AVFilterContext *ctx = fs->parent;
|
AVFilterContext *ctx = fs->parent;
|
||||||
|
@ -123,7 +146,7 @@ static int process_frame(FFFrameSync *fs)
|
||||||
StackContext *s = fs->opaque;
|
StackContext *s = fs->opaque;
|
||||||
AVFrame **in = s->frames;
|
AVFrame **in = s->frames;
|
||||||
AVFrame *out;
|
AVFrame *out;
|
||||||
int i, p, ret;
|
int i, ret;
|
||||||
|
|
||||||
for (i = 0; i < s->nb_inputs; i++) {
|
for (i = 0; i < s->nb_inputs; i++) {
|
||||||
if ((ret = ff_framesync_get_frame(&s->fs, i, &in[i], 0)) < 0)
|
if ((ret = ff_framesync_get_frame(&s->fs, i, &in[i], 0)) < 0)
|
||||||
|
@ -136,17 +159,7 @@ static int process_frame(FFFrameSync *fs)
|
||||||
out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
|
out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
|
||||||
out->sample_aspect_ratio = outlink->sample_aspect_ratio;
|
out->sample_aspect_ratio = outlink->sample_aspect_ratio;
|
||||||
|
|
||||||
for (i = 0; i < s->nb_inputs; i++) {
|
ctx->internal->execute(ctx, process_slice, out, NULL, FFMIN(s->nb_inputs, ff_filter_get_nb_threads(ctx)));
|
||||||
StackItem *item = &s->items[i];
|
|
||||||
|
|
||||||
for (p = 0; p < s->nb_planes; p++) {
|
|
||||||
av_image_copy_plane(out->data[p] + out->linesize[p] * item->y[p] + item->x[p],
|
|
||||||
out->linesize[p],
|
|
||||||
in[i]->data[p],
|
|
||||||
in[i]->linesize[p],
|
|
||||||
item->linesize[p], item->height[p]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ff_filter_frame(outlink, out);
|
return ff_filter_frame(outlink, out);
|
||||||
}
|
}
|
||||||
|
@ -370,7 +383,7 @@ AVFilter ff_vf_hstack = {
|
||||||
.init = init,
|
.init = init,
|
||||||
.uninit = uninit,
|
.uninit = uninit,
|
||||||
.activate = activate,
|
.activate = activate,
|
||||||
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
|
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIG_HSTACK_FILTER */
|
#endif /* CONFIG_HSTACK_FILTER */
|
||||||
|
@ -390,7 +403,7 @@ AVFilter ff_vf_vstack = {
|
||||||
.init = init,
|
.init = init,
|
||||||
.uninit = uninit,
|
.uninit = uninit,
|
||||||
.activate = activate,
|
.activate = activate,
|
||||||
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
|
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIG_VSTACK_FILTER */
|
#endif /* CONFIG_VSTACK_FILTER */
|
||||||
|
@ -416,7 +429,7 @@ AVFilter ff_vf_xstack = {
|
||||||
.init = init,
|
.init = init,
|
||||||
.uninit = uninit,
|
.uninit = uninit,
|
||||||
.activate = activate,
|
.activate = activate,
|
||||||
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
|
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIG_XSTACK_FILTER */
|
#endif /* CONFIG_XSTACK_FILTER */
|
||||||
|
|
Loading…
Reference in New Issue