From: angiebird Date: Tue, 13 Oct 2020 00:58:16 +0000 (-0700) Subject: Add vp9_extrc_update_encodeframe_result() X-Git-Tag: v1.10.0-rc1~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8bfc92063138476dee2d719ec45bb95d16a1a38f;p=libvpx Add vp9_extrc_update_encodeframe_result() Bug: webm:1707 Change-Id: I962ffa23f03b953f7c0dfd81f49dc79d1975bbba --- diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index bf338eed8..3838a9de7 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -5479,6 +5479,13 @@ static void encode_frame_to_data_rate( // build the bitstream vp9_pack_bitstream(cpi, dest, size); + { + const RefCntBuffer *coded_frame_buf = + get_ref_cnt_buffer(cm, cm->new_fb_idx); + vp9_extrc_update_encodeframe_result(&cpi->ext_ratectrl, (*size) << 3, + cpi->Source, &coded_frame_buf->buf, + cpi->oxcf.input_bit_depth); + } #if CONFIG_REALTIME_ONLY (void)encode_frame_result; assert(encode_frame_result == NULL); @@ -7541,7 +7548,7 @@ static void update_encode_frame_result( #if CONFIG_RATE_CTRL PSNR_STATS psnr; #if CONFIG_VP9_HIGHBITDEPTH - vpx_calc_highbd_psnr(source_frame, coded_frame_buf->buf, &psnr, bit_depth, + vpx_calc_highbd_psnr(source_frame, &coded_frame_buf->buf, &psnr, bit_depth, input_bit_depth); #else // CONFIG_VP9_HIGHBITDEPTH (void)bit_depth; diff --git a/vp9/encoder/vp9_ext_ratectrl.c b/vp9/encoder/vp9_ext_ratectrl.c index 59b5c09b8..64414cd38 100644 --- a/vp9/encoder/vp9_ext_ratectrl.c +++ b/vp9/encoder/vp9_ext_ratectrl.c @@ -10,6 +10,7 @@ #include "vp9/encoder/vp9_ext_ratectrl.h" #include "vp9/common/vp9_common.h" +#include "vpx_dsp/psnr.h" void vp9_extrc_init(EXT_RATECTRL *ext_ratectrl) { vp9_zero(*ext_ratectrl); } @@ -112,3 +113,28 @@ void vp9_extrc_get_encodeframe_decision( ext_ratectrl->model, &encode_frame_info, encode_frame_decision); } } + +void vp9_extrc_update_encodeframe_result(EXT_RATECTRL *ext_ratectrl, + int64_t bit_count, + const YV12_BUFFER_CONFIG *source_frame, + const YV12_BUFFER_CONFIG *coded_frame, + uint32_t input_bit_depth) { + if (ext_ratectrl->ready) { + PSNR_STATS psnr; + vpx_rc_encodeframe_result_t encode_frame_result; + encode_frame_result.bit_count = bit_count; + encode_frame_result.pixel_count = + source_frame->y_width * source_frame->y_height + + 2 * source_frame->uv_width * source_frame->uv_height; +#if CONFIG_VP9_HIGHBITDEPTH + vpx_calc_highbd_psnr(source_frame, coded_frame, &psnr, + source_frame->bit_depth, input_bit_depth); +#else + (void)input_bit_depth; + vpx_calc_psnr(source_frame, coded_frame, &psnr); +#endif + encode_frame_result.sse = psnr.sse[0]; + ext_ratectrl->funcs.update_encodeframe_result(ext_ratectrl->model, + &encode_frame_result); + } +} diff --git a/vp9/encoder/vp9_ext_ratectrl.h b/vp9/encoder/vp9_ext_ratectrl.h index 990735ebc..82f300c3a 100644 --- a/vp9/encoder/vp9_ext_ratectrl.h +++ b/vp9/encoder/vp9_ext_ratectrl.h @@ -36,4 +36,10 @@ void vp9_extrc_get_encodeframe_decision( EXT_RATECTRL *ext_ratectrl, const GF_GROUP *gf_group, int show_index, int coding_index, vpx_rc_encodeframe_decision_t *encode_frame_decision); +void vp9_extrc_update_encodeframe_result(EXT_RATECTRL *ext_ratectrl, + int64_t bit_count, + const YV12_BUFFER_CONFIG *source_frame, + const YV12_BUFFER_CONFIG *coded_frame, + uint32_t input_bit_depth); + #endif // VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_ diff --git a/vpx/vpx_ext_ratectrl.h b/vpx/vpx_ext_ratectrl.h index 940227ac2..c99434457 100644 --- a/vpx/vpx_ext_ratectrl.h +++ b/vpx/vpx_ext_ratectrl.h @@ -133,7 +133,7 @@ typedef int (*vpx_rc_get_encodeframe_decision_cb_fn_t)( */ typedef int (*vpx_rc_update_encodeframe_result_cb_fn_t)( vpx_rc_model_t rate_ctrl_model, - vpx_rc_encodeframe_result_t *encode_frame_result); + const vpx_rc_encodeframe_result_t *encode_frame_result); /*!\brief Delete the external rate control model callback prototype *