Tag Parser  6.5.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 OGGPAGE_H
2 #define OGGPAGE_H
3 
4 #include "../global.h"
5 
6 #include <c++utilities/conversion/types.h>
7 
8 #include <vector>
9 #include <numeric>
10 #include <iosfwd>
11 
12 namespace Media {
13 
15 {
16 public:
17  OggPage();
18  OggPage(std::istream &stream, uint64 startOffset, int32 maxSize);
19 
20  void parseHeader(std::istream &stream, uint64 startOffset, int32 maxSize);
21  static uint32 computeChecksum(std::istream &stream, uint64 startOffset);
22  static void updateChecksum(std::iostream &stream, uint64 startOffset);
23 
24  uint64 startOffset() const;
25  byte streamStructureVersion() const;
26  byte headerTypeFlag() const;
27  bool isContinued() const;
28  bool isFirstpage() const;
29  bool isLastPage() const;
30  uint64 absoluteGranulePosition() const;
31  uint32 streamSerialNumber() const;
32  bool matchesStreamSerialNumber(uint32 streamSerialNumber) const;
33  uint32 sequenceNumber() const;
34  uint32 checksum() const;
35  byte segmentTableSize() const;
36  const std::vector<uint32> &segmentSizes() const;
37  uint32 headerSize() const;
38  uint32 dataSize() const;
39  uint32 totalSize() const;
40  uint64 dataOffset(byte segmentIndex = 0) const;
41  static uint32 makeSegmentSizeDenotation(std::ostream &stream, uint32 size);
42 
43 private:
44  uint64 m_startOffset;
45  byte m_streamStructureVersion;
46  byte m_headerTypeFlag;
47  uint64 m_absoluteGranulePosition;
48  uint32 m_streamSerialNumber;
49  uint32 m_sequenceNumber;
50  uint32 m_checksum;
51  byte m_segmentCount;
52  std::vector<uint32> 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 {}
68 
73 inline OggPage::OggPage(std::istream &stream, uint64 startOffset, int32 maxSize) :
74  OggPage()
75 {
76  parseHeader(stream, startOffset, maxSize);
77 }
78 
84 inline uint64 OggPage::startOffset() const
85 {
86  return m_startOffset;
87 }
88 
93 {
94  return m_streamStructureVersion;
95 }
96 
103 inline byte OggPage::headerTypeFlag() const
104 {
105  return m_headerTypeFlag;
106 }
107 
111 inline bool OggPage::isContinued() const
112 {
113  return m_headerTypeFlag & 0x01;
114 }
115 
119 inline bool OggPage::isFirstpage() const
120 {
121  return m_headerTypeFlag & 0x02;
122 }
123 
127 inline bool OggPage::isLastPage() const
128 {
129  return m_headerTypeFlag & 0x04;
130 }
131 
143 inline uint64 OggPage::absoluteGranulePosition() const
144 {
145  return m_absoluteGranulePosition;
146 }
147 
156 inline uint32 OggPage::streamSerialNumber() const
157 {
158  return m_streamSerialNumber;
159 }
160 
166 {
167  return m_streamSerialNumber == streamSerialNumber;
168 }
169 
175 inline uint32 OggPage::sequenceNumber() const
176 {
177  return m_sequenceNumber;
178 }
179 
190 inline uint32 OggPage::checksum() const
191 {
192  return m_checksum;
193 }
194 
200 inline byte OggPage::segmentTableSize() const
201 {
202  return m_segmentCount;
203 }
204 
210 inline const std::vector<uint32> &OggPage::segmentSizes() const
211 {
212  return m_segmentSizes;
213 }
214 
220 inline uint32 OggPage::headerSize() const
221 {
222  return 27 + m_segmentCount;
223 }
224 
228 inline uint32 OggPage::dataSize() const
229 {
230  return std::accumulate(m_segmentSizes.cbegin(), m_segmentSizes.cend(), 0u);
231 }
232 
236 inline uint32 OggPage::totalSize() const
237 {
238  return headerSize() + dataSize();
239 }
240 
249 inline uint64 OggPage::dataOffset(byte segmentIndex) const
250 {
251  return startOffset() + headerSize() + std::accumulate(m_segmentSizes.cbegin(), m_segmentSizes.cbegin() + segmentIndex, 0);
252 }
253 
254 }
255 
256 #endif // OGGPAGE_H
uint64 dataOffset(byte segmentIndex=0) const
Returns the data offset of the segment with the specified segmentIndex.
Definition: oggpage.h:249
uint32 checksum() const
Returns the page checksum.
Definition: oggpage.h:190
void parseHeader(std::istream &stream, uint64 startOffset, int32 maxSize)
Parses the header read from the specified stream at the specified startOffset.
Definition: oggpage.cpp:25
uint32 headerSize() const
Returns the header size in byte.
Definition: oggpage.h:220
bool matchesStreamSerialNumber(uint32 streamSerialNumber) const
Returns whether the stream serial number of the current instance matches the specified one...
Definition: oggpage.h:165
uint32 sequenceNumber() const
Returns the page sequence number.
Definition: oggpage.h:175
byte segmentTableSize() const
Returns the size of the segment table.
Definition: oggpage.h:200
uint32 streamSerialNumber() const
Returns the stream serial number.
Definition: oggpage.h:156
uint32 totalSize() const
Returns the total size of the page in byte.
Definition: oggpage.h:236
The OggPage class is used to parse OGG pages.
Definition: oggpage.h:14
byte streamStructureVersion() const
Returns the stream structure version.
Definition: oggpage.h:92
uint64 absoluteGranulePosition() const
Returns the absolute granule position.
Definition: oggpage.h:143
OggPage()
Constructs a new OGG page.
Definition: oggpage.h:58
bool isFirstpage() const
Returns whether this page is the first page of the logical bitstream.
Definition: oggpage.h:119
byte headerTypeFlag() const
Returns the header type flag.
Definition: oggpage.h:103
bool isContinued() const
Returns whether this page is a continued packed (true) or a fresh packed (false). ...
Definition: oggpage.h:111
uint64 startOffset() const
Returns the start offset of the page.
Definition: oggpage.h:84
bool isLastPage() const
Returns whether this page is the last page of the logical bitstream.
Definition: oggpage.h:127
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
uint32 dataSize() const
Returns the data size in byte.
Definition: oggpage.h:228
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
const std::vector< uint32 > & segmentSizes() const
Returns the sizes of the segments of the page in byte.
Definition: oggpage.h:210