[x265] [PATCH 1 of 3] vbv: add states to hold and init values for vbv cu level ratecontrol

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Sun Feb 16 19:47:39 CET 2014


# HG changeset patch
# User Aarthi Thirumalai<aarthi at multicorewareinc.com>
# Date 1392572113 -19800
#      Sun Feb 16 23:05:13 2014 +0530
# Node ID 6ea3bf6cbed041417ae407b40651557386f5be5a
# Parent  291b3a358a228eb10ecb46701b1632e43a00b232
vbv: add states to hold and init values for vbv cu level ratecontrol

diff -r 291b3a358a22 -r 6ea3bf6cbed0 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Sat Feb 15 17:43:58 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Sun Feb 16 23:05:13 2014 +0530
@@ -99,6 +99,7 @@
     m_mvpIdx[0] = NULL;
     m_mvpIdx[1] = NULL;
     m_chromaFormat = 0;
+    m_baseQp = 0;
 }
 
 TComDataCU::~TComDataCU()
diff -r 291b3a358a22 -r 6ea3bf6cbed0 source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h	Sat Feb 15 17:43:58 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.h	Sun Feb 16 23:05:13 2014 +0530
@@ -182,6 +182,7 @@
     uint64_t      m_avgCost[4];      // stores the avg cost of CU's in frame for each depth
     uint32_t      m_count[4];
     uint64_t      m_sa8dCost;
+    double        m_baseQp;          //Qp of Cu set from RateControl/Vbv.
 
     // -------------------------------------------------------------------------------------------------------------------
     // create / destroy / initialize / copy
diff -r 291b3a358a22 -r 6ea3bf6cbed0 source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp	Sat Feb 15 17:43:58 2014 -0600
+++ b/source/Lib/TLibCommon/TComPic.cpp	Sun Feb 16 23:05:13 2014 +0530
@@ -56,6 +56,13 @@
     , m_bUsedByCurr(false)
     , m_bIsLongTerm(false)
     , m_bCheckLTMSB(false)
+    , m_rowDiagQp(NULL)
+    , m_rowDiagQScale(NULL)
+    , m_rowDiagSatd(NULL)
+    , m_rowSatdForVbv(NULL)
+    , m_cuCostsForVbv(NULL)
+    , m_rowEncodedBits(NULL)
+    , m_numEncodedCusPerRow(NULL)
 {
     m_reconRowCount = 0;
     m_countRefEncoders = 0;
@@ -69,6 +76,9 @@
     m_ssimCnt = 0;
     m_frameTime = 0.0;
     m_elapsedCompressTime = 0.0;
+    m_qpaAq = 0;
+    m_qpaRc = 0;
+    m_avgQpRc = 0;
     m_bChromaPlanesExtended = false;
 }
 
@@ -88,13 +98,51 @@
     m_reconPicYuv = new TComPicYuv;
     if (!m_picSym || !m_origPicYuv || !m_reconPicYuv)
         return false;
-
     bool ok = true;
     ok &= m_picSym->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
     ok &= m_origPicYuv->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
     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)
+    {
+        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);
+        reInit(cfg);
+    }
+
     return ok;
+
+fail :
+    ok = false;
+    return ok;
+}
+
+void TComPic::reInit(TEncCfg* cfg)
+{
+    if (cfg->param.rc.vbvBufferSize > 0 && cfg->param.rc.vbvMaxBitrate > 0)
+    {
+        int numRows = m_picSym->getFrameHeightInCU();
+        int numCols = m_picSym->getFrameWidthInCU();
+        memset(m_rowDiagQp, 0, numRows * sizeof(double));
+        memset(m_rowDiagQScale, 0, numRows * sizeof(double));
+        memset(m_rowDiagSatd, 0, numRows * sizeof(uint32_t));
+        memset(m_rowEncodedBits, 0, numRows * sizeof(uint32_t));
+        memset(m_numEncodedCusPerRow, 0, numRows * sizeof(uint32_t));
+        memset(m_rowSatdForVbv, 0, numRows * sizeof(uint32_t));
+        memset(m_cuCostsForVbv, 0, sizeof(uint32_t) * numRows * numCols);
+        memset(m_qpaRc, 0, numRows * sizeof(double));
+        memset(m_qpaAq, 0, numRows * sizeof(uint32_t));
+    }
 }
 
 void TComPic::destroy(int bframes)
@@ -121,6 +169,16 @@
     }
 
     m_lowres.destroy(bframes);
+
+    X265_FREE(m_rowDiagQp);
+    X265_FREE(m_rowDiagQScale);
+    X265_FREE(m_rowDiagSatd);
+    X265_FREE(m_rowEncodedBits);
+    X265_FREE(m_numEncodedCusPerRow);
+    X265_FREE(m_rowSatdForVbv);
+    X265_FREE(m_cuCostsForVbv);
+    X265_FREE(m_qpaAq);
+    X265_FREE(m_qpaRc);
 }
 
 //! \}
diff -r 291b3a358a22 -r 6ea3bf6cbed0 source/Lib/TLibCommon/TComPic.h
--- a/source/Lib/TLibCommon/TComPic.h	Sat Feb 15 17:43:58 2014 -0600
+++ b/source/Lib/TLibCommon/TComPic.h	Sun Feb 16 23:05:13 2014 +0530
@@ -105,6 +105,18 @@
 
     bool                  m_bChromaPlanesExtended; // orig chroma planes motion extended for weightp analysis
 
+    /* For VBV ratecontrol at Diagonal Cus. */
+    double*               m_rowDiagQp;
+    double*               m_rowDiagQScale;
+    uint32_t*             m_rowDiagSatd;
+    uint32_t*             m_rowEncodedBits;
+    uint32_t*             m_numEncodedCusPerRow;
+    uint32_t*             m_rowSatdForVbv;
+    uint32_t*             m_cuCostsForVbv;
+    int*                  m_qpaAq;
+    double*               m_qpaRc;
+    double                m_avgQpRc;
+
     TComPic();
     virtual ~TComPic();
 
@@ -112,6 +124,8 @@
 
     virtual void  destroy(int bframes);
 
+    void          reInit(TEncCfg* cfg);
+
     bool          getUsedByCurr()           { return m_bUsedByCurr; }
 
     void          setUsedByCurr(bool bUsed) { m_bUsedByCurr = bUsed; }
diff -r 291b3a358a22 -r 6ea3bf6cbed0 source/common/lowres.h
--- a/source/common/lowres.h	Sat Feb 15 17:43:58 2014 -0600
+++ b/source/common/lowres.h	Sun Feb 16 23:05:13 2014 +0530
@@ -118,6 +118,7 @@
     int       intraMbs[X265_BFRAME_MAX + 2];
     int32_t*  intraCost;
     int64_t   satdCost;
+    uint16_t* lowresCostForRc;
     uint16_t(*lowresCosts[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2]);
     int32_t*  lowresMvCosts[2][X265_BFRAME_MAX + 1];
     MV*       lowresMvs[2][X265_BFRAME_MAX + 1];


More information about the x265-devel mailing list