[FFmpeg-cvslog] avfilter/vf_noise: move shift calculation to filter_frame()

Michael Niedermayer git at videolan.org
Thu Oct 16 14:40:03 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Thu Oct 16 14:28:47 2014 +0200| [aba61b22f70ff5407cd5ff1f797fff42dee07359] | committer: Michael Niedermayer

avfilter/vf_noise: move shift calculation to filter_frame()

This makes the temporal noise case deterministic with threads

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=aba61b22f70ff5407cd5ff1f797fff42dee07359
---

 libavfilter/vf_noise.c |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/libavfilter/vf_noise.c b/libavfilter/vf_noise.c
index 051ccc2..6250253 100644
--- a/libavfilter/vf_noise.c
+++ b/libavfilter/vf_noise.c
@@ -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();



More information about the ffmpeg-cvslog mailing list