[x265] [PATCH] rc: added TEncCfg instance to RateControl to reuse all the rc params directly

Aarthi Thirumalai aarthi at multicorewareinc.com
Fri Oct 11 13:01:48 CEST 2013


# HG changeset patch
# User Aarthi Thirumalai
# Date 1381489281 -19800
#      Fri Oct 11 16:31:21 2013 +0530
# Node ID df60f7175473db9723987f9f4f8f85b2fe3d7587
# Parent  9b9c6766967dc99cab93c3e09514346606125b3e
rc: added TEncCfg instance to RateControl to reuse all the rc params directly.

diff -r 9b9c6766967d -r df60f7175473 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Oct 11 16:10:11 2013 +0530
+++ b/source/encoder/encoder.cpp	Fri Oct 11 16:31:21 2013 +0530
@@ -93,7 +93,7 @@
     }
     m_lookahead = new Lookahead(this);
     m_dpb = new DPB(this);
-    m_rateControl = new RateControl(&param);
+    m_rateControl = new RateControl(this);
 }
 
 void Encoder::destroy()
diff -r 9b9c6766967d -r df60f7175473 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Fri Oct 11 16:10:11 2013 +0530
+++ b/source/encoder/ratecontrol.cpp	Fri Oct 11 16:31:21 2013 +0530
@@ -25,6 +25,7 @@
 #include "TLibCommon/TComPic.h"
 #include "slicetype.h"
 #include "ratecontrol.h"
+#include "TLibEncoder/TEncCfg.h"
 #include <math.h>
 
 using namespace x265;
@@ -49,24 +50,16 @@
     return 0.85 * pow(2.0, (qp - 12.0) / 6.0);
 }
 
-RateControl::RateControl(x265_param_t * param)
+RateControl::RateControl(TEncCfg * _cfg)
 {
-    keyFrameInterval = param->keyframeMax;
-    frameThreads = param->frameNumThreads;
-    framerate = param->frameRate;
-    rateTolerance = param->rc.rateTolerance;
-    bitrate = param->rc.bitrate * 1000;
-    frameDuration = 1.0 / param->frameRate;
-    rateControlMode = (RcMethod)(param->rc.rateControlMode);
-    ncu = (int)((param->sourceHeight * param->sourceWidth) / pow((int)param->maxCUSize, 2.0));
+    this->cfg = _cfg;
+    bitrate = cfg->param.rc.bitrate * 1000;
+    frameDuration = 1.0 / cfg->param.frameRate;
+    ncu = (int)((cfg->param.sourceHeight * cfg->param.sourceWidth) / pow((int)cfg->param.maxCUSize, 2.0));
     lastNonBPictType = -1;
-    baseQp = param->rc.qp;
+    baseQp = cfg->param.rc.qp;
     qp = baseQp;
     lastRceq = 1; // handles the cmplxrsum when the previous frame cost is zero
-    // heuristics- encoder specific
-    qCompress = param->rc.qCompress; // tweak and test for x265.
-    ipFactor = param->rc.ipFactor;
-    pbFactor = param->rc.pbFactor;
     totalBits = 0;
     shortTermCplxSum = 0;
     shortTermCplxCount = 0;
@@ -83,8 +76,8 @@
         wantedBitsWindow = bitrate * frameDuration;
         lastNonBPictType = I_SLICE;
     }
-    ipOffset = 6.0 * (float)(X265_LOG2(param->rc.ipFactor));
-    pbOffset = 6.0 * (float)(X265_LOG2(param->rc.pbFactor));
+    ipOffset = 6.0 * (float)(X265_LOG2(cfg->param.rc.ipFactor));
+    pbOffset = 6.0 * (float)(X265_LOG2(cfg->param.rc.pbFactor));
     for (int i = 0; i < 3; i++)
     {
         lastQScaleFor[i] = qp2qScale(ABR_INIT_QP_MIN);
@@ -100,7 +93,7 @@
     }
 
     //qstep - value set as encoder specific.
-    lstep = pow(2, param->rc.qpStep / 6.0);
+    lstep = pow(2, cfg->param.rc.qpStep / 6.0);
 }
 
 void RateControl::rateControlStart(TComPic* pic, Lookahead *l, RateControlEntry* rce)
diff -r 9b9c6766967d -r df60f7175473 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Fri Oct 11 16:10:11 2013 +0530
+++ b/source/encoder/ratecontrol.h	Fri Oct 11 16:31:21 2013 +0530
@@ -30,7 +30,7 @@
 namespace x265 {
 struct Lookahead;
 class TComPic;
-
+class TEncCfg;
 struct RateControlEntry
 {
     int pictType;
@@ -44,6 +44,7 @@
 struct RateControl
 {
     TComSlice *curFrame;        /* all info abt the current frame */
+    TEncCfg *cfg;
     SliceType frameType;        /* Current frame type */
     int ncu;                    /* number of CUs in a frame */
     int framerate;              /* current frame rate TODO: need to initialize in init */
@@ -76,7 +77,7 @@
     int64_t totalBits;   /* totalbits used for already encoded frames */
     double lastRceq;
     int framesDone;   /* framesDone keeps track of # of frames passed through RateCotrol already */
-    RateControl(x265_param_t * param);
+    RateControl(TEncCfg * _cfg);
 
     // to be called for each frame to process RateCOntrol and set QP
     void rateControlStart(TComPic* pic, Lookahead *, RateControlEntry* rce);


More information about the x265-devel mailing list