<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 16, 2015 at 1:50 PM, Ximing Cheng <span dir="ltr"><<a href="mailto:chengximing1989@gmail.com" target="_blank">chengximing1989@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This patch reduce the calculation by saving the SATD moving sum last<br>
time (frame), then the next frame can calculate its SATD moving sum by<br>
the last moving sum and the replaced value in the slidingWindow, so<br>
that each frame in rate ctrl does not need to do a loop for at most<br>
s_slidingWindowFrames times to calculate its SATD moving sum.<br>
<br>
Suppose slidingWindow size is 6, value is x y z a b c<br>
<br>
rc frame (m_sliderPos)                moving sum<br>
0                                               0<br>
1                                               0.5x<br>
2                                               0.5^2x+0.5y<br>
3                                               0.5^3x+0.5^2y+0.5z<br>
4                                               0.5^4x+0.5^3y+0.5^2z+0.5a<br>
5                                               0.5^5x+0.5^4y+0.5^3z+0.5^2a+0.5b<br>
6<br>
0.5^5x+0.5^4y+0.5^3z+0.5^2a+0.5b+c<br>
7                                               0.5<br>
(0.5^4y+0.5^3z+0.5^2a+0.5b+c)+x_1   == 0.5<br>
(0.5^5x+0.5^4y+0.5^3z+0.5^2a+0.5b+c -  0.5^5x) + x_1<br>
<br>
which x_1 is the replaced value of x<br>
<div class="HOEnZb"><div class="h5"><br>
On Mon, Oct 12, 2015 at 10:26 AM, Ximing Cheng<br>
<<a href="mailto:chengximing1989@foxmail.com">chengximing1989@foxmail.com</a>> wrote:<br>
> # HG changeset patch<br>
> # User Ximing Cheng <<a href="mailto:ximingcheng@tencent.com">ximingcheng@tencent.com</a>><br>
> # Date 1444616617 -28800<br>
> #      Mon Oct 12 10:23:37 2015 +0800<br>
> # Node ID 0d1cfbb2716edcf9ba5b8ccc8b0fd585f4de59d7<br>
> # Parent  667253981f61f18c36bf5c7f607fbf6ea8cc6474<br>
> rc: Remove the redundant calculation on slidingWindow<br>
><br>
> diff -r 667253981f61 -r 0d1cfbb2716e source/encoder/ratecontrol.cpp<br>
> --- a/source/encoder/ratecontrol.cpp    Mon Oct 12 10:18:55 2015 +0800<br>
> +++ b/source/encoder/ratecontrol.cpp    Mon Oct 12 10:23:37 2015 +0800<br>
> @@ -219,6 +219,7 @@<br>
>      m_cutreeStatFileOut = m_cutreeStatFileIn = NULL;<br>
>      m_rce2Pass = NULL;<br>
>      m_lastBsliceSatdCost = 0;<br>
> +    m_movingAvgSum = 0.0;<br>
><br>
>      // vbv initialization<br>
>      m_param->rc.vbvBufferSize = x265_clip3(0, 2000000, m_param->rc.vbvBufferSize);<br>
> @@ -1347,18 +1348,28 @@<br>
>      {<br>
>          if (m_isAbr)<br>
>          {<br>
> -            double slidingWindowCplxSum = 0;<br>
> -            int start = m_sliderPos > s_slidingWindowFrames ?  m_sliderPos : 0;<br>
> -            for (int cnt = 0; cnt < s_slidingWindowFrames; cnt++, start++)<br>
> +            int pos = m_sliderPos % s_slidingWindowFrames;<br>
> +            int addPos = (pos + s_slidingWindowFrames - 1) % s_slidingWindowFrames;<br>
> +            if (m_sliderPos > s_slidingWindowFrames)<br>
>              {<br>
> -                int pos = start % s_slidingWindowFrames;<br>
> -                slidingWindowCplxSum *= 0.5;<br>
> -                if (!m_satdCostWindow[pos])<br>
> -                    break;<br>
> -                slidingWindowCplxSum += m_satdCostWindow[pos];<br>
> +                const static double base = pow(0.5, s_slidingWindowFrames - 1);<br>
> +                m_movingAvgSum -= m_lastRemovedSatdCost * base;<br>
> +                m_movingAvgSum *= 0.5;<br>
> +                m_movingAvgSum += m_satdCostWindow[addPos];<br>
>              }<br>
> -            rce->movingAvgSum = slidingWindowCplxSum;<br>
> -            m_satdCostWindow[m_sliderPos % s_slidingWindowFrames] = rce->lastSatd;<br>
> +            else if (m_sliderPos == s_slidingWindowFrames)<br>
> +            {<br>
> +                m_movingAvgSum += m_satdCostWindow[addPos];<br>
> +            }<br>
> +            else if (m_sliderPos > 0)<br>
> +            {<br>
> +                m_movingAvgSum += m_satdCostWindow[addPos];<br>
> +                m_movingAvgSum *= 0.5;<br>
> +            }<br>
> +<br>
> +            rce->movingAvgSum = m_movingAvgSum;<br>
> +            m_lastRemovedSatdCost = m_satdCostWindow[pos];<br>
> +            m_satdCostWindow[pos] = rce->lastSatd;<br>
>              m_sliderPos++;<br>
>          }<br>
>      }<br></div></div></blockquote><div>should the m_lastRemovedSatdCost be taken after incrementing the m_sliderPos  ?</div><div>because at the position = s_slidingWindowFrames, it should delete the data written in m_satdCostWindow</div><div>but the lastRemovedSatdCost would not be pointing to that yet - can you check this once.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
> diff -r 667253981f61 -r 0d1cfbb2716e source/encoder/ratecontrol.h<br>
> --- a/source/encoder/ratecontrol.h      Mon Oct 12 10:18:55 2015 +0800<br>
> +++ b/source/encoder/ratecontrol.h      Mon Oct 12 10:23:37 2015 +0800<br>
> @@ -167,6 +167,8 @@<br>
>      int64_t m_satdCostWindow[50];<br>
>      int64_t m_encodedBitsWindow[50];<br>
>      int     m_sliderPos;<br>
> +    int64_t m_lastRemovedSatdCost;<br>
> +    double  m_movingAvgSum;<br>
><br>
>      /* To detect a pattern of low detailed static frames in single pass ABR using satdcosts */<br>
>      int64_t m_lastBsliceSatdCost;<br>
><br>
><br>
> _______________________________________________<br>
> x265-devel mailing list<br>
> <a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
> <a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</div></div></blockquote></div><br></div></div>