PageRenderTime 69ms CodeModel.GetById 13ms app.highlight 48ms RepoModel.GetById 1ms app.codeStats 0ms

/H264Dec/source/h264bsd_sei.c

http://github.com/mbebenita/Broadway
C | 1693 lines | 1013 code | 326 blank | 354 comment | 301 complexity | 57cd7769ddf808bb97e81a30a4d320d6 MD5 | raw file
   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          h264bsdDecodeSeiMessage
  27          DecodeBufferingPeriod
  28          DecodePictureTiming
  29          DecodePanScanRectangle
  30          DecodeFillerPayload
  31          DecodeUserDataRegisteredITuTT35
  32          DecodeUserDataUnregistered
  33          DecodeRecoveryPoint
  34          DecodeDecRefPicMarkingRepetition
  35          DecodeSparePic
  36          DecodeSceneInfo
  37          DecodeSubSeqInfo
  38          DecodeSubSeqLayerCharacteristics
  39          DecodeSubSeqCharacteristics
  40          DecodeFullFrameFreeze
  41          DecodeFullFrameSnapshot
  42          DecodeProgressiveRefinementSegmentStart
  43          DecodeProgressiveRefinementSegmentEnd
  44          DecodeMotionConstrainedSliceGroupSet
  45          DecodeReservedSeiMessage
  46
  47------------------------------------------------------------------------------*/
  48
  49/*------------------------------------------------------------------------------
  50    1. Include headers
  51------------------------------------------------------------------------------*/
  52
  53#include "h264bsd_sei.h"
  54#include "basetype.h"
  55#include "h264bsd_util.h"
  56#include "h264bsd_stream.h"
  57#include "h264bsd_vlc.h"
  58#include "h264bsd_seq_param_set.h"
  59#include "h264bsd_slice_header.h"
  60
  61/*------------------------------------------------------------------------------
  62    2. External compiler flags
  63--------------------------------------------------------------------------------
  64
  65--------------------------------------------------------------------------------
  66    3. Module defines
  67------------------------------------------------------------------------------*/
  68
  69static const u32 numClockTS[9] = {1,1,1,2,2,3,3,2,3};
  70static const u32 ceilLog2NumSliceGroups[9] = {0,1,1,2,2,3,3,3,3};
  71
  72/*------------------------------------------------------------------------------
  73    4. Local function prototypes
  74------------------------------------------------------------------------------*/
  75
  76static u32 DecodeBufferingPeriod(
  77  strmData_t *pStrmData,
  78  seiBufferingPeriod_t *pBufferingPeriod,
  79  u32 cpbCnt,
  80  u32 initialCpbRemovalDelayLength,
  81  u32 nalHrdBpPresentFlag,
  82  u32 vclHrdBpPresentFlag);
  83
  84static u32 DecodePictureTiming(
  85  strmData_t *pStrmData,
  86  seiPicTiming_t *pPicTiming,
  87  u32 cpbRemovalDelayLength,
  88  u32 dpbOutputDelayLength,
  89  u32 timeOffsetLength,
  90  u32 cpbDpbDelaysPresentFlag,
  91  u32 picStructPresentFlag);
  92
  93static u32 DecodePanScanRectangle(
  94  strmData_t *pStrmData,
  95  seiPanScanRect_t *pPanScanRectangle);
  96
  97static u32 DecodeFillerPayload(strmData_t *pStrmData, u32 payloadSize);
  98
  99static u32 DecodeUserDataRegisteredITuTT35(
 100  strmData_t *pStrmData,
 101  seiUserDataRegisteredItuTT35_t *pUserDataRegisteredItuTT35,
 102  u32 payloadSize);
 103
 104static u32 DecodeUserDataUnregistered(
 105  strmData_t *pStrmData,
 106  seiUserDataUnregistered_t *pUserDataUnregistered,
 107  u32 payloadSize);
 108
 109static u32 DecodeRecoveryPoint(
 110  strmData_t *pStrmData,
 111  seiRecoveryPoint_t *pRecoveryPoint);
 112
 113static u32 DecodeDecRefPicMarkingRepetition(
 114  strmData_t *pStrmData,
 115  seiDecRefPicMarkingRepetition_t *pDecRefPicMarkingRepetition,
 116  u32 numRefFrames);
 117
 118static u32 DecodeSparePic(
 119  strmData_t *pStrmData,
 120  seiSparePic_t *pSparePic,
 121  u32 picSizeInMapUnits);
 122
 123static u32 DecodeSceneInfo(
 124  strmData_t *pStrmData,
 125  seiSceneInfo_t *pSceneInfo);
 126
 127static u32 DecodeSubSeqInfo(
 128  strmData_t *pStrmData,
 129  seiSubSeqInfo_t *pSubSeqInfo);
 130
 131static u32 DecodeSubSeqLayerCharacteristics(
 132  strmData_t *pStrmData,
 133  seiSubSeqLayerCharacteristics_t *pSubSeqLayerCharacteristics);
 134
 135static u32 DecodeSubSeqCharacteristics(
 136  strmData_t *pStrmData,
 137  seiSubSeqCharacteristics_t *pSubSeqCharacteristics);
 138
 139static u32 DecodeFullFrameFreeze(
 140  strmData_t *pStrmData,
 141  seiFullFrameFreeze_t *pFullFrameFreeze);
 142
 143static u32 DecodeFullFrameSnapshot(
 144  strmData_t *pStrmData,
 145  seiFullFrameSnapshot_t *pFullFrameSnapshot);
 146
 147static u32 DecodeProgressiveRefinementSegmentStart(
 148  strmData_t *pStrmData,
 149  seiProgressiveRefinementSegmentStart_t *pProgressiveRefinementSegmentStart);
 150
 151static u32 DecodeProgressiveRefinementSegmentEnd(
 152  strmData_t *pStrmData,
 153  seiProgressiveRefinementSegmentEnd_t *pProgressiveRefinementSegmentEnd);
 154
 155static u32 DecodeMotionConstrainedSliceGroupSet(
 156  strmData_t *pStrmData,
 157  seiMotionConstrainedSliceGroupSet_t *pMotionConstrainedSliceGroupSet,
 158  u32 numSliceGroups);
 159
 160static u32 DecodeReservedSeiMessage(
 161  strmData_t *pStrmData,
 162  seiReservedSeiMessage_t *pReservedSeiMessage,
 163  u32 payloadSize);
 164
 165/*------------------------------------------------------------------------------
 166
 167    Function: h264bsdDecodeSeiMessage
 168
 169        Functional description:
 170          <++>
 171        Inputs:
 172          <++>
 173        Outputs:
 174          <++>
 175
 176------------------------------------------------------------------------------*/
 177
 178u32 h264bsdDecodeSeiMessage(
 179  strmData_t *pStrmData,
 180  seqParamSet_t *pSeqParamSet,
 181  seiMessage_t *pSeiMessage,
 182  u32 numSliceGroups)
 183{
 184
 185/* Variables */
 186
 187    u32 tmp, payloadType, payloadSize, status;
 188
 189/* Code */
 190
 191    ASSERT(pStrmData);
 192    ASSERT(pSeiMessage);
 193
 194
 195    H264SwDecMemset(pSeiMessage, 0, sizeof(seiMessage_t));
 196
 197    do
 198    {
 199        payloadType = 0;
 200        while((tmp = h264bsdGetBits(pStrmData, 8)) == 0xFF)
 201        {
 202            payloadType += 255;
 203                    }
 204        if (tmp == END_OF_STREAM)
 205            return(HANTRO_NOK);
 206        payloadType += tmp;
 207
 208        payloadSize = 0;
 209        while((tmp = h264bsdGetBits(pStrmData, 8)) == 0xFF)
 210        {
 211            payloadSize += 255;
 212        }
 213        if (tmp == END_OF_STREAM)
 214            return(HANTRO_NOK);
 215        payloadSize += tmp;
 216
 217        pSeiMessage->payloadType = payloadType;
 218
 219        switch (payloadType)
 220        {
 221            case 0:
 222                ASSERT(pSeqParamSet);
 223                status = DecodeBufferingPeriod(
 224                  pStrmData,
 225                  &pSeiMessage->bufferingPeriod,
 226                  pSeqParamSet->vuiParameters->vclHrdParameters.cpbCnt,
 227                  pSeqParamSet->vuiParameters->vclHrdParameters.
 228                  initialCpbRemovalDelayLength,
 229                  pSeqParamSet->vuiParameters->nalHrdParametersPresentFlag,
 230                  pSeqParamSet->vuiParameters->vclHrdParametersPresentFlag);
 231                break;
 232
 233            case 1:
 234                ASSERT(pSeqParamSet->vuiParametersPresentFlag);
 235                status = DecodePictureTiming(
 236                  pStrmData,
 237                  &pSeiMessage->picTiming,
 238                  pSeqParamSet->vuiParameters->vclHrdParameters.
 239                      cpbRemovalDelayLength,
 240                  pSeqParamSet->vuiParameters->vclHrdParameters.
 241                      dpbOutputDelayLength,
 242                  pSeqParamSet->vuiParameters->vclHrdParameters.
 243                    timeOffsetLength,
 244                  pSeqParamSet->vuiParameters->nalHrdParametersPresentFlag ||
 245                  pSeqParamSet->vuiParameters->vclHrdParametersPresentFlag ?
 246                  HANTRO_TRUE : HANTRO_FALSE,
 247                  pSeqParamSet->vuiParameters->picStructPresentFlag);
 248                break;
 249
 250            case 2:
 251                status = DecodePanScanRectangle(
 252                  pStrmData,
 253                  &pSeiMessage->panScanRect);
 254                break;
 255
 256            case 3:
 257                status = DecodeFillerPayload(pStrmData, payloadSize);
 258                break;
 259
 260            case 4:
 261                status = DecodeUserDataRegisteredITuTT35(
 262                  pStrmData,
 263                  &pSeiMessage->userDataRegisteredItuTT35,
 264                  payloadSize);
 265                break;
 266
 267            case 5:
 268                status = DecodeUserDataUnregistered(
 269                  pStrmData,
 270                  &pSeiMessage->userDataUnregistered,
 271                  payloadSize);
 272                break;
 273
 274            case 6:
 275                status = DecodeRecoveryPoint(
 276                  pStrmData,
 277                  &pSeiMessage->recoveryPoint);
 278                break;
 279
 280            case 7:
 281                status = DecodeDecRefPicMarkingRepetition(
 282                  pStrmData,
 283                  &pSeiMessage->decRefPicMarkingRepetition,
 284                  pSeqParamSet->numRefFrames);
 285                break;
 286
 287            case 8:
 288                ASSERT(pSeqParamSet);
 289                status = DecodeSparePic(
 290                  pStrmData,
 291                  &pSeiMessage->sparePic,
 292                  pSeqParamSet->picWidthInMbs * pSeqParamSet->picHeightInMbs);
 293                break;
 294
 295            case 9:
 296                status = DecodeSceneInfo(
 297                  pStrmData,
 298                  &pSeiMessage->sceneInfo);
 299                break;
 300
 301            case 10:
 302                status = DecodeSubSeqInfo(
 303                  pStrmData,
 304                  &pSeiMessage->subSeqInfo);
 305                break;
 306
 307            case 11:
 308                status = DecodeSubSeqLayerCharacteristics(
 309                  pStrmData,
 310                  &pSeiMessage->subSeqLayerCharacteristics);
 311                break;
 312
 313            case 12:
 314                status = DecodeSubSeqCharacteristics(
 315                  pStrmData,
 316                  &pSeiMessage->subSeqCharacteristics);
 317                break;
 318
 319            case 13:
 320                status = DecodeFullFrameFreeze(
 321                  pStrmData,
 322                  &pSeiMessage->fullFrameFreeze);
 323                break;
 324
 325            case 14: /* This SEI does not contain data, what to do ??? */
 326                status = HANTRO_OK;
 327                break;
 328
 329            case 15:
 330                status = DecodeFullFrameSnapshot(
 331                  pStrmData,
 332                  &pSeiMessage->fullFrameSnapshot);
 333                break;
 334
 335            case 16:
 336                status = DecodeProgressiveRefinementSegmentStart(
 337                  pStrmData,
 338                  &pSeiMessage->progressiveRefinementSegmentStart);
 339                break;
 340
 341            case 17:
 342                status = DecodeProgressiveRefinementSegmentEnd(
 343                  pStrmData,
 344                  &pSeiMessage->progressiveRefinementSegmentEnd);
 345                break;
 346
 347            case 18:
 348                ASSERT(numSliceGroups);
 349                status = DecodeMotionConstrainedSliceGroupSet(
 350                  pStrmData,
 351                  &pSeiMessage->motionConstrainedSliceGroupSet,
 352                  numSliceGroups);
 353                break;
 354
 355            default:
 356                status = DecodeReservedSeiMessage(
 357                  pStrmData,
 358                  &pSeiMessage->reservedSeiMessage,
 359                  payloadSize);
 360                break;
 361        }
 362
 363        if (status != HANTRO_OK)
 364            return(status);
 365
 366        while (!h264bsdIsByteAligned(pStrmData))
 367        {
 368            if (h264bsdGetBits(pStrmData, 1) != 1)
 369                return(HANTRO_NOK);
 370            while (!h264bsdIsByteAligned(pStrmData))
 371            {
 372                if (h264bsdGetBits(pStrmData, 1) != 0)
 373                    return(HANTRO_NOK);
 374            }
 375        }
 376    } while (h264bsdMoreRbspData(pStrmData));
 377
 378    return(h264bsdRbspTrailingBits(pStrmData));
 379
 380}
 381
 382/*------------------------------------------------------------------------------
 383
 384    Function: DecodeBufferingPeriod
 385
 386        Functional description:
 387          <++>
 388        Inputs:
 389          <++>
 390        Outputs:
 391          <++>
 392
 393------------------------------------------------------------------------------*/
 394
 395static u32 DecodeBufferingPeriod(
 396  strmData_t *pStrmData,
 397  seiBufferingPeriod_t *pBufferingPeriod,
 398  u32 cpbCnt,
 399  u32 initialCpbRemovalDelayLength,
 400  u32 nalHrdBpPresentFlag,
 401  u32 vclHrdBpPresentFlag)
 402{
 403
 404/* Variables */
 405
 406    u32 tmp, i;
 407
 408/* Code */
 409
 410    ASSERT(pStrmData);
 411    ASSERT(pBufferingPeriod);
 412    ASSERT(cpbCnt);
 413    ASSERT(initialCpbRemovalDelayLength);
 414
 415
 416    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
 417      &pBufferingPeriod->seqParameterSetId);
 418    if (tmp != HANTRO_OK)
 419        return(tmp);
 420    if (pBufferingPeriod->seqParameterSetId > 31)
 421        return(HANTRO_NOK);
 422
 423    if (nalHrdBpPresentFlag)
 424    {
 425        for (i = 0; i < cpbCnt; i++)
 426        {
 427            tmp = h264bsdGetBits(pStrmData, initialCpbRemovalDelayLength);
 428            if (tmp == END_OF_STREAM)
 429                return(HANTRO_NOK);
 430            if (tmp == 0)
 431                return(HANTRO_NOK);
 432            pBufferingPeriod->initialCpbRemovalDelay[i] = tmp;
 433
 434            tmp = h264bsdGetBits(pStrmData, initialCpbRemovalDelayLength);
 435            if (tmp == END_OF_STREAM)
 436                return(HANTRO_NOK);
 437            pBufferingPeriod->initialCpbRemovalDelayOffset[i] = tmp;
 438        }
 439    }
 440
 441    if (vclHrdBpPresentFlag)
 442    {
 443        for (i = 0; i < cpbCnt; i++)
 444        {
 445            tmp = h264bsdGetBits(pStrmData, initialCpbRemovalDelayLength);
 446            if (tmp == END_OF_STREAM)
 447                return(HANTRO_NOK);
 448            pBufferingPeriod->initialCpbRemovalDelay[i] = tmp;
 449
 450            tmp = h264bsdGetBits(pStrmData, initialCpbRemovalDelayLength);
 451            if (tmp == END_OF_STREAM)
 452                return(HANTRO_NOK);
 453            pBufferingPeriod->initialCpbRemovalDelayOffset[i] = tmp;
 454        }
 455    }
 456
 457    return(HANTRO_OK);
 458
 459}
 460
 461/*------------------------------------------------------------------------------
 462
 463    Function: DecodePictureTiming
 464
 465        Functional description:
 466          <++>
 467        Inputs:
 468          <++>
 469        Outputs:
 470          <++>
 471
 472------------------------------------------------------------------------------*/
 473
 474static u32 DecodePictureTiming(
 475  strmData_t *pStrmData,
 476  seiPicTiming_t *pPicTiming,
 477  u32 cpbRemovalDelayLength,
 478  u32 dpbOutputDelayLength,
 479  u32 timeOffsetLength,
 480  u32 cpbDpbDelaysPresentFlag,
 481  u32 picStructPresentFlag)
 482{
 483
 484/* Variables */
 485
 486    u32 tmp, i;
 487    i32 itmp;
 488
 489/* Code */
 490
 491    ASSERT(pStrmData);
 492    ASSERT(pPicTiming);
 493
 494
 495    if (cpbDpbDelaysPresentFlag)
 496    {
 497        tmp = h264bsdGetBits(pStrmData, cpbRemovalDelayLength);
 498        if (tmp == END_OF_STREAM)
 499            return(HANTRO_NOK);
 500        pPicTiming->cpbRemovalDelay = tmp;
 501
 502        tmp = h264bsdGetBits(pStrmData, dpbOutputDelayLength);
 503        if (tmp == END_OF_STREAM)
 504            return(HANTRO_NOK);
 505        pPicTiming->dpbOutputDelay = tmp;
 506    }
 507
 508    if (picStructPresentFlag)
 509    {
 510        tmp = h264bsdGetBits(pStrmData, 4);
 511        if (tmp == END_OF_STREAM)
 512            return(HANTRO_NOK);
 513        if (tmp > 8)
 514            return(HANTRO_NOK);
 515        pPicTiming->picStruct = tmp;
 516
 517        for (i = 0; i < numClockTS[pPicTiming->picStruct]; i++)
 518        {
 519            tmp = h264bsdGetBits(pStrmData, 1);
 520            if (tmp == END_OF_STREAM)
 521                return(HANTRO_NOK);
 522            pPicTiming->clockTimeStampFlag[i] = tmp == 1 ?
 523                                    HANTRO_TRUE : HANTRO_FALSE;
 524
 525            if (pPicTiming->clockTimeStampFlag[i])
 526            {
 527                tmp = h264bsdGetBits(pStrmData, 2);
 528                if (tmp == END_OF_STREAM)
 529                    return(HANTRO_NOK);
 530                pPicTiming->ctType[i] = tmp;
 531
 532                tmp = h264bsdGetBits(pStrmData, 1);
 533                if (tmp == END_OF_STREAM)
 534                    return(HANTRO_NOK);
 535                pPicTiming->nuitFieldBasedFlag[i] = tmp == 1 ?
 536                                    HANTRO_TRUE : HANTRO_FALSE;
 537
 538                tmp = h264bsdGetBits(pStrmData, 5);
 539                if (tmp == END_OF_STREAM)
 540                    return(HANTRO_NOK);
 541                if (tmp > 6)
 542                    return(HANTRO_NOK);
 543                pPicTiming->countingType[i] = tmp;
 544
 545                tmp = h264bsdGetBits(pStrmData, 1);
 546                if (tmp == END_OF_STREAM)
 547                    return(HANTRO_NOK);
 548                pPicTiming->fullTimeStampFlag[i] = tmp == 1 ?
 549                                    HANTRO_TRUE : HANTRO_FALSE;
 550
 551                tmp = h264bsdGetBits(pStrmData, 1);
 552                if (tmp == END_OF_STREAM)
 553                    return(HANTRO_NOK);
 554                pPicTiming->discontinuityFlag[i] = tmp == 1 ?
 555                                    HANTRO_TRUE : HANTRO_FALSE;
 556
 557                tmp = h264bsdGetBits(pStrmData, 1);
 558                if (tmp == END_OF_STREAM)
 559                    return(HANTRO_NOK);
 560                pPicTiming->cntDroppedFlag[i] = tmp == 1 ?
 561                                    HANTRO_TRUE : HANTRO_FALSE;
 562
 563                tmp = h264bsdGetBits(pStrmData, 8);
 564                if (tmp == END_OF_STREAM)
 565                    return(HANTRO_NOK);
 566                pPicTiming->nFrames[i] = tmp;
 567
 568                if (pPicTiming->fullTimeStampFlag[i])
 569                {
 570                    tmp = h264bsdGetBits(pStrmData, 6);
 571                    if (tmp == END_OF_STREAM)
 572                        return(HANTRO_NOK);
 573                    if (tmp > 59)
 574                        return(HANTRO_NOK);
 575                    pPicTiming->secondsValue[i] = tmp;
 576
 577                    tmp = h264bsdGetBits(pStrmData, 6);
 578                    if (tmp == END_OF_STREAM)
 579                        return(HANTRO_NOK);
 580                    if (tmp > 59)
 581                        return(HANTRO_NOK);
 582                    pPicTiming->minutesValue[i] = tmp;
 583
 584                    tmp = h264bsdGetBits(pStrmData, 5);
 585                    if (tmp == END_OF_STREAM)
 586                        return(HANTRO_NOK);
 587                    if (tmp > 23)
 588                        return(HANTRO_NOK);
 589                    pPicTiming->hoursValue[i] = tmp;
 590                }
 591                else
 592                {
 593                    tmp = h264bsdGetBits(pStrmData, 1);
 594                    if (tmp == END_OF_STREAM)
 595                        return(HANTRO_NOK);
 596                    pPicTiming->secondsFlag[i] = tmp == 1 ?
 597                                    HANTRO_TRUE : HANTRO_FALSE;
 598
 599                    if (pPicTiming->secondsFlag[i])
 600                    {
 601                        tmp = h264bsdGetBits(pStrmData, 6);
 602                        if (tmp == END_OF_STREAM)
 603                            return(HANTRO_NOK);
 604                        if (tmp > 59)
 605                            return(HANTRO_NOK);
 606                        pPicTiming->secondsValue[i] = tmp;
 607
 608                        tmp = h264bsdGetBits(pStrmData, 1);
 609                        if (tmp == END_OF_STREAM)
 610                            return(HANTRO_NOK);
 611                        pPicTiming->minutesFlag[i] = tmp == 1 ?
 612                                    HANTRO_TRUE : HANTRO_FALSE;
 613
 614                        if (pPicTiming->minutesFlag[i])
 615                        {
 616                            tmp = h264bsdGetBits(pStrmData, 6);
 617                            if (tmp == END_OF_STREAM)
 618                                return(HANTRO_NOK);
 619                            if (tmp > 59)
 620                                return(HANTRO_NOK);
 621                            pPicTiming->minutesValue[i] = tmp;
 622
 623                            tmp = h264bsdGetBits(pStrmData, 1);
 624                            if (tmp == END_OF_STREAM)
 625                                return(HANTRO_NOK);
 626                            pPicTiming->hoursFlag[i] = tmp == 1 ?
 627                                    HANTRO_TRUE : HANTRO_FALSE;
 628
 629                            if (pPicTiming->hoursFlag[i])
 630                            {
 631                                tmp = h264bsdGetBits(pStrmData, 5);
 632                                if (tmp == END_OF_STREAM)
 633                                    return(HANTRO_NOK);
 634                                if (tmp > 23)
 635                                    return(HANTRO_NOK);
 636                                pPicTiming->hoursValue[i] = tmp;
 637                            }
 638                        }
 639                    }
 640                }
 641                if (timeOffsetLength)
 642                {
 643                    tmp = h264bsdGetBits(pStrmData, timeOffsetLength);
 644                    if (tmp == END_OF_STREAM)
 645                        return(HANTRO_NOK);
 646                    itmp = (i32)tmp;
 647                    /* following "converts" timeOffsetLength-bit signed
 648                     * integer into i32 */
 649                    /*lint -save -e701 -e702 */
 650                    itmp <<= (32 - timeOffsetLength);
 651                    itmp >>= (32 - timeOffsetLength);
 652                    /*lint -restore */
 653                    pPicTiming->timeOffset[i] = itmp;
 654                                    }
 655                else
 656                    pPicTiming->timeOffset[i] = 0;
 657            }
 658        }
 659    }
 660
 661    return(HANTRO_OK);
 662
 663}
 664
 665/*------------------------------------------------------------------------------
 666
 667    Function: DecodePanScanRectangle
 668
 669        Functional description:
 670          <++>
 671        Inputs:
 672          <++>
 673        Outputs:
 674          <++>
 675
 676------------------------------------------------------------------------------*/
 677
 678static u32 DecodePanScanRectangle(
 679  strmData_t *pStrmData,
 680  seiPanScanRect_t *pPanScanRectangle)
 681{
 682
 683/* Variables */
 684
 685    u32 tmp, i;
 686
 687/* Code */
 688
 689    ASSERT(pStrmData);
 690    ASSERT(pPanScanRectangle);
 691
 692
 693    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
 694      &pPanScanRectangle->panScanRectId);
 695    if (tmp != HANTRO_OK)
 696        return(tmp);
 697
 698    tmp = h264bsdGetBits(pStrmData, 1);
 699    if (tmp == END_OF_STREAM)
 700        return(HANTRO_NOK);
 701    pPanScanRectangle->panScanRectCancelFlag = tmp == 1 ?
 702                                HANTRO_TRUE : HANTRO_FALSE;
 703
 704    if (!pPanScanRectangle->panScanRectCancelFlag)
 705    {
 706        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
 707          &pPanScanRectangle->panScanCnt);
 708        if (tmp != HANTRO_OK)
 709            return(tmp);
 710        if (pPanScanRectangle->panScanCnt > 2)
 711            return(HANTRO_NOK);
 712        pPanScanRectangle->panScanCnt++;
 713
 714        for (i = 0; i < pPanScanRectangle->panScanCnt; i++)
 715        {
 716            tmp = h264bsdDecodeExpGolombSigned(pStrmData,
 717              &pPanScanRectangle->panScanRectLeftOffset[i]);
 718            if (tmp != HANTRO_OK)
 719                return(tmp);
 720
 721            tmp = h264bsdDecodeExpGolombSigned(pStrmData,
 722              &pPanScanRectangle->panScanRectRightOffset[i]);
 723            if (tmp != HANTRO_OK)
 724                return(tmp);
 725
 726            tmp = h264bsdDecodeExpGolombSigned(pStrmData,
 727              &pPanScanRectangle->panScanRectTopOffset[i]);
 728            if (tmp != HANTRO_OK)
 729                return(tmp);
 730
 731            tmp = h264bsdDecodeExpGolombSigned(pStrmData,
 732              &pPanScanRectangle->panScanRectBottomOffset[i]);
 733            if (tmp != HANTRO_OK)
 734                return(tmp);
 735        }
 736        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
 737          &pPanScanRectangle->panScanRectRepetitionPeriod);
 738        if (tmp != HANTRO_OK)
 739            return(tmp);
 740        if (pPanScanRectangle->panScanRectRepetitionPeriod > 16384)
 741            return(HANTRO_NOK);
 742        if (pPanScanRectangle->panScanCnt > 1 &&
 743          pPanScanRectangle->panScanRectRepetitionPeriod > 1)
 744            return(HANTRO_NOK);
 745    }
 746
 747    return(HANTRO_OK);
 748}
 749
 750/*------------------------------------------------------------------------------
 751
 752    Function: DecodeFillerPayload
 753
 754        Functional description:
 755          <++>
 756        Inputs:
 757          <++>
 758        Outputs:
 759          <++>
 760
 761------------------------------------------------------------------------------*/
 762
 763static u32 DecodeFillerPayload(strmData_t *pStrmData, u32 payloadSize)
 764{
 765
 766/* Variables */
 767
 768/* Code */
 769
 770    ASSERT(pStrmData);
 771
 772
 773    if (payloadSize)
 774        if (h264bsdFlushBits(pStrmData, 8 * payloadSize) == END_OF_STREAM)
 775            return(HANTRO_NOK);
 776
 777    return(HANTRO_OK);
 778
 779}
 780
 781/*------------------------------------------------------------------------------
 782
 783    Function: DecodeUserDataRegisteredITuTT35
 784
 785        Functional description:
 786          <++>
 787        Inputs:
 788          <++>
 789        Outputs:
 790          <++>
 791
 792------------------------------------------------------------------------------*/
 793
 794static u32 DecodeUserDataRegisteredITuTT35(
 795  strmData_t *pStrmData,
 796  seiUserDataRegisteredItuTT35_t *pUserDataRegisteredItuTT35,
 797  u32 payloadSize)
 798{
 799
 800/* Variables */
 801
 802    u32 tmp, i, j;
 803
 804/* Code */
 805
 806    ASSERT(pStrmData);
 807    ASSERT(pUserDataRegisteredItuTT35);
 808    ASSERT(payloadSize);
 809
 810        tmp = h264bsdGetBits(pStrmData, 8);
 811    if (tmp == END_OF_STREAM)
 812        return(HANTRO_NOK);
 813    pUserDataRegisteredItuTT35->ituTT35CountryCode = tmp;
 814
 815    if (pUserDataRegisteredItuTT35->ituTT35CountryCode != 0xFF)
 816        i = 1;
 817    else
 818    {
 819        tmp = h264bsdGetBits(pStrmData, 8);
 820        if (tmp == END_OF_STREAM)
 821            return(HANTRO_NOK);
 822        pUserDataRegisteredItuTT35->ituTT35CountryCodeExtensionByte = tmp;
 823        i = 2;
 824    }
 825
 826    /* where corresponding FREE() ??? */
 827    ALLOCATE(pUserDataRegisteredItuTT35->ituTT35PayloadByte,payloadSize-i,u8);
 828    pUserDataRegisteredItuTT35->numPayloadBytes = payloadSize - i;
 829    if (pUserDataRegisteredItuTT35->ituTT35PayloadByte == NULL)
 830        return(MEMORY_ALLOCATION_ERROR);
 831
 832    j = 0;
 833    do
 834    {
 835        tmp = h264bsdGetBits(pStrmData, 8);
 836        if (tmp == END_OF_STREAM)
 837            return(HANTRO_NOK);
 838        pUserDataRegisteredItuTT35->ituTT35PayloadByte[j] = (u8)tmp;
 839        i++;
 840        j++;
 841    } while (i < payloadSize);
 842
 843    return(HANTRO_OK);
 844
 845}
 846
 847/*------------------------------------------------------------------------------
 848
 849    Function: DecodeUserDataUnregistered
 850
 851        Functional description:
 852          <++>
 853        Inputs:
 854          <++>
 855        Outputs:
 856          <++>
 857
 858------------------------------------------------------------------------------*/
 859
 860static u32 DecodeUserDataUnregistered(
 861  strmData_t *pStrmData,
 862  seiUserDataUnregistered_t *pUserDataUnregistered,
 863  u32 payloadSize)
 864{
 865
 866/* Variables */
 867
 868    u32 i, tmp;
 869
 870/* Code */
 871
 872    ASSERT(pStrmData);
 873    ASSERT(pUserDataUnregistered);
 874
 875
 876    for (i = 0; i < 4; i++)
 877    {
 878        pUserDataUnregistered->uuidIsoIec11578[i] = h264bsdShowBits32(pStrmData);
 879        if (h264bsdFlushBits(pStrmData,32) == END_OF_STREAM)
 880            return(HANTRO_NOK);
 881    }
 882
 883    /* where corresponding FREE() ??? */
 884    ALLOCATE(pUserDataUnregistered->userDataPayloadByte, payloadSize - 16, u8);
 885    if (pUserDataUnregistered->userDataPayloadByte == NULL)
 886        return(MEMORY_ALLOCATION_ERROR);
 887
 888    pUserDataUnregistered->numPayloadBytes = payloadSize - 16;
 889
 890    for (i = 0; i < payloadSize - 16; i++)
 891    {
 892        tmp = h264bsdGetBits(pStrmData, 8);
 893        if (tmp == END_OF_STREAM)
 894            return(HANTRO_NOK);
 895        pUserDataUnregistered->userDataPayloadByte[i] = (u8)tmp;
 896    }
 897
 898    return(HANTRO_OK);
 899
 900}
 901
 902/*------------------------------------------------------------------------------
 903
 904    Function: DecodeRecoveryPoint
 905
 906        Functional description:
 907          <++>
 908        Inputs:
 909          <++>
 910        Outputs:
 911          <++>
 912
 913------------------------------------------------------------------------------*/
 914
 915static u32 DecodeRecoveryPoint(
 916  strmData_t *pStrmData,
 917  seiRecoveryPoint_t *pRecoveryPoint)
 918{
 919
 920/* Variables */
 921
 922    u32 tmp;
 923
 924/* Code */
 925
 926    ASSERT(pStrmData);
 927    ASSERT(pRecoveryPoint);
 928
 929
 930    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
 931        &pRecoveryPoint->recoveryFrameCnt);
 932    if (tmp != HANTRO_OK)
 933        return(tmp);
 934
 935    tmp = h264bsdGetBits(pStrmData, 1);
 936    if (tmp == END_OF_STREAM)
 937        return(HANTRO_NOK);
 938    pRecoveryPoint->exactMatchFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
 939
 940    tmp = h264bsdGetBits(pStrmData, 1);
 941    if (tmp == END_OF_STREAM)
 942        return(HANTRO_NOK);
 943    pRecoveryPoint->brokenLinkFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
 944
 945    tmp = h264bsdGetBits(pStrmData, 2);
 946    if (tmp == END_OF_STREAM)
 947        return(HANTRO_NOK);
 948    if (tmp > 2)
 949        return(HANTRO_NOK);
 950    pRecoveryPoint->changingSliceGroupIdc = tmp;
 951
 952    return(HANTRO_OK);
 953
 954}
 955
 956/*------------------------------------------------------------------------------
 957
 958    Function: DecodeDecRefPicMarkingRepetition
 959
 960        Functional description:
 961          <++>
 962        Inputs:
 963          <++>
 964        Outputs:
 965          <++>
 966
 967------------------------------------------------------------------------------*/
 968
 969static u32 DecodeDecRefPicMarkingRepetition(
 970  strmData_t *pStrmData,
 971  seiDecRefPicMarkingRepetition_t *pDecRefPicMarkingRepetition,
 972  u32 numRefFrames)
 973{
 974
 975/* Variables */
 976
 977    u32 tmp;
 978
 979/* Code */
 980
 981    ASSERT(pStrmData);
 982    ASSERT(pDecRefPicMarkingRepetition);
 983
 984
 985    tmp = h264bsdGetBits(pStrmData, 1);
 986    if (tmp == END_OF_STREAM)
 987        return(HANTRO_NOK);
 988    pDecRefPicMarkingRepetition->originalIdrFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
 989
 990    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
 991      &pDecRefPicMarkingRepetition->originalFrameNum);
 992    if (tmp != HANTRO_OK)
 993        return(tmp);
 994
 995    /* frame_mbs_only_flag assumed always true so some field related syntax
 996     * elements are skipped, see H.264 standard */
 997    // tmp = h264bsdDecRefPicMarking(pStrmData,
 998    //  &pDecRefPicMarkingRepetition->decRefPicMarking, NAL_SEI, numRefFrames);
 999    return(HANTRO_NOK);
1000
1001    return(tmp);
1002
1003}
1004
1005/*------------------------------------------------------------------------------
1006
1007    Function: DecodeSparePic
1008
1009        Functional description:
1010          <++>
1011        Inputs:
1012          <++>
1013        Outputs:
1014          <++>
1015
1016------------------------------------------------------------------------------*/
1017
1018static u32 DecodeSparePic(
1019  strmData_t *pStrmData,
1020  seiSparePic_t *pSparePic,
1021  u32 picSizeInMapUnits)
1022{
1023
1024/* Variables */
1025
1026    u32 tmp, i, j, mapUnitCnt;
1027
1028/* Code */
1029
1030    ASSERT(pStrmData);
1031    ASSERT(pSparePic);
1032
1033
1034    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1035        &pSparePic->targetFrameNum);
1036    if (tmp != HANTRO_OK)
1037        return(tmp);
1038
1039    tmp = h264bsdGetBits(pStrmData, 1);
1040    if (tmp == END_OF_STREAM)
1041        return(HANTRO_NOK);
1042    pSparePic->spareFieldFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1043    /* do not accept fields */
1044    if (pSparePic->spareFieldFlag)
1045        return(HANTRO_NOK);
1046
1047    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSparePic->numSparePics);
1048    if (tmp != HANTRO_OK)
1049        return(tmp);
1050    pSparePic->numSparePics++;
1051    if (pSparePic->numSparePics > MAX_NUM_SPARE_PICS)
1052        return(HANTRO_NOK);
1053
1054    for (i = 0; i < pSparePic->numSparePics; i++)
1055    {
1056        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1057          &pSparePic->deltaSpareFrameNum[i]);
1058        if (tmp != HANTRO_OK)
1059            return(tmp);
1060
1061        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1062            &pSparePic->spareAreaIdc[i]);
1063        if (tmp != HANTRO_OK)
1064            return(tmp);
1065        if (pSparePic->spareAreaIdc[i] > 2)
1066            return(HANTRO_NOK);
1067
1068        if (pSparePic->spareAreaIdc[i] == 1)
1069        {
1070            /* where corresponding FREE() ??? */
1071            ALLOCATE(pSparePic->spareUnitFlag[i], picSizeInMapUnits, u32);
1072            if (pSparePic->spareUnitFlag[i] == NULL)
1073                return(MEMORY_ALLOCATION_ERROR);
1074            pSparePic->zeroRunLength[i] = NULL;
1075
1076            for (j = 0; j < picSizeInMapUnits; j++)
1077            {
1078                tmp = h264bsdGetBits(pStrmData, 1);
1079                if (tmp == END_OF_STREAM)
1080                    return(HANTRO_NOK);
1081                pSparePic->spareUnitFlag[i][j] = tmp == 1 ?
1082                                    HANTRO_TRUE : HANTRO_FALSE;
1083            }
1084        }
1085        else if (pSparePic->spareAreaIdc[i] == 2)
1086        {
1087            /* where corresponding FREE() ??? */
1088            ALLOCATE(pSparePic->zeroRunLength[i], picSizeInMapUnits, u32);
1089            if (pSparePic->zeroRunLength[i] == NULL)
1090                return(MEMORY_ALLOCATION_ERROR);
1091            pSparePic->spareUnitFlag[i] = NULL;
1092
1093            for (j = 0, mapUnitCnt = 0; mapUnitCnt < picSizeInMapUnits; j++)
1094            {
1095                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1096                  &pSparePic->zeroRunLength[i][j]);
1097                if (tmp != HANTRO_OK)
1098                    return(tmp);
1099                mapUnitCnt += pSparePic->zeroRunLength[i][j] + 1;
1100            }
1101        }
1102    }
1103
1104    /* set rest to null */
1105    for (i = pSparePic->numSparePics; i < MAX_NUM_SPARE_PICS; i++)
1106    {
1107        pSparePic->spareUnitFlag[i] = NULL;
1108        pSparePic->zeroRunLength[i] = NULL;
1109    }
1110
1111    return(HANTRO_OK);
1112
1113}
1114
1115/*------------------------------------------------------------------------------
1116
1117    Function: DecodeSceneInfo
1118
1119        Functional description:
1120          <++>
1121        Inputs:
1122          <++>
1123        Outputs:
1124          <++>
1125
1126------------------------------------------------------------------------------*/
1127
1128static u32 DecodeSceneInfo(
1129  strmData_t *pStrmData,
1130  seiSceneInfo_t *pSceneInfo)
1131{
1132
1133/* Variables */
1134
1135    u32 tmp;
1136
1137/* Code */
1138
1139    ASSERT(pStrmData);
1140    ASSERT(pSceneInfo);
1141
1142
1143    tmp = h264bsdGetBits(pStrmData, 1);
1144    if (tmp == END_OF_STREAM)
1145        return(HANTRO_NOK);
1146    pSceneInfo->sceneInfoPresentFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1147
1148    if (pSceneInfo->sceneInfoPresentFlag)
1149    {
1150        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSceneInfo->sceneId);
1151        if (tmp != HANTRO_OK)
1152            return(tmp);
1153
1154        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1155          &pSceneInfo->sceneTransitionType);
1156        if (tmp != HANTRO_OK)
1157            return(tmp);
1158        if (pSceneInfo->sceneTransitionType > 6)
1159            return(HANTRO_NOK);
1160
1161        if (pSceneInfo->sceneTransitionType)
1162        {
1163            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1164              &pSceneInfo->secondSceneId);
1165            if (tmp != HANTRO_OK)
1166                return(tmp);
1167        }
1168
1169    }
1170
1171    return(HANTRO_OK);
1172
1173}
1174
1175/*------------------------------------------------------------------------------
1176
1177    Function: DecodeSubSeqInfo
1178
1179        Functional description:
1180          <++>
1181        Inputs:
1182          <++>
1183        Outputs:
1184          <++>
1185
1186-----------------------------------------------------------------------------*/
1187
1188static u32 DecodeSubSeqInfo(
1189  strmData_t *pStrmData,
1190  seiSubSeqInfo_t *pSubSeqInfo)
1191{
1192
1193/* Variables */
1194
1195    u32 tmp;
1196
1197/* Code */
1198
1199    ASSERT(pStrmData);
1200    ASSERT(pSubSeqInfo);
1201
1202
1203    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1204        &pSubSeqInfo->subSeqLayerNum);
1205    if (tmp != HANTRO_OK)
1206        return(tmp);
1207    if (pSubSeqInfo->subSeqLayerNum > 255)
1208        return(HANTRO_NOK);
1209
1210    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSubSeqInfo->subSeqId);
1211    if (tmp != HANTRO_OK)
1212        return(tmp);
1213    if (pSubSeqInfo->subSeqId > 65535)
1214        return(HANTRO_NOK);
1215
1216    tmp = h264bsdGetBits(pStrmData, 1);
1217    if (tmp == END_OF_STREAM)
1218        return(HANTRO_NOK);
1219    pSubSeqInfo->firstRefPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1220
1221    tmp = h264bsdGetBits(pStrmData, 1);
1222    if (tmp == END_OF_STREAM)
1223        return(HANTRO_NOK);
1224    pSubSeqInfo->leadingNonRefPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1225
1226    tmp = h264bsdGetBits(pStrmData, 1);
1227    if (tmp == END_OF_STREAM)
1228        return(HANTRO_NOK);
1229    pSubSeqInfo->lastPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1230
1231    tmp = h264bsdGetBits(pStrmData, 1);
1232    if (tmp == END_OF_STREAM)
1233        return(HANTRO_NOK);
1234    pSubSeqInfo->subSeqFrameNumFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1235
1236    if (pSubSeqInfo->subSeqFrameNumFlag)
1237    {
1238        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1239            &pSubSeqInfo->subSeqFrameNum);
1240        if (tmp != HANTRO_OK)
1241            return(tmp);
1242    }
1243
1244    return(HANTRO_OK);
1245
1246}
1247
1248/*------------------------------------------------------------------------------
1249
1250    Function: DecodeSubSeqLayerCharacteristics
1251
1252        Functional description:
1253          <++>
1254        Inputs:
1255          <++>
1256        Outputs:
1257          <++>
1258
1259------------------------------------------------------------------------------*/
1260
1261static u32 DecodeSubSeqLayerCharacteristics(
1262  strmData_t *pStrmData,
1263  seiSubSeqLayerCharacteristics_t *pSubSeqLayerCharacteristics)
1264{
1265
1266/* Variables */
1267
1268    u32 tmp, i;
1269
1270/* Code */
1271
1272    ASSERT(pStrmData);
1273    ASSERT(pSubSeqLayerCharacteristics);
1274
1275
1276    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1277      &pSubSeqLayerCharacteristics->numSubSeqLayers);
1278    if (tmp != HANTRO_OK)
1279        return(tmp);
1280    pSubSeqLayerCharacteristics->numSubSeqLayers++;
1281    if (pSubSeqLayerCharacteristics->numSubSeqLayers > MAX_NUM_SUB_SEQ_LAYERS)
1282        return(HANTRO_NOK);
1283
1284    for (i = 0; i < pSubSeqLayerCharacteristics->numSubSeqLayers; i++)
1285    {
1286        tmp = h264bsdGetBits(pStrmData, 1);
1287        if (tmp == END_OF_STREAM)
1288            return(HANTRO_NOK);
1289        pSubSeqLayerCharacteristics->accurateStatisticsFlag[i] =
1290            tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1291
1292        tmp = h264bsdGetBits(pStrmData, 16);
1293        if (tmp == END_OF_STREAM)
1294            return(HANTRO_NOK);
1295        pSubSeqLayerCharacteristics->averageBitRate[i] = tmp;
1296
1297        tmp = h264bsdGetBits(pStrmData, 16);
1298        if (tmp == END_OF_STREAM)
1299            return(HANTRO_NOK);
1300        pSubSeqLayerCharacteristics->averageFrameRate[i] = tmp;
1301    }
1302
1303    return(HANTRO_OK);
1304
1305}
1306
1307/*------------------------------------------------------------------------------
1308
1309    Function: DecodeSubSeqCharacteristics
1310
1311        Functional description:
1312          <++>
1313        Inputs:
1314          <++>
1315        Outputs:
1316          <++>
1317
1318------------------------------------------------------------------------------*/
1319
1320static u32 DecodeSubSeqCharacteristics(
1321  strmData_t *pStrmData,
1322  seiSubSeqCharacteristics_t *pSubSeqCharacteristics)
1323{
1324
1325/* Variables */
1326
1327    u32 tmp, i;
1328
1329/* Code */
1330
1331    ASSERT(pStrmData);
1332    ASSERT(pSubSeqCharacteristics);
1333
1334
1335    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1336      &pSubSeqCharacteristics->subSeqLayerNum);
1337    if (tmp != HANTRO_OK)
1338        return(tmp);
1339    if (pSubSeqCharacteristics->subSeqLayerNum > MAX_NUM_SUB_SEQ_LAYERS-1)
1340        return(HANTRO_NOK);
1341
1342    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1343        &pSubSeqCharacteristics->subSeqId);
1344    if (tmp != HANTRO_OK)
1345        return(tmp);
1346    if (pSubSeqCharacteristics->subSeqId > 65535)
1347        return(HANTRO_NOK);
1348
1349    tmp = h264bsdGetBits(pStrmData, 1);
1350    if (tmp == END_OF_STREAM)
1351        return(HANTRO_NOK);
1352    pSubSeqCharacteristics->durationFlag = tmp == 1 ?
1353                            HANTRO_TRUE : HANTRO_FALSE;
1354
1355    if (pSubSeqCharacteristics->durationFlag)
1356    {
1357        pSubSeqCharacteristics->subSeqDuration = h264bsdShowBits32(pStrmData);
1358        if (h264bsdFlushBits(pStrmData,32) == END_OF_STREAM)
1359            return(HANTRO_NOK);
1360    }
1361
1362    tmp = h264bsdGetBits(pStrmData, 1);
1363    if (tmp == END_OF_STREAM)
1364        return(HANTRO_NOK);
1365    pSubSeqCharacteristics->averageRateFlag = tmp == 1 ?
1366                            HANTRO_TRUE : HANTRO_FALSE;
1367
1368    if (pSubSeqCharacteristics->averageRateFlag)
1369    {
1370        tmp = h264bsdGetBits(pStrmData, 1);
1371        if (tmp == END_OF_STREAM)
1372            return(HANTRO_NOK);
1373        pSubSeqCharacteristics->accurateStatisticsFlag =
1374            tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1375
1376        tmp = h264bsdGetBits(pStrmData, 16);
1377        if (tmp == END_OF_STREAM)
1378            return(HANTRO_NOK);
1379        pSubSeqCharacteristics->averageBitRate = tmp;
1380
1381        tmp = h264bsdGetBits(pStrmData, 16);
1382        if (tmp == END_OF_STREAM)
1383            return(HANTRO_NOK);
1384        pSubSeqCharacteristics->averageFrameRate = tmp;
1385    }
1386
1387    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1388      &pSubSeqCharacteristics->numReferencedSubseqs);
1389    if (tmp != HANTRO_OK)
1390        return(tmp);
1391    if (pSubSeqCharacteristics->numReferencedSubseqs > MAX_NUM_SUB_SEQ_LAYERS-1)
1392        return(HANTRO_NOK);
1393
1394    for (i = 0; i < pSubSeqCharacteristics->numReferencedSubseqs; i++)
1395    {
1396        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1397          &pSubSeqCharacteristics->refSubSeqLayerNum[i]);
1398        if (tmp != HANTRO_OK)
1399            return(tmp);
1400
1401        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1402          &pSubSeqCharacteristics->refSubSeqId[i]);
1403        if (tmp != HANTRO_OK)
1404            return(tmp);
1405
1406        tmp = h264bsdGetBits(pStrmData, 1);
1407        if (tmp == END_OF_STREAM)
1408            return(HANTRO_NOK);
1409        pSubSeqCharacteristics->refSubSeqDirection[i] = tmp;
1410    }
1411
1412    return(HANTRO_OK);
1413
1414}
1415
1416/*------------------------------------------------------------------------------
1417
1418    Function: DecodeFullFrameFreeze
1419
1420        Functional description:
1421          <++>
1422        Inputs:
1423          <++>
1424        Outputs:
1425          <++>
1426
1427------------------------------------------------------------------------------*/
1428
1429static u32 DecodeFullFrameFreeze(
1430  strmData_t *pStrmData,
1431  seiFullFrameFreeze_t *pFullFrameFreeze)
1432{
1433
1434/* Variables */
1435
1436    u32 tmp;
1437
1438/* Code */
1439
1440    ASSERT(pStrmData);
1441    ASSERT(pFullFrameFreeze);
1442
1443
1444    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1445      &pFullFrameFreeze->fullFrameFreezeRepetitionPeriod);
1446    if (tmp != HANTRO_OK)
1447        return(tmp);
1448    if (pFullFrameFreeze->fullFrameFreezeRepetitionPeriod > 16384)
1449        return(HANTRO_NOK);
1450
1451    return(HANTRO_OK);
1452
1453}
1454
1455/*------------------------------------------------------------------------------
1456
1457    Function: DecodeFullFrameSnapshot
1458
1459        Functional description:
1460          <++>
1461        Inputs:
1462          <++>
1463        Outputs:
1464          <++>
1465
1466------------------------------------------------------------------------------*/
1467
1468static u32 DecodeFullFrameSnapshot(
1469  strmData_t *pStrmData,
1470  seiFullFrameSnapshot_t *pFullFrameSnapshot)
1471{
1472
1473/* Variables */
1474
1475    u32 tmp;
1476
1477/* Code */
1478
1479    ASSERT(pStrmData);
1480    ASSERT(pFullFrameSnapshot);
1481
1482
1483    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1484        &pFullFrameSnapshot->snapShotId);
1485    if (tmp != HANTRO_OK)
1486        return(tmp);
1487
1488    return(HANTRO_OK);
1489
1490}
1491
1492/*------------------------------------------------------------------------------
1493
1494    Function: DecodeProgressiveRefinementSegmentStart
1495
1496        Functional description:
1497          <++>
1498        Inputs:
1499          <++>
1500        Outputs:
1501          <++>
1502
1503------------------------------------------------------------------------------*/
1504
1505static u32 DecodeProgressiveRefinementSegmentStart(
1506  strmData_t *pStrmData,
1507  seiProgressiveRefinementSegmentStart_t *pProgressiveRefinementSegmentStart)
1508{
1509
1510/* Variables */
1511
1512    u32 tmp;
1513
1514/* Code */
1515
1516    ASSERT(pStrmData);
1517    ASSERT(pProgressiveRefinementSegmentStart);
1518
1519
1520    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1521      &pProgressiveRefinementSegmentStart->progressiveRefinementId);
1522    if (tmp != HANTRO_OK)
1523        return(tmp);
1524
1525    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1526      &pProgressiveRefinementSegmentStart->numRefinementSteps);
1527    if (tmp != HANTRO_OK)
1528        return(tmp);
1529    pProgressiveRefinementSegmentStart->numRefinementSteps++;
1530
1531    return(HANTRO_OK);
1532
1533}
1534
1535/*------------------------------------------------------------------------------
1536
1537    Function: DecodeProgressiveRefinementSegmentEnd
1538
1539        Functional description:
1540          <++>
1541        Inputs:
1542          <++>
1543        Outputs:
1544          <++>
1545
1546------------------------------------------------------------------------------*/
1547
1548static u32 DecodeProgressiveRefinementSegmentEnd(
1549  strmData_t *pStrmData,
1550  seiProgressiveRefinementSegmentEnd_t *pProgressiveRefinementSegmentEnd)
1551{
1552
1553/* Variables */
1554
1555    u32 tmp;
1556
1557/* Code */
1558
1559    ASSERT(pStrmData);
1560    ASSERT(pProgressiveRefinementSegmentEnd);
1561
1562
1563    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1564      &pProgressiveRefinementSegmentEnd->progressiveRefinementId);
1565    if (tmp != HANTRO_OK)
1566        return(tmp);
1567
1568    return(HANTRO_OK);
1569
1570}
1571
1572/*------------------------------------------------------------------------------
1573
1574    Function: DecodeMotionConstrainedSliceGroupSet
1575
1576        Functional description:
1577          <++>
1578        Inputs:
1579          <++>
1580        Outputs:
1581          <++>
1582
1583------------------------------------------------------------------------------*/
1584
1585static u32 DecodeMotionConstrainedSliceGroupSet(
1586  strmData_t *pStrmData,
1587  seiMotionConstrainedSliceGroupSet_t *pMotionConstrainedSliceGroupSet,
1588  u32 numSliceGroups)
1589{
1590
1591/* Variables */
1592
1593    u32 tmp,i;
1594
1595/* Code */
1596
1597    ASSERT(pStrmData);
1598    ASSERT(pMotionConstrainedSliceGroupSet);
1599    ASSERT(numSliceGroups < MAX_NUM_SLICE_GROUPS);
1600
1601
1602    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1603      &pMotionConstrainedSliceGroupSet->numSliceGroupsInSet);
1604    if (tmp != HANTRO_OK)
1605        return(tmp);
1606    pMotionConstrainedSliceGroupSet->numSliceGroupsInSet++;
1607    if (pMotionConstrainedSliceGroupSet->numSliceGroupsInSet > numSliceGroups)
1608        return(HANTRO_NOK);
1609
1610    for (i = 0; i < pMotionConstrainedSliceGroupSet->numSliceGroupsInSet; i++)
1611    {
1612        tmp = h264bsdGetBits(pStrmData,
1613            ceilLog2NumSliceGroups[numSliceGroups]);
1614        if (tmp == END_OF_STREAM)
1615            return(HANTRO_NOK);
1616        pMotionConstrainedSliceGroupSet->sliceGroupId[i] = tmp;
1617        if (pMotionConstrainedSliceGroupSet->sliceGroupId[i] >
1618          pMotionConstrainedSliceGroupSet->numSliceGroupsInSet-1)
1619            return(HANTRO_NOK);
1620    }
1621
1622    tmp = h264bsdGetBits(pStrmData, 1);
1623    if (tmp == END_OF_STREAM)
1624        return(HANTRO_NOK);
1625    pMotionConstrainedSliceGroupSet->exactSampleValueMatchFlag =
1626        tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1627
1628    tmp = h264bsdGetBits(pStrmData, 1);
1629    if (tmp == END_OF_STREAM)
1630        return(HANTRO_NOK);
1631    pMotionConstrainedSliceGroupSet->panScanRectFlag = tmp == 1 ?
1632                                        HANTRO_TRUE : HANTRO_FALSE;
1633
1634    if (pMotionConstrainedSliceGroupSet->panScanRectFlag)
1635    {
1636        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1637          &pMotionConstrainedSliceGroupSet->panScanRectId);
1638        if (tmp != HANTRO_OK)
1639            return(tmp);
1640    }
1641
1642    return(HANTRO_OK);
1643
1644}
1645
1646/*------------------------------------------------------------------------------
1647
1648    Function: DecodeReservedSeiMessage
1649
1650        Functional description:
1651          <++>
1652        Inputs:
1653          <++>
1654        Outputs:
1655          <++>
1656
1657------------------------------------------------------------------------------*/
1658
1659static u32 DecodeReservedSeiMessage(
1660  strmData_t *pStrmData,
1661  seiReservedSeiMessage_t *pReservedSeiMessage,
1662  u32 payloadSize)
1663{
1664
1665/* Variables */
1666
1667    u32 i, tmp;
1668
1669/* Code */
1670
1671    ASSERT(pStrmData);
1672    ASSERT(pReservedSeiMessage);
1673
1674
1675    /* where corresponding FREE() ??? */
1676    ALLOCATE(pReservedSeiMessage->reservedSeiMessagePayloadByte,payloadSize,u8);
1677    if (pReservedSeiMessage->reservedSeiMessagePayloadByte == NULL)
1678        return(MEMORY_ALLOCATION_ERROR);
1679
1680    pReservedSeiMessage->numPayloadBytes = payloadSize;
1681
1682    for (i = 0; i < payloadSize; i++)
1683    {
1684        tmp = h264bsdGetBits(pStrmData,8);
1685        if (tmp == END_OF_STREAM)
1686            return(HANTRO_NOK);
1687        pReservedSeiMessage->reservedSeiMessagePayloadByte[i] = (u8)tmp;
1688    }
1689
1690    return(HANTRO_OK);
1691
1692}
1693