[x265] [PATCH] vbv: moved updateVbvPlan from Encoder to RateControl:updateVbvPlan

Aarthi Thirumalai aarthi at multicorewareinc.com
Mon Dec 2 06:24:07 CET 2013


# HG changeset patch
# User Aarthi Thirumalai
# Date 1385961804 -19800
#      Mon Dec 02 10:53:24 2013 +0530
# Node ID a717ae477d0c980ab3a05d060e3bf298cd4bf6cb
# Parent  e83550d5f10d7cb950db34cbb96f476ce8b0ab2f
vbv: moved updateVbvPlan from Encoder to RateControl:updateVbvPlan

Since the RateControlStart is executed sequentially for all frameEncoder threads, we can update the bufferFill at the end of RateControlStart itself.

diff -r e83550d5f10d -r a717ae477d0c source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Sun Dec 01 19:44:27 2013 -0600
+++ b/source/encoder/encoder.cpp	Mon Dec 02 10:53:24 2013 +0530
@@ -190,24 +190,7 @@
     return m_frameEncoder->getStreamHeaders(nalunits);
 }
 
-void Encoder::updateVbvPlan(RateControl* rc)
-{
-    int encIdx, curIdx;
 
-    curIdx = (m_curEncoder + param.frameNumThreads - 1) % param.frameNumThreads;
-    encIdx = (curIdx + 1) % param.frameNumThreads;
-    while (encIdx != curIdx)
-    {
-        FrameEncoder *encoder = &m_frameEncoder[encIdx];
-        double bits;
-        bits = encoder->m_rce.frameSizePlanned;
-        rc->bufferFill -= bits;
-        rc->bufferFill = X265_MAX(rc->bufferFill, 0);
-        rc->bufferFill += encoder->m_rce.bufferRate;
-        rc->bufferFill = X265_MIN(rc->bufferFill, rc->bufferSize);
-        encIdx = (encIdx + 1) % param.frameNumThreads;
-    }
-}
 
 /**
  \param   flush               force encoder to encode a frame
@@ -332,7 +315,7 @@
         m_dpb->prepareEncode(fenc);
 
         // set slice QP
-        m_rateControl->rateControlStart(fenc, m_lookahead, &curEncoder->m_rce, this);
+        m_rateControl->rateControlStart(fenc, m_lookahead, &curEncoder->m_rce);
 
         // Allow FrameEncoder::compressFrame() to start in a worker thread
         curEncoder->m_enable.trigger();
diff -r e83550d5f10d -r a717ae477d0c source/encoder/encoder.h
--- a/source/encoder/encoder.h	Sun Dec 01 19:44:27 2013 -0600
+++ b/source/encoder/encoder.h	Mon Dec 02 10:53:24 2013 +0530
@@ -134,8 +134,6 @@
 
     int  extractNalData(NALUnitEBSP **nalunits);
 
-    void updateVbvPlan(RateControl* rc);
-
 protected:
 
     uint64_t calculateHashAndPSNR(TComPic* pic, NALUnitEBSP **nalunits); // Returns total number of bits for encoded pic
diff -r e83550d5f10d -r a717ae477d0c source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Sun Dec 01 19:44:27 2013 -0600
+++ b/source/encoder/ratecontrol.cpp	Mon Dec 02 10:53:24 2013 +0530
@@ -25,7 +25,6 @@
 
 #include "TLibCommon/TComPic.h"
 #include "TLibEncoder/TEncCfg.h"
-#include "encoder.h"
 #include "slicetype.h"
 #include "ratecontrol.h"
 #include <math.h>
@@ -281,7 +280,7 @@
     lstep = pow(2, cfg->param.rc.qpStep / 6.0);
 }
 
-void RateControl::rateControlStart(TComPic* pic, Lookahead *l, RateControlEntry* rce, Encoder* enc)
+void RateControl::rateControlStart(TComPic* pic, Lookahead *l, RateControlEntry* rce)
 {
     curSlice = pic->getSlice();
     sliceType = curSlice->getSliceType();
@@ -297,7 +296,9 @@
     rce->poc = curSlice->getPOC();
 
     if (isVbv)
-        updateVbvPlan(enc);
+    {
+        updateVbvPlan(rce);
+    }
 
     if (isAbr) //ABR,CRF
     {
@@ -321,6 +322,7 @@
     /* set the final QP to slice structure */
     curSlice->setSliceQp(qp);
     curSlice->setSliceQpBase(qp);
+
 }
 
 void RateControl::accumPQpUpdate()
@@ -475,10 +477,14 @@
     }
 }
 
-void RateControl::updateVbvPlan(Encoder* enc)
+void RateControl::updateVbvPlan(RateControlEntry *rce)
 {
     bufferFill = bufferFillFinal;
-    enc->updateVbvPlan(this);
+    double bits = rce->frameSizePlanned;
+    bufferFill -= bits;
+    bufferFill = X265_MAX(bufferFill, 0);
+    bufferFill += rce->bufferRate;
+    bufferFill = X265_MIN(bufferFill, bufferSize);
 }
 
 double RateControl::predictSize(Predictor *p, double q, double var)
diff -r e83550d5f10d -r a717ae477d0c source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Sun Dec 01 19:44:27 2013 -0600
+++ b/source/encoder/ratecontrol.h	Mon Dec 02 10:53:24 2013 +0530
@@ -32,7 +32,6 @@
 // encoder namespace
 
 struct Lookahead;
-class Encoder;
 class TComPic;
 class TEncCfg;
 
@@ -110,7 +109,7 @@
     RateControl(TEncCfg * _cfg);
 
     // to be called for each frame to process RateControl and set QP
-    void rateControlStart(TComPic* pic, Lookahead *, RateControlEntry* rce, Encoder* enc);
+    void rateControlStart(TComPic* pic, Lookahead *, RateControlEntry* rce);
     void calcAdaptiveQuantFrame(TComPic *pic);
     int rateControlEnd(int64_t bits, RateControlEntry* rce);
 
@@ -124,7 +123,7 @@
     void updateVbv(int64_t bits, RateControlEntry* rce);
     void updatePredictor(Predictor *p, double q, double var, double bits);
     double clipQscale(double q);
-    void updateVbvPlan(Encoder* enc);
+    void updateVbvPlan(RateControlEntry *rce);
     double predictSize(Predictor *p, double q, double var);
 };
 }


More information about the x265-devel mailing list