shithub: openh264

Download patch

ref: 2fc9c08710fad9a5a2ef59ebcb128e4b6fc76496
parent: 01016b1c83b019d731e73c0bf513cd79ea3223ff
author: sijchen <sijchen@cisco.com>
date: Tue Nov 24 06:14:20 EST 2015

put duplicated codes into one function

--- a/codec/encoder/core/inc/svc_encode_slice.h
+++ b/codec/encoder/core/inc/svc_encode_slice.h
@@ -50,6 +50,7 @@
 void WelsCountMbType (int32_t (*iMbCount)[18], const EWelsSliceType eSt, const SMB* pMb);
 #endif
 
+void UpdateMbNeighbor(SDqLayer* pCurDq, SMB* pMb, const int32_t kiMbWidth, uint16_t uiSliceIdc);
 
 void UpdateNonZeroCountCache (SMB* pMb, SMbCache* pMbCache);
 
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2689,43 +2689,7 @@
 
   do {
     SMB* pMb = &pMbList[iIdx];
-    uint32_t uiNeighborAvailFlag        = 0;
-    const int32_t kiMbXY                = pMb->iMbXY;
-    const int32_t kiMbX                 = pMb->iMbX;
-    const int32_t kiMbY                 = pMb->iMbY;
-    bool     bLeft;
-    bool     bTop;
-    bool     bLeftTop;
-    bool     bRightTop;
-    uint16_t  uiSliceIdc;
-    int32_t   iLeftXY, iTopXY, iLeftTopXY, iRightTopXY;
-
-    uiSliceIdc = WelsMbToSliceIdc (pCurDq, kiMbXY);
-    pMb->uiSliceIdc = uiSliceIdc;
-    iLeftXY = kiMbXY - 1;
-    iTopXY = kiMbXY - kiMbWidth;
-    iLeftTopXY = iTopXY - 1;
-    iRightTopXY = iTopXY + 1;
-
-    bLeft = (kiMbX > 0) && (uiSliceIdc == WelsMbToSliceIdc (pCurDq, iLeftXY));
-    bTop = (kiMbY > 0) && (uiSliceIdc == WelsMbToSliceIdc (pCurDq, iTopXY));
-    bLeftTop = (kiMbX > 0) && (kiMbY > 0) && (uiSliceIdc == WelsMbToSliceIdc (pCurDq, iLeftTopXY));
-    bRightTop = (kiMbX < (kiMbWidth - 1)) && (kiMbY > 0) && (uiSliceIdc == WelsMbToSliceIdc (pCurDq, iRightTopXY));
-
-    if (bLeft) {
-      uiNeighborAvailFlag |= LEFT_MB_POS;
-    }
-    if (bTop) {
-      uiNeighborAvailFlag |= TOP_MB_POS;
-    }
-    if (bLeftTop) {
-      uiNeighborAvailFlag |= TOPLEFT_MB_POS;
-    }
-    if (bRightTop) {
-      uiNeighborAvailFlag |= TOPRIGHT_MB_POS;
-    }
-    pMb->uiNeighborAvail = (uint8_t)uiNeighborAvailFlag;
-
+    UpdateMbNeighbor(pCurDq, pMb, kiMbWidth, WelsMbToSliceIdc (pCurDq, pMb->iMbXY));
     ++ iIdx;
   } while (iIdx <= kiEndMbInSlice);
 }
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -82,48 +82,12 @@
                                    const int32_t uiSliceIdc) {
   SSliceCtx* pSliceCtx           = &pCurDq->sSliceEncCtx;
   SSlice* pUpdateSlice           = &pCurDq->sLayerInfo.pSliceInLayer[uiSliceIdc];
-  const uint16_t* kpMbMap        = pSliceCtx->pOverallMbMap;
   const int32_t kiMbWidth        = pSliceCtx->iMbWidth;
   int32_t iIdx                   = pUpdateSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
   const int32_t kiEndMbInSlice   = iIdx + pSliceCtx->pCountMbNumInSlice[uiSliceIdc] - 1;
 
   do {
-    SMB* pMb                     = &pMbList[iIdx];
-    uint32_t uiNeighborAvailFlag = 0;
-    const int32_t kiMbXY         = pMb->iMbXY;
-    const int32_t kiMbX          = pMb->iMbX;
-    const int32_t kiMbY          = pMb->iMbY;
-    bool     bLeft;
-    bool     bTop;
-    bool     bLeftTop;
-    bool     bRightTop;
-    int32_t   iLeftXY, iTopXY, iLeftTopXY, iRightTopXY;
-
-    iLeftXY = kiMbXY - 1;
-    iTopXY = kiMbXY - kiMbWidth;
-    iLeftTopXY = iTopXY - 1;
-    iRightTopXY = iTopXY + 1;
-
-    bLeft = (kiMbX > 0) && (uiSliceIdc == kpMbMap[iLeftXY]);
-    bTop = (kiMbY > 0) && (uiSliceIdc == kpMbMap[iTopXY]);
-    bLeftTop = (kiMbX > 0) && (kiMbY > 0) && (uiSliceIdc == kpMbMap[iLeftTopXY]);
-    bRightTop = (kiMbX < (kiMbWidth - 1)) && (kiMbY > 0) && (uiSliceIdc == kpMbMap[iRightTopXY]);
-
-    if (bLeft) {
-      uiNeighborAvailFlag |= LEFT_MB_POS;
-    }
-    if (bTop) {
-      uiNeighborAvailFlag |= TOP_MB_POS;
-    }
-    if (bLeftTop) {
-      uiNeighborAvailFlag |= TOPLEFT_MB_POS;
-    }
-    if (bRightTop) {
-      uiNeighborAvailFlag |= TOPRIGHT_MB_POS;
-    }
-    pMb->uiNeighborAvail        = (uint8_t)uiNeighborAvailFlag;
-    pMb->uiSliceIdc             = uiSliceIdc;
-
+    UpdateMbNeighbor(pCurDq, &pMbList[iIdx], kiMbWidth, uiSliceIdc);
     ++ iIdx;
   } while (iIdx <= kiEndMbInSlice);
 }
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -137,6 +137,44 @@
   }
 }
 
+
+void UpdateMbNeighbor(SDqLayer* pCurDq, SMB* pMb, const int32_t kiMbWidth, uint16_t uiSliceIdc) {
+  uint32_t uiNeighborAvailFlag        = 0;
+  const int32_t kiMbXY                = pMb->iMbXY;
+  const int32_t kiMbX                 = pMb->iMbX;
+  const int32_t kiMbY                 = pMb->iMbY;
+  bool     bLeft;
+  bool     bTop;
+  bool     bLeftTop;
+  bool     bRightTop;
+  int32_t   iLeftXY, iTopXY, iLeftTopXY, iRightTopXY;
+
+  pMb->uiSliceIdc = uiSliceIdc;
+  iLeftXY = kiMbXY - 1;
+  iTopXY = kiMbXY - kiMbWidth;
+  iLeftTopXY = iTopXY - 1;
+  iRightTopXY = iTopXY + 1;
+
+  bLeft = (kiMbX > 0) && (uiSliceIdc == WelsMbToSliceIdc (pCurDq, iLeftXY));
+  bTop = (kiMbY > 0) && (uiSliceIdc == WelsMbToSliceIdc (pCurDq, iTopXY));
+  bLeftTop = (kiMbX > 0) && (kiMbY > 0) && (uiSliceIdc == WelsMbToSliceIdc (pCurDq, iLeftTopXY));
+  bRightTop = (kiMbX < (kiMbWidth - 1)) && (kiMbY > 0) && (uiSliceIdc == WelsMbToSliceIdc (pCurDq, iRightTopXY));
+
+  if (bLeft) {
+    uiNeighborAvailFlag |= LEFT_MB_POS;
+  }
+  if (bTop) {
+    uiNeighborAvailFlag |= TOP_MB_POS;
+  }
+  if (bLeftTop) {
+    uiNeighborAvailFlag |= TOPLEFT_MB_POS;
+  }
+  if (bRightTop) {
+    uiNeighborAvailFlag |= TOPRIGHT_MB_POS;
+  }
+  pMb->uiNeighborAvail = (uint8_t)uiNeighborAvailFlag;
+}
+
 /* count MB types if enabled FRAME_INFO_OUTPUT*/
 #if defined(MB_TYPES_CHECK)
 void WelsCountMbType (int32_t (*iMbCount)[18], const EWelsSliceType keSt, const SMB* kpMb) {
@@ -772,42 +810,7 @@
   SMB* pMb = &pMbList[iIdx];
 
   do {
-    uint32_t uiNeighborAvailFlag = 0;
-    const int32_t kiMbXY = pMb->iMbXY;
-    const int32_t kiMbX  = pMb->iMbX;
-    const int32_t kiMbY  = pMb->iMbY;
-    bool     bLeft;
-    bool     bTop;
-    bool     bLeftTop;
-    bool     bRightTop;
-    int32_t   iLeftXY, iTopXY, iLeftTopXY, iRightTopXY;
-    const uint16_t kuiSliceIdc = WelsMbToSliceIdc (pCurDq, kiMbXY);
-
-    pMb->uiSliceIdc = kuiSliceIdc;
-    iLeftXY = kiMbXY - 1;
-    iTopXY = kiMbXY - kiMbWidth;
-    iLeftTopXY = iTopXY - 1;
-    iRightTopXY = iTopXY + 1;
-
-    bLeft = (kiMbX > 0) && (kuiSliceIdc == WelsMbToSliceIdc (pCurDq, iLeftXY));
-    bTop = (kiMbY > 0) && (kuiSliceIdc == WelsMbToSliceIdc (pCurDq, iTopXY));
-    bLeftTop = (kiMbX > 0) && (kiMbY > 0) && (kuiSliceIdc == WelsMbToSliceIdc (pCurDq, iLeftTopXY));
-    bRightTop = (kiMbX < (kiMbWidth - 1)) && (kiMbY > 0) && (kuiSliceIdc == WelsMbToSliceIdc (pCurDq, iRightTopXY));
-
-    if (bLeft) {
-      uiNeighborAvailFlag |= LEFT_MB_POS;
-    }
-    if (bTop) {
-      uiNeighborAvailFlag |= TOP_MB_POS;
-    }
-    if (bLeftTop) {
-      uiNeighborAvailFlag |= TOPLEFT_MB_POS;
-    }
-    if (bRightTop) {
-      uiNeighborAvailFlag |= TOPRIGHT_MB_POS;
-    }
-    pMb->uiNeighborAvail = (uint8_t)uiNeighborAvailFlag;
-
+    UpdateMbNeighbor(pCurDq, pMb, kiMbWidth, WelsMbToSliceIdc (pCurDq, pMb->iMbXY));
     ++ pMb;
     ++ iIdx;
   } while ((iIdx < kiEndMbNeedUpdate) &&