Refactor inter TMVP selection

Merges three if-clauses to remove two levels of indentation.
This commit is contained in:
Arttu Ylä-Outinen 2017-02-21 23:56:01 +09:00
parent 85e2a40da3
commit db08041d9a

View file

@ -1086,8 +1086,16 @@ static void get_mv_cand_from_candidates(const encoder_state_t * const state,
candidates = 1;
}
// Use Temporal Motion Vector Prediction when enabled
if (state->encoder_control->cfg.tmvp_enable) {
// Use Temporal Motion Vector Prediction when enabled.
// TMVP required at least two sequential P/B-frames.
bool can_use_tmvp =
state->encoder_control->cfg.tmvp_enable &&
state->frame->poc > 1 &&
state->frame->ref->used_size &&
candidates < AMVP_MAX_NUM_CANDS &&
(h != NULL || c3 != NULL);
if (can_use_tmvp) {
/*
Predictor block locations
__________
@ -1098,20 +1106,14 @@ static void get_mv_cand_from_candidates(const encoder_state_t * const state,
|H|
*/
// TMVP required at least two sequential P/B-frames
if (state->frame->poc > 1 && state->frame->ref->used_size && candidates < AMVP_MAX_NUM_CANDS) {
// Use "H" as the primary predictor and "C3" as secondary
const cu_info_t *selected_CU = (h != NULL) ? h : (c3 != NULL) ? c3 : NULL;
const cu_info_t *selected_CU = (h != NULL) ? h : c3;
if (selected_CU) {
uint32_t colocated_ref = UINT_MAX;
int32_t colocated_ref_poc = 0;
int td, tb;
//ToDo: allow other than L0[0] for prediction
// TODO: allow other than L0[0] for prediction
//Fetch ref idx of the selected CU in L0[0] ref list
// Fetch ref idx of the selected CU in L0[0] ref list
for (int temporal_cand = 0; temporal_cand < state->frame->ref->used_size; temporal_cand++) {
if (state->frame->refmap[temporal_cand].list == 1 && state->frame->refmap[temporal_cand].idx == 0) {
colocated_ref = temporal_cand;
@ -1123,7 +1125,7 @@ static void get_mv_cand_from_candidates(const encoder_state_t * const state,
uint8_t used_reflist = reflist;
colocated_ref_poc = state->frame->ref->pocs[colocated_ref];
int32_t colocated_ref_poc = state->frame->ref->pocs[colocated_ref];
if (!(selected_CU->inter.mv_dir & (1 << used_reflist))) {
used_reflist = !reflist;
@ -1132,8 +1134,8 @@ static void get_mv_cand_from_candidates(const encoder_state_t * const state,
// The reference id the colocated block is using
uint32_t colocated_ref_mv_ref = selected_CU->inter.mv_ref[used_reflist];
td = CLIP(-128, 127, colocated_ref_poc - state->frame->ref->images[colocated_ref]->ref_pocs[colocated_ref_mv_ref]);
tb = CLIP(-128, 127, state->frame->poc - state->frame->ref->pocs[cur_cu->inter.mv_ref[reflist]]);
int td = CLIP(-128, 127, colocated_ref_poc - state->frame->ref->images[colocated_ref]->ref_pocs[colocated_ref_mv_ref]);
int tb = CLIP(-128, 127, state->frame->poc - state->frame->ref->pocs[cur_cu->inter.mv_ref[reflist]]);
if (td == tb) {
mv_cand[candidates][0] = selected_CU->inter.mv[used_reflist][0];
@ -1145,11 +1147,8 @@ static void get_mv_cand_from_candidates(const encoder_state_t * const state,
}
candidates++;
}
}
}
}
} // TMVP
// Fill with (0,0)
while (candidates < AMVP_MAX_NUM_CANDS) {