[jccr] cmdline option

This commit is contained in:
Joose Sainio 2021-08-16 15:39:14 +03:00
parent 042b5078d8
commit 29d86aea84
8 changed files with 46 additions and 36 deletions

View file

@ -23,7 +23,7 @@ AC_CONFIG_SRCDIR([src/encmain.c])
#
# Here is a somewhat sane guide to lib versioning: http://apr.apache.org/versioning.html
ver_major=6
ver_minor=5
ver_minor=6
ver_release=0
# Prevents configure from adding a lot of defines to the CFLAGS

View file

@ -181,9 +181,6 @@ int kvz_config_init(kvz_config *cfg)
cfg->fastrd_accuracy_check_on = 0;
cfg->fastrd_learning_outdir_fn = NULL;
int8_t in[] = { 17, 27, 32, 44 };
int8_t out[] = { 17, 29, 34, 41 };
cfg->chroma_scale_out[0][0] = cfg->chroma_scale_in[0][0] = 17;
cfg->chroma_scale_out[0][1] = cfg->chroma_scale_in[0][1] = 27;
cfg->chroma_scale_out[0][2] = cfg->chroma_scale_in[0][2] = 32;
@ -195,6 +192,8 @@ int kvz_config_init(kvz_config *cfg)
parse_qp_map(cfg, 0);
cfg->jccr = 0;
return 1;
}
@ -1823,6 +1822,11 @@ int kvz_config_validate(const kvz_config *const cfg)
}
}
if(cfg->jccr && cfg->rdo < 2) {
fprintf(stderr, "RDO level 2 minimum required to enable joint coding of chroma residuals.\n");
error = 1;
}
return !error;
}

View file

@ -162,6 +162,8 @@ static const struct option long_options[] = {
{ "fastrd-outdir", required_argument, NULL, 0 },
{ "chroma-qp-in", required_argument, NULL, 0 },
{ "chroma-qp-out", required_argument, NULL, 0 },
{ "jccr", no_argument, NULL, 0 },
{ "no-jccr", no_argument, NULL, 0 },
{0, 0, 0, 0}
};
@ -613,6 +615,8 @@ void print_help(void)
" - both: MTS applied for both intra and inter blocks.\n"
" - implicit: uses implicit MTS. Applies DST7 instead \n"
" of DCT2 to certain intra blocks.\n"
" --(no-)jccr : Joint coding of chroma residual. "
" Requires rdo> = 2. [disabled]\n"
"\n"
/* Word wrap to this width to stay under 80 characters (including ") *************/
"Parallel processing:\n"

View file

@ -380,16 +380,6 @@ static void encode_transform_unit(encoder_state_t * const state,
int8_t scan_idx = kvz_get_scan_order(cur_pu->type, cur_pu->intra.mode, depth);
if (state->encoder_control->chroma_format != KVZ_CSP_400) {
// joint_cb_cr
/*
if (type == 2 && cbf_mask) {
cabac->cur_ctx = &(cabac->ctx.joint_cb_cr[0]);
CABAC_BIN(cabac, 0, "joint_cb_cr");
}
*/
}
int cbf_y = cbf_is_set(cur_pu->cbf, depth, COLOR_Y);
if (cbf_y && !only_chroma) {
@ -580,7 +570,7 @@ static void encode_transform_coeff(encoder_state_t * const state,
state->must_code_qp_delta = false;
}
if((cb_flag_u || cb_flag_v ) && (depth != 4 || only_chroma)) {
if((cb_flag_u || cb_flag_v ) && (depth != 4 || only_chroma) && state->encoder_control->cfg.jccr) {
cabac->cur_ctx = &cabac->ctx.joint_cb_cr[cb_flag_u * 2 + cb_flag_v - 1];
CABAC_BIN(cabac, cur_pu->joint_cb_cr != 0, "tu_joint_cbcr_residual_flag");
}

View file

@ -614,7 +614,7 @@ static void encoder_state_write_bitstream_seq_parameter_set(bitstream_t* stream,
if (encoder->chroma_format != KVZ_CSP_400) {
WRITE_U(stream, 1, 1, "sps_joint_cbcr_enabled_flag");
WRITE_U(stream, encoder->cfg.jccr, 1, "sps_joint_cbcr_enabled_flag");
WRITE_U(stream, 1, 1, "same_qp_table_for_chroma");
for (int i = 0; i < encoder->cfg.num_used_table; i++) {
@ -1266,7 +1266,7 @@ void kvz_encoder_state_write_bitstream_slice_header(
}
if (true /*sps_joint_cbcr_enabled*/) {
if (encoder->cfg.jccr) {
WRITE_U(stream, 0, 1, "ph_joint_cbcr_sign_flag");
}

View file

@ -29,7 +29,6 @@
#include <stdint.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -490,6 +489,8 @@ typedef struct kvz_config
int8_t chroma_scale_in[3][17];
int8_t chroma_scale_out[3][17];
int8_t jccr;
} kvz_config;
/**

View file

@ -80,7 +80,7 @@ static INLINE void copy_cu_pixels(int x_local, int y_local, int width, lcu_t *fr
}
}
static INLINE void copy_cu_coeffs(int x_local, int y_local, int width, lcu_t *from, lcu_t *to)
static INLINE void copy_cu_coeffs(int x_local, int y_local, int width, lcu_t *from, lcu_t *to, bool joint)
{
const int luma_z = xy_to_zorder(LCU_WIDTH, x_local, y_local);
copy_coeffs(&from->coeff.y[luma_z], &to->coeff.y[luma_z], width);
@ -89,19 +89,23 @@ static INLINE void copy_cu_coeffs(int x_local, int y_local, int width, lcu_t *fr
const int chroma_z = xy_to_zorder(LCU_WIDTH_C, x_local >> 1, y_local >> 1);
copy_coeffs(&from->coeff.u[chroma_z], &to->coeff.u[chroma_z], width >> 1);
copy_coeffs(&from->coeff.v[chroma_z], &to->coeff.v[chroma_z], width >> 1);
if (joint) {
copy_coeffs(&from->coeff.joint_uv[chroma_z], &to->coeff.joint_uv[chroma_z], width >> 1);
}
}
}
/**
* Copy all non-reference CU data from next level to current level.
*/
static void work_tree_copy_up(int x_local, int y_local, int depth, lcu_t *work_tree)
static void work_tree_copy_up(int x_local, int y_local, int depth, lcu_t *work_tree, bool joint)
{
const int width = LCU_WIDTH >> depth;
copy_cu_info (x_local, y_local, width, &work_tree[depth + 1], &work_tree[depth]);
copy_cu_pixels(x_local, y_local, width, &work_tree[depth + 1], &work_tree[depth]);
copy_cu_coeffs(x_local, y_local, width, &work_tree[depth + 1], &work_tree[depth]);
if(joint) {
copy_cu_coeffs(x_local, y_local, width, &work_tree[depth + 1], &work_tree[depth], joint);
}
}
@ -357,6 +361,7 @@ double kvz_cu_rd_cost_chroma(const encoder_state_t *const state,
width);
ssd = ssd_u + ssd_v;
if(state->encoder_control->cfg.jccr) {
int ssd_u_joint = kvz_pixels_calc_ssd(&lcu->ref.u[index], &lcu->rec.joint_u[index],
LCU_WIDTH_C, LCU_WIDTH_C,
width);
@ -365,6 +370,7 @@ double kvz_cu_rd_cost_chroma(const encoder_state_t *const state,
width);
joint_ssd = ssd_u_joint + ssd_v_joint;
}
}
{
int8_t scan_order = kvz_get_scan_order(pred_cu->type, pred_cu->intra.mode_chroma, depth);
@ -373,16 +379,17 @@ double kvz_cu_rd_cost_chroma(const encoder_state_t *const state,
coeff_bits += kvz_get_coeff_cost(state, &lcu->coeff.u[index], width, 2, scan_order, 0);
coeff_bits += kvz_get_coeff_cost(state, &lcu->coeff.v[index], width, 2, scan_order, 0);
// TODO: Check Joint CBCR cost
if(state->encoder_control->cfg.jccr) {
joint_coeff_bits += kvz_get_coeff_cost(state, &lcu->coeff.joint_uv[index], width, 2, scan_order, 0);
}
}
double bits = tr_tree_bits + coeff_bits;
double joint_bits = tr_tree_bits + joint_coeff_bits;
double cost = (double)ssd + bits * state->c_lambda;
double joint_cost = (double)joint_ssd + joint_bits * state->c_lambda;
if ((cost < joint_cost || !pred_cu->joint_cb_cr) && false) {
if ((cost < joint_cost || !pred_cu->joint_cb_cr) || !state->encoder_control->cfg.jccr) {
pred_cu->joint_cb_cr = 0;
return cost;
}
@ -849,7 +856,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
if (split_cost < cost) {
// Copy split modes to this depth.
cost = split_cost;
work_tree_copy_up(x_local, y_local, depth, work_tree);
work_tree_copy_up(x_local, y_local, depth, work_tree, state->encoder_control->cfg.jccr);
#if KVZ_DEBUG
//debug_split = 1;
#endif
@ -1062,5 +1069,7 @@ void kvz_search_lcu(encoder_state_t * const state, const int x, const int y, con
copy_coeffs(work_tree[0].coeff.y, coeff->y, LCU_WIDTH);
copy_coeffs(work_tree[0].coeff.u, coeff->u, LCU_WIDTH_C);
copy_coeffs(work_tree[0].coeff.v, coeff->v, LCU_WIDTH_C);
if (state->encoder_control->cfg.jccr) {
copy_coeffs(work_tree[0].coeff.joint_uv, coeff->joint_uv, LCU_WIDTH_C);
}
}

View file

@ -539,7 +539,9 @@ void kvz_quantize_lcu_residual(encoder_state_t * const state,
if (chroma) {
quantize_tr_residual(state, COLOR_U, x, y, depth, cur_pu, lcu, early_skip);
quantize_tr_residual(state, COLOR_V, x, y, depth, cur_pu, lcu, early_skip);
if(state->encoder_control->cfg.jccr){
quantize_tr_residual(state, COLOR_UV, x, y, depth, cur_pu, lcu, early_skip);
}
}
}
}