/H264Dec/source/h264bsd_sei.c

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