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 h264bsdDecodePicParamSet 270c1bc742181ded4930842b46e9507372f0b1b963James Dong 280c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 290c1bc742181ded4930842b46e9507372f0b1b963James Dong 300c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 310c1bc742181ded4930842b46e9507372f0b1b963James Dong 1. Include headers 320c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 330c1bc742181ded4930842b46e9507372f0b1b963James Dong 340c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_pic_param_set.h" 350c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h" 360c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_vlc.h" 370c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_cfg.h" 380c1bc742181ded4930842b46e9507372f0b1b963James Dong 390c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 400c1bc742181ded4930842b46e9507372f0b1b963James Dong 2. External compiler flags 410c1bc742181ded4930842b46e9507372f0b1b963James Dong-------------------------------------------------------------------------------- 420c1bc742181ded4930842b46e9507372f0b1b963James Dong 430c1bc742181ded4930842b46e9507372f0b1b963James Dong-------------------------------------------------------------------------------- 440c1bc742181ded4930842b46e9507372f0b1b963James Dong 3. Module defines 450c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 460c1bc742181ded4930842b46e9507372f0b1b963James Dong 470c1bc742181ded4930842b46e9507372f0b1b963James Dong/* lookup table for ceil(log2(numSliceGroups)), i.e. number of bits needed to 480c1bc742181ded4930842b46e9507372f0b1b963James Dong * represent range [0, numSliceGroups) 490c1bc742181ded4930842b46e9507372f0b1b963James Dong * 500c1bc742181ded4930842b46e9507372f0b1b963James Dong * NOTE: if MAX_NUM_SLICE_GROUPS is higher than 8 this table has to be resized 510c1bc742181ded4930842b46e9507372f0b1b963James Dong * accordingly */ 520c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u32 CeilLog2NumSliceGroups[8] = {1, 1, 2, 2, 3, 3, 3, 3}; 530c1bc742181ded4930842b46e9507372f0b1b963James Dong 540c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 550c1bc742181ded4930842b46e9507372f0b1b963James Dong 4. Local function prototypes 560c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 570c1bc742181ded4930842b46e9507372f0b1b963James Dong 580c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 590c1bc742181ded4930842b46e9507372f0b1b963James Dong 600c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: h264bsdDecodePicParamSet 610c1bc742181ded4930842b46e9507372f0b1b963James Dong 620c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 630c1bc742181ded4930842b46e9507372f0b1b963James Dong Decode picture parameter set information from the stream. 640c1bc742181ded4930842b46e9507372f0b1b963James Dong 650c1bc742181ded4930842b46e9507372f0b1b963James Dong Function allocates memory for 660c1bc742181ded4930842b46e9507372f0b1b963James Dong - run lengths if slice group map type is 0 670c1bc742181ded4930842b46e9507372f0b1b963James Dong - top-left and bottom-right arrays if map type is 2 680c1bc742181ded4930842b46e9507372f0b1b963James Dong - for slice group ids if map type is 6 690c1bc742181ded4930842b46e9507372f0b1b963James Dong 700c1bc742181ded4930842b46e9507372f0b1b963James Dong Validity of some of the slice group mapping information depends 710c1bc742181ded4930842b46e9507372f0b1b963James Dong on the image dimensions which are not known here. Therefore the 720c1bc742181ded4930842b46e9507372f0b1b963James Dong validity has to be checked afterwards, currently in the parameter 730c1bc742181ded4930842b46e9507372f0b1b963James Dong set activation phase. 740c1bc742181ded4930842b46e9507372f0b1b963James Dong 750c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 760c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 770c1bc742181ded4930842b46e9507372f0b1b963James Dong 780c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 790c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet decoded information is stored here 800c1bc742181ded4930842b46e9507372f0b1b963James Dong 810c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 820c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 830c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK failure, invalid information or end of stream 840c1bc742181ded4930842b46e9507372f0b1b963James Dong MEMORY_ALLOCATION_ERROR for memory allocation failure 850c1bc742181ded4930842b46e9507372f0b1b963James Dong 860c1bc742181ded4930842b46e9507372f0b1b963James Dong 870c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 880c1bc742181ded4930842b46e9507372f0b1b963James Dong 890c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdDecodePicParamSet(strmData_t *pStrmData, picParamSet_t *pPicParamSet) 900c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 910c1bc742181ded4930842b46e9507372f0b1b963James Dong 920c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 930c1bc742181ded4930842b46e9507372f0b1b963James Dong 940c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, i, value; 950c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 itmp; 960c1bc742181ded4930842b46e9507372f0b1b963James Dong 970c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 980c1bc742181ded4930842b46e9507372f0b1b963James Dong 990c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 1000c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pPicParamSet); 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong 1020c1bc742181ded4930842b46e9507372f0b1b963James Dong 1030c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecMemset(pPicParamSet, 0, sizeof(picParamSet_t)); 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong 1050c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPicParamSet->picParameterSetId); 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1080c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->picParameterSetId >= MAX_NUM_PIC_PARAM_SETS) 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("pic_parameter_set_id"); 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPicParamSet->seqParameterSetId); 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1180c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1190c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->seqParameterSetId >= MAX_NUM_SEQ_PARAM_SETS) 1200c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1210c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("seq_param_set_id"); 1220c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1230c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1240c1bc742181ded4930842b46e9507372f0b1b963James Dong 1250c1bc742181ded4930842b46e9507372f0b1b963James Dong /* entropy_coding_mode_flag, shall be 0 for baseline profile */ 1260c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 1270c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp) 1280c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1290c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("entropy_coding_mode_flag"); 1300c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1310c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1320c1bc742181ded4930842b46e9507372f0b1b963James Dong 1330c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 1340c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 1350c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1360c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->picOrderPresentFlag = (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE; 1370c1bc742181ded4930842b46e9507372f0b1b963James Dong 1380c1bc742181ded4930842b46e9507372f0b1b963James Dong /* num_slice_groups_minus1 */ 1390c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1400c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1410c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1420c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->numSliceGroups = value + 1; 1430c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->numSliceGroups > MAX_NUM_SLICE_GROUPS) 1440c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1450c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("num_slice_groups_minus1"); 1460c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1470c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1480c1bc742181ded4930842b46e9507372f0b1b963James Dong 1490c1bc742181ded4930842b46e9507372f0b1b963James Dong /* decode slice group mapping information if more than one slice groups */ 1500c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->numSliceGroups > 1) 1510c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1520c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, 1530c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPicParamSet->sliceGroupMapType); 1540c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1550c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1560c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->sliceGroupMapType > 6) 1570c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1580c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("slice_group_map_type"); 1590c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1600c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1610c1bc742181ded4930842b46e9507372f0b1b963James Dong 1620c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->sliceGroupMapType == 0) 1630c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1640c1bc742181ded4930842b46e9507372f0b1b963James Dong ALLOCATE(pPicParamSet->runLength, 1650c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->numSliceGroups, u32); 1660c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->runLength == NULL) 1670c1bc742181ded4930842b46e9507372f0b1b963James Dong return(MEMORY_ALLOCATION_ERROR); 1680c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < pPicParamSet->numSliceGroups; i++) 1690c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1700c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1710c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1720c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1730c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->runLength[i] = value+1; 1740c1bc742181ded4930842b46e9507372f0b1b963James Dong /* param values checked in CheckPps() */ 1750c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1760c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1770c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (pPicParamSet->sliceGroupMapType == 2) 1780c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1790c1bc742181ded4930842b46e9507372f0b1b963James Dong ALLOCATE(pPicParamSet->topLeft, 1800c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->numSliceGroups - 1, u32); 1810c1bc742181ded4930842b46e9507372f0b1b963James Dong ALLOCATE(pPicParamSet->bottomRight, 1820c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->numSliceGroups - 1, u32); 1830c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->topLeft == NULL || 1840c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->bottomRight == NULL) 1850c1bc742181ded4930842b46e9507372f0b1b963James Dong return(MEMORY_ALLOCATION_ERROR); 1860c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < pPicParamSet->numSliceGroups - 1; i++) 1870c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1880c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1890c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1900c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1910c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->topLeft[i] = value; 1920c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1930c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 1940c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 1950c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->bottomRight[i] = value; 1960c1bc742181ded4930842b46e9507372f0b1b963James Dong /* param values checked in CheckPps() */ 1970c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1980c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1990c1bc742181ded4930842b46e9507372f0b1b963James Dong else if ( (pPicParamSet->sliceGroupMapType == 3) || 2000c1bc742181ded4930842b46e9507372f0b1b963James Dong (pPicParamSet->sliceGroupMapType == 4) || 2010c1bc742181ded4930842b46e9507372f0b1b963James Dong (pPicParamSet->sliceGroupMapType == 5) ) 2020c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2030c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 2040c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 2050c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2060c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->sliceGroupChangeDirectionFlag = 2070c1bc742181ded4930842b46e9507372f0b1b963James Dong (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE; 2080c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 2090c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2100c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2110c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->sliceGroupChangeRate = value + 1; 2120c1bc742181ded4930842b46e9507372f0b1b963James Dong /* param value checked in CheckPps() */ 2130c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2140c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (pPicParamSet->sliceGroupMapType == 6) 2150c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2160c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 2170c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2180c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2190c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->picSizeInMapUnits = value + 1; 2200c1bc742181ded4930842b46e9507372f0b1b963James Dong 2210c1bc742181ded4930842b46e9507372f0b1b963James Dong ALLOCATE(pPicParamSet->sliceGroupId, 2220c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->picSizeInMapUnits, u32); 2230c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pPicParamSet->sliceGroupId == NULL) 2240c1bc742181ded4930842b46e9507372f0b1b963James Dong return(MEMORY_ALLOCATION_ERROR); 2250c1bc742181ded4930842b46e9507372f0b1b963James Dong 2260c1bc742181ded4930842b46e9507372f0b1b963James Dong /* determine number of bits needed to represent range 2270c1bc742181ded4930842b46e9507372f0b1b963James Dong * [0, numSliceGroups) */ 2280c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = CeilLog2NumSliceGroups[pPicParamSet->numSliceGroups-1]; 2290c1bc742181ded4930842b46e9507372f0b1b963James Dong 2300c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < pPicParamSet->picSizeInMapUnits; i++) 2310c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2320c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->sliceGroupId[i] = h264bsdGetBits(pStrmData, tmp); 2330c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( pPicParamSet->sliceGroupId[i] >= 2340c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->numSliceGroups ) 2350c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2360c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("slice_group_id"); 2370c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2380c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2390c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2400c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2410c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2420c1bc742181ded4930842b46e9507372f0b1b963James Dong 2430c1bc742181ded4930842b46e9507372f0b1b963James Dong /* num_ref_idx_l0_active_minus1 */ 2440c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 2450c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2460c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2470c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value > 31) 2480c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2490c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("num_ref_idx_l0_active_minus1"); 2500c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2510c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2520c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->numRefIdxL0Active = value + 1; 2530c1bc742181ded4930842b46e9507372f0b1b963James Dong 2540c1bc742181ded4930842b46e9507372f0b1b963James Dong /* num_ref_idx_l1_active_minus1 */ 2550c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 2560c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2570c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2580c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value > 31) 2590c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2600c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("num_ref_idx_l1_active_minus1"); 2610c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2620c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2630c1bc742181ded4930842b46e9507372f0b1b963James Dong 2640c1bc742181ded4930842b46e9507372f0b1b963James Dong /* weighted_pred_flag, this shall be 0 for baseline profile */ 2650c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 2660c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp) 2670c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2680c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("weighted_pred_flag"); 2690c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2700c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2710c1bc742181ded4930842b46e9507372f0b1b963James Dong 2720c1bc742181ded4930842b46e9507372f0b1b963James Dong /* weighted_bipred_idc */ 2730c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 2); 2740c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp > 2) 2750c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2760c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("weighted_bipred_idc"); 2770c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2780c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2790c1bc742181ded4930842b46e9507372f0b1b963James Dong 2800c1bc742181ded4930842b46e9507372f0b1b963James Dong /* pic_init_qp_minus26 */ 2810c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 2820c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2830c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2840c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((itmp < -26) || (itmp > 25)) 2850c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2860c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("pic_init_qp_minus26"); 2870c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2880c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2890c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->picInitQp = (u32)(itmp + 26); 2900c1bc742181ded4930842b46e9507372f0b1b963James Dong 2910c1bc742181ded4930842b46e9507372f0b1b963James Dong /* pic_init_qs_minus26 */ 2920c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 2930c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2940c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2950c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((itmp < -26) || (itmp > 25)) 2960c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2970c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("pic_init_qs_minus26"); 2980c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2990c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3000c1bc742181ded4930842b46e9507372f0b1b963James Dong 3010c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 3020c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3030c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3040c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((itmp < -12) || (itmp > 12)) 3050c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3060c1bc742181ded4930842b46e9507372f0b1b963James Dong EPRINT("chroma_qp_index_offset"); 3070c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3080c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3090c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->chromaQpIndexOffset = itmp; 3100c1bc742181ded4930842b46e9507372f0b1b963James Dong 3110c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 3120c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 3130c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3140c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->deblockingFilterControlPresentFlag = 3150c1bc742181ded4930842b46e9507372f0b1b963James Dong (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE; 3160c1bc742181ded4930842b46e9507372f0b1b963James Dong 3170c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 3180c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 3190c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3200c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->constrainedIntraPredFlag = (tmp == 1) ? 3210c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_TRUE : HANTRO_FALSE; 3220c1bc742181ded4930842b46e9507372f0b1b963James Dong 3230c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 3240c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 3250c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3260c1bc742181ded4930842b46e9507372f0b1b963James Dong pPicParamSet->redundantPicCntPresentFlag = (tmp == 1) ? 3270c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_TRUE : HANTRO_FALSE; 3280c1bc742181ded4930842b46e9507372f0b1b963James Dong 3290c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdRbspTrailingBits(pStrmData); 3300c1bc742181ded4930842b46e9507372f0b1b963James Dong 3310c1bc742181ded4930842b46e9507372f0b1b963James Dong /* ignore possible errors in trailing bits of parameters sets */ 3320c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 3330c1bc742181ded4930842b46e9507372f0b1b963James Dong 3340c1bc742181ded4930842b46e9507372f0b1b963James Dong} 3350c1bc742181ded4930842b46e9507372f0b1b963James Dong 336