[x265] [PATCH 2 of 2] rc: Remove the redundant calculation on slidingWindow
Ximing Cheng
chengximing1989 at foxmail.com
Mon Oct 12 04:26:35 CEST 2015
# HG changeset patch
# User Ximing Cheng <ximingcheng at tencent.com>
# Date 1444616617 -28800
# Mon Oct 12 10:23:37 2015 +0800
# Node ID 0d1cfbb2716edcf9ba5b8ccc8b0fd585f4de59d7
# Parent 667253981f61f18c36bf5c7f607fbf6ea8cc6474
rc: Remove the redundant calculation on slidingWindow
diff -r 667253981f61 -r 0d1cfbb2716e source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Mon Oct 12 10:18:55 2015 +0800
+++ b/source/encoder/ratecontrol.cpp Mon Oct 12 10:23:37 2015 +0800
@@ -219,6 +219,7 @@
m_cutreeStatFileOut = m_cutreeStatFileIn = NULL;
m_rce2Pass = NULL;
m_lastBsliceSatdCost = 0;
+ m_movingAvgSum = 0.0;
// vbv initialization
m_param->rc.vbvBufferSize = x265_clip3(0, 2000000, m_param->rc.vbvBufferSize);
@@ -1347,18 +1348,28 @@
{
if (m_isAbr)
{
- double slidingWindowCplxSum = 0;
- int start = m_sliderPos > s_slidingWindowFrames ? m_sliderPos : 0;
- for (int cnt = 0; cnt < s_slidingWindowFrames; cnt++, start++)
+ int pos = m_sliderPos % s_slidingWindowFrames;
+ int addPos = (pos + s_slidingWindowFrames - 1) % s_slidingWindowFrames;
+ if (m_sliderPos > s_slidingWindowFrames)
{
- int pos = start % s_slidingWindowFrames;
- slidingWindowCplxSum *= 0.5;
- if (!m_satdCostWindow[pos])
- break;
- slidingWindowCplxSum += m_satdCostWindow[pos];
+ const static double base = pow(0.5, s_slidingWindowFrames - 1);
+ m_movingAvgSum -= m_lastRemovedSatdCost * base;
+ m_movingAvgSum *= 0.5;
+ m_movingAvgSum += m_satdCostWindow[addPos];
}
- rce->movingAvgSum = slidingWindowCplxSum;
- m_satdCostWindow[m_sliderPos % s_slidingWindowFrames] = rce->lastSatd;
+ else if (m_sliderPos == s_slidingWindowFrames)
+ {
+ m_movingAvgSum += m_satdCostWindow[addPos];
+ }
+ else if (m_sliderPos > 0)
+ {
+ m_movingAvgSum += m_satdCostWindow[addPos];
+ m_movingAvgSum *= 0.5;
+ }
+
+ rce->movingAvgSum = m_movingAvgSum;
+ m_lastRemovedSatdCost = m_satdCostWindow[pos];
+ m_satdCostWindow[pos] = rce->lastSatd;
m_sliderPos++;
}
}
diff -r 667253981f61 -r 0d1cfbb2716e source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Mon Oct 12 10:18:55 2015 +0800
+++ b/source/encoder/ratecontrol.h Mon Oct 12 10:23:37 2015 +0800
@@ -167,6 +167,8 @@
int64_t m_satdCostWindow[50];
int64_t m_encodedBitsWindow[50];
int m_sliderPos;
+ int64_t m_lastRemovedSatdCost;
+ double m_movingAvgSum;
/* To detect a pattern of low detailed static frames in single pass ABR using satdcosts */
int64_t m_lastBsliceSatdCost;
More information about the x265-devel
mailing list