Merge "Moving vp9_decode_frame declaration to vp9_decodframe.h." into experimental
diff --git a/vp9/common/vp9_common.h b/vp9/common/vp9_common.h
index dbfb9ed..b6252d9 100644
--- a/vp9/common/vp9_common.h
+++ b/vp9/common/vp9_common.h
@@ -52,6 +52,10 @@
return value < low ? low : (value > high ? high : value);
}
+static INLINE double fclamp(double value, double low, double high) {
+ return value < low ? low : (value > high ? high : value);
+}
+
static INLINE int multiple16(int value) {
return (value + 15) & ~15;
}
diff --git a/vp9/common/vp9_loopfilter.h b/vp9/common/vp9_loopfilter.h
index 80fccd5..589984f 100644
--- a/vp9/common/vp9_loopfilter.h
+++ b/vp9/common/vp9_loopfilter.h
@@ -49,9 +49,6 @@
void sym(uint8_t *y, uint8_t *u, uint8_t *v, \
int ystride, int uv_stride, struct loop_filter_info *lfi)
-#define prototype_simple_loopfilter(sym) \
- void sym(uint8_t *y, int ystride, const unsigned char *blimit)
-
#if ARCH_X86 || ARCH_X86_64
#include "x86/vp9_loopfilter_x86.h"
#endif
diff --git a/vp9/common/vp9_loopfilter_filters.c b/vp9/common/vp9_loopfilter_filters.c
index bf97589..fc7fbc4 100644
--- a/vp9/common/vp9_loopfilter_filters.c
+++ b/vp9/common/vp9_loopfilter_filters.c
@@ -8,15 +8,13 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include <stdlib.h>
#include "vpx_config.h"
+#include "vp9/common/vp9_common.h"
#include "vp9/common/vp9_loopfilter.h"
#include "vp9/common/vp9_onyxc_int.h"
static INLINE int8_t signed_char_clamp(int t) {
- t = (t < -128 ? -128 : t);
- t = (t > 127 ? 127 : t);
- return (int8_t) t;
+ return (int8_t)clamp(t, -128, 127);
}
// should we apply any filter at all: 11111111 yes, 00000000 no
@@ -36,7 +34,7 @@
return ~mask;
}
-// is there high variance internal edge: 11111111 yes, 00000000 no
+// is there high edge variance internal edge: 11111111 yes, 00000000 no
static INLINE int8_t hevmask(uint8_t thresh, uint8_t p1, uint8_t p0,
uint8_t q0, uint8_t q1) {
int8_t hev = 0;
@@ -68,12 +66,9 @@
*oq0 = signed_char_clamp(qs0 - filter1) ^ 0x80;
*op0 = signed_char_clamp(ps0 + filter2) ^ 0x80;
- filter = filter1;
// outer tap adjustments
- filter += 1;
- filter >>= 1;
- filter &= ~hev;
+ filter = ((filter1 + 1) >> 1) & ~hev;
*oq1 = signed_char_clamp(qs1 - filter) ^ 0x80;
*op1 = signed_char_clamp(ps1 + filter) ^ 0x80;
@@ -84,23 +79,19 @@
const uint8_t *limit,
const uint8_t *thresh,
int count) {
- int i = 0;
+ int i;
// loop filter designed to work using chars so that we can make maximum use
// of 8 bit simd instructions.
- do {
- const int8_t mask = filter_mask(limit[0], blimit[0],
- s[-4 * p], s[-3 * p], s[-2 * p], s[-1 * p],
- s[0 * p], s[1 * p], s[2 * p], s[3 * p]);
-
- // high edge variance
- const int8_t hev = hevmask(thresh[0],
- s[-2 * p], s[-1 * p], s[0 * p], s[1 * p]);
-
+ for (i = 0; i < 8 * count; ++i) {
+ const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
+ const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
+ const int8_t mask = filter_mask(*limit, *blimit,
+ p3, p2, p1, p0, q0, q1, q2, q3);
+ const int8_t hev = hevmask(*thresh, p1, p0, q0, q1);
filter(mask, hev, s - 2 * p, s - 1 * p, s, s + 1 * p);
-
++s;
- } while (++i < count * 8);
+ }
}
void vp9_loop_filter_vertical_edge_c(uint8_t *s, int pitch,
@@ -108,21 +99,21 @@
const uint8_t *limit,
const uint8_t *thresh,
int count) {
- int i = 0;
+ int i;
// loop filter designed to work using chars so that we can make maximum use
// of 8 bit simd instructions.
- do {
- const int8_t mask = filter_mask(limit[0], blimit[0],
- s[-4], s[-3], s[-2], s[-1],
- s[0], s[1], s[2], s[3]);
-
- // high edge variance
- const int8_t hev = hevmask(thresh[0], s[-2], s[-1], s[0], s[1]);
+ for (i = 0; i < 8 * count; ++i) {
+ const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
+ const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
+ const int8_t mask = filter_mask(*limit, *blimit,
+ p3, p2, p1, p0, q0, q1, q2, q3);
+ const int8_t hev = hevmask(*thresh, p1, p0, q0, q1);
filter(mask, hev, s - 2, s - 1, s, s + 1);
s += pitch;
- } while (++i < count * 8);
+ }
}
+
static INLINE int8_t flatmask4(uint8_t thresh,
uint8_t p3, uint8_t p2,
uint8_t p1, uint8_t p0,
@@ -157,14 +148,8 @@
uint8_t *oq2, uint8_t *oq3) {
// use a 7 tap filter [1, 1, 1, 2, 1, 1, 1] for flat line
if (flat && mask) {
- const uint8_t p3 = *op3;
- const uint8_t p2 = *op2;
- const uint8_t p1 = *op1;
- const uint8_t p0 = *op0;
- const uint8_t q0 = *oq0;
- const uint8_t q1 = *oq1;
- const uint8_t q2 = *oq2;
- const uint8_t q3 = *oq3;
+ const uint8_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
+ const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3;
*op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + p2 + p2 + p1 + p0 + q0, 3);
*op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + p1 + p1 + p0 + q0 + q1, 3);
@@ -173,33 +158,7 @@
*oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + q1 + q1 + q2 + q3 + q3, 3);
*oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + q2 + q2 + q3 + q3 + q3, 3);
} else {
- int8_t filter1, filter2;
-
- const int8_t ps1 = (int8_t) *op1 ^ 0x80;
- const int8_t ps0 = (int8_t) *op0 ^ 0x80;
- const int8_t qs0 = (int8_t) *oq0 ^ 0x80;
- const int8_t qs1 = (int8_t) *oq1 ^ 0x80;
-
- // add outer taps if we have high edge variance
- int8_t filter = signed_char_clamp(ps1 - qs1) & hev;
-
- // inner taps
- filter = signed_char_clamp(filter + 3 * (qs0 - ps0)) & mask;
-
- filter1 = signed_char_clamp(filter + 4) >> 3;
- filter2 = signed_char_clamp(filter + 3) >> 3;
-
- *oq0 = signed_char_clamp(qs0 - filter1) ^ 0x80;
- *op0 = signed_char_clamp(ps0 + filter2) ^ 0x80;
- filter = filter1;
-
- // outer tap adjustments
- filter += 1;
- filter >>= 1;
- filter &= ~hev;
-
- *oq1 = signed_char_clamp(qs1 - filter) ^ 0x80;
- *op1 = signed_char_clamp(ps1 + filter) ^ 0x80;
+ filter(mask, hev, op1, op0, oq0, oq1);
}
}
@@ -208,28 +167,23 @@
const uint8_t *limit,
const uint8_t *thresh,
int count) {
- int i = 0;
+ int i;
// loop filter designed to work using chars so that we can make maximum use
// of 8 bit simd instructions.
- do {
- const int8_t mask = filter_mask(limit[0], blimit[0],
- s[-4 * p], s[-3 * p], s[-2 * p], s[-1 * p],
- s[ 0 * p], s[ 1 * p], s[ 2 * p], s[ 3 * p]);
+ for (i = 0; i < 8 * count; ++i) {
+ const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
+ const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
- const int8_t hev = hevmask(thresh[0],
- s[-2 * p], s[-1 * p], s[0 * p], s[1 * p]);
-
- const int8_t flat = flatmask4(1,
- s[-4 * p], s[-3 * p], s[-2 * p], s[-1 * p],
- s[ 0 * p], s[ 1 * p], s[ 2 * p], s[ 3 * p]);
+ const int8_t mask = filter_mask(*limit, *blimit,
+ p3, p2, p1, p0, q0, q1, q2, q3);
+ const int8_t hev = hevmask(*thresh, p1, p0, q0, q1);
+ const int8_t flat = flatmask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
mbfilter(mask, hev, flat,
s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p,
s, s + 1 * p, s + 2 * p, s + 3 * p);
-
++s;
- } while (++i < count * 8);
-
+ }
}
void vp9_mbloop_filter_vertical_edge_c(uint8_t *s, int pitch,
@@ -237,49 +191,19 @@
const uint8_t *limit,
const uint8_t *thresh,
int count) {
- int i = 0;
+ int i;
- do {
- const int8_t mask = filter_mask(limit[0], blimit[0],
- s[-4], s[-3], s[-2], s[-1],
- s[0], s[1], s[2], s[3]);
-
- const int8_t hev = hevmask(thresh[0], s[-2], s[-1], s[0], s[1]);
- const int8_t flat = flatmask4(1, s[-4], s[-3], s[-2], s[-1],
- s[ 0], s[ 1], s[ 2], s[ 3]);
+ for (i = 0; i < 8 * count; ++i) {
+ const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
+ const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
+ const int8_t mask = filter_mask(*limit, *blimit,
+ p3, p2, p1, p0, q0, q1, q2, q3);
+ const int8_t hev = hevmask(thresh[0], p1, p0, q0, q1);
+ const int8_t flat = flatmask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
mbfilter(mask, hev, flat, s - 4, s - 3, s - 2, s - 1,
s, s + 1, s + 2, s + 3);
s += pitch;
- } while (++i < count * 8);
-
-}
-
-// should we apply any filter at all: 11111111 yes, 00000000 no
-static INLINE int8_t simple_filter_mask(uint8_t blimit,
- uint8_t p1, uint8_t p0,
- uint8_t q0, uint8_t q1) {
- return (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 <= blimit) * -1;
-}
-
-static INLINE void simple_filter(int8_t mask,
- uint8_t *op1, uint8_t *op0,
- uint8_t *oq0, uint8_t *oq1) {
- int8_t filter1, filter2;
- const int8_t p1 = (int8_t) *op1 ^ 0x80;
- const int8_t p0 = (int8_t) *op0 ^ 0x80;
- const int8_t q0 = (int8_t) *oq0 ^ 0x80;
- const int8_t q1 = (int8_t) *oq1 ^ 0x80;
-
- int8_t filter = signed_char_clamp(p1 - q1);
- filter = signed_char_clamp(filter + 3 * (q0 - p0));
- filter &= mask;
-
- // save bottom 3 bits so that we round one side +4 and the other +3
- filter1 = signed_char_clamp(filter + 4) >> 3;
- *oq0 = signed_char_clamp(q0 - filter1) ^ 0x80;
-
- filter2 = signed_char_clamp(filter + 3) >> 3;
- *op0 = signed_char_clamp(p0 + filter2) ^ 0x80;
+ }
}
/* Vertical MB Filtering */
@@ -395,22 +319,11 @@
uint8_t *oq7) {
// use a 15 tap filter [1,1,1,1,1,1,1,2,1,1,1,1,1,1,1] for flat line
if (flat2 && flat && mask) {
- const uint8_t p7 = *op7;
- const uint8_t p6 = *op6;
- const uint8_t p5 = *op5;
- const uint8_t p4 = *op4;
- const uint8_t p3 = *op3;
- const uint8_t p2 = *op2;
- const uint8_t p1 = *op1;
- const uint8_t p0 = *op0;
- const uint8_t q0 = *oq0;
- const uint8_t q1 = *oq1;
- const uint8_t q2 = *oq2;
- const uint8_t q3 = *oq3;
- const uint8_t q4 = *oq4;
- const uint8_t q5 = *oq5;
- const uint8_t q6 = *oq6;
- const uint8_t q7 = *oq7;
+ const uint8_t p7 = *op7, p6 = *op6, p5 = *op5, p4 = *op4,
+ p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
+
+ const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3,
+ q4 = *oq4, q5 = *oq5, q6 = *oq6, q7 = *oq7;
*op6 = ROUND_POWER_OF_TWO(p7 * 7 + p6 * 2 + p5 + p4 + p3 + p2 + p1 + p0 +
q0, 4);
@@ -440,49 +353,8 @@
q0 + q1 + q2 + q3 + q4 + q5 * 2 + q6 + q7 * 6, 4);
*oq6 = ROUND_POWER_OF_TWO(p0 +
q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 + q7 * 7, 4);
- } else if (flat && mask) {
- const uint8_t p3 = *op3;
- const uint8_t p2 = *op2;
- const uint8_t p1 = *op1;
- const uint8_t p0 = *op0;
- const uint8_t q0 = *oq0;
- const uint8_t q1 = *oq1;
- const uint8_t q2 = *oq2;
- const uint8_t q3 = *oq3;
-
- *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + p2 + p2 + p1 + p0 + q0, 3);
- *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + p1 + p1 + p0 + q0 + q1, 3);
- *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + p0 + p0 + q0 + q1 + q2, 3);
- *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + q0 + q0 + q1 + q2 + q3, 3);
- *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + q1 + q1 + q2 + q3 + q3, 3);
- *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + q2 + q2 + q3 + q3 + q3, 3);
} else {
- int8_t filter1, filter2;
-
- const int8_t ps1 = (int8_t) * op1 ^ 0x80;
- const int8_t ps0 = (int8_t) * op0 ^ 0x80;
- const int8_t qs0 = (int8_t) * oq0 ^ 0x80;
- const int8_t qs1 = (int8_t) * oq1 ^ 0x80;
-
- // add outer taps if we have high edge variance
- int8_t filter = signed_char_clamp(ps1 - qs1) & hev;
-
- // inner taps
- filter = signed_char_clamp(filter + 3 * (qs0 - ps0)) & mask;
- filter1 = signed_char_clamp(filter + 4) >> 3;
- filter2 = signed_char_clamp(filter + 3) >> 3;
-
- *oq0 = signed_char_clamp(qs0 - filter1) ^ 0x80;
- *op0 = signed_char_clamp(ps0 + filter2) ^ 0x80;
- filter = filter1;
-
- // outer tap adjustments
- filter += 1;
- filter >>= 1;
- filter &= ~hev;
-
- *oq1 = signed_char_clamp(qs1 - filter) ^ 0x80;
- *op1 = signed_char_clamp(ps1 + filter) ^ 0x80;
+ mbfilter(mask, hev, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3);
}
}
@@ -491,25 +363,20 @@
const uint8_t *limit,
const uint8_t *thresh,
int count) {
- int i = 0;
+ int i;
// loop filter designed to work using chars so that we can make maximum use
// of 8 bit simd instructions.
- do {
- const int8_t mask = filter_mask(limit[0], blimit[0],
- s[-4 * p], s[-3 * p], s[-2 * p], s[-1 * p],
- s[ 0 * p], s[ 1 * p], s[ 2 * p], s[ 3 * p]);
-
- const int8_t hev = hevmask(thresh[0],
- s[-2 * p], s[-1 * p], s[0 * p], s[1 * p]);
-
- const int8_t flat = flatmask4(1,
- s[-4 * p], s[-3 * p], s[-2 * p], s[-1 * p],
- s[ 0 * p], s[ 1 * p], s[ 2 * p], s[ 3 * p]);
-
+ for (i = 0; i < 8 * count; ++i) {
+ const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
+ const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
+ const int8_t mask = filter_mask(*limit, *blimit,
+ p3, p2, p1, p0, q0, q1, q2, q3);
+ const int8_t hev = hevmask(*thresh, p1, p0, q0, q1);
+ const int8_t flat = flatmask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
const int8_t flat2 = flatmask5(1,
- s[-8 * p], s[-7 * p], s[-6 * p], s[-5 * p], s[-1 * p],
- s[ 0 * p], s[ 4 * p], s[ 5 * p], s[ 6 * p], s[ 7 * p]);
+ s[-8 * p], s[-7 * p], s[-6 * p], s[-5 * p], p0,
+ q0, s[4 * p], s[5 * p], s[6 * p], s[7 * p]);
wide_mbfilter(mask, hev, flat, flat2,
s - 8 * p, s - 7 * p, s - 6 * p, s - 5 * p,
@@ -518,33 +385,31 @@
s + 4 * p, s + 5 * p, s + 6 * p, s + 7 * p);
++s;
- } while (++i < count * 8);
+ }
}
+
void vp9_mb_lpf_vertical_edge_w(uint8_t *s, int p,
const uint8_t *blimit,
const uint8_t *limit,
const uint8_t *thresh,
int count) {
- int i = 0;
+ int i;
- do {
- const int8_t mask = filter_mask(limit[0], blimit[0],
- s[-4], s[-3], s[-2], s[-1],
- s[0], s[1], s[2], s[3]);
-
- const int8_t hev = hevmask(thresh[0], s[-2], s[-1], s[0], s[1]);
- const int8_t flat = flatmask4(1, s[-4], s[-3], s[-2], s[-1],
- s[ 0], s[ 1], s[ 2], s[ 3]);
- const int8_t flat2 = flatmask5(1, s[-8], s[-7], s[-6], s[-5], s[-1],
- s[ 0], s[ 4], s[ 5], s[ 6], s[ 7]);
+ for (i = 0; i < 8 * count; ++i) {
+ const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
+ const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
+ const int8_t mask = filter_mask(*limit, *blimit,
+ p3, p2, p1, p0, q0, q1, q2, q3);
+ const int8_t hev = hevmask(*thresh, p1, p0, q0, q1);
+ const int8_t flat = flatmask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
+ const int8_t flat2 = flatmask5(1, s[-8], s[-7], s[-6], s[-5], p0,
+ q0, s[4], s[5], s[6], s[7]);
wide_mbfilter(mask, hev, flat, flat2,
- s - 8, s - 7, s - 6, s - 5,
- s - 4, s - 3, s - 2, s - 1,
- s, s + 1, s + 2, s + 3,
- s + 4, s + 5, s + 6, s + 7);
+ s - 8, s - 7, s - 6, s - 5, s - 4, s - 3, s - 2, s - 1,
+ s, s + 1, s + 2, s + 3, s + 4, s + 5, s + 6, s + 7);
s += p;
- } while (++i < count * 8);
+ }
}
void vp9_lpf_mbv_w_c(uint8_t *y, uint8_t *u, uint8_t *v,
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index 9222133..ac29a8e 100644
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -1242,16 +1242,6 @@
FILE *vpxlogc = 0;
#endif
-static void put_delta_q(vp9_writer *bc, int delta_q) {
- if (delta_q != 0) {
- vp9_write_bit(bc, 1);
- vp9_write_literal(bc, abs(delta_q), 4);
- vp9_write_bit(bc, delta_q < 0);
- } else {
- vp9_write_bit(bc, 0);
- }
-}
-
static void decide_kf_ymode_entropy(VP9_COMP *cpi) {
int mode_cost[MB_MODE_COUNT];
int bestcost = INT_MAX;
@@ -1298,9 +1288,21 @@
}
}
-static void encode_loopfilter(MACROBLOCKD *xd, vp9_writer *w) {
+static void encode_loopfilter(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_writer *w) {
int i;
+ // Encode the loop filter level and type
+ vp9_write_literal(w, pc->filter_level, 6);
+ vp9_write_literal(w, pc->sharpness_level, 3);
+#if CONFIG_LOOP_DERING
+ if (pc->dering_enabled) {
+ vp9_write_bit(w, 1);
+ vp9_write_literal(w, pc->dering_enabled - 1, 4);
+ } else {
+ vp9_write_bit(w, 0);
+ }
+#endif
+
// Write out loop filter deltas applied at the MB level based on mode or
// ref frame (if they are enabled).
vp9_write_bit(w, xd->mode_ref_lf_delta_enabled);
@@ -1354,6 +1356,24 @@
}
}
+static void put_delta_q(vp9_writer *bc, int delta_q) {
+ if (delta_q != 0) {
+ vp9_write_bit(bc, 1);
+ vp9_write_literal(bc, abs(delta_q), 4);
+ vp9_write_bit(bc, delta_q < 0);
+ } else {
+ vp9_write_bit(bc, 0);
+ }
+}
+
+static void encode_quantization(VP9_COMMON *pc, vp9_writer *w) {
+ vp9_write_literal(w, pc->base_qindex, QINDEX_BITS);
+ put_delta_q(w, pc->y_dc_delta_q);
+ put_delta_q(w, pc->uv_dc_delta_q);
+ put_delta_q(w, pc->uv_ac_delta_q);
+}
+
+
static void encode_segmentation(VP9_COMP *cpi, vp9_writer *w) {
int i, j;
VP9_COMMON *const pc = &cpi->common;
@@ -1495,27 +1515,9 @@
// lossless mode: note this needs to be before loopfilter
vp9_write_bit(&header_bc, cpi->mb.e_mbd.lossless);
- // Encode the loop filter level and type
- vp9_write_literal(&header_bc, pc->filter_level, 6);
- vp9_write_literal(&header_bc, pc->sharpness_level, 3);
-#if CONFIG_LOOP_DERING
- if (pc->dering_enabled) {
- vp9_write_bit(&header_bc, 1);
- vp9_write_literal(&header_bc, pc->dering_enabled - 1, 4);
- } else {
- vp9_write_bit(&header_bc, 0);
- }
-#endif
+ encode_loopfilter(pc, xd, &header_bc);
- encode_loopfilter(xd, &header_bc);
-
- // Frame Q baseline quantizer index
- vp9_write_literal(&header_bc, pc->base_qindex, QINDEX_BITS);
-
- // Transmit Dc, Second order and Uv quantizer delta information
- put_delta_q(&header_bc, pc->y_dc_delta_q);
- put_delta_q(&header_bc, pc->uv_dc_delta_q);
- put_delta_q(&header_bc, pc->uv_ac_delta_q);
+ encode_quantization(pc, &header_bc);
// When there is a key frame all reference buffers are updated using the new key frame
if (pc->frame_type != KEY_FRAME) {
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c
index 7223851..ddcf849 100644
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -47,7 +47,7 @@
#define KF_MB_INTRA_MIN 150
#define GF_MB_INTRA_MIN 100
-#define DOUBLE_DIVIDE_CHECK(X) ((X)<0?(X)-.000001:(X)+.000001)
+#define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x) - 0.000001 : (x) + 0.000001)
#define POW1 (double)cpi->oxcf.two_pass_vbrbias/100.0
#define POW2 (double)cpi->oxcf.two_pass_vbrbias/100.0
@@ -78,8 +78,8 @@
// Resets the first pass file to the given position using a relative seek from the current position
-static void reset_fpf_position(VP9_COMP *cpi, FIRSTPASS_STATS *Position) {
- cpi->twopass.stats_in = Position;
+static void reset_fpf_position(VP9_COMP *cpi, FIRSTPASS_STATS *position) {
+ cpi->twopass.stats_in = position;
}
static int lookup_next_frame_stats(VP9_COMP *cpi, FIRSTPASS_STATS *next_frame) {
@@ -252,17 +252,11 @@
// Calculate a modified Error used in distributing bits between easier and harder frames
static double calculate_modified_err(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
- double av_err = (cpi->twopass.total_stats.ssim_weighted_pred_err /
- cpi->twopass.total_stats.count);
- double this_err = this_frame->ssim_weighted_pred_err;
- double modified_err;
-
- if (this_err > av_err)
- modified_err = av_err * pow((this_err / DOUBLE_DIVIDE_CHECK(av_err)), POW1);
- else
- modified_err = av_err * pow((this_err / DOUBLE_DIVIDE_CHECK(av_err)), POW2);
-
- return modified_err;
+ const FIRSTPASS_STATS *const stats = &cpi->twopass.total_stats;
+ const double av_err = stats->ssim_weighted_pred_err / stats->count;
+ const double this_err = this_frame->ssim_weighted_pred_err;
+ return av_err * pow(this_err / DOUBLE_DIVIDE_CHECK(av_err),
+ this_err > av_err ? POW1 : POW2);
}
static const double weight_table[256] = {
@@ -328,20 +322,14 @@
static int frame_max_bits(VP9_COMP *cpi) {
// Max allocation for a single frame based on the max section guidelines
// passed in and how many bits are left.
- int max_bits;
-
// For VBR base this on the bits and frames left plus the
// two_pass_vbrmax_section rate passed in by the user.
- max_bits = (int) (((double) cpi->twopass.bits_left
- / (cpi->twopass.total_stats.count - (double) cpi->common
- .current_video_frame))
- * ((double) cpi->oxcf.two_pass_vbrmax_section / 100.0));
+ const double max_bits = (1.0 * cpi->twopass.bits_left /
+ (cpi->twopass.total_stats.count - cpi->common.current_video_frame)) *
+ (cpi->oxcf.two_pass_vbrmax_section / 100.0);
// Trap case where we are out of bits.
- if (max_bits < 0)
- max_bits = 0;
-
- return max_bits;
+ return MAX((int)max_bits, 0);
}
void vp9_init_first_pass(VP9_COMP *cpi) {
@@ -854,26 +842,18 @@
double err_divisor,
double pt_low,
double pt_high,
- int Q) {
- double power_term;
- double error_term = err_per_mb / err_divisor;
- double correction_factor;
+ int q) {
+ const double error_term = err_per_mb / err_divisor;
// Adjustment based on actual quantizer to power term.
- power_term = (vp9_convert_qindex_to_q(Q) * 0.01) + pt_low;
- power_term = (power_term > pt_high) ? pt_high : power_term;
+ const double power_term = MIN(vp9_convert_qindex_to_q(q) * 0.01 + pt_low,
+ pt_high);
// Calculate correction factor
if (power_term < 1.0)
assert(error_term >= 0.0);
- correction_factor = pow(error_term, power_term);
- // Clip range
- correction_factor =
- (correction_factor < 0.05)
- ? 0.05 : (correction_factor > 5.0) ? 5.0 : correction_factor;
-
- return correction_factor;
+ return fclamp(pow(error_term, power_term), 0.05, 5.0);
}
// Given a current maxQ value sets a range for future values.
@@ -882,10 +862,8 @@
// (now uses the actual quantizer) but has not been tuned.
static void adjust_maxq_qrange(VP9_COMP *cpi) {
int i;
- double q;
-
// Set the max corresponding to cpi->avg_q * 2.0
- q = cpi->avg_q * 2.0;
+ double q = cpi->avg_q * 2.0;
cpi->twopass.maxq_max_limit = cpi->worst_quality;
for (i = cpi->best_quality; i <= cpi->worst_quality; i++) {
cpi->twopass.maxq_max_limit = i;
@@ -906,12 +884,11 @@
static int estimate_max_q(VP9_COMP *cpi,
FIRSTPASS_STATS *fpstats,
int section_target_bandwitdh) {
- int Q;
+ int q;
int num_mbs = cpi->common.MBs;
int target_norm_bits_per_mb;
- double section_err = (fpstats->coded_error / fpstats->count);
- double sr_err_diff;
+ double section_err = fpstats->coded_error / fpstats->count;
double sr_correction;
double err_per_mb = section_err / num_mbs;
double err_correction_factor;
@@ -920,92 +897,74 @@
if (section_target_bandwitdh <= 0)
return cpi->twopass.maxq_max_limit; // Highest value allowed
- target_norm_bits_per_mb =
- (section_target_bandwitdh < (1 << 20))
- ? (512 * section_target_bandwitdh) / num_mbs
- : 512 * (section_target_bandwitdh / num_mbs);
+ target_norm_bits_per_mb = section_target_bandwitdh < (1 << 20)
+ ? (512 * section_target_bandwitdh) / num_mbs
+ : 512 * (section_target_bandwitdh / num_mbs);
// Look at the drop in prediction quality between the last frame
// and the GF buffer (which contained an older frame).
if (fpstats->sr_coded_error > fpstats->coded_error) {
- sr_err_diff =
- (fpstats->sr_coded_error - fpstats->coded_error) /
- (fpstats->count * cpi->common.MBs);
- sr_correction = (sr_err_diff / 32.0);
- sr_correction = pow(sr_correction, 0.25);
- if (sr_correction < 0.75)
- sr_correction = 0.75;
- else if (sr_correction > 1.25)
- sr_correction = 1.25;
+ double sr_err_diff = (fpstats->sr_coded_error - fpstats->coded_error) /
+ (fpstats->count * cpi->common.MBs);
+ sr_correction = fclamp(pow(sr_err_diff / 32.0, 0.25), 0.75, 1.25);
} else {
sr_correction = 0.75;
}
// Calculate a corrective factor based on a rolling ratio of bits spent
// vs target bits
- if ((cpi->rolling_target_bits > 0) &&
- (cpi->active_worst_quality < cpi->worst_quality)) {
- double rolling_ratio;
-
- rolling_ratio = (double)cpi->rolling_actual_bits /
- (double)cpi->rolling_target_bits;
+ if (cpi->rolling_target_bits > 0 &&
+ cpi->active_worst_quality < cpi->worst_quality) {
+ double rolling_ratio = (double)cpi->rolling_actual_bits /
+ (double)cpi->rolling_target_bits;
if (rolling_ratio < 0.95)
cpi->twopass.est_max_qcorrection_factor -= 0.005;
else if (rolling_ratio > 1.05)
cpi->twopass.est_max_qcorrection_factor += 0.005;
- cpi->twopass.est_max_qcorrection_factor =
- (cpi->twopass.est_max_qcorrection_factor < 0.1)
- ? 0.1
- : (cpi->twopass.est_max_qcorrection_factor > 10.0)
- ? 10.0 : cpi->twopass.est_max_qcorrection_factor;
+ cpi->twopass.est_max_qcorrection_factor = fclamp(
+ cpi->twopass.est_max_qcorrection_factor, 0.1, 10.0);
}
// Corrections for higher compression speed settings
// (reduced compression expected)
- if (cpi->compressor_speed == 1) {
- if (cpi->oxcf.cpu_used <= 5)
- speed_correction = 1.04 + (cpi->oxcf.cpu_used * 0.04);
- else
- speed_correction = 1.25;
- }
+ if (cpi->compressor_speed == 1)
+ speed_correction = cpi->oxcf.cpu_used <= 5 ?
+ 1.04 + (cpi->oxcf.cpu_used * 0.04) :
+ 1.25;
// Try and pick a max Q that will be high enough to encode the
// content at the given rate.
- for (Q = cpi->twopass.maxq_min_limit; Q < cpi->twopass.maxq_max_limit; Q++) {
+ for (q = cpi->twopass.maxq_min_limit; q < cpi->twopass.maxq_max_limit; q++) {
int bits_per_mb_at_this_q;
- err_correction_factor =
- calc_correction_factor(err_per_mb, ERR_DIVISOR, 0.4, 0.90, Q) *
- sr_correction * speed_correction *
- cpi->twopass.est_max_qcorrection_factor;
+ err_correction_factor = calc_correction_factor(err_per_mb,
+ ERR_DIVISOR, 0.4, 0.90, q) *
+ sr_correction * speed_correction *
+ cpi->twopass.est_max_qcorrection_factor;
-
- bits_per_mb_at_this_q =
- vp9_bits_per_mb(INTER_FRAME, Q, err_correction_factor);
+ bits_per_mb_at_this_q = vp9_bits_per_mb(INTER_FRAME, q,
+ err_correction_factor);
if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
break;
}
// Restriction on active max q for constrained quality mode.
- if ((cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
- (Q < cpi->cq_target_quality)) {
- Q = cpi->cq_target_quality;
- }
+ if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY &&
+ q < cpi->cq_target_quality)
+ q = cpi->cq_target_quality;
// Adjust maxq_min_limit and maxq_max_limit limits based on
// average q observed in clip for non kf/gf/arf frames
// Give average a chance to settle though.
// PGW TODO.. This code is broken for the extended Q range
- if ((cpi->ni_frames >
- ((int)cpi->twopass.total_stats.count >> 8)) &&
- (cpi->ni_frames > 25)) {
+ if (cpi->ni_frames > ((int)cpi->twopass.total_stats.count >> 8) &&
+ cpi->ni_frames > 25)
adjust_maxq_qrange(cpi);
- }
- return Q;
+ return q;
}
// For cq mode estimate a cq level that matches the observed
@@ -1013,7 +972,7 @@
static int estimate_cq(VP9_COMP *cpi,
FIRSTPASS_STATS *fpstats,
int section_target_bandwitdh) {
- int Q;
+ int q;
int num_mbs = cpi->common.MBs;
int target_norm_bits_per_mb;
@@ -1064,29 +1023,29 @@
clip_iifactor = 0.80;
// Try and pick a Q that can encode the content at the given rate.
- for (Q = 0; Q < MAXQ; Q++) {
+ for (q = 0; q < MAXQ; q++) {
int bits_per_mb_at_this_q;
// Error per MB based correction factor
err_correction_factor =
- calc_correction_factor(err_per_mb, 100.0, 0.4, 0.90, Q) *
+ calc_correction_factor(err_per_mb, 100.0, 0.4, 0.90, q) *
sr_correction * speed_correction * clip_iifactor;
bits_per_mb_at_this_q =
- vp9_bits_per_mb(INTER_FRAME, Q, err_correction_factor);
+ vp9_bits_per_mb(INTER_FRAME, q, err_correction_factor);
if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
break;
}
// Clip value to range "best allowed to (worst allowed - 1)"
- Q = select_cq_level(Q);
- if (Q >= cpi->worst_quality)
- Q = cpi->worst_quality - 1;
- if (Q < cpi->best_quality)
- Q = cpi->best_quality;
+ q = select_cq_level(q);
+ if (q >= cpi->worst_quality)
+ q = cpi->worst_quality - 1;
+ if (q < cpi->best_quality)
+ q = cpi->best_quality;
- return Q;
+ return q;
}
@@ -1117,9 +1076,8 @@
// encoded in the second pass is a guess. However the sum duration is not.
// Its calculated based on the actual durations of all frames from the first
// pass.
- vp9_new_frame_rate(cpi,
- 10000000.0 * cpi->twopass.total_stats.count /
- cpi->twopass.total_stats.duration);
+ vp9_new_frame_rate(cpi, 10000000.0 * cpi->twopass.total_stats.count /
+ cpi->twopass.total_stats.duration);
cpi->output_frame_rate = cpi->oxcf.frame_rate;
cpi->twopass.bits_left = (int64_t)(cpi->twopass.total_stats.duration *
@@ -1191,9 +1149,8 @@
// Look at the observed drop in prediction quality between the last frame
// and the GF buffer (which contains an older frame).
- mb_sr_err_diff =
- (next_frame->sr_coded_error - next_frame->coded_error) /
- (cpi->common.MBs);
+ mb_sr_err_diff = (next_frame->sr_coded_error - next_frame->coded_error) /
+ cpi->common.MBs;
if (mb_sr_err_diff <= 512.0) {
second_ref_decay = 1.0 - (mb_sr_err_diff / 512.0);
second_ref_decay = pow(second_ref_decay, 0.5);
@@ -1225,9 +1182,9 @@
// Break clause to detect very still sections after motion
// For example a static image after a fade or other transition
// instead of a clean scene cut.
- if ((frame_interval > MIN_GF_INTERVAL) &&
- (loop_decay_rate >= 0.999) &&
- (last_decay_rate < 0.9)) {
+ if (frame_interval > MIN_GF_INTERVAL &&
+ loop_decay_rate >= 0.999 &&
+ last_decay_rate < 0.9) {
int j;
FIRSTPASS_STATS *position = cpi->twopass.stats_in;
FIRSTPASS_STATS tmp_next_frame;
@@ -1271,10 +1228,9 @@
// are reasonably well predicted by an earlier (pre flash) frame.
// The recovery after a flash is indicated by a high pcnt_second_ref
// comapred to pcnt_inter.
- if ((next_frame.pcnt_second_ref > next_frame.pcnt_inter) &&
- (next_frame.pcnt_second_ref >= 0.5)) {
+ if (next_frame.pcnt_second_ref > next_frame.pcnt_inter &&
+ next_frame.pcnt_second_ref >= 0.5)
flash_detected = 1;
- }
}
return flash_detected;
@@ -1356,13 +1312,9 @@
return frame_boost;
}
-static int calc_arf_boost(
- VP9_COMP *cpi,
- int offset,
- int f_frames,
- int b_frames,
- int *f_boost,
- int *b_boost) {
+static int calc_arf_boost(VP9_COMP *cpi, int offset,
+ int f_frames, int b_frames,
+ int *f_boost, int *b_boost) {
FIRSTPASS_STATS this_frame;
int i;
@@ -1392,8 +1344,7 @@
// Cumulative effect of prediction quality decay
if (!flash_detected) {
- decay_accumulator =
- decay_accumulator * get_prediction_decay_rate(cpi, &this_frame);
+ decay_accumulator *= get_prediction_decay_rate(cpi, &this_frame);
decay_accumulator = decay_accumulator < MIN_DECAY_FACTOR
? MIN_DECAY_FACTOR : decay_accumulator;
}
@@ -1429,10 +1380,9 @@
// Cumulative effect of prediction quality decay
if (!flash_detected) {
- decay_accumulator =
- decay_accumulator * get_prediction_decay_rate(cpi, &this_frame);
+ decay_accumulator *= get_prediction_decay_rate(cpi, &this_frame);
decay_accumulator = decay_accumulator < MIN_DECAY_FACTOR
- ? MIN_DECAY_FACTOR : decay_accumulator;
+ ? MIN_DECAY_FACTOR : decay_accumulator;
}
boost_score += (decay_accumulator *
@@ -1871,26 +1821,20 @@
for (i = 0;
i <= (cpi->source_alt_ref_pending && cpi->common.frame_type != KEY_FRAME);
++i) {
- int boost;
int allocation_chunks;
- int Q =
- (cpi->oxcf.fixed_q < 0) ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q;
+ int q = cpi->oxcf.fixed_q < 0 ? cpi->last_q[INTER_FRAME]
+ : cpi->oxcf.fixed_q;
int gf_bits;
- boost = (cpi->gfu_boost * vp9_gfboost_qadjust(Q)) / 100;
+ int boost = (cpi->gfu_boost * vp9_gfboost_qadjust(q)) / 100;
// Set max and minimum boost and hence minimum allocation
- if (boost > ((cpi->baseline_gf_interval + 1) * 200))
- boost = ((cpi->baseline_gf_interval + 1) * 200);
- else if (boost < 125)
- boost = 125;
+ boost = clamp(boost, 125, (cpi->baseline_gf_interval + 1) * 200);
if (cpi->source_alt_ref_pending && i == 0)
- allocation_chunks =
- ((cpi->baseline_gf_interval + 1) * 100) + boost;
+ allocation_chunks = ((cpi->baseline_gf_interval + 1) * 100) + boost;
else
- allocation_chunks =
- (cpi->baseline_gf_interval * 100) + (boost - 100);
+ allocation_chunks = (cpi->baseline_gf_interval * 100) + (boost - 100);
// Prevent overflow
if (boost > 1023) {
@@ -1901,41 +1845,34 @@
// Calculate the number of bits to be spent on the gf or arf based on
// the boost number
- gf_bits = (int)((double)boost *
- (cpi->twopass.gf_group_bits /
- (double)allocation_chunks));
+ gf_bits = (int)((double)boost * (cpi->twopass.gf_group_bits /
+ (double)allocation_chunks));
// If the frame that is to be boosted is simpler than the average for
// the gf/arf group then use an alternative calculation
// based on the error score of the frame itself
if (mod_frame_err < gf_group_err / (double)cpi->baseline_gf_interval) {
- double alt_gf_grp_bits;
- int alt_gf_bits;
-
- alt_gf_grp_bits =
+ double alt_gf_grp_bits =
(double)cpi->twopass.kf_group_bits *
(mod_frame_err * (double)cpi->baseline_gf_interval) /
DOUBLE_DIVIDE_CHECK(cpi->twopass.kf_group_error_left);
- alt_gf_bits = (int)((double)boost * (alt_gf_grp_bits /
+ int alt_gf_bits = (int)((double)boost * (alt_gf_grp_bits /
(double)allocation_chunks));
- if (gf_bits > alt_gf_bits) {
+ if (gf_bits > alt_gf_bits)
gf_bits = alt_gf_bits;
- }
}
// Else if it is harder than other frames in the group make sure it at
// least receives an allocation in keeping with its relative error
// score, otherwise it may be worse off than an "un-boosted" frame
else {
- int alt_gf_bits =
- (int)((double)cpi->twopass.kf_group_bits *
- mod_frame_err /
- DOUBLE_DIVIDE_CHECK(cpi->twopass.kf_group_error_left));
+ int alt_gf_bits = (int)((double)cpi->twopass.kf_group_bits *
+ mod_frame_err /
+ DOUBLE_DIVIDE_CHECK(cpi->twopass.kf_group_error_left));
- if (alt_gf_bits > gf_bits) {
+ if (alt_gf_bits > gf_bits)
gf_bits = alt_gf_bits;
- }
}
// Dont allow a negative value for gf_bits
@@ -1983,14 +1920,11 @@
// despite (MIN_GF_INTERVAL) and would cause a divide by 0 in the
// calculation of alt_extra_bits.
if (cpi->baseline_gf_interval >= 3) {
- int boost = (cpi->source_alt_ref_pending)
- ? b_boost : cpi->gfu_boost;
+ const int boost = cpi->source_alt_ref_pending ? b_boost : cpi->gfu_boost;
if (boost >= 150) {
- int pct_extra;
int alt_extra_bits;
-
- pct_extra = (boost - 100) / 50;
+ int pct_extra = (boost - 100) / 50;
pct_extra = (pct_extra > 20) ? 20 : pct_extra;
alt_extra_bits = (int)((cpi->twopass.gf_group_bits * pct_extra) / 100);
@@ -2071,33 +2005,21 @@
// Make a damped adjustment to the active max q.
static int adjust_active_maxq(int old_maxqi, int new_maxqi) {
int i;
- int ret_val = new_maxqi;
- double old_q;
- double new_q;
- double target_q;
-
- old_q = vp9_convert_qindex_to_q(old_maxqi);
- new_q = vp9_convert_qindex_to_q(new_maxqi);
-
- target_q = ((old_q * 7.0) + new_q) / 8.0;
+ const double old_q = vp9_convert_qindex_to_q(old_maxqi);
+ const double new_q = vp9_convert_qindex_to_q(new_maxqi);
+ const double target_q = ((old_q * 7.0) + new_q) / 8.0;
if (target_q > old_q) {
- for (i = old_maxqi; i <= new_maxqi; i++) {
- if (vp9_convert_qindex_to_q(i) >= target_q) {
- ret_val = i;
- break;
- }
- }
+ for (i = old_maxqi; i <= new_maxqi; i++)
+ if (vp9_convert_qindex_to_q(i) >= target_q)
+ return i;
} else {
- for (i = old_maxqi; i >= new_maxqi; i--) {
- if (vp9_convert_qindex_to_q(i) <= target_q) {
- ret_val = i;
- break;
- }
- }
+ for (i = old_maxqi; i >= new_maxqi; i--)
+ if (vp9_convert_qindex_to_q(i) <= target_q)
+ return i;
}
- return ret_val;
+ return new_maxqi;
}
void vp9_second_pass(VP9_COMP *cpi) {
@@ -2111,9 +2033,8 @@
double this_frame_intra_error;
double this_frame_coded_error;
- if (!cpi->twopass.stats_in) {
+ if (!cpi->twopass.stats_in)
return;
- }
vp9_clear_system_state();
@@ -2123,12 +2044,8 @@
// Set a cq_level in constrained quality mode.
if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) {
- int est_cq;
-
- est_cq =
- estimate_cq(cpi,
- &cpi->twopass.total_left_stats,
- (int)(cpi->twopass.bits_left / frames_left));
+ int est_cq = estimate_cq(cpi, &cpi->twopass.total_left_stats,
+ (int)(cpi->twopass.bits_left / frames_left));
cpi->cq_target_quality = cpi->oxcf.cq_level;
if (est_cq > cpi->cq_target_quality)
@@ -2139,14 +2056,12 @@
cpi->twopass.maxq_max_limit = cpi->worst_quality;
cpi->twopass.maxq_min_limit = cpi->best_quality;
- tmp_q = estimate_max_q(
- cpi,
- &cpi->twopass.total_left_stats,
- (int)(cpi->twopass.bits_left / frames_left));
+ tmp_q = estimate_max_q(cpi, &cpi->twopass.total_left_stats,
+ (int)(cpi->twopass.bits_left / frames_left));
- cpi->active_worst_quality = tmp_q;
- cpi->ni_av_qi = tmp_q;
- cpi->avg_q = vp9_convert_qindex_to_q(tmp_q);
+ cpi->active_worst_quality = tmp_q;
+ cpi->ni_av_qi = tmp_q;
+ cpi->avg_q = vp9_convert_qindex_to_q(tmp_q);
#ifndef ONE_SHOT_Q_ESTIMATE
// Limit the maxq value returned subsequently.
@@ -2404,9 +2319,9 @@
if (cpi->oxcf.auto_key
&& lookup_next_frame_stats(cpi, &next_frame) != EOF) {
// Normal scene cut check
- if (test_candidate_kf(cpi, &last_frame, this_frame, &next_frame)) {
+ if (test_candidate_kf(cpi, &last_frame, this_frame, &next_frame))
break;
- }
+
// How fast is prediction quality decaying
loop_decay_rate = get_prediction_decay_rate(cpi, &next_frame);
@@ -2416,19 +2331,14 @@
// quality since the last GF or KF.
recent_loop_decay[i % 8] = loop_decay_rate;
decay_accumulator = 1.0;
- for (j = 0; j < 8; j++) {
- decay_accumulator = decay_accumulator * recent_loop_decay[j];
- }
+ for (j = 0; j < 8; j++)
+ decay_accumulator *= recent_loop_decay[j];
// Special check for transition or high motion followed by a
// to a static scene.
- if (detect_transition_to_still(cpi, i,
- (cpi->key_frame_frequency - i),
- loop_decay_rate,
- decay_accumulator)) {
+ if (detect_transition_to_still(cpi, i, cpi->key_frame_frequency - i,
+ loop_decay_rate, decay_accumulator))
break;
- }
-
// Step on to the next frame
cpi->twopass.frames_to_key++;