[x265] [PATCH] vbv: fix race condition in processRowEncoder, store row qp directly in m_pic->m_rowDiagQp

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Thu Mar 20 10:53:51 CET 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1395309217 -19800
#      Thu Mar 20 15:23:37 2014 +0530
# Node ID 137579db4ed278d807b6a8d39d669755c7cc1037
# Parent  96d1d690d2ab75ffc58dbd252c2f245b55f05f80
vbv: fix race condition in processRowEncoder, store row qp directly in m_pic->m_rowDiagQp.

diff -r 96d1d690d2ab -r 137579db4ed2 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Wed Mar 19 11:46:10 2014 -0500
+++ b/source/encoder/frameencoder.cpp	Thu Mar 20 15:23:37 2014 +0530
@@ -1021,7 +1021,6 @@
     CTURow& codeRow = m_rows[m_cfg->param->bEnableWavefront ? row : 0];
     const uint32_t numCols = m_pic->getPicSym()->getFrameWidthInCU();
     const uint32_t lineStartCUAddr = row * numCols;
-    double qpBase = m_pic->m_avgQpRc;
     bool isVbv = m_cfg->param->rc.vbvBufferSize > 0 && m_cfg->param->rc.vbvMaxBitrate > 0;
     for (uint32_t col = curRow.m_completed; col < numCols; col++)
     {
@@ -1033,17 +1032,25 @@
         codeRow.m_entropyCoder.setEntropyCoder(&m_sbacCoder, m_pic->getSlice());
         codeRow.m_entropyCoder.resetEntropy();
         TEncSbac *bufSbac = (m_cfg->param->bEnableWavefront && col == 0 && row > 0) ? &m_rows[row - 1].m_bufferSbacCoder : NULL;
+        if (isVbv)
+        {
+            if (!row)
+                m_pic->m_rowDiagQp[row] = m_pic->m_avgQpRc;
 
-        if ((uint32_t)row >= col && (row != 0) && isVbv)
-            qpBase = m_pic->getCU(cuAddr - numCols + 1)->m_baseQp;
+            if ((uint32_t)row >= col && (row != 0))
+                cu->m_baseQp = m_pic->getCU(cuAddr - numCols + 1)->m_baseQp;
+            else
+                cu->m_baseQp = m_pic->m_rowDiagQp[row];
+        }
+        else
+            cu->m_baseQp = m_pic->m_avgQpRc;
 
         if (m_cfg->param->rc.aqMode || isVbv)
         {
-            int qp = calcQpForCu(m_pic, cuAddr, qpBase);
+            int qp = calcQpForCu(m_pic, cuAddr, cu->m_baseQp);
             setLambda(qp, row);
             qp = Clip3(-QP_BD_OFFSET, MAX_QP, qp);
             cu->setQPSubParts(char(qp), 0, 0);
-            cu->m_baseQp = qpBase;
             if (m_cfg->param->rc.aqMode)
                 m_pic->m_qpaAq[row] += qp;
         }
@@ -1056,14 +1063,14 @@
             m_pic->m_numEncodedCusPerRow[row] = cuAddr;
             m_pic->m_qpaRc[row] += cu->m_baseQp;
 
-            if ((uint32_t)row == col)
-                m_pic->m_rowDiagQp[row] = qpBase;
-
             // If current block is at row diagonal checkpoint, call vbv ratecontrol.
+ 
             if ((uint32_t)row == col && row != 0)
             {
-                m_top->m_rateControl->rowDiagonalVbvRateControl(m_pic, row, &m_rce, qpBase);
-                qpBase = Clip3((double)MIN_QP, (double)MAX_MAX_QP, qpBase);
+                m_pic->m_rowDiagQp[row] = cu->m_baseQp;
+                m_top->m_rateControl->rowDiagonalVbvRateControl(m_pic, row, &m_rce, m_pic->m_rowDiagQp[row]);
+                m_pic->m_rowDiagQScale[row] = Clip3((double)MIN_QP, (double)MAX_QP, m_pic->m_rowDiagQScale[row]);
+                m_pic->m_rowDiagQScale[row] =  x265_qp2qScale(m_pic->m_rowDiagQp[row]);
             }
         }
         // Completed CU processing
diff -r 96d1d690d2ab -r 137579db4ed2 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Wed Mar 19 11:46:10 2014 -0500
+++ b/source/encoder/ratecontrol.cpp	Thu Mar 20 15:23:37 2014 +0530
@@ -792,7 +792,7 @@
                 }
 
                 refRowSatdCost >>= X265_DEPTH - 8;
-                refQScale = row == maxRows - 1 ? refPic->m_rowDiagQScale[row] : refPic->m_rowDiagQScale[row + 1];
+                refQScale = refPic->m_rowDiagQScale[row];
             }
 
             if (picType == I_SLICE || qScale >= refQScale)
@@ -828,9 +828,6 @@
 int RateControl::rowDiagonalVbvRateControl(TComPic* pic, uint32_t row, RateControlEntry* rce, double& qpVbv)
 {
     double qScaleVbv = x265_qp2qScale(qpVbv);
-
-    pic->m_rowDiagQp[row] = qpVbv;
-    pic->m_rowDiagQScale[row] = qScaleVbv;
     uint64_t rowSatdCost = pic->m_rowDiagSatd[row];
     double encodedBits = pic->m_rowEncodedBits[row];
     if (row == 1)


More information about the x265-devel mailing list