2001-08-22 04:30:27 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstfilesrc.c:
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#include <gst/gst.h>
|
2001-12-12 06:08:44 +00:00
|
|
|
#include "gstfilesrc.h"
|
|
|
|
|
2001-12-15 22:59:24 +00:00
|
|
|
#include <stdio.h>
|
2001-08-22 04:30:27 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2004-05-07 02:36:28 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2001-08-22 04:30:27 +00:00
|
|
|
#include <unistd.h>
|
2004-05-07 02:36:28 +00:00
|
|
|
#endif
|
2004-04-13 22:18:36 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2001-08-22 04:30:27 +00:00
|
|
|
#include <sys/mman.h>
|
2004-04-13 22:18:36 +00:00
|
|
|
#endif
|
2001-10-17 10:21:27 +00:00
|
|
|
#include <errno.h>
|
2001-12-22 21:18:17 +00:00
|
|
|
#include <string.h>
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-01-18 21:36:20 +00:00
|
|
|
#include "../gst-i18n-lib.h"
|
|
|
|
|
2004-05-07 02:36:28 +00:00
|
|
|
/* FIXME we should be using glib for this */
|
|
|
|
#ifndef S_ISREG
|
|
|
|
#define S_ISREG(mode) ((mode)&_S_IFREG)
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(mode) ((mode)&_S_IFDIR)
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISSOCK
|
|
|
|
#define S_ISSOCK(x) (0)
|
|
|
|
#endif
|
2004-07-12 21:57:35 +00:00
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY (0)
|
|
|
|
#endif
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GStreamer Default File Source
|
|
|
|
* Theory of Operation
|
|
|
|
*
|
|
|
|
* This source uses mmap(2) to efficiently load data from a file.
|
|
|
|
* To do this without seriously polluting the applications' memory
|
|
|
|
* space, it must do so in smaller chunks, say 1-4MB at a time.
|
|
|
|
* Buffers are then subdivided from these mmap'd chunks, to directly
|
|
|
|
* make use of the mmap.
|
|
|
|
*
|
|
|
|
* To handle refcounting so that the mmap can be freed at the appropriate
|
|
|
|
* time, a buffer will be created for each mmap'd region, and all new
|
|
|
|
* buffers will be sub-buffers of this top-level buffer. As they are
|
|
|
|
* freed, the refcount goes down on the mmap'd buffer and its free()
|
|
|
|
* function is called, which will call munmap(2) on itself.
|
|
|
|
*
|
|
|
|
* If a buffer happens to cross the boundaries of an mmap'd region, we
|
|
|
|
* have to decide whether it's more efficient to copy the data into a
|
|
|
|
* new buffer, or mmap() just that buffer. There will have to be a
|
|
|
|
* breakpoint size to determine which will be done. The mmap() size
|
|
|
|
* has a lot to do with this as well, because you end up in double-
|
|
|
|
* jeopardy: the larger the outgoing buffer, the more data to copy when
|
|
|
|
* it overlaps, *and* the more frequently you'll have buffers that *do*
|
|
|
|
* overlap.
|
|
|
|
*
|
|
|
|
* Seeking is another tricky aspect to do efficiently. The initial
|
|
|
|
* implementation of this source won't make use of these features, however.
|
|
|
|
* The issue is that if an application seeks backwards in a file, *and*
|
|
|
|
* that region of the file is covered by an mmap that hasn't been fully
|
|
|
|
* deallocated, we really should re-use it. But keeping track of these
|
|
|
|
* regions is tricky because we have to lock the structure that holds
|
|
|
|
* them. We need to settle on a locking primitive (GMutex seems to be
|
|
|
|
* a really good option...), then we can do that.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_filesrc_debug);
|
2003-06-29 14:05:49 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_filesrc_debug
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GstElementDetails gst_filesrc_details = GST_ELEMENT_DETAILS ("File Source",
|
|
|
|
"Source/File",
|
|
|
|
"Read from arbitrary point in a file",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2002-11-21 23:52:30 +00:00
|
|
|
#define DEFAULT_BLOCKSIZE 4*1024
|
|
|
|
#define DEFAULT_MMAPSIZE 4*1024*1024
|
|
|
|
|
2001-08-22 04:30:27 +00:00
|
|
|
/* FileSrc signals and args */
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-08-22 04:30:27 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-08-22 04:30:27 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_LOCATION,
|
2001-08-22 19:54:08 +00:00
|
|
|
ARG_FD,
|
2001-08-22 04:30:27 +00:00
|
|
|
ARG_BLOCKSIZE,
|
2002-11-21 23:52:30 +00:00
|
|
|
ARG_MMAPSIZE,
|
2004-01-30 20:48:13 +00:00
|
|
|
ARG_TOUCH
|
2001-08-22 04:30:27 +00:00
|
|
|
};
|
|
|
|
|
2004-02-04 19:38:33 +00:00
|
|
|
static const GstEventMask *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_get_event_mask (GstPad * pad)
|
2004-02-04 19:38:33 +00:00
|
|
|
{
|
|
|
|
static const GstEventMask masks[] = {
|
2004-03-13 15:27:01 +00:00
|
|
|
{GST_EVENT_SEEK, GST_SEEK_METHOD_CUR |
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_SEEK_METHOD_SET | GST_SEEK_METHOD_END | GST_SEEK_FLAG_FLUSH},
|
2004-03-13 15:27:01 +00:00
|
|
|
{GST_EVENT_FLUSH, 0},
|
|
|
|
{GST_EVENT_SIZE, 0},
|
|
|
|
{0, 0}
|
2004-02-04 19:38:33 +00:00
|
|
|
};
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2004-02-04 19:38:33 +00:00
|
|
|
return masks;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GstQueryType *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_get_query_types (GstPad * pad)
|
2004-02-04 19:38:33 +00:00
|
|
|
{
|
|
|
|
static const GstQueryType types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
|
|
|
0
|
|
|
|
};
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2004-02-04 19:38:33 +00:00
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GstFormat *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_get_formats (GstPad * pad)
|
2004-02-04 19:38:33 +00:00
|
|
|
{
|
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
0,
|
|
|
|
};
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2004-02-04 19:38:33 +00:00
|
|
|
return formats;
|
|
|
|
}
|
2002-07-30 19:19:15 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_filesrc_dispose (GObject * object);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_filesrc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_filesrc_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static gboolean gst_filesrc_check_filesize (GstFileSrc * src);
|
|
|
|
static GstData *gst_filesrc_get (GstPad * pad);
|
|
|
|
static gboolean gst_filesrc_srcpad_event (GstPad * pad, GstEvent * event);
|
|
|
|
static gboolean gst_filesrc_srcpad_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static GstElementStateReturn gst_filesrc_change_state (GstElement * element);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_filesrc_uri_handler_init (gpointer g_iface,
|
|
|
|
gpointer iface_data);
|
2003-11-24 03:21:54 +00:00
|
|
|
|
2004-01-08 04:10:18 +00:00
|
|
|
static void
|
|
|
|
_do_init (GType filesrc_type)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2004-01-08 04:10:18 +00:00
|
|
|
static const GInterfaceInfo urihandler_info = {
|
|
|
|
gst_filesrc_uri_handler_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_type_add_interface_static (filesrc_type, GST_TYPE_URI_HANDLER,
|
|
|
|
&urihandler_info);
|
2004-01-08 04:10:18 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_filesrc_debug, "filesrc", 0, "filesrc element");
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstFileSrc, gst_filesrc, GstElement, GST_TYPE_ELEMENT,
|
|
|
|
_do_init);
|
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
static void
|
|
|
|
gst_filesrc_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (gstelement_class, &gst_filesrc_details);
|
|
|
|
}
|
2001-08-22 04:30:27 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_class_init (GstFileSrcClass * klass)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2003-10-31 19:32:47 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-08-22 19:54:08 +00:00
|
|
|
|
2002-11-21 23:52:30 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FD,
|
2004-03-13 15:27:01 +00:00
|
|
|
g_param_spec_int ("fd", "File-descriptor",
|
2004-03-15 19:27:17 +00:00
|
|
|
"File-descriptor for the file being mmap()d", 0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READABLE));
|
2002-11-21 23:52:30 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOCATION,
|
2004-03-13 15:27:01 +00:00
|
|
|
g_param_spec_string ("location", "File Location",
|
2004-03-15 19:27:17 +00:00
|
|
|
"Location of the file to read", NULL, G_PARAM_READWRITE));
|
2002-11-21 23:52:30 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BLOCKSIZE,
|
2004-03-13 15:27:01 +00:00
|
|
|
g_param_spec_ulong ("blocksize", "Block size",
|
2004-03-15 19:27:17 +00:00
|
|
|
"Size in bytes to read per buffer", 1, G_MAXULONG, DEFAULT_BLOCKSIZE,
|
|
|
|
G_PARAM_READWRITE));
|
2002-11-21 23:52:30 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MMAPSIZE,
|
2004-03-13 15:27:01 +00:00
|
|
|
g_param_spec_ulong ("mmapsize", "mmap() Block Size",
|
2004-03-15 19:27:17 +00:00
|
|
|
"Size in bytes of mmap()d regions", 0, G_MAXULONG, DEFAULT_MMAPSIZE,
|
|
|
|
G_PARAM_READWRITE));
|
2002-11-21 23:52:30 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TOUCH,
|
2004-03-13 15:27:01 +00:00
|
|
|
g_param_spec_boolean ("touch", "Touch read data",
|
2004-03-15 19:27:17 +00:00
|
|
|
"Touch data to force disk read", FALSE, G_PARAM_READWRITE));
|
2001-08-22 19:54:08 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gobject_class->dispose = gst_filesrc_dispose;
|
|
|
|
gobject_class->set_property = gst_filesrc_set_property;
|
|
|
|
gobject_class->get_property = gst_filesrc_get_property;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_filesrc_change_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_init (GstFileSrc * src)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
|
|
|
src->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
2002-05-26 21:54:27 +00:00
|
|
|
gst_pad_set_get_function (src->srcpad, gst_filesrc_get);
|
|
|
|
gst_pad_set_event_function (src->srcpad, gst_filesrc_srcpad_event);
|
2002-07-24 21:08:43 +00:00
|
|
|
gst_pad_set_event_mask_function (src->srcpad, gst_filesrc_get_event_mask);
|
2002-05-26 21:54:27 +00:00
|
|
|
gst_pad_set_query_function (src->srcpad, gst_filesrc_srcpad_query);
|
2002-07-24 21:08:43 +00:00
|
|
|
gst_pad_set_query_type_function (src->srcpad, gst_filesrc_get_query_types);
|
|
|
|
gst_pad_set_formats_function (src->srcpad, gst_filesrc_get_formats);
|
2001-08-22 04:30:27 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (src), src->srcpad);
|
|
|
|
|
2004-04-14 01:38:27 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2004-03-13 15:27:01 +00:00
|
|
|
src->pagesize = getpagesize ();
|
2004-04-14 01:38:27 +00:00
|
|
|
#endif
|
2001-08-22 19:54:08 +00:00
|
|
|
|
2001-08-22 04:30:27 +00:00
|
|
|
src->filename = NULL;
|
|
|
|
src->fd = 0;
|
|
|
|
src->filelen = 0;
|
2004-03-21 03:22:55 +00:00
|
|
|
src->uri = NULL;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
src->curoffset = 0;
|
2002-11-21 23:52:30 +00:00
|
|
|
src->block_size = DEFAULT_BLOCKSIZE;
|
|
|
|
src->touch = FALSE;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
src->mapbuf = NULL;
|
2004-03-15 19:27:17 +00:00
|
|
|
src->mapsize = DEFAULT_MMAPSIZE; /* default is 4MB */
|
2004-04-21 14:51:27 +00:00
|
|
|
|
|
|
|
src->is_regular = FALSE;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
2001-12-28 15:19:38 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_dispose (GObject * object)
|
2001-12-28 15:19:38 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src;
|
|
|
|
|
|
|
|
src = GST_FILESRC (object);
|
|
|
|
|
2004-03-21 03:22:55 +00:00
|
|
|
g_free (src->filename);
|
|
|
|
g_free (src->uri);
|
|
|
|
|
|
|
|
/* dispose may be called multiple times */
|
|
|
|
src->filename = NULL;
|
|
|
|
src->uri = NULL;
|
2001-12-28 15:19:38 +00:00
|
|
|
|
2004-03-21 03:22:55 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2001-12-28 15:19:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_set_location (GstFileSrc * src, const gchar * location)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
/* the element must be stopped in order to do this */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (GST_STATE (src) != GST_STATE_READY && GST_STATE (src) != GST_STATE_NULL)
|
2003-11-24 03:21:54 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2004-03-21 03:22:55 +00:00
|
|
|
g_free (src->filename);
|
|
|
|
g_free (src->uri);
|
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
/* clear the filename if we get a NULL (is that possible?) */
|
|
|
|
if (location == NULL) {
|
|
|
|
src->filename = NULL;
|
|
|
|
src->uri = NULL;
|
|
|
|
} else {
|
|
|
|
src->filename = g_strdup (location);
|
|
|
|
src->uri = gst_uri_construct ("file", src->filename);
|
|
|
|
}
|
|
|
|
g_object_notify (G_OBJECT (src), "location");
|
|
|
|
gst_uri_handler_new_uri (GST_URI_HANDLER (src), src->uri);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_FILESRC (object));
|
|
|
|
|
|
|
|
src = GST_FILESRC (object);
|
|
|
|
|
2001-08-22 19:54:08 +00:00
|
|
|
switch (prop_id) {
|
2001-08-22 04:30:27 +00:00
|
|
|
case ARG_LOCATION:
|
2003-11-24 03:21:54 +00:00
|
|
|
gst_filesrc_set_location (src, g_value_get_string (value));
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
|
|
|
case ARG_BLOCKSIZE:
|
2001-08-22 19:54:08 +00:00
|
|
|
src->block_size = g_value_get_ulong (value);
|
2002-02-05 21:11:43 +00:00
|
|
|
g_object_notify (G_OBJECT (src), "blocksize");
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
2002-11-21 23:52:30 +00:00
|
|
|
case ARG_MMAPSIZE:
|
2002-05-14 00:40:15 +00:00
|
|
|
if ((src->mapsize % src->pagesize) == 0) {
|
2004-03-15 19:27:17 +00:00
|
|
|
src->mapsize = g_value_get_ulong (value);
|
|
|
|
g_object_notify (G_OBJECT (src), "mmapsize");
|
2002-05-14 00:40:15 +00:00
|
|
|
} else {
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_INFO_OBJECT (src,
|
|
|
|
"invalid mapsize, must be a multiple of pagesize, which is %d",
|
|
|
|
src->pagesize);
|
2002-05-14 00:40:15 +00:00
|
|
|
}
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
2001-10-17 10:21:27 +00:00
|
|
|
case ARG_TOUCH:
|
|
|
|
src->touch = g_value_get_boolean (value);
|
2002-02-05 21:11:43 +00:00
|
|
|
g_object_notify (G_OBJECT (src), "touch");
|
2001-10-17 10:21:27 +00:00
|
|
|
break;
|
2001-08-22 04:30:27 +00:00
|
|
|
default:
|
2004-04-20 16:25:41 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_FILESRC (object));
|
|
|
|
|
|
|
|
src = GST_FILESRC (object);
|
|
|
|
|
2001-08-22 19:54:08 +00:00
|
|
|
switch (prop_id) {
|
2001-08-22 04:30:27 +00:00
|
|
|
case ARG_LOCATION:
|
2001-08-22 19:54:08 +00:00
|
|
|
g_value_set_string (value, src->filename);
|
|
|
|
break;
|
|
|
|
case ARG_FD:
|
|
|
|
g_value_set_int (value, src->fd);
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
|
|
|
case ARG_BLOCKSIZE:
|
2001-08-22 19:54:08 +00:00
|
|
|
g_value_set_ulong (value, src->block_size);
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
2002-11-21 23:52:30 +00:00
|
|
|
case ARG_MMAPSIZE:
|
2001-08-22 19:54:08 +00:00
|
|
|
g_value_set_ulong (value, src->mapsize);
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
2001-10-17 10:21:27 +00:00
|
|
|
case ARG_TOUCH:
|
|
|
|
g_value_set_boolean (value, src->touch);
|
|
|
|
break;
|
2001-08-22 04:30:27 +00:00
|
|
|
default:
|
2001-08-22 19:54:08 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 22:18:36 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2001-08-22 04:30:27 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_free_parent_mmap (GstBuffer * buf)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG ("freeing mmap()d buffer at %" G_GUINT64_FORMAT "+%u",
|
2004-02-03 00:27:09 +00:00
|
|
|
GST_BUFFER_OFFSET (buf), GST_BUFFER_SIZE (buf));
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-10-17 20:57:53 +00:00
|
|
|
#ifdef MADV_DONTNEED
|
2001-12-17 18:14:51 +00:00
|
|
|
/* madvise to tell the kernel what to do with it */
|
2002-11-21 23:52:30 +00:00
|
|
|
madvise (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf), MADV_DONTNEED);
|
2001-10-17 20:57:53 +00:00
|
|
|
#endif
|
2001-12-17 18:14:51 +00:00
|
|
|
/* now unmap the memory */
|
2002-11-21 23:52:30 +00:00
|
|
|
munmap (GST_BUFFER_DATA (buf), GST_BUFFER_MAXSIZE (buf));
|
2003-02-01 20:29:27 +00:00
|
|
|
/* cast to unsigned long, since there's no gportable way to print
|
|
|
|
* guint64 as hex */
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG ("unmapped region %08lx+%08lx at %p",
|
2004-02-03 00:27:09 +00:00
|
|
|
(unsigned long) GST_BUFFER_OFFSET (buf),
|
2004-03-13 15:27:01 +00:00
|
|
|
(unsigned long) GST_BUFFER_MAXSIZE (buf), GST_BUFFER_DATA (buf));
|
2002-07-08 19:22:02 +00:00
|
|
|
|
|
|
|
GST_BUFFER_DATA (buf) = NULL;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
2004-04-13 22:18:36 +00:00
|
|
|
#endif
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-04-13 22:18:36 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2001-08-22 04:30:27 +00:00
|
|
|
static GstBuffer *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_map_region (GstFileSrc * src, off_t offset, size_t size)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
2001-09-10 19:46:01 +00:00
|
|
|
gint retval;
|
2002-11-20 21:31:05 +00:00
|
|
|
void *mmapregion;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
g_return_val_if_fail (offset >= 0, NULL);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG_OBJECT (src, "mapping region %08llx+%08lx from file into memory",
|
|
|
|
offset, (unsigned long) size);
|
2002-11-20 21:31:05 +00:00
|
|
|
mmapregion = mmap (NULL, size, PROT_READ, MAP_SHARED, src->fd, offset);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2002-11-20 21:31:05 +00:00
|
|
|
if (mmapregion == NULL) {
|
2004-01-31 19:30:31 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, (NULL), ("mmap call failed."));
|
2002-11-20 21:31:05 +00:00
|
|
|
return NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
} else if (mmapregion == MAP_FAILED) {
|
2003-10-28 20:25:30 +00:00
|
|
|
GST_WARNING_OBJECT (src, "mmap (0x%08lx, %d, 0x%llx) failed: %s",
|
2004-03-15 19:27:17 +00:00
|
|
|
(unsigned long) size, src->fd, offset, strerror (errno));
|
2002-11-20 21:31:05 +00:00
|
|
|
return NULL;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG_OBJECT (src, "mapped region %08lx+%08lx from file into memory at %p",
|
|
|
|
(unsigned long) offset, (unsigned long) size, mmapregion);
|
2002-11-20 21:31:05 +00:00
|
|
|
|
|
|
|
/* time to allocate a new mapbuf */
|
2002-11-21 23:52:30 +00:00
|
|
|
buf = gst_buffer_new ();
|
2002-11-20 21:31:05 +00:00
|
|
|
/* mmap() the data into this new buffer */
|
2002-11-21 23:52:30 +00:00
|
|
|
GST_BUFFER_DATA (buf) = mmapregion;
|
2002-11-20 21:31:05 +00:00
|
|
|
|
2001-10-17 20:57:53 +00:00
|
|
|
#ifdef MADV_SEQUENTIAL
|
2001-12-17 18:14:51 +00:00
|
|
|
/* madvise to tell the kernel what to do with it */
|
2004-03-13 15:27:01 +00:00
|
|
|
retval =
|
|
|
|
madvise (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf), MADV_SEQUENTIAL);
|
2001-10-17 20:57:53 +00:00
|
|
|
#endif
|
2001-12-17 18:14:51 +00:00
|
|
|
/* fill in the rest of the fields */
|
2002-11-21 23:52:30 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_READONLY);
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_ORIGINAL);
|
|
|
|
GST_BUFFER_SIZE (buf) = size;
|
|
|
|
GST_BUFFER_MAXSIZE (buf) = size;
|
|
|
|
GST_BUFFER_OFFSET (buf) = offset;
|
2004-02-02 21:18:54 +00:00
|
|
|
GST_BUFFER_OFFSET_END (buf) = offset + size;
|
2002-11-27 23:14:33 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE;
|
2004-01-11 22:11:35 +00:00
|
|
|
GST_BUFFER_PRIVATE (buf) = src;
|
2004-02-03 00:27:09 +00:00
|
|
|
GST_BUFFER_FREE_DATA_FUNC (buf) = gst_filesrc_free_parent_mmap;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
2004-04-13 22:18:36 +00:00
|
|
|
#endif
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-04-13 22:18:36 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2001-08-22 04:30:27 +00:00
|
|
|
static GstBuffer *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_map_small_region (GstFileSrc * src, off_t offset, size_t size)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2001-10-17 10:21:27 +00:00
|
|
|
size_t mapsize;
|
|
|
|
off_t mod, mapbase;
|
2001-08-22 04:30:27 +00:00
|
|
|
GstBuffer *map;
|
|
|
|
|
2001-12-17 18:14:51 +00:00
|
|
|
/* printf("attempting to map a small buffer at %d+%d\n",offset,size); */
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-12-17 18:14:51 +00:00
|
|
|
/* if the offset starts at a non-page boundary, we have to special case */
|
2001-08-22 19:54:08 +00:00
|
|
|
if ((mod = offset % src->pagesize)) {
|
2001-10-17 10:21:27 +00:00
|
|
|
GstBuffer *ret;
|
|
|
|
|
2001-08-22 04:30:27 +00:00
|
|
|
mapbase = offset - mod;
|
2004-03-13 15:27:01 +00:00
|
|
|
mapsize =
|
2004-03-15 19:27:17 +00:00
|
|
|
((size + mod + src->pagesize - 1) / src->pagesize) * src->pagesize;
|
2001-12-17 18:14:51 +00:00
|
|
|
/* printf("not on page boundaries, resizing map to %d+%d\n",mapbase,mapsize);*/
|
2004-03-13 15:27:01 +00:00
|
|
|
map = gst_filesrc_map_region (src, mapbase, mapsize);
|
2002-11-20 21:31:05 +00:00
|
|
|
if (map == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
ret = gst_buffer_create_sub (map, offset - mapbase, size);
|
2003-05-24 10:09:39 +00:00
|
|
|
GST_BUFFER_OFFSET (ret) = GST_BUFFER_OFFSET (map) + offset - mapbase;
|
2001-10-17 10:21:27 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (map);
|
|
|
|
|
|
|
|
return ret;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return gst_filesrc_map_region (src, offset, size);
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
2004-04-13 22:18:36 +00:00
|
|
|
#endif
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-04-13 22:18:36 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2001-08-22 04:30:27 +00:00
|
|
|
/**
|
2003-07-30 00:44:58 +00:00
|
|
|
* gst_filesrc_get_mmap:
|
2004-04-21 14:51:27 +00:00
|
|
|
* @src: #GstElement to get data from
|
2001-08-22 04:30:27 +00:00
|
|
|
*
|
2004-04-21 14:51:27 +00:00
|
|
|
* Returns: a new #GstData from the mmap'd source.
|
2001-08-22 04:30:27 +00:00
|
|
|
*/
|
2004-04-21 14:51:27 +00:00
|
|
|
static GstData *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_get_mmap (GstFileSrc * src)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2004-02-03 00:27:09 +00:00
|
|
|
GstBuffer *buf = NULL;
|
2003-05-24 10:09:39 +00:00
|
|
|
size_t readsize, mapsize;
|
2004-03-13 15:27:01 +00:00
|
|
|
off_t readend, mapstart, mapend;
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-12-17 18:14:51 +00:00
|
|
|
/* calculate end pointers so we don't have to do so repeatedly later */
|
2001-09-10 19:46:01 +00:00
|
|
|
readsize = src->block_size;
|
2004-03-15 19:27:17 +00:00
|
|
|
readend = src->curoffset + src->block_size; /* note this is the byte *after* the read */
|
2003-05-24 10:09:39 +00:00
|
|
|
mapstart = GST_BUFFER_OFFSET (src->mapbuf);
|
|
|
|
mapsize = GST_BUFFER_SIZE (src->mapbuf);
|
2004-03-15 19:27:17 +00:00
|
|
|
mapend = mapstart + mapsize; /* note this is the byte *after* the map */
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-12-17 18:14:51 +00:00
|
|
|
/* check to see if we're going to overflow the end of the file */
|
2001-09-10 19:46:01 +00:00
|
|
|
if (readend > src->filelen) {
|
2003-11-17 01:11:32 +00:00
|
|
|
if (!gst_filesrc_check_filesize (src) || readend > src->filelen) {
|
|
|
|
readsize = src->filelen - src->curoffset;
|
|
|
|
readend = src->curoffset + readsize;
|
|
|
|
}
|
2001-09-10 19:46:01 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG ("attempting to read %08lx, %08lx, %08lx, %08lx",
|
|
|
|
(unsigned long) readsize, (unsigned long) readend,
|
|
|
|
(unsigned long) mapstart, (unsigned long) mapend);
|
2002-12-08 16:43:27 +00:00
|
|
|
|
2001-12-17 18:14:51 +00:00
|
|
|
/* if the start is past the mapstart */
|
2001-08-22 04:30:27 +00:00
|
|
|
if (src->curoffset >= mapstart) {
|
2001-12-17 18:14:51 +00:00
|
|
|
/* if the end is before the mapend, the buffer is in current mmap region... */
|
|
|
|
/* ('cause by definition if readend is in the buffer, so's readstart) */
|
2001-08-22 04:30:27 +00:00
|
|
|
if (readend <= mapend) {
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG_OBJECT (src,
|
2004-03-15 19:27:17 +00:00
|
|
|
"read buf %llu+%d lives in current mapbuf %lld+%d, creating subbuffer of mapbuf",
|
|
|
|
src->curoffset, (int) readsize, mapstart, mapsize);
|
2004-03-13 15:27:01 +00:00
|
|
|
buf =
|
2004-03-15 19:27:17 +00:00
|
|
|
gst_buffer_create_sub (src->mapbuf, src->curoffset - mapstart,
|
|
|
|
readsize);
|
2003-05-24 10:09:39 +00:00
|
|
|
GST_BUFFER_OFFSET (buf) = src->curoffset;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
/* if the start actually is within the current mmap region, map an overlap buffer */
|
2001-08-22 04:30:27 +00:00
|
|
|
} else if (src->curoffset < mapend) {
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG_OBJECT (src,
|
2004-03-15 19:27:17 +00:00
|
|
|
"read buf %llu+%d starts in mapbuf %d+%d but ends outside, creating new mmap",
|
|
|
|
(unsigned long long) src->curoffset, (gint) readsize, (gint) mapstart,
|
|
|
|
(gint) mapsize);
|
2001-09-10 19:46:01 +00:00
|
|
|
buf = gst_filesrc_map_small_region (src, src->curoffset, readsize);
|
2002-12-08 16:43:27 +00:00
|
|
|
if (buf == NULL)
|
2004-03-15 19:27:17 +00:00
|
|
|
return NULL;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
2001-12-17 18:14:51 +00:00
|
|
|
/* the only other option is that buffer is totally outside, which means we search for it */
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
/* now we can assume that the start is *before* the current mmap region */
|
|
|
|
/* if the readend is past mapstart, we have two options */
|
2001-08-22 04:30:27 +00:00
|
|
|
} else if (readend >= mapstart) {
|
2001-12-17 18:14:51 +00:00
|
|
|
/* either the read buffer overlaps the start of the mmap region */
|
|
|
|
/* or the read buffer fully contains the current mmap region */
|
2004-03-13 15:27:01 +00:00
|
|
|
/* either way, it's really not relevant, we just create a new region anyway */
|
|
|
|
GST_LOG_OBJECT (src,
|
2004-03-15 19:27:17 +00:00
|
|
|
"read buf %llu+%d starts before mapbuf %d+%d, but overlaps it",
|
|
|
|
(unsigned long long) src->curoffset, (gint) readsize, (gint) mapstart,
|
|
|
|
(gint) mapsize);
|
2001-09-10 19:46:01 +00:00
|
|
|
buf = gst_filesrc_map_small_region (src, src->curoffset, readsize);
|
2002-12-08 16:43:27 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return NULL;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
2001-12-17 18:14:51 +00:00
|
|
|
/* then deal with the case where the read buffer is totally outside */
|
2001-08-22 04:30:27 +00:00
|
|
|
if (buf == NULL) {
|
2001-12-17 18:14:51 +00:00
|
|
|
/* first check to see if there's a map that covers the right region already */
|
2004-02-07 01:23:13 +00:00
|
|
|
GST_LOG_OBJECT (src, "searching for mapbuf to cover %llu+%d",
|
2004-03-15 19:27:17 +00:00
|
|
|
src->curoffset, (int) readsize);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-02-03 00:27:09 +00:00
|
|
|
/* if the read buffer crosses a mmap region boundary, create a one-off region */
|
|
|
|
if ((src->curoffset / src->mapsize) != (readend / src->mapsize)) {
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG_OBJECT (src,
|
2004-03-15 19:27:17 +00:00
|
|
|
"read buf %llu+%d crosses a %d-byte boundary, creating a one-off",
|
|
|
|
src->curoffset, (int) readsize, (int) src->mapsize);
|
2004-02-03 00:27:09 +00:00
|
|
|
buf = gst_filesrc_map_small_region (src, src->curoffset, readsize);
|
|
|
|
if (buf == NULL)
|
2004-03-15 19:27:17 +00:00
|
|
|
return NULL;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
/* otherwise we will create a new mmap region and set it to the default */
|
2001-08-22 04:30:27 +00:00
|
|
|
} else {
|
2004-02-03 00:27:09 +00:00
|
|
|
size_t mapsize;
|
|
|
|
|
|
|
|
off_t nextmap = src->curoffset - (src->curoffset % src->mapsize);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (src,
|
2004-03-15 19:27:17 +00:00
|
|
|
"read buf %llu+%d in new mapbuf at %llu+%d, mapping and subbuffering",
|
|
|
|
src->curoffset, readsize, nextmap, src->mapsize);
|
2004-02-03 00:27:09 +00:00
|
|
|
/* first, we're done with the old mapbuf */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_buffer_unref (src->mapbuf);
|
2004-02-03 00:27:09 +00:00
|
|
|
mapsize = src->mapsize;
|
|
|
|
|
|
|
|
/* double the mapsize as long as the readsize is smaller */
|
gst/elements/gstfilesrc.c: compute mapsize correctly
Original commit message from CVS:
* gst/elements/gstfilesrc.c: (gst_filesrc_get_mmap):
compute mapsize correctly
* gst/elements/gstfilesrc.c: (gst_filesrc_get_mmap):
use correct datatypes when calling a varargs function
* gst/elements/gsttypefindelement.c: (stop_typefinding):
push a DISCONT event as first thing
* gst/gst_private.h:
* gst/gstinfo.c: (_gst_debug_init):
remove GST_DATAFLOW debugging category
* gst/gstbin.c: (gst_bin_iterate):
use GST_SCHEDULING category
* gst/gstpad.c: (gst_pad_get_type), (_invent_event),
(gst_pad_push), (gst_pad_pull), (gst_pad_call_chain_function),
(gst_pad_call_get_function):
add GST_DATAFLOW to easily track flow of buffers or events.
* gst/gstqueue.c: (gst_queue_get_type),
(gst_queue_handle_pending_events), (gst_queue_chain),
(gst_queue_get), (gst_queue_handle_src_event):
use own static debugging category GST_DATAFLOW for dataflow,
use DEBUG category for showing which path events go, use LOG
category for buffers.
2004-05-11 16:20:41 +00:00
|
|
|
while (readsize + src->curoffset > nextmap + mapsize) {
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_LOG_OBJECT (src, "readsize smaller then mapsize %08x %d",
|
|
|
|
readsize, (int) mapsize);
|
|
|
|
mapsize <<= 1;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
2004-02-03 00:27:09 +00:00
|
|
|
/* create a new one */
|
|
|
|
src->mapbuf = gst_filesrc_map_region (src, nextmap, mapsize);
|
|
|
|
if (src->mapbuf == NULL)
|
2004-03-15 19:27:17 +00:00
|
|
|
return NULL;
|
2004-02-03 00:27:09 +00:00
|
|
|
|
|
|
|
/* subbuffer it */
|
2004-03-13 15:27:01 +00:00
|
|
|
buf =
|
2004-03-15 19:27:17 +00:00
|
|
|
gst_buffer_create_sub (src->mapbuf, src->curoffset - nextmap,
|
|
|
|
readsize);
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_BUFFER_OFFSET (buf) =
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_BUFFER_OFFSET (src->mapbuf) + src->curoffset - nextmap;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-22 19:54:08 +00:00
|
|
|
/* if we need to touch the buffer (to bring it into memory), do so */
|
|
|
|
if (src->touch) {
|
2001-12-14 12:15:27 +00:00
|
|
|
volatile guchar *p = GST_BUFFER_DATA (buf), c;
|
2002-11-21 23:52:30 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < GST_BUFFER_SIZE (buf); i += src->pagesize)
|
2001-12-14 12:15:27 +00:00
|
|
|
c = p[i];
|
2001-08-22 19:54:08 +00:00
|
|
|
}
|
|
|
|
|
2001-08-22 04:30:27 +00:00
|
|
|
/* we're done, return the buffer */
|
2004-02-07 15:51:39 +00:00
|
|
|
g_assert (src->curoffset == GST_BUFFER_OFFSET (buf));
|
2004-03-13 15:27:01 +00:00
|
|
|
src->curoffset += GST_BUFFER_SIZE (buf);
|
2004-04-21 14:51:27 +00:00
|
|
|
return GST_DATA (buf);
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
2004-04-13 22:18:36 +00:00
|
|
|
#endif
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-04-21 14:51:27 +00:00
|
|
|
static GstData *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_get_read (GstFileSrc * src)
|
2003-07-30 00:44:58 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
size_t readsize;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
readsize = src->block_size;
|
2004-04-21 14:51:27 +00:00
|
|
|
/* for regular files, we can use the filesize to check how much we
|
|
|
|
can read */
|
|
|
|
if (src->is_regular) {
|
|
|
|
if (src->curoffset + readsize > src->filelen) {
|
|
|
|
if (!gst_filesrc_check_filesize (src)
|
|
|
|
|| src->curoffset + readsize > src->filelen) {
|
|
|
|
readsize = src->filelen - src->curoffset;
|
|
|
|
}
|
2003-11-17 01:11:32 +00:00
|
|
|
}
|
2003-07-30 00:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf = gst_buffer_new_and_alloc (readsize);
|
|
|
|
g_return_val_if_fail (buf != NULL, NULL);
|
|
|
|
|
2004-04-21 14:51:27 +00:00
|
|
|
GST_LOG_OBJECT (src, "Reading %d bytes", readsize);
|
2003-07-30 00:44:58 +00:00
|
|
|
ret = read (src->fd, GST_BUFFER_DATA (buf), readsize);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (ret < 0) {
|
2004-01-31 19:30:31 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
|
2003-09-16 09:57:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-04-21 14:51:27 +00:00
|
|
|
/* regular files should have given us what we expected */
|
|
|
|
if (ret < readsize && src->is_regular) {
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
2004-03-15 19:27:17 +00:00
|
|
|
("unexpected end of file."));
|
2003-07-30 00:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-04-21 14:51:27 +00:00
|
|
|
/* other files should eos if they read 0 */
|
|
|
|
if (ret == 0) {
|
|
|
|
GST_DEBUG ("non-regular file hits EOS");
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
gst_element_set_eos (GST_ELEMENT (src));
|
|
|
|
return GST_DATA (gst_event_new (GST_EVENT_EOS));
|
|
|
|
}
|
|
|
|
readsize = ret;
|
2003-07-30 00:44:58 +00:00
|
|
|
|
2004-02-02 21:18:54 +00:00
|
|
|
GST_BUFFER_SIZE (buf) = readsize;
|
|
|
|
GST_BUFFER_MAXSIZE (buf) = readsize;
|
|
|
|
GST_BUFFER_OFFSET (buf) = src->curoffset;
|
|
|
|
GST_BUFFER_OFFSET_END (buf) = src->curoffset + readsize;
|
2003-07-30 00:44:58 +00:00
|
|
|
src->curoffset += readsize;
|
|
|
|
|
2004-04-21 14:51:27 +00:00
|
|
|
return GST_DATA (buf);
|
2003-07-30 00:44:58 +00:00
|
|
|
}
|
|
|
|
|
2003-10-08 16:06:02 +00:00
|
|
|
static GstData *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_get (GstPad * pad)
|
2003-07-30 00:44:58 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
src = GST_FILESRC (gst_pad_get_parent (pad));
|
|
|
|
g_return_val_if_fail (GST_FLAG_IS_SET (src, GST_FILESRC_OPEN), NULL);
|
|
|
|
|
2004-01-29 22:43:41 +00:00
|
|
|
/* check for flush */
|
|
|
|
if (src->need_flush) {
|
|
|
|
src->need_flush = FALSE;
|
|
|
|
GST_DEBUG_OBJECT (src, "sending flush");
|
|
|
|
return GST_DATA (gst_event_new_flush ());
|
|
|
|
}
|
2003-07-30 00:44:58 +00:00
|
|
|
/* check for seek */
|
2004-04-16 02:57:55 +00:00
|
|
|
if (src->need_discont) {
|
2003-07-30 00:44:58 +00:00
|
|
|
GstEvent *event;
|
|
|
|
|
2003-10-28 20:25:30 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "sending discont");
|
2004-03-13 15:27:01 +00:00
|
|
|
event =
|
2004-05-06 21:40:55 +00:00
|
|
|
gst_event_new_discontinuous (src->need_discont > 1, GST_FORMAT_BYTES,
|
gst/elements/gstfilesrc.c: compute mapsize correctly
Original commit message from CVS:
* gst/elements/gstfilesrc.c: (gst_filesrc_get_mmap):
compute mapsize correctly
* gst/elements/gstfilesrc.c: (gst_filesrc_get_mmap):
use correct datatypes when calling a varargs function
* gst/elements/gsttypefindelement.c: (stop_typefinding):
push a DISCONT event as first thing
* gst/gst_private.h:
* gst/gstinfo.c: (_gst_debug_init):
remove GST_DATAFLOW debugging category
* gst/gstbin.c: (gst_bin_iterate):
use GST_SCHEDULING category
* gst/gstpad.c: (gst_pad_get_type), (_invent_event),
(gst_pad_push), (gst_pad_pull), (gst_pad_call_chain_function),
(gst_pad_call_get_function):
add GST_DATAFLOW to easily track flow of buffers or events.
* gst/gstqueue.c: (gst_queue_get_type),
(gst_queue_handle_pending_events), (gst_queue_chain),
(gst_queue_get), (gst_queue_handle_src_event):
use own static debugging category GST_DATAFLOW for dataflow,
use DEBUG category for showing which path events go, use LOG
category for buffers.
2004-05-11 16:20:41 +00:00
|
|
|
(guint64) src->curoffset, GST_FORMAT_UNDEFINED);
|
2004-05-06 21:40:55 +00:00
|
|
|
src->need_discont = 0;
|
2003-10-08 16:06:02 +00:00
|
|
|
return GST_DATA (event);
|
2003-07-30 00:44:58 +00:00
|
|
|
}
|
|
|
|
|
2004-04-21 14:51:27 +00:00
|
|
|
/* check for EOF if it's a regular file */
|
|
|
|
if (src->is_regular) {
|
|
|
|
g_assert (src->curoffset <= src->filelen);
|
|
|
|
if (src->curoffset == src->filelen) {
|
|
|
|
if (!gst_filesrc_check_filesize (src) || src->curoffset >= src->filelen) {
|
|
|
|
GST_DEBUG_OBJECT (src, "eos %" G_GINT64_FORMAT " %" G_GINT64_FORMAT,
|
|
|
|
src->curoffset, src->filelen);
|
|
|
|
}
|
2003-11-17 01:11:32 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (src));
|
|
|
|
return GST_DATA (gst_event_new (GST_EVENT_EOS));
|
2004-04-21 14:51:27 +00:00
|
|
|
|
2003-11-17 01:11:32 +00:00
|
|
|
}
|
2003-07-30 00:44:58 +00:00
|
|
|
}
|
2004-04-13 22:18:36 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2004-03-13 15:27:01 +00:00
|
|
|
if (src->using_mmap) {
|
2004-04-21 14:51:27 +00:00
|
|
|
return gst_filesrc_get_mmap (src);
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
2004-04-21 14:51:27 +00:00
|
|
|
return gst_filesrc_get_read (src);
|
2003-07-30 00:44:58 +00:00
|
|
|
}
|
2004-04-13 22:18:36 +00:00
|
|
|
#else
|
2004-04-21 14:51:27 +00:00
|
|
|
return gst_filesrc_get_read (src);
|
2004-04-13 22:18:36 +00:00
|
|
|
#endif
|
2003-07-30 00:44:58 +00:00
|
|
|
}
|
|
|
|
|
2003-11-17 01:11:32 +00:00
|
|
|
/* TRUE if the filesize of the file was updated */
|
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_check_filesize (GstFileSrc * src)
|
2003-11-17 01:11:32 +00:00
|
|
|
{
|
|
|
|
struct stat stat_results;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (GST_FLAG_IS_SET (src, GST_FILESRC_OPEN), FALSE);
|
|
|
|
|
|
|
|
fstat (src->fd, &stat_results);
|
|
|
|
GST_DEBUG_OBJECT (src,
|
|
|
|
"checked filesize on %s (was %" G_GUINT64_FORMAT ", is %" G_GUINT64_FORMAT
|
|
|
|
")", src->filename, src->filelen, (guint64) stat_results.st_size);
|
2003-11-17 01:11:32 +00:00
|
|
|
if (src->filelen == (guint64) stat_results.st_size)
|
|
|
|
return FALSE;
|
|
|
|
src->filelen = stat_results.st_size;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2001-08-22 04:30:27 +00:00
|
|
|
/* open the file and mmap it, necessary to go to READY state */
|
2004-01-18 21:36:20 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_open_file (GstFileSrc * src)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (!GST_FLAG_IS_SET (src, GST_FILESRC_OPEN), FALSE);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (src->filename == NULL || src->filename[0] == '\0') {
|
2004-01-29 23:17:58 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
|
2004-03-15 19:27:17 +00:00
|
|
|
(_("No file name specified for reading.")), (NULL));
|
2004-01-18 21:36:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_INFO_OBJECT (src, "opening file %s", src->filename);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
/* open the file */
|
2004-07-12 21:57:35 +00:00
|
|
|
src->fd = open (src->filename, O_RDONLY | O_BINARY);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (src->fd < 0) {
|
2004-01-18 21:36:20 +00:00
|
|
|
if (errno == ENOENT)
|
2004-04-25 18:24:02 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
|
|
|
|
("No such file \"%s\"", src->filename));
|
2004-01-18 21:36:20 +00:00
|
|
|
else
|
2004-01-29 23:17:58 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
2004-03-15 19:27:17 +00:00
|
|
|
(_("Could not open file \"%s\" for reading."), src->filename),
|
|
|
|
GST_ERROR_SYSTEM);
|
2001-08-22 04:30:27 +00:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
2002-05-08 20:40:48 +00:00
|
|
|
/* check if it is a regular file, otherwise bail out */
|
|
|
|
struct stat stat_results;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
fstat (src->fd, &stat_results);
|
2002-05-08 20:40:48 +00:00
|
|
|
|
2004-04-21 14:51:27 +00:00
|
|
|
if (S_ISDIR (stat_results.st_mode)) {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
|
|
|
(_("\"%s\" is a directory."), src->filename), (NULL));
|
|
|
|
close (src->fd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (S_ISSOCK (stat_results.st_mode)) {
|
2004-01-29 23:17:58 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
2004-04-21 14:51:27 +00:00
|
|
|
(_("File \"%s\" is a socket."), src->filename), (NULL));
|
2004-03-13 15:27:01 +00:00
|
|
|
close (src->fd);
|
2002-05-08 20:40:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2001-08-22 04:30:27 +00:00
|
|
|
/* find the file length */
|
2003-07-30 00:44:58 +00:00
|
|
|
src->filelen = stat_results.st_size;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-04-13 22:18:36 +00:00
|
|
|
src->using_mmap = FALSE;
|
2004-04-21 14:51:27 +00:00
|
|
|
|
|
|
|
/* record if it's a regular (hence seekable and lengthable) file */
|
|
|
|
if (S_ISREG (stat_results.st_mode))
|
|
|
|
src->is_regular = TRUE;
|
2004-04-13 22:18:36 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2004-04-21 14:51:27 +00:00
|
|
|
/* FIXME: maybe we should only try to mmap if it's a regular file */
|
|
|
|
/* allocate the first mmap'd region if it's a regular file ? */
|
2001-08-22 04:30:27 +00:00
|
|
|
src->mapbuf = gst_filesrc_map_region (src, 0, src->mapsize);
|
2004-04-13 22:18:36 +00:00
|
|
|
if (src->mapbuf != NULL) {
|
2004-04-21 14:51:27 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "using mmap for file");
|
2003-07-30 00:44:58 +00:00
|
|
|
src->using_mmap = TRUE;
|
|
|
|
}
|
2004-04-13 22:18:36 +00:00
|
|
|
#endif
|
|
|
|
|
2001-08-22 04:30:27 +00:00
|
|
|
src->curoffset = 0;
|
|
|
|
|
|
|
|
GST_FLAG_SET (src, GST_FILESRC_OPEN);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unmap and close the file */
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_close_file (GstFileSrc * src)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_FLAG_IS_SET (src, GST_FILESRC_OPEN));
|
|
|
|
|
|
|
|
/* close the file */
|
|
|
|
close (src->fd);
|
|
|
|
|
|
|
|
/* zero out a lot of our state */
|
|
|
|
src->fd = 0;
|
|
|
|
src->filelen = 0;
|
|
|
|
src->curoffset = 0;
|
2004-04-21 14:51:27 +00:00
|
|
|
src->is_regular = FALSE;
|
2002-02-05 21:11:43 +00:00
|
|
|
|
2002-12-08 16:43:27 +00:00
|
|
|
if (src->mapbuf) {
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_buffer_unref (src->mapbuf);
|
2002-12-08 16:43:27 +00:00
|
|
|
src->mapbuf = NULL;
|
|
|
|
}
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
GST_FLAG_UNSET (src, GST_FILESRC_OPEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_change_state (GstElement * element)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GstFileSrc *src = GST_FILESRC (element);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
2002-06-07 19:32:53 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2001-12-22 21:18:17 +00:00
|
|
|
if (!GST_FLAG_IS_SET (element, GST_FILESRC_OPEN)) {
|
2004-03-15 19:27:17 +00:00
|
|
|
if (!gst_filesrc_open_file (GST_FILESRC (element)))
|
|
|
|
return GST_STATE_FAILURE;
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
2004-05-06 21:40:55 +00:00
|
|
|
src->need_discont = 2;
|
2001-12-22 21:18:17 +00:00
|
|
|
break;
|
2002-06-07 19:32:53 +00:00
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_FLAG_IS_SET (element, GST_FILESRC_OPEN))
|
2004-03-15 19:27:17 +00:00
|
|
|
gst_filesrc_close_file (GST_FILESRC (element));
|
2002-06-07 19:32:53 +00:00
|
|
|
break;
|
2001-12-22 21:18:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
2001-09-10 19:46:01 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_srcpad_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value)
|
2002-05-26 21:54:27 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src = GST_FILESRC (GST_PAD_PARENT (pad));
|
|
|
|
|
2004-05-13 12:06:11 +00:00
|
|
|
if (*format == GST_FORMAT_DEFAULT)
|
|
|
|
*format = GST_FORMAT_BYTES;
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
switch (type) {
|
2002-12-30 17:42:11 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-05-26 21:54:27 +00:00
|
|
|
if (*format != GST_FORMAT_BYTES) {
|
2004-03-15 19:27:17 +00:00
|
|
|
return FALSE;
|
2002-05-26 21:54:27 +00:00
|
|
|
}
|
2004-04-21 14:51:27 +00:00
|
|
|
if (!src->is_regular)
|
|
|
|
return FALSE;
|
2003-11-17 01:11:32 +00:00
|
|
|
gst_filesrc_check_filesize (src);
|
2002-05-26 21:54:27 +00:00
|
|
|
*value = src->filelen;
|
|
|
|
break;
|
2002-12-30 17:42:11 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-12-22 14:03:09 +00:00
|
|
|
switch (*format) {
|
2004-03-15 19:27:17 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*value = src->curoffset;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_PERCENT:
|
|
|
|
if (src->filelen == 0)
|
|
|
|
return FALSE;
|
2004-04-21 14:51:27 +00:00
|
|
|
if (!src->is_regular)
|
|
|
|
return FALSE;
|
2004-03-15 19:27:17 +00:00
|
|
|
*value = src->curoffset * GST_FORMAT_PERCENT_MAX / src->filelen;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
2002-05-26 21:54:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-09-10 19:46:01 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_srcpad_event (GstPad * pad, GstEvent * event)
|
2001-09-10 19:46:01 +00:00
|
|
|
{
|
2002-05-26 21:54:27 +00:00
|
|
|
GstFileSrc *src = GST_FILESRC (GST_PAD_PARENT (pad));
|
2001-09-10 19:46:01 +00:00
|
|
|
|
2004-07-07 16:50:30 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "received event type %d", GST_EVENT_TYPE (event));
|
2002-05-31 21:36:11 +00:00
|
|
|
|
2001-10-21 21:58:29 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
2002-06-22 09:23:40 +00:00
|
|
|
{
|
2003-04-28 21:48:37 +00:00
|
|
|
gint64 offset;
|
2002-06-22 09:23:40 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
if (GST_EVENT_SEEK_FORMAT (event) != GST_FORMAT_BYTES) {
|
2004-03-15 19:27:17 +00:00
|
|
|
goto error;
|
2002-05-26 21:54:27 +00:00
|
|
|
}
|
2004-04-21 14:51:27 +00:00
|
|
|
if (!src->is_regular) {
|
|
|
|
GST_DEBUG ("can't handle seek on a non-regular file");
|
|
|
|
goto error;
|
|
|
|
}
|
2002-06-22 09:23:40 +00:00
|
|
|
|
|
|
|
offset = GST_EVENT_SEEK_OFFSET (event);
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
switch (GST_EVENT_SEEK_METHOD (event)) {
|
2004-03-15 19:27:17 +00:00
|
|
|
case GST_SEEK_METHOD_SET:
|
2004-04-06 23:46:37 +00:00
|
|
|
if (offset < 0 ||
|
|
|
|
(offset > src->filelen && (!gst_filesrc_check_filesize (src)
|
|
|
|
|| offset > src->filelen))) {
|
2004-03-15 19:27:17 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
src->curoffset = offset;
|
|
|
|
GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT,
|
|
|
|
src->curoffset);
|
|
|
|
break;
|
|
|
|
case GST_SEEK_METHOD_CUR:
|
|
|
|
if (offset + src->curoffset > src->filelen)
|
|
|
|
if (!gst_filesrc_check_filesize (src)
|
|
|
|
|| offset + src->curoffset > src->filelen)
|
|
|
|
goto error;
|
|
|
|
src->curoffset += offset;
|
|
|
|
GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT,
|
|
|
|
src->curoffset);
|
|
|
|
break;
|
|
|
|
case GST_SEEK_METHOD_END:
|
|
|
|
if (ABS (offset) > src->filelen) {
|
|
|
|
if (!gst_filesrc_check_filesize (src)
|
|
|
|
|| ABS (offset) > src->filelen)
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
src->curoffset = src->filelen - ABS (offset);
|
|
|
|
GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT,
|
|
|
|
src->curoffset);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto error;
|
|
|
|
break;
|
2002-01-26 18:28:55 +00:00
|
|
|
}
|
2004-05-06 21:40:55 +00:00
|
|
|
src->need_discont = 1;
|
2004-03-13 15:27:01 +00:00
|
|
|
src->need_flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
|
2002-02-02 13:24:25 +00:00
|
|
|
break;
|
2002-06-22 09:23:40 +00:00
|
|
|
}
|
2002-06-13 22:27:40 +00:00
|
|
|
case GST_EVENT_SIZE:
|
|
|
|
if (GST_EVENT_SIZE_FORMAT (event) != GST_FORMAT_BYTES) {
|
2004-03-15 19:27:17 +00:00
|
|
|
goto error;
|
2002-06-13 22:27:40 +00:00
|
|
|
}
|
|
|
|
src->block_size = GST_EVENT_SIZE_VALUE (event);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_object_notify (G_OBJECT (src), "blocksize");
|
2002-06-13 22:27:40 +00:00
|
|
|
break;
|
2002-02-02 13:24:25 +00:00
|
|
|
case GST_EVENT_FLUSH:
|
|
|
|
src->need_flush = TRUE;
|
|
|
|
break;
|
2001-10-21 21:58:29 +00:00
|
|
|
default:
|
2002-07-08 19:22:02 +00:00
|
|
|
goto error;
|
2001-10-21 21:58:29 +00:00
|
|
|
break;
|
2001-09-10 19:46:01 +00:00
|
|
|
}
|
2002-07-08 19:22:02 +00:00
|
|
|
gst_event_unref (event);
|
2001-10-21 21:58:29 +00:00
|
|
|
return TRUE;
|
2002-07-08 19:22:02 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
gst_event_unref (event);
|
|
|
|
return FALSE;
|
2001-09-10 19:46:01 +00:00
|
|
|
}
|
2003-11-24 03:21:54 +00:00
|
|
|
|
|
|
|
/*** GSTURIHANDLER INTERFACE *************************************************/
|
|
|
|
|
|
|
|
static guint
|
|
|
|
gst_filesrc_uri_get_type (void)
|
|
|
|
{
|
|
|
|
return GST_URI_SRC;
|
|
|
|
}
|
|
|
|
static gchar **
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_uri_get_protocols (void)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
static gchar *protocols[] = { "file", NULL };
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
return protocols;
|
|
|
|
}
|
|
|
|
static const gchar *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_uri_get_uri (GstURIHandler * handler)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src = GST_FILESRC (handler);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
return src->uri;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_filesrc_uri_set_uri (GstURIHandler * handler, const gchar * uri)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
gchar *protocol, *location;
|
|
|
|
gboolean ret;
|
|
|
|
GstFileSrc *src = GST_FILESRC (handler);
|
|
|
|
|
|
|
|
protocol = gst_uri_get_protocol (uri);
|
|
|
|
if (strcmp (protocol, "file") != 0) {
|
|
|
|
g_free (protocol);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
g_free (protocol);
|
|
|
|
location = gst_uri_get_location (uri);
|
|
|
|
ret = gst_filesrc_set_location (src, location);
|
|
|
|
g_free (location);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_filesrc_uri_handler_init (gpointer g_iface, gpointer iface_data)
|
|
|
|
{
|
|
|
|
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
|
|
|
|
|
|
|
|
iface->get_type = gst_filesrc_uri_get_type;
|
|
|
|
iface->get_protocols = gst_filesrc_uri_get_protocols;
|
|
|
|
iface->get_uri = gst_filesrc_uri_get_uri;
|
|
|
|
iface->set_uri = gst_filesrc_uri_set_uri;
|
|
|
|
}
|