Tag Parser 11.3.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
oggpage.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_OGGPAGE_H
2#define TAG_PARSER_OGGPAGE_H
3
4#include "../global.h"
5
6#include <cstdint>
7#include <iosfwd>
8#include <numeric>
9#include <vector>
10
11namespace TagParser {
12
14public:
15 OggPage();
16 OggPage(std::istream &stream, std::uint64_t startOffset, std::int32_t maxSize);
17
18 void parseHeader(std::istream &stream, std::uint64_t startOffset, std::int32_t maxSize);
19 static std::uint32_t computeChecksum(std::istream &stream, std::uint64_t startOffset);
20 static void updateChecksum(std::iostream &stream, std::uint64_t startOffset);
21
22 std::uint64_t startOffset() const;
23 std::uint8_t streamStructureVersion() const;
24 std::uint8_t headerTypeFlag() const;
25 bool isContinued() const;
26 bool isFirstpage() const;
27 bool isLastPage() const;
28 bool isLastSegmentUnconcluded() const;
29 std::uint64_t absoluteGranulePosition() const;
30 std::uint32_t streamSerialNumber() const;
31 bool matchesStreamSerialNumber(std::uint32_t streamSerialNumber) const;
32 std::uint32_t sequenceNumber() const;
33 std::uint32_t checksum() const;
34 std::uint8_t segmentTableSize() const;
35 const std::vector<std::uint32_t> &segmentSizes() const;
36 std::uint32_t headerSize() const;
37 std::uint32_t dataSize() const;
38 std::uint32_t totalSize() const;
39 std::uint64_t dataOffset(std::vector<std::uint32_t>::size_type segmentIndex = 0) const;
40 static std::uint32_t makeSegmentSizeDenotation(std::ostream &stream, std::uint32_t size);
41
42private:
43 std::uint64_t m_startOffset;
44 std::uint8_t m_streamStructureVersion;
45 std::uint8_t m_headerTypeFlag;
46 std::uint64_t m_absoluteGranulePosition;
47 std::uint32_t m_streamSerialNumber;
48 std::uint32_t m_sequenceNumber;
49 std::uint32_t m_checksum;
50 std::uint8_t m_segmentCount;
51 std::vector<std::uint32_t> m_segmentSizes;
52};
53
58 : m_startOffset(0)
59 , m_streamStructureVersion(0)
60 , m_headerTypeFlag(0)
61 , m_absoluteGranulePosition(0)
62 , m_streamSerialNumber(0)
63 , m_sequenceNumber(0)
64 , m_checksum(0)
65 , m_segmentCount(0)
66{
67}
68
73inline OggPage::OggPage(std::istream &stream, std::uint64_t startOffset, std::int32_t maxSize)
74 : OggPage()
75{
76 parseHeader(stream, startOffset, maxSize);
77}
78
84inline std::uint64_t OggPage::startOffset() const
85{
86 return m_startOffset;
87}
88
92inline std::uint8_t OggPage::streamStructureVersion() const
93{
94 return m_streamStructureVersion;
95}
96
103inline std::uint8_t OggPage::headerTypeFlag() const
104{
105 return m_headerTypeFlag & 0xF; // last 4 bits are used internally
106}
107
111inline bool OggPage::isContinued() const
112{
113 return m_headerTypeFlag & 0x01;
114}
115
119inline bool OggPage::isFirstpage() const
120{
121 return m_headerTypeFlag & 0x02;
122}
123
127inline bool OggPage::isLastPage() const
128{
129 return m_headerTypeFlag & 0x04;
130}
131
136{
137 return m_headerTypeFlag & 0x80;
138}
139
151inline std::uint64_t OggPage::absoluteGranulePosition() const
152{
153 return m_absoluteGranulePosition;
154}
155
164inline std::uint32_t OggPage::streamSerialNumber() const
165{
166 return m_streamSerialNumber;
167}
168
173inline bool OggPage::matchesStreamSerialNumber(std::uint32_t streamSerialNumber) const
174{
175 return m_streamSerialNumber == streamSerialNumber;
176}
177
183inline std::uint32_t OggPage::sequenceNumber() const
184{
185 return m_sequenceNumber;
186}
187
198inline std::uint32_t OggPage::checksum() const
199{
200 return m_checksum;
201}
202
208inline std::uint8_t OggPage::segmentTableSize() const
209{
210 return m_segmentCount;
211}
212
218inline const std::vector<std::uint32_t> &OggPage::segmentSizes() const
219{
220 return m_segmentSizes;
221}
222
228inline std::uint32_t OggPage::headerSize() const
229{
230 return 27 + m_segmentCount;
231}
232
236inline std::uint32_t OggPage::dataSize() const
237{
238 return std::accumulate(m_segmentSizes.cbegin(), m_segmentSizes.cend(), 0u);
239}
240
244inline std::uint32_t OggPage::totalSize() const
245{
246 return headerSize() + dataSize();
247}
248
257inline std::uint64_t OggPage::dataOffset(std::vector<std::uint32_t>::size_type segmentIndex) const
258{
259 return startOffset() + headerSize()
260 + std::accumulate<decltype(m_segmentSizes)::const_iterator, std::uint64_t>(
261 m_segmentSizes.cbegin(), m_segmentSizes.cbegin() + static_cast<decltype(m_segmentSizes)::difference_type>(segmentIndex), 0u);
262}
263
264} // namespace TagParser
265
266#endif // TAG_PARSER_OGGPAGE_H
The OggPage class is used to parse OGG pages.
Definition: oggpage.h:13
std::uint32_t sequenceNumber() const
Returns the page sequence number.
Definition: oggpage.h:183
std::uint32_t dataSize() const
Returns the data size in byte.
Definition: oggpage.h:236
void parseHeader(std::istream &stream, std::uint64_t startOffset, std::int32_t maxSize)
Parses the header read from the specified stream at the specified startOffset.
Definition: oggpage.cpp:27
bool isFirstpage() const
Returns whether this page is the first page of the logical bitstream.
Definition: oggpage.h:119
bool isLastSegmentUnconcluded() const
Returns whether the last segment is unconcluded (the last lacing value of the last segment is 0xFF).
Definition: oggpage.h:135
std::uint32_t totalSize() const
Returns the total size of the page in byte.
Definition: oggpage.h:244
std::uint64_t dataOffset(std::vector< std::uint32_t >::size_type segmentIndex=0) const
Returns the data offset of the segment with the specified segmentIndex.
Definition: oggpage.h:257
std::uint32_t streamSerialNumber() const
Returns the stream serial number.
Definition: oggpage.h:164
const std::vector< std::uint32_t > & segmentSizes() const
Returns the sizes of the segments of the page in byte.
Definition: oggpage.h:218
std::uint8_t headerTypeFlag() const
Returns the header type flag.
Definition: oggpage.h:103
OggPage()
Constructs a new OGG page.
Definition: oggpage.h:57
std::uint64_t startOffset() const
Returns the start offset of the page.
Definition: oggpage.h:84
bool matchesStreamSerialNumber(std::uint32_t streamSerialNumber) const
Returns whether the stream serial number of the current instance matches the specified one.
Definition: oggpage.h:173
std::uint32_t checksum() const
Returns the page checksum.
Definition: oggpage.h:198
std::uint8_t streamStructureVersion() const
Returns the stream structure version.
Definition: oggpage.h:92
bool isLastPage() const
Returns whether this page is the last page of the logical bitstream.
Definition: oggpage.h:127
bool isContinued() const
Returns whether this page is a continued packed (true) or a fresh packed (false).
Definition: oggpage.h:111
std::uint8_t segmentTableSize() const
Returns the size of the segment table.
Definition: oggpage.h:208
std::uint64_t absoluteGranulePosition() const
Returns the absolute granule position.
Definition: oggpage.h:151
std::uint32_t headerSize() const
Returns the header size in byte.
Definition: oggpage.h:228
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10