diff options
author | Max Kellermann <max@duempel.org> | 2013-01-07 23:12:29 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-08 01:30:44 +0100 |
commit | 97b164d03b3f204f9fb0597d6a09fda712f4bb4e (patch) | |
tree | 1f4314c445f92d311a706001e8c5af23acb71c52 | |
parent | 61e7e531c2e05133f3f01aa559e4b6137f47f4a2 (diff) | |
download | mpd-97b164d03b3f204f9fb0597d6a09fda712f4bb4e.tar.gz mpd-97b164d03b3f204f9fb0597d6a09fda712f4bb4e.tar.xz mpd-97b164d03b3f204f9fb0597d6a09fda712f4bb4e.zip |
decoder/OggUtil: add OggExpectPageSeek()
Diffstat (limited to '')
-rw-r--r-- | src/decoder/OggUtil.cxx | 40 | ||||
-rw-r--r-- | src/decoder/OggUtil.hxx | 16 |
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 |