[x265] [PATCH 2 of 2] Using weighted lowres ref frames in cost estimation in lookahead

Steve Borho steve at borho.org
Thu Nov 14 02:34:45 CET 2013


On Wed, Nov 13, 2013 at 6:40 AM, <shazeb at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
> # Date 1384346304 -19800
> #      Wed Nov 13 18:08:24 2013 +0530
> # Node ID a7b6c5a45c69814e35473af81a5d2a0299d634ca
> # Parent  213808a2069d21c49a4d5e99d71ad71b8af344b8
> Using weighted lowres ref frames in cost estimation in lookahead
>
> diff -r 213808a2069d -r a7b6c5a45c69 source/common/lowres.cpp
> --- a/source/common/lowres.cpp  Wed Nov 13 18:03:02 2013 +0530
> +++ b/source/common/lowres.cpp  Wed Nov 13 18:08:24 2013 +0530
> @@ -40,6 +40,7 @@
>      int cuWidth = (width + X265_LOWRES_CU_SIZE - 1) >>
> X265_LOWRES_CU_BITS;
>      int cuHeight = (lines + X265_LOWRES_CU_SIZE - 1) >>
> X265_LOWRES_CU_BITS;
>      int cuCount = cuWidth * cuHeight;
> +    bufferSize = lumaStride * (lines + 2 * orig->getLumaMarginY());
>

it seems bufferSize is only used below to know the number of lines to
weight?  this could be done more efficiently

>
>      /* rounding the width to multiple of lowres CU size */
>      width = cuWidth * X265_LOWRES_CU_SIZE;
> @@ -115,6 +116,18 @@
>      X265_FREE(invQscaleFactor);
>  }
>
> +void Lowres::initWeighted(Lowres *ref, wpScalingParam *w)
> +{
> +    isWeighted = true;
> +    int correction = (IF_INTERNAL_PREC - X265_DEPTH);
> +    for (int i = 0; i < 4; i++)
> +    {
> +        //Adding (IF_INTERNAL_PREC - X265_DEPTH) to cancel effect of
> pixel to short conversion inside the primitive
>

space after //


> +        primitives.weightpUniPixel(ref->buffer[i], this->buffer[i],
> lumaStride, lumaStride, lumaStride, (int) bufferSize / lumaStride,
> w->inputWeight, (1<<(w->log2WeightDenom - 1 + correction)),
> (w->log2WeightDenom + correction), w->inputOffset);
>

white-space


> +    }
> +    fpelPlane = lowresPlane[0];
> +}
> +
>  // (re) initialize lowres state
>  void Lowres::init(TComPicYuv *orig, int poc, int type, int bframes)
>  {
> diff -r 213808a2069d -r a7b6c5a45c69 source/common/lowres.h
> --- a/source/common/lowres.h    Wed Nov 13 18:03:02 2013 +0530
> +++ b/source/common/lowres.h    Wed Nov 13 18:08:24 2013 +0530
> @@ -33,6 +33,7 @@
>
>  class TComPic;
>  class TComPicYuv;
> +typedef struct WpScalingParam wpScalingParam;
>
>  struct ReferencePlanes
>  {
> @@ -100,6 +101,7 @@
>  struct Lowres : public ReferencePlanes
>  {
>      pixel *buffer[4];
> +    int bufferSize;
>
>      int    frameNum;         // Presentation frame number
>      int    sliceType;        // Slice type decided by lookahead
> @@ -132,6 +134,7 @@
>      void create(TComPic *pic, int bframes, int32_t *aqMode);
>      void destroy(int bframes);
>      void init(TComPicYuv *orig, int poc, int sliceType, int bframes);
> +    void initWeighted(Lowres *ref, wpScalingParam *w);
>  };
>  }
>
> diff -r 213808a2069d -r a7b6c5a45c69 source/encoder/slicetype.cpp
> --- a/source/encoder/slicetype.cpp      Wed Nov 13 18:03:02 2013 +0530
> +++ b/source/encoder/slicetype.cpp      Wed Nov 13 18:08:24 2013 +0530
> @@ -79,12 +79,16 @@
>      widthInCU = ((cfg->param.sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1)
> >> X265_LOWRES_CU_BITS;
>      heightInCU = ((cfg->param.sourceHeight / 2) + X265_LOWRES_CU_SIZE -
> 1) >> X265_LOWRES_CU_BITS;
>
> +    weightedRef.buffer[0] = NULL;
> +
>      lhrows = new LookaheadRow[heightInCU];
>      for (int i = 0; i < heightInCU; i++)
>      {
>          lhrows[i].widthInCU = widthInCU;
>          lhrows[i].heightInCU = heightInCU;
>          lhrows[i].frames = frames;
> +        lhrows[i].weightedRef = &weightedRef;
> +        lhrows[i].cfg = cfg;
>

lookahead rows should not need cfg


>      }
>  }
>
> @@ -127,7 +131,11 @@
>  void Lookahead::addPicture(TComPic *pic, int sliceType)
>  {
>      pic->m_lowres.init(pic->getPicYuvOrg(), pic->getSlice()->getPOC(),
> sliceType, cfg->param.bframes);
> -
> +    if (weightedRef.buffer[0] == NULL)
>

drop "== NULL"


> +    {
> +        // Just using width/height data from the pic to create a
> standalone Lowres object
> +        weightedRef.create(pic, cfg->param.bframes,
> &cfg->param.rc.aqMode);
> +    }
>      inputQueue.pushBack(*pic);
>      if (inputQueue.size() >= cfg->param.lookaheadDepth)
>          slicetypeDecide();
> @@ -347,6 +355,14 @@
>              if( cfg->param.bEnableWeightedPred && b==p1)
>              {
>                  weightsAnalyse(b, p0, 1, &wp);
> +                if (wp.bPresentFlag)
> +                {
> +                    weightedRef.initWeighted(frames[p0], &wp);
>

weightsAnalyze should call this function directly.  Actually, wp could be a
stack variable in weightsAnalyze()


> +                }
> +                else
> +                {
> +                    weightedRef.isWeighted = false;
> +                }
>              }
>              bDoSearch[0] = b != p0 && fenc->lowresMvs[0][b - p0 - 1][0].x
> == 0x7FFF;
>              bDoSearch[1] = b != p1 && fenc->lowresMvs[1][p1 - b - 1][0].x
> == 0x7FFF;
> @@ -437,6 +453,11 @@
>      Lowres *fref1 = frames[p1];
>      Lowres *fenc  = frames[b];
>
> +    if (weightedRef->isWeighted)
> +    {
> +        fref0 = weightedRef;
> +    }
> +
>      const int bBidir = (b < p1);
>      const int cuXY = cux + cuy * widthInCU;
>      const int cuSize = X265_LOWRES_CU_SIZE;
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>



-- 
Steve Borho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20131113/f9258cae/attachment.html>


More information about the x265-devel mailing list