Implement WebM RC VBR TPL QP override For ext_rc, allow overriding the base layer QP using TPL frame decisions when TPL QP mode is enabled. Change-Id: Ibd426dfe865541f78f2bb15358099632c2f46324
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c index 3842190..626e574 100644 --- a/av1/encoder/encoder.c +++ b/av1/encoder/encoder.c
@@ -3476,6 +3476,18 @@ // q. if (encode_frame_decision.q_index != AOM_DEFAULT_Q) { q = encode_frame_decision.q_index; +#if !CONFIG_REALTIME_ONLY + // This pass sends tpl stats to ext_rc. Use libaom's own Q. + if (av1_use_tpl_for_extrc(&cpi->ext_ratectrl) && + cpi->ppi->tpl_data.tpl_frame[cpi->gf_frame_index].is_valid && + !is_lossless_requested(&cpi->oxcf.rc_cfg)) { + q = av1_tpl_get_q_index(&cpi->ppi->tpl_data, cpi->gf_frame_index, + cpi->ppi->p_rc.base_layer_qp, + cm->seq_params->bit_depth); + q = clamp(q, cpi->oxcf.rc_cfg.best_allowed_q, + cpi->oxcf.rc_cfg.worst_allowed_q); + } +#endif } }
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c index ba54d55..218c596 100644 --- a/av1/encoder/tpl_model.c +++ b/av1/encoder/tpl_model.c
@@ -2136,6 +2136,29 @@ int extended_frame_count = init_gop_frames_for_tpl( cpi, frame_params, gf_group, &tpl_gf_group_frames, &pframe_qindex); + if (av1_encode_for_extrc(&cpi->ext_ratectrl)) { + // Find the maximum QP for this GOP from ext_rc. Use it as the base qp. + int max_q = 0; + for (int frame_idx = 0; frame_idx < gf_group->size; ++frame_idx) { + aom_rc_encodeframe_decision_t encode_frame_decision; + + int use_delta_q = 0; + encode_frame_decision.use_delta_q = &use_delta_q; + encode_frame_decision.sb_params_list = NULL; + if (av1_extrc_get_encodeframe_decision(&cpi->ext_ratectrl, frame_idx, + &encode_frame_decision) == + AOM_CODEC_OK) { + if (encode_frame_decision.q_index != AOM_DEFAULT_Q && + encode_frame_decision.q_index > max_q) { + max_q = encode_frame_decision.q_index; + } + } + } + if (max_q > 0) { + pframe_qindex = max_q; + } + } + cpi->ppi->p_rc.base_layer_qp = pframe_qindex; av1_init_tpl_stats(tpl_data);
diff --git a/test/ext_ratectrl_test.cc b/test/ext_ratectrl_test.cc index 57944d9..5f22d77 100644 --- a/test/ext_ratectrl_test.cc +++ b/test/ext_ratectrl_test.cc
@@ -259,6 +259,7 @@ protected: ExtRateCtrlQpTest() { rc_funcs_.get_encodeframe_decision = mock_get_encodeframe_decision_const_q; + rc_funcs_.send_tpl_gop_stats = nullptr; } ~ExtRateCtrlQpTest() override = default; @@ -295,6 +296,7 @@ rc_funcs_.rc_type = AOM_RC_QP; rc_funcs_.get_encodeframe_decision = mock_get_encodeframe_decision_const_q; rc_funcs_.update_encodeframe_result = mock_update_encodeframe_result; + rc_funcs_.send_tpl_gop_stats = nullptr; } ~ExtRateCtrlUpdateEncodeFrameResultTest() override = default;