shithub: openh264

Download patch

ref: 336b2d153731b12d5e2daef54be2e65b86b1ee55
parent: 53c14dccf0b24a7d42009ebbde5c7094fa4f59d6
parent: cdd410ca66831751b6d23d7759c53c2b3e6e7fd3
author: sijchen <sijchen@cisco.com>
date: Mon Nov 24 06:27:38 EST 2014

Merge pull request #1542 from sijchen/review

[Encoder] refactor Sps generation: passed review at https://rbcommons.com/s/OpenH264/r/930/

--- a/codec/encoder/core/inc/au_set.h
+++ b/codec/encoder/core/inc/au_set.h
@@ -106,7 +106,8 @@
  */
 int32_t WelsInitSps (SWelsSPS* pSps, SSpatialLayerConfig* pLayerParam, SSpatialLayerInternal* pLayerParamInternal,
                      const uint32_t kuiIntraPeriod, const int32_t kiNumRefFrame,
-                     const uint32_t kiSpsId, const bool kbEnableFrameCropping, bool bEnableRc);
+                     const uint32_t kiSpsId, const bool kbEnableFrameCropping, bool bEnableRc,
+                     const int32_t kiDlayerCount);
 
 /*!
  * \brief	initialize subset pSps based on configurable parameters in svc
--- a/codec/encoder/core/src/au_set.cpp
+++ b/codec/encoder/core/src/au_set.cpp
@@ -347,7 +347,8 @@
 }
 int32_t WelsInitSps (SWelsSPS* pSps, SSpatialLayerConfig* pLayerParam, SSpatialLayerInternal* pLayerParamInternal,
                      const uint32_t kuiIntraPeriod, const int32_t kiNumRefFrame,
-                     const uint32_t kuiSpsId, const bool kbEnableFrameCropping, bool bEnableRc) {
+                     const uint32_t kuiSpsId, const bool kbEnableFrameCropping, bool bEnableRc,
+                     const int32_t kiDlayerCount) {
   memset (pSps, 0, sizeof (SWelsSPS));
 
   pSps->uiSpsId		= kuiSpsId;
@@ -383,6 +384,16 @@
     pSps->iLevelIdc = 11;
     pSps->bConstraintSet3Flag = true;
   }
+
+  if (pLayerParam->uiProfileIdc == PRO_BASELINE) {
+    pSps->bConstraintSet0Flag = true;
+  }
+  if (pLayerParam->uiProfileIdc <= PRO_MAIN) {
+    pSps->bConstraintSet1Flag = true;
+  }
+  if (kiDlayerCount > 1) {
+    pSps->bConstraintSet2Flag = true;
+  }
   return 0;
 }
 
@@ -396,7 +407,7 @@
   memset (pSubsetSps, 0, sizeof (SSubsetSps));
 
   WelsInitSps (pSps, pLayerParam, pLayerParamInternal, kuiIntraPeriod, kiNumRefFrame, kuiSpsId, kbEnableFrameCropping,
-               bEnableRc);
+               bEnableRc, 1);
 
   pSps->uiProfileIdc	= (pLayerParam->uiProfileIdc >= PRO_SCALABLE_BASELINE) ? pLayerParam->uiProfileIdc :
                         PRO_SCALABLE_BASELINE;
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -763,7 +763,36 @@
   }
 }
 
+int32_t WelsGenerateNewSps (sWelsEncCtx* pCtx, const bool kbUseSubsetSps, const int32_t iDlayerIndex,
+                            const int32_t iDlayerCount, const int32_t kiSpsId,
+                            SWelsSPS*& pSps, SSubsetSps*& pSubsetSps) {
+  int32_t iRet = 0;
 
+  if (!kbUseSubsetSps) {
+    pSps	= & (pCtx->pSpsArray[kiSpsId]);
+  } else {
+    pSubsetSps	= & (pCtx->pSubsetArray[kiSpsId]);
+    pSps			= &pSubsetSps->pSps;
+  }
+
+  SWelsSvcCodingParam* pParam	= pCtx->pSvcParam;
+  SSpatialLayerConfig* pDlayerParam	= &pParam->sSpatialLayers[iDlayerIndex];
+  // Need port pSps/pPps initialization due to spatial scalability changed
+  if (!kbUseSubsetSps) {
+    iRet = WelsInitSps (pSps, pDlayerParam, &pParam->sDependencyLayers[iDlayerIndex], pParam->uiIntraPeriod,
+                        pParam->iMaxNumRefFrame,
+                        kiSpsId, pParam->bEnableFrameCroppingFlag, pParam->iRCMode != RC_OFF_MODE, iDlayerCount);
+
+
+
+  } else {
+    iRet = WelsInitSubsetSps (pSubsetSps, pDlayerParam, &pParam->sDependencyLayers[iDlayerIndex], pParam->uiIntraPeriod,
+                              pParam->iMaxNumRefFrame,
+                              kiSpsId, pParam->bEnableFrameCroppingFlag, pParam->iRCMode != RC_OFF_MODE);
+  }
+  return iRet;
+}
+
 /*!
  * \brief	initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available
  * \pParam	pCtx			sWelsEncCtx*
@@ -952,35 +981,11 @@
     SSpatialLayerConfig* pDlayerParam	= &pParam->sSpatialLayers[iDlayerIndex];
 
     pDqIdc->uiSpatialId	= iDlayerIndex;
-    pPps	= & (*ppCtx)->pPPSArray[iPpsId];
-    if (!bUseSubsetSps) {
-      pSps	= & (*ppCtx)->pSpsArray[iSpsId];
-    } else {
-      pSubsetSps	= & (*ppCtx)->pSubsetArray[iSpsId];
-      pSps			= &pSubsetSps->pSps;
-    }
 
-    // Need port pSps/pPps initialization due to spatial scalability changed
-    if (!bUseSubsetSps) {
-      WelsInitSps (pSps, pDlayerParam, &pParam->sDependencyLayers[iDlayerIndex], pParam->uiIntraPeriod,
-                   pParam->iMaxNumRefFrame,
-                   iSpsId, pParam->bEnableFrameCroppingFlag, pParam->iRCMode != RC_OFF_MODE);
+    WelsGenerateNewSps (*ppCtx, bUseSubsetSps, iDlayerIndex,
+                        iDlayerCount, iSpsId, pSps, pSubsetSps);
 
-      if (pDlayerParam->uiProfileIdc == PRO_BASELINE) {
-        pSps->bConstraintSet0Flag = true;
-      }
-      if (pDlayerParam->uiProfileIdc <= PRO_MAIN) {
-        pSps->bConstraintSet1Flag = true;
-      }
-      if (iDlayerCount > 1) {
-        pSps->bConstraintSet2Flag = true;
-      }
-    } else {
-      WelsInitSubsetSps (pSubsetSps, pDlayerParam, &pParam->sDependencyLayers[iDlayerIndex], pParam->uiIntraPeriod,
-                         pParam->iMaxNumRefFrame,
-                         iSpsId, pParam->bEnableFrameCroppingFlag, pParam->iRCMode != RC_OFF_MODE);
-    }
-
+    pPps	= & (*ppCtx)->pPPSArray[iPpsId];
     // initialize pPps
     WelsInitPps (pPps, pSps, pSubsetSps, iPpsId, true, bUseSubsetSps, pParam->iEntropyCodingModeFlag != 0);