Commit 1ecdf2bf authored by Alex Converse's avatar Alex Converse
Browse files

ans: Move buf_ans_flush to the .c file

It is called relatively rarely and doesn't need to be inlined.

Change-Id: I4ee7f95548f008f2ee29da807aaca54b9a25aecd
parent b0bbd606
...@@ -40,3 +40,20 @@ void aom_buf_ans_grow(struct BufAnsCoder *c) { ...@@ -40,3 +40,20 @@ void aom_buf_ans_grow(struct BufAnsCoder *c) {
c->buf = new_buf; c->buf = new_buf;
c->size = new_size; c->size = new_size;
} }
void aom_buf_ans_flush(struct BufAnsCoder *const c) {
int offset;
for (offset = c->offset - 1; offset >= 0; --offset) {
if (c->buf[offset].method == ANS_METHOD_RANS) {
struct rans_sym sym;
sym.prob = c->buf[offset].prob;
sym.cum_prob = c->buf[offset].val_start;
rans_write(&c->ans, &sym);
} else {
uabs_write(&c->ans, (uint8_t)c->buf[offset].val_start,
(AnsP8)c->buf[offset].prob);
}
}
c->offset = 0;
c->output_bytes += ans_write_end(&c->ans);
}
...@@ -52,6 +52,8 @@ void aom_buf_ans_free(struct BufAnsCoder *c); ...@@ -52,6 +52,8 @@ void aom_buf_ans_free(struct BufAnsCoder *c);
void aom_buf_ans_grow(struct BufAnsCoder *c); void aom_buf_ans_grow(struct BufAnsCoder *c);
void aom_buf_ans_flush(struct BufAnsCoder *const c);
static INLINE void buf_ans_write_init(struct BufAnsCoder *const c, static INLINE void buf_ans_write_init(struct BufAnsCoder *const c,
uint8_t *const output_buffer) { uint8_t *const output_buffer) {
c->offset = 0; c->offset = 0;
...@@ -83,23 +85,6 @@ static INLINE void buf_rans_write(struct BufAnsCoder *const c, ...@@ -83,23 +85,6 @@ static INLINE void buf_rans_write(struct BufAnsCoder *const c,
++c->offset; ++c->offset;
} }
static INLINE void buf_ans_flush(struct BufAnsCoder *const c) {
int offset;
for (offset = c->offset - 1; offset >= 0; --offset) {
if (c->buf[offset].method == ANS_METHOD_RANS) {
struct rans_sym sym;
sym.prob = c->buf[offset].prob;
sym.cum_prob = c->buf[offset].val_start;
rans_write(&c->ans, &sym);
} else {
uabs_write(&c->ans, (uint8_t)c->buf[offset].val_start,
(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) {
buf_uabs_write(c, bit, 128); buf_uabs_write(c, bit, 128);
} }
......
...@@ -3536,7 +3536,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst, ...@@ -3536,7 +3536,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
buf_ans_write_init(buf_ans, buf->data + data_offset); 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);
buf_ans_flush(buf_ans); aom_buf_ans_flush(buf_ans);
tile_size = buf_ans_write_end(buf_ans); tile_size = buf_ans_write_end(buf_ans);
#endif // !CONFIG_ANS #endif // !CONFIG_ANS
...@@ -3685,7 +3685,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst, ...@@ -3685,7 +3685,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
buf_ans_write_init(buf_ans, dst + total_size); 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);
buf_ans_flush(buf_ans); aom_buf_ans_flush(buf_ans);
tile_size = buf_ans_write_end(buf_ans); tile_size = buf_ans_write_end(buf_ans);
#else #else
aom_start_encode(&mode_bc, dst + total_size); aom_start_encode(&mode_bc, dst + total_size);
...@@ -4327,7 +4327,7 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) { ...@@ -4327,7 +4327,7 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) {
#endif #endif
#endif #endif
#if CONFIG_ANS #if CONFIG_ANS
buf_ans_flush(header_bc); aom_buf_ans_flush(header_bc);
header_size = buf_ans_write_end(header_bc); header_size = buf_ans_write_end(header_bc);
assert(header_size <= 0xffff); assert(header_size <= 0xffff);
return header_size; return header_size;
......
...@@ -56,7 +56,7 @@ bool check_uabs(const PvVec &pv_vec, uint8_t *buf) { ...@@ -56,7 +56,7 @@ bool check_uabs(const PvVec &pv_vec, uint8_t *buf) {
for (PvVec::const_iterator it = pv_vec.begin(); it != pv_vec.end(); ++it) { for (PvVec::const_iterator it = pv_vec.begin(); it != pv_vec.end(); ++it) {
buf_uabs_write(&a, it->second, 256 - it->first); buf_uabs_write(&a, it->second, 256 - it->first);
} }
buf_ans_flush(&a); aom_buf_ans_flush(&a);
std::clock_t enc_time = std::clock() - start; std::clock_t enc_time = std::clock() - start;
int offset = buf_ans_write_end(&a); int offset = buf_ans_write_end(&a);
aom_buf_ans_free(&a); aom_buf_ans_free(&a);
...@@ -125,7 +125,7 @@ bool check_rans(const std::vector<int> &sym_vec, const rans_sym *const tab, ...@@ -125,7 +125,7 @@ bool check_rans(const std::vector<int> &sym_vec, const rans_sym *const tab,
it != sym_vec.end(); ++it) { it != sym_vec.end(); ++it) {
buf_rans_write(&a, &tab[*it]); buf_rans_write(&a, &tab[*it]);
} }
buf_ans_flush(&a); aom_buf_ans_flush(&a);
std::clock_t enc_time = std::clock() - start; std::clock_t enc_time = std::clock() - start;
int offset = buf_ans_write_end(&a); int offset = buf_ans_write_end(&a);
aom_buf_ans_free(&a); aom_buf_ans_free(&a);
......
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