PageRenderTime 30ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/H264Dec/source/h264bsd_storage.c

http://github.com/mbebenita/Broadway
C | 888 lines | 401 code | 132 blank | 355 comment | 129 complexity | 63f82fa7fab59be07488b585dc328e56 MD5 | raw file
Possible License(s): BSD-3-Clause
  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. h264bsdInitStorage
  24. h264bsdStoreSeqParamSet
  25. h264bsdStorePicParamSet
  26. h264bsdActivateParamSets
  27. h264bsdResetStorage
  28. h264bsdIsStartOfPicture
  29. h264bsdIsEndOfPicture
  30. h264bsdComputeSliceGroupMap
  31. h264bsdCheckAccessUnitBoundary
  32. CheckPps
  33. h264bsdValidParamSets
  34. ------------------------------------------------------------------------------*/
  35. /*------------------------------------------------------------------------------
  36. 1. Include headers
  37. ------------------------------------------------------------------------------*/
  38. #include "h264bsd_storage.h"
  39. #include "h264bsd_util.h"
  40. #include "h264bsd_neighbour.h"
  41. #include "h264bsd_slice_group_map.h"
  42. #include "h264bsd_dpb.h"
  43. #include "h264bsd_nal_unit.h"
  44. #include "h264bsd_slice_header.h"
  45. #include "h264bsd_seq_param_set.h"
  46. /*------------------------------------------------------------------------------
  47. 2. External compiler flags
  48. --------------------------------------------------------------------------------
  49. --------------------------------------------------------------------------------
  50. 3. Module defines
  51. ------------------------------------------------------------------------------*/
  52. /*------------------------------------------------------------------------------
  53. 4. Local function prototypes
  54. ------------------------------------------------------------------------------*/
  55. static u32 CheckPps(picParamSet_t *pps, seqParamSet_t *sps);
  56. /*------------------------------------------------------------------------------
  57. Function name: h264bsdInitStorage
  58. Functional description:
  59. Initialize storage structure. Sets contents of the storage to '0'
  60. except for the active parameter set ids, which are initialized
  61. to invalid values.
  62. Inputs:
  63. Outputs:
  64. pStorage initialized data stored here
  65. Returns:
  66. none
  67. ------------------------------------------------------------------------------*/
  68. void h264bsdInitStorage(storage_t *pStorage)
  69. {
  70. /* Variables */
  71. /* Code */
  72. ASSERT(pStorage);
  73. H264SwDecMemset(pStorage, 0, sizeof(storage_t));
  74. pStorage->activeSpsId = MAX_NUM_SEQ_PARAM_SETS;
  75. pStorage->activePpsId = MAX_NUM_PIC_PARAM_SETS;
  76. pStorage->aub->firstCallFlag = HANTRO_TRUE;
  77. }
  78. /*------------------------------------------------------------------------------
  79. Function: h264bsdStoreSeqParamSet
  80. Functional description:
  81. Store sequence parameter set into the storage. If active SPS is
  82. overwritten -> check if contents changes and if it does, set
  83. parameters to force reactivation of parameter sets
  84. Inputs:
  85. pStorage pointer to storage structure
  86. pSeqParamSet pointer to param set to be stored
  87. Outputs:
  88. none
  89. Returns:
  90. HANTRO_OK success
  91. MEMORY_ALLOCATION_ERROR failure in memory allocation
  92. ------------------------------------------------------------------------------*/
  93. u32 h264bsdStoreSeqParamSet(storage_t *pStorage, seqParamSet_t *pSeqParamSet)
  94. {
  95. /* Variables */
  96. u32 id;
  97. /* Code */
  98. ASSERT(pStorage);
  99. ASSERT(pSeqParamSet);
  100. ASSERT(pSeqParamSet->seqParameterSetId < MAX_NUM_SEQ_PARAM_SETS);
  101. id = pSeqParamSet->seqParameterSetId;
  102. /* seq parameter set with id not used before -> allocate memory */
  103. if (pStorage->sps[id] == NULL)
  104. {
  105. ALLOCATE(pStorage->sps[id], 1, seqParamSet_t);
  106. if (pStorage->sps[id] == NULL)
  107. return(MEMORY_ALLOCATION_ERROR);
  108. }
  109. /* sequence parameter set with id equal to id of active sps */
  110. else if (id == pStorage->activeSpsId)
  111. {
  112. /* if seq parameter set contents changes
  113. * -> overwrite and re-activate when next IDR picture decoded
  114. * ids of active param sets set to invalid values to force
  115. * re-activation. Memories allocated for old sps freed
  116. * otherwise free memeries allocated for just decoded sps and
  117. * continue */
  118. if (h264bsdCompareSeqParamSets(pSeqParamSet, pStorage->activeSps) != 0)
  119. {
  120. FREE(pStorage->sps[id]->offsetForRefFrame);
  121. FREE(pStorage->sps[id]->vuiParameters);
  122. pStorage->activeSpsId = MAX_NUM_SEQ_PARAM_SETS + 1;
  123. pStorage->activePpsId = MAX_NUM_PIC_PARAM_SETS + 1;
  124. pStorage->activeSps = NULL;
  125. pStorage->activePps = NULL;
  126. }
  127. else
  128. {
  129. FREE(pSeqParamSet->offsetForRefFrame);
  130. FREE(pSeqParamSet->vuiParameters);
  131. return(HANTRO_OK);
  132. }
  133. }
  134. /* overwrite seq param set other than active one -> free memories
  135. * allocated for old param set */
  136. else
  137. {
  138. FREE(pStorage->sps[id]->offsetForRefFrame);
  139. FREE(pStorage->sps[id]->vuiParameters);
  140. }
  141. *pStorage->sps[id] = *pSeqParamSet;
  142. return(HANTRO_OK);
  143. }
  144. /*------------------------------------------------------------------------------
  145. Function: h264bsdStorePicParamSet
  146. Functional description:
  147. Store picture parameter set into the storage. If active PPS is
  148. overwritten -> check if active SPS changes and if it does -> set
  149. parameters to force reactivation of parameter sets
  150. Inputs:
  151. pStorage pointer to storage structure
  152. pPicParamSet pointer to param set to be stored
  153. Outputs:
  154. none
  155. Returns:
  156. HANTRO_OK success
  157. MEMORY_ALLOCATION_ERROR failure in memory allocation
  158. ------------------------------------------------------------------------------*/
  159. u32 h264bsdStorePicParamSet(storage_t *pStorage, picParamSet_t *pPicParamSet)
  160. {
  161. /* Variables */
  162. u32 id;
  163. /* Code */
  164. ASSERT(pStorage);
  165. ASSERT(pPicParamSet);
  166. ASSERT(pPicParamSet->picParameterSetId < MAX_NUM_PIC_PARAM_SETS);
  167. ASSERT(pPicParamSet->seqParameterSetId < MAX_NUM_SEQ_PARAM_SETS);
  168. id = pPicParamSet->picParameterSetId;
  169. /* pic parameter set with id not used before -> allocate memory */
  170. if (pStorage->pps[id] == NULL)
  171. {
  172. ALLOCATE(pStorage->pps[id], 1, picParamSet_t);
  173. if (pStorage->pps[id] == NULL)
  174. return(MEMORY_ALLOCATION_ERROR);
  175. }
  176. /* picture parameter set with id equal to id of active pps */
  177. else if (id == pStorage->activePpsId)
  178. {
  179. /* check whether seq param set changes, force re-activation of
  180. * param set if it does. Set activeSpsId to invalid value to
  181. * accomplish this */
  182. if (pPicParamSet->seqParameterSetId != pStorage->activeSpsId)
  183. {
  184. pStorage->activePpsId = MAX_NUM_PIC_PARAM_SETS + 1;
  185. }
  186. /* free memories allocated for old param set */
  187. FREE(pStorage->pps[id]->runLength);
  188. FREE(pStorage->pps[id]->topLeft);
  189. FREE(pStorage->pps[id]->bottomRight);
  190. FREE(pStorage->pps[id]->sliceGroupId);
  191. }
  192. /* overwrite pic param set other than active one -> free memories
  193. * allocated for old param set */
  194. else
  195. {
  196. FREE(pStorage->pps[id]->runLength);
  197. FREE(pStorage->pps[id]->topLeft);
  198. FREE(pStorage->pps[id]->bottomRight);
  199. FREE(pStorage->pps[id]->sliceGroupId);
  200. }
  201. *pStorage->pps[id] = *pPicParamSet;
  202. return(HANTRO_OK);
  203. }
  204. /*------------------------------------------------------------------------------
  205. Function: h264bsdActivateParamSets
  206. Functional description:
  207. Activate certain SPS/PPS combination. This function shall be
  208. called in the beginning of each picture. Picture parameter set
  209. can be changed as wanted, but sequence parameter set may only be
  210. changed when the starting picture is an IDR picture.
  211. When new SPS is activated the function allocates memory for
  212. macroblock storages and slice group map and (re-)initializes the
  213. decoded picture buffer. If this is not the first activation the old
  214. allocations are freed and FreeDpb called before new allocations.
  215. Inputs:
  216. pStorage pointer to storage data structure
  217. ppsId identifies the PPS to be activated, SPS id obtained
  218. from the PPS
  219. isIdr flag to indicate if the picture is an IDR picture
  220. Outputs:
  221. none
  222. Returns:
  223. HANTRO_OK success
  224. HANTRO_NOK non-existing or invalid param set combination,
  225. trying to change SPS with non-IDR picture
  226. MEMORY_ALLOCATION_ERROR failure in memory allocation
  227. ------------------------------------------------------------------------------*/
  228. u32 h264bsdActivateParamSets(storage_t *pStorage, u32 ppsId, u32 isIdr)
  229. {
  230. /* Variables */
  231. u32 tmp;
  232. u32 flag;
  233. /* Code */
  234. ASSERT(pStorage);
  235. ASSERT(ppsId < MAX_NUM_PIC_PARAM_SETS);
  236. /* check that pps and corresponding sps exist */
  237. if ( (pStorage->pps[ppsId] == NULL) ||
  238. (pStorage->sps[pStorage->pps[ppsId]->seqParameterSetId] == NULL) )
  239. {
  240. return(HANTRO_NOK);
  241. }
  242. /* check that pps parameters do not violate picture size constraints */
  243. tmp = CheckPps(pStorage->pps[ppsId],
  244. pStorage->sps[pStorage->pps[ppsId]->seqParameterSetId]);
  245. if (tmp != HANTRO_OK)
  246. return(tmp);
  247. /* first activation part1 */
  248. if (pStorage->activePpsId == MAX_NUM_PIC_PARAM_SETS)
  249. {
  250. pStorage->activePpsId = ppsId;
  251. pStorage->activePps = pStorage->pps[ppsId];
  252. pStorage->activeSpsId = pStorage->activePps->seqParameterSetId;
  253. pStorage->activeSps = pStorage->sps[pStorage->activeSpsId];
  254. pStorage->picSizeInMbs =
  255. pStorage->activeSps->picWidthInMbs *
  256. pStorage->activeSps->picHeightInMbs;
  257. pStorage->currImage->width = pStorage->activeSps->picWidthInMbs;
  258. pStorage->currImage->height = pStorage->activeSps->picHeightInMbs;
  259. pStorage->pendingActivation = HANTRO_TRUE;
  260. }
  261. /* first activation part2 */
  262. else if (pStorage->pendingActivation)
  263. {
  264. pStorage->pendingActivation = HANTRO_FALSE;
  265. FREE(pStorage->mb);
  266. FREE(pStorage->sliceGroupMap);
  267. ALLOCATE(pStorage->mb, pStorage->picSizeInMbs, mbStorage_t);
  268. ALLOCATE(pStorage->sliceGroupMap, pStorage->picSizeInMbs, u32);
  269. if (pStorage->mb == NULL || pStorage->sliceGroupMap == NULL)
  270. return(MEMORY_ALLOCATION_ERROR);
  271. H264SwDecMemset(pStorage->mb, 0,
  272. pStorage->picSizeInMbs * sizeof(mbStorage_t));
  273. h264bsdInitMbNeighbours(pStorage->mb,
  274. pStorage->activeSps->picWidthInMbs,
  275. pStorage->picSizeInMbs);
  276. /* dpb output reordering disabled if
  277. * 1) application set noReordering flag
  278. * 2) POC type equal to 2
  279. * 3) num_reorder_frames in vui equal to 0 */
  280. if ( pStorage->noReordering ||
  281. pStorage->activeSps->picOrderCntType == 2 ||
  282. (pStorage->activeSps->vuiParametersPresentFlag &&
  283. pStorage->activeSps->vuiParameters->bitstreamRestrictionFlag &&
  284. !pStorage->activeSps->vuiParameters->numReorderFrames) )
  285. flag = HANTRO_TRUE;
  286. else
  287. flag = HANTRO_FALSE;
  288. tmp = h264bsdResetDpb(pStorage->dpb,
  289. pStorage->activeSps->picWidthInMbs *
  290. pStorage->activeSps->picHeightInMbs,
  291. pStorage->activeSps->maxDpbSize,
  292. pStorage->activeSps->numRefFrames,
  293. pStorage->activeSps->maxFrameNum,
  294. flag);
  295. if (tmp != HANTRO_OK)
  296. return(tmp);
  297. }
  298. else if (ppsId != pStorage->activePpsId)
  299. {
  300. /* sequence parameter set shall not change but before an IDR picture */
  301. if (pStorage->pps[ppsId]->seqParameterSetId != pStorage->activeSpsId)
  302. {
  303. DEBUG(("SEQ PARAM SET CHANGING...\n"));
  304. if (isIdr)
  305. {
  306. pStorage->activePpsId = ppsId;
  307. pStorage->activePps = pStorage->pps[ppsId];
  308. pStorage->activeSpsId = pStorage->activePps->seqParameterSetId;
  309. pStorage->activeSps = pStorage->sps[pStorage->activeSpsId];
  310. pStorage->picSizeInMbs =
  311. pStorage->activeSps->picWidthInMbs *
  312. pStorage->activeSps->picHeightInMbs;
  313. pStorage->currImage->width = pStorage->activeSps->picWidthInMbs;
  314. pStorage->currImage->height =
  315. pStorage->activeSps->picHeightInMbs;
  316. pStorage->pendingActivation = HANTRO_TRUE;
  317. }
  318. else
  319. {
  320. DEBUG(("TRYING TO CHANGE SPS IN NON-IDR SLICE\n"));
  321. return(HANTRO_NOK);
  322. }
  323. }
  324. else
  325. {
  326. pStorage->activePpsId = ppsId;
  327. pStorage->activePps = pStorage->pps[ppsId];
  328. }
  329. }
  330. return(HANTRO_OK);
  331. }
  332. /*------------------------------------------------------------------------------
  333. Function: h264bsdResetStorage
  334. Functional description:
  335. Reset contents of the storage. This should be called before
  336. processing of new image is started.
  337. Inputs:
  338. pStorage pointer to storage structure
  339. Outputs:
  340. none
  341. Returns:
  342. none
  343. ------------------------------------------------------------------------------*/
  344. void h264bsdResetStorage(storage_t *pStorage)
  345. {
  346. /* Variables */
  347. u32 i;
  348. /* Code */
  349. ASSERT(pStorage);
  350. pStorage->slice->numDecodedMbs = 0;
  351. pStorage->slice->sliceId = 0;
  352. for (i = 0; i < pStorage->picSizeInMbs; i++)
  353. {
  354. pStorage->mb[i].sliceId = 0;
  355. pStorage->mb[i].decoded = 0;
  356. }
  357. }
  358. /*------------------------------------------------------------------------------
  359. Function: h264bsdIsStartOfPicture
  360. Functional description:
  361. Determine if the decoder is in the start of a picture. This
  362. information is needed to decide if h264bsdActivateParamSets and
  363. h264bsdCheckGapsInFrameNum functions should be called. Function
  364. considers that new picture is starting if no slice headers
  365. have been successfully decoded for the current access unit.
  366. Inputs:
  367. pStorage pointer to storage structure
  368. Outputs:
  369. none
  370. Returns:
  371. HANTRO_TRUE new picture is starting
  372. HANTRO_FALSE not starting
  373. ------------------------------------------------------------------------------*/
  374. u32 h264bsdIsStartOfPicture(storage_t *pStorage)
  375. {
  376. /* Variables */
  377. /* Code */
  378. if (pStorage->validSliceInAccessUnit == HANTRO_FALSE)
  379. return(HANTRO_TRUE);
  380. else
  381. return(HANTRO_FALSE);
  382. }
  383. /*------------------------------------------------------------------------------
  384. Function: h264bsdIsEndOfPicture
  385. Functional description:
  386. Determine if the decoder is in the end of a picture. This
  387. information is needed to determine when deblocking filtering
  388. and reference picture marking processes should be performed.
  389. If the decoder is processing primary slices the return value
  390. is determined by checking the value of numDecodedMbs in the
  391. storage. On the other hand, if the decoder is processing
  392. redundant slices the numDecodedMbs may not contain valid
  393. informationa and each macroblock has to be checked separately.
  394. Inputs:
  395. pStorage pointer to storage structure
  396. Outputs:
  397. none
  398. Returns:
  399. HANTRO_TRUE end of picture
  400. HANTRO_FALSE noup
  401. ------------------------------------------------------------------------------*/
  402. u32 h264bsdIsEndOfPicture(storage_t *pStorage)
  403. {
  404. /* Variables */
  405. u32 i, tmp;
  406. /* Code */
  407. /* primary picture */
  408. if (!pStorage->sliceHeader[0].redundantPicCnt)
  409. {
  410. if (pStorage->slice->numDecodedMbs == pStorage->picSizeInMbs)
  411. return(HANTRO_TRUE);
  412. }
  413. else
  414. {
  415. for (i = 0, tmp = 0; i < pStorage->picSizeInMbs; i++)
  416. tmp += pStorage->mb[i].decoded ? 1 : 0;
  417. if (tmp == pStorage->picSizeInMbs)
  418. return(HANTRO_TRUE);
  419. }
  420. return(HANTRO_FALSE);
  421. }
  422. /*------------------------------------------------------------------------------
  423. Function: h264bsdComputeSliceGroupMap
  424. Functional description:
  425. Compute slice group map. Just call h264bsdDecodeSliceGroupMap with
  426. appropriate parameters.
  427. Inputs:
  428. pStorage pointer to storage structure
  429. sliceGroupChangeCycle
  430. Outputs:
  431. none
  432. Returns:
  433. none
  434. ------------------------------------------------------------------------------*/
  435. void h264bsdComputeSliceGroupMap(storage_t *pStorage, u32 sliceGroupChangeCycle)
  436. {
  437. /* Variables */
  438. /* Code */
  439. h264bsdDecodeSliceGroupMap(pStorage->sliceGroupMap,
  440. pStorage->activePps, sliceGroupChangeCycle,
  441. pStorage->activeSps->picWidthInMbs,
  442. pStorage->activeSps->picHeightInMbs);
  443. }
  444. /*------------------------------------------------------------------------------
  445. Function: h264bsdCheckAccessUnitBoundary
  446. Functional description:
  447. Check if next NAL unit starts a new access unit. Following
  448. conditions specify start of a new access unit:
  449. -NAL unit types 6-11, 13-18 (e.g. SPS, PPS)
  450. following conditions checked only for slice NAL units, values
  451. compared to ones obtained from previous slice:
  452. -NAL unit type differs (slice / IDR slice)
  453. -frame_num differs
  454. -nal_ref_idc differs and one of the values is 0
  455. -POC information differs
  456. -both are IDR slices and idr_pic_id differs
  457. Inputs:
  458. strm pointer to stream data structure
  459. nuNext pointer to NAL unit structure
  460. storage pointer to storage structure
  461. Outputs:
  462. accessUnitBoundaryFlag the result is stored here, TRUE for
  463. access unit boundary, FALSE otherwise
  464. Returns:
  465. HANTRO_OK success
  466. HANTRO_NOK failure, invalid stream data
  467. PARAM_SET_ERROR invalid param set usage
  468. ------------------------------------------------------------------------------*/
  469. u32 h264bsdCheckAccessUnitBoundary(
  470. strmData_t *strm,
  471. nalUnit_t *nuNext,
  472. storage_t *storage,
  473. u32 *accessUnitBoundaryFlag)
  474. {
  475. /* Variables */
  476. u32 tmp, ppsId, frameNum, idrPicId, picOrderCntLsb;
  477. i32 deltaPicOrderCntBottom, deltaPicOrderCnt[2];
  478. seqParamSet_t *sps;
  479. picParamSet_t *pps;
  480. /* Code */
  481. ASSERT(strm);
  482. ASSERT(nuNext);
  483. ASSERT(storage);
  484. ASSERT(storage->sps);
  485. ASSERT(storage->pps);
  486. /* initialize default output to FALSE */
  487. *accessUnitBoundaryFlag = HANTRO_FALSE;
  488. if ( ( (nuNext->nalUnitType > 5) && (nuNext->nalUnitType < 12) ) ||
  489. ( (nuNext->nalUnitType > 12) && (nuNext->nalUnitType <= 18) ) )
  490. {
  491. *accessUnitBoundaryFlag = HANTRO_TRUE;
  492. return(HANTRO_OK);
  493. }
  494. else if ( nuNext->nalUnitType != NAL_CODED_SLICE &&
  495. nuNext->nalUnitType != NAL_CODED_SLICE_IDR )
  496. {
  497. return(HANTRO_OK);
  498. }
  499. /* check if this is the very first call to this function */
  500. if (storage->aub->firstCallFlag)
  501. {
  502. *accessUnitBoundaryFlag = HANTRO_TRUE;
  503. storage->aub->firstCallFlag = HANTRO_FALSE;
  504. }
  505. /* get picture parameter set id */
  506. tmp = h264bsdCheckPpsId(strm, &ppsId);
  507. if (tmp != HANTRO_OK)
  508. return(tmp);
  509. /* store sps and pps in separate pointers just to make names shorter */
  510. pps = storage->pps[ppsId];
  511. if ( pps == NULL || storage->sps[pps->seqParameterSetId] == NULL ||
  512. (storage->activeSpsId != MAX_NUM_SEQ_PARAM_SETS &&
  513. pps->seqParameterSetId != storage->activeSpsId &&
  514. nuNext->nalUnitType != NAL_CODED_SLICE_IDR) )
  515. return(PARAM_SET_ERROR);
  516. sps = storage->sps[pps->seqParameterSetId];
  517. if (storage->aub->nuPrev->nalRefIdc != nuNext->nalRefIdc &&
  518. (storage->aub->nuPrev->nalRefIdc == 0 || nuNext->nalRefIdc == 0))
  519. *accessUnitBoundaryFlag = HANTRO_TRUE;
  520. if ((storage->aub->nuPrev->nalUnitType == NAL_CODED_SLICE_IDR &&
  521. nuNext->nalUnitType != NAL_CODED_SLICE_IDR) ||
  522. (storage->aub->nuPrev->nalUnitType != NAL_CODED_SLICE_IDR &&
  523. nuNext->nalUnitType == NAL_CODED_SLICE_IDR))
  524. *accessUnitBoundaryFlag = HANTRO_TRUE;
  525. tmp = h264bsdCheckFrameNum(strm, sps->maxFrameNum, &frameNum);
  526. if (tmp != HANTRO_OK)
  527. return(HANTRO_NOK);
  528. if (storage->aub->prevFrameNum != frameNum)
  529. {
  530. storage->aub->prevFrameNum = frameNum;
  531. *accessUnitBoundaryFlag = HANTRO_TRUE;
  532. }
  533. if (nuNext->nalUnitType == NAL_CODED_SLICE_IDR)
  534. {
  535. tmp = h264bsdCheckIdrPicId(strm, sps->maxFrameNum, nuNext->nalUnitType,
  536. &idrPicId);
  537. if (tmp != HANTRO_OK)
  538. return(HANTRO_NOK);
  539. if (storage->aub->nuPrev->nalUnitType == NAL_CODED_SLICE_IDR &&
  540. storage->aub->prevIdrPicId != idrPicId)
  541. *accessUnitBoundaryFlag = HANTRO_TRUE;
  542. storage->aub->prevIdrPicId = idrPicId;
  543. }
  544. if (sps->picOrderCntType == 0)
  545. {
  546. tmp = h264bsdCheckPicOrderCntLsb(strm, sps, nuNext->nalUnitType,
  547. &picOrderCntLsb);
  548. if (tmp != HANTRO_OK)
  549. return(HANTRO_NOK);
  550. if (storage->aub->prevPicOrderCntLsb != picOrderCntLsb)
  551. {
  552. storage->aub->prevPicOrderCntLsb = picOrderCntLsb;
  553. *accessUnitBoundaryFlag = HANTRO_TRUE;
  554. }
  555. if (pps->picOrderPresentFlag)
  556. {
  557. tmp = h264bsdCheckDeltaPicOrderCntBottom(strm, sps,
  558. nuNext->nalUnitType, &deltaPicOrderCntBottom);
  559. if (tmp != HANTRO_OK)
  560. return(tmp);
  561. if (storage->aub->prevDeltaPicOrderCntBottom !=
  562. deltaPicOrderCntBottom)
  563. {
  564. storage->aub->prevDeltaPicOrderCntBottom =
  565. deltaPicOrderCntBottom;
  566. *accessUnitBoundaryFlag = HANTRO_TRUE;
  567. }
  568. }
  569. }
  570. else if (sps->picOrderCntType == 1 && !sps->deltaPicOrderAlwaysZeroFlag)
  571. {
  572. tmp = h264bsdCheckDeltaPicOrderCnt(strm, sps, nuNext->nalUnitType,
  573. pps->picOrderPresentFlag, deltaPicOrderCnt);
  574. if (tmp != HANTRO_OK)
  575. return(tmp);
  576. if (storage->aub->prevDeltaPicOrderCnt[0] != deltaPicOrderCnt[0])
  577. {
  578. storage->aub->prevDeltaPicOrderCnt[0] = deltaPicOrderCnt[0];
  579. *accessUnitBoundaryFlag = HANTRO_TRUE;
  580. }
  581. if (pps->picOrderPresentFlag)
  582. if (storage->aub->prevDeltaPicOrderCnt[1] != deltaPicOrderCnt[1])
  583. {
  584. storage->aub->prevDeltaPicOrderCnt[1] = deltaPicOrderCnt[1];
  585. *accessUnitBoundaryFlag = HANTRO_TRUE;
  586. }
  587. }
  588. *storage->aub->nuPrev = *nuNext;
  589. return(HANTRO_OK);
  590. }
  591. /*------------------------------------------------------------------------------
  592. Function: CheckPps
  593. Functional description:
  594. Check picture parameter set. Contents of the picture parameter
  595. set information that depends on the image dimensions is checked
  596. against the dimensions in the sps.
  597. Inputs:
  598. pps pointer to picture paramter set
  599. sps pointer to sequence parameter set
  600. Outputs:
  601. none
  602. Returns:
  603. HANTRO_OK everything ok
  604. HANTRO_NOK invalid data in picture parameter set
  605. ------------------------------------------------------------------------------*/
  606. u32 CheckPps(picParamSet_t *pps, seqParamSet_t *sps)
  607. {
  608. u32 i;
  609. u32 picSize;
  610. picSize = sps->picWidthInMbs * sps->picHeightInMbs;
  611. /* check slice group params */
  612. if (pps->numSliceGroups > 1)
  613. {
  614. if (pps->sliceGroupMapType == 0)
  615. {
  616. ASSERT(pps->runLength);
  617. for (i = 0; i < pps->numSliceGroups; i++)
  618. {
  619. if (pps->runLength[i] > picSize)
  620. return(HANTRO_NOK);
  621. }
  622. }
  623. else if (pps->sliceGroupMapType == 2)
  624. {
  625. ASSERT(pps->topLeft);
  626. ASSERT(pps->bottomRight);
  627. for (i = 0; i < pps->numSliceGroups-1; i++)
  628. {
  629. if (pps->topLeft[i] > pps->bottomRight[i] ||
  630. pps->bottomRight[i] >= picSize)
  631. return(HANTRO_NOK);
  632. if ( (pps->topLeft[i] % sps->picWidthInMbs) >
  633. (pps->bottomRight[i] % sps->picWidthInMbs) )
  634. return(HANTRO_NOK);
  635. }
  636. }
  637. else if (pps->sliceGroupMapType > 2 && pps->sliceGroupMapType < 6)
  638. {
  639. if (pps->sliceGroupChangeRate > picSize)
  640. return(HANTRO_NOK);
  641. }
  642. else if (pps->sliceGroupMapType == 6 &&
  643. pps->picSizeInMapUnits < picSize)
  644. return(HANTRO_NOK);
  645. }
  646. return(HANTRO_OK);
  647. }
  648. /*------------------------------------------------------------------------------
  649. Function: h264bsdValidParamSets
  650. Functional description:
  651. Check if any valid SPS/PPS combination exists in the storage.
  652. Function tries each PPS in the buffer and checks if corresponding
  653. SPS exists and calls CheckPps to determine if the PPS conforms
  654. to image dimensions of the SPS.
  655. Inputs:
  656. pStorage pointer to storage structure
  657. Outputs:
  658. HANTRO_OK there is at least one valid combination
  659. HANTRO_NOK no valid combinations found
  660. ------------------------------------------------------------------------------*/
  661. u32 h264bsdValidParamSets(storage_t *pStorage)
  662. {
  663. /* Variables */
  664. u32 i;
  665. /* Code */
  666. ASSERT(pStorage);
  667. for (i = 0; i < MAX_NUM_PIC_PARAM_SETS; i++)
  668. {
  669. if ( pStorage->pps[i] &&
  670. pStorage->sps[pStorage->pps[i]->seqParameterSetId] &&
  671. CheckPps(pStorage->pps[i],
  672. pStorage->sps[pStorage->pps[i]->seqParameterSetId]) ==
  673. HANTRO_OK)
  674. {
  675. return(HANTRO_OK);
  676. }
  677. }
  678. return(HANTRO_NOK);
  679. }