decoder/OggUtil: add OggExpectPageSeek()
This commit is contained in:
parent
61e7e531c2
commit
97b164d03b
@ -76,3 +76,43 @@ OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
|
|||||||
ogg_stream_pagein(&os, &page);
|
ogg_stream_pagein(&os, &page);
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
@ -68,4 +68,20 @@ bool
|
|||||||
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
|
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
|
||||||
decoder *decoder, input_stream *is);
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user