[xiph-commits] r17533 - trunk/Tremor
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Wed Oct 13 21:25:03 PDT 2010
Author: xiphmont
Date: 2010-10-13 21:25:03 -0700 (Wed, 13 Oct 2010)
New Revision: 17533
Modified:
trunk/Tremor/iseeking_example.c
Log:
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
Modified: trunk/Tremor/iseeking_example.c
===================================================================
--- trunk/Tremor/iseeking_example.c 2010-10-14 01:45:30 UTC (rev 17532)
+++ trunk/Tremor/iseeking_example.c 2010-10-14 04:25:03 UTC (rev 17533)
@@ -60,20 +60,22 @@
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 @@
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 @@
(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 @@
(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 @@
(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 @@
(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){
More information about the commits
mailing list