Commit e23d5c30 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Make the binary codes library accounting enabled

Change-Id: Icde963dfa58ebea490dd1e4d125cd9ca5d27e7db
parent 4581ee08
......@@ -9,7 +9,7 @@
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include "aom_dsp/bitreader.h"
#include "aom_dsp/binary_codes_reader.h"
#include "av1/common/common.h"
......@@ -33,26 +33,28 @@ static uint16_t inv_recenter_finite_nonneg(uint16_t n, uint16_t r, uint16_t v) {
}
}
int16_t aom_read_primitive_symmetric(aom_reader *r, unsigned int mag_bits) {
if (aom_read_bit(r, NULL)) {
int s = aom_read_bit(r, NULL);
int16_t x = aom_read_literal(r, mag_bits, NULL) + 1;
int16_t aom_read_primitive_symmetric_(aom_reader *r,
unsigned int mag_bits ACCT_STR_PARAM) {
if (aom_read_bit(r, ACCT_STR_NAME)) {
int s = aom_read_bit(r, ACCT_STR_NAME);
int16_t x = aom_read_literal(r, mag_bits, ACCT_STR_NAME) + 1;
return (s > 0 ? -x : x);
} else {
return 0;
}
}
uint16_t aom_read_primitive_quniform(aom_reader *r, uint16_t n) {
uint16_t aom_read_primitive_quniform_(aom_reader *r,
uint16_t n ACCT_STR_PARAM) {
if (n <= 1) return 0;
const int l = get_msb(n - 1) + 1;
const int m = (1 << l) - n;
const int v = aom_read_literal(r, l - 1, NULL);
return v < m ? v : (v << 1) - m + aom_read_bit(r, NULL);
const int v = aom_read_literal(r, l - 1, ACCT_STR_NAME);
return v < m ? v : (v << 1) - m + aom_read_bit(r, ACCT_STR_NAME);
}
uint16_t aom_read_primitive_refbilevel(aom_reader *r, uint16_t n, uint16_t p,
uint16_t ref) {
uint16_t aom_read_primitive_refbilevel_(aom_reader *r, uint16_t n, uint16_t p,
uint16_t ref ACCT_STR_PARAM) {
if (n <= 1) return 0;
assert(p > 0 && p <= n);
assert(ref < n);
......@@ -64,10 +66,10 @@ uint16_t aom_read_primitive_refbilevel(aom_reader *r, uint16_t n, uint16_t p,
lolimit = n - p;
}
int v;
if (aom_read_bit(r, NULL)) {
v = aom_read_primitive_quniform(r, p) + lolimit;
if (aom_read_bit(r, ACCT_STR_NAME)) {
v = aom_read_primitive_quniform(r, p, ACCT_STR_NAME) + lolimit;
} else {
v = aom_read_primitive_quniform(r, n - p);
v = aom_read_primitive_quniform(r, n - p, ACCT_STR_NAME);
if (v >= lolimit) v += p;
}
return v;
......@@ -75,7 +77,8 @@ uint16_t aom_read_primitive_refbilevel(aom_reader *r, uint16_t n, uint16_t p,
// Decode finite subexponential code that for a symbol v in [0, n-1] with
// parameter k
uint16_t aom_read_primitive_subexpfin(aom_reader *r, uint16_t n, uint16_t k) {
uint16_t aom_read_primitive_subexpfin_(aom_reader *r, uint16_t n,
uint16_t k ACCT_STR_PARAM) {
int i = 0;
int mk = 0;
uint16_t v;
......@@ -83,14 +86,14 @@ uint16_t aom_read_primitive_subexpfin(aom_reader *r, uint16_t n, uint16_t k) {
int b = (i ? k + i - 1 : k);
int a = (1 << b);
if (n <= mk + 3 * a) {
v = aom_read_primitive_quniform(r, n - mk) + mk;
v = aom_read_primitive_quniform(r, n - mk, ACCT_STR_NAME) + mk;
break;
} else {
if (aom_read_bit(r, NULL)) {
if (aom_read_bit(r, ACCT_STR_NAME)) {
i = i + 1;
mk += a;
} else {
v = aom_read_literal(r, b, NULL) + mk;
v = aom_read_literal(r, b, ACCT_STR_NAME) + mk;
break;
}
}
......@@ -101,17 +104,19 @@ uint16_t aom_read_primitive_subexpfin(aom_reader *r, uint16_t n, uint16_t k) {
// Decode finite subexponential code that for a symbol v in [0, n-1] with
// parameter k
// based on a reference ref also in [0, n-1].
uint16_t aom_read_primitive_refsubexpfin(aom_reader *r, uint16_t n, uint16_t k,
uint16_t ref) {
return inv_recenter_finite_nonneg(n, ref,
aom_read_primitive_subexpfin(r, n, k));
uint16_t aom_read_primitive_refsubexpfin_(aom_reader *r, uint16_t n, uint16_t k,
uint16_t ref ACCT_STR_PARAM) {
return inv_recenter_finite_nonneg(
n, ref, aom_read_primitive_subexpfin(r, n, k, ACCT_STR_NAME));
}
// Decode finite subexponential code that for a symbol v in [-(n-1), n-1] with
// parameter k based on a reference ref also in [-(n-1), n-1].
int16_t aom_read_signed_primitive_refsubexpfin(aom_reader *r, uint16_t n,
uint16_t k, int16_t ref) {
int16_t aom_read_signed_primitive_refsubexpfin_(aom_reader *r, uint16_t n,
uint16_t k,
int16_t ref ACCT_STR_PARAM) {
ref += n - 1;
const uint16_t scaled_n = (n << 1) - 1;
return aom_read_primitive_refsubexpfin(r, scaled_n, k, ref) - n + 1;
return aom_read_primitive_refsubexpfin(r, scaled_n, k, ref, ACCT_STR_NAME) -
n + 1;
}
......@@ -21,16 +21,32 @@ extern "C" {
#include "aom/aom_integer.h"
#include "aom_dsp/bitreader.h"
int16_t aom_read_primitive_symmetric(aom_reader *r, unsigned int mag_bits);
#define aom_read_primitive_symmetric(r, n, ACCT_STR_NAME) \
aom_read_primitive_symmetric_(r, n ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_primitive_quniform(r, n, ACCT_STR_NAME) \
aom_read_primitive_quniform_(r, n ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_primitive_refbilevel(r, n, p, ref, ACCT_STR_NAME) \
aom_read_primitive_refbilevel_(r, n, p, ref ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_primitive_subexpfin(r, n, k, ACCT_STR_NAME) \
aom_read_primitive_subexpfin_(r, n, k ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_primitive_refsubexpfin(r, n, k, ref, ACCT_STR_NAME) \
aom_read_primitive_refsubexpfin_(r, n, k, ref ACCT_STR_ARG(ACCT_STR_NAME))
#define aom_read_signed_primitive_refsubexpfin(r, n, k, ref, ACCT_STR_NAME) \
aom_read_signed_primitive_refsubexpfin_(r, n, k, \
ref ACCT_STR_ARG(ACCT_STR_NAME))
uint16_t aom_read_primitive_quniform(aom_reader *r, uint16_t n);
uint16_t aom_read_primitive_refbilevel(aom_reader *r, uint16_t n, uint16_t p,
uint16_t ref);
uint16_t aom_read_primitive_subexpfin(aom_reader *r, uint16_t n, uint16_t k);
uint16_t aom_read_primitive_refsubexpfin(aom_reader *r, uint16_t n, uint16_t k,
uint16_t ref);
int16_t aom_read_signed_primitive_refsubexpfin(aom_reader *r, uint16_t n,
uint16_t k, int16_t ref);
int16_t aom_read_primitive_symmetric_(aom_reader *r,
unsigned int mag_bits ACCT_STR_PARAM);
uint16_t aom_read_primitive_quniform_(aom_reader *r, uint16_t n ACCT_STR_PARAM);
uint16_t aom_read_primitive_refbilevel_(aom_reader *r, uint16_t n, uint16_t p,
uint16_t ref ACCT_STR_PARAM);
uint16_t aom_read_primitive_subexpfin_(aom_reader *r, uint16_t n,
uint16_t k ACCT_STR_PARAM);
uint16_t aom_read_primitive_refsubexpfin_(aom_reader *r, uint16_t n, uint16_t k,
uint16_t ref ACCT_STR_PARAM);
int16_t aom_read_signed_primitive_refsubexpfin_(aom_reader *r, uint16_t n,
uint16_t k,
int16_t ref ACCT_STR_PARAM);
#ifdef __cplusplus
} // extern "C"
#endif
......
......@@ -2499,19 +2499,19 @@ static void read_wiener_filter(WienerInfo *wiener_info,
aom_read_primitive_refsubexpfin(
rb, WIENER_FILT_TAP0_MAXV - WIENER_FILT_TAP0_MINV + 1,
WIENER_FILT_TAP0_SUBEXP_K,
ref_wiener_info->vfilter[0] - WIENER_FILT_TAP0_MINV) +
ref_wiener_info->vfilter[0] - WIENER_FILT_TAP0_MINV, ACCT_STR) +
WIENER_FILT_TAP0_MINV;
wiener_info->vfilter[1] = wiener_info->vfilter[WIENER_WIN - 2] =
aom_read_primitive_refsubexpfin(
rb, WIENER_FILT_TAP1_MAXV - WIENER_FILT_TAP1_MINV + 1,
WIENER_FILT_TAP1_SUBEXP_K,
ref_wiener_info->vfilter[1] - WIENER_FILT_TAP1_MINV) +
ref_wiener_info->vfilter[1] - WIENER_FILT_TAP1_MINV, ACCT_STR) +
WIENER_FILT_TAP1_MINV;
wiener_info->vfilter[2] = wiener_info->vfilter[WIENER_WIN - 3] =
aom_read_primitive_refsubexpfin(
rb, WIENER_FILT_TAP2_MAXV - WIENER_FILT_TAP2_MINV + 1,
WIENER_FILT_TAP2_SUBEXP_K,
ref_wiener_info->vfilter[2] - WIENER_FILT_TAP2_MINV) +
ref_wiener_info->vfilter[2] - WIENER_FILT_TAP2_MINV, ACCT_STR) +
WIENER_FILT_TAP2_MINV;
// The central element has an implicit +WIENER_FILT_STEP
wiener_info->vfilter[WIENER_HALFWIN] =
......@@ -2522,19 +2522,19 @@ static void read_wiener_filter(WienerInfo *wiener_info,
aom_read_primitive_refsubexpfin(
rb, WIENER_FILT_TAP0_MAXV - WIENER_FILT_TAP0_MINV + 1,
WIENER_FILT_TAP0_SUBEXP_K,
ref_wiener_info->hfilter[0] - WIENER_FILT_TAP0_MINV) +
ref_wiener_info->hfilter[0] - WIENER_FILT_TAP0_MINV, ACCT_STR) +
WIENER_FILT_TAP0_MINV;
wiener_info->hfilter[1] = wiener_info->hfilter[WIENER_WIN - 2] =
aom_read_primitive_refsubexpfin(
rb, WIENER_FILT_TAP1_MAXV - WIENER_FILT_TAP1_MINV + 1,
WIENER_FILT_TAP1_SUBEXP_K,
ref_wiener_info->hfilter[1] - WIENER_FILT_TAP1_MINV) +
ref_wiener_info->hfilter[1] - WIENER_FILT_TAP1_MINV, ACCT_STR) +
WIENER_FILT_TAP1_MINV;
wiener_info->hfilter[2] = wiener_info->hfilter[WIENER_WIN - 3] =
aom_read_primitive_refsubexpfin(
rb, WIENER_FILT_TAP2_MAXV - WIENER_FILT_TAP2_MINV + 1,
WIENER_FILT_TAP2_SUBEXP_K,
ref_wiener_info->hfilter[2] - WIENER_FILT_TAP2_MINV) +
ref_wiener_info->hfilter[2] - WIENER_FILT_TAP2_MINV, ACCT_STR) +
WIENER_FILT_TAP2_MINV;
// The central element has an implicit +WIENER_FILT_STEP
wiener_info->hfilter[WIENER_HALFWIN] =
......@@ -2549,12 +2549,12 @@ static void read_sgrproj_filter(SgrprojInfo *sgrproj_info,
sgrproj_info->xqd[0] =
aom_read_primitive_refsubexpfin(
rb, SGRPROJ_PRJ_MAX0 - SGRPROJ_PRJ_MIN0 + 1, SGRPROJ_PRJ_SUBEXP_K,
ref_sgrproj_info->xqd[0] - SGRPROJ_PRJ_MIN0) +
ref_sgrproj_info->xqd[0] - SGRPROJ_PRJ_MIN0, ACCT_STR) +
SGRPROJ_PRJ_MIN0;
sgrproj_info->xqd[1] =
aom_read_primitive_refsubexpfin(
rb, SGRPROJ_PRJ_MAX1 - SGRPROJ_PRJ_MIN1 + 1, SGRPROJ_PRJ_SUBEXP_K,
ref_sgrproj_info->xqd[1] - SGRPROJ_PRJ_MIN1) +
ref_sgrproj_info->xqd[1] - SGRPROJ_PRJ_MIN1, ACCT_STR) +
SGRPROJ_PRJ_MIN1;
memcpy(ref_sgrproj_info, sgrproj_info, sizeof(*sgrproj_info));
}
......@@ -4469,37 +4469,41 @@ static void read_global_motion_params(WarpedMotionParams *params,
params->wmmat[6] =
aom_read_signed_primitive_refsubexpfin(
r, GM_ROW3HOMO_MAX + 1, SUBEXPFIN_K,
(ref_params->wmmat[6] >> GM_ROW3HOMO_PREC_DIFF)) *
(ref_params->wmmat[6] >> GM_ROW3HOMO_PREC_DIFF), ACCT_STR) *
GM_ROW3HOMO_DECODE_FACTOR;
if (type != VERTRAPEZOID)
params->wmmat[7] =
aom_read_signed_primitive_refsubexpfin(
r, GM_ROW3HOMO_MAX + 1, SUBEXPFIN_K,
(ref_params->wmmat[7] >> GM_ROW3HOMO_PREC_DIFF)) *
(ref_params->wmmat[7] >> GM_ROW3HOMO_PREC_DIFF), ACCT_STR) *
GM_ROW3HOMO_DECODE_FACTOR;
case AFFINE:
case ROTZOOM:
params->wmmat[2] = aom_read_signed_primitive_refsubexpfin(
r, GM_ALPHA_MAX + 1, SUBEXPFIN_K,
(ref_params->wmmat[2] >> GM_ALPHA_PREC_DIFF) -
(1 << GM_ALPHA_PREC_BITS)) *
(1 << GM_ALPHA_PREC_BITS),
ACCT_STR) *
GM_ALPHA_DECODE_FACTOR +
(1 << WARPEDMODEL_PREC_BITS);
if (type != VERTRAPEZOID)
params->wmmat[3] = aom_read_signed_primitive_refsubexpfin(
r, GM_ALPHA_MAX + 1, SUBEXPFIN_K,
(ref_params->wmmat[3] >> GM_ALPHA_PREC_DIFF)) *
GM_ALPHA_DECODE_FACTOR;
params->wmmat[3] =
aom_read_signed_primitive_refsubexpfin(
r, GM_ALPHA_MAX + 1, SUBEXPFIN_K,
(ref_params->wmmat[3] >> GM_ALPHA_PREC_DIFF), ACCT_STR) *
GM_ALPHA_DECODE_FACTOR;
if (type >= AFFINE) {
if (type != HORTRAPEZOID)
params->wmmat[4] = aom_read_signed_primitive_refsubexpfin(
r, GM_ALPHA_MAX + 1, SUBEXPFIN_K,
(ref_params->wmmat[4] >> GM_ALPHA_PREC_DIFF)) *
GM_ALPHA_DECODE_FACTOR;
params->wmmat[4] =
aom_read_signed_primitive_refsubexpfin(
r, GM_ALPHA_MAX + 1, SUBEXPFIN_K,
(ref_params->wmmat[4] >> GM_ALPHA_PREC_DIFF), ACCT_STR) *
GM_ALPHA_DECODE_FACTOR;
params->wmmat[5] = aom_read_signed_primitive_refsubexpfin(
r, GM_ALPHA_MAX + 1, SUBEXPFIN_K,
(ref_params->wmmat[5] >> GM_ALPHA_PREC_DIFF) -
(1 << GM_ALPHA_PREC_BITS)) *
(1 << GM_ALPHA_PREC_BITS),
ACCT_STR) *
GM_ALPHA_DECODE_FACTOR +
(1 << WARPEDMODEL_PREC_BITS);
} else {
......@@ -4516,14 +4520,16 @@ static void read_global_motion_params(WarpedMotionParams *params,
trans_prec_diff = (type == TRANSLATION)
? GM_TRANS_ONLY_PREC_DIFF + !allow_hp
: GM_TRANS_PREC_DIFF;
params->wmmat[0] = aom_read_signed_primitive_refsubexpfin(
r, (1 << trans_bits) + 1, SUBEXPFIN_K,
(ref_params->wmmat[0] >> trans_prec_diff)) *
trans_dec_factor;
params->wmmat[1] = aom_read_signed_primitive_refsubexpfin(
r, (1 << trans_bits) + 1, SUBEXPFIN_K,
(ref_params->wmmat[1] >> trans_prec_diff)) *
trans_dec_factor;
params->wmmat[0] =
aom_read_signed_primitive_refsubexpfin(
r, (1 << trans_bits) + 1, SUBEXPFIN_K,
(ref_params->wmmat[0] >> trans_prec_diff), ACCT_STR) *
trans_dec_factor;
params->wmmat[1] =
aom_read_signed_primitive_refsubexpfin(
r, (1 << trans_bits) + 1, SUBEXPFIN_K,
(ref_params->wmmat[1] >> trans_prec_diff), ACCT_STR) *
trans_dec_factor;
case IDENTITY: break;
default: assert(0);
}
......
......@@ -15,6 +15,7 @@
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
#include "./aom_config.h"
#include "test/acm_random.h"
#include "aom/aom_integer.h"
#include "aom_dsp/bitreader.h"
......@@ -22,6 +23,8 @@
#include "aom_dsp/binary_codes_reader.h"
#include "aom_dsp/binary_codes_writer.h"
#define ACCT_STR __func__
using libaom_test::ACMRandom;
namespace {
......@@ -68,8 +71,8 @@ TEST(AV1, TestPrimitiveRefbilivel) {
const uint16_t range = enc_values[n][p][r][v][0];
const uint16_t near_range = enc_values[n][p][r][v][1];
const uint16_t ref = enc_values[n][p][r][v][2];
const uint16_t value =
aom_read_primitive_refbilevel(&br, range, near_range, ref);
const uint16_t value = aom_read_primitive_refbilevel(
&br, range, near_range, ref, ACCT_STR);
GTEST_ASSERT_EQ(value, enc_values[n][p][r][v][3]);
}
}
......@@ -119,7 +122,7 @@ TEST(AV1, TestPrimitiveRefsubexpfin) {
assert(k == enc_values[n][k][r][v][1]);
const uint16_t ref = enc_values[n][k][r][v][2];
const uint16_t value =
aom_read_primitive_refsubexpfin(&br, range, k, ref);
aom_read_primitive_refsubexpfin(&br, range, k, ref, ACCT_STR);
GTEST_ASSERT_EQ(value, enc_values[n][k][r][v][3]);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment