From 080a2cccba88c482cbea7be092734bc7d5490884 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 20 Sep 2016 16:39:01 -0700 Subject: [PATCH] Migrate bitwriter to the interface in aom/master Change-Id: I73d46229f0feea43cbe933e51da997833cce032b --- aom_dsp/bitwriter.h | 37 ++++++++++++++++++++++++++++++++++--- av1/encoder/bitstream.c | 2 +- av1/encoder/bitwriter.h | 19 ------------------- av1/encoder/treewriter.h | 6 +++--- test/av1_ans_test.cc | 19 ++++++++++--------- test/test.mk | 5 ++++- 6 files changed, 52 insertions(+), 36 deletions(-) diff --git a/aom_dsp/bitwriter.h b/aom_dsp/bitwriter.h index 550893a42..d3e4ae9c6 100644 --- a/aom_dsp/bitwriter.h +++ b/aom_dsp/bitwriter.h @@ -12,31 +12,62 @@ #ifndef AOM_DSP_BITWRITER_H_ #define AOM_DSP_BITWRITER_H_ +#include +#include "./aom_config.h" +#if CONFIG_ANS +#include "aom_dsp/buf_ans.h" +#elif CONFIG_DAALA_EC +#include "aom_dsp/daalaboolwriter.h" +#else #include "aom_dsp/dkboolwriter.h" +#endif #include "aom_dsp/prob.h" #ifdef __cplusplus extern "C" { #endif +#if CONFIG_ANS +typedef struct BufAnsCoder aom_writer; +#else typedef struct aom_dk_writer aom_writer; +#endif 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"); +#else aom_dk_start_encode(bc, buffer); +#endif } -static INLINE void aom_stop_encode(aom_writer *bc) { aom_dk_stop_encode(bc); } +static INLINE void aom_stop_encode(aom_writer *bc) { +#if CONFIG_ANS + (void)bc; + assert(0 && "buf_ans requires a more complicated shutdown procedure"); +#else + aom_dk_stop_encode(bc); +#endif +} static INLINE void aom_write(aom_writer *br, int bit, int probability) { +#if CONFIG_ANS + buf_uabs_write(br, bit, probability); +#else aom_dk_write(br, bit, probability); +#endif } static INLINE void aom_write_bit(aom_writer *w, int bit) { - aom_dk_write_bit(w, bit); + aom_write(w, bit, 128); // aom_prob_half } static INLINE void aom_write_literal(aom_writer *w, int data, int bits) { - aom_dk_write_literal(w, data, bits); + int bit; + + for (bit = bits - 1; bit >= 0; bit--) aom_write_bit(w, 1 & (data >> bit)); } #ifdef __cplusplus diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c index fedc26390..82f60facc 100644 --- a/av1/encoder/bitstream.c +++ b/av1/encoder/bitstream.c @@ -2890,7 +2890,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst, const int have_tiles = tile_cols * tile_rows > 1; #endif // CONFIG_EXT_TILE #if CONFIG_ANS - BufAnsCoder *buf_ans = &cpi->buf_ans; + struct BufAnsCoder *buf_ans = &cpi->buf_ans; #endif // CONFIG_ANS *max_tile_size = 0; diff --git a/av1/encoder/bitwriter.h b/av1/encoder/bitwriter.h index e4e72502a..21cc6a3a8 100644 --- a/av1/encoder/bitwriter.h +++ b/av1/encoder/bitwriter.h @@ -14,25 +14,6 @@ #ifndef AOM10_ENCODER_BITWRITER_H_ #define AOM10_ENCODER_BITWRITER_H_ -#include "./aom_config.h" -#include "aom_dsp/prob.h" -// Include bitwriter.h in the CONFIG_ANS to keep ANS building while -// porting from VP10 style entropy coder abstraction to the aom/master style -// entropy coder abstractions. #include "aom_dsp/bitwriter.h" -#if CONFIG_ANS -typedef struct BufAnsCoder BufAnsCoder; -#include "aom_dsp/buf_ans.h" -#define aom_writer BufAnsCoder -#define aom_write buf_uabs_write -#define aom_write_bit buf_uabs_write_bit -#define aom_write_literal buf_uabs_write_literal -#else -#define aom_writer aom_writer -#define aom_write aom_write -#define aom_write_bit aom_write_bit -#define aom_write_literal aom_write_literal -#endif - #endif // AOM10_ENCODER_BITWRITER_H_ diff --git a/av1/encoder/treewriter.h b/av1/encoder/treewriter.h index 7a5c702ed..eb7f0a7c8 100644 --- a/av1/encoder/treewriter.h +++ b/av1/encoder/treewriter.h @@ -13,9 +13,9 @@ #define AV1_ENCODER_TREEWRITER_H_ #ifdef AV1_FORCE_AOMBOOL_TREEWRITER -#include "aom_dsp/bitwriter.h" -#define tree_writer aom_writer -#define tree_bit_write aom_write +#include "aom_dsp/dkboolwriter.h" +#define tree_writer aom_dk_writer +#define tree_bit_write aom_dk_write #else #include "av1/encoder/bitwriter.h" #define tree_writer aom_writer diff --git a/test/av1_ans_test.cc b/test/av1_ans_test.cc index 29a1cf5d5..b0cec9023 100644 --- a/test/av1_ans_test.cc +++ b/test/av1_ans_test.cc @@ -19,11 +19,12 @@ #include "third_party/googletest/src/include/gtest/gtest.h" -#include "test/acm_random.h" #include "aom_dsp/ans.h" -#include "av1/encoder/treewriter.h" #include "aom_dsp/bitreader.h" #include "aom_dsp/bitwriter.h" +#include "aom_dsp/dkboolwriter.h" +#include "av1/encoder/treewriter.h" +#include "test/acm_random.h" namespace { typedef std::vector > PvVec; @@ -125,16 +126,16 @@ bool check_uabs(const PvVec &pv_vec, uint8_t *buf) { } bool check_aombool(const PvVec &pv_vec, uint8_t *buf) { - aom_writer w; + aom_dk_writer w; aom_reader r; - aom_start_encode(&w, buf); + aom_dk_start_encode(&w, buf); std::clock_t start = std::clock(); for (PvVec::const_iterator it = pv_vec.begin(); it != pv_vec.end(); ++it) { - aom_write(&w, it->second, 256 - it->first); + aom_dk_write(&w, it->second, 256 - it->first); } std::clock_t enc_time = std::clock() - start; - aom_stop_encode(&w); + aom_dk_stop_encode(&w); bool okay = true; aom_reader_init(&r, buf, w.pos, NULL, NULL); start = std::clock(); @@ -274,9 +275,9 @@ void build_tpb(aom_prob probs[/*num_syms*/], bool check_aomtree(const std::vector &sym_vec, const rans_sym *sym_tab, uint8_t *buf) { - aom_writer w; + aom_dk_writer w; aom_reader r; - aom_start_encode(&w, buf); + aom_dk_start_encode(&w, buf); aom_prob probs[kDistinctSyms]; aom_tree_index tree[2 * kDistinctSyms]; @@ -289,7 +290,7 @@ bool check_aomtree(const std::vector &sym_vec, const rans_sym *sym_tab, av1_write_tree(&w, tree, probs, bit_len[*it].bits, bit_len[*it].len, 0); } std::clock_t enc_time = std::clock() - start; - aom_stop_encode(&w); + aom_dk_stop_encode(&w); aom_reader_init(&r, buf, w.pos, NULL, NULL); start = std::clock(); for (std::vector::const_iterator it = sym_vec.begin(); diff --git a/test/test.mk b/test/test.mk index 30b1b6813..ce9e342e9 100644 --- a/test/test.mk +++ b/test/test.mk @@ -101,7 +101,11 @@ LIBAOM_TEST_SRCS-yes += idct8x8_test.cc LIBAOM_TEST_SRCS-yes += partial_idct_test.cc LIBAOM_TEST_SRCS-yes += superframe_test.cc LIBAOM_TEST_SRCS-yes += tile_independence_test.cc +ifeq ($(CONFIG_ANS),yes) +LIBAOM_TEST_SRCS-yes += av1_ans_test.cc +else LIBAOM_TEST_SRCS-yes += boolcoder_test.cc +endif LIBAOM_TEST_SRCS-yes += divu_small_test.cc #LIBAOM_TEST_SRCS-yes += encoder_parms_get_to_decoder.cc endif @@ -136,7 +140,6 @@ ifeq ($(CONFIG_EXT_TX),yes) LIBAOM_TEST_SRCS-$(CONFIG_AV1_ENCODER) += av1_fht8x16_test.cc LIBAOM_TEST_SRCS-$(CONFIG_AV1_ENCODER) += av1_fht16x8_test.cc endif -LIBAOM_TEST_SRCS-$(CONFIG_ANS) += av1_ans_test.cc LIBAOM_TEST_SRCS-$(CONFIG_EXT_TILE) += av1_ext_tile_test.cc LIBAOM_TEST_SRCS-$(CONFIG_AV1_ENCODER) += sum_squares_test.cc