Merge commit '92c6c2a605f9b077b8fbc25b7ed6625541232b87'
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 21 Mar 2015 12:13:12 +0000 (13:13 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 21 Mar 2015 12:13:12 +0000 (13:13 +0100)
* commit '92c6c2a605f9b077b8fbc25b7ed6625541232b87':
  h264: split weighted pred-related vars into per-slice context

Conflicts:
libavcodec/h264.c
libavcodec/h264.h
libavcodec/h264_mb.c
libavcodec/svq3.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/dxva2_h264.c
libavcodec/h264.c
libavcodec/h264.h
libavcodec/h264_mb.c
libavcodec/h264_mb_template.c
libavcodec/h264_mc_template.c
libavcodec/h264_parser.c
libavcodec/h264_refs.c
libavcodec/h264_slice.c
libavcodec/svq3.c
libavcodec/vaapi_h264.c

Simple merge
@@@ -89,9 -73,8 +89,9 @@@ static void h264_er_decode_mb(void *opa
      fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
      fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8,
                     pack16to32((*mv)[0][0][0], (*mv)[0][0][1]), 4);
 -    assert(!FRAME_MBAFF(h));
 +    h->mb_mbaff =
 +    h->mb_field_decoding_flag = 0;
-     ff_h264_hl_decode_mb(h);
+     ff_h264_hl_decode_mb(h, &h->slice_ctx[0]);
  }
  
  void ff_h264_draw_horiz_band(H264Context *h, int y, int height)
@@@ -985,27 -1002,17 +1006,27 @@@ int ff_pred_weight_table(H264Context *h
      int list, i;
      int luma_def, chroma_def;
  
-     h->use_weight             = 0;
-     h->use_weight_chroma      = 0;
-     h->luma_log2_weight_denom = get_ue_golomb(&h->gb);
+     sl->use_weight             = 0;
+     sl->use_weight_chroma      = 0;
+     sl->luma_log2_weight_denom = get_ue_golomb(&h->gb);
      if (h->sps.chroma_format_idc)
-         h->chroma_log2_weight_denom = get_ue_golomb(&h->gb);
+         sl->chroma_log2_weight_denom = get_ue_golomb(&h->gb);
 +
-     if (h->luma_log2_weight_denom > 7U) {
-         av_log(h->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", h->luma_log2_weight_denom);
-         h->luma_log2_weight_denom = 0;
++    if (sl->luma_log2_weight_denom > 7U) {
++        av_log(h->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", sl->luma_log2_weight_denom);
++        sl->luma_log2_weight_denom = 0;
 +    }
-     if (h->chroma_log2_weight_denom > 7U) {
-         av_log(h->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", h->chroma_log2_weight_denom);
-         h->chroma_log2_weight_denom = 0;
++    if (sl->chroma_log2_weight_denom > 7U) {
++        av_log(h->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", sl->chroma_log2_weight_denom);
++        sl->chroma_log2_weight_denom = 0;
 +    }
 +
-     luma_def   = 1 << h->luma_log2_weight_denom;
-     chroma_def = 1 << h->chroma_log2_weight_denom;
+     luma_def   = 1 << sl->luma_log2_weight_denom;
+     chroma_def = 1 << sl->chroma_log2_weight_denom;
  
      for (list = 0; list < 2; list++) {
-         h->luma_weight_flag[list]   = 0;
-         h->chroma_weight_flag[list] = 0;
+         sl->luma_weight_flag[list]   = 0;
+         sl->chroma_weight_flag[list] = 0;
          for (i = 0; i < h->ref_count[list]; i++) {
              int luma_weight_flag, chroma_weight_flag;
  
@@@ -1546,21 -1528,12 +1569,21 @@@ again
                  hx->intra_gb_ptr      =
                  hx->inter_gb_ptr      = &hx->gb;
  
-                 if ((err = ff_h264_decode_slice_header(hx, h)))
+                 if ((err = ff_h264_decode_slice_header(hx, sl, h)))
                      break;
  
 -                if (h->sei_recovery_frame_cnt >= 0 && h->recovery_frame < 0) {
 -                    h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) &
 -                                        ((1 << h->sps.log2_max_frame_num) - 1);
 +                if (h->sei_recovery_frame_cnt >= 0) {
 +                    if (h->frame_num != h->sei_recovery_frame_cnt || hx->slice_type_nos != AV_PICTURE_TYPE_I)
 +                        h->valid_recovery_point = 1;
 +
 +                    if (   h->recovery_frame < 0
 +                        || ((h->recovery_frame - h->frame_num) & ((1 << h->sps.log2_max_frame_num)-1)) > h->sei_recovery_frame_cnt) {
 +                        h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) &
 +                                            ((1 << h->sps.log2_max_frame_num) - 1);
 +
 +                        if (!h->valid_recovery_point)
 +                            h->recovery_frame = h->frame_num;
 +                    }
                  }
  
                  h->cur_pic_ptr->f.key_frame |=
@@@ -325,14 -294,24 +325,30 @@@ typedef struct H264Picture 
      int needs_realloc;      ///< picture needs to be reallocated (eg due to a frame size change)
      int reference;
      int recovered;          ///< picture at IDR or recovery point + recovery count
 +    int invalid_gap;
 +    int sei_recovery_frame_cnt;
 +
 +    int crop;
 +    int crop_left;
 +    int crop_top;
  } H264Picture;
  
+ typedef struct H264SliceContext {
+     struct H264Context *h264;
+     // Weighted pred stuff
+     int use_weight;
+     int use_weight_chroma;
+     int luma_log2_weight_denom;
+     int chroma_log2_weight_denom;
+     int luma_weight_flag[2];    ///< 7.4.3.2 luma_weight_lX_flag
+     int chroma_weight_flag[2];  ///< 7.4.3.2 chroma_weight_lX_flag
+     // The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss
+     int luma_weight[48][2][2];
+     int chroma_weight[48][2][2][2];
+     int implicit_weight[48][48][2];
+ } H264SliceContext;
  /**
   * H264Context
   */
@@@ -349,8 -327,10 +365,11 @@@ typedef struct H264Context 
      H264Picture *DPB;
      H264Picture *cur_pic_ptr;
      H264Picture cur_pic;
 +    H264Picture last_pic_for_ec;
  
+     H264SliceContext *slice_ctx;
+     int            nb_slice_ctx;
      int pixel_shift;    ///< 0 for 8-bit H264, 1 for high-bit-depth H264
      int chroma_qp[2];   // QPc
  
  
      int frame_recovered;    ///< Initial frame has been completely recovered
  
-     int luma_weight_flag[2];    ///< 7.4.3.2 luma_weight_lX_flag
-     int chroma_weight_flag[2];  ///< 7.4.3.2 chroma_weight_lX_flag
 +    int has_recovery_point;
 +
 +    int missing_fields;
 +
  
      // Timestamp stuff
      int sei_buffering_period_present;   ///< Buffering period SEI flag
@@@ -847,8 -795,8 +855,8 @@@ int ff_h264_check_intra4x4_pred_mode(H2
   */
  int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma);
  
- void ff_h264_hl_decode_mb(H264Context *h);
+ void ff_h264_hl_decode_mb(H264Context *h, H264SliceContext *sl);
 -int ff_h264_decode_extradata(H264Context *h);
 +int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size);
  int ff_h264_decode_init(AVCodecContext *avctx);
  void ff_h264_decode_init_vlc(void);
  
@@@ -1137,13 -1044,10 +1145,13 @@@ int ff_h264_set_parameter_from_sps(H264
  
  void ff_h264_draw_horiz_band(H264Context *h, int y, int height);
  int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc);
- int ff_pred_weight_table(H264Context *h);
+ int ff_pred_weight_table(H264Context *h, H264SliceContext *sl);
  int ff_set_ref_count(H264Context *h);
  
- int ff_h264_decode_slice_header(H264Context *h, H264Context *h0);
+ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Context *h0);
 +#define SLICE_SINGLETHREAD 1
 +#define SLICE_SKIPED 2
 +
  int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count);
  int ff_h264_update_thread_context(AVCodecContext *dst,
                                    const AVCodecContext *src);
@@@ -420,33 -421,29 +421,33 @@@ static av_always_inline void mc_part_we
              int weight1 = 64 - weight0;
              luma_weight_avg(dest_y, tmp_y, h->mb_linesize,
                              height, 5, weight0, weight1, 0);
 -            chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize,
 -                              chroma_height, 5, weight0, weight1, 0);
 -            chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize,
 -                              chroma_height, 5, weight0, weight1, 0);
 +            if (!CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) {
 +                chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize,
 +                                  chroma_height, 5, weight0, weight1, 0);
 +                chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize,
 +                                  chroma_height, 5, weight0, weight1, 0);
 +            }
          } else {
              luma_weight_avg(dest_y, tmp_y, h->mb_linesize, height,
-                             h->luma_log2_weight_denom,
-                             h->luma_weight[refn0][0][0],
-                             h->luma_weight[refn1][1][0],
-                             h->luma_weight[refn0][0][1] +
-                             h->luma_weight[refn1][1][1]);
+                             sl->luma_log2_weight_denom,
+                             sl->luma_weight[refn0][0][0],
+                             sl->luma_weight[refn1][1][0],
+                             sl->luma_weight[refn0][0][1] +
+                             sl->luma_weight[refn1][1][1]);
 -            chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, chroma_height,
 -                              sl->chroma_log2_weight_denom,
 -                              sl->chroma_weight[refn0][0][0][0],
 -                              sl->chroma_weight[refn1][1][0][0],
 -                              sl->chroma_weight[refn0][0][0][1] +
 -                              sl->chroma_weight[refn1][1][0][1]);
 -            chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, chroma_height,
 -                              sl->chroma_log2_weight_denom,
 -                              sl->chroma_weight[refn0][0][1][0],
 -                              sl->chroma_weight[refn1][1][1][0],
 -                              sl->chroma_weight[refn0][0][1][1] +
 -                              sl->chroma_weight[refn1][1][1][1]);
 +            if (!CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) {
 +                chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, chroma_height,
-                                   h->chroma_log2_weight_denom,
-                                   h->chroma_weight[refn0][0][0][0],
-                                   h->chroma_weight[refn1][1][0][0],
-                                   h->chroma_weight[refn0][0][0][1] +
-                                   h->chroma_weight[refn1][1][0][1]);
++                                  sl->chroma_log2_weight_denom,
++                                  sl->chroma_weight[refn0][0][0][0],
++                                  sl->chroma_weight[refn1][1][0][0],
++                                  sl->chroma_weight[refn0][0][0][1] +
++                                  sl->chroma_weight[refn1][1][0][1]);
 +                chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, chroma_height,
-                                   h->chroma_log2_weight_denom,
-                                   h->chroma_weight[refn0][0][1][0],
-                                   h->chroma_weight[refn1][1][1][0],
-                                   h->chroma_weight[refn0][0][1][1] +
-                                   h->chroma_weight[refn1][1][1][1]);
++                                  sl->chroma_log2_weight_denom,
++                                  sl->chroma_weight[refn0][0][1][0],
++                                  sl->chroma_weight[refn1][1][1][0],
++                                  sl->chroma_weight[refn0][0][1][1] +
++                                  sl->chroma_weight[refn1][1][1][1]);
 +            }
          }
      } else {
          int list     = list1 ? 1 : 0;
                      qpix_put, chroma_put, pixel_shift, chroma_idc);
  
          luma_weight_op(dest_y, h->mb_linesize, height,
-                        h->luma_log2_weight_denom,
-                        h->luma_weight[refn][list][0],
-                        h->luma_weight[refn][list][1]);
+                        sl->luma_log2_weight_denom,
+                        sl->luma_weight[refn][list][0],
+                        sl->luma_weight[refn][list][1]);
 -        if (sl->use_weight_chroma) {
 -            chroma_weight_op(dest_cb, h->mb_uvlinesize, chroma_height,
 -                             sl->chroma_log2_weight_denom,
 -                             sl->chroma_weight[refn][list][0][0],
 -                             sl->chroma_weight[refn][list][0][1]);
 -            chroma_weight_op(dest_cr, h->mb_uvlinesize, chroma_height,
 -                             sl->chroma_log2_weight_denom,
 -                             sl->chroma_weight[refn][list][1][0],
 -                             sl->chroma_weight[refn][list][1][1]);
 +        if (!CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) {
-             if (h->use_weight_chroma) {
++            if (sl->use_weight_chroma) {
 +                chroma_weight_op(dest_cb, h->mb_uvlinesize, chroma_height,
-                                  h->chroma_log2_weight_denom,
-                                  h->chroma_weight[refn][list][0][0],
-                                  h->chroma_weight[refn][list][0][1]);
++                                 sl->chroma_log2_weight_denom,
++                                 sl->chroma_weight[refn][list][0][0],
++                                 sl->chroma_weight[refn][list][0][1]);
 +                chroma_weight_op(dest_cr, h->mb_uvlinesize, chroma_height,
-                                  h->chroma_log2_weight_denom,
-                                  h->chroma_weight[refn][list][1][0],
-                                  h->chroma_weight[refn][list][1][1]);
++                                 sl->chroma_log2_weight_denom,
++                                 sl->chroma_weight[refn][list][1][0],
++                                 sl->chroma_weight[refn][list][1][1]);
 +            }
          }
      }
  }
Simple merge
Simple merge
Simple merge
@@@ -341,10 -337,10 +341,10 @@@ int ff_h264_decode_ref_pic_list_reorder
      return 0;
  }
  
- void ff_h264_fill_mbaff_ref_list(H264Context *h)
+ void ff_h264_fill_mbaff_ref_list(H264Context *h, H264SliceContext *sl)
  {
      int list, i, j;
 -    for (list = 0; list < 2; list++) { //FIXME try list_count
 +    for (list = 0; list < h->list_count; list++) {
          for (i = 0; i < h->ref_count[list]; i++) {
              H264Picture *frame = &h->ref_list[list][i];
              H264Picture *field = &h->ref_list[list][16 + 2 * i];
@@@ -506,21 -474,18 +506,23 @@@ int ff_h264_update_thread_context(AVCod
          }
          context_reinitialized = 1;
  
 -        /* update linesize on resize. The decoder doesn't
 -         * necessarily call h264_frame_start in the new thread */
 -        h->linesize   = h1->linesize;
 -        h->uvlinesize = h1->uvlinesize;
 -
 -        /* copy block_offset since frame_start may not be called */
 -        memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset));
 +#if 0
 +        h264_set_parameter_from_sps(h);
 +        //Note we set context_reinitialized which will cause h264_set_parameter_from_sps to be reexecuted
 +        h->cur_chroma_format_idc = h1->cur_chroma_format_idc;
 +#endif
      }
 +    /* update linesize on resize for h264. The h264 decoder doesn't
 +     * necessarily call ff_mpv_frame_start in the new thread */
 +    h->linesize   = h1->linesize;
 +    h->uvlinesize = h1->uvlinesize;
 +
 +    /* copy block_offset since frame_start may not be called */
 +    memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset));
  
      if (!inited) {
+         H264SliceContext *orig_slice_ctx = h->slice_ctx;
          for (i = 0; i < MAX_SPS_COUNT; i++)
              av_freep(h->sps_buffers + i);
  
          memset(&h->mb, 0, sizeof(h->mb));
          memset(&h->mb_luma_dc, 0, sizeof(h->mb_luma_dc));
          memset(&h->mb_padding, 0, sizeof(h->mb_padding));
 -        h->context_initialized = 0;
 -
          memset(&h->cur_pic, 0, sizeof(h->cur_pic));
 -        av_frame_unref(&h->cur_pic.f);
 -        h->cur_pic.tf.f = &h->cur_pic.f;
 +        memset(&h->last_pic_for_ec, 0, sizeof(h->last_pic_for_ec));
  
+         h->slice_ctx = orig_slice_ctx;
          h->avctx             = dst;
          h->DPB               = NULL;
          h->qscale_table_pool = NULL;
@@@ -2573,25 -2345,18 +2580,25 @@@ int ff_h264_execute_decode_slices(H264C
      H264Context *hx;
      int i;
  
 -    if (h->avctx->hwaccel)
 +    av_assert0(h->mb_y < h->mb_height);
 +
 +    if (h->avctx->hwaccel ||
 +        h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
          return 0;
      if (context_count == 1) {
-         return decode_slice(avctx, &h);
+         return decode_slice(avctx, &h->slice_ctx[0]);
      } else {
 +        av_assert0(context_count > 0);
          for (i = 1; i < context_count; i++) {
              hx                 = h->thread_context[i];
 -            hx->er.error_count = 0;
 +            if (CONFIG_ERROR_RESILIENCE) {
 +                hx->er.error_count = 0;
 +            }
 +            hx->x264_build     = h->x264_build;
          }
  
-         avctx->execute(avctx, decode_slice, h->thread_context,
-                        NULL, context_count, sizeof(void *));
+         avctx->execute(avctx, decode_slice, h->slice_ctx,
+                        NULL, context_count, sizeof(h->slice_ctx[0]));
  
          /* pull back stuff from slices to master context */
          hx                   = h->thread_context[context_count - 1];
@@@ -1302,8 -1267,8 +1302,8 @@@ static int svq3_decode_frame(AVCodecCon
                  return -1;
              }
  
 -            if (mb_type != 0)
 +            if (mb_type != 0 || h->cbp)
-                 ff_h264_hl_decode_mb(h);
+                 ff_h264_hl_decode_mb(h, &h->slice_ctx[0]);
  
              if (h->pict_type != AV_PICTURE_TYPE_B && !h->low_delay)
                  h->cur_pic.mb_type[h->mb_x + h->mb_y * h->mb_stride] =
Simple merge