[x265-commits] [x265] Generating sum & ssd values for weightp decision in looka...

Shazeb Nawaz Khan shazeb at multicorewareinc.com
Mon Nov 4 07:21:21 CET 2013


details:   http://hg.videolan.org/x265/rev/2ab39c2dd50f
branches:  
changeset: 4822:2ab39c2dd50f
user:      Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
date:      Mon Nov 04 11:40:49 2013 +0530
description:
Generating sum & ssd values for weightp decision in lookahead

diffstat:

 source/common/lowres.h         |   8 ++++--
 source/encoder/encoder.cpp     |   2 +-
 source/encoder/ratecontrol.cpp |  46 ++++++++++++++++++++++++++---------------
 3 files changed, 35 insertions(+), 21 deletions(-)

diffs (133 lines):

diff -r 8621008756ba -r 2ab39c2dd50f source/common/lowres.h
--- a/source/common/lowres.h	Sat Nov 02 10:19:22 2013 -0500
+++ b/source/common/lowres.h	Mon Nov 04 11:40:49 2013 +0530
@@ -42,6 +42,8 @@ struct Lowres : public ReferencePlanes
     int    frameNum;  // Presentation frame number
     int    sliceType; // Slice type decided by lookahead
     int    leadingBframes; // number of leading B frames for P or I
+    uint64_t m_wp_ssd[3];  // This is different than m_SSDY, this is sum(pixel^2) - sum(pixel)^2 for entire frame
+    uint64_t m_wp_sum[3];
 
     bool   bIntraCalculated;
     bool   bScenecut; // Set to false if the frame cannot possibly be part of a real scenecut.
@@ -51,12 +53,12 @@ struct Lowres : public ReferencePlanes
     /* lookahead output data */
     int       costEst[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
     int       costEstAq[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
-    int32_t      *rowSatds[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;
+    int32_t*  intraCost;
     int       satdCost;
     uint16_t(*lowresCosts[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2]);
-    int32_t      *lowresMvCosts[2][X265_BFRAME_MAX + 1];
+    int32_t  *lowresMvCosts[2][X265_BFRAME_MAX + 1];
     MV       *lowresMvs[2][X265_BFRAME_MAX + 1];
 
     void create(TComPic *pic, int bframes, int32_t *aqMode);
diff -r 8621008756ba -r 2ab39c2dd50f source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Sat Nov 02 10:19:22 2013 -0500
+++ b/source/encoder/encoder.cpp	Mon Nov 04 11:40:49 2013 +0530
@@ -217,7 +217,7 @@ int Encoder::encode(bool flush, const x2
 
         // Encoder holds a reference count until collecting stats
         ATOMIC_INC(&pic->m_countRefEncoders);
-        if (param.rc.aqMode)
+        if (param.rc.aqMode || param.bEnableWeightedPred)
             m_rateControl->calcAdaptiveQuantFrame(pic);
         m_lookahead->addPicture(pic, pic_in->sliceType);
     }
diff -r 8621008756ba -r 2ab39c2dd50f source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Sat Nov 02 10:19:22 2013 -0500
+++ b/source/encoder/ratecontrol.cpp	Mon Nov 04 11:40:49 2013 +0530
@@ -51,25 +51,26 @@ static inline double qp2qScale(double qp
 }
 
 /* Compute variance to derive AC energy of each block */
-static inline uint32_t acEnergyVar(uint64_t sum_ssd, int shift)
+static inline uint32_t acEnergyVar(TComPic *pic, uint64_t sum_ssd, int shift, int i)
 {
     uint32_t sum = (uint32_t)sum_ssd;
     uint32_t ssd = (uint32_t)(sum_ssd >> 32);
-
+    pic->m_lowres.m_wp_sum[i] += sum;
+    pic->m_lowres.m_wp_ssd[i] += ssd;
     return ssd - ((uint64_t)sum * sum >> shift);
 }
 
 /* Find the energy of each block in Y/Cb/Cr plane */
-static inline uint32_t acEnergyPlane(pixel* src, int srcStride, int bChroma)
+static inline uint32_t acEnergyPlane(TComPic *pic, pixel* src, int srcStride, int bChroma)
 {
     if (bChroma)
     {
         ALIGN_VAR_8(pixel, pix[8 * 8]);
         primitives.blockcpy_pp(8, 8, pix, 8, src, srcStride);
-        return acEnergyVar(primitives.var[LUMA_8x8](pix, 8), 6);
+        return acEnergyVar(pic, primitives.var[LUMA_8x8](pix, 8), 6, bChroma);
     }
     else
-        return acEnergyVar(primitives.var[LUMA_16x16](src, srcStride), 8);
+        return acEnergyVar(pic, primitives.var[LUMA_16x16](src, srcStride), 8, bChroma);
 }
 
 /* Find the total AC energy of each block in all planes */
@@ -81,9 +82,9 @@ double RateControl::acEnergyCu(TComPic* 
     uint32_t blockOffsetChroma = (block_x >> 1) + ((block_y >> 1) * cStride);
 
     uint32_t var;
-    var  = acEnergyPlane(pic->getPicYuvOrg()->getLumaAddr() + blockOffsetLuma, stride, 0);
-    var += acEnergyPlane(pic->getPicYuvOrg()->getCbAddr() + blockOffsetChroma, cStride, 1);
-    var += acEnergyPlane(pic->getPicYuvOrg()->getCrAddr() + blockOffsetChroma, cStride, 1);
+    var  = acEnergyPlane(pic, pic->getPicYuvOrg()->getLumaAddr() + blockOffsetLuma, stride, 0);
+    var += acEnergyPlane(pic, pic->getPicYuvOrg()->getCbAddr() + blockOffsetChroma, cStride, 1);
+    var += acEnergyPlane(pic, pic->getPicYuvOrg()->getCrAddr() + blockOffsetChroma, cStride, 2);
     x265_emms();
     double strength = cfg->param.rc.aqStrength * 1.0397f;
     return strength * (X265_LOG2(X265_MAX(var, 1)) - 14.427f);
@@ -92,24 +93,35 @@ double RateControl::acEnergyCu(TComPic* 
 void RateControl::calcAdaptiveQuantFrame(TComPic *pic)
 {
     /* Actual adaptive quantization */
-    if (cfg->param.rc.aqMode)
+    int maxCol = pic->getPicYuvOrg()->getWidth();
+    int maxRow = pic->getPicYuvOrg()->getHeight();
+
+    /* Calculate Qp offset for each 16x16 block in the frame */
+    int block_xy = 0;
+    int block_x = 0, block_y = 0;
+    for (block_y = 0; block_y < maxRow; block_y += 16)
     {
-        int maxCol = pic->getPicYuvOrg()->getWidth();
-        int maxRow = pic->getPicYuvOrg()->getHeight();
-
-        /* Calculate Qp offset for each 16x16 block in the frame */
-        int block_xy = 0;
-        for (int block_y = 0; block_y < maxRow; block_y += 16)
+        for (block_x = 0; block_x < maxCol; block_x += 16)
         {
-            for (int block_x = 0; block_x < maxCol; block_x += 16)
+            double qp_adj = acEnergyCu(pic, block_x, block_y);
+            if (cfg->param.rc.aqMode)
             {
-                double qp_adj = acEnergyCu(pic, block_x, block_y);
                 pic->m_lowres.m_qpAqOffset[block_xy] = qp_adj;
                 pic->m_lowres.m_invQscaleFactor[block_xy] = x265_exp2fix8(qp_adj);
                 block_xy++;
             }
         }
     }
+    if (cfg->param.bEnableWeightedPred)
+    {
+        for(int i=0; i < 3; i++)
+        {
+            UInt64 sum, ssd;
+            sum = pic->m_lowres.m_wp_sum[i];
+            ssd = pic->m_lowres.m_wp_ssd[i];
+            pic->m_lowres.m_wp_ssd[i] = ssd - (sum*sum + (block_x * block_y) / 2 ) / (block_x * block_y);
+        }
+    }
 }
 
 RateControl::RateControl(TEncCfg * _cfg)


More information about the x265-commits mailing list