Refactor bitreader and bitwriter wrapper.
Move code for reading and writing literals and reading trees to use
just the aom_read_bit() and aom_write_bit() function calls.
Change-Id: Id2bced5f0125a5558030a813c51c3d79e5701873
(cherry picked from aom/master commit bc1ac15846a200272551699d45457039535e56b2)
diff --git a/aom_dsp/bitreader.h b/aom_dsp/bitreader.h
index d189e74..86c5173 100644
--- a/aom_dsp/bitreader.h
+++ b/aom_dsp/bitreader.h
@@ -77,25 +77,25 @@
#if CONFIG_ANS
return uabs_read_bit(r); // Non trivial optimization at half probability
#else
- return aom_dk_read_bit(r);
+ return aom_read(r, 128); // aom_prob_half
#endif
}
static INLINE int aom_read_literal(aom_reader *r, int bits) {
-#if CONFIG_ANS
- return uabs_read_literal(r, bits);
-#else
- return aom_dk_read_literal(r, bits);
-#endif
+ int literal = 0, bit;
+
+ for (bit = bits - 1; bit >= 0; bit--) literal |= aom_read_bit(r) << bit;
+
+ return literal;
}
static INLINE int aom_read_tree(aom_reader *r, const aom_tree_index *tree,
const aom_prob *probs) {
-#if CONFIG_ANS
- return uabs_read_tree(r, tree, probs);
-#else
- return aom_dk_read_tree(r, tree, probs);
-#endif
+ aom_tree_index i = 0;
+
+ while ((i = tree[i + aom_read(r, probs[i >> 1])]) > 0) continue;
+
+ return -i;
}
#ifdef __cplusplus
diff --git a/aom_dsp/dkboolreader.c b/aom_dsp/dkboolreader.c
index c26d90b..8ec7ffc 100644
--- a/aom_dsp/dkboolreader.c
+++ b/aom_dsp/dkboolreader.c
@@ -18,6 +18,10 @@
#include "aom_mem/aom_mem.h"
#include "aom_util/endian_inl.h"
+static INLINE int aom_dk_read_bit(struct aom_dk_reader *r) {
+ return aom_dk_read(r, 128); // aom_prob_half
+}
+
int aom_dk_reader_init(struct aom_dk_reader *r, const uint8_t *buffer,
size_t size, aom_decrypt_cb decrypt_cb,
void *decrypt_state) {
diff --git a/aom_dsp/dkboolreader.h b/aom_dsp/dkboolreader.h
index 531c5dc..fe68ecc 100644
--- a/aom_dsp/dkboolreader.h
+++ b/aom_dsp/dkboolreader.h
@@ -135,28 +135,6 @@
return bit;
}
-static INLINE int aom_dk_read_bit(struct aom_dk_reader *r) {
- return aom_dk_read(r, 128); // aom_prob_half
-}
-
-static INLINE int aom_dk_read_literal(struct aom_dk_reader *r, int bits) {
- int literal = 0, bit;
-
- for (bit = bits - 1; bit >= 0; bit--) literal |= aom_dk_read_bit(r) << bit;
-
- return literal;
-}
-
-static INLINE int aom_dk_read_tree(struct aom_dk_reader *r,
- const aom_tree_index *tree,
- const aom_prob *probs) {
- aom_tree_index i = 0;
-
- while ((i = tree[i + aom_dk_read(r, probs[i >> 1])]) > 0) continue;
-
- return -i;
-}
-
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/aom_dsp/dkboolwriter.c b/aom_dsp/dkboolwriter.c
index 259316c..238f37c 100644
--- a/aom_dsp/dkboolwriter.c
+++ b/aom_dsp/dkboolwriter.c
@@ -12,6 +12,10 @@
#include "./dkboolwriter.h"
+static INLINE void aom_dk_write_bit(aom_dk_writer *w, int bit) {
+ aom_dk_write(w, bit, 128); // aom_prob_half
+}
+
void aom_dk_start_encode(aom_dk_writer *br, uint8_t *source) {
br->lowvalue = 0;
br->range = 255;
diff --git a/aom_dsp/dkboolwriter.h b/aom_dsp/dkboolwriter.h
index 8475238..8354368 100644
--- a/aom_dsp/dkboolwriter.h
+++ b/aom_dsp/dkboolwriter.h
@@ -97,16 +97,6 @@
br->range = range;
}
-static INLINE void aom_dk_write_bit(aom_dk_writer *w, int bit) {
- aom_dk_write(w, bit, 128); // aom_prob_half
-}
-
-static INLINE void aom_dk_write_literal(aom_dk_writer *w, int data, int bits) {
- int bit;
-
- for (bit = bits - 1; bit >= 0; bit--) aom_dk_write_bit(w, 1 & (data >> bit));
-}
-
#ifdef __cplusplus
} // extern "C"
#endif