]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h264_loopfilter.c
avcodec/h264: Fix race between slices where one overwrites data from the next
[ffmpeg] / libavcodec / h264_loopfilter.c
index e81751a2041cb5447c6e5cd89ea977265e499b5d..aed14fd007683ffd1fd4d03ca34357919a53feec 100644 (file)
@@ -101,7 +101,7 @@ static const uint8_t tc0_table[52*3][4] = {
 static av_always_inline void filter_mb_edgev(uint8_t *pix, int stride,
                                              const int16_t bS[4],
                                              unsigned int qp, int a, int b,
-                                             H264Context *h, int intra)
+                                             const H264Context *h, int intra)
 {
     const unsigned int index_a = qp + a;
     const int alpha = alpha_table[index_a];
@@ -123,7 +123,7 @@ static av_always_inline void filter_mb_edgev(uint8_t *pix, int stride,
 static av_always_inline void filter_mb_edgecv(uint8_t *pix, int stride,
                                               const int16_t bS[4],
                                               unsigned int qp, int a, int b,
-                                              H264Context *h, int intra)
+                                              const H264Context *h, int intra)
 {
     const unsigned int index_a = qp + a;
     const int alpha = alpha_table[index_a];
@@ -142,7 +142,7 @@ static av_always_inline void filter_mb_edgecv(uint8_t *pix, int stride,
     }
 }
 
-static av_always_inline void filter_mb_mbaff_edgev(H264Context *h, uint8_t *pix,
+static av_always_inline void filter_mb_mbaff_edgev(const H264Context *h, uint8_t *pix,
                                                    int stride,
                                                    const int16_t bS[7], int bsi,
                                                    int qp, int a, int b,
@@ -165,7 +165,7 @@ static av_always_inline void filter_mb_mbaff_edgev(H264Context *h, uint8_t *pix,
     }
 }
 
-static av_always_inline void filter_mb_mbaff_edgecv(H264Context *h,
+static av_always_inline void filter_mb_mbaff_edgecv(const H264Context *h,
                                                     uint8_t *pix, int stride,
                                                     const int16_t bS[7],
                                                     int bsi, int qp, int a,
@@ -191,7 +191,7 @@ static av_always_inline void filter_mb_mbaff_edgecv(H264Context *h,
 static av_always_inline void filter_mb_edgeh(uint8_t *pix, int stride,
                                              const int16_t bS[4],
                                              unsigned int qp, int a, int b,
-                                             H264Context *h, int intra)
+                                             const H264Context *h, int intra)
 {
     const unsigned int index_a = qp + a;
     const int alpha = alpha_table[index_a];
@@ -213,7 +213,7 @@ static av_always_inline void filter_mb_edgeh(uint8_t *pix, int stride,
 static av_always_inline void filter_mb_edgech(uint8_t *pix, int stride,
                                               const int16_t bS[4],
                                               unsigned int qp, int a, int b,
-                                              H264Context *h, int intra)
+                                              const H264Context *h, int intra)
 {
     const unsigned int index_a = qp + a;
     const int alpha = alpha_table[index_a];
@@ -232,7 +232,7 @@ static av_always_inline void filter_mb_edgech(uint8_t *pix, int stride,
     }
 }
 
-static av_always_inline void h264_filter_mb_fast_internal(H264Context *h,
+static av_always_inline void h264_filter_mb_fast_internal(const H264Context *h,
                                                           H264SliceContext *sl,
                                                           int mb_x, int mb_y,
                                                           uint8_t *img_y,
@@ -246,7 +246,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h,
     int chroma444 = CHROMA444(h);
     int chroma422 = CHROMA422(h);
 
-    int mb_xy = h->mb_xy;
+    int mb_xy = sl->mb_xy;
     int left_type = sl->left_type[LTOP];
     int top_type  = sl->top_type;
 
@@ -414,7 +414,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h,
     }
 }
 
-void ff_h264_filter_mb_fast(H264Context *h, H264SliceContext *sl,
+void ff_h264_filter_mb_fast(const H264Context *h, H264SliceContext *sl,
                             int mb_x, int mb_y, uint8_t *img_y,
                             uint8_t *img_cb, uint8_t *img_cr,
                             unsigned int linesize, unsigned int uvlinesize)
@@ -436,7 +436,7 @@ void ff_h264_filter_mb_fast(H264Context *h, H264SliceContext *sl,
 #endif
 }
 
-static int check_mv(H264Context *h, H264SliceContext *sl, long b_idx, long bn_idx, int mvy_limit)
+static int check_mv(H264SliceContext *sl, long b_idx, long bn_idx, int mvy_limit)
 {
     int v;
 
@@ -466,7 +466,7 @@ static int check_mv(H264Context *h, H264SliceContext *sl, long b_idx, long bn_id
     return v;
 }
 
-static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl,
+static av_always_inline void filter_mb_dir(const H264Context *h, H264SliceContext *sl,
                                            int mb_x, int mb_y,
                                            uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
                                            unsigned int linesize, unsigned int uvlinesize,
@@ -563,7 +563,7 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl,
                     int b_idx= 8 + 4;
                     int bn_idx= b_idx - (dir ? 8:1);
 
-                    bS[0] = bS[1] = bS[2] = bS[3] = check_mv(h, sl, 8 + 4, bn_idx, mvy_limit);
+                    bS[0] = bS[1] = bS[2] = bS[3] = check_mv(sl, 8 + 4, bn_idx, mvy_limit);
                     mv_done = 1;
                 }
                 else
@@ -581,7 +581,7 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl,
                     }
                     else if(!mv_done)
                     {
-                        bS[i] = check_mv(h, sl, b_idx, bn_idx, mvy_limit);
+                        bS[i] = check_mv(sl, b_idx, bn_idx, mvy_limit);
                     }
                 }
             }
@@ -646,7 +646,7 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl,
                 int b_idx= 8 + 4 + edge * (dir ? 8:1);
                 int bn_idx= b_idx - (dir ? 8:1);
 
-                bS[0] = bS[1] = bS[2] = bS[3] = check_mv(h, sl, b_idx, bn_idx, mvy_limit);
+                bS[0] = bS[1] = bS[2] = bS[3] = check_mv(sl, b_idx, bn_idx, mvy_limit);
                 mv_done = 1;
             }
             else
@@ -664,7 +664,7 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl,
                 }
                 else if(!mv_done)
                 {
-                    bS[i] = check_mv(h, sl, b_idx, bn_idx, mvy_limit);
+                    bS[i] = check_mv(sl, b_idx, bn_idx, mvy_limit);
                 }
             }
 
@@ -714,7 +714,7 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl,
     }
 }
 
-void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl,
+void ff_h264_filter_mb(const H264Context *h, H264SliceContext *sl,
                        int mb_x, int mb_y,
                        uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
                        unsigned int linesize, unsigned int uvlinesize)
@@ -757,9 +757,9 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl,
                     {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},
                 }
             };
-            const uint8_t *off= offset[MB_FIELD(h)][mb_y&1];
+            const uint8_t *off= offset[MB_FIELD(sl)][mb_y&1];
             for( i = 0; i < 8; i++ ) {
-                int j= MB_FIELD(h) ? i>>2 : i&1;
+                int j= MB_FIELD(sl) ? i>>2 : i&1;
                 int mbn_xy = sl->left_mb_xy[LEFT(j)];
                 int mbn_type = sl->left_type[LEFT(j)];
 
@@ -768,7 +768,7 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl,
                 else{
                     bS[i] = 1 + !!(sl->non_zero_count_cache[12+8*(i>>1)] |
                          ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ?
-                            (h->cbp_table[mbn_xy] & (((MB_FIELD(h) ? (i&2) : (mb_y&1)) ? 8 : 2) << 12))
+                            (h->cbp_table[mbn_xy] & (((MB_FIELD(sl) ? (i&2) : (mb_y&1)) ? 8 : 2) << 12))
                                                                        :
                             h->non_zero_count[mbn_xy][ off[i] ]));
                 }
@@ -792,7 +792,7 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl,
         /* Filter edge */
         tprintf(h->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize);
         { int i; for (i = 0; i < 8; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); }
-        if (MB_FIELD(h)) {
+        if (MB_FIELD(sl)) {
             filter_mb_mbaff_edgev ( h, img_y                ,   linesize, bS  , 1, qp [0], a, b, 1 );
             filter_mb_mbaff_edgev ( h, img_y  + 8*  linesize,   linesize, bS+4, 1, qp [1], a, b, 1 );
             if (chroma){