shithub: openh264

Download patch

ref: f10f6a788f3258a1321a38405327f206e648073c
parent: 292d2511e2f91ffc00a1b9addf0876a0bcad271e
parent: f2c1395ab608b70156d3d9d2278362e313786f49
author: ruil2 <ruil2@cisco.com>
date: Wed Oct 29 05:28:06 EDT 2014

Merge pull request #1467 from mstorsjo/cabac-stash-fix

Don't stash the cabac state into the SBitStringAux buffer

--- a/codec/encoder/core/inc/wels_func_ptr_def.h
+++ b/codec/encoder/core/inc/wels_func_ptr_def.h
@@ -202,8 +202,8 @@
 typedef  int32_t (*PCavlcParamCalFunc) (int16_t* pCoff, uint8_t* pRun, int16_t* pLevel, int32_t* pTotalCoeffs,
                                         int32_t iEndIdx);
 typedef int32_t (*PWelsSpatialWriteMbSyn) (void* pCtx, SSlice* pSlice, SMB* pCurMb);
-typedef void (*PStashMBStatus) (SDynamicSlicingStack* pDss, void* pBuffer, SSlice* pSlice, int32_t iMbSkipRun);
-typedef int32_t (*PStashPopMBStatus) (SDynamicSlicingStack* pDss, void* pBuffer, SSlice* pSlice);
+typedef void (*PStashMBStatus) (SDynamicSlicingStack* pDss, SSlice* pSlice, int32_t iMbSkipRun);
+typedef int32_t (*PStashPopMBStatus) (SDynamicSlicingStack* pDss, SSlice* pSlice);
 
 struct TagWelsFuncPointerList {
   SExpandPicFunc sExpandPicFunc;
--- a/codec/encoder/core/src/set_mb_syn_cavlc.cpp
+++ b/codec/encoder/core/src/set_mb_syn_cavlc.cpp
@@ -199,8 +199,8 @@
   return ENC_RETURN_SUCCESS;
 }
 
-void StashMBStatusCavlc (SDynamicSlicingStack* pDss, void* pBuffer, SSlice* pSlice, int32_t iMbSkipRun) {
-  SBitStringAux* pBs = (SBitStringAux*)pBuffer;
+void StashMBStatusCavlc (SDynamicSlicingStack* pDss, SSlice* pSlice, int32_t iMbSkipRun) {
+  SBitStringAux* pBs = pSlice->pSliceBsa;
   pDss->pBsStackBufPtr	= pBs->pBufPtr;
   pDss->uiBsStackCurBits	= pBs->uiCurBits;
   pDss->iBsStackLeftBits	= pBs->iLeftBits;
@@ -207,8 +207,8 @@
   pDss->uiLastMbQp =  pSlice->uiLastMbQp;
   pDss->iMbSkipRunStack = iMbSkipRun;
 }
-int32_t StashPopMBStatusCavlc (SDynamicSlicingStack* pDss, void* pBuffer, SSlice* pSlice) {
-  SBitStringAux* pBs = (SBitStringAux*)pBuffer;
+int32_t StashPopMBStatusCavlc (SDynamicSlicingStack* pDss, SSlice* pSlice) {
+  SBitStringAux* pBs = pSlice->pSliceBsa;
   pBs->pBufPtr		= pDss->pBsStackBufPtr;
   pBs->uiCurBits	= pDss->uiBsStackCurBits;
   pBs->iLeftBits	= pDss->iBsStackLeftBits;
@@ -215,14 +215,14 @@
   pSlice->uiLastMbQp = pDss->uiLastMbQp;
   return pDss->iMbSkipRunStack;
 }
-void StashMBStatusCabac (SDynamicSlicingStack* pDss, void* pBuffer, SSlice* pSlice, int32_t iMbSkipRun) {
-  SCabacCtx* pCtx = (SCabacCtx*)pBuffer;
+void StashMBStatusCabac (SDynamicSlicingStack* pDss, SSlice* pSlice, int32_t iMbSkipRun) {
+  SCabacCtx* pCtx = &pSlice->sCabacCtx;
   memcpy (&pDss->sStoredCabac, pCtx, sizeof (SCabacCtx));
   pDss->uiLastMbQp =  pSlice->uiLastMbQp;
   pDss->iMbSkipRunStack = iMbSkipRun;
 }
-int32_t StashPopMBStatusCabac (SDynamicSlicingStack* pDss, void* pBuffer, SSlice* pSlice) {
-  SCabacCtx* pCtx = (SCabacCtx*)pBuffer;
+int32_t StashPopMBStatusCabac (SDynamicSlicingStack* pDss, SSlice* pSlice) {
+  SCabacCtx* pCtx = &pSlice->sCabacCtx;
   memcpy (pCtx, &pDss->sStoredCabac, sizeof (SCabacCtx));
   pSlice->uiLastMbQp = pDss->uiLastMbQp;
   return pDss->iMbSkipRunStack;
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -493,13 +493,12 @@
 
   SWelsMD sMd;
   int32_t iEncReturn = ENC_RETURN_SUCCESS;
-  SBitStringAux* pBs = pSlice->pSliceBsa;
   SDynamicSlicingStack sDss;
   if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) {
     WelsInitSliceCabac (pEncCtx, pSlice);
   }
   for (; ;) {
-    pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, 0);
+    pEncCtx->pFuncList->pfStashMBStatus (&sDss, pSlice, 0);
     iCurMbIdx	= iNextMbIdx;
     pCurMb = &pMbList[ iCurMbIdx ];
 
@@ -514,7 +513,7 @@
 
     iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
     if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
-      pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
+      pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pSlice);
       UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
       goto TRY_REENCODING;
     }
@@ -567,7 +566,7 @@
     iCurMbIdx	= iNextMbIdx;
     pCurMb = &pMbList[ iCurMbIdx ];
 
-    pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, 0);
+    pEncCtx->pFuncList->pfStashMBStatus (&sDss, pSlice, 0);
     pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);
     // if already reaches the largest number of slices, set QPs to the upper bound
     if (pSlice->bDynamicSlicingSliceSizeCtrlFlag) {
@@ -583,7 +582,7 @@
 
     iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
     if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
-      pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
+      pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pSlice);
       UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
       goto TRY_REENCODING;
     }
@@ -593,7 +592,7 @@
     sDss.iCurrentPos = BsGetBitsPos (pBs);
 
     if (DynSlcJudgeSliceBoundaryStepBack (pEncCtx, pSlice, pSliceCtx, pCurMb, &sDss)) { //islice
-      pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
+      pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pSlice);
       pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx -
           1;	// update pLastCodedMbIdxOfPartition, need to -1 due to stepping back
       ++ pCurLayer->pNumSliceCodedOfPartition[kiPartitionId];
@@ -954,7 +953,7 @@
   }
   pSlice->iMbSkipRun = 0;
   for (;;) {
-    pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, pSlice->iMbSkipRun);
+    pEncCtx->pFuncList->pfStashMBStatus (&sDss, pSlice, pSlice->iMbSkipRun);
     //point to current pMb
     iCurMbIdx	= iNextMbIdx;
     pCurMb = &pMbList[ iCurMbIdx ];
@@ -985,7 +984,7 @@
 
     iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
     if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
-      pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
+      pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pSlice);
       UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
       goto TRY_REENCODING;
     }
@@ -1050,7 +1049,7 @@
   for (;;) {
     //DYNAMIC_SLICING_ONE_THREAD - MultiD
     //stack pBs pointer
-    pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, pSlice->iMbSkipRun);
+    pEncCtx->pFuncList->pfStashMBStatus (&sDss, pSlice, pSlice->iMbSkipRun);
 
     //point to current pMb
     iCurMbIdx	= iNextMbIdx;
@@ -1091,7 +1090,7 @@
 
     iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
     if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
-      pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
+      pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pSlice);
       UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
       goto TRY_REENCODING;
     }
@@ -1102,7 +1101,7 @@
     //DYNAMIC_SLICING_ONE_THREAD - MultiD
     sDss.iCurrentPos = BsGetBitsPos (pBs);
     if (DynSlcJudgeSliceBoundaryStepBack (pEncCtx, pSlice, pSliceCtx, pCurMb, &sDss)) {
-      pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
+      pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pSlice);
       pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx -
           1;	// update pLastCodedMbIdxOfPartition, need to -1 due to stepping back
       ++ pCurLayer->pNumSliceCodedOfPartition[kiPartitionId];