[FFmpeg-devel] [PATCH] lavfi/noise: support slice threading
Paul B Mahol
onemda at gmail.com
Sun May 26 13:57:55 CEST 2013
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavfilter/vf_noise.c | 56 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 39 insertions(+), 17 deletions(-)
diff --git a/libavfilter/vf_noise.c b/libavfilter/vf_noise.c
index 12aca24..4d59d58 100644
--- a/libavfilter/vf_noise.c
+++ b/libavfilter/vf_noise.c
@@ -67,6 +67,13 @@ typedef struct {
void (*line_noise_avg)(uint8_t *dst, const uint8_t *src, int len, int8_t **shift);
} NoiseContext;
+typedef struct ThreadData {
+ const uint8_t *src;
+ uint8_t *dst;
+ int dst_linesize, src_linesize;
+ int comp;
+} ThreadData;
+
#define OFFSET(x) offsetof(NoiseContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
@@ -328,22 +335,30 @@ static inline void line_noise_avg_mmx(uint8_t *dst, const uint8_t *src,
#endif
}
-static void noise(uint8_t *dst, const uint8_t *src,
- int dst_linesize, int src_linesize,
- int width, int height, NoiseContext *n, int comp)
+static int noise(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
+ NoiseContext *n = ctx->priv;
+ ThreadData *td = arg;
+ const int comp = td->comp;
+ int height = n->height[comp];
+ int start = (height * jobnr ) / nb_jobs;
+ int end = (height * (jobnr+1)) / nb_jobs;
int8_t *noise = n->param[comp].noise;
int flags = n->param[comp].flags;
AVLFG *lfg = &n->param[comp].lfg;
+ uint8_t *dst = td->dst + start * td->dst_linesize;
+ const uint8_t *src = td->src + start * td->src_linesize;
+ const int width = n->linesize[comp];
int shift, y;
if (!noise) {
if (dst != src)
- av_image_copy_plane(dst, dst_linesize, src, src_linesize, width, height);
- return;
+ av_image_copy_plane(dst, td->dst_linesize, src, td->src_linesize,
+ width, end - start);
+ return 0;
}
- for (y = 0; y < height; y++) {
+ for (y = start; y < end; y++) {
if (flags & NOISE_TEMPORAL)
shift = av_lfg_get(lfg) & (MAX_SHIFT - 1);
else
@@ -355,19 +370,18 @@ static void noise(uint8_t *dst, const uint8_t *src,
} else {
n->line_noise(dst, src, noise, width, shift);
}
- dst += dst_linesize;
- src += src_linesize;
+ dst += td->dst_linesize;
+ src += td->src_linesize;
}
- n->param[comp].shiftptr++;
- if (n->param[comp].shiftptr == 3)
- n->param[comp].shiftptr = 0;
+ return 0;
}
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
{
- NoiseContext *n = inlink->dst->priv;
- AVFilterLink *outlink = inlink->dst->outputs[0];
+ AVFilterContext *ctx = inlink->dst;
+ AVFilterLink *outlink = ctx->outputs[0];
+ NoiseContext *n = ctx->priv;
AVFrame *out;
int i;
@@ -382,9 +396,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
av_frame_copy_props(out, inpicref);
}
- for (i = 0; i < n->nb_planes; i++)
- noise(out->data[i], inpicref->data[i], out->linesize[i],
- inpicref->linesize[i], n->linesize[i], n->height[i], n, i);
+ for (i = 0; i < n->nb_planes; i++) {
+ ThreadData td = { .src = inpicref->data[i], .dst = out->data[i],
+ .src_linesize = inpicref->linesize[i],
+ .dst_linesize = out->linesize[i], .comp = i };
+
+ ctx->internal->execute(ctx, noise, &td, NULL, FFMIN(n->height[i], ctx->graph->nb_threads));
+
+ n->param[i].shiftptr++;
+ if (n->param[i].shiftptr == 3)
+ n->param[i].shiftptr = 0;
+ }
emms_c();
if (inpicref != out)
@@ -463,5 +485,5 @@ AVFilter avfilter_vf_noise = {
.inputs = noise_inputs,
.outputs = noise_outputs,
.priv_class = &noise_class,
- .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
};
--
1.7.11.2
More information about the ffmpeg-devel
mailing list