Fixed crash in SDL_mixer on armeabi-v7a arch, caused by improper compiler flags, updated libvorbis

This commit is contained in:
pelya
2012-11-01 18:20:32 +02:00
parent f37cc6cda0
commit e4cace0d07
15 changed files with 212 additions and 103 deletions

View File

@@ -398,7 +398,7 @@ class DataDownloader extends Thread
if( response == null )
{
System.out.println("Error connecting to " + url);
Status.setText( res.getString(R.string.failed_connecting_to, url) + (responseError == null ? "" : ": " + responseError.getStatusLine().getStatusCode() + " " + responseError.response.getStatusLine().getReasonPhrase()) );
Status.setText( res.getString(R.string.failed_connecting_to, url) + (responseError == null ? "" : ": " + responseError.getStatusLine().getStatusCode() + " " + responseError.getStatusLine().getReasonPhrase()) );
return false;
}

View File

@@ -9,8 +9,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/../sdl-$(SDL_VERSION)/include $(
$(LOCAL_PATH)/../vorbis/include $(LOCAL_PATH)/../tremor/include $(LOCAL_PATH)/../mikmod/include \
$(LOCAL_PATH)/timidity
LOCAL_CFLAGS := -O3 \
-DWAV_MUSIC -DOGG_USE_TREMOR -DOGG_MUSIC -DFLAC_MUSIC -DMOD_MUSIC \
-DMID_MUSIC -DUSE_TIMIDITY_MIDI
-DWAV_MUSIC -DOGG_MUSIC -DFLAC_MUSIC -DMOD_MUSIC -DMID_MUSIC -DUSE_TIMIDITY_MIDI
LOCAL_CPP_EXTENSION := .cpp

View File

@@ -63,13 +63,13 @@
#define PACKAGE_NAME "libvorbis"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libvorbis 1.3.1"
#define PACKAGE_STRING "libvorbis 1.3.3"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libvorbis"
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.3.1"
#define PACKAGE_VERSION "1.3.3"
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
@@ -83,7 +83,7 @@
#define STDC_HEADERS 1
/* Version number of package */
#define VERSION "1.3.1"
#define VERSION "1.3.3"
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */

View File

@@ -11,7 +11,7 @@
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
last mod: $Id: vorbisfile.h 17021 2010-03-24 09:29:41Z xiphmont $
last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $
********************************************************************/
@@ -147,14 +147,14 @@ typedef struct OggVorbis_File {
extern int ov_clear(OggVorbis_File *vf);
extern int ov_fopen(char *path,OggVorbis_File *vf);
extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
extern int ov_fopen(const char *path,OggVorbis_File *vf);
extern int ov_open(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes);
extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
char *initial, long ibytes, ov_callbacks callbacks);
const char *initial, long ibytes, ov_callbacks callbacks);
extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
extern int ov_test(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes);
extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
char *initial, long ibytes, ov_callbacks callbacks);
const char *initial, long ibytes, ov_callbacks callbacks);
extern int ov_test_open(OggVorbis_File *vf);
extern long ov_bitrate(OggVorbis_File *vf,int i);

View File

@@ -11,7 +11,7 @@
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
last mod: $Id: block.c 16330 2009-07-24 01:58:50Z xiphmont $
last mod: $Id: block.c 17561 2010-10-23 10:34:24Z xiphmont $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
@@ -232,16 +232,17 @@ static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
v->analysisp=1;
}else{
/* finish the codebooks */
if(!ci->fullbooks)
if(!ci->fullbooks){
ci->fullbooks=_ogg_calloc(ci->books,sizeof(*ci->fullbooks));
for(i=0;i<ci->books;i++){
if(ci->book_param[i]==NULL)
goto abort_books;
if(vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]))
goto abort_books;
for(i=0;i<ci->books;i++){
if(ci->book_param[i]==NULL)
goto abort_books;
if(vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]))
goto abort_books;
/* decode codebooks are now standalone after init */
vorbis_staticbook_destroy(ci->book_param[i]);
ci->book_param[i]=NULL;
vorbis_staticbook_destroy(ci->book_param[i]);
ci->book_param[i]=NULL;
}
}
}
@@ -859,17 +860,32 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
if(b->sample_count>v->granulepos){
/* corner case; if this is both the first and last audio page,
then spec says the end is cut, not beginning */
long extra=b->sample_count-vb->granulepos;
/* we use ogg_int64_t for granule positions because a
uint64 isn't universally available. Unfortunately,
that means granposes can be 'negative' and result in
extra being negative */
if(extra<0)
extra=0;
if(vb->eofflag){
/* trim the end */
/* no preceeding granulepos; assume we started at zero (we'd
/* no preceding granulepos; assume we started at zero (we'd
have to in a short single-page stream) */
/* granulepos could be -1 due to a seek, but that would result
in a long count, not short count */
v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
/* Guard against corrupt/malicious frames that set EOP and
a backdated granpos; don't rewind more samples than we
actually have */
if(extra > (v->pcm_current - v->pcm_returned)<<hs)
extra = (v->pcm_current - v->pcm_returned)<<hs;
v->pcm_current-=extra>>hs;
}else{
/* trim the beginning */
v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
v->pcm_returned+=extra>>hs;
if(v->pcm_returned>v->pcm_current)
v->pcm_returned=v->pcm_current;
}
@@ -887,6 +903,20 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
if(extra)
if(vb->eofflag){
/* partial last frame. Strip the extra samples off */
/* Guard against corrupt/malicious frames that set EOP and
a backdated granpos; don't rewind more samples than we
actually have */
if(extra > (v->pcm_current - v->pcm_returned)<<hs)
extra = (v->pcm_current - v->pcm_returned)<<hs;
/* we use ogg_int64_t for granule positions because a
uint64 isn't universally available. Unfortunately,
that means granposes can be 'negative' and result in
extra being negative */
if(extra<0)
extra=0;
v->pcm_current-=extra>>hs;
} /* else {Shouldn't happen *unless* the bitstream is out of
spec. Either way, believe the bitstream } */

View File

@@ -11,7 +11,7 @@
********************************************************************
function: basic codebook pack/unpack/code/decode operations
last mod: $Id: codebook.c 17030 2010-03-25 06:52:55Z xiphmont $
last mod: $Id: codebook.c 18183 2012-02-03 20:51:27Z xiphmont $
********************************************************************/
@@ -163,12 +163,17 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){
/* codeword ordering.... length ordered or unordered? */
switch((int)oggpack_read(opb,1)){
case 0:
case 0:{
long unused;
/* allocated but unused entries? */
unused=oggpack_read(opb,1);
if((s->entries*(unused?1:5)+7)>>3>opb->storage-oggpack_bytes(opb))
goto _eofout;
/* unordered */
s->lengthlist=_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
/* allocated but unused entries? */
if(oggpack_read(opb,1)){
if(unused){
/* yes, unused entries */
for(i=0;i<s->entries;i++){
@@ -189,17 +194,23 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){
}
break;
}
case 1:
/* ordered */
{
long length=oggpack_read(opb,5)+1;
if(length==0)goto _eofout;
s->lengthlist=_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
for(i=0;i<s->entries;){
long num=oggpack_read(opb,_ilog(s->entries-i));
if(num==-1)goto _eofout;
if(length>32 || num>s->entries-i ||
(num>0 && (num-1)>>(length-1)>1)){
goto _errout;
}
if(length>32)goto _errout;
for(j=0;j<num && i<s->entries;j++,i++)
for(j=0;j<num;j++,i++)
s->lengthlist[i]=length;
length++;
}
@@ -237,6 +248,8 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){
}
/* quantized values */
if(((quantvals*s->q_quant+7)>>3)>opb->storage-oggpack_bytes(opb))
goto _eofout;
s->quantlist=_ogg_malloc(sizeof(*s->quantlist)*quantvals);
for(i=0;i<quantvals;i++)
s->quantlist[i]=oggpack_read(opb,s->q_quant);
@@ -354,6 +367,7 @@ long vorbis_book_decode(codebook *book, oggpack_buffer *b){
}
/* returns 0 on OK or -1 on eof *************************************/
/* decode vector / dim granularity gaurding is done in the upper layer */
long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
if(book->used_entries>0){
int step=n/book->dim;
@@ -373,6 +387,7 @@ long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
return(0);
}
/* decode vector / dim granularity gaurding is done in the upper layer */
long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
if(book->used_entries>0){
int i,j,entry;
@@ -418,6 +433,9 @@ long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
return(0);
}
/* unlike the others, we guard against n not being an integer number
of <dim> internally rather than in the upper layer (called only by
floor0) */
long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
if(book->used_entries>0){
int i,j,entry;
@@ -427,15 +445,15 @@ long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
entry = decode_packed_entry_number(book,b);
if(entry==-1)return(-1);
t = book->valuelist+entry*book->dim;
for (j=0;j<book->dim;)
for (j=0;i<n && j<book->dim;){
a[i++]=t[j++];
}
}
}else{
int i,j;
for(i=0;i<n;){
for (j=0;j<book->dim;)
a[i++]=0.f;
a[i++]=0.f;
}
}
return(0);

View File

@@ -11,7 +11,7 @@
********************************************************************
function: floor backend 0 implementation
last mod: $Id: floor0.c 16227 2009-07-08 06:58:46Z xiphmont $
last mod: $Id: floor0.c 18184 2012-02-03 20:55:12Z xiphmont $
********************************************************************/
@@ -91,6 +91,8 @@ static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
for(j=0;j<info->numbooks;j++){
info->books[j]=oggpack_read(opb,8);
if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
if(ci->book_param[info->books[j]]->maptype==0)goto err_out;
if(ci->book_param[info->books[j]]->dim<1)goto err_out;
}
return(info);
@@ -175,10 +177,9 @@ static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
vector */
float *lsp=_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
for(j=0;j<look->m;j+=b->dim)
if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
if(vorbis_book_decodev_set(b,lsp,&vb->opb,look->m)==-1)goto eop;
for(j=0;j<look->m;){
for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
for(k=0;j<look->m && k<b->dim;k++,j++)lsp[j]+=last;
last=lsp[j-1];
}

View File

@@ -11,7 +11,7 @@
********************************************************************
function: floor backend 1 implementation
last mod: $Id: floor1.c 17079 2010-03-26 06:51:41Z xiphmont $
last mod: $Id: floor1.c 18151 2012-01-20 07:35:26Z xiphmont $
********************************************************************/
@@ -167,6 +167,7 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
for(j=0,k=0;j<info->partitions;j++){
count+=info->class_dim[info->partitionclass[j]];
if(count>VIF_POSIT) goto err_out;
for(;k<count;k++){
int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
if(t<0 || t>=(1<<rangebits))
@@ -1035,7 +1036,7 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
}
}
fit_value[i]=val+predicted;
fit_value[i]=(val+predicted)&0x7fff;
fit_value[look->loneighbor[i-2]]&=0x7fff;
fit_value[look->hineighbor[i-2]]&=0x7fff;
@@ -1066,13 +1067,18 @@ static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
int hx=0;
int lx=0;
int ly=fit_value[0]*info->mult;
/* guard lookup against out-of-range values */
ly=(ly<0?0:ly>255?255:ly);
for(j=1;j<look->posts;j++){
int current=look->forward_index[j];
int hy=fit_value[current]&0x7fff;
if(hy==fit_value[current]){
hy*=info->mult;
hx=info->postlist[current];
hy*=info->mult;
/* guard lookup against out-of-range values */
hy=(hy<0?0:hy>255?255:hy);
render_line(n,lx,hx,ly,hy,out);

View File

@@ -10,8 +10,8 @@
* *
********************************************************************
function: highlevel encoder setup struct seperated out for vorbisenc clarity
last mod: $Id: highlevel.h 16995 2010-03-23 03:44:44Z xiphmont $
function: highlevel encoder setup struct separated out for vorbisenc clarity
last mod: $Id: highlevel.h 17195 2010-05-05 21:49:51Z giles $
********************************************************************/

View File

@@ -11,7 +11,7 @@
********************************************************************
function: maintain the info structure, info <-> header packets
last mod: $Id: info.c 17080 2010-03-26 06:59:58Z xiphmont $
last mod: $Id: info.c 18186 2012-02-03 22:08:44Z xiphmont $
********************************************************************/
@@ -31,8 +31,8 @@
#include "misc.h"
#include "os.h"
#define GENERAL_VENDOR_STRING "Xiph.Org libVorbis 1.3.1"
#define ENCODE_VENDOR_STRING "Xiph.Org libVorbis I 20100325 (Everywhere)"
#define GENERAL_VENDOR_STRING "Xiph.Org libVorbis 1.3.3"
#define ENCODE_VENDOR_STRING "Xiph.Org libVorbis I 20120203 (Omnipresent)"
/* helpers */
static int ilog2(unsigned int v){
@@ -550,7 +550,10 @@ int vorbis_commentheader_out(vorbis_comment *vc,
oggpack_buffer opb;
oggpack_writeinit(&opb);
if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
if(_vorbis_pack_comment(&opb,vc)){
oggpack_writeclear(&opb);
return OV_EIMPL;
}
op->packet = _ogg_malloc(oggpack_bytes(&opb));
memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
@@ -561,6 +564,7 @@ int vorbis_commentheader_out(vorbis_comment *vc,
op->granulepos=0;
op->packetno=1;
oggpack_writeclear(&opb);
return 0;
}
@@ -645,9 +649,18 @@ int vorbis_analysis_headerout(vorbis_dsp_state *v,
}
double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
if(granulepos>=0)
if(granulepos == -1) return -1;
/* We're not guaranteed a 64 bit unsigned type everywhere, so we
have to put the unsigned granpo in a signed type. */
if(granulepos>=0){
return((double)granulepos/v->vi->rate);
return(-1);
}else{
ogg_int64_t granuleoff=0xffffffff;
granuleoff<<=31;
granuleoff|=0x7ffffffff;
return(((double)granulepos+2+granuleoff+granuleoff)/v->vi->rate);
}
}
const char *vorbis_version_string(void){

View File

@@ -11,7 +11,7 @@
********************************************************************
function: LSP (also called LSF) conversion routines
last mod: $Id: lsp.c 16227 2009-07-08 06:58:46Z xiphmont $
last mod: $Id: lsp.c 17538 2010-10-15 02:52:29Z tterribe $
The LSP generation code is taken (with minimal modification and a
few bugfixes) from "On the Computation of the LSP Frequencies" by
@@ -46,7 +46,7 @@
implementation. The float lookup is likely the optimal choice on
any machine with an FPU. The integer implementation is *not* fixed
point (due to the need for a large dynamic range and thus a
seperately tracked exponent) and thus much more complex than the
separately tracked exponent) and thus much more complex than the
relatively simple float implementations. It's mostly for future
work on a fully fixed point implementation for processors like the
ARM family. */
@@ -81,11 +81,11 @@ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
float *ftmp=lsp;
int c=m>>1;
do{
while(c--){
q*=ftmp[0]-w;
p*=ftmp[1]-w;
ftmp+=2;
}while(--c);
}
if(m&1){
/* odd order filter; slightly assymetric */

View File

@@ -11,7 +11,7 @@
********************************************************************
function: psychoacoustics not including preecho
last mod: $Id: psy.c 17077 2010-03-26 06:22:19Z xiphmont $
last mod: $Id: psy.c 18077 2011-09-02 02:49:00Z giles $
********************************************************************/
@@ -1020,7 +1020,9 @@ void _vp_couple_quantize_normalize(int blobno,
int limit = g->coupling_pointlimit[p->vi->blockflag][blobno];
float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
#if 0
float de=0.1*p->m_val; /* a blend of the AoTuV M2 and M3 code here and below */
#endif
/* mdct is our raw mdct output, floor not removed. */
/* inout passes in the ifloor, passes back quantized result */
@@ -1154,6 +1156,7 @@ void _vp_couple_quantize_normalize(int blobno,
reM[j] += reA[j];
qeM[j] = fabs(reM[j]);
}else{
#if 0
/* AoTuV */
/** @ M2 **
The boost problem by the combination of noise normalization and point stereo is eased.
@@ -1161,13 +1164,21 @@ void _vp_couple_quantize_normalize(int blobno,
by Aoyumi @ 2004/04/18
*/
float derate = (1.0 - de*((float)(j-limit+i) / (float)(n-limit)));
/* elliptical */
if(reM[j]+reA[j]<0){
reM[j] = - (qeM[j] = (fabs(reM[j])+fabs(reA[j]))*derate*derate);
}else{
reM[j] = (qeM[j] = (fabs(reM[j])+fabs(reA[j]))*derate*derate);
}
#else
/* elliptical */
if(reM[j]+reA[j]<0){
reM[j] = - (qeM[j] = fabs(reM[j])+fabs(reA[j]));
}else{
reM[j] = (qeM[j] = fabs(reM[j])+fabs(reA[j]));
}
#endif
}
reA[j]=qeA[j]=0.f;
fA[j]=1;

View File

@@ -11,7 +11,7 @@
********************************************************************
function: residue backend 0, 1 and 2 implementation
last mod: $Id: res0.c 16962 2010-03-11 07:30:34Z xiphmont $
last mod: $Id: res0.c 17556 2010-10-21 18:25:19Z tterribe $
********************************************************************/
@@ -250,6 +250,7 @@ vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
int entries = ci->book_param[info->groupbook]->entries;
int dim = ci->book_param[info->groupbook]->dim;
int partvals = 1;
if (dim<1) goto errout;
while(dim>0){
partvals *= info->partitions;
if(partvals > entries) goto errout;
@@ -828,7 +829,7 @@ int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
if(s==0){
/* fetch the partition word */
int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
if(temp==-1 || temp>info->partvals)goto eopbreak;
if(temp==-1 || temp>=info->partvals)goto eopbreak;
partword[l]=look->decodemap[temp];
if(partword[l]==NULL)goto errout;
}

View File

@@ -11,7 +11,7 @@
********************************************************************
function: single-block PCM synthesis
last mod: $Id: synthesis.c 17027 2010-03-25 05:21:20Z xiphmont $
last mod: $Id: synthesis.c 17474 2010-09-30 03:41:41Z gmaxwell $
********************************************************************/
@@ -114,6 +114,10 @@ int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
if(mode==-1)return(OV_EBADPACKET);
vb->mode=mode;
if(!ci->mode_param[mode]){
return(OV_EBADPACKET);
}
vb->W=ci->mode_param[mode]->blockflag;
if(vb->W){
vb->lW=oggpack_read(opb,1);

View File

@@ -11,7 +11,7 @@
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
last mod: $Id: vorbisfile.c 17012 2010-03-24 07:37:36Z xiphmont $
last mod: $Id: vorbisfile.c 17573 2010-10-27 14:53:59Z xiphmont $
********************************************************************/
@@ -451,8 +451,9 @@ static ogg_int64_t _initial_pcmoffset(OggVorbis_File *vf, vorbis_info *vi){
}
}
/* less than zero? This is a stream with samples trimmed off
the beginning, a normal occurrence; set the offset to zero */
/* less than zero? Either a corrupt file or a stream with samples
trimmed off the beginning, a normal occurrence; in both cases set
the offset to zero */
if(accumulated<0)accumulated=0;
return accumulated;
@@ -513,7 +514,7 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
vf->offsets[m+1]=end;
vf->offsets[m]=begin;
vf->pcmlengths[m*2+1]=endgran;
vf->pcmlengths[m*2+1]=(endgran<0?0:endgran);
}else{
@@ -533,8 +534,10 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
bisect=(searched+endsearched)/2;
}
ret=_seek_helper(vf,bisect);
if(ret)return(ret);
if(bisect != vf->offset){
ret=_seek_helper(vf,bisect);
if(ret)return(ret);
}
last=_get_next_page(vf,&og,-1);
if(last==OV_EREAD)return(OV_EREAD);
@@ -542,7 +545,7 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
endsearched=bisect;
if(last>=0)next=last;
}else{
searched=last+og.header_len+og.body_len;
searched=vf->offset;
}
}
@@ -588,7 +591,7 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
vf->pcmlengths[m*2+1]=searchgran;
vf->pcmlengths[m*2+2]=pcmoffset;
vf->pcmlengths[m*2+3]-=pcmoffset;
if(vf->pcmlengths[m*2+3]<0)vf->pcmlengths[m*2+3]=0;
}
return(0);
}
@@ -647,6 +650,7 @@ static int _open_seekable2(OggVorbis_File *vf){
vf->dataoffsets[0]=dataoffset;
vf->pcmlengths[0]=pcmoffset;
vf->pcmlengths[1]-=pcmoffset;
if(vf->pcmlengths[1]<0)vf->pcmlengths[1]=0;
return(ov_raw_seek(vf,dataoffset));
}
@@ -687,6 +691,8 @@ static int _fetch_and_process_packet(OggVorbis_File *vf,
/* process a packet if we can. */
if(vf->ready_state==INITSET){
int hs=vorbis_synthesis_halfrate_p(vf->vi);
while(1) {
ogg_packet op;
ogg_packet *op_ptr=(op_in?op_in:&op);
@@ -714,7 +720,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf,
if(oldsamples)return(OV_EFAULT);
vorbis_synthesis_blockin(&vf->vd,&vf->vb);
vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
vf->samptrack+=(vorbis_synthesis_pcmout(&vf->vd,NULL)<<hs);
vf->bittrack+=op_ptr->bytes*8;
}
@@ -743,7 +749,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)<<hs);
granulepos-=samples;
for(i=0;i<link;i++)
@@ -869,7 +875,7 @@ static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
return fseek(f,off,whence);
}
static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial,
long ibytes, ov_callbacks callbacks){
int offsettest=((f && callbacks.seek_func)?callbacks.seek_func(f,0,SEEK_CUR):-1);
long *serialno_list=NULL;
@@ -913,7 +919,7 @@ static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
for second stage of seekable stream open; this saves having to
seek/reread first link's serialnumber data then. */
vf->serialnos=_ogg_calloc(serialno_list_size+2,sizeof(*vf->serialnos));
vf->serialnos[0]=vf->current_serialno;
vf->serialnos[0]=vf->current_serialno=vf->os.serialno;
vf->serialnos[1]=serialno_list_size;
memcpy(vf->serialnos+2,serialno_list,serialno_list_size*sizeof(*vf->serialnos));
@@ -921,7 +927,6 @@ static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
vf->dataoffsets=_ogg_calloc(1,sizeof(*vf->dataoffsets));
vf->offsets[0]=0;
vf->dataoffsets[0]=vf->offset;
vf->current_serialno=vf->os.serialno;
vf->ready_state=PARTOPEN;
}
@@ -985,14 +990,14 @@ int ov_clear(OggVorbis_File *vf){
0) OK
*/
int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
ov_callbacks callbacks){
int ov_open_callbacks(void *f,OggVorbis_File *vf,
const char *initial,long ibytes,ov_callbacks callbacks){
int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
if(ret)return ret;
return _ov_open2(vf);
}
int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
int ov_open(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes){
ov_callbacks callbacks = {
(size_t (*)(void *, size_t, size_t, void *)) fread,
(int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
@@ -1003,7 +1008,7 @@ int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
}
int ov_fopen(char *path,OggVorbis_File *vf){
int ov_fopen(const char *path,OggVorbis_File *vf){
int ret;
FILE *f = fopen(path,"rb");
if(!f) return -1;
@@ -1020,17 +1025,22 @@ int ov_fopen(char *path,OggVorbis_File *vf){
int ov_halfrate(OggVorbis_File *vf,int flag){
int i;
if(vf->vi==NULL)return OV_EINVAL;
if(!vf->seekable)return OV_EINVAL;
if(vf->ready_state>=STREAMSET)
_decode_clear(vf); /* clear out stream state; later on libvorbis
will be able to swap this on the fly, but
for now dumping the decode machine is needed
to reinit the MDCT lookups. 1.1 libvorbis
is planned to be able to switch on the fly */
if(vf->ready_state>STREAMSET){
/* clear out stream state; dumping the decode machine is needed to
reinit the MDCT lookups. */
vorbis_dsp_clear(&vf->vd);
vorbis_block_clear(&vf->vb);
vf->ready_state=STREAMSET;
if(vf->pcm_offset>=0){
ogg_int64_t pos=vf->pcm_offset;
vf->pcm_offset=-1; /* make sure the pos is dumped if unseekable */
ov_pcm_seek(vf,pos);
}
}
for(i=0;i<vf->links;i++){
if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
ov_halfrate(vf,0);
if(flag) ov_halfrate(vf,0);
return OV_EINVAL;
}
}
@@ -1047,13 +1057,13 @@ int ov_halfrate_p(OggVorbis_File *vf){
seekability). Use ov_test_open to finish opening the file, else
ov_clear to close/free it. Same return codes as open. */
int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
ov_callbacks callbacks)
int ov_test_callbacks(void *f,OggVorbis_File *vf,
const char *initial,long ibytes,ov_callbacks callbacks)
{
return _ov_open1(f,vf,initial,ibytes,callbacks);
}
int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
int ov_test(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes){
ov_callbacks callbacks = {
(size_t (*)(void *, size_t, size_t, void *)) fread,
(int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
@@ -1226,6 +1236,12 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
if(pos<0 || pos>vf->end)return(OV_EINVAL);
/* is the seek position outside our current link [if any]? */
if(vf->ready_state>=STREAMSET){
if(pos<vf->offsets[vf->current_link] || pos>=vf->offsets[vf->current_link+1])
_decode_clear(vf); /* clear out stream state */
}
/* don't yet clear out decoding machine (if it's initialized), in
the case we're in the same link. Restart the decode lapping, and
let _fetch_and_process_packet deal with a potential bitstream
@@ -1285,7 +1301,7 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
/* We can't get a guaranteed correct pcm position out of the
last page in a stream because it might have a 'short'
granpos, which can only be detected in the presence of a
preceeding page. However, if the last page is also the first
preceding page. However, if the last page is also the first
page, the granpos rules of a first page take precedence. Not
only that, but for first==last, the EOS page must be treated
as if its a normal first page for the stream to open/play. */
@@ -1382,7 +1398,7 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
/* Page granularity seek (faster than sample granularity because we
don't do the last bit of decode to find a specific sample).
Seek to the last [granule marked] page preceeding the specified pos
Seek to the last [granule marked] page preceding the specified pos
location, such that decoding past the returned point will quickly
arrive at the requested position. */
int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
@@ -1402,7 +1418,7 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
}
/* search within the logical bitstream for the page with the highest
pcm_pos preceeding (or equal to) pos. There is a danger here;
pcm_pos preceding (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
would be an error condition) */
@@ -1427,12 +1443,14 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
bisect=begin +
(ogg_int64_t)((double)(target-begintime)*(end-begin)/(endtime-begintime))
- CHUNKSIZE;
if(bisect<=begin)
bisect=begin+1;
if(bisect<begin+CHUNKSIZE)
bisect=begin;
}
result=_seek_helper(vf,bisect);
if(result) goto seek_error;
if(bisect!=vf->offset){
result=_seek_helper(vf,bisect);
if(result) goto seek_error;
}
while(begin<end){
result=_get_next_page(vf,&og,end-vf->offset);
@@ -1485,7 +1503,7 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
}
/* found our page. seek to it, update pcm offset. Easier case than
raw_seek, don't keep packets preceeding granulepos. */
raw_seek, don't keep packets preceding granulepos. */
{
ogg_page og;
ogg_packet op;
@@ -1517,7 +1535,7 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
result=ogg_stream_packetpeek(&vf->os,&op);
if(result==0){
/* !!! the packet finishing this page originated on a
preceeding page. Keep fetching previous pages until we
preceding page. Keep fetching previous pages until we
get one with a granulepos or without the 'continued' flag
set. Then just use raw_seek for simplicity. */
@@ -1647,17 +1665,22 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
vf->samptrack=0.f;
/* discard samples until we reach the desired position. Crossing a
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);
{
/* note that halfrate could be set differently in each link, but
vorbisfile encoforces all links are set or unset */
int hs=vorbis_synthesis_halfrate_p(vf->vi);
while(vf->pcm_offset<((pos>>hs)<<hs)){
ogg_int64_t target=(pos-vf->pcm_offset)>>hs;
long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
if(samples>target)samples=target;
vorbis_synthesis_read(&vf->vd,samples);
vf->pcm_offset+=samples;
if(samples>target)samples=target;
vorbis_synthesis_read(&vf->vd,samples);
vf->pcm_offset+=samples<<hs;
if(samples<target)
if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
if(samples<target)
if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
}
}
return 0;
}
@@ -1848,6 +1871,7 @@ long ov_read_filter(OggVorbis_File *vf,char *buffer,int length,
void (*filter)(float **pcm,long channels,long samples,void *filter_param),void *filter_param){
int i,j;
int host_endian = host_is_big_endian();
int hs;
float **pcm;
long samples;
@@ -1971,7 +1995,8 @@ long ov_read_filter(OggVorbis_File *vf,char *buffer,int length,
}
vorbis_synthesis_read(&vf->vd,samples);
vf->pcm_offset+=samples;
hs=vorbis_synthesis_halfrate_p(vf->vi);
vf->pcm_offset+=(samples<<hs);
if(bitstream)*bitstream=vf->current_link;
return(samples*bytespersample);
}else{
@@ -2008,10 +2033,11 @@ long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
float **pcm;
long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
if(samples){
int hs=vorbis_synthesis_halfrate_p(vf->vi);
if(pcm_channels)*pcm_channels=pcm;
if(samples>length)samples=length;
vorbis_synthesis_read(&vf->vd,samples);
vf->pcm_offset+=samples;
vf->pcm_offset+=samples<<hs;
if(bitstream)*bitstream=vf->current_link;
return samples;