[x265] [PATCH] Generating sum & ssd values for weightp decision in lookahead

Shazeb Khan shazeb at multicorewareinc.com
Fri Nov 1 13:20:48 CET 2013


We have a check inside calcAdaptiveQuantFrame() too!!


On Thu, Oct 31, 2013 at 8:59 PM, Steve Borho <steve at borho.org> wrote:

>
>
>
> On Thu, Oct 31, 2013 at 7:03 AM, <shazeb at multicorewareinc.com> wrote:
>
>> # HG changeset patch
>> # User Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
>> # Date 1383220857 -19800
>> #      Thu Oct 31 17:30:57 2013 +0530
>> # Node ID c2cba0b6736c52ad177afa6a4974dfe2d35f56ef
>> # Parent  9a0da4e6d9e363e383eae7243f0c64026a5f6d00
>> Generating sum & ssd values for weightp decision in lookahead
>>
>> diff -r 9a0da4e6d9e3 -r c2cba0b6736c source/common/lowres.h
>> --- a/source/common/lowres.h    Thu Oct 31 15:10:34 2013 +0530
>> +++ b/source/common/lowres.h    Thu Oct 31 17:30:57 2013 +0530
>> @@ -42,6 +42,8 @@
>>      int    frameNum;  // Presentation frame number
>>      int    sliceType; // Slice type decided by lookahead
>>      int    leadingBframes; // number of leading B frames for P or I
>> +    UInt64 m_wp_ssd[3];       // This is different than m_SSDY, this is
>> sum(pixel^2) - sum(pixel)^2 for entire frame
>> +    UInt64 m_wp_sum[3];
>>
>>      bool   bIntraCalculated;
>>      bool   bScenecut; // Set to false if the frame cannot possibly be
>> part of a real scenecut.
>> diff -r 9a0da4e6d9e3 -r c2cba0b6736c source/encoder/encoder.cpp
>> --- a/source/encoder/encoder.cpp        Thu Oct 31 15:10:34 2013 +0530
>> +++ b/source/encoder/encoder.cpp        Thu Oct 31 17:30:57 2013 +0530
>> @@ -217,8 +217,7 @@
>>
>>          // Encoder holds a reference count until collecting stats
>>          ATOMIC_INC(&pic->m_countRefEncoders);
>> -        if (param.rc.aqMode)
>> -            m_rateControl->calcAdaptiveQuantFrame(pic);
>> +        m_rateControl->calcAdaptiveQuantFrame(pic);
>>
>
> should this also be:
>
>  if (param.rc.aqMode || param.bEnableWeightedPred)
>
>
>>          m_lookahead->addPicture(pic, pic_in->sliceType);
>>      }
>>
>> diff -r 9a0da4e6d9e3 -r c2cba0b6736c source/encoder/ratecontrol.cpp
>> --- a/source/encoder/ratecontrol.cpp    Thu Oct 31 15:10:34 2013 +0530
>> +++ b/source/encoder/ratecontrol.cpp    Thu Oct 31 17:30:57 2013 +0530
>> @@ -51,16 +51,17 @@
>>  }
>>
>>  /* 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)
>>  {
>>      int blockStride = FENC_STRIDE >> 3;
>>
>> @@ -68,10 +69,10 @@
>>      {
>>          ALIGN_VAR_8(pixel, pix[8 * 8]);
>>          primitives.blockcpy_pp(8, 8, pix, blockStride, src, srcStride);
>> -        return acEnergyVar(primitives.var[LUMA_8x8](pix, blockStride),
>> 6);
>> +        return acEnergyVar(pic, primitives.var[LUMA_8x8](pix,
>> blockStride), 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 */
>> @@ -86,9 +87,9 @@
>>      int cStride = pic->getPicYuvOrg()->getCStride();
>>      uint32_t blockOffsetLuma = block_x + (block_y * frameStride);
>>      uint32_t blockOffsetChroma = (block_x >> 1) + ((block_y >> 1) *
>> cStride);
>> -    var = acEnergyPlane(srcLuma + blockOffsetLuma, frameStride, 0);
>> -    var += acEnergyPlane(srcCb + blockOffsetChroma, cStride, 1);
>> -    var += acEnergyPlane(srcCr + blockOffsetChroma, cStride, 1);
>> +    var = acEnergyPlane(pic, srcLuma + blockOffsetLuma, frameStride, 0);
>> +    var += acEnergyPlane(pic, srcCb + blockOffsetChroma, cStride, 1);
>> +    var += acEnergyPlane(pic, srcCr + blockOffsetChroma, cStride, 2);
>>      avgQp = strength * (X265_LOG2( X265_MAX(var, 1) ) - 14.427f);
>>      x265_emms();
>>      return avgQp;
>> @@ -97,23 +98,38 @@
>>  void RateControl::calcAdaptiveQuantFrame(TComPic *pic)
>>  {
>>      /* Actual adaptive quantization */
>> -    if (cfg->param.rc.aqMode)
>> +    if (cfg->param.rc.aqMode || cfg->param.bEnableWeightedPred)
>>      {
>>          uint32_t blockWidth = g_maxCUWidth >> 2;
>>          uint32_t blockHeight = g_maxCUHeight >> 2;
>>          double qp_adj = 0;
>>          int block_xy = 0;
>> +        int block_x = 0, block_y = 0;
>>          int maxCol = pic->getPicYuvOrg()->getWidth();
>>          int maxRow = pic->getPicYuvOrg()->getHeight();
>>          /* Calculate Qp offset for each 16x16 block in the frame */
>> -         for (int block_y = 0; block_y < maxRow; block_y += blockHeight)
>> +        for (block_y = 0; block_y < maxRow; block_y += blockHeight)
>>          {
>> -            for (int block_x = 0; block_x < maxCol; block_x +=
>> blockWidth)
>> +            for (block_x = 0; block_x < maxCol; block_x += blockWidth)
>>              {
>>                  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.rc.aqMode)
>> +                {
>> +                    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);
>>              }
>>          }
>>      }
>> _______________________________________________
>> x265-devel mailing list
>> x265-devel at videolan.org
>> https://mailman.videolan.org/listinfo/x265-devel
>>
>
>
>
> --
> Steve Borho
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20131101/d22c663f/attachment.html>


More information about the x265-devel mailing list