[x265] [PATCH 1 of 2] TComPic: store average Qp (as decided by AQ) used per frame

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Tue Feb 25 23:02:11 CET 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1393365328 -19800
#      Wed Feb 26 03:25:28 2014 +0530
# Node ID 378444ab3d1a23e06418ab904ac2dbcb6fad19e7
# Parent  b456566376adae3c3323fda9b272f853852041cc
TComPic: store average Qp (as decided by AQ) used per frame.

diff -r b456566376ad -r 378444ab3d1a source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp	Tue Feb 25 11:20:47 2014 -0600
+++ b/source/Lib/TLibCommon/TComPic.cpp	Wed Feb 26 03:25:28 2014 +0530
@@ -79,6 +79,7 @@
     m_qpaAq = 0;
     m_qpaRc = 0;
     m_avgQpRc = 0;
+    m_avgQpAq = 0;
     m_bChromaPlanesExtended = false;
 }
 
@@ -105,19 +106,25 @@
     ok &= m_reconPicYuv->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
     ok &= m_lowres.create(m_origPicYuv, cfg->param.bframes, !!cfg->param.rc.aqMode);
 
-    if (ok && cfg->param.rc.vbvBufferSize > 0 && cfg->param.rc.vbvMaxBitrate > 0)
+    bool isVbv = cfg->param.rc.vbvBufferSize > 0 && cfg->param.rc.vbvMaxBitrate > 0;
+    if (ok && (isVbv || cfg->param.rc.aqMode))
     {
         int numRows = m_picSym->getFrameHeightInCU();
         int numCols = m_picSym->getFrameWidthInCU();
-        CHECKED_MALLOC(m_rowDiagQp, double, numRows);
-        CHECKED_MALLOC(m_rowDiagQScale, double, numRows);
-        CHECKED_MALLOC(m_rowDiagSatd, uint32_t, numRows);
-        CHECKED_MALLOC(m_rowEncodedBits, uint32_t, numRows);
-        CHECKED_MALLOC(m_numEncodedCusPerRow, uint32_t, numRows);
-        CHECKED_MALLOC(m_rowSatdForVbv, uint32_t, numRows);
-        CHECKED_MALLOC(m_cuCostsForVbv, uint32_t, numRows * numCols);
-        CHECKED_MALLOC(m_qpaRc, double, numRows);
-        CHECKED_MALLOC(m_qpaAq, int, numRows);
+
+        if (cfg->param.rc.aqMode)
+            CHECKED_MALLOC(m_qpaAq, double, numRows);
+        if (isVbv)
+        {
+            CHECKED_MALLOC(m_rowDiagQp, double, numRows);
+            CHECKED_MALLOC(m_rowDiagQScale, double, numRows);
+            CHECKED_MALLOC(m_rowDiagSatd, uint32_t, numRows);
+            CHECKED_MALLOC(m_rowEncodedBits, uint32_t, numRows);
+            CHECKED_MALLOC(m_numEncodedCusPerRow, uint32_t, numRows);
+            CHECKED_MALLOC(m_rowSatdForVbv, uint32_t, numRows);
+            CHECKED_MALLOC(m_cuCostsForVbv, uint32_t, numRows * numCols);
+            CHECKED_MALLOC(m_qpaRc, double, numRows);
+        }
         reInit(cfg);
     }
 
@@ -142,8 +149,9 @@
         memset(m_rowSatdForVbv, 0, numRows * sizeof(uint32_t));
         memset(m_cuCostsForVbv, 0,  numRows * numCols * sizeof(uint32_t));
         memset(m_qpaRc, 0, numRows * sizeof(double));
-        memset(m_qpaAq, 0, numRows * sizeof(uint32_t));
     }
+    if (cfg->param.rc.aqMode)
+        memset(m_qpaAq, 0,  m_picSym->getFrameHeightInCU() * sizeof(double));
 }
 
 void TComPic::destroy(int bframes)
diff -r b456566376ad -r 378444ab3d1a source/Lib/TLibCommon/TComPic.h
--- a/source/Lib/TLibCommon/TComPic.h	Tue Feb 25 11:20:47 2014 -0600
+++ b/source/Lib/TLibCommon/TComPic.h	Wed Feb 26 03:25:28 2014 +0530
@@ -110,9 +110,11 @@
     uint32_t*             m_numEncodedCusPerRow;
     uint32_t*             m_rowSatdForVbv;
     uint32_t*             m_cuCostsForVbv;
-    int*                  m_qpaAq;
+    double*                  m_qpaAq;
     double*               m_qpaRc;
-    double                m_avgQpRc;
+    double                m_avgQpRc; //avg QP as decided by ratecontrol
+    double                m_avgQpAq; //avg QP as decided by AQ in addition to ratecontrol
+
     TComPic();
     virtual ~TComPic();
 
diff -r b456566376ad -r 378444ab3d1a source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Tue Feb 25 11:20:47 2014 -0600
+++ b/source/encoder/frameencoder.cpp	Wed Feb 26 03:25:28 2014 +0530
@@ -412,11 +412,9 @@
     }
 
     /* Clip qps back to 0-51 range before encoding */
-    if (qp > MAX_QP)
-    {
-        qp = MAX_QP;
-        slice->setSliceQp(qp);
-    }
+    qp = X265_MIN(qp, MAX_QP);
+    slice->setSliceQp(qp);
+    m_pic->m_avgQpAq = qp;
     slice->setSliceQpDelta(0);
     slice->setSliceQpDeltaCb(0);
     slice->setSliceQpDeltaCr(0);
@@ -1079,6 +1077,7 @@
             qp = X265_MIN(qp, MAX_QP);
             cu->setQP(0, char(qp));
             cu->m_baseQp = qpBase;
+            m_pic->m_qpaAq[row] += qp;
         }
         codeRow.processCU(cu, m_pic->getSlice(), bufSbac, m_cfg->param.bEnableWavefront && col == 1);
         if (isVbv)
@@ -1087,7 +1086,6 @@
             m_pic->m_rowDiagSatd[row] += m_pic->m_cuCostsForVbv[cuAddr];
             m_pic->m_rowEncodedBits[row] += cu->m_totalBits;
             m_pic->m_numEncodedCusPerRow[row] = cuAddr;
-            m_pic->m_qpaAq[row] += cu->getQP(0);
             m_pic->m_qpaRc[row] += cu->m_baseQp;
 
             if ((uint32_t)row == col)
diff -r b456566376ad -r 378444ab3d1a source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Tue Feb 25 11:20:47 2014 -0600
+++ b/source/encoder/ratecontrol.cpp	Wed Feb 26 03:25:28 2014 +0530
@@ -415,7 +415,7 @@
         double q = qScale2qp(rateEstimateQscale(pic, rce));
         q = Clip3((double)MIN_QP, (double)MAX_MAX_QP, q);
         qp = int(q + 0.5);
-        rce->qpaRc = pic->m_avgQpRc = q;
+        rce->qpaRc = pic->m_avgQpRc = pic->m_avgQpAq = q;
         /* copy value of lastRceq into thread local rce struct *to be used in RateControlEnd() */
         rce->qRceq = lastRceq;
         rce->qpNoVbv = qpNoVbv;
@@ -427,7 +427,7 @@
             qp = (qpConstant[B_SLICE] + qpConstant[P_SLICE]) / 2;
         else
             qp = qpConstant[sliceType];
-        pic->m_avgQpRc = qp;
+        pic->m_avgQpAq = pic->m_avgQpRc = qp;
     }
     if (sliceType != B_SLICE)
     {
@@ -1014,15 +1014,24 @@
         }
         if (!isAbrReset)
         {
-            if (pic->m_qpaRc)
+            if (cfg->param.rc.aqMode || isVbv)
             {
-                for (uint32_t i = 0; i < pic->getFrameHeightInCU(); i++)
+                if (pic->m_qpaRc)
                 {
-                    pic->m_avgQpRc += pic->m_qpaRc[i];
+                    for (uint32_t i = 0; i < pic->getFrameHeightInCU(); i++)
+                        pic->m_avgQpRc += pic->m_qpaRc[i];
+
+                    pic->m_avgQpRc /= (pic->getFrameHeightInCU() * pic->getFrameWidthInCU());
+                    rce->qpaRc = pic->m_avgQpRc;
                 }
 
-                pic->m_avgQpRc /= (pic->getFrameHeightInCU() * pic->getFrameWidthInCU());
-                rce->qpaRc = pic->m_avgQpRc;
+                if (pic->m_qpaAq)
+                {
+                    for (uint32_t i = 0; i < pic->getFrameHeightInCU(); i++)
+                        pic->m_avgQpAq += pic->m_qpaAq[i];
+
+                    pic->m_avgQpAq /= (pic->getFrameHeightInCU() * pic->getFrameWidthInCU());
+                }
             }
 
             if (rce->sliceType != B_SLICE)


More information about the x265-devel mailing list