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           h264bsdDecodeSliceHeader
     27           NumSliceGroupChangeCycleBits
     28           RefPicListReordering
     29           DecRefPicMarking
     30           CheckPpsId
     31           CheckFrameNum
     32           CheckIdrPicId
     33           CheckPicOrderCntLsb
     34           CheckDeltaPicOrderCntBottom
     35           CheckDeltaPicOrderCnt
     36           CheckRedundantPicCnt
     37 
     38 ------------------------------------------------------------------------------*/
     39 
     40 /*------------------------------------------------------------------------------
     41     1. Include headers
     42 ------------------------------------------------------------------------------*/
     43 
     44 #include "h264bsd_slice_header.h"
     45 #include "h264bsd_util.h"
     46 #include "h264bsd_vlc.h"
     47 #include "h264bsd_nal_unit.h"
     48 #include "h264bsd_dpb.h"
     49 
     50 /*------------------------------------------------------------------------------
     51     2. External compiler flags
     52 --------------------------------------------------------------------------------
     53 
     54 --------------------------------------------------------------------------------
     55     3. Module defines
     56 ------------------------------------------------------------------------------*/
     57 
     58 /*------------------------------------------------------------------------------
     59     4. Local function prototypes
     60 ------------------------------------------------------------------------------*/
     61 
     62 static u32 RefPicListReordering(strmData_t *, refPicListReordering_t *,
     63     u32, u32);
     64 
     65 static u32 NumSliceGroupChangeCycleBits(u32 picSizeInMbs,
     66     u32 sliceGroupChangeRate);
     67 
     68 static u32 DecRefPicMarking(strmData_t *pStrmData,
     69     decRefPicMarking_t *pDecRefPicMarking, nalUnitType_e nalUnitType,
     70     u32 numRefFrames);
     71 
     72 
     73 /*------------------------------------------------------------------------------
     74 
     75     Function name: h264bsdDecodeSliceHeader
     76 
     77         Functional description:
     78             Decode slice header data from the stream.
     79 
     80         Inputs:
     81             pStrmData       pointer to stream data structure
     82             pSeqParamSet    pointer to active sequence parameter set
     83             pPicParamSet    pointer to active picture parameter set
     84             pNalUnit        pointer to current NAL unit structure
     85 
     86         Outputs:
     87             pSliceHeader    decoded data is stored here
     88 
     89         Returns:
     90             HANTRO_OK       success
     91             HANTRO_NOK      invalid stream data or end of stream
     92 
     93 ------------------------------------------------------------------------------*/
     94 
     95 u32 h264bsdDecodeSliceHeader(strmData_t *pStrmData, sliceHeader_t *pSliceHeader,
     96     seqParamSet_t *pSeqParamSet, picParamSet_t *pPicParamSet,
     97     nalUnit_t *pNalUnit)
     98 {
     99 
    100 /* Variables */
    101 
    102     u32 tmp, i, value;
    103     i32 itmp;
    104     u32 picSizeInMbs;
    105 
    106 /* Code */
    107 
    108     ASSERT(pStrmData);
    109     ASSERT(pSliceHeader);
    110     ASSERT(pSeqParamSet);
    111     ASSERT(pPicParamSet);
    112     ASSERT( pNalUnit->nalUnitType == NAL_CODED_SLICE ||
    113             pNalUnit->nalUnitType == NAL_CODED_SLICE_IDR );
    114 
    115 
    116     H264SwDecMemset(pSliceHeader, 0, sizeof(sliceHeader_t));
    117 
    118     picSizeInMbs = pSeqParamSet->picWidthInMbs * pSeqParamSet->picHeightInMbs;
    119     tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    120     if (tmp != HANTRO_OK)
    121         return(tmp);
    122     pSliceHeader->firstMbInSlice = value;
    123     if (value >= picSizeInMbs)
    124     {
    125         EPRINT("first_mb_in_slice");
    126         return(HANTRO_NOK);
    127     }
    128 
    129     tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    130     if (tmp != HANTRO_OK)
    131         return(tmp);
    132     pSliceHeader->sliceType = value;
    133     /* slice type has to be either I or P slice. P slice is not allowed when
    134      * current NAL unit is an IDR NAL unit or num_ref_frames is 0 */
    135     if ( !IS_I_SLICE(pSliceHeader->sliceType) &&
    136          ( !IS_P_SLICE(pSliceHeader->sliceType) ||
    137            IS_IDR_NAL_UNIT(pNalUnit) ||
    138            !pSeqParamSet->numRefFrames ) )
    139     {
    140         EPRINT("slice_type");
    141         return(HANTRO_NOK);
    142     }
    143 
    144     tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    145     if (tmp != HANTRO_OK)
    146         return(tmp);
    147     pSliceHeader->picParameterSetId = value;
    148     if (pSliceHeader->picParameterSetId != pPicParamSet->picParameterSetId)
    149     {
    150         EPRINT("pic_parameter_set_id");
    151         return(HANTRO_NOK);
    152     }
    153 
    154     /* log2(maxFrameNum) -> num bits to represent frame_num */
    155     i = 0;
    156     while (pSeqParamSet->maxFrameNum >> i)
    157         i++;
    158     i--;
    159 
    160     tmp = h264bsdGetBits(pStrmData, i);
    161     if (tmp == END_OF_STREAM)
    162         return(HANTRO_NOK);
    163     if (IS_IDR_NAL_UNIT(pNalUnit) && tmp != 0)
    164     {
    165         EPRINT("frame_num");
    166         return(HANTRO_NOK);
    167     }
    168     pSliceHeader->frameNum = tmp;
    169 
    170     if (IS_IDR_NAL_UNIT(pNalUnit))
    171     {
    172         tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    173         if (tmp != HANTRO_OK)
    174             return(tmp);
    175         pSliceHeader->idrPicId = value;
    176         if (value > 65535)
    177         {
    178             EPRINT("idr_pic_id");
    179             return(HANTRO_NOK);
    180         }
    181     }
    182 
    183     if (pSeqParamSet->picOrderCntType == 0)
    184     {
    185         /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
    186         i = 0;
    187         while (pSeqParamSet->maxPicOrderCntLsb >> i)
    188             i++;
    189         i--;
    190 
    191         tmp = h264bsdGetBits(pStrmData, i);
    192         if (tmp == END_OF_STREAM)
    193             return(HANTRO_NOK);
    194         pSliceHeader->picOrderCntLsb = tmp;
    195 
    196         if (pPicParamSet->picOrderPresentFlag)
    197         {
    198             tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
    199             if (tmp != HANTRO_OK)
    200                 return(tmp);
    201             pSliceHeader->deltaPicOrderCntBottom = itmp;
    202         }
    203 
    204         /* check that picOrderCnt for IDR picture will be zero. See
    205          * DecodePicOrderCnt function to understand the logic here */
    206         if ( IS_IDR_NAL_UNIT(pNalUnit) &&
    207              ( (pSliceHeader->picOrderCntLsb >
    208                 pSeqParamSet->maxPicOrderCntLsb/2) ||
    209                 MIN((i32)pSliceHeader->picOrderCntLsb,
    210                     (i32)pSliceHeader->picOrderCntLsb +
    211                     pSliceHeader->deltaPicOrderCntBottom) != 0 ) )
    212         {
    213             return(HANTRO_NOK);
    214         }
    215     }
    216 
    217     if ( (pSeqParamSet->picOrderCntType == 1) &&
    218          !pSeqParamSet->deltaPicOrderAlwaysZeroFlag )
    219     {
    220         tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
    221         if (tmp != HANTRO_OK)
    222             return(tmp);
    223         pSliceHeader->deltaPicOrderCnt[0] = itmp;
    224 
    225         if (pPicParamSet->picOrderPresentFlag)
    226         {
    227             tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
    228             if (tmp != HANTRO_OK)
    229                 return(tmp);
    230             pSliceHeader->deltaPicOrderCnt[1] = itmp;
    231         }
    232 
    233         /* check that picOrderCnt for IDR picture will be zero. See
    234          * DecodePicOrderCnt function to understand the logic here */
    235         if ( IS_IDR_NAL_UNIT(pNalUnit) &&
    236              MIN(pSliceHeader->deltaPicOrderCnt[0],
    237                  pSliceHeader->deltaPicOrderCnt[0] +
    238                  pSeqParamSet->offsetForTopToBottomField +
    239                  pSliceHeader->deltaPicOrderCnt[1]) != 0)
    240         {
    241             return(HANTRO_NOK);
    242         }
    243     }
    244 
    245     if (pPicParamSet->redundantPicCntPresentFlag)
    246     {
    247         tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    248         if (tmp != HANTRO_OK)
    249             return(tmp);
    250         pSliceHeader->redundantPicCnt = value;
    251         if (value > 127)
    252         {
    253             EPRINT("redundant_pic_cnt");
    254             return(HANTRO_NOK);
    255         }
    256     }
    257 
    258     if (IS_P_SLICE(pSliceHeader->sliceType))
    259     {
    260         tmp = h264bsdGetBits(pStrmData, 1);
    261         if (tmp == END_OF_STREAM)
    262             return(HANTRO_NOK);
    263         pSliceHeader->numRefIdxActiveOverrideFlag = tmp;
    264 
    265         if (pSliceHeader->numRefIdxActiveOverrideFlag)
    266         {
    267             tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    268             if (tmp != HANTRO_OK)
    269                 return(tmp);
    270             if (value > 15)
    271             {
    272                 EPRINT("num_ref_idx_l0_active_minus1");
    273                 return(HANTRO_NOK);
    274             }
    275             pSliceHeader->numRefIdxL0Active = value + 1;
    276         }
    277         /* set numRefIdxL0Active from pic param set */
    278         else
    279         {
    280             /* if value (minus1) in picture parameter set exceeds 15 it should
    281              * have been overridden here */
    282             if (pPicParamSet->numRefIdxL0Active > 16)
    283             {
    284                 EPRINT("num_ref_idx_active_override_flag");
    285                 return(HANTRO_NOK);
    286             }
    287             pSliceHeader->numRefIdxL0Active = pPicParamSet->numRefIdxL0Active;
    288         }
    289     }
    290 
    291     if (IS_P_SLICE(pSliceHeader->sliceType))
    292     {
    293         tmp = RefPicListReordering(pStrmData,
    294             &pSliceHeader->refPicListReordering,
    295             pSliceHeader->numRefIdxL0Active,
    296             pSeqParamSet->maxFrameNum);
    297         if (tmp != HANTRO_OK)
    298             return(tmp);
    299     }
    300 
    301     if (pNalUnit->nalRefIdc != 0)
    302     {
    303         tmp = DecRefPicMarking(pStrmData, &pSliceHeader->decRefPicMarking,
    304             pNalUnit->nalUnitType, pSeqParamSet->numRefFrames);
    305         if (tmp != HANTRO_OK)
    306             return(tmp);
    307     }
    308 
    309     /* decode sliceQpDelta and check that initial QP for the slice will be on
    310      * the range [0, 51] */
    311     tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
    312     if (tmp != HANTRO_OK)
    313         return(tmp);
    314     pSliceHeader->sliceQpDelta = itmp;
    315     itmp += (i32)pPicParamSet->picInitQp;
    316     if ( (itmp < 0) || (itmp > 51) )
    317     {
    318         EPRINT("slice_qp_delta");
    319         return(HANTRO_NOK);
    320     }
    321 
    322     if (pPicParamSet->deblockingFilterControlPresentFlag)
    323     {
    324         tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    325         if (tmp != HANTRO_OK)
    326             return(tmp);
    327         pSliceHeader->disableDeblockingFilterIdc = value;
    328         if (pSliceHeader->disableDeblockingFilterIdc > 2)
    329         {
    330             EPRINT("disable_deblocking_filter_idc");
    331             return(HANTRO_NOK);
    332         }
    333 
    334         if (pSliceHeader->disableDeblockingFilterIdc != 1)
    335         {
    336             tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
    337             if (tmp != HANTRO_OK)
    338                 return(tmp);
    339             if ( (itmp < -6) || (itmp > 6) )
    340             {
    341                EPRINT("slice_alpha_c0_offset_div2");
    342                return(HANTRO_NOK);
    343             }
    344             pSliceHeader->sliceAlphaC0Offset = itmp * 2;
    345 
    346             tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
    347             if (tmp != HANTRO_OK)
    348                 return(tmp);
    349             if ( (itmp < -6) || (itmp > 6) )
    350             {
    351                EPRINT("slice_beta_offset_div2");
    352                return(HANTRO_NOK);
    353             }
    354             pSliceHeader->sliceBetaOffset = itmp * 2;
    355         }
    356     }
    357 
    358     if ( (pPicParamSet->numSliceGroups > 1) &&
    359          (pPicParamSet->sliceGroupMapType >= 3) &&
    360          (pPicParamSet->sliceGroupMapType <= 5) )
    361     {
    362         /* set tmp to number of bits used to represent slice_group_change_cycle
    363          * in the stream */
    364         tmp = NumSliceGroupChangeCycleBits(picSizeInMbs,
    365             pPicParamSet->sliceGroupChangeRate);
    366         value = h264bsdGetBits(pStrmData, tmp);
    367         if (value == END_OF_STREAM)
    368             return(HANTRO_NOK);
    369         pSliceHeader->sliceGroupChangeCycle = value;
    370 
    371         /* corresponds to tmp = Ceil(picSizeInMbs / sliceGroupChangeRate) */
    372         tmp = (picSizeInMbs + pPicParamSet->sliceGroupChangeRate - 1) /
    373               pPicParamSet->sliceGroupChangeRate;
    374         if (pSliceHeader->sliceGroupChangeCycle > tmp)
    375         {
    376             EPRINT("slice_group_change_cycle");
    377             return(HANTRO_NOK);
    378         }
    379     }
    380 
    381     return(HANTRO_OK);
    382 
    383 }
    384 
    385 /*------------------------------------------------------------------------------
    386 
    387     Function: NumSliceGroupChangeCycleBits
    388 
    389         Functional description:
    390             Determine number of bits needed to represent
    391             slice_group_change_cycle in the stream. The standard states that
    392             slice_group_change_cycle is represented by
    393                 Ceil( Log2( (picSizeInMbs / sliceGroupChangeRate) + 1) )
    394 
    395             bits. Division "/" in the equation is non-truncating division.
    396 
    397         Inputs:
    398             picSizeInMbs            picture size in macroblocks
    399             sliceGroupChangeRate
    400 
    401         Outputs:
    402             none
    403 
    404         Returns:
    405             number of bits needed
    406 
    407 ------------------------------------------------------------------------------*/
    408 
    409 u32 NumSliceGroupChangeCycleBits(u32 picSizeInMbs, u32 sliceGroupChangeRate)
    410 {
    411 
    412 /* Variables */
    413 
    414     u32 tmp,numBits,mask;
    415 
    416 /* Code */
    417 
    418     ASSERT(picSizeInMbs);
    419     ASSERT(sliceGroupChangeRate);
    420     ASSERT(sliceGroupChangeRate <= picSizeInMbs);
    421 
    422     /* compute (picSizeInMbs / sliceGroupChangeRate + 1), rounded up */
    423     if (picSizeInMbs % sliceGroupChangeRate)
    424         tmp = 2 + picSizeInMbs/sliceGroupChangeRate;
    425     else
    426         tmp = 1 + picSizeInMbs/sliceGroupChangeRate;
    427 
    428     numBits = 0;
    429     mask = ~0U;
    430 
    431     /* set numBits to position of right-most non-zero bit */
    432     while (tmp & (mask<<++numBits))
    433         ;
    434     numBits--;
    435 
    436     /* add one more bit if value greater than 2^numBits */
    437     if (tmp & ((1<<numBits)-1))
    438         numBits++;
    439 
    440     return(numBits);
    441 
    442 }
    443 
    444 /*------------------------------------------------------------------------------
    445 
    446     Function: RefPicListReordering
    447 
    448         Functional description:
    449             Decode reference picture list reordering syntax elements from
    450             the stream. Max number of reordering commands is numRefIdxActive.
    451 
    452         Inputs:
    453             pStrmData       pointer to stream data structure
    454             numRefIdxActive number of active reference indices to be used for
    455                             current slice
    456             maxPicNum       maxFrameNum from the active SPS
    457 
    458         Outputs:
    459             pRefPicListReordering   decoded data is stored here
    460 
    461         Returns:
    462             HANTRO_OK       success
    463             HANTRO_NOK      invalid stream data
    464 
    465 ------------------------------------------------------------------------------*/
    466 
    467 u32 RefPicListReordering(strmData_t *pStrmData,
    468     refPicListReordering_t *pRefPicListReordering, u32 numRefIdxActive,
    469     u32 maxPicNum)
    470 {
    471 
    472 /* Variables */
    473 
    474     u32 tmp, value, i;
    475     u32 command;
    476 
    477 /* Code */
    478 
    479     ASSERT(pStrmData);
    480     ASSERT(pRefPicListReordering);
    481     ASSERT(numRefIdxActive);
    482     ASSERT(maxPicNum);
    483 
    484 
    485     tmp = h264bsdGetBits(pStrmData, 1);
    486     if (tmp == END_OF_STREAM)
    487         return(HANTRO_NOK);
    488 
    489     pRefPicListReordering->refPicListReorderingFlagL0 = tmp;
    490 
    491     if (pRefPicListReordering->refPicListReorderingFlagL0)
    492     {
    493         i = 0;
    494 
    495         do
    496         {
    497             if (i > numRefIdxActive)
    498             {
    499                 EPRINT("Too many reordering commands");
    500                 return(HANTRO_NOK);
    501             }
    502 
    503             tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &command);
    504             if (tmp != HANTRO_OK)
    505                 return(tmp);
    506             if (command > 3)
    507             {
    508                 EPRINT("reordering_of_pic_nums_idc");
    509                 return(HANTRO_NOK);
    510             }
    511 
    512             pRefPicListReordering->command[i].reorderingOfPicNumsIdc = command;
    513 
    514             if ((command == 0) || (command == 1))
    515             {
    516                 tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    517                 if (tmp != HANTRO_OK)
    518                     return(tmp);
    519                 if (value >= maxPicNum)
    520                 {
    521                     EPRINT("abs_diff_pic_num_minus1");
    522                     return(HANTRO_NOK);
    523                 }
    524                 pRefPicListReordering->command[i].absDiffPicNum = value + 1;
    525                             }
    526             else if (command == 2)
    527             {
    528                 tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    529                 if (tmp != HANTRO_OK)
    530                     return(tmp);
    531                 pRefPicListReordering->command[i].longTermPicNum = value;
    532                             }
    533             i++;
    534         } while (command != 3);
    535 
    536         /* there shall be at least one reordering command if
    537          * refPicListReorderingFlagL0 was set */
    538         if (i == 1)
    539         {
    540             EPRINT("ref_pic_list_reordering");
    541             return(HANTRO_NOK);
    542         }
    543     }
    544 
    545     return(HANTRO_OK);
    546 
    547 }
    548 
    549 /*------------------------------------------------------------------------------
    550 
    551     Function: DecRefPicMarking
    552 
    553         Functional description:
    554             Decode decoded reference picture marking syntax elements from
    555             the stream.
    556 
    557         Inputs:
    558             pStrmData       pointer to stream data structure
    559             nalUnitType     type of the current NAL unit
    560             numRefFrames    max number of reference frames from the active SPS
    561 
    562         Outputs:
    563             pDecRefPicMarking   decoded data is stored here
    564 
    565         Returns:
    566             HANTRO_OK       success
    567             HANTRO_NOK      invalid stream data
    568 
    569 ------------------------------------------------------------------------------*/
    570 
    571 u32 DecRefPicMarking(strmData_t *pStrmData,
    572     decRefPicMarking_t *pDecRefPicMarking, nalUnitType_e nalUnitType,
    573     u32 numRefFrames)
    574 {
    575 
    576 /* Variables */
    577 
    578     u32 tmp, value;
    579     u32 i;
    580     u32 operation;
    581     /* variables for error checking purposes, store number of memory
    582      * management operations of certain type */
    583     u32 num4 = 0, num5 = 0, num6 = 0, num1to3 = 0;
    584 
    585 /* Code */
    586 
    587     ASSERT( nalUnitType == NAL_CODED_SLICE_IDR ||
    588             nalUnitType == NAL_CODED_SLICE ||
    589             nalUnitType == NAL_SEI );
    590 
    591 
    592     if (nalUnitType == NAL_CODED_SLICE_IDR)
    593     {
    594         tmp = h264bsdGetBits(pStrmData, 1);
    595         if (tmp == END_OF_STREAM)
    596             return(HANTRO_NOK);
    597         pDecRefPicMarking->noOutputOfPriorPicsFlag = tmp;
    598 
    599         tmp = h264bsdGetBits(pStrmData, 1);
    600         if (tmp == END_OF_STREAM)
    601             return(HANTRO_NOK);
    602         pDecRefPicMarking->longTermReferenceFlag = tmp;
    603         if (!numRefFrames && pDecRefPicMarking->longTermReferenceFlag)
    604         {
    605             EPRINT("long_term_reference_flag");
    606             return(HANTRO_NOK);
    607         }
    608     }
    609     else
    610     {
    611         tmp = h264bsdGetBits(pStrmData, 1);
    612         if (tmp == END_OF_STREAM)
    613             return(HANTRO_NOK);
    614         pDecRefPicMarking->adaptiveRefPicMarkingModeFlag = tmp;
    615         if (pDecRefPicMarking->adaptiveRefPicMarkingModeFlag)
    616         {
    617             i = 0;
    618             do
    619             {
    620                 /* see explanation of the MAX_NUM_MMC_OPERATIONS in
    621                  * slice_header.h */
    622                 if (i > (2 * numRefFrames + 2))
    623                 {
    624                     EPRINT("Too many management operations");
    625                     return(HANTRO_NOK);
    626                 }
    627 
    628                 tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &operation);
    629                 if (tmp != HANTRO_OK)
    630                     return(tmp);
    631                 if (operation > 6)
    632                 {
    633                     EPRINT("memory_management_control_operation");
    634                     return(HANTRO_NOK);
    635                 }
    636 
    637                 pDecRefPicMarking->operation[i].
    638                     memoryManagementControlOperation = operation;
    639                 if ((operation == 1) || (operation == 3))
    640                 {
    641                     tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    642                     if (tmp != HANTRO_OK)
    643                         return(tmp);
    644                     pDecRefPicMarking->operation[i].differenceOfPicNums =
    645                         value + 1;
    646                 }
    647                 if (operation == 2)
    648                 {
    649                     tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    650                     if (tmp != HANTRO_OK)
    651                         return(tmp);
    652                     pDecRefPicMarking->operation[i].longTermPicNum = value;
    653                 }
    654                 if ((operation == 3) || (operation == 6))
    655                 {
    656                     tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    657                     if (tmp != HANTRO_OK)
    658                         return(tmp);
    659                     pDecRefPicMarking->operation[i].longTermFrameIdx =
    660                         value;
    661                 }
    662                 if (operation == 4)
    663                 {
    664                     tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
    665                     if (tmp != HANTRO_OK)
    666                         return(tmp);
    667                     /* value shall be in range [0, numRefFrames] */
    668                     if (value > numRefFrames)
    669                     {
    670                         EPRINT("max_long_term_frame_idx_plus1");
    671                         return(HANTRO_NOK);
    672                     }
    673                     if (value == 0)
    674                     {
    675                         pDecRefPicMarking->operation[i].
    676                             maxLongTermFrameIdx =
    677                             NO_LONG_TERM_FRAME_INDICES;
    678                     }
    679                     else
    680                     {
    681                         pDecRefPicMarking->operation[i].
    682                             maxLongTermFrameIdx = value - 1;
    683                     }
    684                     num4++;
    685                 }
    686                 if (operation == 5)
    687                 {
    688                     num5++;
    689                 }
    690                 if (operation && operation <= 3)
    691                     num1to3++;
    692                 if (operation == 6)
    693                     num6++;
    694 
    695                 i++;
    696             } while (operation != 0);
    697 
    698             /* error checking */
    699             if (num4 > 1 || num5 > 1 || num6 > 1 || (num1to3 && num5))
    700                 return(HANTRO_NOK);
    701 
    702         }
    703     }
    704 
    705     return(HANTRO_OK);
    706 }
    707 
    708 /*------------------------------------------------------------------------------
    709 
    710     Function name: h264bsdCheckPpsId
    711 
    712         Functional description:
    713             Peek value of pic_parameter_set_id from the slice header. Function
    714             does not modify current stream positions but copies the stream
    715             data structure to tmp structure which is used while accessing
    716             stream data.
    717 
    718         Inputs:
    719             pStrmData       pointer to stream data structure
    720 
    721         Outputs:
    722             picParamSetId   value is stored here
    723 
    724         Returns:
    725             HANTRO_OK       success
    726             HANTRO_NOK      invalid stream data
    727 
    728 ------------------------------------------------------------------------------*/
    729 
    730 u32 h264bsdCheckPpsId(strmData_t *pStrmData, u32 *picParamSetId)
    731 {
    732 
    733 /* Variables */
    734 
    735     u32 tmp, value;
    736     strmData_t tmpStrmData[1];
    737 
    738 /* Code */
    739 
    740     ASSERT(pStrmData);
    741 
    742     /* don't touch original stream position params */
    743     *tmpStrmData = *pStrmData;
    744 
    745     /* first_mb_in_slice */
    746     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    747     if (tmp != HANTRO_OK)
    748         return(tmp);
    749 
    750     /* slice_type */
    751     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    752     if (tmp != HANTRO_OK)
    753         return(tmp);
    754 
    755     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    756     if (tmp != HANTRO_OK)
    757         return(tmp);
    758     if (value >= MAX_NUM_PIC_PARAM_SETS)
    759         return(HANTRO_NOK);
    760 
    761     *picParamSetId = value;
    762 
    763     return(HANTRO_OK);
    764 
    765 }
    766 
    767 /*------------------------------------------------------------------------------
    768 
    769     Function: h264bsdCheckFrameNum
    770 
    771         Functional description:
    772             Peek value of frame_num from the slice header. Function does not
    773             modify current stream positions but copies the stream data
    774             structure to tmp structure which is used while accessing stream
    775             data.
    776 
    777         Inputs:
    778             pStrmData       pointer to stream data structure
    779             maxFrameNum
    780 
    781         Outputs:
    782             frameNum        value is stored here
    783 
    784         Returns:
    785             HANTRO_OK       success
    786             HANTRO_NOK      invalid stream data
    787 
    788 ------------------------------------------------------------------------------*/
    789 
    790 u32 h264bsdCheckFrameNum(
    791   strmData_t *pStrmData,
    792   u32 maxFrameNum,
    793   u32 *frameNum)
    794 {
    795 
    796 /* Variables */
    797 
    798     u32 tmp, value, i;
    799     strmData_t tmpStrmData[1];
    800 
    801 /* Code */
    802 
    803     ASSERT(pStrmData);
    804     ASSERT(maxFrameNum);
    805     ASSERT(frameNum);
    806 
    807     /* don't touch original stream position params */
    808     *tmpStrmData = *pStrmData;
    809 
    810     /* skip first_mb_in_slice */
    811     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    812     if (tmp != HANTRO_OK)
    813         return(tmp);
    814 
    815     /* skip slice_type */
    816     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    817     if (tmp != HANTRO_OK)
    818         return(tmp);
    819 
    820     /* skip pic_parameter_set_id */
    821     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    822     if (tmp != HANTRO_OK)
    823         return(tmp);
    824 
    825     /* log2(maxFrameNum) -> num bits to represent frame_num */
    826     i = 0;
    827     while (maxFrameNum >> i)
    828         i++;
    829     i--;
    830 
    831     /* frame_num */
    832     tmp = h264bsdGetBits(tmpStrmData, i);
    833     if (tmp == END_OF_STREAM)
    834         return(HANTRO_NOK);
    835     *frameNum = tmp;
    836 
    837     return(HANTRO_OK);
    838 
    839 }
    840 
    841 /*------------------------------------------------------------------------------
    842 
    843     Function: h264bsdCheckIdrPicId
    844 
    845         Functional description:
    846             Peek value of idr_pic_id from the slice header. Function does not
    847             modify current stream positions but copies the stream data
    848             structure to tmp structure which is used while accessing stream
    849             data.
    850 
    851         Inputs:
    852             pStrmData       pointer to stream data structure
    853             maxFrameNum     max frame number from active SPS
    854             nalUnitType     type of the current NAL unit
    855 
    856         Outputs:
    857             idrPicId        value is stored here
    858 
    859         Returns:
    860             HANTRO_OK       success
    861             HANTRO_NOK      invalid stream data
    862 
    863 ------------------------------------------------------------------------------*/
    864 
    865 u32 h264bsdCheckIdrPicId(
    866   strmData_t *pStrmData,
    867   u32 maxFrameNum,
    868   nalUnitType_e nalUnitType,
    869   u32 *idrPicId)
    870 {
    871 
    872 /* Variables */
    873 
    874     u32 tmp, value, i;
    875     strmData_t tmpStrmData[1];
    876 
    877 /* Code */
    878 
    879     ASSERT(pStrmData);
    880     ASSERT(maxFrameNum);
    881     ASSERT(idrPicId);
    882 
    883     /* nalUnitType must be equal to 5 because otherwise idrPicId is not
    884      * present */
    885     if (nalUnitType != NAL_CODED_SLICE_IDR)
    886         return(HANTRO_NOK);
    887 
    888     /* don't touch original stream position params */
    889     *tmpStrmData = *pStrmData;
    890 
    891     /* skip first_mb_in_slice */
    892     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    893     if (tmp != HANTRO_OK)
    894         return(tmp);
    895 
    896     /* skip slice_type */
    897     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    898     if (tmp != HANTRO_OK)
    899         return(tmp);
    900 
    901     /* skip pic_parameter_set_id */
    902     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    903     if (tmp != HANTRO_OK)
    904         return(tmp);
    905 
    906     /* log2(maxFrameNum) -> num bits to represent frame_num */
    907     i = 0;
    908     while (maxFrameNum >> i)
    909         i++;
    910     i--;
    911 
    912     /* skip frame_num */
    913     tmp = h264bsdGetBits(tmpStrmData, i);
    914     if (tmp == END_OF_STREAM)
    915         return(HANTRO_NOK);
    916 
    917     /* idr_pic_id */
    918     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, idrPicId);
    919     if (tmp != HANTRO_OK)
    920         return(tmp);
    921 
    922     return(HANTRO_OK);
    923 
    924 }
    925 
    926 /*------------------------------------------------------------------------------
    927 
    928     Function: h264bsdCheckPicOrderCntLsb
    929 
    930         Functional description:
    931             Peek value of pic_order_cnt_lsb from the slice header. Function
    932             does not modify current stream positions but copies the stream
    933             data structure to tmp structure which is used while accessing
    934             stream data.
    935 
    936         Inputs:
    937             pStrmData       pointer to stream data structure
    938             pSeqParamSet    pointer to active SPS
    939             nalUnitType     type of the current NAL unit
    940 
    941         Outputs:
    942             picOrderCntLsb  value is stored here
    943 
    944         Returns:
    945             HANTRO_OK       success
    946             HANTRO_NOK      invalid stream data
    947 
    948 ------------------------------------------------------------------------------*/
    949 
    950 u32 h264bsdCheckPicOrderCntLsb(
    951   strmData_t *pStrmData,
    952   seqParamSet_t *pSeqParamSet,
    953   nalUnitType_e nalUnitType,
    954   u32 *picOrderCntLsb)
    955 {
    956 
    957 /* Variables */
    958 
    959     u32 tmp, value, i;
    960     strmData_t tmpStrmData[1];
    961 
    962 /* Code */
    963 
    964     ASSERT(pStrmData);
    965     ASSERT(pSeqParamSet);
    966     ASSERT(picOrderCntLsb);
    967 
    968     /* picOrderCntType must be equal to 0 */
    969     ASSERT(pSeqParamSet->picOrderCntType == 0);
    970     ASSERT(pSeqParamSet->maxFrameNum);
    971     ASSERT(pSeqParamSet->maxPicOrderCntLsb);
    972 
    973     /* don't touch original stream position params */
    974     *tmpStrmData = *pStrmData;
    975 
    976     /* skip first_mb_in_slice */
    977     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    978     if (tmp != HANTRO_OK)
    979         return(tmp);
    980 
    981     /* skip slice_type */
    982     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    983     if (tmp != HANTRO_OK)
    984         return(tmp);
    985 
    986     /* skip pic_parameter_set_id */
    987     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
    988     if (tmp != HANTRO_OK)
    989         return(tmp);
    990 
    991     /* log2(maxFrameNum) -> num bits to represent frame_num */
    992     i = 0;
    993     while (pSeqParamSet->maxFrameNum >> i)
    994         i++;
    995     i--;
    996 
    997     /* skip frame_num */
    998     tmp = h264bsdGetBits(tmpStrmData, i);
    999     if (tmp == END_OF_STREAM)
   1000         return(HANTRO_NOK);
   1001 
   1002     /* skip idr_pic_id when necessary */
   1003     if (nalUnitType == NAL_CODED_SLICE_IDR)
   1004     {
   1005         tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1006         if (tmp != HANTRO_OK)
   1007             return(tmp);
   1008     }
   1009 
   1010     /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
   1011     i = 0;
   1012     while (pSeqParamSet->maxPicOrderCntLsb >> i)
   1013         i++;
   1014     i--;
   1015 
   1016     /* pic_order_cnt_lsb */
   1017     tmp = h264bsdGetBits(tmpStrmData, i);
   1018     if (tmp == END_OF_STREAM)
   1019         return(HANTRO_NOK);
   1020     *picOrderCntLsb = tmp;
   1021 
   1022     return(HANTRO_OK);
   1023 
   1024 }
   1025 
   1026 /*------------------------------------------------------------------------------
   1027 
   1028     Function: h264bsdCheckDeltaPicOrderCntBottom
   1029 
   1030         Functional description:
   1031             Peek value of delta_pic_order_cnt_bottom from the slice header.
   1032             Function does not modify current stream positions but copies the
   1033             stream data structure to tmp structure which is used while
   1034             accessing stream data.
   1035 
   1036         Inputs:
   1037             pStrmData       pointer to stream data structure
   1038             pSeqParamSet    pointer to active SPS
   1039             nalUnitType     type of the current NAL unit
   1040 
   1041         Outputs:
   1042             deltaPicOrderCntBottom  value is stored here
   1043 
   1044         Returns:
   1045             HANTRO_OK       success
   1046             HANTRO_NOK      invalid stream data
   1047 
   1048 ------------------------------------------------------------------------------*/
   1049 
   1050 u32 h264bsdCheckDeltaPicOrderCntBottom(
   1051   strmData_t *pStrmData,
   1052   seqParamSet_t *pSeqParamSet,
   1053   nalUnitType_e nalUnitType,
   1054   i32 *deltaPicOrderCntBottom)
   1055 {
   1056 
   1057 /* Variables */
   1058 
   1059     u32 tmp, value, i;
   1060     strmData_t tmpStrmData[1];
   1061 
   1062 /* Code */
   1063 
   1064     ASSERT(pStrmData);
   1065     ASSERT(pSeqParamSet);
   1066     ASSERT(deltaPicOrderCntBottom);
   1067 
   1068     /* picOrderCntType must be equal to 0 and picOrderPresentFlag must be TRUE
   1069      * */
   1070     ASSERT(pSeqParamSet->picOrderCntType == 0);
   1071     ASSERT(pSeqParamSet->maxFrameNum);
   1072     ASSERT(pSeqParamSet->maxPicOrderCntLsb);
   1073 
   1074     /* don't touch original stream position params */
   1075     *tmpStrmData = *pStrmData;
   1076 
   1077     /* skip first_mb_in_slice */
   1078     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1079     if (tmp != HANTRO_OK)
   1080         return(tmp);
   1081 
   1082     /* skip slice_type */
   1083     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1084     if (tmp != HANTRO_OK)
   1085         return(tmp);
   1086 
   1087     /* skip pic_parameter_set_id */
   1088     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1089     if (tmp != HANTRO_OK)
   1090         return(tmp);
   1091 
   1092     /* log2(maxFrameNum) -> num bits to represent frame_num */
   1093     i = 0;
   1094     while (pSeqParamSet->maxFrameNum >> i)
   1095         i++;
   1096     i--;
   1097 
   1098     /* skip frame_num */
   1099     tmp = h264bsdGetBits(tmpStrmData, i);
   1100     if (tmp == END_OF_STREAM)
   1101         return(HANTRO_NOK);
   1102 
   1103     /* skip idr_pic_id when necessary */
   1104     if (nalUnitType == NAL_CODED_SLICE_IDR)
   1105     {
   1106         tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1107         if (tmp != HANTRO_OK)
   1108             return(tmp);
   1109     }
   1110 
   1111     /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
   1112     i = 0;
   1113     while (pSeqParamSet->maxPicOrderCntLsb >> i)
   1114         i++;
   1115     i--;
   1116 
   1117     /* skip pic_order_cnt_lsb */
   1118     tmp = h264bsdGetBits(tmpStrmData, i);
   1119     if (tmp == END_OF_STREAM)
   1120         return(HANTRO_NOK);
   1121 
   1122     /* delta_pic_order_cnt_bottom */
   1123     tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, deltaPicOrderCntBottom);
   1124     if (tmp != HANTRO_OK)
   1125         return(tmp);
   1126 
   1127     return(HANTRO_OK);
   1128 
   1129 }
   1130 
   1131 /*------------------------------------------------------------------------------
   1132 
   1133     Function: h264bsdCheckDeltaPicOrderCnt
   1134 
   1135         Functional description:
   1136             Peek values delta_pic_order_cnt[0] and delta_pic_order_cnt[1]
   1137             from the slice header. Function does not modify current stream
   1138             positions but copies the stream data structure to tmp structure
   1139             which is used while accessing stream data.
   1140 
   1141         Inputs:
   1142             pStrmData               pointer to stream data structure
   1143             pSeqParamSet            pointer to active SPS
   1144             nalUnitType             type of the current NAL unit
   1145             picOrderPresentFlag     flag indicating if delta_pic_order_cnt[1]
   1146                                     is present in the stream
   1147 
   1148         Outputs:
   1149             deltaPicOrderCnt        values are stored here
   1150 
   1151         Returns:
   1152             HANTRO_OK               success
   1153             HANTRO_NOK              invalid stream data
   1154 
   1155 ------------------------------------------------------------------------------*/
   1156 
   1157 u32 h264bsdCheckDeltaPicOrderCnt(
   1158   strmData_t *pStrmData,
   1159   seqParamSet_t *pSeqParamSet,
   1160   nalUnitType_e nalUnitType,
   1161   u32 picOrderPresentFlag,
   1162   i32 *deltaPicOrderCnt)
   1163 {
   1164 
   1165 /* Variables */
   1166 
   1167     u32 tmp, value, i;
   1168     strmData_t tmpStrmData[1];
   1169 
   1170 /* Code */
   1171 
   1172     ASSERT(pStrmData);
   1173     ASSERT(pSeqParamSet);
   1174     ASSERT(deltaPicOrderCnt);
   1175 
   1176     /* picOrderCntType must be equal to 1 and deltaPicOrderAlwaysZeroFlag must
   1177      * be FALSE */
   1178     ASSERT(pSeqParamSet->picOrderCntType == 1);
   1179     ASSERT(!pSeqParamSet->deltaPicOrderAlwaysZeroFlag);
   1180     ASSERT(pSeqParamSet->maxFrameNum);
   1181 
   1182     /* don't touch original stream position params */
   1183     *tmpStrmData = *pStrmData;
   1184 
   1185     /* skip first_mb_in_slice */
   1186     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1187     if (tmp != HANTRO_OK)
   1188         return(tmp);
   1189 
   1190     /* skip slice_type */
   1191     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1192     if (tmp != HANTRO_OK)
   1193         return(tmp);
   1194 
   1195     /* skip pic_parameter_set_id */
   1196     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1197     if (tmp != HANTRO_OK)
   1198         return(tmp);
   1199 
   1200     /* log2(maxFrameNum) -> num bits to represent frame_num */
   1201     i = 0;
   1202     while (pSeqParamSet->maxFrameNum >> i)
   1203         i++;
   1204     i--;
   1205 
   1206     /* skip frame_num */
   1207     tmp = h264bsdGetBits(tmpStrmData, i);
   1208     if (tmp == END_OF_STREAM)
   1209         return(HANTRO_NOK);
   1210 
   1211     /* skip idr_pic_id when necessary */
   1212     if (nalUnitType == NAL_CODED_SLICE_IDR)
   1213     {
   1214         tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1215         if (tmp != HANTRO_OK)
   1216             return(tmp);
   1217     }
   1218 
   1219     /* delta_pic_order_cnt[0] */
   1220     tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &deltaPicOrderCnt[0]);
   1221     if (tmp != HANTRO_OK)
   1222         return(tmp);
   1223 
   1224     /* delta_pic_order_cnt[1] if present */
   1225     if (picOrderPresentFlag)
   1226     {
   1227         tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &deltaPicOrderCnt[1]);
   1228         if (tmp != HANTRO_OK)
   1229             return(tmp);
   1230     }
   1231 
   1232     return(HANTRO_OK);
   1233 
   1234 }
   1235 
   1236 /*------------------------------------------------------------------------------
   1237 
   1238     Function: h264bsdCheckRedundantPicCnt
   1239 
   1240         Functional description:
   1241             Peek value of redundant_pic_cnt from the slice header. Function
   1242             does not modify current stream positions but copies the stream
   1243             data structure to tmp structure which is used while accessing
   1244             stream data.
   1245 
   1246         Inputs:
   1247             pStrmData       pointer to stream data structure
   1248             pSeqParamSet    pointer to active SPS
   1249             pPicParamSet    pointer to active PPS
   1250             nalUnitType     type of the current NAL unit
   1251 
   1252         Outputs:
   1253             redundantPicCnt value is stored here
   1254 
   1255         Returns:
   1256             HANTRO_OK       success
   1257             HANTRO_NOK      invalid stream data
   1258 
   1259 ------------------------------------------------------------------------------*/
   1260 
   1261 u32 h264bsdCheckRedundantPicCnt(
   1262   strmData_t *pStrmData,
   1263   seqParamSet_t *pSeqParamSet,
   1264   picParamSet_t *pPicParamSet,
   1265   nalUnitType_e nalUnitType,
   1266   u32 *redundantPicCnt)
   1267 {
   1268 
   1269 /* Variables */
   1270 
   1271     u32 tmp, value, i;
   1272     i32 ivalue;
   1273     strmData_t tmpStrmData[1];
   1274 
   1275 /* Code */
   1276 
   1277     ASSERT(pStrmData);
   1278     ASSERT(pSeqParamSet);
   1279     ASSERT(pPicParamSet);
   1280     ASSERT(redundantPicCnt);
   1281 
   1282     /* redundant_pic_cnt_flag must be TRUE */
   1283     ASSERT(pPicParamSet->redundantPicCntPresentFlag);
   1284     ASSERT(pSeqParamSet->maxFrameNum);
   1285     ASSERT(pSeqParamSet->picOrderCntType > 0 ||
   1286            pSeqParamSet->maxPicOrderCntLsb);
   1287 
   1288     /* don't touch original stream position params */
   1289     *tmpStrmData = *pStrmData;
   1290 
   1291     /* skip first_mb_in_slice */
   1292     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1293     if (tmp != HANTRO_OK)
   1294         return(tmp);
   1295 
   1296     /* skip slice_type */
   1297     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1298     if (tmp != HANTRO_OK)
   1299         return(tmp);
   1300 
   1301     /* skip pic_parameter_set_id */
   1302     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1303     if (tmp != HANTRO_OK)
   1304         return(tmp);
   1305 
   1306     /* log2(maxFrameNum) -> num bits to represent frame_num */
   1307     i = 0;
   1308     while (pSeqParamSet->maxFrameNum >> i)
   1309         i++;
   1310     i--;
   1311 
   1312     /* skip frame_num */
   1313     tmp = h264bsdGetBits(tmpStrmData, i);
   1314     if (tmp == END_OF_STREAM)
   1315         return(HANTRO_NOK);
   1316 
   1317     /* skip idr_pic_id when necessary */
   1318     if (nalUnitType == NAL_CODED_SLICE_IDR)
   1319     {
   1320         tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1321         if (tmp != HANTRO_OK)
   1322             return(tmp);
   1323     }
   1324 
   1325     if (pSeqParamSet->picOrderCntType == 0)
   1326     {
   1327         /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
   1328         i = 0;
   1329         while (pSeqParamSet->maxPicOrderCntLsb >> i)
   1330             i++;
   1331         i--;
   1332 
   1333         /* pic_order_cnt_lsb */
   1334         tmp = h264bsdGetBits(tmpStrmData, i);
   1335         if (tmp == END_OF_STREAM)
   1336             return(HANTRO_NOK);
   1337 
   1338         if (pPicParamSet->picOrderPresentFlag)
   1339         {
   1340             /* skip delta_pic_order_cnt_bottom */
   1341             tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
   1342             if (tmp != HANTRO_OK)
   1343                 return(tmp);
   1344         }
   1345     }
   1346 
   1347     if (pSeqParamSet->picOrderCntType == 1 &&
   1348       !pSeqParamSet->deltaPicOrderAlwaysZeroFlag)
   1349     {
   1350         /* delta_pic_order_cnt[0] */
   1351         tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
   1352         if (tmp != HANTRO_OK)
   1353             return(tmp);
   1354 
   1355         /* delta_pic_order_cnt[1] if present */
   1356         if (pPicParamSet->picOrderPresentFlag)
   1357         {
   1358             tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
   1359             if (tmp != HANTRO_OK)
   1360                 return(tmp);
   1361         }
   1362     }
   1363 
   1364     /* redundant_pic_cnt */
   1365     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, redundantPicCnt);
   1366     if (tmp != HANTRO_OK)
   1367         return(tmp);
   1368 
   1369     return(HANTRO_OK);
   1370 
   1371 }
   1372 
   1373 
   1374 /*------------------------------------------------------------------------------
   1375 
   1376     Function: h264bsdCheckPriorPicsFlag
   1377 
   1378         Functional description:
   1379             Peek value of no_output_of_prior_pics_flag from the slice header.
   1380             Function does not modify current stream positions but copies
   1381             the stream data structure to tmp structure which is used while
   1382             accessing stream data.
   1383 
   1384         Inputs:
   1385             pStrmData       pointer to stream data structure
   1386             pSeqParamSet    pointer to active SPS
   1387             pPicParamSet    pointer to active PPS
   1388             nalUnitType     type of the current NAL unit
   1389 
   1390         Outputs:
   1391             noOutputOfPriorPicsFlag value is stored here
   1392 
   1393         Returns:
   1394             HANTRO_OK       success
   1395             HANTRO_NOK      invalid stream data
   1396 
   1397 ------------------------------------------------------------------------------*/
   1398 /*lint -e715 disable lint info nalUnitType not referenced */
   1399 u32 h264bsdCheckPriorPicsFlag(u32 * noOutputOfPriorPicsFlag,
   1400                               const strmData_t * pStrmData,
   1401                               const seqParamSet_t * pSeqParamSet,
   1402                               const picParamSet_t * pPicParamSet,
   1403                               nalUnitType_e nalUnitType)
   1404 {
   1405 /* Variables */
   1406 
   1407     u32 tmp, value, i;
   1408     i32 ivalue;
   1409     strmData_t tmpStrmData[1];
   1410 
   1411 /* Code */
   1412 
   1413     ASSERT(pStrmData);
   1414     ASSERT(pSeqParamSet);
   1415     ASSERT(pPicParamSet);
   1416     ASSERT(noOutputOfPriorPicsFlag);
   1417 
   1418     /* must be IDR lsice */
   1419     ASSERT(nalUnitType == NAL_CODED_SLICE_IDR);
   1420 
   1421     /* don't touch original stream position params */
   1422     *tmpStrmData = *pStrmData;
   1423 
   1424     /* skip first_mb_in_slice */
   1425     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1426     if(tmp != HANTRO_OK)
   1427         return (tmp);
   1428 
   1429     /* slice_type */
   1430     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1431     if(tmp != HANTRO_OK)
   1432         return (tmp);
   1433 
   1434     /* skip pic_parameter_set_id */
   1435     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1436     if(tmp != HANTRO_OK)
   1437         return (tmp);
   1438 
   1439     /* log2(maxFrameNum) -> num bits to represent frame_num */
   1440     i = 0;
   1441     while(pSeqParamSet->maxFrameNum >> i)
   1442         i++;
   1443     i--;
   1444 
   1445     /* skip frame_num */
   1446     tmp = h264bsdGetBits(tmpStrmData, i);
   1447     if(tmp == END_OF_STREAM)
   1448         return (HANTRO_NOK);
   1449 
   1450     /* skip idr_pic_id */
   1451     tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1452     if(tmp != HANTRO_OK)
   1453         return (tmp);
   1454 
   1455     if(pSeqParamSet->picOrderCntType == 0)
   1456     {
   1457         /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
   1458         i = 0;
   1459         while(pSeqParamSet->maxPicOrderCntLsb >> i)
   1460             i++;
   1461         i--;
   1462 
   1463         /* skip pic_order_cnt_lsb */
   1464         tmp = h264bsdGetBits(tmpStrmData, i);
   1465         if(tmp == END_OF_STREAM)
   1466             return (HANTRO_NOK);
   1467 
   1468         if(pPicParamSet->picOrderPresentFlag)
   1469         {
   1470             /* skip delta_pic_order_cnt_bottom */
   1471             tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
   1472             if(tmp != HANTRO_OK)
   1473                 return (tmp);
   1474         }
   1475     }
   1476 
   1477     if(pSeqParamSet->picOrderCntType == 1 &&
   1478        !pSeqParamSet->deltaPicOrderAlwaysZeroFlag)
   1479     {
   1480         /* skip delta_pic_order_cnt[0] */
   1481         tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
   1482         if(tmp != HANTRO_OK)
   1483             return (tmp);
   1484 
   1485         /* skip delta_pic_order_cnt[1] if present */
   1486         if(pPicParamSet->picOrderPresentFlag)
   1487         {
   1488             tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
   1489             if(tmp != HANTRO_OK)
   1490                 return (tmp);
   1491         }
   1492     }
   1493 
   1494     /* skip redundant_pic_cnt */
   1495     if(pPicParamSet->redundantPicCntPresentFlag)
   1496     {
   1497         tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
   1498         if(tmp != HANTRO_OK)
   1499             return (tmp);
   1500     }
   1501 
   1502     *noOutputOfPriorPicsFlag = h264bsdGetBits(tmpStrmData, 1);
   1503     if(*noOutputOfPriorPicsFlag == END_OF_STREAM)
   1504         return (HANTRO_NOK);
   1505 
   1506     return (HANTRO_OK);
   1507 
   1508 }
   1509 /*lint +e715 */
   1510 
   1511 
   1512