ref: 0a5024d176e0d12841cc39156d0aeb6f31359544
parent: c17994c6bf7d282924046b95bf7144738693f818
author: volvet <qizh@cisco.com>
date: Mon Feb 17 05:24:56 EST 2014
move alloc spatial picture and free spatial picture to CWelsPreProcess
--- a/codec/encoder/core/inc/wels_preprocess.h
+++ b/codec/encoder/core/inc/wels_preprocess.h
@@ -108,6 +108,8 @@
public:
int32_t WelsPreprocessReset (sWelsEncCtx* pEncCtx);
+ int32_t AllocSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam);
+ void FreeSpatialPictures (sWelsEncCtx* pCtx);
int32_t WelsPreprocessStep1 (sWelsEncCtx* pEncCtx, const SSourcePicture** kppSrcPicList, const int32_t kiConfiguredLayerNum);
int32_t WelsPreprocessStep3 (sWelsEncCtx* pEncCtx, const int32_t kiDIdx);
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -570,57 +570,6 @@
return 0;
}
-/*!
- * \brief alloc spatial layers pictures (I420 based source pictures)
- */
-int32_t AllocSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam) {
- CMemoryAlign* pMa = pCtx->pMemAlign;
- const int32_t kiDlayerCount = pParam->iNumDependencyLayer;
- int32_t iDlayerIndex = 0;
-
- // spatial pictures
- iDlayerIndex = 0;
- do {
- const int32_t kiPicWidth = pParam->sDependencyLayers[iDlayerIndex].iFrameWidth;
- const int32_t kiPicHeight = pParam->sDependencyLayers[iDlayerIndex].iFrameHeight;
- const uint8_t kuiLayerInTemporal = 2 + WELS_MAX (pParam->sDependencyLayers[iDlayerIndex].iHighestTemporalId, 1);
- const uint8_t kuiRefNumInTemporal = kuiLayerInTemporal + pParam->iLTRRefNum;
- uint8_t i = 0;
-
- do {
- SPicture* pPic = AllocPicture (pMa, kiPicWidth, kiPicHeight, false);
- WELS_VERIFY_RETURN_IF(1, (NULL == pPic))
- pCtx->pSpatialPic[iDlayerIndex][i] = pPic;
- ++ i;
- } while (i < kuiRefNumInTemporal);
-
- pCtx->uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
- pCtx->uiSpatialPicNum[iDlayerIndex] = kuiRefNumInTemporal;
- ++ iDlayerIndex;
- } while (iDlayerIndex < kiDlayerCount);
-
- return 0;
-}
-
-void FreeSpatialPictures (sWelsEncCtx* pCtx) {
- CMemoryAlign* pMa = pCtx->pMemAlign;
- int32_t j = 0;
- while (j < pCtx->pSvcParam->iNumDependencyLayer) {
- uint8_t i = 0;
- uint8_t uiRefNumInTemporal = pCtx->uiSpatialPicNum[j];
-
- while (i < uiRefNumInTemporal) {
- if (NULL != pCtx->pSpatialPic[j][i]) {
- FreePicture (pMa, &pCtx->pSpatialPic[j][i]);
- }
- ++ i;
- }
- pCtx->uiSpatialLayersInTemporal[j] = 0;
- ++ j;
- }
-
-}
-
static void InitMbInfo (sWelsEncCtx* pEnc, SMB* pList, SDqLayer* pLayer, const int32_t kiDlayerId,
const int32_t kiMaxMbNum) {
int32_t iMbWidth = pLayer->iMbWidth;
@@ -846,12 +795,6 @@
++ iDlayerIndex;
}
- // for I420 based source spatial pictures
- if (AllocSpatialPictures (*ppCtx, pParam)) {
- FreeMemorySvc (ppCtx);
- return 1;
- }
-
iDlayerIndex = 0;
while (iDlayerIndex < iDlayerCount) {
SDqLayer* pDqLayer = NULL;
@@ -1702,8 +1645,6 @@
pMa->WelsFree (pCtx->ppDqLayerList, "ppDqLayerList");
pCtx->ppDqLayerList = NULL;
}
- FreeSpatialPictures (pCtx);
-
// reference picture list extension
if (NULL != pCtx->ppRefPicListExt && pParam != NULL) {
ilayer = 0;
@@ -2125,10 +2066,16 @@
pCtx->pVpp = new CWelsPreProcess (pCtx);
if (pCtx->pVpp == NULL) {
+ iRet = 1;
WelsLog (pCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pOut of memory in case new CWelsPreProcess().\n");
FreeMemorySvc (&pCtx);
return iRet;
}
+ if( (iRet = pCtx->pVpp->AllocSpatialPictures(pCtx, pCtx->pSvcParam)) != 0 ){
+ WelsLog( pCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pVPP alloc spatial pictures failed\n");
+ FreeMemorySvc(&pCtx);
+ return iRet;
+ }
#if defined(MEMORY_MONITOR)
WelsLog (pCtx, WELS_LOG_INFO, "WelsInitEncoderExt() exit, overall memory usage: %llu bytes\n",
@@ -2285,6 +2232,7 @@
#endif//MT_ENABLED
if ((*ppCtx)->pVpp) {
+ (*ppCtx)->pVpp->FreeSpatialPictures(*ppCtx);
delete (*ppCtx)->pVpp;
(*ppCtx)->pVpp = NULL;
}
--- a/codec/encoder/core/src/wels_preprocess.cpp
+++ b/codec/encoder/core/src/wels_preprocess.cpp
@@ -260,6 +260,53 @@
return iRet;
}
+int32_t CWelsPreProcess::AllocSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam) {
+ CMemoryAlign* pMa = pCtx->pMemAlign;
+ const int32_t kiDlayerCount = pParam->iNumDependencyLayer;
+ int32_t iDlayerIndex = 0;
+
+ // spatial pictures
+ iDlayerIndex = 0;
+ do {
+ const int32_t kiPicWidth = pParam->sDependencyLayers[iDlayerIndex].iFrameWidth;
+ const int32_t kiPicHeight = pParam->sDependencyLayers[iDlayerIndex].iFrameHeight;
+ const uint8_t kuiLayerInTemporal = 2 + WELS_MAX (pParam->sDependencyLayers[iDlayerIndex].iHighestTemporalId, 1);
+ const uint8_t kuiRefNumInTemporal = kuiLayerInTemporal + pParam->iLTRRefNum;
+ uint8_t i = 0;
+
+ do {
+ SPicture* pPic = AllocPicture (pMa, kiPicWidth, kiPicHeight, false);
+ WELS_VERIFY_RETURN_IF(1, (NULL == pPic))
+ pCtx->pSpatialPic[iDlayerIndex][i] = pPic;
+ ++ i;
+ } while (i < kuiRefNumInTemporal);
+
+ pCtx->uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
+ pCtx->uiSpatialPicNum[iDlayerIndex] = kuiRefNumInTemporal;
+ ++ iDlayerIndex;
+ } while (iDlayerIndex < kiDlayerCount);
+
+ return 0;
+}
+
+void CWelsPreProcess::FreeSpatialPictures (sWelsEncCtx* pCtx) {
+ CMemoryAlign* pMa = pCtx->pMemAlign;
+ int32_t j = 0;
+ while (j < pCtx->pSvcParam->iNumDependencyLayer) {
+ uint8_t i = 0;
+ uint8_t uiRefNumInTemporal = pCtx->uiSpatialPicNum[j];
+
+ while (i < uiRefNumInTemporal) {
+ if (NULL != pCtx->pSpatialPic[j][i]) {
+ FreePicture (pMa, &pCtx->pSpatialPic[j][i]);
+ }
+ ++ i;
+ }
+ pCtx->uiSpatialLayersInTemporal[j] = 0;
+ ++ j;
+ }
+}
+
int32_t CWelsPreProcess::WelsPreprocessStep1 (sWelsEncCtx* pCtx, const SSourcePicture** kppSrcPicList,
const int32_t kiConfiguredLayerNum) {
SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;