Commit 9f9918d2 authored by Monty's avatar Monty
Browse files

Numerous fixes to seeking methods in vorbisfile.c

svn path=/trunk/vorbis/; revision=164
parent f945d854
......@@ -52,7 +52,7 @@ int main(){
printf("\t\tcompressed length: %ld bytes ",ov_raw_total(&ov,i));
printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
}
ov_clear(&ov);
return 0;
}
......
......@@ -357,7 +357,7 @@ extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
extern int ogg_stream_init(ogg_stream_state *os,int serialno);
extern int ogg_stream_clear(ogg_stream_state *os);
extern int ogg_stream_reset(ogg_stream_state *os);
extern int ogg_stream_reset(ogg_stream_state *os,long expected_pageno);
extern int ogg_stream_destroy(ogg_stream_state *os);
extern int ogg_stream_eof(ogg_stream_state *os);
......
......@@ -268,7 +268,7 @@ int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
for(vals=0;vals<maxvals;vals++){
if(acc>4096)break;
acc+=os->lacing_vals[vals]&0x0ff;
if((os->lacing_vals[vals]&0x0ff)<255)pcm_pos=os->pcm_vals[vals];
pcm_pos=os->pcm_vals[vals];
}
}
......@@ -685,7 +685,7 @@ int ogg_sync_reset(ogg_sync_state *oy){
return(0);
}
int ogg_stream_reset(ogg_stream_state *os){
int ogg_stream_reset(ogg_stream_state *os,long expected_pageno){
os->body_fill=0;
os->body_returned=0;
......@@ -697,7 +697,7 @@ int ogg_stream_reset(ogg_stream_state *os){
os->e_o_s=0;
os->b_o_s=0;
os->pageno=0;
os->pageno=expected_pageno;
os->packetno=0;
os->pcmpos=0;
......@@ -874,8 +874,8 @@ void test_pack(int *pl, int **headers){
int eosflag=0;
int bosflag=0;
ogg_stream_reset(&os_en);
ogg_stream_reset(&os_de);
ogg_stream_reset(&os_en,0);
ogg_stream_reset(&os_de,0);
ogg_sync_reset(&oy);
for(packets=0;;packets++)if(pl[packets]==-1)break;
......@@ -1302,7 +1302,7 @@ int main(void){
int inptr=0,i,j;
ogg_page og[5];
ogg_stream_reset(&os_en);
ogg_stream_reset(&os_en,0);
for(i=0;pl[i]!=-1;i++){
ogg_packet op;
......@@ -1336,7 +1336,7 @@ int main(void){
fprintf(stderr,"Testing loss of pages... ");
ogg_sync_reset(&oy);
ogg_stream_reset(&os_de);
ogg_stream_reset(&os_de,0);
for(i=0;i<5;i++){
memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
og[i].header_len);
......@@ -1381,7 +1381,7 @@ int main(void){
fprintf(stderr,"Testing loss of pages (rollback required)... ");
ogg_sync_reset(&oy);
ogg_stream_reset(&os_de);
ogg_stream_reset(&os_de,0);
for(i=0;i<5;i++){
memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
og[i].header_len);
......
......@@ -473,6 +473,7 @@ static int _process_packet(OggVorbis_File *vf,int readp){
/* reload */
ogg_stream_init(&vf->os,vf->current_serialno);
ogg_stream_reset(&vf->os,ogg_page_pageno(&og));
vorbis_synthesis_init(&vf->vd,vf->vi+link);
vorbis_block_init(&vf->vd,&vf->vb);
vf->decode_ready=1;
......@@ -744,7 +745,7 @@ int ov_pcm_seek(OggVorbis_File *vf,size64 pos){
if(pos>=total)break;
}
/* seach within the logical bitstream for the page with the highest
/* search within the logical bitstream for the page with the highest
pcm_pos preceeding (or equal to) pos. There is a danger here;
missing pages or incorrect frame number information in the
bitstream could make our task impossible. Account for that (it
......@@ -758,7 +759,7 @@ int ov_pcm_seek(OggVorbis_File *vf,size64 pos){
ogg_page og;
while(begin<end){
long bisect;
long ret,acc;
long ret;
if(end-begin<CHUNKSIZE){
bisect=begin;
......@@ -767,25 +768,18 @@ int ov_pcm_seek(OggVorbis_File *vf,size64 pos){
}
_seek_helper(vf,bisect);
acc=0;
while(1){
ret=_get_next_page(vf,&og,-1);
if(ret==-1){
end=bisect;
ret=_get_next_page(vf,&og,-1);
if(ret==-1){
end=bisect;
}else{
size64 frameno=ogg_page_frameno(&og);
if(ogg_page_serialno(&og)==vf->serialnos[link] && frameno<target){
best=ret; /* raw offset of packet with frameno */
begin=vf->offset; /* raw offset of next packet */
}else{
size64 frameno=ogg_page_frameno(&og);
acc+=ret;
if(frameno==-1)continue;
if(frameno<target){
best=bisect+acc; /* raw offset of packet with frameno */
begin=vf->offset; /* raw offset of next packet */
}else{
end=bisect;
}
end=bisect;
}
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment