shithub: openh264

Download patch

ref: 1888fba3360a7e2824b918e61960b81838edd47a
parent: d84d739ec88fb445a5d2d8af109642dba77c04c6
author: Martin Storsjö <[email protected]>
date: Thu Jun 26 10:57:06 EDT 2014

Move pfCavlcParamCal into the function pointer list

This avoids using a global variable for this function.

--- a/codec/encoder/core/inc/set_mb_syn_cavlc.h
+++ b/codec/encoder/core/inc/set_mb_syn_cavlc.h
@@ -43,6 +43,7 @@
 
 #include "typedefs.h"
 #include "bit_stream.h"
+#include "wels_func_ptr_def.h"
 
 namespace WelsSVCEnc {
 
@@ -59,16 +60,6 @@
 
 #define LUMA_DC_AC    0x04
 
-typedef  int32_t (*PCavlcParamCalFunc) (int16_t* pCoff, uint8_t* pRun, int16_t* pLevel, int32_t* pTotalCoeffs,
-                                        int32_t iEndIdx);
-
-typedef  struct TagCoeffFunc {
-PCavlcParamCalFunc    pfCavlcParamCal;
-} SCoeffFunc;
-
-/*  For CAVLC   */
-extern SCoeffFunc    sCoeffFunc;
-
 typedef struct TagCavlcTableItem {
 uint16_t uiBits;
 uint8_t  uiLen;
@@ -75,9 +66,10 @@
 uint8_t  uiSuffixLength;
 } SCavlcTableItem;
 
-void  InitCoeffFunc (const uint32_t uiCpuFlag);
+void  InitCoeffFunc (SWelsFuncPtrList* pFuncList, const uint32_t uiCpuFlag);
 
-int32_t  WriteBlockResidualCavlc (int16_t* pCoffLevel, int32_t iEndIdx, int32_t iCalRunLevelFlag,
+int32_t  WriteBlockResidualCavlc (SWelsFuncPtrList* pFuncList, int16_t* pCoffLevel, int32_t iEndIdx,
+                                  int32_t iCalRunLevelFlag,
                                   int32_t iResidualProperty, int8_t iNC, SBitStringAux* pBs);
 
 #if defined(__cplusplus)
--- a/codec/encoder/core/inc/svc_set_mb_syn_cavlc.h
+++ b/codec/encoder/core/inc/svc_set_mb_syn_cavlc.h
@@ -50,7 +50,7 @@
 
 namespace WelsSVCEnc {
 
-int32_t WelsWriteMbResidual (SMbCache* sMbCacheInfo, SMB* pCurMb, SBitStringAux* pBs);
+int32_t WelsWriteMbResidual (SWelsFuncPtrList* pFuncList, SMbCache* sMbCacheInfo, SMB* pCurMb, SBitStringAux* pBs);
 
 void WelsSpatialWriteSubMbPred (sWelsEncCtx* pEncCtx, SSlice* pSlice, SMB* pCurMb);
 
--- a/codec/encoder/core/inc/wels_func_ptr_def.h
+++ b/codec/encoder/core/inc/wels_func_ptr_def.h
@@ -191,6 +191,9 @@
 typedef void (*PMarkPicFunc) (void* pCtx);
 typedef bool (*PUpdateRefListFunc) (void* pCtx);
 
+typedef  int32_t (*PCavlcParamCalFunc) (int16_t* pCoff, uint8_t* pRun, int16_t* pLevel, int32_t* pTotalCoeffs,
+                                        int32_t iEndIdx);
+
 struct TagWelsFuncPointerList {
   SExpandPicFunc sExpandPicFunc;
   PFillInterNeighborCacheFunc       pfFillInterNeighborCache;
@@ -280,6 +283,8 @@
   PBuildRefListFunc     pBuildRefList;
   PMarkPicFunc          pMarkPic;
   PUpdateRefListFunc    pUpdateRefList;
+
+  PCavlcParamCalFunc    pfCavlcParamCal;
 };
 
 }  //end of namespace WelsSVCEnc {
--- a/codec/encoder/core/src/encoder.cpp
+++ b/codec/encoder/core/src/encoder.cpp
@@ -200,7 +200,7 @@
   /*init pixel average function*/
   /*get one column or row pixel when refinement*/
   WelsInitMcFuncs (pFuncList, uiCpuFlag);
-  InitCoeffFunc (uiCpuFlag);
+  InitCoeffFunc (pFuncList, uiCpuFlag);
 
   WelsInitEncodingFuncs (pFuncList, uiCpuFlag);
   WelsInitReconstructionFuncs (pFuncList, uiCpuFlag);
--- a/codec/encoder/core/src/set_mb_syn_cavlc.cpp
+++ b/codec/encoder/core/src/set_mb_syn_cavlc.cpp
@@ -44,7 +44,6 @@
 #include "wels_const.h"
 
 namespace WelsSVCEnc {
-SCoeffFunc    sCoeffFunc;
 
 const  ALIGNED_DECLARE (uint8_t, g_kuiZeroLeftMap[16], 16) = {
   0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7
@@ -74,7 +73,8 @@
   return iTotalZeros;
 }
 
-int32_t  WriteBlockResidualCavlc (int16_t* pCoffLevel, int32_t iEndIdx, int32_t iCalRunLevelFlag,
+int32_t  WriteBlockResidualCavlc (SWelsFuncPtrList* pFuncList, int16_t* pCoffLevel, int32_t iEndIdx,
+                                  int32_t iCalRunLevelFlag,
                                   int32_t iResidualProperty, int8_t iNC, SBitStringAux* pBs) {
   ENFORCE_STACK_ALIGN_1D (int16_t, iLevel, 16, 16)
   ENFORCE_STACK_ALIGN_1D (uint8_t, uiRun, 16, 16)
@@ -95,7 +95,7 @@
 
   if (iCalRunLevelFlag) {
     int32_t iCount = 0;
-    iTotalZeros = sCoeffFunc.pfCavlcParamCal (pCoffLevel, uiRun, iLevel, &iTotalCoeffs, iEndIdx);
+    iTotalZeros = pFuncList->pfCavlcParamCal (pCoffLevel, uiRun, iLevel, &iTotalCoeffs, iEndIdx);
     iCount = (iTotalCoeffs > 3) ? 3 : iTotalCoeffs;
     for (i = 0; i < iCount ; i++) {
       if (WELS_ABS (iLevel[i]) == 1) {
@@ -200,12 +200,12 @@
 }
 
 
-void InitCoeffFunc (const uint32_t uiCpuFlag) {
-  sCoeffFunc.pfCavlcParamCal = CavlcParamCal_c;
+void InitCoeffFunc (SWelsFuncPtrList* pFuncList, const uint32_t uiCpuFlag) {
+  pFuncList->pfCavlcParamCal = CavlcParamCal_c;
 
 #if defined(X86_ASM)
   if (uiCpuFlag & WELS_CPU_SSE2) {
-    // sCoeffFunc.pfCavlcParamCal = CavlcParamCal_sse2;
+    // pFuncList->pfCavlcParamCal = CavlcParamCal_sse2;
   }
 #endif
 }
--- a/codec/encoder/core/src/svc_set_mb_syn_cavlc.cpp
+++ b/codec/encoder/core/src/svc_set_mb_syn_cavlc.cpp
@@ -244,7 +244,7 @@
     pSlice->uiLastMbQp = pCurMb->uiLumaQp;
 
     BsWriteSE (pBs, kiDeltaQp);
-    if (WelsWriteMbResidual (pMbCache, pCurMb, pBs))
+    if (WelsWriteMbResidual (pEncCtx->pFuncList, pMbCache, pCurMb, pBs))
       return ENC_RETURN_VLCOVERFLOWFOUND;
   } else {
     pCurMb->uiLumaQp = pSlice->uiLastMbQp;
@@ -256,7 +256,7 @@
   return CheckBitstreamBuffer (pSlice->uiSliceIdx, pEncCtx, pBs);
 }
 
-int32_t WelsWriteMbResidual (SMbCache* sMbCacheInfo, SMB* pCurMb, SBitStringAux* pBs) {
+int32_t WelsWriteMbResidual (SWelsFuncPtrList* pFuncList, SMbCache* sMbCacheInfo, SMB* pCurMb, SBitStringAux* pBs) {
   int32_t i;
   Mb_Type uiMbType					= pCurMb->uiMbType;
   const int32_t kiCbpChroma		= pCurMb->uiCbp >> 4;
@@ -270,7 +270,7 @@
     iA = pNonZeroCoeffCount[8];
     iB = pNonZeroCoeffCount[ 1];
     WELS_NON_ZERO_COUNT_AVERAGE (iC, iA, iB);
-    if (WriteBlockResidualCavlc (sMbCacheInfo->pDct->iLumaI16x16Dc, 15, 1, LUMA_4x4, iC, pBs))
+    if (WriteBlockResidualCavlc (pFuncList, sMbCacheInfo->pDct->iLumaI16x16Dc, 15, 1, LUMA_4x4, iC, pBs))
       return ENC_RETURN_VLCOVERFLOWFOUND;
 
     /* AC Luma */
@@ -282,7 +282,7 @@
         iA = pNonZeroCoeffCount[iIdx - 1];
         iB = pNonZeroCoeffCount[iIdx - 8];
         WELS_NON_ZERO_COUNT_AVERAGE (iC, iA, iB);
-        if (WriteBlockResidualCavlc (pBlock, 14, pNonZeroCoeffCount[iIdx] > 0, LUMA_AC, iC, pBs))
+        if (WriteBlockResidualCavlc (pFuncList, pBlock, 14, pNonZeroCoeffCount[iIdx] > 0, LUMA_AC, iC, pBs))
           return ENC_RETURN_VLCOVERFLOWFOUND;
         pBlock += 16;
       }
@@ -302,25 +302,25 @@
           iA = pNonZeroCoeffCount[iIdx - 1];
           iB = pNonZeroCoeffCount[iIdx - 8];
           WELS_NON_ZERO_COUNT_AVERAGE (iC, iA, iB);
-          if (WriteBlockResidualCavlc (pBlock, 15, kiA > 0, LUMA_4x4, iC, pBs))
+          if (WriteBlockResidualCavlc (pFuncList, pBlock, 15, kiA > 0, LUMA_4x4, iC, pBs))
             return ENC_RETURN_VLCOVERFLOWFOUND;
 
           iA = kiA;
           iB = pNonZeroCoeffCount[iIdx - 7];
           WELS_NON_ZERO_COUNT_AVERAGE (iC, iA, iB);
-          if (WriteBlockResidualCavlc (pBlock + 16, 15, kiB > 0, LUMA_4x4, iC, pBs))
+          if (WriteBlockResidualCavlc (pFuncList, pBlock + 16, 15, kiB > 0, LUMA_4x4, iC, pBs))
             return ENC_RETURN_VLCOVERFLOWFOUND;
 
           iA = pNonZeroCoeffCount[iIdx + 7];
           iB = kiA;
           WELS_NON_ZERO_COUNT_AVERAGE (iC, iA, iB);
-          if (WriteBlockResidualCavlc (pBlock + 32, 15, kiC > 0, LUMA_4x4, iC, pBs))
+          if (WriteBlockResidualCavlc (pFuncList, pBlock + 32, 15, kiC > 0, LUMA_4x4, iC, pBs))
             return ENC_RETURN_VLCOVERFLOWFOUND;
 
           iA = kiC;
           iB = kiB;
           WELS_NON_ZERO_COUNT_AVERAGE (iC, iA, iB);
-          if (WriteBlockResidualCavlc (pBlock + 48, 15, kiD > 0, LUMA_4x4, iC, pBs))
+          if (WriteBlockResidualCavlc (pFuncList, pBlock + 48, 15, kiD > 0, LUMA_4x4, iC, pBs))
             return ENC_RETURN_VLCOVERFLOWFOUND;
         }
         pBlock += 64;
@@ -331,11 +331,11 @@
   if (kiCbpChroma) {
     /* Chroma DC residual present */
     pBlock = sMbCacheInfo->pDct->iChromaDc[0]; // Cb
-    if (WriteBlockResidualCavlc (pBlock, 3, 1, CHROMA_DC, CHROMA_DC_NC_OFFSET, pBs))
+    if (WriteBlockResidualCavlc (pFuncList, pBlock, 3, 1, CHROMA_DC, CHROMA_DC_NC_OFFSET, pBs))
       return ENC_RETURN_VLCOVERFLOWFOUND;
 
     pBlock += 4; // Cr
-    if (WriteBlockResidualCavlc (pBlock, 3, 1, CHROMA_DC, CHROMA_DC_NC_OFFSET, pBs))
+    if (WriteBlockResidualCavlc (pFuncList, pBlock, 3, 1, CHROMA_DC, CHROMA_DC_NC_OFFSET, pBs))
       return ENC_RETURN_VLCOVERFLOWFOUND;
 
     /* Chroma AC residual present */
@@ -348,7 +348,7 @@
         iA = pNonZeroCoeffCount[iIdx - 1];
         iB = pNonZeroCoeffCount[iIdx - 8];
         WELS_NON_ZERO_COUNT_AVERAGE (iC, iA, iB);
-        if (WriteBlockResidualCavlc (pBlock, 14, pNonZeroCoeffCount[iIdx] > 0, CHROMA_AC, iC, pBs))
+        if (WriteBlockResidualCavlc (pFuncList, pBlock, 14, pNonZeroCoeffCount[iIdx] > 0, CHROMA_AC, iC, pBs))
           return ENC_RETURN_VLCOVERFLOWFOUND;
         pBlock += 16;
       }
@@ -360,7 +360,7 @@
         iA = pNonZeroCoeffCount[iIdx - 1];
         iB = pNonZeroCoeffCount[iIdx - 8];
         WELS_NON_ZERO_COUNT_AVERAGE (iC, iA, iB);
-        if (WriteBlockResidualCavlc (pBlock, 14, pNonZeroCoeffCount[iIdx] > 0, CHROMA_AC, iC, pBs))
+        if (WriteBlockResidualCavlc (pFuncList, pBlock, 14, pNonZeroCoeffCount[iIdx] > 0, CHROMA_AC, iC, pBs))
           return ENC_RETURN_VLCOVERFLOWFOUND;
         pBlock += 16;
       }