diff options
author | Yusuke Nakamura <muken.the.vfrmaniac@gmail.com> | 2013-09-24 18:30:50 +0900 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2013-10-15 20:02:55 +0200 |
commit | 4baba6c813b7a1f27370e20fb1a87b05fcb39208 (patch) | |
tree | 3b935fa8d12754098394af24fd3029f07e698726 /libavcodec/h264.c | |
parent | b81dbd6cb7522bea96d78a52f8a4c25a47b820c9 (diff) | |
download | ffmpeg-4baba6c813b7a1f27370e20fb1a87b05fcb39208.tar.gz |
h264_parser: Fix POC parsing for the case where MMCO_RESET is present.
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavcodec/h264.c')
-rw-r--r-- | libavcodec/h264.c | 89 |
1 files changed, 50 insertions, 39 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 7311e6a54a..5a9ab6a084 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -2554,7 +2554,7 @@ void ff_h264_hl_decode_mb(H264Context *h) hl_decode_mb_simple_8(h); } -static int pred_weight_table(H264Context *h) +int ff_pred_weight_table(H264Context *h) { int list, i; int luma_def, chroma_def; @@ -3198,6 +3198,50 @@ static int h264_slice_header_init(H264Context *h, int reinit) return 0; } +int ff_set_ref_count(H264Context *h) +{ + int num_ref_idx_active_override_flag, max_refs; + + // set defaults, might be overridden a few lines later + h->ref_count[0] = h->pps.ref_count[0]; + h->ref_count[1] = h->pps.ref_count[1]; + + if (h->slice_type_nos != AV_PICTURE_TYPE_I) { + if (h->slice_type_nos == AV_PICTURE_TYPE_B) + h->direct_spatial_mv_pred = get_bits1(&h->gb); + num_ref_idx_active_override_flag = get_bits1(&h->gb); + + if (num_ref_idx_active_override_flag) { + h->ref_count[0] = get_ue_golomb(&h->gb) + 1; + if (h->ref_count[0] < 1) + return AVERROR_INVALIDDATA; + if (h->slice_type_nos == AV_PICTURE_TYPE_B) { + h->ref_count[1] = get_ue_golomb(&h->gb) + 1; + if (h->ref_count[1] < 1) + return AVERROR_INVALIDDATA; + } + } + + if (h->slice_type_nos == AV_PICTURE_TYPE_B) + h->list_count = 2; + else + h->list_count = 1; + } else { + h->list_count = 0; + h->ref_count[0] = h->ref_count[1] = 0; + } + + max_refs = h->picture_structure == PICT_FRAME ? 16 : 32; + + if (h->ref_count[0] > max_refs || h->ref_count[1] > max_refs) { + av_log(h->avctx, AV_LOG_ERROR, "reference overflow\n"); + h->ref_count[0] = h->ref_count[1] = 0; + return AVERROR_INVALIDDATA; + } + + return 0; +} + /** * Decode a slice header. * This will also call ff_MPV_common_init() and frame_start() as needed. @@ -3212,7 +3256,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0) { unsigned int first_mb_in_slice; unsigned int pps_id; - int num_ref_idx_active_override_flag, max_refs, ret; + int ret; unsigned int slice_type, tmp, i, j; int default_ref_list_done = 0; int last_pic_structure, last_pic_droppable; @@ -3619,42 +3663,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0) if (h->pps.redundant_pic_cnt_present) h->redundant_pic_count = get_ue_golomb(&h->gb); - // set defaults, might be overridden a few lines later - h->ref_count[0] = h->pps.ref_count[0]; - h->ref_count[1] = h->pps.ref_count[1]; - - if (h->slice_type_nos != AV_PICTURE_TYPE_I) { - if (h->slice_type_nos == AV_PICTURE_TYPE_B) - h->direct_spatial_mv_pred = get_bits1(&h->gb); - num_ref_idx_active_override_flag = get_bits1(&h->gb); - - if (num_ref_idx_active_override_flag) { - h->ref_count[0] = get_ue_golomb(&h->gb) + 1; - if (h->ref_count[0] < 1) - return AVERROR_INVALIDDATA; - if (h->slice_type_nos == AV_PICTURE_TYPE_B) { - h->ref_count[1] = get_ue_golomb(&h->gb) + 1; - if (h->ref_count[1] < 1) - return AVERROR_INVALIDDATA; - } - } - - if (h->slice_type_nos == AV_PICTURE_TYPE_B) - h->list_count = 2; - else - h->list_count = 1; - } else { - h->list_count = 0; - h->ref_count[0] = h->ref_count[1] = 0; - } - - max_refs = h->picture_structure == PICT_FRAME ? 16 : 32; - - if (h->ref_count[0] > max_refs || h->ref_count[1] > max_refs) { - av_log(h->avctx, AV_LOG_ERROR, "reference overflow\n"); - h->ref_count[0] = h->ref_count[1] = 0; - return AVERROR_INVALIDDATA; - } + ret = ff_set_ref_count(h); + if (ret < 0) + return ret; if (!default_ref_list_done) ff_h264_fill_default_ref_list(h); @@ -3670,7 +3681,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0) if ((h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P) || (h->pps.weighted_bipred_idc == 1 && h->slice_type_nos == AV_PICTURE_TYPE_B)) - pred_weight_table(h); + ff_pred_weight_table(h); else if (h->pps.weighted_bipred_idc == 2 && h->slice_type_nos == AV_PICTURE_TYPE_B) { implicit_weight_table(h, -1); |