Tag Parser  6.4.0
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 ConversionUtilities;
11 
12 namespace Media {
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<byte>(*(buff + 0x00));
36  m_minorVersion = static_cast<byte>(*(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 }
byte type() const
Returns the block type.
Definition: flacmetadata.h:89
void parseHeader(const char *buffer)
Parses the FLAC "METADATA_BLOCK_HEADER" which is read using the specified iterator.
The FlacMetaDataBlockHeader class is a FLAC "METADATA_BLOCK_HEADER" parser and maker.
Definition: flacmetadata.h:38
STL namespace.
The exception that is thrown when the data to be parsed or to be made seems invalid and therefore can...
Definition: exceptions.h:27
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 ...
Definition: exceptions.h:35
The OggIterator class helps iterating through all segments of an OGG bitstream.
Definition: oggiterator.h:11
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
uint32 dataSize() const
Returns the length in bytes of the meta data (excluding the size of the header itself).
Definition: flacmetadata.h:105