shithub: openh264

Download patch

ref: 09b45e3ef92ebd2c34675687f507afa8a3ef1469
parent: fb4f677f779904b23475a2e972642729006eaa50
parent: 8ad9e0b60d909a2803f42cb58f4bdfc43d22cab8
author: Ethan Hugg <[email protected]>
date: Fri Mar 7 06:02:02 EST 2014

Merge pull request #440 from licaiguo/refine-pps-sps

Refine pps sps

--- a/codec/decoder/core/src/au_parser.cpp
+++ b/codec/decoder/core/src/au_parser.cpp
@@ -174,21 +174,12 @@
 
   switch (pNalUnitHeader->eNalUnitType) {
   case NAL_UNIT_SEI:
-
-    if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) {
-      pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1;
-      pCtx->bAuReadyFlag = true;
-    }
-
-    break;
-
   case NAL_UNIT_SPS:
-
+  case NAL_UNIT_PPS:
     if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) {
       pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1;
       pCtx->bAuReadyFlag = true;
     }
-
     break;
 
   case NAL_UNIT_PREFIX:
@@ -768,6 +759,7 @@
 
 int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicWidth, int32_t* pPicHeight) {
   PBitStringAux pBs		= pBsAux;
+  SSubsetSps sTempSubsetSps;
   PSps pSps				= NULL;
   PSubsetSps pSubsetSps	= NULL;
   SNalUnitHeader* pNalHead = &pCtx->sCurNalHead;
@@ -779,12 +771,6 @@
   bool bConstraintSetFlags[6] = { false };
   const bool kbUseSubsetFlag   = IS_SUBSET_SPS_NAL (pNalHead->eNalUnitType);
 
-  if (kbUseSubsetFlag) {	// SubsetSps
-    pCtx->bSubspsExistAheadFlag	= true;
-  } else {	// Sps
-    pCtx->bSpsExistAheadFlag		= true;
-  }
-
   WELS_READ_VERIFY (BsGetBits (pBs, 8, &uiCode)); //profile_idc
   uiProfileIdc	= uiCode;
   WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //constraint_set0_flag
@@ -810,13 +796,13 @@
   iSpsId		= uiCode;
 
   if (kbUseSubsetFlag) {
-    pSubsetSps	= &pCtx->sSubsetSpsBuffer[iSpsId];
-    pSps		= &pSubsetSps->sSps;
     pCtx->bSubspsAvailFlags[iSpsId]	= false;
   } else {
-    pSps = &pCtx->sSpsBuffer[iSpsId];
     pCtx->bSpsAvailFlags[iSpsId] = false;
   }
+  pSubsetSps = &sTempSubsetSps;
+  pSps = &sTempSubsetSps.sSps;
+  memset (pSubsetSps, 0, sizeof(SSubsetSps));
   const SLevelLimits* pSLevelLimits = GetLevelLimits (uiLevelIdc, bConstraintSetFlags[3]);
   if (NULL == pSLevelLimits) {
     WelsLog (pCtx, WELS_LOG_WARNING, "ParseSps(): level_idx (%d).\n", uiLevelIdc);
@@ -995,9 +981,13 @@
   *pPicWidth	= pSps->iMbWidth << 4;
   *pPicHeight	= pSps->iMbHeight << 4;
   if (kbUseSubsetFlag) {
+    memcpy (&pCtx->sSubsetSpsBuffer[iSpsId], pSubsetSps, sizeof(SSubsetSps));
     pCtx->bSubspsAvailFlags[iSpsId]	= true;
+    pCtx->bSubspsExistAheadFlag	= true;
   } else {
+    memcpy (&pCtx->sSpsBuffer[iSpsId], pSps, sizeof(SSps));
     pCtx->bSpsAvailFlags[iSpsId] = true;
+    pCtx->bSpsExistAheadFlag		= true;
   }
   return 0;
 }
@@ -1019,6 +1009,7 @@
 int32_t ParsePps (PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux) {
 
   PPps pPps = NULL;
+  SPps sTempPps;
   uint32_t uiPpsId = 0;
   uint32_t iTmp;
   uint32_t uiCode;
@@ -1031,7 +1022,8 @@
   }
 
   pCtx->bPpsAvailFlags[uiPpsId] = false;
-  pPps = &pPpsList[uiPpsId];
+  pPps = &sTempPps;
+  memset (pPps, 0, sizeof(SPps));
 
   pPps->iPpsId = uiPpsId;
   WELS_READ_VERIFY (BsGetUe (pBsAux, &uiCode)); //seq_parameter_set_id
@@ -1113,6 +1105,7 @@
   WELS_READ_VERIFY (BsGetOneBit (pBsAux, &uiCode)); //redundant_pic_cnt_present_flag
   pPps->bRedundantPicCntPresentFlag           = !!uiCode;
 
+  memcpy (&pCtx->sPpsBuffer[uiPpsId], pPps, sizeof(SPps));
   pCtx->bPpsAvailFlags[uiPpsId] = true;
 
   return ERR_NONE;