• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/minidlna/libvorbis-1.2.3/lib/

Lines Matching defs:vf

66 static long _get_data(OggVorbis_File *vf){
68 if(!(vf->callbacks.read_func))return(-1);
69 if(vf->datasource){
70 char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
71 long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
72 if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
80 static int _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
81 if(vf->datasource){
82 if(!(vf->callbacks.seek_func)||
83 (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1)
85 vf->offset=offset;
86 ogg_sync_reset(&vf->oy);
107 static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
109 if(boundary>0)boundary+=vf->offset;
113 if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
114 more=ogg_sync_pageseek(&vf->oy,og);
118 vf->offset-=more;
124 long ret=_get_data(vf);
131 ogg_int64_t ret=vf->offset;
132 vf->offset+=more;
145 static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
146 ogg_int64_t begin=vf->offset;
156 ret=_seek_helper(vf,begin);
159 while(vf->offset<end){
161 ret=_get_next_page(vf,og,end-vf->offset);
175 ret=_seek_helper(vf,offset);
178 ret=_get_next_page(vf,og,CHUNKSIZE);
222 static ogg_int64_t _get_prev_page_serial(OggVorbis_File *vf,
226 ogg_int64_t begin=vf->offset;
240 ret=_seek_helper(vf,begin);
243 while(vf->offset<end){
244 ret=_get_next_page(vf,&og,end-vf->offset);
278 /* uses the local ogg_stream storage in vf; this is important for
280 static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
289 ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
297 vf->ready_state=OPENED;
316 if(vf->ready_state<STREAMSET){
319 ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
320 ogg_stream_pagein(&vf->os,og_ptr);
322 if(ogg_stream_packetout(&vf->os,&op) > 0 &&
325 vf->ready_state=STREAMSET;
335 ogg_int64_t llret=_get_next_page(vf,og_ptr,CHUNKSIZE);
346 if(vf->ready_state==STREAMSET &&
347 vf->os.serialno == ogg_page_serialno(og_ptr)){
348 ogg_stream_pagein(&vf->os,og_ptr);
354 if(vf->ready_state!=STREAMSET){
366 int result=ogg_stream_packetout(&vf->os,&op);
380 if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
386 if(vf->os.serialno == ogg_page_serialno(og_ptr)){
387 ogg_stream_pagein(&vf->os,og_ptr);
411 vf->ready_state=OPENED;
420 static ogg_int64_t _initial_pcmoffset(OggVorbis_File *vf, vorbis_info *vi){
425 int serialno = vf->os.serialno;
429 if(_get_next_page(vf,&og,-1)<0)
436 ogg_stream_pagein(&vf->os,&og);
437 while((result=ogg_stream_packetout(&vf->os,&op))){
464 static int _bisect_forward_serialno(OggVorbis_File *vf,
480 int serialno = vf->os.serialno;
498 vf->offset=_get_prev_page_serial(vf,currentno_list,currentnos,&endserial,&endgran);
501 vf->links=m+1;
502 if(vf->offsets)_ogg_free(vf->offsets);
503 if(vf->serialnos)_ogg_free(vf->serialnos);
504 if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
506 vf->offsets=_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
507 vf->vi=_ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
508 vf->vc=_ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
509 vf->serialnos=_ogg_malloc(vf->links*sizeof(*vf->serialnos));
510 vf->dataoffsets=_ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
511 vf->pcmlengths=_ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
513 vf->offsets[m+1]=end;
514 vf->offsets[m]=begin;
515 vf->pcmlengths[m*2+1]=endgran;
535 ret=_seek_helper(vf,bisect);
538 last=_get_next_page(vf,&og,-1);
553 vf->offset = next;
556 vf->offset=_get_prev_page_serial(vf,currentno_list,currentnos,&testserial,&searchgran);
560 if(vf->offset!=next){
561 ret=_seek_helper(vf,next);
565 ret=_fetch_headers(vf,&vi,&vc,&next_serialno_list,&next_serialnos,NULL);
567 serialno = vf->os.serialno;
568 dataoffset = vf->offset;
572 pcmoffset = _initial_pcmoffset(vf,&vi);
574 ret=_bisect_forward_serialno(vf,next,vf->offset,end,endgran,endserial,
580 vf->offsets[m+1]=next;
581 vf->serialnos[m+1]=serialno;
582 vf->dataoffsets[m+1]=dataoffset;
584 vf->vi[m+1]=vi;
585 vf->vc[m+1]=vc;
587 vf->pcmlengths[m*2+1]=searchgran;
588 vf->pcmlengths[m*2+2]=pcmoffset;
589 vf->pcmlengths[m*2+3]-=pcmoffset;
595 static int _make_decode_ready(OggVorbis_File *vf){
596 if(vf->ready_state>STREAMSET)return 0;
597 if(vf->ready_state<STREAMSET)return OV_EFAULT;
598 if(vf->seekable){
599 if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
602 if(vorbis_synthesis_init(&vf->vd,vf->vi))
605 vorbis_block_init(&vf->vd,&vf->vb);
606 vf->ready_state=INITSET;
607 vf->bittrack=0.f;
608 vf->samptrack=0.f;
612 static int _open_seekable2(OggVorbis_File *vf){
613 ogg_int64_t dataoffset=vf->dataoffsets[0],end,endgran=-1;
614 int endserial=vf->os.serialno;
615 int serialno=vf->os.serialno;
618 storage in vf */
621 ogg_int64_t pcmoffset = _initial_pcmoffset(vf,vf->vi);
624 if(vf->callbacks.seek_func && vf->callbacks.tell_func){
625 (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
626 vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
628 vf->offset=vf->end=-1;
632 if(vf->end==-1) return(OV_EINVAL);
637 end=_get_prev_page_serial(vf,vf->serialnos+2,vf->serialnos[1],&endserial,&endgran);
641 if(_bisect_forward_serialno(vf,0,dataoffset,vf->offset,endgran,endserial,
642 vf->serialnos+2,vf->serialnos[1],0)<0)return(OV_EREAD);
644 vf->offsets[0]=0;
645 vf->serialnos[0]=serialno;
646 vf->dataoffsets[0]=dataoffset;
647 vf->pcmlengths[0]=pcmoffset;
648 vf->pcmlengths[1]-=pcmoffset;
650 return(ov_raw_seek(vf,dataoffset));
654 static void _decode_clear(OggVorbis_File *vf){
655 vorbis_dsp_clear(&vf->vd);
656 vorbis_block_clear(&vf->vb);
657 vf->ready_state=OPENED;
671 static int _fetch_and_process_packet(OggVorbis_File *vf,
681 if(vf->ready_state==STREAMSET){
682 int ret=_make_decode_ready(vf);
688 if(vf->ready_state==INITSET){
692 int result=ogg_stream_packetout(&vf->os,op_ptr);
700 if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
710 int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
715 vorbis_synthesis_blockin(&vf->vd,&vf->vb);
716 vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
717 vf->bittrack+=op_ptr->bytes*8;
722 int link=(vf->seekable?vf->current_link:0);
738 if(vf->seekable && link>0)
739 granulepos-=vf->pcmlengths[link*2];
745 samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
749 granulepos+=vf->pcmlengths[i*2+1];
750 vf->pcm_offset=granulepos;
760 if(vf->ready_state>=OPENED){
771 if((ret=_get_next_page(vf,&og,-1))<0){
777 vf->bittrack+=og.header_len*8;
779 if(vf->ready_state==INITSET){
780 if(vf->current_serialno!=ogg_page_serialno(&og)){
791 _decode_clear(vf);
793 if(!vf->seekable){
794 vorbis_info_clear(vf->vi);
795 vorbis_comment_clear(vf->vc);
820 if(vf->ready_state!=INITSET){
823 if(vf->ready_state<STREAMSET){
824 if(vf->seekable){
831 for(link=0;link<vf->links;link++)
832 if(vf->serialnos[link]==serialno)break;
834 if(link==vf->links) continue; /* not the desired Vorbis
838 vf->current_serialno=serialno;
839 vf->current_link=link;
841 ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
842 vf->ready_state=STREAMSET;
848 int ret=_fetch_headers(vf,vf->vi,vf->vc,NULL,NULL,&og);
850 vf->current_serialno=vf->os.serialno;
851 vf->current_link++;
859 ogg_stream_pagein(&vf->os,&og);
871 static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
878 memset(vf,0,sizeof(*vf));
879 vf->datasource=f;
880 vf->callbacks = callbacks;
883 ogg_sync_init(&vf->oy);
890 char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
892 ogg_sync_wrote(&vf->oy,ibytes);
896 if(offsettest!=-1)vf->seekable=1;
900 vf->links=1;
901 vf->vi=_ogg_calloc(vf->links,sizeof(*vf->vi));
902 vf->vc=_ogg_calloc(vf->links,sizeof(*vf->vc));
903 ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
907 if((ret=_fetch_headers(vf,vf->vi,vf->vc,&serialno_list,&serialno_list_size,NULL))<0){
908 vf->datasource=NULL;
909 ov_clear(vf);
914 vf->serialnos=_ogg_calloc(serialno_list_size+2,sizeof(*vf->serialnos));
915 vf->serialnos[0]=vf->current_serialno;
916 vf->serialnos[1]=serialno_list_size;
917 memcpy(vf->serialnos+2,serialno_list,serialno_list_size*sizeof(*vf->serialnos));
919 vf->offsets=_ogg_calloc(1,sizeof(*vf->offsets));
920 vf->dataoffsets=_ogg_calloc(1,sizeof(*vf->dataoffsets));
921 vf->offsets[0]=0;
922 vf->dataoffsets[0]=vf->offset;
923 vf->current_serialno=vf->os.serialno;
925 vf->ready_state=PARTOPEN;
931 static int _ov_open2(OggVorbis_File *vf){
932 if(vf->ready_state != PARTOPEN) return OV_EINVAL;
933 vf->ready_state=OPENED;
934 if(vf->seekable){
935 int ret=_open_seekable2(vf);
937 vf->datasource=NULL;
938 ov_clear(vf);
942 vf->ready_state=STREAMSET;
949 int ov_clear(OggVorbis_File *vf){
950 if(vf){
951 vorbis_block_clear(&vf->vb);
952 vorbis_dsp_clear(&vf->vd);
953 ogg_stream_clear(&vf->os);
955 if(vf->vi && vf->links){
957 for(i=0;i<vf->links;i++){
958 vorbis_info_clear(vf->vi+i);
959 vorbis_comment_clear(vf->vc+i);
961 _ogg_free(vf->vi);
962 _ogg_free(vf->vc);
964 if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
965 if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
966 if(vf->serialnos)_ogg_free(vf->serialnos);
967 if(vf->offsets)_ogg_free(vf->offsets);
968 ogg_sync_clear(&vf->oy);
969 if(vf->datasource && vf->callbacks.close_func)
970 (vf->callbacks.close_func)(vf->datasource);
971 memset(vf,0,sizeof(*vf));
987 int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
989 int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
991 return _ov_open2(vf);
994 int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
1002 return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
1005 int ov_fopen(char *path,OggVorbis_File *vf){
1010 ret = ov_open(f,vf,NULL,0);
1019 int ov_halfrate(OggVorbis_File *vf,int flag){
1021 if(vf->vi==NULL)return OV_EINVAL;
1022 if(!vf->seekable)return OV_EINVAL;
1023 if(vf->ready_state>=STREAMSET)
1024 _decode_clear(vf); /* clear out stream state; later on libvorbis
1030 for(i=0;i<vf->links;i++){
1031 if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
1032 ov_halfrate(vf,0);
1039 int ov_halfrate_p(OggVorbis_File *vf){
1040 if(vf->vi==NULL)return OV_EINVAL;
1041 return vorbis_synthesis_halfrate_p(vf->vi);
1049 int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
1052 return _ov_open1(f,vf,initial,ibytes,callbacks);
1055 int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
1063 return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
1066 int ov_test_open(OggVorbis_File *vf){
1067 if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
1068 return _ov_open2(vf);
1072 long ov_streams(OggVorbis_File *vf){
1073 return vf->links;
1076 /* Is the FILE * associated with vf seekable? */
1077 long ov_seekable(OggVorbis_File *vf){
1078 return vf->seekable;
1090 long ov_bitrate(OggVorbis_File *vf,int i){
1091 if(vf->ready_state<OPENED)return(OV_EINVAL);
1092 if(i>=vf->links)return(OV_EINVAL);
1093 if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
1098 for(i=0;i<vf->links;i++)
1099 bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
1100 /* This once read: return(rint(bits/ov_time_total(vf,-1)));
1104 br = bits/ov_time_total(vf,-1);
1107 if(vf->seekable){
1109 return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
1112 if(vf->vi[i].bitrate_nominal>0){
1113 return vf->vi[i].bitrate_nominal;
1115 if(vf->vi[i].bitrate_upper>0){
1116 if(vf->vi[i].bitrate_lower>0){
1117 return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
1119 return vf->vi[i].bitrate_upper;
1132 long ov_bitrate_instant(OggVorbis_File *vf){
1133 int link=(vf->seekable?vf->current_link:0);
1135 if(vf->ready_state<OPENED)return(OV_EINVAL);
1136 if(vf->samptrack==0)return(OV_FALSE);
1137 ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
1138 vf->bittrack=0.f;
1139 vf->samptrack=0.f;
1144 long ov_serialnumber(OggVorbis_File *vf,int i){
1145 if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
1146 if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
1148 return(vf->current_serialno);
1150 return(vf->serialnos[i]);
1159 ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
1160 if(vf->ready_state<OPENED)return(OV_EINVAL);
1161 if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
1165 for(i=0;i<vf->links;i++)
1166 acc+=ov_raw_total(vf,i);
1169 return(vf->offsets[i+1]-vf->offsets[i]);
1178 ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
1179 if(vf->ready_state<OPENED)return(OV_EINVAL);
1180 if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
1184 for(i=0;i<vf->links;i++)
1185 acc+=ov_pcm_total(vf,i);
1188 return(vf->pcmlengths[i*2+1]);
1197 double ov_time_total(OggVorbis_File *vf,int i){
1198 if(vf->ready_state<OPENED)return(OV_EINVAL);
1199 if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
1203 for(i=0;i<vf->links;i++)
1204 acc+=ov_time_total(vf,i);
1207 return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
1218 int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
1222 if(vf->ready_state<OPENED)return(OV_EINVAL);
1223 if(!vf->seekable)
1226 if(pos<0 || pos>vf->end)return(OV_EINVAL);
1232 vf->pcm_offset=-1;
1233 ogg_stream_reset_serialno(&vf->os,
1234 vf->current_serialno); /* must set serialno */
1235 vorbis_synthesis_restart(&vf->vd);
1237 ret=_seek_helper(vf,pos);
1246 the shared vf->os stream state. We use the local state to
1265 ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
1271 if(vf->ready_state>=STREAMSET){
1277 if(vf->vi[vf->current_link].codec_setup){
1278 thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
1280 ogg_stream_packetout(&vf->os,NULL);
1292 ogg_stream_packetout(&vf->os,NULL);
1298 int i,link=vf->current_link;
1299 ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
1303 granulepos+=vf->pcmlengths[i*2+1];
1304 vf->pcm_offset=granulepos-accblock;
1305 if(vf->pcm_offset<0)vf->pcm_offset=0;
1311 ogg_stream_packetout(&vf->os,NULL);
1316 pagepos=_get_next_page(vf,&og,-1);
1318 vf->pcm_offset=ov_pcm_total(vf,-1);
1323 vf->pcm_offset=-1;
1328 if(vf->ready_state>=STREAMSET){
1329 if(vf->current_serialno!=ogg_page_serialno(&og)){
1337 _decode_clear(vf); /* clear out stream state */
1343 if(vf->ready_state<STREAMSET){
1347 for(link=0;link<vf->links;link++)
1348 if(vf->serialnos[link]==serialno)break;
1350 if(link==vf->links) continue; /* not the desired Vorbis
1353 vf->current_link=link;
1354 vf->current_serialno=serialno;
1355 ogg_stream_reset_serialno(&vf->os,serialno);
1357 vf->ready_state=STREAMSET;
1358 firstflag=(pagepos<=vf->dataoffsets[link]);
1361 ogg_stream_pagein(&vf->os,&og);
1369 vf->bittrack=0.f;
1370 vf->samptrack=0.f;
1375 vf->pcm_offset=-1;
1377 _decode_clear(vf);
1387 int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
1390 ogg_int64_t total=ov_pcm_total(vf,-1);
1392 if(vf->ready_state<OPENED)return(OV_EINVAL);
1393 if(!vf->seekable)return(OV_ENOSEEK);
1398 for(link=vf->links-1;link>=0;link--){
1399 total-=vf->pcmlengths[link*2+1];
1411 ogg_int64_t end=vf->offsets[link+1];
1412 ogg_int64_t begin=vf->offsets[link];
1413 ogg_int64_t begintime = vf->pcmlengths[link*2];
1414 ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
1433 result=_seek_helper(vf,bisect);
1437 result=_get_next_page(vf,&og,end-vf->offset);
1446 result=_seek_helper(vf,bisect);
1452 if(ogg_page_serialno(&og)!=vf->serialnos[link])
1460 begin=vf->offset; /* raw offset of next page */
1469 if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
1473 result=_seek_helper(vf,bisect);
1493 result=_seek_helper(vf,best);
1494 vf->pcm_offset=-1;
1496 result=_get_next_page(vf,&og,-1);
1499 if(link!=vf->current_link){
1501 _decode_clear(vf);
1503 vf->current_link=link;
1504 vf->current_serialno=vf->serialnos[link];
1505 vf->ready_state=STREAMSET;
1508 vorbis_synthesis_restart(&vf->vd);
1511 ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
1512 ogg_stream_pagein(&vf->os,&og);
1516 result=ogg_stream_packetpeek(&vf->os,&op);
1523 result=_seek_helper(vf,best);
1527 result=_get_prev_page(vf,&og);
1529 if(ogg_page_serialno(&og)==vf->current_serialno &&
1532 return ov_raw_seek(vf,result);
1534 vf->offset=result;
1542 vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
1543 if(vf->pcm_offset<0)vf->pcm_offset=0;
1544 vf->pcm_offset+=total;
1547 result=ogg_stream_packetout(&vf->os,NULL);
1553 if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
1557 vf->bittrack=0.f;
1558 vf->samptrack=0.f;
1563 vf->pcm_offset=-1;
1564 _decode_clear(vf);
1571 int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
1573 int ret=ov_pcm_seek_page(vf,pos);
1575 if((ret=_make_decode_ready(vf)))return ret;
1584 int ret=ogg_stream_packetpeek(&vf->os,&op);
1586 thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
1588 ogg_stream_packetout(&vf->os,NULL);
1591 if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
1593 if(vf->pcm_offset+((thisblock+
1594 vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
1597 ogg_stream_packetout(&vf->os,NULL);
1598 vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
1601 vorbis_synthesis_blockin(&vf->vd,&vf->vb);
1609 vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
1610 if(vf->pcm_offset<0)vf->pcm_offset=0;
1611 for(i=0;i<vf->current_link;i++)
1612 vf->pcm_offset+=vf->pcmlengths[i*2+1];
1621 if(_get_next_page(vf,&og,-1)<0)break;
1622 if(ogg_page_bos(&og))_decode_clear(vf);
1624 if(vf->ready_state<STREAMSET){
1628 for(link=0;link<vf->links;link++)
1629 if(vf->serialnos[link]==serialno)break;
1630 if(link==vf->links) continue;
1631 vf->current_link=link;
1633 vf->ready_state=STREAMSET;
1634 vf->current_serialno=ogg_page_serialno(&og);
1635 ogg_stream_reset_serialno(&vf->os,serialno);
1636 ret=_make_decode_ready(vf);
1641 ogg_stream_pagein(&vf->os,&og);
1645 vf->bittrack=0.f;
1646 vf->samptrack=0.f;
1649 while(vf->pcm_offset<pos){
1650 ogg_int64_t target=pos-vf->pcm_offset;
1651 long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
1654 vorbis_synthesis_read(&vf->vd,samples);
1655 vf->pcm_offset+=samples;
1658 if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
1659 vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
1666 int ov_time_seek(OggVorbis_File *vf,double seconds){
1673 if(vf->ready_state<OPENED)return(OV_EINVAL);
1674 if(!vf->seekable)return(OV_ENOSEEK);
1678 for(link=0;link<vf->links;link++){
1679 double addsec = ov_time_total(vf,link);
1682 pcm_total+=vf->pcmlengths[link*2+1];
1685 if(link==vf->links)return(OV_EINVAL);
1689 ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
1690 return(ov_pcm_seek(vf,target));
1696 int ov_time_seek_page(OggVorbis_File *vf,double seconds){
1703 if(vf->ready_state<OPENED)return(OV_EINVAL);
1704 if(!vf->seekable)return(OV_ENOSEEK);
1708 for(link=0;link<vf->links;link++){
1709 double addsec = ov_time_total(vf,link);
1712 pcm_total+=vf->pcmlengths[link*2+1];
1715 if(link==vf->links)return(OV_EINVAL);
1719 ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
1720 return(ov_pcm_seek_page(vf,target));
1726 ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
1727 if(vf->ready_state<OPENED)return(OV_EINVAL);
1728 return(vf->offset);
1732 ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
1733 if(vf->ready_state<OPENED)return(OV_EINVAL);
1734 return(vf->pcm_offset);
1738 double ov_time_tell(OggVorbis_File *vf){
1743 if(vf->ready_state<OPENED)return(OV_EINVAL);
1744 if(vf->seekable){
1745 pcm_total=ov_pcm_total(vf,-1);
1746 time_total=ov_time_total(vf,-1);
1749 for(link=vf->links-1;link>=0;link--){
1750 pcm_total-=vf->pcmlengths[link*2+1];
1751 time_total-=ov_time_total(vf,link);
1752 if(vf->pcm_offset>=pcm_total)break;
1756 return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
1767 vorbis_info *ov_info(OggVorbis_File *vf,int link){
1768 if(vf->seekable){
1770 if(vf->ready_state>=STREAMSET)
1771 return vf->vi+vf->current_link;
1773 return vf->vi;
1775 if(link>=vf->links)
1778 return vf->vi+link;
1780 return vf->vi;
1785 vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
1786 if(vf->seekable){
1788 if(vf->ready_state>=STREAMSET)
1789 return vf->vc+vf->current_link;
1791 return vf->vc;
1793 if(link>=vf->links)
1796 return vf->vc+link;
1798 return vf->vc;
1845 long ov_read_filter(OggVorbis_File *vf,char *buffer,int length,
1854 if(vf->ready_state<OPENED)return(OV_EINVAL);
1857 if(vf->ready_state==INITSET){
1858 samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
1864 int ret=_fetch_and_process_packet(vf,NULL,1,1);
1877 long channels=ov_info(vf,-1)->channels;
1972 vorbis_synthesis_read(&vf->vd,samples);
1973 vf->pcm_offset+=samples;
1974 if(bitstream)*bitstream=vf->current_link;
1981 long ov_read(OggVorbis_File *vf,char *buffer,int length,
1983 return ov_read_filter(vf, buffer, length, bigendianp, word, sgned, bitstream, NULL, NULL);
2000 long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
2003 if(vf->ready_state<OPENED)return(OV_EINVAL);
2006 if(vf->ready_state==INITSET){
2008 long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
2012 vorbis_synthesis_read(&vf->vd,samples);
2013 vf->pcm_offset+=samples;
2014 if(bitstream)*bitstream=vf->current_link;
2022 int ret=_fetch_and_process_packet(vf,NULL,1,1);
2067 /* make sure vf is INITSET */
2068 static int _ov_initset(OggVorbis_File *vf){
2070 if(vf->ready_state==INITSET)break;
2073 int ret=_fetch_and_process_packet(vf,NULL,1,0);
2080 /* make sure vf is INITSET and that we have a primed buffer; if
2083 static int _ov_initprime(OggVorbis_File *vf){
2084 vorbis_dsp_state *vd=&vf->vd;
2086 if(vf->ready_state==INITSET)
2091 int ret=_fetch_and_process_packet(vf,NULL,1,0);
2098 /* grab enough data for lapping from vf; this may be in the form of
2101 static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
2117 int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
2125 int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
2194 static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
2203 if(vf->ready_state<OPENED)return(OV_EINVAL);
2204 ret=_ov_initset(vf);
2206 vi=ov_info(vf,-1);
2207 hs=ov_halfrate_p(vf);
2211 w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
2219 _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
2222 ret=localseek(vf,pos);
2224 ret=_ov_initprime(vf);
2228 vi=ov_info(vf,-1);
2231 w2=vorbis_window(&vf->vd,0);
2234 vorbis_synthesis_lapout(&vf->vd,&pcm);
2243 int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
2244 return _ov_64_seek_lap(vf,pos,ov_raw_seek);
2247 int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
2248 return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
2251 int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
2252 return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
2255 static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
2264 if(vf->ready_state<OPENED)return(OV_EINVAL);
2265 ret=_ov_initset(vf);
2267 vi=ov_info(vf,-1);
2268 hs=ov_halfrate_p(vf);
2272 w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
2280 _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
2283 ret=localseek(vf,pos);
2285 ret=_ov_initprime(vf);
2289 vi=ov_info(vf,-1);
2292 w2=vorbis_window(&vf->vd,0);
2295 vorbis_synthesis_lapout(&vf->vd,&pcm);
2304 int ov_time_seek_lap(OggVorbis_File *vf,double pos){
2305 return _ov_d_seek_lap(vf,pos,ov_time_seek);
2308 int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
2309 return _ov_d_seek_lap(vf,pos,ov_time_seek_page);