Commit d6da2ae3 authored by Dmitry Kovalev's avatar Dmitry Kovalev Committed by Gerrit Code Review
Browse files

Merge "Finally removing BOOL_DECODER and using vp9_reader instead." into experimental

parents 5c632dbb 0b44624c
...@@ -68,8 +68,8 @@ TEST(VP9, TestBitIO) { ...@@ -68,8 +68,8 @@ TEST(VP9, TestBitIO) {
vp9_stop_encode(&bw); vp9_stop_encode(&bw);
BOOL_DECODER br; vp9_reader br;
vp9_start_decode(&br, bw_buffer, buffer_size); vp9_reader_init(&br, bw_buffer, buffer_size);
bit_rnd.Reset(random_seed); bit_rnd.Reset(random_seed);
for (int i = 0; i < bits_to_test; ++i) { for (int i = 0; i < bits_to_test; ++i) {
if (bit_method == 2) { if (bit_method == 2) {
......
...@@ -13,25 +13,25 @@ ...@@ -13,25 +13,25 @@
#include "vp9/decoder/vp9_dboolhuff.h" #include "vp9/decoder/vp9_dboolhuff.h"
int vp9_start_decode(BOOL_DECODER *br, const uint8_t *buffer, size_t size) { int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size) {
br->buffer_end = buffer + size; r->buffer_end = buffer + size;
br->buffer = buffer; r->buffer = buffer;
br->value = 0; r->value = 0;
br->count = -8; r->count = -8;
br->range = 255; r->range = 255;
if (size && !buffer) if (size && !buffer)
return 1; return 1;
vp9_reader_fill(br); vp9_reader_fill(r);
return 0; return 0;
} }
void vp9_reader_fill(BOOL_DECODER *br) { void vp9_reader_fill(vp9_reader *r) {
const uint8_t *const buffer_end = br->buffer_end; const uint8_t *const buffer_end = r->buffer_end;
const uint8_t *buffer = br->buffer; const uint8_t *buffer = r->buffer;
VP9_BD_VALUE value = br->value; VP9_BD_VALUE value = r->value;
int count = br->count; int count = r->count;
int shift = VP9_BD_VALUE_SIZE - 8 - (count + 8); int shift = VP9_BD_VALUE_SIZE - 8 - (count + 8);
int loop_end = 0; int loop_end = 0;
const int bits_left = (int)((buffer_end - buffer)*CHAR_BIT); const int bits_left = (int)((buffer_end - buffer)*CHAR_BIT);
...@@ -50,8 +50,17 @@ void vp9_reader_fill(BOOL_DECODER *br) { ...@@ -50,8 +50,17 @@ void vp9_reader_fill(BOOL_DECODER *br) {
} }
} }
br->buffer = buffer; r->buffer = buffer;
br->value = value; r->value = value;
br->count = count; r->count = count;
}
const uint8_t *vp9_reader_find_end(vp9_reader *r) {
// Find the end of the coded buffer
while (r->count > CHAR_BIT && r->count < VP9_BD_VALUE_SIZE) {
r->count -= CHAR_BIT;
r->buffer--;
}
return r->buffer;
} }
...@@ -33,24 +33,17 @@ typedef struct { ...@@ -33,24 +33,17 @@ typedef struct {
VP9_BD_VALUE value; VP9_BD_VALUE value;
int count; int count;
unsigned int range; unsigned int range;
} BOOL_DECODER; } vp9_reader;
DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]); DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
int vp9_start_decode(BOOL_DECODER *br, const uint8_t *buffer, size_t size); int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size);
void vp9_reader_fill(BOOL_DECODER *br); void vp9_reader_fill(vp9_reader *r);
static INLINE const uint8_t *vp9_reader_find_end(BOOL_DECODER *br) { const uint8_t *vp9_reader_find_end(vp9_reader *r);
// Find the end of the coded buffer
while (br->count > CHAR_BIT && br->count < VP9_BD_VALUE_SIZE) {
br->count -= CHAR_BIT;
br->buffer--;
}
return br->buffer;
}
static int vp9_read(BOOL_DECODER *br, int probability) { static int vp9_read(vp9_reader *br, int probability) {
unsigned int bit = 0; unsigned int bit = 0;
VP9_BD_VALUE value; VP9_BD_VALUE value;
VP9_BD_VALUE bigsplit; VP9_BD_VALUE bigsplit;
...@@ -87,21 +80,20 @@ static int vp9_read(BOOL_DECODER *br, int probability) { ...@@ -87,21 +80,20 @@ static int vp9_read(BOOL_DECODER *br, int probability) {
return bit; return bit;
} }
static int vp9_read_bit(BOOL_DECODER *r) { static int vp9_read_bit(vp9_reader *r) {
return vp9_read(r, 128); // vp9_prob_half return vp9_read(r, 128); // vp9_prob_half
} }
static int vp9_read_literal(BOOL_DECODER *br, int bits) { static int vp9_read_literal(vp9_reader *br, int bits) {
int z = 0, bit; int z = 0, bit;
for (bit = bits - 1; bit >= 0; bit--) { for (bit = bits - 1; bit >= 0; bit--)
z |= vp9_read_bit(br) << bit; z |= vp9_read_bit(br) << bit;
}
return z; return z;
} }
static int bool_error(BOOL_DECODER *br) { static int vp9_reader_has_error(vp9_reader *r) {
// Check if we have reached the end of the buffer. // Check if we have reached the end of the buffer.
// //
// Variable 'count' stores the number of bits in the 'value' buffer, minus // Variable 'count' stores the number of bits in the 'value' buffer, minus
...@@ -116,7 +108,7 @@ static int bool_error(BOOL_DECODER *br) { ...@@ -116,7 +108,7 @@ static int bool_error(BOOL_DECODER *br) {
// //
// 1 if we have tried to decode bits after the end of stream was encountered. // 1 if we have tried to decode bits after the end of stream was encountered.
// 0 No error. // 0 No error.
return br->count > VP9_BD_VALUE_SIZE && br->count < VP9_LOTS_OF_BITS; return r->count > VP9_BD_VALUE_SIZE && r->count < VP9_LOTS_OF_BITS;
} }
#endif // VP9_DECODER_VP9_DBOOLHUFF_H_ #endif // VP9_DECODER_VP9_DBOOLHUFF_H_
...@@ -727,7 +727,7 @@ static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd, ...@@ -727,7 +727,7 @@ static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
if (xd->segmentation_enabled) if (xd->segmentation_enabled)
mb_init_dequantizer(pbi, xd); mb_init_dequantizer(pbi, xd);
if (!bool_error(r)) { if (!vp9_reader_has_error(r)) {
#if CONFIG_NEWBINTRAMODES #if CONFIG_NEWBINTRAMODES
if (mode != I4X4_PRED) if (mode != I4X4_PRED)
#endif #endif
...@@ -739,7 +739,7 @@ static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd, ...@@ -739,7 +739,7 @@ static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
mode != I4X4_PRED && mode != I4X4_PRED &&
mode != SPLITMV && mode != SPLITMV &&
mode != I8X8_PRED && mode != I8X8_PRED &&
!bool_error(r)) { !vp9_reader_has_error(r)) {
xd->mode_info_context->mbmi.mb_skip_coeff = 1; xd->mode_info_context->mbmi.mb_skip_coeff = 1;
} else { } else {
#if 0 // def DEC_DEBUG #if 0 // def DEC_DEBUG
...@@ -879,7 +879,7 @@ static void decode_modes_b(VP9D_COMP *pbi, int mb_row, int mb_col, ...@@ -879,7 +879,7 @@ static void decode_modes_b(VP9D_COMP *pbi, int mb_row, int mb_col,
else else
decode_mb(pbi, xd, mb_row, mb_col, r); decode_mb(pbi, xd, mb_row, mb_col, r);
xd->corrupted |= bool_error(r); xd->corrupted |= vp9_reader_has_error(r);
} }
static void decode_modes_sb(VP9D_COMP *pbi, int mb_row, int mb_col, static void decode_modes_sb(VP9D_COMP *pbi, int mb_row, int mb_col,
...@@ -970,7 +970,7 @@ static void setup_token_decoder(VP9D_COMP *pbi, ...@@ -970,7 +970,7 @@ static void setup_token_decoder(VP9D_COMP *pbi,
"Truncated packet or corrupt partition " "Truncated packet or corrupt partition "
"%d length", 1); "%d length", 1);
if (vp9_start_decode(r, data, partition_size)) if (vp9_reader_init(r, data, partition_size))
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder %d", 1); "Failed to allocate bool decoder %d", 1);
} }
...@@ -1546,7 +1546,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { ...@@ -1546,7 +1546,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
pc->width, pc->height, pc->width, pc->height,
VP9BORDERINPIXELS); VP9BORDERINPIXELS);
if (vp9_start_decode(&header_bc, data, first_partition_size)) if (vp9_reader_init(&header_bc, data, first_partition_size))
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder 0"); "Failed to allocate bool decoder 0");
...@@ -1696,7 +1696,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) { ...@@ -1696,7 +1696,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
// Collect information about decoder corruption. // Collect information about decoder corruption.
// 1. Check first boolean decoder for errors. // 1. Check first boolean decoder for errors.
// 2. Check the macroblock information // 2. Check the macroblock information
pc->yv12_fb[pc->new_fb_idx].corrupted = bool_error(&header_bc) | pc->yv12_fb[pc->new_fb_idx].corrupted = vp9_reader_has_error(&header_bc) |
corrupt_tokens; corrupt_tokens;
if (!pbi->decoded_key_frame) { if (!pbi->decoded_key_frame) {
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
#include "vp9/common/vp9_treecoder.h" #include "vp9/common/vp9_treecoder.h"
#include "vp9/decoder/vp9_dboolhuff.h" #include "vp9/decoder/vp9_dboolhuff.h"
typedef BOOL_DECODER vp9_reader;
#define vp9_read_prob(r) ((vp9_prob)vp9_read_literal(r, 8)) #define vp9_read_prob(r) ((vp9_prob)vp9_read_literal(r, 8))
#define vp9_read_and_apply_sign(r, value) (vp9_read_bit(r) ? -(value) : (value)) #define vp9_read_and_apply_sign(r, value) (vp9_read_bit(r) ? -(value) : (value))
......
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