Refactor show_existing_alt_ref related code
Move show_existing_alt_ref flag from cpi to gf_group structure
and refactor code related to it.
Change-Id: I02455c03a73f3bc2061f8f295d69c814ed0b390a
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 12fda39..9634ec0 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -191,6 +191,22 @@
}
}
+// Update show_existing_frame flag for frames of type OVERLAY_UPDATE in the
+// current GF interval
+static INLINE void set_show_existing_alt_ref(GF_GROUP *const gf_group,
+ int apply_filtering,
+ int enable_overlay,
+ int show_existing_alt_ref) {
+ if (get_frame_update_type(gf_group) != ARF_UPDATE &&
+ get_frame_update_type(gf_group) != KFFLT_UPDATE)
+ return;
+ if (!enable_overlay)
+ gf_group->show_existing_alt_ref = 1;
+ else
+ gf_group->show_existing_alt_ref =
+ apply_filtering ? show_existing_alt_ref : 1;
+}
+
static void update_rc_counts(AV1_COMP *cpi) {
update_keyframe_counters(cpi);
update_frames_till_gf_update(cpi);
@@ -947,8 +963,8 @@
// Save the pointer to the original source image.
YV12_BUFFER_CONFIG *source_buffer = frame_input->source;
// apply filtering to frame
+ int show_existing_alt_ref = 0;
if (apply_filtering) {
- int show_existing_alt_ref = 0;
// TODO(bohanli): figure out why we need frame_type in cm here.
cm->current_frame.frame_type = frame_params->frame_type;
const int code_arf =
@@ -959,14 +975,10 @@
aom_copy_metadata_to_frame_buffer(frame_input->source,
source_buffer->metadata);
}
- if (get_frame_update_type(&cpi->gf_group) == ARF_UPDATE ||
- get_frame_update_type(&cpi->gf_group) == KFFLT_UPDATE) {
- cpi->show_existing_alt_ref = show_existing_alt_ref;
- }
- } else if (get_frame_update_type(&cpi->gf_group) == ARF_UPDATE ||
- get_frame_update_type(&cpi->gf_group) == KFFLT_UPDATE) {
- cpi->show_existing_alt_ref = 1;
}
+ set_show_existing_alt_ref(&cpi->gf_group, apply_filtering,
+ oxcf->algo_cfg.enable_overlay,
+ show_existing_alt_ref);
// perform tpl after filtering
int allow_tpl = oxcf->gf_cfg.lag_in_frames > 1 &&
@@ -1254,7 +1266,7 @@
frame_params.show_existing_frame = 1;
} else {
frame_params.show_existing_frame =
- ((oxcf->algo_cfg.enable_overlay == 0 || cpi->show_existing_alt_ref) &&
+ (gf_group->show_existing_alt_ref &&
(gf_group->update_type[gf_group->index] == OVERLAY_UPDATE ||
gf_group->update_type[gf_group->index] == KFFLT_OVERLAY_UPDATE)) ||
gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE;
@@ -1264,7 +1276,7 @@
// Reset show_existing_alt_ref decision to 0 after it is used.
if (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE ||
gf_group->update_type[gf_group->index] == KFFLT_OVERLAY_UPDATE) {
- cpi->show_existing_alt_ref = 0;
+ gf_group->show_existing_alt_ref = 0;
}
} else {
frame_params.show_existing_frame = 0;
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 315592a..d1d7009 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -840,6 +840,9 @@
int arf_boost[MAX_STATIC_GF_GROUP_LENGTH];
int max_layer_depth;
int max_layer_depth_allowed;
+ // Flag to indicate if the frame of type OVERLAY_UPDATE in the current GF
+ // interval shows existing alt-ref frame
+ int show_existing_alt_ref;
// This is currently only populated for AOM_Q mode
unsigned char q_val[MAX_STATIC_GF_GROUP_LENGTH];
int bit_allocation[MAX_STATIC_GF_GROUP_LENGTH];
@@ -2316,11 +2319,6 @@
*/
YV12_BUFFER_CONFIG alt_ref_buffer;
- /*!
- * Tell if OVERLAY frame shows existing alt_ref frame.
- */
- int show_existing_alt_ref;
-
#if CONFIG_INTERNAL_STATS
/*!\cond */
uint64_t time_receive_data;