Skip to content
Snippets Groups Projects
Commit 88c612e3 authored by Anton Khirnov's avatar Anton Khirnov
Browse files

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
No related branches found
No related tags found
No related merge requests found
......@@ -431,51 +431,34 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
need_reinit = 1;
}
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));
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));
// 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;
h->avctx = dst;
h->qscale_table_pool = NULL;
h->mb_type_pool = NULL;
h->ref_index_pool = NULL;
h->motion_val_pool = NULL;
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;
ret = ff_h264_alloc_tables(h);
if (ret < 0) {
av_log(dst, AV_LOG_ERROR, "Could not allocate memory\n");
return ret;
}
ret = ff_h264_slice_context_init(h, &h->slice_ctx[0]);
if (ret < 0) {
av_log(dst, AV_LOG_ERROR, "context_init() failed.\n");
return ret;
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;
......@@ -512,18 +495,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
h->is_avc = h1->is_avc;
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
// FIXME these are big - can they be only copied when PPS changes?
copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
......@@ -551,24 +522,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
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)
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment