[x265] [PATCH 1 of 6] vbv: Introduce states to hold row data for row level VBV ratecontrol

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Thu Feb 20 14:25:43 CET 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1392895417 -19800
#      Thu Feb 20 16:53:37 2014 +0530
# Node ID 39efc006d3efa89df765b3d62e810854b41fe401
# Parent  fec3cab870437c101b409425b6c2d6c403bd0efa
vbv: Introduce states to hold row data for row level VBV ratecontrol.

diff -r fec3cab87043 -r 39efc006d3ef source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Thu Feb 20 15:54:52 2014 +0530
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Thu Feb 20 16:53:37 2014 +0530
@@ -99,6 +99,7 @@
     m_mvpIdx[0] = NULL;
     m_mvpIdx[1] = NULL;
     m_chromaFormat = 0;
+    m_baseQp = 0;
 }
 
 TComDataCU::~TComDataCU()
@@ -235,6 +236,7 @@
     m_totalBits        = 0;
     m_numPartitions    = pic->getNumPartInCU();
     int qp             = pic->m_lowres.invQscaleFactor ? pic->getCU(getAddr())->getQP(0) : m_slice->getSliceQp();
+    m_baseQp           = pic->getCU(getAddr())->m_baseQp;
     for (int i = 0; i < 4; i++)
     {
         m_avgCost[i] = 0;
diff -r fec3cab87043 -r 39efc006d3ef source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h	Thu Feb 20 15:54:52 2014 +0530
+++ b/source/Lib/TLibCommon/TComDataCU.h	Thu Feb 20 16:53:37 2014 +0530
@@ -179,6 +179,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 fec3cab87043 -r 39efc006d3ef source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp	Thu Feb 20 15:54:52 2014 +0530
+++ b/source/Lib/TLibCommon/TComPic.cpp	Thu Feb 20 16:53:37 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;
 }
 
@@ -94,7 +104,46 @@
     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,  numRows * numCols * sizeof(uint32_t));
+        memset(m_qpaRc, 0, numRows * sizeof(double));
+        memset(m_qpaAq, 0, numRows * sizeof(uint32_t));
+    }
 }
 
 void TComPic::destroy(int bframes)
@@ -121,6 +170,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 fec3cab87043 -r 39efc006d3ef source/Lib/TLibCommon/TComPic.h
--- a/source/Lib/TLibCommon/TComPic.h	Thu Feb 20 15:54:52 2014 +0530
+++ b/source/Lib/TLibCommon/TComPic.h	Thu Feb 20 16:53:37 2014 +0530
@@ -104,6 +104,16 @@
     uint32_t              m_checksum[3];
 
     bool                  m_bChromaPlanesExtended; // orig chroma planes motion extended for weightp analysis
+    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 +122,8 @@
 
     virtual void  destroy(int bframes);
 
+    void          reInit(TEncCfg* cfg);
+
     bool          getUsedByCurr()           { return m_bUsedByCurr; }
 
     void          setUsedByCurr(bool bUsed) { m_bUsedByCurr = bUsed; }
diff -r fec3cab87043 -r 39efc006d3ef source/common/lowres.h
--- a/source/common/lowres.h	Thu Feb 20 15:54:52 2014 +0530
+++ b/source/common/lowres.h	Thu Feb 20 16:53:37 2014 +0530
@@ -117,6 +117,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];
diff -r fec3cab87043 -r 39efc006d3ef source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Feb 20 15:54:52 2014 +0530
+++ b/source/encoder/encoder.cpp	Thu Feb 20 16:53:37 2014 +0530
@@ -280,6 +280,7 @@
 
         /* Copy input picture into a TComPic, send to lookahead */
         pic->getSlice()->setPOC(++m_pocLast);
+        pic->reInit(this);
         pic->getPicYuvOrg()->copyFromPicture(*pic_in, m_pad);
         pic->m_userData = pic_in->userData;
         pic->m_pts = pic_in->pts;
diff -r fec3cab87043 -r 39efc006d3ef source/encoder/encoder.h
--- a/source/encoder/encoder.h	Thu Feb 20 15:54:52 2014 +0530
+++ b/source/encoder/encoder.h	Thu Feb 20 16:53:37 2014 +0530
@@ -84,7 +84,6 @@
     Lookahead*         m_lookahead;
     FrameEncoder*      m_frameEncoder;
     DPB*               m_dpb;
-    RateControl*       m_rateControl;
 
     /* frame parallelism */
     int                m_curEncoder;
@@ -145,6 +144,8 @@
 
     void signalReconRowCompleted(int poc);
 
+    RateControl*       m_rateControl;
+
 protected:
 
     // Returns total number of bits for encoded pic
diff -r fec3cab87043 -r 39efc006d3ef source/x265.h
--- a/source/x265.h	Thu Feb 20 15:54:52 2014 +0530
+++ b/source/x265.h	Thu Feb 20 16:53:37 2014 +0530
@@ -801,6 +801,8 @@
          * across frames and assigns more bits to these CUs. Improves encode efficiency.
          * Default: OFF (0) */
         int       cuTree;
+        /* In CRF mode, maximum CRF as caused by VBV */
+        double    rfConstantMax;
     } rc;
 } x265_param;
 


More information about the x265-devel mailing list