summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-04-05 21:56:50 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-04-05 21:56:50 +0200
commitabae926ef80c8553c732b95649d334b7a91374d3 (patch)
treeec37d08707415640b4d603d5fa2a6a462a0a333e /libavcodec
parente6c710600e1d474b53e52398969140f79052bfde (diff)
parente1f907711a91e5ce19402a1831cfbe8f709b67f7 (diff)
Merge commit 'e1f907711a91e5ce19402a1831cfbe8f709b67f7'
* commit 'e1f907711a91e5ce19402a1831cfbe8f709b67f7': h264: factor out common code from init() and init_thread_copy() Conflicts: libavcodec/h264.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/h264.c86
1 files changed, 46 insertions, 40 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index ba2fc40792..d5da5861fe 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -608,37 +608,34 @@ int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size)
return size;
}
-av_cold int ff_h264_decode_init(AVCodecContext *avctx)
+static int h264_init_context(AVCodecContext *avctx, H264Context *h)
{
- H264Context *h = avctx->priv_data;
int i;
- int ret;
-
- h->avctx = avctx;
- h->dequant_coeff_pps = -1;
- h->current_sps_id = -1;
+ h->avctx = avctx;
+ h->dequant_coeff_pps = -1;
+ h->current_sps_id = -1;
h->cur_chroma_format_idc = -1;
- memset(h->pps.scaling_matrix4, 16, 6 * 16 * sizeof(uint8_t));
- memset(h->pps.scaling_matrix8, 16, 2 * 64 * sizeof(uint8_t));
+ h->picture_structure = PICT_FRAME;
+ h->slice_context_count = 1;
+ h->workaround_bugs = avctx->workaround_bugs;
+ h->flags = avctx->flags;
+ h->prev_poc_msb = 1 << 16;
+ h->x264_build = -1;
+ h->recovery_frame = -1;
+ h->frame_recovered = 0;
+ h->prev_frame_num = -1;
+ h->sei_fpa.frame_packing_arrangement_cancel_flag = -1;
- h->picture_structure = PICT_FRAME;
- h->slice_context_count = 1;
- h->workaround_bugs = avctx->workaround_bugs;
- h->flags = avctx->flags;
+ h->outputed_poc = h->next_outputed_poc = INT_MIN;
+ for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+ h->last_pocs[i] = INT_MIN;
- /* set defaults */
- // s->decode_mb = ff_h263_decode_mb;
- if (!avctx->has_b_frames)
- h->low_delay = 1;
+ ff_h264_reset_sei(h);
avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
- ff_h264_decode_init_vlc();
-
- ff_init_cabac_states();
-
h->nb_slice_ctx = (avctx->active_thread_type & FF_THREAD_SLICE) ? H264_MAX_THREADS : 1;
h->slice_ctx = av_mallocz_array(h->nb_slice_ctx, sizeof(*h->slice_ctx));
if (!h->slice_ctx) {
@@ -649,14 +646,30 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx)
for (i = 0; i < h->nb_slice_ctx; i++)
h->slice_ctx[i].h264 = h;
- h->outputed_poc = h->next_outputed_poc = INT_MIN;
- for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
- h->last_pocs[i] = INT_MIN;
- h->prev_poc_msb = 1 << 16;
- h->prev_frame_num = -1;
- h->x264_build = -1;
- h->sei_fpa.frame_packing_arrangement_cancel_flag = -1;
- ff_h264_reset_sei(h);
+ return 0;
+}
+
+av_cold int ff_h264_decode_init(AVCodecContext *avctx)
+{
+ H264Context *h = avctx->priv_data;
+ int ret;
+
+ ret = h264_init_context(avctx, h);
+ if (ret < 0)
+ return ret;
+
+ memset(h->pps.scaling_matrix4, 16, 6 * 16 * sizeof(uint8_t));
+ memset(h->pps.scaling_matrix8, 16, 2 * 64 * sizeof(uint8_t));
+
+ /* set defaults */
+ // s->decode_mb = ff_h263_decode_mb;
+ if (!avctx->has_b_frames)
+ h->low_delay = 1;
+
+ ff_h264_decode_init_vlc();
+
+ ff_init_cabac_states();
+
if (avctx->codec_id == AV_CODEC_ID_H264) {
if (avctx->ticks_per_frame == 1) {
if(h->avctx->time_base.den < INT_MAX/2) {
@@ -700,24 +713,17 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx)
static int decode_init_thread_copy(AVCodecContext *avctx)
{
H264Context *h = avctx->priv_data;
- int i;
+ int ret;
if (!avctx->internal->is_copy)
return 0;
memset(h->sps_buffers, 0, sizeof(h->sps_buffers));
memset(h->pps_buffers, 0, sizeof(h->pps_buffers));
- h->nb_slice_ctx = (avctx->active_thread_type & FF_THREAD_SLICE) ? H264_MAX_THREADS : 1;
- h->slice_ctx = av_mallocz_array(h->nb_slice_ctx, sizeof(*h->slice_ctx));
- if (!h->slice_ctx) {
- h->nb_slice_ctx = 0;
- return AVERROR(ENOMEM);
- }
-
- for (i = 0; i < h->nb_slice_ctx; i++)
- h->slice_ctx[i].h264 = h;
+ ret = h264_init_context(avctx, h);
+ if (ret < 0)
+ return ret;
- h->avctx = avctx;
h->context_initialized = 0;
return 0;