[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
Fri Feb 21 07:08:36 CET 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1392958743 -19800
#      Fri Feb 21 10:29:03 2014 +0530
# Node ID d90c9b27f413a4b00079a31ca7b0411a5fb8eb19
# Parent  0c19c44af2d3a8825d804597f1c2f82e32e4d4b7
vbv: Introduce states to hold row data for row level VBV ratecontrol.

diff -r 0c19c44af2d3 -r d90c9b27f413 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Fri Feb 21 12:23:22 2014 +0900
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Fri Feb 21 10:29:03 2014 +0530
@@ -99,8 +99,8 @@
     m_mvpIdx[0] = NULL;
     m_mvpIdx[1] = NULL;
     m_chromaFormat = 0;
+    m_baseQp = 0;
 }
-
 TComDataCU::~TComDataCU()
 {}
 
@@ -235,6 +235,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 0c19c44af2d3 -r d90c9b27f413 source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h	Fri Feb 21 12:23:22 2014 +0900
+++ b/source/Lib/TLibCommon/TComDataCU.h	Fri Feb 21 10:29:03 2014 +0530
@@ -179,7 +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 0c19c44af2d3 -r d90c9b27f413 source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp	Fri Feb 21 12:23:22 2014 +0900
+++ b/source/Lib/TLibCommon/TComPic.cpp	Fri Feb 21 10:29:03 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_rowEncodedBits(NULL)
+    , m_numEncodedCusPerRow(NULL)
+    , m_rowSatdForVbv(NULL)
+    , m_cuCostsForVbv(NULL)
 {
     m_reconRowCount = 0;
     m_countRefEncoders = 0;
@@ -69,9 +76,11 @@
     m_ssimCnt = 0;
     m_frameTime = 0.0;
     m_elapsedCompressTime = 0.0;
+    m_qpaAq = 0;
+    m_qpaRc = 0;
+    m_avgQpRc = 0;
     m_bChromaPlanesExtended = false;
 }
-
 TComPic::~TComPic()
 {}
 
@@ -94,9 +103,47 @@
     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)
 {
     if (m_picSym)
@@ -119,8 +166,16 @@
         delete m_reconPicYuv;
         m_reconPicYuv = NULL;
     }
+    m_lowres.destroy(bframes);
 
-    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 0c19c44af2d3 -r d90c9b27f413 source/Lib/TLibCommon/TComPic.h
--- a/source/Lib/TLibCommon/TComPic.h	Fri Feb 21 12:23:22 2014 +0900
+++ b/source/Lib/TLibCommon/TComPic.h	Fri Feb 21 10:29:03 2014 +0530
@@ -102,18 +102,25 @@
     MD5Context            m_state[3];
     uint32_t              m_crc[3];
     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();
 
     bool          create(TEncCfg* cfg);
-
     virtual void  destroy(int bframes);
+    void          reInit(TEncCfg* cfg);
 
     bool          getUsedByCurr()           { return m_bUsedByCurr; }
-
     void          setUsedByCurr(bool bUsed) { m_bUsedByCurr = bUsed; }
 
     bool          getIsLongTerm()           { return m_bIsLongTerm; }
diff -r 0c19c44af2d3 -r d90c9b27f413 source/common/lowres.h
--- a/source/common/lowres.h	Fri Feb 21 12:23:22 2014 +0900
+++ b/source/common/lowres.h	Fri Feb 21 10:29:03 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 0c19c44af2d3 -r d90c9b27f413 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Feb 21 12:23:22 2014 +0900
+++ b/source/encoder/encoder.cpp	Fri Feb 21 10:29:03 2014 +0530
@@ -277,9 +277,9 @@
         }
         else
             pic = m_freeList.popBack();
-
         /* 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 0c19c44af2d3 -r d90c9b27f413 source/encoder/encoder.h
--- a/source/encoder/encoder.h	Fri Feb 21 12:23:22 2014 +0900
+++ b/source/encoder/encoder.h	Fri Feb 21 10:29:03 2014 +0530
@@ -84,8 +84,6 @@
     Lookahead*         m_lookahead;
     FrameEncoder*      m_frameEncoder;
     DPB*               m_dpb;
-    RateControl*       m_rateControl;
-
     /* frame parallelism */
     int                m_curEncoder;
 
@@ -142,11 +140,10 @@
     int  extractNalData(NALUnitEBSP **nalunits);
 
     void updateVbvPlan(RateControl* rc);
-
     void signalReconRowCompleted(int poc);
+    RateControl*       m_rateControl;
 
 protected:
-
     // Returns total number of bits for encoded pic
     uint64_t calculateHashAndPSNR(TComPic* pic, FrameEncoder *curEncoder, NALUnitEBSP **nalunits);
 };
diff -r 0c19c44af2d3 -r d90c9b27f413 source/x265.h
--- a/source/x265.h	Fri Feb 21 12:23:22 2014 +0900
+++ b/source/x265.h	Fri Feb 21 10:29:03 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