Commit 4d5d90ed authored by Frederic Barbier's avatar Frederic Barbier Committed by Sebastien Alaiwan
Browse files

Ensure that diff_len is lower than frame_id_length

A frame should be referenced with a unique delta,
which is not guaranteed when diff_len is greater than frame_id_length.

Otherwise, it's possible to get into a situation where a frame
can be referenced with many different delta_frame_id values,
although the decoder only accepts one of them.

Avoid ambiguities when delta-referencing a frame, and
avoid wasting bits by using a coding enforcing the restriction.

Change-Id: If7c611c9b6ec69662c5af540ade59f08bacda2ba
parent e83fcfeb
...@@ -3367,8 +3367,12 @@ void read_sequence_header(SequenceHeader *seq_params, ...@@ -3367,8 +3367,12 @@ void read_sequence_header(SequenceHeader *seq_params,
/* Placeholder for actually reading from the bitstream */ /* Placeholder for actually reading from the bitstream */
seq_params->frame_id_numbers_present_flag = aom_rb_read_bit(rb); seq_params->frame_id_numbers_present_flag = aom_rb_read_bit(rb);
if (seq_params->frame_id_numbers_present_flag) { if (seq_params->frame_id_numbers_present_flag) {
seq_params->frame_id_length = aom_rb_read_literal(rb, 4) + 7; // We must always have delta_frame_id_length < frame_id_length,
// in order for a frame to be referenced with a unique delta.
// Avoid wasting bits by using a coding that enforces this restriction.
seq_params->delta_frame_id_length = aom_rb_read_literal(rb, 4) + 2; seq_params->delta_frame_id_length = aom_rb_read_literal(rb, 4) + 2;
seq_params->frame_id_length =
aom_rb_read_literal(rb, 3) + seq_params->delta_frame_id_length + 1;
} }
} }
#endif // CONFIG_REFERENCE_BUFFER #endif // CONFIG_REFERENCE_BUFFER
...@@ -4753,8 +4757,12 @@ static uint32_t read_sequence_header_obu(AV1Decoder *pbi, ...@@ -4753,8 +4757,12 @@ static uint32_t read_sequence_header_obu(AV1Decoder *pbi,
seq_params->frame_id_numbers_present_flag = aom_rb_read_bit(rb); seq_params->frame_id_numbers_present_flag = aom_rb_read_bit(rb);
if (seq_params->frame_id_numbers_present_flag) { if (seq_params->frame_id_numbers_present_flag) {
seq_params->frame_id_length = aom_rb_read_literal(rb, 4) + 7; // We must always have delta_frame_id_length < frame_id_length,
// in order for a frame to be referenced with a unique delta.
// Avoid wasting bits by using a coding that enforces this restriction.
seq_params->delta_frame_id_length = aom_rb_read_literal(rb, 4) + 2; seq_params->delta_frame_id_length = aom_rb_read_literal(rb, 4) + 2;
seq_params->frame_id_length =
aom_rb_read_literal(rb, 3) + seq_params->delta_frame_id_length + 1;
} }
read_bitdepth_colorspace_sampling(cm, rb, pbi->allow_lowbitdepth); read_bitdepth_colorspace_sampling(cm, rb, pbi->allow_lowbitdepth);
......
...@@ -4154,8 +4154,13 @@ void write_sequence_header(AV1_COMMON *const cm, ...@@ -4154,8 +4154,13 @@ void write_sequence_header(AV1_COMMON *const cm,
aom_wb_write_bit(wb, seq_params->frame_id_numbers_present_flag); aom_wb_write_bit(wb, seq_params->frame_id_numbers_present_flag);
if (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 - 7, 4); // We must always have delta_frame_id_length < frame_id_length,
// in order for a frame to be referenced with a unique delta.
// Avoid wasting bits by using a coding that enforces this restriction.
aom_wb_write_literal(wb, seq_params->delta_frame_id_length - 2, 4); aom_wb_write_literal(wb, seq_params->delta_frame_id_length - 2, 4);
aom_wb_write_literal(
wb, seq_params->frame_id_length - seq_params->delta_frame_id_length - 1,
3);
} }
} }
#endif // CONFIG_REFERENCE_BUFFER #endif // CONFIG_REFERENCE_BUFFER
...@@ -5239,8 +5244,13 @@ static uint32_t write_sequence_header_obu(AV1_COMP *cpi, uint8_t *const dst) { ...@@ -5239,8 +5244,13 @@ static uint32_t write_sequence_header_obu(AV1_COMP *cpi, uint8_t *const dst) {
if (seq_params->frame_id_numbers_present_flag) { if (seq_params->frame_id_numbers_present_flag) {
seq_params->frame_id_length = FRAME_ID_LENGTH_MINUS7 + 7; seq_params->frame_id_length = FRAME_ID_LENGTH_MINUS7 + 7;
seq_params->delta_frame_id_length = DELTA_FRAME_ID_LENGTH_MINUS2 + 2; seq_params->delta_frame_id_length = DELTA_FRAME_ID_LENGTH_MINUS2 + 2;
aom_wb_write_literal(&wb, seq_params->frame_id_length - 7, 4); // We must always have delta_frame_id_length < frame_id_length,
// in order for a frame to be referenced with a unique delta.
// Avoid wasting bits by using a coding that enforces this restriction.
aom_wb_write_literal(&wb, seq_params->delta_frame_id_length - 2, 4); aom_wb_write_literal(&wb, seq_params->delta_frame_id_length - 2, 4);
aom_wb_write_literal(
&wb,
seq_params->frame_id_length - seq_params->delta_frame_id_length - 1, 3);
} }
// color_config // color_config
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment