This is a more appropriate place for it, since we only do this once per
lifetime of the decoding context.
---
 libavcodec/h264.c       | 18 ++++++++----------
 libavcodec/h264_slice.c |  3 ++-
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index d4306fe..a5f3dd4 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -379,7 +379,7 @@ 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;
-    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)
@@ -425,15 +425,6 @@ int ff_h264_alloc_tables(H264Context *h)
     if (!h->dequant4_coeff[0])
         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:
@@ -599,6 +590,13 @@ static int h264_init_context(AVCodecContext *avctx, 
H264Context *h)
         return AVERROR(ENOMEM);
     }
 
+    h->DPB = av_mallocz_array(H264_MAX_PICTURE_COUNT, sizeof(*h->DPB));
+    if (!h->DPB)
+        return AVERROR(ENOMEM);
+    for (i = 0; i < H264_MAX_PICTURE_COUNT; i++)
+        av_frame_unref(&h->DPB[i].f);
+    av_frame_unref(&h->cur_pic.f);
+
     for (i = 0; i < h->nb_slice_ctx; i++)
         h->slice_ctx[i].h264 = h;
 
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 9f1fa1d..c893cdf 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -433,6 +433,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
 
     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);
@@ -450,6 +451,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
         h->cur_pic.tf.f = &h->cur_pic.f;
 
         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));
@@ -457,7 +459,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
         memset(&h->slice_ctx[0].mb_padding, 0, 
sizeof(h->slice_ctx[0].mb_padding));
 
         h->avctx             = dst;
-        h->DPB               = NULL;
         h->qscale_table_pool = NULL;
         h->mb_type_pool      = NULL;
         h->ref_index_pool    = NULL;
-- 
2.0.0

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to