shithub: openh264

Download patch

ref: a37f1abe5e64a407857df87b8909ab46d5c074d9
parent: 9512515a41173c4bcf7acbd15ca56305f430667b
parent: 560fcf17fd254a7062c61321711d0f8b6cb9bb3e
author: sijchen <[email protected]>
date: Tue Nov 11 09:52:04 EST 2014

Merge pull request #1517 from ruil2/cabac_qp

fix cabac encoding bug -- don't get the correct previous mb qp

--- a/codec/encoder/core/src/svc_set_mb_syn_cabac.cpp
+++ b/codec/encoder/core/src/svc_set_mb_syn_cabac.cpp
@@ -224,12 +224,11 @@
   }
 }
 
-void WelsCabacMbDeltaQp (SMB* pCurMb, SCabacCtx* pCabacCtx) {
+void WelsCabacMbDeltaQp (SMB* pCurMb, SCabacCtx* pCabacCtx, bool bFirstMbInSlice) {
   SMB* pPrevMb = NULL;
   int32_t iCtx = 0;
-  uint32_t uiNeighborAvail = pCurMb->uiNeighborAvail;
 
-  if ((uiNeighborAvail & LEFT_MB_POS) || (uiNeighborAvail & TOP_MB_POS)) {
+  if (!bFirstMbInSlice) {
     pPrevMb = pCurMb - 1;
     pCurMb->iLumaDQp = pCurMb->uiLumaQp - pPrevMb->uiLumaQp;
 
@@ -482,6 +481,8 @@
   SMbCache* pMbCache	= &pSlice->sMbCacheInfo;
   int16_t i = 0;
   int8_t* pNonZeroCoeffCount	= pMbCache->iNonZeroCoeffCount;
+  SSliceHeaderExt* pSliceHeadExt = &pSlice->sSliceHeaderExt;
+  const int32_t iSliceFirstMbXY	= pSliceHeadExt->sSliceHeader.iFirstMbInSlice;
 
 
   pCurMb->iCbpDc = 0;
@@ -492,7 +493,7 @@
     int32_t iCbpLuma   = pCurMb->uiCbp & 15;
 
     pCurMb->iLumaDQp = pCurMb->uiLumaQp - pSlice->uiLastMbQp;
-    WelsCabacMbDeltaQp (pCurMb, pCabacCtx);
+    WelsCabacMbDeltaQp (pCurMb, pCabacCtx, (pCurMb->iMbXY == iSliceFirstMbXY));
     pSlice->uiLastMbQp = pCurMb->uiLumaQp;
 
     if (uiMbType == MB_TYPE_INTRA16x16) {
@@ -557,6 +558,7 @@
       }
     }
   } else {
+    pCurMb->iLumaDQp = 0;
     pCurMb->uiLumaQp	= pSlice->uiLastMbQp;
     pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + uiChromaQpIndexOffset)];
   }