#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#ifdef HAVE_MMAP
#include <sys/mman.h>
+#endif
#include <errno.h>
#include <string.h>
gst_pad_set_formats_function (src->srcpad, gst_filesrc_get_formats);
gst_element_add_pad (GST_ELEMENT (src), src->srcpad);
+#ifdef HAVE_MMAP
src->pagesize = getpagesize ();
+#endif
src->filename = NULL;
src->fd = 0;
src->mapbuf = NULL;
src->mapsize = DEFAULT_MMAPSIZE; /* default is 4MB */
-
- src->seek_happened = FALSE;
}
static void
g_object_notify (G_OBJECT (src), "touch");
break;
default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
}
}
+#ifdef HAVE_MMAP
static void
gst_filesrc_free_parent_mmap (GstBuffer * buf)
{
GST_BUFFER_DATA (buf) = NULL;
}
+#endif
+#ifdef HAVE_MMAP
static GstBuffer *
gst_filesrc_map_region (GstFileSrc * src, off_t offset, size_t size)
{
return buf;
}
+#endif
+#ifdef HAVE_MMAP
static GstBuffer *
gst_filesrc_map_small_region (GstFileSrc * src, off_t offset, size_t size)
{
return gst_filesrc_map_region (src, offset, size);
}
+#endif
+#ifdef HAVE_MMAP
/**
* gst_filesrc_get_mmap:
* @pad: #GstPad to push a buffer from
src->curoffset += GST_BUFFER_SIZE (buf);
return buf;
}
+#endif
static GstBuffer *
gst_filesrc_get_read (GstFileSrc * src)
return GST_DATA (gst_event_new_flush ());
}
/* check for seek */
- if (src->seek_happened) {
+ if (src->need_discont) {
GstEvent *event;
- src->seek_happened = FALSE;
+ src->need_discont = FALSE;
GST_DEBUG_OBJECT (src, "sending discont");
event =
gst_event_new_discontinuous (FALSE, GST_FORMAT_BYTES, src->curoffset,
return GST_DATA (gst_event_new (GST_EVENT_EOS));
}
}
-
+#ifdef HAVE_MMAP
if (src->using_mmap) {
return GST_DATA (gst_filesrc_get_mmap (src));
} else {
return GST_DATA (gst_filesrc_get_read (src));
}
+#else
+ return GST_DATA (gst_filesrc_get_read (src));
+#endif
}
/* TRUE if the filesize of the file was updated */
/* find the file length */
src->filelen = stat_results.st_size;
+ src->using_mmap = FALSE;
+#ifdef HAVE_MMAP
/* allocate the first mmap'd region */
src->mapbuf = gst_filesrc_map_region (src, 0, src->mapsize);
- if (src->mapbuf == NULL) {
- src->using_mmap = FALSE;
- } else {
+ if (src->mapbuf != NULL) {
src->using_mmap = TRUE;
}
+#endif
+
src->curoffset = 0;
if (!gst_filesrc_open_file (GST_FILESRC (element)))
return GST_STATE_FAILURE;
}
+ src->need_discont = TRUE;
break;
case GST_STATE_PAUSED_TO_READY:
if (GST_FLAG_IS_SET (element, GST_FILESRC_OPEN))
gst_filesrc_close_file (GST_FILESRC (element));
- src->seek_happened = TRUE;
+ src->need_discont = TRUE;
break;
default:
break;
switch (GST_EVENT_SEEK_METHOD (event)) {
case GST_SEEK_METHOD_SET:
- if (offset > src->filelen && (!gst_filesrc_check_filesize (src)
- || offset > src->filelen)) {
+ if (offset < 0 ||
+ (offset > src->filelen && (!gst_filesrc_check_filesize (src)
+ || offset > src->filelen))) {
goto error;
}
src->curoffset = offset;
goto error;
break;
}
- src->seek_happened = TRUE;
+ src->need_discont = TRUE;
src->need_flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
break;
}