Tag Parser: flac/flactooggmappingheader.cpp Source File

Tag Parser 12.5.3 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.
1#include "./flactooggmappingheader.h"
2
3#include "../ogg/oggiterator.h"
4
5#include "../exceptions.h"
6
7#include <c++utilities/conversion/binaryconversion.h>
8
9using namespace std;
10using namespace CppUtilities;
11
12namespace TagParser {
13
19
24 void FlacToOggMappingHeader::parseHeader(OggIterator &iterator)
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"
44 FlacMetaDataBlockHeader header;
45 header.parseHeader(std::string_view(buff + mappingHeaderSize - idSize, blockHeaderSize));
46 if (header.type() != FlacMetaDataBlockType::StreamInfo) {
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
TagParser::FlacMetaDataBlockHeader
The FlacMetaDataBlockHeader class is a FLAC "METADATA_BLOCK_HEADER" parser and maker.
Definition flacmetadata.h:28
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::FlacMetaDataBlockHeader::type
constexpr std::uint8_t type() const
Returns the block type.
Definition flacmetadata.h:79
TagParser::FlacMetaDataBlockHeader::parseHeader
void parseHeader(std::string_view buffer)
Parses the FLAC "METADATA_BLOCK_HEADER" which is read using the specified iterator.
Definition flacmetadata.cpp:29
TagParser::FlacToOggMappingHeader::parseHeader
void parseHeader(OggIterator &iterator)
Parses the FLAC-to-Ogg mapping header which is read using the specified iterator.
Definition flactooggmappingheader.cpp:24
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::OggIterator
The OggIterator class helps iterating through all segments of an Ogg bitstream.
Definition oggiterator.h:11
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
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
exceptions.h
flactooggmappingheader.h
CppUtilities
Definition abstractcontainer.h:16
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::FlacMetaDataBlockType::StreamInfo
@ StreamInfo
Definition flacmetadata.h:16
oggiterator.h