Commit d7246171 authored by Angie Chiang's avatar Angie Chiang
Browse files

Add helper functions to modify RD_STATS

Those functions includes
init_rd_stats()
invalid_rd_stats()
merge_rd_stats()

This CL help simplify the code.

Change-Id: Id1704d883bd21a039b0478a940994ca14184ae1c
parent 394c3377
......@@ -3067,12 +3067,11 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
txfm_partition_context(tx_above + (blk_col >> 1),
tx_left + (blk_row >> 1), mbmi->sb_type, tx_size);
int64_t sum_dist = 0, sum_bsse = 0;
int64_t sum_rd = INT64_MAX;
int sum_rate = 0;
int all_skip = 1;
int tmp_eob = 0;
int zero_blk_rate;
RD_STATS sum_rd_stats;
init_rd_stats(&sum_rd_stats);
#if CONFIG_EXT_TX
assert(tx_size < TX_SIZES);
......@@ -3085,10 +3084,7 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
coeff_ctx = get_entropy_context(tx_size, pta, ptl);
rd_stats->rate = 0;
rd_stats->dist = 0;
rd_stats->sse = 0;
rd_stats->skip = 1;
init_rd_stats(rd_stats);
if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
......@@ -3129,7 +3125,8 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
int this_cost_valid = 1;
int64_t tmp_rd = 0;
sum_rate = av1_cost_bit(cpi->common.fc->txfm_partition_prob[ctx], 1);
sum_rd_stats.rate =
av1_cost_bit(cpi->common.fc->txfm_partition_prob[ctx], 1);
#if CONFIG_EXT_TX
assert(tx_size < TX_SIZES);
#endif // CONFIG_EXT_TX
......@@ -3143,12 +3140,10 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
depth + 1, plane_bsize, ta, tl, tx_above, tx_left,
&this_rd_stats, ref_best_rd - tmp_rd, &this_cost_valid);
sum_rate += this_rd_stats.rate;
sum_dist += this_rd_stats.dist;
sum_bsse += this_rd_stats.sse;
all_skip &= this_rd_stats.skip;
merge_rd_stats(&sum_rd_stats, &this_rd_stats);
tmp_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist);
tmp_rd =
RDCOST(x->rdmult, x->rddiv, sum_rd_stats.rate, sum_rd_stats.dist);
if (this_rd < tmp_rd) break;
block += sub_step;
}
......@@ -3169,10 +3164,7 @@ static void select_tx_block(const AV1_COMP *cpi, MACROBLOCK *x, int blk_row,
if (this_rd == INT64_MAX) *is_cost_valid = 0;
x->blk_skip[plane][blk_row * bw + blk_col] = rd_stats->skip;
} else {
rd_stats->rate = sum_rate;
rd_stats->dist = sum_dist;
rd_stats->sse = sum_bsse;
rd_stats->skip = all_skip;
*rd_stats = sum_rd_stats;
if (sum_rd == INT64_MAX) *is_cost_valid = 0;
}
}
......@@ -3186,10 +3178,7 @@ static void inter_block_yrd(const AV1_COMP *cpi, MACROBLOCK *x,
if (ref_best_rd < 0) is_cost_valid = 0;
rd_stats->rate = 0;
rd_stats->dist = 0;
rd_stats->sse = 0;
rd_stats->skip = 1;
init_rd_stats(rd_stats);
if (is_cost_valid) {
const struct macroblockd_plane *const pd = &xd->plane[0];
......@@ -3208,10 +3197,7 @@ static void inter_block_yrd(const AV1_COMP *cpi, MACROBLOCK *x,
TXFM_CONTEXT tx_left[MAX_MIB_SIZE];
RD_STATS pn_rd_stats;
pn_rd_stats.rate = 0;
pn_rd_stats.skip = 1;
pn_rd_stats.dist = 0;
pn_rd_stats.sse = 0;
init_rd_stats(&pn_rd_stats);
av1_get_entropy_contexts(bsize, TX_4X4, pd, ctxa, ctxl);
memcpy(tx_above, xd->above_txfm_context,
......@@ -3225,10 +3211,7 @@ static void inter_block_yrd(const AV1_COMP *cpi, MACROBLOCK *x,
mi_height != mi_width, plane_bsize, ctxa, ctxl,
tx_above, tx_left, &pn_rd_stats, ref_best_rd - this_rd,
&is_cost_valid);
rd_stats->rate += pn_rd_stats.rate;
rd_stats->dist += pn_rd_stats.dist;
rd_stats->sse += pn_rd_stats.sse;
rd_stats->skip &= pn_rd_stats.skip;
merge_rd_stats(rd_stats, &pn_rd_stats);
this_rd += AOMMIN(
RDCOST(x->rdmult, x->rddiv, pn_rd_stats.rate, pn_rd_stats.dist),
RDCOST(x->rdmult, x->rddiv, 0, pn_rd_stats.sse));
......@@ -3243,10 +3226,7 @@ static void inter_block_yrd(const AV1_COMP *cpi, MACROBLOCK *x,
if (!is_cost_valid) {
// reset cost value
rd_stats->rate = INT_MAX;
rd_stats->dist = INT64_MAX;
rd_stats->sse = INT64_MAX;
rd_stats->skip = 0;
invalid_rd_stats(rd_stats);
}
}
......@@ -3385,17 +3365,11 @@ static void select_tx_type_yrd(const AV1_COMP *cpi, MACROBLOCK *x,
prune = prune_tx_types(cpi, bsize, x, xd, 0);
#endif
rd_stats->dist = INT64_MAX;
rd_stats->rate = INT_MAX;
rd_stats->skip = 0;
rd_stats->sse = INT64_MAX;
invalid_rd_stats(rd_stats);
for (tx_type = DCT_DCT; tx_type < TX_TYPES; ++tx_type) {
RD_STATS this_rd_stats;
this_rd_stats.rate = 0;
this_rd_stats.skip = 1;
this_rd_stats.dist = 0;
this_rd_stats.sse = 0;
init_rd_stats(&this_rd_stats);
#if CONFIG_EXT_TX
if (is_inter) {
if (!ext_tx_used_inter[ext_tx_set][tx_type]) continue;
......@@ -3512,10 +3486,7 @@ static int inter_block_uvrd(const AV1_COMP *cpi, MACROBLOCK *x,
if (ref_best_rd < 0) is_cost_valid = 0;
rd_stats->rate = 0;
rd_stats->dist = 0;
rd_stats->sse = 0;
rd_stats->skip = 1;
init_rd_stats(rd_stats);
#if CONFIG_EXT_TX && CONFIG_RECT_TX
if (is_rect_tx(mbmi->tx_size)) {
......@@ -3544,10 +3515,7 @@ static int inter_block_uvrd(const AV1_COMP *cpi, MACROBLOCK *x,
ENTROPY_CONTEXT ta[2 * MAX_MIB_SIZE];
ENTROPY_CONTEXT tl[2 * MAX_MIB_SIZE];
RD_STATS pn_rd_stats;
pn_rd_stats.rate = 0;
pn_rd_stats.skip = 1;
pn_rd_stats.dist = 0;
pn_rd_stats.sse = 0;
init_rd_stats(&pn_rd_stats);
av1_get_entropy_contexts(bsize, TX_4X4, pd, ta, tl);
......@@ -3581,10 +3549,7 @@ static int inter_block_uvrd(const AV1_COMP *cpi, MACROBLOCK *x,
if (!is_cost_valid) {
// reset cost value
rd_stats->rate = INT_MAX;
rd_stats->dist = INT64_MAX;
rd_stats->sse = INT64_MAX;
rd_stats->skip = 0;
invalid_rd_stats(rd_stats);
}
return is_cost_valid;
......
......@@ -34,6 +34,28 @@ typedef struct RD_STATS {
int64_t sse;
int skip;
} RD_STATS;
static INLINE void init_rd_stats(RD_STATS *rd_stats) {
rd_stats->rate = 0;
rd_stats->dist = 0;
rd_stats->sse = 0;
rd_stats->skip = 1;
}
static INLINE void invalid_rd_stats(RD_STATS *rd_stats) {
rd_stats->rate = INT_MAX;
rd_stats->dist = INT64_MAX;
rd_stats->sse = INT64_MAX;
rd_stats->skip = 0;
}
static INLINE void merge_rd_stats(RD_STATS *rd_stats_dst,
const RD_STATS *rd_stats_src) {
rd_stats_dst->rate += rd_stats_src->rate;
rd_stats_dst->dist += rd_stats_src->dist;
rd_stats_dst->sse += rd_stats_src->sse;
rd_stats_dst->skip &= rd_stats_src->skip;
}
#endif
int av1_cost_coeffs(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
......
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