10c1bc742181ded4930842b46e9507372f0b1b963James Dong/* 20c1bc742181ded4930842b46e9507372f0b1b963James Dong * Copyright (C) 2009 The Android Open Source Project 30c1bc742181ded4930842b46e9507372f0b1b963James Dong * 40c1bc742181ded4930842b46e9507372f0b1b963James Dong * Licensed under the Apache License, Version 2.0 (the "License"); 50c1bc742181ded4930842b46e9507372f0b1b963James Dong * you may not use this file except in compliance with the License. 60c1bc742181ded4930842b46e9507372f0b1b963James Dong * You may obtain a copy of the License at 70c1bc742181ded4930842b46e9507372f0b1b963James Dong * 80c1bc742181ded4930842b46e9507372f0b1b963James Dong * http://www.apache.org/licenses/LICENSE-2.0 90c1bc742181ded4930842b46e9507372f0b1b963James Dong * 100c1bc742181ded4930842b46e9507372f0b1b963James Dong * Unless required by applicable law or agreed to in writing, software 110c1bc742181ded4930842b46e9507372f0b1b963James Dong * distributed under the License is distributed on an "AS IS" BASIS, 120c1bc742181ded4930842b46e9507372f0b1b963James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130c1bc742181ded4930842b46e9507372f0b1b963James Dong * See the License for the specific language governing permissions and 140c1bc742181ded4930842b46e9507372f0b1b963James Dong * limitations under the License. 150c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 160c1bc742181ded4930842b46e9507372f0b1b963James Dong 170c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 180c1bc742181ded4930842b46e9507372f0b1b963James Dong 190c1bc742181ded4930842b46e9507372f0b1b963James Dong Table of contents 200c1bc742181ded4930842b46e9507372f0b1b963James Dong 210c1bc742181ded4930842b46e9507372f0b1b963James Dong 1. Include headers 220c1bc742181ded4930842b46e9507372f0b1b963James Dong 2. External compiler flags 230c1bc742181ded4930842b46e9507372f0b1b963James Dong 3. Module defines 240c1bc742181ded4930842b46e9507372f0b1b963James Dong 4. Local function prototypes 250c1bc742181ded4930842b46e9507372f0b1b963James Dong 5. Functions 260c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdDecodeSliceHeader 270c1bc742181ded4930842b46e9507372f0b1b963James Dong NumSliceGroupChangeCycleBits 280c1bc742181ded4930842b46e9507372f0b1b963James Dong RefPicListReordering 290c1bc742181ded4930842b46e9507372f0b1b963James Dong DecRefPicMarking 300c1bc742181ded4930842b46e9507372f0b1b963James Dong CheckPpsId 310c1bc742181ded4930842b46e9507372f0b1b963James Dong CheckFrameNum 320c1bc742181ded4930842b46e9507372f0b1b963James Dong CheckIdrPicId 330c1bc742181ded4930842b46e9507372f0b1b963James Dong CheckPicOrderCntLsb 340c1bc742181ded4930842b46e9507372f0b1b963James Dong CheckDeltaPicOrderCntBottom 350c1bc742181ded4930842b46e9507372f0b1b963James Dong CheckDeltaPicOrderCnt 360c1bc742181ded4930842b46e9507372f0b1b963James Dong CheckRedundantPicCnt 370c1bc742181ded4930842b46e9507372f0b1b963James Dong 380c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 390c1bc742181ded4930842b46e9507372f0b1b963James Dong 400c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 410c1bc742181ded4930842b46e9507372f0b1b963James Dong 1. Include headers 420c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 430c1bc742181ded4930842b46e9507372f0b1b963James Dong 440c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_slice_header.h" 450c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h" 460c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_vlc.h" 470c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_nal_unit.h" 480c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_dpb.h" 490c1bc742181ded4930842b46e9507372f0b1b963James Dong 5084333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber#define UNUSED(x) (void)(x) 5184333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber 520c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 530c1bc742181ded4930842b46e9507372f0b1b963James Dong 2. External compiler flags 540c1bc742181ded4930842b46e9507372f0b1b963James Dong-------------------------------------------------------------------------------- 550c1bc742181ded4930842b46e9507372f0b1b963James Dong 560c1bc742181ded4930842b46e9507372f0b1b963James Dong-------------------------------------------------------------------------------- 570c1bc742181ded4930842b46e9507372f0b1b963James Dong 3. Module defines 580c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 590c1bc742181ded4930842b46e9507372f0b1b963James Dong 600c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 610c1bc742181ded4930842b46e9507372f0b1b963James Dong 4. Local function prototypes 620c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 630c1bc742181ded4930842b46e9507372f0b1b963James Dong 640c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 RefPicListReordering(strmData_t *, refPicListReordering_t *, 650c1bc742181ded4930842b46e9507372f0b1b963James Dong u32, u32); 660c1bc742181ded4930842b46e9507372f0b1b963James Dong 670c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 NumSliceGroupChangeCycleBits(u32 picSizeInMbs, 680c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 sliceGroupChangeRate); 690c1bc742181ded4930842b46e9507372f0b1b963James Dong 700c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 DecRefPicMarking(strmData_t *pStrmData, 710c1bc742181ded4930842b46e9507372f0b1b963James Dong decRefPicMarking_t *pDecRefPicMarking, nalUnitType_e nalUnitType, 720c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 numRefFrames); 730c1bc742181ded4930842b46e9507372f0b1b963James Dong 740c1bc742181ded4930842b46e9507372f0b1b963James Dong 750c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 760c1bc742181ded4930842b46e9507372f0b1b963James Dong 770c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: h264bsdDecodeSliceHeader 780c1bc742181ded4930842b46e9507372f0b1b963James Dong 790c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 800c1bc742181ded4930842b46e9507372f0b1b963James Dong Decode slice header data from the stream. 810c1bc742181ded4930842b46e9507372f0b1b963James Dong 820c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 830c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 840c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet pointer to active sequence parameter set 850c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet pointer to active picture parameter set 860c1bc742181ded4930842b46e9507372f0b1b963James Dong pNalUnit pointer to current NAL unit structure 870c1bc742181ded4930842b46e9507372f0b1b963James Dong 880c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 890c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader decoded data is stored here 900c1bc742181ded4930842b46e9507372f0b1b963James Dong 910c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 920c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 930c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data or end of stream 940c1bc742181ded4930842b46e9507372f0b1b963James Dong 950c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 960c1bc742181ded4930842b46e9507372f0b1b963James Dong 970c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdDecodeSliceHeader(strmData_t *pStrmData, sliceHeader_t *pSliceHeader, 980c1bc742181ded4930842b46e9507372f0b1b963James Dong seqParamSet_t *pSeqParamSet, picParamSet_t *pPicParamSet, 990c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnit_t *pNalUnit) 1000c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong 1020c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 1030c1bc742181ded4930842b46e9507372f0b1b963James Dong 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, i, value; 1050c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 itmp; 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 picSizeInMbs; 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong 1080c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSliceHeader); 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet); 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pPicParamSet); 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT( pNalUnit->nalUnitType == NAL_CODED_SLICE || 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong pNalUnit->nalUnitType == NAL_CODED_SLICE_IDR ); 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong 1180c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecMemset(pSliceHeader, 0, sizeof(sliceHeader_t)); 1190c1bc742181ded4930842b46e9507372f0b1b963James Dong 1200c1bc742181ded4930842b46e9507372f0b1b963James Dong picSizeInMbs = pSeqParamSet->picWidthInMbs * pSeqParamSet->picHeightInMbs; 1210c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1220c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1230c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1240c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->firstMbInSlice = value; 1250c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value >= picSizeInMbs) 1260c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1270c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("first_mb_in_slice"); 1280c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1290c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1300c1bc742181ded4930842b46e9507372f0b1b963James Dong 1310c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1320c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1330c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1340c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->sliceType = value; 1350c1bc742181ded4930842b46e9507372f0b1b963James Dong /* slice type has to be either I or P slice. P slice is not allowed when 1360c1bc742181ded4930842b46e9507372f0b1b963James Dong * current NAL unit is an IDR NAL unit or num_ref_frames is 0 */ 1370c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( !IS_I_SLICE(pSliceHeader->sliceType) && 1380c1bc742181ded4930842b46e9507372f0b1b963James Dong ( !IS_P_SLICE(pSliceHeader->sliceType) || 1390c1bc742181ded4930842b46e9507372f0b1b963James Dong IS_IDR_NAL_UNIT(pNalUnit) || 1400c1bc742181ded4930842b46e9507372f0b1b963James Dong !pSeqParamSet->numRefFrames ) ) 1410c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1420c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("slice_type"); 1430c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1440c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1450c1bc742181ded4930842b46e9507372f0b1b963James Dong 1460c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1470c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1480c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1490c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->picParameterSetId = value; 1500c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pSliceHeader->picParameterSetId != pPicParamSet->picParameterSetId) 1510c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1520c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("pic_parameter_set_id"); 1530c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1540c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1550c1bc742181ded4930842b46e9507372f0b1b963James Dong 1560c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxFrameNum) -> num bits to represent frame_num */ 1570c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 1580c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxFrameNum >> i) 1590c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 1600c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 1610c1bc742181ded4930842b46e9507372f0b1b963James Dong 1620c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, i); 1630c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 1640c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1650c1bc742181ded4930842b46e9507372f0b1b963James Dong if (IS_IDR_NAL_UNIT(pNalUnit) && tmp != 0) 1660c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1670c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("frame_num"); 1680c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1690c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1700c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->frameNum = tmp; 1710c1bc742181ded4930842b46e9507372f0b1b963James Dong 1720c1bc742181ded4930842b46e9507372f0b1b963James Dong if (IS_IDR_NAL_UNIT(pNalUnit)) 1730c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1740c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1750c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1760c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1770c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->idrPicId = value; 1780c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value > 65535) 1790c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1800c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("idr_pic_id"); 1810c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1820c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1830c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1840c1bc742181ded4930842b46e9507372f0b1b963James Dong 1850c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pSeqParamSet->picOrderCntType == 0) 1860c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1870c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */ 1880c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 1890c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxPicOrderCntLsb >> i) 1900c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 1910c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 1920c1bc742181ded4930842b46e9507372f0b1b963James Dong 1930c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, i); 1940c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 1950c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1960c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->picOrderCntLsb = tmp; 1970c1bc742181ded4930842b46e9507372f0b1b963James Dong 1980c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->picOrderPresentFlag) 1990c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2000c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 2010c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2020c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2030c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->deltaPicOrderCntBottom = itmp; 2040c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2050c1bc742181ded4930842b46e9507372f0b1b963James Dong 2060c1bc742181ded4930842b46e9507372f0b1b963James Dong /* check that picOrderCnt for IDR picture will be zero. See 2070c1bc742181ded4930842b46e9507372f0b1b963James Dong * DecodePicOrderCnt function to understand the logic here */ 2080c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( IS_IDR_NAL_UNIT(pNalUnit) && 2090c1bc742181ded4930842b46e9507372f0b1b963James Dong ( (pSliceHeader->picOrderCntLsb > 2100c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet->maxPicOrderCntLsb/2) || 2110c1bc742181ded4930842b46e9507372f0b1b963James Dong MIN((i32)pSliceHeader->picOrderCntLsb, 2120c1bc742181ded4930842b46e9507372f0b1b963James Dong (i32)pSliceHeader->picOrderCntLsb + 2130c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->deltaPicOrderCntBottom) != 0 ) ) 2140c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2150c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2160c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2170c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2180c1bc742181ded4930842b46e9507372f0b1b963James Dong 2190c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (pSeqParamSet->picOrderCntType == 1) && 2200c1bc742181ded4930842b46e9507372f0b1b963James Dong !pSeqParamSet->deltaPicOrderAlwaysZeroFlag ) 2210c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2220c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 2230c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2240c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2250c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->deltaPicOrderCnt[0] = itmp; 2260c1bc742181ded4930842b46e9507372f0b1b963James Dong 2270c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->picOrderPresentFlag) 2280c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2290c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 2300c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2310c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2320c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->deltaPicOrderCnt[1] = itmp; 2330c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2340c1bc742181ded4930842b46e9507372f0b1b963James Dong 2350c1bc742181ded4930842b46e9507372f0b1b963James Dong /* check that picOrderCnt for IDR picture will be zero. See 2360c1bc742181ded4930842b46e9507372f0b1b963James Dong * DecodePicOrderCnt function to understand the logic here */ 2370c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( IS_IDR_NAL_UNIT(pNalUnit) && 2380c1bc742181ded4930842b46e9507372f0b1b963James Dong MIN(pSliceHeader->deltaPicOrderCnt[0], 2390c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->deltaPicOrderCnt[0] + 2400c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet->offsetForTopToBottomField + 2410c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->deltaPicOrderCnt[1]) != 0) 2420c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2430c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2440c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2450c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2460c1bc742181ded4930842b46e9507372f0b1b963James Dong 2470c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->redundantPicCntPresentFlag) 2480c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2490c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 2500c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2510c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2520c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->redundantPicCnt = value; 2530c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value > 127) 2540c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2550c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("redundant_pic_cnt"); 2560c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2570c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2580c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2590c1bc742181ded4930842b46e9507372f0b1b963James Dong 2600c1bc742181ded4930842b46e9507372f0b1b963James Dong if (IS_P_SLICE(pSliceHeader->sliceType)) 2610c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2620c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 2630c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 2640c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2650c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->numRefIdxActiveOverrideFlag = tmp; 2660c1bc742181ded4930842b46e9507372f0b1b963James Dong 2670c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pSliceHeader->numRefIdxActiveOverrideFlag) 2680c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2690c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 2700c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2710c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2720c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value > 15) 2730c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2740c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("num_ref_idx_l0_active_minus1"); 2750c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2760c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2770c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->numRefIdxL0Active = value + 1; 2780c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2790c1bc742181ded4930842b46e9507372f0b1b963James Dong /* set numRefIdxL0Active from pic param set */ 2800c1bc742181ded4930842b46e9507372f0b1b963James Dong else 2810c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2820c1bc742181ded4930842b46e9507372f0b1b963James Dong /* if value (minus1) in picture parameter set exceeds 15 it should 2830c1bc742181ded4930842b46e9507372f0b1b963James Dong * have been overridden here */ 2840c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->numRefIdxL0Active > 16) 2850c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2860c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("num_ref_idx_active_override_flag"); 2870c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2880c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2890c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->numRefIdxL0Active = pPicParamSet->numRefIdxL0Active; 2900c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2910c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2920c1bc742181ded4930842b46e9507372f0b1b963James Dong 2930c1bc742181ded4930842b46e9507372f0b1b963James Dong if (IS_P_SLICE(pSliceHeader->sliceType)) 2940c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2950c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = RefPicListReordering(pStrmData, 2960c1bc742181ded4930842b46e9507372f0b1b963James Dong &pSliceHeader->refPicListReordering, 2970c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->numRefIdxL0Active, 2980c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet->maxFrameNum); 2990c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3000c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3010c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3020c1bc742181ded4930842b46e9507372f0b1b963James Dong 3030c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pNalUnit->nalRefIdc != 0) 3040c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3050c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = DecRefPicMarking(pStrmData, &pSliceHeader->decRefPicMarking, 3060c1bc742181ded4930842b46e9507372f0b1b963James Dong pNalUnit->nalUnitType, pSeqParamSet->numRefFrames); 3070c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3080c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3090c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3100c1bc742181ded4930842b46e9507372f0b1b963James Dong 3110c1bc742181ded4930842b46e9507372f0b1b963James Dong /* decode sliceQpDelta and check that initial QP for the slice will be on 3120c1bc742181ded4930842b46e9507372f0b1b963James Dong * the range [0, 51] */ 3130c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 3140c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3150c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3160c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->sliceQpDelta = itmp; 3170c1bc742181ded4930842b46e9507372f0b1b963James Dong itmp += (i32)pPicParamSet->picInitQp; 3180c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (itmp < 0) || (itmp > 51) ) 3190c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3200c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("slice_qp_delta"); 3210c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3220c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3230c1bc742181ded4930842b46e9507372f0b1b963James Dong 3240c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->deblockingFilterControlPresentFlag) 3250c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3260c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 3270c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3280c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3290c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->disableDeblockingFilterIdc = value; 3300c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pSliceHeader->disableDeblockingFilterIdc > 2) 3310c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3320c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("disable_deblocking_filter_idc"); 3330c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3340c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3350c1bc742181ded4930842b46e9507372f0b1b963James Dong 3360c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pSliceHeader->disableDeblockingFilterIdc != 1) 3370c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3380c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 3390c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3400c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3410c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (itmp < -6) || (itmp > 6) ) 3420c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3430c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("slice_alpha_c0_offset_div2"); 3440c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3450c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3460c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->sliceAlphaC0Offset = itmp * 2; 3470c1bc742181ded4930842b46e9507372f0b1b963James Dong 3480c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 3490c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3500c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3510c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (itmp < -6) || (itmp > 6) ) 3520c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3530c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("slice_beta_offset_div2"); 3540c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3550c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3560c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->sliceBetaOffset = itmp * 2; 3570c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3580c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3590c1bc742181ded4930842b46e9507372f0b1b963James Dong 3600c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (pPicParamSet->numSliceGroups > 1) && 3610c1bc742181ded4930842b46e9507372f0b1b963James Dong (pPicParamSet->sliceGroupMapType >= 3) && 3620c1bc742181ded4930842b46e9507372f0b1b963James Dong (pPicParamSet->sliceGroupMapType <= 5) ) 3630c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3640c1bc742181ded4930842b46e9507372f0b1b963James Dong /* set tmp to number of bits used to represent slice_group_change_cycle 3650c1bc742181ded4930842b46e9507372f0b1b963James Dong * in the stream */ 3660c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = NumSliceGroupChangeCycleBits(picSizeInMbs, 3670c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->sliceGroupChangeRate); 3680c1bc742181ded4930842b46e9507372f0b1b963James Dong value = h264bsdGetBits(pStrmData, tmp); 3690c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value == END_OF_STREAM) 3700c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3710c1bc742181ded4930842b46e9507372f0b1b963James Dong pSliceHeader->sliceGroupChangeCycle = value; 3720c1bc742181ded4930842b46e9507372f0b1b963James Dong 3730c1bc742181ded4930842b46e9507372f0b1b963James Dong /* corresponds to tmp = Ceil(picSizeInMbs / sliceGroupChangeRate) */ 3740c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = (picSizeInMbs + pPicParamSet->sliceGroupChangeRate - 1) / 3750c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->sliceGroupChangeRate; 3760c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pSliceHeader->sliceGroupChangeCycle > tmp) 3770c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3780c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("slice_group_change_cycle"); 3790c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3800c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3810c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3820c1bc742181ded4930842b46e9507372f0b1b963James Dong 3830c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 3840c1bc742181ded4930842b46e9507372f0b1b963James Dong 3850c1bc742181ded4930842b46e9507372f0b1b963James Dong} 3860c1bc742181ded4930842b46e9507372f0b1b963James Dong 3870c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 3880c1bc742181ded4930842b46e9507372f0b1b963James Dong 3890c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: NumSliceGroupChangeCycleBits 3900c1bc742181ded4930842b46e9507372f0b1b963James Dong 3910c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 3920c1bc742181ded4930842b46e9507372f0b1b963James Dong Determine number of bits needed to represent 3930c1bc742181ded4930842b46e9507372f0b1b963James Dong slice_group_change_cycle in the stream. The standard states that 3940c1bc742181ded4930842b46e9507372f0b1b963James Dong slice_group_change_cycle is represented by 3950c1bc742181ded4930842b46e9507372f0b1b963James Dong Ceil( Log2( (picSizeInMbs / sliceGroupChangeRate) + 1) ) 3960c1bc742181ded4930842b46e9507372f0b1b963James Dong 3970c1bc742181ded4930842b46e9507372f0b1b963James Dong bits. Division "/" in the equation is non-truncating division. 3980c1bc742181ded4930842b46e9507372f0b1b963James Dong 3990c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 4000c1bc742181ded4930842b46e9507372f0b1b963James Dong picSizeInMbs picture size in macroblocks 4010c1bc742181ded4930842b46e9507372f0b1b963James Dong sliceGroupChangeRate 4020c1bc742181ded4930842b46e9507372f0b1b963James Dong 4030c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 4040c1bc742181ded4930842b46e9507372f0b1b963James Dong none 4050c1bc742181ded4930842b46e9507372f0b1b963James Dong 4060c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 4070c1bc742181ded4930842b46e9507372f0b1b963James Dong number of bits needed 4080c1bc742181ded4930842b46e9507372f0b1b963James Dong 4090c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 4100c1bc742181ded4930842b46e9507372f0b1b963James Dong 4110c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 NumSliceGroupChangeCycleBits(u32 picSizeInMbs, u32 sliceGroupChangeRate) 4120c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 4130c1bc742181ded4930842b46e9507372f0b1b963James Dong 4140c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 4150c1bc742181ded4930842b46e9507372f0b1b963James Dong 4160c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp,numBits,mask; 4170c1bc742181ded4930842b46e9507372f0b1b963James Dong 4180c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 4190c1bc742181ded4930842b46e9507372f0b1b963James Dong 4200c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(picSizeInMbs); 4210c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(sliceGroupChangeRate); 4220c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(sliceGroupChangeRate <= picSizeInMbs); 4230c1bc742181ded4930842b46e9507372f0b1b963James Dong 4240c1bc742181ded4930842b46e9507372f0b1b963James Dong /* compute (picSizeInMbs / sliceGroupChangeRate + 1), rounded up */ 4250c1bc742181ded4930842b46e9507372f0b1b963James Dong if (picSizeInMbs % sliceGroupChangeRate) 4260c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = 2 + picSizeInMbs/sliceGroupChangeRate; 4270c1bc742181ded4930842b46e9507372f0b1b963James Dong else 4280c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = 1 + picSizeInMbs/sliceGroupChangeRate; 4290c1bc742181ded4930842b46e9507372f0b1b963James Dong 4300c1bc742181ded4930842b46e9507372f0b1b963James Dong numBits = 0; 4310c1bc742181ded4930842b46e9507372f0b1b963James Dong mask = ~0U; 4320c1bc742181ded4930842b46e9507372f0b1b963James Dong 4330c1bc742181ded4930842b46e9507372f0b1b963James Dong /* set numBits to position of right-most non-zero bit */ 4340c1bc742181ded4930842b46e9507372f0b1b963James Dong while (tmp & (mask<<++numBits)) 4350c1bc742181ded4930842b46e9507372f0b1b963James Dong ; 4360c1bc742181ded4930842b46e9507372f0b1b963James Dong numBits--; 4370c1bc742181ded4930842b46e9507372f0b1b963James Dong 4380c1bc742181ded4930842b46e9507372f0b1b963James Dong /* add one more bit if value greater than 2^numBits */ 4390c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp & ((1<<numBits)-1)) 4400c1bc742181ded4930842b46e9507372f0b1b963James Dong numBits++; 4410c1bc742181ded4930842b46e9507372f0b1b963James Dong 4420c1bc742181ded4930842b46e9507372f0b1b963James Dong return(numBits); 4430c1bc742181ded4930842b46e9507372f0b1b963James Dong 4440c1bc742181ded4930842b46e9507372f0b1b963James Dong} 4450c1bc742181ded4930842b46e9507372f0b1b963James Dong 4460c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 4470c1bc742181ded4930842b46e9507372f0b1b963James Dong 4480c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: RefPicListReordering 4490c1bc742181ded4930842b46e9507372f0b1b963James Dong 4500c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 4510c1bc742181ded4930842b46e9507372f0b1b963James Dong Decode reference picture list reordering syntax elements from 4520c1bc742181ded4930842b46e9507372f0b1b963James Dong the stream. Max number of reordering commands is numRefIdxActive. 4530c1bc742181ded4930842b46e9507372f0b1b963James Dong 4540c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 4550c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 4560c1bc742181ded4930842b46e9507372f0b1b963James Dong numRefIdxActive number of active reference indices to be used for 4570c1bc742181ded4930842b46e9507372f0b1b963James Dong current slice 4580c1bc742181ded4930842b46e9507372f0b1b963James Dong maxPicNum maxFrameNum from the active SPS 4590c1bc742181ded4930842b46e9507372f0b1b963James Dong 4600c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 4610c1bc742181ded4930842b46e9507372f0b1b963James Dong pRefPicListReordering decoded data is stored here 4620c1bc742181ded4930842b46e9507372f0b1b963James Dong 4630c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 4640c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 4650c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 4660c1bc742181ded4930842b46e9507372f0b1b963James Dong 4670c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 4680c1bc742181ded4930842b46e9507372f0b1b963James Dong 4690c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 RefPicListReordering(strmData_t *pStrmData, 4700c1bc742181ded4930842b46e9507372f0b1b963James Dong refPicListReordering_t *pRefPicListReordering, u32 numRefIdxActive, 4710c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 maxPicNum) 4720c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 4730c1bc742181ded4930842b46e9507372f0b1b963James Dong 4740c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 4750c1bc742181ded4930842b46e9507372f0b1b963James Dong 4760c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value, i; 4770c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 command; 4780c1bc742181ded4930842b46e9507372f0b1b963James Dong 4790c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 4800c1bc742181ded4930842b46e9507372f0b1b963James Dong 4810c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 4820c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pRefPicListReordering); 4830c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(numRefIdxActive); 4840c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(maxPicNum); 4850c1bc742181ded4930842b46e9507372f0b1b963James Dong 4860c1bc742181ded4930842b46e9507372f0b1b963James Dong 4870c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 4880c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 4890c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 4900c1bc742181ded4930842b46e9507372f0b1b963James Dong 4910c1bc742181ded4930842b46e9507372f0b1b963James Dong pRefPicListReordering->refPicListReorderingFlagL0 = tmp; 4920c1bc742181ded4930842b46e9507372f0b1b963James Dong 4930c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pRefPicListReordering->refPicListReorderingFlagL0) 4940c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4950c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 4960c1bc742181ded4930842b46e9507372f0b1b963James Dong 4970c1bc742181ded4930842b46e9507372f0b1b963James Dong do 4980c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4990c1bc742181ded4930842b46e9507372f0b1b963James Dong if (i > numRefIdxActive) 5000c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5010c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("Too many reordering commands"); 5020c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 5030c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5040c1bc742181ded4930842b46e9507372f0b1b963James Dong 5050c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &command); 5060c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 5070c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 5080c1bc742181ded4930842b46e9507372f0b1b963James Dong if (command > 3) 5090c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5100c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("reordering_of_pic_nums_idc"); 5110c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 5120c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5130c1bc742181ded4930842b46e9507372f0b1b963James Dong 5140c1bc742181ded4930842b46e9507372f0b1b963James Dong pRefPicListReordering->command[i].reorderingOfPicNumsIdc = command; 5150c1bc742181ded4930842b46e9507372f0b1b963James Dong 5160c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((command == 0) || (command == 1)) 5170c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5180c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 5190c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 5200c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 5210c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value >= maxPicNum) 5220c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5230c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("abs_diff_pic_num_minus1"); 5240c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 5250c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5260c1bc742181ded4930842b46e9507372f0b1b963James Dong pRefPicListReordering->command[i].absDiffPicNum = value + 1; 5270c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5280c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (command == 2) 5290c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5300c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 5310c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 5320c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 5330c1bc742181ded4930842b46e9507372f0b1b963James Dong pRefPicListReordering->command[i].longTermPicNum = value; 5340c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5350c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 5360c1bc742181ded4930842b46e9507372f0b1b963James Dong } while (command != 3); 5370c1bc742181ded4930842b46e9507372f0b1b963James Dong 5380c1bc742181ded4930842b46e9507372f0b1b963James Dong /* there shall be at least one reordering command if 5390c1bc742181ded4930842b46e9507372f0b1b963James Dong * refPicListReorderingFlagL0 was set */ 5400c1bc742181ded4930842b46e9507372f0b1b963James Dong if (i == 1) 5410c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5420c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("ref_pic_list_reordering"); 5430c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 5440c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5450c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5460c1bc742181ded4930842b46e9507372f0b1b963James Dong 5470c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 5480c1bc742181ded4930842b46e9507372f0b1b963James Dong 5490c1bc742181ded4930842b46e9507372f0b1b963James Dong} 5500c1bc742181ded4930842b46e9507372f0b1b963James Dong 5510c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 5520c1bc742181ded4930842b46e9507372f0b1b963James Dong 5530c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: DecRefPicMarking 5540c1bc742181ded4930842b46e9507372f0b1b963James Dong 5550c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 5560c1bc742181ded4930842b46e9507372f0b1b963James Dong Decode decoded reference picture marking syntax elements from 5570c1bc742181ded4930842b46e9507372f0b1b963James Dong the stream. 5580c1bc742181ded4930842b46e9507372f0b1b963James Dong 5590c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 5600c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 5610c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType type of the current NAL unit 5620c1bc742181ded4930842b46e9507372f0b1b963James Dong numRefFrames max number of reference frames from the active SPS 5630c1bc742181ded4930842b46e9507372f0b1b963James Dong 5640c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 5650c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking decoded data is stored here 5660c1bc742181ded4930842b46e9507372f0b1b963James Dong 5670c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 5680c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 5690c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 5700c1bc742181ded4930842b46e9507372f0b1b963James Dong 5710c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 5720c1bc742181ded4930842b46e9507372f0b1b963James Dong 5730c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 DecRefPicMarking(strmData_t *pStrmData, 5740c1bc742181ded4930842b46e9507372f0b1b963James Dong decRefPicMarking_t *pDecRefPicMarking, nalUnitType_e nalUnitType, 5750c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 numRefFrames) 5760c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 5770c1bc742181ded4930842b46e9507372f0b1b963James Dong 5780c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 5790c1bc742181ded4930842b46e9507372f0b1b963James Dong 5800c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value; 5810c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i; 5820c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 operation; 5830c1bc742181ded4930842b46e9507372f0b1b963James Dong /* variables for error checking purposes, store number of memory 5840c1bc742181ded4930842b46e9507372f0b1b963James Dong * management operations of certain type */ 5850c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 num4 = 0, num5 = 0, num6 = 0, num1to3 = 0; 5860c1bc742181ded4930842b46e9507372f0b1b963James Dong 5870c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 5880c1bc742181ded4930842b46e9507372f0b1b963James Dong 5890c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT( nalUnitType == NAL_CODED_SLICE_IDR || 5900c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType == NAL_CODED_SLICE || 5910c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType == NAL_SEI ); 5920c1bc742181ded4930842b46e9507372f0b1b963James Dong 5930c1bc742181ded4930842b46e9507372f0b1b963James Dong 5940c1bc742181ded4930842b46e9507372f0b1b963James Dong if (nalUnitType == NAL_CODED_SLICE_IDR) 5950c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5960c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 5970c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 5980c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 5990c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->noOutputOfPriorPicsFlag = tmp; 6000c1bc742181ded4930842b46e9507372f0b1b963James Dong 6010c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 6020c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 6030c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6040c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->longTermReferenceFlag = tmp; 6050c1bc742181ded4930842b46e9507372f0b1b963James Dong if (!numRefFrames && pDecRefPicMarking->longTermReferenceFlag) 6060c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6070c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("long_term_reference_flag"); 6080c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6090c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6100c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6110c1bc742181ded4930842b46e9507372f0b1b963James Dong else 6120c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6130c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 6140c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 6150c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6160c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->adaptiveRefPicMarkingModeFlag = tmp; 6170c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pDecRefPicMarking->adaptiveRefPicMarkingModeFlag) 6180c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6190c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 6200c1bc742181ded4930842b46e9507372f0b1b963James Dong do 6210c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6220c1bc742181ded4930842b46e9507372f0b1b963James Dong /* see explanation of the MAX_NUM_MMC_OPERATIONS in 6230c1bc742181ded4930842b46e9507372f0b1b963James Dong * slice_header.h */ 6240c1bc742181ded4930842b46e9507372f0b1b963James Dong if (i > (2 * numRefFrames + 2)) 6250c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6260c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("Too many management operations"); 6270c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6280c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6290c1bc742181ded4930842b46e9507372f0b1b963James Dong 6300c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &operation); 6310c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 6320c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 6330c1bc742181ded4930842b46e9507372f0b1b963James Dong if (operation > 6) 6340c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6350c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("memory_management_control_operation"); 6360c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6370c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6380c1bc742181ded4930842b46e9507372f0b1b963James Dong 6390c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->operation[i]. 6400c1bc742181ded4930842b46e9507372f0b1b963James Dong memoryManagementControlOperation = operation; 6410c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((operation == 1) || (operation == 3)) 6420c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6430c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 6440c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 6450c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 6460c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->operation[i].differenceOfPicNums = 6470c1bc742181ded4930842b46e9507372f0b1b963James Dong value + 1; 6480c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6490c1bc742181ded4930842b46e9507372f0b1b963James Dong if (operation == 2) 6500c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6510c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 6520c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 6530c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 6540c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->operation[i].longTermPicNum = value; 6550c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6560c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((operation == 3) || (operation == 6)) 6570c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6580c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 6590c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 6600c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 6610c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->operation[i].longTermFrameIdx = 6620c1bc742181ded4930842b46e9507372f0b1b963James Dong value; 6630c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6640c1bc742181ded4930842b46e9507372f0b1b963James Dong if (operation == 4) 6650c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6660c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 6670c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 6680c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 6690c1bc742181ded4930842b46e9507372f0b1b963James Dong /* value shall be in range [0, numRefFrames] */ 6700c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value > numRefFrames) 6710c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6720c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("max_long_term_frame_idx_plus1"); 6730c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6740c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6750c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value == 0) 6760c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6770c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->operation[i]. 6780c1bc742181ded4930842b46e9507372f0b1b963James Dong maxLongTermFrameIdx = 6790c1bc742181ded4930842b46e9507372f0b1b963James Dong NO_LONG_TERM_FRAME_INDICES; 6800c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6810c1bc742181ded4930842b46e9507372f0b1b963James Dong else 6820c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6830c1bc742181ded4930842b46e9507372f0b1b963James Dong pDecRefPicMarking->operation[i]. 6840c1bc742181ded4930842b46e9507372f0b1b963James Dong maxLongTermFrameIdx = value - 1; 6850c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6860c1bc742181ded4930842b46e9507372f0b1b963James Dong num4++; 6870c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6880c1bc742181ded4930842b46e9507372f0b1b963James Dong if (operation == 5) 6890c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6900c1bc742181ded4930842b46e9507372f0b1b963James Dong num5++; 6910c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6920c1bc742181ded4930842b46e9507372f0b1b963James Dong if (operation && operation <= 3) 6930c1bc742181ded4930842b46e9507372f0b1b963James Dong num1to3++; 6940c1bc742181ded4930842b46e9507372f0b1b963James Dong if (operation == 6) 6950c1bc742181ded4930842b46e9507372f0b1b963James Dong num6++; 6960c1bc742181ded4930842b46e9507372f0b1b963James Dong 6970c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 6980c1bc742181ded4930842b46e9507372f0b1b963James Dong } while (operation != 0); 6990c1bc742181ded4930842b46e9507372f0b1b963James Dong 7000c1bc742181ded4930842b46e9507372f0b1b963James Dong /* error checking */ 7010c1bc742181ded4930842b46e9507372f0b1b963James Dong if (num4 > 1 || num5 > 1 || num6 > 1 || (num1to3 && num5)) 7020c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 7030c1bc742181ded4930842b46e9507372f0b1b963James Dong 7040c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7050c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7060c1bc742181ded4930842b46e9507372f0b1b963James Dong 7070c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 7080c1bc742181ded4930842b46e9507372f0b1b963James Dong} 7090c1bc742181ded4930842b46e9507372f0b1b963James Dong 7100c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 7110c1bc742181ded4930842b46e9507372f0b1b963James Dong 7120c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: h264bsdCheckPpsId 7130c1bc742181ded4930842b46e9507372f0b1b963James Dong 7140c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 7150c1bc742181ded4930842b46e9507372f0b1b963James Dong Peek value of pic_parameter_set_id from the slice header. Function 7160c1bc742181ded4930842b46e9507372f0b1b963James Dong does not modify current stream positions but copies the stream 7170c1bc742181ded4930842b46e9507372f0b1b963James Dong data structure to tmp structure which is used while accessing 7180c1bc742181ded4930842b46e9507372f0b1b963James Dong stream data. 7190c1bc742181ded4930842b46e9507372f0b1b963James Dong 7200c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 7210c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 7220c1bc742181ded4930842b46e9507372f0b1b963James Dong 7230c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 7240c1bc742181ded4930842b46e9507372f0b1b963James Dong picParamSetId value is stored here 7250c1bc742181ded4930842b46e9507372f0b1b963James Dong 7260c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 7270c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 7280c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 7290c1bc742181ded4930842b46e9507372f0b1b963James Dong 7300c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 7310c1bc742181ded4930842b46e9507372f0b1b963James Dong 7320c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdCheckPpsId(strmData_t *pStrmData, u32 *picParamSetId) 7330c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 7340c1bc742181ded4930842b46e9507372f0b1b963James Dong 7350c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 7360c1bc742181ded4930842b46e9507372f0b1b963James Dong 7370c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value; 7380c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t tmpStrmData[1]; 7390c1bc742181ded4930842b46e9507372f0b1b963James Dong 7400c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 7410c1bc742181ded4930842b46e9507372f0b1b963James Dong 7420c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 7430c1bc742181ded4930842b46e9507372f0b1b963James Dong 7440c1bc742181ded4930842b46e9507372f0b1b963James Dong /* don't touch original stream position params */ 7450c1bc742181ded4930842b46e9507372f0b1b963James Dong *tmpStrmData = *pStrmData; 7460c1bc742181ded4930842b46e9507372f0b1b963James Dong 7470c1bc742181ded4930842b46e9507372f0b1b963James Dong /* first_mb_in_slice */ 7480c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 7490c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 7500c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 7510c1bc742181ded4930842b46e9507372f0b1b963James Dong 7520c1bc742181ded4930842b46e9507372f0b1b963James Dong /* slice_type */ 7530c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 7540c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 7550c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 7560c1bc742181ded4930842b46e9507372f0b1b963James Dong 7570c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 7580c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 7590c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 7600c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value >= MAX_NUM_PIC_PARAM_SETS) 7610c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 7620c1bc742181ded4930842b46e9507372f0b1b963James Dong 7630c1bc742181ded4930842b46e9507372f0b1b963James Dong *picParamSetId = value; 7640c1bc742181ded4930842b46e9507372f0b1b963James Dong 7650c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 7660c1bc742181ded4930842b46e9507372f0b1b963James Dong 7670c1bc742181ded4930842b46e9507372f0b1b963James Dong} 7680c1bc742181ded4930842b46e9507372f0b1b963James Dong 7690c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 7700c1bc742181ded4930842b46e9507372f0b1b963James Dong 7710c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdCheckFrameNum 7720c1bc742181ded4930842b46e9507372f0b1b963James Dong 7730c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 7740c1bc742181ded4930842b46e9507372f0b1b963James Dong Peek value of frame_num from the slice header. Function does not 7750c1bc742181ded4930842b46e9507372f0b1b963James Dong modify current stream positions but copies the stream data 7760c1bc742181ded4930842b46e9507372f0b1b963James Dong structure to tmp structure which is used while accessing stream 7770c1bc742181ded4930842b46e9507372f0b1b963James Dong data. 7780c1bc742181ded4930842b46e9507372f0b1b963James Dong 7790c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 7800c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 7810c1bc742181ded4930842b46e9507372f0b1b963James Dong maxFrameNum 7820c1bc742181ded4930842b46e9507372f0b1b963James Dong 7830c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 7840c1bc742181ded4930842b46e9507372f0b1b963James Dong frameNum value is stored here 7850c1bc742181ded4930842b46e9507372f0b1b963James Dong 7860c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 7870c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 7880c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 7890c1bc742181ded4930842b46e9507372f0b1b963James Dong 7900c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 7910c1bc742181ded4930842b46e9507372f0b1b963James Dong 7920c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdCheckFrameNum( 7930c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t *pStrmData, 7940c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 maxFrameNum, 7950c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 *frameNum) 7960c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 7970c1bc742181ded4930842b46e9507372f0b1b963James Dong 7980c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 7990c1bc742181ded4930842b46e9507372f0b1b963James Dong 8000c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value, i; 8010c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t tmpStrmData[1]; 8020c1bc742181ded4930842b46e9507372f0b1b963James Dong 8030c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 8040c1bc742181ded4930842b46e9507372f0b1b963James Dong 8050c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 8060c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(maxFrameNum); 8070c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(frameNum); 8080c1bc742181ded4930842b46e9507372f0b1b963James Dong 8090c1bc742181ded4930842b46e9507372f0b1b963James Dong /* don't touch original stream position params */ 8100c1bc742181ded4930842b46e9507372f0b1b963James Dong *tmpStrmData = *pStrmData; 8110c1bc742181ded4930842b46e9507372f0b1b963James Dong 8120c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip first_mb_in_slice */ 8130c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 8140c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 8150c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 8160c1bc742181ded4930842b46e9507372f0b1b963James Dong 8170c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip slice_type */ 8180c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 8190c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 8200c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 8210c1bc742181ded4930842b46e9507372f0b1b963James Dong 8220c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_parameter_set_id */ 8230c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 8240c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 8250c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 8260c1bc742181ded4930842b46e9507372f0b1b963James Dong 8270c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxFrameNum) -> num bits to represent frame_num */ 8280c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 8290c1bc742181ded4930842b46e9507372f0b1b963James Dong while (maxFrameNum >> i) 8300c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 8310c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 8320c1bc742181ded4930842b46e9507372f0b1b963James Dong 8330c1bc742181ded4930842b46e9507372f0b1b963James Dong /* frame_num */ 8340c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 8350c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 8360c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 8370c1bc742181ded4930842b46e9507372f0b1b963James Dong *frameNum = tmp; 8380c1bc742181ded4930842b46e9507372f0b1b963James Dong 8390c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 8400c1bc742181ded4930842b46e9507372f0b1b963James Dong 8410c1bc742181ded4930842b46e9507372f0b1b963James Dong} 8420c1bc742181ded4930842b46e9507372f0b1b963James Dong 8430c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 8440c1bc742181ded4930842b46e9507372f0b1b963James Dong 8450c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdCheckIdrPicId 8460c1bc742181ded4930842b46e9507372f0b1b963James Dong 8470c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 8480c1bc742181ded4930842b46e9507372f0b1b963James Dong Peek value of idr_pic_id from the slice header. Function does not 8490c1bc742181ded4930842b46e9507372f0b1b963James Dong modify current stream positions but copies the stream data 8500c1bc742181ded4930842b46e9507372f0b1b963James Dong structure to tmp structure which is used while accessing stream 8510c1bc742181ded4930842b46e9507372f0b1b963James Dong data. 8520c1bc742181ded4930842b46e9507372f0b1b963James Dong 8530c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 8540c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 8550c1bc742181ded4930842b46e9507372f0b1b963James Dong maxFrameNum max frame number from active SPS 8560c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType type of the current NAL unit 8570c1bc742181ded4930842b46e9507372f0b1b963James Dong 8580c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 8590c1bc742181ded4930842b46e9507372f0b1b963James Dong idrPicId value is stored here 8600c1bc742181ded4930842b46e9507372f0b1b963James Dong 8610c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 8620c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 8630c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 8640c1bc742181ded4930842b46e9507372f0b1b963James Dong 8650c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 8660c1bc742181ded4930842b46e9507372f0b1b963James Dong 8670c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdCheckIdrPicId( 8680c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t *pStrmData, 8690c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 maxFrameNum, 8700c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType_e nalUnitType, 8710c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 *idrPicId) 8720c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 8730c1bc742181ded4930842b46e9507372f0b1b963James Dong 8740c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 8750c1bc742181ded4930842b46e9507372f0b1b963James Dong 8760c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value, i; 8770c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t tmpStrmData[1]; 8780c1bc742181ded4930842b46e9507372f0b1b963James Dong 8790c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 8800c1bc742181ded4930842b46e9507372f0b1b963James Dong 8810c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 8820c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(maxFrameNum); 8830c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(idrPicId); 8840c1bc742181ded4930842b46e9507372f0b1b963James Dong 8850c1bc742181ded4930842b46e9507372f0b1b963James Dong /* nalUnitType must be equal to 5 because otherwise idrPicId is not 8860c1bc742181ded4930842b46e9507372f0b1b963James Dong * present */ 8870c1bc742181ded4930842b46e9507372f0b1b963James Dong if (nalUnitType != NAL_CODED_SLICE_IDR) 8880c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 8890c1bc742181ded4930842b46e9507372f0b1b963James Dong 8900c1bc742181ded4930842b46e9507372f0b1b963James Dong /* don't touch original stream position params */ 8910c1bc742181ded4930842b46e9507372f0b1b963James Dong *tmpStrmData = *pStrmData; 8920c1bc742181ded4930842b46e9507372f0b1b963James Dong 8930c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip first_mb_in_slice */ 8940c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 8950c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 8960c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 8970c1bc742181ded4930842b46e9507372f0b1b963James Dong 8980c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip slice_type */ 8990c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 9000c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 9010c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 9020c1bc742181ded4930842b46e9507372f0b1b963James Dong 9030c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_parameter_set_id */ 9040c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 9050c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 9060c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 9070c1bc742181ded4930842b46e9507372f0b1b963James Dong 9080c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxFrameNum) -> num bits to represent frame_num */ 9090c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 9100c1bc742181ded4930842b46e9507372f0b1b963James Dong while (maxFrameNum >> i) 9110c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 9120c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 9130c1bc742181ded4930842b46e9507372f0b1b963James Dong 9140c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip frame_num */ 9150c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 9160c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 9170c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 9180c1bc742181ded4930842b46e9507372f0b1b963James Dong 9190c1bc742181ded4930842b46e9507372f0b1b963James Dong /* idr_pic_id */ 9200c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, idrPicId); 9210c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 9220c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 9230c1bc742181ded4930842b46e9507372f0b1b963James Dong 9240c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 9250c1bc742181ded4930842b46e9507372f0b1b963James Dong 9260c1bc742181ded4930842b46e9507372f0b1b963James Dong} 9270c1bc742181ded4930842b46e9507372f0b1b963James Dong 9280c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 9290c1bc742181ded4930842b46e9507372f0b1b963James Dong 9300c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdCheckPicOrderCntLsb 9310c1bc742181ded4930842b46e9507372f0b1b963James Dong 9320c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 9330c1bc742181ded4930842b46e9507372f0b1b963James Dong Peek value of pic_order_cnt_lsb from the slice header. Function 9340c1bc742181ded4930842b46e9507372f0b1b963James Dong does not modify current stream positions but copies the stream 9350c1bc742181ded4930842b46e9507372f0b1b963James Dong data structure to tmp structure which is used while accessing 9360c1bc742181ded4930842b46e9507372f0b1b963James Dong stream data. 9370c1bc742181ded4930842b46e9507372f0b1b963James Dong 9380c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 9390c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 9400c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet pointer to active SPS 9410c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType type of the current NAL unit 9420c1bc742181ded4930842b46e9507372f0b1b963James Dong 9430c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 9440c1bc742181ded4930842b46e9507372f0b1b963James Dong picOrderCntLsb value is stored here 9450c1bc742181ded4930842b46e9507372f0b1b963James Dong 9460c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 9470c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 9480c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 9490c1bc742181ded4930842b46e9507372f0b1b963James Dong 9500c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 9510c1bc742181ded4930842b46e9507372f0b1b963James Dong 9520c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdCheckPicOrderCntLsb( 9530c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t *pStrmData, 9540c1bc742181ded4930842b46e9507372f0b1b963James Dong seqParamSet_t *pSeqParamSet, 9550c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType_e nalUnitType, 9560c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 *picOrderCntLsb) 9570c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 9580c1bc742181ded4930842b46e9507372f0b1b963James Dong 9590c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 9600c1bc742181ded4930842b46e9507372f0b1b963James Dong 9610c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value, i; 9620c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t tmpStrmData[1]; 9630c1bc742181ded4930842b46e9507372f0b1b963James Dong 9640c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 9650c1bc742181ded4930842b46e9507372f0b1b963James Dong 9660c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 9670c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet); 9680c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(picOrderCntLsb); 9690c1bc742181ded4930842b46e9507372f0b1b963James Dong 9700c1bc742181ded4930842b46e9507372f0b1b963James Dong /* picOrderCntType must be equal to 0 */ 9710c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->picOrderCntType == 0); 9720c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->maxFrameNum); 9730c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->maxPicOrderCntLsb); 9740c1bc742181ded4930842b46e9507372f0b1b963James Dong 9750c1bc742181ded4930842b46e9507372f0b1b963James Dong /* don't touch original stream position params */ 9760c1bc742181ded4930842b46e9507372f0b1b963James Dong *tmpStrmData = *pStrmData; 9770c1bc742181ded4930842b46e9507372f0b1b963James Dong 9780c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip first_mb_in_slice */ 9790c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 9800c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 9810c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 9820c1bc742181ded4930842b46e9507372f0b1b963James Dong 9830c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip slice_type */ 9840c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 9850c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 9860c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 9870c1bc742181ded4930842b46e9507372f0b1b963James Dong 9880c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_parameter_set_id */ 9890c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 9900c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 9910c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 9920c1bc742181ded4930842b46e9507372f0b1b963James Dong 9930c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxFrameNum) -> num bits to represent frame_num */ 9940c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 9950c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxFrameNum >> i) 9960c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 9970c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 9980c1bc742181ded4930842b46e9507372f0b1b963James Dong 9990c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip frame_num */ 10000c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 10010c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 10020c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 10030c1bc742181ded4930842b46e9507372f0b1b963James Dong 10040c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip idr_pic_id when necessary */ 10050c1bc742181ded4930842b46e9507372f0b1b963James Dong if (nalUnitType == NAL_CODED_SLICE_IDR) 10060c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10070c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 10080c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 10090c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 10100c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10110c1bc742181ded4930842b46e9507372f0b1b963James Dong 10120c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */ 10130c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 10140c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxPicOrderCntLsb >> i) 10150c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 10160c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 10170c1bc742181ded4930842b46e9507372f0b1b963James Dong 10180c1bc742181ded4930842b46e9507372f0b1b963James Dong /* pic_order_cnt_lsb */ 10190c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 10200c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 10210c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 10220c1bc742181ded4930842b46e9507372f0b1b963James Dong *picOrderCntLsb = tmp; 10230c1bc742181ded4930842b46e9507372f0b1b963James Dong 10240c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 10250c1bc742181ded4930842b46e9507372f0b1b963James Dong 10260c1bc742181ded4930842b46e9507372f0b1b963James Dong} 10270c1bc742181ded4930842b46e9507372f0b1b963James Dong 10280c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 10290c1bc742181ded4930842b46e9507372f0b1b963James Dong 10300c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdCheckDeltaPicOrderCntBottom 10310c1bc742181ded4930842b46e9507372f0b1b963James Dong 10320c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 10330c1bc742181ded4930842b46e9507372f0b1b963James Dong Peek value of delta_pic_order_cnt_bottom from the slice header. 10340c1bc742181ded4930842b46e9507372f0b1b963James Dong Function does not modify current stream positions but copies the 10350c1bc742181ded4930842b46e9507372f0b1b963James Dong stream data structure to tmp structure which is used while 10360c1bc742181ded4930842b46e9507372f0b1b963James Dong accessing stream data. 10370c1bc742181ded4930842b46e9507372f0b1b963James Dong 10380c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 10390c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 10400c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet pointer to active SPS 10410c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType type of the current NAL unit 10420c1bc742181ded4930842b46e9507372f0b1b963James Dong 10430c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 10440c1bc742181ded4930842b46e9507372f0b1b963James Dong deltaPicOrderCntBottom value is stored here 10450c1bc742181ded4930842b46e9507372f0b1b963James Dong 10460c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 10470c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 10480c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 10490c1bc742181ded4930842b46e9507372f0b1b963James Dong 10500c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 10510c1bc742181ded4930842b46e9507372f0b1b963James Dong 10520c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdCheckDeltaPicOrderCntBottom( 10530c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t *pStrmData, 10540c1bc742181ded4930842b46e9507372f0b1b963James Dong seqParamSet_t *pSeqParamSet, 10550c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType_e nalUnitType, 10560c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 *deltaPicOrderCntBottom) 10570c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 10580c1bc742181ded4930842b46e9507372f0b1b963James Dong 10590c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 10600c1bc742181ded4930842b46e9507372f0b1b963James Dong 10610c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value, i; 10620c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t tmpStrmData[1]; 10630c1bc742181ded4930842b46e9507372f0b1b963James Dong 10640c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 10650c1bc742181ded4930842b46e9507372f0b1b963James Dong 10660c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 10670c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet); 10680c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(deltaPicOrderCntBottom); 10690c1bc742181ded4930842b46e9507372f0b1b963James Dong 10700c1bc742181ded4930842b46e9507372f0b1b963James Dong /* picOrderCntType must be equal to 0 and picOrderPresentFlag must be TRUE 10710c1bc742181ded4930842b46e9507372f0b1b963James Dong * */ 10720c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->picOrderCntType == 0); 10730c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->maxFrameNum); 10740c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->maxPicOrderCntLsb); 10750c1bc742181ded4930842b46e9507372f0b1b963James Dong 10760c1bc742181ded4930842b46e9507372f0b1b963James Dong /* don't touch original stream position params */ 10770c1bc742181ded4930842b46e9507372f0b1b963James Dong *tmpStrmData = *pStrmData; 10780c1bc742181ded4930842b46e9507372f0b1b963James Dong 10790c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip first_mb_in_slice */ 10800c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 10810c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 10820c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 10830c1bc742181ded4930842b46e9507372f0b1b963James Dong 10840c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip slice_type */ 10850c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 10860c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 10870c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 10880c1bc742181ded4930842b46e9507372f0b1b963James Dong 10890c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_parameter_set_id */ 10900c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 10910c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 10920c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 10930c1bc742181ded4930842b46e9507372f0b1b963James Dong 10940c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxFrameNum) -> num bits to represent frame_num */ 10950c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 10960c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxFrameNum >> i) 10970c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 10980c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 10990c1bc742181ded4930842b46e9507372f0b1b963James Dong 11000c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip frame_num */ 11010c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 11020c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 11030c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 11040c1bc742181ded4930842b46e9507372f0b1b963James Dong 11050c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip idr_pic_id when necessary */ 11060c1bc742181ded4930842b46e9507372f0b1b963James Dong if (nalUnitType == NAL_CODED_SLICE_IDR) 11070c1bc742181ded4930842b46e9507372f0b1b963James Dong { 11080c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 11090c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 11100c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 11110c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11120c1bc742181ded4930842b46e9507372f0b1b963James Dong 11130c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */ 11140c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 11150c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxPicOrderCntLsb >> i) 11160c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 11170c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 11180c1bc742181ded4930842b46e9507372f0b1b963James Dong 11190c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_order_cnt_lsb */ 11200c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 11210c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 11220c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 11230c1bc742181ded4930842b46e9507372f0b1b963James Dong 11240c1bc742181ded4930842b46e9507372f0b1b963James Dong /* delta_pic_order_cnt_bottom */ 11250c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, deltaPicOrderCntBottom); 11260c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 11270c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 11280c1bc742181ded4930842b46e9507372f0b1b963James Dong 11290c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 11300c1bc742181ded4930842b46e9507372f0b1b963James Dong 11310c1bc742181ded4930842b46e9507372f0b1b963James Dong} 11320c1bc742181ded4930842b46e9507372f0b1b963James Dong 11330c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 11340c1bc742181ded4930842b46e9507372f0b1b963James Dong 11350c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdCheckDeltaPicOrderCnt 11360c1bc742181ded4930842b46e9507372f0b1b963James Dong 11370c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 11380c1bc742181ded4930842b46e9507372f0b1b963James Dong Peek values delta_pic_order_cnt[0] and delta_pic_order_cnt[1] 11390c1bc742181ded4930842b46e9507372f0b1b963James Dong from the slice header. Function does not modify current stream 11400c1bc742181ded4930842b46e9507372f0b1b963James Dong positions but copies the stream data structure to tmp structure 11410c1bc742181ded4930842b46e9507372f0b1b963James Dong which is used while accessing stream data. 11420c1bc742181ded4930842b46e9507372f0b1b963James Dong 11430c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 11440c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 11450c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet pointer to active SPS 11460c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType type of the current NAL unit 11470c1bc742181ded4930842b46e9507372f0b1b963James Dong picOrderPresentFlag flag indicating if delta_pic_order_cnt[1] 11480c1bc742181ded4930842b46e9507372f0b1b963James Dong is present in the stream 11490c1bc742181ded4930842b46e9507372f0b1b963James Dong 11500c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 11510c1bc742181ded4930842b46e9507372f0b1b963James Dong deltaPicOrderCnt values are stored here 11520c1bc742181ded4930842b46e9507372f0b1b963James Dong 11530c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 11540c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 11550c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 11560c1bc742181ded4930842b46e9507372f0b1b963James Dong 11570c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 11580c1bc742181ded4930842b46e9507372f0b1b963James Dong 11590c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdCheckDeltaPicOrderCnt( 11600c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t *pStrmData, 11610c1bc742181ded4930842b46e9507372f0b1b963James Dong seqParamSet_t *pSeqParamSet, 11620c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType_e nalUnitType, 11630c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 picOrderPresentFlag, 11640c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 *deltaPicOrderCnt) 11650c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 11660c1bc742181ded4930842b46e9507372f0b1b963James Dong 11670c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 11680c1bc742181ded4930842b46e9507372f0b1b963James Dong 11690c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value, i; 11700c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t tmpStrmData[1]; 11710c1bc742181ded4930842b46e9507372f0b1b963James Dong 11720c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 11730c1bc742181ded4930842b46e9507372f0b1b963James Dong 11740c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 11750c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet); 11760c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(deltaPicOrderCnt); 11770c1bc742181ded4930842b46e9507372f0b1b963James Dong 11780c1bc742181ded4930842b46e9507372f0b1b963James Dong /* picOrderCntType must be equal to 1 and deltaPicOrderAlwaysZeroFlag must 11790c1bc742181ded4930842b46e9507372f0b1b963James Dong * be FALSE */ 11800c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->picOrderCntType == 1); 11810c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(!pSeqParamSet->deltaPicOrderAlwaysZeroFlag); 11820c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->maxFrameNum); 11830c1bc742181ded4930842b46e9507372f0b1b963James Dong 11840c1bc742181ded4930842b46e9507372f0b1b963James Dong /* don't touch original stream position params */ 11850c1bc742181ded4930842b46e9507372f0b1b963James Dong *tmpStrmData = *pStrmData; 11860c1bc742181ded4930842b46e9507372f0b1b963James Dong 11870c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip first_mb_in_slice */ 11880c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 11890c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 11900c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 11910c1bc742181ded4930842b46e9507372f0b1b963James Dong 11920c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip slice_type */ 11930c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 11940c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 11950c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 11960c1bc742181ded4930842b46e9507372f0b1b963James Dong 11970c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_parameter_set_id */ 11980c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 11990c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 12000c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 12010c1bc742181ded4930842b46e9507372f0b1b963James Dong 12020c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxFrameNum) -> num bits to represent frame_num */ 12030c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 12040c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxFrameNum >> i) 12050c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 12060c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 12070c1bc742181ded4930842b46e9507372f0b1b963James Dong 12080c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip frame_num */ 12090c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 12100c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 12110c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 12120c1bc742181ded4930842b46e9507372f0b1b963James Dong 12130c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip idr_pic_id when necessary */ 12140c1bc742181ded4930842b46e9507372f0b1b963James Dong if (nalUnitType == NAL_CODED_SLICE_IDR) 12150c1bc742181ded4930842b46e9507372f0b1b963James Dong { 12160c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 12170c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 12180c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 12190c1bc742181ded4930842b46e9507372f0b1b963James Dong } 12200c1bc742181ded4930842b46e9507372f0b1b963James Dong 12210c1bc742181ded4930842b46e9507372f0b1b963James Dong /* delta_pic_order_cnt[0] */ 12220c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &deltaPicOrderCnt[0]); 12230c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 12240c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 12250c1bc742181ded4930842b46e9507372f0b1b963James Dong 12260c1bc742181ded4930842b46e9507372f0b1b963James Dong /* delta_pic_order_cnt[1] if present */ 12270c1bc742181ded4930842b46e9507372f0b1b963James Dong if (picOrderPresentFlag) 12280c1bc742181ded4930842b46e9507372f0b1b963James Dong { 12290c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &deltaPicOrderCnt[1]); 12300c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 12310c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 12320c1bc742181ded4930842b46e9507372f0b1b963James Dong } 12330c1bc742181ded4930842b46e9507372f0b1b963James Dong 12340c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 12350c1bc742181ded4930842b46e9507372f0b1b963James Dong 12360c1bc742181ded4930842b46e9507372f0b1b963James Dong} 12370c1bc742181ded4930842b46e9507372f0b1b963James Dong 12380c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 12390c1bc742181ded4930842b46e9507372f0b1b963James Dong 12400c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdCheckRedundantPicCnt 12410c1bc742181ded4930842b46e9507372f0b1b963James Dong 12420c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 12430c1bc742181ded4930842b46e9507372f0b1b963James Dong Peek value of redundant_pic_cnt from the slice header. Function 12440c1bc742181ded4930842b46e9507372f0b1b963James Dong does not modify current stream positions but copies the stream 12450c1bc742181ded4930842b46e9507372f0b1b963James Dong data structure to tmp structure which is used while accessing 12460c1bc742181ded4930842b46e9507372f0b1b963James Dong stream data. 12470c1bc742181ded4930842b46e9507372f0b1b963James Dong 12480c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 12490c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 12500c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet pointer to active SPS 12510c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet pointer to active PPS 12520c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType type of the current NAL unit 12530c1bc742181ded4930842b46e9507372f0b1b963James Dong 12540c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 12550c1bc742181ded4930842b46e9507372f0b1b963James Dong redundantPicCnt value is stored here 12560c1bc742181ded4930842b46e9507372f0b1b963James Dong 12570c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 12580c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 12590c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 12600c1bc742181ded4930842b46e9507372f0b1b963James Dong 12610c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 12620c1bc742181ded4930842b46e9507372f0b1b963James Dong 12630c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdCheckRedundantPicCnt( 12640c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t *pStrmData, 12650c1bc742181ded4930842b46e9507372f0b1b963James Dong seqParamSet_t *pSeqParamSet, 12660c1bc742181ded4930842b46e9507372f0b1b963James Dong picParamSet_t *pPicParamSet, 12670c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType_e nalUnitType, 12680c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 *redundantPicCnt) 12690c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 12700c1bc742181ded4930842b46e9507372f0b1b963James Dong 12710c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 12720c1bc742181ded4930842b46e9507372f0b1b963James Dong 12730c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value, i; 12740c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 ivalue; 12750c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t tmpStrmData[1]; 12760c1bc742181ded4930842b46e9507372f0b1b963James Dong 12770c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 12780c1bc742181ded4930842b46e9507372f0b1b963James Dong 12790c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 12800c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet); 12810c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pPicParamSet); 12820c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(redundantPicCnt); 12830c1bc742181ded4930842b46e9507372f0b1b963James Dong 12840c1bc742181ded4930842b46e9507372f0b1b963James Dong /* redundant_pic_cnt_flag must be TRUE */ 12850c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pPicParamSet->redundantPicCntPresentFlag); 12860c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->maxFrameNum); 12870c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet->picOrderCntType > 0 || 12880c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet->maxPicOrderCntLsb); 12890c1bc742181ded4930842b46e9507372f0b1b963James Dong 12900c1bc742181ded4930842b46e9507372f0b1b963James Dong /* don't touch original stream position params */ 12910c1bc742181ded4930842b46e9507372f0b1b963James Dong *tmpStrmData = *pStrmData; 12920c1bc742181ded4930842b46e9507372f0b1b963James Dong 12930c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip first_mb_in_slice */ 12940c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 12950c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 12960c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 12970c1bc742181ded4930842b46e9507372f0b1b963James Dong 12980c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip slice_type */ 12990c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 13000c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 13010c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 13020c1bc742181ded4930842b46e9507372f0b1b963James Dong 13030c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_parameter_set_id */ 13040c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 13050c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 13060c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 13070c1bc742181ded4930842b46e9507372f0b1b963James Dong 13080c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxFrameNum) -> num bits to represent frame_num */ 13090c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 13100c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxFrameNum >> i) 13110c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 13120c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 13130c1bc742181ded4930842b46e9507372f0b1b963James Dong 13140c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip frame_num */ 13150c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 13160c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 13170c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 13180c1bc742181ded4930842b46e9507372f0b1b963James Dong 13190c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip idr_pic_id when necessary */ 13200c1bc742181ded4930842b46e9507372f0b1b963James Dong if (nalUnitType == NAL_CODED_SLICE_IDR) 13210c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13220c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 13230c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 13240c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 13250c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13260c1bc742181ded4930842b46e9507372f0b1b963James Dong 13270c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pSeqParamSet->picOrderCntType == 0) 13280c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13290c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */ 13300c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 13310c1bc742181ded4930842b46e9507372f0b1b963James Dong while (pSeqParamSet->maxPicOrderCntLsb >> i) 13320c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 13330c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 13340c1bc742181ded4930842b46e9507372f0b1b963James Dong 13350c1bc742181ded4930842b46e9507372f0b1b963James Dong /* pic_order_cnt_lsb */ 13360c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 13370c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 13380c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 13390c1bc742181ded4930842b46e9507372f0b1b963James Dong 13400c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->picOrderPresentFlag) 13410c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13420c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip delta_pic_order_cnt_bottom */ 13430c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue); 13440c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 13450c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 13460c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13470c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13480c1bc742181ded4930842b46e9507372f0b1b963James Dong 13490c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pSeqParamSet->picOrderCntType == 1 && 13500c1bc742181ded4930842b46e9507372f0b1b963James Dong !pSeqParamSet->deltaPicOrderAlwaysZeroFlag) 13510c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13520c1bc742181ded4930842b46e9507372f0b1b963James Dong /* delta_pic_order_cnt[0] */ 13530c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue); 13540c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 13550c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 13560c1bc742181ded4930842b46e9507372f0b1b963James Dong 13570c1bc742181ded4930842b46e9507372f0b1b963James Dong /* delta_pic_order_cnt[1] if present */ 13580c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->picOrderPresentFlag) 13590c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13600c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue); 13610c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 13620c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 13630c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13640c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13650c1bc742181ded4930842b46e9507372f0b1b963James Dong 13660c1bc742181ded4930842b46e9507372f0b1b963James Dong /* redundant_pic_cnt */ 13670c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, redundantPicCnt); 13680c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 13690c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 13700c1bc742181ded4930842b46e9507372f0b1b963James Dong 13710c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 13720c1bc742181ded4930842b46e9507372f0b1b963James Dong 13730c1bc742181ded4930842b46e9507372f0b1b963James Dong} 13740c1bc742181ded4930842b46e9507372f0b1b963James Dong 13750c1bc742181ded4930842b46e9507372f0b1b963James Dong 13760c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 13770c1bc742181ded4930842b46e9507372f0b1b963James Dong 13780c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdCheckPriorPicsFlag 13790c1bc742181ded4930842b46e9507372f0b1b963James Dong 13800c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 13810c1bc742181ded4930842b46e9507372f0b1b963James Dong Peek value of no_output_of_prior_pics_flag from the slice header. 13820c1bc742181ded4930842b46e9507372f0b1b963James Dong Function does not modify current stream positions but copies 13830c1bc742181ded4930842b46e9507372f0b1b963James Dong the stream data structure to tmp structure which is used while 13840c1bc742181ded4930842b46e9507372f0b1b963James Dong accessing stream data. 13850c1bc742181ded4930842b46e9507372f0b1b963James Dong 13860c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 13870c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 13880c1bc742181ded4930842b46e9507372f0b1b963James Dong pSeqParamSet pointer to active SPS 13890c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet pointer to active PPS 13900c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType type of the current NAL unit 13910c1bc742181ded4930842b46e9507372f0b1b963James Dong 13920c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 13930c1bc742181ded4930842b46e9507372f0b1b963James Dong noOutputOfPriorPicsFlag value is stored here 13940c1bc742181ded4930842b46e9507372f0b1b963James Dong 13950c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 13960c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 13970c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid stream data 13980c1bc742181ded4930842b46e9507372f0b1b963James Dong 13990c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 14000c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint -e715 disable lint info nalUnitType not referenced */ 14010c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdCheckPriorPicsFlag(u32 * noOutputOfPriorPicsFlag, 14020c1bc742181ded4930842b46e9507372f0b1b963James Dong const strmData_t * pStrmData, 14030c1bc742181ded4930842b46e9507372f0b1b963James Dong const seqParamSet_t * pSeqParamSet, 14040c1bc742181ded4930842b46e9507372f0b1b963James Dong const picParamSet_t * pPicParamSet, 14050c1bc742181ded4930842b46e9507372f0b1b963James Dong nalUnitType_e nalUnitType) 14060c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 14070c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 14080c1bc742181ded4930842b46e9507372f0b1b963James Dong 14090c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, value, i; 14100c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 ivalue; 14110c1bc742181ded4930842b46e9507372f0b1b963James Dong strmData_t tmpStrmData[1]; 141284333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber UNUSED(nalUnitType); 14130c1bc742181ded4930842b46e9507372f0b1b963James Dong 14140c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 14150c1bc742181ded4930842b46e9507372f0b1b963James Dong 14160c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 14170c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSeqParamSet); 14180c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pPicParamSet); 14190c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(noOutputOfPriorPicsFlag); 14200c1bc742181ded4930842b46e9507372f0b1b963James Dong 14210c1bc742181ded4930842b46e9507372f0b1b963James Dong /* must be IDR lsice */ 14220c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(nalUnitType == NAL_CODED_SLICE_IDR); 14230c1bc742181ded4930842b46e9507372f0b1b963James Dong 14240c1bc742181ded4930842b46e9507372f0b1b963James Dong /* don't touch original stream position params */ 14250c1bc742181ded4930842b46e9507372f0b1b963James Dong *tmpStrmData = *pStrmData; 14260c1bc742181ded4930842b46e9507372f0b1b963James Dong 14270c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip first_mb_in_slice */ 14280c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 14290c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp != HANTRO_OK) 14300c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 14310c1bc742181ded4930842b46e9507372f0b1b963James Dong 14320c1bc742181ded4930842b46e9507372f0b1b963James Dong /* slice_type */ 14330c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 14340c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp != HANTRO_OK) 14350c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 14360c1bc742181ded4930842b46e9507372f0b1b963James Dong 14370c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_parameter_set_id */ 14380c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 14390c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp != HANTRO_OK) 14400c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 14410c1bc742181ded4930842b46e9507372f0b1b963James Dong 14420c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxFrameNum) -> num bits to represent frame_num */ 14430c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 14440c1bc742181ded4930842b46e9507372f0b1b963James Dong while(pSeqParamSet->maxFrameNum >> i) 14450c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 14460c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 14470c1bc742181ded4930842b46e9507372f0b1b963James Dong 14480c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip frame_num */ 14490c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 14500c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp == END_OF_STREAM) 14510c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 14520c1bc742181ded4930842b46e9507372f0b1b963James Dong 14530c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip idr_pic_id */ 14540c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 14550c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp != HANTRO_OK) 14560c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 14570c1bc742181ded4930842b46e9507372f0b1b963James Dong 14580c1bc742181ded4930842b46e9507372f0b1b963James Dong if(pSeqParamSet->picOrderCntType == 0) 14590c1bc742181ded4930842b46e9507372f0b1b963James Dong { 14600c1bc742181ded4930842b46e9507372f0b1b963James Dong /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */ 14610c1bc742181ded4930842b46e9507372f0b1b963James Dong i = 0; 14620c1bc742181ded4930842b46e9507372f0b1b963James Dong while(pSeqParamSet->maxPicOrderCntLsb >> i) 14630c1bc742181ded4930842b46e9507372f0b1b963James Dong i++; 14640c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 14650c1bc742181ded4930842b46e9507372f0b1b963James Dong 14660c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip pic_order_cnt_lsb */ 14670c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(tmpStrmData, i); 14680c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp == END_OF_STREAM) 14690c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 14700c1bc742181ded4930842b46e9507372f0b1b963James Dong 14710c1bc742181ded4930842b46e9507372f0b1b963James Dong if(pPicParamSet->picOrderPresentFlag) 14720c1bc742181ded4930842b46e9507372f0b1b963James Dong { 14730c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip delta_pic_order_cnt_bottom */ 14740c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue); 14750c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp != HANTRO_OK) 14760c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 14770c1bc742181ded4930842b46e9507372f0b1b963James Dong } 14780c1bc742181ded4930842b46e9507372f0b1b963James Dong } 14790c1bc742181ded4930842b46e9507372f0b1b963James Dong 14800c1bc742181ded4930842b46e9507372f0b1b963James Dong if(pSeqParamSet->picOrderCntType == 1 && 14810c1bc742181ded4930842b46e9507372f0b1b963James Dong !pSeqParamSet->deltaPicOrderAlwaysZeroFlag) 14820c1bc742181ded4930842b46e9507372f0b1b963James Dong { 14830c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip delta_pic_order_cnt[0] */ 14840c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue); 14850c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp != HANTRO_OK) 14860c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 14870c1bc742181ded4930842b46e9507372f0b1b963James Dong 14880c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip delta_pic_order_cnt[1] if present */ 14890c1bc742181ded4930842b46e9507372f0b1b963James Dong if(pPicParamSet->picOrderPresentFlag) 14900c1bc742181ded4930842b46e9507372f0b1b963James Dong { 14910c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue); 14920c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp != HANTRO_OK) 14930c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 14940c1bc742181ded4930842b46e9507372f0b1b963James Dong } 14950c1bc742181ded4930842b46e9507372f0b1b963James Dong } 14960c1bc742181ded4930842b46e9507372f0b1b963James Dong 14970c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip redundant_pic_cnt */ 14980c1bc742181ded4930842b46e9507372f0b1b963James Dong if(pPicParamSet->redundantPicCntPresentFlag) 14990c1bc742181ded4930842b46e9507372f0b1b963James Dong { 15000c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value); 15010c1bc742181ded4930842b46e9507372f0b1b963James Dong if(tmp != HANTRO_OK) 15020c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 15030c1bc742181ded4930842b46e9507372f0b1b963James Dong } 15040c1bc742181ded4930842b46e9507372f0b1b963James Dong 15050c1bc742181ded4930842b46e9507372f0b1b963James Dong *noOutputOfPriorPicsFlag = h264bsdGetBits(tmpStrmData, 1); 15060c1bc742181ded4930842b46e9507372f0b1b963James Dong if(*noOutputOfPriorPicsFlag == END_OF_STREAM) 15070c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 15080c1bc742181ded4930842b46e9507372f0b1b963James Dong 15090c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_OK); 15100c1bc742181ded4930842b46e9507372f0b1b963James Dong 15110c1bc742181ded4930842b46e9507372f0b1b963James Dong} 15120c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint +e715 */ 15130c1bc742181ded4930842b46e9507372f0b1b963James Dong 15140c1bc742181ded4930842b46e9507372f0b1b963James Dong 1515