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 h264bsdDecodeNalUnit 270c1bc742181ded4930842b46e9507372f0b1b963James Dong 280c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 290c1bc742181ded4930842b46e9507372f0b1b963James Dong 300c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 310c1bc742181ded4930842b46e9507372f0b1b963James Dong 1. Include headers 320c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 330c1bc742181ded4930842b46e9507372f0b1b963James Dong 340c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_nal_unit.h" 350c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h" 360c1bc742181ded4930842b46e9507372f0b1b963James Dong 370c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 380c1bc742181ded4930842b46e9507372f0b1b963James Dong 2. External compiler flags 390c1bc742181ded4930842b46e9507372f0b1b963James Dong-------------------------------------------------------------------------------- 400c1bc742181ded4930842b46e9507372f0b1b963James Dong 410c1bc742181ded4930842b46e9507372f0b1b963James Dong-------------------------------------------------------------------------------- 420c1bc742181ded4930842b46e9507372f0b1b963James Dong 3. Module defines 430c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 440c1bc742181ded4930842b46e9507372f0b1b963James Dong 450c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 460c1bc742181ded4930842b46e9507372f0b1b963James Dong 4. Local function prototypes 470c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 480c1bc742181ded4930842b46e9507372f0b1b963James Dong 490c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 500c1bc742181ded4930842b46e9507372f0b1b963James Dong 510c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: h264bsdDecodeNalUnit 520c1bc742181ded4930842b46e9507372f0b1b963James Dong 530c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 540c1bc742181ded4930842b46e9507372f0b1b963James Dong Decode NAL unit header information 550c1bc742181ded4930842b46e9507372f0b1b963James Dong 560c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 570c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 580c1bc742181ded4930842b46e9507372f0b1b963James Dong 590c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 600c1bc742181ded4930842b46e9507372f0b1b963James Dong pNalUnit NAL unit header information is stored here 610c1bc742181ded4930842b46e9507372f0b1b963James Dong 620c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 630c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 640c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK invalid NAL unit header information 650c1bc742181ded4930842b46e9507372f0b1b963James Dong 660c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 670c1bc742181ded4930842b46e9507372f0b1b963James Dong 680c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdDecodeNalUnit(strmData_t *pStrmData, nalUnit_t *pNalUnit) 690c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 700c1bc742181ded4930842b46e9507372f0b1b963James Dong 710c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 720c1bc742181ded4930842b46e9507372f0b1b963James Dong 730c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp; 740c1bc742181ded4930842b46e9507372f0b1b963James Dong 750c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 760c1bc742181ded4930842b46e9507372f0b1b963James Dong 770c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 780c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pNalUnit); 790c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData->bitPosInWord == 0); 800c1bc742181ded4930842b46e9507372f0b1b963James Dong 810c1bc742181ded4930842b46e9507372f0b1b963James Dong /* forbidden_zero_bit (not checked to be zero, errors ignored) */ 820c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 830c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Assuming that NAL unit starts from byte boundary �> don't have to check 840c1bc742181ded4930842b46e9507372f0b1b963James Dong * following 7 bits for END_OF_STREAM */ 850c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp == END_OF_STREAM) 860c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 870c1bc742181ded4930842b46e9507372f0b1b963James Dong 880c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 2); 890c1bc742181ded4930842b46e9507372f0b1b963James Dong pNalUnit->nalRefIdc = tmp; 900c1bc742181ded4930842b46e9507372f0b1b963James Dong 910c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 5); 920c1bc742181ded4930842b46e9507372f0b1b963James Dong pNalUnit->nalUnitType = (nalUnitType_e)tmp; 930c1bc742181ded4930842b46e9507372f0b1b963James Dong 940c1bc742181ded4930842b46e9507372f0b1b963James Dong /* data partitioning NAL units not supported */ 950c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (tmp == 2) || (tmp == 3) || (tmp == 4) ) 960c1bc742181ded4930842b46e9507372f0b1b963James Dong { 970c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 980c1bc742181ded4930842b46e9507372f0b1b963James Dong } 990c1bc742181ded4930842b46e9507372f0b1b963James Dong 1000c1bc742181ded4930842b46e9507372f0b1b963James Dong /* nal_ref_idc shall not be zero for these nal_unit_types */ 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( ( (tmp == NAL_SEQ_PARAM_SET) || (tmp == NAL_PIC_PARAM_SET) || 1020c1bc742181ded4930842b46e9507372f0b1b963James Dong (tmp == NAL_CODED_SLICE_IDR) ) && (pNalUnit->nalRefIdc == 0) ) 1030c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1050c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong /* nal_ref_idc shall be zero for these nal_unit_types */ 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong else if ( ( (tmp == NAL_SEI) || (tmp == NAL_ACCESS_UNIT_DELIMITER) || 1080c1bc742181ded4930842b46e9507372f0b1b963James Dong (tmp == NAL_END_OF_SEQUENCE) || (tmp == NAL_END_OF_STREAM) || 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong (tmp == NAL_FILLER_DATA) ) && (pNalUnit->nalRefIdc != 0) ) 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong} 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong 118