Commit 2a1b3af3 authored by Alex Converse's avatar Alex Converse
Browse files

ans: Give buf_ans ownership of the AnsCoder

Change-Id: I509bbba0d84c1d378044e2c612dd48cd8f99848d
parent 7833d2bf
...@@ -39,8 +39,10 @@ struct buffered_ans_symbol { ...@@ -39,8 +39,10 @@ struct buffered_ans_symbol {
struct BufAnsCoder { struct BufAnsCoder {
struct aom_internal_error_info *error; struct aom_internal_error_info *error;
struct buffered_ans_symbol *buf; struct buffered_ans_symbol *buf;
struct AnsCoder ans;
int size; int size;
int offset; int offset;
int output_bytes;
}; };
void aom_buf_ans_alloc(struct BufAnsCoder *c, void aom_buf_ans_alloc(struct BufAnsCoder *c,
...@@ -50,8 +52,11 @@ void aom_buf_ans_free(struct BufAnsCoder *c); ...@@ -50,8 +52,11 @@ void aom_buf_ans_free(struct BufAnsCoder *c);
void aom_buf_ans_grow(struct BufAnsCoder *c); void aom_buf_ans_grow(struct BufAnsCoder *c);
static INLINE void buf_ans_write_reset(struct BufAnsCoder *const c) { static INLINE void buf_ans_write_init(struct BufAnsCoder *const c,
uint8_t *const output_buffer) {
c->offset = 0; c->offset = 0;
c->output_bytes = 0;
ans_write_init(&c->ans, output_buffer);
} }
static INLINE void buf_uabs_write(struct BufAnsCoder *const c, uint8_t val, static INLINE void buf_uabs_write(struct BufAnsCoder *const c, uint8_t val,
...@@ -78,20 +83,21 @@ static INLINE void buf_rans_write(struct BufAnsCoder *const c, ...@@ -78,20 +83,21 @@ static INLINE void buf_rans_write(struct BufAnsCoder *const c,
++c->offset; ++c->offset;
} }
static INLINE void buf_ans_flush(const struct BufAnsCoder *const c, static INLINE void buf_ans_flush(struct BufAnsCoder *const c) {
struct AnsCoder *ans) {
int offset; int offset;
for (offset = c->offset - 1; offset >= 0; --offset) { for (offset = c->offset - 1; offset >= 0; --offset) {
if (c->buf[offset].method == ANS_METHOD_RANS) { if (c->buf[offset].method == ANS_METHOD_RANS) {
struct rans_sym sym; struct rans_sym sym;
sym.prob = c->buf[offset].prob; sym.prob = c->buf[offset].prob;
sym.cum_prob = c->buf[offset].val_start; sym.cum_prob = c->buf[offset].val_start;
rans_write(ans, &sym); rans_write(&c->ans, &sym);
} else { } else {
uabs_write(ans, (uint8_t)c->buf[offset].val_start, uabs_write(&c->ans, (uint8_t)c->buf[offset].val_start,
(AnsP8)c->buf[offset].prob); (AnsP8)c->buf[offset].prob);
} }
} }
c->offset = 0;
c->output_bytes += ans_write_end(&c->ans);
} }
static INLINE void buf_uabs_write_bit(struct BufAnsCoder *c, int bit) { static INLINE void buf_uabs_write_bit(struct BufAnsCoder *c, int bit) {
...@@ -106,6 +112,11 @@ static INLINE void buf_uabs_write_literal(struct BufAnsCoder *c, int literal, ...@@ -106,6 +112,11 @@ static INLINE void buf_uabs_write_literal(struct BufAnsCoder *c, int literal,
for (bit = bits - 1; bit >= 0; bit--) for (bit = bits - 1; bit >= 0; bit--)
buf_uabs_write_bit(c, 1 & (literal >> bit)); buf_uabs_write_bit(c, 1 & (literal >> bit));
} }
static INLINE int buf_ans_write_end(struct BufAnsCoder *const c) {
assert(c->offset == 0);
return c->output_bytes;
}
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif // __cplusplus #endif // __cplusplus
......
...@@ -3464,7 +3464,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst, ...@@ -3464,7 +3464,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
#endif #endif
const AV1_COMMON *const cm = &cpi->common; const AV1_COMMON *const cm = &cpi->common;
#if CONFIG_ANS #if CONFIG_ANS
struct AnsCoder token_ans; struct BufAnsCoder *buf_ans = &cpi->buf_ans;
#else #else
aom_writer mode_bc; aom_writer mode_bc;
#endif // CONFIG_ANS #endif // CONFIG_ANS
...@@ -3495,9 +3495,6 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst, ...@@ -3495,9 +3495,6 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
#if CONFIG_EXT_TILE #if CONFIG_EXT_TILE
const int have_tiles = tile_cols * tile_rows > 1; const int have_tiles = tile_cols * tile_rows > 1;
#endif // CONFIG_EXT_TILE #endif // CONFIG_EXT_TILE
#if CONFIG_ANS
struct BufAnsCoder *buf_ans = &cpi->buf_ans;
#endif // CONFIG_ANS
*max_tile_size = 0; *max_tile_size = 0;
*max_tile_col_size = 0; *max_tile_col_size = 0;
...@@ -3536,12 +3533,11 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst, ...@@ -3536,12 +3533,11 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
aom_stop_encode(&mode_bc); aom_stop_encode(&mode_bc);
tile_size = mode_bc.pos; tile_size = mode_bc.pos;
#else #else
buf_ans_write_reset(buf_ans); buf_ans_write_init(buf_ans, buf->data + data_offset);
write_modes(cpi, &tile_info, buf_ans, &tok, tok_end); write_modes(cpi, &tile_info, buf_ans, &tok, tok_end);
assert(tok == tok_end); assert(tok == tok_end);
ans_write_init(&token_ans, buf->data + data_offset); buf_ans_flush(buf_ans);
buf_ans_flush(buf_ans, &token_ans); tile_size = buf_ans_write_end(buf_ans);
tile_size = ans_write_end(&token_ans);
#endif // !CONFIG_ANS #endif // !CONFIG_ANS
buf->size = tile_size; buf->size = tile_size;
...@@ -3686,12 +3682,11 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst, ...@@ -3686,12 +3682,11 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
if (!is_last_tile) total_size += 4; if (!is_last_tile) total_size += 4;
#if CONFIG_ANS #if CONFIG_ANS
buf_ans_write_reset(buf_ans); buf_ans_write_init(buf_ans, dst + total_size);
write_modes(cpi, &tile_info, buf_ans, &tok, tok_end); write_modes(cpi, &tile_info, buf_ans, &tok, tok_end);
assert(tok == tok_end); assert(tok == tok_end);
ans_write_init(&token_ans, dst + total_size); buf_ans_flush(buf_ans);
buf_ans_flush(buf_ans, &token_ans); tile_size = buf_ans_write_end(buf_ans);
tile_size = ans_write_end(&token_ans);
#else #else
aom_start_encode(&mode_bc, dst + total_size); aom_start_encode(&mode_bc, dst + total_size);
#if CONFIG_PVQ #if CONFIG_PVQ
...@@ -3703,10 +3698,10 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst, ...@@ -3703,10 +3698,10 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
assert(tok == tok_end); assert(tok == tok_end);
aom_stop_encode(&mode_bc); aom_stop_encode(&mode_bc);
tile_size = mode_bc.pos; tile_size = mode_bc.pos;
#endif #endif // CONFIG_ANS
#if CONFIG_PVQ #if CONFIG_PVQ
cpi->td.mb.pvq_q = NULL; cpi->td.mb.pvq_q = NULL;
#endif // !CONFIG_ANS #endif
assert(tile_size > 0); assert(tile_size > 0);
...@@ -4132,10 +4127,9 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) { ...@@ -4132,10 +4127,9 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) {
#endif #endif
#if CONFIG_ANS #if CONFIG_ANS
struct AnsCoder header_ans;
int header_size; int header_size;
header_bc = &cpi->buf_ans; header_bc = &cpi->buf_ans;
buf_ans_write_reset(header_bc); buf_ans_write_init(header_bc, data);
#else #else
aom_writer real_header_bc; aom_writer real_header_bc;
header_bc = &real_header_bc; header_bc = &real_header_bc;
...@@ -4333,9 +4327,8 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) { ...@@ -4333,9 +4327,8 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) {
#endif #endif
#endif #endif
#if CONFIG_ANS #if CONFIG_ANS
ans_write_init(&header_ans, data); buf_ans_flush(header_bc);
buf_ans_flush(header_bc, &header_ans); header_size = buf_ans_write_end(header_bc);
header_size = ans_write_end(&header_ans);
assert(header_size <= 0xffff); assert(header_size <= 0xffff);
return header_size; return header_size;
#else #else
......
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