[NORMATIVE] Decoder buffer model implementation
BUG=aomedia:1716
Change-Id: I07c2c0f6dedae861ebf64a7148cec181ea2cfd19
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 6e6a269..0ba4410 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -2255,21 +2255,82 @@
void av1_read_timing_info_header(AV1_COMMON *cm,
struct aom_read_bit_buffer *rb) {
+#if !CONFIG_BUFFER_MODEL
cm->timing_info_present = aom_rb_read_bit(rb); // timing info present flag
if (cm->timing_info_present) {
- cm->num_units_in_tick =
- aom_rb_read_unsigned_literal(rb, 32); // Number of units in tick
- cm->time_scale = aom_rb_read_unsigned_literal(rb, 32); // Time scale
- cm->equal_picture_interval =
+#endif
+#if CONFIG_BUFFER_MODEL
+ cm->timing_info.num_units_in_display_tick = aom_rb_read_unsigned_literal(
+ rb, 32); // Number of units in a display tick
+ cm->timing_info.time_scale =
+ aom_rb_read_unsigned_literal(rb, 32); // Time scale
+ cm->timing_info.equal_picture_interval =
aom_rb_read_bit(rb); // Equal picture interval bit
- if (cm->equal_picture_interval) {
- cm->num_ticks_per_picture =
+ if (cm->timing_info.equal_picture_interval) {
+ cm->timing_info.num_ticks_per_picture =
aom_rb_read_uvlc(rb) + 1; // ticks per picture
+#else
+ cm->num_units_in_tick =
+ aom_rb_read_unsigned_literal(rb, 32); // Number of units in tick
+ cm->time_scale = aom_rb_read_unsigned_literal(rb, 32); // Time scale
+ cm->equal_picture_interval =
+ aom_rb_read_bit(rb); // Equal picture interval bit
+ if (cm->equal_picture_interval) {
+ cm->num_ticks_per_picture = aom_rb_read_uvlc(rb) + 1; // ticks per picture
+#endif
}
+#if !CONFIG_BUFFER_MODEL
}
+#endif
}
+#if CONFIG_BUFFER_MODEL
+void av1_read_decoder_model_info(AV1_COMMON *cm,
+ struct aom_read_bit_buffer *rb) {
+ cm->buffer_model.bitrate_scale = aom_rb_read_literal(rb, 4);
+ cm->buffer_model.buffer_size_scale = aom_rb_read_literal(rb, 4);
+ cm->buffer_model.encoder_decoder_buffer_delay_length =
+ aom_rb_read_literal(rb, 5) + 1;
+ cm->buffer_model.num_units_in_decoding_tick = aom_rb_read_unsigned_literal(
+ rb, 32); // Number of units in a decoding tick
+ cm->buffer_model.buffer_removal_delay_length = aom_rb_read_literal(rb, 5) + 1;
+ cm->buffer_model.frame_presentation_delay_length =
+ aom_rb_read_literal(rb, 5) + 1;
+}
+
+void av1_read_op_parameters_info(AV1_COMMON *const cm,
+ struct aom_read_bit_buffer *rb, int op_num) {
+ if (op_num > MAX_NUM_OPERATING_POINTS)
+ aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
+ "AV1 does not support %d decoder model operating points",
+ op_num + 1);
+
+ // cm->op_params[op_num].has_parameters = aom_rb_read_bit(rb);
+ // if (!cm->op_params[op_num].has_parameters) return;
+
+ cm->op_params[op_num].bitrate = aom_rb_read_uvlc(rb) + 1;
+
+ cm->op_params[op_num].buffer_size = aom_rb_read_uvlc(rb) + 1;
+
+ cm->op_params[op_num].cbr_flag = aom_rb_read_bit(rb);
+
+ cm->op_params[op_num].decoder_buffer_delay = aom_rb_read_literal(
+ rb, cm->buffer_model.encoder_decoder_buffer_delay_length);
+
+ cm->op_params[op_num].encoder_buffer_delay = aom_rb_read_literal(
+ rb, cm->buffer_model.encoder_decoder_buffer_delay_length);
+
+ cm->op_params[op_num].low_delay_mode_flag = aom_rb_read_bit(rb);
+}
+
+static void av1_read_tu_pts_info(AV1_COMMON *const cm,
+ struct aom_read_bit_buffer *rb) {
+ cm->tu_presentation_delay =
+ aom_rb_read_literal(rb, cm->buffer_model.frame_presentation_delay_length);
+}
+#endif
+
void read_sequence_header(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
SequenceHeader *seq_params = &cm->seq_params;
int num_bits_width = aom_rb_read_literal(rb, 4) + 1;
@@ -2566,6 +2627,12 @@
// Show an existing frame directly.
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_BUFFER_MODEL
+ if (cm->decoder_model_info_present_flag &&
+ cm->timing_info.equal_picture_interval == 0) {
+ av1_read_tu_pts_info(cm, rb);
+ }
+#endif
if (cm->seq_params.frame_id_numbers_present_flag) {
int frame_id_length = cm->seq_params.frame_id_length;
int display_frame_id = aom_rb_read_literal(rb, frame_id_length);
@@ -2610,7 +2677,15 @@
cm->frame_type = (FRAME_TYPE)aom_rb_read_literal(rb, 2); // 2 bits
cm->show_frame = aom_rb_read_bit(rb);
cm->showable_frame = 0;
+#if CONFIG_BUFFER_MODEL
+ if (cm->show_frame) {
+ if (cm->decoder_model_info_present_flag &&
+ cm->timing_info.equal_picture_interval == 0)
+ av1_read_tu_pts_info(cm, rb);
+ } else {
+#else
if (!cm->show_frame) {
+#endif
// See if this frame can be used as show_existing_frame in future
cm->showable_frame = aom_rb_read_bit(rb);
}
@@ -2700,6 +2775,27 @@
}
}
+#if CONFIG_BUFFER_MODEL
+ if (cm->decoder_model_info_present_flag) {
+ cm->buffer_removal_delay_present = aom_rb_read_bit(rb);
+ if (cm->buffer_removal_delay_present) {
+ for (int op_num = 0; op_num < cm->operating_points_decoder_model_cnt;
+ op_num++) {
+ if (((cm->op_params[op_num].decoder_model_operating_point_idc >>
+ cm->temporal_layer_id) &
+ 0x1 &&
+ (cm->op_params[op_num].decoder_model_operating_point_idc >>
+ (cm->enhancement_layer_id + 8)) &
+ 0x1) ||
+ cm->op_params[op_num].decoder_model_operating_point_idc == 0) {
+ cm->op_frame_timing[op_num].buffer_removal_delay =
+ aom_rb_read_literal(rb,
+ cm->buffer_model.buffer_removal_delay_length);
+ }
+ }
+ }
+ }
+#endif
if (cm->frame_type == KEY_FRAME) {
if (!cm->show_frame) // unshown keyframe (forward keyframe)
pbi->refresh_frame_flags = aom_rb_read_literal(rb, REF_FRAMES);
diff --git a/av1/decoder/decodeframe.h b/av1/decoder/decodeframe.h
index fd0a358..d1e682c 100644
--- a/av1/decoder/decodeframe.h
+++ b/av1/decoder/decodeframe.h
@@ -47,6 +47,12 @@
int allow_lowbitdepth);
void av1_read_timing_info_header(AV1_COMMON *cm,
struct aom_read_bit_buffer *rb);
+#if CONFIG_BUFFER_MODEL
+void av1_read_decoder_model_info(AV1_COMMON *cm,
+ struct aom_read_bit_buffer *rb);
+void av1_read_op_parameters_info(AV1_COMMON *const cm,
+ struct aom_read_bit_buffer *rb, int op_num);
+#endif
struct aom_read_bit_buffer *av1_init_read_bit_buffer(
struct AV1Decoder *pbi, struct aom_read_bit_buffer *rb, const uint8_t *data,
diff --git a/av1/decoder/obu.c b/av1/decoder/obu.c
index d558e8a..e84fa85 100644
--- a/av1/decoder/obu.c
+++ b/av1/decoder/obu.c
@@ -170,6 +170,7 @@
seq_params->operating_point_idc[i] =
aom_rb_read_literal(rb, OP_POINTS_IDC_BITS);
seq_params->level[i] = aom_rb_read_literal(rb, LEVEL_BITS);
+#if !CONFIG_BUFFER_MODEL
seq_params->decoder_rate_model_param_present_flag[i] =
aom_rb_read_literal(rb, 1);
if (seq_params->decoder_rate_model_param_present_flag[i]) {
@@ -178,6 +179,7 @@
seq_params->initial_display_delay[i] = aom_rb_read_literal(rb, 24);
seq_params->extra_frame_buffers[i] = aom_rb_read_literal(rb, 4);
}
+#endif
}
}
// This decoder supports all levels. Choose the first operating point
@@ -187,10 +189,52 @@
av1_read_bitdepth_colorspace_sampling(cm, rb, pbi->allow_lowbitdepth);
+#if !CONFIG_BUFFER_MODEL
if (!seq_params->reduced_still_picture_hdr)
av1_read_timing_info_header(cm, rb);
else
cm->timing_info_present = 0;
+#else
+ if (!seq_params->reduced_still_picture_hdr)
+ cm->timing_info_present = aom_rb_read_bit(rb); // timing info present flag
+ else
+ cm->timing_info_present = 0;
+
+ if (cm->timing_info_present) {
+ av1_read_timing_info_header(cm, rb);
+
+ cm->decoder_model_info_present_flag = aom_rb_read_bit(rb);
+ if (cm->decoder_model_info_present_flag)
+ av1_read_decoder_model_info(cm, rb);
+ }
+ int operating_points_decoder_model_present = aom_rb_read_bit(rb);
+ if (operating_points_decoder_model_present) {
+ cm->operating_points_decoder_model_cnt = aom_rb_read_literal(rb, 5) + 1;
+ } else {
+ cm->operating_points_decoder_model_cnt = 0;
+ }
+ for (int op_num = 0; op_num < cm->operating_points_decoder_model_cnt;
+ ++op_num) {
+ cm->op_params[op_num].decoder_model_operating_point_idc =
+ aom_rb_read_literal(rb, 12);
+ cm->op_params[op_num].display_model_param_present_flag =
+ aom_rb_read_bit(rb);
+ if (cm->op_params[op_num].display_model_param_present_flag) {
+ cm->op_params[op_num].initial_display_delay =
+ aom_rb_read_literal(rb, 4) + 1;
+ if (cm->op_params[op_num].initial_display_delay > 10)
+ aom_internal_error(
+ &cm->error, AOM_CODEC_UNSUP_BITSTREAM,
+ "AV1 does not support more than 10 decoded frames delay");
+ }
+ if (cm->decoder_model_info_present_flag) {
+ cm->op_params[op_num].decoder_model_param_present_flag =
+ aom_rb_read_bit(rb);
+ if (cm->op_params[op_num].decoder_model_param_present_flag)
+ av1_read_op_parameters_info(cm, rb, op_num);
+ }
+ }
+#endif
cm->film_grain_params_present = aom_rb_read_bit(rb);