summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2009-10-08 08:55:59 +0200
committerEdward Hervey <bilboed@bilboed.com>2009-10-08 08:55:59 +0200
commit4cfe11d42c7fc0a7e1083fd1313c8229fd160fa4 (patch)
tree76bc18e8a2a643828fa795091a15568d652928f2 /plugins
parent9b17059deb4ebf40069a5ccf2141cddcac5298ea (diff)
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.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/elements/gstfilesrc.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c
index f1590890c6..a9f1be5590 100644
--- a/plugins/elements/gstfilesrc.c
+++ b/plugins/elements/gstfilesrc.c
@@ -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;
-
- /* 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;
-
- length = ret;
-
- GST_BUFFER_SIZE (buf) = length;
- GST_BUFFER_OFFSET (buf) = offset;
- GST_BUFFER_OFFSET_END (buf) = offset + length;
+ /* 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;
+
+ /* other files should eos if they read 0 and more was requested */
+ if (G_UNLIKELY (ret == 0 && length > 0))
+ goto eos;
+
+ length = ret;
+ 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 */