Commit 4ceb066d authored by Jingning Han's avatar Jingning Han

Account DRL in the motion vector coding

This commit makes the motion vector coding context account for the
dynamic motion vector predictor index.

Change-Id: I86fc98668130140118458c773b3dd6d3ed4bc448
parent ac8cdc8c
......@@ -39,7 +39,7 @@ typedef struct mv32 {
typedef struct candidate_mv {
int_mv this_mv;
int_mv comp_mv;
int_mv pred_mv;
int_mv pred_mv[2];
int weight;
} CANDIDATE_MV;
#endif
......
......@@ -35,7 +35,7 @@ static uint8_t add_ref_mv_candidate(
// Add a new item to the list.
if (index == *refmv_count) {
ref_mv_stack[index].this_mv = this_refmv;
ref_mv_stack[index].pred_mv =
ref_mv_stack[index].pred_mv[0] =
get_sub_block_pred_mv(candidate_mi, ref, col, block);
ref_mv_stack[index].weight = 2 * len;
++(*refmv_count);
......@@ -57,7 +57,7 @@ static uint8_t add_ref_mv_candidate(
// Add a new item to the list.
if (index == *refmv_count) {
ref_mv_stack[index].this_mv = this_refmv;
ref_mv_stack[index].pred_mv =
ref_mv_stack[index].pred_mv[0] =
get_sub_block_pred_mv(candidate_mi, ref, col, alt_block);
ref_mv_stack[index].weight = len;
++(*refmv_count);
......@@ -89,6 +89,10 @@ static uint8_t add_ref_mv_candidate(
if (index == *refmv_count) {
ref_mv_stack[index].this_mv = this_refmv[0];
ref_mv_stack[index].comp_mv = this_refmv[1];
ref_mv_stack[index].pred_mv[0] =
get_sub_block_pred_mv(candidate_mi, 0, col, block);
ref_mv_stack[index].pred_mv[1] =
get_sub_block_pred_mv(candidate_mi, 1, col, block);
ref_mv_stack[index].weight = 2 * len;
++(*refmv_count);
......@@ -117,6 +121,10 @@ static uint8_t add_ref_mv_candidate(
if (index == *refmv_count) {
ref_mv_stack[index].this_mv = this_refmv[0];
ref_mv_stack[index].comp_mv = this_refmv[1];
ref_mv_stack[index].pred_mv[0] =
get_sub_block_pred_mv(candidate_mi, 0, col, block);
ref_mv_stack[index].pred_mv[1] =
get_sub_block_pred_mv(candidate_mi, 1, col, block);
ref_mv_stack[index].weight = len;
++(*refmv_count);
......@@ -296,7 +304,7 @@ static int add_col_ref_mv(const AV1_COMMON *cm,
if (idx == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) {
ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int;
ref_mv_stack[idx].pred_mv = prev_frame_mvs->pred_mv[ref];
ref_mv_stack[idx].pred_mv[0] = prev_frame_mvs->pred_mv[ref];
ref_mv_stack[idx].weight = 2;
++(*refmv_count);
}
......
......@@ -324,16 +324,21 @@ static INLINE void lower_mv_precision(MV *mv, int allow_hp) {
#if CONFIG_REF_MV
static INLINE int av1_nmv_ctx(const uint8_t ref_mv_count,
const CANDIDATE_MV *ref_mv_stack) {
if (ref_mv_stack[0].weight >= REF_CAT_LEVEL && ref_mv_count > 0) {
if (abs(ref_mv_stack[0].this_mv.as_mv.row -
ref_mv_stack[0].pred_mv.as_mv.row) <= 4 &&
abs(ref_mv_stack[0].this_mv.as_mv.col -
ref_mv_stack[0].pred_mv.as_mv.col) <= 4)
const CANDIDATE_MV *ref_mv_stack, int ref,
int ref_mv_idx) {
int_mv this_mv = (ref == 0) ? ref_mv_stack[ref_mv_idx].this_mv
: ref_mv_stack[ref_mv_idx].comp_mv;
if (ref_mv_stack[ref_mv_idx].weight >= REF_CAT_LEVEL && ref_mv_count > 0) {
if (abs(this_mv.as_mv.row -
ref_mv_stack[ref_mv_idx].pred_mv[ref].as_mv.row) <= 4 &&
abs(this_mv.as_mv.col -
ref_mv_stack[ref_mv_idx].pred_mv[ref].as_mv.col) <= 4)
return 2;
else
return 1;
}
return 0;
}
......
......@@ -557,8 +557,10 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
#endif
for (i = 0; i < 1 + is_compound; ++i) {
#if CONFIG_REF_MV
int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[mbmi->ref_frame[i]],
xd->ref_mv_stack[mbmi->ref_frame[i]]);
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx =
av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
mbmi->ref_mv_idx);
nmv_context_counts *const mv_counts =
counts ? &counts->mv[nmv_ctx] : NULL;
read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc[nmv_ctx],
......
......@@ -511,9 +511,10 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const MODE_INFO *mi,
if (b_mode == NEWMV) {
for (ref = 0; ref < 1 + is_compound; ++ref) {
#if CONFIG_REF_MV
int nmv_ctx =
av1_nmv_ctx(mbmi_ext->ref_mv_count[mbmi->ref_frame[ref]],
mbmi_ext->ref_mv_stack[mbmi->ref_frame[ref]]);
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type],
mbmi_ext->ref_mv_stack[rf_type], ref,
mbmi->ref_mv_idx);
const nmv_context *nmvc = &cm->fc->nmvc[nmv_ctx];
#endif
av1_encode_mv(cpi, w, &mi->bmi[j].as_mv[ref].as_mv,
......@@ -528,9 +529,10 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const MODE_INFO *mi,
int_mv ref_mv;
for (ref = 0; ref < 1 + is_compound; ++ref) {
#if CONFIG_REF_MV
int nmv_ctx =
av1_nmv_ctx(mbmi_ext->ref_mv_count[mbmi->ref_frame[ref]],
mbmi_ext->ref_mv_stack[mbmi->ref_frame[ref]]);
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type],
mbmi_ext->ref_mv_stack[rf_type], ref,
mbmi->ref_mv_idx);
const nmv_context *nmvc = &cm->fc->nmvc[nmv_ctx];
#endif
ref_mv = mbmi_ext->ref_mvs[mbmi->ref_frame[ref]][0];
......
......@@ -280,8 +280,10 @@ static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext,
const MV diff = { mvs[i].as_mv.row - ref->row,
mvs[i].as_mv.col - ref->col };
#if CONFIG_REF_MV
int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[mbmi->ref_frame[i]],
mbmi_ext->ref_mv_stack[mbmi->ref_frame[i]]);
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx =
av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type],
mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx);
nmv_context_counts *counts = &nmv_counts[nmv_ctx];
#else
nmv_context_counts *counts = nmv_counts;
......
......@@ -258,10 +258,13 @@ static void set_block_thresholds(const AV1_COMMON *cm, RD_OPT *rd) {
}
#if CONFIG_REF_MV
void av1_set_mvcost(MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame) {
void av1_set_mvcost(MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame, int ref,
int ref_mv_idx) {
MB_MODE_INFO_EXT *mbmi_ext = x->mbmi_ext;
int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[ref_frame],
mbmi_ext->ref_mv_stack[ref_frame]);
int8_t rf_type = av1_ref_frame_type(x->e_mbd.mi[0]->mbmi.ref_frame);
int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type],
mbmi_ext->ref_mv_stack[rf_type], ref, ref_mv_idx);
(void)ref_frame;
x->mvcost = x->mv_cost_stack[nmv_ctx];
x->nmvjointcost = x->nmv_vec_cost[nmv_ctx];
x->mvsadcost = x->mvcost;
......
......@@ -153,7 +153,8 @@ YV12_BUFFER_CONFIG *av1_get_scaled_ref_frame(const struct AV1_COMP *cpi,
void av1_init_me_luts(void);
#if CONFIG_REF_MV
void av1_set_mvcost(MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame);
void av1_set_mvcost(MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame, int ref,
int ref_mv_idx);
#endif
void av1_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
......
......@@ -1665,7 +1665,7 @@ static void joint_motion_search(AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
tmp_mv.row >>= 3;
#if CONFIG_REF_MV
av1_set_mvcost(x, refs[id]);
av1_set_mvcost(x, refs[id], id, mbmi->ref_mv_idx);
#endif
// Small-range full-pixel motion search.
bestsme = av1_refining_search_8p_c(x, &tmp_mv, sadpb, search_range,
......@@ -1859,7 +1859,7 @@ static int64_t rd_pick_best_sub8x8_mode(
av1_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv);
#if CONFIG_REF_MV
av1_set_mvcost(x, mbmi->ref_frame[0]);
av1_set_mvcost(x, mbmi->ref_frame[0], 0, mbmi->ref_mv_idx);
#endif
bestsme = av1_full_pixel_search(
cpi, x, bsize, &mvp_full, step_param, sadpb,
......@@ -2219,7 +2219,7 @@ static void single_motion_search(AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
av1_set_mv_search_range(x, &ref_mv);
#if CONFIG_REF_MV
av1_set_mvcost(x, ref);
av1_set_mvcost(x, ref, 0, mbmi->ref_mv_idx);
#endif
// Work out the size of the first step in the mv step search.
......
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