TUT HEVC Encoder
Data Structures | Functions
search_inter.c File Reference
#include "search_inter.h"
#include <limits.h>
#include <stdlib.h>
#include "cabac.h"
#include "encoder.h"
#include "encode_coding_tree.h"
#include "image.h"
#include "imagelist.h"
#include "inter.h"
#include "kvazaar.h"
#include "rdo.h"
#include "search.h"
#include "strategies/strategies-ipol.h"
#include "strategies/strategies-picture.h"
#include "transform.h"
#include "videoframe.h"
Include dependency graph for search_inter.c:

Data Structures

struct  inter_search_info_t
 

Functions

static bool fracmv_within_tile (const inter_search_info_t *info, int x, int y)
 
static bool intmv_within_tile (const inter_search_info_t *info, int x, int y)
 
static bool check_mv_cost (inter_search_info_t *info, int x, int y, double *best_cost, double *best_bits, vector2d_t *best_mv)
 Calculate cost for an integer motion vector. More...
 
static unsigned get_ep_ex_golomb_bitcost (unsigned symbol)
 
static bool mv_in_merge (const inter_search_info_t *info, vector2d_t mv)
 Checks if mv is one of the merge candidates. More...
 
static void select_starting_point (inter_search_info_t *info, vector2d_t extra_mv, double *best_cost, double *best_bits, vector2d_t *best_mv)
 Select starting point for integer motion estimation search. More...
 
static double get_mvd_coding_cost (const encoder_state_t *state, const cabac_data_t *cabac, const int32_t mvd_hor, const int32_t mvd_ver)
 
static int select_mv_cand (const encoder_state_t *state, int16_t mv_cand[2][2], int32_t mv_x, int32_t mv_y, double *cost_out)
 
static double calc_mvd_cost (const encoder_state_t *state, int x, int y, int mv_shift, int16_t mv_cand[2][2], inter_merge_cand_t merge_cand[5], int16_t num_cand, int32_t ref_idx, double *bitcost)
 
static bool early_terminate (inter_search_info_t *info, double *best_cost, double *best_bits, vector2d_t *best_mv)
 
void kvz_tz_pattern_search (inter_search_info_t *info, unsigned pattern_type, const int iDist, vector2d_t mv, int *best_dist, double *best_cost, double *best_bits, vector2d_t *best_mv)
 
void kvz_tz_raster_search (inter_search_info_t *info, int iSearchRange, int iRaster, double *best_cost, double *best_bits, vector2d_t *best_mv)
 
static void tz_search (inter_search_info_t *info, vector2d_t extra_mv, double *best_cost, double *best_bits, vector2d_t *best_mv)
 
static void hexagon_search (inter_search_info_t *info, vector2d_t extra_mv, uint32_t steps, double *best_cost, double *best_bits, vector2d_t *best_mv)
 Do motion search using the HEXBS algorithm. More...
 
static void diamond_search (inter_search_info_t *info, vector2d_t extra_mv, uint32_t steps, double *best_cost, double *best_bits, vector2d_t *best_mv)
 Do motion search using the diamond algorithm. More...
 
static void search_mv_full (inter_search_info_t *info, int32_t search_range, vector2d_t extra_mv, double *best_cost, double *best_bits, vector2d_t *best_mv)
 
static void search_frac (inter_search_info_t *info, double *best_cost, double *best_bits, vector2d_t *best_mv)
 Do fractional motion estimation. More...
 
int kvz_get_skip_context (int x, int y, lcu_t *const lcu, cu_array_t *const cu_a)
 
static int16_t get_scaled_mv (int16_t mv, int scale)
 Calculate the scaled MV. More...
 
static void apply_mv_scaling (int32_t current_poc, int32_t current_ref_poc, int32_t neighbor_poc, int32_t neighbor_ref_poc, vector2d_t *mv_cand)
 Scale the MV according to the POC difference. More...
 
static void search_pu_inter_ref (inter_search_info_t *info, int depth, lcu_t *lcu, cu_info_t *cur_cu, unit_stats_map_t *amvp)
 Perform inter search for a single reference frame. More...
 
static void search_pu_inter_bipred (inter_search_info_t *info, int depth, lcu_t *lcu, unit_stats_map_t *amvp_bipred)
 Search bipred modes for a PU. More...
 
static bool merge_candidate_in_list (inter_merge_cand_t *all_cands, inter_merge_cand_t *cand_to_add, unit_stats_map_t *merge)
 Check if an identical merge candidate exists in a list. More...
 
static void search_pu_inter (encoder_state_t *const state, int x_cu, int y_cu, int depth, part_mode_t part_mode, int i_pu, lcu_t *lcu, unit_stats_map_t *amvp, unit_stats_map_t *merge, inter_search_info_t *info)
 Collect PU parameters and costs at this depth. More...
 
void kvz_cu_cost_inter_rd2 (encoder_state_t *const state, int x, int y, int depth, cu_info_t *cur_cu, lcu_t *lcu, double *inter_cost, double *inter_bitcost)
 Calculate inter coding cost for luma and chroma CBs (–rd=2 accuracy). More...
 
void kvz_search_cu_inter (encoder_state_t *const state, int x, int y, int depth, lcu_t *lcu, double *inter_cost, double *inter_bitcost)
 Update CU to have best modes at this depth. More...
 
void kvz_search_cu_smp (encoder_state_t *const state, int x, int y, int depth, part_mode_t part_mode, lcu_t *lcu, double *inter_cost, double *inter_bitcost)
 Update CU to have best modes at this depth. More...
 

Function Documentation

◆ apply_mv_scaling()

static void apply_mv_scaling ( int32_t  current_poc,
int32_t  current_ref_poc,
int32_t  neighbor_poc,
int32_t  neighbor_ref_poc,
vector2d_t mv_cand 
)
static
Parameters
current_pocPOC of current frame
current_ref_pocPOC of reference frame
neighbor_pocPOC of neighbor frame
neighbor_ref_pocPOC of neighbors reference frame
mv_candMV candidates to scale
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calc_mvd_cost()

static double calc_mvd_cost ( const encoder_state_t state,
int  x,
int  y,
int  mv_shift,
int16_t  mv_cand[2][2],
inter_merge_cand_t  merge_cand[5],
int16_t  num_cand,
int32_t  ref_idx,
double *  bitcost 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_mv_cost()

static bool check_mv_cost ( inter_search_info_t info,
int  x,
int  y,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
static

Updates best_mv, best_cost and best_bitcost to the new motion vector if it yields a lower cost than the current one.

If the motion vector violates the MV constraints for tiles or WPP, the cost is not set.

Returns
true if best_mv was changed, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ diamond_search()

static void diamond_search ( inter_search_info_t info,
vector2d_t  extra_mv,
uint32_t  steps,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
static
Parameters
infosearch info
extra_mvextra motion vector to check
stepshow many steps are done at maximum before exiting

Motion vector is searched by searching iteratively with a diamond-shaped pattern. We take care of not checking the direction we came from, but further checking for avoiding visits to already visited points is not done.

If a non 0,0 predicted motion vector predictor is given as extra_mv, the 0,0 vector is also tried. This is hoped to help in the case where the predicted motion vector is way off. In the future even more additional points like 0,0 might be used, such as vectors from top or left.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ early_terminate()

static bool early_terminate ( inter_search_info_t info,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fracmv_within_tile()

static bool fracmv_within_tile ( const inter_search_info_t info,
int  x,
int  y 
)
inlinestatic
Returns
True if referred block is within current tile.
Here is the caller graph for this function:

◆ get_ep_ex_golomb_bitcost()

static unsigned get_ep_ex_golomb_bitcost ( unsigned  symbol)
static
Here is the caller graph for this function:

◆ get_mvd_coding_cost()

static double get_mvd_coding_cost ( const encoder_state_t state,
const cabac_data_t cabac,
const int32_t  mvd_hor,
const int32_t  mvd_ver 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_scaled_mv()

static int16_t get_scaled_mv ( int16_t  mv,
int  scale 
)
inlinestatic
Here is the caller graph for this function:

◆ hexagon_search()

static void hexagon_search ( inter_search_info_t info,
vector2d_t  extra_mv,
uint32_t  steps,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
static
Parameters
infosearch info
extra_mvextra motion vector to check
stepshow many steps are done at maximum before exiting, does not affect the final step

Motion vector is searched by first searching iteratively with the large hexagon pattern until the best match is at the center of the hexagon. As a final step a smaller hexagon is used to check the adjacent pixels.

If a non 0,0 predicted motion vector predictor is given as extra_mv, the 0,0 vector is also tried. This is hoped to help in the case where the predicted motion vector is way off. In the future even more additional points like 0,0 might be used, such as vectors from top or left.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intmv_within_tile()

static bool intmv_within_tile ( const inter_search_info_t info,
int  x,
int  y 
)
inlinestatic
Returns
True if referred block is within current tile.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_cu_cost_inter_rd2()

void kvz_cu_cost_inter_rd2 ( encoder_state_t *const  state,
int  x,
int  y,
int  depth,
cu_info_t cur_cu,
lcu_t lcu,
double *  inter_cost,
double *  inter_bitcost 
)

Calculate inter coding cost of each CB. This should match the intra coding cost calculation that is used on this RDO accuracy, since CU type decision is based on this.

The cost includes SSD distortion, transform unit tree bits and motion vector bits for both luma and chroma if enabled.

Parameters
stateencoder state
xx-coordinate of the CU
yy-coordinate of the CU
depthdepth of the CU in the quadtree
lcucontaining LCU
inter_costReturn inter cost
inter_bitcostReturn inter bitcost
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_get_skip_context()

int kvz_get_skip_context ( int  x,
int  y,
lcu_t *const  lcu,
cu_array_t *const  cu_a 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_search_cu_inter()

void kvz_search_cu_inter ( encoder_state_t *const  state,
int  x,
int  y,
int  depth,
lcu_t lcu,
double *  inter_cost,
double *  inter_bitcost 
)

Only searches the 2Nx2N partition mode.

Parameters
stateencoder state
xx-coordinate of the CU
yy-coordinate of the CU
depthdepth of the CU in the quadtree
lcucontaining LCU
inter_costReturn inter cost
inter_bitcostReturn inter bitcost
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_search_cu_smp()

void kvz_search_cu_smp ( encoder_state_t *const  state,
int  x,
int  y,
int  depth,
part_mode_t  part_mode,
lcu_t lcu,
double *  inter_cost,
double *  inter_bitcost 
)

Only searches the given partition mode.

Parameters
stateencoder state
xx-coordinate of the CU
yy-coordinate of the CU
depthdepth of the CU in the quadtree
part_modepartition mode to search
lcucontaining LCU
inter_costReturn inter cost
inter_bitcostReturn inter bitcost
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_tz_pattern_search()

void kvz_tz_pattern_search ( inter_search_info_t info,
unsigned  pattern_type,
const int  iDist,
vector2d_t  mv,
int *  best_dist,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_tz_raster_search()

void kvz_tz_raster_search ( inter_search_info_t info,
int  iSearchRange,
int  iRaster,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ merge_candidate_in_list()

static bool merge_candidate_in_list ( inter_merge_cand_t all_cands,
inter_merge_cand_t cand_to_add,
unit_stats_map_t merge 
)
static
Parameters
all_candFull list of available merge candidates
cand_to_addMerge candidate to be checked for duplicates
added_idx_listList of indices of unique merge candidates
list_sizeSize of the list
Returns
Does an identical candidate exist in list
Here is the caller graph for this function:

◆ mv_in_merge()

static bool mv_in_merge ( const inter_search_info_t info,
vector2d_t  mv 
)
static
Returns
true if found else return false
Here is the caller graph for this function:

◆ search_frac()

static void search_frac ( inter_search_info_t info,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
static

Algoritm first searches 1/2-pel positions around integer mv and after best match is found, refines the search by searching best 1/4-pel postion around best 1/2-pel position.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_mv_full()

static void search_mv_full ( inter_search_info_t info,
int32_t  search_range,
vector2d_t  extra_mv,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_pu_inter()

static void search_pu_inter ( encoder_state_t *const  state,
int  x_cu,
int  y_cu,
int  depth,
part_mode_t  part_mode,
int  i_pu,
lcu_t lcu,
unit_stats_map_t amvp,
unit_stats_map_t merge,
inter_search_info_t info 
)
static
Parameters
stateencoder state
x_cux-coordinate of the containing CU
y_cuy-coordinate of the containing CU
depthdepth of the CU in the quadtree
part_modepartition mode of the CU
i_puindex of the PU in the CU
lcucontaining LCU
amvpReturn searched AMVP PUs sorted by costs
mergeReturn searched Merge PUs sorted by costs
Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_pu_inter_bipred()

static void search_pu_inter_bipred ( inter_search_info_t info,
int  depth,
lcu_t lcu,
unit_stats_map_t amvp_bipred 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_pu_inter_ref()

static void search_pu_inter_ref ( inter_search_info_t info,
int  depth,
lcu_t lcu,
cu_info_t cur_cu,
unit_stats_map_t amvp 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ select_mv_cand()

static int select_mv_cand ( const encoder_state_t state,
int16_t  mv_cand[2][2],
int32_t  mv_x,
int32_t  mv_y,
double *  cost_out 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ select_starting_point()

static void select_starting_point ( inter_search_info_t info,
vector2d_t  extra_mv,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
static

Checks the zero vector, extra_mv and merge candidates and updates best_mv to the best one.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tz_search()

static void tz_search ( inter_search_info_t info,
vector2d_t  extra_mv,
double *  best_cost,
double *  best_bits,
vector2d_t best_mv 
)
static
Here is the call graph for this function:
Here is the caller graph for this function: