Tag Parser 12.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
flactooggmappingheader.cpp
Go to the documentation of this file.
2
4
5#include "../exceptions.h"
6
7#include <c++utilities/conversion/binaryconversion.h>
8
9using namespace std;
10using namespace CppUtilities;
11
12namespace TagParser {
13
25{
26 // prepare parsing
27 constexpr auto idSize = 0x05, mappingHeaderSize = 0x0D, blockHeaderSize = 0x04, streamInfoSize = 0x22;
28 char buff[mappingHeaderSize + blockHeaderSize + streamInfoSize - idSize];
29 iterator.read(buff, idSize);
30 if (*buff != 0x7Fu || BE::toInt<std::uint32_t>(buff + 1) != 0x464C4143u) {
31 throw InvalidDataException(); // not FLAC-to-Ogg mapping header
32 }
33 iterator.read(buff, sizeof(buff));
34
35 // parse FLAC-to-Ogg mapping header
36 m_majorVersion = static_cast<std::uint8_t>(*(buff + 0x00));
37 m_minorVersion = static_cast<std::uint8_t>(*(buff + 0x01));
38 m_headerCount = BE::toInt<std::uint16_t>(buff + 0x02);
39 if (BE::toInt<std::uint32_t>(buff + 0x04) != 0x664C6143u) {
40 throw InvalidDataException(); // native FLAC signature not present
41 }
42
43 // parse "METADATA_BLOCK_HEADER"
45 header.parseHeader(std::string_view(buff + mappingHeaderSize - idSize, blockHeaderSize));
47 throw InvalidDataException(); // "METADATA_BLOCK_STREAMINFO" expected
48 }
49 if (header.dataSize() < streamInfoSize) {
50 throw TruncatedDataException(); // "METADATA_BLOCK_STREAMINFO" is truncated
51 }
52
53 // parse "METADATA_BLOCK_STREAMINFO"
54 m_streamInfo.parse(std::string_view(buff + mappingHeaderSize + blockHeaderSize - idSize, streamInfoSize));
55}
56
57} // namespace TagParser
The FlacMetaDataBlockHeader class is a FLAC "METADATA_BLOCK_HEADER" parser and maker.
constexpr std::uint32_t dataSize() const
Returns the length in bytes of the meta data (excluding the size of the header itself).
constexpr std::uint8_t type() const
Returns the block type.
void parseHeader(std::string_view buffer)
Parses the FLAC "METADATA_BLOCK_HEADER" which is read using the specified iterator.
void parse(std::string_view buffer)
Parses the FLAC "METADATA_BLOCK_STREAMINFO" which is read using the specified iterator.
void parseHeader(OggIterator &iterator)
Parses the FLAC-to-Ogg mapping header which is read using the specified iterator.
The exception that is thrown when the data to be parsed or to be made seems invalid and therefore can...
The OggIterator class helps iterating through all segments of an Ogg bitstream.
void read(char *buffer, std::size_t count)
Reads count bytes from the Ogg stream and writes it to the specified buffer.
The exception that is thrown when the data to be parsed is truncated and therefore can not be parsed ...
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10