plugins/gstfilesrc: Make a fast-path for length == 0 buffer creation.

If the requested length is 0, we don't need to read anything from the file.
This commit is contained in:
Edward Hervey 2009-10-08 08:55:59 +02:00
parent 9b17059deb
commit 4cfe11d42c

View file

@ -835,30 +835,32 @@ gst_file_src_create_read (GstFileSrc * src, guint64 offset, guint length,
return GST_FLOW_ERROR;
}
GST_LOG_OBJECT (src, "Reading %d bytes at offset 0x%" G_GINT64_MODIFIER "x",
length, offset);
ret = read (src->fd, GST_BUFFER_DATA (buf), length);
if (G_UNLIKELY (ret < 0))
goto could_not_read;
/* No need to read anything if length is 0 */
if (length > 0) {
GST_LOG_OBJECT (src, "Reading %d bytes at offset 0x%" G_GINT64_MODIFIER "x",
length, offset);
ret = read (src->fd, GST_BUFFER_DATA (buf), length);
if (G_UNLIKELY (ret < 0))
goto could_not_read;
/* seekable regular files should have given us what we expected */
if (G_UNLIKELY ((guint) ret < length && src->seekable))
goto unexpected_eos;
/* seekable regular files should have given us what we expected */
if (G_UNLIKELY ((guint) ret < length && src->seekable))
goto unexpected_eos;
/* other files should eos if they read 0 and more was requested */
if (G_UNLIKELY (ret == 0 && length > 0))
goto eos;
/* other files should eos if they read 0 and more was requested */
if (G_UNLIKELY (ret == 0 && length > 0))
goto eos;
length = ret;
length = ret;
GST_BUFFER_SIZE (buf) = length;
GST_BUFFER_OFFSET (buf) = offset;
GST_BUFFER_OFFSET_END (buf) = offset + length;
GST_BUFFER_SIZE (buf) = length;
GST_BUFFER_OFFSET (buf) = offset;
GST_BUFFER_OFFSET_END (buf) = offset + length;
src->read_position += length;
}
*buffer = buf;
src->read_position += length;
return GST_FLOW_OK;
/* ERROR */