[x265] [PATCH] Added few varibales in related to ABR stuff in x265_param_t and made corresponding changes in ratecontrol.cpp and .h

sumalatha at multicorewareinc.com sumalatha at multicorewareinc.com
Tue Aug 13 08:22:09 CEST 2013


# HG changeset patch
# User sumalatha
# Date 1376370329 -19800
# Node ID 3144cbb0d745ffd94a58f5414e3fd8070166a43d
# Parent  c8fff4b1bec8716803984b5d378e917f01720e8b
Added few varibales in related to ABR stuff in x265_param_t and made corresponding changes in ratecontrol.cpp and .h.

diff -r c8fff4b1bec8 -r 3144cbb0d745 source/common/common.cpp
--- a/source/common/common.cpp	Mon Aug 12 22:38:13 2013 -0500
+++ b/source/common/common.cpp	Tue Aug 13 10:35:29 2013 +0530
@@ -137,6 +137,14 @@
     param->bEnableRDOQTS = 1;
     param->bEnableTransformSkip = 1;
     param->bEnableTSkipFast = 1;
+    //ABR relatedstuff
+    param->bitrate = 1000;
+    param->rateTolerance = 1;
+    param->qCompress = 0.6;
+    param->ipFactor = 1.4;
+    param->pbFactor = 1.3;
+    param->qpStep = 4;
+    param->rateControlMode = X265_RC_ABR;
 }
 
 extern "C"
diff -r c8fff4b1bec8 -r 3144cbb0d745 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Mon Aug 12 22:38:13 2013 -0500
+++ b/source/encoder/ratecontrol.cpp	Tue Aug 13 10:35:29 2013 +0530
@@ -31,20 +31,19 @@
     keyFrameInterval = param->keyframeInterval;
     fps = param->frameRate;
     bframes = param->bframes;
-    //TODO : set default value here,later can get from  param as done in x264?
-    rateTolerance = 1;
-    //TODO : introduce bitrate var in param and cli options
-    bitrate = param->bitrate * 1000;
+    rateTolerance = param->rc.rateTolerance;
+    bitrate = param->rc.bitrate * 1000;
     fps = param->frameRate;
-    isAbrEnabled = true; // set from param later.
+    rateControlMode = param->rc.rateControlMode;
     ncu = (param->sourceHeight * param->sourceWidth) / pow(2, param->maxCUSize);
     lastNonBPictType = -1;
-    //TODO : need  to confirm default val if mbtree is disabled
-    qCompress = 1;
-    if (isAbrEnabled)
+    qCompress = param->rc.qCompress;
+    ipFactor = param->rc.ipFactor;
+    pbFactor = param->rc.pbFactor;
+    if (rateControlMode == X265_RC_ABR)
     {
         //TODO : confirm this value. obtained it from x264 when crf is disabled , abr enabled.
-#define ABR_INIT_QP (24  + 6 * (param->internalBitDepth - 8));
+#define ABR_INIT_QP (24  + 6 * (X265_DEPTH - 8))
         accumPNorm = .01;
         accumPQp = (ABR_INIT_QP)*accumPNorm;
         /* estimated ratio that produces a reasonable QP for the first I-frame */
@@ -52,6 +51,16 @@
         wantedBitsWindow = 1.0 * bitrate / fps;
         lastNonBPictType = I_SLICE;
     }
+    ipOffset = 6.0 * log( param->rc.ipFactor );
+    pbOffset = 6.0 * log( param->rc.pbFactor );
+    for( int i = 0; i < 3; i++ )
+    {
+        lastQScaleFor[i] = qp2qScale( ABR_INIT_QP );
+        lmin[i] = qp2qScale( MIN_QP);
+        lmax[i] = qp2qScale( MAX_QP );
+    }
+    lstep = pow( 2, param->rc.qpStep / 6.0 );
+
 }
 
 void RateControl::rateControlInit(TComSlice* frame)
@@ -66,7 +75,7 @@
     float q;
 
     //Always enabling ABR
-    if (isAbrEnabled)
+    if (rateControlMode == X265_RC_ABR)
     {
         q = qScale2qp(rateEstimateQscale(lFrame));
     }
@@ -86,7 +95,6 @@
 
 void RateControl::accumPQpUpdate()
 {
-    //x264_ratecontrol_t *rc = h->rc;
     accumPQp   *= .95;
     accumPNorm *= .95;
     accumPNorm += 1;
@@ -131,7 +139,6 @@
         else
             q += pbOffset;
 
-        qpNoVbv = q;
         return qp2qScale(q);
     }
     else
@@ -152,20 +159,14 @@
 
         double wantedBits, overflow = 1;
 
-        lastSatd = 0;     //need to get this from lookahead  //x264_rc_analyse_slice( h );
-        shortTermCplxSum *= 0.5;
-        shortTermCplxCount *= 0.5;
-        //TODO:need to get the duration for each frame
-        //short_term_cplxsum += last_satd / (CLIP_DURATION(h->fenc->f_duration) / BASE_FRAME_DURATION);
-        shortTermCplxCount++;
-
+        lastSatd = 0;     //TODO:need to get this from lookahead  //x264_rc_analyse_slice( h );
         rce->pCount = ncu;
 
         rce->pictType = pictType;
 
         //TODO:wanted_bits_window, fps , h->fenc->i_reordered_pts, h->i_reordered_pts_delay, h->fref_nearest[0]->f_qp_avg_rc, h->param.rc.f_ip_factor, h->sh.i_type
         //need to checked where it is initialized
-        q = getQScale(rce, wantedBitsWindow / cplxrSum, fps);
+        q = getQScale(rce, wantedBitsWindow / cplxrSum);
 
         /* ABR code can potentially be counterproductive in CBR, so just don't bother.
          * Don't run it if the frame complexity is zero either. */
@@ -193,7 +194,7 @@
             && lastNonBPictType != I_SLICE)
         {
             q = qp2qScale(accumPQp / accumPNorm);
-            q /= fabs(h->param.rc.f_ip_factor);
+            q /= fabs(ipFactor);
         }
         else if (fps > 0)
         {
@@ -212,7 +213,7 @@
             }
         }
 
-        qpNoVbv = qScale2qp(q);
+        //qpNoVbv = qScale2qp(q);
 
         //FIXME use get_diff_limited_q() ?
         //q = clip_qscale( h, pict_type, q );
@@ -224,7 +225,7 @@
             lastQScale = q;
 
         if (!fps == 0)
-            lastQScaleFor[P_SLICE] = q * fabs(h->param.rc.f_ip_factor);
+            lastQScaleFor[P_SLICE] = q * fabs(ipFactor);
 
         //this is for VBV stuff
         //frame_size_planned = predict_size( &pred[h->sh.i_type], q, last_satd );
@@ -249,7 +250,7 @@
         q = lastQScaleFor[rce->pictType];
     else
     {
-        lastRceq = q;
+        //lastRceq = q;// CHECK: not used further
         q /= rateFactor;
         lastQScale = q;
     }
diff -r c8fff4b1bec8 -r 3144cbb0d745 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Mon Aug 12 22:38:13 2013 -0500
+++ b/source/encoder/ratecontrol.h	Tue Aug 13 10:35:29 2013 +0530
@@ -59,8 +59,8 @@
     int ncu;                    /* number of CUs in a frame */
     TComSlice *curFrame;        /* all info abt the current frame */
     SliceType frameType;        /* Current frame type */
-    float frameDuration;        /* current frame duration in seconds */
-    int fps;          /* current frame number TODO: need to initaialize in init */
+    //float frameDuration;        /* current frame duration in seconds */
+    int fps;                    /* current frame rate TODO: need to initaialize in init */
     int keyFrameInterval;       /* TODO: need to initialize in init */
     bool isAbrEnabled;
 
@@ -75,17 +75,13 @@
     int bframes;
     /* ABR stuff */
     int    lastSatd;
-    double lastRceq;
     double cplxrSum;           /* sum of bits*qscale/rceq */
-    double expectedBitsSum;   /* sum of qscale2bits after rceq, ratefactor, and overflow, only includes finished frames */
-    int64_t fillerBitsSum;    /* sum in bits of finished frames' filler data */
     double wantedBitsWindow;  /* target bitrate * window */
-    double cbrDecay;
-    double shortTermCplxSum;
-    double shortTermCplxCount;
-    double rateFactorConstant;
+
     double ipOffset;
     double pbOffset;
+    float ipFactor;
+    float pbFactor;
 
     int lastNonBPictType;
     double accumPQp;          /* for determining I-frame quant */
@@ -97,7 +93,8 @@
     float qpNoVbv;             /* QP for the current frame if 1-pass VBV was disabled. */
     double lmin[3];             /* min qscale by frame type */
     double lmax[3];
-    double frameSizePlanned;
+
+    RcMethod rateControlMode;
 
     RateControl(x265_param_t * param);    // constructor for initializing values for ratecontrol vars
     void rateControlInit(TComSlice* frame);   // to be called for each frame to set the reqired parameters for rateControl.
diff -r c8fff4b1bec8 -r 3144cbb0d745 source/x265.h
--- a/source/x265.h	Mon Aug 12 22:38:13 2013 -0500
+++ b/source/x265.h	Tue Aug 13 10:35:29 2013 +0530
@@ -155,6 +155,27 @@
 #define X265_LOG_INFO           2
 #define X265_LOG_DEBUG          3
 
+/* rate tolerance method */
+typedef enum RcMethod
+{
+    X265_RC_ABR,
+    X265_RC_CQP
+}
+X265_RC_METHODS;
+
+typedef struct rate_control_t
+{
+    double    bitrate;
+    double    rateTolerance;
+    double    qCompress;
+    float     ipFactor;
+    float     pbFactor;
+    int       qpStep;
+    RcMethod  rateControlMode;
+}
+rate_control_t;
+
+
 typedef struct x265_param_t
 {
     int       logLevel;
@@ -218,6 +239,9 @@
 
     // debugging
     int       bEnableDecodedPictureHashSEI;    ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
+
+    //rate control related Stuff
+    rate_control_t rc;
 }
 x265_param_t;
 


More information about the x265-devel mailing list