Commit c2c3c872 authored by Jingning Han's avatar Jingning Han

Refactor the motion field projection process

Make the motion field projection process independent of the
reference frame type syntax.

Change-Id: Ie5d024d76ddb990fe623c83b3f4b4b6fadc72d2c
parent 707f8321
......@@ -1498,98 +1498,48 @@ static int get_block_position(AV1_COMMON *cm, int *mi_r, int *mi_c, int blk_row,
return 1;
}
static uint32_t mv_sign_reverse(int_mv ref) {
int_mv this_mv;
this_mv.as_mv.row = -ref.as_mv.row;
this_mv.as_mv.col = -ref.as_mv.col;
return this_mv.as_int;
}
static void motion_field_projection(AV1_COMMON *cm,
MV_REFERENCE_FRAME ref_frame,
int ref_stamp) {
MV_REFERENCE_FRAME ref_frame, int ref_stamp,
int dir) {
TPL_MV_REF *tpl_mvs_base = cm->tpl_mvs;
int cur_rf_index[TOTAL_REFS_PER_FRAME] = { 0 };
int ref_rf_idx[TOTAL_REFS_PER_FRAME] = { 0 };
int cur_offset[TOTAL_REFS_PER_FRAME] = { 0 };
int ref_offset[TOTAL_REFS_PER_FRAME] = { 0 };
int cur_frame_index = cm->cur_frame->cur_frame_offset;
int lst_frame_index = 0, alt_frame_index = 0, gld_frame_index = 0;
int lst2_frame_index = 0, lst3_frame_index = 0;
int bwd_frame_index = 0, alt2_frame_index = 0;
int alt_buf_idx = cm->frame_refs[FWD_RF_OFFSET(ALTREF_FRAME)].idx;
int lst_buf_idx = cm->frame_refs[FWD_RF_OFFSET(LAST_FRAME)].idx;
int gld_buf_idx = cm->frame_refs[FWD_RF_OFFSET(GOLDEN_FRAME)].idx;
int lst2_buf_idx = cm->frame_refs[FWD_RF_OFFSET(LAST2_FRAME)].idx;
int lst3_buf_idx = cm->frame_refs[FWD_RF_OFFSET(LAST3_FRAME)].idx;
int bwd_buf_idx = cm->frame_refs[FWD_RF_OFFSET(BWDREF_FRAME)].idx;
int alt2_buf_idx = cm->frame_refs[FWD_RF_OFFSET(ALTREF2_FRAME)].idx;
(void)dir;
int ref_frame_idx = cm->frame_refs[FWD_RF_OFFSET(ref_frame)].idx;
if (ref_frame_idx < 0) return;
int ref_frame_index =
cm->buffer_pool->frame_bufs[ref_frame_idx].cur_frame_offset;
int cur_frame_index = cm->cur_frame->cur_frame_offset;
int ref_to_cur = ref_frame_index - cur_frame_index;
if (alt_buf_idx >= 0)
alt_frame_index = cm->buffer_pool->frame_bufs[alt_buf_idx].cur_frame_offset;
if (lst_buf_idx >= 0)
lst_frame_index = cm->buffer_pool->frame_bufs[lst_buf_idx].cur_frame_offset;
if (gld_buf_idx >= 0)
gld_frame_index = cm->buffer_pool->frame_bufs[gld_buf_idx].cur_frame_offset;
if (lst2_buf_idx >= 0)
lst2_frame_index =
cm->buffer_pool->frame_bufs[lst2_buf_idx].cur_frame_offset;
if (lst3_buf_idx >= 0)
lst3_frame_index =
cm->buffer_pool->frame_bufs[lst3_buf_idx].cur_frame_offset;
if (bwd_buf_idx >= 0)
bwd_frame_index = cm->buffer_pool->frame_bufs[bwd_buf_idx].cur_frame_offset;
if (alt2_buf_idx >= 0)
alt2_frame_index =
cm->buffer_pool->frame_bufs[alt2_buf_idx].cur_frame_offset;
MV_REF *mv_ref_base = cm->buffer_pool->frame_bufs[ref_frame_idx].mvs;
const int lst_frame_idx =
ref_rf_idx[LAST_FRAME] =
cm->buffer_pool->frame_bufs[ref_frame_idx].lst_frame_offset;
const int gld_frame_idx =
ref_rf_idx[GOLDEN_FRAME] =
cm->buffer_pool->frame_bufs[ref_frame_idx].gld_frame_offset;
const int lst2_frame_idx =
ref_rf_idx[LAST2_FRAME] =
cm->buffer_pool->frame_bufs[ref_frame_idx].lst2_frame_offset;
const int lst3_frame_idx =
ref_rf_idx[LAST3_FRAME] =
cm->buffer_pool->frame_bufs[ref_frame_idx].lst3_frame_offset;
const int bwd_frame_idx =
ref_rf_idx[BWDREF_FRAME] =
cm->buffer_pool->frame_bufs[ref_frame_idx].bwd_frame_offset;
const int alt2_frame_idx =
ref_rf_idx[ALTREF2_FRAME] =
cm->buffer_pool->frame_bufs[ref_frame_idx].alt2_frame_offset;
ref_rf_idx[ALTREF_FRAME] =
cm->buffer_pool->frame_bufs[ref_frame_idx].alt_frame_offset;
int cur_to_ref = ref_frame_index - cur_frame_index;
int lst_offset = AOMMAX(1, ref_frame_index - lst_frame_idx);
int gld_offset = AOMMAX(1, ref_frame_index - gld_frame_idx);
int cur_to_alt = alt_frame_index - cur_frame_index;
int cur_to_lst = cur_frame_index - lst_frame_index;
int cur_to_gld = cur_frame_index - gld_frame_index;
int bwd_offset = AOMMAX(1, ref_frame_index - bwd_frame_idx);
int alt2_offset = AOMMAX(1, ref_frame_index - alt2_frame_idx);
int lst2_offset = AOMMAX(1, ref_frame_index - lst2_frame_idx);
int lst3_offset = AOMMAX(1, ref_frame_index - lst3_frame_idx);
int cur_to_lst2 = cur_frame_index - lst2_frame_index;
int cur_to_lst3 = cur_frame_index - lst3_frame_index;
int cur_to_bwd = bwd_frame_index - cur_frame_index;
int cur_to_alt2 = alt2_frame_index - cur_frame_index;
// clang-format off
const int ref_frame_offset_buffer[TOTAL_REFS_PER_FRAME] = {
0, lst_offset, lst2_offset, lst3_offset, gld_offset,
bwd_offset, alt2_offset, 0,
};
// clang-format on
for (MV_REFERENCE_FRAME rf = LAST_FRAME; rf <= INTER_REFS_PER_FRAME; ++rf) {
int buf_idx = cm->frame_refs[FWD_RF_OFFSET(rf)].idx;
if (buf_idx >= 0)
cur_rf_index[rf] = cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset;
cur_offset[rf] = cur_frame_index - cur_rf_index[rf];
ref_offset[rf] = ref_frame_index - ref_rf_idx[rf];
}
MV_REF *mv_ref_base = cm->buffer_pool->frame_bufs[ref_frame_idx].mvs;
const int mvs_rows = (cm->mi_rows + 1) >> 1;
const int mvs_cols = (cm->mi_cols + 1) >> 1;
......@@ -1597,62 +1547,25 @@ static void motion_field_projection(AV1_COMMON *cm,
for (int blk_col = 0; blk_col < mvs_cols; ++blk_col) {
MV_REF *mv_ref = &mv_ref_base[blk_row * mvs_cols + blk_col];
MV fwd_mv = mv_ref->mv[0].as_mv;
MV_REFERENCE_FRAME rf[2] = { mv_ref->ref_frame[0], mv_ref->ref_frame[1] };
const int ref_frame_offset = ref_frame_offset_buffer[rf[0]];
const int ref_frame_offset = ref_offset[mv_ref->ref_frame[0]];
if (rf[0] <= GOLDEN_FRAME && rf[0] > INTRA_FRAME) {
if (mv_ref->ref_frame[0] > INTRA_FRAME) {
int_mv this_mv;
int mi_r, mi_c;
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_ref, ref_frame_offset);
get_mv_projection(&this_mv.as_mv, fwd_mv, ref_to_cur, ref_frame_offset);
int pos_valid = get_block_position(cm, &mi_r, &mi_c, blk_row, blk_col,
this_mv.as_mv, 0);
if (pos_valid) {
int mi_offset = mi_r * (cm->mi_stride >> 1) + mi_c;
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_alt,
ref_frame_offset);
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(ALTREF_FRAME)][ref_stamp]
.as_int = mv_sign_reverse(this_mv);
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_alt2,
ref_frame_offset);
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(ALTREF2_FRAME)][ref_stamp]
.as_int = mv_sign_reverse(this_mv);
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_bwd,
ref_frame_offset);
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(BWDREF_FRAME)][ref_stamp]
.as_int = mv_sign_reverse(this_mv);
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_lst,
ref_frame_offset);
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(LAST_FRAME)][ref_stamp]
.as_int = this_mv.as_int;
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_lst2,
ref_frame_offset);
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(LAST2_FRAME)][ref_stamp]
.as_int = this_mv.as_int;
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_lst3,
ref_frame_offset);
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(LAST3_FRAME)][ref_stamp]
.as_int = this_mv.as_int;
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_gld,
ref_frame_offset);
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(GOLDEN_FRAME)][ref_stamp]
.as_int = this_mv.as_int;
for (MV_REFERENCE_FRAME rf = ALTREF_FRAME; rf >= LAST_FRAME; --rf) {
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_offset[rf],
ref_frame_offset);
tpl_mvs_base[mi_offset].mfmv[FWD_RF_OFFSET(rf)][ref_stamp].as_int =
this_mv.as_int;
}
}
}
}
......@@ -1707,7 +1620,7 @@ void av1_setup_motion_field(AV1_COMMON *cm) {
cm->buffer_pool->frame_bufs[alt2_buf_idx].cur_frame_offset;
memset(cm->ref_frame_side, 0, sizeof(cm->ref_frame_side));
for (int ref_frame = LAST_FRAME; ref_frame < INTER_REFS_PER_FRAME;
for (int ref_frame = LAST_FRAME; ref_frame <= INTER_REFS_PER_FRAME;
++ref_frame) {
int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx;
int frame_index = -1;
......@@ -1855,17 +1768,17 @@ void av1_setup_motion_field(AV1_COMMON *cm) {
}
if (bwd_frame_index > cur_frame_index) {
motion_field_projection(cm, BWDREF_FRAME, ref_stamp);
motion_field_projection(cm, BWDREF_FRAME, ref_stamp, 0);
--ref_stamp;
}
if (alt2_frame_index > cur_frame_index) {
motion_field_projection(cm, ALTREF2_FRAME, ref_stamp);
motion_field_projection(cm, ALTREF2_FRAME, ref_stamp, 0);
--ref_stamp;
}
if (alt_frame_index > cur_frame_index && ref_stamp >= 0)
motion_field_projection(cm, ALTREF_FRAME, ref_stamp);
motion_field_projection(cm, ALTREF_FRAME, ref_stamp, 0);
}
#endif // CONFIG_MFMV
......
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