Change byte_alignment() to call aom_internal_error Change byte_alignment() to report error by calling aom_internal_error() so that it can set an error message. Also clean up the error reporting code to use pbi->error instead of cm->error. Since cm->error is set equal to &pbi->error, this is just a cosmetic change. Update stale comments that still refer to pbi->common.error.error_code. pbi->common.error is now a pointer. Change-Id: Idb7cc93dc01eb59f45f7a2e04b9a290ba26c3582
diff --git a/av1/decoder/obu.c b/av1/decoder/obu.c index 45a3f15..4809578 100644 --- a/av1/decoder/obu.c +++ b/av1/decoder/obu.c
@@ -66,15 +66,14 @@ return 0; } -static int byte_alignment(AV1_COMMON *const cm, - struct aom_read_bit_buffer *const rb) { +static void byte_alignment(AV1Decoder *pbi, + struct aom_read_bit_buffer *const rb) { while (rb->bit_offset & 7) { if (aom_rb_read_bit(rb)) { - cm->error->error_code = AOM_CODEC_CORRUPT_FRAME; - return -1; + aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, + "byte_alignment() is not all 0 bits"); } } - return 0; } static uint32_t read_temporal_delimiter_obu(void) { return 0; } @@ -93,7 +92,7 @@ // On success, sets pbi->sequence_header_ready to 1 and returns the number of // bytes read from 'rb'. // On failure, calls aom_internal_error() and does not return, or sets -// pbi->common.error.error_code and returns 0. +// pbi->error.error_code and returns 0. static uint32_t read_sequence_header_obu(AV1Decoder *pbi, struct aom_read_bit_buffer *rb) { AV1_COMMON *const cm = &pbi->common; @@ -281,10 +280,10 @@ // On success, returns the tile group header size. On failure, calls // aom_internal_error() and does not return. -static int32_t read_tile_group_header(AV1Decoder *pbi, - struct aom_read_bit_buffer *rb, - int *start_tile, int *end_tile, - int tile_start_implicit) { +static uint32_t read_tile_group_header(AV1Decoder *pbi, + struct aom_read_bit_buffer *rb, + int *start_tile, int *end_tile, + int tile_start_implicit) { AV1_COMMON *const cm = &pbi->common; CommonTileParams *const tiles = &cm->tiles; uint32_t saved_bit_offset = rb->bit_offset; @@ -329,27 +328,26 @@ return ((rb->bit_offset - saved_bit_offset + 7) >> 3); } -// On success, returns the tile group OBU size. On failure, sets -// pbi->common.error.error_code and returns 0. +// On success, returns the tile group OBU size. On failure, calls +// aom_internal_error() and does not return. static uint32_t read_one_tile_group_obu( AV1Decoder *pbi, struct aom_read_bit_buffer *rb, int is_first_tg, const uint8_t *data, const uint8_t *data_end, const uint8_t **p_data_end, int *is_last_tg, int tile_start_implicit) { AV1_COMMON *const cm = &pbi->common; int start_tile, end_tile; - int32_t header_size, tg_payload_size; assert((rb->bit_offset & 7) == 0); assert(rb->bit_buffer + aom_rb_bytes_read(rb) == data); - header_size = read_tile_group_header(pbi, rb, &start_tile, &end_tile, - tile_start_implicit); - if (header_size == -1 || byte_alignment(cm, rb)) return 0; + uint32_t header_size = read_tile_group_header(pbi, rb, &start_tile, &end_tile, + tile_start_implicit); + byte_alignment(pbi, rb); data += header_size; av1_decode_tg_tiles_and_wrapup(pbi, data, data_end, p_data_end, start_tile, end_tile, is_first_tg); - tg_payload_size = (uint32_t)(*p_data_end - data); + uint32_t tg_payload_size = (uint32_t)(*p_data_end - data); *is_last_tg = end_tile == cm->tiles.rows * cm->tiles.cols - 1; return header_size + tg_payload_size; @@ -465,7 +463,7 @@ // Only called while large_scale_tile = 1. // // On success, returns the tile list OBU size. On failure, sets -// pbi->common.error.error_code and returns 0. +// pbi->error.error_code and returns 0. static uint32_t read_and_decode_one_tile_list(AV1Decoder *pbi, struct aom_read_bit_buffer *rb, const uint8_t *data, @@ -767,8 +765,8 @@ // Checks the metadata for correct syntax but ignores the parsed metadata. // // On success, returns the number of bytes read from 'data'. On failure, sets -// pbi->common.error.error_code and returns 0, or calls aom_internal_error() -// and does not return. +// pbi->error.error_code and returns 0, or calls aom_internal_error() and does +// not return. static size_t read_metadata(AV1Decoder *pbi, const uint8_t *data, size_t sz, bool has_obu_extension_header) { size_t type_length; @@ -828,10 +826,9 @@ return type_length + (rb.bit_offset >> 3); } -// On success, returns 'sz'. On failure, sets pbi->common.error.error_code and -// returns 0. -static size_t read_padding(AV1_COMMON *const cm, const uint8_t *data, - size_t sz) { +// On success, returns 'sz'. On failure, sets pbi->error.error_code and returns +// 0. +static size_t read_padding(AV1Decoder *pbi, const uint8_t *data, size_t sz) { // The spec allows a padding OBU to be header-only (i.e., obu_size = 0). So // check trailing bits only if sz > 0. if (sz > 0) { @@ -839,7 +836,7 @@ // trailing byte should be 0x80. See https://crbug.com/aomedia/2393. const uint8_t last_nonzero_byte = get_last_nonzero_byte(data, sz); if (last_nonzero_byte != 0x80) { - cm->error->error_code = AOM_CODEC_CORRUPT_FRAME; + pbi->error.error_code = AOM_CODEC_CORRUPT_FRAME; return 0; } } @@ -1026,8 +1023,7 @@ if (obu_header.type != OBU_FRAME) break; obu_payload_offset = frame_header_size; // Byte align the reader before reading the tile group. - // byte_alignment() has set pbi->error.error_code if it returns -1. - if (byte_alignment(cm, &rb)) return -1; + byte_alignment(pbi, &rb); AOM_FALLTHROUGH_INTENDED; // fall through to read tile group. case OBU_TILE_GROUP: if (!pbi->seen_frame_header) { @@ -1042,7 +1038,6 @@ pbi, &rb, is_first_tg_obu_received, data + obu_payload_offset, data + payload_size, p_data_end, &frame_decoding_finished, obu_header.type == OBU_FRAME); - if (pbi->error.error_code != AOM_CODEC_OK) return -1; is_first_tg_obu_received = 0; if (frame_decoding_finished) { pbi->seen_frame_header = 0; @@ -1077,7 +1072,7 @@ if (pbi->error.error_code != AOM_CODEC_OK) return -1; break; case OBU_PADDING: - decoded_payload_size = read_padding(cm, data, payload_size); + decoded_payload_size = read_padding(pbi, data, payload_size); if (pbi->error.error_code != AOM_CODEC_OK) return -1; break; default: