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"
73 #include <gnome-vfs-module-2.0/libgnomevfs/gnome-vfs-cancellable-ops.h>
77 #include <sys/types.h>
78 #include <sys/socket.h>
80 #include <netinet/in.h>
81 #include <arpa/inet.h>
91 #include <gst/tag/tag.h>
93 /* gnome-vfs.h doesn't include the following header, which we need: */
94 #include <libgnomevfs/gnome-vfs-standard-callbacks.h>
96 GST_DEBUG_CATEGORY_STATIC (gnomevfssrc_debug);
97 #define GST_CAT_DEFAULT gnomevfssrc_debug
99 static GStaticMutex count_lock = G_STATIC_MUTEX_INIT;
100 static gint ref_count = 0;
101 static gboolean vfs_owner = FALSE;
103 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
106 GST_STATIC_CAPS_ANY);
120 static void gst_gnome_vfs_src_finalize (GObject * object);
121 static void gst_gnome_vfs_src_uri_handler_init (gpointer g_iface,
122 gpointer iface_data);
124 static void gst_gnome_vfs_src_set_property (GObject * object, guint prop_id,
125 const GValue * value, GParamSpec * pspec);
126 static void gst_gnome_vfs_src_get_property (GObject * object, guint prop_id,
127 GValue * value, GParamSpec * pspec);
129 static gboolean gst_gnome_vfs_src_stop (GstBaseSrc * src);
130 static gboolean gst_gnome_vfs_src_start (GstBaseSrc * src);
131 static gboolean gst_gnome_vfs_src_is_seekable (GstBaseSrc * src);
132 static gboolean gst_gnome_vfs_src_unlock (GstBaseSrc * basesrc);
133 static gboolean gst_gnome_vfs_src_unlock_stop (GstBaseSrc * basesrc);
134 static gboolean gst_gnome_vfs_src_get_size (GstBaseSrc * src, guint64 * size);
135 static GstFlowReturn gst_gnome_vfs_src_create (GstBaseSrc * basesrc,
136 guint64 offset, guint size, GstBuffer ** buffer);
137 static gboolean gst_gnome_vfs_src_query (GstBaseSrc * src, GstQuery * query);
139 #define gst_gnome_vfs_src_parent_class parent_class
140 G_DEFINE_TYPE_WITH_CODE (GstGnomeVFSSrc, gst_gnome_vfs_src, GST_TYPE_BASE_SRC,
141 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
142 gst_gnome_vfs_src_uri_handler_init));
145 gst_gnome_vfs_src_class_init (GstGnomeVFSSrcClass * klass)
147 GObjectClass *gobject_class;
148 GstElementClass *gstelement_class;
149 GstBaseSrcClass *gstbasesrc_class;
151 gobject_class = G_OBJECT_CLASS (klass);
152 gstelement_class = GST_ELEMENT_CLASS (klass);
153 gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
155 GST_DEBUG_CATEGORY_INIT (gnomevfssrc_debug, "gnomevfssrc", 0,
158 gobject_class->finalize = gst_gnome_vfs_src_finalize;
159 gobject_class->set_property = gst_gnome_vfs_src_set_property;
160 gobject_class->get_property = gst_gnome_vfs_src_get_property;
163 gst_element_class_install_std_props (GST_ELEMENT_CLASS (klass),
164 "location", ARG_LOCATION, G_PARAM_READWRITE, NULL);
165 g_object_class_install_property (gobject_class,
167 g_param_spec_boxed ("handle",
168 "GnomeVFSHandle", "Handle for GnomeVFS",
169 GST_TYPE_GNOME_VFS_HANDLE,
170 GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
171 G_PARAM_STATIC_STRINGS));
174 g_object_class_install_property (gobject_class,
176 g_param_spec_boolean ("iradio-mode",
178 "Enable internet radio mode (extraction of shoutcast/icecast metadata)",
179 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
180 g_object_class_install_property (gobject_class,
182 g_param_spec_string ("iradio-name",
183 "iradio-name", "Name of the stream", NULL,
184 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
185 g_object_class_install_property (gobject_class, ARG_IRADIO_GENRE,
186 g_param_spec_string ("iradio-genre", "iradio-genre",
187 "Genre of the stream", NULL,
188 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
189 g_object_class_install_property (gobject_class, ARG_IRADIO_URL,
190 g_param_spec_string ("iradio-url", "iradio-url",
191 "Homepage URL for radio stream", NULL,
192 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
193 g_object_class_install_property (gobject_class, ARG_IRADIO_TITLE,
194 g_param_spec_string ("iradio-title", "iradio-title",
195 "Name of currently playing song", NULL,
196 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
198 gst_element_class_add_pad_template (gstelement_class,
199 gst_static_pad_template_get (&srctemplate));
200 gst_element_class_set_details_simple (gstelement_class,
201 "GnomeVFS Source", "Source/File",
202 "Read from any GnomeVFS-supported file",
203 "Bastien Nocera <hadess@hadess.net>, "
204 "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
206 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_start);
207 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_stop);
208 gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_unlock);
209 gstbasesrc_class->unlock_stop =
210 GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_unlock_stop);
211 gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_get_size);
212 gstbasesrc_class->is_seekable =
213 GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_is_seekable);
214 gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_create);
215 gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_query);
219 gst_gnome_vfs_src_init (GstGnomeVFSSrc * gnomevfssrc)
221 gnomevfssrc->uri = NULL;
222 gnomevfssrc->uri_name = NULL;
223 gnomevfssrc->context = NULL;
224 gnomevfssrc->handle = NULL;
225 gnomevfssrc->interrupted = FALSE;
226 gnomevfssrc->curoffset = 0;
227 gnomevfssrc->seekable = FALSE;
229 gnomevfssrc->iradio_mode = FALSE;
230 gnomevfssrc->http_callbacks_pushed = FALSE;
231 gnomevfssrc->iradio_name = NULL;
232 gnomevfssrc->iradio_genre = NULL;
233 gnomevfssrc->iradio_url = NULL;
234 gnomevfssrc->iradio_title = NULL;
236 g_static_mutex_lock (&count_lock);
237 if (ref_count == 0) {
238 /* gnome vfs engine init */
239 if (gnome_vfs_initialized () == FALSE) {
245 g_static_mutex_unlock (&count_lock);
249 gst_gnome_vfs_src_finalize (GObject * object)
251 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (object);
253 g_static_mutex_lock (&count_lock);
255 if (ref_count == 0 && vfs_owner) {
256 if (gnome_vfs_initialized () == TRUE) {
257 gnome_vfs_shutdown ();
260 g_static_mutex_unlock (&count_lock);
263 gnome_vfs_uri_unref (src->uri);
267 g_free (src->uri_name);
268 src->uri_name = NULL;
270 g_free (src->iradio_name);
271 src->iradio_name = NULL;
273 g_free (src->iradio_genre);
274 src->iradio_genre = NULL;
276 g_free (src->iradio_url);
277 src->iradio_url = NULL;
279 g_free (src->iradio_title);
280 src->iradio_title = NULL;
282 G_OBJECT_CLASS (parent_class)->finalize (object);
286 * URI interface support.
290 gst_gnome_vfs_src_uri_get_type (void)
296 gst_gnome_vfs_src_uri_get_protocols (void)
298 return gst_gnomevfs_get_supported_uris ();
302 gst_gnome_vfs_src_uri_get_uri (GstURIHandler * handler)
304 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (handler);
306 return src->uri_name;
310 gst_gnome_vfs_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
312 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (handler);
314 if (GST_STATE (src) == GST_STATE_PLAYING ||
315 GST_STATE (src) == GST_STATE_PAUSED)
318 g_object_set (G_OBJECT (src), "location", uri, NULL);
324 gst_gnome_vfs_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
326 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
328 iface->get_type = gst_gnome_vfs_src_uri_get_type;
329 iface->get_protocols = gst_gnome_vfs_src_uri_get_protocols;
330 iface->get_uri = gst_gnome_vfs_src_uri_get_uri;
331 iface->set_uri = gst_gnome_vfs_src_uri_set_uri;
335 gst_gnome_vfs_src_set_property (GObject * object, guint prop_id,
336 const GValue * value, GParamSpec * pspec)
340 src = GST_GNOME_VFS_SRC (object);
344 const gchar *new_location;
346 /* the element must be stopped or paused in order to do this */
347 if (GST_STATE (src) == GST_STATE_PLAYING ||
348 GST_STATE (src) == GST_STATE_PAUSED)
352 gnome_vfs_uri_unref (src->uri);
356 g_free (src->uri_name);
357 src->uri_name = NULL;
360 new_location = g_value_get_string (value);
362 src->uri_name = gst_gnome_vfs_location_to_uri_string (new_location);
363 src->uri = gnome_vfs_uri_new (src->uri_name);
368 if (GST_STATE (src) == GST_STATE_NULL ||
369 GST_STATE (src) == GST_STATE_READY) {
371 gnome_vfs_uri_unref (src->uri);
375 g_free (src->uri_name);
376 src->uri_name = NULL;
378 src->handle = g_value_get_boxed (value);
381 case ARG_IRADIO_MODE:
382 src->iradio_mode = g_value_get_boolean (value);
385 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
391 gst_gnome_vfs_src_get_property (GObject * object, guint prop_id, GValue * value,
396 src = GST_GNOME_VFS_SRC (object);
400 g_value_set_string (value, src->uri_name);
403 g_value_set_boxed (value, src->handle);
405 case ARG_IRADIO_MODE:
406 g_value_set_boolean (value, src->iradio_mode);
408 case ARG_IRADIO_NAME:
409 g_value_set_string (value, src->iradio_name);
411 case ARG_IRADIO_GENRE:
412 g_value_set_string (value, src->iradio_genre);
415 g_value_set_string (value, src->iradio_url);
417 case ARG_IRADIO_TITLE:
418 g_value_set_string (value, src->iradio_title);
421 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
427 gst_gnome_vfs_src_unicodify (const char *str)
429 const gchar *env_vars[] = { "GST_ICY_TAG_ENCODING",
430 "GST_TAG_ENCODING", NULL
433 return gst_tag_freeform_string_to_utf8 (str, -1, env_vars);
437 gst_gnome_vfs_src_send_additional_headers_callback (gconstpointer in,
438 gsize in_size, gpointer out, gsize out_size, gpointer callback_data)
440 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (callback_data);
441 GnomeVFSModuleCallbackAdditionalHeadersOut *out_args =
442 (GnomeVFSModuleCallbackAdditionalHeadersOut *) out;
444 if (!src->iradio_mode)
446 GST_DEBUG_OBJECT (src, "sending headers\n");
448 out_args->headers = g_list_append (out_args->headers,
449 g_strdup ("icy-metadata:1\r\n"));
453 gst_gnome_vfs_src_received_headers_callback (gconstpointer in,
454 gsize in_size, gpointer out, gsize out_size, gpointer callback_data)
458 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (callback_data);
459 GnomeVFSModuleCallbackReceivedHeadersIn *in_args =
460 (GnomeVFSModuleCallbackReceivedHeadersIn *) in;
462 /* This is only used for internet radio stuff right now */
463 if (!src->iradio_mode)
466 GST_DEBUG_OBJECT (src, "receiving internet radio metadata\n");
468 /* FIXME: Could we use "Accept-Ranges: bytes"
469 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.5
470 * to enable pull-mode?
473 for (i = in_args->headers; i; i = i->next) {
474 char *data = (char *) i->data;
475 char *value = strchr (data, ':');
486 GST_LOG_OBJECT (src, "data %s", data);
489 if (strncmp (data, "icy-metaint:", 12) == 0) { /* ugh */
490 if (sscanf (data + 12, "%d", &icy_metaint) == 1) {
491 if (icy_metaint > 0) {
494 icy_caps = gst_caps_new_simple ("application/x-icy",
495 "metadata-interval", G_TYPE_INT, icy_metaint, NULL);
496 gst_pad_set_caps (GST_BASE_SRC_PAD (src), icy_caps);
497 gst_caps_unref (icy_caps);
503 if (!strncmp (data, "icy-", 4))
508 GST_DEBUG_OBJECT (src, "key: %s", key);
509 if (!strncmp (key, "name", 4)) {
510 g_free (src->iradio_name);
511 src->iradio_name = gst_gnome_vfs_src_unicodify (value);
512 if (src->iradio_name)
513 g_object_notify (G_OBJECT (src), "iradio-name");
514 } else if (!strncmp (key, "genre", 5)) {
515 g_free (src->iradio_genre);
516 src->iradio_genre = gst_gnome_vfs_src_unicodify (value);
517 if (src->iradio_genre)
518 g_object_notify (G_OBJECT (src), "iradio-genre");
519 } else if (!strncmp (key, "url", 3)) {
520 g_free (src->iradio_url);
521 src->iradio_url = gst_gnome_vfs_src_unicodify (value);
523 g_object_notify (G_OBJECT (src), "iradio-url");
529 gst_gnome_vfs_src_push_callbacks (GstGnomeVFSSrc * src)
531 if (src->http_callbacks_pushed)
534 GST_DEBUG_OBJECT (src, "pushing callbacks");
535 gnome_vfs_module_callback_push
536 (GNOME_VFS_MODULE_CALLBACK_HTTP_SEND_ADDITIONAL_HEADERS,
537 gst_gnome_vfs_src_send_additional_headers_callback, src, NULL);
538 gnome_vfs_module_callback_push
539 (GNOME_VFS_MODULE_CALLBACK_HTTP_RECEIVED_HEADERS,
540 gst_gnome_vfs_src_received_headers_callback, src, NULL);
542 src->http_callbacks_pushed = TRUE;
546 gst_gnome_vfs_src_pop_callbacks (GstGnomeVFSSrc * src)
548 if (!src->http_callbacks_pushed)
551 GST_DEBUG_OBJECT (src, "popping callbacks");
552 gnome_vfs_module_callback_pop
553 (GNOME_VFS_MODULE_CALLBACK_HTTP_SEND_ADDITIONAL_HEADERS);
554 gnome_vfs_module_callback_pop
555 (GNOME_VFS_MODULE_CALLBACK_HTTP_RECEIVED_HEADERS);
557 src->http_callbacks_pushed = FALSE;
561 * Read a new buffer from src->reqoffset, takes care of events
562 * and seeking and such.
565 gst_gnome_vfs_src_create (GstBaseSrc * basesrc, guint64 offset, guint size,
570 GnomeVFSFileSize readbytes;
574 gboolean interrupted = FALSE;
576 src = GST_GNOME_VFS_SRC (basesrc);
578 GST_DEBUG ("now at %" G_GINT64_FORMAT ", reading from %" G_GUINT64_FORMAT
579 ", size %u", src->curoffset, offset, size);
581 /* seek if required */
582 if (G_UNLIKELY (src->curoffset != offset)) {
583 GST_DEBUG ("need to seek");
585 GST_DEBUG ("seeking to %" G_GUINT64_FORMAT, offset);
586 res = gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_START, offset);
587 if (res != GNOME_VFS_OK)
589 src->curoffset = offset;
595 buf = gst_buffer_new_and_alloc (size);
596 if (G_UNLIKELY (buf == NULL)) {
597 GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", size);
598 return GST_FLOW_ERROR;
601 data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
605 while (!src->interrupted && todo > 0) {
606 /* this can return less that we ask for */
608 gnome_vfs_read_cancellable (src->handle, data, todo, &readbytes,
611 if (G_UNLIKELY (res == GNOME_VFS_ERROR_CANCELLED)) {
612 GST_DEBUG_OBJECT (src, "interrupted");
614 /* Just take what we've so far gotten and return */
621 if (G_UNLIKELY (res == GNOME_VFS_ERROR_EOF || (res == GNOME_VFS_OK
625 if (G_UNLIKELY (res != GNOME_VFS_OK))
628 if (readbytes < todo) {
634 GST_LOG (" got size %" G_GUINT64_FORMAT, readbytes);
636 gst_buffer_unmap (buf, data, size);
641 GST_BUFFER_OFFSET (buf) = src->curoffset;
642 src->curoffset += size;
644 /* we're done, return the buffer */
651 GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL),
652 ("Failed to seek to requested position %" G_GINT64_FORMAT ": %s",
653 offset, gnome_vfs_result_to_string (res)));
654 return GST_FLOW_ERROR;
658 GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL),
659 ("Requested seek from %" G_GINT64_FORMAT " to %" G_GINT64_FORMAT
660 " on non-seekable stream", src->curoffset, offset));
661 return GST_FLOW_ERROR;
665 gst_buffer_unmap (buf, data, size);
666 gst_buffer_unref (buf);
667 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
668 ("Failed to read data: %s", gnome_vfs_result_to_string (res)));
669 return GST_FLOW_ERROR;
673 gst_buffer_unref (buf);
674 return GST_FLOW_WRONG_STATE;
678 gst_buffer_unmap (buf, data, size);
679 gst_buffer_unref (buf);
680 GST_DEBUG_OBJECT (src, "Reading data gave EOS");
681 return GST_FLOW_UNEXPECTED;
686 gst_gnome_vfs_src_is_seekable (GstBaseSrc * basesrc)
690 src = GST_GNOME_VFS_SRC (basesrc);
692 return src->seekable;
696 gst_gnome_vfs_src_scheduling (GstBaseSrc * basesrc, GstQuery * query)
699 const gchar *protocol;
702 src = GST_GNOME_VFS_SRC (basesrc);
706 if (src->uri == NULL) {
707 GST_WARNING_OBJECT (src, "no URI set yet");
711 if (gnome_vfs_uri_is_local (src->uri)) {
712 GST_LOG_OBJECT (src, "local URI (%s), assuming random access is possible",
713 GST_STR_NULL (src->uri_name));
716 /* blacklist certain protocols we know won't work getrange-based */
717 protocol = gnome_vfs_uri_get_scheme (src->uri);
718 if (protocol == NULL)
721 if (strcmp (protocol, "http") == 0 || strcmp (protocol, "https") == 0) {
723 "blacklisted protocol '%s', no random access possible" " (URI=%s)",
724 protocol, GST_STR_NULL (src->uri_name));
726 GST_LOG_OBJECT (src, "undecided about URI '%s', let base class handle it",
727 GST_STR_NULL (src->uri_name));
731 gst_query_set_scheduling (query, pull_mode, pull_mode, FALSE, 1, -1, 1);
735 /* fall through to undecided */
738 /* don't know what to do, let the basesrc class decide for us */
739 return GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
744 gst_gnome_vfs_src_query (GstBaseSrc * basesrc, GstQuery * query)
746 gboolean ret = FALSE;
747 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (basesrc);
749 switch (GST_QUERY_TYPE (query)) {
751 gst_query_set_uri (query, src->uri_name);
754 case GST_QUERY_SCHEDULING:
755 ret = gst_gnome_vfs_src_scheduling (basesrc, query);
758 ret = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
765 /* Interrupt a blocking request. */
767 gst_gnome_vfs_src_unlock (GstBaseSrc * basesrc)
771 src = GST_GNOME_VFS_SRC (basesrc);
772 GST_DEBUG_OBJECT (src, "unlock()");
773 src->interrupted = TRUE;
775 GnomeVFSCancellation *cancel =
776 gnome_vfs_context_get_cancellation (src->context);
778 gnome_vfs_cancellation_cancel (cancel);
783 /* Interrupt interrupt. */
785 gst_gnome_vfs_src_unlock_stop (GstBaseSrc * basesrc)
789 src = GST_GNOME_VFS_SRC (basesrc);
790 GST_DEBUG_OBJECT (src, "unlock_stop()");
792 src->interrupted = FALSE;
797 gst_gnome_vfs_src_get_size (GstBaseSrc * basesrc, guint64 * size)
800 GnomeVFSFileInfo *info;
801 GnomeVFSFileInfoOptions options;
804 src = GST_GNOME_VFS_SRC (basesrc);
807 info = gnome_vfs_file_info_new ();
808 options = GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS;
809 res = gnome_vfs_get_file_info_from_handle (src->handle, info, options);
810 if (res == GNOME_VFS_OK) {
811 if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) {
813 GST_DEBUG_OBJECT (src, "from handle: %" G_GUINT64_FORMAT " bytes", *size);
814 } else if (src->own_handle && gnome_vfs_uri_is_local (src->uri)) {
815 GST_DEBUG_OBJECT (src,
816 "file size not known, file local, trying fallback");
817 res = gnome_vfs_get_file_info_uri (src->uri, info, options);
818 if (res == GNOME_VFS_OK &&
819 (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) {
821 GST_DEBUG_OBJECT (src, "from uri: %" G_GUINT64_FORMAT " bytes", *size);
825 GST_WARNING_OBJECT (src, "getting info failed: %s",
826 gnome_vfs_result_to_string (res));
828 gnome_vfs_file_info_unref (info);
830 if (*size == (GnomeVFSFileSize) - 1)
833 GST_DEBUG_OBJECT (src, "return size %" G_GUINT64_FORMAT, *size);
838 /* open the file, do stuff necessary to go to PAUSED state */
840 gst_gnome_vfs_src_start (GstBaseSrc * basesrc)
845 src = GST_GNOME_VFS_SRC (basesrc);
847 gst_gnome_vfs_src_push_callbacks (src);
849 src->context = gnome_vfs_context_new ();
850 if (src->uri != NULL) {
851 GnomeVFSOpenMode mode = GNOME_VFS_OPEN_READ;
853 /* this can block... */
854 res = gnome_vfs_open_uri (&src->handle, src->uri, mode);
855 if (res != GNOME_VFS_OK)
857 src->own_handle = TRUE;
858 } else if (!src->handle) {
861 src->own_handle = FALSE;
864 if (gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_CURRENT, 0) == GNOME_VFS_OK) {
865 src->seekable = TRUE;
867 src->seekable = FALSE;
875 gchar *filename = gnome_vfs_uri_to_string (src->uri,
876 GNOME_VFS_URI_HIDE_PASSWORD);
878 gst_gnome_vfs_src_pop_callbacks (src);
880 if (res == GNOME_VFS_ERROR_NOT_FOUND ||
881 res == GNOME_VFS_ERROR_HOST_NOT_FOUND ||
882 res == GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE) {
883 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
884 ("Could not open vfs file \"%s\" for reading: %s (%d)",
885 filename, gnome_vfs_result_to_string (res), res));
887 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
888 ("Could not open vfs file \"%s\" for reading: %s (%d)",
889 filename, gnome_vfs_result_to_string (res), res));
896 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("No filename given"));
902 gst_gnome_vfs_src_stop (GstBaseSrc * basesrc)
906 src = GST_GNOME_VFS_SRC (basesrc);
908 gst_gnome_vfs_src_pop_callbacks (src);
910 if (src->own_handle) {
913 res = gnome_vfs_close (src->handle);
914 if (res != GNOME_VFS_OK) {
915 GST_ELEMENT_ERROR (src, RESOURCE, CLOSE, (NULL),
916 ("Could not close vfs handle: %s", gnome_vfs_result_to_string (res)));
921 src->interrupted = FALSE;
922 gnome_vfs_context_free (src->context);