[vorbis-dev] decoder_example -- event driven?

Michael Smith msmith at labyrinth.net.au
Fri Apr 6 07:22:33 PDT 2001

At 01:58 AM 4/6/01 -0400, you wrote:
>I'm trying to adapt decoder_example to to support more of an event driven
>model.  I'm building an RTSP client/server where the client will have a
>function called everytime a new packet comes in.  So, I want to queue
>up these packets to be played.

Note that there is an RTP spec (draft) for vorbis. This is completely
different from that, and will have other problems (headers, for example).

>My current attack is as follows (note this isn't very robust and I
>realized that):
>For first and second packet i grab all the header stuff in the same way
>as decoder_example.  From the third packet on, I send it to a bunch of

There are 3 packets for headers, but from your description you are in fact
getting all three. 

The following code is completely wrong if you're executing it for each
incoming packet. If you already have a packet at this point, you shouldn't
be calling any of the ogg_* functions. Presumably, you just have a data

>      float **pcm;
>      int samples;
>      buffer=ogg_sync_buffer(&oy,4096);
>      bytes = 4096;
>      buffer = memcpy (buffer, data, bytes);
        ^^^^^^ not actually wrong, merely strange. Also, are you sure you 
                always have 4096 bytes in your buffer?

>      ogg_sync_wrote(&oy,bytes);
>      ogg_sync_pageout(&oy,&og);
        You MUST check that this succeeds (it WON'T always. This would be my 
       first guess as to what's causing your problem.

>      ogg_stream_pagein(&os,&og); /* can safely ignore errors at
>				     this point */
>      /* we have a packet.  Decode it */
       No, you don't yet have a packet. This is my second guess as to 
       what's causing a problem. You need to use ogg_stream_packetout() to
       get a packet first. 

The rest doesn't have any really obvious mistakes. You WILL NEED more
return value checking (decoder_example has this). You should also check for
error returns, which decoder_example mostly doesn't.


--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.

More information about the Vorbis-dev mailing list