Merge commit 'e6287f077c3e8e4aca11e61dd4bade1351439e6b'
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 21 Mar 2015 13:03:14 +0000 (14:03 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 21 Mar 2015 13:06:30 +0000 (14:06 +0100)
* commit 'e6287f077c3e8e4aca11e61dd4bade1351439e6b':
  h264: move {mv,ref}_cache into the per-slice context

Conflicts:
libavcodec/h264_cabac.c
libavcodec/h264_mb.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
12 files changed:
1  2 
libavcodec/h264.c
libavcodec/h264.h
libavcodec/h264_cabac.c
libavcodec/h264_cavlc.c
libavcodec/h264_direct.c
libavcodec/h264_loopfilter.c
libavcodec/h264_mb.c
libavcodec/h264_mb_template.c
libavcodec/h264_mc_template.c
libavcodec/h264_mvpred.h
libavcodec/h264_slice.c
libavcodec/svq3.c

@@@ -77,21 -69,12 +77,21 @@@ static void h264_er_decode_mb(void *opa
       * practice then correct remapping should be added. */
      if (ref >= h->ref_count[0])
          ref = 0;
 +    if (!h->ref_list[0][ref].f.data[0]) {
 +        av_log(h->avctx, AV_LOG_DEBUG, "Reference not available for error concealing\n");
 +        ref = 0;
 +    }
 +    if ((h->ref_list[0][ref].reference&3) != 3) {
 +        av_log(h->avctx, AV_LOG_DEBUG, "Reference invalid\n");
 +        return;
 +    }
      fill_rectangle(&h->cur_pic.ref_index[0][4 * h->mb_xy],
                     2, 2, 2, ref, 1);
-     fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
-     fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8,
+     fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
+     fill_rectangle(sl->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, &h->slice_ctx[0]);
  }
  
@@@ -502,17 -479,19 +502,19 @@@ int ff_h264_context_init(H264Context *h
      int yc_size = y_size + 2   * c_size;
      int x, y, i;
  
 -    FF_ALLOCZ_OR_GOTO(h->avctx, h->top_borders[0],
 -                      h->mb_width * 16 * 3 * sizeof(uint8_t) * 2, fail)
 -    FF_ALLOCZ_OR_GOTO(h->avctx, h->top_borders[1],
 -                      h->mb_width * 16 * 3 * sizeof(uint8_t) * 2, fail)
 +    FF_ALLOCZ_ARRAY_OR_GOTO(h->avctx, h->top_borders[0],
 +                      h->mb_width, 16 * 3 * sizeof(uint8_t) * 2, fail)
 +    FF_ALLOCZ_ARRAY_OR_GOTO(h->avctx, h->top_borders[1],
 +                      h->mb_width, 16 * 3 * sizeof(uint8_t) * 2, fail)
  
-     h->ref_cache[0][scan8[5]  + 1] =
-     h->ref_cache[0][scan8[7]  + 1] =
-     h->ref_cache[0][scan8[13] + 1] =
-     h->ref_cache[1][scan8[5]  + 1] =
-     h->ref_cache[1][scan8[7]  + 1] =
-     h->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE;
+     for (i = 0; i < h->nb_slice_ctx; i++) {
+         h->slice_ctx[i].ref_cache[0][scan8[5]  + 1] =
+         h->slice_ctx[i].ref_cache[0][scan8[7]  + 1] =
+         h->slice_ctx[i].ref_cache[0][scan8[13] + 1] =
+         h->slice_ctx[i].ref_cache[1][scan8[5]  + 1] =
+         h->slice_ctx[i].ref_cache[1][scan8[7]  + 1] =
+         h->slice_ctx[i].ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE;
+     }
  
      if (CONFIG_ERROR_RESILIENCE) {
          /* init ER */
Simple merge
@@@ -2118,10 -2113,11 +2119,10 @@@ decode_intra_mb
                  for( i = 0; i < 4; i++ ) {
                      if(IS_DIRECT(h->sub_mb_type[i])) continue;
                      if(IS_DIR(h->sub_mb_type[i], 0, list)){
 -                        int rc = h->ref_count[list] << MB_MBAFF(h);
 -                        if (rc > 1) {
 +                        if (local_ref_count[list] > 1) {
-                             ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );
+                             ref[list][i] = decode_cabac_mb_ref(h, sl, list, 4 * i);
 -                            if (ref[list][i] >= (unsigned) rc) {
 -                                av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], rc);
 +                            if (ref[list][i] >= (unsigned)local_ref_count[list]) {
 +                                av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], local_ref_count[list]);
                                  return -1;
                              }
                          }else
          if(IS_16X16(mb_type)){
              for(list=0; list<h->list_count; list++){
                  if(IS_DIR(mb_type, 0, list)){
 -                    int ref, rc = h->ref_count[list] << MB_MBAFF(h);
 -                    if (rc > 1) {
 +                    int ref;
 +                    if (local_ref_count[list] > 1) {
-                         ref= decode_cabac_mb_ref(h, list, 0);
+                         ref= decode_cabac_mb_ref(h, sl, list, 0);
 -                        if (ref >= (unsigned) rc) {
 -                            av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, rc);
 +                        if (ref >= (unsigned)local_ref_count[list]) {
 +                            av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]);
                              return -1;
                          }
                      }else
              for(list=0; list<h->list_count; list++){
                      for(i=0; i<2; i++){
                          if(IS_DIR(mb_type, i, list)){
 -                            int ref, rc = h->ref_count[list] << MB_MBAFF(h);
 -                            if (rc > 1) {
 +                            int ref;
 +                            if (local_ref_count[list] > 1) {
-                                 ref= decode_cabac_mb_ref( h, list, 8*i );
+                                 ref= decode_cabac_mb_ref(h, sl, list, 8 * i);
 -                                if (ref >= (unsigned) rc) {
 -                                    av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, rc);
 +                                if (ref >= (unsigned)local_ref_count[list]) {
 +                                    av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]);
                                      return -1;
                                  }
                              }else
              for(list=0; list<h->list_count; list++){
                      for(i=0; i<2; i++){
                          if(IS_DIR(mb_type, i, list)){ //FIXME optimize
 -                            int ref, rc = h->ref_count[list] << MB_MBAFF(h);
 -                            if (rc > 1) {
 +                            int ref;
 +                            if (local_ref_count[list] > 1) {
-                                 ref= decode_cabac_mb_ref( h, list, 4*i );
+                                 ref= decode_cabac_mb_ref(h, sl, list, 4 * i);
 -                                if (ref >= (unsigned) rc) {
 -                                    av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, rc);
 +                                if (ref >= (unsigned)local_ref_count[list]) {
 +                                    av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]);
                                      return -1;
                                  }
                              }else
@@@ -856,14 -845,14 +856,14 @@@ decode_intra_mb
                  h->sub_mb_type[i]=      b_sub_mb_type_info[ h->sub_mb_type[i] ].type;
              }
              if( IS_DIRECT(h->sub_mb_type[0]|h->sub_mb_type[1]|h->sub_mb_type[2]|h->sub_mb_type[3])) {
-                 ff_h264_pred_direct_motion(h, &mb_type);
-                 h->ref_cache[0][scan8[4]] =
-                 h->ref_cache[1][scan8[4]] =
-                 h->ref_cache[0][scan8[12]] =
-                 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
+                 ff_h264_pred_direct_motion(h, sl, &mb_type);
+                 sl->ref_cache[0][scan8[4]] =
+                 sl->ref_cache[1][scan8[4]] =
+                 sl->ref_cache[0][scan8[12]] =
+                 sl->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
              }
          }else{
 -            assert(h->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ?
 +            av_assert2(h->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ?
              for(i=0; i<4; i++){
                  h->sub_mb_type[i]= get_ue_golomb_31(&h->gb);
                  if(h->sub_mb_type[i] >=4){
Simple merge
Simple merge
  #include "svq3.h"
  #include "thread.h"
  
- static inline int get_lowest_part_list_y(H264Context *h, H264Picture *pic, int n,
+ static inline int get_lowest_part_list_y(H264Context *h, H264SliceContext *sl,
+                                          H264Picture *pic, int n,
                                           int height, int y_offset, int list)
  {
-     int raw_my             = h->mv_cache[list][scan8[n]][1];
+     int raw_my             = sl->mv_cache[list][scan8[n]][1];
 -    int filter_height_up   = (raw_my & 3) ? 2 : 0;
      int filter_height_down = (raw_my & 3) ? 3 : 0;
      int full_my            = (raw_my >> 2) + y_offset;
 -    int top                = full_my - filter_height_up;
      int bottom             = full_my + filter_height_down + height;
  
 -    return FFMAX(abs(top), bottom);
 +    av_assert2(height >= 0);
 +
 +    return FFMAX(0, bottom);
  }
  
- static inline void get_lowest_part_y(H264Context *h, int16_t refs[2][48], int n,
+ static inline void get_lowest_part_y(H264Context *h, H264SliceContext *sl,
 -                                     int refs[2][48], int n,
++                                     int16_t refs[2][48], int n,
                                       int height, int y_offset, int list0,
                                       int list1, int *nrefs)
  {
@@@ -150,10 -152,10 +152,10 @@@ static void await_references(H264Contex
                                    nrefs);
              } else {
                  int j;
 -                assert(IS_SUB_4X4(sub_mb_type));
 +                av_assert2(IS_SUB_4X4(sub_mb_type));
                  for (j = 0; j < 4; j++) {
                      int sub_y_offset = y_offset + 2 * (j & 2);
-                     get_lowest_part_y(h, refs, n + j, 4, sub_y_offset,
+                     get_lowest_part_y(h, sl, refs, n + j, 4, sub_y_offset,
                                        IS_DIR(sub_mb_type, 0, 0),
                                        IS_DIR(sub_mb_type, 0, 1),
                                        nrefs);
@@@ -210,10 -213,10 +213,10 @@@ static av_always_inline void mc_dir_par
                                           h264_chroma_mc_func chroma_op,
                                           int pixel_shift, int chroma_idc)
  {
-     const int mx      = h->mv_cache[list][scan8[n]][0] + src_x_offset * 8;
-     int my            = h->mv_cache[list][scan8[n]][1] + src_y_offset * 8;
+     const int mx      = sl->mv_cache[list][scan8[n]][0] + src_x_offset * 8;
+     int my            = sl->mv_cache[list][scan8[n]][1] + src_y_offset * 8;
      const int luma_xy = (mx & 3) + ((my & 3) << 2);
 -    ptrdiff_t offset  = ((mx >> 2) << pixel_shift) + (my >> 2) * h->mb_linesize;
 +    ptrdiff_t offset  = (mx >> 2) * (1 << pixel_shift) + (my >> 2) * h->mb_linesize;
      uint8_t *src_y    = pic->f.data[0] + offset;
      uint8_t *src_cb, *src_cr;
      int extra_width  = 0;
          src_cr = h->edge_emu_buffer;
      }
      chroma_op(dest_cr, src_cr, h->mb_uvlinesize, height >> (chroma_idc == 1 /* yuv420 */),
 -              mx & 7, (my << (chroma_idc == 2 /* yuv422 */)) & 7);
 +              mx & 7, ((unsigned)my << (chroma_idc == 2 /* yuv422 */)) & 7);
  }
  
- static av_always_inline void mc_part_std(H264Context *h, int n, int square,
+ static av_always_inline void mc_part_std(H264Context *h, H264SliceContext *sl,
+                                          int n, int square,
                                           int height, int delta,
                                           uint8_t *dest_y, uint8_t *dest_cb,
                                           uint8_t *dest_cr,
@@@ -481,12 -480,12 +486,12 @@@ static av_always_inline void prefetch_m
  {
      /* fetch pixels for estimated mv 4 macroblocks ahead
       * optimized for 64byte cache lines */
-     const int refn = h->ref_cache[list][scan8[0]];
+     const int refn = sl->ref_cache[list][scan8[0]];
      if (refn >= 0) {
-         const int mx  = (h->mv_cache[list][scan8[0]][0] >> 2) + 16 * h->mb_x + 8;
-         const int my  = (h->mv_cache[list][scan8[0]][1] >> 2) + 16 * h->mb_y;
+         const int mx  = (sl->mv_cache[list][scan8[0]][0] >> 2) + 16 * h->mb_x + 8;
+         const int my  = (sl->mv_cache[list][scan8[0]][1] >> 2) + 16 * h->mb_y;
          uint8_t **src = h->ref_list[list][refn].f.data;
 -        int off       = (mx << pixel_shift) +
 +        int off       =  mx * (1<< pixel_shift) +
                          (my + (h->mb_x & 3) * 4) * h->mb_linesize +
                          (64 << pixel_shift);
          h->vdsp.prefetch(src[0] + off, h->linesize, 4);
Simple merge
@@@ -74,11 -74,11 +74,11 @@@ static void MCFUNC(hl_motion)(H264Conte
      const int mb_xy   = h->mb_xy;
      const int mb_type = h->cur_pic.mb_type[mb_xy];
  
 -    assert(IS_INTER(mb_type));
 +    av_assert2(IS_INTER(mb_type));
  
      if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME))
-         await_references(h);
-     prefetch_motion(h, 0, PIXEL_SHIFT, CHROMA_IDC);
+         await_references(h, sl);
+     prefetch_motion(h, sl, 0, PIXEL_SHIFT, CHROMA_IDC);
  
      if (IS_16X16(mb_type)) {
          mc_part(h, sl, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,
Simple merge
Simple merge
@@@ -1130,11 -1108,11 +1130,12 @@@ fail
  static int svq3_decode_frame(AVCodecContext *avctx, void *data,
                               int *got_frame, AVPacket *avpkt)
  {
 -    const uint8_t *buf = avpkt->data;
      SVQ3Context *s     = avctx->priv_data;
      H264Context *h     = &s->h;
+     H264SliceContext *sl = &h->slice_ctx[0];
      int buf_size       = avpkt->size;
 +    int left;
 +    uint8_t *buf;
      int ret, m, i;
  
      /* special case for last picture */