[x265] [PATCH 3 of 6] vbv: Add row predictors, rc states for vbv

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


# HG changeset patch
# User Aarthi Thirumalai
# Date 1392898673 -19800
#      Thu Feb 20 17:47:53 2014 +0530
# Node ID ebc23ec5ac1c5f8e2abe0d0b88414fabd2fdf1bb
# Parent  1c037c64274dce2f39db348967259d7d623c1b18
vbv: Add row predictors, rc states for vbv.

diff -r 1c037c64274d -r ebc23ec5ac1c source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Feb 20 17:03:38 2014 +0530
+++ b/source/encoder/encoder.cpp	Thu Feb 20 17:47:53 2014 +0530
@@ -218,6 +218,7 @@
         FrameEncoder *encoder = &m_frameEncoder[encIdx];
         double bits;
         bits = encoder->m_rce.frameSizePlanned;
+        bits = X265_MAX(bits, m_rateControl->frameSizeEstimated);
         rc->bufferFill -= bits;
         rc->bufferFill = X265_MAX(rc->bufferFill, 0);
         rc->bufferFill += encoder->m_rce.bufferRate;
diff -r 1c037c64274d -r ebc23ec5ac1c source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Thu Feb 20 17:03:38 2014 +0530
+++ b/source/encoder/ratecontrol.cpp	Thu Feb 20 17:47:53 2014 +0530
@@ -243,11 +243,12 @@
     lastNonBPictType = I_SLICE;
     isAbrReset = false;
     lastAbrResetPoc = -1;
+    frameSizeEstimated = 0;
     // vbv initialization
     cfg->param.rc.vbvBufferSize = Clip3(0, 2000000, cfg->param.rc.vbvBufferSize);
     cfg->param.rc.vbvMaxBitrate = Clip3(0, 2000000, cfg->param.rc.vbvMaxBitrate);
     cfg->param.rc.vbvBufferInit = Clip3(0.0, 2000000.0, cfg->param.rc.vbvBufferInit);
-
+    vbvMinRate = 0;
     if (cfg->param.rc.vbvBufferSize)
     {
         if (cfg->param.rc.rateControlMode == X265_RC_CQP)
@@ -318,6 +319,14 @@
         pred[i].offset = 0.0;
     }
 
+    for (int i = 0; i < 4; i++)
+    {
+        rowPreds[i].coeff = 0.25;
+        rowPreds[i].count = 1.0;
+        rowPreds[i].decay = 0.5;
+        rowPreds[i].offset = 0.0;
+    }
+
     predBfromP = pred[0];
     bframes = cfg->param.bframes;
     bframeBits = 0;
@@ -376,7 +385,11 @@
     rce->poc = curSlice->getPOC();
 
     if (isVbv)
+    {
+        rowPred[0] = &rowPreds[sliceType];
+        rowPred[1] = &rowPreds[3];
         updateVbvPlan(enc);
+    }
 
     if (isAbr) //ABR,CRF
     {
@@ -385,9 +398,10 @@
         rce->lastSatd = currentSatd; 
         double q = qScale2qp(rateEstimateQscale(pic, rce));
         qp = Clip3(MIN_QP, MAX_MAX_QP, (int)(q + 0.5));
-        rce->qpaRc = q;
+        rce->qpaRc = pic->m_avgQpRc = q;
         /* copy value of lastRceq into thread local rce struct *to be used in RateControlEnd() */
         rce->qRceq = lastRceq;
+        rce->qpNoVbv = qpNoVbv;
         accumPQpUpdate();
     }
     else //CQP
@@ -399,7 +413,11 @@
     }
 
     if (sliceType != B_SLICE)
+    {
         lastNonBPictType = sliceType;
+        leadingNoBSatd = currentSatd;
+    }
+    rce->leadingNoBSatd = leadingNoBSatd;
     framesDone++;
     /* set the final QP to slice structure */
     curSlice->setSliceQp(qp);
@@ -462,9 +480,11 @@
         else
             q += pbOffset;
 
-        rce->frameSizePlanned = predictSize(&predBfromP, qp2qScale(q), leadingNoBSatd);
-
-        return qp2qScale(q);
+        qpNoVbv = q;
+        double qScale = qp2qScale(qpNoVbv);
+        rce->frameSizePlanned = predictSize(&predBfromP, qScale, (double)leadingNoBSatd);
+        frameSizeEstimated = rce->frameSizePlanned;
+        return qScale;
     }
     else
     {
@@ -555,7 +575,7 @@
             if (qCompress != 1 && framesDone == 0)
                 q = qp2qScale(ABR_INIT_QP) / fabs(cfg->param.rc.ipFactor);
         }
-
+        qpNoVbv = qScale2qp(q);
         double lmin1 = lmin[sliceType];
         double lmax1 = lmax[sliceType];
         q = Clip3(lmin1, lmax1, q);
@@ -840,7 +860,7 @@
             if (rce->bLastMiniGopBFrame)
             {
                 if (rce->bframes != 0)
-                    updatePredictor(&predBfromP, qp2qScale(rce->qpaRc), (double)rce->lastSatd, (double)bframeBits / rce->bframes);
+                    updatePredictor(&predBfromP, qp2qScale(rce->qpaRc), (double)rce->leadingNoBSatd, (double)bframeBits / rce->bframes);
                 bframeBits = 0;
             }
         }
diff -r 1c037c64274d -r ebc23ec5ac1c source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Thu Feb 20 17:03:38 2014 +0530
+++ b/source/encoder/ratecontrol.h	Thu Feb 20 17:47:53 2014 +0530
@@ -53,7 +53,7 @@
     int mvBits;
     int bframes;
     int poc;
-
+    int64_t leadingNoBSatd;
     bool bLastMiniGopBFrame;
     double blurredComplexity;
     double qpaRc;
@@ -61,6 +61,7 @@
     double frameSizePlanned;
     double bufferRate;
     double movingAvgSum;
+    double qpNoVbv;
 };
 
 struct Predictor
@@ -94,9 +95,10 @@
     bool isVbv;
     Predictor pred[5];
     Predictor predBfromP;
+    Predictor rowPreds[4];
+    Predictor *rowPred[2];
     int bframes;
     int bframeBits;
-    double leadingNoBSatd;
     bool isAbrReset;
     int lastAbrResetPoc;
     int64_t currentSatd;
@@ -106,6 +108,7 @@
     double ipOffset;
     double pbOffset;
     int lastNonBPictType;
+    int64_t leadingNoBSatd;
     double accumPQp;          /* for determining I-frame quant */
     double accumPNorm;
     double lastQScaleFor[3];  /* last qscale for a specific pict type, used for max_diff & ipb factor stuff */
@@ -118,6 +121,8 @@
     double lastRceq;
     int framesDone;           /* framesDone keeps track of # of frames passed through RateCotrol already */
     double qCompress;
+    double qpNoVbv;             /* QP for the current frame if 1-pass VBV was disabled. */
+    double frameSizeEstimated;  /* hold synched frameSize, updated from cu level vbv rc */
     RateControl(TEncCfg * _cfg);
 
     // to be called for each frame to process RateControl and set QP


More information about the x265-devel mailing list