[xiph-cvs] cvs commit: vorbis/lib vorbis-errors.txt analysis.c block.c info.c synthesis.c vorbisfile.c
Monty
xiphmont at xiph.org
Fri Oct 13 20:14:09 PDT 2000
xiphmont 00/10/13 20:14:08
Modified: include/vorbis Tag: branch_beta3 codec.h
lib Tag: branch_beta3 analysis.c block.c info.c
synthesis.c vorbisfile.c
Added: lib Tag: branch_beta3 vorbis-errors.txt
Log:
First take at adding real eror return codes to libvorbis and
libvorbisfile. The change is complete, but not really well tested.
Also stripped all the fprintfs from vorbisfile.
Monty
Revision Changes Path
No revision
No revision
1.32.2.1 +19 -1 vorbis/include/vorbis/codec.h
Index: codec.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/include/vorbis/codec.h,v
retrieving revision 1.32
retrieving revision 1.32.2.1
diff -u -r1.32 -r1.32.2.1
--- codec.h 2000/10/12 07:28:03 1.32
+++ codec.h 2000/10/14 03:14:06 1.32.2.1
@@ -12,7 +12,7 @@
********************************************************************
function: libvorbis codec headers
- last mod: $Id: codec.h,v 1.32 2000/10/12 07:28:03 jack Exp $
+ last mod: $Id: codec.h,v 1.32.2.1 2000/10/14 03:14:06 xiphmont Exp $
********************************************************************/
@@ -310,6 +310,24 @@
extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
+
+/* Vorbis ERRORS and return codes ***********************************/
+
+#define OV_FALSE -1
+#define OV_EOF -2
+#define OV_HOLE -3
+
+#define OV_EREAD -128
+#define OV_EFAULT -129
+#define OV_EIMPL -130
+#define OV_EINVAL -131
+#define OV_ENOTVORBIS -132
+#define OV_EBADHEADER -133
+#define OV_EVERSION -134
+#define OV_ENOTAUDIO -135
+#define OV_EBADPACKET -136
+#define OV_EBADLINK -137
+#define OV_ENOSEEK -138
#ifdef __cplusplus
}
No revision
No revision
1.34.2.1 +7 -7 vorbis/lib/analysis.c
Index: analysis.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/analysis.c,v
retrieving revision 1.34
retrieving revision 1.34.2.1
diff -u -r1.34 -r1.34.2.1
--- analysis.c 2000/10/12 03:12:52 1.34
+++ analysis.c 2000/10/14 03:14:06 1.34.2.1
@@ -12,7 +12,7 @@
********************************************************************
function: single-block PCM analysis mode dispatch
- last mod: $Id: analysis.c,v 1.34 2000/10/12 03:12:52 xiphmont Exp $
+ last mod: $Id: analysis.c,v 1.34.2.1 2000/10/14 03:14:06 xiphmont Exp $
********************************************************************/
@@ -29,7 +29,7 @@
int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
vorbis_dsp_state *vd=vb->vd;
vorbis_info *vi=vd->vi;
- int type;
+ int type,ret;
int mode=0;
vb->glue_bits=0;
@@ -58,18 +58,18 @@
fprintf(stderr,".");
}*/
- if(_mapping_P[type]->forward(vb,vd->mode[mode]))
- return(-1);
-
+ if((ret=_mapping_P[type]->forward(vb,vd->mode[mode])))
+ return(ret);
+
/* set up the packet wrapper */
-
+
op->packet=oggpack_get_buffer(&vb->opb);
op->bytes=oggpack_bytes(&vb->opb);
op->b_o_s=0;
op->e_o_s=vb->eofflag;
op->granulepos=vb->granulepos;
op->packetno=vb->sequence; /* for sake of completeness */
-
+
return(0);
}
1.39.2.1 +3 -3 vorbis/lib/block.c
Index: block.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/block.c,v
retrieving revision 1.39
retrieving revision 1.39.2.1
diff -u -r1.39 -r1.39.2.1
--- block.c 2000/10/12 03:12:52 1.39
+++ block.c 2000/10/14 03:14:06 1.39.2.1
@@ -12,7 +12,7 @@
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.39 2000/10/12 03:12:52 xiphmont Exp $
+ last mod: $Id: block.c,v 1.39.2.1 2000/10/14 03:14:06 xiphmont Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
@@ -432,7 +432,7 @@
}else{
if(v->pcm_current+vals>v->pcm_storage)
- return(-1);
+ return(OV_EINVAL);
v->pcm_current+=vals;
@@ -722,7 +722,7 @@
}
int vorbis_synthesis_read(vorbis_dsp_state *v,int bytes){
- if(bytes && v->pcm_returned+bytes>v->centerW)return(-1);
+ if(bytes && v->pcm_returned+bytes>v->centerW)return(OV_EINVAL);
v->pcm_returned+=bytes;
return(0);
}
1.31.2.1 +13 -13 vorbis/lib/info.c
Index: info.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/info.c,v
retrieving revision 1.31
retrieving revision 1.31.2.1
diff -u -r1.31 -r1.31.2.1
--- info.c 2000/10/12 03:12:52 1.31
+++ info.c 2000/10/14 03:14:06 1.31.2.1
@@ -12,7 +12,7 @@
********************************************************************
function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.31 2000/10/12 03:12:52 xiphmont Exp $
+ last mod: $Id: info.c,v 1.31.2.1 2000/10/14 03:14:06 xiphmont Exp $
********************************************************************/
@@ -190,7 +190,7 @@
static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
vi->version=oggpack_read(opb,32);
- if(vi->version!=0)return(-1);
+ if(vi->version!=0)return(OV_EVERSION);
vi->channels=oggpack_read(opb,8);
vi->rate=oggpack_read(opb,32);
@@ -212,7 +212,7 @@
return(0);
err_out:
vorbis_info_clear(vi);
- return(-1);
+ return(OV_EBADHEADER);
}
static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
@@ -238,7 +238,7 @@
return(0);
err_out:
vorbis_comment_clear(vc);
- return(-1);
+ return(OV_EBADHEADER);
}
/* all of the real encoding details are here. The modes, books,
@@ -318,7 +318,7 @@
return(0);
err_out:
vorbis_info_clear(vi);
- return(-1);
+ return(OV_EBADHEADER);
}
/* The Vorbis header is in three packets; the initial small packet in
@@ -341,17 +341,17 @@
_v_readstring(&opb,buffer,6);
if(memcmp(buffer,"vorbis",6)){
/* not a vorbis header */
- return(-1);
+ return(OV_ENOTVORBIS);
}
switch(packtype){
case 0x01: /* least significant *bit* is read first */
if(!op->b_o_s){
/* Not the initial packet */
- return(-1);
+ return(OV_EBADHEADER);
}
if(vi->rate!=0){
/* previously initialized info header */
- return(-1);
+ return(OV_EBADHEADER);
}
return(_vorbis_unpack_info(vi,&opb));
@@ -359,7 +359,7 @@
case 0x03: /* least significant *bit* is read first */
if(vi->rate==0){
/* um... we didn't get the initial header */
- return(-1);
+ return(OV_EBADHEADER);
}
return(_vorbis_unpack_comment(vc,&opb));
@@ -367,19 +367,19 @@
case 0x05: /* least significant *bit* is read first */
if(vi->rate==0 || vc->vendor==NULL){
/* um... we didn;t get the initial header or comments yet */
- return(-1);
+ return(OV_EBADHEADER);
}
return(_vorbis_unpack_books(vi,&opb));
default:
/* Not a valid vorbis header type */
- return(-1);
+ return(OV_EBADHEADER);
break;
}
}
}
- return(-1);
+ return(OV_EBADHEADER);
}
/* pack side **********************************************************/
@@ -553,6 +553,6 @@
v->header=NULL;
v->header1=NULL;
v->header2=NULL;
- return(-1);
+ return(OV_EIMPL);
}
1.18.2.1 +4 -4 vorbis/lib/synthesis.c
Index: synthesis.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/synthesis.c,v
retrieving revision 1.18
retrieving revision 1.18.2.1
diff -u -r1.18 -r1.18.2.1
--- synthesis.c 2000/10/12 03:12:54 1.18
+++ synthesis.c 2000/10/14 03:14:07 1.18.2.1
@@ -12,7 +12,7 @@
********************************************************************
function: single-block PCM synthesis
- last mod: $Id: synthesis.c,v 1.18 2000/10/12 03:12:54 xiphmont Exp $
+ last mod: $Id: synthesis.c,v 1.18.2.1 2000/10/14 03:14:07 xiphmont Exp $
********************************************************************/
@@ -36,19 +36,19 @@
/* Check the packet type */
if(oggpack_read(opb,1)!=0){
/* Oops. This is not an audio data packet */
- return(-1);
+ return(OV_ENOTAUDIO);
}
/* read our mode and pre/post windowsize */
mode=oggpack_read(opb,vd->modebits);
- if(mode==-1)return(-1);
+ if(mode==-1)return(OV_EBADPACKET);
vb->mode=mode;
vb->W=vi->mode_param[mode]->blockflag;
if(vb->W){
vb->lW=oggpack_read(opb,1);
vb->nW=oggpack_read(opb,1);
- if(vb->nW==-1) return(-1);
+ if(vb->nW==-1) return(OV_EBADPACKET);
}else{
vb->lW=0;
vb->nW=0;
1.30.2.1 +149 -131 vorbis/lib/vorbisfile.c
Index: vorbisfile.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/vorbisfile.c,v
retrieving revision 1.30
retrieving revision 1.30.2.1
diff -u -r1.30 -r1.30.2.1
--- vorbisfile.c 2000/10/13 19:48:03 1.30
+++ vorbisfile.c 2000/10/14 03:14:07 1.30.2.1
@@ -12,7 +12,7 @@
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c,v 1.30 2000/10/13 19:48:03 xiphmont Exp $
+ last mod: $Id: vorbisfile.c,v 1.30.2.1 2000/10/14 03:14:07 xiphmont Exp $
********************************************************************/
@@ -62,7 +62,7 @@
static long _get_data(OggVorbis_File *vf){
char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
- ogg_sync_wrote(&vf->oy,bytes);
+ if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
return(bytes);
}
@@ -83,7 +83,7 @@
0) read no additional data; use cached only
n) search for a new page beginning for n bytes
- return: -1) did not find a page
+ return: <0) did not find a page (OV_FALSE, OV_EOF, OV_EREAD)
n) found a page at absolute offset n */
static long _get_next_page(OggVorbis_File *vf,ogg_page *og,int boundary){
@@ -91,7 +91,7 @@
while(1){
long more;
- if(boundary>0 && vf->offset>=boundary)return(-1);
+ if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
more=ogg_sync_pageseek(&vf->oy,og);
if(more<0){
@@ -100,8 +100,12 @@
}else{
if(more==0){
/* send more paramedics */
- if(!boundary)return(-1);
- if(_get_data(vf)<=0)return(-1);
+ if(!boundary)return(OV_FALSE);
+ {
+ long ret=_get_data(vf);
+ if(ret==0)return(OV_EOF);
+ if(ret<0)return(OV_EREAD);
+ }
}else{
/* got a page. Return the offset at the page beginning,
advance the internal offset past the page end */
@@ -118,6 +122,7 @@
position. Much dirtier than the above as Ogg doesn't have any
backward search linkage. no 'readp' as it will certainly have to
read. */
+/* returns offset or OV_EREAD, OV_FAULT */
static long _get_prev_page(OggVorbis_File *vf,ogg_page *og){
long begin=vf->offset;
long ret;
@@ -128,7 +133,8 @@
_seek_helper(vf,begin);
while(vf->offset<begin+CHUNKSIZE){
ret=_get_next_page(vf,og,begin+CHUNKSIZE-vf->offset);
- if(ret==-1){
+ if(ret==OV_EREAD)return(OV_EREAD);
+ if(ret<0){
break;
}else{
offset=ret;
@@ -139,12 +145,10 @@
/* we have the offset. Actually snork and hold the page now */
_seek_helper(vf,offset);
ret=_get_next_page(vf,og,CHUNKSIZE);
- if(ret==-1){
+ if(ret<0)
/* this shouldn't be possible */
- fprintf(stderr,"Missed page fencepost at end of logical bitstream. "
- "Exiting.\n");
- exit(1);
- }
+ return(OV_EFAULT);
+
return(offset);
}
@@ -152,12 +156,12 @@
(has to begin by knowing the offset of the lb's initial page).
Recurses for each link so it can alloc the link storage after
finding them all, then unroll and fill the cache at the same time */
-static void _bisect_forward_serialno(OggVorbis_File *vf,
- long begin,
- long searched,
- long end,
- long currentno,
- long m){
+static int _bisect_forward_serialno(OggVorbis_File *vf,
+ long begin,
+ long searched,
+ long end,
+ long currentno,
+ long m){
long endsearched=end;
long next=end;
ogg_page og;
@@ -176,6 +180,7 @@
_seek_helper(vf,bisect);
ret=_get_next_page(vf,&og,-1);
+ if(ret==OV_EREAD)return(OV_EREAD);
if(ret<0 || ogg_page_serialno(&og)!=currentno){
endsearched=bisect;
if(ret>=0)next=ret;
@@ -186,17 +191,20 @@
_seek_helper(vf,next);
ret=_get_next_page(vf,&og,-1);
+ if(ret==OV_EREAD)return(OV_EREAD);
- if(searched>=end || ret==-1){
+ if(searched>=end || ret<0){
vf->links=m+1;
vf->offsets=malloc((m+2)*sizeof(ogg_int64_t));
vf->offsets[m+1]=searched;
}else{
- _bisect_forward_serialno(vf,next,vf->offset,
- end,ogg_page_serialno(&og),m+1);
+ ret=_bisect_forward_serialno(vf,next,vf->offset,
+ end,ogg_page_serialno(&og),m+1);
+ if(ret==OV_EREAD)return(OV_EREAD);
}
vf->offsets[m]=begin;
+ return(0);
}
/* uses the local ogg_stream storage in vf; this is important for
@@ -205,14 +213,12 @@
long *serialno,ogg_page *og_ptr){
ogg_page og;
ogg_packet op;
- int i,ret;
+ int i,ret=0;
if(!og_ptr){
ret=_get_next_page(vf,&og,CHUNKSIZE);
- if(ret==-1){
- fprintf(stderr,"Did not find initial header for bitstream.\n");
- return -1;
- }
+ if(ret==OV_EREAD)return(OV_EREAD);
+ if(ret<0)return OV_ENOTVORBIS;
og_ptr=&og;
}
@@ -232,18 +238,17 @@
int result=ogg_stream_packetout(&vf->os,&op);
if(result==0)break;
if(result==-1){
- fprintf(stderr,"Corrupt header in logical bitstream.\n");
+ ret=OV_EBADHEADER;
goto bail_header;
}
- if(vorbis_synthesis_headerin(vi,vc,&op)){
- fprintf(stderr,"Illegal header in logical bitstream.\n");
+ if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
goto bail_header;
}
i++;
}
if(i<3)
if(_get_next_page(vf,og_ptr,1)<0){
- fprintf(stderr,"Missing header in logical bitstream.\n");
+ ret=OV_EBADHEADER;
goto bail_header;
}
}
@@ -253,13 +258,18 @@
vorbis_info_clear(vi);
vorbis_comment_clear(vc);
ogg_stream_clear(&vf->os);
- return -1;
+ return ret;
}
/* last step of the OggVorbis_File initialization; get all the
vorbis_info structs and PCM positions. Only called by the seekable
initialization (local stream storage is hacked slightly; pay
attention to how that's done) */
+
+/* this is void and does not propogate errors up because we want to be
+ able to open and use damaged bitstreams as well as we can. Just
+ watch out for missing information for links in the OggVorbis_File
+ struct */
static void _prefetch_all_headers(OggVorbis_File *vf,vorbis_info *first_i,
vorbis_comment *first_c,
long dataoffset){
@@ -284,8 +294,7 @@
/* seek to the location of the initial header */
_seek_helper(vf,vf->offsets[i]);
- if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)==-1){
- fprintf(stderr,"Error opening logical bitstream #%d.\n\n",i+1);
+ if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
vf->dataoffsets[i]=-1;
}else{
vf->dataoffsets[i]=vf->offset;
@@ -301,10 +310,8 @@
while(1){
ret=_get_prev_page(vf,&og);
- if(ret==-1){
- /* this should not be possible */
- fprintf(stderr,"Could not find last page of logical "
- "bitstream #%d\n\n",i);
+ if(ret<0){
+ /* this should not be possible, actually */
vorbis_info_clear(vf->vi+i);
vorbis_comment_clear(vf->vc+i);
break;
@@ -319,8 +326,8 @@
}
}
-static int _make_decode_ready(OggVorbis_File *vf){
- if(vf->decode_ready)exit(1);
+static void _make_decode_ready(OggVorbis_File *vf){
+ if(vf->decode_ready)return;
if(vf->seekable){
vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link);
}else{
@@ -328,7 +335,7 @@
}
vorbis_block_init(&vf->vd,&vf->vb);
vf->decode_ready=1;
- return(0);
+ return;
}
static int _open_seekable(OggVorbis_File *vf){
@@ -343,7 +350,7 @@
ret=_fetch_headers(vf,&initial_i,&initial_c,&serialno,NULL);
dataoffset=vf->offset;
ogg_stream_clear(&vf->os);
- if(ret==-1)return(-1);
+ if(ret<0)return(ret);
/* we can seek, so set out learning all about this file */
vf->seekable=1;
@@ -353,18 +360,28 @@
/* We get the offset for the last page of the physical bitstream.
Most OggVorbis files will contain a single logical bitstream */
end=_get_prev_page(vf,&og);
+ if(end<0){
+ ogg_stream_clear(&vf->os);
+ return(end);
+ }
- /* moer than one logical bitstream? */
+ /* more than one logical bitstream? */
if(ogg_page_serialno(&og)!=serialno){
/* Chained bitstream. Bisect-search each logical bitstream
section. Do so based on serial number only */
- _bisect_forward_serialno(vf,0,0,end+1,serialno,0);
+ if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0){
+ ogg_stream_clear(&vf->os);
+ return(OV_EREAD);
+ }
}else{
/* Only one logical bitstream */
- _bisect_forward_serialno(vf,0,end,end+1,serialno,0);
+ if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0)){
+ ogg_stream_clear(&vf->os);
+ return(OV_EREAD);
+ }
}
@@ -374,13 +391,15 @@
}
static int _open_nonseekable(OggVorbis_File *vf){
+ int ret;
/* we cannot seek. Set up a 'single' (current) logical bitstream entry */
vf->links=1;
vf->vi=calloc(vf->links,sizeof(vorbis_info));
vf->vc=calloc(vf->links,sizeof(vorbis_info));
/* Try to fetch the headers, maintaining all the storage */
- if(_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL)==-1)return(-1);
+ if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0)
+ return(ret);
_make_decode_ready(vf);
return 0;
@@ -403,8 +422,8 @@
date (seek and read both use this. seek uses a special hack with
readp).
- return: -1) hole in the data (lost packet)
- 0) need more date (only if readp==0)/eof
+ return: <0) error, OV_HOLE (lost packet) or OV_EOF
+ 0) need more data (only if readp==0)
1) got a packet
*/
@@ -422,9 +441,7 @@
int result=ogg_stream_packetout(&vf->os,&op);
ogg_int64_t granulepos;
- /* if(result==-1)return(-1); hole in the data. For now, swallow
- and go. We'll need to add a real
- error code in a bit. */
+ if(result==-1)return(OV_HOLE); /* hole in the data. */
if(result>0){
/* got a packet. process it */
granulepos=op.granulepos;
@@ -475,7 +492,7 @@
}
if(!readp)return(0);
- if(_get_next_page(vf,&og,-1)<0)return(0); /* eof. leave unitialized */
+ if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* eof. leave unitialized */
/* bitrate tracking; add the header's bytes here, the body bytes
are done by packet above */
@@ -510,14 +527,16 @@
boundaries */
for(link=0;link<vf->links;link++)
if(vf->serialnos[link]==vf->current_serialno)break;
- if(link==vf->links)return(-1); /* sign of a bogus stream. error out,
- leave machine uninitialized */
+ if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
+ stream. error out,
+ leave machine
+ uninitialized */
vf->current_link=link;
-
+
ogg_stream_init(&vf->os,vf->current_serialno);
ogg_stream_reset(&vf->os);
-
+
}else{
/* we're streaming */
/* fetch the three header packets, build the info struct */
@@ -646,7 +665,7 @@
vorbis_info structs */
long ov_bitrate(OggVorbis_File *vf,int i){
- if(i>=vf->links)return(-1);
+ if(i>=vf->links)return(OV_EINVAL);
if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
if(i<0){
ogg_int64_t bits=0;
@@ -670,7 +689,7 @@
return vf->vi[i].bitrate_upper;
}
}
- return(-1);
+ return(OV_FALSE);
}
}
}
@@ -681,7 +700,7 @@
long ov_bitrate_instant(OggVorbis_File *vf){
int link=(vf->seekable?vf->current_link:0);
long ret;
- if(vf->samptrack==0)return(-1);
+ if(vf->samptrack==0)return(OV_FALSE);
ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
vf->bittrack=0.;
vf->samptrack=0.;
@@ -690,7 +709,7 @@
/* Guess */
long ov_serialnumber(OggVorbis_File *vf,int i){
- if(i>=vf->links)return(-1);
+ if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
if(i<0){
return(vf->current_serialno);
@@ -704,7 +723,7 @@
-1 if the stream is not seekable (we can't know the length)
*/
ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
- if(!vf->seekable || i>=vf->links)return(-1);
+ if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
if(i<0){
long acc=0;
int i;
@@ -721,7 +740,7 @@
-1 if the stream is not seekable (we can't know the length)
*/
ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
- if(!vf->seekable || i>=vf->links)return(-1);
+ if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
if(i<0){
ogg_int64_t acc=0;
int i;
@@ -738,7 +757,7 @@
-1 if the stream is not seekable (we can't know the length)
*/
double ov_time_total(OggVorbis_File *vf,int i){
- if(!vf->seekable || i>=vf->links)return(-1);
+ if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
if(i<0){
double acc=0;
int i;
@@ -759,14 +778,14 @@
returns zero on success, nonzero on failure */
int ov_raw_seek(OggVorbis_File *vf,long pos){
-
- if(!vf->seekable)return(-1); /* don't dump machine if we can't seek */
- if(pos<0 || pos>vf->offsets[vf->links])goto seek_error;
+ int flag=0;
+ if(!vf->seekable)return(OV_ENOSEEK); /* don't dump machine if we can't seek */
+ if(pos<0 || pos>vf->offsets[vf->links])return(OV_EINVAL);
/* clear out decoding machine state */
vf->pcm_offset=-1;
_decode_clear(vf);
-
+
/* seek */
_seek_helper(vf,pos);
@@ -776,29 +795,34 @@
from a page has the 'granulepos' field set, and that's how the
helper updates the offset */
- switch(_process_packet(vf,1)){
- case 0:
- /* oh, eof. There are no packets remaining. Set the pcm offset to
- the end of file */
- vf->pcm_offset=ov_pcm_total(vf,-1);
- return(0);
- case -1:
- /* error! missing data or invalid bitstream structure */
- goto seek_error;
- default:
- /* all OK */
- break;
+ while(!flag){
+ switch(_process_packet(vf,1)){
+ case 0:case OV_EOF:
+ /* oh, eof. There are no packets remaining. Set the pcm offset to
+ the end of file */
+ vf->pcm_offset=ov_pcm_total(vf,-1);
+ return(0);
+ case OV_HOLE:
+ break;
+ case OV_EBADLINK:
+ goto seek_error;
+ default:
+ /* all OK */
+ flag=1;
+ break;
+ }
}
-
+
while(1){
+ /* don't have to check each time through for the updated granule;
+ it's always the last complete packet on a page */
switch(_process_packet(vf,0)){
- case 0:
- /* the offset is set. If it's a bogus bitstream with no offset
- information, it's not but that's not our fault. We still run
+ case 0:case OV_EOF:
+ /* the offset is set unless it's a bogus bitstream with no
+ offset information but that's not our fault. We still run
gracefully, we're just missing the offset */
return(0);
- case -1:
- /* error! missing data or invalid bitstream structure */
+ case OV_EBADLINK:
goto seek_error;
default:
/* continue processing packets */
@@ -810,7 +834,7 @@
/* dump the machine so we're in a known state */
vf->pcm_offset=-1;
_decode_clear(vf);
- return -1;
+ return OV_EBADLINK;
}
/* Page granularity seek (faster than sample granularity because we
@@ -821,10 +845,11 @@
arrive at the requested position. */
int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
int link=-1;
+ long ret;
ogg_int64_t total=ov_pcm_total(vf,-1);
- if(!vf->seekable)return(-1); /* don't dump machine if we can't seek */
- if(pos<0 || pos>total)goto seek_error;
+ if(!vf->seekable)return(OV_ENOSEEK);
+ if(pos<0 || pos>total)return(OV_EINVAL);
/* which bitstream section does this pcm offset occur in? */
for(link=vf->links-1;link>=0;link--){
@@ -846,7 +871,6 @@
ogg_page og;
while(begin<end){
long bisect;
- long ret;
if(end-begin<CHUNKSIZE){
bisect=begin;
@@ -856,43 +880,51 @@
_seek_helper(vf,bisect);
ret=_get_next_page(vf,&og,end-bisect);
-
- if(ret==-1){
+ switch(ret){
+ case OV_FALSE: case OV_EOF:
end=bisect;
- }else{
- ogg_int64_t granulepos=ogg_page_granulepos(&og);
- if(granulepos<target){
- best=ret; /* raw offset of packet with granulepos */
- begin=vf->offset; /* raw offset of next packet */
- }else{
- end=bisect;
+ break;
+ case OV_EREAD:
+ goto seek_error;
+ default:
+ {
+ ogg_int64_t granulepos=ogg_page_granulepos(&og);
+ if(granulepos<target){
+ best=ret; /* raw offset of packet with granulepos */
+ begin=vf->offset; /* raw offset of next packet */
+ }else{
+ end=bisect;
+ }
}
}
}
/* found our page. seek to it (call raw_seek). */
- if(ov_raw_seek(vf,best))goto seek_error;
+ if((ret=ov_raw_seek(vf,best)))goto seek_error;
}
-
+
/* verify result */
- if(vf->pcm_offset>=pos)goto seek_error;
- if(pos>ov_pcm_total(vf,-1))goto seek_error;
+ if(vf->pcm_offset>=pos || pos>ov_pcm_total(vf,-1)){
+ ret=OV_EFAULT;
+ goto seek_error;
+ }
return(0);
-
+
seek_error:
/* dump machine so we're in a known state */
vf->pcm_offset=-1;
_decode_clear(vf);
- return -1;
+ return ret;
}
/* seek to a sample offset relative to the decompressed pcm stream
returns zero on success, nonzero on failure */
int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
- if(ov_pcm_seek_page(vf,pos))return(-1);
-
+ int ret=ov_pcm_seek_page(vf,pos);
+ if(ret<0)return(ret);
+
/* discard samples until we reach the desired position. Crossing a
logical bitstream boundary with abandon is OK. */
while(vf->pcm_offset<pos){
@@ -920,8 +952,8 @@
ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
double time_total=ov_time_total(vf,-1);
- if(!vf->seekable)return(-1); /* don't dump machine if we can't seek */
- if(seconds<0 || seconds>time_total)goto seek_error;
+ if(!vf->seekable)return(OV_ENOSEEK);
+ if(seconds<0 || seconds>time_total)return(OV_EINVAL);
/* which bitstream section does this time offset occur in? */
for(link=vf->links-1;link>=0;link--){
@@ -935,12 +967,6 @@
ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
return(ov_pcm_seek(vf,target));
}
-
- seek_error:
- /* dump machine so we're in a known state */
- vf->pcm_offset=-1;
- _decode_clear(vf);
- return -1;
}
/* page-granularity version of ov_time_seek
@@ -952,8 +978,8 @@
ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
double time_total=ov_time_total(vf,-1);
- if(!vf->seekable)return(-1); /* don't dump machine if we can't seek */
- if(seconds<0 || seconds>time_total)goto seek_error;
+ if(!vf->seekable)return(OV_ENOSEEK);
+ if(seconds<0 || seconds>time_total)return(OV_EINVAL);
/* which bitstream section does this time offset occur in? */
for(link=vf->links-1;link>=0;link--){
@@ -967,12 +993,6 @@
ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
return(ov_pcm_seek_page(vf,target));
}
-
- seek_error:
- /* dump machine so we're in a known state */
- vf->pcm_offset=-1;
- _decode_clear(vf);
- return -1;
}
/* tell the current stream offset cursor. Note that seek followed by
@@ -1059,11 +1079,9 @@
}
int host_is_big_endian() {
- short pattern = 0xbabe;
+ ogg_int32_t pattern = 0xfeedface; /* deadbeef */
unsigned char *bytewise = (unsigned char *)&pattern;
- if (bytewise[0] == 0xba) return 1;
-
- assert(bytewise[0] == 0xbe);
+ if (bytewise[0] == 0xfe) return 1;
return 0;
}
@@ -1089,7 +1107,7 @@
word) word size for output. currently 1 (byte) or
2 (16 bit short)
- return values: -1) error/hole in data
+ return values: -1) error/hole in data (OV_HOLE)
0) EOF
n) number of bytes of PCM actually returned. The
below works on a packet-by-packet basis, so the
@@ -1190,12 +1208,12 @@
/* suck in another packet */
switch(_process_packet(vf,1)){
- case 0:
+ case 0:case OV_EOF:
return(0);
- case -1:
- return -1;
- default:
- break;
+ case OV_HOLE:
+ return(OV_HOLE);
+ case OV_EBADLINK:
+ return(OV_EBADLINK);
}
}
}
No revision
No revision
1.1.2.1 +83 -0 vorbis/lib/Attic/vorbis-errors.txt
--- >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 'cvs-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 commits
mailing list