Form CurrentFrame structure, rename frame_offset
Move a number of elements of AV1_COMMON which refer specifically to the
current frame into a new CurrentFrame structure. Also, move those
elements specific to skip mode into a SkipModeInfo structure. This
change is not exhaustive; we plan to move over more elements in future.
Also, frame_offset is renamed to order_hint in order to be clearer about
its purpose and to match the terminology in the bitstream spec.
This forms part of wider restructuring and refactoring in order to
achieve a clean API separation at the entry to the low-level encoder.
BUG=aomedia:2244
Change-Id: Ie85280138d11b83625a764602bef502252a4567f
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index fe025fd..3cb1567 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -1420,8 +1420,8 @@
is_frame_visible = cpi->common.show_frame;
- has_fwd_keyframe |=
- (!is_frame_visible && cpi->common.frame_type == KEY_FRAME);
+ has_fwd_keyframe |= (!is_frame_visible &&
+ cpi->common.current_frame.frame_type == KEY_FRAME);
}
}
if (is_frame_visible) {
diff --git a/av1/av1_dx_iface.c b/av1/av1_dx_iface.c
index c68cdee..510100d 100644
--- a/av1/av1_dx_iface.c
+++ b/av1/av1_dx_iface.c
@@ -448,7 +448,8 @@
const AV1Decoder *const pbi) {
// Clear resync flag if worker got a key frame or intra only frame.
if (ctx->need_resync == 1 && pbi->need_resync == 0 &&
- (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME))
+ (pbi->common.current_frame.intra_only ||
+ pbi->common.current_frame.frame_type == KEY_FRAME))
ctx->need_resync = 0;
}
diff --git a/av1/common/debugmodes.c b/av1/common/debugmodes.c
index 868f341..5242f19 100644
--- a/av1/common/debugmodes.c
+++ b/av1/common/debugmodes.c
@@ -17,7 +17,7 @@
static void log_frame_info(AV1_COMMON *cm, const char *str, FILE *f) {
fprintf(f, "%s", str);
- fprintf(f, "(Frame %d, Show:%d, Q:%d): \n", cm->current_video_frame,
+ fprintf(f, "(Frame %d, Show:%d, Q:%d): \n", cm->current_frame.frame_number,
cm->show_frame, cm->base_qindex);
}
/* This function dereferences a pointer to the mbmi structure
diff --git a/av1/common/mvref_common.c b/av1/common/mvref_common.c
index 663a0c8..e897777 100644
--- a/av1/common/mvref_common.c
+++ b/av1/common/mvref_common.c
@@ -864,7 +864,7 @@
}
void av1_setup_frame_buf_refs(AV1_COMMON *cm) {
- cm->cur_frame->cur_frame_offset = cm->frame_offset;
+ cm->cur_frame->cur_frame_offset = cm->current_frame.order_hint;
MV_REFERENCE_FRAME ref_frame;
for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
@@ -885,7 +885,7 @@
cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset;
cm->ref_frame_sign_bias[ref_frame] =
(get_relative_dist(&cm->seq_params.order_hint_info, ref_frame_offset,
- (int)cm->frame_offset) <= 0)
+ (int)cm->current_frame.order_hint) <= 0)
? 0
: 1;
} else {
@@ -1276,16 +1276,18 @@
void av1_setup_skip_mode_allowed(AV1_COMMON *cm) {
const OrderHintInfo *const order_hint_info = &cm->seq_params.order_hint_info;
+ SkipModeInfo *const skip_mode_info = &cm->current_frame.skip_mode_info;
- cm->is_skip_mode_allowed = 0;
- cm->ref_frame_idx_0 = cm->ref_frame_idx_1 = INVALID_IDX;
+ skip_mode_info->skip_mode_allowed = 0;
+ skip_mode_info->ref_frame_idx_0 = INVALID_IDX;
+ skip_mode_info->ref_frame_idx_1 = INVALID_IDX;
if (!order_hint_info->enable_order_hint || frame_is_intra_only(cm) ||
- cm->reference_mode == SINGLE_REFERENCE)
+ cm->current_frame.reference_mode == SINGLE_REFERENCE)
return;
RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
- const int cur_frame_offset = cm->frame_offset;
+ const int cur_frame_offset = cm->current_frame.order_hint;
int ref_frame_offset[2] = { -1, INT_MAX };
int ref_idx[2] = { INVALID_IDX, INVALID_IDX };
@@ -1317,9 +1319,9 @@
if (ref_idx[0] != INVALID_IDX && ref_idx[1] != INVALID_IDX) {
// == Bi-directional prediction ==
- cm->is_skip_mode_allowed = 1;
- cm->ref_frame_idx_0 = AOMMIN(ref_idx[0], ref_idx[1]);
- cm->ref_frame_idx_1 = AOMMAX(ref_idx[0], ref_idx[1]);
+ skip_mode_info->skip_mode_allowed = 1;
+ skip_mode_info->ref_frame_idx_0 = AOMMIN(ref_idx[0], ref_idx[1]);
+ skip_mode_info->ref_frame_idx_1 = AOMMAX(ref_idx[0], ref_idx[1]);
} else if (ref_idx[0] != INVALID_IDX && ref_idx[1] == INVALID_IDX) {
// == Forward prediction only ==
// Identify the second nearest forward reference.
@@ -1341,9 +1343,9 @@
}
}
if (ref_frame_offset[1] != -1) {
- cm->is_skip_mode_allowed = 1;
- cm->ref_frame_idx_0 = AOMMIN(ref_idx[0], ref_idx[1]);
- cm->ref_frame_idx_1 = AOMMAX(ref_idx[0], ref_idx[1]);
+ skip_mode_info->skip_mode_allowed = 1;
+ skip_mode_info->ref_frame_idx_0 = AOMMIN(ref_idx[0], ref_idx[1]);
+ skip_mode_info->ref_frame_idx_1 = AOMMAX(ref_idx[0], ref_idx[1]);
}
}
}
@@ -1386,7 +1388,7 @@
assert(cm->seq_params.order_hint_info.enable_order_hint);
assert(cm->seq_params.order_hint_info.order_hint_bits_minus_1 >= 0);
- const int cur_frame_offset = (int)cm->frame_offset;
+ const int cur_frame_offset = (int)cm->current_frame.order_hint;
const int cur_frame_sort_idx =
1 << cm->seq_params.order_hint_info.order_hint_bits_minus_1;
diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h
index 3d04511..d1bd9e3 100644
--- a/av1/common/onyxc_int.h
+++ b/av1/common/onyxc_int.h
@@ -291,7 +291,26 @@
int film_grain_params_present;
} SequenceHeader;
+typedef struct {
+ int skip_mode_allowed;
+ int skip_mode_flag;
+ int ref_frame_idx_0;
+ int ref_frame_idx_1;
+} SkipModeInfo;
+
+typedef struct {
+ FRAME_TYPE frame_type;
+ // Flag signaling that the frame is encoded using only INTRA modes.
+ uint8_t intra_only;
+ REFERENCE_MODE reference_mode;
+
+ unsigned int order_hint;
+ unsigned int frame_number;
+ SkipModeInfo skip_mode_info;
+} CurrentFrame;
+
typedef struct AV1Common {
+ CurrentFrame current_frame;
struct aom_internal_error_info error;
int width;
int height;
@@ -335,17 +354,11 @@
// (inter) reference frame type to the corresponding reference buffer.
RefBuffer frame_refs[INTER_REFS_PER_FRAME];
- int is_skip_mode_allowed;
- int skip_mode_flag;
- int ref_frame_idx_0;
- int ref_frame_idx_1;
-
// Index to the 'new' frame (i.e. the frame currently being encoded or
// decoded) in the buffer pool 'cm->buffer_pool'.
int new_fb_idx;
FRAME_TYPE last_frame_type; /* last frame's frame type for motion search.*/
- FRAME_TYPE frame_type;
int show_frame;
int showable_frame; // frame can be used as show existing frame in future
@@ -355,8 +368,6 @@
int is_reference_frame;
int reset_decoder_state;
- // Flag signaling that the frame is encoded using only INTRA modes.
- uint8_t intra_only;
uint8_t last_intra_only;
uint8_t disable_cdf_update;
int allow_high_precision_mv;
@@ -475,7 +486,6 @@
// Context probabilities for reference frame prediction
MV_REFERENCE_FRAME comp_fwd_ref[FWD_REFS];
MV_REFERENCE_FRAME comp_bwd_ref[BWD_REFS];
- REFERENCE_MODE reference_mode;
FRAME_CONTEXT *fc; /* this frame entropy */
FRAME_CONTEXT *frame_contexts; // FRAME_CONTEXTS
@@ -483,10 +493,6 @@
int fb_of_context_type[REF_FRAMES];
int primary_ref_frame;
- unsigned int frame_offset;
-
- unsigned int current_video_frame;
-
aom_bit_depth_t dequant_bit_depth; // bit_depth of current dequantizer
int error_resilient_mode;
@@ -646,11 +652,12 @@
}
static INLINE int frame_is_intra_only(const AV1_COMMON *const cm) {
- return cm->frame_type == KEY_FRAME || cm->intra_only;
+ return cm->current_frame.frame_type == KEY_FRAME ||
+ cm->current_frame.intra_only;
}
static INLINE int frame_is_sframe(const AV1_COMMON *cm) {
- return cm->frame_type == S_FRAME;
+ return cm->current_frame.frame_type == S_FRAME;
}
static INLINE RefCntBuffer *get_prev_frame(const AV1_COMMON *const cm) {
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 0e7ff5c..4269a5a 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -268,8 +268,8 @@
int blk_h = block_size_high[bsize];
mi_to_pixel_loc(&pixel_c, &pixel_r, mi_col, mi_row, blk_col, blk_row,
pd->subsampling_x, pd->subsampling_y);
- mismatch_check_block_tx(dst, pd->dst.stride, cm->frame_offset, plane, pixel_c,
- pixel_r, blk_w, blk_h,
+ mismatch_check_block_tx(dst, pd->dst.stride, cm->current_frame.order_hint,
+ plane, pixel_c, pixel_r, blk_w, blk_h,
xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH);
#endif
}
@@ -1083,8 +1083,9 @@
if (!is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x,
pd->subsampling_y))
continue;
- mismatch_check_block_pre(pd->dst.buf, pd->dst.stride, cm->frame_offset,
- plane, pixel_c, pixel_r, pd->width, pd->height,
+ mismatch_check_block_pre(pd->dst.buf, pd->dst.stride,
+ cm->current_frame.order_hint, plane, pixel_c,
+ pixel_r, pd->width, pd->height,
xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH);
}
#endif
@@ -4184,7 +4185,7 @@
}
pars->random_seed = aom_rb_read_literal(rb, 16);
- if (cm->frame_type == INTER_FRAME)
+ if (cm->current_frame.frame_type == INTER_FRAME)
pars->update_parameters = aom_rb_read_bit(rb);
else
pars->update_parameters = 1;
@@ -4654,7 +4655,7 @@
*/
/*
printf("Dec Ref %d [%d/%d]: %d %d %d %d\n",
- frame, cm->current_video_frame, cm->show_frame,
+ frame, cm->current_frame.frame_number, cm->show_frame,
cm->global_motion[frame].wmmat[0],
cm->global_motion[frame].wmmat[1],
cm->global_motion[frame].wmmat[2],
@@ -4715,7 +4716,7 @@
assert(cm->show_existing_frame);
- cm->frame_type = KEY_FRAME;
+ cm->current_frame.frame_type = KEY_FRAME;
pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1;
@@ -4785,6 +4786,7 @@
struct aom_read_bit_buffer *rb) {
AV1_COMMON *const cm = &pbi->common;
const SequenceHeader *const seq_params = &cm->seq_params;
+ CurrentFrame *const current_frame = &cm->current_frame;
MACROBLOCKD *const xd = &pbi->mb;
BufferPool *const pool = cm->buffer_pool;
RefCntBuffer *const frame_bufs = pool->frame_bufs;
@@ -4794,8 +4796,8 @@
"No sequence header");
}
- cm->last_frame_type = cm->frame_type;
- cm->last_intra_only = cm->intra_only;
+ cm->last_frame_type = current_frame->frame_type;
+ cm->last_intra_only = current_frame->intra_only;
// NOTE: By default all coded frames to be used as a reference
cm->is_reference_frame = 1;
@@ -4803,7 +4805,7 @@
if (seq_params->reduced_still_picture_hdr) {
cm->show_existing_frame = 0;
cm->show_frame = 1;
- cm->frame_type = KEY_FRAME;
+ current_frame->frame_type = KEY_FRAME;
if (pbi->sequence_header_changed) {
// This is the start of a new coded video sequence.
pbi->sequence_header_changed = 0;
@@ -4878,9 +4880,9 @@
return 0;
}
- cm->frame_type = (FRAME_TYPE)aom_rb_read_literal(rb, 2); // 2 bits
+ current_frame->frame_type = (FRAME_TYPE)aom_rb_read_literal(rb, 2);
if (pbi->sequence_header_changed) {
- if (cm->frame_type == KEY_FRAME) {
+ if (current_frame->frame_type == KEY_FRAME) {
// This is the start of a new coded video sequence.
pbi->sequence_header_changed = 0;
pbi->decoding_first_frame = 1;
@@ -4893,11 +4895,11 @@
cm->show_frame = aom_rb_read_bit(rb);
if (seq_params->still_picture &&
- (cm->frame_type != KEY_FRAME || !cm->show_frame)) {
+ (current_frame->frame_type != KEY_FRAME || !cm->show_frame)) {
aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
"Still pictures must be coded as shown keyframes");
}
- cm->showable_frame = cm->frame_type != KEY_FRAME;
+ cm->showable_frame = current_frame->frame_type != KEY_FRAME;
if (cm->show_frame) {
if (seq_params->decoder_model_info_present_flag &&
cm->timing_info.equal_picture_interval == 0)
@@ -4907,9 +4909,10 @@
cm->showable_frame = aom_rb_read_bit(rb);
}
cm->cur_frame->showable_frame = cm->showable_frame;
- cm->intra_only = cm->frame_type == INTRA_ONLY_FRAME;
+ current_frame->intra_only = current_frame->frame_type == INTRA_ONLY_FRAME;
cm->error_resilient_mode =
- frame_is_sframe(cm) || (cm->frame_type == KEY_FRAME && cm->show_frame)
+ frame_is_sframe(cm) ||
+ (current_frame->frame_type == KEY_FRAME && cm->show_frame)
? 1
: aom_rb_read_bit(rb);
}
@@ -4941,8 +4944,9 @@
int frame_id_length = seq_params->frame_id_length;
int diff_len = seq_params->delta_frame_id_length;
int prev_frame_id = 0;
- int have_prev_frame_id = !pbi->decoding_first_frame &&
- !(cm->frame_type == KEY_FRAME && cm->show_frame);
+ int have_prev_frame_id =
+ !pbi->decoding_first_frame &&
+ !(current_frame->frame_type == KEY_FRAME && cm->show_frame);
if (have_prev_frame_id) {
prev_frame_id = cm->current_frame_id;
}
@@ -4965,7 +4969,7 @@
}
/* Check if some frames need to be marked as not valid for referencing */
for (int i = 0; i < REF_FRAMES; i++) {
- if (cm->frame_type == KEY_FRAME && cm->show_frame) {
+ if (current_frame->frame_type == KEY_FRAME && cm->show_frame) {
cm->valid_for_referencing[i] = 0;
} else if (cm->current_frame_id - (1 << diff_len) > 0) {
if (cm->ref_frame_id[i] > cm->current_frame_id ||
@@ -4982,9 +4986,9 @@
frame_size_override_flag = frame_is_sframe(cm) ? 1 : aom_rb_read_bit(rb);
- cm->frame_offset = aom_rb_read_literal(
+ current_frame->order_hint = aom_rb_read_literal(
rb, seq_params->order_hint_info.order_hint_bits_minus_1 + 1);
- cm->current_video_frame = cm->frame_offset;
+ current_frame->frame_number = current_frame->order_hint;
if (!cm->error_resilient_mode && !frame_is_intra_only(cm)) {
cm->primary_ref_frame = aom_rb_read_literal(rb, PRIMARY_REF_BITS);
@@ -5016,7 +5020,7 @@
}
}
}
- if (cm->frame_type == KEY_FRAME) {
+ if (current_frame->frame_type == KEY_FRAME) {
if (!cm->show_frame) // unshown keyframe (forward keyframe)
pbi->refresh_frame_flags = aom_rb_read_literal(rb, REF_FRAMES);
else // shown keyframe
@@ -5031,7 +5035,7 @@
pbi->need_resync = 0;
}
} else {
- if (cm->intra_only) {
+ if (current_frame->intra_only) {
pbi->refresh_frame_flags = aom_rb_read_literal(rb, REF_FRAMES);
if (pbi->refresh_frame_flags == 0xFF) {
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
@@ -5100,7 +5104,7 @@
}
}
- if (cm->frame_type == KEY_FRAME) {
+ if (current_frame->frame_type == KEY_FRAME) {
setup_frame_size(cm, frame_size_override_flag, rb);
if (cm->allow_screen_content_tools && !av1_superres_scaled(cm))
@@ -5110,7 +5114,7 @@
} else {
cm->allow_ref_frame_mvs = 0;
- if (cm->intra_only) {
+ if (current_frame->intra_only) {
cm->cur_frame->film_grain_params_present =
seq_params->film_grain_params_present;
setup_frame_size(cm, frame_size_override_flag, rb);
@@ -5214,7 +5218,7 @@
"frame context is unavailable.");
}
- if (!cm->intra_only && pbi->need_resync != 1) {
+ if (!current_frame->intra_only && pbi->need_resync != 1) {
if (frame_might_allow_ref_frame_mvs(cm))
cm->allow_ref_frame_mvs = aom_rb_read_bit(rb);
else
@@ -5236,8 +5240,9 @@
av1_setup_frame_sign_bias(cm);
- cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only;
- cm->cur_frame->frame_type = cm->frame_type;
+ cm->cur_frame->intra_only =
+ current_frame->frame_type == KEY_FRAME || current_frame->intra_only;
+ cm->cur_frame->frame_type = current_frame->frame_type;
if (seq_params->frame_id_numbers_present_flag) {
/* If bitmask is set, update reference frame id values and
@@ -5369,11 +5374,13 @@
}
cm->tx_mode = read_tx_mode(cm, rb);
- cm->reference_mode = read_frame_reference_mode(cm, rb);
- if (cm->reference_mode != SINGLE_REFERENCE) setup_compound_reference_mode(cm);
+ current_frame->reference_mode = read_frame_reference_mode(cm, rb);
+ if (current_frame->reference_mode != SINGLE_REFERENCE)
+ setup_compound_reference_mode(cm);
av1_setup_skip_mode_allowed(cm);
- cm->skip_mode_flag = cm->is_skip_mode_allowed ? aom_rb_read_bit(rb) : 0;
+ current_frame->skip_mode_info.skip_mode_flag =
+ current_frame->skip_mode_info.skip_mode_allowed ? aom_rb_read_bit(rb) : 0;
if (frame_might_allow_warped_motion(cm))
cm->allow_warped_motion = aom_rb_read_bit(rb);
@@ -5446,7 +5453,8 @@
MACROBLOCKD *const xd = &pbi->mb;
#if CONFIG_BITSTREAM_DEBUG
- bitstream_queue_set_frame_read(cm->current_video_frame * 2 + cm->show_frame);
+ bitstream_queue_set_frame_read(cm->current_frame.frame_number * 2 +
+ cm->show_frame);
#endif
#if CONFIG_MISMATCH_DEBUG
mismatch_move_frame_idx_r();
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index d8e6a71..4cfed5b 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -395,7 +395,7 @@
static int read_skip_mode(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
aom_reader *r) {
- if (!cm->skip_mode_flag) return 0;
+ if (!cm->current_frame.skip_mode_info.skip_mode_flag) return 0;
if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
return 0;
@@ -883,14 +883,14 @@
const MACROBLOCKD *xd,
aom_reader *r) {
if (!is_comp_ref_allowed(xd->mi[0]->sb_type)) return SINGLE_REFERENCE;
- if (cm->reference_mode == REFERENCE_MODE_SELECT) {
+ if (cm->current_frame.reference_mode == REFERENCE_MODE_SELECT) {
const int ctx = av1_get_reference_mode_context(xd);
const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read_symbol(
r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_STR);
return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE
} else {
- assert(cm->reference_mode == SINGLE_REFERENCE);
- return cm->reference_mode;
+ assert(cm->current_frame.reference_mode == SINGLE_REFERENCE);
+ return cm->current_frame.reference_mode;
}
}
@@ -908,8 +908,8 @@
static void set_ref_frames_for_skip_mode(AV1_COMMON *const cm,
MV_REFERENCE_FRAME ref_frame[2]) {
- ref_frame[0] = LAST_FRAME + cm->ref_frame_idx_0;
- ref_frame[1] = LAST_FRAME + cm->ref_frame_idx_1;
+ ref_frame[0] = LAST_FRAME + cm->current_frame.skip_mode_info.ref_frame_idx_0;
+ ref_frame[1] = LAST_FRAME + cm->current_frame.skip_mode_info.ref_frame_idx_1;
}
// Read the referncence frame
@@ -1232,16 +1232,16 @@
}
#define FRAME_TO_CHECK 11
- if (cm->current_video_frame == FRAME_TO_CHECK && cm->show_frame == 1) {
+ if (cm->current_frame.frame_number == FRAME_TO_CHECK && cm->show_frame == 1) {
printf(
"=== DECODER ===: "
"Frame=%d, (mi_row,mi_col)=(%d,%d), skip_mode=%d, mode=%d, bsize=%d, "
"show_frame=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, "
"ref[1]=%d, motion_mode=%d, mode_ctx=%d, "
"newmv_ctx=%d, zeromv_ctx=%d, refmv_ctx=%d, tx_size=%d\n",
- cm->current_video_frame, mi_row, mi_col, mbmi->skip_mode, mbmi->mode,
- mbmi->sb_type, cm->show_frame, mv[0].as_mv.row, mv[0].as_mv.col,
- mv[1].as_mv.row, mv[1].as_mv.col, mbmi->ref_frame[0],
+ cm->current_frame.frame_number, mi_row, mi_col, mbmi->skip_mode,
+ mbmi->mode, mbmi->sb_type, cm->show_frame, mv[0].as_mv.row,
+ mv[0].as_mv.col, mv[1].as_mv.row, mv[1].as_mv.col, mbmi->ref_frame[0],
mbmi->ref_frame[1], mbmi->motion_mode, mode_ctx, newmv_ctx, zeromv_ctx,
refmv_ctx, mbmi->tx_size);
}
@@ -1430,7 +1430,7 @@
mbmi->compound_idx = 1;
}
} else {
- assert(cm->reference_mode != SINGLE_REFERENCE &&
+ assert(cm->current_frame.reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION);
assert(masked_compound_used);
diff --git a/av1/decoder/decoder.c b/av1/decoder/decoder.c
index 50bee81..4383a43 100644
--- a/av1/decoder/decoder.c
+++ b/av1/decoder/decoder.c
@@ -103,7 +103,7 @@
memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
memset(&cm->next_ref_frame_map, -1, sizeof(cm->next_ref_frame_map));
- cm->current_video_frame = 0;
+ cm->current_frame.frame_number = 0;
pbi->decoding_first_frame = 1;
pbi->common.buffer_pool = pool;
diff --git a/av1/decoder/inspection.c b/av1/decoder/inspection.c
index 01819cc..17a9f98 100644
--- a/av1/decoder/inspection.c
+++ b/av1/decoder/inspection.c
@@ -42,9 +42,9 @@
ifd_init_mi_rc(fd, cm->mi_rows, cm->mi_cols);
}
fd->show_existing_frame = cm->show_existing_frame;
- fd->frame_number = cm->current_video_frame;
+ fd->frame_number = cm->current_frame.frame_number;
fd->show_frame = cm->show_frame;
- fd->frame_type = cm->frame_type;
+ fd->frame_type = cm->current_frame.frame_type;
fd->base_qindex = cm->base_qindex;
// Set width and height of the first tile until generic support can be added
TileInfo tile_info;
diff --git a/av1/encoder/aq_complexity.c b/av1/encoder/aq_complexity.c
index daa3438..16edbc6 100644
--- a/av1/encoder/aq_complexity.c
+++ b/av1/encoder/aq_complexity.c
@@ -93,7 +93,7 @@
if (segment == DEFAULT_AQ2_SEG) continue;
qindex_delta = av1_compute_qdelta_by_rate(
- &cpi->rc, cm->frame_type, cm->base_qindex,
+ &cpi->rc, cm->current_frame.frame_type, cm->base_qindex,
aq_c_q_adj_factor[aq_strength][segment], cm->seq_params.bit_depth);
// For AQ complexity mode, we dont allow Q0 in a segment if the base
diff --git a/av1/encoder/aq_cyclicrefresh.c b/av1/encoder/aq_cyclicrefresh.c
index f532d48..8d96b23 100644
--- a/av1/encoder/aq_cyclicrefresh.c
+++ b/av1/encoder/aq_cyclicrefresh.c
@@ -140,8 +140,8 @@
const CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
const RATE_CONTROL *const rc = &cpi->rc;
int deltaq =
- av1_compute_qdelta_by_rate(rc, cpi->common.frame_type, q, rate_factor,
- cpi->common.seq_params.bit_depth);
+ av1_compute_qdelta_by_rate(rc, cpi->common.current_frame.frame_type, q,
+ rate_factor, cpi->common.seq_params.bit_depth);
if ((-deltaq) > cr->max_qdelta_perc * q / 100) {
deltaq = -cr->max_qdelta_perc * q / 100;
}
@@ -166,15 +166,15 @@
// Take segment weighted average for estimated bits.
estimated_bits =
(int)((1.0 - weight_segment1 - weight_segment2) *
- av1_estimate_bits_at_q(cm->frame_type, cm->base_qindex, mbs,
- correction_factor,
+ av1_estimate_bits_at_q(cm->current_frame.frame_type,
+ cm->base_qindex, mbs, correction_factor,
cm->seq_params.bit_depth) +
weight_segment1 * av1_estimate_bits_at_q(
- cm->frame_type,
+ cm->current_frame.frame_type,
cm->base_qindex + cr->qindex_delta[1], mbs,
correction_factor, cm->seq_params.bit_depth) +
weight_segment2 * av1_estimate_bits_at_q(
- cm->frame_type,
+ cm->current_frame.frame_type,
cm->base_qindex + cr->qindex_delta[2], mbs,
correction_factor, cm->seq_params.bit_depth));
return estimated_bits;
@@ -203,10 +203,11 @@
// Take segment weighted average for bits per mb.
bits_per_mb =
(int)((1.0 - weight_segment) *
- av1_rc_bits_per_mb(cm->frame_type, i, correction_factor,
+ av1_rc_bits_per_mb(cm->current_frame.frame_type, i,
+ correction_factor,
cm->seq_params.bit_depth) +
- weight_segment * av1_rc_bits_per_mb(cm->frame_type, i + deltaq,
- correction_factor,
+ weight_segment * av1_rc_bits_per_mb(cm->current_frame.frame_type,
+ i + deltaq, correction_factor,
cm->seq_params.bit_depth));
return bits_per_mb;
}
@@ -496,14 +497,14 @@
av1_disable_segmentation(seg);
return;
}
- if (cm->current_video_frame == 0) cr->low_content_avg = 0.0;
+ if (cm->current_frame.frame_number == 0) cr->low_content_avg = 0.0;
// Don't apply refresh on key frame or enhancement layer frames.
- if (!apply_cyclic_refresh || cm->frame_type == KEY_FRAME) {
+ if (!apply_cyclic_refresh || cm->current_frame.frame_type == KEY_FRAME) {
// Set segmentation map to 0 and disable.
unsigned char *const seg_map = cpi->segmentation_map;
memset(seg_map, 0, cm->mi_rows * cm->mi_cols);
av1_disable_segmentation(&cm->seg);
- if (cm->frame_type == KEY_FRAME) {
+ if (cm->current_frame.frame_type == KEY_FRAME) {
memset(cr->last_coded_q_map, MAXQ,
cm->mi_rows * cm->mi_cols * sizeof(*cr->last_coded_q_map));
cr->sb_index = 0;
diff --git a/av1/encoder/aq_variance.c b/av1/encoder/aq_variance.c
index e9f80a7..cfd7610 100644
--- a/av1/encoder/aq_variance.c
+++ b/av1/encoder/aq_variance.c
@@ -77,8 +77,8 @@
// Set up avg segment id to be 1.0 and adjust the other segments around
// it.
int qindex_delta = av1_compute_qdelta_by_rate(
- &cpi->rc, cm->frame_type, cm->base_qindex, rate_ratio[i] / avg_ratio,
- cm->seq_params.bit_depth);
+ &cpi->rc, cm->current_frame.frame_type, cm->base_qindex,
+ rate_ratio[i] / avg_ratio, cm->seq_params.bit_depth);
// We don't allow qindex 0 in a segment if the base value is not 0.
// Q index 0 (lossless) implies 4x4 encoding only and in AQ mode a segment
@@ -192,8 +192,8 @@
rate_level = block_var_level;
}
int qindex_delta = av1_compute_qdelta_by_rate(
- &cpi->rc, cm->frame_type, cm->base_qindex, deltaq_rate_ratio[rate_level],
- cm->seq_params.bit_depth);
+ &cpi->rc, cm->current_frame.frame_type, cm->base_qindex,
+ deltaq_rate_ratio[rate_level], cm->seq_params.bit_depth);
if ((cm->base_qindex != 0) && ((cm->base_qindex + qindex_delta) == 0)) {
qindex_delta = -cm->base_qindex + 1;
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index b56e91e..620fad6 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -229,7 +229,7 @@
static int write_skip_mode(const AV1_COMMON *cm, const MACROBLOCKD *xd,
int segment_id, const MB_MODE_INFO *mi,
aom_writer *w) {
- if (!cm->skip_mode_flag) return 0;
+ if (!cm->current_frame.skip_mode_info.skip_mode_flag) return 0;
if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
return 0;
}
@@ -500,11 +500,12 @@
} else {
// does the feature use compound prediction or not
// (if not specified at the frame/segment level)
- if (cm->reference_mode == REFERENCE_MODE_SELECT) {
+ if (cm->current_frame.reference_mode == REFERENCE_MODE_SELECT) {
if (is_comp_ref_allowed(mbmi->sb_type))
aom_write_symbol(w, is_compound, av1_get_reference_mode_cdf(xd), 2);
} else {
- assert((!is_compound) == (cm->reference_mode == SINGLE_REFERENCE));
+ assert((!is_compound) ==
+ (cm->current_frame.reference_mode == SINGLE_REFERENCE));
}
if (is_compound) {
@@ -1108,7 +1109,7 @@
av1_encode_mv(cpi, w, &mbmi->mv[0].as_mv, &ref_mv.as_mv, nmvc, allow_hp);
}
- if (cpi->common.reference_mode != COMPOUND_REFERENCE &&
+ if (cpi->common.current_frame.reference_mode != COMPOUND_REFERENCE &&
cpi->common.seq_params.enable_interintra_compound &&
is_interintra_allowed(mbmi)) {
const int interintra = mbmi->ref_frame[1] == INTRA_FRAME;
@@ -1159,7 +1160,7 @@
assert(mbmi->compound_idx == 1);
}
} else {
- assert(cpi->common.reference_mode != SINGLE_REFERENCE &&
+ assert(cpi->common.current_frame.reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION);
assert(masked_compound_used);
@@ -1278,7 +1279,8 @@
const MB_MODE_INFO *const *mbmi = xd->mi[0];
if (is_inter_block(mbmi)) {
#define FRAME_TO_CHECK 11
- if (cm->current_video_frame == FRAME_TO_CHECK && cm->show_frame == 1) {
+ if (cm->current_frame.frame_number == FRAME_TO_CHECK &&
+ cm->show_frame == 1) {
const BLOCK_SIZE bsize = mbmi->sb_type;
int_mv mv[2];
@@ -1315,8 +1317,8 @@
"show_frame=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, "
"ref[1]=%d, motion_mode=%d, mode_ctx=%d, "
"newmv_ctx=%d, zeromv_ctx=%d, refmv_ctx=%d, tx_size=%d\n",
- cm->current_video_frame, mi_row, mi_col, mbmi->skip_mode, mbmi->mode,
- bsize, cm->show_frame, mv[0].as_mv.row, mv[0].as_mv.col,
+ cm->current_frame.frame_number, mi_row, mi_col, mbmi->skip_mode,
+ mbmi->mode, bsize, cm->show_frame, mv[0].as_mv.row, mv[0].as_mv.col,
mv[1].as_mv.row, mv[1].as_mv.col, mbmi->ref_frame[0],
mbmi->ref_frame[1], mbmi->motion_mode, mode_ctx, newmv_ctx,
zeromv_ctx, refmv_ctx, mbmi->tx_size);
@@ -2212,7 +2214,8 @@
}
static int get_refresh_mask(AV1_COMP *cpi) {
- if ((cpi->common.frame_type == KEY_FRAME && cpi->common.show_frame) ||
+ if ((cpi->common.current_frame.frame_type == KEY_FRAME &&
+ cpi->common.show_frame) ||
frame_is_sframe(&cpi->common))
return 0xFF;
@@ -2552,7 +2555,7 @@
pars->random_seed += 3381; // Changing random seed for film grain
if (!pars->random_seed) // Random seed should not be zero
pars->random_seed += 7391;
- if (cm->frame_type == INTER_FRAME)
+ if (cm->current_frame.frame_type == INTER_FRAME)
aom_wb_write_bit(wb, pars->update_parameters);
else
pars->update_parameters = 1;
@@ -2834,7 +2837,7 @@
*/
/*
printf("Frame %d/%d: Enc Ref %d: %d %d %d %d\n",
- cm->current_video_frame, cm->show_frame, frame,
+ cm->current_frame.frame_number, cm->show_frame, frame,
cm->global_motion[frame].wmmat[0],
cm->global_motion[frame].wmmat[1], cm->global_motion[frame].wmmat[2],
cm->global_motion[frame].wmmat[3]);
@@ -2897,7 +2900,7 @@
}
#if 0 // For debug
- printf("\nFrame=%d: \n", cm->current_video_frame);
+ printf("\nFrame=%d: \n", cm->current_frame.frame_number);
printf("***frame_refs_short_signaling=%d\n", cm->frame_refs_short_signaling);
for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
printf("enc_ref(map_idx=%d, buf_idx=%d)=%d, vs. "
@@ -2922,15 +2925,17 @@
AV1_COMMON *const cm = &cpi->common;
const SequenceHeader *const seq_params = &cm->seq_params;
MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
+ CurrentFrame *const current_frame = &cm->current_frame;
// NOTE: By default all coded frames to be used as a reference
cm->is_reference_frame = 1;
- cm->frame_type = cm->intra_only ? INTRA_ONLY_FRAME : cm->frame_type;
+ current_frame->frame_type =
+ current_frame->intra_only ? INTRA_ONLY_FRAME : current_frame->frame_type;
if (seq_params->still_picture) {
assert(cm->show_existing_frame == 0);
assert(cm->show_frame == 1);
- assert(cm->frame_type == KEY_FRAME);
+ assert(current_frame->frame_type == KEY_FRAME);
}
if (!seq_params->reduced_still_picture_hdr) {
if (encode_show_existing_frame(cm)) {
@@ -2969,7 +2974,7 @@
aom_wb_write_bit(wb, 0); // show_existing_frame
}
- aom_wb_write_literal(wb, cm->frame_type, 2);
+ aom_wb_write_literal(wb, current_frame->frame_type, 2);
aom_wb_write_bit(wb, cm->show_frame);
if (cm->show_frame) {
@@ -2981,7 +2986,7 @@
}
if (frame_is_sframe(cm)) {
assert(cm->error_resilient_mode);
- } else if (!(cm->frame_type == KEY_FRAME && cm->show_frame)) {
+ } else if (!(current_frame->frame_type == KEY_FRAME && cm->show_frame)) {
aom_wb_write_bit(wb, cm->error_resilient_mode);
}
}
@@ -3031,7 +3036,7 @@
if (seq_params->order_hint_info.enable_order_hint)
aom_wb_write_literal(
- wb, cm->frame_offset,
+ wb, current_frame->order_hint,
seq_params->order_hint_info.order_hint_bits_minus_1 + 1);
if (!cm->error_resilient_mode && !frame_is_intra_only(cm)) {
@@ -3066,14 +3071,14 @@
}
}
cpi->refresh_frame_mask = get_refresh_mask(cpi);
- if (cm->frame_type == KEY_FRAME) {
+ if (current_frame->frame_type == KEY_FRAME) {
if (!cm->show_frame) { // unshown keyframe (forward keyframe)
aom_wb_write_literal(wb, cpi->refresh_frame_mask, REF_FRAMES);
} else {
assert(cpi->refresh_frame_mask == 0xFF);
}
} else {
- if (cm->frame_type == INTRA_ONLY_FRAME) {
+ if (current_frame->frame_type == INTRA_ONLY_FRAME) {
assert(cpi->refresh_frame_mask != 0xFF);
int updated_fb = -1;
for (int i = 0; i < REF_FRAMES; i++) {
@@ -3087,8 +3092,9 @@
assert(updated_fb >= 0);
cm->fb_of_context_type[cm->frame_context_idx] = updated_fb;
aom_wb_write_literal(wb, cpi->refresh_frame_mask, REF_FRAMES);
- } else if (cm->frame_type == INTER_FRAME || frame_is_sframe(cm)) {
- if (cm->frame_type == INTER_FRAME) {
+ } else if (current_frame->frame_type == INTER_FRAME ||
+ frame_is_sframe(cm)) {
+ if (current_frame->frame_type == INTER_FRAME) {
aom_wb_write_literal(wb, cpi->refresh_frame_mask, REF_FRAMES);
} else {
assert(frame_is_sframe(cm) && cpi->refresh_frame_mask == 0xFF);
@@ -3133,7 +3139,7 @@
}
}
- if (cm->frame_type == KEY_FRAME) {
+ if (current_frame->frame_type == KEY_FRAME) {
write_frame_size(cm, frame_size_override_flag, wb);
assert(!av1_superres_scaled(cm) || !cm->allow_intrabc);
if (cm->allow_screen_content_tools && !av1_superres_scaled(cm))
@@ -3141,12 +3147,13 @@
// all eight fbs are refreshed, pick one that will live long enough
cm->fb_of_context_type[REGULAR_FRAME] = 0;
} else {
- if (cm->frame_type == INTRA_ONLY_FRAME) {
+ if (current_frame->frame_type == INTRA_ONLY_FRAME) {
write_frame_size(cm, frame_size_override_flag, wb);
assert(!av1_superres_scaled(cm) || !cm->allow_intrabc);
if (cm->allow_screen_content_tools && !av1_superres_scaled(cm))
aom_wb_write_bit(wb, cm->allow_intrabc);
- } else if (cm->frame_type == INTER_FRAME || frame_is_sframe(cm)) {
+ } else if (current_frame->frame_type == INTER_FRAME ||
+ frame_is_sframe(cm)) {
MV_REFERENCE_FRAME ref_frame;
// NOTE: Error resilient mode turns off frame_refs_short_signaling
@@ -3265,12 +3272,14 @@
write_tx_mode(cm, &cm->tx_mode, wb);
if (cpi->allow_comp_inter_inter) {
- const int use_hybrid_pred = cm->reference_mode == REFERENCE_MODE_SELECT;
+ const int use_hybrid_pred =
+ current_frame->reference_mode == REFERENCE_MODE_SELECT;
aom_wb_write_bit(wb, use_hybrid_pred);
}
- if (cm->is_skip_mode_allowed) aom_wb_write_bit(wb, cm->skip_mode_flag);
+ if (current_frame->skip_mode_info.skip_mode_allowed)
+ aom_wb_write_bit(wb, current_frame->skip_mode_info.skip_mode_flag);
if (frame_might_allow_warped_motion(cm))
aom_wb_write_bit(wb, cm->allow_warped_motion);
@@ -3284,7 +3293,7 @@
if (seq_params->film_grain_params_present &&
(cm->show_frame || cm->showable_frame)) {
int flip_back_update_parameters_flag = 0;
- if (cm->frame_type != INTER_FRAME &&
+ if (current_frame->frame_type != INTER_FRAME &&
cm->film_grain_params.update_parameters == 0) {
cm->film_grain_params.update_parameters = 1;
flip_back_update_parameters_flag = 1;
@@ -3642,9 +3651,9 @@
#if EXT_TILE_DEBUG
{
char fn[20] = "./fh";
- fn[4] = cm->current_video_frame / 100 + '0';
- fn[5] = (cm->current_video_frame % 100) / 10 + '0';
- fn[6] = (cm->current_video_frame % 10) + '0';
+ fn[4] = cm->current_frame.frame_number / 100 + '0';
+ fn[5] = (cm->current_frame.frame_number % 100) / 10 + '0';
+ fn[6] = (cm->current_frame.frame_number % 10) + '0';
fn[7] = '\0';
av1_print_uncompressed_frame_header(data - frame_header_size,
frame_header_size, fn);
@@ -3706,7 +3715,7 @@
// If tile_copy_mode = 1, check if this tile is a copy tile.
// Very low chances to have copy tiles on the key frames, so don't
// search on key frames to reduce unnecessary search.
- if (cm->frame_type != KEY_FRAME && tile_copy_mode) {
+ if (cm->current_frame.frame_type != KEY_FRAME && tile_copy_mode) {
const int identical_tile_offset =
find_identical_tile(tile_row, tile_col, tile_buffers);
@@ -3954,7 +3963,7 @@
// The TD is now written outside the frame encode loop
// write sequence header obu if KEY_FRAME, preceded by 4-byte size
- if (cm->frame_type == KEY_FRAME && cm->show_frame) {
+ if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) {
obu_header_size = write_obu_header(OBU_SEQUENCE_HEADER, 0, data);
obu_payload_size = write_sequence_header_obu(cpi, data + obu_header_size);
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index cf250ce..08bb332 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -660,8 +660,8 @@
// Examine the resulting rate and for AQ mode 2 make a segment choice.
if ((rd_cost->rate != INT_MAX) && (aq_mode == COMPLEXITY_AQ) &&
(bsize >= BLOCK_16X16) &&
- (cm->frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame ||
- cpi->refresh_alt2_ref_frame ||
+ (cm->current_frame.frame_type == KEY_FRAME ||
+ cpi->refresh_alt_ref_frame || cpi->refresh_alt2_ref_frame ||
(cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref))) {
av1_caq_select_segment(cpi, x, bsize, mi_row, mi_col, rd_cost->rate);
}
@@ -894,6 +894,7 @@
MACROBLOCKD *const xd = &x->e_mbd;
const MB_MODE_INFO *const mbmi = xd->mi[0];
const MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
+ const CurrentFrame *const current_frame = &cm->current_frame;
const BLOCK_SIZE bsize = mbmi->sb_type;
FRAME_CONTEXT *fc = xd->tile_ctx;
const uint8_t allow_update_cdf = tile_data->allow_update_cdf;
@@ -906,7 +907,8 @@
const int seg_ref_active =
segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_REF_FRAME);
- if (cm->skip_mode_flag && !seg_ref_active && is_comp_ref_allowed(bsize)) {
+ if (current_frame->skip_mode_info.skip_mode_flag && !seg_ref_active &&
+ is_comp_ref_allowed(bsize)) {
const int skip_mode_ctx = av1_get_skip_mode_context(xd);
#if CONFIG_ENTROPY_STATS
td->counts->skip_mode[skip_mode_ctx][mbmi->skip_mode]++;
@@ -994,7 +996,7 @@
if (mbmi->skip_mode) {
rdc->skip_mode_used_flag = 1;
- if (cm->reference_mode == REFERENCE_MODE_SELECT) {
+ if (current_frame->reference_mode == REFERENCE_MODE_SELECT) {
assert(has_second_ref(mbmi));
rdc->compound_ref_used_flag = 1;
}
@@ -1021,7 +1023,7 @@
av1_collect_neighbors_ref_counts(xd);
- if (cm->reference_mode == REFERENCE_MODE_SELECT) {
+ if (current_frame->reference_mode == REFERENCE_MODE_SELECT) {
if (has_second_ref(mbmi))
// This flag is also updated for 4x4 blocks
rdc->compound_ref_used_flag = 1;
@@ -1249,7 +1251,7 @@
}
if (has_second_ref(mbmi)) {
- assert(cm->reference_mode != SINGLE_REFERENCE &&
+ assert(current_frame->reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION);
@@ -2108,7 +2110,8 @@
BLOCK_SIZE max_size = BLOCK_LARGEST;
// Trap case where we do not have a prediction.
- if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) {
+ if (left_in_image || above_in_image ||
+ cm->current_frame.frame_type != KEY_FRAME) {
// Default "min to max" and "max to min"
min_size = BLOCK_LARGEST;
max_size = BLOCK_4X4;
@@ -2116,7 +2119,7 @@
// NOTE: each call to get_sb_partition_size_range() uses the previous
// passed in values for min and max as a starting point.
// Find the min and max partition used in previous frame at this location
- if (cm->frame_type != KEY_FRAME) {
+ if (cm->current_frame.frame_type != KEY_FRAME) {
MB_MODE_INFO **prev_mi =
&cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col];
get_sb_partition_size_range(cm, xd, prev_mi, &min_size, &max_size);
@@ -3601,7 +3604,7 @@
if (cpi->sf.cb_partition_search && bsize == BLOCK_16X16) {
const int cb_partition_search_ctrl =
((pc_tree->index == 0 || pc_tree->index == 3) +
- get_chessboard_index(cm->current_video_frame)) &
+ get_chessboard_index(cm->current_frame.frame_number)) &
0x1;
if (cb_partition_search_ctrl && bsize > min_size && bsize < max_size)
@@ -5090,7 +5093,7 @@
cpi->sf.use_square_partition_only_threshold > BLOCK_4X4 &&
mi_row + mi_size_high[sb_size] < cm->mi_rows &&
mi_col + mi_size_wide[sb_size] < cm->mi_cols &&
- cm->frame_type != KEY_FRAME) {
+ cm->current_frame.frame_type != KEY_FRAME) {
first_partition_search_pass(cpi, td, tile_data, mi_row, mi_col, tp);
}
@@ -5324,8 +5327,9 @@
#if CONFIG_FP_MB_STATS
static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats,
AV1_COMMON *cm, uint8_t **this_frame_mb_stats) {
- uint8_t *mb_stats_in = firstpass_mb_stats->mb_stats_start +
- cm->current_video_frame * cm->MBs * sizeof(uint8_t);
+ uint8_t *mb_stats_in =
+ firstpass_mb_stats->mb_stats_start +
+ cm->current_frame.frame_number * cm->MBs * sizeof(uint8_t);
if (mb_stats_in > firstpass_mb_stats->mb_stats_end) return EOF;
@@ -5512,7 +5516,7 @@
const int ref_offset =
cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset;
if (get_relative_dist(&cm->seq_params.order_hint_info, ref_offset,
- (int)cm->frame_offset) > 0) {
+ (int)cm->current_frame.order_hint) > 0) {
one_sided_refs = 0; // bwd reference
break;
}
@@ -5522,11 +5526,12 @@
static INLINE void get_skip_mode_ref_offsets(const AV1_COMMON *cm,
int ref_offset[2]) {
+ const SkipModeInfo *const skip_mode_info = &cm->current_frame.skip_mode_info;
ref_offset[0] = ref_offset[1] = 0;
- if (!cm->is_skip_mode_allowed) return;
+ if (!skip_mode_info->skip_mode_allowed) return;
- const int buf_idx_0 = cm->frame_refs[cm->ref_frame_idx_0].idx;
- const int buf_idx_1 = cm->frame_refs[cm->ref_frame_idx_1].idx;
+ const int buf_idx_0 = cm->frame_refs[skip_mode_info->ref_frame_idx_0].idx;
+ const int buf_idx_1 = cm->frame_refs[skip_mode_info->ref_frame_idx_1].idx;
assert(buf_idx_0 != INVALID_IDX && buf_idx_1 != INVALID_IDX);
ref_offset[0] = cm->buffer_pool->frame_bufs[buf_idx_0].cur_frame_offset;
@@ -5537,11 +5542,11 @@
AV1_COMMON *const cm = &cpi->common;
av1_setup_skip_mode_allowed(cm);
- if (!cm->is_skip_mode_allowed) return 0;
+ if (!cm->current_frame.skip_mode_info.skip_mode_allowed) return 0;
// Turn off skip mode if the temporal distances of the reference pair to the
// current frame are different by more than 1 frame.
- const int cur_offset = (int)cm->frame_offset;
+ const int cur_offset = (int)cm->current_frame.order_hint;
int ref_offset[2];
get_skip_mode_ref_offsets(cm, ref_offset);
const int cur_to_ref0 = get_relative_dist(&cm->seq_params.order_hint_info,
@@ -5561,8 +5566,10 @@
AOM_BWD_FLAG,
AOM_ALT2_FLAG,
AOM_ALT_FLAG };
- const int ref_frame[2] = { cm->ref_frame_idx_0 + LAST_FRAME,
- cm->ref_frame_idx_1 + LAST_FRAME };
+ const int ref_frame[2] = {
+ cm->current_frame.skip_mode_info.ref_frame_idx_0 + LAST_FRAME,
+ cm->current_frame.skip_mode_info.ref_frame_idx_1 + LAST_FRAME
+ };
if (!(cpi->ref_frame_flags & flag_list[ref_frame[0]]) ||
!(cpi->ref_frame_flags & flag_list[ref_frame[1]]))
return 0;
@@ -5782,7 +5789,7 @@
#if !CONFIG_GLOBAL_MOTION_SEARCH
cpi->global_motion_search_done = 1;
#endif // !CONFIG_GLOBAL_MOTION_SEARCH
- if (cpi->common.frame_type == INTER_FRAME && cpi->source &&
+ if (cpi->common.current_frame.frame_type == INTER_FRAME && cpi->source &&
!cpi->global_motion_search_done) {
YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES];
int frame;
@@ -5917,7 +5924,8 @@
cpi->all_one_sided_refs =
frame_is_intra_only(cm) ? 0 : av1_refs_are_one_sided(cm);
- cm->skip_mode_flag = check_skip_mode_enabled(cpi);
+ cm->current_frame.skip_mode_info.skip_mode_flag =
+ check_skip_mode_enabled(cpi);
{
struct aom_usec_timer emr_timer;
@@ -5956,6 +5964,7 @@
void av1_encode_frame(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
+ CurrentFrame *const current_frame = &cm->current_frame;
const int num_planes = av1_num_planes(cm);
// Indicates whether or not to use a default reduced set for ext-tx
// rather than the potential full set of 16 transforms
@@ -5968,11 +5977,11 @@
int brf_offset =
cpi->twopass.gf_group.brf_src_offset[cpi->twopass.gf_group.index];
arf_offset = AOMMIN((MAX_GF_INTERVAL - 1), arf_offset + brf_offset);
- cm->frame_offset = cm->current_video_frame + arf_offset;
+ current_frame->order_hint = current_frame->frame_number + arf_offset;
} else {
- cm->frame_offset = cm->current_video_frame;
+ current_frame->order_hint = current_frame->frame_number;
}
- cm->frame_offset %=
+ current_frame->order_hint %=
(1 << (cm->seq_params.order_hint_info.order_hint_bits_minus_1 + 1));
// Make sure segment_id is no larger than last_active_segid.
@@ -6023,9 +6032,9 @@
/* prediction (compound, single or hybrid) mode selection */
// NOTE: "is_alt_ref" is true only for OVERLAY/INTNL_OVERLAY frames
if (is_alt_ref || !cpi->allow_comp_inter_inter)
- cm->reference_mode = SINGLE_REFERENCE;
+ current_frame->reference_mode = SINGLE_REFERENCE;
else
- cm->reference_mode = REFERENCE_MODE_SELECT;
+ current_frame->reference_mode = REFERENCE_MODE_SELECT;
cm->interp_filter = SWITCHABLE;
if (cm->large_scale_tile) cm->interp_filter = EIGHTTAP_REGULAR;
@@ -6040,22 +6049,24 @@
for (i = 0; i < REFERENCE_MODES; ++i)
mode_thrs[i] = (mode_thrs[i] + rdc->comp_pred_diff[i] / cm->MBs) / 2;
- if (cm->reference_mode == REFERENCE_MODE_SELECT) {
+ if (current_frame->reference_mode == REFERENCE_MODE_SELECT) {
// Use a flag that includes 4x4 blocks
if (rdc->compound_ref_used_flag == 0) {
- cm->reference_mode = SINGLE_REFERENCE;
+ current_frame->reference_mode = SINGLE_REFERENCE;
#if CONFIG_ENTROPY_STATS
av1_zero(cpi->td.counts->comp_inter);
#endif // CONFIG_ENTROPY_STATS
}
}
// Re-check on the skip mode status as reference mode may have been changed.
- if (frame_is_intra_only(cm) || cm->reference_mode == SINGLE_REFERENCE) {
- cm->is_skip_mode_allowed = 0;
- cm->skip_mode_flag = 0;
+ SkipModeInfo *const skip_mode_info = ¤t_frame->skip_mode_info;
+ if (frame_is_intra_only(cm) ||
+ current_frame->reference_mode == SINGLE_REFERENCE) {
+ skip_mode_info->skip_mode_allowed = 0;
+ skip_mode_info->skip_mode_flag = 0;
}
- if (cm->skip_mode_flag && rdc->skip_mode_used_flag == 0)
- cm->skip_mode_flag = 0;
+ if (skip_mode_info->skip_mode_flag && rdc->skip_mode_used_flag == 0)
+ skip_mode_info->skip_mode_flag = 0;
if (!cm->large_scale_tile) {
if (cm->tx_mode == TX_MODE_SELECT && cpi->td.mb.txb_split_count == 0)
@@ -6312,9 +6323,9 @@
if (!is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x,
pd->subsampling_y))
continue;
- mismatch_record_block_pre(pd->dst.buf, pd->dst.stride, cm->frame_offset,
- plane, pixel_c, pixel_r, pd->width,
- pd->height,
+ mismatch_record_block_pre(pd->dst.buf, pd->dst.stride,
+ cm->current_frame.order_hint, plane, pixel_c,
+ pixel_r, pd->width, pd->height,
xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH);
}
}
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index de5cc46..e0c0370 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -285,8 +285,8 @@
int blk_h = block_size_high[bsize];
mi_to_pixel_loc(&pixel_c, &pixel_r, mi_col, mi_row, blk_col, blk_row,
pd->subsampling_x, pd->subsampling_y);
- mismatch_record_block_tx(dst, pd->dst.stride, cm->frame_offset, plane,
- pixel_c, pixel_r, blk_w, blk_h,
+ mismatch_record_block_tx(dst, pd->dst.stride, cm->current_frame.order_hint,
+ plane, pixel_c, pixel_r, blk_w, blk_h,
xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH);
}
#endif
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 712f4aa..ce28c86 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -397,7 +397,7 @@
}
}
- if (cm->frame_type == KEY_FRAME && cm->show_frame) {
+ if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) {
cpi->refresh_golden_frame = 1;
cpi->refresh_alt_ref_frame = 1;
av1_zero(cpi->interp_filter_selected);
@@ -527,7 +527,7 @@
if (oxcf->film_grain_test_vector) {
cm->seq_params.film_grain_params_present = 1;
- if (cm->frame_type == KEY_FRAME) {
+ if (cm->current_frame.frame_type == KEY_FRAME) {
memcpy(&cm->film_grain_params,
film_grain_test_vectors + oxcf->film_grain_test_vector - 1,
sizeof(cm->film_grain_params));
@@ -669,7 +669,7 @@
int qi_delta;
// Disable and clear down for KF
- if (cm->frame_type == KEY_FRAME) {
+ if (cm->current_frame.frame_type == KEY_FRAME) {
// Clear down the global segmentation map
memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
seg->update_map = 0;
@@ -2606,7 +2606,7 @@
init_config(cpi, oxcf);
av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
- cm->current_video_frame = 0;
+ cm->current_frame.frame_number = 0;
cpi->seq_params_locked = 0;
cpi->partition_search_skippable_frame = 0;
cpi->tile_data = NULL;
@@ -2996,7 +2996,7 @@
cm = &cpi->common;
const int num_planes = av1_num_planes(cm);
- if (cm->current_video_frame > 0) {
+ if (cm->current_frame.frame_number > 0) {
#if CONFIG_ENTROPY_STATS
if (cpi->oxcf.pass != 1) {
fprintf(stderr, "Writing counts.stt\n");
@@ -3466,7 +3466,7 @@
for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
char file_name[256] = "";
snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv",
- cm->current_video_frame, ref_frame);
+ cm->current_frame.frame_number, ref_frame);
dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name);
}
}
@@ -3566,7 +3566,8 @@
// Only update all of the reference buffers if a KEY_FRAME is also a
// show_frame. This ensures a fwd keyframe does not update all of the buffers
- if ((cm->frame_type == KEY_FRAME && cm->show_frame) || frame_is_sframe(cm)) {
+ if ((cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) ||
+ frame_is_sframe(cm)) {
for (int ref_frame = 0; ref_frame < REF_FRAMES; ++ref_frame) {
assign_frame_buffer(pool->frame_bufs,
&cm->ref_frame_map[cpi->remapped_ref_idx[ref_frame]],
@@ -4137,7 +4138,7 @@
switch (oxcf->resize_mode) {
case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break;
case RESIZE_FIXED:
- if (cpi->common.frame_type == KEY_FRAME)
+ if (cpi->common.current_frame.frame_type == KEY_FRAME)
new_denom = oxcf->resize_kf_scale_denominator;
else
new_denom = oxcf->resize_scale_denominator;
@@ -4165,7 +4166,7 @@
switch (oxcf->superres_mode) {
case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break;
case SUPERRES_FIXED:
- if (cpi->common.frame_type == KEY_FRAME)
+ if (cpi->common.current_frame.frame_type == KEY_FRAME)
new_denom = oxcf->superres_kf_scale_denominator;
else
new_denom = oxcf->superres_scale_denominator;
@@ -4498,7 +4499,8 @@
// Update some stats from cyclic refresh, and check if we should not update
// golden reference, for 1 pass CBR.
- if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->frame_type != KEY_FRAME &&
+ if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
+ cm->current_frame.frame_type != KEY_FRAME &&
(cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR))
av1_cyclic_refresh_check_golden_update(cpi);
@@ -4572,8 +4574,9 @@
scale_references(cpi);
}
av1_set_quantizer(cm, q);
- // printf("Frame %d/%d: q = %d, frame_type = %d\n", cm->current_video_frame,
- // cm->show_frame, q, cm->frame_type);
+ // printf("Frame %d/%d: q = %d, frame_type = %d\n",
+ // cm->current_frame.frame_number,
+ // cm->show_frame, q, cm->current_frame.frame_type);
if (loop_count == 0) setup_frame(cpi);
@@ -4631,7 +4634,8 @@
if (cpi->oxcf.rc_mode == AOM_Q) {
loop = 0;
} else {
- if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced &&
+ if ((cm->current_frame.frame_type == KEY_FRAME) &&
+ rc->this_key_frame_forced &&
(rc->projected_frame_size < rc->max_frame_bandwidth)) {
int last_q = q;
int64_t kf_err;
@@ -4869,7 +4873,7 @@
// av1_update_reference() and av1_update_entropy() calls
// Note: The overrides are valid only for the next frame passed
// to encode_frame_to_data_rate() function
- if (cpi->ext_use_s_frame) cpi->common.frame_type = S_FRAME;
+ if (cpi->ext_use_s_frame) cpi->common.current_frame.frame_type = S_FRAME;
cpi->common.force_primary_ref_none = cpi->ext_use_primary_ref_none;
if (cpi->ext_refresh_frame_context_pending) {
@@ -4889,7 +4893,8 @@
// error_resilient_mode interferes with the use of show_existing_frame
// when forward reference keyframes are enabled.
cpi->common.error_resilient_mode =
- cpi->ext_use_error_resilient && cpi->common.frame_type != KEY_FRAME;
+ cpi->ext_use_error_resilient &&
+ cpi->common.current_frame.frame_type != KEY_FRAME;
}
#define DUMP_RECON_FRAMES 0
@@ -4898,10 +4903,11 @@
// NOTE(zoeliu): For debug - Output the filtered reconstructed video.
static void dump_filtered_recon_frames(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
+ const CurrentFrame *const current_frame = &cm->current_frame;
const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show;
if (recon_buf == NULL) {
- printf("Frame %d is not ready.\n", cm->current_video_frame);
+ printf("Frame %d is not ready.\n", current_frame->frame_number);
return;
}
@@ -4917,7 +4923,7 @@
"\n***Frame=%d (frame_offset=%d, show_frame=%d, "
"show_existing_frame=%d) "
"[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[",
- cm->current_video_frame, cm->frame_offset, cm->show_frame,
+ current_frame->frame_number, current_frame->order_hint, cm->show_frame,
cm->show_existing_frame);
for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx;
@@ -4935,7 +4941,7 @@
if (!cm->show_frame) {
printf("Frame %d is a no show frame, so no image dump.\n",
- cm->current_video_frame);
+ current_frame->frame_number);
return;
}
@@ -4943,7 +4949,7 @@
char file_name[256] = "/tmp/enc_filtered_recon.yuv";
FILE *f_recon = NULL;
- if (cm->current_video_frame == 0) {
+ if (current_frame->frame_number == 0) {
if ((f_recon = fopen(file_name, "wb")) == NULL) {
printf("Unable to open file %s to write.\n", file_name);
return;
@@ -4959,9 +4965,9 @@
"show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, "
"refresh_alt_ref_frame=%d, rf_level=%d, "
"y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n",
- cm->current_video_frame, cpi->twopass.gf_group.index,
+ current_frame->frame_number, cpi->twopass.gf_group.index,
cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index],
- cm->frame_offset, cm->show_frame, cm->show_existing_frame,
+ current_frame->order_hint, cm->show_frame, cm->show_existing_frame,
cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame,
cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index],
recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height);
@@ -5010,6 +5016,7 @@
unsigned int *frame_flags) {
AV1_COMMON *const cm = &cpi->common;
SequenceHeader *const seq_params = &cm->seq_params;
+ CurrentFrame *const current_frame = &cm->current_frame;
const AV1EncoderConfig *const oxcf = &cpi->oxcf;
struct segmentation *const seg = &cm->seg;
@@ -5018,7 +5025,7 @@
// frame type has been decided outside of this function call
cm->cur_frame->intra_only = frame_is_intra_only(cm);
- cm->cur_frame->frame_type = cm->frame_type;
+ cm->cur_frame->frame_type = current_frame->frame_type;
// S_FRAMEs are always error resilient
cm->error_resilient_mode |= frame_is_sframe(cm);
@@ -5037,8 +5044,8 @@
cpi->oxcf.allow_warped_motion && frame_might_allow_warped_motion(cm);
// Reset the frame packet stamp index.
- if (cm->frame_type == KEY_FRAME && cm->show_frame)
- cm->current_video_frame = 0;
+ if (current_frame->frame_type == KEY_FRAME && cm->show_frame)
+ current_frame->frame_number = 0;
// NOTE:
// (1) Move the setup of the ref_frame_flags upfront as it would be
@@ -5046,16 +5053,16 @@
// (2) The setup of the ref_frame_flags applies to both
// show_existing_frame's
// and the other cases.
- if (cm->current_video_frame > 0)
+ if (current_frame->frame_number > 0)
cpi->ref_frame_flags = get_ref_frame_flags(cpi);
if (encode_show_existing_frame(cm)) {
// NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current
// BWDREF_FRAME in the reference frame buffer.
- if (cm->frame_type == KEY_FRAME) {
+ if (current_frame->frame_type == KEY_FRAME) {
cm->reset_decoder_state = 1;
} else {
- cm->frame_type = INTER_FRAME;
+ current_frame->frame_type = INTER_FRAME;
}
cm->show_frame = 1;
cpi->frame_flags = *frame_flags;
@@ -5072,7 +5079,7 @@
cm->frame_to_show = get_frame_new_buffer(cm);
// Update current frame offset.
- cm->frame_offset =
+ current_frame->order_hint =
cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset;
#if DUMP_RECON_FRAMES == 1
@@ -5102,7 +5109,7 @@
*frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
// Update the frame type
- cm->last_frame_type = cm->frame_type;
+ cm->last_frame_type = current_frame->frame_type;
// Since we allocate a spot for the OVERLAY frame in the gf group, we need
// to do post-encoding update accordingly.
@@ -5111,7 +5118,7 @@
av1_rc_postencode_update(cpi, *size);
}
- ++cm->current_video_frame;
+ ++current_frame->frame_number;
return AOM_CODEC_OK;
}
@@ -5144,7 +5151,7 @@
// For 1 pass CBR, check if we are dropping this frame.
// Never drop on key frame.
if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR &&
- cm->frame_type != KEY_FRAME) {
+ current_frame->frame_type != KEY_FRAME) {
if (av1_rc_drop_frame(cpi)) {
av1_rc_postencode_update_drop_frame(cpi);
return AOM_CODEC_OK;
@@ -5217,7 +5224,7 @@
cm->last_tile_rows = cm->tile_rows;
#ifdef OUTPUT_YUV_SKINMAP
- if (cpi->common.current_video_frame > 1) {
+ if (cpi->common.current_frame.frame_number > 1) {
av1_compute_skin_map(cpi, yuv_skinmap_file);
}
#endif // OUTPUT_YUV_SKINMAP
@@ -5235,7 +5242,8 @@
}
// If the encoder forced a KEY_FRAME decision or if frame is an S_FRAME
- if ((cm->frame_type == KEY_FRAME && cm->show_frame) || frame_is_sframe(cm)) {
+ if ((current_frame->frame_type == KEY_FRAME && cm->show_frame) ||
+ frame_is_sframe(cm)) {
cpi->refresh_last_frame = 1;
}
@@ -5339,11 +5347,11 @@
else
cpi->frame_flags &= ~FRAMEFLAGS_BWDREF;
- cm->last_frame_type = cm->frame_type;
+ cm->last_frame_type = current_frame->frame_type;
av1_rc_postencode_update(cpi, *size);
- if (cm->frame_type == KEY_FRAME) {
+ if (current_frame->frame_type == KEY_FRAME) {
// Tell the caller that the frame was coded as a key frame
*frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY;
} else {
@@ -5368,7 +5376,7 @@
// Don't increment frame counters if this was an altref buffer
// update not a real frame
- ++cm->current_video_frame;
+ ++current_frame->frame_number;
}
// NOTE: Shall not refer to any frame not used as reference.
@@ -5389,7 +5397,7 @@
// differently here for rc->avg_frame_bandwidth.
if (cpi->common.show_frame || cpi->rc.is_bwd_ref_frame) {
if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref ||
- cpi->common.frame_type == KEY_FRAME) {
+ cpi->common.current_frame.frame_type == KEY_FRAME) {
// If this is a show_existing_frame with a source other than altref,
// or if it is not a displayed forward keyframe, the keyframe update
// counters were incremented when it was originally encoded.
@@ -5417,7 +5425,7 @@
// a displayed forward keyframe, the index was incremented when it was
// originally encoded.
if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref ||
- cpi->common.frame_type == KEY_FRAME) {
+ cpi->common.current_frame.frame_type == KEY_FRAME) {
++cpi->twopass.gf_group.index;
}
}
@@ -5718,7 +5726,7 @@
uint32_t bit_depth = 8;
#if CONFIG_INTER_STATS_ONLY
- if (cm->frame_type == KEY_FRAME) return; // skip key frame
+ if (cm->current_frame.frame_type == KEY_FRAME) return; // skip key frame
#endif
cpi->bytes += frame_bytes;
@@ -5763,7 +5771,7 @@
double v2 = psnr.psnr[3];
double frame_psnr2 = psnr.psnr[0];
fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n",
- cm->current_video_frame, y2, u2, v2,
+ cm->current_frame.frame_number, y2, u2, v2,
frame_psnr2, frame_ssim2);
fclose(f);
}
@@ -6512,6 +6520,7 @@
const aom_rational_t *timebase) {
const AV1EncoderConfig *const oxcf = &cpi->oxcf;
AV1_COMMON *const cm = &cpi->common;
+ CurrentFrame *const current_frame = &cm->current_frame;
const int num_planes = av1_num_planes(cm);
BufferPool *const pool = cm->buffer_pool;
RATE_CONTROL *const rc = &cpi->rc;
@@ -6527,7 +6536,8 @@
assert(cpi->oxcf.max_threads == 0 &&
"bitstream debug tool does not support multithreading");
bitstream_queue_record_write();
- bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame);
+ bitstream_queue_set_frame_write(current_frame->frame_number * 2 +
+ cm->show_frame);
#endif
cm->showable_frame = 0;
@@ -6554,7 +6564,7 @@
// does not depend on any previous frames. We must make this exception here
// because of the use of show_existing_frame with forward coded keyframes.
struct lookahead_entry *lookahead_src = NULL;
- if (cm->current_video_frame > 0)
+ if (current_frame->frame_number > 0)
lookahead_src = av1_lookahead_peek(cpi->lookahead, 0);
int use_show_existing = 1;
@@ -6658,7 +6668,7 @@
}
}
cm->show_frame = 0;
- cm->intra_only = 0;
+ current_frame->intra_only = 0;
if (oxcf->pass < 2) {
// In second pass, the buffer updates configure will be set
@@ -6700,7 +6710,7 @@
}
cm->show_frame = 0;
- cm->intra_only = 0;
+ current_frame->intra_only = 0;
if (oxcf->pass < 2) {
// In second pass, the buffer updates configure will be set
@@ -6718,7 +6728,7 @@
if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) {
cm->showable_frame = 1;
cm->show_frame = 0;
- cm->intra_only = 0;
+ current_frame->intra_only = 0;
if (oxcf->pass < 2) {
// In second pass, the buffer updates configure will be set
@@ -6730,17 +6740,17 @@
if (!source) {
// Get last frame source.
- if (cm->current_video_frame > 0) {
+ if (current_frame->frame_number > 0) {
if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL)
return -1;
}
- if (cm->current_video_frame > 0) assert(last_source != NULL);
+ if (current_frame->frame_number > 0) assert(last_source != NULL);
// Read in the source frame.
source = av1_lookahead_pop(cpi->lookahead, flush);
if (source != NULL) {
cm->show_frame = 1;
- cm->intra_only = 0;
+ current_frame->intra_only = 0;
// Check to see if the frame should be encoded as an arf overlay.
check_src_altref(cpi, source);
@@ -6892,9 +6902,9 @@
#if EXT_TILE_DEBUG
if (cm->large_scale_tile && oxcf->pass == 2) {
char fn[20] = "./fc";
- fn[4] = cm->current_video_frame / 100 + '0';
- fn[5] = (cm->current_video_frame % 100) / 10 + '0';
- fn[6] = (cm->current_video_frame % 10) + '0';
+ fn[4] = current_frame->frame_number / 100 + '0';
+ fn[5] = (current_frame->frame_number % 100) / 10 + '0';
+ fn[6] = (current_frame->frame_number % 10) + '0';
fn[7] = '\0';
av1_print_frame_contexts(cm->fc, fn);
}
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index cb286eb..70f3ada 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -1059,8 +1059,8 @@
// frame. An exception can be made for a forward keyframe since it has no
// previous dependencies.
static INLINE int encode_show_existing_frame(const AV1_COMMON *cm) {
- return cm->show_existing_frame &&
- (!cm->error_resilient_mode || cm->frame_type == KEY_FRAME);
+ return cm->show_existing_frame && (!cm->error_resilient_mode ||
+ cm->current_frame.frame_type == KEY_FRAME);
}
// Returns a Sequence Header OBU stored in an aom_fixed_buf_t, or NULL upon
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index 56fc611..b68fdbb 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -451,11 +451,11 @@
static void set_first_pass_params(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
- if (!cpi->refresh_alt_ref_frame &&
- (cm->current_video_frame == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY))) {
- cm->frame_type = KEY_FRAME;
+ if (!cpi->refresh_alt_ref_frame && (cm->current_frame.frame_number == 0 ||
+ (cpi->frame_flags & FRAMEFLAGS_KEY))) {
+ cm->current_frame.frame_type = KEY_FRAME;
} else {
- cm->frame_type = INTER_FRAME;
+ cm->current_frame.frame_type = INTER_FRAME;
}
// Do not use periodic key frames.
cpi->rc.frames_to_key = INT_MAX;
@@ -490,6 +490,7 @@
int mb_row, mb_col;
MACROBLOCK *const x = &cpi->td.mb;
AV1_COMMON *const cm = &cpi->common;
+ CurrentFrame *const current_frame = &cm->current_frame;
const SequenceHeader *const seq_params = &cm->seq_params;
const int num_planes = av1_num_planes(cm);
MACROBLOCKD *const xd = &x->e_mbd;
@@ -772,7 +773,7 @@
}
// Search in an older reference frame.
- if ((cm->current_video_frame > 1) && gld_yv12 != NULL) {
+ if ((current_frame->frame_number > 1) && gld_yv12 != NULL) {
// Assume 0,0 motion with no mv overhead.
int gf_motion_error;
@@ -997,7 +998,7 @@
brightness_factor = brightness_factor / (double)num_mbs;
fps.weight = intra_factor * brightness_factor;
- fps.frame = cm->current_video_frame;
+ fps.frame = current_frame->frame_number;
fps.coded_error = (double)(coded_error >> 8) + min_err;
fps.sr_coded_error = (double)(sr_coded_error >> 8) + min_err;
fps.intra_error = (double)(intra_error >> 8) + min_err;
@@ -1056,7 +1057,7 @@
// Copy the previous Last Frame back into gf and and arf buffers if
// the prediction is good enough... but also don't allow it to lag too far.
if ((twopass->sr_update_lag > 3) ||
- ((cm->current_video_frame > 0) &&
+ ((current_frame->frame_number > 0) &&
(twopass->this_frame_stats.pcnt_inter > 0.20) &&
((twopass->this_frame_stats.intra_error /
DOUBLE_DIVIDE_CHECK(twopass->this_frame_stats.coded_error)) > 2.0))) {
@@ -1081,7 +1082,7 @@
// Special case for the first frame. Copy into the GF buffer as a second
// reference.
- if (cm->current_video_frame == 0 &&
+ if (current_frame->frame_number == 0 &&
get_ref_frame_map_idx(cpi, GOLDEN_FRAME) != INVALID_IDX) {
assign_frame_buffer(
pool->frame_bufs,
@@ -1094,9 +1095,9 @@
char filename[512];
FILE *recon_file;
snprintf(filename, sizeof(filename), "enc%04d.yuv",
- (int)cm->current_video_frame);
+ (int)current_frame->frame_number);
- if (cm->current_video_frame == 0)
+ if (current_frame->frame_number == 0)
recon_file = fopen(filename, "wb");
else
recon_file = fopen(filename, "ab");
@@ -1105,7 +1106,7 @@
fclose(recon_file);
}
- ++cm->current_video_frame;
+ ++current_frame->frame_number;
}
static double calc_correction_factor(double err_per_mb, double err_divisor,
@@ -1698,7 +1699,7 @@
RATE_CONTROL *const rc = &cpi->rc;
TWO_PASS *const twopass = &cpi->twopass;
GF_GROUP *const gf_group = &twopass->gf_group;
- const int key_frame = cpi->common.frame_type == KEY_FRAME;
+ const int key_frame = cpi->common.current_frame.frame_type == KEY_FRAME;
assert(rc->baseline_gf_interval >= 4 &&
rc->baseline_gf_interval <= MAX_PYRAMID_SIZE);
@@ -1819,7 +1820,7 @@
RATE_CONTROL *const rc = &cpi->rc;
TWO_PASS *const twopass = &cpi->twopass;
GF_GROUP *const gf_group = &twopass->gf_group;
- const int key_frame = cpi->common.frame_type == KEY_FRAME;
+ const int key_frame = cpi->common.current_frame.frame_type == KEY_FRAME;
assert(rc->baseline_gf_interval == GF_INTERVAL_4);
@@ -1924,7 +1925,7 @@
GF_GROUP *const gf_group = &twopass->gf_group;
int i;
int frame_index = 0;
- const int key_frame = cpi->common.frame_type == KEY_FRAME;
+ const int key_frame = cpi->common.current_frame.frame_type == KEY_FRAME;
// The use of bi-predictive frames are only enabled when following 3
// conditions are met:
@@ -2162,7 +2163,7 @@
av1_zero_array(ext_arf_boost, MAX_EXT_ARFS);
- key_frame = cpi->common.frame_type == KEY_FRAME;
+ key_frame = cpi->common.current_frame.frame_type == KEY_FRAME;
// For key frames the frame target rate is already set and it
// is also the golden frame.
@@ -2769,7 +2770,7 @@
reset_fpf_position(twopass, start_pos);
// Calculate a section intra ratio used in setting max loop filter.
- if (cpi->common.frame_type != KEY_FRAME) {
+ if (cpi->common.current_frame.frame_type != KEY_FRAME) {
twopass->section_intra_rating = calculate_section_intra_ratio(
start_pos, twopass->stats_in_end, rc->baseline_gf_interval);
}
@@ -2908,7 +2909,7 @@
av1_zero(next_frame);
- cpi->common.frame_type = KEY_FRAME;
+ cpi->common.current_frame.frame_type = KEY_FRAME;
rc->frames_since_key = 0;
// Reset the GF group data structures.
@@ -3203,6 +3204,7 @@
void av1_rc_get_second_pass_params(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
+ CurrentFrame *const current_frame = &cm->current_frame;
RATE_CONTROL *const rc = &cpi->rc;
TWO_PASS *const twopass = &cpi->twopass;
GF_GROUP *const gf_group = &twopass->gf_group;
@@ -3211,7 +3213,7 @@
int target_rate;
- frames_left = (int)(twopass->total_stats.count - cm->current_video_frame);
+ frames_left = (int)(twopass->total_stats.count - current_frame->frame_number);
if (!twopass->stats_in) return;
@@ -3226,9 +3228,9 @@
if (cpi->no_show_kf) {
assert(gf_group->update_type[gf_group->index] == ARF_UPDATE);
- cm->frame_type = KEY_FRAME;
+ current_frame->frame_type = KEY_FRAME;
} else {
- cm->frame_type = INTER_FRAME;
+ current_frame->frame_type = INTER_FRAME;
}
// Do the firstpass stats indicate that this frame is skippable for the
@@ -3244,7 +3246,7 @@
if (cpi->oxcf.rc_mode == AOM_Q) {
twopass->active_worst_quality = cpi->oxcf.cq_level;
- } else if (cm->current_video_frame == 0) {
+ } else if (current_frame->frame_number == 0) {
// Special case code for first frame.
const int section_target_bandwidth =
(int)(twopass->bits_left / frames_left);
@@ -3287,7 +3289,7 @@
find_next_key_frame(cpi, &this_frame);
this_frame = this_frame_copy;
} else {
- cm->frame_type = INTER_FRAME;
+ current_frame->frame_type = INTER_FRAME;
}
// Define a new GF/ARF group. (Should always enter here for key frames).
@@ -3301,7 +3303,7 @@
FILE *fpfile;
fpfile = fopen("arf.stt", "a");
++arf_count;
- fprintf(fpfile, "%10d %10d %10d %10d %10d\n", cm->current_video_frame,
+ fprintf(fpfile, "%10d %10d %10d %10d %10d\n", current_frame->frame_number,
rc->frames_till_gf_update_due, rc->kf_boost, arf_count,
rc->gfu_boost);
@@ -3320,7 +3322,7 @@
target_rate = gf_group->bit_allocation[gf_group->index];
- if (cpi->common.frame_type == KEY_FRAME)
+ if (cpi->common.current_frame.frame_type == KEY_FRAME)
target_rate = av1_rc_clamp_iframe_target_size(cpi, target_rate);
else
target_rate = av1_rc_clamp_pframe_target_size(cpi, target_rate);
@@ -3367,7 +3369,7 @@
rc->rate_error_estimate = 0;
}
- if (cpi->common.frame_type != KEY_FRAME) {
+ if (cpi->common.current_frame.frame_type != KEY_FRAME) {
twopass->kf_group_bits -= bits_used;
twopass->last_kfgroup_zeromotion_pct = twopass->kf_zeromotion_pct;
}
diff --git a/av1/encoder/picklpf.c b/av1/encoder/picklpf.c
index 5bd0e60..b6b84c8 100644
--- a/av1/encoder/picklpf.c
+++ b/av1/encoder/picklpf.c
@@ -213,7 +213,7 @@
int filt_guess;
switch (cm->seq_params.bit_depth) {
case AOM_BITS_8:
- filt_guess = (cm->frame_type == KEY_FRAME)
+ filt_guess = (cm->current_frame.frame_type == KEY_FRAME)
? ROUND_POWER_OF_TWO(q * 17563 - 421574, 18)
: ROUND_POWER_OF_TWO(q * 6017 + 650707, 18);
break;
@@ -229,7 +229,8 @@
"or AOM_BITS_12");
return;
}
- if (cm->seq_params.bit_depth != AOM_BITS_8 && cm->frame_type == KEY_FRAME)
+ if (cm->seq_params.bit_depth != AOM_BITS_8 &&
+ cm->current_frame.frame_type == KEY_FRAME)
filt_guess -= 4;
// TODO(chengchen): retrain the model for Y, U, V filter levels
lf->filter_level[0] = clamp(filt_guess, min_filter_level, max_filter_level);
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index 53c5ec7..c31baa9 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -357,7 +357,7 @@
const RATE_CONTROL *const rc = &cpi->rc;
double rcf;
- if (cpi->common.frame_type == KEY_FRAME) {
+ if (cpi->common.current_frame.frame_type == KEY_FRAME) {
rcf = rc->rate_correction_factors[KF_STD];
} else if (cpi->oxcf.pass == 2) {
RATE_FACTOR_LEVEL rf_lvl =
@@ -384,7 +384,7 @@
factor = fclamp(factor, MIN_BPB_FACTOR, MAX_BPB_FACTOR);
- if (cpi->common.frame_type == KEY_FRAME) {
+ if (cpi->common.current_frame.frame_type == KEY_FRAME) {
rc->rate_correction_factors[KF_STD] = factor;
} else if (cpi->oxcf.pass == 2) {
RATE_FACTOR_LEVEL rf_lvl =
@@ -425,8 +425,8 @@
av1_cyclic_refresh_estimate_bits_at_q(cpi, rate_correction_factor);
} else {
projected_size_based_on_q = av1_estimate_bits_at_q(
- cpi->common.frame_type, cm->base_qindex, MBs, rate_correction_factor,
- cm->seq_params.bit_depth);
+ cpi->common.current_frame.frame_type, cm->base_qindex, MBs,
+ rate_correction_factor, cm->seq_params.bit_depth);
}
// Work out a size correction factor.
if (projected_size_based_on_q > FRAME_OVERHEAD_BITS)
@@ -497,8 +497,9 @@
bits_per_mb_at_this_q =
(int)av1_cyclic_refresh_rc_bits_per_mb(cpi, i, correction_factor);
} else {
- bits_per_mb_at_this_q = (int)av1_rc_bits_per_mb(
- cm->frame_type, i, correction_factor, cm->seq_params.bit_depth);
+ bits_per_mb_at_this_q =
+ (int)av1_rc_bits_per_mb(cm->current_frame.frame_type, i,
+ correction_factor, cm->seq_params.bit_depth);
}
if (bits_per_mb_at_this_q <= target_bits_per_mb) {
@@ -569,10 +570,10 @@
static int calc_active_worst_quality_one_pass_vbr(const AV1_COMP *cpi) {
const RATE_CONTROL *const rc = &cpi->rc;
- const unsigned int curr_frame = cpi->common.current_video_frame;
+ const unsigned int curr_frame = cpi->common.current_frame.frame_number;
int active_worst_quality;
- if (cpi->common.frame_type == KEY_FRAME) {
+ if (cpi->common.current_frame.frame_type == KEY_FRAME) {
active_worst_quality =
curr_frame == 0 ? rc->worst_quality : rc->last_q[KEY_FRAME] * 2;
} else {
@@ -604,13 +605,13 @@
int adjustment = 0;
int active_worst_quality;
int ambient_qp;
- if (cm->frame_type == KEY_FRAME) return rc->worst_quality;
+ if (cm->current_frame.frame_type == KEY_FRAME) return rc->worst_quality;
// For ambient_qp we use minimum of avg_frame_qindex[KEY_FRAME/INTER_FRAME]
// for the first few frames following key frame. These are both initialized
// to worst_quality and updated with (3/4, 1/4) average in postencode_update.
// So for first few frames following key, the qp of that key frame is weighted
// into the active_worst_quality setting.
- ambient_qp = (cm->current_video_frame < 5)
+ ambient_qp = (cm->current_frame.frame_number < 5)
? AOMMIN(rc->avg_frame_qindex[INTER_FRAME],
rc->avg_frame_qindex[KEY_FRAME])
: rc->avg_frame_qindex[INTER_FRAME];
@@ -650,6 +651,7 @@
int *top_index) {
const AV1_COMMON *const cm = &cpi->common;
const RATE_CONTROL *const rc = &cpi->rc;
+ const CurrentFrame *const current_frame = &cm->current_frame;
int active_best_quality;
int active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
int q;
@@ -668,7 +670,7 @@
int delta_qindex = av1_compute_qdelta(rc, last_boosted_q,
(last_boosted_q * 0.75), bit_depth);
active_best_quality = AOMMAX(qindex + delta_qindex, rc->best_quality);
- } else if (cm->current_video_frame > 0) {
+ } else if (current_frame->frame_number > 0) {
// not first frame of one pass and kf_boost is set
double q_adj_factor = 1.0;
double q_val;
@@ -701,7 +703,7 @@
active_best_quality = get_gf_active_quality(rc, q, bit_depth);
} else {
// Use the lower of active_worst_quality and recent/average Q.
- if (cm->current_video_frame > 1) {
+ if (current_frame->frame_number > 1) {
if (rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality)
active_best_quality = rtc_minq[rc->avg_frame_qindex[INTER_FRAME]];
else
@@ -724,18 +726,18 @@
*bottom_index = active_best_quality;
// Limit Q range for the adaptive loop.
- if (cm->frame_type == KEY_FRAME && !rc->this_key_frame_forced &&
- !(cm->current_video_frame == 0)) {
+ if (current_frame->frame_type == KEY_FRAME && !rc->this_key_frame_forced &&
+ !(current_frame->frame_number == 0)) {
int qdelta = 0;
aom_clear_system_state();
- qdelta = av1_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
+ qdelta = av1_compute_qdelta_by_rate(&cpi->rc, current_frame->frame_type,
active_worst_quality, 2.0, bit_depth);
*top_index = active_worst_quality + qdelta;
*top_index = AOMMAX(*top_index, *bottom_index);
}
// Special case code to try and match quality with forced key frames
- if (cm->frame_type == KEY_FRAME && rc->this_key_frame_forced) {
+ if (current_frame->frame_type == KEY_FRAME && rc->this_key_frame_forced) {
q = rc->last_boosted_qindex;
} else {
q = av1_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
@@ -774,6 +776,7 @@
int *top_index) {
const AV1_COMMON *const cm = &cpi->common;
const RATE_CONTROL *const rc = &cpi->rc;
+ const CurrentFrame *const current_frame = &cm->current_frame;
const AV1EncoderConfig *const oxcf = &cpi->oxcf;
const int cq_level = get_active_cq_level(rc, oxcf);
int active_best_quality;
@@ -849,12 +852,12 @@
0.70, 1.0, 0.85, 1.0 };
const int delta_qindex = av1_compute_qdelta(
rc, q_val,
- q_val * delta_rate[cm->current_video_frame % FIXED_GF_INTERVAL],
+ q_val * delta_rate[current_frame->frame_number % FIXED_GF_INTERVAL],
bit_depth);
active_best_quality = AOMMAX(qindex + delta_qindex, rc->best_quality);
} else {
// Use the lower of active_worst_quality and recent/average Q.
- active_best_quality = (cm->current_video_frame > 1)
+ active_best_quality = (current_frame->frame_number > 1)
? inter_minq[rc->avg_frame_qindex[INTER_FRAME]]
: inter_minq[rc->avg_frame_qindex[KEY_FRAME]];
// For the constrained quality mode we don't want
@@ -878,14 +881,15 @@
{
int qdelta = 0;
aom_clear_system_state();
- if (cm->frame_type == KEY_FRAME && !rc->this_key_frame_forced &&
- !(cm->current_video_frame == 0)) {
- qdelta = av1_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
+ if (current_frame->frame_type == KEY_FRAME && !rc->this_key_frame_forced &&
+ !(current_frame->frame_number == 0)) {
+ qdelta = av1_compute_qdelta_by_rate(&cpi->rc, current_frame->frame_type,
active_worst_quality, 2.0, bit_depth);
} else if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
- qdelta = av1_compute_qdelta_by_rate(
- &cpi->rc, cm->frame_type, active_worst_quality, 1.75, bit_depth);
+ qdelta =
+ av1_compute_qdelta_by_rate(&cpi->rc, current_frame->frame_type,
+ active_worst_quality, 1.75, bit_depth);
}
*top_index = active_worst_quality + qdelta;
*top_index = AOMMAX(*top_index, *bottom_index);
@@ -894,7 +898,8 @@
if (oxcf->rc_mode == AOM_Q) {
q = active_best_quality;
// Special case code to try and match quality with forced key frames
- } else if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced) {
+ } else if ((current_frame->frame_type == KEY_FRAME) &&
+ rc->this_key_frame_forced) {
q = rc->last_boosted_qindex;
} else {
q = av1_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
@@ -1148,7 +1153,7 @@
// Modify active_best_quality for downscaled normal frames.
if (av1_frame_scaled(cm) && !frame_is_kf_gf_arf(cpi)) {
int qdelta = av1_compute_qdelta_by_rate(
- rc, cm->frame_type, active_best_quality, 2.0, bit_depth);
+ rc, cm->current_frame.frame_type, active_best_quality, 2.0, bit_depth);
active_best_quality =
AOMMAX(active_best_quality + qdelta, rc->best_quality);
}
@@ -1448,6 +1453,7 @@
void av1_rc_postencode_update(AV1_COMP *cpi, uint64_t bytes_used) {
const AV1_COMMON *const cm = &cpi->common;
+ const CurrentFrame *const current_frame = &cm->current_frame;
RATE_CONTROL *const rc = &cpi->rc;
#if CUSTOMIZED_GF
const TWO_PASS *const twopass = &cpi->twopass;
@@ -1473,7 +1479,7 @@
av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
// Keep a record of last Q and ambient average Q.
- if (cm->frame_type == KEY_FRAME) {
+ if (current_frame->frame_type == KEY_FRAME) {
rc->last_q[KEY_FRAME] = qindex;
rc->avg_frame_qindex[KEY_FRAME] =
ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2);
@@ -1499,13 +1505,14 @@
// If all mbs in this group are skipped only update if the Q value is
// better than that already stored.
// This is used to help set quality in forced key frames to reduce popping
- if ((qindex < rc->last_boosted_qindex) || (cm->frame_type == KEY_FRAME) ||
+ if ((qindex < rc->last_boosted_qindex) ||
+ (current_frame->frame_type == KEY_FRAME) ||
(!rc->constrained_gf_group &&
(cpi->refresh_alt_ref_frame || is_intrnl_arf ||
(cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) {
rc->last_boosted_qindex = qindex;
}
- if (cm->frame_type == KEY_FRAME) rc->last_kf_qindex = qindex;
+ if (current_frame->frame_type == KEY_FRAME) rc->last_kf_qindex = qindex;
update_buffer_level(cpi, rc->projected_frame_size);
@@ -1515,7 +1522,7 @@
rc->this_frame_target =
(int)(rc->this_frame_target /
resize_rate_factor(cpi, cm->width, cm->height));
- if (cm->frame_type != KEY_FRAME) {
+ if (current_frame->frame_type != KEY_FRAME) {
rc->rolling_target_bits = ROUND_POWER_OF_TWO(
rc->rolling_target_bits * 3 + rc->this_frame_target, 2);
rc->rolling_actual_bits = ROUND_POWER_OF_TWO(
@@ -1536,15 +1543,15 @@
rc->total_target_vs_actual = rc->total_actual_bits - rc->total_target_bits;
if (is_altref_enabled(cpi) && cpi->refresh_alt_ref_frame &&
- (cm->frame_type != KEY_FRAME))
+ (current_frame->frame_type != KEY_FRAME))
// Update the alternate reference frame stats as appropriate.
update_alt_ref_frame_stats(cpi);
else
// Update the Golden frame stats as appropriate.
update_golden_frame_stats(cpi);
- if (cm->frame_type == KEY_FRAME) rc->frames_since_key = 0;
- // if (cm->current_video_frame == 1 && cm->show_frame)
+ if (current_frame->frame_type == KEY_FRAME) rc->frames_since_key = 0;
+ // if (current_frame->frame_number == 1 && cm->show_frame)
/*
rc->this_frame_target =
(int)(rc->this_frame_target / resize_rate_factor(cpi, cm->width,
@@ -1592,6 +1599,7 @@
void av1_rc_get_one_pass_vbr_params(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
+ CurrentFrame *const current_frame = &cm->current_frame;
int target;
int altref_enabled = is_altref_enabled(cpi);
int sframe_dist = cpi->oxcf.sframe_dist;
@@ -1599,44 +1607,47 @@
int sframe_enabled = cpi->oxcf.sframe_enabled;
// TODO(yaowu): replace the "auto_key && 0" below with proper decision logic.
if (!cpi->refresh_alt_ref_frame &&
- (cm->current_video_frame == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY) ||
- rc->frames_to_key == 0 || (cpi->oxcf.auto_key && 0))) {
- cm->frame_type = KEY_FRAME;
+ (current_frame->frame_number == 0 ||
+ (cpi->frame_flags & FRAMEFLAGS_KEY) || rc->frames_to_key == 0 ||
+ (cpi->oxcf.auto_key && 0))) {
+ current_frame->frame_type = KEY_FRAME;
rc->this_key_frame_forced =
- cm->current_video_frame != 0 && rc->frames_to_key == 0;
+ current_frame->frame_number != 0 && rc->frames_to_key == 0;
rc->frames_to_key = cpi->oxcf.key_freq;
rc->kf_boost = DEFAULT_KF_BOOST;
rc->source_alt_ref_active = 0;
} else {
- cm->frame_type = INTER_FRAME;
+ current_frame->frame_type = INTER_FRAME;
if (sframe_enabled) {
if (altref_enabled) {
if (sframe_mode == 1) {
// sframe_mode == 1: insert sframe if it matches altref frame.
- if (cm->current_video_frame % sframe_dist == 0 &&
- cm->frame_type != KEY_FRAME && cm->current_video_frame != 0 &&
- cpi->refresh_alt_ref_frame) {
- cm->frame_type = S_FRAME;
+ if (current_frame->frame_number % sframe_dist == 0 &&
+ current_frame->frame_type != KEY_FRAME &&
+ current_frame->frame_number != 0 && cpi->refresh_alt_ref_frame) {
+ current_frame->frame_type = S_FRAME;
}
} else {
// sframe_mode != 1: if sframe will be inserted at the next available
// altref frame
- if (cm->current_video_frame % sframe_dist == 0 &&
- cm->frame_type != KEY_FRAME && cm->current_video_frame != 0) {
+ if (current_frame->frame_number % sframe_dist == 0 &&
+ current_frame->frame_type != KEY_FRAME &&
+ current_frame->frame_number != 0) {
rc->sframe_due = 1;
}
if (rc->sframe_due && cpi->refresh_alt_ref_frame) {
- cm->frame_type = S_FRAME;
+ current_frame->frame_type = S_FRAME;
rc->sframe_due = 0;
}
}
} else {
- if (cm->current_video_frame % sframe_dist == 0 &&
- cm->frame_type != KEY_FRAME && cm->current_video_frame != 0) {
- cm->frame_type = S_FRAME;
+ if (current_frame->frame_number % sframe_dist == 0 &&
+ current_frame->frame_type != KEY_FRAME &&
+ current_frame->frame_number != 0) {
+ current_frame->frame_type = S_FRAME;
}
}
}
@@ -1659,7 +1670,7 @@
if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
av1_cyclic_refresh_update_parameters(cpi);
- if (cm->frame_type == KEY_FRAME)
+ if (current_frame->frame_type == KEY_FRAME)
target = calc_iframe_target_size_one_pass_vbr(cpi);
else
target = calc_pframe_target_size_one_pass_vbr(cpi);
@@ -1708,7 +1719,7 @@
static int calc_iframe_target_size_one_pass_cbr(const AV1_COMP *cpi) {
const RATE_CONTROL *rc = &cpi->rc;
int target;
- if (cpi->common.current_video_frame == 0) {
+ if (cpi->common.current_frame.frame_number == 0) {
target = ((rc->starting_buffer_level / 2) > INT_MAX)
? INT_MAX
: (int)(rc->starting_buffer_level / 2);
@@ -1728,18 +1739,20 @@
void av1_rc_get_one_pass_cbr_params(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
+ CurrentFrame *const current_frame = &cm->current_frame;
int target;
// TODO(yaowu): replace the "auto_key && 0" below with proper decision logic.
- if ((cm->current_video_frame == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY) ||
- rc->frames_to_key == 0 || (cpi->oxcf.auto_key && 0))) {
- cm->frame_type = KEY_FRAME;
+ if ((current_frame->frame_number == 0 ||
+ (cpi->frame_flags & FRAMEFLAGS_KEY) || rc->frames_to_key == 0 ||
+ (cpi->oxcf.auto_key && 0))) {
+ current_frame->frame_type = KEY_FRAME;
rc->this_key_frame_forced =
- cm->current_video_frame != 0 && rc->frames_to_key == 0;
+ current_frame->frame_number != 0 && rc->frames_to_key == 0;
rc->frames_to_key = cpi->oxcf.key_freq;
rc->kf_boost = DEFAULT_KF_BOOST;
rc->source_alt_ref_active = 0;
} else {
- cm->frame_type = INTER_FRAME;
+ current_frame->frame_type = INTER_FRAME;
}
if (rc->frames_till_gf_update_due == 0) {
if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
@@ -1760,7 +1773,7 @@
if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
av1_cyclic_refresh_update_parameters(cpi);
- if (cm->frame_type == KEY_FRAME)
+ if (current_frame->frame_type == KEY_FRAME)
target = calc_iframe_target_size_one_pass_cbr(cpi);
else
target = calc_pframe_target_size_one_pass_cbr(cpi);
@@ -1886,7 +1899,7 @@
// This number is used to damp the per frame rate correction.
// Range 0 - 1.0
if (cpi->twopass.total_stats.count != 0.) {
- position_factor = sqrt((double)cpi->common.current_video_frame /
+ position_factor = sqrt((double)cpi->common.current_frame.frame_number /
cpi->twopass.total_stats.count);
}
max_delta = (int)(position_factor *
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index f3019b4..510bb3b 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -91,7 +91,7 @@
for (i = 0; i < PARTITION_CONTEXTS; ++i)
av1_cost_tokens_from_cdf(x->partition_cost[i], fc->partition_cdf[i], NULL);
- if (cm->skip_mode_flag) {
+ if (cm->current_frame.skip_mode_info.skip_mode_flag) {
for (i = 0; i < SKIP_CONTEXTS; ++i) {
av1_cost_tokens_from_cdf(x->skip_mode_cost[i], fc->skip_mode_cdfs[i],
NULL);
@@ -370,7 +370,8 @@
int av1_compute_rd_mult(const AV1_COMP *cpi, int qindex) {
int64_t rdmult = av1_compute_rd_mult_based_on_qindex(cpi, qindex);
- if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) {
+ if (cpi->oxcf.pass == 2 &&
+ (cpi->common.current_frame.frame_type != KEY_FRAME)) {
const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index];
const int boost_index = AOMMIN(15, (cpi->rc.gfu_boost / 100));
@@ -398,7 +399,8 @@
break;
}
- if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) {
+ if (cpi->oxcf.pass == 2 &&
+ (cpi->common.current_frame.frame_type != KEY_FRAME)) {
const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index];
const int boost_index = AOMMIN(15, (cpi->rc.gfu_boost / 100));
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 371aa90..0f25149 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -6896,7 +6896,7 @@
ref_costs_single[BWDREF_FRAME] += x->single_ref_cost[ctx_p6][5][0];
ref_costs_single[ALTREF2_FRAME] += x->single_ref_cost[ctx_p6][5][1];
- if (cm->reference_mode != SINGLE_REFERENCE) {
+ if (cm->current_frame.reference_mode != SINGLE_REFERENCE) {
// Similar to single ref, determine cost of compound ref frames.
// cost_compound_refs = cost_first_ref + cost_second_ref
const int bwdref_comp_ctx_p = av1_get_pred_context_comp_bwdref_p(xd);
@@ -9139,7 +9139,7 @@
rd_stats->rate += est_residue_cost;
rd_stats->dist = est_dist;
rd_stats->rdcost = RDCOST(x->rdmult, rd_stats->rate, rd_stats->dist);
- if (cm->reference_mode == SINGLE_REFERENCE) {
+ if (cm->current_frame.reference_mode == SINGLE_REFERENCE) {
if (!is_comp_pred) {
inter_modes_info_push(inter_modes_info, mode_rate, curr_sse,
rd_stats->rdcost, mbmi);
@@ -10311,6 +10311,7 @@
BLOCK_SIZE bsize, int mi_row, int mi_col,
struct buf_2d yv12_mb[REF_FRAMES][MAX_MB_PLANE]) {
const AV1_COMMON *const cm = &cpi->common;
+ const SkipModeInfo *const skip_mode_info = &cm->current_frame.skip_mode_info;
const int num_planes = av1_num_planes(cm);
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = xd->mi[0];
@@ -10319,13 +10320,15 @@
RD_STATS skip_mode_rd_stats;
av1_invalid_rd_stats(&skip_mode_rd_stats);
- if (cm->ref_frame_idx_0 == INVALID_IDX ||
- cm->ref_frame_idx_1 == INVALID_IDX) {
+ if (skip_mode_info->ref_frame_idx_0 == INVALID_IDX ||
+ skip_mode_info->ref_frame_idx_1 == INVALID_IDX) {
return;
}
- const MV_REFERENCE_FRAME ref_frame = LAST_FRAME + cm->ref_frame_idx_0;
- const MV_REFERENCE_FRAME second_ref_frame = LAST_FRAME + cm->ref_frame_idx_1;
+ const MV_REFERENCE_FRAME ref_frame =
+ LAST_FRAME + skip_mode_info->ref_frame_idx_0;
+ const MV_REFERENCE_FRAME second_ref_frame =
+ LAST_FRAME + skip_mode_info->ref_frame_idx_1;
const PREDICTION_MODE this_mode = NEAREST_NEARESTMV;
const int mode_index =
get_prediction_mode_idx(this_mode, ref_frame, second_ref_frame);
@@ -10978,6 +10981,7 @@
const AV1_COMMON *const cm = &cpi->common;
const struct segmentation *const seg = &cm->seg;
const OrderHintInfo *const order_hint_info = &cm->seq_params.order_hint_info;
+ const CurrentFrame *const current_frame = &cm->current_frame;
const MACROBLOCKD *const xd = &x->e_mbd;
const MB_MODE_INFO *const mbmi = xd->mi[0];
const unsigned char segment_id = mbmi->segment_id;
@@ -11067,7 +11071,7 @@
if (comp_pred) {
if (!cpi->allow_comp_inter_inter) return 1;
- if (cm->reference_mode == SINGLE_REFERENCE) return 1;
+ if (current_frame->reference_mode == SINGLE_REFERENCE) return 1;
// Skip compound inter modes if ARF is not available.
if (!(cpi->ref_frame_flags & ref_frame_flag_list[ref_frame[1]])) return 1;
@@ -11083,13 +11087,13 @@
if (get_relative_dist(
order_hint_info,
cm->cur_frame->ref_frame_offset[ALTREF2_FRAME - LAST_FRAME],
- cm->frame_offset) < 0)
+ current_frame->order_hint) < 0)
return 1;
if (ref_frame[0] == BWDREF_FRAME || ref_frame[1] == BWDREF_FRAME)
if (get_relative_dist(
order_hint_info,
cm->cur_frame->ref_frame_offset[BWDREF_FRAME - LAST_FRAME],
- cm->frame_offset) < 0)
+ current_frame->order_hint) < 0)
return 1;
}
@@ -11120,14 +11124,14 @@
assert(buf_idx >= 0);
ref_offsets[i] = cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset;
}
- if ((get_relative_dist(order_hint_info, ref_offsets[0], cm->frame_offset) <=
- 0 &&
- get_relative_dist(order_hint_info, ref_offsets[1], cm->frame_offset) <=
- 0) ||
- (get_relative_dist(order_hint_info, ref_offsets[0], cm->frame_offset) >
- 0 &&
- get_relative_dist(order_hint_info, ref_offsets[1], cm->frame_offset) >
- 0))
+ if ((get_relative_dist(order_hint_info, ref_offsets[0],
+ current_frame->order_hint) <= 0 &&
+ get_relative_dist(order_hint_info, ref_offsets[1],
+ current_frame->order_hint) <= 0) ||
+ (get_relative_dist(order_hint_info, ref_offsets[0],
+ current_frame->order_hint) > 0 &&
+ get_relative_dist(order_hint_info, ref_offsets[1],
+ current_frame->order_hint) > 0))
return 1;
}
@@ -11903,7 +11907,9 @@
const int compmode_cost =
is_comp_ref_allowed(mbmi->sb_type) ? comp_inter_cost[comp_pred] : 0;
const int real_compmode_cost =
- cm->reference_mode == REFERENCE_MODE_SELECT ? compmode_cost : 0;
+ cm->current_frame.reference_mode == REFERENCE_MODE_SELECT
+ ? compmode_cost
+ : 0;
if (comp_pred) {
if ((sf->mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
@@ -12005,7 +12011,7 @@
if (this_rd < search_state.best_rd || x->skip) {
int mode_excluded = 0;
if (comp_pred) {
- mode_excluded = cm->reference_mode == SINGLE_REFERENCE;
+ mode_excluded = cm->current_frame.reference_mode == SINGLE_REFERENCE;
}
if (!mode_excluded) {
// Note index of best mode so far
@@ -12063,7 +12069,7 @@
if (!disable_skip && ref_frame != INTRA_FRAME) {
int64_t single_rd, hybrid_rd, single_rate, hybrid_rate;
- if (cm->reference_mode == REFERENCE_MODE_SELECT) {
+ if (cm->current_frame.reference_mode == REFERENCE_MODE_SELECT) {
single_rate = rate2 - compmode_cost;
hybrid_rate = rate2;
} else {
@@ -12221,7 +12227,7 @@
}
search_state.best_mbmode.skip_mode = 0;
- if (cm->skip_mode_flag &&
+ if (cm->current_frame.skip_mode_info.skip_mode_flag &&
!segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
is_comp_ref_allowed(bsize)) {
rd_pick_skip_mode(rd_cost, &search_state, cpi, x, bsize, mi_row, mi_col,
@@ -12388,7 +12394,7 @@
mbmi->interp_filters = av1_broadcast_interp_filter(best_filter);
rate2 += av1_get_switchable_rate(cm, x, xd);
- if (cm->reference_mode == REFERENCE_MODE_SELECT)
+ if (cm->current_frame.reference_mode == REFERENCE_MODE_SELECT)
rate2 += comp_inter_cost[comp_pred];
// Estimate the reference frame signaling cost and add it
diff --git a/av1/encoder/segmentation.c b/av1/encoder/segmentation.c
index 2e91027..6d0c654 100644
--- a/av1/encoder/segmentation.c
+++ b/av1/encoder/segmentation.c
@@ -62,7 +62,7 @@
no_pred_segcounts[segment_id]++;
// Temporal prediction not allowed on key frames
- if (cm->frame_type != KEY_FRAME) {
+ if (cm->current_frame.frame_type != KEY_FRAME) {
const BLOCK_SIZE bsize = xd->mi[0]->sb_type;
// Test to see if the segment id matches the predicted value.
const int pred_segment_id =
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 7990710..3f55d1f 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -310,7 +310,7 @@
sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
sf->adaptive_rd_thresh = 4;
sf->mode_search_skip_flags =
- (cm->frame_type == KEY_FRAME)
+ (cm->current_frame.frame_type == KEY_FRAME)
? 0
: FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR |
diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index da707a1..141b096 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -597,7 +597,7 @@
frames = frames_bwd + 1 + frames_fwd;
// Adjust the strength based on active max q.
- if (cpi->common.current_video_frame > 1)
+ if (cpi->common.current_frame.frame_number > 1)
q = ((int)av1_convert_qindex_to_q(cpi->rc.avg_frame_qindex[INTER_FRAME],
cpi->common.seq_params.bit_depth));
else