Commit b7f1f0c0 authored by Wan-Teh Chang's avatar Wan-Teh Chang

Simple changes to OBU header decoding code.

These changes are intended to make it easier to compare the code with
the spec.

1. Rename has_length_field to has_size_field to match the name of the
corresponding syntax element (obu_has_size_field) in the spec.

2. Reorder the OBU types in valid_obu_type() to match the order of OBU
types in the spec.

3. Require that the reserve bits be 0 per the spec.

Change-Id: I617486414869b45f3e0d57027a7e5e6bc6d13386
parent 0221e9de
......@@ -48,10 +48,10 @@ static int valid_obu_type(int obu_type) {
case OBU_SEQUENCE_HEADER:
case OBU_TEMPORAL_DELIMITER:
case OBU_FRAME_HEADER:
case OBU_REDUNDANT_FRAME_HEADER:
case OBU_FRAME:
case OBU_TILE_GROUP:
case OBU_METADATA:
case OBU_FRAME:
case OBU_REDUNDANT_FRAME_HEADER:
case OBU_TILE_LIST:
case OBU_PADDING: valid_type = 1; break;
default: break;
......@@ -79,14 +79,17 @@ static aom_codec_err_t read_obu_header(struct aom_read_bit_buffer *rb,
if (!valid_obu_type(header->type)) return AOM_CODEC_CORRUPT_FRAME;
header->has_extension = aom_rb_read_bit(rb);
header->has_length_field = aom_rb_read_bit(rb);
header->has_size_field = aom_rb_read_bit(rb);
if (!header->has_length_field && !is_annexb) {
// section 5 obu streams must have length field set.
if (!header->has_size_field && !is_annexb) {
// section 5 obu streams must have obu_size field set.
return AOM_CODEC_UNSUP_BITSTREAM;
}
aom_rb_read_bit(rb); // reserved
if (aom_rb_read_bit(rb) != 0) {
// obu_reserved_1bit must be set to 0.
return AOM_CODEC_CORRUPT_FRAME;
}
if (header->has_extension) {
if (bit_buffer_byte_length == 1) return AOM_CODEC_CORRUPT_FRAME;
......@@ -94,7 +97,10 @@ static aom_codec_err_t read_obu_header(struct aom_read_bit_buffer *rb,
header->size += 1;
header->temporal_layer_id = aom_rb_read_literal(rb, 3);
header->spatial_layer_id = aom_rb_read_literal(rb, 2);
aom_rb_read_literal(rb, 3); // reserved
if (aom_rb_read_literal(rb, 3) != 0) {
// extension_header_reserved_3bits must be set to 0.
return AOM_CODEC_CORRUPT_FRAME;
}
}
return AOM_CODEC_OK;
......
......@@ -16,10 +16,13 @@
#include "av1/decoder/decoder.h"
typedef struct {
size_t size;
size_t size; // Size (1 or 2 bytes) of the OBU header (including the
// optional OBU extension header) in the bitstream.
OBU_TYPE type;
int has_length_field;
int has_size_field;
int has_extension;
// The following fields come from the OBU extension header and therefore are
// only used if has_extension is true.
int temporal_layer_id;
int spatial_layer_id;
} ObuHeader;
......
......@@ -284,7 +284,7 @@ int file_is_obu(struct ObuDecInputContext *obu_ctx) {
return 0;
}
if (obu_header.has_length_field) {
if (obu_header.has_size_field) {
if (obu_header.type == OBU_TEMPORAL_DELIMITER && payload_length != 0) {
fprintf(
stderr,
......
......@@ -87,7 +87,7 @@ bool ParseObuHeader(uint8_t obu_header_byte, ObuHeader *obu_header) {
obu_header->has_extension =
(obu_header_byte >> kObuExtensionFlagBitShift) & kObuExtensionFlagBitMask;
obu_header->has_length_field =
obu_header->has_size_field =
(obu_header_byte >> kObuHasPayloadLengthFlagBitShift) &
kObuHasPayloadLengthFlagBitMask;
return true;
......
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