Fix a bug not decreasing frames_till_gf_update_due properly
If a frame is going to be dropped, it will not be shown but
since it has a space in the gf group, we still need to
decrease the counter frames_till_gf_update_due.
BUG=aomedia:1992
Change-Id: I67ff95d212e4b9f2b750f68cbc944ecbe45b0bc4
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index e713276..878fb7e 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -4728,6 +4728,12 @@
}
#endif // DUMP_RECON_FRAMES
+static INLINE int is_frame_droppable(AV1_COMP *cpi) {
+ return !(cpi->refresh_alt_ref_frame || cpi->refresh_alt2_ref_frame ||
+ cpi->refresh_bwd_ref_frame || cpi->refresh_golden_frame ||
+ cpi->refresh_last_frame);
+}
+
static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, uint8_t *dest,
int skip_adapt,
unsigned int *frame_flags) {
@@ -5097,6 +5103,19 @@
cm->seg.update_data = 0;
cm->lf.mode_ref_delta_update = 0;
+ // A droppable frame might not be shown but it always
+ // takes a space in the gf group. Therefore, even when
+ // it is not shown, we still need update the count down.
+
+ // TODO(weitinglin): This is a work-around to handle the condition
+ // when a frame is drop. We should fix the cm->show_frame flag
+ // instead of checking the other condition to update the counter properly.
+ if (cm->show_frame || is_frame_droppable(cpi)) {
+ // Decrement count down till next gf
+ if (cpi->rc.frames_till_gf_update_due > 0)
+ cpi->rc.frames_till_gf_update_due--;
+ }
+
if (cm->show_frame) {
// TODO(zoeliu): We may only swamp mi and prev_mi for those frames that
// are
@@ -5105,10 +5124,6 @@
// Don't increment frame counters if this was an altref buffer
// update not a real frame
- // Decrement count down till next gf
- if (cpi->rc.frames_till_gf_update_due > 0)
- cpi->rc.frames_till_gf_update_due--;
-
++cm->current_video_frame;
}