OSDN Git Service

Merge commit 'b77fffa127663028169c5ed543956af4b9496c29'
authorClément Bœsch <clement@stupeflix.com>
Mon, 20 Jun 2016 11:00:17 +0000 (13:00 +0200)
committerClément Bœsch <clement@stupeflix.com>
Mon, 20 Jun 2016 13:34:26 +0000 (15:34 +0200)
* commit 'b77fffa127663028169c5ed543956af4b9496c29':
  h264: make slice threading work with deblocking_filter=1

again label, and SLICE_SINGLETHREAD error handling are preserved as that
SLICE_SINGLETHREAD can be raised on a remaining case.

slice_context_count is also kept since it's still in use.

Merged-by: Clément Bœsch <clement@stupeflix.com>
1  2 
libavcodec/h264.h
libavcodec/h264_slice.c

Simple merge
@@@ -1869,12 -1589,12 +1858,12 @@@ static av_always_inline void fill_filte
          if (USES_LIST(top_type, list)) {
              const int b_xy  = h->mb2b_xy[top_xy] + 3 * b_stride;
              const int b8_xy = 4 * top_xy + 2;
-             int *ref2frm = sl->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
 -            int (*ref2frm)[64] = h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2);
++            int *ref2frm = h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
              AV_COPY128(mv_dst - 1 * 8, h->cur_pic.motion_val[list][b_xy + 0]);
              ref_cache[0 - 1 * 8] =
 -            ref_cache[1 - 1 * 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 0]];
 +            ref_cache[1 - 1 * 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 0]];
              ref_cache[2 - 1 * 8] =
 -            ref_cache[3 - 1 * 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 1]];
 +            ref_cache[3 - 1 * 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 1]];
          } else {
              AV_ZERO128(mv_dst - 1 * 8);
              AV_WN32A(&ref_cache[0 - 1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u);
              if (USES_LIST(left_type[LTOP], list)) {
                  const int b_xy  = h->mb2b_xy[left_xy[LTOP]] + 3;
                  const int b8_xy = 4 * left_xy[LTOP] + 1;
-                 int *ref2frm = sl->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
 -                int (*ref2frm)[64] = h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2);
++                int *ref2frm = h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
                  AV_COPY32(mv_dst - 1 +  0, h->cur_pic.motion_val[list][b_xy + b_stride * 0]);
                  AV_COPY32(mv_dst - 1 +  8, h->cur_pic.motion_val[list][b_xy + b_stride * 1]);
                  AV_COPY32(mv_dst - 1 + 16, h->cur_pic.motion_val[list][b_xy + b_stride * 2]);
  
      {
          int8_t *ref = &h->cur_pic.ref_index[list][4 * mb_xy];
-         int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
 -        int (*ref2frm)[64] = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2);
 -        uint32_t ref01 = (pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
 -        uint32_t ref23 = (pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
++        int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
 +        uint32_t ref01 = (pack16to32(ref2frm[ref[0]], ref2frm[ref[1]]) & 0x00FF00FF) * 0x0101;
 +        uint32_t ref23 = (pack16to32(ref2frm[ref[2]], ref2frm[ref[3]]) & 0x00FF00FF) * 0x0101;
          AV_WN32A(&ref_cache[0 * 8], ref01);
          AV_WN32A(&ref_cache[1 * 8], ref01);
          AV_WN32A(&ref_cache[2 * 8], ref23);
@@@ -2226,8 -1951,9 +2219,11 @@@ static int decode_slice(struct AVCodecC
  
      sl->mb_skip_run = -1;
  
 +    av_assert0(h->block_offset[15] == (4 * ((scan8[15] - scan8[0]) & 7) << h->pixel_shift) + 4 * sl->linesize * ((scan8[15] - scan8[0]) >> 3));
 +
+     if (h->postpone_filter)
+         sl->deblocking_filter = 0;
      sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME ||
                       avctx->codec_id != AV_CODEC_ID_H264 ||
                       (CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY));
                               sl->mb_y, ER_MB_END);
                  if (sl->mb_x >= lf_x_start)
                      loop_filter(h, sl, lf_x_start, sl->mb_x + 1);
-                 return 0;
+                 goto finish;
              }
 -            if (ret < 0 || sl->cabac.bytestream > sl->cabac.bytestream_end + 2) {
 +            if (sl->cabac.bytestream > sl->cabac.bytestream_end + 2 )
 +                av_log(h->avctx, AV_LOG_DEBUG, "bytestream overread %"PTRDIFF_SPECIFIER"\n", sl->cabac.bytestream_end - sl->cabac.bytestream);
 +            if (ret < 0 || sl->cabac.bytestream > sl->cabac.bytestream_end + 4) {
                  av_log(h->avctx, AV_LOG_ERROR,
 -                       "error while decoding MB %d %d, bytestream %td\n",
 +                       "error while decoding MB %d %d, bytestream %"PTRDIFF_SPECIFIER"\n",
                         sl->mb_x, sl->mb_y,
                         sl->cabac.bytestream_end - sl->cabac.bytestream);
                  er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
                          er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,
                                       sl->mb_x - 1, sl->mb_y, ER_MB_END);
  
-                         return 0;
+                         goto finish;
                      } else {
                          er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,
 -                                     sl->mb_x - 1, sl->mb_y, ER_MB_END);
 +                                     sl->mb_x, sl->mb_y, ER_MB_END);
  
                          return AVERROR_INVALIDDATA;
                      }
@@@ -2472,10 -2174,26 +2473,28 @@@ int ff_h264_execute_decode_slices(H264C
          /* pull back stuff from slices to master context */
          sl                   = &h->slice_ctx[context_count - 1];
          h->mb_y              = sl->mb_y;
 -        for (i = 1; i < context_count; i++)
 -            h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count;
 +        if (CONFIG_ERROR_RESILIENCE) {
 +            for (i = 1; i < context_count; i++)
 +                h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count;
 +        }
+         if (h->postpone_filter) {
+             h->postpone_filter = 0;
+             for (i = 0; i < context_count; i++) {
+                 int y_end, x_end;
+                 sl = &h->slice_ctx[i];
+                 y_end = FFMIN(sl->mb_y + 1, h->mb_height);
+                 x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x;
+                 for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {
+                     sl->mb_y = j;
+                     loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,
+                                 j == y_end - 1 ? x_end : h->mb_width);
+                 }
+             }
+         }
      }
  
      return 0;