ref: 3915f0616add47d9187b679802dd757a90f2977f
parent: 4caea79ffa54719a5a10320d22b3dc6a7f84918d
parent: 48d045057d49d386371f812f66a8720500d65b1b
author: Marco Paniconi <marpan@google.com>
date: Tue Jan 15 00:05:18 EST 2019
Merge "vp9-svc: Rate control fix for key base layer"
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -1800,6 +1800,8 @@
}
}
+ if (cpi->use_svc) vp9_svc_adjust_avg_frame_qindex(cpi);
+
// Keep record of last boosted (KF/KF/ARF) Q value.
// If the current frame is coded at a lower Q then we also update it.
// If all mbs in this group are skipped only update if the Q value is
--- a/vp9/encoder/vp9_svc_layercontext.c
+++ b/vp9/encoder/vp9_svc_layercontext.c
@@ -1227,3 +1227,25 @@
cpi->svc.timebase_fac * cpi->svc.duration[cpi->svc.spatial_layer_id];
vp9_new_framerate(cpi, 10000000.0 / this_duration);
}
+
+void vp9_svc_adjust_avg_frame_qindex(VP9_COMP *const cpi) {
+ VP9_COMMON *const cm = &cpi->common;
+ SVC *const svc = &cpi->svc;
+ RATE_CONTROL *const rc = &cpi->rc;
+ // On key frames in CBR mode: reset the avg_frame_index for base layer
+ // (to level closer to worst_quality) if the overshoot is significant.
+ // Reset it for all temporal layers on base spatial layer.
+ if (cm->frame_type == KEY_FRAME && cpi->oxcf.rc_mode == VPX_CBR &&
+ rc->projected_frame_size > 3 * rc->avg_frame_bandwidth) {
+ int tl;
+ rc->avg_frame_qindex[INTER_FRAME] =
+ VPXMAX(rc->avg_frame_qindex[INTER_FRAME],
+ (cm->base_qindex + rc->worst_quality) >> 1);
+ for (tl = 0; tl < svc->number_temporal_layers; ++tl) {
+ const int layer = LAYER_IDS_TO_IDX(0, tl, svc->number_temporal_layers);
+ LAYER_CONTEXT *lc = &svc->layer_context[layer];
+ RATE_CONTROL *lrc = &lc->rc;
+ lrc->avg_frame_qindex[INTER_FRAME] = rc->avg_frame_qindex[INTER_FRAME];
+ }
+ }
+}
--- a/vp9/encoder/vp9_svc_layercontext.h
+++ b/vp9/encoder/vp9_svc_layercontext.h
@@ -262,6 +262,7 @@
void vp9_svc_adjust_frame_rate(struct VP9_COMP *const cpi);
+void vp9_svc_adjust_avg_frame_qindex(struct VP9_COMP *const cpi);
#ifdef __cplusplus
} // extern "C"
#endif