Home | History | Annotate | Download | only in source
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*------------------------------------------------------------------------------
     18 
     19     Table of contents
     20 
     21      1. Include headers
     22      2. External compiler flags
     23      3. Module defines
     24      4. Local function prototypes
     25      5. Functions
     26           h264bsdDecodeNalUnit
     27 
     28 ------------------------------------------------------------------------------*/
     29 
     30 /*------------------------------------------------------------------------------
     31     1. Include headers
     32 ------------------------------------------------------------------------------*/
     33 
     34 #include "h264bsd_nal_unit.h"
     35 #include "h264bsd_util.h"
     36 
     37 /*------------------------------------------------------------------------------
     38     2. External compiler flags
     39 --------------------------------------------------------------------------------
     40 
     41 --------------------------------------------------------------------------------
     42     3. Module defines
     43 ------------------------------------------------------------------------------*/
     44 
     45 /*------------------------------------------------------------------------------
     46     4. Local function prototypes
     47 ------------------------------------------------------------------------------*/
     48 
     49 /*------------------------------------------------------------------------------
     50 
     51     Function name: h264bsdDecodeNalUnit
     52 
     53         Functional description:
     54             Decode NAL unit header information
     55 
     56         Inputs:
     57             pStrmData       pointer to stream data structure
     58 
     59         Outputs:
     60             pNalUnit        NAL unit header information is stored here
     61 
     62         Returns:
     63             HANTRO_OK       success
     64             HANTRO_NOK      invalid NAL unit header information
     65 
     66 ------------------------------------------------------------------------------*/
     67 
     68 u32 h264bsdDecodeNalUnit(strmData_t *pStrmData, nalUnit_t *pNalUnit)
     69 {
     70 
     71 /* Variables */
     72 
     73     u32 tmp;
     74 
     75 /* Code */
     76 
     77     ASSERT(pStrmData);
     78     ASSERT(pNalUnit);
     79     ASSERT(pStrmData->bitPosInWord == 0);
     80 
     81     /* forbidden_zero_bit (not checked to be zero, errors ignored) */
     82     tmp = h264bsdGetBits(pStrmData, 1);
     83     /* Assuming that NAL unit starts from byte boundary > don't have to check
     84      * following 7 bits for END_OF_STREAM */
     85     if (tmp == END_OF_STREAM)
     86         return(HANTRO_NOK);
     87 
     88     tmp = h264bsdGetBits(pStrmData, 2);
     89     pNalUnit->nalRefIdc = tmp;
     90 
     91     tmp = h264bsdGetBits(pStrmData, 5);
     92     pNalUnit->nalUnitType = (nalUnitType_e)tmp;
     93 
     94     /* data partitioning NAL units not supported */
     95     if ( (tmp == 2) || (tmp == 3) || (tmp == 4) )
     96     {
     97         return(HANTRO_NOK);
     98     }
     99 
    100     /* nal_ref_idc shall not be zero for these nal_unit_types */
    101     if ( ( (tmp == NAL_SEQ_PARAM_SET) || (tmp == NAL_PIC_PARAM_SET) ||
    102            (tmp == NAL_CODED_SLICE_IDR) ) && (pNalUnit->nalRefIdc == 0) )
    103     {
    104         return(HANTRO_NOK);
    105     }
    106     /* nal_ref_idc shall be zero for these nal_unit_types */
    107     else if ( ( (tmp == NAL_SEI) || (tmp == NAL_ACCESS_UNIT_DELIMITER) ||
    108                 (tmp == NAL_END_OF_SEQUENCE) || (tmp == NAL_END_OF_STREAM) ||
    109                 (tmp == NAL_FILLER_DATA) ) && (pNalUnit->nalRefIdc != 0) )
    110     {
    111         return(HANTRO_NOK);
    112     }
    113 
    114     return(HANTRO_OK);
    115 
    116 }
    117 
    118