[vorbis-dev] some (basic?) development questions...

Monty xiphmont at xiph.org
Tue May 16 03:52:28 PDT 2000



> Here's a basic overview of what I'm doing; could someone tell me if I've
> got the right basic idea?

Sure.  BTW, have you read the Ogg bitstream/framing spec on the website?  This 
details all the implications of modifying packets/pages. (I assume that if 
you've gotten this far without asking for help the answer is yes, but it's 
worth checking).

> Basically because the all the packets are variable-width, I (AFAIK) need
> to read out all the packets one at a time, replacing the second (comment
> header) packet with the new comments.

Correct. You will also need to rebuild the comment page at a minimum.

> All the other packets can stay
> exactly the same.  

Also correct.

> I read the packets out of one ogg stream, and feed them
> into a second ogg stream, grabbing pages from the second stream as I get
> them and writing them to disk.  Then I move the new file into place where
> the old file was.

I assume you're doing this using the ogg_stream_xxxx and ogg_sync_xxxx 
functions, correct?

> It's a little ugly, but I can't think of any other way to do it.

No, this seems like the proper way to do it to me.

> If I knew the second or third header was going to fall on a page boundary,
> I could figure out how long the header pages were in the first file, then
> figure out how long the header pages were in the new stream, then expand
> or contract the original file to match and overwrite the header pages.  

The second packet is guaranteed to be the first packet content on the second 
page, but it is not necessarily constrained to the second page, or the only 
packet on the second page.

One thing I need to add to the libvorbis API is an ogg_stream_flush() so that 
one can flush a complete page comprised of however many packets one has 
submitted up to that point, rather than when libvorbis feels like flushing.  
That way you still don't know exactly how much you need to read, but when you 
*do* have all the pages needed to extract the second (comment) packet, you 
only need to split open those pages, not the pages for the entire stream.

> That would probably be a classier way of doing it, but since I am probably
> screwing with the page boundaries by changing the comment header, that
> won't work, and my two file approach is apparently the only way to do it.

Once you have the flush command, you'd be able to do this because you could 
just build new pages with the modified header packet (with one restriction 
actually; the pages have sequence numbers, so you'd need to end up with the 
same number of pages after editing if you don't want to peel/rewrap each page 
after editing.  The max page size is just under 64k, and libvorbis normally 
outputs pages at 4k, so you've got lots of room to work before needing to 
start re-wrapping pages)
 
> Can anyone tell me if the above assumptions are correct?  If they are I
> can show you a few lines of pseudocode and hopefully you could tell me
> what I'm doing wrong...

Your assumptions as stated are all correct.  Can you provide more detail of the
trouble you're having?

Monty

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/



More information about the Vorbis-dev mailing list