Commit 8a59bd55 authored by Jingning Han's avatar Jingning Han

[NORMATIVE] Resolve enc/dec mismatch in TRAILING_BITS

Process the trailing bits at the corresponding sequence header,
frame header, and tile decoding. This makes the encoder and decoder
behavior synchronized when CONFIG_TRAILING_BITS is enabled. This
commit resolves the enc/dec mismatch issues when trailing_bits on.

STATS_CHANGED

BUG=aomedia:1641

Change-Id: I7a13f58741d1ae49f35d70d8d358b689ffbd8eba
parent 61b71abc
......@@ -62,6 +62,24 @@
#define MAX_AV1_HEADER_SIZE 80
#define ACCT_STR __func__
#if CONFIG_TRAILING_BITS
// Checks that the remaining bits start with a 1 and ends with 0s.
// It consumes an additional byte, if already byte aligned before the check.
int av1_check_trailing_bits(AV1Decoder *pbi, struct aom_read_bit_buffer *rb,
int *consumed_byte) {
AV1_COMMON *const cm = &pbi->common;
// bit_offset is set to 0 (mod 8) when the reader is already byte aligned
int bits_before_alignment = 8 - rb->bit_offset % 8;
*consumed_byte = (bits_before_alignment == 8);
int trailing = aom_rb_read_literal(rb, bits_before_alignment);
if (trailing != (1 << (bits_before_alignment - 1))) {
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
return 1;
}
return 0;
}
#endif
// Use only_chroma = 1 to only set the chroma planes
static void set_planes_to_neutral_grey(AV1_COMMON *const cm,
MACROBLOCKD *const xd, int only_chroma) {
......@@ -3253,6 +3271,11 @@ int av1_decode_frame_headers_and_setup(AV1Decoder *pbi,
av1_init_read_bit_buffer(pbi, &rb, data, data_end));
#endif
#if CONFIG_TRAILING_BITS
int consumed_byte = 0;
av1_check_trailing_bits(pbi, rb, &consumed_byte);
#endif
// If cm->single_tile_decoding = 0, the independent decoding of a single tile
// or a section of a frame is not allowed.
if (!cm->single_tile_decoding &&
......
......@@ -26,6 +26,11 @@ void av1_read_frame_size(struct aom_read_bit_buffer *rb, int num_bits_width,
int num_bits_height, int *width, int *height);
BITSTREAM_PROFILE av1_read_profile(struct aom_read_bit_buffer *rb);
#if CONFIG_TRAILING_BITS
int av1_check_trailing_bits(struct AV1Decoder *pbi,
struct aom_read_bit_buffer *rb, int *consumed_byte);
#endif
// This function is now obsolete
void av1_decode_frame(struct AV1Decoder *pbi, const uint8_t *data,
const uint8_t *data_end, const uint8_t **p_data_end);
......
......@@ -131,24 +131,6 @@ aom_codec_err_t aom_read_obu_header(uint8_t *buffer, size_t buffer_length,
return parse_result;
}
#if CONFIG_TRAILING_BITS
// Checks that the remaining bits start with a 1 and ends with 0s.
// It consumes an additional byte, if already byte aligned before the check.
static int check_trailing_bits(AV1Decoder *pbi, struct aom_read_bit_buffer *rb,
int *consumed_byte) {
AV1_COMMON *const cm = &pbi->common;
// bit_offset is set to 0 (mod 8) when the reader is already byte aligned
int bits_before_alignment = 8 - rb->bit_offset % 8;
*consumed_byte = (bits_before_alignment == 8);
int trailing = aom_rb_read_literal(rb, bits_before_alignment);
if (trailing != (1 << (bits_before_alignment - 1))) {
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
return 1;
}
return 0;
}
#endif
#if CONFIG_OPERATING_POINTS
static int is_obu_in_current_operating_point(AV1Decoder *pbi,
ObuHeader obu_header) {
......@@ -218,6 +200,11 @@ static uint32_t read_sequence_header_obu(AV1Decoder *pbi,
cm->film_grain_params_present = aom_rb_read_bit(rb);
#endif
#if CONFIG_TRAILING_BITS
int consumed_byte = 0;
av1_check_trailing_bits(pbi, rb, &consumed_byte);
#endif
pbi->sequence_header_ready = 1;
return ((rb->bit_offset - saved_bit_offset + 7) >> 3);
......@@ -563,20 +550,6 @@ void av1_decode_frame_from_obus(struct AV1Decoder *pbi, const uint8_t *data,
break;
}
#if CONFIG_TRAILING_BITS
// Cannot check bit pattern at the end of frame, redundant frame headers,
// tile group, metadata, padding or unrecognized OBUs
// because the current code consumes or skips all bytes
int consumed_byte = 0;
if (payload_size > 0 &&
(obu_header.type == OBU_SEQUENCE_HEADER ||
obu_header.type == OBU_FRAME_HEADER) &&
check_trailing_bits(pbi, &rb, &consumed_byte)) {
return;
}
decoded_payload_size += consumed_byte;
#endif
// Check that the signalled OBU size matches the actual amount of data read
if (decoded_payload_size != payload_size) {
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
......
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