TUT HEVC Encoder
Loading...
Searching...
No Matches
Macros | Functions | Variables
rdo.c File Reference
#include "rdo.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "cabac.h"
#include "context.h"
#include "encode_coding_tree.h"
#include "encoder.h"
#include "imagelist.h"
#include "inter.h"
#include "scalinglist.h"
#include "strategyselector.h"
#include "tables.h"
#include "transform.h"
#include "strategies/strategies-quant.h"
Include dependency graph for rdo.c:

Macros

#define QUANT_SHIFT   14
 
#define SCAN_SET_SIZE   16
 
#define LOG2_SCAN_SET_SIZE   4
 
#define SBH_THRESHOLD   4
 
#define RD_SAMPLING_MAX_LAST_QP   50
 
#define RD_SAMPLING_MAX_FN_LENGTH   4095
 
#define COEF_REMAIN_BIN_REDUCTION   3
 
#define PRECISION_INC   (15 - CTX_FRAC_BITS)
 

Functions

int kvz_init_rdcost_outfiles (const char *dir_path)
 
static double get_coeff_cabac_cost (const encoder_state_t *const state, const coeff_t *coeff, int32_t width, int32_t type, int8_t scan_mode)
 Calculate actual (or really close to actual) bitcost for coding coefficients.
 
static void save_ccc (int qp, const coeff_t *coeff, int32_t size, double ccc)
 
static void save_accuracy (int qp, double ccc, double fast_cost)
 
double kvz_get_coeff_cost (const encoder_state_t *const state, const coeff_t *coeff, int32_t width, int32_t type, int8_t scan_mode)
 Estimate bitcost for coding coefficients.
 
int32_t kvz_get_ic_rate (encoder_state_t *const state, uint32_t abs_level, uint16_t ctx_num_one, uint16_t ctx_num_abs, uint16_t abs_go_rice, uint32_t c1_idx, uint32_t c2_idx, int8_t type)
 Calculates the cost for specific absolute transform level.
 
uint32_t kvz_get_coded_level (encoder_state_t *const state, double *coded_cost, double *coded_cost0, double *coded_cost_sig, int32_t level_double, uint32_t max_abs_level, uint16_t ctx_num_sig, uint16_t ctx_num_one, uint16_t ctx_num_abs, uint16_t abs_go_rice, uint32_t c1_idx, uint32_t c2_idx, int32_t q_bits, double temp, int8_t last, int8_t type)
 Get the best level in RD sense.
 
static double get_rate_last (const encoder_state_t *const state, const uint32_t pos_x, const uint32_t pos_y, int32_t *last_x_bits, int32_t *last_y_bits)
 Calculates the cost of signaling the last significant coefficient in the block.
 
static void calc_last_bits (encoder_state_t *const state, int32_t width, int32_t height, int8_t type, int32_t *last_x_bits, int32_t *last_y_bits)
 
void kvz_rdoq_sign_hiding (const encoder_state_t *const state, const int32_t qp_scaled, const uint32_t *const scan2raster, const struct kvz_sh_rates_t *const sh_rates, const int32_t last_pos, const coeff_t *const coeffs, coeff_t *const quant_coeffs)
 Select which coefficient to change for sign hiding, and change it.
 
void kvz_rdoq (encoder_state_t *const state, coeff_t *coef, coeff_t *dest_coeff, int32_t width, int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth)
 RDOQ with CABAC.
 
double kvz_get_mvd_coding_cost_cabac (const encoder_state_t *state, const cabac_data_t *cabac, const int32_t mvd_hor, const int32_t mvd_ver)
 Calculate cost of actual motion vectors using CABAC coding.
 
double kvz_calc_mvd_cost_cabac (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)
 MVD cost calculation with CABAC.
 
void kvz_close_rdcost_outfiles (void)
 

Variables

static FILEfastrd_learning_outfile [50+1] = {NULL}
 
static pthread_mutex_t outfile_mutex [50+1]
 
const uint32_t kvz_g_go_rice_range [5] = { 7, 14, 26, 46, 78 }
 
const uint32_t kvz_g_go_rice_prefix_len [5] = { 8, 7, 6, 5, 4 }
 
const uint32_t kvz_entropy_bits [128]
 Entropy bits to estimate coded bits in RDO / RDOQ (From HM 12.0)
 
const float kvz_f_entropy_bits [128]
 

Macro Definition Documentation

◆ COEF_REMAIN_BIN_REDUCTION

#define COEF_REMAIN_BIN_REDUCTION   3

◆ LOG2_SCAN_SET_SIZE

#define LOG2_SCAN_SET_SIZE   4

◆ PRECISION_INC

#define PRECISION_INC   (15 - CTX_FRAC_BITS)

◆ QUANT_SHIFT

#define QUANT_SHIFT   14

◆ RD_SAMPLING_MAX_FN_LENGTH

#define RD_SAMPLING_MAX_FN_LENGTH   4095

◆ RD_SAMPLING_MAX_LAST_QP

#define RD_SAMPLING_MAX_LAST_QP   50

◆ SBH_THRESHOLD

#define SBH_THRESHOLD   4

◆ SCAN_SET_SIZE

#define SCAN_SET_SIZE   16

Function Documentation

◆ calc_last_bits()

static void calc_last_bits ( encoder_state_t *const  state,
int32_t  width,
int32_t  height,
int8_t  type,
int32_t last_x_bits,
int32_t last_y_bits 
)
static
Here is the caller graph for this function:

◆ get_coeff_cabac_cost()

static double get_coeff_cabac_cost ( const encoder_state_t *const  state,
const coeff_t coeff,
int32_t  width,
int32_t  type,
int8_t  scan_mode 
)
inlinestatic
Parameters
coeffcoefficient array
widthcoeff block width
typedata type (0 == luma)
Returns
bits needed to code input coefficients
Here is the caller graph for this function:

◆ get_rate_last()

static double get_rate_last ( const encoder_state_t *const  state,
const uint32_t  pos_x,
const uint32_t  pos_y,
int32_t last_x_bits,
int32_t last_y_bits 
)
static
Parameters
pos_xX coordinate of the last significant coefficient
pos_yY coordinate of the last significant coefficient
Returns
cost of last significant coefficient
Parameters
uiWidthwidth of the transform unit (TU)

From HM 12.0

Here is the caller graph for this function:

◆ kvz_calc_mvd_cost_cabac()

double kvz_calc_mvd_cost_cabac ( 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 
)
Returns
int Calculates Motion Vector cost and related costs using CABAC coding
Here is the call graph for this function:

◆ kvz_close_rdcost_outfiles()

void kvz_close_rdcost_outfiles ( void  )
Here is the caller graph for this function:

◆ kvz_get_coded_level()

uint32_t kvz_get_coded_level ( encoder_state_t *const  state,
double coded_cost,
double coded_cost0,
double coded_cost_sig,
int32_t  level_double,
uint32_t  max_abs_level,
uint16_t  ctx_num_sig,
uint16_t  ctx_num_one,
uint16_t  ctx_num_abs,
uint16_t  abs_go_rice,
uint32_t  c1_idx,
uint32_t  c2_idx,
int32_t  q_bits,
double  temp,
int8_t  last,
int8_t  type 
)
inline
Parameters
coded_costreference to coded cost
coded_cost0reference to cost when coefficient is 0
coded_cost_sigreference to cost of significant coefficient
level_doublereference to unscaled quantized level
max_abs_levelscaled quantized level
ctx_num_sigcurrent ctxInc for coeff_abs_significant_flag
ctx_num_onecurrent ctxInc for coeff_abs_level_greater1 (1st bin of coeff_abs_level_minus1 in AVC)
ctx_num_abscurrent ctxInc for coeff_abs_level_greater2 (remaining bins of coeff_abs_level_minus1 in AVC)
abs_go_ricecurrent Rice parameter for coeff_abs_level_minus3
q_bitsquantization step size
tempcorrection factor
lastindicates if the coefficient is the last significant
Returns
best quantized transform level for given scan position This method calculates the best quantized transform level for a given scan position. From HM 12.0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_get_coeff_cost()

double kvz_get_coeff_cost ( const encoder_state_t *const  state,
const coeff_t coeff,
int32_t  width,
int32_t  type,
int8_t  scan_mode 
)
Parameters
coeffcoefficient array
widthcoeff block width
typedata type (0 == luma)
Returns
number of bits needed to code coefficients
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_get_ic_rate()

int32_t kvz_get_ic_rate ( encoder_state_t *const  state,
uint32_t  abs_level,
uint16_t  ctx_num_one,
uint16_t  ctx_num_abs,
uint16_t  abs_go_rice,
uint32_t  c1_idx,
uint32_t  c2_idx,
int8_t  type 
)
inline
Parameters
abs_levelscaled quantized level
ctx_num_onecurrent ctxInc for coeff_abs_level_greater1 (1st bin of coeff_abs_level_minus1 in AVC)
ctx_num_abscurrent ctxInc for coeff_abs_level_greater2 (remaining bins of coeff_abs_level_minus1 in AVC)
abs_go_riceRice parameter for coeff_abs_level_minus3
Returns
cost of given absolute transform level From HM 12.0
Here is the caller graph for this function:

◆ kvz_get_mvd_coding_cost_cabac()

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

◆ kvz_init_rdcost_outfiles()

int kvz_init_rdcost_outfiles ( const char dir_path)
Here is the caller graph for this function:

◆ kvz_rdoq()

void kvz_rdoq ( encoder_state_t *const  state,
coeff_t coef,
coeff_t dest_coeff,
int32_t  width,
int32_t  height,
int8_t  type,
int8_t  scan_mode,
int8_t  block_type,
int8_t  tr_depth 
)
Returns
void Rate distortion optimized quantization for entropy coding engines using probability models like CABAC From HM 12.0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_rdoq_sign_hiding()

void kvz_rdoq_sign_hiding ( const encoder_state_t *const  state,
const int32_t  qp_scaled,
const uint32_t *const  scan2raster,
const struct kvz_sh_rates_t *const  sh_rates,
const int32_t  last_pos,
const coeff_t *const  coeffs,
coeff_t *const  quant_coeffs 
)

When sign hiding is enabled, the last sign bit of the last coefficient is calculated from the parity of the other coefficients. If the parity is not correct, one coefficient has to be changed by one. This function uses tables generated during RDOQ to select the best coefficient to change.

Here is the caller graph for this function:

◆ save_accuracy()

static void save_accuracy ( int  qp,
double  ccc,
double  fast_cost 
)
inlinestatic
Here is the caller graph for this function:

◆ save_ccc()

static void save_ccc ( int  qp,
const coeff_t coeff,
int32_t  size,
double  ccc 
)
inlinestatic
Here is the caller graph for this function:

Variable Documentation

◆ fastrd_learning_outfile

FILE* fastrd_learning_outfile[50+1] = {NULL}
static

◆ kvz_entropy_bits

const uint32_t kvz_entropy_bits[128]
Initial value:
=
{
0x08000, 0x08000, 0x076da, 0x089a0, 0x06e92, 0x09340, 0x0670a, 0x09cdf, 0x06029, 0x0a67f, 0x059dd, 0x0b01f, 0x05413, 0x0b9bf, 0x04ebf, 0x0c35f,
0x049d3, 0x0ccff, 0x04546, 0x0d69e, 0x0410d, 0x0e03e, 0x03d22, 0x0e9de, 0x0397d, 0x0f37e, 0x03619, 0x0fd1e, 0x032ee, 0x106be, 0x02ffa, 0x1105d,
0x02d37, 0x119fd, 0x02aa2, 0x1239d, 0x02836, 0x12d3d, 0x025f2, 0x136dd, 0x023d1, 0x1407c, 0x021d2, 0x14a1c, 0x01ff2, 0x153bc, 0x01e2f, 0x15d5c,
0x01c87, 0x166fc, 0x01af7, 0x1709b, 0x0197f, 0x17a3b, 0x0181d, 0x183db, 0x016d0, 0x18d7b, 0x01595, 0x1971b, 0x0146c, 0x1a0bb, 0x01354, 0x1aa5a,
0x0124c, 0x1b3fa, 0x01153, 0x1bd9a, 0x01067, 0x1c73a, 0x00f89, 0x1d0da, 0x00eb7, 0x1da79, 0x00df0, 0x1e419, 0x00d34, 0x1edb9, 0x00c82, 0x1f759,
0x00bda, 0x200f9, 0x00b3c, 0x20a99, 0x00aa5, 0x21438, 0x00a17, 0x21dd8, 0x00990, 0x22778, 0x00911, 0x23118, 0x00898, 0x23ab8, 0x00826, 0x24458,
0x007ba, 0x24df7, 0x00753, 0x25797, 0x006f2, 0x26137, 0x00696, 0x26ad7, 0x0063f, 0x27477, 0x005ed, 0x27e17, 0x0059f, 0x287b6, 0x00554, 0x29156,
0x0050e, 0x29af6, 0x004cc, 0x2a497, 0x0048d, 0x2ae35, 0x00451, 0x2b7d6, 0x00418, 0x2c176, 0x003e2, 0x2cb15, 0x003af, 0x2d4b5, 0x0037f, 0x2de55
}

◆ kvz_f_entropy_bits

const float kvz_f_entropy_bits[128]

◆ kvz_g_go_rice_prefix_len

const uint32_t kvz_g_go_rice_prefix_len[5] = { 8, 7, 6, 5, 4 }

◆ kvz_g_go_rice_range

const uint32_t kvz_g_go_rice_range[5] = { 7, 14, 26, 46, 78 }

◆ outfile_mutex

pthread_mutex_t outfile_mutex[50+1]
static