[x265] [PATCH] Cleanup

Ashok Kumar Mishra ashok at multicorewareinc.com
Tue Sep 25 15:27:37 CEST 2018


On Tue, Sep 25, 2018 at 6:15 PM <ashok at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Ashok Kumar Mishra <ashok at multicorewareinc.com>
> # Date 1537871551 -19800
> #      Tue Sep 25 16:02:31 2018 +0530
> # Node ID e5434c75d9ba2a327a06d74bbc93523cf5c81b80
> # Parent  bbad4e55b51a938dd4ce1375e0cb4dd4f59a5f27
> Cleanup
>
> diff -r bbad4e55b51a -r e5434c75d9ba source/common/frame.cpp
> --- a/source/common/frame.cpp   Tue Sep 18 16:34:04 2018 +0530
> +++ b/source/common/frame.cpp   Tue Sep 25 16:02:31 2018 +0530
> @@ -94,7 +94,7 @@
>          CHECKED_MALLOC_ZERO(m_classifyCount, uint32_t, size);
>      }
>
> -    if (m_fencPic->create(param, !!m_param->bCopyPicToFrame) &&
> m_lowres.create(m_fencPic, param->bframes, !!param->rc.aqMode ||
> !!param->bAQMotion, param->rc.qgSize))
> +    if (m_fencPic->create(param, !!m_param->bCopyPicToFrame) &&
> m_lowres.create(param, m_fencPic, param->rc.qgSize))
>      {
>          X265_CHECK((m_reconColCount == NULL), "m_reconColCount was
> initialized");
>          m_numRows = (m_fencPic->m_picHeight + param->maxCUSize - 1)  /
> param->maxCUSize;
> @@ -103,11 +103,8 @@
>
>          if (quantOffsets)
>          {
> -            int32_t cuCount;
> -            if (param->rc.qgSize == 8)
> -                cuCount = m_lowres.maxBlocksInRowFullRes *
> m_lowres.maxBlocksInColFullRes;
> -            else
> -                cuCount = m_lowres.maxBlocksInRow *
> m_lowres.maxBlocksInCol;
> +            int32_t cuCount = (param->rc.qgSize == 8) ?
> m_lowres.maxBlocksInRowFullRes * m_lowres.maxBlocksInColFullRes :
> +
> m_lowres.maxBlocksInRow * m_lowres.maxBlocksInCol;
>              m_quantOffsets = new float[cuCount];
>          }
>          return true;
> diff -r bbad4e55b51a -r e5434c75d9ba source/common/lowres.cpp
> --- a/source/common/lowres.cpp  Tue Sep 18 16:34:04 2018 +0530
> +++ b/source/common/lowres.cpp  Tue Sep 25 16:02:31 2018 +0530
> @@ -27,10 +27,10 @@
>
>  using namespace X265_NS;
>
> -bool Lowres::create(PicYuv *origPic, int _bframes, bool bAQEnabled,
> uint32_t qgSize)
> +bool Lowres::create(x265_param* param, PicYuv *origPic, uint32_t qgSize)
>  {
>      isLowres = true;
> -    bframes = _bframes;
> +    bframes = param->bframes;
>      width = origPic->m_picWidth / 2;
>      lines = origPic->m_picHeight / 2;
>      lumaStride = width + 2 * origPic->m_lumaMarginX;
> @@ -41,11 +41,7 @@
>      maxBlocksInRowFullRes = maxBlocksInRow * 2;
>      maxBlocksInColFullRes = maxBlocksInCol * 2;
>      int cuCount = maxBlocksInRow * maxBlocksInCol;
> -    int cuCountFullRes;
> -    if (qgSize == 8)
> -        cuCountFullRes = maxBlocksInRowFullRes * maxBlocksInColFullRes;
> -    else
> -        cuCountFullRes = cuCount;
> +    int cuCountFullRes = (qgSize > 8) ? cuCount : cuCount << 2;
>
>      /* rounding the width to multiple of lowres CU size */
>      width = maxBlocksInRow * X265_LOWRES_CU_SIZE;
> @@ -53,7 +49,7 @@
>
>      size_t planesize = lumaStride * (lines + 2 * origPic->m_lumaMarginY);
>      size_t padoffset = lumaStride * origPic->m_lumaMarginY +
> origPic->m_lumaMarginX;
> -    if (bAQEnabled)
> +    if (!!param->rc.aqMode)
>      {
>          CHECKED_MALLOC_ZERO(qpAqOffset, double, cuCountFullRes);
>          CHECKED_MALLOC_ZERO(invQscaleFactor, int, cuCountFullRes);
> diff -r bbad4e55b51a -r e5434c75d9ba source/common/lowres.h
> --- a/source/common/lowres.h    Tue Sep 18 16:34:04 2018 +0530
> +++ b/source/common/lowres.h    Tue Sep 25 16:02:31 2018 +0530
> @@ -152,14 +152,12 @@
>      uint32_t* blockVariance;
>      uint64_t  wp_ssd[3];       // This is different than SSDY, this is
> sum(pixel^2) - sum(pixel)^2 for entire frame
>      uint64_t  wp_sum[3];
> -    uint64_t  frameVariance;
>
>      /* cutree intermediate data */
>      uint16_t* propagateCost;
>      double    weightedCostDelta[X265_BFRAME_MAX + 2];
>      ReferencePlanes weightedRef[X265_BFRAME_MAX + 2];
> -
> -    bool create(PicYuv *origPic, int _bframes, bool bAqEnabled, uint32_t
> qgSize);
> +    bool create(x265_param* param, PicYuv *origPic, uint32_t qgSize);
>      void destroy();
>      void init(PicYuv *origPic, int poc);
>  };
> diff -r bbad4e55b51a -r e5434c75d9ba source/encoder/analysis.cpp
> --- a/source/encoder/analysis.cpp       Tue Sep 18 16:34:04 2018 +0530
> +++ b/source/encoder/analysis.cpp       Tue Sep 25 16:02:31 2018 +0530
> @@ -3357,13 +3357,13 @@
>
>  primitives.chroma[m_csp].cu[sizeIdx].copy_pp(reconPic.getCbAddr(cu.m_cuAddr,
> absPartIdx), reconPic.m_strideC,
>                                                           predU,
> predYuv.m_csize);
>
> -             if (cu.m_cbf[2][0])
> -             {
> -                 bool reconPicAlign = (reconPic.m_cuOffsetC[cu.m_cuAddr]
> + reconPic.m_buOffsetC[absPartIdx]) % 64 == 0;
> -                 bool predValign =
> predYuv.getChromaAddrOffset(absPartIdx) % 64 == 0;
> -
>  primitives.chroma[m_csp].cu[sizeIdx].add_ps[reconPicAlign && predValign &&
> (reconPic.m_strideC % 64 == 0) && (predYuv.m_csize % 64 == 0) &&
> -                     (resiYuv.m_csize % 64 ==
> 0)](reconPic.getCrAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC, predV,
> resiYuv.m_buf[2], predYuv.m_csize, resiYuv.m_csize);
> -             }
> +            if (cu.m_cbf[2][0])
> +            {
> +                bool reconPicAlign = (reconPic.m_cuOffsetC[cu.m_cuAddr] +
> reconPic.m_buOffsetC[absPartIdx]) % 64 == 0;
> +                bool predValign = predYuv.getChromaAddrOffset(absPartIdx)
> % 64 == 0;
> +                primitives.chroma[m_csp].cu[sizeIdx].add_ps[reconPicAlign
> && predValign && (reconPic.m_strideC % 64 == 0) && (predYuv.m_csize % 64 ==
> 0) &&
> +                    (resiYuv.m_csize % 64 ==
> 0)](reconPic.getCrAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC, predV,
> resiYuv.m_buf[2], predYuv.m_csize, resiYuv.m_csize);
> +            }
>              else
>
>  primitives.chroma[m_csp].cu[sizeIdx].copy_pp(reconPic.getCrAddr(cu.m_cuAddr,
> absPartIdx), reconPic.m_strideC,
>                                                           predV,
> predYuv.m_csize);
> @@ -3568,18 +3568,12 @@
>              qp += distortionData->offset[ctu.m_cuAddr];
>      }
>
> -    int loopIncr;
> -    if (m_param->rc.qgSize == 8)
> -        loopIncr = 8;
> -    else
> -        loopIncr = 16;
> +    int loopIncr = (m_param->rc.qgSize == 8) ? 8 : 16;
> +
>      /* Use cuTree offsets if cuTree enabled and frame is referenced, else
> use AQ offsets */
>      bool isReferenced = IS_REFERENCED(m_frame);
> -    double *qpoffs;
> -    if (complexCheck)
> -        qpoffs = m_frame->m_lowres.qpAqOffset;
> -    else
> -        qpoffs = (isReferenced && m_param->rc.cuTree) ?
> m_frame->m_lowres.qpCuTreeOffset : m_frame->m_lowres.qpAqOffset;
> +    double *qpoffs = (isReferenced && m_param->rc.cuTree &&
> !complexCheck) ? m_frame->m_lowres.qpCuTreeOffset :
> +
>    m_frame->m_lowres.qpAqOffset;
>      if (qpoffs)
>      {
>          uint32_t width = m_frame->m_fencPic->m_picWidth;
> @@ -3590,13 +3584,11 @@
>          uint32_t blockSize = m_param->maxCUSize >> cuGeom.depth;
>          double qp_offset = 0;
>          uint32_t cnt = 0;
> -        uint32_t idx;
> -
>          for (uint32_t block_yy = block_y; block_yy < block_y + blockSize
> && block_yy < height; block_yy += loopIncr)
>          {
>              for (uint32_t block_xx = block_x; block_xx < block_x +
> blockSize && block_xx < width; block_xx += loopIncr)
>              {
> -                idx = ((block_yy / loopIncr) * (maxCols)) + (block_xx /
> loopIncr);
> +                uint32_t idx = ((block_yy / loopIncr) * (maxCols)) +
> (block_xx / loopIncr);
>                  qp_offset += qpoffs[idx];
>                  cnt++;
>              }
> @@ -3609,10 +3601,7 @@
>              int32_t offset = (int32_t)(qp_offset * 100 + .5);
>              double threshold = (1 - ((x265_ADAPT_RD_STRENGTH -
> m_param->dynamicRd) * 0.5));
>              int32_t max_threshold = (int32_t)(threshold * 100 + .5);
> -            if (offset < max_threshold)
> -                return 1;
> -            else
> -                return 0;
> +            return (offset < max_threshold);
>          }
>      }
>
> diff -r bbad4e55b51a -r e5434c75d9ba source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cpp    Tue Sep 18 16:34:04 2018 +0530
> +++ b/source/encoder/ratecontrol.cpp    Tue Sep 25 16:02:31 2018 +0530
> @@ -2803,12 +2803,8 @@
>  /* called to write out the rate control frame stats info in multipass
> encodes */
>  int RateControl::writeRateControlFrameStats(Frame* curFrame,
> RateControlEntry* rce)
>  {
> -    FrameData& curEncData = *curFrame->m_encData;
> -    int ncu;
> -    if (m_param->rc.qgSize == 8)
> -        ncu = m_ncu * 4;
> -    else
> -        ncu = m_ncu;
> +    FrameData& curEncData = *curFrame->m_encData;
> +    int ncu = (m_param->rc.qgSize == 8) ? m_ncu * 4 : m_ncu;
>      char cType = rce->sliceType == I_SLICE ?
> (curFrame->m_lowres.sliceType == X265_TYPE_IDR ? 'I' : 'i')
>          : rce->sliceType == P_SLICE ? 'P'
>          : IS_REFERENCED(curFrame) ? 'B' : 'b';
> diff -r bbad4e55b51a -r e5434c75d9ba source/encoder/slicetype.cpp
> --- a/source/encoder/slicetype.cpp      Tue Sep 18 16:34:04 2018 +0530
> +++ b/source/encoder/slicetype.cpp      Tue Sep 25 16:02:31 2018 +0530
> @@ -150,20 +150,14 @@
>          curFrame->m_lowres.wp_sum[y] = 0;
>      }
>
> -    /* Calculate Qp offset for each 16x16 or 8x8 block in the frame */
> -    int blockXY = 0;
> -    int blockX = 0, blockY = 0;
> -    double strength = 0.f;
> +    /* Calculate Qp offset for each 16x16 or 8x8 block in the frame */
>      if ((param->rc.aqMode == X265_AQ_NONE || param->rc.aqStrength == 0)
> || (param->rc.bStatRead && param->rc.cuTree && IS_REFERENCED(curFrame)))
>      {
> -        /* Need to init it anyways for CU tree */
> -        int cuCount = blockCount;
> -
>          if (param->rc.aqMode && param->rc.aqStrength == 0)
>          {
>              if (quantOffsets)
>              {
> -                for (int cuxy = 0; cuxy < cuCount; cuxy++)
> +                for (int cuxy = 0; cuxy < blockCount; cuxy++)
>                  {
>                      curFrame->m_lowres.qpCuTreeOffset[cuxy] =
> curFrame->m_lowres.qpAqOffset[cuxy] = quantOffsets[cuxy];
>                      curFrame->m_lowres.invQscaleFactor[cuxy] =
> x265_exp2fix8(curFrame->m_lowres.qpCuTreeOffset[cuxy]);
> @@ -171,60 +165,55 @@
>              }
>              else
>              {
> -                memset(curFrame->m_lowres.qpCuTreeOffset, 0, cuCount *
> sizeof(double));
> -                memset(curFrame->m_lowres.qpAqOffset, 0, cuCount *
> sizeof(double));
> -                for (int cuxy = 0; cuxy < cuCount; cuxy++)
> -                    curFrame->m_lowres.invQscaleFactor[cuxy] = 256;
> +               memset(curFrame->m_lowres.qpCuTreeOffset, 0, blockCount *
> sizeof(double));
> +               memset(curFrame->m_lowres.qpAqOffset, 0, blockCount *
> sizeof(double));
> +               for (int cuxy = 0; cuxy < blockCount; cuxy++)
> +                   curFrame->m_lowres.invQscaleFactor[cuxy] = 256;
>              }
>          }
>
>          /* Need variance data for weighted prediction and dynamic
> refinement*/
>          if (param->bEnableWeightedPred || param->bEnableWeightedBiPred)
> -        {
> -            for (blockY = 0; blockY < maxRow; blockY += loopIncr)
> -                for (blockX = 0; blockX < maxCol; blockX += loopIncr)
>
> +        {
> +            for (int blockY = 0; blockY < maxRow; blockY += loopIncr)
> +                for (int blockX = 0; blockX < maxCol; blockX +=
> loopIncr)
>                      acEnergyCu(curFrame, blockX, blockY,
> param->internalCsp, param->rc.qgSize);
>          }
>      }
>      else
>      {
> -        blockXY = 0;
> -        double avg_adj_pow2 = 0, avg_adj = 0, qp_adj = 0;
> -        double bias_strength = 0.f;
> +        int blockXY = 0;
> +        double avg_adj_pow2 = 0.f, avg_adj = 0.f, qp_adj = 0.f;
> +        double bias_strength = 0.f, strength = 0.f;
>          if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE || param->rc.aqMode
> == X265_AQ_AUTO_VARIANCE_BIASED)
>          {
> -            double bit_depth_correction = 1.f / (1 << (2*(X265_DEPTH-8)));
> -            curFrame->m_lowres.frameVariance = 0;
> -            uint64_t rowVariance = 0;
> -            for (blockY = 0; blockY < maxRow; blockY += loopIncr)
> -            {
> -                rowVariance = 0;
> -                for (blockX = 0; blockX < maxCol; blockX += loopIncr)
> +            double bit_depth_correction = 1.f / (1 <<
> (2*(X265_DEPTH-8)));
> +
> +            for (int blockY = 0; blockY < maxRow; blockY += loopIncr)
> +            {
> +                for (int blockX = 0; blockX < maxCol; blockX += loopIncr)
>                  {
> -                    uint32_t energy = acEnergyCu(curFrame, blockX,
> blockY, param->internalCsp, param->rc.qgSize);
> -                    rowVariance += energy;
> +                    uint32_t energy = acEnergyCu(curFrame, blockX,
> blockY, param->internalCsp, param->rc.qgSize);
>                      qp_adj = pow(energy * bit_depth_correction + 1, 0.1);
>                      curFrame->m_lowres.qpCuTreeOffset[blockXY] = qp_adj;
>                      avg_adj += qp_adj;
>                      avg_adj_pow2 += qp_adj * qp_adj;
>                      blockXY++;
>                  }
> -                curFrame->m_lowres.frameVariance += (rowVariance /
> maxCol);
>              }
> -            curFrame->m_lowres.frameVariance /= maxRow;
>              avg_adj /= blockCount;
>              avg_adj_pow2 /= blockCount;
>              strength = param->rc.aqStrength * avg_adj;
> -            avg_adj = avg_adj - 0.5f * (avg_adj_pow2 - (modeTwoConst)) /
> avg_adj;
> +            avg_adj = avg_adj - 0.5f * (avg_adj_pow2 - modeTwoConst) /
> avg_adj;
>              bias_strength = param->rc.aqStrength;
>          }
>          else
>              strength = param->rc.aqStrength * 1.0397f;
>
>          blockXY = 0;
> -        for (blockY = 0; blockY < maxRow; blockY += loopIncr)
> +        for (int blockY = 0; blockY < maxRow; blockY += loopIncr)
>          {
> -            for (blockX = 0; blockX < maxCol; blockX += loopIncr)
> +            for (int blockX = 0; blockX < maxCol; blockX += loopIncr)
>              {
>                  if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE_BIASED)
>                  {
> @@ -310,9 +299,9 @@
>
>      if (param->bDynamicRefine)
>      {
> -        blockXY = 0;
> -        for (blockY = 0; blockY < maxRow; blockY += loopIncr)
> -            for (blockX = 0; blockX < maxCol; blockX += loopIncr)
> +        int blockXY = 0;
> +        for (int blockY = 0; blockY < maxRow; blockY += loopIncr)
> +            for (int blockX = 0; blockX < maxCol; blockX += loopIncr)
>              {
>                  curFrame->m_lowres.blockVariance[blockXY] =
> acEnergyCu(curFrame, blockX, blockY, param->internalCsp, param->rc.qgSize);
>                  blockXY++;
>

Pushed to default.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20180925/85a7ce1f/attachment-0001.html>


More information about the x265-devel mailing list