From 16d13ed0462113b72c428dd5f4ce2e4ccb410b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Fri, 18 Mar 2016 15:14:15 +0200 Subject: [PATCH] Move cost field out of cu_info_t.inter The cost is only needed for the currently searched CU. --- src/cu.h | 1 - src/search_inter.c | 21 ++++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cu.h b/src/cu.h index 28976148..d3e38871 100644 --- a/src/cu.h +++ b/src/cu.h @@ -134,7 +134,6 @@ typedef struct int8_t tr_skip; //!< \brief transform skip flag } intra[4]; struct { - double cost; uint32_t bitcost; int16_t mv[2][2]; // \brief Motion vectors for L0 and L1 int16_t mvd[2][2]; // \brief Motion vector differences for L0 and L1 diff --git a/src/search_inter.c b/src/search_inter.c index 8c493628..c52e3c05 100644 --- a/src/search_inter.c +++ b/src/search_inter.c @@ -1092,7 +1092,8 @@ static void search_pu_inter_ref(encoder_state_t * const state, inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS], int16_t num_cand, unsigned ref_idx, - uint32_t(*get_mvd_cost)(encoder_state_t * const, vector2d_t *, cabac_data_t*)) + uint32_t(*get_mvd_cost)(encoder_state_t * const, vector2d_t *, cabac_data_t*), + double *inter_cost) { const int x_cu = x >> 3; const int y_cu = y >> 3; @@ -1248,7 +1249,9 @@ static void search_pu_inter_ref(encoder_state_t * const state, mvd.x = mv.x - mv_cand[cu_mv_cand][0]; mvd.y = mv.y - mv_cand[cu_mv_cand][1]; - if(temp_cost < cur_cu->inter.cost) { + if (temp_cost < *inter_cost) { + + *inter_cost = temp_cost; // Map reference index to L0/L1 pictures cur_cu->inter.mv_dir = ref_list+1; @@ -1261,7 +1264,6 @@ static void search_pu_inter_ref(encoder_state_t * const state, cur_cu->inter.mv[ref_list][1] = (int16_t)mv.y; cur_cu->inter.mvd[ref_list][0] = (int16_t)mvd.x; cur_cu->inter.mvd[ref_list][1] = (int16_t)mvd.y; - cur_cu->inter.cost = temp_cost; cur_cu->inter.bitcost = temp_bitcost + cur_cu->inter.mv_dir - 1 + cur_cu->inter.mv_ref_coded[ref_list]; cur_cu->inter.mv_cand[ref_list] = cu_mv_cand; } @@ -1339,7 +1341,7 @@ static int search_pu_inter(encoder_state_t * const state, cur_cu->inter.mv_cand[0] = 0; cur_cu->inter.mv_cand[1] = 0; - cur_cu->inter.cost = INT_MAX; + double inter_cost = INT_MAX; uint32_t ref_idx; for (ref_idx = 0; ref_idx < state->global->ref->used_size; ref_idx++) { @@ -1350,7 +1352,8 @@ static int search_pu_inter(encoder_state_t * const state, lcu, cur_cu, mv_cand, merge_cand, num_cand, ref_idx, - get_mvd_cost); + get_mvd_cost, + &inter_cost); } // Search bi-pred positions @@ -1427,7 +1430,7 @@ static int search_pu_inter(encoder_state_t * const state, cost += calc_mvd(state, merge_cand[i].mv[0][0], merge_cand[i].mv[0][1], 0, mv_cand, merge_cand, 0, ref_idx, &bitcost[0]); cost += calc_mvd(state, merge_cand[i].mv[1][0], merge_cand[i].mv[1][1], 0, mv_cand, merge_cand, 0, ref_idx, &bitcost[1]); - if (cost < cur_cu->inter.cost) { + if (cost < inter_cost) { cur_cu->inter.mv_dir = 3; cur_cu->inter.mv_ref_coded[0] = state->global->refmap[merge_cand[i].ref[0]].idx; @@ -1484,7 +1487,7 @@ static int search_pu_inter(encoder_state_t * const state, cur_cu->inter.mvd[reflist][1] = cur_cu->inter.mv[reflist][1] - mv_cand[cu_mv_cand][1]; cur_cu->inter.mv_cand[reflist] = cu_mv_cand; } - cur_cu->inter.cost = cost; + inter_cost = cost; cur_cu->inter.bitcost = bitcost[0] + bitcost[1] + cur_cu->inter.mv_dir - 1 + cur_cu->inter.mv_ref_coded[0] + cur_cu->inter.mv_ref_coded[1]; } } @@ -1493,14 +1496,14 @@ static int search_pu_inter(encoder_state_t * const state, FREE_POINTER(templcu); } - if (cur_cu->inter.cost < INT_MAX) { + if (inter_cost < INT_MAX) { const vector2d_t orig = { x, y }; if (cur_cu->inter.mv_dir == 1) { assert(fracmv_within_tile(state, &orig, cur_cu->inter.mv[0][0], cur_cu->inter.mv[0][1], width, height, -1)); } } - return cur_cu->inter.cost; + return inter_cost; }