From 1a35c22a52e9e8f924cae04e1eff5b40bc9427bb Mon Sep 17 00:00:00 2001 From: Joose Sainio Date: Tue, 14 Jan 2020 14:46:05 +0200 Subject: [PATCH] Change clipping of lambda and qp for ctus on OBA rc instead of clipping qp and lambda to the value of last value from the state clip to previous frame with same layer and if such frame doesn't exist, clip to previous frame --- src/rate_control.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/rate_control.c b/src/rate_control.c index 9d888413..7b561325 100644 --- a/src/rate_control.c +++ b/src/rate_control.c @@ -686,6 +686,7 @@ void kvz_set_ctu_qp_lambda(encoder_state_t * const state, vector2d_t pos) { const double clip_lambda = state->frame->lambda; double clip_neighbor_lambda = -1; + int clip_qp = -1; if (encoder->cfg.clip_neighbour) { for (int temp_index = index - 1; temp_index >= ctu_limit; --temp_index) { if (state->frame->lcu_stats[temp_index].lambda > 0) { @@ -693,10 +694,27 @@ void kvz_set_ctu_qp_lambda(encoder_state_t * const state, vector2d_t pos) { break; } } + for (int temp_index = index - 1; temp_index >= ctu_limit; --temp_index) { + if (state->frame->lcu_stats[temp_index].qp > -1) { + clip_qp = state->frame->lcu_stats[temp_index].qp; + break; + } + } } else { + encoder_state_t *previous = state->previous_encoder_state; + const int layer = encoder->cfg.gop[state->frame->gop_offset].layer; + int owf = encoder->cfg.owf; + + while (layer != encoder->cfg.gop[previous->frame->gop_offset].layer && --owf) { + previous = previous->previous_encoder_state; + } + if (state->frame->lcu_stats[index].lambda > 0) { - clip_neighbor_lambda = state->frame->lcu_stats[index].lambda; + clip_neighbor_lambda = previous->frame->lcu_stats[index].lambda; + } + if (state->frame->lcu_stats[index].qp > 0) { + clip_qp = previous->frame->lcu_stats[index].qp; } } @@ -722,21 +740,6 @@ void kvz_set_ctu_qp_lambda(encoder_state_t * const state, vector2d_t pos) { est_qp = lambda_to_qp(est_lambda); - int clip_qp = -1; - if(encoder->cfg.clip_neighbour) { - for (int temp_index = index - 1; temp_index >= ctu_limit; --temp_index) { - if (state->frame->lcu_stats[temp_index].qp > -1) { - clip_qp = state->frame->lcu_stats[temp_index].qp; - break; - } - } - } - else { - if (state->frame->lcu_stats[index].qp > 0) { - clip_qp = state->frame->lcu_stats[index].qp; - } - } - if( clip_qp > -1) { est_qp = CLIP(clip_qp - 1 - frame_allocation, clip_qp + 1 + frame_allocation,