Slightly better read function

Original commit message from CVS:
Slightly better read function
This commit is contained in:
Wim Taymans 2003-01-19 20:11:13 +00:00
parent 7ad0c4a30f
commit dc7a0dc712

View file

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