avfilter/vf_noise: move shift calculation to filter_frame()

This makes the temporal noise case deterministic with threads

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-10-16 14:28:47 +02:00
parent 411be72dcb
commit aba61b22f7
1 changed files with 15 additions and 12 deletions

View File

@ -157,12 +157,6 @@ static av_cold int init_noise(NoiseContext *n, int comp)
for (j = 0; j < 3; j++)
fp->prev_shift[i][j] = noise + (av_lfg_get(lfg) & (MAX_SHIFT - 1));
if (!n->rand_shift_init) {
for (i = 0; i < MAX_RES; i++)
n->rand_shift[i] = av_lfg_get(lfg) & (MAX_SHIFT - 1);
n->rand_shift_init = 1;
}
fp->noise = noise;
return 0;
}
@ -337,8 +331,7 @@ static void noise(uint8_t *dst, const uint8_t *src,
FilterParams *p = &n->param[comp];
int8_t *noise = p->noise;
const int flags = p->flags;
AVLFG *lfg = &p->lfg;
int shift, y;
int y;
if (!noise) {
if (dst != src)
@ -351,10 +344,7 @@ static void noise(uint8_t *dst, const uint8_t *src,
int x;
for (x=0; x < width; x+= MAX_RES) {
int w = FFMIN(width - x, MAX_RES);
if (flags & NOISE_TEMPORAL)
shift = av_lfg_get(lfg) & (MAX_SHIFT - 1);
else
shift = n->rand_shift[ix];
int shift = n->rand_shift[ix];
if (flags & NOISE_AVERAGED) {
n->line_noise_avg(dst + x, src + x, w, (const int8_t**)p->prev_shift[ix]);
@ -393,6 +383,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
NoiseContext *n = ctx->priv;
ThreadData td;
AVFrame *out;
int comp, i;
if (av_frame_is_writable(inpicref)) {
out = inpicref;
@ -405,6 +396,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
av_frame_copy_props(out, inpicref);
}
for (comp = 0; comp < 4; comp++) {
FilterParams *fp = &n->param[comp];
if ((!n->rand_shift_init || (fp->flags & NOISE_TEMPORAL)) && fp->strength) {
for (i = 0; i < MAX_RES; i++) {
n->rand_shift[i] = av_lfg_get(&fp->lfg) & (MAX_SHIFT - 1);
}
n->rand_shift_init = 1;
}
}
td.in = inpicref; td.out = out;
ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(n->height[0], ctx->graph->nb_threads));
emms_c();