OggSpeexWriter and packets > 255 bytes

Mar 7, 2012 at 12:57 AM

Though in practice, packets greater than 255 bytes are sort of silly, using larger packets will break your OggSpeexWriter implementation. The packet size is passed into WritePacket(...) as an int, and that many bytes are written to the dataBuffer, but you record the packet length in the headerBuffer array as a byte. So, the length of the stream will be out of sync with the segment table if the packet sizes are sent to the encoder.

Although an ogg segment is limited to 255 bytes, ogg does support packets larger than 255 by overflowing into the next segment--if a segment is 255 bytes, it is implied that the next segment is a continuation (packets of exactly 255 bytes take up 2 segments, with the 2nd one being 0 bytes long), and if a packet runs through the end of the page, the next page's header type will indicate that it is a continuation.

All that said, since it's silly to have such long packets, you could just throw an exception for large packet sizes. 

Aside from that, it looks good. Thanks for all your work!