/******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * * by the Xiph.Org Foundation http://www.xiph.org/ * * * ******************************************************************** function: illustrate seeking, and test it too last mod: $Id: seeking_example.c 16037 2009-05-26 21:10:58Z xiphmont $ ********************************************************************/ #include #include #include "vorbis/codec.h" #include "vorbis/vorbisfile.h" #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */ # include # include #endif void _verify(OggVorbis_File *ov, ogg_int64_t val,ogg_int64_t pcmval,double timeval, ogg_int64_t pcmlength, char *bigassbuffer){ int j; long bread; char buffer[4096]; int dummy; ogg_int64_t pos; /* verify the raw position, the pcm position and position decode */ if(val!=-1 && ov_raw_tell(ov)pcmval){ fprintf(stderr,"pcm position out of tolerance: requested %ld, got %ld\n", (long)pcmval,(long)ov_pcm_tell(ov)); exit(1); } if(timeval!=-1 && ov_time_tell(ov)>timeval){ fprintf(stderr,"time position out of tolerance: requested %f, got %f\n", timeval,ov_time_tell(ov)); exit(1); } pos=ov_pcm_tell(ov); if(pos<0 || pos>pcmlength){ fprintf(stderr,"pcm position out of bounds: got %ld\n",(long)pos); exit(1); } bread=ov_read(ov,buffer,4096,1,1,1,&dummy); for(j=0;jchannels!=2){ fprintf(stderr,"Sorry; right now seeking_test can only use Vorbis files\n" "that are entirely stereo.\n\n"); exit(1); } } /* because we want to do sample-level verification that the seek does what it claimed, decode the entire file into memory */ pcmlength=ov_pcm_total(&ov,-1); timelength=ov_time_total(&ov,-1); bigassbuffer=malloc(pcmlength*2); /* w00t */ i=0; while(ival+1){ fprintf(stderr,"Declared position didn't perfectly match request: %f != %f\n", val,ov_time_tell(&ov)); exit(1); } _verify(&ov,-1,-1,val,pcmlength,bigassbuffer); } } fprintf(stderr,"\r \nOK.\n\n"); }else{ fprintf(stderr,"Standard input was not seekable.\n"); } ov_clear(&ov); return 0; }