/* read a little more data from the file/pipe into the ogg_sync framer
*/
-#define CHUNKSIZE 65536
+#define CHUNKSIZE 65536 /* greater-than-page-size granularity seeking */
+#define READSIZE 2048 /* a smaller read size is needed for low-rate streaming. */
static long _get_data(OggVorbis_File *vf){
errno=0;
if(!(vf->callbacks.read_func))return(-1);
if(vf->datasource){
- char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
- long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
+ char *buffer=ogg_sync_buffer(&vf->oy,READSIZE);
+ long bytes=(vf->callbacks.read_func)(buffer,1,READSIZE,vf->datasource);
if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
if(bytes==0 && errno)return(-1);
return(bytes);
ogg_int64_t prefoffset=-1;
ogg_int64_t offset=-1;
- ogg_int64_t ret_serialno;
- ogg_int64_t ret_gran;
+ ogg_int64_t ret_serialno=-1;
+ ogg_int64_t ret_gran=-1;
while(offset==-1){
begin-=CHUNKSIZE;
bisect=begin +
(ogg_int64_t)((double)(target-begintime)*(end-begin)/(endtime-begintime))
- CHUNKSIZE;
- if(bisect<=begin)
- bisect=begin+1;
+ if(bisect>begin+CHUNKSIZE){
+ result=_seek_helper(vf,bisect);
+ if(result) goto seek_error;
+ }else{
+ bisect=begin;
+ }
}
- result=_seek_helper(vf,bisect);
- if(result) goto seek_error;
-
while(begin<end){
result=_get_next_page(vf,&og,end-vf->offset);
if(result==OV_EREAD) goto seek_error;