[Vorbis] ogg_sync_buffer() memory alignment

Ralph Giles giles at xiph.org
Fri Mar 16 11:12:40 PDT 2007


On Fri, Mar 16, 2007 at 05:22:59PM +0000, Patrick Byrne wrote:

> Unfortunately, the ogg_sync_buffer() call gives me a pointer from its 
> own, internally allocated buffer. I have found no docs to indicate that 
> this would be "page-aligned' (say 4k memory pages).

This is hard to do with the current code. It maintains a working buffer 
and expects you to write into it at the current write pointer. Then
when there's a complete page to return, ogg_sync_pageout() returns
the a pointer to the start of that page inside the working buffer.

Then, the next time you call ogg_sync_buffer(), it moves the unparsed 
data down to the beginning of the work buffer to make space.

So, I suppose you could hack ogg_sync_buffer() to only move far enough 
that the write pointer is aligned the way you want. You'd also have to 
redifine _ogg_malloc() if the Win32 malloc() isn't sufficiently aligned,
so that the first buffer is correct.

You might also look at the libogg2 implementation, which is designed to 
work with discrete buffers allocated by the client. See for example 

 http://svn.xiph.org/trunk/ogg2/ and
 http://svn.xiph.org/trunk/Tremor/ which includes an internal copy.

It's experimental though, so not guaranteed to be safer than the hack.

Hope that helps,
 -r


More information about the Vorbis mailing list