[Theora] encoding to many clients

Ralph Giles giles at xiph.org
Mon Aug 29 13:47:54 PDT 2005

On Mon, Aug 29, 2005 at 10:37:04PM +0200, Karol Bryd wrote:

> I see, is stream splitting  a complicated operation? I would like to do it
> myself so the application would not be dependant on other software.

Not really. The basic idea is you just buffer a bit of the stream,
and send that buffer to each client in turn. Then repeat.

In practice people usually use a chain of buffers, send in whatever 
order sockets are able to accept data, and free/recycle a given buffer 
once it's been sent to all connected clients. You'll also want to keep
track and close connections that have too many pending buffers to bound 
resource use.

The trick with Theora (and Vorbis audio) is that the decoder
requires a couple of header packets from the start of the Ogg
stream to configure itself and properly decode the following
data packets. This means you need to cache these header packets
(as Ogg pages) and send them to new clients on connect before
sending any of the currently in-processes data. If the clients
all connect at the same time and receive the entire Ogg stream
in order, it's not an issue.


More information about the Theora mailing list