gst/elements/gstfilesrc.c: (gst_filesrc_get_read)

Original commit message from CVS:
* gst/elements/gstfilesrc.c: (gst_filesrc_get_read)
* gst/elements/gstfilesrc.h:
fix the pb of seeking when mmap is not used
This commit is contained in:
Steve Lhomme 2005-09-12 15:37:50 +00:00
parent b744a3d270
commit 6edf71e0c8
6 changed files with 38 additions and 5 deletions

View file

@ -1,3 +1,8 @@
2005-09-12 Steve Lhomme <steve.lhomme@free.fr>
* 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 <steve.lhomme@free.fr>
* gst/gstpad.c:
replace g_alloca by more portable alternatives

2
common

@ -1 +1 @@
Subproject commit 00cc4f5af95a15be55b8c1b3eed09f4738412f91
Subproject commit 30a1fc4dc24133cc411e0232af87790ae2f845b2

View file

@ -108,8 +108,8 @@ GstElementDetails gst_filesrc_details = GST_ELEMENT_DETAILS ("File Source",
"Read from arbitrary point in a file",
"Erik Walthinsen <omega@cse.ogi.edu>");
#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) {

View file

@ -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 */

View file

@ -108,8 +108,8 @@ GstElementDetails gst_filesrc_details = GST_ELEMENT_DETAILS ("File Source",
"Read from arbitrary point in a file",
"Erik Walthinsen <omega@cse.ogi.edu>");
#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) {

View file

@ -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 */