fix a bug where a fclose() was called after an ov_clear()
authorkoda
Sun, 19 Jul 2009 00:52:09 +0000
changeset 2265 eae64600fb69
parent 2264 b8fff48235de
child 2266 289dc8e51210
fix a bug where a fclose() was called after an ov_clear() moved to ov_open_callback in hope to see less windows linking problems
openalbridge/loaders.c
openalbridge/oggvorbis.h
--- a/openalbridge/loaders.c	Sat Jul 18 21:38:14 2009 +0000
+++ b/openalbridge/loaders.c	Sun Jul 19 00:52:09 2009 +0000
@@ -125,7 +125,7 @@
         return AL_TRUE;
     }
     
-    
+
     int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) {
         /*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */
         FILE		*oggFile;		/*ogg handle*/
@@ -137,10 +137,15 @@
         int i;
         vorbis_comment	*vorbisComment;	/*other less useful data*/
 #endif
-        
+
         oggFile = Fopen(filename, "rb");
-        result = ov_open(oggFile, &oggStream, NULL, 0);	/*TODO: check returning value of result*/
-        
+	result = ov_open_callbacks(oggFile, &oggStream, NULL, 0, NULL);
+	if (result < 0) {
+		fprintf (stderr, "ERROR: ov_open_callbacks failed with %X", result) 
+		fclose(oggFile);
+		return -1;
+	}
+
         vorbisInfo = ov_info(&oggStream, -1);
         pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels;	
         
@@ -171,35 +176,37 @@
                 *format = AL_FORMAT_STEREO16;
             else {
                 fprintf(stderr, "ERROR: wrong OGG header - channel value (%d)\n", vorbisInfo->channels);
-                ov_clear (&oggStream);
+                ov_clear(&oggStream);
                 fclose(oggFile);
                 return AL_FALSE;
             }
         }
         
-        while(size < pcm_length) {
+        while (size < pcm_length) {
             /*ov_read decodes the ogg stream and storse the pcm in data*/
             result = ov_read (&oggStream, *data + size, pcm_length - size, 0, 2, 1, &section);
-            if(result > 0) {
+            if (result > 0) {
                 size += result;
             } else {
                 if (result == 0)
                     break;
                 else { 
                     fprintf(stderr, "ERROR: end of file from OGG stream\n");
-                    ov_clear (&oggStream);
+                    ov_clear(&oggStream);
                     fclose(oggFile);
                     return AL_FALSE;
                 }
             }
         }
         
-        /*records the last fields*/
+        /*set the last fields*/
         *bitsize = size;
         *freq    = vorbisInfo->rate;
         
-        ov_clear (&oggStream);
-        fclose (oggFile);
+	/*cleaning time*/
+        ov_clear(&oggStream);
+	fclose(oggFile);
+
         return AL_TRUE;
     }
     
--- a/openalbridge/oggvorbis.h	Sat Jul 18 21:38:14 2009 +0000
+++ b/openalbridge/oggvorbis.h	Sun Jul 19 00:52:09 2009 +0000
@@ -31,8 +31,7 @@
     int channels;
     long rate;
     /* The below bitrate declarations are *hints*.
-     Combinations of the three values carry the following implications:
-     all three set to the same value: implies a fixed rate bitstream
+     Combinations of the three values carry the following implications: all three set to the same value: implies a fixed rate bitstream
      only nominal set: implies a VBR stream that averages the nominal bitrate.  No hard upper/lower limit
      upper and or lower set: implies a VBR bitstream that obeys the bitrate limits. nominal may also be set to give a nominal rate.
      none set: the coder does not care to speculate. */
@@ -54,10 +53,9 @@
     long    body_storage;          /* storage elements allocated */
     long    body_fill;             /* elements stored; fill mark */
     long    body_returned;         /* elements of fill returned */
-    int     *lacing_vals;      /* The values that will go to the segment table */
+    int     *lacing_vals;      	   /* The values that will go to the segment table */
     ogg_int64_t *granule_vals; 
-    /* granulepos values for headers. Not compact
-     this way, but it is simple coupled to the lacing fifo */
+    /* granulepos values for headers. Not compact this way, but it is simple coupled to the lacing fifo */
     long    lacing_storage;
     long    lacing_fill;
     long    lacing_packet;
@@ -172,5 +170,6 @@
 extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
 extern vorbis_comment *ov_comment(OggVorbis_File *f, int num);
 extern int ov_clear(OggVorbis_File *vf);
+extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf, char *initial, long ibytes, ov_callbacks callbacks);
 
 #endif /*_OGGVORBIS_H*/