Commit 5e70a114 authored by David Barker's avatar David Barker

Deduplicate use_reference_buffer/frame_id_numbers_present_flag

These two flags serve essentially the same purpose, so we can
simplify down to just having one flag. Since the
frame_id_numbers_present_flag is older and listed in the
reference-buffer design doc, this is the one we'll keep.

Note that, previously, frame_id_numbers_present_flag was only
sent when CONFIG_OBU was enabled - otherwise it was always set
to 1. On the other hand, use_reference_buffer was always signalled
so that allowed us to disable frame ids even without CONFIG_OBU.

In order to keep the ability to disable frame IDs without
CONFIG_OBU, we send a "real" sequence header (ie, with the same
data as in CONFIG_OBU) in-line within the uncompressed header.
This is sent every keyframe and every intra-only frame, just
as the use_reference_buffer flag was before this patch.

BUG=aomedia:853

Change-Id: I4bb6c7a222aeddfb6d3737a39d10782d32ee2eee
parent c5a1f263
......@@ -1286,7 +1286,7 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
&dst_time_stamp, &dst_end_time_stamp,
!img)) {
#if CONFIG_REFERENCE_BUFFER
if (cpi->common.use_reference_buffer) {
if (cpi->common.seq_params.frame_id_numbers_present_flag) {
if (cpi->common.invalid_delta_frame_id_minus1) {
ctx->base.err_detail = "Invalid delta_frame_id_minus1";
return AOM_CODEC_ERROR;
......
......@@ -277,26 +277,20 @@ static aom_codec_err_t decoder_peek_si_internal(
}
error_resilient = aom_rb_read_bit(&rb);
#if CONFIG_REFERENCE_BUFFER
int use_reference_buffer = 1;
SequenceHeader seq_params = { 0, 0, 0 };
if (si->is_kf) {
/* TODO: Move outside frame loop or inside key-frame branch */
use_reference_buffer = aom_rb_read_bit(&rb);
if (use_reference_buffer) {
read_sequence_header(&seq_params);
read_sequence_header(&seq_params, &rb);
#if CONFIG_EXT_TILE
if (large_scale_tile) seq_params.frame_id_numbers_present_flag = 0;
if (large_scale_tile) seq_params.frame_id_numbers_present_flag = 0;
#endif // CONFIG_EXT_TILE
}
}
#endif // CONFIG_REFERENCE_BUFFER
#if CONFIG_REFERENCE_BUFFER
if (use_reference_buffer) {
if (seq_params.frame_id_numbers_present_flag) {
int frame_id_len;
if (seq_params.frame_id_numbers_present_flag) {
frame_id_len = seq_params.frame_id_length_minus7 + 7;
aom_rb_read_literal(&rb, frame_id_len);
}
frame_id_len = seq_params.frame_id_length_minus7 + 7;
aom_rb_read_literal(&rb, frame_id_len);
}
#endif // CONFIG_REFERENCE_BUFFER
if (si->is_kf) {
......
......@@ -204,6 +204,15 @@ typedef int BASE_CTX_TABLE[2 /*col*/][2 /*sig_map*/]
[BASE_CONTEXT_POSITION_NUM + 1];
#endif
#if CONFIG_REFERENCE_BUFFER
/* Initial version of sequence header structure */
typedef struct SequenceHeader {
int frame_id_numbers_present_flag;
int frame_id_length_minus7;
int delta_frame_id_length_minus2;
} SequenceHeader;
#endif // CONFIG_REFERENCE_BUFFER
typedef struct AV1Common {
struct aom_internal_error_info error;
aom_color_space_t color_space;
......@@ -507,7 +516,7 @@ typedef struct AV1Common {
#endif
int num_tg;
#if CONFIG_REFERENCE_BUFFER
int use_reference_buffer;
SequenceHeader seq_params;
int current_frame_id;
int ref_frame_id[REF_FRAMES];
int valid_for_referencing[REF_FRAMES];
......@@ -528,15 +537,6 @@ typedef struct AV1Common {
#endif
} AV1_COMMON;
#if CONFIG_REFERENCE_BUFFER
/* Initial version of sequence header structure */
typedef struct SequenceHeader {
int frame_id_numbers_present_flag;
int frame_id_length_minus7;
int delta_frame_id_length_minus2;
} SequenceHeader;
#endif // CONFIG_REFERENCE_BUFFER
// TODO(hkuang): Don't need to lock the whole pool after implementing atomic
// frame reference count.
static void lock_buffer_pool(BufferPool *const pool) {
......@@ -1329,7 +1329,7 @@ static INLINE PARTITION_TYPE get_partition(const AV1_COMMON *const cm,
static INLINE void set_use_reference_buffer(AV1_COMMON *const cm, int use) {
#if CONFIG_REFERENCE_BUFFER
cm->use_reference_buffer = use;
cm->seq_params.frame_id_numbers_present_flag = use;
#else
(void)cm;
(void)use;
......
......@@ -4411,11 +4411,14 @@ static void read_bitdepth_colorspace_sampling(AV1_COMMON *cm,
}
#if CONFIG_REFERENCE_BUFFER
void read_sequence_header(SequenceHeader *seq_params) {
void read_sequence_header(SequenceHeader *seq_params,
struct aom_read_bit_buffer *rb) {
/* Placeholder for actually reading from the bitstream */
seq_params->frame_id_numbers_present_flag = FRAME_ID_NUMBERS_PRESENT_FLAG;
seq_params->frame_id_length_minus7 = FRAME_ID_LENGTH_MINUS7;
seq_params->delta_frame_id_length_minus2 = DELTA_FRAME_ID_LENGTH_MINUS2;
seq_params->frame_id_numbers_present_flag = aom_rb_read_bit(rb);
if (seq_params->frame_id_numbers_present_flag) {
seq_params->frame_id_length_minus7 = aom_rb_read_literal(rb, 4);
seq_params->delta_frame_id_length_minus2 = aom_rb_read_literal(rb, 4);
}
}
#endif // CONFIG_REFERENCE_BUFFER
......@@ -4646,7 +4649,7 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
#if CONFIG_EXT_TILE
cm->large_scale_tile = aom_rb_read_literal(rb, 1);
#if CONFIG_REFERENCE_BUFFER
if (cm->large_scale_tile) pbi->seq_params.frame_id_numbers_present_flag = 0;
if (cm->large_scale_tile) cm->seq_params.frame_id_numbers_present_flag = 0;
#endif // CONFIG_REFERENCE_BUFFER
#endif // CONFIG_EXT_TILE
......@@ -4657,17 +4660,15 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
const int existing_frame_idx = aom_rb_read_literal(rb, 3);
const int frame_to_show = cm->ref_frame_map[existing_frame_idx];
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (pbi->seq_params.frame_id_numbers_present_flag) {
int frame_id_length = pbi->seq_params.frame_id_length_minus7 + 7;
int display_frame_id = aom_rb_read_literal(rb, frame_id_length);
/* Compare display_frame_id with ref_frame_id and check valid for
* referencing */
if (display_frame_id != cm->ref_frame_id[existing_frame_idx] ||
cm->valid_for_referencing[existing_frame_idx] == 0)
aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
"Reference buffer frame ID mismatch");
}
if (cm->seq_params.frame_id_numbers_present_flag) {
int frame_id_length = cm->seq_params.frame_id_length_minus7 + 7;
int display_frame_id = aom_rb_read_literal(rb, frame_id_length);
/* Compare display_frame_id with ref_frame_id and check valid for
* referencing */
if (display_frame_id != cm->ref_frame_id[existing_frame_idx] ||
cm->valid_for_referencing[existing_frame_idx] == 0)
aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
"Reference buffer frame ID mismatch");
}
#endif
lock_buffer_pool(pool);
......@@ -4709,51 +4710,46 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
#endif
cm->error_resilient_mode = aom_rb_read_bit(rb);
#if CONFIG_REFERENCE_BUFFER
if (frame_is_intra_only(cm)) {
cm->use_reference_buffer = aom_rb_read_bit(rb);
#if !CONFIG_OBU
read_sequence_header(&pbi->seq_params);
if (frame_is_intra_only(cm)) read_sequence_header(&cm->seq_params, rb);
#endif // !CONFIG_OBU
}
if (cm->use_reference_buffer) {
if (pbi->seq_params.frame_id_numbers_present_flag) {
int frame_id_length = pbi->seq_params.frame_id_length_minus7 + 7;
int diff_len = pbi->seq_params.delta_frame_id_length_minus2 + 2;
int prev_frame_id = 0;
if (cm->frame_type != KEY_FRAME) {
prev_frame_id = cm->current_frame_id;
}
cm->current_frame_id = aom_rb_read_literal(rb, frame_id_length);
if (cm->seq_params.frame_id_numbers_present_flag) {
int frame_id_length = cm->seq_params.frame_id_length_minus7 + 7;
int diff_len = cm->seq_params.delta_frame_id_length_minus2 + 2;
int prev_frame_id = 0;
if (cm->frame_type != KEY_FRAME) {
prev_frame_id = cm->current_frame_id;
}
cm->current_frame_id = aom_rb_read_literal(rb, frame_id_length);
if (cm->frame_type != KEY_FRAME) {
int diff_frame_id;
if (cm->current_frame_id > prev_frame_id) {
diff_frame_id = cm->current_frame_id - prev_frame_id;
} else {
diff_frame_id =
(1 << frame_id_length) + cm->current_frame_id - prev_frame_id;
}
/* Check current_frame_id for conformance */
if (prev_frame_id == cm->current_frame_id ||
diff_frame_id >= (1 << (frame_id_length - 1))) {
aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
"Invalid value of current_frame_id");
}
if (cm->frame_type != KEY_FRAME) {
int diff_frame_id;
if (cm->current_frame_id > prev_frame_id) {
diff_frame_id = cm->current_frame_id - prev_frame_id;
} else {
diff_frame_id =
(1 << frame_id_length) + cm->current_frame_id - prev_frame_id;
}
/* Check if some frames need to be marked as not valid for referencing */
for (i = 0; i < REF_FRAMES; i++) {
if (cm->frame_type == KEY_FRAME) {
/* Check current_frame_id for conformance */
if (prev_frame_id == cm->current_frame_id ||
diff_frame_id >= (1 << (frame_id_length - 1))) {
aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
"Invalid value of current_frame_id");
}
}
/* Check if some frames need to be marked as not valid for referencing */
for (i = 0; i < REF_FRAMES; i++) {
if (cm->frame_type == KEY_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 ||
cm->ref_frame_id[i] < cm->current_frame_id - (1 << diff_len))
cm->valid_for_referencing[i] = 0;
} else {
if (cm->ref_frame_id[i] > cm->current_frame_id &&
cm->ref_frame_id[i] <
(1 << frame_id_length) + cm->current_frame_id - (1 << diff_len))
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 ||
cm->ref_frame_id[i] < cm->current_frame_id - (1 << diff_len))
cm->valid_for_referencing[i] = 0;
} else {
if (cm->ref_frame_id[i] > cm->current_frame_id &&
cm->ref_frame_id[i] < (1 << frame_id_length) +
cm->current_frame_id - (1 << diff_len))
cm->valid_for_referencing[i] = 0;
}
}
}
}
......@@ -4870,22 +4866,20 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
cm->ref_frame_sign_bias[LAST_FRAME + i] = aom_rb_read_bit(rb);
#endif
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (pbi->seq_params.frame_id_numbers_present_flag) {
int frame_id_length = pbi->seq_params.frame_id_length_minus7 + 7;
int diff_len = pbi->seq_params.delta_frame_id_length_minus2 + 2;
int delta_frame_id_minus1 = aom_rb_read_literal(rb, diff_len);
int ref_frame_id =
((cm->current_frame_id - (delta_frame_id_minus1 + 1) +
(1 << frame_id_length)) %
(1 << frame_id_length));
/* Compare values derived from delta_frame_id_minus1 and
* refresh_frame_flags. Also, check valid for referencing */
if (ref_frame_id != cm->ref_frame_id[ref] ||
cm->valid_for_referencing[ref] == 0)
aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
"Reference buffer frame ID mismatch");
}
if (cm->seq_params.frame_id_numbers_present_flag) {
int frame_id_length = cm->seq_params.frame_id_length_minus7 + 7;
int diff_len = cm->seq_params.delta_frame_id_length_minus2 + 2;
int delta_frame_id_minus1 = aom_rb_read_literal(rb, diff_len);
int ref_frame_id =
((cm->current_frame_id - (delta_frame_id_minus1 + 1) +
(1 << frame_id_length)) %
(1 << frame_id_length));
/* Compare values derived from delta_frame_id_minus1 and
* refresh_frame_flags. Also, check valid for referencing */
if (ref_frame_id != cm->ref_frame_id[ref] ||
cm->valid_for_referencing[ref] == 0)
aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
"Reference buffer frame ID mismatch");
}
#endif // CONFIG_REFERENCE_BUFFER
}
......@@ -4948,17 +4942,15 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
#endif
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (pbi->seq_params.frame_id_numbers_present_flag) {
/* If bitmask is set, update reference frame id values and
mark frames as valid for reference */
int refresh_frame_flags =
cm->frame_type == KEY_FRAME ? 0xFF : pbi->refresh_frame_flags;
for (i = 0; i < REF_FRAMES; i++) {
if ((refresh_frame_flags >> i) & 1) {
cm->ref_frame_id[i] = cm->current_frame_id;
cm->valid_for_referencing[i] = 1;
}
if (cm->seq_params.frame_id_numbers_present_flag) {
/* If bitmask is set, update reference frame id values and
mark frames as valid for reference */
int refresh_frame_flags =
cm->frame_type == KEY_FRAME ? 0xFF : pbi->refresh_frame_flags;
for (i = 0; i < REF_FRAMES; i++) {
if ((refresh_frame_flags >> i) & 1) {
cm->ref_frame_id[i] = cm->current_frame_id;
cm->valid_for_referencing[i] = 1;
}
}
}
......@@ -5795,7 +5787,7 @@ static uint32_t read_temporal_delimiter_obu() { return 0; }
static uint32_t read_sequence_header_obu(AV1Decoder *pbi,
struct aom_read_bit_buffer *rb) {
AV1_COMMON *const cm = &pbi->common;
SequenceHeader *const seq_params = &pbi->seq_params;
SequenceHeader *const seq_params = &cm->seq_params;
uint32_t saved_bit_offset = rb->bit_offset;
cm->profile = av1_read_profile(rb);
......
......@@ -21,7 +21,8 @@ struct aom_read_bit_buffer;
#if CONFIG_REFERENCE_BUFFER
/* Placeholder for now */
void read_sequence_header(SequenceHeader *seq_params);
void read_sequence_header(SequenceHeader *seq_params,
struct aom_read_bit_buffer *rb);
#endif
void av1_read_frame_size(struct aom_read_bit_buffer *rb, int *width,
......
......@@ -140,9 +140,6 @@ typedef struct AV1Decoder {
int tg_size; // Number of tiles in the current tilegroup
int tg_start; // First tile in the current tilegroup
int tg_size_bit_offset;
#if CONFIG_REFERENCE_BUFFER
SequenceHeader seq_params;
#endif // CONFIG_REFERENCE_BUFFER
#if CONFIG_INSPECTION
aom_inspect_cb inspect_cb;
void *inspect_ctx;
......
......@@ -4337,11 +4337,9 @@ static void write_bitdepth_colorspace_sampling(
}
#if CONFIG_REFERENCE_BUFFER
void write_sequence_header(
#if CONFIG_EXT_TILE
AV1_COMMON *const cm,
#endif // CONFIG_EXT_TILE
SequenceHeader *seq_params) {
void write_sequence_header(AV1_COMMON *const cm,
struct aom_write_bit_buffer *wb) {
SequenceHeader *seq_params = &cm->seq_params;
/* Placeholder for actually writing to the bitstream */
seq_params->frame_id_numbers_present_flag =
#if CONFIG_EXT_TILE
......@@ -4350,6 +4348,12 @@ void write_sequence_header(
FRAME_ID_NUMBERS_PRESENT_FLAG;
seq_params->frame_id_length_minus7 = FRAME_ID_LENGTH_MINUS7;
seq_params->delta_frame_id_length_minus2 = DELTA_FRAME_ID_LENGTH_MINUS2;
aom_wb_write_bit(wb, seq_params->frame_id_numbers_present_flag);
if (seq_params->frame_id_numbers_present_flag) {
aom_wb_write_literal(wb, seq_params->frame_id_length_minus7, 4);
aom_wb_write_literal(wb, seq_params->delta_frame_id_length_minus2, 4);
}
}
#endif // CONFIG_REFERENCE_BUFFER
......@@ -4540,16 +4544,14 @@ static void write_uncompressed_header_frame(AV1_COMP *cpi,
aom_wb_write_literal(wb, cpi->existing_fb_idx_to_show, 3);
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cpi->seq_params.frame_id_numbers_present_flag) {
int frame_id_len = cpi->seq_params.frame_id_length_minus7 + 7;
int display_frame_id = cm->ref_frame_id[cpi->existing_fb_idx_to_show];
aom_wb_write_literal(wb, display_frame_id, frame_id_len);
/* Add a zero byte to prevent emulation of superframe marker */
/* Same logic as when when terminating the entropy coder */
/* Consider to have this logic only one place */
aom_wb_write_literal(wb, 0, 8);
}
if (cm->seq_params.frame_id_numbers_present_flag) {
int frame_id_len = cm->seq_params.frame_id_length_minus7 + 7;
int display_frame_id = cm->ref_frame_id[cpi->existing_fb_idx_to_show];
aom_wb_write_literal(wb, display_frame_id, frame_id_len);
/* Add a zero byte to prevent emulation of superframe marker */
/* Same logic as when when terminating the entropy coder */
/* Consider to have this logic only one place */
aom_wb_write_literal(wb, 0, 8);
}
#endif // CONFIG_REFERENCE_BUFFER
......@@ -4569,23 +4571,14 @@ static void write_uncompressed_header_frame(AV1_COMP *cpi,
if (frame_is_intra_only(cm)) {
#if CONFIG_REFERENCE_BUFFER
aom_wb_write_bit(wb, cm->use_reference_buffer);
if (cm->use_reference_buffer) {
write_sequence_header(
#if CONFIG_EXT_TILE
cm,
#endif // CONFIG_EXT_TILE
&cpi->seq_params);
}
write_sequence_header(cm, wb);
#endif // CONFIG_REFERENCE_BUFFER
}
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
cm->invalid_delta_frame_id_minus1 = 0;
if (cpi->seq_params.frame_id_numbers_present_flag) {
int frame_id_len = cpi->seq_params.frame_id_length_minus7 + 7;
aom_wb_write_literal(wb, cm->current_frame_id, frame_id_len);
}
cm->invalid_delta_frame_id_minus1 = 0;
if (cm->seq_params.frame_id_numbers_present_flag) {
int frame_id_len = cm->seq_params.frame_id_length_minus7 + 7;
aom_wb_write_literal(wb, cm->current_frame_id, frame_id_len);
}
#endif // CONFIG_REFERENCE_BUFFER
if (cm->frame_type == KEY_FRAME) {
......@@ -4667,21 +4660,19 @@ static void write_uncompressed_header_frame(AV1_COMP *cpi,
REF_FRAMES_LOG2);
aom_wb_write_bit(wb, cm->ref_frame_sign_bias[ref_frame]);
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cpi->seq_params.frame_id_numbers_present_flag) {
int i = get_ref_frame_map_idx(cpi, ref_frame);
int frame_id_len = cpi->seq_params.frame_id_length_minus7 + 7;
int diff_len = cpi->seq_params.delta_frame_id_length_minus2 + 2;
int delta_frame_id_minus1 =
((cm->current_frame_id - cm->ref_frame_id[i] +
(1 << frame_id_len)) %
(1 << frame_id_len)) -
1;
if (delta_frame_id_minus1 < 0 ||
delta_frame_id_minus1 >= (1 << diff_len))
cm->invalid_delta_frame_id_minus1 = 1;
aom_wb_write_literal(wb, delta_frame_id_minus1, diff_len);
}
if (cm->seq_params.frame_id_numbers_present_flag) {
int i = get_ref_frame_map_idx(cpi, ref_frame);
int frame_id_len = cm->seq_params.frame_id_length_minus7 + 7;
int diff_len = cm->seq_params.delta_frame_id_length_minus2 + 2;
int delta_frame_id_minus1 =
((cm->current_frame_id - cm->ref_frame_id[i] +
(1 << frame_id_len)) %
(1 << frame_id_len)) -
1;
if (delta_frame_id_minus1 < 0 ||
delta_frame_id_minus1 >= (1 << diff_len))
cm->invalid_delta_frame_id_minus1 = 1;
aom_wb_write_literal(wb, delta_frame_id_minus1, diff_len);
}
#endif // CONFIG_REFERENCE_BUFFER
}
......@@ -4729,7 +4720,7 @@ static void write_uncompressed_header_frame(AV1_COMP *cpi,
#endif
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cm->seq_params.frame_id_numbers_present_flag) {
cm->refresh_mask =
cm->frame_type == KEY_FRAME ? 0xFF : get_refresh_mask(cpi);
}
......@@ -4841,16 +4832,14 @@ static void write_uncompressed_header_obu(AV1_COMP *cpi,
aom_wb_write_literal(wb, cpi->existing_fb_idx_to_show, 3);
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cpi->seq_params.frame_id_numbers_present_flag) {
int frame_id_len = cpi->seq_params.frame_id_length_minus7 + 7;
int display_frame_id = cm->ref_frame_id[cpi->existing_fb_idx_to_show];
aom_wb_write_literal(wb, display_frame_id, frame_id_len);
/* Add a zero byte to prevent emulation of superframe marker */
/* Same logic as when when terminating the entropy coder */
/* Consider to have this logic only one place */
aom_wb_write_literal(wb, 0, 8);
}
if (cm->seq_params.frame_id_numbers_present_flag) {
int frame_id_len = cm->seq_params.frame_id_length_minus7 + 7;
int display_frame_id = cm->ref_frame_id[cpi->existing_fb_idx_to_show];
aom_wb_write_literal(wb, display_frame_id, frame_id_len);
/* Add a zero byte to prevent emulation of superframe marker */
/* Same logic as when when terminating the entropy coder */
/* Consider to have this logic only one place */
aom_wb_write_literal(wb, 0, 8);
}
#endif // CONFIG_REFERENCE_BUFFER
......@@ -4871,18 +4860,10 @@ static void write_uncompressed_header_obu(AV1_COMP *cpi,
aom_wb_write_bit(wb, cm->error_resilient_mode);
#if CONFIG_REFERENCE_BUFFER
if (cm->frame_type == KEY_FRAME) {
aom_wb_write_bit(wb, cm->use_reference_buffer);
}
#endif // CONFIG_REFERENCE_BUFFER
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
cm->invalid_delta_frame_id_minus1 = 0;
if (cpi->seq_params.frame_id_numbers_present_flag) {
int frame_id_len = cpi->seq_params.frame_id_length_minus7 + 7;
aom_wb_write_literal(wb, cm->current_frame_id, frame_id_len);
}
cm->invalid_delta_frame_id_minus1 = 0;
if (cm->seq_params.frame_id_numbers_present_flag) {
int frame_id_len = cm->seq_params.frame_id_length_minus7 + 7;
aom_wb_write_literal(wb, cm->current_frame_id, frame_id_len);
}
#endif // CONFIG_REFERENCE_BUFFER
if (cm->frame_type == KEY_FRAME) {
......@@ -4965,21 +4946,19 @@ static void write_uncompressed_header_obu(AV1_COMP *cpi,
REF_FRAMES_LOG2);
aom_wb_write_bit(wb, cm->ref_frame_sign_bias[ref_frame]);
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cpi->seq_params.frame_id_numbers_present_flag) {
int i = get_ref_frame_map_idx(cpi, ref_frame);
int frame_id_len = cpi->seq_params.frame_id_length_minus7 + 7;
int diff_len = cpi->seq_params.delta_frame_id_length_minus2 + 2;
int delta_frame_id_minus1 =
((cm->current_frame_id - cm->ref_frame_id[i] +
(1 << frame_id_len)) %
(1 << frame_id_len)) -
1;
if (delta_frame_id_minus1 < 0 ||
delta_frame_id_minus1 >= (1 << diff_len))
cm->invalid_delta_frame_id_minus1 = 1;
aom_wb_write_literal(wb, delta_frame_id_minus1, diff_len);
}
if (cm->seq_params.frame_id_numbers_present_flag) {
int i = get_ref_frame_map_idx(cpi, ref_frame);
int frame_id_len = cm->seq_params.frame_id_length_minus7 + 7;
int diff_len = cm->seq_params.delta_frame_id_length_minus2 + 2;
int delta_frame_id_minus1 =
((cm->current_frame_id - cm->ref_frame_id[i] +
(1 << frame_id_len)) %
(1 << frame_id_len)) -
1;
if (delta_frame_id_minus1 < 0 ||
delta_frame_id_minus1 >= (1 << diff_len))
cm->invalid_delta_frame_id_minus1 = 1;
aom_wb_write_literal(wb, delta_frame_id_minus1, diff_len);
}
#endif // CONFIG_REFERENCE_BUFFER
}
......@@ -5034,10 +5013,10 @@ static void write_uncompressed_header_obu(AV1_COMP *cpi,
REF_FRAMES_LOG2);
assert(cm->ref_frame_sign_bias[ref_frame] == 0);
#if CONFIG_REFERENCE_BUFFER
if (cpi->seq_params.frame_id_numbers_present_flag) {
if (cm->seq_params.frame_id_numbers_present_flag) {
int i = get_ref_frame_map_idx(cpi, ref_frame);
int frame_id_len = cpi->seq_params.frame_id_length_minus7 + 7;
int diff_len = cpi->seq_params.delta_frame_id_length_minus2 + 2;
int frame_id_len = cm->seq_params.frame_id_length_minus7 + 7;
int diff_len = cm->seq_params.delta_frame_id_length_minus2 + 2;
int delta_frame_id_minus1 =
((cm->current_frame_id - cm->ref_frame_id[i] +
(1 << frame_id_len)) %
......@@ -5088,7 +5067,7 @@ static void write_uncompressed_header_obu(AV1_COMP *cpi,
#endif
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cm->seq_params.frame_id_numbers_present_flag) {
cm->refresh_mask =
cm->frame_type == KEY_FRAME ? 0xFF : get_refresh_mask(cpi);
}
......@@ -5480,7 +5459,7 @@ static uint32_t write_temporal_delimiter_obu() { return 0; }
static uint32_t write_sequence_header_obu(AV1_COMP *cpi, uint8_t *const dst) {
AV1_COMMON *const cm = &cpi->common;
SequenceHeader *const seq_params = &cpi->seq_params;
SequenceHeader *const seq_params = &cm->seq_params;
struct aom_write_bit_buffer wb = { dst, 0 };
uint32_t size = 0;
......
......@@ -18,12 +18,11 @@ extern "C" {
#include "av1/encoder/encoder.h"
struct aom_write_bit_buffer;
#if CONFIG_REFERENCE_BUFFER
void write_sequence_header(
#if CONFIG_EXT_TILE
AV1_COMMON *const cm,
#endif // CONFIG_EXT_TILE
SequenceHeader *seq_params);
void write_sequence_header(AV1_COMMON *const cm,
struct aom_write_bit_buffer *wb);
#endif
void av1_pack_bitstream(AV1_COMP *const cpi, uint8_t *dest, size_t *size);
......
......@@ -5522,7 +5522,7 @@ static void encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size,
#endif
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cm->seq_params.frame_id_numbers_present_flag) {
/* Non-normative definition of current_frame_id ("frame counter" with
* wraparound) */
const int frame_id_length = FRAME_ID_LENGTH_MINUS7 + 7;
......@@ -5622,7 +5622,7 @@ static void encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size,
}
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cm->seq_params.frame_id_numbers_present_flag) {
int i;
/* Update reference frame id values based on the value of refresh_mask */
for (i = 0; i < REF_FRAMES; i++) {
......@@ -6588,7 +6588,7 @@ int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
#endif
#if CONFIG_REFERENCE_BUFFER
if (cm->use_reference_buffer) {
if (cm->seq_params.frame_id_numbers_present_flag) {