Commit 3bd1bc23 authored by Jingning Han's avatar Jingning Han
Browse files

Refactor motion field projection process

Abstract the operation for backward projection.

Change-Id: If458cfe8d2f152227565e8b58c864fd2e7824b43
parent e554f36c
......@@ -1636,6 +1636,168 @@ static uint32_t mv_sign_reverse(int_mv ref) {
return this_mv.as_int;
}
static void motion_field_projection(AV1_COMMON *cm,
MV_REFERENCE_FRAME ref_frame) {
TPL_MV_REF *tpl_mvs_base = cm->tpl_mvs;
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;
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;
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 =
cm->buffer_pool->frame_bufs[ref_frame_idx].lst_frame_offset;
const int gld_frame_idx =
cm->buffer_pool->frame_bufs[ref_frame_idx].gld_frame_offset;
const int lst2_frame_idx =
cm->buffer_pool->frame_bufs[ref_frame_idx].lst2_frame_offset;
const int lst3_frame_idx =
cm->buffer_pool->frame_bufs[ref_frame_idx].lst3_frame_offset;
const int bwd_frame_idx =
cm->buffer_pool->frame_bufs[ref_frame_idx].bwd_frame_offset;
const int alt2_frame_idx =
cm->buffer_pool->frame_bufs[ref_frame_idx].alt2_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;
const int ref_stamp = FWD_RF_OFFSET(ref_frame);
// 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
const int mvs_rows = (cm->mi_rows + 1) >> 1;
const int mvs_cols = (cm->mi_cols + 1) >> 1;
for (int blk_row = 0; blk_row < mvs_rows; ++blk_row) {
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]];
if (rf[0] <= GOLDEN_FRAME && rf[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);
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;
if (ref_frame == ALTREF_FRAME) {
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);
}
if (ref_frame >= ALTREF2_FRAME) {
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;
if (rf[0] >= LAST2_FRAME) {
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;
}
if (rf[0] >= LAST3_FRAME) {
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;
}
if (rf[0] >= GOLDEN_FRAME) {
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;
}
}
}
}
}
}
void av1_setup_motion_field(AV1_COMMON *cm) {
int cur_frame_index = cm->cur_frame->cur_frame_offset;
int lst_frame_index = 0, alt_frame_index = 0, gld_frame_index = 0;
......@@ -1807,219 +1969,9 @@ void av1_setup_motion_field(AV1_COMMON *cm) {
}
}
// =======================
// Process ARF frame
// =======================
if (alt_buf_idx >= 0) {
MV_REF *mv_ref_base = cm->buffer_pool->frame_bufs[alt_buf_idx].mvs;
const int lst_frame_idx =
cm->buffer_pool->frame_bufs[alt_buf_idx].lst_frame_offset;
const int gld_frame_idx =
cm->buffer_pool->frame_bufs[alt_buf_idx].gld_frame_offset;
const int lst2_frame_idx =
cm->buffer_pool->frame_bufs[alt_buf_idx].lst2_frame_offset;
const int lst3_frame_idx =
cm->buffer_pool->frame_bufs[alt_buf_idx].lst3_frame_offset;
const int bwd_frame_idx =
cm->buffer_pool->frame_bufs[alt_buf_idx].bwd_frame_offset;
const int alt2_frame_idx =
cm->buffer_pool->frame_bufs[alt_buf_idx].alt2_frame_offset;
motion_field_projection(cm, ALTREF_FRAME);
int lst_offset = AOMMAX(1, alt_frame_index - lst_frame_idx);
int gld_offset = AOMMAX(1, alt_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, alt_frame_index - bwd_frame_idx);
int alt2_offset = AOMMAX(1, alt_frame_index - alt2_frame_idx);
int lst2_offset = AOMMAX(1, alt_frame_index - lst2_frame_idx);
int lst3_offset = AOMMAX(1, alt_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;
const int ref_stamp = FWD_RF_OFFSET(ALTREF_FRAME);
// 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
const int mvs_rows = (cm->mi_rows + 1) >> 1;
const int mvs_cols = (cm->mi_cols + 1) >> 1;
for (int blk_row = 0; blk_row < mvs_rows; ++blk_row) {
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 ref_frame[2] = { mv_ref->ref_frame[0],
mv_ref->ref_frame[1] };
const int ref_frame_offset = ref_frame_offset_buffer[ref_frame[0]];
if (ref_frame[0] <= GOLDEN_FRAME && 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_alt,
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;
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_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_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_alt2,
ref_frame_offset);
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(ALTREF2_FRAME)][ref_stamp]
.as_int = mv_sign_reverse(this_mv);
if (ref_frame[0] >= LAST2_FRAME) {
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;
}
if (ref_frame[0] >= LAST3_FRAME) {
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;
}
if (ref_frame[0] >= GOLDEN_FRAME) {
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;
}
}
}
}
}
}
// ==========================================
// Process BWD reference frame
// ==========================================
if (bwd_buf_idx >= 0) {
MV_REF *mv_ref_base = cm->buffer_pool->frame_bufs[bwd_buf_idx].mvs;
const int lst_frame_idx =
cm->buffer_pool->frame_bufs[bwd_buf_idx].lst_frame_offset;
const int gld_frame_idx =
cm->buffer_pool->frame_bufs[bwd_buf_idx].gld_frame_offset;
const int lst2_frame_idx =
cm->buffer_pool->frame_bufs[bwd_buf_idx].lst2_frame_offset;
const int lst3_frame_idx =
cm->buffer_pool->frame_bufs[bwd_buf_idx].lst3_frame_offset;
const int bwd_frame_idx =
cm->buffer_pool->frame_bufs[bwd_buf_idx].bwd_frame_offset;
const int alt2_frame_idx =
cm->buffer_pool->frame_bufs[bwd_buf_idx].alt2_frame_offset;
const int alt_frame_idx =
cm->buffer_pool->frame_bufs[bwd_buf_idx].alt_frame_offset;
int lst_offset = AOMMAX(1, bwd_frame_index - lst_frame_idx);
int gld_offset = AOMMAX(1, bwd_frame_index - gld_frame_idx);
int cur_to_lst = cur_frame_index - lst_frame_index;
int lst2_offset = AOMMAX(1, bwd_frame_index - lst2_frame_idx);
int lst3_offset = AOMMAX(1, bwd_frame_index - lst3_frame_idx);
int bwd_offset = AOMMAX(1, bwd_frame_idx - bwd_frame_index);
int alt2_offset = AOMMAX(1, alt2_frame_idx - bwd_frame_index);
int alt_offset = AOMMAX(1, alt_frame_idx - bwd_frame_index);
int cur_to_lst2 = cur_frame_index - lst2_frame_index;
int cur_to_lst3 = cur_frame_index - lst3_frame_index;
int cur_to_gld = cur_frame_index - gld_frame_index;
int cur_to_bwd = bwd_frame_index - cur_frame_index;
const int ref_stamp = FWD_RF_OFFSET(BWDREF_FRAME);
const int ref_frame_offset_buffer[TOTAL_REFS_PER_FRAME] = {
0, lst_offset, lst2_offset, lst3_offset,
gld_offset, bwd_offset, alt2_offset, alt_offset,
};
const int mvs_rows = (cm->mi_rows + 1) >> 1;
const int mvs_cols = (cm->mi_cols + 1) >> 1;
for (int blk_row = 0; blk_row < mvs_rows; ++blk_row) {
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 ref_frame[2] = { mv_ref->ref_frame[0],
mv_ref->ref_frame[1] };
if (ref_frame[0] <= GOLDEN_FRAME && ref_frame[0] > INTRA_FRAME) {
const int ref_frame_offset = ref_frame_offset_buffer[ref_frame[0]];
int_mv this_mv;
int mi_r, mi_c;
get_mv_projection(&this_mv.as_mv, fwd_mv, cur_to_bwd,
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;
tpl_mvs_base[mi_offset]
.mfmv[FWD_RF_OFFSET(BWDREF_FRAME)][ref_stamp]
.as_int = mv_sign_reverse(this_mv);
// Project the motion vector onto last reference frame
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;
if (ref_frame[0] >= LAST2_FRAME) {
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;
}
if (ref_frame[0] >= LAST3_FRAME) {
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;
}
if (ref_frame[0] >= GOLDEN_FRAME) {
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;
}
}
}
}
}
}
motion_field_projection(cm, BWDREF_FRAME);
}
#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