2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2001 Bastien Nocera <hadess@hadess.net>
5 * 2002 Kristian Rietveld <kris@gtk.org>
6 * 2002,2003 Colin Walters <walters@gnu.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
27 * SECTION:element-gnomevfssrc
28 * @see_also: #GstFileSrc, #GstGnomeVFSSink
30 * This plugin reads data from a local or remote location specified
31 * by an URI. This location can be specified using any protocol supported by
32 * the GnomeVFS library. Common protocols are 'file', 'http', 'ftp', or 'smb'.
34 * In case the #GstGnomeVFSSrc:iradio-mode property is set and the
35 * location is a http resource, gnomevfssrc will send special icecast http
36 * headers to the server to request additional icecast metainformation. If
37 * the server is not an icecast server, it will display the same behaviour
38 * as if the #GstGnomeVFSSrc:iradio-mode property was not set. However,
39 * if the server is in fact an icecast server, gnomevfssrc will output
40 * data with a media type of application/x-icy, in which case you will
41 * need to use the #GstICYDemux element as follow-up element to extract
42 * the icecast meta data and to determine the underlying media type.
45 * <title>Example launch lines</title>
47 * gst-launch -v gnomevfssrc location=file:///home/joe/foo.xyz ! fakesink
48 * ]| The above pipeline will simply read a local file and do nothing with the
49 * data read. Instead of gnomevfssrc, we could just as well have used the
50 * filesrc element here.
52 * gst-launch -v gnomevfssrc location=smb://othercomputer/foo.xyz ! filesink location=/home/joe/foo.xyz
53 * ]| The above pipeline will copy a file from a remote host to the local file
54 * system using the Samba protocol.
56 * gst-launch -v gnomevfssrc location=http://music.foobar.com/demo.mp3 ! mad ! audioconvert ! audioresample ! alsasink
57 * ]| The above pipeline will read and decode and play an mp3 file from a
58 * web server using the http protocol.
64 /*#undef BROKEN_SIG */
70 #include "gst/gst-i18n-plugin.h"
72 #include "gstgnomevfssrc.h"
76 #include <sys/types.h>
77 #include <sys/socket.h>
79 #include <netinet/in.h>
80 #include <arpa/inet.h>
90 #include <gst/tag/tag.h>
92 /* gnome-vfs.h doesn't include the following header, which we need: */
93 #include <libgnomevfs/gnome-vfs-standard-callbacks.h>
95 GST_DEBUG_CATEGORY_STATIC (gnomevfssrc_debug);
96 #define GST_CAT_DEFAULT gnomevfssrc_debug
98 static GStaticMutex count_lock = G_STATIC_MUTEX_INIT;
99 static gint ref_count = 0;
100 static gboolean vfs_owner = FALSE;
102 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
105 GST_STATIC_CAPS_ANY);
119 static void gst_gnome_vfs_src_base_init (gpointer g_class);
120 static void gst_gnome_vfs_src_class_init (GstGnomeVFSSrcClass * klass);
121 static void gst_gnome_vfs_src_init (GstGnomeVFSSrc * gnomevfssrc);
122 static void gst_gnome_vfs_src_finalize (GObject * object);
123 static void gst_gnome_vfs_src_uri_handler_init (gpointer g_iface,
124 gpointer iface_data);
126 static void gst_gnome_vfs_src_set_property (GObject * object, guint prop_id,
127 const GValue * value, GParamSpec * pspec);
128 static void gst_gnome_vfs_src_get_property (GObject * object, guint prop_id,
129 GValue * value, GParamSpec * pspec);
131 static gboolean gst_gnome_vfs_src_stop (GstBaseSrc * src);
132 static gboolean gst_gnome_vfs_src_start (GstBaseSrc * src);
133 static gboolean gst_gnome_vfs_src_is_seekable (GstBaseSrc * src);
134 static gboolean gst_gnome_vfs_src_check_get_range (GstBaseSrc * src);
135 static gboolean gst_gnome_vfs_src_get_size (GstBaseSrc * src, guint64 * size);
136 static GstFlowReturn gst_gnome_vfs_src_create (GstBaseSrc * basesrc,
137 guint64 offset, guint size, GstBuffer ** buffer);
138 static gboolean gst_gnome_vfs_src_query (GstBaseSrc * src, GstQuery * query);
140 static GstElementClass *parent_class = NULL;
143 gst_gnome_vfs_src_get_type (void)
145 static GType gnomevfssrc_type = 0;
147 if (!gnomevfssrc_type) {
148 static const GTypeInfo gnomevfssrc_info = {
149 sizeof (GstGnomeVFSSrcClass),
150 gst_gnome_vfs_src_base_init,
152 (GClassInitFunc) gst_gnome_vfs_src_class_init,
155 sizeof (GstGnomeVFSSrc),
157 (GInstanceInitFunc) gst_gnome_vfs_src_init,
159 static const GInterfaceInfo urihandler_info = {
160 gst_gnome_vfs_src_uri_handler_init,
166 g_type_register_static (GST_TYPE_BASE_SRC,
167 "GstGnomeVFSSrc", &gnomevfssrc_info, 0);
168 g_type_add_interface_static (gnomevfssrc_type, GST_TYPE_URI_HANDLER,
171 return gnomevfssrc_type;
175 gst_gnome_vfs_src_base_init (gpointer g_class)
177 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
179 gst_element_class_add_pad_template (element_class,
180 gst_static_pad_template_get (&srctemplate));
181 gst_element_class_set_details_simple (element_class,
182 "GnomeVFS Source", "Source/File",
183 "Read from any GnomeVFS-supported file",
184 "Bastien Nocera <hadess@hadess.net>, "
185 "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
187 GST_DEBUG_CATEGORY_INIT (gnomevfssrc_debug, "gnomevfssrc", 0,
192 gst_gnome_vfs_src_class_init (GstGnomeVFSSrcClass * klass)
194 GObjectClass *gobject_class;
195 GstBaseSrcClass *gstbasesrc_class;
197 gobject_class = G_OBJECT_CLASS (klass);
198 gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
200 parent_class = g_type_class_peek_parent (klass);
202 gobject_class->finalize = gst_gnome_vfs_src_finalize;
203 gobject_class->set_property = gst_gnome_vfs_src_set_property;
204 gobject_class->get_property = gst_gnome_vfs_src_get_property;
207 gst_element_class_install_std_props (GST_ELEMENT_CLASS (klass),
208 "location", ARG_LOCATION, G_PARAM_READWRITE, NULL);
209 g_object_class_install_property (gobject_class,
211 g_param_spec_boxed ("handle",
212 "GnomeVFSHandle", "Handle for GnomeVFS",
213 GST_TYPE_GNOME_VFS_HANDLE,
214 GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
215 G_PARAM_STATIC_STRINGS));
218 g_object_class_install_property (gobject_class,
220 g_param_spec_boolean ("iradio-mode",
222 "Enable internet radio mode (extraction of shoutcast/icecast metadata)",
223 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
224 g_object_class_install_property (gobject_class,
226 g_param_spec_string ("iradio-name",
227 "iradio-name", "Name of the stream", NULL,
228 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
229 g_object_class_install_property (gobject_class, ARG_IRADIO_GENRE,
230 g_param_spec_string ("iradio-genre", "iradio-genre",
231 "Genre of the stream", NULL,
232 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
233 g_object_class_install_property (gobject_class, ARG_IRADIO_URL,
234 g_param_spec_string ("iradio-url", "iradio-url",
235 "Homepage URL for radio stream", NULL,
236 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
237 g_object_class_install_property (gobject_class, ARG_IRADIO_TITLE,
238 g_param_spec_string ("iradio-title", "iradio-title",
239 "Name of currently playing song", NULL,
240 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
242 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_start);
243 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_stop);
244 gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_get_size);
245 gstbasesrc_class->is_seekable =
246 GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_is_seekable);
247 gstbasesrc_class->check_get_range =
248 GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_check_get_range);
249 gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_create);
250 gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_query);
254 gst_gnome_vfs_src_init (GstGnomeVFSSrc * gnomevfssrc)
256 gnomevfssrc->uri = NULL;
257 gnomevfssrc->uri_name = NULL;
258 gnomevfssrc->handle = NULL;
259 gnomevfssrc->curoffset = 0;
260 gnomevfssrc->seekable = FALSE;
262 gnomevfssrc->iradio_mode = FALSE;
263 gnomevfssrc->http_callbacks_pushed = FALSE;
264 gnomevfssrc->iradio_name = NULL;
265 gnomevfssrc->iradio_genre = NULL;
266 gnomevfssrc->iradio_url = NULL;
267 gnomevfssrc->iradio_title = NULL;
269 g_static_mutex_lock (&count_lock);
270 if (ref_count == 0) {
271 /* gnome vfs engine init */
272 if (gnome_vfs_initialized () == FALSE) {
278 g_static_mutex_unlock (&count_lock);
282 gst_gnome_vfs_src_finalize (GObject * object)
284 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (object);
286 g_static_mutex_lock (&count_lock);
288 if (ref_count == 0 && vfs_owner) {
289 if (gnome_vfs_initialized () == TRUE) {
290 gnome_vfs_shutdown ();
293 g_static_mutex_unlock (&count_lock);
296 gnome_vfs_uri_unref (src->uri);
300 g_free (src->uri_name);
301 src->uri_name = NULL;
303 g_free (src->iradio_name);
304 src->iradio_name = NULL;
306 g_free (src->iradio_genre);
307 src->iradio_genre = NULL;
309 g_free (src->iradio_url);
310 src->iradio_url = NULL;
312 g_free (src->iradio_title);
313 src->iradio_title = NULL;
315 G_OBJECT_CLASS (parent_class)->finalize (object);
319 * URI interface support.
323 gst_gnome_vfs_src_uri_get_type (void)
329 gst_gnome_vfs_src_uri_get_protocols (void)
331 return gst_gnomevfs_get_supported_uris ();
335 gst_gnome_vfs_src_uri_get_uri (GstURIHandler * handler)
337 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (handler);
339 return src->uri_name;
343 gst_gnome_vfs_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
345 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (handler);
347 if (GST_STATE (src) == GST_STATE_PLAYING ||
348 GST_STATE (src) == GST_STATE_PAUSED)
351 g_object_set (G_OBJECT (src), "location", uri, NULL);
357 gst_gnome_vfs_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
359 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
361 iface->get_type = gst_gnome_vfs_src_uri_get_type;
362 iface->get_protocols = gst_gnome_vfs_src_uri_get_protocols;
363 iface->get_uri = gst_gnome_vfs_src_uri_get_uri;
364 iface->set_uri = gst_gnome_vfs_src_uri_set_uri;
368 gst_gnome_vfs_src_set_property (GObject * object, guint prop_id,
369 const GValue * value, GParamSpec * pspec)
373 src = GST_GNOME_VFS_SRC (object);
377 const gchar *new_location;
379 /* the element must be stopped or paused in order to do this */
380 if (GST_STATE (src) == GST_STATE_PLAYING ||
381 GST_STATE (src) == GST_STATE_PAUSED)
385 gnome_vfs_uri_unref (src->uri);
389 g_free (src->uri_name);
390 src->uri_name = NULL;
393 new_location = g_value_get_string (value);
395 src->uri_name = gst_gnome_vfs_location_to_uri_string (new_location);
396 src->uri = gnome_vfs_uri_new (src->uri_name);
401 if (GST_STATE (src) == GST_STATE_NULL ||
402 GST_STATE (src) == GST_STATE_READY) {
404 gnome_vfs_uri_unref (src->uri);
408 g_free (src->uri_name);
409 src->uri_name = NULL;
411 src->handle = g_value_get_boxed (value);
414 case ARG_IRADIO_MODE:
415 src->iradio_mode = g_value_get_boolean (value);
418 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
424 gst_gnome_vfs_src_get_property (GObject * object, guint prop_id, GValue * value,
429 src = GST_GNOME_VFS_SRC (object);
433 g_value_set_string (value, src->uri_name);
436 g_value_set_boxed (value, src->handle);
438 case ARG_IRADIO_MODE:
439 g_value_set_boolean (value, src->iradio_mode);
441 case ARG_IRADIO_NAME:
442 g_value_set_string (value, src->iradio_name);
444 case ARG_IRADIO_GENRE:
445 g_value_set_string (value, src->iradio_genre);
448 g_value_set_string (value, src->iradio_url);
450 case ARG_IRADIO_TITLE:
451 g_value_set_string (value, src->iradio_title);
454 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
460 gst_gnome_vfs_src_unicodify (const char *str)
462 const gchar *env_vars[] = { "GST_ICY_TAG_ENCODING",
463 "GST_TAG_ENCODING", NULL
466 return gst_tag_freeform_string_to_utf8 (str, -1, env_vars);
470 gst_gnome_vfs_src_send_additional_headers_callback (gconstpointer in,
471 gsize in_size, gpointer out, gsize out_size, gpointer callback_data)
473 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (callback_data);
474 GnomeVFSModuleCallbackAdditionalHeadersOut *out_args =
475 (GnomeVFSModuleCallbackAdditionalHeadersOut *) out;
477 if (!src->iradio_mode)
479 GST_DEBUG_OBJECT (src, "sending headers\n");
481 out_args->headers = g_list_append (out_args->headers,
482 g_strdup ("icy-metadata:1\r\n"));
486 gst_gnome_vfs_src_received_headers_callback (gconstpointer in,
487 gsize in_size, gpointer out, gsize out_size, gpointer callback_data)
491 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (callback_data);
492 GnomeVFSModuleCallbackReceivedHeadersIn *in_args =
493 (GnomeVFSModuleCallbackReceivedHeadersIn *) in;
495 /* This is only used for internet radio stuff right now */
496 if (!src->iradio_mode)
499 GST_DEBUG_OBJECT (src, "receiving internet radio metadata\n");
501 /* FIXME: Could we use "Accept-Ranges: bytes"
502 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.5
503 * to enable pull-mode?
506 for (i = in_args->headers; i; i = i->next) {
507 char *data = (char *) i->data;
508 char *value = strchr (data, ':');
519 GST_LOG_OBJECT (src, "data %s", data);
522 if (strncmp (data, "icy-metaint:", 12) == 0) { /* ugh */
523 if (sscanf (data + 12, "%d", &icy_metaint) == 1) {
524 if (icy_metaint > 0) {
527 icy_caps = gst_caps_new_simple ("application/x-icy",
528 "metadata-interval", G_TYPE_INT, icy_metaint, NULL);
529 gst_pad_set_caps (GST_BASE_SRC_PAD (src), icy_caps);
530 gst_caps_unref (icy_caps);
536 if (!strncmp (data, "icy-", 4))
541 GST_DEBUG_OBJECT (src, "key: %s", key);
542 if (!strncmp (key, "name", 4)) {
543 g_free (src->iradio_name);
544 src->iradio_name = gst_gnome_vfs_src_unicodify (value);
545 if (src->iradio_name)
546 g_object_notify (G_OBJECT (src), "iradio-name");
547 } else if (!strncmp (key, "genre", 5)) {
548 g_free (src->iradio_genre);
549 src->iradio_genre = gst_gnome_vfs_src_unicodify (value);
550 if (src->iradio_genre)
551 g_object_notify (G_OBJECT (src), "iradio-genre");
552 } else if (!strncmp (key, "url", 3)) {
553 g_free (src->iradio_url);
554 src->iradio_url = gst_gnome_vfs_src_unicodify (value);
556 g_object_notify (G_OBJECT (src), "iradio-url");
562 gst_gnome_vfs_src_push_callbacks (GstGnomeVFSSrc * src)
564 if (src->http_callbacks_pushed)
567 GST_DEBUG_OBJECT (src, "pushing callbacks");
568 gnome_vfs_module_callback_push
569 (GNOME_VFS_MODULE_CALLBACK_HTTP_SEND_ADDITIONAL_HEADERS,
570 gst_gnome_vfs_src_send_additional_headers_callback, src, NULL);
571 gnome_vfs_module_callback_push
572 (GNOME_VFS_MODULE_CALLBACK_HTTP_RECEIVED_HEADERS,
573 gst_gnome_vfs_src_received_headers_callback, src, NULL);
575 src->http_callbacks_pushed = TRUE;
579 gst_gnome_vfs_src_pop_callbacks (GstGnomeVFSSrc * src)
581 if (!src->http_callbacks_pushed)
584 GST_DEBUG_OBJECT (src, "popping callbacks");
585 gnome_vfs_module_callback_pop
586 (GNOME_VFS_MODULE_CALLBACK_HTTP_SEND_ADDITIONAL_HEADERS);
587 gnome_vfs_module_callback_pop
588 (GNOME_VFS_MODULE_CALLBACK_HTTP_RECEIVED_HEADERS);
590 src->http_callbacks_pushed = FALSE;
594 * Read a new buffer from src->reqoffset, takes care of events
595 * and seeking and such.
598 gst_gnome_vfs_src_create (GstBaseSrc * basesrc, guint64 offset, guint size,
603 GnomeVFSFileSize readbytes;
608 src = GST_GNOME_VFS_SRC (basesrc);
610 GST_DEBUG ("now at %" G_GINT64_FORMAT ", reading from %" G_GUINT64_FORMAT
611 ", size %u", src->curoffset, offset, size);
613 /* seek if required */
614 if (G_UNLIKELY (src->curoffset != offset)) {
615 GST_DEBUG ("need to seek");
617 GST_DEBUG ("seeking to %" G_GUINT64_FORMAT, offset);
618 res = gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_START, offset);
619 if (res != GNOME_VFS_OK)
621 src->curoffset = offset;
627 buf = gst_buffer_try_new_and_alloc (size);
628 if (G_UNLIKELY (buf == NULL)) {
629 GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", size);
630 return GST_FLOW_ERROR;
633 data = GST_BUFFER_DATA (buf);
637 /* this can return less that we ask for */
638 res = gnome_vfs_read (src->handle, data, todo, &readbytes);
640 if (G_UNLIKELY (res == GNOME_VFS_ERROR_EOF || (res == GNOME_VFS_OK
644 if (G_UNLIKELY (res != GNOME_VFS_OK))
647 if (readbytes < todo) {
648 data = &data[readbytes];
653 GST_LOG (" got size %" G_GUINT64_FORMAT, readbytes);
655 GST_BUFFER_OFFSET (buf) = src->curoffset;
656 src->curoffset += size;
658 /* we're done, return the buffer */
665 GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL),
666 ("Failed to seek to requested position %" G_GINT64_FORMAT ": %s",
667 offset, gnome_vfs_result_to_string (res)));
668 return GST_FLOW_ERROR;
672 GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL),
673 ("Requested seek from %" G_GINT64_FORMAT " to %" G_GINT64_FORMAT
674 " on non-seekable stream", src->curoffset, offset));
675 return GST_FLOW_ERROR;
679 gst_buffer_unref (buf);
680 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
681 ("Failed to read data: %s", gnome_vfs_result_to_string (res)));
682 return GST_FLOW_ERROR;
686 gst_buffer_unref (buf);
687 GST_DEBUG_OBJECT (src, "Reading data gave EOS");
688 return GST_FLOW_UNEXPECTED;
693 gst_gnome_vfs_src_query (GstBaseSrc * basesrc, GstQuery * query)
695 gboolean ret = FALSE;
696 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (basesrc);
698 switch (GST_QUERY_TYPE (query)) {
700 gst_query_set_uri (query, src->uri_name);
709 ret = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
715 gst_gnome_vfs_src_is_seekable (GstBaseSrc * basesrc)
719 src = GST_GNOME_VFS_SRC (basesrc);
721 return src->seekable;
725 gst_gnome_vfs_src_check_get_range (GstBaseSrc * basesrc)
728 const gchar *protocol;
730 src = GST_GNOME_VFS_SRC (basesrc);
732 if (src->uri == NULL) {
733 GST_WARNING_OBJECT (src, "no URI set yet");
737 if (gnome_vfs_uri_is_local (src->uri)) {
738 GST_LOG_OBJECT (src, "local URI (%s), assuming random access is possible",
739 GST_STR_NULL (src->uri_name));
743 /* blacklist certain protocols we know won't work getrange-based */
744 protocol = gnome_vfs_uri_get_scheme (src->uri);
745 if (protocol == NULL)
748 if (strcmp (protocol, "http") == 0 || strcmp (protocol, "https") == 0) {
749 GST_LOG_OBJECT (src, "blacklisted protocol '%s', no random access possible"
750 " (URI=%s)", protocol, GST_STR_NULL (src->uri_name));
754 /* fall through to undecided */
758 /* don't know what to do, let the basesrc class decide for us */
759 GST_LOG_OBJECT (src, "undecided about URI '%s', let base class handle it",
760 GST_STR_NULL (src->uri_name));
762 if (GST_BASE_SRC_CLASS (parent_class)->check_get_range)
763 return GST_BASE_SRC_CLASS (parent_class)->check_get_range (basesrc);
770 gst_gnome_vfs_src_get_size (GstBaseSrc * basesrc, guint64 * size)
773 GnomeVFSFileInfo *info;
774 GnomeVFSFileInfoOptions options;
777 src = GST_GNOME_VFS_SRC (basesrc);
780 info = gnome_vfs_file_info_new ();
781 options = GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS;
782 res = gnome_vfs_get_file_info_from_handle (src->handle, info, options);
783 if (res == GNOME_VFS_OK) {
784 if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) {
786 GST_DEBUG_OBJECT (src, "from handle: %" G_GUINT64_FORMAT " bytes", *size);
787 } else if (src->own_handle && gnome_vfs_uri_is_local (src->uri)) {
788 GST_DEBUG_OBJECT (src,
789 "file size not known, file local, trying fallback");
790 res = gnome_vfs_get_file_info_uri (src->uri, info, options);
791 if (res == GNOME_VFS_OK &&
792 (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) {
794 GST_DEBUG_OBJECT (src, "from uri: %" G_GUINT64_FORMAT " bytes", *size);
798 GST_WARNING_OBJECT (src, "getting info failed: %s",
799 gnome_vfs_result_to_string (res));
801 gnome_vfs_file_info_unref (info);
803 if (*size == (GnomeVFSFileSize) - 1)
806 GST_DEBUG_OBJECT (src, "return size %" G_GUINT64_FORMAT, *size);
811 /* open the file, do stuff necessary to go to PAUSED state */
813 gst_gnome_vfs_src_start (GstBaseSrc * basesrc)
818 src = GST_GNOME_VFS_SRC (basesrc);
820 gst_gnome_vfs_src_push_callbacks (src);
822 if (src->uri != NULL) {
823 GnomeVFSOpenMode mode = GNOME_VFS_OPEN_READ;
825 /* this can block... */
826 res = gnome_vfs_open_uri (&src->handle, src->uri, mode);
827 if (res != GNOME_VFS_OK)
829 src->own_handle = TRUE;
830 } else if (!src->handle) {
833 src->own_handle = FALSE;
836 if (gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_CURRENT, 0) == GNOME_VFS_OK) {
837 src->seekable = TRUE;
839 src->seekable = FALSE;
847 gchar *filename = gnome_vfs_uri_to_string (src->uri,
848 GNOME_VFS_URI_HIDE_PASSWORD);
850 gst_gnome_vfs_src_pop_callbacks (src);
852 if (res == GNOME_VFS_ERROR_NOT_FOUND ||
853 res == GNOME_VFS_ERROR_HOST_NOT_FOUND ||
854 res == GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE) {
855 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
856 ("Could not open vfs file \"%s\" for reading: %s (%d)",
857 filename, gnome_vfs_result_to_string (res), res));
859 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
860 ("Could not open vfs file \"%s\" for reading: %s (%d)",
861 filename, gnome_vfs_result_to_string (res), res));
868 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("No filename given"));
874 gst_gnome_vfs_src_stop (GstBaseSrc * basesrc)
878 src = GST_GNOME_VFS_SRC (basesrc);
880 gst_gnome_vfs_src_pop_callbacks (src);
882 if (src->own_handle) {
885 res = gnome_vfs_close (src->handle);
886 if (res != GNOME_VFS_OK) {
887 GST_ELEMENT_ERROR (src, RESOURCE, CLOSE, (NULL),
888 ("Could not close vfs handle: %s", gnome_vfs_result_to_string (res)));