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