[vorbis-dev] Am I missing something?

Michael Smith msmith at xn.com.au
Sun Feb 4 15:23:22 PST 2001



> 
> The relevant part of _fetch_headers() is here:
> 
>   i=0;
>   while(i<3){
>     ogg_stream_pagein(&vf->os,og_ptr);
>     while(i<3){
>       int result=ogg_stream_packetout(&vf->os,&op);
>       if(result==0)break;
>       if(result==-1){
>         ret=OV_EBADHEADER;
>         goto bail_header;
>       }
>       if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
>         goto bail_header;
>       }
>       i++;
>     }
>     if(i<3)
>       if(_get_next_page(vf,og_ptr,1)<0){
>         ret=OV_EBADHEADER;
>         goto bail_header;
>       }
>   }
>   return 0;
> 
> Also, notice that ogg_stream_packetout() is called in a loop, but no
> reading can happen during the loop.  And ogg_stream_packetout() never
> returns zero, it returns -1 on error and +1 if everything goes ok.
> Which means either this code is confused, or I am.  Which one is it?
> 

You. Sorry ;-)

That code loops over the entire thing until all the headers have been
found (if this were buggy it would be pretty obvious - the third packet
(codebooks) is frequently over 4k (which is what libogg currently
chooses as the max page size).

In each loop iteration, a page is streamed in (ogg_stream_pagein()).
Then, any number of completed packets are streamed out
(ogg_stream_packetout()) - note that ogg_stream_packetout() will only
return completed packets, thus avoiding the problem you thought was
there.

The ogg_stream_packetout() returns 0 if there is insufficient
information (i.e. there aren't any pending packets), thus breaking from
the inner loop. If it was successful, it submits the header packet for
processing.

It then gets the next page, if it hasn't yet completed getting the
headers, and loops around.

Michael

--- >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