Commit dfd72323 authored by Jingning Han's avatar Jingning Han
Browse files

Refactor lv-map rate cost estimation

Use the rate cost to replace the probability fetch. This improves
the encoding speed of level map by 10%. No coding stats change.

Change-Id: Iab0beac5da291eed50f657549667d4edffb4ead8
parent 7496d66d
...@@ -63,6 +63,17 @@ typedef struct macroblock_plane { ...@@ -63,6 +63,17 @@ typedef struct macroblock_plane {
typedef int av1_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] typedef int av1_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][COEFF_CONTEXTS]
[TAIL_TOKENS]; [TAIL_TOKENS];
#if CONFIG_LV_MAP
typedef struct {
int txb_skip_cost[TXB_SKIP_CONTEXTS][2];
int nz_map_cost[SIG_COEF_CONTEXTS][2];
int eob_cost[EOB_COEF_CONTEXTS][2];
int dc_sign_cost[DC_SIGN_CONTEXTS][2];
int base_cost[NUM_BASE_LEVELS][COEFF_BASE_CONTEXTS][2];
int lps_cost[LEVEL_CONTEXTS][2];
} LV_MAP_COEFF_COST;
#endif
typedef struct { typedef struct {
int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
int16_t mode_context[MODE_CTX_REF_FRAMES]; int16_t mode_context[MODE_CTX_REF_FRAMES];
...@@ -163,6 +174,10 @@ struct macroblock { ...@@ -163,6 +174,10 @@ struct macroblock {
int skip_chroma_rd; int skip_chroma_rd;
#endif #endif
#if CONFIG_LV_MAP
LV_MAP_COEFF_COST coeff_costs[TX_SIZES][PLANE_TYPES];
#endif
av1_coeff_cost token_head_costs[TX_SIZES]; av1_coeff_cost token_head_costs[TX_SIZES];
av1_coeff_cost token_tail_costs[TX_SIZES]; av1_coeff_cost token_tail_costs[TX_SIZES];
......
...@@ -4872,6 +4872,10 @@ void av1_encode_tile(AV1_COMP *cpi, ThreadData *td, int tile_row, ...@@ -4872,6 +4872,10 @@ void av1_encode_tile(AV1_COMP *cpi, ThreadData *td, int tile_row,
av1_setup_across_tile_boundary_info(cm, tile_info); av1_setup_across_tile_boundary_info(cm, tile_info);
#if CONFIG_LV_MAP
av1_fill_coeff_costs(&td->mb, cm->fc);
#endif
for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end; for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end;
mi_row += cm->mib_size) { mi_row += cm->mib_size) {
encode_rd_sb_row(cpi, td, this_tile, mi_row, &tok); encode_rd_sb_row(cpi, td, this_tile, mi_row, &tok);
......
This diff is collapsed.
...@@ -430,6 +430,41 @@ void av1_set_mvcost(MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame, int ref, ...@@ -430,6 +430,41 @@ void av1_set_mvcost(MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame, int ref,
x->nmvjointcost = x->nmv_vec_cost[nmv_ctx]; x->nmvjointcost = x->nmv_vec_cost[nmv_ctx];
} }
#if CONFIG_LV_MAP
static void get_rate_cost(aom_prob p, int cost[2]) {
cost[0] = av1_cost_bit(p, 0);
cost[1] = av1_cost_bit(p, 1);
}
void av1_fill_coeff_costs(MACROBLOCK *x, FRAME_CONTEXT *fc) {
for (TX_SIZE tx_size = 0; tx_size < TX_SIZES; ++tx_size) {
for (int plane = 0; plane < PLANE_TYPES; ++plane) {
LV_MAP_COEFF_COST *pcost = &x->coeff_costs[tx_size][plane];
for (int ctx = 0; ctx < TXB_SKIP_CONTEXTS; ++ctx)
get_rate_cost(fc->txb_skip[tx_size][ctx], pcost->txb_skip_cost[ctx]);
for (int ctx = 0; ctx < SIG_COEF_CONTEXTS; ++ctx)
get_rate_cost(fc->nz_map[tx_size][plane][ctx], pcost->nz_map_cost[ctx]);
for (int ctx = 0; ctx < EOB_COEF_CONTEXTS; ++ctx)
get_rate_cost(fc->eob_flag[tx_size][plane][ctx], pcost->eob_cost[ctx]);
for (int ctx = 0; ctx < DC_SIGN_CONTEXTS; ++ctx)
get_rate_cost(fc->dc_sign[plane][ctx], pcost->dc_sign_cost[ctx]);
for (int layer = 0; layer < NUM_BASE_LEVELS; ++layer)
for (int ctx = 0; ctx < COEFF_BASE_CONTEXTS; ++ctx)
get_rate_cost(fc->coeff_base[tx_size][plane][layer][ctx],
pcost->base_cost[layer][ctx]);
for (int ctx = 0; ctx < LEVEL_CONTEXTS; ++ctx)
get_rate_cost(fc->coeff_lps[tx_size][plane][ctx], pcost->lps_cost[ctx]);
}
}
}
#endif
void av1_fill_token_costs_from_cdf(av1_coeff_cost *cost, void av1_fill_token_costs_from_cdf(av1_coeff_cost *cost,
coeff_cdf_model (*cdf)[PLANE_TYPES]) { coeff_cdf_model (*cdf)[PLANE_TYPES]) {
for (int tx = 0; tx < TX_SIZES; ++tx) { for (int tx = 0; tx < TX_SIZES; ++tx) {
......
...@@ -712,6 +712,10 @@ int av1_get_intra_cost_penalty(int qindex, int qdelta, ...@@ -712,6 +712,10 @@ int av1_get_intra_cost_penalty(int qindex, int qdelta,
void av1_fill_mode_rates(AV1_COMMON *const cm, MACROBLOCK *x, void av1_fill_mode_rates(AV1_COMMON *const cm, MACROBLOCK *x,
FRAME_CONTEXT *fc); FRAME_CONTEXT *fc);
#if CONFIG_LV_MAP
void av1_fill_coeff_costs(MACROBLOCK *x, FRAME_CONTEXT *fc);
#endif
void av1_fill_token_costs_from_cdf(av1_coeff_cost *cost, void av1_fill_token_costs_from_cdf(av1_coeff_cost *cost,
coeff_cdf_model (*cdf)[PLANE_TYPES]); coeff_cdf_model (*cdf)[PLANE_TYPES]);
......
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