PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.c

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