Commit 30f0e15d authored by Alex Converse's avatar Alex Converse

Remove special ANS initialization handling

Change-Id: I5d5a93b27a42d591ff41ff23c007fc2954d2f9a7
parent 9efbaf9c
......@@ -62,9 +62,8 @@ static INLINE void init_token_stats(TOKEN_STATS *token_stats) {
static INLINE void aom_start_encode(aom_writer *bc, uint8_t *buffer) {
#if CONFIG_ANS
(void)bc;
(void)buffer;
assert(0 && "buf_ans requires a more complicated startup procedure");
aom_buf_ans_alloc(bc, /* error context*/ NULL);
buf_ans_write_init(bc, buffer);
#else
aom_daala_start_encode(bc, buffer);
#endif
......@@ -72,8 +71,8 @@ static INLINE void aom_start_encode(aom_writer *bc, uint8_t *buffer) {
static INLINE void aom_stop_encode(aom_writer *bc) {
#if CONFIG_ANS
(void)bc;
assert(0 && "buf_ans requires a more complicated shutdown procedure");
aom_buf_ans_flush(bc);
bc->pos = buf_ans_write_end(bc);
#else
aom_daala_stop_encode(bc);
#endif
......
......@@ -16,9 +16,8 @@
#include "aom/internal/aom_codec_internal.h"
void aom_buf_ans_alloc(struct BufAnsCoder *c,
struct aom_internal_error_info *error, int size) {
struct aom_internal_error_info *error) {
c->error = error;
c->size = size;
assert(c->size > 1);
AOM_CHECK_MEM_ERROR(error, c->buf, aom_malloc(c->size * sizeof(*c->buf)));
// Initialize to overfull to trigger the assert in write.
......
......@@ -46,6 +46,7 @@ struct BufAnsCoder {
#if ANS_MAX_SYMBOLS
int window_size;
#endif
int pos; // Dummy variable to store the output buffer after closing
};
// Allocate a buffered ANS coder to store size symbols.
......@@ -54,7 +55,7 @@ struct BufAnsCoder {
// When ANS_MAX_SYMBOLS is turned off, size is merely an initial hint and the
// buffer will grow on demand
void aom_buf_ans_alloc(struct BufAnsCoder *c,
struct aom_internal_error_info *error, int hint);
struct aom_internal_error_info *error);
void aom_buf_ans_free(struct BufAnsCoder *c);
......
......@@ -40,9 +40,6 @@
#include "av1/common/seg_common.h"
#include "av1/common/tile_common.h"
#if CONFIG_ANS
#include "aom_dsp/buf_ans.h"
#endif // CONFIG_ANS
#if CONFIG_LV_MAP
#include "av1/encoder/encodetxb.h"
#endif // CONFIG_LV_MAP
......@@ -3780,11 +3777,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
unsigned int *max_tile_size,
unsigned int *max_tile_col_size) {
const AV1_COMMON *const cm = &cpi->common;
#if CONFIG_ANS
struct BufAnsCoder *buf_ans = &cpi->buf_ans;
#else
aom_writer mode_bc;
#endif // CONFIG_ANS
int tile_row, tile_col;
TOKENEXTRA *(*const tok_buffers)[MAX_TILE_COLS] = cpi->tile_tok;
TileBufferEnc(*const tile_buffers)[MAX_TILE_COLS] = cpi->tile_buffers;
......@@ -3857,19 +3850,14 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
cpi->td.mb.pvq_q = &this_tile->pvq_q;
cpi->td.mb.daala_enc.state.adapt = &this_tile->tctx.pvq_context;
#endif // CONFIG_PVQ
#if !CONFIG_ANS
#if CONFIG_ANS
mode_bc.size = 1 << cpi->common.ans_window_size_log2;
#endif
aom_start_encode(&mode_bc, buf->data + data_offset);
write_modes(cpi, &tile_info, &mode_bc, &tok, tok_end);
assert(tok == tok_end);
aom_stop_encode(&mode_bc);
tile_size = mode_bc.pos;
#else
buf_ans_write_init(buf_ans, buf->data + data_offset);
write_modes(cpi, &tile_info, buf_ans, &tok, tok_end);
assert(tok == tok_end);
aom_buf_ans_flush(buf_ans);
tile_size = buf_ans_write_end(buf_ans);
#endif // !CONFIG_ANS
#if CONFIG_PVQ
cpi->td.mb.pvq_q = NULL;
#endif
......@@ -4033,22 +4021,17 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
cpi->td.mb.daala_enc.state.adapt = &this_tile->tctx.pvq_context;
#endif // CONFIG_PVQ
#if CONFIG_ANS
buf_ans_write_init(buf_ans, dst + total_size);
write_modes(cpi, &tile_info, buf_ans, &tok, tok_end);
assert(tok == tok_end);
aom_buf_ans_flush(buf_ans);
tile_size = buf_ans_write_end(buf_ans);
#else
aom_start_encode(&mode_bc, dst + total_size);
write_modes(cpi, &tile_info, &mode_bc, &tok, tok_end);
mode_bc.size = 1 << cpi->common.ans_window_size_log2;
#endif // CONFIG_ANS
aom_start_encode(&mode_bc, dst + total_size);
write_modes(cpi, &tile_info, &mode_bc, &tok, tok_end);
#if !CONFIG_LV_MAP
#if !CONFIG_PVQ
assert(tok == tok_end);
assert(tok == tok_end);
#endif // !CONFIG_PVQ
#endif // !CONFIG_LV_MAP
aom_stop_encode(&mode_bc);
tile_size = mode_bc.pos;
#endif // CONFIG_ANS
aom_stop_encode(&mode_bc);
tile_size = mode_bc.pos;
#if CONFIG_PVQ
cpi->td.mb.pvq_q = NULL;
#endif
......@@ -4635,15 +4618,12 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) {
(void)i;
(void)fc;
#if CONFIG_ANS
int header_size;
header_bc = &cpi->buf_ans;
buf_ans_write_init(header_bc, data);
#else
aom_writer real_header_bc;
header_bc = &real_header_bc;
aom_start_encode(header_bc, data);
#if CONFIG_ANS
header_bc->size = 1 << cpi->common.ans_window_size_log2;
#endif
aom_start_encode(header_bc, data);
#if CONFIG_LOOP_RESTORATION
encode_restoration(cm, header_bc);
......@@ -4788,16 +4768,9 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) {
write_global_motion(cpi, header_bc);
#endif // CONFIG_GLOBAL_MOTION
}
#if CONFIG_ANS
aom_buf_ans_flush(header_bc);
header_size = buf_ans_write_end(header_bc);
assert(header_size <= 0xffff);
return header_size;
#else
aom_stop_encode(header_bc);
assert(header_bc->pos <= 0xffff);
return header_bc->pos;
#endif // CONFIG_ANS
}
static int choose_size_bytes(uint32_t size, int spare_msbs) {
......
......@@ -835,9 +835,6 @@ void av1_alloc_compressor_data(AV1_COMP *cpi) {
unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols);
CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0],
aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0])));
#if CONFIG_ANS && !ANS_MAX_SYMBOLS
aom_buf_ans_alloc(&cpi->buf_ans, &cm->error, (int)tokens);
#endif // CONFIG_ANS
}
av1_setup_pc_tree(&cpi->common, &cpi->td);
......@@ -2390,14 +2387,8 @@ void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) {
#if CONFIG_HIGHBITDEPTH
highbd_set_var_fns(cpi);
#endif
#if CONFIG_ANS && ANS_MAX_SYMBOLS
cpi->common.ans_window_size_log2 = cpi->oxcf.ans_window_size_log2;
if (cpi->buf_ans.size != (1 << cpi->common.ans_window_size_log2)) {
aom_buf_ans_free(&cpi->buf_ans);
aom_buf_ans_alloc(&cpi->buf_ans, &cpi->common.error,
1 << cpi->common.ans_window_size_log2);
}
#endif // CONFIG_ANS && ANS_MAX_SYMBOLS
}
......
......@@ -51,7 +51,8 @@ PvVec abs_encode_build_vals(int iters) {
bool check_rabs(const PvVec &pv_vec, uint8_t *buf) {
BufAnsCoder a;
aom_buf_ans_alloc(&a, NULL, kBufAnsSize);
a.size = kBufAnsSize;
aom_buf_ans_alloc(&a, NULL);
buf_ans_write_init(&a, buf);
std::clock_t start = std::clock();
......@@ -125,7 +126,8 @@ void rans_build_dec_tab(const struct rans_sym sym_tab[],
bool check_rans(const std::vector<int> &sym_vec, const rans_sym *const tab,
uint8_t *buf) {
BufAnsCoder a;
aom_buf_ans_alloc(&a, NULL, kBufAnsSize);
a.size = kBufAnsSize;
aom_buf_ans_alloc(&a, NULL);
buf_ans_write_init(&a, buf);
aom_cdf_prob dec_tab[kRansSymbols];
rans_build_dec_tab(tab, dec_tab);
......
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