Commit 0c2ee67a authored by Deb Mukherjee's avatar Deb Mukherjee Committed by Gerrit Code Review
Browse files

Merge "Enable coefficient range checking for 10-/12-bit"

parents 238c4fa7 0ce2a27e
This diff is collapsed.
...@@ -80,13 +80,7 @@ static const tran_high_t sinpi_3_9 = 13377; ...@@ -80,13 +80,7 @@ static const tran_high_t sinpi_3_9 = 13377;
static const tran_high_t sinpi_4_9 = 15212; static const tran_high_t sinpi_4_9 = 15212;
static INLINE tran_low_t check_range(tran_high_t input) { static INLINE tran_low_t check_range(tran_high_t input) {
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_COEFFICIENT_RANGE_CHECKING
// For valid highbitdepth VP9 streams, intermediate stage coefficients will
// stay within the ranges:
// - 8 bit: signed 16 bit integer
// - 10 bit: signed 18 bit integer
// - 12 bit: signed 20 bit integer
#elif CONFIG_COEFFICIENT_RANGE_CHECKING
// For valid VP9 input streams, intermediate stage coefficients should always // For valid VP9 input streams, intermediate stage coefficients should always
// stay within the range of a signed 16 bit integer. Coefficients can go out // stay within the range of a signed 16 bit integer. Coefficients can go out
// of this range for invalid/corrupt VP9 streams. However, strictly checking // of this range for invalid/corrupt VP9 streams. However, strictly checking
...@@ -95,7 +89,7 @@ static INLINE tran_low_t check_range(tran_high_t input) { ...@@ -95,7 +89,7 @@ static INLINE tran_low_t check_range(tran_high_t input) {
// --enable-coefficient-range-checking. // --enable-coefficient-range-checking.
assert(INT16_MIN <= input); assert(INT16_MIN <= input);
assert(input <= INT16_MAX); assert(input <= INT16_MAX);
#endif #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
return (tran_low_t)input; return (tran_low_t)input;
} }
...@@ -104,6 +98,32 @@ static INLINE tran_low_t dct_const_round_shift(tran_high_t input) { ...@@ -104,6 +98,32 @@ static INLINE tran_low_t dct_const_round_shift(tran_high_t input) {
return check_range(rv); return check_range(rv);
} }
#if CONFIG_VP9_HIGHBITDEPTH
static INLINE tran_low_t highbd_check_range(tran_high_t input,
int bd) {
#if CONFIG_COEFFICIENT_RANGE_CHECKING
// For valid highbitdepth VP9 streams, intermediate stage coefficients will
// stay within the ranges:
// - 8 bit: signed 16 bit integer
// - 10 bit: signed 18 bit integer
// - 12 bit: signed 20 bit integer
const int32_t int_max = (1 << (7 + bd)) - 1;
const int32_t int_min = -int_max - 1;
assert(int_min <= input);
assert(input <= int_max);
(void) int_min;
#endif // CONFIG_COEFFICIENT_RANGE_CHECKING
(void) bd;
return (tran_low_t)input;
}
static INLINE tran_low_t highbd_dct_const_round_shift(tran_high_t input,
int bd) {
tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
return highbd_check_range(rv, bd);
}
#endif // CONFIG_VP9_HIGHBITDEPTH
typedef void (*transform_1d)(const tran_low_t*, tran_low_t*); typedef void (*transform_1d)(const tran_low_t*, tran_low_t*);
typedef struct { typedef struct {
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include "vp9/common/vp9_blockd.h" #include "vp9/common/vp9_blockd.h"
#include "vp9/common/vp9_common.h" #include "vp9/common/vp9_common.h"
#include "vp9/common/vp9_entropy.h" #include "vp9/common/vp9_entropy.h"
#if CONFIG_COEFFICIENT_RANGE_CHECKING
#include "vp9/common/vp9_idct.h"
#endif
#include "vp9/decoder/vp9_detokenize.h" #include "vp9/decoder/vp9_detokenize.h"
...@@ -32,7 +35,7 @@ ...@@ -32,7 +35,7 @@
#define INCREMENT_COUNT(token) \ #define INCREMENT_COUNT(token) \
do { \ do { \
if (!cm->frame_parallel_decoding_mode) \ if (!cm->frame_parallel_decoding_mode) \
++coef_counts[band][ctx][token]; \ ++coef_counts[band][ctx][token]; \
} while (0) } while (0)
static INLINE int read_coeff(const vp9_prob *probs, int n, vp9_reader *r) { static INLINE int read_coeff(const vp9_prob *probs, int n, vp9_reader *r) {
...@@ -191,10 +194,15 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, PLANE_TYPE type, ...@@ -191,10 +194,15 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, PLANE_TYPE type,
} }
v = (val * dqv) >> dq_shift; v = (val * dqv) >> dq_shift;
#if CONFIG_COEFFICIENT_RANGE_CHECKING #if CONFIG_COEFFICIENT_RANGE_CHECKING
#if CONFIG_VP9_HIGHBITDEPTH
dqcoeff[scan[c]] = highbd_check_range((vp9_read_bit(r) ? -v : v),
cm->bit_depth);
#else
dqcoeff[scan[c]] = check_range(vp9_read_bit(r) ? -v : v); dqcoeff[scan[c]] = check_range(vp9_read_bit(r) ? -v : v);
#endif // CONFIG_VP9_HIGHBITDEPTH
#else #else
dqcoeff[scan[c]] = vp9_read_bit(r) ? -v : v; dqcoeff[scan[c]] = vp9_read_bit(r) ? -v : v;
#endif #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
token_cache[scan[c]] = vp9_pt_energy_class[token]; token_cache[scan[c]] = vp9_pt_energy_class[token];
++c; ++c;
ctx = get_coef_context(nb, token_cache, c); ctx = get_coef_context(nb, token_cache, c);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment