aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/decoder/OggUtil.cxx40
-rw-r--r--src/decoder/OggUtil.hxx16
2 files changed, 56 insertions, 0 deletions
diff --git a/src/decoder/OggUtil.cxx b/src/decoder/OggUtil.cxx
index b821acfc6..a1125a2c6 100644
--- a/src/decoder/OggUtil.cxx
+++ b/src/decoder/OggUtil.cxx
@@ -76,3 +76,43 @@ OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
ogg_stream_pagein(&os, &page);
return true;
}
+
+bool
+OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
+ decoder *decoder, input_stream *input_stream)
+{
+ size_t remaining_skipped = 16384;
+
+ while (true) {
+ int r = ogg_sync_pageseek(&oy, &page);
+ if (r > 0)
+ return true;
+
+ if (r < 0) {
+ /* skipped -r bytes */
+ size_t nbytes = -r;
+ if (nbytes > remaining_skipped)
+ /* still no ogg page - we lost our
+ patience, abort */
+ return false;
+
+ remaining_skipped -= nbytes;
+ continue;
+ }
+
+ if (!OggFeed(oy, decoder, input_stream, 1024))
+ return false;
+ }
+}
+
+bool
+OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os,
+ decoder *decoder, input_stream *is)
+{
+ ogg_page page;
+ if (!OggExpectPageSeek(oy, page, decoder, is))
+ return false;
+
+ ogg_stream_pagein(&os, &page);
+ return true;
+}
diff --git a/src/decoder/OggUtil.hxx b/src/decoder/OggUtil.hxx
index 0ef4a0fa2..324797815 100644
--- a/src/decoder/OggUtil.hxx
+++ b/src/decoder/OggUtil.hxx
@@ -68,4 +68,20 @@ bool
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
decoder *decoder, input_stream *is);
+/**
+ * Like OggExpectPage(), but allow skipping garbage (after seeking).
+ */
+bool
+OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
+ decoder *decoder, input_stream *input_stream);
+
+/**
+ * Combines OggExpectPageSeek() and ogg_stream_pagein().
+ *
+ * @return true if a page was delivered to the stream
+ */
+bool
+OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os,
+ decoder *decoder, input_stream *is);
+
#endif