TUT HEVC Encoder
|
#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"
Data Structures | |
struct | inter_search_info_t |
Macros | |
#define | KVZ_TEMP_DOUBLE_PRECISION 0.001 |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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). | |
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. | |
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. | |
#define KVZ_TEMP_DOUBLE_PRECISION 0.001 |
|
static |
current_poc | POC of current frame |
current_ref_poc | POC of reference frame |
neighbor_poc | POC of neighbor frame |
neighbor_ref_poc | POC of neighbors reference frame |
mv_cand | MV candidates to scale |
|
static |
|
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.
|
static |
info | search info |
extra_mv | extra motion vector to check |
steps | how 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.
|
static |
|
inlinestatic |
|
static |
|
static |
|
inlinestatic |
|
static |
info | search info |
extra_mv | extra motion vector to check |
steps | how 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.
|
inlinestatic |
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.
state | encoder state |
x | x-coordinate of the CU |
y | y-coordinate of the CU |
depth | depth of the CU in the quadtree |
lcu | containing LCU |
inter_cost | Return inter cost |
inter_bitcost | Return inter bitcost |
int kvz_get_skip_context | ( | int | x, |
int | y, | ||
lcu_t *const | lcu, | ||
cu_array_t *const | cu_a ) |
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.
state | encoder state |
x | x-coordinate of the CU |
y | y-coordinate of the CU |
depth | depth of the CU in the quadtree |
lcu | containing LCU |
inter_cost | Return inter cost |
inter_bitcost | Return inter bitcost |
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.
state | encoder state |
x | x-coordinate of the CU |
y | y-coordinate of the CU |
depth | depth of the CU in the quadtree |
part_mode | partition mode to search |
lcu | containing LCU |
inter_cost | Return inter cost |
inter_bitcost | Return inter bitcost |
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 |
all_cand | Full list of available merge candidates |
cand_to_add | Merge candidate to be checked for duplicates |
added_idx_list | List of indices of unique merge candidates |
list_size | Size of the list |
|
static |
|
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.
|
static |
|
static |
state | encoder state |
x_cu | x-coordinate of the containing CU |
y_cu | y-coordinate of the containing CU |
depth | depth of the CU in the quadtree |
part_mode | partition mode of the CU |
i_pu | index of the PU in the CU |
lcu | containing LCU |
amvp | Return searched AMVP PUs sorted by costs |
merge | Return searched Merge PUs sorted by costs |
|
static |
|
static |
|
static |
|
static |
Checks the zero vector, extra_mv and merge candidates and updates best_mv to the best one.
|
static |