Commit 88c612e3 authored by Anton Khirnov's avatar Anton Khirnov

h264: merge the init and reinit paths in update_thread_context()

There is no real need to handle the init case specially, everything
necessary is initialized in the reinit code as well.
parent 8a66fd40
...@@ -431,51 +431,34 @@ int ff_h264_update_thread_context(AVCodecContext *dst, ...@@ -431,51 +431,34 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
need_reinit = 1; need_reinit = 1;
} }
if (!inited) { // SPS/PPS
H264SliceContext *orig_slice_ctx = h->slice_ctx; if ((ret = copy_parameter_set((void **)h->sps_buffers,
H264Picture *orig_DPB = h->DPB; (void **)h1->sps_buffers,
MAX_SPS_COUNT, sizeof(SPS))) < 0)
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));
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;
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));
memset(&h->slice_ctx[0].mb_luma_dc, 0, sizeof(h->slice_ctx[0].mb_luma_dc));
memset(&h->slice_ctx[0].mb_padding, 0, sizeof(h->slice_ctx[0].mb_padding));
h->avctx = dst;
h->qscale_table_pool = NULL;
h->mb_type_pool = NULL;
h->ref_index_pool = NULL;
h->motion_val_pool = NULL;
ret = ff_h264_alloc_tables(h);
if (ret < 0) {
av_log(dst, AV_LOG_ERROR, "Could not allocate memory\n");
return ret; return ret;
} h->sps = h1->sps;
ret = ff_h264_slice_context_init(h, &h->slice_ctx[0]); if ((ret = copy_parameter_set((void **)h->pps_buffers,
if (ret < 0) { (void **)h1->pps_buffers,
av_log(dst, AV_LOG_ERROR, "context_init() failed.\n"); MAX_PPS_COUNT, sizeof(PPS))) < 0)
return ret; return ret;
h->pps = h1->pps;
if (need_reinit || !inited) {
h->width = h1->width;
h->height = h1->height;
h->mb_height = h1->mb_height;
h->mb_width = h1->mb_width;
h->mb_num = h1->mb_num;
h->mb_stride = h1->mb_stride;
h->b_stride = h1->b_stride;
if ((err = h264_slice_header_init(h)) < 0) {
av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed");
return err;
} }
h->context_initialized = 1; /* copy block_offset since frame_start may not be called */
memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset));
} }
h->avctx->coded_height = h1->avctx->coded_height; h->avctx->coded_height = h1->avctx->coded_height;
...@@ -512,18 +495,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst, ...@@ -512,18 +495,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
h->is_avc = h1->is_avc; h->is_avc = h1->is_avc;
h->nal_length_size = h1->nal_length_size; h->nal_length_size = h1->nal_length_size;
// SPS/PPS
if ((ret = copy_parameter_set((void **)h->sps_buffers,
(void **)h1->sps_buffers,
MAX_SPS_COUNT, sizeof(SPS))) < 0)
return ret;
h->sps = h1->sps;
if ((ret = copy_parameter_set((void **)h->pps_buffers,
(void **)h1->pps_buffers,
MAX_PPS_COUNT, sizeof(PPS))) < 0)
return ret;
h->pps = h1->pps;
// Dequantization matrices // Dequantization matrices
// FIXME these are big - can they be only copied when PPS changes? // FIXME these are big - can they be only copied when PPS changes?
copy_fields(h, h1, dequant4_buffer, dequant4_coeff); copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
...@@ -551,24 +522,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst, ...@@ -551,24 +522,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
h->last_slice_type = h1->last_slice_type; h->last_slice_type = h1->last_slice_type;
if (need_reinit) {
h->width = h1->width;
h->height = h1->height;
h->mb_height = h1->mb_height;
h->mb_width = h1->mb_width;
h->mb_num = h1->mb_num;
h->mb_stride = h1->mb_stride;
h->b_stride = h1->b_stride;
if ((err = h264_slice_header_init(h)) < 0) {
av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed");
return err;
}
/* copy block_offset since frame_start may not be called */
memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset));
}
if (!h->cur_pic_ptr) if (!h->cur_pic_ptr)
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment