ref: 72df20000b1d4e88884a313f33a4258ad9e4b379
parent: fd8d41dbb90f5446689c20bafd1bba2685328c86
parent: 6673a5f71e09526422deddb41fd3a6a7d31733af
author: dongzha <[email protected]>
date: Mon Sep 29 04:34:44 EDT 2014
Merge pull request #1391 from sijchen/modi_stra34 [Encoder] Fix a warning and refactor
--- a/codec/encoder/core/inc/picture.h
+++ b/codec/encoder/core/inc/picture.h
@@ -99,6 +99,27 @@
/*******************************for screen reference frames****************************/
SScreenBlockFeatureStorage* pScreenBlockFeatureStorage;
+
+ /*
+ * set picture as unreferenced
+ */
+ void SetUnref () {
+ if (NULL != this) {
+ iFramePoc = -1;
+ iFrameNum = -1;
+ uiTemporalId =
+ uiSpatialId =
+ iLongTermPicNum = -1;
+ bIsLongRef = false;
+ uiRecieveConfirmed = RECIEVE_FAILED;
+ iMarkFrameNum = -1;
+ bUsedAsRef = false;
+
+ if (NULL != pScreenBlockFeatureStorage)
+ pScreenBlockFeatureStorage->bRefBlockFeatureCalculated = false;
+ }
+ }
+
} SPicture;
/*
--- a/codec/encoder/core/inc/picture_handle.h
+++ b/codec/encoder/core/inc/picture_handle.h
@@ -62,12 +62,5 @@
*/
void FreePicture (CMemoryAlign* pMa, SPicture** ppPic);
-/*!
-* \brief exchange two picture pData planes
-* \param ppPic1 picture pointer to picture 1
-* \param ppPic2 picture pointer to picture 2
-* \return none
-*/
-void WelsExchangeSpatialPictures (SPicture** ppPic1, SPicture** ppPic2);
}
#endif//WELS_ENCODER_PICTURE_HANDLE_H__
--- a/codec/encoder/core/inc/ref_list_mgr_svc.h
+++ b/codec/encoder/core/inc/ref_list_mgr_svc.h
@@ -47,11 +47,6 @@
#include "codec_app_def.h"
namespace WelsEnc {
-typedef enum {
-RECIEVE_UNKOWN = 0,
-RECIEVE_SUCCESS = 1,
-RECIEVE_FAILED = 2,
-} LTR_MARKING_RECEIVE_STATE;
typedef enum {
LTR_DIRECT_MARK = 0,
--- a/codec/encoder/core/inc/wels_const.h
+++ b/codec/encoder/core/inc/wels_const.h
@@ -189,6 +189,12 @@
BLOCK_SIZE_ALL = 5
};
+typedef enum {
+RECIEVE_UNKOWN = 0,
+RECIEVE_SUCCESS = 1,
+RECIEVE_FAILED = 2,
+} LTR_MARKING_RECEIVE_STATE;
+
enum {
CUR_AU_IDX = 0, // index symbol for current access unit
SUC_AU_IDX = 1 // index symbol for successive access unit
--- a/codec/encoder/core/inc/wels_preprocess.h
+++ b/codec/encoder/core/inc/wels_preprocess.h
@@ -132,6 +132,14 @@
const int32_t kiDependencyId, const bool kbCalculateBGD);
int32_t UpdateBlockIdcForScreen (uint8_t* pCurBlockStaticPointer, const SPicture* kpRefPic, const SPicture* kpSrcPic);
+ SPicture* GetCurrentFrameFromOrigList (int32_t iDIdx) {
+ return m_pSpatialPic[iDIdx][0];
+ };
+ void UpdateSrcList (SPicture* pCurPicture, const int32_t kiCurDid, SPicture** pShortRefList,
+ const uint32_t kuiShortRefCount);
+ void UpdateSrcListLosslessScreenRefSelectionWithLtr (SPicture* pCurPicture, const int32_t kiCurDid,
+ const int32_t kuiMarkLongTermPicIdx, SPicture** pLongRefList);
+
private:
int32_t WelsPreprocessCreate();
int32_t WelsPreprocessDestroy();
@@ -160,8 +168,9 @@
ESceneChangeIdc DetectSceneChangeScreen (sWelsEncCtx* pCtx, SPicture* pCurPicture);
void InitPixMap (const SPicture* pPicture, SPixMap* pPixMap);
- void GetAvailableRefListLosslessScreenRefSelection (SPicture** pSrcPicList, uint8_t iCurTid, const int32_t iClosestLtrFrameNum,
- SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum);
+ void GetAvailableRefListLosslessScreenRefSelection (SPicture** pSrcPicList, uint8_t iCurTid,
+ const int32_t iClosestLtrFrameNum,
+ SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum);
void GetAvailableRefList (SPicture** pSrcPicList, uint8_t iCurTid, const int32_t iClosestLtrFrameNum,
SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum);
void InitRefJudgement (SRefJudgement* pRefJudgement);
@@ -172,6 +181,14 @@
SRefInfoParam* pRefSaved);
void SaveBestRefToVaa (SRefInfoParam& sRefSaved, SRefInfoParam* pVaaBestRef);
+ /*!
+ * \brief exchange two picture pData planes
+ * \param ppPic1 picture pointer to picture 1
+ * \param ppPic2 picture pointer to picture 2
+ * \return none
+ */
+ void WelsExchangeSpatialPictures (SPicture** ppPic1, SPicture** ppPic2);
+
private:
Scaled_Picture m_sScaledPicture;
SPicture* m_pLastSpatialPicture[MAX_DEPENDENCY_LAYER][2];
@@ -182,8 +199,9 @@
uint8_t m_uiSpatialPicNum[MAX_DEPENDENCY_LAYER];
public:
/* For Downsampling & VAA I420 based source pictures */
- SPicture* m_pSpatialPic[MAX_DEPENDENCY_LAYER][MAX_TEMPORAL_LEVEL + 1 +
- LONG_TERM_REF_NUM]; // need memory requirement with total number of (log2(uiGopSize)+1+1+long_term_ref_num)
+ SPicture* m_pSpatialPic[MAX_DEPENDENCY_LAYER][MAX_REF_PIC_COUNT + 1];
+ // need memory requirement with total number of num_of_ref + 1, "+1" is for current frame
+ int32_t m_iAvaliableRefInSpatialPicList;
};
--- a/codec/encoder/core/src/picture_handle.cpp
+++ b/codec/encoder/core/src/picture_handle.cpp
@@ -179,20 +179,6 @@
*ppPic = NULL;
}
}
-/*!
-* \brief exchange two picture pData planes
-* \param ppPic1 picture pointer to picture 1
-* \param ppPic2 picture pointer to picture 2
-* \return none
-*/
-void WelsExchangeSpatialPictures (SPicture** ppPic1, SPicture** ppPic2) {
- SPicture* tmp = *ppPic1;
-
- assert (*ppPic1 != *ppPic2);
-
- *ppPic1 = *ppPic2;
- *ppPic2 = tmp;
-}
} // namespace WelsEnc
--- a/codec/encoder/core/src/ref_list_mgr_svc.cpp
+++ b/codec/encoder/core/src/ref_list_mgr_svc.cpp
@@ -35,26 +35,7 @@
#include "utils.h"
#include "picture_handle.h"
namespace WelsEnc {
-/*
- * set picture as unreferenced
- */
-void SetUnref (SPicture* pRef) {
- if (NULL != pRef) {
- pRef->iFramePoc = -1;
- pRef->iFrameNum = -1;
- pRef->uiTemporalId =
- pRef->uiSpatialId =
- pRef->iLongTermPicNum = -1;
- pRef->bIsLongRef = false;
- pRef->uiRecieveConfirmed = RECIEVE_FAILED;
- pRef->iMarkFrameNum = -1;
- pRef->bUsedAsRef = false;
- if (NULL != pRef->pScreenBlockFeatureStorage)
- pRef->pScreenBlockFeatureStorage->bRefBlockFeatureCalculated = false;
- }
-}
-
/*
* reset LTR marking , recovery ,feedback state to default
*/
@@ -90,7 +71,7 @@
for (i = 0; i < pCtx->pSvcParam->iLTRRefNum + 1; i++)
pRefList->pLongRefList[i] = NULL;
for (i = 0; i < pCtx->pSvcParam->iNumRefFrame + 1; i++)
- SetUnref (pRefList->pRef[i]);
+ pRefList->pRef[i]->SetUnref ();
pRefList->uiLongRefCount = 0;
pRefList->uiShortRefCount = 0;
@@ -125,7 +106,7 @@
SPicture* pRef = pRefList->pLongRefList[i];
if (pRef != NULL && pRef->bUsedAsRef && pRef->bIsLongRef && (!pRef->bIsSceneLTR) &&
(pCtx->uiTemporalId < pRef->uiTemporalId || pCtx->bCurFrameMarkedAsSceneLtr)) {
- SetUnref (pRef);
+ pRef->SetUnref ();
DeleteLTRFromLongList (pCtx, i);
i--;
}
@@ -181,7 +162,7 @@
iMaxFrameNumPlus1) & (FRAME_NUM_EQUAL | FRAME_NUM_SMALLER))) {
WelsLog (pLogCtx, WELS_LOG_WARNING, "LTR ,invalid LTR delete ,long_term_idx = %d , iFrameNum =%d ",
pLongRefList[i]->iLongTermPicNum, pLongRefList[i]->iFrameNum);
- SetUnref (pLongRefList[i]);
+ pLongRefList[i]->SetUnref ();
DeleteLTRFromLongList (pCtx, i);
pLtr->bLTRMarkEnable = true;
if (pRefList->uiLongRefCount == 0) {
@@ -194,7 +175,7 @@
&& pLtr->iLTRMarkMode == LTR_DELAY_MARK) {
WelsLog (pLogCtx, WELS_LOG_WARNING, "LTR ,iMarkFrameNum invalid LTR delete ,long_term_idx = %d , iFrameNum =%d ",
pLongRefList[i]->iLongTermPicNum, pLongRefList[i]->iFrameNum);
- SetUnref (pLongRefList[i]);
+ pLongRefList[i]->SetUnref ();
DeleteLTRFromLongList (pCtx, i);
pLtr->bLTRMarkEnable = true;
if (pRefList->uiLongRefCount == 0) {
@@ -230,7 +211,7 @@
for (j = 0; j < pRefList->uiLongRefCount; j++) {
if (pLongRefList[j]->iLongTermPicNum != pLtr->iCurLtrIdx) {
- SetUnref (pLongRefList[j]);
+ pLongRefList[j]->SetUnref ();
DeleteLTRFromLongList (pCtx, j);
}
}
@@ -247,7 +228,7 @@
} else if (pLtr->uiLtrMarkState == LTR_MARKING_FAILED) {
for (i = 0; i < pRefList->uiLongRefCount; i++) {
if (pLongRefList[i]->iFrameNum == pLtr->iLtrMarkFbFrameNum) {
- SetUnref (pLongRefList[i]);
+ pLongRefList[i]->SetUnref ();
DeleteLTRFromLongList (pCtx, i);
break;
}
@@ -316,7 +297,7 @@
pLongRefList[0] = pShortRefList[i];
pRefList->uiLongRefCount++;
if (pRefList->uiLongRefCount > pCtx->pSvcParam->iLTRRefNum) {
- SetUnref (pRefList->pLongRefList[pRefList->uiLongRefCount - 1]);
+ pRefList->pLongRefList[pRefList->uiLongRefCount - 1]->SetUnref ();
DeleteLTRFromLongList (pCtx, pRefList->uiLongRefCount - 1);
}
DeleteSTRFromShortList (pCtx, i);
@@ -330,7 +311,7 @@
pCtx->pVaa->uiMarkLongTermPicIdx = pCtx->pDecPic->iLongTermPicNum;
if (pLongRefList[iLtrIdx] != NULL) {
- SetUnref (pLongRefList[iLtrIdx]);
+ pLongRefList[iLtrIdx]->SetUnref ();
DeleteLTRFromLongList (pCtx, iLtrIdx);
}
pLongRefList[iLtrIdx] = pCtx->pDecPic;
@@ -353,7 +334,7 @@
if (pRefList->pNextBuffer == NULL && pRefList->uiShortRefCount > 0) {
pRefList->pNextBuffer = pRefList->pShortRefList[pRefList->uiShortRefCount - 1];
- SetUnref (pRefList->pNextBuffer);
+ pRefList->pNextBuffer->SetUnref ();
}
pCtx->pDecPic = pRefList->pNextBuffer;
@@ -417,12 +398,12 @@
}
for (i = pRefList->uiShortRefCount - 1; i > 0; i--) {
- SetUnref (pRefList->pShortRefList[i]);
+ pRefList->pShortRefList[i]->SetUnref ();
DeleteSTRFromShortList (pCtx, i);
}
if (pRefList->uiShortRefCount > 0 && (pRefList->pShortRefList[0]->uiTemporalId > 0
|| pRefList->pShortRefList[0]->iFrameNum != pCtx->iFrameNum)) {
- SetUnref (pRefList->pShortRefList[0]);
+ pRefList->pShortRefList[0]->SetUnref ();
DeleteSTRFromShortList (pCtx, 0);
}
}
@@ -711,43 +692,6 @@
pOrigPic->iFrameAverageQp = pReconPic->iFrameAverageQp;
}
-static void UpdateSrcListLosslessScreenRefSelectionWithLtr (sWelsEncCtx* pCtx) {
- int32_t iDIdx = pCtx->uiDependencyId;
- SPicture** pLongRefList = pCtx->ppRefPicListExt[iDIdx]->pLongRefList;
- SPicture** pLongRefSrcList = &pCtx->pVpp->m_pSpatialPic[iDIdx][0];
- for (int32_t i = 0; i < MAX_REF_PIC_COUNT; ++i) {
- if (NULL == pLongRefSrcList[i + 1] || (NULL != pLongRefList[i] && pLongRefList[i]->bUsedAsRef
- && pLongRefList[i]->bIsLongRef)) {
- continue;
- } else {
- SetUnref (pLongRefSrcList[i + 1]);
- }
- }
- WelsExchangeSpatialPictures (&pCtx->pVpp->m_pSpatialPic[iDIdx][0],
- &pCtx->pVpp->m_pSpatialPic[iDIdx][1 + pCtx->pVaa->uiMarkLongTermPicIdx]);
-}
-
-static void UpdateSrcList (sWelsEncCtx* pCtx) {
- int32_t iDIdx = pCtx->uiDependencyId;
- SPicture** pShortRefList = pCtx->ppRefPicListExt[iDIdx]->pShortRefList;
- const uint32_t kuiShortRefCount = pCtx->ppRefPicListExt[iDIdx]->uiShortRefCount;
- SPicture** pRefSrcList = &pCtx->pVpp->m_pSpatialPic[iDIdx][0];
-
- //pRefSrcList[0] is for current frame
- if (pCtx->eSliceType == P_SLICE && pCtx->uiTemporalId != 0) {
- for (int iRefIdx = kuiShortRefCount - 1; iRefIdx >= 0; --iRefIdx) {
- WelsExchangeSpatialPictures (&pRefSrcList[iRefIdx + 1],
- &pRefSrcList[iRefIdx]);
- }
- } else {
- WelsExchangeSpatialPictures (&pRefSrcList[0], &pRefSrcList[1]);
- for (int32_t i = MAX_SHORT_REF_COUNT - 1; i > 0 ; --i) {
- if (pRefSrcList[i + 1] != NULL) {
- SetUnref (pRefSrcList[i + 1]);
- }
- }
- }
-}
static void UpdateSrcPicListLosslessScreenRefSelectionWithLtr (void* pEncCtx) {
sWelsEncCtx* pCtx = (sWelsEncCtx*)pEncCtx;
int32_t iDIdx = pCtx->uiDependencyId;
@@ -754,10 +698,9 @@
//update info in src list
UpdateOriginalPicInfo (pCtx->pEncPic, pCtx->pDecPic);
PrefetchNextBuffer (pCtx);
- UpdateSrcListLosslessScreenRefSelectionWithLtr (pCtx);
- SetUnref (pCtx->pVpp->m_pSpatialPic[iDIdx][0]);
+ pCtx->pVpp->UpdateSrcListLosslessScreenRefSelectionWithLtr (pCtx->pEncPic, iDIdx, pCtx->pVaa->uiMarkLongTermPicIdx, pCtx->ppRefPicListExt[iDIdx]->pLongRefList);
}
-
+
static void UpdateSrcPicList (void* pEncCtx) {
sWelsEncCtx* pCtx = (sWelsEncCtx*)pEncCtx;
int32_t iDIdx = pCtx->uiDependencyId;
@@ -764,9 +707,9 @@
//update info in src list
UpdateOriginalPicInfo (pCtx->pEncPic, pCtx->pDecPic);
PrefetchNextBuffer (pCtx);
- UpdateSrcList (pCtx);
- SetUnref (pCtx->pVpp->m_pSpatialPic[iDIdx][0]);
+ pCtx->pVpp->UpdateSrcList (pCtx->pEncPic, iDIdx, pCtx->ppRefPicListExt[iDIdx]->pShortRefList, pCtx->ppRefPicListExt[iDIdx]->uiShortRefCount);
}
+
bool WelsUpdateRefListScreen (void* pEncCtx) {
sWelsEncCtx* pCtx = (sWelsEncCtx*)pEncCtx;
SRefList* pRefList = pCtx->ppRefPicListExt[pCtx->uiDependencyId];
--- a/codec/encoder/core/src/wels_preprocess.cpp
+++ b/codec/encoder/core/src/wels_preprocess.cpp
@@ -185,6 +185,8 @@
if (WelsPreprocessReset (pCtx) != 0)
return -1;
+ m_iAvaliableRefInSpatialPicList = pSvcParam->iNumRefFrame;
+
m_bInitDone = true;
}
@@ -861,8 +863,7 @@
void CWelsPreProcess::GetAvailableRefListLosslessScreenRefSelection (SPicture** pSrcPicList, uint8_t iCurTid,
const int32_t iClosestLtrFrameNum,
SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum) {
- SWelsSvcCodingParam* pSvcParam = m_pEncCtx->pSvcParam;
- const int32_t iSourcePicNum = pSvcParam->iNumRefFrame;
+ const int32_t iSourcePicNum = m_iAvaliableRefInSpatialPicList;
if (0 >= iSourcePicNum) {
iAvailableRefNum = 0;
iAvailableSceneRefNum = 0;
@@ -911,8 +912,7 @@
void CWelsPreProcess::GetAvailableRefList (SPicture** pSrcPicList, uint8_t iCurTid, const int32_t iClosestLtrFrameNum,
SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum) {
- SWelsSvcCodingParam* pSvcParam = m_pEncCtx->pSvcParam;
- const int32_t iSourcePicNum = pSvcParam->iNumRefFrame;
+ const int32_t iSourcePicNum = m_iAvaliableRefInSpatialPicList;
if (0 >= iSourcePicNum) {
iAvailableRefNum = 0;
iAvailableSceneRefNum = 0;
@@ -1178,6 +1178,60 @@
return 0;
}
return iRet;
+}
+
+/*!
+* \brief exchange two picture pData planes
+* \param ppPic1 picture pointer to picture 1
+* \param ppPic2 picture pointer to picture 2
+* \return none
+*/
+void CWelsPreProcess::WelsExchangeSpatialPictures (SPicture** ppPic1, SPicture** ppPic2) {
+ SPicture* tmp = *ppPic1;
+
+ assert (*ppPic1 != *ppPic2);
+
+ *ppPic1 = *ppPic2;
+ *ppPic2 = tmp;
+}
+
+void CWelsPreProcess::UpdateSrcListLosslessScreenRefSelectionWithLtr (SPicture* pCurPicture, const int32_t kiCurDid, const int32_t kuiMarkLongTermPicIdx, SPicture** pLongRefList) {
+ SPicture** pLongRefSrcList = &m_pSpatialPic[kiCurDid][0];
+ for (int32_t i = 0; i < MAX_REF_PIC_COUNT; ++i) {
+ if (NULL == pLongRefSrcList[i + 1] || (NULL != pLongRefList[i] && pLongRefList[i]->bUsedAsRef
+ && pLongRefList[i]->bIsLongRef)) {
+ continue;
+ } else {
+ pLongRefSrcList[i + 1]->SetUnref ();
+ }
+ }
+ WelsExchangeSpatialPictures (&m_pSpatialPic[kiCurDid][0],
+ &m_pSpatialPic[kiCurDid][1 + kuiMarkLongTermPicIdx]);
+ m_iAvaliableRefInSpatialPicList = MAX_REF_PIC_COUNT;
+ (GetCurrentFrameFromOrigList(kiCurDid))->SetUnref ();
+}
+void CWelsPreProcess::UpdateSrcList (SPicture* pCurPicture, const int32_t kiCurDid, SPicture** pShortRefList, const uint32_t kuiShortRefCount) {
+ SPicture** pRefSrcList = &m_pSpatialPic[kiCurDid][0];
+
+ //pRefSrcList[0] is for current frame
+ if (pCurPicture->bUsedAsRef || pCurPicture->bIsLongRef) {
+ if (pCurPicture->iPictureType == P_SLICE && pCurPicture->uiTemporalId != 0 ) {
+ for (int iRefIdx = kuiShortRefCount - 1; iRefIdx >= 0; --iRefIdx) {
+ WelsExchangeSpatialPictures (&pRefSrcList[iRefIdx + 1],
+ &pRefSrcList[iRefIdx]);
+ }
+ m_iAvaliableRefInSpatialPicList = kuiShortRefCount;
+ } else {
+ WelsExchangeSpatialPictures (&pRefSrcList[0], &pRefSrcList[1]);
+ for (int32_t i = MAX_SHORT_REF_COUNT - 1; i > 0 ; --i) {
+ if (pRefSrcList[i + 1] != NULL) {
+ pRefSrcList[i + 1]->SetUnref ();
+ }
+ }
+ m_iAvaliableRefInSpatialPicList = 1;
+ }
+ }
+ (GetCurrentFrameFromOrigList(kiCurDid))->SetUnref ();
}
//TODO: may opti later