cleanup
diff --git a/av1/common/entropy.h b/av1/common/entropy.h
index 5dc7649..d84c233 100644
--- a/av1/common/entropy.h
+++ b/av1/common/entropy.h
@@ -82,12 +82,14 @@
#define NUM_BASE_LEVELS 2
-#define BR_CDF_SIZE (4)
#if CONFIG_ADAPTIVE_HR
-#define COEFF_BASE_RANGE (1 * (BR_CDF_SIZE - 1))
+#define BR_NUM_ITERATIONS 1
#else
-#define COEFF_BASE_RANGE (4 * (BR_CDF_SIZE - 1))
+#define BR_NUM_ITERATIONS 4
#endif // CONFIG_ADAPTIVE_HR
+
+#define BR_CDF_SIZE (4)
+#define COEFF_BASE_RANGE (BR_NUM_ITERATIONS * (BR_CDF_SIZE - 1))
#define COEFF_CONTEXT_BITS 3
#define COEFF_CONTEXT_MASK ((1 << COEFF_CONTEXT_BITS) - 1)
#define MAX_BASE_BR_RANGE (COEFF_BASE_RANGE + NUM_BASE_LEVELS + 1)
diff --git a/av1/common/hr_coding.c b/av1/common/hr_coding.c
index 782e6e7..6fb9673 100644
--- a/av1/common/hr_coding.c
+++ b/av1/common/hr_coding.c
@@ -64,46 +64,23 @@
#if CONFIG_ADAPTIVE_HR
-typedef struct adaptive_table {
- int *table;
- int initial_param;
- unsigned int table_size;
-} adaptive_table;
+static int adaptive_table[] = { 10, 20, 40, 75, 135 };
-int intra_table[] = { 10, 20, 40, 75, 135 };
-int inter_table[] = { 20, 35, 55, 95, 170 };
-int idtx_table[] = { 25, 50, 130 };
-
-adaptive_table tables[] = {
- { .table = intra_table, .initial_param = 1, .table_size = 5 }, // Intra table
- { .table = inter_table, .initial_param = 1, .table_size = 5 }, // Inter table
- { .table = idtx_table,
- .initial_param = 1,
- .table_size = 3 }, // IDTX table (only for inter)
-};
-
-int get_adaptive_param(adaptive_hr_info *info) {
- adaptive_table *adp_table;
- adp_table = &tables[0];
-
- int m = adp_table->initial_param;
-
- for (unsigned int i = 0; i < adp_table->table_size; ++i) {
- if (info->context < adp_table->table[i]) break;
- ++m;
- }
-
- return m;
+static int get_adaptive_param(int ctx) {
+ const int table_size = sizeof(adaptive_table) / sizeof(int);
+ int m = 0;
+ while (m < table_size && ctx >= adaptive_table[m]) ++m;
+ return m + 1;
}
void write_truncated_rice(aom_writer *w, int level, int m, int k, int cmax) {
- const int mask = (1 << m) - 1;
int q = level >> m;
if (q >= cmax) {
aom_write_literal(w, 0, cmax);
write_exp_golomb(w, level - (cmax << m), k);
} else {
+ const int mask = (1 << m) - 1;
aom_write_literal(w, 0, q);
aom_write_literal(w, 1, 1);
aom_write_literal(w, level & mask, m);
@@ -113,15 +90,13 @@
int read_truncated_rice(MACROBLOCKD *xd, aom_reader *r, int m, int k,
int cmax) {
int q = aom_read_unary(r, cmax, ACCT_INFO("hr"));
- if (q == cmax) return read_exp_golomb(xd, r, k) + (cmax << m);
-
- int rem = aom_read_literal(r, m, ACCT_INFO("hr"));
+ int rem = (q == cmax) ? read_exp_golomb(xd, r, k)
+ : aom_read_literal(r, m, ACCT_INFO("hr"));
return rem + (q << m);
}
int get_truncated_rice_length(int level, int m, int k, int cmax) {
int q = level >> m;
-
if (q >= cmax) return cmax + get_exp_golomb_length(level - (cmax << m), k);
return q + 1 + m;
@@ -135,6 +110,7 @@
int lshifted = level - (cmax << m);
if (lshifted == 0) {
int golomb_len0 = k + 1;
+ // diff = (cmax + golomb_len0) - (cmax - 1 + 1 + m)
*diff = golomb_len0 - m;
return cmax + golomb_len0;
}
@@ -150,23 +126,23 @@
return q + 1 + m;
}
-void write_adaptive_hr(aom_writer *w, int level, adaptive_hr_info *info) {
- int m = get_adaptive_param(info);
+void write_adaptive_hr(aom_writer *w, int level, int ctx) {
+ int m = get_adaptive_param(ctx);
write_truncated_rice(w, level, m, m + 1, AOMMIN(m + 4, 6));
}
-int read_adaptive_hr(MACROBLOCKD *xd, aom_reader *r, adaptive_hr_info *info) {
- int m = get_adaptive_param(info);
+int read_adaptive_hr(MACROBLOCKD *xd, aom_reader *r, int ctx) {
+ int m = get_adaptive_param(ctx);
return read_truncated_rice(xd, r, m, m + 1, AOMMIN(m + 4, 6));
}
-int get_adaptive_hr_length(int level, adaptive_hr_info *info) {
- int m = get_adaptive_param(info);
+int get_adaptive_hr_length(int level, int ctx) {
+ int m = get_adaptive_param(ctx);
return get_truncated_rice_length(level, m, m + 1, AOMMIN(m + 4, 6));
}
-int get_adaptive_hr_length_diff(int level, adaptive_hr_info *info, int *diff) {
- int m = get_adaptive_param(info);
+int get_adaptive_hr_length_diff(int level, int ctx, int *diff) {
+ int m = get_adaptive_param(ctx);
return get_truncated_rice_length_diff(level, m, m + 1, AOMMIN(m + 4, 6),
diff);
}
diff --git a/av1/common/hr_coding.h b/av1/common/hr_coding.h
index 4b56c37..81fc3f1 100644
--- a/av1/common/hr_coding.h
+++ b/av1/common/hr_coding.h
@@ -39,26 +39,16 @@
#if CONFIG_ADAPTIVE_HR
-typedef struct adaptive_hr_info {
- int context;
- TX_SIZE tx_size;
- TX_TYPE tx_type;
- int qindex;
- bool is_inter;
- bool is_dc;
- bool is_eob;
-} adaptive_hr_info;
-
void write_truncated_rice(aom_writer *w, int level, int m, int k, int cmax);
int read_truncated_rice(MACROBLOCKD *xd, aom_reader *r, int m, int k, int cmax);
int get_truncated_rice_length(int level, int m, int k, int cmax);
int get_truncated_rice_length_diff(int level, int m, int k, int cmax,
int *diff);
-void write_adaptive_hr(aom_writer *w, int level, adaptive_hr_info *info);
-int read_adaptive_hr(MACROBLOCKD *xd, aom_reader *r, adaptive_hr_info *info);
-int get_adaptive_hr_length(int level, adaptive_hr_info *info);
-int get_adaptive_hr_length_diff(int level, adaptive_hr_info *info, int *diff);
+void write_adaptive_hr(aom_writer *w, int level, int ctx);
+int read_adaptive_hr(MACROBLOCKD *xd, aom_reader *r, int ctx);
+int get_adaptive_hr_length(int level, int ctx);
+int get_adaptive_hr_length_diff(int level, int ctx, int *diff);
#endif // CONFIG_ADAPTIVE_HR
diff --git a/av1/decoder/decodetxb.c b/av1/decoder/decodetxb.c
index 3313fb7..4c5edb2 100644
--- a/av1/decoder/decodetxb.c
+++ b/av1/decoder/decodetxb.c
@@ -403,11 +403,6 @@
#if CONFIG_ADAPTIVE_HR
const TX_CLASS tx_class = tx_type_to_class[get_primary_tx_type(tx_type)];
- adaptive_hr_info hr_info = { .tx_size = tx_size,
- .tx_type = tx_type,
- .qindex = xd->qindex[mbmi->segment_id],
- .is_inter =
- is_inter_block(mbmi, xd->tree_type) };
#endif // CONFIG_ADAPTIVE_HR
#if CONFIG_INSPECTION
@@ -461,10 +456,8 @@
if (level >= MAX_BASE_BR_RANGE) {
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob_data->eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx_skip(levels, pos, bwl, is_eob, tx_class);
- level += read_adaptive_hr(xd, r, &hr_info);
+ int hr_ctx = get_hr_ctx_skip(levels, pos, bwl, is_eob, tx_class);
+ level += read_adaptive_hr(xd, r, hr_ctx);
levels[get_padded_idx_left(pos, bwl)] =
(uint8_t)(AOMMIN(level, UINT8_MAX));
@@ -580,14 +573,6 @@
const qm_val_t *iqmatrix =
av1_get_iqmatrix(&cm->quant_params, xd, plane, tx_size, tx_type);
-#if CONFIG_ADAPTIVE_HR
- adaptive_hr_info hr_info = { .tx_size = tx_size,
- .tx_type = tx_type,
- .qindex = xd->qindex[mbmi->segment_id],
- .is_inter =
- is_inter_block(mbmi, xd->tree_type) };
-#endif // CONFIG_ADAPTIVE_HR
-
#if CONFIG_INSPECTION
for (int c = 0; c < width * height; c++) {
dequant_values[c] = get_dqv(dequant, c, iqmatrix);
@@ -763,11 +748,9 @@
if (level >= (MAX_BASE_BR_RANGE << 1)) {
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (*eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
// Use context divided by 2 since the coefficient is also divided by 2
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class) >> 1;
- level += (read_adaptive_hr(xd, r, &hr_info) << 1);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class) >> 1;
+ level += (read_adaptive_hr(xd, r, hr_ctx) << 1);
levels[get_padded_idx(pos, bwl)] =
(uint8_t)(AOMMIN(level, UINT8_MAX));
@@ -783,10 +766,8 @@
if (level >= LF_MAX_BASE_BR_RANGE) {
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (*eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
- level += read_adaptive_hr(xd, r, &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ level += read_adaptive_hr(xd, r, hr_ctx);
levels[get_padded_idx(pos, bwl)] =
(uint8_t)(AOMMIN(level, UINT8_MAX));
@@ -798,10 +779,8 @@
if (level >= MAX_BASE_BR_RANGE) {
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (*eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
- level += read_adaptive_hr(xd, r, &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ level += read_adaptive_hr(xd, r, hr_ctx);
levels[get_padded_idx(pos, bwl)] =
(uint8_t)(AOMMIN(level, UINT8_MAX));
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c
index e8a24cb..b7a2ce8 100644
--- a/av1/encoder/encodetxb.c
+++ b/av1/encoder/encodetxb.c
@@ -278,32 +278,32 @@
#if CONFIG_ADAPTIVE_HR
static INLINE int get_br_cost(tran_low_t level, const int *coeff_lps,
- adaptive_hr_info *info) {
+ int hr_ctx) {
const int base_range = AOMMIN(level - 1 - NUM_BASE_LEVELS, COEFF_BASE_RANGE);
int cost = coeff_lps[base_range];
if (level >= 1 + NUM_BASE_LEVELS + COEFF_BASE_RANGE) {
const int r = level - COEFF_BASE_RANGE - NUM_BASE_LEVELS - 1;
- cost += av1_cost_literal(get_adaptive_hr_length(r, info));
+ cost += av1_cost_literal(get_adaptive_hr_length(r, hr_ctx));
}
return cost;
}
static INLINE int get_br_lf_cost(tran_low_t level, const int *coeff_lps,
- adaptive_hr_info *info) {
+ int hr_ctx) {
const int base_range =
AOMMIN(level - 1 - LF_NUM_BASE_LEVELS, COEFF_BASE_RANGE);
int cost = coeff_lps[base_range];
if (level >= 1 + LF_NUM_BASE_LEVELS + COEFF_BASE_RANGE) {
const int r = level - COEFF_BASE_RANGE - LF_NUM_BASE_LEVELS - 1;
- cost += av1_cost_literal(get_adaptive_hr_length(r, info));
+ cost += av1_cost_literal(get_adaptive_hr_length(r, hr_ctx));
}
return cost;
}
static INLINE int get_br_cost_with_diff(tran_low_t level, const int *coeff_lps,
- int *diff, adaptive_hr_info *info) {
+ int *diff, int hr_ctx) {
const int base_range = AOMMIN(level - 1 - NUM_BASE_LEVELS, COEFF_BASE_RANGE);
int cost = coeff_lps[base_range];
@@ -313,7 +313,7 @@
if (level >= COEFF_BASE_RANGE + 1 + NUM_BASE_LEVELS) {
const int r = level - COEFF_BASE_RANGE - NUM_BASE_LEVELS - 1;
int bits, diff_bits;
- bits = get_adaptive_hr_length_diff(r, info, &diff_bits);
+ bits = get_adaptive_hr_length_diff(r, hr_ctx, &diff_bits);
*diff += av1_cost_literal(diff_bits);
cost += av1_cost_literal(bits);
}
@@ -323,7 +323,7 @@
static INLINE int get_br_lf_cost_with_diff(tran_low_t level,
const int *coeff_lps, int *diff,
- adaptive_hr_info *info) {
+ int hr_ctx) {
const int base_range =
AOMMIN(level - 1 - LF_NUM_BASE_LEVELS, COEFF_BASE_RANGE);
int cost = coeff_lps[base_range];
@@ -334,7 +334,7 @@
if (level >= COEFF_BASE_RANGE + 1 + LF_NUM_BASE_LEVELS) {
const int r = level - COEFF_BASE_RANGE - LF_NUM_BASE_LEVELS - 1;
int bits, diff_bits;
- bits = get_adaptive_hr_length_diff(r, info, &diff_bits);
+ bits = get_adaptive_hr_length_diff(r, hr_ctx, &diff_bits);
*diff += av1_cost_literal(diff_bits);
cost += av1_cost_literal(bits);
}
@@ -748,12 +748,6 @@
#if CONFIG_ADAPTIVE_HR
const TX_CLASS tx_class = tx_type_to_class[get_primary_tx_type(tx_type)];
- const MB_MODE_INFO *mbmi = xd->mi[0];
- adaptive_hr_info hr_info = { .tx_size = tx_size,
- .tx_type = tx_type,
- .qindex = xd->qindex[mbmi->segment_id],
- .is_inter =
- is_inter_block(mbmi, xd->tree_type) };
#endif // CONFIG_ADAPTIVE_HR
DECLARE_ALIGNED(16, int8_t, coeff_contexts[MAX_TX_SQUARE]);
@@ -801,11 +795,9 @@
if (level > COEFF_BASE_RANGE + NUM_BASE_LEVELS) {
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx_skip(levels, pos, bwl, is_eob, tx_class);
+ int hr_ctx = get_hr_ctx_skip(levels, pos, bwl, is_eob, tx_class);
write_adaptive_hr(w, level - COEFF_BASE_RANGE - 1 - NUM_BASE_LEVELS,
- &hr_info);
+ hr_ctx);
#else
write_exp_golomb(w, level - COEFF_BASE_RANGE - 1 - NUM_BASE_LEVELS, 0);
#endif // CONFIG_ADAPTIVE_HR
@@ -904,15 +896,6 @@
const int bwl = get_txb_bwl(tx_size);
-#if CONFIG_ADAPTIVE_HR
- const MB_MODE_INFO *mbmi = xd->mi[0];
- adaptive_hr_info hr_info = { .tx_size = tx_size,
- .tx_type = tx_type,
- .qindex = xd->qindex[mbmi->segment_id],
- .is_inter =
- is_inter_block(mbmi, xd->tree_type) };
-#endif // CONFIG_ADAPTIVE_HR
-
bool enable_parity_hiding = cm->features.allow_parity_hiding &&
!xd->lossless[xd->mi[0]->segment_id] &&
plane == PLANE_TYPE_Y &&
@@ -1112,13 +1095,10 @@
if (q_index > COEFF_BASE_RANGE + NUM_BASE_LEVELS) {
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
// Use context divided by 2 since the coefficient is also divided by 2
- hr_info.context =
- get_hr_ctx(levels, scan[0], bwl, is_eob, tx_class) >> 1;
+ int hr_ctx = get_hr_ctx(levels, scan[0], bwl, is_eob, tx_class) >> 1;
write_adaptive_hr(w, q_index - COEFF_BASE_RANGE - 1 - NUM_BASE_LEVELS,
- &hr_info);
+ hr_ctx);
#else
write_exp_golomb(w, q_index - COEFF_BASE_RANGE - 1 - NUM_BASE_LEVELS,
0);
@@ -1133,11 +1113,9 @@
if (level > COEFF_BASE_RANGE + LF_NUM_BASE_LEVELS) {
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
write_adaptive_hr(
- w, level - COEFF_BASE_RANGE - 1 - LF_NUM_BASE_LEVELS, &hr_info);
+ w, level - COEFF_BASE_RANGE - 1 - LF_NUM_BASE_LEVELS, hr_ctx);
#else
write_exp_golomb(
w, level - COEFF_BASE_RANGE - 1 - LF_NUM_BASE_LEVELS, 0);
@@ -1147,11 +1125,9 @@
if (level > COEFF_BASE_RANGE + NUM_BASE_LEVELS) {
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
write_adaptive_hr(w, level - COEFF_BASE_RANGE - 1 - NUM_BASE_LEVELS,
- &hr_info);
+ hr_ctx);
#else
write_exp_golomb(w, level - COEFF_BASE_RANGE - 1 - NUM_BASE_LEVELS,
0);
@@ -1427,11 +1403,6 @@
#if CONFIG_ADAPTIVE_HR
const TX_CLASS tx_class = tx_type_to_class[get_primary_tx_type(tx_type)];
- adaptive_hr_info hr_info = { .tx_size = tx_size,
- .tx_type = tx_type,
- .qindex = xd->qindex[mbmi->segment_id],
- .is_inter =
- is_inter_block(mbmi, xd->tree_type) };
#endif // CONFIG_ADAPTIVE_HR
const int eob_multi_size = txsize_log2_minus4[tx_size];
@@ -1467,10 +1438,8 @@
const int ctx = get_br_ctx_skip(levels, pos, bwl);
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx_skip(levels, pos, bwl, is_eob, tx_class);
- cost += get_br_cost(level, lps_cost[ctx], &hr_info);
+ int hr_ctx = get_hr_ctx_skip(levels, pos, bwl, is_eob, tx_class);
+ cost += get_br_cost(level, lps_cost[ctx], hr_ctx);
#else
cost += get_br_cost(level, lps_cost[ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -1538,15 +1507,6 @@
int cost = coeff_costs->txb_skip_cost[txb_skip_ctx][0];
#endif // CONFIG_CONTEXT_DERIVATION
-#if CONFIG_ADAPTIVE_HR
- const MB_MODE_INFO *mbmi = xd->mi[0];
- adaptive_hr_info hr_info = { .tx_size = tx_size,
- .tx_type = tx_type,
- .qindex = xd->qindex[mbmi->segment_id],
- .is_inter =
- is_inter_block(mbmi, xd->tree_type) };
-#endif // CONFIG_ADAPTIVE_HR
-
av1_txb_init_levels(qcoeff, width, height, levels);
const int bob_code = p->bobs[block];
@@ -1597,10 +1557,8 @@
const int ctx = get_br_ctx_lf_eob(pos, tx_class);
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
- cost += get_br_lf_cost(level, lps_lf_cost[ctx], &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ cost += get_br_lf_cost(level, lps_lf_cost[ctx], hr_ctx);
#else
cost += get_br_lf_cost(level, lps_lf_cost[ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -1610,10 +1568,8 @@
const int ctx = 7; /* get_lf_ctx_eob */
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
- cost += get_br_cost(level, lps_cost[ctx], &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ cost += get_br_cost(level, lps_cost[ctx], hr_ctx);
#else
cost += get_br_cost(level, lps_cost[ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -1680,10 +1636,8 @@
const int ctx = get_br_lf_ctx(levels, pos, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
- cost += get_br_lf_cost(level, lps_lf_cost[ctx], &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ cost += get_br_lf_cost(level, lps_lf_cost[ctx], hr_ctx);
#else
cost += get_br_lf_cost(level, lps_lf_cost[ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -1693,10 +1647,8 @@
const int ctx = get_br_ctx(levels, pos, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
- cost += get_br_cost(level, lps_cost[ctx], &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ cost += get_br_cost(level, lps_cost[ctx], hr_ctx);
#else
cost += get_br_cost(level, lps_cost[ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -1726,12 +1678,9 @@
const int ctx = get_par_br_ctx(levels, pos, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
// Use context divided by 2 since the coefficient is also divided by 2
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class) >> 1;
- cost +=
- get_br_cost(q_index, coeff_costs_ph->lps_ph_cost[ctx], &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class) >> 1;
+ cost += get_br_cost(q_index, coeff_costs_ph->lps_ph_cost[ctx], hr_ctx);
#else
cost += get_br_cost(q_index, coeff_costs_ph->lps_ph_cost[ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -1773,10 +1722,8 @@
const int ctx = get_br_lf_ctx(levels, pos, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
- cost += get_br_lf_cost(level, lps_lf_cost[ctx], &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ cost += get_br_lf_cost(level, lps_lf_cost[ctx], hr_ctx);
#else
cost += get_br_lf_cost(level, lps_lf_cost[ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -1786,10 +1733,8 @@
const int ctx = get_br_ctx(levels, pos, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
bool is_eob = c == (eob - 1);
- hr_info.is_dc = (c == 0);
- hr_info.is_eob = is_eob;
- hr_info.context = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
- cost += get_br_cost(level, lps_cost[ctx], &hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, is_eob, tx_class);
+ cost += get_br_cost(level, lps_cost[ctx], hr_ctx);
#else
cost += get_br_cost(level, lps_cost[ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -2056,12 +2001,7 @@
static AOM_FORCE_INLINE int get_two_coeff_cost_simple(
int plane, int ci, tran_low_t abs_qc, int coeff_ctx,
const LV_MAP_COEFF_COST *txb_costs, int bwl, TX_CLASS tx_class,
- const uint8_t *levels, int *cost_low
-#if CONFIG_ADAPTIVE_HR
- ,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
-) {
+ const uint8_t *levels, int *cost_low) {
// this simple version assumes the coeff's scan_idx is not DC (scan_idx != 0)
// and not the last (scan_idx != eob - 1)
assert(ci > 0);
@@ -2121,11 +2061,9 @@
const int br_ctx = get_br_lf_ctx(levels, ci, bwl, tx_class);
int brcost_diff = 0;
#if CONFIG_ADAPTIVE_HR
- hr_info->is_dc = false;
- hr_info->is_eob = false;
- hr_info->context = get_hr_ctx(levels, ci, bwl, false, tx_class);
+ int hr_ctx = get_hr_ctx(levels, ci, bwl, false, tx_class);
cost += get_br_lf_cost_with_diff(abs_qc, txb_costs->lps_lf_cost[br_ctx],
- &brcost_diff, hr_info);
+ &brcost_diff, hr_ctx);
#else
cost += get_br_lf_cost_with_diff(abs_qc, txb_costs->lps_lf_cost[br_ctx],
&brcost_diff);
@@ -2137,11 +2075,9 @@
const int br_ctx = get_br_ctx(levels, ci, bwl, tx_class);
int brcost_diff = 0;
#if CONFIG_ADAPTIVE_HR
- hr_info->is_dc = false;
- hr_info->is_eob = false;
- hr_info->context = get_hr_ctx(levels, ci, bwl, false, tx_class);
+ int hr_ctx = get_hr_ctx(levels, ci, bwl, false, tx_class);
cost += get_br_cost_with_diff(abs_qc, txb_costs->lps_cost[br_ctx],
- &brcost_diff, hr_info);
+ &brcost_diff, hr_ctx);
#else
cost += get_br_cost_with_diff(abs_qc, txb_costs->lps_cost[br_ctx],
&brcost_diff);
@@ -2164,13 +2100,7 @@
int32_t *tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- int plane
-#if CONFIG_ADAPTIVE_HR
- ,
- const uint8_t *levels,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
-) {
+ int plane) {
int cost = 0;
const int row = ci >> bwl;
const int col = ci - (row << bwl);
@@ -2206,10 +2136,8 @@
if (abs_qc > LF_NUM_BASE_LEVELS) {
int br_ctx = get_br_ctx_lf_eob(ci, tx_class);
#if CONFIG_ADAPTIVE_HR
- hr_info->is_eob = true;
- hr_info->is_dc = (ci == 0);
- hr_info->context = get_hr_ctx(levels, ci, bwl, true, tx_class);
- cost += get_br_lf_cost(abs_qc, txb_costs->lps_lf_cost[br_ctx], hr_info);
+ int hr_ctx = 0; /* get_hr_ctx */
+ cost += get_br_lf_cost(abs_qc, txb_costs->lps_lf_cost[br_ctx], hr_ctx);
#else
cost += get_br_lf_cost(abs_qc, txb_costs->lps_lf_cost[br_ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -2218,10 +2146,8 @@
if (abs_qc > NUM_BASE_LEVELS) {
int br_ctx = 7; /* get_br_ctx_eob */
#if CONFIG_ADAPTIVE_HR
- hr_info->is_eob = true;
- hr_info->is_dc = (ci == 0);
- hr_info->context = get_hr_ctx(levels, ci, bwl, true, tx_class);
- cost += get_br_cost(abs_qc, txb_costs->lps_cost[br_ctx], hr_info);
+ int hr_ctx = 0; /* get_hr_ctx */
+ cost += get_br_cost(abs_qc, txb_costs->lps_cost[br_ctx], hr_ctx);
#else
cost += get_br_cost(abs_qc, txb_costs->lps_cost[br_ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -2242,12 +2168,7 @@
int32_t *tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- int plane
-#if CONFIG_ADAPTIVE_HR
- ,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
-) {
+ int plane) {
int cost = 0;
if (is_last) {
const int row = ci >> bwl;
@@ -2304,10 +2225,8 @@
br_ctx = get_br_lf_ctx(levels, ci, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
- hr_info->is_dc = (ci == 0);
- hr_info->is_eob = is_last;
- hr_info->context = get_hr_ctx(levels, ci, bwl, is_last, tx_class);
- cost += get_br_lf_cost(abs_qc, txb_costs->lps_lf_cost[br_ctx], hr_info);
+ int hr_ctx = get_hr_ctx(levels, ci, bwl, is_last, tx_class);
+ cost += get_br_lf_cost(abs_qc, txb_costs->lps_lf_cost[br_ctx], hr_ctx);
#else
cost += get_br_lf_cost(abs_qc, txb_costs->lps_lf_cost[br_ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -2321,10 +2240,8 @@
br_ctx = get_br_ctx(levels, ci, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
- hr_info->is_dc = (ci == 0);
- hr_info->is_eob = is_last;
- hr_info->context = get_hr_ctx(levels, ci, bwl, is_last, tx_class);
- cost += get_br_cost(abs_qc, txb_costs->lps_cost[br_ctx], hr_info);
+ int hr_ctx = get_hr_ctx(levels, ci, bwl, is_last, tx_class);
+ cost += get_br_cost(abs_qc, txb_costs->lps_cost[br_ctx], hr_ctx);
#else
cost += get_br_cost(abs_qc, txb_costs->lps_cost[br_ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -2362,12 +2279,7 @@
int32_t *tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- int plane, coeff_info *coef_info, bool enable_parity_hiding
-#if CONFIG_ADAPTIVE_HR
- ,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
-) {
+ int plane, coeff_info *coef_info, bool enable_parity_hiding) {
const int dqv = get_dqv(dequant, scan[si], iqmatrix);
const int ci = scan[si];
const tran_low_t qc = qcoeff[ci];
@@ -2398,12 +2310,7 @@
tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane
-#if CONFIG_ADAPTIVE_HR
- ,
- hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane);
const int64_t rd = RDCOST(rdmult, rate, dist);
tran_low_t qc_low, dqc_low;
@@ -2433,12 +2340,7 @@
tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane
-#if CONFIG_ADAPTIVE_HR
- ,
- hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane);
}
rd_low = RDCOST(rdmult, rate_low, dist_low);
@@ -2467,12 +2369,7 @@
const LV_MAP_COEFF_COST *txb_costs, const tran_low_t *tcoeff,
tran_low_t *qcoeff, tran_low_t *dqcoeff, uint8_t *levels,
const qm_val_t *iqmatrix, coeff_info *coef_info, bool enable_parity_hiding,
- int plane
-#if CONFIG_ADAPTIVE_HR
- ,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
-) {
+ int plane) {
const int dqv = get_dqv(dequant, scan[si], iqmatrix);
(void)eob;
// this simple version assumes the coeff's scan_idx is not DC (scan_idx != 0)
@@ -2509,12 +2406,7 @@
int rate_low = 0;
const int rate =
get_two_coeff_cost_simple(plane, ci, abs_qc, coeff_ctx, txb_costs, bwl,
- tx_class, levels, &rate_low
-#if CONFIG_ADAPTIVE_HR
- ,
- hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ tx_class, levels, &rate_low);
if (abs_dqc < abs_tqc) {
*accu_rate += rate;
@@ -2569,12 +2461,7 @@
int32_t *tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- int plane, coeff_info *coef_info, bool enable_parity_hiding
-#if CONFIG_ADAPTIVE_HR
- ,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
-) {
+ int plane, coeff_info *coef_info, bool enable_parity_hiding) {
const int bwl = get_txb_bwl(tx_size);
const int height = get_txb_high(tx_size);
const int dqv = get_dqv(dequant, scan[si], iqmatrix);
@@ -2619,12 +2506,7 @@
tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane
-#if CONFIG_ADAPTIVE_HR
- ,
- hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane);
int64_t rd = RDCOST(rdmult, *accu_rate + rate, *accu_dist + dist);
tran_low_t qc_low, dqc_low;
@@ -2653,12 +2535,7 @@
tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane
-#if CONFIG_ADAPTIVE_HR
- ,
- hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane);
rd_low = RDCOST(rdmult, *accu_rate + rate_low, *accu_dist + dist_low);
}
int rate_up_backup = rate;
@@ -2680,12 +2557,7 @@
tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane
-#if CONFIG_ADAPTIVE_HR
- ,
- levels, hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane);
int64_t dist_new_eob = dist;
int64_t rd_new_eob = RDCOST(rdmult, rate_coeff_eob, dist_new_eob);
int rateeobup = rate_coeff_eob;
@@ -2700,12 +2572,7 @@
tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane
-#if CONFIG_ADAPTIVE_HR
- ,
- levels, hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane);
const int64_t dist_new_eob_low = dist_low;
const int64_t rd_new_eob_low =
RDCOST(rdmult, rate_coeff_eob_low, dist_new_eob_low);
@@ -2793,10 +2660,6 @@
,
int plane
#endif // CONFIG_CHROMA_TX_COEFF_CODING
-#if CONFIG_ADAPTIVE_HR
- ,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
) {
tran_low_t abslevel = abs(level), q_index = abslevel >> 1;
int sign = level < 0;
@@ -2821,22 +2684,15 @@
0
#endif // CONFIG_CONTEXT_DERIVATION
,
- 0
-#if CONFIG_ADAPTIVE_HR
- ,
- hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ 0);
const int base_ctx_ph = get_base_ctx_ph(levels, pos, bwl, tx_class);
int rate_ph = txb_costs_ph->base_ph_cost[base_ctx_ph][AOMMIN(q_index, 3)];
if (q_index > NUM_BASE_LEVELS) {
int br_ctx = get_par_br_ctx(levels, pos, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
- hr_info->is_eob = false;
- hr_info->is_dc = (pos == 0);
- hr_info->context = get_hr_ctx(levels, pos, bwl, false, tx_class);
- rate_ph += get_br_cost(q_index, txb_costs_ph->lps_ph_cost[br_ctx], hr_info);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, false, tx_class);
+ rate_ph += get_br_cost(q_index, txb_costs_ph->lps_ph_cost[br_ctx], hr_ctx);
#else
rate_ph += get_br_cost(q_index, txb_costs_ph->lps_ph_cost[br_ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -2861,12 +2717,7 @@
const LV_MAP_COEFF_COST *txb_costs_ph, int dc_sign_ctx, TX_CLASS tx_class,
uint8_t *levels, const int bwl, const int64_t rdmult,
const int32_t *dequant, const qm_val_t *iqmatrix, tune_cand *t_cand,
- int rate_cur
-#if CONFIG_ADAPTIVE_HR
- ,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
-) {
+ int rate_cur) {
const int dqv = get_dqv(dequant, pos, iqmatrix);
tran_low_t abslevel = abs(qcoeff), abstqc = abs(tcoeff);
int64_t dist = get_coeff_dist(tcoeff, dqcoeff, shift);
@@ -2888,11 +2739,9 @@
if (q_index > NUM_BASE_LEVELS) {
int br_ctx = get_par_br_ctx(levels, pos, bwl, tx_class);
#if CONFIG_ADAPTIVE_HR
- hr_info->is_eob = false;
- hr_info->is_dc = (pos == 0);
- hr_info->context = get_hr_ctx(levels, pos, bwl, 0, tx_class);
+ int hr_ctx = get_hr_ctx(levels, pos, bwl, false, tx_class);
rate_cand +=
- get_br_cost(q_index, txb_costs_ph->lps_ph_cost[br_ctx], hr_info);
+ get_br_cost(q_index, txb_costs_ph->lps_ph_cost[br_ctx], hr_ctx);
#else
rate_cand += get_br_cost(q_index, txb_costs_ph->lps_ph_cost[br_ctx]);
#endif // CONFIG_ADAPTIVE_HR
@@ -3033,10 +2882,6 @@
,
int plane
#endif // CONFIG_CHROMA_TX_COEFF_CODING
-#if CONFIG_ADAPTIVE_HR
- ,
- adaptive_hr_info *hr_info
-#endif // CONFIG_ADAPTIVE_HR
) {
int nzsbb = 0, sum_abs1 = 0;
for (int scan_idx = eob - 1; scan_idx > 0; --scan_idx) {
@@ -3061,10 +2906,6 @@
,
plane
#endif // CONFIG_CHROMA_TX_COEFF_CODING
-#if CONFIG_ADAPTIVE_HR
- ,
- hr_info
-#endif // CONFIG_ADAPTIVE_HR
);
if (!needtune && nzsbb >= PHTHRESH) {
@@ -3079,12 +2920,7 @@
if (nzsbb >= PHTHRESH) {
cost_hide_par(qcoeff[hidepos], dqcoeff[hidepos], tcoeff[hidepos], shift,
txb_costs, hidepos, txb_costs_ph, dc_sign_ctx, tx_class,
- levels, bwl, rdmult, dequant, iqmatrix, &t_cand_dc, rate_cur
-#if CONFIG_ADAPTIVE_HR
- ,
- hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ levels, bwl, rdmult, dequant, iqmatrix, &t_cand_dc, rate_cur);
}
// we change the level candidates to check the cost change.
@@ -3171,14 +3007,6 @@
coef_info[scan_idx].upround = false;
}
-#if CONFIG_ADAPTIVE_HR
- adaptive_hr_info hr_info = { .tx_size = tx_size,
- .tx_type = tx_type,
- .qindex = xd->qindex[mbmi->segment_id],
- .is_inter =
- is_inter_block(mbmi, xd->tree_type) };
-#endif // CONFIG_ADAPTIVE_HR
-
const int rshift =
(sharpness +
(cpi->oxcf.q_cfg.aq_mode == VARIANCE_AQ && mbmi->segment_id < 4
@@ -3250,12 +3078,7 @@
xd->tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane, coef_info, enable_parity_hiding
-#if CONFIG_ADAPTIVE_HR
- ,
- &hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane, coef_info, enable_parity_hiding);
--si;
} else {
assert(abs_qc == 1);
@@ -3268,12 +3091,7 @@
xd->tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane
-#if CONFIG_ADAPTIVE_HR
- ,
- levels, &hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane);
const tran_low_t tqc = tcoeff[ci];
const tran_low_t dqc = dqcoeff[ci];
const int64_t dist = get_coeff_dist(tqc, dqc, shift);
@@ -3294,12 +3112,7 @@
xd->tmp_sign
#endif
,
- plane, coef_info, enable_parity_hiding
-#if CONFIG_ADAPTIVE_HR
- ,
- &hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane, coef_info, enable_parity_hiding);
}
if (si == -1 && nz_num <= max_nz_num) {
update_skip(&accu_rate, accu_dist, &eob, nz_num, nz_ci, rdmult, skip_cost,
@@ -3309,12 +3122,8 @@
for (; si >= 1; --si) {
update_coeff_simple(&accu_rate, si, eob, tx_class, bwl, rdmult, shift,
dequant, scan, txb_costs, tcoeff, qcoeff, dqcoeff,
- levels, iqmatrix, coef_info, enable_parity_hiding, plane
-#if CONFIG_ADAPTIVE_HR
- ,
- &hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ levels, iqmatrix, coef_info, enable_parity_hiding,
+ plane);
}
// DC position
@@ -3330,12 +3139,7 @@
xd->tmp_sign
#endif // CONFIG_CONTEXT_DERIVATION
,
- plane, coef_info, enable_parity_hiding
-#if CONFIG_ADAPTIVE_HR
- ,
- &hr_info
-#endif // CONFIG_ADAPTIVE_HR
- );
+ plane, coef_info, enable_parity_hiding);
}
if (enable_parity_hiding) {
@@ -3346,10 +3150,6 @@
,
plane
#endif // CONFIG_CHROMA_TX_COEFF_CODING
-#if CONFIG_ADAPTIVE_HR
- ,
- &hr_info
-#endif // CONFIG_ADAPTIVE_HR
);
}
diff --git a/build/cmake/aom_config_defaults.cmake b/build/cmake/aom_config_defaults.cmake
index 3d308c3..b0fb3bf 100644
--- a/build/cmake/aom_config_defaults.cmake
+++ b/build/cmake/aom_config_defaults.cmake
@@ -339,7 +339,7 @@
"Keep optical flow refined MVs in TMVP list.")
set_aom_config_var(CONFIG_AFFINE_REFINEMENT 1
"Decoder side affine motion refinement.")
-set_aom_config_var(CONFIG_ADAPTIVE_HR 1 "AV2 new adaptive HR coefficient level coding.")
+set_aom_config_var(CONFIG_ADAPTIVE_HR 1 "Base range reduction and adaptive HR coefficient coding from CWG-E005.")
#
# Variables in this section control optional features of the build system.
#