Modularize refresh frame flags in ExternalFlags
This CL groups refresh flags for various frame types from
ExternalFlags into a new struct ExtRefreshFrameFlagsInfo,
adds relevant documentation, and cleans up function
interfaces.
BUG=aomedia:2610
Change-Id: I448f621ca2f86a0475ee214864023055402ba3ff
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 326ecc0..1499216 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -43,7 +43,8 @@
// NOTE(weitinglin): Should we define another function to take care of
// cpi->rc.is_$Source_Type to make this function as it is in the comment?
- const ExternalFlags *const ext_flags = &cpi->ext_flags;
+ const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags =
+ &cpi->ext_flags.refresh_frame;
cpi->rc.is_src_frame_alt_ref = 0;
switch (type) {
@@ -97,11 +98,13 @@
default: assert(0); break;
}
- if (ext_flags->refresh_frame_flags_pending &&
+ if (ext_refresh_frame_flags->update_pending &&
(!is_stat_generation_stage(cpi))) {
- frame_params->refresh_golden_frame = ext_flags->refresh_golden_frame;
- frame_params->refresh_alt_ref_frame = ext_flags->refresh_alt_ref_frame;
- frame_params->refresh_bwd_ref_frame = ext_flags->refresh_bwd_ref_frame;
+ frame_params->refresh_golden_frame = ext_refresh_frame_flags->golden_frame;
+ frame_params->refresh_alt_ref_frame =
+ ext_refresh_frame_flags->alt_ref_frame;
+ frame_params->refresh_bwd_ref_frame =
+ ext_refresh_frame_flags->bwd_ref_frame;
}
if (force_refresh_all) {
@@ -137,17 +140,19 @@
}
}
-static INLINE int is_frame_droppable(const SVC *const svc,
- const ExternalFlags *const ext_flags) {
+static INLINE int is_frame_droppable(
+ const SVC *const svc,
+ const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags) {
// Droppable frame is only used by external refresh flags. VoD setting won't
// trigger its use case.
if (svc->external_ref_frame_config)
return svc->non_reference_frame;
- else if (ext_flags->refresh_frame_flags_pending)
- return !(ext_flags->refresh_alt_ref_frame ||
- ext_flags->refresh_alt2_ref_frame ||
- ext_flags->refresh_bwd_ref_frame ||
- ext_flags->refresh_golden_frame || ext_flags->refresh_last_frame);
+ else if (ext_refresh_frame_flags->update_pending)
+ return !(ext_refresh_frame_flags->alt_ref_frame ||
+ ext_refresh_frame_flags->alt2_ref_frame ||
+ ext_refresh_frame_flags->bwd_ref_frame ||
+ ext_refresh_frame_flags->golden_frame ||
+ ext_refresh_frame_flags->last_frame);
else
return 0;
}
@@ -158,7 +163,7 @@
// We should fix the cpi->common.show_frame flag
// instead of checking the other condition to update the counter properly.
if (cpi->common.show_frame ||
- is_frame_droppable(&cpi->svc, &cpi->ext_flags)) {
+ is_frame_droppable(&cpi->svc, &cpi->ext_flags.refresh_frame)) {
// Decrement count down till next gf
if (cpi->rc.frames_till_gf_update_due > 0)
cpi->rc.frames_till_gf_update_due--;
@@ -640,7 +645,7 @@
// expressed than converting the frame update type.
if (frame_is_sframe(cm)) frame_update_type = KEY_FRAME;
- if (is_frame_droppable(&cpi->svc, &cpi->ext_flags)) return;
+ if (is_frame_droppable(&cpi->svc, &cpi->ext_flags.refresh_frame)) return;
switch (frame_update_type) {
case KEY_FRAME:
@@ -727,7 +732,9 @@
FRAME_UPDATE_TYPE frame_update_type,
const RefBufferStack *const ref_buffer_stack) {
const AV1_COMMON *const cm = &cpi->common;
- const ExternalFlags *const ext_flags = &cpi->ext_flags;
+ const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags =
+ &cpi->ext_flags.refresh_frame;
+
const SVC *const svc = &cpi->svc;
// Switch frames and shown key-frames overwrite all reference slots
if ((frame_params->frame_type == KEY_FRAME && frame_params->show_frame) ||
@@ -742,11 +749,11 @@
return 0;
}
- if (is_frame_droppable(svc, ext_flags)) return 0;
+ if (is_frame_droppable(svc, ext_refresh_frame_flags)) return 0;
int refresh_mask = 0;
- if (ext_flags->refresh_frame_flags_pending) {
+ if (ext_refresh_frame_flags->update_pending) {
if (svc->external_ref_frame_config) {
for (unsigned int i = 0; i < INTER_REFS_PER_FRAME; i++) {
int ref_frame_map_idx = svc->ref_idx[i];
@@ -759,28 +766,33 @@
// order to preserve the behaviour of the flag overrides.
int ref_frame_map_idx = get_ref_frame_map_idx(cm, LAST_FRAME);
if (ref_frame_map_idx != INVALID_IDX)
- refresh_mask |= ext_flags->refresh_last_frame << ref_frame_map_idx;
+ refresh_mask |= ext_refresh_frame_flags->last_frame << ref_frame_map_idx;
ref_frame_map_idx = get_ref_frame_map_idx(cm, EXTREF_FRAME);
if (ref_frame_map_idx != INVALID_IDX)
- refresh_mask |= ext_flags->refresh_bwd_ref_frame << ref_frame_map_idx;
+ refresh_mask |= ext_refresh_frame_flags->bwd_ref_frame
+ << ref_frame_map_idx;
ref_frame_map_idx = get_ref_frame_map_idx(cm, ALTREF2_FRAME);
if (ref_frame_map_idx != INVALID_IDX)
- refresh_mask |= ext_flags->refresh_alt2_ref_frame << ref_frame_map_idx;
+ refresh_mask |= ext_refresh_frame_flags->alt2_ref_frame
+ << ref_frame_map_idx;
if (frame_update_type == OVERLAY_UPDATE) {
ref_frame_map_idx = get_ref_frame_map_idx(cm, ALTREF_FRAME);
if (ref_frame_map_idx != INVALID_IDX)
- refresh_mask |= ext_flags->refresh_golden_frame << ref_frame_map_idx;
+ refresh_mask |= ext_refresh_frame_flags->golden_frame
+ << ref_frame_map_idx;
} else {
ref_frame_map_idx = get_ref_frame_map_idx(cm, GOLDEN_FRAME);
if (ref_frame_map_idx != INVALID_IDX)
- refresh_mask |= ext_flags->refresh_golden_frame << ref_frame_map_idx;
+ refresh_mask |= ext_refresh_frame_flags->golden_frame
+ << ref_frame_map_idx;
ref_frame_map_idx = get_ref_frame_map_idx(cm, ALTREF_FRAME);
if (ref_frame_map_idx != INVALID_IDX)
- refresh_mask |= ext_flags->refresh_alt_ref_frame << ref_frame_map_idx;
+ refresh_mask |= ext_refresh_frame_flags->alt_ref_frame
+ << ref_frame_map_idx;
}
return refresh_mask;
}
@@ -1203,7 +1215,7 @@
const RefCntBuffer *ref_frames[INTER_REFS_PER_FRAME];
const YV12_BUFFER_CONFIG *ref_frame_buf[INTER_REFS_PER_FRAME];
- if (!ext_flags->refresh_frame_flags_pending) {
+ if (!ext_flags->refresh_frame.update_pending) {
av1_get_ref_frames(cpi, &cpi->ref_buffer_stack);
} else if (cpi->svc.external_ref_frame_config) {
for (unsigned int i = 0; i < INTER_REFS_PER_FRAME; i++)
@@ -1279,7 +1291,7 @@
// First pass doesn't modify reference buffer assignment or produce frame
// flags
update_frame_flags(cpi, frame_flags);
- if (!ext_flags->refresh_frame_flags_pending) {
+ if (!ext_flags->refresh_frame.update_pending) {
int ref_map_index =
av1_get_refresh_ref_frame_map(cm->current_frame.refresh_frame_flags);
av1_update_ref_frame_map(cpi, frame_update_type, cm->show_existing_frame,
@@ -1312,7 +1324,7 @@
// Leave a signal for a higher level caller about if this frame is droppable
if (*size > 0) {
- cpi->droppable = is_frame_droppable(&cpi->svc, ext_flags);
+ cpi->droppable = is_frame_droppable(&cpi->svc, &ext_flags->refresh_frame);
}
if (cpi->use_svc) av1_save_layer_context(cpi);
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 6c1fb2c..9ec8e60 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2952,7 +2952,7 @@
set_tile_info(cpi);
if (!cpi->svc.external_ref_frame_config)
- cpi->ext_flags.refresh_frame_flags_pending = 0;
+ cpi->ext_flags.refresh_frame.update_pending = 0;
cpi->ext_flags.refresh_frame_context_pending = 0;
#if CONFIG_AV1_HIGHBITDEPTH
@@ -7025,13 +7025,13 @@
}
static void svc_set_updates_external_ref_frame_config(
- ExternalFlags *const ext_flags, SVC *const svc) {
- ext_flags->refresh_frame_flags_pending = 1;
- ext_flags->refresh_last_frame = svc->refresh[svc->ref_idx[0]];
- ext_flags->refresh_golden_frame = svc->refresh[svc->ref_idx[3]];
- ext_flags->refresh_bwd_ref_frame = svc->refresh[svc->ref_idx[4]];
- ext_flags->refresh_alt2_ref_frame = svc->refresh[svc->ref_idx[5]];
- ext_flags->refresh_alt_ref_frame = svc->refresh[svc->ref_idx[6]];
+ ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags, SVC *const svc) {
+ ext_refresh_frame_flags->update_pending = 1;
+ ext_refresh_frame_flags->last_frame = svc->refresh[svc->ref_idx[0]];
+ ext_refresh_frame_flags->golden_frame = svc->refresh[svc->ref_idx[3]];
+ ext_refresh_frame_flags->bwd_ref_frame = svc->refresh[svc->ref_idx[4]];
+ ext_refresh_frame_flags->alt2_ref_frame = svc->refresh[svc->ref_idx[5]];
+ ext_refresh_frame_flags->alt_ref_frame = svc->refresh[svc->ref_idx[6]];
svc->non_reference_frame = 1;
for (int i = 0; i < REF_FRAMES; i++) {
if (svc->refresh[i] == 1) {
@@ -7059,6 +7059,8 @@
// GOLDEN, BWDREF, ALTREF2.
ExternalFlags *const ext_flags = &cpi->ext_flags;
+ ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags =
+ &ext_flags->refresh_frame;
ext_flags->ref_frame_flags = AOM_REFFRAME_ALL;
if (flags &
(AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
@@ -7104,17 +7106,18 @@
upd ^= AOM_ALT2_FLAG;
}
- ext_flags->refresh_last_frame = (upd & AOM_LAST_FLAG) != 0;
- ext_flags->refresh_golden_frame = (upd & AOM_GOLD_FLAG) != 0;
- ext_flags->refresh_alt_ref_frame = (upd & AOM_ALT_FLAG) != 0;
- ext_flags->refresh_bwd_ref_frame = (upd & AOM_BWD_FLAG) != 0;
- ext_flags->refresh_alt2_ref_frame = (upd & AOM_ALT2_FLAG) != 0;
- ext_flags->refresh_frame_flags_pending = 1;
+ ext_refresh_frame_flags->last_frame = (upd & AOM_LAST_FLAG) != 0;
+ ext_refresh_frame_flags->golden_frame = (upd & AOM_GOLD_FLAG) != 0;
+ ext_refresh_frame_flags->alt_ref_frame = (upd & AOM_ALT_FLAG) != 0;
+ ext_refresh_frame_flags->bwd_ref_frame = (upd & AOM_BWD_FLAG) != 0;
+ ext_refresh_frame_flags->alt2_ref_frame = (upd & AOM_ALT2_FLAG) != 0;
+ ext_refresh_frame_flags->update_pending = 1;
} else {
if (cpi->svc.external_ref_frame_config)
- svc_set_updates_external_ref_frame_config(ext_flags, &cpi->svc);
+ svc_set_updates_external_ref_frame_config(ext_refresh_frame_flags,
+ &cpi->svc);
else
- ext_flags->refresh_frame_flags_pending = 0;
+ ext_refresh_frame_flags->update_pending = 0;
}
ext_flags->use_ref_frame_mvs = cpi->oxcf.allow_ref_frame_mvs &
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 82d00cb..9b41653 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -966,21 +966,26 @@
} WinnerModeParams;
typedef struct {
+ // Flags set by external interface to determine which reference buffers are
+ // refreshed by this frame. When set, the encoder will update the particular
+ // reference frame buffer with the contents of the current frame.
+ bool last_frame;
+ bool golden_frame;
+ bool bwd_ref_frame;
+ bool alt2_ref_frame;
+ bool alt_ref_frame;
+
+ // Flag to indicate that update of refresh frame flags from external interface
+ // is pending.
+ bool update_pending;
+} ExtRefreshFrameFlagsInfo;
+
+typedef struct {
// Bit mask to disable certain reference frame types.
int ref_frame_flags;
- // Flags to determine which reference buffers are refreshed by this frame.
- // When set, the encoder will update the particular reference frame buffer
- // with the contents of the current frame.
- bool refresh_last_frame;
- bool refresh_golden_frame;
- bool refresh_bwd_ref_frame;
- bool refresh_alt2_ref_frame;
- bool refresh_alt_ref_frame;
-
- // Flag to indicate that updation of refresh frame flags from external
- // interface is pending.
- bool refresh_frame_flags_pending;
+ // Frame refresh flags set by the external interface.
+ ExtRefreshFrameFlagsInfo refresh_frame;
// Flag to enable the updation of frame contexts at the end of a frame decode.
bool refresh_frame_context;
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index 433163f..3bdce0d 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -1959,6 +1959,8 @@
static void set_reference_structure_one_pass_rt(AV1_COMP *cpi, int gf_update) {
AV1_COMMON *const cm = &cpi->common;
ExternalFlags *const ext_flags = &cpi->ext_flags;
+ ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags =
+ &ext_flags->refresh_frame;
SVC *const svc = &cpi->svc;
// Specify the reference prediction structure, for 1 layer nonrd mode.
// Current structue is to use 3 references (LAST, GOLDEN, ALTREF),
@@ -1971,12 +1973,12 @@
int last_idx_refresh = 0;
int gld_idx = 0;
int alt_ref_idx = 0;
- ext_flags->refresh_frame_flags_pending = 1;
+ ext_refresh_frame_flags->update_pending = 1;
svc->external_ref_frame_config = 1;
ext_flags->ref_frame_flags = 0;
- ext_flags->refresh_last_frame = 1;
- ext_flags->refresh_golden_frame = 0;
- ext_flags->refresh_alt_ref_frame = 0;
+ ext_refresh_frame_flags->last_frame = 1;
+ ext_refresh_frame_flags->golden_frame = 0;
+ ext_refresh_frame_flags->alt_ref_frame = 0;
for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) svc->ref_idx[i] = 7;
for (int i = 0; i < REF_FRAMES; ++i) svc->refresh[i] = 0;
// Always reference LAST, GOLDEN, ALTREF
@@ -2008,7 +2010,7 @@
svc->refresh[last_idx_refresh] = 1;
// Update GOLDEN on period for fixed slot case.
if (gld_fixed_slot && gf_update) {
- ext_flags->refresh_golden_frame = 1;
+ ext_refresh_frame_flags->golden_frame = 1;
svc->refresh[gld_idx] = 1;
}
}