{
int ret;
GstBuffer *buf;
+ guint64 woffset;
if (G_UNLIKELY (src->read_position != offset)) {
off_t res;
}
/* No need to read anything if length is 0 */
- if (length > 0) {
+ GST_BUFFER_SIZE (buf) = 0;
+ GST_BUFFER_OFFSET (buf) = offset;
+ GST_BUFFER_OFFSET_END (buf) = offset;
+ woffset = 0;
+ while (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))
+ length, offset + woffset);
+ errno = 0;
+ ret = read (src->fd, GST_BUFFER_DATA (buf) + woffset, length);
+ if (G_UNLIKELY (ret < 0)) {
+ if (errno == EAGAIN || errno == EINTR)
+ continue;
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))
+ /* files should eos if they read 0 and more was requested */
+ if (G_UNLIKELY (ret == 0))
goto eos;
- length = ret;
- GST_BUFFER_SIZE (buf) = length;
- GST_BUFFER_OFFSET (buf) = offset;
- GST_BUFFER_OFFSET_END (buf) = offset + length;
+ length -= ret;
+ woffset += ret;
+ GST_BUFFER_SIZE (buf) += ret;
+ GST_BUFFER_OFFSET_END (buf) += ret;
- src->read_position += length;
+ src->read_position += ret;
}
*buffer = buf;
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
-unexpected_eos:
- {
- GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
- ("unexpected end of file."));
- gst_buffer_unref (buf);
- return GST_FLOW_ERROR;
- }
eos:
{
- GST_DEBUG ("non-regular file hits EOS");
+ GST_DEBUG ("EOS");
gst_buffer_unref (buf);
return GST_FLOW_UNEXPECTED;
}