[x265] [PATCH STABLE] slicetype: upgrade frame cost variables to uint64_t

Steve Borho steve at borho.org
Fri Jan 24 02:20:03 CET 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1390526036 21600
#      Thu Jan 23 19:13:56 2014 -0600
# Branch stable
# Node ID 629d0a685dcbab262749bda97d6541899d6d6080
# Parent  e9ec7787cf5e3d5b15551d7e1b4542e05d868509
slicetype: upgrade frame cost variables to uint64_t

diff -r e9ec7787cf5e -r 629d0a685dcb source/common/lowres.cpp
--- a/source/common/lowres.cpp	Tue Jan 21 16:43:15 2014 -0600
+++ b/source/common/lowres.cpp	Thu Jan 23 19:13:56 2014 -0600
@@ -127,7 +127,7 @@
     sliceType = type;
     frameNum = poc;
     leadingBframes = 0;
-    satdCost = -1;
+    satdCost = (uint64_t)-1;
     memset(costEst, -1, sizeof(costEst));
 
     if (qpAqOffset && invQscaleFactor)
diff -r e9ec7787cf5e -r 629d0a685dcb source/common/lowres.h
--- a/source/common/lowres.h	Tue Jan 21 16:43:15 2014 -0600
+++ b/source/common/lowres.h	Thu Jan 23 19:13:56 2014 -0600
@@ -112,12 +112,12 @@
     bool   bLastMiniGopBFrame;
 
     /* lookahead output data */
-    int       costEst[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
-    int       costEstAq[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
+    uint64_t  costEst[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
+    uint64_t  costEstAq[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
     int32_t*  rowSatds[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
     int       intraMbs[X265_BFRAME_MAX + 2];
     int32_t*  intraCost;
-    int       satdCost;
+    uint64_t  satdCost;
     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 e9ec7787cf5e -r 629d0a685dcb source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Tue Jan 21 16:43:15 2014 -0600
+++ b/source/encoder/ratecontrol.cpp	Thu Jan 23 19:13:56 2014 -0600
@@ -534,7 +534,7 @@
         if (curSlice->getPOC() == 0)
             lastQScaleFor[P_SLICE] = q * fabs(cfg->param.rc.ipFactor);
 
-        rce->frameSizePlanned = predictSize(&pred[sliceType], q, lastSatd);
+        rce->frameSizePlanned = predictSize(&pred[sliceType], q, (double)lastSatd);
 
         return q;
     }
@@ -573,7 +573,7 @@
 
             // Now a hard threshold to make sure the frame fits in VBV.
             // This one is mostly for I-frames.
-            double bits = predictSize(&pred[sliceType], q, lastSatd);
+            double bits = predictSize(&pred[sliceType], q, (double)lastSatd);
 
             // For small VBVs, allow the frame to use up the entire VBV.
             double maxFillFactor;
@@ -590,7 +590,7 @@
                 bits *= qf;
                 if (bits < bufferRate / minFillFactor)
                     q *= bits * minFillFactor / bufferRate;
-                bits = predictSize(&pred[sliceType], q, lastSatd);
+                bits = predictSize(&pred[sliceType], q, (double)lastSatd);
             }
 
             q = X265_MAX(q0, q);
@@ -601,9 +601,9 @@
         if (sliceType == P_SLICE)
         {
             int nb = bframes;
-            double bits = predictSize(&pred[sliceType], q, lastSatd);
+            double bits = predictSize(&pred[sliceType], q, (double)lastSatd);
             double pbbits = bits;
-            double bbits = predictSize(&predBfromP, q * cfg->param.rc.pbFactor, lastSatd);
+            double bbits = predictSize(&predBfromP, q * cfg->param.rc.pbFactor, (double)lastSatd);
             double space;
             if (bbits > bufferRate)
                 nb = 0;
@@ -678,7 +678,7 @@
     int mbCount = (int)((cfg->param.sourceHeight * cfg->param.sourceWidth) / pow((int)16, 2.0));
 
     if  (rce->lastSatd >= mbCount)
-        updatePredictor(&pred[rce->sliceType], qp2qScale(rce->qpaRc), rce->lastSatd, (double)bits);
+        updatePredictor(&pred[rce->sliceType], qp2qScale(rce->qpaRc), (double)rce->lastSatd, (double)bits);
 
     if (!isVbv)
         return;
diff -r e9ec7787cf5e -r 629d0a685dcb source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Tue Jan 21 16:43:15 2014 -0600
+++ b/source/encoder/ratecontrol.h	Thu Jan 23 19:13:56 2014 -0600
@@ -46,19 +46,20 @@
 
 struct RateControlEntry
 {
+    uint64_t texBits;
+    uint64_t lastSatd;
+
     int sliceType;
-    int texBits;
     int mvBits;
+    int bframes;
+    int poc;
+
+    bool bLastMiniGopBFrame;
     double blurredComplexity;
     double qpaRc;
     double qRceq;
-
-    int lastSatd;
-    bool bLastMiniGopBFrame;
     double frameSizePlanned;
     double bufferRate;
-    int bframes;
-    int poc;
 };
 
 struct Predictor
@@ -97,7 +98,7 @@
     int bframeBits;
     double leadingNoBSatd;
 
-    int    lastSatd;
+    uint64_t lastSatd;
     int    qpConstant[3];
     double cplxrSum;          /* sum of bits*qscale/rceq */
     double wantedBitsWindow;  /* target bitrate * window */
diff -r e9ec7787cf5e -r 629d0a685dcb source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Tue Jan 21 16:43:15 2014 -0600
+++ b/source/encoder/slicetype.cpp	Thu Jan 23 19:13:56 2014 -0600
@@ -110,7 +110,7 @@
 // Called by RateControl to get the estimated SATD cost for a given picture.
 // It assumes dpb->prepareEncode() has already been called for the picture and
 // all the references are established
-int Lookahead::getEstimatedPictureCost(TComPic *pic)
+uint64_t Lookahead::getEstimatedPictureCost(TComPic *pic)
 {
     Lowres *frames[X265_LOOKAHEAD_MAX];
 
@@ -160,7 +160,7 @@
         break;
 
     default:
-        return -1;
+        return (uint64_t)-1;
     }
 
     if (pic->m_lowres.costEst[b - p0][p1 - b] < 0)
@@ -461,8 +461,8 @@
     int num_frames, origNumFrames, keyint_limit, framecnt;
     int maxSearch = X265_MIN(cfg->param.lookaheadDepth, X265_LOOKAHEAD_MAX);
     int cuCount = NUM_CUS;
-    int cost1p0, cost2p0, cost1b1, cost2p1;
     int reset_start;
+    uint64_t cost1p0, cost2p0, cost1b1, cost2p1;
 
     if (!lastNonB)
         return;
@@ -560,8 +560,8 @@
                 int j;
                 for (j = i + 2; j <= X265_MIN(i + cfg->param.bframes, num_frames - 1); j++)
                 {
-                    int pthresh = X265_MAX(INTER_THRESH - P_SENS_BIAS * (j - i - 1), INTER_THRESH / 10);
-                    int pcost = est.estimateFrameCost(frames, i + 0, j + 1, j + 1, 1);
+                    uint64_t pthresh = X265_MAX(INTER_THRESH - P_SENS_BIAS * (j - i - 1), INTER_THRESH / 10);
+                    uint64_t pcost = est.estimateFrameCost(frames, i + 0, j + 1, j + 1, 1);
                     if (pcost > pthresh * cuCount || frames[j + 1]->intraMbs[j - i + 1] > cuCount / 3)
                         break;
                     frames[j]->sliceType = X265_TYPE_B;
@@ -629,7 +629,7 @@
 }
 
 
-int Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int num_frames, int maxSearch)
+uint64_t Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int num_frames, int maxSearch)
 {
     /* Only do analysis during a normal scenecut check. */
     if (bRealScenecut && cfg->param.bframes)
@@ -675,21 +675,21 @@
     return scenecutInternal(frames, p0, p1, bRealScenecut);
 }
 
-int Lookahead::scenecutInternal(Lowres **frames, int p0, int p1, bool bRealScenecut)
+uint64_t Lookahead::scenecutInternal(Lowres **frames, int p0, int p1, bool bRealScenecut)
 {
     Lowres *frame = frames[p1];
 
     est.estimateFrameCost(frames, p0, p1, p1, 0);
 
-    int icost = frame->costEst[0][0];
-    int pcost = frame->costEst[p1 - p0][0];
+    uint64_t icost = frame->costEst[0][0];
+    uint64_t pcost = frame->costEst[p1 - p0][0];
     float bias;
     int gopSize = frame->frameNum - lastKeyframe;
     float threshMax = (float)(cfg->param.scenecutThreshold / 100.0);
 
     /* magic numbers pulled out of thin air */
     float threshMin = (float)(threshMax * 0.25);
-    int res;
+    uint64_t res;
 
     if (cfg->param.keyframeMin == cfg->param.keyframeMax)
         threshMin = threshMax;
@@ -720,7 +720,7 @@
 {
     char paths[2][X265_LOOKAHEAD_MAX + 1];
     int num_paths = X265_MIN(cfg->param.bframes + 1, length);
-    int best_cost = MotionEstimate::COST_MAX;
+    uint64_t best_cost = (uint64_t)-1;
     int idx = 0;
 
     /* Iterate over all currently possible paths */
@@ -733,7 +733,7 @@
         strcpy(paths[idx] + len + path, "P");
 
         /* Calculate the actual cost of the current path */
-        int cost = slicetypePathCost(frames, paths[idx], best_cost);
+        uint64_t cost = slicetypePathCost(frames, paths[idx], best_cost);
         if (cost < best_cost)
         {
             best_cost = cost;
@@ -745,10 +745,10 @@
     memcpy(best_paths[length % (X265_BFRAME_MAX + 1)], paths[idx ^ 1], length);
 }
 
-int Lookahead::slicetypePathCost(Lowres **frames, char *path, int threshold)
+uint64_t Lookahead::slicetypePathCost(Lowres **frames, char *path, uint64_t threshold)
 {
+    uint64_t cost = 0;
     int loc = 1;
-    int cost = 0;
     int cur_p = 0;
 
     path--; /* Since the 1st path element is really the second frame */
@@ -1035,10 +1035,10 @@
 
 /* If MB-tree changes the quantizers, we need to recalculate the frame cost without
  * re-running lookahead. */
-int Lookahead::frameCostRecalculate(Lowres** frames, int p0, int p1, int b)
+uint64_t Lookahead::frameCostRecalculate(Lowres** frames, int p0, int p1, int b)
 {
-    int score = 0;
-    int *row_satd = frames[b]->rowSatds[b-p0][p1-b]; 
+    uint64_t score = 0;
+    int *row_satd = frames[b]->rowSatds[b-p0][p1-b];
     double *qp_offset = IS_X265_TYPE_B(frames[0]->sliceType) ? frames[b]->qpAqOffset : frames[b]->qpOffset;
     x265_emms();
     for (int cuy = heightInCU - 1; cuy >= 0; cuy--)
@@ -1129,9 +1129,9 @@
     }
 }
 
-int CostEstimate::estimateFrameCost(Lowres **frames, int p0, int p1, int b, bool bIntraPenalty)
+uint64_t CostEstimate::estimateFrameCost(Lowres **frames, int p0, int p1, int b, bool bIntraPenalty)
 {
-    int score = 0;
+    uint64_t score = 0;
     Lowres *fenc = frames[b];
 
     if (fenc->costEst[b - p0][p1 - b] >= 0 && fenc->rowSatds[b - p0][p1 - b][0] != -1)
diff -r e9ec7787cf5e -r 629d0a685dcb source/encoder/slicetype.h
--- a/source/encoder/slicetype.h	Tue Jan 21 16:43:15 2014 -0600
+++ b/source/encoder/slicetype.h	Thu Jan 23 19:13:56 2014 -0600
@@ -52,11 +52,11 @@
     volatile uint32_t   completed;      // Number of CUs in this row for which cost estimation is completed
     volatile bool       active;
 
-    int                 costEst;        // Estimated cost for all CUs in a row
-    int                 costEstAq;      // Estimated weight Aq cost for all CUs in a row
+    uint64_t            costEst;        // Estimated cost for all CUs in a row
+    uint64_t            costEstAq;      // Estimated weight Aq cost for all CUs in a row
+    uint64_t            costIntraAq;    // Estimated weighted Aq Intra cost for all CUs in a row
+    int                 intraMbs;       // Number of Intra CUs
     int                 costIntra;      // Estimated Intra cost for all CUs in a row
-    int                 costIntraAq;    // Estimated weighted Aq Intra cost for all CUs in a row
-    int                 intraMbs;       // Number of Intra CUs
 
     int                 widthInCU;
     int                 heightInCU;
@@ -103,9 +103,9 @@
     bool             bDoSearch[2];
     bool             rowsCompleted;
     int              curb, curp0, curp1;
-    void             processRow(int row);
 
-    int      estimateFrameCost(Lowres **frames, int p0, int p1, int b, bool bIntraPenalty);
+    void     processRow(int row);
+    uint64_t estimateFrameCost(Lowres **frames, int p0, int p1, int b, bool bIntraPenalty);
 
 protected:
 
@@ -136,7 +136,7 @@
     void addPicture(TComPic*, int sliceType);
     void flush();
 
-    int  getEstimatedPictureCost(TComPic *pic);
+    uint64_t getEstimatedPictureCost(TComPic *pic);
 
 protected:
 
@@ -145,10 +145,10 @@
     void slicetypeAnalyse(Lowres **frames, bool bKeyframe);
 
     /* called by slicetypeAnalyse() to make slice decisions */
-    int  scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int numFrames, int maxSearch);
-    int  scenecutInternal(Lowres **frames, int p0, int p1, bool bRealScenecut);
-    void slicetypePath(Lowres **frames, int length, char(*best_paths)[X265_LOOKAHEAD_MAX + 1]);
-    int  slicetypePathCost(Lowres **frames, char *path, int threshold);
+    uint64_t scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int numFrames, int maxSearch);
+    uint64_t scenecutInternal(Lowres **frames, int p0, int p1, bool bRealScenecut);
+    void     slicetypePath(Lowres **frames, int length, char(*best_paths)[X265_LOOKAHEAD_MAX + 1]);
+    uint64_t slicetypePathCost(Lowres **frames, char *path, uint64_t threshold);
 
     /* called by slicetypeAnalyse() to effect cuTree adjustments to adaptive
      * quant offsets */
@@ -159,7 +159,7 @@
     void cuTreeFinish(Lowres *frame, double averageDuration, int ref0Distance);
 
     /* called by getEstimatedPictureCost() to finalize cuTree costs */
-    int  frameCostRecalculate(Lowres **frames, int p0, int p1, int b);
+    uint64_t frameCostRecalculate(Lowres **frames, int p0, int p1, int b);
 };
 }
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265.patch
Type: text/x-patch
Size: 13080 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20140123/cebb3955/attachment-0001.bin>


More information about the x265-devel mailing list