#endif
#include "aom_dsp/entdec.h"
-#if OD_ACCOUNTING
-#include "./accounting.h"
-#endif
/*A range decoder.
This is an entropy decoder based upon \cite{Mar79}, which is itself a
URL="http://researchcommons.waikato.ac.nz/bitstream/handle/10289/78/content.pdf"
}*/
-#if OD_ACCOUNTING
-#define od_ec_dec_normalize(dec, dif, rng, ret, str) \
- od_ec_dec_normalize_(dec, dif, rng, ret, str)
-static void od_process_accounting(od_ec_dec *dec, char *str) {
- if (dec->acct != NULL) {
- uint32_t tell;
- tell = od_ec_dec_tell_frac(dec);
- OD_ASSERT(tell >= dec->acct->last_tell);
- od_accounting_record(dec->acct, str, tell - dec->acct->last_tell);
- dec->acct->last_tell = tell;
- }
-}
-#else
-#define od_ec_dec_normalize(dec, dif, rng, ret, str) \
- od_ec_dec_normalize_(dec, dif, rng, ret)
-#endif
-
/*This is meant to be a large, positive constant that can still be efficiently
loaded as an immediate (on platforms like ARM, for example).
Even relatively modest values like 100 would work fine.*/
ret: The value to return.
Return: ret.
This allows the compiler to jump to this function via a tail-call.*/
-static int od_ec_dec_normalize_(od_ec_dec *dec, od_ec_window dif, unsigned rng,
- int ret OD_ACC_STR) {
+static int od_ec_dec_normalize(od_ec_dec *dec, od_ec_window dif, unsigned rng,
+ int ret) {
int d;
OD_ASSERT(rng <= 65535U);
d = 16 - OD_ILOG_NZ(rng);
dec->dif = dif << d;
dec->rng = rng << d;
if (dec->cnt < 0) od_ec_dec_refill(dec);
-#if OD_ACCOUNTING
- od_process_accounting(dec, acc_str);
-#endif
return ret;
}
dec->cnt = -15;
dec->error = 0;
od_ec_dec_refill(dec);
-#if OD_ACCOUNTING
- dec->acct = NULL;
-#endif
}
/*Decode a bit that has an fz/ft probability of being a zero.
ft: The total probability.
This must be at least 16384 and no more than 32768.
Return: The value decoded (0 or 1).*/
-int od_ec_decode_bool_(od_ec_dec *dec, unsigned fz, unsigned ft OD_ACC_STR) {
+int od_ec_decode_bool(od_ec_dec *dec, unsigned fz, unsigned ft) {
od_ec_window dif;
od_ec_window vw;
unsigned r;
ret = dif >= vw;
if (ret) dif -= vw;
r = ret ? r - v : v;
- return od_ec_dec_normalize(dec, dif, r, ret, acc_str);
+ return od_ec_dec_normalize(dec, dif, r, ret);
}
/*Decode a bit that has an fz probability of being a zero in Q15.
or _dyadic() functions instead.
fz: The probability that the bit is zero, scaled by 32768.
Return: The value decoded (0 or 1).*/
-int od_ec_decode_bool_q15_(od_ec_dec *dec, unsigned fz OD_ACC_STR) {
+int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned fz) {
od_ec_window dif;
od_ec_window vw;
unsigned r;
ret = dif >= vw;
if (ret) dif -= vw;
r = ret ? r - v : v;
- return od_ec_dec_normalize(dec, dif, r, ret, acc_str);
+ return od_ec_dec_normalize(dec, dif, r, ret);
}
/*Decodes a symbol given a cumulative distribution function (CDF) table.
nsyms: The number of symbols in the alphabet.
This should be at most 16.
Return: The decoded symbol s.*/
-int od_ec_decode_cdf_(od_ec_dec *dec, const uint16_t *cdf,
- int nsyms OD_ACC_STR) {
+int od_ec_decode_cdf(od_ec_dec *dec, const uint16_t *cdf, int nsyms) {
od_ec_window dif;
unsigned r;
unsigned c;
#endif
r = v - u;
dif -= (od_ec_window)u << (OD_EC_WINDOW_SIZE - 16);
- return od_ec_dec_normalize(dec, dif, r, ret, acc_str);
+ return od_ec_dec_normalize(dec, dif, r, ret);
}
/*Decodes a symbol given a cumulative distribution function (CDF) table.
nsyms: The number of symbols in the alphabet.
This should be at most 16.
Return: The decoded symbol s.*/
-int od_ec_decode_cdf_unscaled_(od_ec_dec *dec, const uint16_t *cdf,
- int nsyms OD_ACC_STR) {
+int od_ec_decode_cdf_unscaled(od_ec_dec *dec, const uint16_t *cdf, int nsyms) {
od_ec_window dif;
unsigned r;
unsigned c;
#endif
r = v - u;
dif -= (od_ec_window)u << (OD_EC_WINDOW_SIZE - 16);
- return od_ec_dec_normalize(dec, dif, r, ret, acc_str);
+ return od_ec_dec_normalize(dec, dif, r, ret);
}
/*Decodes a symbol given a cumulative distribution function (CDF) table that
ftb: The number of bits of precision in the cumulative distribution.
This must be no more than 15.
Return: The decoded symbol s.*/
-int od_ec_decode_cdf_unscaled_dyadic_(od_ec_dec *dec, const uint16_t *cdf,
- int nsyms, unsigned ftb OD_ACC_STR) {
+int od_ec_decode_cdf_unscaled_dyadic(od_ec_dec *dec, const uint16_t *cdf,
+ int nsyms, unsigned ftb) {
od_ec_window dif;
unsigned r;
unsigned c;
OD_ASSERT(v <= r);
r = v - u;
dif -= (od_ec_window)u << (OD_EC_WINDOW_SIZE - 16);
- return od_ec_dec_normalize(dec, dif, r, ret, acc_str);
+ return od_ec_dec_normalize(dec, dif, r, ret);
}
/*Decodes a symbol given a cumulative distribution function (CDF) table in Q15.
nsyms: The number of symbols in the alphabet.
This should be at most 16.
Return: The decoded symbol s.*/
-int od_ec_decode_cdf_q15_(od_ec_dec *dec, const uint16_t *cdf,
- int nsyms OD_ACC_STR) {
- return od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, 15, acc_str);
+int od_ec_decode_cdf_q15(od_ec_dec *dec, const uint16_t *cdf, int nsyms) {
+ return od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, 15);
}
/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream.
ft: The number of integers that can be decoded (one more than the max).
This must be at least 2, and no more than 2**29.
Return: The decoded bits.*/
-uint32_t od_ec_dec_uint_(od_ec_dec *dec, uint32_t ft OD_ACC_STR) {
+uint32_t od_ec_dec_uint(od_ec_dec *dec, uint32_t ft) {
OD_ASSERT(ft >= 2);
OD_ASSERT(ft <= (uint32_t)1 << (25 + OD_EC_UINT_BITS));
if (ft > 1U << OD_EC_UINT_BITS) {
ft--;
ftb = OD_ILOG_NZ(ft) - OD_EC_UINT_BITS;
ft1 = (int)(ft >> ftb) + 1;
- t = od_ec_decode_cdf_q15(dec, OD_UNIFORM_CDF_Q15(ft1), ft1, acc_str);
- t = t << ftb | od_ec_dec_bits(dec, ftb, acc_str);
+ t = od_ec_decode_cdf_q15(dec, OD_UNIFORM_CDF_Q15(ft1), ft1);
+ t = t << ftb | od_ec_dec_bits(dec, ftb);
if (t <= ft) return t;
dec->error = 1;
return ft;
}
- return od_ec_decode_cdf_q15(dec, OD_UNIFORM_CDF_Q15(ft), (int)ft, acc_str);
+ return od_ec_decode_cdf_q15(dec, OD_UNIFORM_CDF_Q15(ft), (int)ft);
}
/*Extracts a sequence of raw bits from the stream.
ftb: The number of bits to extract.
This must be between 0 and 25, inclusive.
Return: The decoded bits.*/
-uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb OD_ACC_STR) {
+uint32_t od_ec_dec_bits(od_ec_dec *dec, unsigned ftb) {
od_ec_window window;
int available;
uint32_t ret;
available -= ftb;
dec->end_window = window;
dec->nend_bits = available;
-#if OD_ACCOUNTING
- od_process_accounting(dec, acc_str);
-#endif
return ret;
}
#define _entdec_H (1)
#include <limits.h>
#include "aom_dsp/entcode.h"
-#if OD_ACCOUNTING
-#include "./accounting.h"
-#endif
#ifdef __cplusplus
extern "C" {
typedef struct od_ec_dec od_ec_dec;
-#if OD_ACCOUNTING
-#define OD_ACC_STR , char *acc_str
-#define od_ec_decode_bool(dec, fz, ft, str) od_ec_decode_bool_(dec, fz, ft, str)
-#define od_ec_decode_bool_q15(dec, fz, str) od_ec_decode_bool_q15_(dec, fz, str)
-#define od_ec_decode_cdf(dec, cdf, nsyms, str) \
- od_ec_decode_cdf_(dec, cdf, nsyms, str)
-#define od_ec_decode_cdf_q15(dec, cdf, nsyms, str) \
- od_ec_decode_cdf_q15_(dec, cdf, nsyms, str)
-#define od_ec_decode_cdf_unscaled(dec, cdf, nsyms, str) \
- od_ec_decode_cdf_unscaled_(dec, cdf, nsyms, str)
-#define od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, ftb, str) \
- od_ec_decode_cdf_unscaled_dyadic_(dec, cdf, nsyms, ftb, str)
-#define od_ec_dec_uint(dec, ft, str) od_ec_dec_uint_(dec, ft, str)
-#define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb, str)
-#else
-#define OD_ACC_STR
-#define od_ec_decode_bool(dec, fz, ft, str) od_ec_decode_bool_(dec, fz, ft)
-#define od_ec_decode_bool_q15(dec, fz, str) od_ec_decode_bool_q15_(dec, fz)
-#define od_ec_decode_cdf(dec, cdf, nsyms, str) \
- od_ec_decode_cdf_(dec, cdf, nsyms)
-#define od_ec_decode_cdf_q15(dec, cdf, nsyms, str) \
- od_ec_decode_cdf_q15_(dec, cdf, nsyms)
-#define od_ec_decode_cdf_unscaled(dec, cdf, nsyms, str) \
- od_ec_decode_cdf_unscaled_(dec, cdf, nsyms)
-#define od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, ftb, str) \
- od_ec_decode_cdf_unscaled_dyadic_(dec, cdf, nsyms, ftb)
-#define od_ec_dec_uint(dec, ft, str) od_ec_dec_uint_(dec, ft)
-#define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb)
-#endif
-
/*The entropy decoder context.*/
struct od_ec_dec {
/*The start of the current input buffer.*/
int16_t cnt;
/*Nonzero if an error occurred.*/
int error;
-#if OD_ACCOUNTING
- od_accounting_internal *acct;
-#endif
};
/*See entdec.c for further documentation.*/
void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf, uint32_t storage)
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
-OD_WARN_UNUSED_RESULT int od_ec_decode_bool_(od_ec_dec *dec, unsigned fz,
- unsigned ft OD_ACC_STR)
+OD_WARN_UNUSED_RESULT int od_ec_decode_bool(od_ec_dec *dec, unsigned fz,
+ unsigned ft) OD_ARG_NONNULL(1);
+OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned fz)
OD_ARG_NONNULL(1);
-OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15_(od_ec_dec *dec,
- unsigned fz OD_ACC_STR)
- OD_ARG_NONNULL(1);
-OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_(od_ec_dec *dec, const uint16_t *cdf,
- int nsyms OD_ACC_STR)
- OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
-OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15_(od_ec_dec *dec,
- const uint16_t *cdf,
- int nsyms OD_ACC_STR)
- OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
-OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled_(od_ec_dec *dec,
- const uint16_t *cdf,
- int nsyms OD_ACC_STR)
+OD_WARN_UNUSED_RESULT int od_ec_decode_cdf(od_ec_dec *dec, const uint16_t *cdf,
+ int nsyms) OD_ARG_NONNULL(1)
+ OD_ARG_NONNULL(2);
+OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15(od_ec_dec *dec,
+ const uint16_t *cdf, int nsyms)
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
-OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled_dyadic_(
- od_ec_dec *dec, const uint16_t *cdf, int nsyms, unsigned _ftb OD_ACC_STR)
+OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled(od_ec_dec *dec,
+ const uint16_t *cdf,
+ int nsyms) OD_ARG_NONNULL(1)
+ OD_ARG_NONNULL(2);
+OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled_dyadic(od_ec_dec *dec,
+ const uint16_t *cdf,
+ int nsyms,
+ unsigned _ftb)
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
-OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_uint_(od_ec_dec *dec,
- uint32_t ft OD_ACC_STR)
+OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_uint(od_ec_dec *dec, uint32_t ft)
OD_ARG_NONNULL(1);
-OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec,
- unsigned ftb OD_ACC_STR)
+OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits(od_ec_dec *dec, unsigned ftb)
OD_ARG_NONNULL(1);
OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec)