2001-08-22 04:30:27 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
* 2000,2005 Wim Taymans <wim@fluendo.com>
|
2001-08-22 04:30:27 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2001-08-22 04:30:27 +00:00
|
|
|
*/
|
2005-08-05 13:42:10 +00:00
|
|
|
/**
|
2005-12-01 12:29:34 +00:00
|
|
|
* SECTION:element-filesrc
|
2005-08-05 13:42:10 +00:00
|
|
|
* @see_also: #GstFileSrc
|
|
|
|
*
|
2006-07-27 10:54:29 +00:00
|
|
|
* Read data from a file in the local file system.
|
2010-08-16 15:01:27 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* |[
|
2014-07-08 09:17:41 +00:00
|
|
|
* gst-launch filesrc location=song.ogg ! decodebin ! autoaudiosink
|
2010-08-16 15:01:27 +00:00
|
|
|
* ]| Play a song.ogg from local dir.
|
|
|
|
* </refsect2>
|
2005-08-05 13:42:10 +00:00
|
|
|
*/
|
2001-08-22 04:30:27 +00:00
|
|
|
|
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>
|
2005-10-13 17:43:36 +00:00
|
|
|
#include <sys/types.h>
|
2012-04-30 16:29:21 +00:00
|
|
|
#include <sys/stat.h>
|
2008-08-19 17:23:18 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h> /* lseek, open, close, read */
|
|
|
|
/* On win32, stat* default to 32 bit; we need the 64-bit
|
|
|
|
* variants, so explicitly define it that way. */
|
2012-05-05 19:17:43 +00:00
|
|
|
#undef stat
|
2008-08-19 17:23:18 +00:00
|
|
|
#define stat __stat64
|
2012-05-05 19:17:43 +00:00
|
|
|
#undef fstat
|
2008-08-19 17:23:18 +00:00
|
|
|
#define fstat _fstat64
|
|
|
|
#undef lseek
|
|
|
|
#define lseek _lseeki64
|
|
|
|
#undef off_t
|
|
|
|
#define off_t guint64
|
|
|
|
/* Prevent stat.h from defining the stat* functions as
|
|
|
|
* _stat*, since we're explicitly overriding that */
|
|
|
|
#undef _INC_STAT_INL
|
|
|
|
#endif
|
2001-08-22 04:30:27 +00:00
|
|
|
#include <fcntl.h>
|
2005-10-13 17:51:51 +00:00
|
|
|
|
2004-05-07 02:36:28 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-10-13 17:51:51 +00:00
|
|
|
# include <unistd.h>
|
2004-05-07 02:36:28 +00:00
|
|
|
#endif
|
2005-10-13 17:51:51 +00:00
|
|
|
|
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
|
|
|
|
2005-11-29 18:00:15 +00:00
|
|
|
#include "../../gst/gst-i18n-lib.h"
|
2004-01-18 21:36:20 +00:00
|
|
|
|
gst/: s/gst_pad_new/&_from_template/ register pad templates in the base_init function add static pad template definit...
Original commit message from CVS:
* gst/autoplug/gstspideridentity.c:
(gst_spider_identity_request_new_pad):
* gst/elements/gstaggregator.c: (gst_aggregator_base_init),
(gst_aggregator_init):
* gst/elements/gstfakesink.c: (gst_fakesink_base_init),
(gst_fakesink_init):
* gst/elements/gstfakesrc.c: (gst_fakesrc_base_init),
(gst_fakesrc_init):
* gst/elements/gstfdsink.c: (gst_fdsink_base_init),
(gst_fdsink_init):
* gst/elements/gstfdsrc.c: (gst_fdsrc_base_init), (gst_fdsrc_init):
* gst/elements/gstfilesink.c: (gst_filesink_base_init),
(gst_filesink_init):
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_init):
* gst/elements/gstidentity.c: (gst_identity_base_init),
(gst_identity_init):
* gst/elements/gstmultifilesrc.c: (gst_multifilesrc_base_init),
(gst_multifilesrc_init):
* gst/elements/gstpipefilter.c: (gst_pipefilter_base_init),
(gst_pipefilter_init):
* gst/elements/gststatistics.c: (gst_statistics_base_init),
(gst_statistics_init):
* gst/elements/gsttee.c: (gst_tee_base_init), (gst_tee_init):
* gst/gstqueue.c: (gst_queue_base_init), (gst_queue_init):
s/gst_pad_new/&_from_template/
register pad templates in the base_init function
add static pad template definitions
2004-08-17 14:11:23 +00:00
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
2004-05-07 02:36:28 +00:00
|
|
|
#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
|
|
|
|
2008-08-19 17:23:18 +00:00
|
|
|
/* Copy of glib's g_open due to win32 libc/cross-DLL brokenness: we can't
|
|
|
|
* use the 'file descriptor' opened in glib (and returned from this function)
|
|
|
|
* in this library, as they may have unrelated C runtimes. */
|
2010-03-02 21:58:06 +00:00
|
|
|
static int
|
2008-08-19 17:23:18 +00:00
|
|
|
gst_open (const gchar * filename, int flags, int mode)
|
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
|
|
|
|
int retval;
|
|
|
|
int save_errno;
|
|
|
|
|
|
|
|
if (wfilename == NULL) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = _wopen (wfilename, flags, mode);
|
|
|
|
save_errno = errno;
|
|
|
|
|
|
|
|
g_free (wfilename);
|
|
|
|
|
|
|
|
errno = save_errno;
|
|
|
|
return retval;
|
|
|
|
#else
|
|
|
|
return open (filename, flags, mode);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_file_src_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_file_src_debug
|
2003-06-29 14:05:49 +00:00
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2005-12-06 19:29:15 +00:00
|
|
|
#define DEFAULT_BLOCKSIZE 4*1024
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2011-06-07 15:03:09 +00:00
|
|
|
PROP_0,
|
2011-12-26 18:44:39 +00:00
|
|
|
PROP_LOCATION
|
2001-08-22 04:30:27 +00:00
|
|
|
};
|
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
static void gst_file_src_finalize (GObject * object);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
static void gst_file_src_set_property (GObject * object, guint prop_id,
|
2004-03-13 15:27:01 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2005-07-14 09:35:12 +00:00
|
|
|
static void gst_file_src_get_property (GObject * object, guint prop_id,
|
2004-03-13 15:27:01 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
static gboolean gst_file_src_start (GstBaseSrc * basesrc);
|
|
|
|
static gboolean gst_file_src_stop (GstBaseSrc * basesrc);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
static gboolean gst_file_src_is_seekable (GstBaseSrc * src);
|
|
|
|
static gboolean gst_file_src_get_size (GstBaseSrc * src, guint64 * size);
|
2011-06-10 11:04:23 +00:00
|
|
|
static GstFlowReturn gst_file_src_fill (GstBaseSrc * src, guint64 offset,
|
|
|
|
guint length, GstBuffer * buf);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
static void gst_file_src_uri_handler_init (gpointer g_iface,
|
2004-03-13 15:27:01 +00:00
|
|
|
gpointer iface_data);
|
2003-11-24 03:21:54 +00:00
|
|
|
|
2011-04-18 16:07:06 +00:00
|
|
|
#define _do_init \
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_file_src_uri_handler_init); \
|
2005-07-14 09:35:12 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_file_src_debug, "filesrc", 0, "filesrc element");
|
2011-04-18 16:07:06 +00:00
|
|
|
#define gst_file_src_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstFileSrc, gst_file_src, GST_TYPE_BASE_SRC, _do_init);
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
|
2001-08-22 04:30:27 +00:00
|
|
|
static void
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_class_init (GstFileSrcClass * klass)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
GObjectClass *gobject_class;
|
2011-04-18 16:07:06 +00:00
|
|
|
GstElementClass *gstelement_class;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
GstBaseSrcClass *gstbasesrc_class;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2006-05-11 18:10:34 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2011-04-18 16:07:06 +00:00
|
|
|
gstelement_class = GST_ELEMENT_CLASS (klass);
|
2006-05-11 18:10:34 +00:00
|
|
|
gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
gobject_class->set_property = gst_file_src_set_property;
|
|
|
|
gobject_class->get_property = gst_file_src_get_property;
|
2001-08-22 19:54:08 +00:00
|
|
|
|
2011-06-07 15:03:09 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LOCATION,
|
2004-03-13 15:27:01 +00:00
|
|
|
g_param_spec_string ("location", "File Location",
|
2008-03-22 14:56:17 +00:00
|
|
|
"Location of the file to read", NULL,
|
2009-02-20 19:09:19 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
|
|
|
GST_PARAM_MUTABLE_READY));
|
2001-08-22 19:54:08 +00:00
|
|
|
|
2009-10-28 00:29:30 +00:00
|
|
|
gobject_class->finalize = gst_file_src_finalize;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2012-04-09 12:05:07 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2011-04-18 16:07:06 +00:00
|
|
|
"File Source",
|
|
|
|
"Source/File",
|
|
|
|
"Read from arbitrary point in a file",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&srctemplate));
|
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_file_src_start);
|
|
|
|
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_file_src_stop);
|
|
|
|
gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_file_src_is_seekable);
|
|
|
|
gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_file_src_get_size);
|
2011-06-10 11:04:23 +00:00
|
|
|
gstbasesrc_class->fill = GST_DEBUG_FUNCPTR (gst_file_src_fill);
|
2005-07-30 15:00:07 +00:00
|
|
|
|
|
|
|
if (sizeof (off_t) < 8) {
|
2006-11-02 13:00:38 +00:00
|
|
|
GST_LOG ("No large file support, sizeof (off_t) = %" G_GSIZE_FORMAT "!",
|
|
|
|
sizeof (off_t));
|
2005-07-30 15:00:07 +00:00
|
|
|
}
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-18 16:07:06 +00:00
|
|
|
gst_file_src_init (GstFileSrc * src)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
|
|
|
src->filename = NULL;
|
|
|
|
src->fd = 0;
|
2004-03-21 03:22:55 +00:00
|
|
|
src->uri = NULL;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2004-04-21 14:51:27 +00:00
|
|
|
src->is_regular = FALSE;
|
2012-04-07 14:20:05 +00:00
|
|
|
|
|
|
|
gst_base_src_set_blocksize (GST_BASE_SRC (src), DEFAULT_BLOCKSIZE);
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
2001-12-28 15:19:38 +00:00
|
|
|
static void
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_finalize (GObject * object)
|
2001-12-28 15:19:38 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src;
|
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
src = GST_FILE_SRC (object);
|
2001-12-28 15:19:38 +00:00
|
|
|
|
2004-03-21 03:22:55 +00:00
|
|
|
g_free (src->filename);
|
|
|
|
g_free (src->uri);
|
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-12-28 15:19:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
static gboolean
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_set_location (GstFileSrc * src, const gchar * location)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
2007-06-05 16:25:06 +00:00
|
|
|
GstState state;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
|
2007-06-05 16:25:06 +00:00
|
|
|
/* the element must be stopped in order to do this */
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
state = GST_STATE (src);
|
|
|
|
if (state != GST_STATE_READY && state != GST_STATE_NULL)
|
|
|
|
goto wrong_state;
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
2003-11-24 03:21:54 +00:00
|
|
|
|
2004-03-21 03:22:55 +00:00
|
|
|
g_free (src->filename);
|
|
|
|
g_free (src->uri);
|
|
|
|
|
2013-09-29 15:35:11 +00:00
|
|
|
/* clear the filename if we get a NULL */
|
2003-11-24 03:21:54 +00:00
|
|
|
if (location == NULL) {
|
|
|
|
src->filename = NULL;
|
|
|
|
src->uri = NULL;
|
|
|
|
} else {
|
2011-02-24 15:32:00 +00:00
|
|
|
/* we store the filename as received by the application. On Windows this
|
2008-05-21 16:06:53 +00:00
|
|
|
* should be UTF8 */
|
2003-11-24 03:21:54 +00:00
|
|
|
src->filename = g_strdup (location);
|
2011-02-24 15:32:00 +00:00
|
|
|
src->uri = gst_filename_to_uri (location, NULL);
|
|
|
|
GST_INFO ("filename : %s", src->filename);
|
|
|
|
GST_INFO ("uri : %s", src->uri);
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|
|
|
|
g_object_notify (G_OBJECT (src), "location");
|
2014-09-25 19:21:09 +00:00
|
|
|
/* FIXME 2.0: notify "uri" property once there is one */
|
2003-11-24 03:21:54 +00:00
|
|
|
|
|
|
|
return TRUE;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
|
|
|
|
/* ERROR */
|
|
|
|
wrong_state:
|
|
|
|
{
|
2010-01-30 18:57:44 +00:00
|
|
|
g_warning ("Changing the `location' property on filesrc when a file is "
|
2009-06-12 14:51:22 +00:00
|
|
|
"open is not supported.");
|
2007-06-05 16:25:06 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
static void
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src;
|
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
g_return_if_fail (GST_IS_FILE_SRC (object));
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
src = GST_FILE_SRC (object);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-08-22 19:54:08 +00:00
|
|
|
switch (prop_id) {
|
2011-06-07 15:03:09 +00:00
|
|
|
case PROP_LOCATION:
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_set_location (src, g_value_get_string (value));
|
2001-08-22 04:30:27 +00:00
|
|
|
break;
|
|
|
|
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
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_get_property (GObject * object, guint prop_id, GValue * value,
|
2004-03-13 15:27:01 +00:00
|
|
|
GParamSpec * pspec)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
|
|
|
GstFileSrc *src;
|
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
g_return_if_fail (GST_IS_FILE_SRC (object));
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
src = GST_FILE_SRC (object);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
2001-08-22 19:54:08 +00:00
|
|
|
switch (prop_id) {
|
2011-06-07 15:03:09 +00:00
|
|
|
case PROP_LOCATION:
|
2001-08-22 19:54:08 +00:00
|
|
|
g_value_set_string (value, src->filename);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
/***
|
2005-07-14 09:35:12 +00:00
|
|
|
* read code below
|
|
|
|
* that is to say, you shouldn't read the code below, but the code that reads
|
|
|
|
* stuff is below. Well, you shouldn't not read the code below, feel free
|
|
|
|
* to read it of course. It's just that "read code below" is a pretty crappy
|
|
|
|
* documentation string because it sounds like we're expecting you to read
|
|
|
|
* the code to understand what it does, which, while true, is really not
|
|
|
|
* the sort of attitude we want to be advertising. No sir.
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2011-06-10 11:04:23 +00:00
|
|
|
gst_file_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
|
|
|
|
GstBuffer * buf)
|
2003-07-30 00:44:58 +00:00
|
|
|
{
|
2011-06-10 11:04:23 +00:00
|
|
|
GstFileSrc *src;
|
2011-12-25 11:58:12 +00:00
|
|
|
guint to_read, bytes_read;
|
2003-07-30 00:44:58 +00:00
|
|
|
int ret;
|
2012-01-20 13:23:57 +00:00
|
|
|
GstMapInfo info;
|
2011-03-21 17:13:55 +00:00
|
|
|
guint8 *data;
|
2011-06-10 11:04:23 +00:00
|
|
|
|
|
|
|
src = GST_FILE_SRC_CAST (basesrc);
|
2003-07-30 00:44:58 +00:00
|
|
|
|
2014-01-07 15:18:37 +00:00
|
|
|
if (G_UNLIKELY (offset != -1 && src->read_position != offset)) {
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
off_t res;
|
|
|
|
|
|
|
|
res = lseek (src->fd, offset, SEEK_SET);
|
2006-07-26 10:39:58 +00:00
|
|
|
if (G_UNLIKELY (res < 0 || res != offset))
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
goto seek_failed;
|
2006-02-23 10:24:13 +00:00
|
|
|
|
|
|
|
src->read_position = offset;
|
2003-07-30 00:44:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_buffer_map (buf, &info, GST_MAP_WRITE);
|
|
|
|
data = info.data;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
|
2011-12-25 11:58:12 +00:00
|
|
|
bytes_read = 0;
|
|
|
|
to_read = length;
|
|
|
|
while (to_read > 0) {
|
2009-10-08 06:55:59 +00:00
|
|
|
GST_LOG_OBJECT (src, "Reading %d bytes at offset 0x%" G_GINT64_MODIFIER "x",
|
2011-12-25 11:58:12 +00:00
|
|
|
to_read, offset + bytes_read);
|
2011-12-12 13:05:36 +00:00
|
|
|
errno = 0;
|
2011-12-25 11:58:12 +00:00
|
|
|
ret = read (src->fd, data + bytes_read, to_read);
|
2011-12-12 13:05:36 +00:00
|
|
|
if (G_UNLIKELY (ret < 0)) {
|
|
|
|
if (errno == EAGAIN || errno == EINTR)
|
|
|
|
continue;
|
2009-10-08 06:55:59 +00:00
|
|
|
goto could_not_read;
|
2011-12-12 13:05:36 +00:00
|
|
|
}
|
2009-10-08 06:55:59 +00:00
|
|
|
|
2011-12-12 13:05:36 +00:00
|
|
|
/* files should eos if they read 0 and more was requested */
|
2011-12-25 12:39:49 +00:00
|
|
|
if (G_UNLIKELY (ret == 0)) {
|
|
|
|
/* .. but first we should return any remaining data */
|
|
|
|
if (bytes_read > 0)
|
|
|
|
break;
|
2009-10-08 06:55:59 +00:00
|
|
|
goto eos;
|
2011-12-25 12:39:49 +00:00
|
|
|
}
|
2009-10-08 06:55:59 +00:00
|
|
|
|
2011-12-25 11:58:12 +00:00
|
|
|
to_read -= ret;
|
|
|
|
bytes_read += ret;
|
2009-10-08 06:55:59 +00:00
|
|
|
|
2011-12-12 13:05:36 +00:00
|
|
|
src->read_position += ret;
|
2009-10-08 06:55:59 +00:00
|
|
|
}
|
2011-03-21 17:13:55 +00:00
|
|
|
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_buffer_unmap (buf, &info);
|
2012-03-14 23:25:50 +00:00
|
|
|
if (bytes_read != length)
|
|
|
|
gst_buffer_resize (buf, 0, bytes_read);
|
2011-03-21 17:13:55 +00:00
|
|
|
|
2011-06-10 11:04:23 +00:00
|
|
|
GST_BUFFER_OFFSET (buf) = offset;
|
2011-12-25 11:58:12 +00:00
|
|
|
GST_BUFFER_OFFSET_END (buf) = offset + bytes_read;
|
2003-07-30 00:44:58 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
return GST_FLOW_OK;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
/* ERROR */
|
|
|
|
seek_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
could_not_read:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_buffer_unmap (buf, &info);
|
|
|
|
gst_buffer_resize (buf, 0, 0);
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2006-07-26 10:39:58 +00:00
|
|
|
eos:
|
|
|
|
{
|
2011-12-12 13:05:36 +00:00
|
|
|
GST_DEBUG ("EOS");
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_buffer_unmap (buf, &info);
|
|
|
|
gst_buffer_resize (buf, 0, 0);
|
2011-10-10 09:33:51 +00:00
|
|
|
return GST_FLOW_EOS;
|
2006-07-26 10:39:58 +00:00
|
|
|
}
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
2005-04-12 10:52:55 +00:00
|
|
|
static gboolean
|
2005-09-08 17:23:57 +00:00
|
|
|
gst_file_src_is_seekable (GstBaseSrc * basesrc)
|
2005-04-12 10:52:55 +00:00
|
|
|
{
|
2005-09-08 17:23:57 +00:00
|
|
|
GstFileSrc *src = GST_FILE_SRC (basesrc);
|
|
|
|
|
|
|
|
return src->seekable;
|
2005-04-12 10:52:55 +00:00
|
|
|
}
|
|
|
|
|
2003-11-17 01:11:32 +00:00
|
|
|
static gboolean
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_get_size (GstBaseSrc * basesrc, guint64 * size)
|
2003-11-17 01:11:32 +00:00
|
|
|
{
|
|
|
|
struct stat stat_results;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
GstFileSrc *src;
|
2003-11-17 01:11:32 +00:00
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
src = GST_FILE_SRC (basesrc);
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
|
2005-09-08 17:23:57 +00:00
|
|
|
if (!src->seekable) {
|
|
|
|
/* If it isn't seekable, we won't know the length (but fstat will still
|
|
|
|
* succeed, and wrongly say our length is zero. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
if (fstat (src->fd, &stat_results) < 0)
|
|
|
|
goto could_not_stat;
|
|
|
|
|
|
|
|
*size = stat_results.st_size;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-17 01:11:32 +00:00
|
|
|
return TRUE;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
|
|
|
|
/* ERROR */
|
|
|
|
could_not_stat:
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-11-17 01:11:32 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2012-05-15 18:11:15 +00:00
|
|
|
/* open the file, necessary to go to READY state */
|
2004-01-18 21:36:20 +00:00
|
|
|
static gboolean
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_start (GstBaseSrc * basesrc)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2005-07-14 09:35:12 +00:00
|
|
|
GstFileSrc *src = GST_FILE_SRC (basesrc);
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
struct stat stat_results;
|
2004-01-18 21:36:20 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
if (src->filename == NULL || src->filename[0] == '\0')
|
|
|
|
goto no_filename;
|
2004-01-18 21:36:20 +00:00
|
|
|
|
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 */
|
2008-08-19 17:23:18 +00:00
|
|
|
src->fd = gst_open (src->filename, O_RDONLY | O_BINARY, 0);
|
2008-05-21 16:06:53 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
if (src->fd < 0)
|
|
|
|
goto open_failed;
|
2002-05-08 20:40:48 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
/* check if it is a regular file, otherwise bail out */
|
|
|
|
if (fstat (src->fd, &stat_results) < 0)
|
|
|
|
goto no_stat;
|
2002-05-08 20:40:48 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
if (S_ISDIR (stat_results.st_mode))
|
|
|
|
goto was_directory;
|
|
|
|
|
|
|
|
if (S_ISSOCK (stat_results.st_mode))
|
|
|
|
goto was_socket;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
src->read_position = 0;
|
2001-08-22 04:30:27 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +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-21 14:51:27 +00:00
|
|
|
|
2011-06-07 15:03:09 +00:00
|
|
|
/* We need to check if the underlying file is seekable. */
|
2005-09-08 17:23:57 +00:00
|
|
|
{
|
2007-01-25 17:54:07 +00:00
|
|
|
off_t res = lseek (src->fd, 0, SEEK_END);
|
2005-09-08 17:23:57 +00:00
|
|
|
|
|
|
|
if (res < 0) {
|
2012-05-15 18:11:15 +00:00
|
|
|
GST_LOG_OBJECT (src, "disabling seeking, lseek failed: %s",
|
|
|
|
g_strerror (errno));
|
2005-09-08 17:23:57 +00:00
|
|
|
src->seekable = FALSE;
|
|
|
|
} else {
|
2014-06-03 02:07:52 +00:00
|
|
|
res = lseek (src->fd, 0, SEEK_SET);
|
|
|
|
|
|
|
|
if (res < 0) {
|
|
|
|
/* We really don't like not being able to go back to 0 */
|
|
|
|
src->seekable = FALSE;
|
|
|
|
goto lseek_wonky;
|
|
|
|
}
|
|
|
|
|
2005-09-08 17:23:57 +00:00
|
|
|
src->seekable = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can only really do seeking on regular files - for other file types, we
|
|
|
|
* don't know their length, so seeking isn't useful/meaningful */
|
|
|
|
src->seekable = src->seekable && src->is_regular;
|
2004-04-13 22:18:36 +00:00
|
|
|
|
2011-06-08 16:22:36 +00:00
|
|
|
gst_base_src_set_dynamic_size (basesrc, src->seekable);
|
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
return TRUE;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
/* ERROR */
|
|
|
|
no_filename:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
|
|
|
|
(_("No file name specified for reading.")), (NULL));
|
2011-12-06 12:47:29 +00:00
|
|
|
goto error_exit;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
}
|
|
|
|
open_failed:
|
|
|
|
{
|
|
|
|
switch (errno) {
|
|
|
|
case ENOENT:
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
|
|
|
|
("No such file \"%s\"", src->filename));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
2006-11-04 12:54:08 +00:00
|
|
|
(_("Could not open file \"%s\" for reading."), src->filename),
|
|
|
|
GST_ERROR_SYSTEM);
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
break;
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
2011-12-06 12:47:29 +00:00
|
|
|
goto error_exit;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
}
|
|
|
|
no_stat:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
2006-07-02 23:22:31 +00:00
|
|
|
(_("Could not get info on \"%s\"."), src->filename), (NULL));
|
2011-12-06 12:47:29 +00:00
|
|
|
goto error_close;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
}
|
|
|
|
was_directory:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
|
|
|
(_("\"%s\" is a directory."), src->filename), (NULL));
|
2011-12-06 12:47:29 +00:00
|
|
|
goto error_close;
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
}
|
|
|
|
was_socket:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
|
|
|
(_("File \"%s\" is a socket."), src->filename), (NULL));
|
2011-12-06 12:47:29 +00:00
|
|
|
goto error_close;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
2014-04-07 14:18:32 +00:00
|
|
|
lseek_wonky:
|
|
|
|
{
|
2014-04-07 14:38:17 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
|
|
|
|
("Could not seek back to zero after seek test in file \"%s\"",
|
|
|
|
src->filename));
|
2014-04-07 14:18:32 +00:00
|
|
|
goto error_close;
|
|
|
|
}
|
2011-12-06 12:47:29 +00:00
|
|
|
error_close:
|
|
|
|
close (src->fd);
|
|
|
|
error_exit:
|
|
|
|
return FALSE;
|
2001-08-22 04:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* unmap and close the file */
|
gst/: More work on the generic source base class, implement seeking, query.
Original commit message from CVS:
* gst/base/README:
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_get_formats), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state), (basesrc_find_peek),
(basesrc_find_suggest), (gst_basesrc_type_find):
* gst/base/gstbasesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_class_init), (gst_filesrc_init),
(gst_filesrc_finalize), (gst_filesrc_set_location),
(gst_filesrc_set_property), (gst_filesrc_get_property),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_get_size), (gst_filesrc_start), (gst_filesrc_stop):
* gst/elements/gstfilesrc.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_set_checkgetrange_function), (gst_pad_check_pull_range),
(gst_pad_pull_range):
* gst/gstpad.h:
More work on the generic source base class, implement seeking,
query.
Make filesrc extend the base source class.
Added gst_pad_set_checkgetrange_function to GstPad.
2005-04-06 17:30:48 +00:00
|
|
|
static gboolean
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_stop (GstBaseSrc * basesrc)
|
2001-08-22 04:30:27 +00:00
|
|
|
{
|
2005-07-14 09:35:12 +00:00
|
|
|
GstFileSrc *src = GST_FILE_SRC (basesrc);
|
2001-08-22 04:30:27 +00:00
|
|
|
|
|
|
|
/* close the file */
|
|
|
|
close (src->fd);
|
|
|
|
|
|
|
|
/* zero out a lot of our state */
|
|
|
|
src->fd = 0;
|
2004-04-21 14:51:27 +00:00
|
|
|
src->is_regular = FALSE;
|
2002-02-05 21:11:43 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
/*** GSTURIHANDLER INTERFACE *************************************************/
|
|
|
|
|
2006-10-09 09:32:29 +00:00
|
|
|
static GstURIType
|
2011-06-22 14:38:04 +00:00
|
|
|
gst_file_src_uri_get_type (GType type)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
return GST_URI_SRC;
|
|
|
|
}
|
2008-10-23 12:52:58 +00:00
|
|
|
|
2011-11-13 23:25:23 +00:00
|
|
|
static const gchar *const *
|
2011-06-22 14:38:04 +00:00
|
|
|
gst_file_src_uri_get_protocols (GType type)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
2011-11-13 23:25:23 +00:00
|
|
|
static const gchar *protocols[] = { "file", NULL };
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
return protocols;
|
|
|
|
}
|
2008-10-23 12:52:58 +00:00
|
|
|
|
2011-11-13 17:44:57 +00:00
|
|
|
static gchar *
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_uri_get_uri (GstURIHandler * handler)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
2005-07-14 09:35:12 +00:00
|
|
|
GstFileSrc *src = GST_FILE_SRC (handler);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2011-11-13 17:44:57 +00:00
|
|
|
/* FIXME: make thread-safe */
|
|
|
|
return g_strdup (src->uri);
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
static gboolean
|
2011-11-13 17:44:57 +00:00
|
|
|
gst_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
|
|
|
|
GError ** err)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
2008-11-20 21:05:14 +00:00
|
|
|
gchar *location, *hostname = NULL;
|
2008-11-24 11:56:44 +00:00
|
|
|
gboolean ret = FALSE;
|
2005-07-14 09:35:12 +00:00
|
|
|
GstFileSrc *src = GST_FILE_SRC (handler);
|
2003-11-24 03:21:54 +00:00
|
|
|
|
2008-11-20 21:05:14 +00:00
|
|
|
if (strcmp (uri, "file://") == 0) {
|
2007-04-27 07:27:36 +00:00
|
|
|
/* Special case for "file://" as this is used by some applications
|
|
|
|
* to test with gst_element_make_from_uri if there's an element
|
|
|
|
* that supports the URI protocol. */
|
2007-04-27 07:34:10 +00:00
|
|
|
gst_file_src_set_location (src, NULL);
|
2007-04-27 07:27:36 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-11-13 17:44:57 +00:00
|
|
|
location = g_filename_from_uri (uri, &hostname, err);
|
2008-11-20 21:05:14 +00:00
|
|
|
|
2011-11-13 17:44:57 +00:00
|
|
|
if (!location || (err != NULL && *err != NULL)) {
|
|
|
|
GST_WARNING_OBJECT (src, "Invalid URI '%s' for filesrc: %s", uri,
|
|
|
|
(err != NULL && *err != NULL) ? (*err)->message : "unknown error");
|
2008-11-24 11:56:44 +00:00
|
|
|
goto beach;
|
2007-02-02 10:41:29 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 11:56:44 +00:00
|
|
|
if ((hostname) && (strcmp (hostname, "localhost"))) {
|
|
|
|
/* Only 'localhost' is permitted */
|
|
|
|
GST_WARNING_OBJECT (src, "Invalid hostname '%s' for filesrc", hostname);
|
2011-11-13 17:44:57 +00:00
|
|
|
g_set_error (err, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
|
|
|
|
"File URI with invalid hostname '%s'", hostname);
|
2008-11-24 11:56:44 +00:00
|
|
|
goto beach;
|
2008-11-20 21:05:14 +00:00
|
|
|
}
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/* Unfortunately, g_filename_from_uri() doesn't handle some UNC paths
|
|
|
|
* correctly on windows, it leaves them with an extra backslash
|
|
|
|
* at the start if they're of the mozilla-style file://///host/path/file
|
|
|
|
* form. Correct this.
|
|
|
|
*/
|
|
|
|
if (location[0] == '\\' && location[1] == '\\' && location[2] == '\\')
|
2014-05-04 13:32:46 +00:00
|
|
|
memmove (location, location + 1, strlen (location + 1) + 1);
|
2008-11-20 21:05:14 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
ret = gst_file_src_set_location (src, location);
|
2008-11-24 11:56:44 +00:00
|
|
|
|
|
|
|
beach:
|
|
|
|
if (location)
|
|
|
|
g_free (location);
|
|
|
|
if (hostname)
|
|
|
|
g_free (hostname);
|
2003-11-24 03:21:54 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-07-14 09:35:12 +00:00
|
|
|
gst_file_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
|
|
|
|
|
2005-07-14 09:35:12 +00:00
|
|
|
iface->get_type = gst_file_src_uri_get_type;
|
|
|
|
iface->get_protocols = gst_file_src_uri_get_protocols;
|
|
|
|
iface->get_uri = gst_file_src_uri_get_uri;
|
|
|
|
iface->set_uri = gst_file_src_uri_set_uri;
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|