Tag Parser  6.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 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 totalSize() const;
39  uint64 dataOffset(byte segmentIndex = 0) const;
40  static uint32 makeSegmentSizeDenotation(std::ostream &stream, uint32 size);
41 
42 private:
43  uint64 m_startOffset;
44  byte m_streamStructureVersion;
45  byte m_headerTypeFlag;
46  uint64 m_absoluteGranulePosition;
47  uint32 m_streamSerialNumber;
48  uint32 m_sequenceNumber;
49  uint32 m_checksum;
50  byte m_segmentCount;
51  std::vector<uint32> m_segmentSizes;
52 };
53 
57 inline OggPage::OggPage() :
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 
72 inline OggPage::OggPage(std::istream &stream, uint64 startOffset, int32 maxSize) :
73  OggPage()
74 {
75  parseHeader(stream, startOffset, maxSize);
76 }
77 
83 inline uint64 OggPage::startOffset() const
84 {
85  return m_startOffset;
86 }
87 
92 {
93  return m_streamStructureVersion;
94 }
95 
102 inline byte OggPage::headerTypeFlag() const
103 {
104  return m_headerTypeFlag;
105 }
106 
110 inline bool OggPage::isContinued() const
111 {
112  return m_headerTypeFlag & 0x01;
113 }
114 
118 inline bool OggPage::isFirstpage() const
119 {
120  return m_headerTypeFlag & 0x02;
121 }
122 
126 inline bool OggPage::isLastPage() const
127 {
128  return m_headerTypeFlag & 0x04;
129 }
130 
142 inline uint64 OggPage::absoluteGranulePosition() const
143 {
144  return m_absoluteGranulePosition;
145 }
146 
155 inline uint32 OggPage::streamSerialNumber() const
156 {
157  return m_streamSerialNumber;
158 }
159 
165 {
166  return m_streamSerialNumber == streamSerialNumber;
167 }
168 
174 inline uint32 OggPage::sequenceNumber() const
175 {
176  return m_sequenceNumber;
177 }
178 
189 inline uint32 OggPage::checksum() const
190 {
191  return m_checksum;
192 }
193 
199 inline byte OggPage::segmentTableSize() const
200 {
201  return m_segmentCount;
202 }
203 
209 inline const std::vector<uint32> &OggPage::segmentSizes() const
210 {
211  return m_segmentSizes;
212 }
213 
219 inline uint32 OggPage::headerSize() const
220 {
221  return 27 + m_segmentCount;
222 }
223 
227 inline uint32 OggPage::totalSize() const
228 {
229  return headerSize() + std::accumulate(m_segmentSizes.cbegin(), m_segmentSizes.cend(), 0);
230 }
231 
240 inline uint64 OggPage::dataOffset(byte segmentIndex) const
241 {
242  return startOffset() + headerSize() + std::accumulate(m_segmentSizes.cbegin(), m_segmentSizes.cbegin() + segmentIndex, 0);
243 }
244 
245 }
246 
247 #endif // OGGPAGE_H
uint64 dataOffset(byte segmentIndex=0) const
Returns the data offset of the segment with the specified segmentIndex.
Definition: oggpage.h:240
uint32 checksum() const
Returns the page checksum.
Definition: oggpage.h:189
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:219
bool matchesStreamSerialNumber(uint32 streamSerialNumber) const
Returns whether the stream serial number of the current instance matches the specified one...
Definition: oggpage.h:164
uint32 sequenceNumber() const
Returns the page sequence number.
Definition: oggpage.h:174
byte segmentTableSize() const
Returns the size of the segment table.
Definition: oggpage.h:199
uint32 streamSerialNumber() const
Returns the stream serial number.
Definition: oggpage.h:155
uint32 totalSize() const
Returns the total size of the page in byte.
Definition: oggpage.h:227
The OggPage class is used to parse OGG pages.
Definition: oggpage.h:14
byte streamStructureVersion() const
Returns the stream structure version.
Definition: oggpage.h:91
uint64 absoluteGranulePosition() const
Returns the absolute granule position.
Definition: oggpage.h:142
OggPage()
Constructs a new OGG page.
Definition: oggpage.h:57
bool isFirstpage() const
Returns whether this page is the first page of the logical bitstream.
Definition: oggpage.h:118
byte headerTypeFlag() const
Returns the header type flag.
Definition: oggpage.h:102
bool isContinued() const
Returns whether this page is a continued packed (true) or a fresh packed (false). ...
Definition: oggpage.h:110
uint64 startOffset() const
Returns the start offset of the page.
Definition: oggpage.h:83
bool isLastPage() const
Returns whether this page is the last page of the logical bitstream.
Definition: oggpage.h:126
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
#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:209