aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/OggUtil.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-07 23:12:29 +0100
committerMax Kellermann <max@duempel.org>2013-01-08 01:30:44 +0100
commit97b164d03b3f204f9fb0597d6a09fda712f4bb4e (patch)
tree1f4314c445f92d311a706001e8c5af23acb71c52 /src/decoder/OggUtil.cxx
parent61e7e531c2e05133f3f01aa559e4b6137f47f4a2 (diff)
downloadmpd-97b164d03b3f204f9fb0597d6a09fda712f4bb4e.tar.gz
mpd-97b164d03b3f204f9fb0597d6a09fda712f4bb4e.tar.xz
mpd-97b164d03b3f204f9fb0597d6a09fda712f4bb4e.zip
decoder/OggUtil: add OggExpectPageSeek()
Diffstat (limited to 'src/decoder/OggUtil.cxx')
-rw-r--r--src/decoder/OggUtil.cxx40
1 files changed, 40 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;
+}