diff --git a/src/search.c b/src/search.c index 45167531..fe8a194e 100644 --- a/src/search.c +++ b/src/search.c @@ -1102,7 +1102,65 @@ static int search_cu_inter(const encoder_state_t * const state, int x, int y, in } // Search bi-pred positions + if (state->global->slicetype == SLICE_B) { + #define NUM_PRIORITY_LIST 12; + static const uint8_t priorityList0[] = { 0, 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3 }; + static const uint8_t priorityList1[] = { 1, 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2 }; + uint8_t cutoff = num_cand; + for (int32_t idx = 0; idx= num_cand || j >= num_cand) break; + // Find one L0 and L1 candidate according to the priority list + if ((merge_cand[i].dir & 0x1) && (merge_cand[j].dir & 0x2)) { + if (merge_cand[i].ref[0] != merge_cand[j].ref[1] || + merge_cand[i].mv[0][0] != merge_cand[j].mv[1][0] || + merge_cand[i].mv[0][1] != merge_cand[j].mv[1][1]) { + int8_t cu_mv_cand = 0; + // Force L0 and L1 references + if (state->global->refmap[merge_cand[i].ref[0]].list == 2 || state->global->refmap[merge_cand[j].ref[1]].list == 1) continue; + cur_cu->inter.mv_dir = 3; + cur_cu->inter.mv_ref_coded[0] = state->global->refmap[merge_cand[i].ref[0]].idx; + cur_cu->inter.mv_ref_coded[1] = state->global->refmap[merge_cand[j].ref[1]].idx; + + cur_cu->merged = 0; + cur_cu->inter.mv_ref[0] = merge_cand[i].ref[0]; + cur_cu->inter.mv_ref[1] = merge_cand[j].ref[1]; + cur_cu->inter.mv[0][0] = merge_cand[i].mv[0][0]; + cur_cu->inter.mv[0][1] = merge_cand[i].mv[0][1]; + cur_cu->inter.mv[1][0] = merge_cand[j].mv[1][0]; + cur_cu->inter.mv[1][1] = merge_cand[j].mv[1][1]; + + for (int reflist = 0; reflist < 2; reflist++) { + if ((mv_cand[0][0] != mv_cand[1][0] || mv_cand[0][1] != mv_cand[1][1])) { + vector2d_t mvd_temp1, mvd_temp2; + int cand1_cost, cand2_cost; + + mvd_temp1.x = cur_cu->inter.mv[reflist][0] - mv_cand[0][0]; + mvd_temp1.y = cur_cu->inter.mv[reflist][1] - mv_cand[0][1]; + cand1_cost = get_mvd_coding_cost(&mvd_temp1); + + mvd_temp2.x = cur_cu->inter.mv[reflist][0] - mv_cand[1][0]; + mvd_temp2.y = cur_cu->inter.mv[reflist][1] - mv_cand[1][1]; + cand2_cost = get_mvd_coding_cost(&mvd_temp2); + + // Select candidate 1 if it has lower cost + if (cand2_cost < cand1_cost) { + //cu_mv_cand = 1; + } + } + cur_cu->inter.mvd[reflist][0] = cur_cu->inter.mv[reflist][0] - mv_cand[cu_mv_cand][0]; + cur_cu->inter.mvd[reflist][1] = cur_cu->inter.mv[reflist][1] - mv_cand[cu_mv_cand][1]; + } + cur_cu->inter.cost = 0; + cur_cu->inter.bitcost = 10 + cur_cu->inter.mv_dir - 1 + cur_cu->inter.mv_ref_coded[0] + cur_cu->inter.mv_ref_coded[1]; + cur_cu->inter.mv_cand = cu_mv_cand; + break; + } + } + } + } return cur_cu->inter.cost; }