Tag Parser: ogg/oggpage.h 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
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
13 class 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
58 inline OggPage::OggPage()
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
75 inline OggPage::OggPage(std::istream &stream, std::uint64_t startOffset, std::int32_t maxSize)
76 : OggPage()
77{
78 parseHeader(stream, startOffset, maxSize);
79}
80
86 inline std::uint64_t OggPage::startOffset() const
87{
88 return m_startOffset;
89}
90
94 inline std::uint8_t OggPage::streamStructureVersion() const
95{
96 return m_streamStructureVersion;
97}
98
105 inline std::uint8_t OggPage::headerTypeFlag() const
106{
107 return m_headerTypeFlag & 0xF; // last 4 bits are used internally
108}
109
113 inline bool OggPage::isContinued() const
114{
115 return m_headerTypeFlag & 0x01;
116}
117
121 inline bool OggPage::isFirstpage() const
122{
123 return m_headerTypeFlag & 0x02;
124}
125
129 inline bool OggPage::isLastPage() const
130{
131 return m_headerTypeFlag & 0x04;
132}
133
137 inline bool OggPage::isLastSegmentUnconcluded() const
138{
139 return m_lastSegmentUnconcluded;
140}
141
153 inline std::uint64_t OggPage::absoluteGranulePosition() const
154{
155 return m_absoluteGranulePosition;
156}
157
166 inline std::uint32_t OggPage::streamSerialNumber() const
167{
168 return m_streamSerialNumber;
169}
170
175 inline bool OggPage::matchesStreamSerialNumber(std::uint32_t streamSerialNumber) const
176{
177 return m_streamSerialNumber == streamSerialNumber;
178}
179
185 inline std::uint32_t OggPage::sequenceNumber() const
186{
187 return m_sequenceNumber;
188}
189
200 inline std::uint32_t OggPage::checksum() const
201{
202 return m_checksum;
203}
204
210 inline std::uint8_t OggPage::segmentTableSize() const
211{
212 return m_segmentCount;
213}
214
220 inline const std::vector<std::uint32_t> &OggPage::segmentSizes() const
221{
222 return m_segmentSizes;
223}
224
230 inline std::uint32_t OggPage::headerSize() const
231{
232 return 27 + m_segmentCount;
233}
234
238 inline std::uint32_t OggPage::dataSize() const
239{
240 return std::accumulate(m_segmentSizes.cbegin(), m_segmentSizes.cend(), 0u);
241}
242
246 inline std::uint32_t OggPage::totalSize() const
247{
248 return headerSize() + dataSize();
249}
250
259 inline 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
TagParser::OggPage::sequenceNumber
std::uint32_t sequenceNumber() const
Returns the page sequence number.
Definition oggpage.h:185
TagParser::OggPage::dataSize
std::uint32_t dataSize() const
Returns the data size in byte.
Definition oggpage.h:238
TagParser::OggPage::parseHeader
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
TagParser::OggPage::isFirstpage
bool isFirstpage() const
Returns whether this page is the first page of the logical bitstream.
Definition oggpage.h:121
TagParser::OggPage::isLastSegmentUnconcluded
bool isLastSegmentUnconcluded() const
Returns whether the last segment is unconcluded (the last lacing value of the last segment is 0xFF).
Definition oggpage.h:137
TagParser::OggPage::totalSize
std::uint32_t totalSize() const
Returns the total size of the page in byte.
Definition oggpage.h:246
TagParser::OggPage::dataOffset
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
TagParser::OggPage::streamSerialNumber
std::uint32_t streamSerialNumber() const
Returns the stream serial number.
Definition oggpage.h:166
TagParser::OggPage::segmentSizes
const std::vector< std::uint32_t > & segmentSizes() const
Returns the sizes of the segments of the page in byte.
Definition oggpage.h:220
TagParser::OggPage::headerTypeFlag
std::uint8_t headerTypeFlag() const
Returns the header type flag.
Definition oggpage.h:105
TagParser::OggPage::makeSegmentSizeDenotation
static std::uint32_t makeSegmentSizeDenotation(std::ostream &stream, std::uint32_t size)
Writes the segment size denotation for the specified segment size to the specified stream.
Definition oggpage.cpp:129
TagParser::OggPage::OggPage
OggPage()
Constructs a new Ogg page.
Definition oggpage.h:58
TagParser::OggPage::startOffset
std::uint64_t startOffset() const
Returns the start offset of the page.
Definition oggpage.h:86
TagParser::OggPage::matchesStreamSerialNumber
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
TagParser::OggPage::checksum
std::uint32_t checksum() const
Returns the page checksum.
Definition oggpage.h:200
TagParser::OggPage::computeChecksum
static std::uint32_t computeChecksum(std::istream &stream, std::uint64_t startOffset)
Computes the actual checksum of the page read from the specified stream at the specified startOffset.
Definition oggpage.cpp:79
TagParser::OggPage::streamStructureVersion
std::uint8_t streamStructureVersion() const
Returns the stream structure version.
Definition oggpage.h:94
TagParser::OggPage::isLastPage
bool isLastPage() const
Returns whether this page is the last page of the logical bitstream.
Definition oggpage.h:129
TagParser::OggPage::isContinued
bool isContinued() const
Returns whether this page is a continued packet (true) or a fresh packet (false).
Definition oggpage.h:113
TagParser::OggPage::updateChecksum
static void updateChecksum(std::iostream &stream, std::uint64_t startOffset)
Updates the checksum of the page read from the specified stream at the specified startOffset.
Definition oggpage.cpp:116
TagParser::OggPage::segmentTableSize
std::uint8_t segmentTableSize() const
Returns the size of the segment table.
Definition oggpage.h:210
TagParser::OggPage::absoluteGranulePosition
std::uint64_t absoluteGranulePosition() const
Returns the absolute granule position.
Definition oggpage.h:153
TagParser::OggPage::headerSize
std::uint32_t headerSize() const
Returns the header size in byte.
Definition oggpage.h:230
global.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10