Merge commit '7bbc254d646ed9cf6deffc3fda75ae6729f95979'
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 21 Mar 2015 15:54:48 +0000 (16:54 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 21 Mar 2015 15:54:48 +0000 (16:54 +0100)
* commit '7bbc254d646ed9cf6deffc3fda75ae6729f95979':
  h264: move resync_mb_{x,y} into the per-slice context

Conflicts:
libavcodec/h264_slice.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/h264.h
libavcodec/h264_slice.c

Simple merge
@@@ -1756,12 -1557,12 +1756,12 @@@ int ff_h264_decode_slice_header(H264Con
          av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
          return AVERROR_INVALIDDATA;
      }
-     h->resync_mb_x = sl->mb_x =  first_mb_in_slice % h->mb_width;
-     h->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) <<
-                                FIELD_OR_MBAFF_PICTURE(h);
+     sl->resync_mb_x = sl->mb_x =  first_mb_in_slice % h->mb_width;
+     sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) <<
+                                  FIELD_OR_MBAFF_PICTURE(h);
      if (h->picture_structure == PICT_BOTTOM_FIELD)
-         h->resync_mb_y = sl->mb_y = sl->mb_y + 1;
+         sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
 -    assert(sl->mb_y < h->mb_height);
 +    av_assert1(sl->mb_y < h->mb_height);
  
      if (h->picture_structure == PICT_FRAME) {
          h->curr_pic_num = h->frame_num;
                     6 * (h->sps.bit_depth_luma - 8);
  
      h0->last_slice_type = slice_type;
 +    memcpy(h0->last_ref_count, sl->ref_count, sizeof(h0->last_ref_count));
      sl->slice_num       = ++h0->current_slice;
 -    if (sl->slice_num >= MAX_SLICES) {
 -        av_log(h->avctx, AV_LOG_ERROR,
 -               "Too many slices, increase MAX_SLICES and recompile\n");
 +
 +    if (sl->slice_num)
-         h0->slice_row[(sl->slice_num-1)&(MAX_SLICES-1)]= h->resync_mb_y;
-     if (   h0->slice_row[sl->slice_num&(MAX_SLICES-1)] + 3 >= h->resync_mb_y
-         && h0->slice_row[sl->slice_num&(MAX_SLICES-1)] <= h->resync_mb_y
++        h0->slice_row[(sl->slice_num-1)&(MAX_SLICES-1)]= sl->resync_mb_y;
++    if (   h0->slice_row[sl->slice_num&(MAX_SLICES-1)] + 3 >= sl->resync_mb_y
++        && h0->slice_row[sl->slice_num&(MAX_SLICES-1)] <= sl->resync_mb_y
 +        && sl->slice_num >= MAX_SLICES) {
 +        //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case
 +        av_log(h->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", sl->slice_num, MAX_SLICES);
      }
  
      for (j = 0; j < 2; j++) {
@@@ -2409,16 -2190,6 +2409,16 @@@ static int decode_slice(struct AVCodecC
                       avctx->codec_id != AV_CODEC_ID_H264 ||
                       (CONFIG_GRAY && (h->flags & CODEC_FLAG_GRAY));
  
-         const int start_i  = av_clip(h->resync_mb_x + h->resync_mb_y * h->mb_width, 0, h->mb_num - 1);
 +    if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && h->er.error_status_table) {
++        const int start_i  = av_clip(sl->resync_mb_x + sl->resync_mb_y * h->mb_width, 0, h->mb_num - 1);
 +        if (start_i) {
 +            int prev_status = h->er.error_status_table[h->er.mb_index2xy[start_i - 1]];
 +            prev_status &= ~ VP_START;
 +            if (prev_status != (ER_MV_END | ER_DC_END | ER_AC_END))
 +                h->er.error_occurred = 1;
 +        }
 +    }
 +
      if (h->pps.cabac) {
          /* realign */
          align_get_bits(&h->gb);
                      loop_filter(h, sl, lf_x_start, sl->mb_x + 1);
                  return 0;
              }
 -            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(h, sl, h->resync_mb_x, h->resync_mb_y, sl->mb_x,
+                 er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
                               sl->mb_y, ER_MB_ERROR);
                  return AVERROR_INVALIDDATA;
              }
                      tprintf(h->avctx, "slice end %d %d\n",
                              get_bits_count(&h->gb), h->gb.size_in_bits);
  
 -                    if (get_bits_left(&h->gb) == 0) {
 +                    if (   get_bits_left(&h->gb) == 0
 +                        || get_bits_left(&h->gb) > 0 && !(h->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
-                         er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y,
+                         er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y,
                                       sl->mb_x - 1, sl->mb_y, ER_MB_END);
  
                          return 0;
                      } else {
-                         er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y,
+                         er_add_slice(h, 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;
                      }