Commit e6b12944 authored by Michael Bebenita's avatar Michael Bebenita Committed by Nathan Egge

Bit accounting.

This patch adds bit account infrastructure to the bit reader API.
When configured with --enable-accounting, every bit reader API
function records the number of bits necessary to decoding a symbol.
Accounting symbol entries are collected in global accounting data
structure, that can be used to understand exactly where bits are
spent (http://aomanalyzer.org). The data structure is cleared and
reused each frame to reduce memory usage. When configured without
--enable-accounting, bit accounting does not incur any runtime
overhead.

All aom_read_xxx functions now have an additional string parameter
that specifies the symbol name. By default, the ACCT_STR macro is
used (which expands to __func__). For more precise accounting,
these should be replaced with more descriptive names.

Change-Id: Ia2e1343cb842c9391b12b77272587dfbe307a56d
parent b87951a6
......@@ -28,6 +28,29 @@
#include "aom_dsp/prob.h"
#include "av1/common/odintrin.h"
#if CONFIG_ACCOUNTING
#include "av1/common/accounting.h"
#define ACCT_STR_NAME acct_str
#define ACCT_STR_PARAM , const char *ACCT_STR_NAME
#define ACCT_STR_ARG(s) , s
#else
#define ACCT_STR_PARAM
#define ACCT_STR_ARG(s)
#endif
#define aom_read(r, prob, ACCT_STR_NAME) \
aom_read_(r, prob ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_bit(r, ACCT_STR_NAME) \
aom_read_bit_(r ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_tree(r, tree, probs, ACCT_STR_NAME) \
aom_read_tree_(r, tree, probs ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_literal(r, bits, ACCT_STR_NAME) \
aom_read_literal_(r, bits ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_tree_bits(r, tree, probs, ACCT_STR_NAME) \
aom_read_tree_bits_(r, tree, probs ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_symbol(r, cdf, nsymbs, ACCT_STR_NAME) \
aom_read_symbol_(r, cdf, nsymbs ACCT_STR_ARG(ACCT_STR_NAME))
#ifdef __cplusplus
extern "C" {
#endif
......@@ -105,64 +128,100 @@ static INLINE ptrdiff_t aom_reader_tell_frac(const aom_reader *r) {
#endif
}
static INLINE int aom_read(aom_reader *r, int prob) {
#if CONFIG_ACCOUNTING
static INLINE void aom_process_accounting(const aom_reader *r ACCT_STR_PARAM) {
if (r->accounting != NULL) {
uint32_t tell_frac;
tell_frac = aom_reader_tell_frac(r);
aom_accounting_record(r->accounting, ACCT_STR_NAME,
tell_frac - r->accounting->last_tell_frac);
r->accounting->last_tell_frac = tell_frac;
}
}
#endif
static INLINE int aom_read_(aom_reader *r, int prob ACCT_STR_PARAM) {
int ret;
#if CONFIG_ANS
return uabs_read(r, prob);
ret = uabs_read(r, prob);
#elif CONFIG_DAALA_EC
return aom_daala_read(r, prob);
ret = aom_daala_read(r, prob);
#else
return aom_dk_read(r, prob);
ret = aom_dk_read(r, prob);
#endif
#if CONFIG_ACCOUNTING
if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
#endif
return ret;
}
static INLINE int aom_read_bit(aom_reader *r) {
static INLINE int aom_read_bit_(aom_reader *r ACCT_STR_PARAM) {
int ret;
#if CONFIG_ANS
return uabs_read_bit(r); // Non trivial optimization at half probability
ret = uabs_read_bit(r); // Non trivial optimization at half probability
#else
return aom_read(r, 128); // aom_prob_half
ret = aom_read(r, 128, NULL); // aom_prob_half
#endif
#if CONFIG_ACCOUNTING
if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
#endif
return ret;
}
static INLINE int aom_read_literal(aom_reader *r, int bits) {
static INLINE int aom_read_literal_(aom_reader *r, int bits ACCT_STR_PARAM) {
int literal = 0, bit;
for (bit = bits - 1; bit >= 0; bit--) literal |= aom_read_bit(r) << bit;
for (bit = bits - 1; bit >= 0; bit--) literal |= aom_read_bit(r, NULL) << bit;
#if CONFIG_ACCOUNTING
if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
#endif
return literal;
}
static INLINE int aom_read_tree_bits(aom_reader *r, const aom_tree_index *tree,
const aom_prob *probs) {
static INLINE int aom_read_tree_bits_(aom_reader *r, const aom_tree_index *tree,
const aom_prob *probs ACCT_STR_PARAM) {
aom_tree_index i = 0;
while ((i = tree[i + aom_read(r, probs[i >> 1])]) > 0) continue;
while ((i = tree[i + aom_read(r, probs[i >> 1], NULL)]) > 0) continue;
#if CONFIG_ACCOUNTING
if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
#endif
return -i;
}
static INLINE int aom_read_tree(aom_reader *r, const aom_tree_index *tree,
const aom_prob *probs) {
static INLINE int aom_read_tree_(aom_reader *r, const aom_tree_index *tree,
const aom_prob *probs ACCT_STR_PARAM) {
int ret;
#if CONFIG_DAALA_EC
return daala_read_tree_bits(r, tree, probs);
ret = daala_read_tree_bits(r, tree, probs);
#else
return aom_read_tree_bits(r, tree, probs);
ret = aom_read_tree_bits(r, tree, probs, NULL);
#endif
#if CONFIG_ACCOUNTING
if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
#endif
return ret;
}
static INLINE int aom_read_symbol(aom_reader *r, const aom_cdf_prob *cdf,
int nsymbs) {
static INLINE int aom_read_symbol_(aom_reader *r, const aom_cdf_prob *cdf,
int nsymbs ACCT_STR_PARAM) {
int ret;
#if CONFIG_RANS
(void)nsymbs;
return rans_read(r, cdf);
ret = rans_read(r, cdf);
#elif CONFIG_DAALA_EC
return daala_read_symbol(r, cdf, nsymbs);
ret = daala_read_symbol(r, cdf, nsymbs);
#else
(void)r;
(void)cdf;
(void)nsymbs;
assert(0 && "Unsupported bitreader operation");
return -1;
ret = -1;
#endif
#if CONFIG_ACCOUNTING
if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
#endif
return ret;
}
#ifdef __cplusplus
......
......@@ -18,6 +18,9 @@ int aom_daala_reader_init(daala_reader *r, const uint8_t *buffer, int size) {
r->buffer_end = buffer + size;
r->buffer = buffer;
od_ec_dec_init(&r->ec, buffer, size - 1);
#if CONFIG_ACCOUNTING
r->accounting = NULL;
#endif
return 0;
}
......
......@@ -12,8 +12,12 @@
#ifndef AOM_DSP_DAALABOOLREADER_H_
#define AOM_DSP_DAALABOOLREADER_H_
#include "aom/aom_integer.h"
#include "aom_dsp/entdec.h"
#include "aom_dsp/prob.h"
#if CONFIG_ACCOUNTING
#include "av1/common/accounting.h"
#endif
#ifdef __cplusplus
extern "C" {
......@@ -23,6 +27,9 @@ struct daala_reader {
const uint8_t *buffer;
const uint8_t *buffer_end;
od_ec_dec ec;
#if CONFIG_ACCOUNTING
Accounting *accounting;
#endif
};
typedef struct daala_reader daala_reader;
......
......@@ -37,6 +37,9 @@ int aom_dk_reader_init(struct aom_dk_reader *r, const uint8_t *buffer,
r->decrypt_cb = decrypt_cb;
r->decrypt_state = decrypt_state;
aom_dk_reader_fill(r);
#if CONFIG_ACCOUNTING
r->accounting = NULL;
#endif
return aom_dk_read_bit(r) != 0; // marker bit
}
}
......
......@@ -20,6 +20,9 @@
#include "aom/aomdx.h"
#include "aom/aom_integer.h"
#include "aom_dsp/prob.h"
#if CONFIG_ACCOUNTING
#include "av1/common/accounting.h"
#endif
#ifdef __cplusplus
extern "C" {
......@@ -45,6 +48,9 @@ struct aom_dk_reader {
aom_decrypt_cb decrypt_cb;
void *decrypt_state;
uint8_t clear_buffer[sizeof(BD_VALUE) + 1];
#if CONFIG_ACCOUNTING
Accounting *accounting;
#endif
};
int aom_dk_reader_init(struct aom_dk_reader *r, const uint8_t *buffer,
......
......@@ -87,6 +87,10 @@ AV1_COMMON_SRCS-yes += common/od_dering.h
AV1_COMMON_SRCS-yes += common/dering.c
AV1_COMMON_SRCS-yes += common/dering.h
endif
ifeq ($(CONFIG_ACCOUNTING),yes)
AV1_COMMON_SRCS-yes += common/accounting.h
AV1_COMMON_SRCS-yes += common/accounting.c
endif
AV1_COMMON_SRCS-yes += common/odintrin.c
AV1_COMMON_SRCS-yes += common/odintrin.h
......
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aom/aom_integer.h"
#include "./accounting.h"
static int aom_accounting_hash(const char *str) {
uint32_t val;
const unsigned char *ustr;
val = 0;
ustr = (const unsigned char *)str;
/* This is about the worst hash one can design, but it should be good enough
here. */
while (*ustr) val += *ustr++;
return val % AOM_ACCOUNTING_HASH_SIZE;
}
/* Dictionary lookup based on an open-addressing hash table. */
int aom_accounting_dictionary_lookup(Accounting *accounting, const char *str) {
int hash;
int len;
AccountingDictionary *dictionary;
dictionary = &accounting->syms.dictionary;
hash = aom_accounting_hash(str);
while (accounting->hash_dictionary[hash] != -1) {
if (strcmp(dictionary->strs[accounting->hash_dictionary[hash]], str) == 0) {
return accounting->hash_dictionary[hash];
}
hash++;
if (hash == AOM_ACCOUNTING_HASH_SIZE) hash = 0;
}
/* No match found. */
assert(dictionary->num_strs + 1 < MAX_SYMBOL_TYPES);
accounting->hash_dictionary[hash] = dictionary->num_strs;
len = strlen(str);
dictionary->strs[dictionary->num_strs] = malloc(len + 1);
snprintf(dictionary->strs[dictionary->num_strs], len + 1, "%s", str);
dictionary->num_strs++;
return dictionary->num_strs - 1;
}
void aom_accounting_init(Accounting *accounting) {
int i;
accounting->num_syms_allocated = 1000;
accounting->syms.syms =
malloc(sizeof(AccountingSymbol) * accounting->num_syms_allocated);
accounting->syms.dictionary.num_strs = 0;
assert(AOM_ACCOUNTING_HASH_SIZE > 2 * MAX_SYMBOL_TYPES);
for (i = 0; i < AOM_ACCOUNTING_HASH_SIZE; i++)
accounting->hash_dictionary[i] = -1;
aom_accounting_reset(accounting);
}
void aom_accounting_reset(Accounting *accounting) {
accounting->syms.num_syms = 0;
accounting->context.x = -1;
accounting->context.y = -1;
accounting->last_tell_frac = 0;
}
void aom_accounting_clear(Accounting *accounting) {
int i;
AccountingDictionary *dictionary;
free(accounting->syms.syms);
dictionary = &accounting->syms.dictionary;
for (i = 0; i < dictionary->num_strs; i++) {
free(dictionary->strs[i]);
}
}
void aom_accounting_set_context(Accounting *accounting, int16_t x, int16_t y) {
accounting->context.x = x;
accounting->context.y = y;
}
void aom_accounting_record(Accounting *accounting, const char *str,
uint32_t bits) {
AccountingSymbol sym;
// Reuse previous symbol if it has the same context and symbol id.
if (accounting->syms.num_syms) {
AccountingSymbol *last_sym;
last_sym = &accounting->syms.syms[accounting->syms.num_syms - 1];
if (memcmp(&last_sym->context, &accounting->context,
sizeof(AccountingSymbolContext)) == 0) {
uint32_t id;
id = aom_accounting_dictionary_lookup(accounting, str);
if (id == last_sym->id) {
last_sym->bits += bits;
last_sym->samples++;
return;
}
}
}
sym.context = accounting->context;
sym.samples = 1;
sym.bits = bits;
sym.id = aom_accounting_dictionary_lookup(accounting, str);
assert(sym.id <= 255);
if (accounting->syms.num_syms == accounting->num_syms_allocated) {
accounting->num_syms_allocated *= 2;
accounting->syms.syms =
realloc(accounting->syms.syms,
sizeof(AccountingSymbol) * accounting->num_syms_allocated);
assert(accounting->syms.syms != NULL);
}
accounting->syms.syms[accounting->syms.num_syms++] = sym;
}
void aom_accounting_dump(Accounting *accounting) {
int i;
AccountingSymbol *sym;
printf("----- %d -----\n", accounting->syms.num_syms);
for (i = 0; i < accounting->syms.num_syms; i++) {
sym = &accounting->syms.syms[i];
printf("%s x: %d, y: %d bits: %f samples: %d\n",
accounting->syms.dictionary.strs[sym->id], sym->context.x,
sym->context.y, (float)sym->bits / 8.0, sym->samples);
}
}
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef AOM_ACCOUNTING_H_
#define AOM_ACCOUNTING_H_
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#define AOM_ACCOUNTING_HASH_SIZE (1021)
/* Max number of entries for symbol types in the dictionary (increase as
necessary). */
#define MAX_SYMBOL_TYPES (256)
/*The resolution of fractional-precision bit usage measurements, i.e.,
3 => 1/8th bits.*/
#define AOM_ACCT_BITRES (3)
typedef struct {
int16_t x;
int16_t y;
} AccountingSymbolContext;
typedef struct {
AccountingSymbolContext context;
uint32_t id;
/** Number of bits in units of 1/8 bit. */
uint32_t bits;
uint32_t samples;
} AccountingSymbol;
/** Dictionary for translating strings into id. */
typedef struct {
char *(strs[MAX_SYMBOL_TYPES]);
int num_strs;
} AccountingDictionary;
typedef struct {
/** All recorded symbols decoded. */
AccountingSymbol *syms;
/** Number of symbols actually recorded. */
int num_syms;
/** Dictionary for translating strings into id. */
AccountingDictionary dictionary;
} AccountingSymbols;
typedef struct {
AccountingSymbols syms;
/** Size allocated for symbols (not all may be used). */
int num_syms_allocated;
int16_t hash_dictionary[AOM_ACCOUNTING_HASH_SIZE];
AccountingSymbolContext context;
uint32_t last_tell_frac;
} Accounting;
void aom_accounting_init(Accounting *accounting);
void aom_accounting_reset(Accounting *accounting);
void aom_accounting_clear(Accounting *accounting);
void aom_accounting_set_context(Accounting *accounting, int16_t x, int16_t y);
int aom_accounting_dictionary_lookup(Accounting *accounting, const char *str);
void aom_accounting_record(Accounting *accounting, const char *str,
uint32_t bits);
void aom_accounting_dump(Accounting *accounting);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // AOM_ACCOUNTING_H_
......@@ -53,6 +53,7 @@
#include "av1/decoder/dsubexp.h"
#define MAX_AV1_HEADER_SIZE 80
#define ACCT_STR __func__
static int is_compound_reference_allowed(const AV1_COMMON *cm) {
int i;
......@@ -105,8 +106,8 @@ static TX_MODE read_tx_mode(struct aom_read_bit_buffer *rb) {
}
#else
static TX_MODE read_tx_mode(aom_reader *r) {
TX_MODE tx_mode = aom_read_literal(r, 2);
if (tx_mode == ALLOW_32X32) tx_mode += aom_read_bit(r);
TX_MODE tx_mode = aom_read_literal(r, 2, ACCT_STR);
if (tx_mode == ALLOW_32X32) tx_mode += aom_read_bit(r, ACCT_STR);
return tx_mode;
}
#endif
......@@ -116,22 +117,22 @@ static void read_tx_mode_probs(struct tx_probs *tx_probs, aom_reader *r) {
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
for (j = TX_4X4; j < TX_SIZES - 3; ++j)
av1_diff_update_prob(r, &tx_probs->p8x8[i][j]);
av1_diff_update_prob(r, &tx_probs->p8x8[i][j], ACCT_STR);
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
for (j = TX_4X4; j < TX_SIZES - 2; ++j)
av1_diff_update_prob(r, &tx_probs->p16x16[i][j]);
av1_diff_update_prob(r, &tx_probs->p16x16[i][j], ACCT_STR);
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
for (j = TX_4X4; j < TX_SIZES - 1; ++j)
av1_diff_update_prob(r, &tx_probs->p32x32[i][j]);
av1_diff_update_prob(r, &tx_probs->p32x32[i][j], ACCT_STR);
}
static void read_switchable_interp_probs(FRAME_CONTEXT *fc, aom_reader *r) {
int i, j;
for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) {
for (i = 0; i < SWITCHABLE_FILTERS - 1; ++i)
av1_diff_update_prob(r, &fc->switchable_interp_prob[j][i]);
av1_diff_update_prob(r, &fc->switchable_interp_prob[j][i], ACCT_STR);
#if CONFIG_DAALA_EC
av1_tree_to_cdf(av1_switchable_interp_tree, fc->switchable_interp_prob[j],
fc->switchable_interp_cdf[j]);
......@@ -143,18 +144,18 @@ static void read_inter_mode_probs(FRAME_CONTEXT *fc, aom_reader *r) {
int i;
#if CONFIG_REF_MV
for (i = 0; i < NEWMV_MODE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->newmv_prob[i]);
av1_diff_update_prob(r, &fc->newmv_prob[i], ACCT_STR);
for (i = 0; i < ZEROMV_MODE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->zeromv_prob[i]);
av1_diff_update_prob(r, &fc->zeromv_prob[i], ACCT_STR);
for (i = 0; i < REFMV_MODE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->refmv_prob[i]);
av1_diff_update_prob(r, &fc->refmv_prob[i], ACCT_STR);
for (i = 0; i < DRL_MODE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->drl_prob[i]);
av1_diff_update_prob(r, &fc->drl_prob[i], ACCT_STR);
#else
int j;
for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
for (j = 0; j < INTER_MODES - 1; ++j)
av1_diff_update_prob(r, &fc->inter_mode_probs[i][j]);
av1_diff_update_prob(r, &fc->inter_mode_probs[i][j], ACCT_STR);
#endif
}
......@@ -173,8 +174,9 @@ static REFERENCE_MODE read_frame_reference_mode(
static REFERENCE_MODE read_frame_reference_mode(const AV1_COMMON *cm,
aom_reader *r) {
if (is_compound_reference_allowed(cm)) {
return aom_read_bit(r)
? (aom_read_bit(r) ? REFERENCE_MODE_SELECT : COMPOUND_REFERENCE)
return aom_read_bit(r, ACCT_STR)
? (aom_read_bit(r, ACCT_STR) ? REFERENCE_MODE_SELECT
: COMPOUND_REFERENCE)
: SINGLE_REFERENCE;
} else {
return SINGLE_REFERENCE;
......@@ -188,24 +190,23 @@ static void read_frame_reference_mode_probs(AV1_COMMON *cm, aom_reader *r) {
if (cm->reference_mode == REFERENCE_MODE_SELECT)
for (i = 0; i < COMP_INTER_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->comp_inter_prob[i]);
av1_diff_update_prob(r, &fc->comp_inter_prob[i], ACCT_STR);
if (cm->reference_mode != COMPOUND_REFERENCE)
for (i = 0; i < REF_CONTEXTS; ++i)
for (j = 0; j < (SINGLE_REFS - 1); ++j)
av1_diff_update_prob(r, &fc->single_ref_prob[i][j]);
av1_diff_update_prob(r, &fc->single_ref_prob[i][j], ACCT_STR);
if (cm->reference_mode != SINGLE_REFERENCE)
#if CONFIG_EXT_REFS
for (i = 0; i < REF_CONTEXTS; ++i) {
for (j = 0; j < (FWD_REFS - 1); ++j)
av1_diff_update_prob(r, &fc->comp_fwdref_prob[i][j]);
for (j = 0; j < (BWD_REFS - 1); ++j)
av1_diff_update_prob(r, &fc->comp_bwdref_prob[i][j]);
av1_diff_update_prob(r, &fc->comp_fwdref_prob[i][j], ACCT_STR);
for (j = 0; j < (BWD_REFS - 1); ++j) (r, &fc->comp_bwdref_prob[i][j]);
}
#else
for (i = 0; i < REF_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->comp_ref_prob[i]);
av1_diff_update_prob(r, &fc->comp_ref_prob[i], ACCT_STR);
#endif // CONFIG_EXT_REFS
}
......@@ -213,9 +214,10 @@ static void update_mv_probs(aom_prob *p, int n, aom_reader *r) {
int i;
for (i = 0; i < n; ++i)
#if CONFIG_MISC_FIXES
av1_diff_update_prob(r, &p[i]);
av1_diff_update_prob(r, &p[i], ACCT_STR);
#else
if (aom_read(r, MV_UPDATE_PROB)) p[i] = (aom_read_literal(r, 7) << 1) | 1;
if (aom_read(r, MV_UPDATE_PROB, ACCT_STR))
p[i] = (aom_read_literal(r, 7, ACCT_STR) << 1) | 1;
#endif
}
......@@ -469,6 +471,9 @@ static void decode_block(AV1Decoder *const pbi, MACROBLOCKD *const xd,
const int x_mis = AOMMIN(bw, cm->mi_cols - mi_col);
const int y_mis = AOMMIN(bh, cm->mi_rows - mi_row);
#if CONFIG_ACCOUNTING
aom_accounting_set_context(&pbi->accounting, mi_col, mi_row);
#endif
MB_MODE_INFO *mbmi = set_offsets(cm, xd, bsize, mi_row, mi_col, bw, bh, x_mis,
y_mis, bwl, bhl);
......@@ -599,14 +604,14 @@ static PARTITION_TYPE read_partition(AV1_COMMON *cm, MACROBLOCKD *xd,
if (has_rows && has_cols)
#if CONFIG_DAALA_EC
p = (PARTITION_TYPE)aom_read_symbol(r, cm->fc->partition_cdf[ctx],
PARTITION_TYPES);
PARTITION_TYPES, ACCT_STR);
#else
p = (PARTITION_TYPE)aom_read_tree(r, av1_partition_tree, probs);
p = (PARTITION_TYPE)aom_read_tree(r, av1_partition_tree, probs, ACCT_STR);
#endif
else if (!has_rows && has_cols)
p = aom_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ;
p = aom_read(r, probs[1], ACCT_STR) ? PARTITION_SPLIT : PARTITION_HORZ;
else if (has_rows && !has_cols)
p = aom_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT;
p = aom_read(r, probs[2], ACCT_STR) ? PARTITION_SPLIT : PARTITION_VERT;
else
p = PARTITION_SPLIT;
......@@ -705,13 +710,13 @@ static void read_coef_probs_common(av1_coeff_probs_model *coef_probs,
aom_reader *r) {
int i, j, k, l, m;
if (aom_read_bit(r))
if (aom_read_bit(r, ACCT_STR))
for (i = 0; i < PLANE_TYPES; ++i)
for (j = 0; j < REF_TYPES; ++j)
for (k = 0; k < COEF_BANDS; ++k)
for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l)
for (m = 0; m < UNCONSTRAINED_NODES; ++m)
av1_diff_update_prob(r, &coef_probs[i][j][k][l][m]);
av1_diff_update_prob(r, &coef_probs[i][j][k][l][m], ACCT_STR);
}
static void read_coef_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode, aom_reader *r) {
......@@ -1266,7 +1271,9 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data,
aom_memalign(32, tile_cols * tile_rows * (sizeof(*pbi->tile_data))));
pbi->total_tiles = tile_rows * tile_cols;
}
#if CONFIG_ACCOUNTING
aom_accounting_reset(&pbi->accounting);
#endif
// Load all tile information into tile_data.
for (tile_row = 0; tile_row < tile_rows; ++tile_row) {
for (tile_col = 0; tile_col < tile_cols; ++tile_col) {
......@@ -1284,6 +1291,9 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data,
setup_token_decoder(buf->data, data_end, buf->size, &cm->error,
&tile_data->bit_reader, pbi->decrypt_cb,
pbi->decrypt_state);
#if CONFIG_ACCOUNTING
tile_data->bit_reader.accounting = &pbi->accounting;
#endif
av1_init_macroblockd(cm, &tile_data->xd, tile_data->dqcoeff);
#if CONFIG_PALETTE
tile_data->xd.plane[0].color_index_map = tile_data->color_index_map[0];
......@@ -1301,6 +1311,10 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data,
const int col =
pbi