Slightly better read function
authorWim Taymans <wim.taymans@gmail.com>
Sun, 19 Jan 2003 20:11:13 +0000 (20:11 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Sun, 19 Jan 2003 20:11:13 +0000 (20:11 +0000)
Original commit message from CVS:
Slightly better read function

ext/vorbis/vorbisfile.c

index 628ace4..d3a031f 100644 (file)
@@ -225,7 +225,7 @@ gst_vorbisfile_init (VorbisFile * vorbisfile)
 static size_t
 gst_vorbisfile_read (void *ptr, size_t size, size_t nmemb, void *datasource)
 {
-  guint32 got_bytes = 0;
+  guint32 got_bytes;
   guint8 *data;
   size_t read_size = size * nmemb;
 
@@ -243,9 +243,10 @@ gst_vorbisfile_read (void *ptr, size_t size, size_t nmemb, void *datasource)
   if (read_size == 0 || vorbisfile->eos)
     return 0;
   
-  while (got_bytes == 0) {
+  do {
     got_bytes = gst_bytestream_peek_bytes (vorbisfile->bs, &data, read_size);
-    if (got_bytes < read_size) {
+
+    if (got_bytes == 0) {
       GstEvent *event;
       guint32 avail;
     
@@ -255,11 +256,8 @@ gst_vorbisfile_read (void *ptr, size_t size, size_t nmemb, void *datasource)
        case GST_EVENT_EOS:
          GST_DEBUG (0, "eos");
           vorbisfile->eos = TRUE;
-          if (avail == 0) {
-            gst_event_unref (event);
-            return 0;
-         }
-         break;
+          gst_event_unref (event);
+          goto done;
        case GST_EVENT_DISCONTINUOUS:
          GST_DEBUG (0, "discont");
          vorbisfile->need_discont = TRUE;
@@ -267,18 +265,15 @@ gst_vorbisfile_read (void *ptr, size_t size, size_t nmemb, void *datasource)
           break;
       }
       gst_event_unref (event);
-      if (avail > 0) 
-        got_bytes = gst_bytestream_peek_bytes (vorbisfile->bs, &data, avail);
-      else
-       got_bytes = 0;
     }
-  }
+  } while (got_bytes == 0);
 
   memcpy (ptr, data, got_bytes);
   gst_bytestream_flush_fast (vorbisfile->bs, got_bytes);
 
   vorbisfile->offset += got_bytes;
 
+done:
   return got_bytes / size;
 }