From 0f8f422ad6ada5a8e24a27be8f8aae43ffeb03c5 Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Sun, 25 Jul 2021 20:19:17 +0300 Subject: [PATCH] [alf] use correct lcu index with wpp and use proper cabac context for alf search --- src/alf.c | 3 ++- src/encoder_state-bitstream.c | 2 +- src/encoderstate.c | 15 ++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/alf.c b/src/alf.c index 16116b79..7a71573f 100644 --- a/src/alf.c +++ b/src/alf.c @@ -1644,7 +1644,8 @@ static void encode_alf_aps(encoder_state_t * const state) { const encoder_control_t * const encoder = state->encoder_control; bitstream_t * const stream = &state->stream; - if (encoder->cfg.alf_type) // && (state->slice->alf->tile_group_alf_enabled_flag[COMPONENT_Y] || state->slice->alf->tile_group_cc_alf_cb_enabled_flag || state->slice->alf->tile_group_cc_alf_cr_enabled_flag)) + + if (encoder->cfg.alf_type && (state->slice->alf->tile_group_alf_enabled_flag[COMPONENT_Y] || state->slice->alf->tile_group_cc_alf_cb_enabled_flag || state->slice->alf->tile_group_cc_alf_cr_enabled_flag)) { param_set_map *aps_map = state->tile->frame->alf_param_set_map; for (int aps_id = 0; aps_id < ALF_CTB_MAX_NUM_APS; aps_id++) diff --git a/src/encoder_state-bitstream.c b/src/encoder_state-bitstream.c index a4394b95..2552cc58 100644 --- a/src/encoder_state-bitstream.c +++ b/src/encoder_state-bitstream.c @@ -703,7 +703,7 @@ static void encoder_state_write_bitstream_seq_parameter_set(bitstream_t* stream, WRITE_U(stream, 0, 1, "sps_palette_enabled_flag"); if (encoder->cfg.trskip_enable /* || pcSPS->getPLTMode()*/) { - WRITE_UE(stream, MIN_QP_PRIME_TS, "sps_min_qp_prime_ts"); + WRITE_UE(stream, 0, "sps_internal_bit_depth_minus_input_bit_depth"); } WRITE_U(stream, 0, 1, "sps_ibc_enabled_flag"); diff --git a/src/encoderstate.c b/src/encoderstate.c index 33c6fafb..9092778e 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -695,7 +695,7 @@ static void encoder_state_worker_encode_lcu_bitstream(void * opaque) } //Encode ALF - kvz_encode_alf_bits(state, lcu->index); + kvz_encode_alf_bits(state, lcu->position.y * frame->width_in_lcu + lcu->position.x); //Encode coding tree kvz_encode_coding_tree(state, lcu->position.x * LCU_WIDTH, lcu->position.y * LCU_WIDTH, 0, lcu->coeff); @@ -1615,12 +1615,17 @@ void kvz_encode_one_frame(encoder_state_t * const state, kvz_picture* frame) if (state->frame->num == 0) kvz_cabac_bins_verbose = true; else kvz_cabac_bins_verbose = false; #endif - // Create a separate job for ALF done after everything else, and only then do final bitstream writing (for ALF parameters) - if (state->encoder_control->cfg.alf_type && state->encoder_control->cfg.wpp) { - state->tqj_alf_process = kvz_threadqueue_job_create(kvz_alf_enc_process_job, state); - } + encoder_state_init_new_frame(state, frame); + + // Create a separate job for ALF done after everything else, and only then do final bitstream writing (for ALF parameters) + if (state->encoder_control->cfg.alf_type && state->encoder_control->cfg.wpp) { + encoder_state_t* child_state = state; + while (child_state->lcu_order == NULL) child_state = &child_state->children[0]; + state->tqj_alf_process = kvz_threadqueue_job_create(kvz_alf_enc_process_job, child_state); + } + encoder_state_encode(state); threadqueue_job_t *job =