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.
This commit is contained in:
parent
8a66fd4026
commit
88c612e3a4
@ -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)
|
||||||
|
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;
|
||||||
|
|
||||||
for (i = 0; i < MAX_SPS_COUNT; i++)
|
if (need_reinit || !inited) {
|
||||||
av_freep(h->sps_buffers + i);
|
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;
|
||||||
|
|
||||||
for (i = 0; i < MAX_PPS_COUNT; i++)
|
if ((err = h264_slice_header_init(h)) < 0) {
|
||||||
av_freep(h->pps_buffers + i);
|
av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed");
|
||||||
|
return err;
|
||||||
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;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|||||||
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,
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user