Commit fcd8a58d authored by Monty's avatar Monty

Patch iseeking example to continue if there's insufficient memory to allocate...

Patch iseeking example to continue if there's insufficient memory to allocate a verification buffer for excessively
large samples.

Also correct sample/time calculation to not overflow 64 bit math, again for
those excessively long samples



git-svn-id: https://svn.xiph.org/trunk/Tremor@17533 0101bb08-14d6-0310-b084-bc0e0c8e3800
parent 44ac4c42
......@@ -60,20 +60,22 @@ void _verify(OggVorbis_File *ov,
exit(1);
}
bread=ov_read(ov,buffer,4096,&dummy);
for(j=0;j<bread;j++){
if(buffer[j]!=bigassbuffer[j+pos*4]){
fprintf(stderr,"data position after seek doesn't match pcm position\n");
{
FILE *f=fopen("a.m","w");
for(j=0;j<bread;j++)fprintf(f,"%d\n",(int)buffer[j]);
fclose(f);
f=fopen("b.m","w");
for(j=0;j<bread;j++)fprintf(f,"%d\n",(int)bigassbuffer[j+pos*2]);
fclose(f);
if(bigassbuffer){
for(j=0;j<bread;j++){
if(buffer[j]!=bigassbuffer[j+pos*4]){
fprintf(stderr,"data position after seek doesn't match pcm position\n");
{
FILE *f=fopen("a.m","w");
for(j=0;j<bread;j++)fprintf(f,"%d\n",(int)buffer[j]);
fclose(f);
f=fopen("b.m","w");
for(j=0;j<bread;j++)fprintf(f,"%d\n",(int)bigassbuffer[j+pos*2]);
fclose(f);
}
exit(1);
}
exit(1);
}
}
}
......@@ -116,17 +118,21 @@ int main(){
pcmlength=ov_pcm_total(&ov,-1);
timelength=ov_time_total(&ov,-1);
bigassbuffer=malloc(pcmlength*4); /* w00t */
i=0;
while(i<pcmlength*4){
int ret=ov_read(&ov,bigassbuffer+i,pcmlength*4-i,&dummy);
if(ret<0)continue;
if(ret){
i+=ret;
}else{
pcmlength=i/4;
if(bigassbuffer){
i=0;
while(i<pcmlength*4){
int ret=ov_read(&ov,bigassbuffer+i,pcmlength*4-i,&dummy);
if(ret<0)continue;
if(ret){
i+=ret;
}else{
pcmlength=i/4;
}
fprintf(stderr,"\rloading.... [%ld left] ",
(long)(pcmlength*4-i));
}
fprintf(stderr,"\rloading.... [%ld left] ",
(long)(pcmlength*4-i));
}else{
fprintf(stderr,"\rfile too large to load into memory for read tests;\n\tonly verifying seek positioning...\n");
}
{
......@@ -154,7 +160,7 @@ int main(){
(long)pcmlength);
for(i=0;i<1000;i++){
ogg_int64_t val=rand()*pcmlength/RAND_MAX;
ogg_int64_t val=(double)rand()*pcmlength/RAND_MAX;
fprintf(stderr,"\r\t%d [pcm position %ld]... ",i,(long)val);
ret=ov_pcm_seek_page(&ov,val);
if(ret<0){
......@@ -173,7 +179,7 @@ int main(){
(long)pcmlength);
for(i=0;i<1000;i++){
ogg_int64_t val=rand()*pcmlength/RAND_MAX;
ogg_int64_t val=(double)rand()*pcmlength/RAND_MAX;
fprintf(stderr,"\r\t%d [pcm position %ld]... ",i,(long)val);
ret=ov_pcm_seek(&ov,val);
if(ret<0){
......@@ -197,7 +203,7 @@ int main(){
(long)timelength);
for(i=0;i<1000;i++){
ogg_int64_t val=rand()*timelength/RAND_MAX;
ogg_int64_t val=(double)rand()*timelength/RAND_MAX;
fprintf(stderr,"\r\t%d [time position %ld]... ",i,(long)val);
ret=ov_time_seek_page(&ov,val);
if(ret<0){
......@@ -216,7 +222,7 @@ int main(){
(long)timelength);
for(i=0;i<1000;i++){
ogg_int64_t val=rand()*timelength/RAND_MAX;
ogg_int64_t val=(double)rand()*timelength/RAND_MAX;
fprintf(stderr,"\r\t%d [time position %ld]... ",i,(long)val);
ret=ov_time_seek(&ov,val);
if(ret<0){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment