Add token cost comparison in write_modes_b()
This is just partial implementation
Compare token cost of pack_mb_tokens/pack_txb_tokens with token cost
from rate-distortion loop. If there is any difference, dump out mode
info.
Change-Id: I46b373ee2522c5047f799f36baf7cec5fbc06f06
diff --git a/aom_dsp/bitwriter.h b/aom_dsp/bitwriter.h
index ef529fc..b437669 100644
--- a/aom_dsp/bitwriter.h
+++ b/aom_dsp/bitwriter.h
@@ -27,6 +27,10 @@
#endif
#include "aom_dsp/prob.h"
+#if CONFIG_RD_DEBUG
+#include "av1/encoder/cost.h"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -39,6 +43,8 @@
typedef struct aom_dk_writer aom_writer;
#endif
+typedef struct TOKEN_STATS { int64_t cost; } TOKEN_STATS;
+
static INLINE void aom_start_encode(aom_writer *bc, uint8_t *buffer) {
#if CONFIG_ANS
(void)bc;
@@ -72,10 +78,25 @@
#endif
}
+static INLINE void aom_write_record(aom_writer *br, int bit, int probability,
+ TOKEN_STATS *token_stats) {
+ aom_write(br, bit, probability);
+#if CONFIG_RD_DEBUG
+ token_stats->cost += av1_cost_bit(probability, bit);
+#else
+ (void)token_stats;
+#endif
+}
+
static INLINE void aom_write_bit(aom_writer *w, int bit) {
aom_write(w, bit, 128); // aom_prob_half
}
+static INLINE void aom_write_bit_record(aom_writer *w, int bit,
+ TOKEN_STATS *token_stats) {
+ aom_write_record(w, bit, 128, token_stats); // aom_prob_half
+}
+
static INLINE void aom_write_literal(aom_writer *w, int data, int bits) {
int bit;
@@ -92,6 +113,18 @@
} while (len);
}
+static INLINE void aom_write_tree_bits_record(aom_writer *w,
+ const aom_tree_index *tr,
+ const aom_prob *probs, int bits,
+ int len, aom_tree_index i,
+ TOKEN_STATS *token_stats) {
+ do {
+ const int bit = (bits >> --len) & 1;
+ aom_write_record(w, bit, probs[i >> 1], token_stats);
+ i = tr[i + bit];
+ } while (len);
+}
+
static INLINE void aom_write_tree(aom_writer *w, const aom_tree_index *tree,
const aom_prob *probs, int bits, int len,
aom_tree_index i) {
@@ -102,6 +135,19 @@
#endif
}
+static INLINE void aom_write_tree_record(aom_writer *w,
+ const aom_tree_index *tree,
+ const aom_prob *probs, int bits,
+ int len, aom_tree_index i,
+ TOKEN_STATS *token_stats) {
+#if CONFIG_DAALA_EC
+ (void)token_stats;
+ daala_write_tree_bits(w, tree, probs, bits, len, i);
+#else
+ aom_write_tree_bits_record(w, tree, probs, bits, len, i, token_stats);
+#endif
+}
+
#if CONFIG_EC_MULTISYMBOL
static INLINE void aom_write_symbol(aom_writer *w, int symb, aom_cdf_prob *cdf,
int nsymbs) {