Make KF_DISABLED work for rtc
Change-Id: Ie348bd1ebcfcb284ba78494c02cc55f4bc025e24
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index f4d7823..4764ed5 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -2712,7 +2712,7 @@
#endif
// Handle fixed keyframe intervals
- if (is_stat_generation_stage(ppi->cpi)) {
+ if (is_stat_generation_stage(ppi->cpi) || is_one_pass_rt_params(ppi->cpi)) {
if (ctx->cfg.kf_mode == AOM_KF_AUTO &&
ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) {
if (ppi->cpi->common.spatial_layer_id == 0 &&
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index c916eb3..9ee0c3a 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -2303,11 +2303,15 @@
av1_cyclic_refresh_set_golden_update(cpi);
else
p_rc->baseline_gf_interval = FIXED_GF_INTERVAL;
- if (p_rc->baseline_gf_interval > rc->frames_to_key)
+ if (p_rc->baseline_gf_interval > rc->frames_to_key &&
+ cpi->oxcf.kf_cfg.auto_key)
p_rc->baseline_gf_interval = rc->frames_to_key;
p_rc->gfu_boost = DEFAULT_GF_BOOST_RT;
p_rc->constrained_gf_group =
- (p_rc->baseline_gf_interval >= rc->frames_to_key) ? 1 : 0;
+ (p_rc->baseline_gf_interval >= rc->frames_to_key &&
+ cpi->oxcf.kf_cfg.auto_key)
+ ? 1
+ : 0;
rc->frames_till_gf_update_due = p_rc->baseline_gf_interval;
cpi->gf_frame_index = 0;
// SVC does not use GF as periodic boost.
@@ -2748,6 +2752,30 @@
return;
}
+static INLINE int set_key_frame(AV1_COMP *cpi, unsigned int frame_flags) {
+ RATE_CONTROL *const rc = &cpi->rc;
+ AV1_COMMON *const cm = &cpi->common;
+ SVC *const svc = &cpi->svc;
+
+ // Very first frame has to be key frame.
+ if (cm->current_frame.frame_number == 0) return 1;
+ // Set key frame if forced by frame flags.
+ if (frame_flags & FRAMEFLAGS_KEY) return 1;
+ if (!cpi->ppi->use_svc) {
+ // Non-SVC
+ if (cpi->oxcf.kf_cfg.auto_key && rc->frames_to_key == 0) return 1;
+ } else {
+ // SVC
+ if (svc->spatial_layer_id == 0 &&
+ (cpi->oxcf.kf_cfg.auto_key &&
+ (cpi->oxcf.kf_cfg.key_freq_max == 0 ||
+ svc->current_superframe % cpi->oxcf.kf_cfg.key_freq_max == 0)))
+ return 1;
+ }
+
+ return 0;
+}
+
void av1_get_one_pass_rt_params(AV1_COMP *cpi,
EncodeFrameParams *const frame_params,
unsigned int frame_flags) {
@@ -2769,11 +2797,7 @@
av1_restore_layer_context(cpi);
}
// Set frame type.
- if ((!cpi->ppi->use_svc && rc->frames_to_key == 0) ||
- (cpi->ppi->use_svc && svc->spatial_layer_id == 0 &&
- (cpi->oxcf.kf_cfg.key_freq_max == 0 ||
- svc->current_superframe % cpi->oxcf.kf_cfg.key_freq_max == 0)) ||
- (frame_flags & FRAMEFLAGS_KEY)) {
+ if (set_key_frame(cpi, frame_flags)) {
frame_params->frame_type = KEY_FRAME;
p_rc->this_key_frame_forced =
cm->current_frame.frame_number != 0 && rc->frames_to_key == 0;