Modularize intrabc motion vector costs in AV1_COMP
This CL groups intrabc motion vector cost related
variables from AV1_COMP into a new structure
IntraBCMVCosts and adds documentation for the same.
Change-Id: I8ff96a024dcf4a56b3ff2655017e0daa24572306
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index c0cac27..82d00cb 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -1268,9 +1268,9 @@
int internal_altref_allowed;
// A flag to indicate if intrabc is ever used in current frame.
int intrabc_used;
- int dv_cost[2][MV_VALS];
- // TODO(huisu@google.com): we can update dv_joint_cost per SB.
- int dv_joint_cost[MV_JOINTS];
+
+ // Tables to calculate IntraBC MV cost.
+ IntraBCMVCosts dv_costs;
// Mark which ref frames can be skipped for encoding current frame druing RDO.
int prune_ref_frame_mask;
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 3d13cda..e48c771 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -605,8 +605,10 @@
if (!cpi->sf.rt_sf.use_nonrd_pick_mode && frame_is_intra_only(cm) &&
cm->features.allow_screen_content_tools &&
!is_stat_generation_stage(cpi)) {
- int *dvcost[2] = { &cpi->dv_cost[0][MV_MAX], &cpi->dv_cost[1][MV_MAX] };
- av1_build_nmv_cost_table(cpi->dv_joint_cost, dvcost, &cm->fc->ndvc,
+ IntraBCMVCosts *const dv_costs = &cpi->dv_costs;
+ int *dvcost[2] = { &dv_costs->mv_component[0][MV_MAX],
+ &dv_costs->mv_component[1][MV_MAX] };
+ av1_build_nmv_cost_table(dv_costs->joint_mv, dvcost, &cm->fc->ndvc,
MV_SUBPEL_NONE);
}
diff --git a/av1/encoder/rd.h b/av1/encoder/rd.h
index 34fbe9b..1addbae 100644
--- a/av1/encoder/rd.h
+++ b/av1/encoder/rd.h
@@ -82,6 +82,20 @@
double mc_saved_base, mc_count_base;
} RD_OPT;
+typedef struct {
+ // Cost of transmitting the actual motion vector.
+ // mv_component[0][i] is the cost of motion vector with horizontal component
+ // (mv_row) equal to i - MV_MAX.
+ // mv_component[1][i] is the cost of motion vector with vertical component
+ // (mv_col) equal to i - MV_MAX.
+ int mv_component[2][MV_VALS];
+
+ // joint_mv[i] is the cost of transmitting joint mv(MV_JOINT_TYPE) of
+ // type i.
+ // TODO(huisu@google.com): we can update dv_joint_cost per SB.
+ int joint_mv[MV_JOINTS];
+} IntraBCMVCosts;
+
static INLINE void av1_init_rd_stats(RD_STATS *rd_stats) {
#if CONFIG_RD_DEBUG
int plane;
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 9f27786..02afcd1 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -2783,11 +2783,12 @@
av1_enc_build_inter_predictor(cm, xd, mi_row, mi_col, NULL, bsize, 0,
av1_num_planes(cm) - 1);
- int *dvcost[2] = { (int *)&cpi->dv_cost[0][MV_MAX],
- (int *)&cpi->dv_cost[1][MV_MAX] };
+ const IntraBCMVCosts *const dv_costs = &cpi->dv_costs;
+ int *dvcost[2] = { (int *)&dv_costs->mv_component[0][MV_MAX],
+ (int *)&dv_costs->mv_component[1][MV_MAX] };
// TODO(aconverse@google.com): The full motion field defining discount
// in MV_COST_WEIGHT is too large. Explore other values.
- const int rate_mv = av1_mv_bit_cost(&dv, &dv_ref.as_mv, cpi->dv_joint_cost,
+ const int rate_mv = av1_mv_bit_cost(&dv, &dv_ref.as_mv, dv_costs->joint_mv,
dvcost, MV_COST_WEIGHT_SUB);
const int rate_mode = x->intrabc_cost[1];
RD_STATS rd_stats_yuv, rd_stats_y, rd_stats_uv;