resize-refactor: Change resizing process with helpers
Adds three new helpers and changes one other. The intention of this is
to make the triggering and function of resizing simpler. The new process
is to resize to the next state and then update the current state to
match. The new helpers reflect this change and make the overall flow
simpler.
resize_pending is now a helper instead of a member, so it doesn't need
to be raised manually. A resize is pending when the numerator or
denominator of the next resize state is different from the current one.
resize_pending could be 1 (scale down), 0 (no change), or -1 (return to
original resolution if 1-pass CBR), but now it can only be 1 or 0. To
return to the original resolution just set the scale to 1:1. This
reduces complexity with no change in functionality.
resize_unscaled just returns 1 if the current numerator and denominator
are equal. This makes some if conditions cleaner.
resize_step makes the current scale equal to the next scale. This
signifies that a resize is complete and will cause resize_pending to be
false until the next state is changed. This is the end of the new
resizing procedure.
av1_calculate_coded_size has been changed to calculate the next size
instead of the current size. The current state can't be updated until
the resize is complete because if it were, the resize_pending state
would drop and the resize wouldn't finish. This just means the next
resolution is the target resolution until the resize is complete.
Change-Id: I5d5855cc83f532d3a8b1f8853ba70a0d43221fbf
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index efca371..4552c67 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -1081,8 +1081,7 @@
}
// Modify active_best_quality for downscaled normal frames.
- if (cpi->resize_scale_num != cpi->resize_scale_den &&
- !frame_is_kf_gf_arf(cpi)) {
+ if (!av1_resize_unscaled(cpi) && !frame_is_kf_gf_arf(cpi)) {
int qdelta = av1_compute_qdelta_by_rate(
rc, cm->frame_type, active_best_quality, 2.0, cm->bit_depth);
active_best_quality =
@@ -1164,9 +1163,8 @@
rc->this_frame_target = target;
- // Modify frame size target when down-scaling.
- if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC &&
- cpi->resize_scale_num != cpi->resize_scale_den)
+ // Modify frame size target when down-scaled.
+ if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC && !av1_resize_unscaled(cpi))
rc->this_frame_target =
(int)(rc->this_frame_target * av1_resize_rate_factor(cpi));
@@ -1231,7 +1229,6 @@
void av1_rc_postencode_update(AV1_COMP *cpi, uint64_t bytes_used) {
const AV1_COMMON *const cm = &cpi->common;
- const AV1EncoderConfig *const oxcf = &cpi->oxcf;
RATE_CONTROL *const rc = &cpi->rc;
const int qindex = cm->base_qindex;
@@ -1323,15 +1320,6 @@
rc->frames_since_key++;
rc->frames_to_key--;
}
-
- // Trigger the resizing of the next frame if it is scaled.
- if (oxcf->pass != 0) {
- cpi->resize_pending =
- (cpi->resize_next_scale_num != cpi->resize_scale_num ||
- cpi->resize_next_scale_den != cpi->resize_scale_den);
- cpi->resize_scale_num = cpi->resize_next_scale_num;
- cpi->resize_scale_den = cpi->resize_next_scale_den;
- }
}
void av1_rc_postencode_update_drop_frame(AV1_COMP *cpi) {