diff --git a/av1/av1configuration.cpp b/av1/av1configuration.cpp index 0a92a92..05c1c3d 100644 --- a/av1/av1configuration.cpp +++ b/av1/av1configuration.cpp @@ -3,9 +3,11 @@ #include "../diagnostics.h" #include "../exceptions.h" +#include #include using namespace std; +using namespace ConversionUtilities; using namespace IoUtilities; namespace TagParser { @@ -19,14 +21,20 @@ namespace TagParser { * \brief Parses the AV1 configuration using the specified \a reader. * \throws Throws TruncatedDataException() when the config size exceeds the specified \a maxSize. * \remarks Logging/reporting parsing errors is not implemented yet. - * \todo Provide implementation + * \todo Read all fields. */ void Av1Configuration::parse(BinaryReader &reader, uint64 maxSize, Diagnostics &diag) { - VAR_UNUSED(reader) - VAR_UNUSED(maxSize) - VAR_UNUSED(diag) - throw NotImplementedException(); + if (maxSize < 4) { + throw TruncatedDataException(); + } + markerAndVersion = reader.readUInt32BE(); + if (marker() != 1) { + diag.emplace_back(DiagLevel::Warning, argsToString("Marker is ", marker(), " (and not 1)."), "parsing AV1 config"); + } + if (version() != 1) { + diag.emplace_back(DiagLevel::Warning, argsToString("Version ", version(), " is not supported (only 1)."), "parsing AV1 config"); + } } } // namespace TagParser diff --git a/av1/av1configuration.h b/av1/av1configuration.h index c79a62b..ecac726 100644 --- a/av1/av1configuration.h +++ b/av1/av1configuration.h @@ -15,8 +15,11 @@ class MediaFormat; class Diagnostics; struct TAG_PARSER_EXPORT Av1Configuration { - Av1Configuration(); + constexpr Av1Configuration(); + // FIXME: make this uint32 in v9 uint64 markerAndVersion; + + // FIXME: get rid of unused members in v9 uint64 profileAndLevel; byte tier; byte highBitdepth; @@ -27,12 +30,24 @@ struct TAG_PARSER_EXPORT Av1Configuration { uint16 chromaSamplePosition; void parse(IoUtilities::BinaryReader &reader, uint64 maxSize, Diagnostics &diag); + + constexpr byte marker() const; + constexpr byte version() const; + constexpr byte sequenceProfile() const; + constexpr byte sequenceLevelIndex() const; + constexpr byte sequenceTier() const; + constexpr byte isHighBitDepth() const; + constexpr byte isTwelveBit() const; + constexpr byte isMonochrome() const; + constexpr byte hasChromaSubsamplingX() const; + constexpr byte hasChromaSubsamplingY() const; + constexpr byte chromaSamplePos() const; }; /*! * \brief Constructs an empty AVC configuration. */ -inline Av1Configuration::Av1Configuration() +constexpr Av1Configuration::Av1Configuration() : markerAndVersion(0) , profileAndLevel(0) , tier(0) @@ -45,6 +60,61 @@ inline Av1Configuration::Av1Configuration() { } +constexpr byte Av1Configuration::marker() const +{ + return static_cast((markerAndVersion >> (32 - 1)) & 0x01); +} + +constexpr byte Av1Configuration::version() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7)) & 0x7F); +} + +constexpr byte Av1Configuration::sequenceProfile() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3)) & 0x07); +} + +constexpr byte Av1Configuration::sequenceLevelIndex() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3 - 5)) & 0x1F); +} + +constexpr byte Av1Configuration::sequenceTier() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3 - 5 - 1)) & 0x01); +} + +constexpr byte Av1Configuration::isHighBitDepth() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3 - 5 - 1 - 1)) & 0x01); +} + +constexpr byte Av1Configuration::isTwelveBit() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3 - 5 - 1 - 1)) & 0x01); +} + +constexpr byte Av1Configuration::isMonochrome() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3 - 5 - 1 - 1 - 1)) & 0x01); +} + +constexpr byte Av1Configuration::hasChromaSubsamplingX() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3 - 5 - 1 - 1 - 1 - 1)) & 0x01); +} + +constexpr byte Av1Configuration::hasChromaSubsamplingY() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3 - 5 - 1 - 1 - 1 - 1 - 1)) & 0x01); +} + +constexpr byte Av1Configuration::chromaSamplePos() const +{ + return static_cast((markerAndVersion >> (32 - 1 - 7 - 3 - 5 - 1 - 1 - 1 - 1 - 1 - 1)) & 0x03); +} + } // namespace TagParser #endif // TAG_PARSER_AV1CONFIGURATION_H