summaryrefslogtreecommitdiff
path: root/vp9/encoder/vp9_ext_ratectrl.c
diff options
context:
space:
mode:
authorCheng Chen <chengchen@google.com>2022-05-13 13:42:28 -0700
committerCheng Chen <chengchen@google.com>2022-05-27 15:02:32 -0700
commit3e7685cf621af3e876274f7be9fef83e3d35de3d (patch)
treed9633825c49e5cd84a7886b780a83a2f9000f128 /vp9/encoder/vp9_ext_ratectrl.c
parent4832bcff20d34ed25a771f3704cfe0a046dbd0f9 (diff)
downloadlibvpx-3e7685cf621af3e876274f7be9fef83e3d35de3d.tar
libvpx-3e7685cf621af3e876274f7be9fef83e3d35de3d.tar.gz
libvpx-3e7685cf621af3e876274f7be9fef83e3d35de3d.tar.bz2
libvpx-3e7685cf621af3e876274f7be9fef83e3d35de3d.zip
L2E: Add vp9 GOP decision helper function
Add a helper function to call the external rate control model. The helper function is placed in the function where vp9 determines GOP decisions. The helper function passes frame information, including current frame show index, coding index, etc to the external rate control model, and then receives GOP decisions. The received GOP decisions overwrites the default GOP decision, only when the external rate control model is set to be active via the codec control. The decision should satisfy a few constraints, for example, larger than min_gf_interval; smaller than max_gf_interval. Otherwise, return error. Unit tests are added to test the new functionality. Change-Id: Id129b4e1a91c844ee5c356a7801c862b1130a3d8
Diffstat (limited to 'vp9/encoder/vp9_ext_ratectrl.c')
-rw-r--r--vp9/encoder/vp9_ext_ratectrl.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/vp9/encoder/vp9_ext_ratectrl.c b/vp9/encoder/vp9_ext_ratectrl.c
index 67f58329c..48c90913e 100644
--- a/vp9/encoder/vp9_ext_ratectrl.c
+++ b/vp9/encoder/vp9_ext_ratectrl.c
@@ -172,7 +172,7 @@ vpx_codec_err_t vp9_extrc_update_encodeframe_result(
if (ext_ratectrl == NULL) {
return VPX_CODEC_INVALID_PARAM;
}
- if (ext_ratectrl->ready && ext_ratectrl->funcs.rc_type == VPX_RC_QP) {
+ if (ext_ratectrl->ready) {
PSNR_STATS psnr;
vpx_rc_status_t rc_status;
vpx_rc_encodeframe_result_t encode_frame_result;
@@ -198,3 +198,34 @@ vpx_codec_err_t vp9_extrc_update_encodeframe_result(
}
return VPX_CODEC_OK;
}
+
+vpx_codec_err_t vp9_extrc_get_gop_decision(
+ EXT_RATECTRL *ext_ratectrl, const vpx_rc_gop_info_t *const gop_info,
+ vpx_rc_gop_decision_t *gop_decision) {
+ if (ext_ratectrl == NULL) {
+ return VPX_CODEC_INVALID_PARAM;
+ }
+ if (ext_ratectrl->ready && ext_ratectrl->funcs.rc_type == VPX_RC_GOP) {
+ vpx_rc_status_t rc_status;
+ rc_status = ext_ratectrl->funcs.get_gop_decision(ext_ratectrl->model,
+ gop_info, gop_decision);
+ if (gop_decision->use_alt_ref) {
+ const int arf_constraint =
+ gop_decision->gop_coding_frames >= gop_info->min_gf_interval &&
+ gop_decision->gop_coding_frames < gop_info->lag_in_frames;
+ if (!arf_constraint || !gop_info->allow_alt_ref) return VPX_CODEC_ERROR;
+ }
+ // TODO(chengchen): Take min and max gf interval from the model
+ // and overwrite libvpx's decision so that we can get rid
+ // of one of the checks here.
+ if (gop_decision->gop_coding_frames > gop_info->frames_to_key ||
+ gop_decision->gop_coding_frames - gop_decision->use_alt_ref >
+ gop_info->max_gf_interval) {
+ return VPX_CODEC_ERROR;
+ }
+ if (rc_status == VPX_RC_ERROR) {
+ return VPX_CODEC_ERROR;
+ }
+ }
+ return VPX_CODEC_OK;
+}