TUT HEVC Encoder
|
#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"
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | kvz_close_rdcost_outfiles (void) |
Variables | |
static FILE * | fastrd_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) More... | |
const float | kvz_f_entropy_bits [128] |
#define COEF_REMAIN_BIN_REDUCTION 3 |
#define LOG2_SCAN_SET_SIZE 4 |
#define PRECISION_INC (15 - CTX_FRAC_BITS) |
#define QUANT_SHIFT 14 |
#define RD_SAMPLING_MAX_FN_LENGTH 4095 |
#define RD_SAMPLING_MAX_LAST_QP 50 |
#define SBH_THRESHOLD 4 |
#define SCAN_SET_SIZE 16 |
|
static |
|
inlinestatic |
coeff | coefficient array |
width | coeff block width |
type | data type (0 == luma) |
|
static |
pos_x | X coordinate of the last significant coefficient |
pos_y | Y coordinate of the last significant coefficient |
uiWidth | width of the transform unit (TU) |
From HM 12.0
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 | ||
) |
void kvz_close_rdcost_outfiles | ( | void | ) |
|
inline |
coded_cost | reference to coded cost |
coded_cost0 | reference to cost when coefficient is 0 |
coded_cost_sig | reference to cost of significant coefficient |
level_double | reference to unscaled quantized level |
max_abs_level | scaled quantized level |
ctx_num_sig | current ctxInc for coeff_abs_significant_flag |
ctx_num_one | current ctxInc for coeff_abs_level_greater1 (1st bin of coeff_abs_level_minus1 in AVC) |
ctx_num_abs | current ctxInc for coeff_abs_level_greater2 (remaining bins of coeff_abs_level_minus1 in AVC) |
abs_go_rice | current Rice parameter for coeff_abs_level_minus3 |
q_bits | quantization step size |
temp | correction factor |
last | indicates if the coefficient is the last significant |
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 | ||
) |
coeff | coefficient array |
width | coeff block width |
type | data type (0 == luma) |
|
inline |
abs_level | scaled quantized level |
ctx_num_one | current ctxInc for coeff_abs_level_greater1 (1st bin of coeff_abs_level_minus1 in AVC) |
ctx_num_abs | current ctxInc for coeff_abs_level_greater2 (remaining bins of coeff_abs_level_minus1 in AVC) |
abs_go_rice | Rice parameter for coeff_abs_level_minus3 |
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 | ||
) |
int kvz_init_rdcost_outfiles | ( | const char * | dir_path | ) |
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 | ||
) |
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.
|
inlinestatic |
|
inlinestatic |
|
static |
const uint32_t kvz_entropy_bits[128] |
const float kvz_f_entropy_bits[128] |
const uint32_t kvz_g_go_rice_prefix_len[5] = { 8, 7, 6, 5, 4 } |
const uint32_t kvz_g_go_rice_range[5] = { 7, 14, 26, 46, 78 } |
|
static |