5#include <c++utilities/io/binaryreader.h>
48 for (m_page = m_segment = m_offset = 0; m_page < m_pages.size() || fetchNextPage(); ++m_page) {
49 const OggPage &page = m_pages[m_page];
50 if (!page.
segmentSizes().empty() && matchesFilter(page)) {
65 while (++m_page < m_pages.size() || fetchNextPage()) {
66 const OggPage &page = m_pages[m_page];
67 if (!page.
segmentSizes().empty() && matchesFilter(page)) {
69 m_segment = m_bytesRead = 0;
83 const OggPage &page = m_pages[m_page];
84 if (matchesFilter(page) && ++m_segment < page.
segmentSizes().size()) {
101 const OggPage &page = m_pages[--m_page];
102 if (matchesFilter(page)) {
115 const OggPage &page = m_pages[m_page];
116 if (m_segment && matchesFilter(page)) {
136 std::size_t bytesRead = 0;
137 while (*
this && count) {
140 if (count <= available) {
141 stream().read(buffer + bytesRead,
static_cast<std::streamsize
>(count));
142 m_bytesRead += count;
145 stream().read(buffer + bytesRead,
static_cast<std::streamsize
>(available));
147 bytesRead += available;
171 auto bytesRead = std::size_t(0);
172 while (*
this && max) {
175 if (max <= available) {
176 stream().read(buffer + bytesRead,
static_cast<std::streamsize
>(max));
178 return bytesRead + max;
180 stream().read(buffer + bytesRead,
static_cast<std::streamsize
>(available));
182 bytesRead += available;
203 if (count <= available) {
204 m_bytesRead += count;
240 if (offset >=
streamSize() || offset < (m_pages.empty() ? m_startOffset : m_pages.back().startOffset() + m_pages.back().totalSize())) {
245 stream().seekg(
static_cast<streamoff
>(offset));
246 std::uint8_t lettersFound = 0;
247 for (std::uint64_t bytesAvailable = max<std::uint64_t>(
streamSize() - offset, 65307ul); bytesAvailable >= 27; --bytesAvailable) {
248 switch (
static_cast<char>(
stream().get())) {
253 lettersFound = lettersFound == 1 || lettersFound == 2 ? lettersFound + 1 : 0;
256 if (lettersFound == 3) {
258 const auto currentOffset =
stream().tellg();
262 bytesAvailable > numeric_limits<std::int32_t>::max() ? numeric_limits<std::int32_t>::max()
263 :
static_cast<std::int32_t
>(bytesAvailable));
267 stream().seekg(currentOffset);
288bool OggIterator::fetchNextPage()
290 if (m_page == m_pages.size()) {
291 m_offset = m_pages.empty() ? m_startOffset : m_pages.back().startOffset() + m_pages.back().totalSize();
292 if (m_offset < m_streamSize) {
293 const std::uint64_t bytesAvailable = m_streamSize - m_offset;
294 m_pages.emplace_back(*m_stream, m_offset,
295 bytesAvailable > numeric_limits<std::int32_t>::max() ? numeric_limits<std::int32_t>::max()
296 :
static_cast<std::int32_t
>(bytesAvailable));
The class inherits from std::exception and serves as base class for exceptions thrown by the elements...
void nextPage()
Increases the current position by one page.
std::uint64_t currentCharacterOffset() const
Returns the offset of the current character in the input stream if the iterator is valid; otherwise a...
void read(char *buffer, std::size_t count)
Reads count bytes from the Ogg stream and writes it to the specified buffer.
std::uint64_t remainingBytesInCurrentSegment() const
Returns the number of bytes left to read in the current segment.
std::uint64_t tellg() const
Same as currentCharacterOffset(); only provided for compliance with std::istream.
std::size_t readAll(char *buffer, std::size_t max)
Reads all bytes from the Ogg stream and writes it to the specified buffer.
void clear(std::istream &stream, std::uint64_t startOffset, std::uint64_t streamSize)
Sets the stream and related parameters and clears all available pages.
void previousPage()
Decreases the current position by one page.
bool resyncAt(std::uint64_t offset)
Fetches the next page at the specified offset.
std::istream & stream()
Returns the stream.
std::uint64_t startOffset() const
Returns the start offset (which has been specified when constructing the iterator).
void setPageIndex(std::vector< OggPage >::size_type index)
Sets the current page index.
std::uint32_t currentSegmentSize() const
Returns the size of the current segment.
void nextSegment()
Increases the current position by one segment.
void reset()
Resets the iterator to point at the first segment of the first page (matching the filter if set).
void ignore(std::size_t count=1)
Advances the position of the next character to be read from the Ogg stream by count bytes.
void previousSegment()
Decreases the current position by one segment.
std::uint64_t streamSize() const
Returns the stream size (which has been specified when constructing the iterator).
The OggPage class is used to parse Ogg pages.
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.
const std::vector< std::uint32_t > & segmentSizes() const
Returns the sizes of the segments of the page in byte.
std::uint64_t startOffset() const
Returns the start offset of the page.
std::uint32_t headerSize() const
Returns the header size in byte.
The exception that is thrown when the data to be parsed is truncated and therefore can not be parsed ...
Contains all classes and functions of the TagInfo library.