[ogg-dev] page syncing and magic OggS
Ian Malone
ibmalone at gmail.com
Thu Dec 7 12:03:15 PST 2006
Ralph Giles wrote:
> On Thu, Dec 07, 2006 at 03:18:02PM +0000, Ian Malone wrote:
>
>> Pages have to start with 'OggS', but this could also turn
>> up elsewhere in the bitstream, so is there a simple strategy
>> using the libogg API to find out which ones are the start of
>> pages?
>
> Yes, 'OggS' can occur randomly. So to be more sure, you can parse the
> subsequent bytes as a header. Calculate the offset to the start of the
> next ogg page and see if the 'OggS' sequence occurs there as well. You
> can also verify the CRC for the page as an additional check.
>
> ogg_sync_pageseek() does the CRC check, and scans for the next 'OggS' if
> it does not succeed, so by calling it repeatedly you can scan through
> the stream finding pages.
>
> Note that ogg_sync_pageout does this automatically. You can check the
> return code to identify any holes or corrupt pages in the data stream.
>
Thanks (and thanks also to Michael Smith). What I hadn't understood
about ogg_sync_pageseek is that when returning n >= 0 it's acting
like ogg_sync_pageout and n < 0 it's saying it read through -n more
bytes of the sync buffer. The documentation for it makes perfect
sense now.
--
imalone
More information about the ogg-dev
mailing list