diff options
author | Monty <xiphmont@xiph.org> | 2003-04-14 06:40:51 +0000 |
---|---|---|
committer | Monty <xiphmont@xiph.org> | 2003-04-14 06:40:51 +0000 |
commit | 63f97e0602c6bb8aaa22e5706869f282113ec0b9 (patch) | |
tree | de93bfe824663a53c2321a039457ab4175e5cd9d | |
parent | 53ed41b25c4bd98352e7d1b1d66eabaab5f75e4d (diff) | |
download | tremor-63f97e0602c6bb8aaa22e5706869f282113ec0b9.tar.gz |
Hide internal decode structures from vorbisfile structure; gives a
better shot at binary compat from release to release.
git-svn-id: https://svn.xiph.org/branches/lowmem-branch/Tremor@4611 0101bb08-14d6-0310-b084-bc0e0c8e3800
-rw-r--r-- | block.c | 57 | ||||
-rw-r--r-- | info.c | 3 | ||||
-rw-r--r-- | ivorbiscodec.h | 9 | ||||
-rw-r--r-- | ivorbisfile.h | 4 | ||||
-rw-r--r-- | vorbisfile.c | 46 |
5 files changed, 62 insertions, 57 deletions
@@ -67,13 +67,13 @@ #define WORD_ALIGN 8 #endif -int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){ - memset(vb,0,sizeof(*vb)); +vorbis_block *vorbis_block_create(vorbis_dsp_state *v){ + vorbis_block *vb=_ogg_calloc(1,sizeof(*vb)); vb->vd=v; vb->localalloc=0; vb->localstore=NULL; - return(0); + return vb; } void *_vorbis_block_alloc(vorbis_block *vb,long bytes){ @@ -122,12 +122,11 @@ void _vorbis_block_ripcord(vorbis_block *vb){ vb->reap=NULL; } -int vorbis_block_clear(vorbis_block *vb){ +int vorbis_block_destroy(vorbis_block *vb){ _vorbis_block_ripcord(vb); if(vb->localstore)_ogg_free(vb->localstore); - - memset(vb,0,sizeof(*vb)); - return(0); + _ogg_free(vb); + return 0; } static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ @@ -152,32 +151,34 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ } int vorbis_synthesis_restart(vorbis_dsp_state *v){ - vorbis_info *vi=v->vi; - codec_setup_info *ci; - - if(!vi)return -1; - ci=vi->codec_setup; - if(!ci)return -1; - - v->centerW=ci->blocksizes[1]/2; - v->pcm_current=v->centerW; - - v->pcm_returned=-1; - v->granulepos=-1; - v->sequence=-1; - v->sample_count=-1; - - return(0); + if(!v)return -1; + { + vorbis_info *vi=v->vi; + codec_setup_info *ci; + + if(!vi)return -1; + ci=vi->codec_setup; + if(!ci)return -1; + + v->centerW=ci->blocksizes[1]/2; + v->pcm_current=v->centerW; + + v->pcm_returned=-1; + v->granulepos=-1; + v->sequence=-1; + v->sample_count=-1; + } + return 0; } -int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){ +vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi){ + vorbis_dsp_state *v=_ogg_calloc(1,sizeof(*v)); _vds_init(v,vi); vorbis_synthesis_restart(v); - - return(0); + return v; } -void vorbis_dsp_clear(vorbis_dsp_state *v){ +void vorbis_dsp_destroy(vorbis_dsp_state *v){ int i; if(v){ vorbis_info *vi=v->vi; @@ -190,7 +191,7 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){ if(v->pcmret)_ogg_free(v->pcmret); } - memset(v,0,sizeof(*v)); + _ogg_free(v); } } @@ -222,8 +222,7 @@ static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){ /* codebooks */ ci->books=oggpack_read(opb,8)+1; - ci->book_param=(codebook *) - _ogg_calloc(ci->books,sizeof(*ci->book_param)); + ci->book_param=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->book_param)); for(i=0;i<ci->books;i++) if(vorbis_book_unpack(opb,ci->book_param+i))goto err_out; diff --git a/ivorbiscodec.h b/ivorbiscodec.h index aaa3fb8..5a76dbf 100644 --- a/ivorbiscodec.h +++ b/ivorbiscodec.h @@ -156,15 +156,16 @@ extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count); extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag); extern void vorbis_comment_clear(vorbis_comment *vc); -extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb); -extern int vorbis_block_clear(vorbis_block *vb); -extern void vorbis_dsp_clear(vorbis_dsp_state *v); +extern vorbis_block *vorbis_block_create(vorbis_dsp_state *v); +extern int vorbis_block_destroy(vorbis_block *vb); + +extern vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi); +extern void vorbis_dsp_destroy(vorbis_dsp_state *v); /* Vorbis PRIMITIVES: synthesis layer *******************************/ extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc, ogg_packet *op); -extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi); extern int vorbis_synthesis_restart(vorbis_dsp_state *v); extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep); extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb); diff --git a/ivorbisfile.h b/ivorbisfile.h index dd77378..e01afe0 100644 --- a/ivorbisfile.h +++ b/ivorbisfile.h @@ -78,8 +78,8 @@ typedef struct OggVorbis_File { ogg_stream_state *os; /* take physical pages, weld into a logical stream of packets */ - vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ - vorbis_block vb; /* local working space for packet->PCM decode */ + vorbis_dsp_state *vd; /* central working state for the packet->PCM decoder */ + vorbis_block *vb; /* local working space for packet->PCM decode */ ov_callbacks callbacks; diff --git a/vorbisfile.c b/vorbisfile.c index 76afad5..93e681f 100644 --- a/vorbisfile.c +++ b/vorbisfile.c @@ -12,7 +12,7 @@ ******************************************************************** function: stdio-based convenience library for opening/seeking/decoding - last mod: $Id: vorbisfile.c,v 1.6.2.1 2003/04/09 09:43:49 xiphmont Exp $ + last mod: $Id: vorbisfile.c,v 1.6.2.2 2003/04/14 06:40:51 xiphmont Exp $ ********************************************************************/ @@ -409,11 +409,11 @@ static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){ static void _make_decode_ready(OggVorbis_File *vf){ if(vf->ready_state!=STREAMSET)return; if(vf->seekable){ - vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link); + vf->vd=vorbis_dsp_create(vf->vi+vf->current_link); }else{ - vorbis_synthesis_init(&vf->vd,vf->vi); + vf->vd=vorbis_dsp_create(vf->vi); } - vorbis_block_init(&vf->vd,&vf->vb); + vf->vb=vorbis_block_create(vf->vd); vf->ready_state=INITSET; vf->bittrack=0; vf->samptrack=0; @@ -461,8 +461,10 @@ static int _open_seekable2(OggVorbis_File *vf){ /* clear out the current logical bitstream decoder */ static void _decode_clear(OggVorbis_File *vf){ - vorbis_dsp_clear(&vf->vd); - vorbis_block_clear(&vf->vb); + vorbis_dsp_destroy(vf->vd); + vorbis_block_destroy(vf->vb); + vf->vd=0; + vf->vb=0; vf->ready_state=OPENED; } @@ -502,7 +504,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, if(result>0){ /* got a packet. process it */ granulepos=op.granulepos; - if(!vorbis_synthesis(&vf->vb,&op,1)){ /* lazy check for lazy + if(!vorbis_synthesis(vf->vb,&op,1)){ /* lazy check for lazy header handling. The header packets aren't audio, so if/when we @@ -512,7 +514,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, /* suck in the synthesis data and track bitrate */ { - int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL); + int oldsamples=vorbis_synthesis_pcmout(vf->vd,NULL); /* for proper use of libvorbis within libvorbisfile, oldsamples will always be zero. */ if(oldsamples){ @@ -520,8 +522,8 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, goto cleanup; } - vorbis_synthesis_blockin(&vf->vd,&vf->vb); - vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples; + vorbis_synthesis_blockin(vf->vd,vf->vb); + vf->samptrack+=vorbis_synthesis_pcmout(vf->vd,NULL)-oldsamples; vf->bittrack+=op.bytes*8; } @@ -550,7 +552,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, here unless the stream is very broken */ - samples=vorbis_synthesis_pcmout(&vf->vd,NULL); + samples=vorbis_synthesis_pcmout(vf->vd,NULL); granulepos-=samples; for(i=0;i<link;i++) @@ -726,8 +728,10 @@ static int _ov_open2(OggVorbis_File *vf){ /* clear out the OggVorbis_File struct */ int ov_clear(OggVorbis_File *vf){ if(vf){ - vorbis_block_clear(&vf->vb); - vorbis_dsp_clear(&vf->vd); + vorbis_block_destroy(vf->vb); + vorbis_dsp_destroy(vf->vd); + vf->vd=0; + vf->vb=0; ogg_stream_destroy(vf->os); if(vf->vi && vf->links){ @@ -970,7 +974,7 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){ vf->pcm_offset=-1; ogg_stream_reset_serialno(vf->os, vf->current_serialno); /* must set serialno */ - vorbis_synthesis_restart(&vf->vd); + vorbis_synthesis_restart(vf->vd); _seek_helper(vf,pos); @@ -1214,7 +1218,7 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ vf->ready_state=STREAMSET; }else{ - vorbis_synthesis_restart(&vf->vd); + vorbis_synthesis_restart(vf->vd); } ogg_stream_reset_serialno(vf->os,vf->current_serialno); @@ -1309,10 +1313,10 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ /* remove the packet from packet queue and track its granulepos */ ogg_stream_packetout(vf->os,NULL); - vorbis_synthesis(&vf->vb,&op,0); /* set up a vb with + vorbis_synthesis(vf->vb,&op,0); /* set up a vb with only tracking, no pcm_decode */ - vorbis_synthesis_blockin(&vf->vd,&vf->vb); + vorbis_synthesis_blockin(vf->vd,vf->vb); /* end of logical stream case is hard, especially with exact length positioning. */ @@ -1364,10 +1368,10 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ logical bitstream boundary with abandon is OK. */ while(vf->pcm_offset<pos){ ogg_int64_t target=pos-vf->pcm_offset; - long samples=vorbis_synthesis_pcmout(&vf->vd,NULL); + long samples=vorbis_synthesis_pcmout(vf->vd,NULL); if(samples>target)samples=target; - vorbis_synthesis_read(&vf->vd,samples); + vorbis_synthesis_read(vf->vd,samples); vf->pcm_offset+=samples; if(samples<target) @@ -1549,7 +1553,7 @@ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ while(1){ if(vf->ready_state==INITSET){ - samples=vorbis_synthesis_pcmout(&vf->vd,&pcm); + samples=vorbis_synthesis_pcmout(vf->vd,&pcm); if(samples)break; } @@ -1587,7 +1591,7 @@ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ } } - vorbis_synthesis_read(&vf->vd,samples); + vorbis_synthesis_read(vf->vd,samples); vf->pcm_offset+=samples; if(bitstream)*bitstream=vf->current_link; return(samples*2*channels); |