Tag Parser 12.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
13class TAG_PARSER_EXPORT OggPage {
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 bool m_lastSegmentUnconcluded;
52 std::vector<std::uint32_t> m_segmentSizes;
53};
54
59 : m_startOffset(0)
60 , m_streamStructureVersion(0)
61 , m_headerTypeFlag(0)
62 , m_absoluteGranulePosition(0)
63 , m_streamSerialNumber(0)
64 , m_sequenceNumber(0)
65 , m_checksum(0)
66 , m_segmentCount(0)
67 , m_lastSegmentUnconcluded(false)
68{
69}
70
75inline OggPage::OggPage(std::istream &stream, std::uint64_t startOffset, std::int32_t maxSize)
76 : OggPage()
77{
78 parseHeader(stream, startOffset, maxSize);
79}
80
86inline std::uint64_t OggPage::startOffset() const
87{
88 return m_startOffset;
89}
90
94inline std::uint8_t OggPage::streamStructureVersion() const
95{
96 return m_streamStructureVersion;
97}
98
105inline std::uint8_t OggPage::headerTypeFlag() const
106{
107 return m_headerTypeFlag & 0xF; // last 4 bits are used internally
108}
109
113inline bool OggPage::isContinued() const
114{
115 return m_headerTypeFlag & 0x01;
116}
117
121inline bool OggPage::isFirstpage() const
122{
123 return m_headerTypeFlag & 0x02;
124}
125
129inline bool OggPage::isLastPage() const
130{
131 return m_headerTypeFlag & 0x04;
132}
133
138{
139 return m_lastSegmentUnconcluded;
140}
141
153inline std::uint64_t OggPage::absoluteGranulePosition() const
154{
155 return m_absoluteGranulePosition;
156}
157
166inline std::uint32_t OggPage::streamSerialNumber() const
167{
168 return m_streamSerialNumber;
169}
170
175inline bool OggPage::matchesStreamSerialNumber(std::uint32_t streamSerialNumber) const
176{
177 return m_streamSerialNumber == streamSerialNumber;
178}
179
185inline std::uint32_t OggPage::sequenceNumber() const
186{
187 return m_sequenceNumber;
188}
189
200inline std::uint32_t OggPage::checksum() const
201{
202 return m_checksum;
203}
204
210inline std::uint8_t OggPage::segmentTableSize() const
211{
212 return m_segmentCount;
213}
214
220inline const std::vector<std::uint32_t> &OggPage::segmentSizes() const
221{
222 return m_segmentSizes;
223}
224
230inline std::uint32_t OggPage::headerSize() const
231{
232 return 27 + m_segmentCount;
233}
234
238inline std::uint32_t OggPage::dataSize() const
239{
240 return std::accumulate(m_segmentSizes.cbegin(), m_segmentSizes.cend(), 0u);
241}
242
246inline std::uint32_t OggPage::totalSize() const
247{
248 return headerSize() + dataSize();
249}
250
259inline std::uint64_t OggPage::dataOffset(std::vector<std::uint32_t>::size_type segmentIndex) const
260{
261 return startOffset() + headerSize()
262 + std::accumulate<decltype(m_segmentSizes)::const_iterator, std::uint64_t>(
263 m_segmentSizes.cbegin(), m_segmentSizes.cbegin() + static_cast<decltype(m_segmentSizes)::difference_type>(segmentIndex), 0u);
264}
265
266} // namespace TagParser
267
268#endif // TAG_PARSER_OGGPAGE_H
The OggPage class is used to parse Ogg pages.
std::uint32_t sequenceNumber() const
Returns the page sequence number.
Definition oggpage.h:185
std::uint32_t dataSize() const
Returns the data size in byte.
Definition oggpage.h:238
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:121
bool isLastSegmentUnconcluded() const
Returns whether the last segment is unconcluded (the last lacing value of the last segment is 0xFF).
Definition oggpage.h:137
std::uint32_t totalSize() const
Returns the total size of the page in byte.
Definition oggpage.h:246
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:259
std::uint32_t streamSerialNumber() const
Returns the stream serial number.
Definition oggpage.h:166
const std::vector< std::uint32_t > & segmentSizes() const
Returns the sizes of the segments of the page in byte.
Definition oggpage.h:220
std::uint8_t headerTypeFlag() const
Returns the header type flag.
Definition oggpage.h:105
OggPage()
Constructs a new Ogg page.
Definition oggpage.h:58
std::uint64_t startOffset() const
Returns the start offset of the page.
Definition oggpage.h:86
bool matchesStreamSerialNumber(std::uint32_t streamSerialNumber) const
Returns whether the stream serial number of the current instance matches the specified one.
Definition oggpage.h:175
std::uint32_t checksum() const
Returns the page checksum.
Definition oggpage.h:200
std::uint8_t streamStructureVersion() const
Returns the stream structure version.
Definition oggpage.h:94
bool isLastPage() const
Returns whether this page is the last page of the logical bitstream.
Definition oggpage.h:129
bool isContinued() const
Returns whether this page is a continued packet (true) or a fresh packet (false).
Definition oggpage.h:113
std::uint8_t segmentTableSize() const
Returns the size of the segment table.
Definition oggpage.h:210
std::uint64_t absoluteGranulePosition() const
Returns the absolute granule position.
Definition oggpage.h:153
std::uint32_t headerSize() const
Returns the header size in byte.
Definition oggpage.h:230
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10