Merge commit 'a6cd154463bea7eb56d28192db4c8c6d83f67fd7'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 29 Apr 2015 09:48:39 +0000 (11:48 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 29 Apr 2015 09:48:39 +0000 (11:48 +0200)
* commit 'a6cd154463bea7eb56d28192db4c8c6d83f67fd7':
  h264: move the DPB init/uninit to init_context()/free_context()

Conflicts:
libavcodec/h264.c

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

@@@ -412,11 -383,11 +403,11 @@@ void ff_h264_free_tables(H264Context *h
  int ff_h264_alloc_tables(H264Context *h)
  {
      const int big_mb_num = h->mb_stride * (h->mb_height + 1);
 -    const int row_mb_num = h->mb_stride * 2 * h->avctx->thread_count;
 +    const int row_mb_num = 2*h->mb_stride*FFMAX(h->avctx->thread_count, 1);
-     int x, y, i;
+     int x, y;
  
 -    FF_ALLOCZ_OR_GOTO(h->avctx, h->intra4x4_pred_mode,
 -                      row_mb_num * 8 * sizeof(uint8_t), fail)
 +    FF_ALLOCZ_ARRAY_OR_GOTO(h->avctx, h->intra4x4_pred_mode,
 +                      row_mb_num, 8 * sizeof(uint8_t), fail)
      h->slice_ctx[0].intra4x4_pred_mode = h->intra4x4_pred_mode;
  
      FF_ALLOCZ_OR_GOTO(h->avctx, h->non_zero_count,
          }
  
      if (!h->dequant4_coeff[0])
 -        h264_init_dequant_tables(h);
 +        ff_h264_init_dequant_tables(h);
  
-     if (!h->DPB) {
-         h->DPB = av_mallocz_array(H264_MAX_PICTURE_COUNT, sizeof(*h->DPB));
-         if (!h->DPB)
-             goto fail;
-         for (i = 0; i < H264_MAX_PICTURE_COUNT; i++)
-             av_frame_unref(&h->DPB[i].f);
-         av_frame_unref(&h->cur_pic.f);
-     }
      return 0;
  
  fail:
@@@ -1914,6 -1746,14 +1903,15 @@@ av_cold void ff_h264_free_context(H264C
  
      ff_h264_free_tables(h, 1); // FIXME cleanup init stuff perhaps
  
+     if (h->DPB) {
+         for (i = 0; i < H264_MAX_PICTURE_COUNT; i++)
+             ff_h264_unref_picture(h, &h->DPB[i]);
++        memset(h->delayed_pic, 0, sizeof(h->delayed_pic));
+         av_freep(&h->DPB);
+     }
+     h->cur_pic_ptr = NULL;
      av_freep(&h->slice_ctx);
      h->nb_slice_ctx = 0;
  
@@@ -476,18 -448,13 +476,19 @@@ int ff_h264_update_thread_context(AVCod
          }
          context_reinitialized = 1;
  
 -        /* 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
      }
  
 +    /* 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;
+         H264Picture *orig_DPB = h->DPB;
  
          for (i = 0; i < MAX_SPS_COUNT; i++)
              av_freep(h->sps_buffers + i);
          for (i = 0; i < MAX_PPS_COUNT; i++)
              av_freep(h->pps_buffers + i);
  
 -        memcpy(h, h1, sizeof(*h1));
 +        ff_h264_unref_picture(h, &h->last_pic_for_ec);
 +        memcpy(h, h1, sizeof(H264Context));
 +
          memset(h->sps_buffers, 0, sizeof(h->sps_buffers));
          memset(h->pps_buffers, 0, sizeof(h->pps_buffers));
 -        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->DPB       = orig_DPB;
  
          memset(&h->slice_ctx[0].er,         0, sizeof(h->slice_ctx[0].er));
          memset(&h->slice_ctx[0].mb,         0, sizeof(h->slice_ctx[0].mb));