From 84f226a3bcd8b39801a4c9051c033ab7d61aaf76 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 6 Mar 2015 16:03:51 +0100 Subject: [PATCH] h264: use the correct SPS during PPS parsing There is in general no reason for the currently active SPS to be the one referenced by the PPS being parsed. --- libavcodec/h264_ps.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index ad284da5f9..d1708076b8 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -545,19 +545,15 @@ static void build_qp_table(PPS *pps, int t, int index, const int depth) int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length) { + const SPS *sps; unsigned int pps_id = get_ue_golomb(&h->gb); PPS *pps; - const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); + int qp_bd_offset; int bits_left; if (pps_id >= MAX_PPS_COUNT) { av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id); return AVERROR_INVALIDDATA; - } else if (h->sps.bit_depth_luma > 10) { - av_log(h->avctx, AV_LOG_ERROR, - "Unimplemented luma bit depth=%d (max=10)\n", - h->sps.bit_depth_luma); - return AVERROR_PATCHWELCOME; } pps = av_mallocz(sizeof(PPS)); @@ -569,6 +565,14 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length) av_log(h->avctx, AV_LOG_ERROR, "sps_id %u out of range\n", pps->sps_id); goto fail; } + sps = h->sps_buffers[pps->sps_id]; + + if (sps->bit_depth_luma > 10) { + av_log(h->avctx, AV_LOG_ERROR, + "Unimplemented luma bit depth=%d (max=10)\n", + sps->bit_depth_luma); + return AVERROR_PATCHWELCOME; + } pps->cabac = get_bits1(&h->gb); pps->pic_order_present = get_bits1(&h->gb); @@ -615,6 +619,8 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length) goto fail; } + qp_bd_offset = 6 * (sps->bit_depth_luma - 8); + pps->weighted_pred = get_bits1(&h->gb); pps->weighted_bipred_idc = get_bits(&h->gb, 2); pps->init_qp = get_se_golomb(&h->gb) + 26 + qp_bd_offset; @@ -645,9 +651,9 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length) } build_qp_table(pps, 0, pps->chroma_qp_index_offset[0], - h->sps.bit_depth_luma); + sps->bit_depth_luma); build_qp_table(pps, 1, pps->chroma_qp_index_offset[1], - h->sps.bit_depth_luma); + sps->bit_depth_luma); if (pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) pps->chroma_qp_diff = 1;