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
1000    return(tmp);
1001
1002}
1003
1004/*------------------------------------------------------------------------------
1005
1006    Function: DecodeSparePic
1007
1008        Functional description:
1009          <++>
1010        Inputs:
1011          <++>
1012        Outputs:
1013          <++>
1014
1015------------------------------------------------------------------------------*/
1016
1017static u32 DecodeSparePic(
1018  strmData_t *pStrmData,
1019  seiSparePic_t *pSparePic,
1020  u32 picSizeInMapUnits)
1021{
1022
1023/* Variables */
1024
1025    u32 tmp, i, j, mapUnitCnt;
1026
1027/* Code */
1028
1029    ASSERT(pStrmData);
1030    ASSERT(pSparePic);
1031
1032
1033    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1034        &pSparePic->targetFrameNum);
1035    if (tmp != HANTRO_OK)
1036        return(tmp);
1037
1038    tmp = h264bsdGetBits(pStrmData, 1);
1039    if (tmp == END_OF_STREAM)
1040        return(HANTRO_NOK);
1041    pSparePic->spareFieldFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1042    /* do not accept fields */
1043    if (pSparePic->spareFieldFlag)
1044        return(HANTRO_NOK);
1045
1046    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSparePic->numSparePics);
1047    if (tmp != HANTRO_OK)
1048        return(tmp);
1049    pSparePic->numSparePics++;
1050    if (pSparePic->numSparePics > MAX_NUM_SPARE_PICS)
1051        return(HANTRO_NOK);
1052
1053    for (i = 0; i < pSparePic->numSparePics; i++)
1054    {
1055        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1056          &pSparePic->deltaSpareFrameNum[i]);
1057        if (tmp != HANTRO_OK)
1058            return(tmp);
1059
1060        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1061            &pSparePic->spareAreaIdc[i]);
1062        if (tmp != HANTRO_OK)
1063            return(tmp);
1064        if (pSparePic->spareAreaIdc[i] > 2)
1065            return(HANTRO_NOK);
1066
1067        if (pSparePic->spareAreaIdc[i] == 1)
1068        {
1069            /* where corresponding FREE() ??? */
1070            ALLOCATE(pSparePic->spareUnitFlag[i], picSizeInMapUnits, u32);
1071            if (pSparePic->spareUnitFlag[i] == NULL)
1072                return(MEMORY_ALLOCATION_ERROR);
1073            pSparePic->zeroRunLength[i] = NULL;
1074
1075            for (j = 0; j < picSizeInMapUnits; j++)
1076            {
1077                tmp = h264bsdGetBits(pStrmData, 1);
1078                if (tmp == END_OF_STREAM)
1079                    return(HANTRO_NOK);
1080                pSparePic->spareUnitFlag[i][j] = tmp == 1 ?
1081                                    HANTRO_TRUE : HANTRO_FALSE;
1082            }
1083        }
1084        else if (pSparePic->spareAreaIdc[i] == 2)
1085        {
1086            /* where corresponding FREE() ??? */
1087            ALLOCATE(pSparePic->zeroRunLength[i], picSizeInMapUnits, u32);
1088            if (pSparePic->zeroRunLength[i] == NULL)
1089                return(MEMORY_ALLOCATION_ERROR);
1090            pSparePic->spareUnitFlag[i] = NULL;
1091
1092            for (j = 0, mapUnitCnt = 0; mapUnitCnt < picSizeInMapUnits; j++)
1093            {
1094                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1095                  &pSparePic->zeroRunLength[i][j]);
1096                if (tmp != HANTRO_OK)
1097                    return(tmp);
1098                mapUnitCnt += pSparePic->zeroRunLength[i][j] + 1;
1099            }
1100        }
1101    }
1102
1103    /* set rest to null */
1104    for (i = pSparePic->numSparePics; i < MAX_NUM_SPARE_PICS; i++)
1105    {
1106        pSparePic->spareUnitFlag[i] = NULL;
1107        pSparePic->zeroRunLength[i] = NULL;
1108    }
1109
1110    return(HANTRO_OK);
1111
1112}
1113
1114/*------------------------------------------------------------------------------
1115
1116    Function: DecodeSceneInfo
1117
1118        Functional description:
1119          <++>
1120        Inputs:
1121          <++>
1122        Outputs:
1123          <++>
1124
1125------------------------------------------------------------------------------*/
1126
1127static u32 DecodeSceneInfo(
1128  strmData_t *pStrmData,
1129  seiSceneInfo_t *pSceneInfo)
1130{
1131
1132/* Variables */
1133
1134    u32 tmp;
1135
1136/* Code */
1137
1138    ASSERT(pStrmData);
1139    ASSERT(pSceneInfo);
1140
1141
1142    tmp = h264bsdGetBits(pStrmData, 1);
1143    if (tmp == END_OF_STREAM)
1144        return(HANTRO_NOK);
1145    pSceneInfo->sceneInfoPresentFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1146
1147    if (pSceneInfo->sceneInfoPresentFlag)
1148    {
1149        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSceneInfo->sceneId);
1150        if (tmp != HANTRO_OK)
1151            return(tmp);
1152
1153        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1154          &pSceneInfo->sceneTransitionType);
1155        if (tmp != HANTRO_OK)
1156            return(tmp);
1157        if (pSceneInfo->sceneTransitionType > 6)
1158            return(HANTRO_NOK);
1159
1160        if (pSceneInfo->sceneTransitionType)
1161        {
1162            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1163              &pSceneInfo->secondSceneId);
1164            if (tmp != HANTRO_OK)
1165                return(tmp);
1166        }
1167
1168    }
1169
1170    return(HANTRO_OK);
1171
1172}
1173
1174/*------------------------------------------------------------------------------
1175
1176    Function: DecodeSubSeqInfo
1177
1178        Functional description:
1179          <++>
1180        Inputs:
1181          <++>
1182        Outputs:
1183          <++>
1184
1185-----------------------------------------------------------------------------*/
1186
1187static u32 DecodeSubSeqInfo(
1188  strmData_t *pStrmData,
1189  seiSubSeqInfo_t *pSubSeqInfo)
1190{
1191
1192/* Variables */
1193
1194    u32 tmp;
1195
1196/* Code */
1197
1198    ASSERT(pStrmData);
1199    ASSERT(pSubSeqInfo);
1200
1201
1202    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1203        &pSubSeqInfo->subSeqLayerNum);
1204    if (tmp != HANTRO_OK)
1205        return(tmp);
1206    if (pSubSeqInfo->subSeqLayerNum > 255)
1207        return(HANTRO_NOK);
1208
1209    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSubSeqInfo->subSeqId);
1210    if (tmp != HANTRO_OK)
1211        return(tmp);
1212    if (pSubSeqInfo->subSeqId > 65535)
1213        return(HANTRO_NOK);
1214
1215    tmp = h264bsdGetBits(pStrmData, 1);
1216    if (tmp == END_OF_STREAM)
1217        return(HANTRO_NOK);
1218    pSubSeqInfo->firstRefPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1219
1220    tmp = h264bsdGetBits(pStrmData, 1);
1221    if (tmp == END_OF_STREAM)
1222        return(HANTRO_NOK);
1223    pSubSeqInfo->leadingNonRefPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1224
1225    tmp = h264bsdGetBits(pStrmData, 1);
1226    if (tmp == END_OF_STREAM)
1227        return(HANTRO_NOK);
1228    pSubSeqInfo->lastPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1229
1230    tmp = h264bsdGetBits(pStrmData, 1);
1231    if (tmp == END_OF_STREAM)
1232        return(HANTRO_NOK);
1233    pSubSeqInfo->subSeqFrameNumFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1234
1235    if (pSubSeqInfo->subSeqFrameNumFlag)
1236    {
1237        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1238            &pSubSeqInfo->subSeqFrameNum);
1239        if (tmp != HANTRO_OK)
1240            return(tmp);
1241    }
1242
1243    return(HANTRO_OK);
1244
1245}
1246
1247/*------------------------------------------------------------------------------
1248
1249    Function: DecodeSubSeqLayerCharacteristics
1250
1251        Functional description:
1252          <++>
1253        Inputs:
1254          <++>
1255        Outputs:
1256          <++>
1257
1258------------------------------------------------------------------------------*/
1259
1260static u32 DecodeSubSeqLayerCharacteristics(
1261  strmData_t *pStrmData,
1262  seiSubSeqLayerCharacteristics_t *pSubSeqLayerCharacteristics)
1263{
1264
1265/* Variables */
1266
1267    u32 tmp, i;
1268
1269/* Code */
1270
1271    ASSERT(pStrmData);
1272    ASSERT(pSubSeqLayerCharacteristics);
1273
1274
1275    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1276      &pSubSeqLayerCharacteristics->numSubSeqLayers);
1277    if (tmp != HANTRO_OK)
1278        return(tmp);
1279    pSubSeqLayerCharacteristics->numSubSeqLayers++;
1280    if (pSubSeqLayerCharacteristics->numSubSeqLayers > MAX_NUM_SUB_SEQ_LAYERS)
1281        return(HANTRO_NOK);
1282
1283    for (i = 0; i < pSubSeqLayerCharacteristics->numSubSeqLayers; i++)
1284    {
1285        tmp = h264bsdGetBits(pStrmData, 1);
1286        if (tmp == END_OF_STREAM)
1287            return(HANTRO_NOK);
1288        pSubSeqLayerCharacteristics->accurateStatisticsFlag[i] =
1289            tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1290
1291        tmp = h264bsdGetBits(pStrmData, 16);
1292        if (tmp == END_OF_STREAM)
1293            return(HANTRO_NOK);
1294        pSubSeqLayerCharacteristics->averageBitRate[i] = tmp;
1295
1296        tmp = h264bsdGetBits(pStrmData, 16);
1297        if (tmp == END_OF_STREAM)
1298            return(HANTRO_NOK);
1299        pSubSeqLayerCharacteristics->averageFrameRate[i] = tmp;
1300    }
1301
1302    return(HANTRO_OK);
1303
1304}
1305
1306/*------------------------------------------------------------------------------
1307
1308    Function: DecodeSubSeqCharacteristics
1309
1310        Functional description:
1311          <++>
1312        Inputs:
1313          <++>
1314        Outputs:
1315          <++>
1316
1317------------------------------------------------------------------------------*/
1318
1319static u32 DecodeSubSeqCharacteristics(
1320  strmData_t *pStrmData,
1321  seiSubSeqCharacteristics_t *pSubSeqCharacteristics)
1322{
1323
1324/* Variables */
1325
1326    u32 tmp, i;
1327
1328/* Code */
1329
1330    ASSERT(pStrmData);
1331    ASSERT(pSubSeqCharacteristics);
1332
1333
1334    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1335      &pSubSeqCharacteristics->subSeqLayerNum);
1336    if (tmp != HANTRO_OK)
1337        return(tmp);
1338    if (pSubSeqCharacteristics->subSeqLayerNum > MAX_NUM_SUB_SEQ_LAYERS-1)
1339        return(HANTRO_NOK);
1340
1341    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1342        &pSubSeqCharacteristics->subSeqId);
1343    if (tmp != HANTRO_OK)
1344        return(tmp);
1345    if (pSubSeqCharacteristics->subSeqId > 65535)
1346        return(HANTRO_NOK);
1347
1348    tmp = h264bsdGetBits(pStrmData, 1);
1349    if (tmp == END_OF_STREAM)
1350        return(HANTRO_NOK);
1351    pSubSeqCharacteristics->durationFlag = tmp == 1 ?
1352                            HANTRO_TRUE : HANTRO_FALSE;
1353
1354    if (pSubSeqCharacteristics->durationFlag)
1355    {
1356        pSubSeqCharacteristics->subSeqDuration = h264bsdShowBits32(pStrmData);
1357        if (h264bsdFlushBits(pStrmData,32) == END_OF_STREAM)
1358            return(HANTRO_NOK);
1359    }
1360
1361    tmp = h264bsdGetBits(pStrmData, 1);
1362    if (tmp == END_OF_STREAM)
1363        return(HANTRO_NOK);
1364    pSubSeqCharacteristics->averageRateFlag = tmp == 1 ?
1365                            HANTRO_TRUE : HANTRO_FALSE;
1366
1367    if (pSubSeqCharacteristics->averageRateFlag)
1368    {
1369        tmp = h264bsdGetBits(pStrmData, 1);
1370        if (tmp == END_OF_STREAM)
1371            return(HANTRO_NOK);
1372        pSubSeqCharacteristics->accurateStatisticsFlag =
1373            tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1374
1375        tmp = h264bsdGetBits(pStrmData, 16);
1376        if (tmp == END_OF_STREAM)
1377            return(HANTRO_NOK);
1378        pSubSeqCharacteristics->averageBitRate = tmp;
1379
1380        tmp = h264bsdGetBits(pStrmData, 16);
1381        if (tmp == END_OF_STREAM)
1382            return(HANTRO_NOK);
1383        pSubSeqCharacteristics->averageFrameRate = tmp;
1384    }
1385
1386    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1387      &pSubSeqCharacteristics->numReferencedSubseqs);
1388    if (tmp != HANTRO_OK)
1389        return(tmp);
1390    if (pSubSeqCharacteristics->numReferencedSubseqs > MAX_NUM_SUB_SEQ_LAYERS-1)
1391        return(HANTRO_NOK);
1392
1393    for (i = 0; i < pSubSeqCharacteristics->numReferencedSubseqs; i++)
1394    {
1395        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1396          &pSubSeqCharacteristics->refSubSeqLayerNum[i]);
1397        if (tmp != HANTRO_OK)
1398            return(tmp);
1399
1400        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1401          &pSubSeqCharacteristics->refSubSeqId[i]);
1402        if (tmp != HANTRO_OK)
1403            return(tmp);
1404
1405        tmp = h264bsdGetBits(pStrmData, 1);
1406        if (tmp == END_OF_STREAM)
1407            return(HANTRO_NOK);
1408        pSubSeqCharacteristics->refSubSeqDirection[i] = tmp;
1409    }
1410
1411    return(HANTRO_OK);
1412
1413}
1414
1415/*------------------------------------------------------------------------------
1416
1417    Function: DecodeFullFrameFreeze
1418
1419        Functional description:
1420          <++>
1421        Inputs:
1422          <++>
1423        Outputs:
1424          <++>
1425
1426------------------------------------------------------------------------------*/
1427
1428static u32 DecodeFullFrameFreeze(
1429  strmData_t *pStrmData,
1430  seiFullFrameFreeze_t *pFullFrameFreeze)
1431{
1432
1433/* Variables */
1434
1435    u32 tmp;
1436
1437/* Code */
1438
1439    ASSERT(pStrmData);
1440    ASSERT(pFullFrameFreeze);
1441
1442
1443    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1444      &pFullFrameFreeze->fullFrameFreezeRepetitionPeriod);
1445    if (tmp != HANTRO_OK)
1446        return(tmp);
1447    if (pFullFrameFreeze->fullFrameFreezeRepetitionPeriod > 16384)
1448        return(HANTRO_NOK);
1449
1450    return(HANTRO_OK);
1451
1452}
1453
1454/*------------------------------------------------------------------------------
1455
1456    Function: DecodeFullFrameSnapshot
1457
1458        Functional description:
1459          <++>
1460        Inputs:
1461          <++>
1462        Outputs:
1463          <++>
1464
1465------------------------------------------------------------------------------*/
1466
1467static u32 DecodeFullFrameSnapshot(
1468  strmData_t *pStrmData,
1469  seiFullFrameSnapshot_t *pFullFrameSnapshot)
1470{
1471
1472/* Variables */
1473
1474    u32 tmp;
1475
1476/* Code */
1477
1478    ASSERT(pStrmData);
1479    ASSERT(pFullFrameSnapshot);
1480
1481
1482    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1483        &pFullFrameSnapshot->snapShotId);
1484    if (tmp != HANTRO_OK)
1485        return(tmp);
1486
1487    return(HANTRO_OK);
1488
1489}
1490
1491/*------------------------------------------------------------------------------
1492
1493    Function: DecodeProgressiveRefinementSegmentStart
1494
1495        Functional description:
1496          <++>
1497        Inputs:
1498          <++>
1499        Outputs:
1500          <++>
1501
1502------------------------------------------------------------------------------*/
1503
1504static u32 DecodeProgressiveRefinementSegmentStart(
1505  strmData_t *pStrmData,
1506  seiProgressiveRefinementSegmentStart_t *pProgressiveRefinementSegmentStart)
1507{
1508
1509/* Variables */
1510
1511    u32 tmp;
1512
1513/* Code */
1514
1515    ASSERT(pStrmData);
1516    ASSERT(pProgressiveRefinementSegmentStart);
1517
1518
1519    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1520      &pProgressiveRefinementSegmentStart->progressiveRefinementId);
1521    if (tmp != HANTRO_OK)
1522        return(tmp);
1523
1524    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1525      &pProgressiveRefinementSegmentStart->numRefinementSteps);
1526    if (tmp != HANTRO_OK)
1527        return(tmp);
1528    pProgressiveRefinementSegmentStart->numRefinementSteps++;
1529
1530    return(HANTRO_OK);
1531
1532}
1533
1534/*------------------------------------------------------------------------------
1535
1536    Function: DecodeProgressiveRefinementSegmentEnd
1537
1538        Functional description:
1539          <++>
1540        Inputs:
1541          <++>
1542        Outputs:
1543          <++>
1544
1545------------------------------------------------------------------------------*/
1546
1547static u32 DecodeProgressiveRefinementSegmentEnd(
1548  strmData_t *pStrmData,
1549  seiProgressiveRefinementSegmentEnd_t *pProgressiveRefinementSegmentEnd)
1550{
1551
1552/* Variables */
1553
1554    u32 tmp;
1555
1556/* Code */
1557
1558    ASSERT(pStrmData);
1559    ASSERT(pProgressiveRefinementSegmentEnd);
1560
1561
1562    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1563      &pProgressiveRefinementSegmentEnd->progressiveRefinementId);
1564    if (tmp != HANTRO_OK)
1565        return(tmp);
1566
1567    return(HANTRO_OK);
1568
1569}
1570
1571/*------------------------------------------------------------------------------
1572
1573    Function: DecodeMotionConstrainedSliceGroupSet
1574
1575        Functional description:
1576          <++>
1577        Inputs:
1578          <++>
1579        Outputs:
1580          <++>
1581
1582------------------------------------------------------------------------------*/
1583
1584static u32 DecodeMotionConstrainedSliceGroupSet(
1585  strmData_t *pStrmData,
1586  seiMotionConstrainedSliceGroupSet_t *pMotionConstrainedSliceGroupSet,
1587  u32 numSliceGroups)
1588{
1589
1590/* Variables */
1591
1592    u32 tmp,i;
1593
1594/* Code */
1595
1596    ASSERT(pStrmData);
1597    ASSERT(pMotionConstrainedSliceGroupSet);
1598    ASSERT(numSliceGroups < MAX_NUM_SLICE_GROUPS);
1599
1600
1601    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1602      &pMotionConstrainedSliceGroupSet->numSliceGroupsInSet);
1603    if (tmp != HANTRO_OK)
1604        return(tmp);
1605    pMotionConstrainedSliceGroupSet->numSliceGroupsInSet++;
1606    if (pMotionConstrainedSliceGroupSet->numSliceGroupsInSet > numSliceGroups)
1607        return(HANTRO_NOK);
1608
1609    for (i = 0; i < pMotionConstrainedSliceGroupSet->numSliceGroupsInSet; i++)
1610    {
1611        tmp = h264bsdGetBits(pStrmData,
1612            ceilLog2NumSliceGroups[numSliceGroups]);
1613        if (tmp == END_OF_STREAM)
1614            return(HANTRO_NOK);
1615        pMotionConstrainedSliceGroupSet->sliceGroupId[i] = tmp;
1616        if (pMotionConstrainedSliceGroupSet->sliceGroupId[i] >
1617          pMotionConstrainedSliceGroupSet->numSliceGroupsInSet-1)
1618            return(HANTRO_NOK);
1619    }
1620
1621    tmp = h264bsdGetBits(pStrmData, 1);
1622    if (tmp == END_OF_STREAM)
1623        return(HANTRO_NOK);
1624    pMotionConstrainedSliceGroupSet->exactSampleValueMatchFlag =
1625        tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
1626
1627    tmp = h264bsdGetBits(pStrmData, 1);
1628    if (tmp == END_OF_STREAM)
1629        return(HANTRO_NOK);
1630    pMotionConstrainedSliceGroupSet->panScanRectFlag = tmp == 1 ?
1631                                        HANTRO_TRUE : HANTRO_FALSE;
1632
1633    if (pMotionConstrainedSliceGroupSet->panScanRectFlag)
1634    {
1635        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
1636          &pMotionConstrainedSliceGroupSet->panScanRectId);
1637        if (tmp != HANTRO_OK)
1638            return(tmp);
1639    }
1640
1641    return(HANTRO_OK);
1642
1643}
1644
1645/*------------------------------------------------------------------------------
1646
1647    Function: DecodeReservedSeiMessage
1648
1649        Functional description:
1650          <++>
1651        Inputs:
1652          <++>
1653        Outputs:
1654          <++>
1655
1656------------------------------------------------------------------------------*/
1657
1658static u32 DecodeReservedSeiMessage(
1659  strmData_t *pStrmData,
1660  seiReservedSeiMessage_t *pReservedSeiMessage,
1661  u32 payloadSize)
1662{
1663
1664/* Variables */
1665
1666    u32 i, tmp;
1667
1668/* Code */
1669
1670    ASSERT(pStrmData);
1671    ASSERT(pReservedSeiMessage);
1672
1673
1674    /* where corresponding FREE() ??? */
1675    ALLOCATE(pReservedSeiMessage->reservedSeiMessagePayloadByte,payloadSize,u8);
1676    if (pReservedSeiMessage->reservedSeiMessagePayloadByte == NULL)
1677        return(MEMORY_ALLOCATION_ERROR);
1678
1679    pReservedSeiMessage->numPayloadBytes = payloadSize;
1680
1681    for (i = 0; i < payloadSize; i++)
1682    {
1683        tmp = h264bsdGetBits(pStrmData,8);
1684        if (tmp == END_OF_STREAM)
1685            return(HANTRO_NOK);
1686        pReservedSeiMessage->reservedSeiMessagePayloadByte[i] = (u8)tmp;
1687    }
1688
1689    return(HANTRO_OK);
1690
1691}
1692
1693