diff --git a/ChangeLog b/ChangeLog index bc13f15636..cbf48c431b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-09-12 Steve Lhomme + * gst/elements/gstfilesrc.c: (gst_filesrc_get_read) + * gst/elements/gstfilesrc.h: + fix the pb of seeking when mmap is not used + 2005-09-09 Steve Lhomme * gst/gstpad.c: replace g_alloca by more portable alternatives diff --git a/common b/common index 00cc4f5af9..30a1fc4dc2 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 00cc4f5af95a15be55b8c1b3eed09f4738412f91 +Subproject commit 30a1fc4dc24133cc411e0232af87790ae2f845b2 diff --git a/gst/elements/gstfilesrc.c b/gst/elements/gstfilesrc.c index 5126fa8f20..db3b5d40f1 100644 --- a/gst/elements/gstfilesrc.c +++ b/gst/elements/gstfilesrc.c @@ -108,8 +108,8 @@ GstElementDetails gst_filesrc_details = GST_ELEMENT_DETAILS ("File Source", "Read from arbitrary point in a file", "Erik Walthinsen "); -#define DEFAULT_BLOCKSIZE 4*1024 -#define DEFAULT_MMAPSIZE 4*1024*1024 +#define DEFAULT_BLOCKSIZE 4*1024 +#define DEFAULT_MMAPSIZE 4*1024*1024 /* FileSrc signals and args */ enum @@ -268,6 +268,7 @@ gst_filesrc_init (GstFileSrc * src) src->uri = NULL; src->curoffset = 0; + src->lastoffset = 0; src->block_size = DEFAULT_BLOCKSIZE; src->touch = FALSE; @@ -659,6 +660,15 @@ gst_filesrc_get_read (GstFileSrc * src) buf = gst_buffer_new_and_alloc (readsize); g_return_val_if_fail (buf != NULL, NULL); + GST_LOG_OBJECT (src, "Seeking at location %d", src->curoffset); + if (src->lastoffset != src->curoffset) { + ret = lseek (src->fd, src->curoffset, SEEK_SET); + if (ret < 0) { + GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL), GST_ERROR_SYSTEM); + return NULL; + } + } + GST_LOG_OBJECT (src, "Reading %d bytes", readsize); ret = read (src->fd, GST_BUFFER_DATA (buf), readsize); if (ret < 0) { @@ -685,6 +695,7 @@ gst_filesrc_get_read (GstFileSrc * src) GST_BUFFER_OFFSET (buf) = src->curoffset; GST_BUFFER_OFFSET_END (buf) = src->curoffset + readsize; src->curoffset += readsize; + src->lastoffset = src->curoffset; return GST_DATA (buf); } @@ -821,6 +832,7 @@ gst_filesrc_open_file (GstFileSrc * src) #endif src->curoffset = 0; + src->lastoffset = 0; GST_FLAG_SET (src, GST_FILESRC_OPEN); } @@ -840,6 +852,7 @@ gst_filesrc_close_file (GstFileSrc * src) src->fd = 0; src->filelen = 0; src->curoffset = 0; + src->lastoffset = 0; src->is_regular = FALSE; if (src->mapbuf) { diff --git a/gst/elements/gstfilesrc.h b/gst/elements/gstfilesrc.h index 17230088c4..a5f2183fc3 100644 --- a/gst/elements/gstfilesrc.h +++ b/gst/elements/gstfilesrc.h @@ -63,6 +63,7 @@ struct _GstFileSrc { off_t filelen; /* what's the file length?*/ off_t curoffset; /* current offset in file*/ + off_t lastoffset; /* last offset seen in file*/ off_t block_size; /* bytes per read */ gboolean touch; /* whether to touch every page */ gboolean using_mmap; /* whether we opened it with mmap */ diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index 5126fa8f20..db3b5d40f1 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -108,8 +108,8 @@ GstElementDetails gst_filesrc_details = GST_ELEMENT_DETAILS ("File Source", "Read from arbitrary point in a file", "Erik Walthinsen "); -#define DEFAULT_BLOCKSIZE 4*1024 -#define DEFAULT_MMAPSIZE 4*1024*1024 +#define DEFAULT_BLOCKSIZE 4*1024 +#define DEFAULT_MMAPSIZE 4*1024*1024 /* FileSrc signals and args */ enum @@ -268,6 +268,7 @@ gst_filesrc_init (GstFileSrc * src) src->uri = NULL; src->curoffset = 0; + src->lastoffset = 0; src->block_size = DEFAULT_BLOCKSIZE; src->touch = FALSE; @@ -659,6 +660,15 @@ gst_filesrc_get_read (GstFileSrc * src) buf = gst_buffer_new_and_alloc (readsize); g_return_val_if_fail (buf != NULL, NULL); + GST_LOG_OBJECT (src, "Seeking at location %d", src->curoffset); + if (src->lastoffset != src->curoffset) { + ret = lseek (src->fd, src->curoffset, SEEK_SET); + if (ret < 0) { + GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL), GST_ERROR_SYSTEM); + return NULL; + } + } + GST_LOG_OBJECT (src, "Reading %d bytes", readsize); ret = read (src->fd, GST_BUFFER_DATA (buf), readsize); if (ret < 0) { @@ -685,6 +695,7 @@ gst_filesrc_get_read (GstFileSrc * src) GST_BUFFER_OFFSET (buf) = src->curoffset; GST_BUFFER_OFFSET_END (buf) = src->curoffset + readsize; src->curoffset += readsize; + src->lastoffset = src->curoffset; return GST_DATA (buf); } @@ -821,6 +832,7 @@ gst_filesrc_open_file (GstFileSrc * src) #endif src->curoffset = 0; + src->lastoffset = 0; GST_FLAG_SET (src, GST_FILESRC_OPEN); } @@ -840,6 +852,7 @@ gst_filesrc_close_file (GstFileSrc * src) src->fd = 0; src->filelen = 0; src->curoffset = 0; + src->lastoffset = 0; src->is_regular = FALSE; if (src->mapbuf) { diff --git a/plugins/elements/gstfilesrc.h b/plugins/elements/gstfilesrc.h index 17230088c4..a5f2183fc3 100644 --- a/plugins/elements/gstfilesrc.h +++ b/plugins/elements/gstfilesrc.h @@ -63,6 +63,7 @@ struct _GstFileSrc { off_t filelen; /* what's the file length?*/ off_t curoffset; /* current offset in file*/ + off_t lastoffset; /* last offset seen in file*/ off_t block_size; /* bytes per read */ gboolean touch; /* whether to touch every page */ gboolean using_mmap; /* whether we opened it with mmap */