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_base_init (gpointer g_class);
121 static void gst_gnome_vfs_src_class_init (GstGnomeVFSSrcClass * klass);
122 static void gst_gnome_vfs_src_init (GstGnomeVFSSrc * gnomevfssrc);
123 static void gst_gnome_vfs_src_finalize (GObject * object);
124 static void gst_gnome_vfs_src_uri_handler_init (gpointer g_iface,
125 gpointer iface_data);
127 static void gst_gnome_vfs_src_set_property (GObject * object, guint prop_id,
128 const GValue * value, GParamSpec * pspec);
129 static void gst_gnome_vfs_src_get_property (GObject * object, guint prop_id,
130 GValue * value, GParamSpec * pspec);
132 static gboolean gst_gnome_vfs_src_stop (GstBaseSrc * src);
133 static gboolean gst_gnome_vfs_src_start (GstBaseSrc * src);
134 static gboolean gst_gnome_vfs_src_is_seekable (GstBaseSrc * src);
135 static gboolean gst_gnome_vfs_src_check_get_range (GstBaseSrc * src);
136 static gboolean gst_gnome_vfs_src_unlock (GstBaseSrc * basesrc);
137 static gboolean gst_gnome_vfs_src_unlock_stop (GstBaseSrc * basesrc);
138 static gboolean gst_gnome_vfs_src_get_size (GstBaseSrc * src, guint64 * size);
139 static GstFlowReturn gst_gnome_vfs_src_create (GstBaseSrc * basesrc,
140 guint64 offset, guint size, GstBuffer ** buffer);
141 static gboolean gst_gnome_vfs_src_query (GstBaseSrc * src, GstQuery * query);
143 static GstElementClass *parent_class = NULL;
146 gst_gnome_vfs_src_get_type (void)
148 static GType gnomevfssrc_type = 0;
150 if (!gnomevfssrc_type) {
151 static const GTypeInfo gnomevfssrc_info = {
152 sizeof (GstGnomeVFSSrcClass),
153 gst_gnome_vfs_src_base_init,
155 (GClassInitFunc) gst_gnome_vfs_src_class_init,
158 sizeof (GstGnomeVFSSrc),
160 (GInstanceInitFunc) gst_gnome_vfs_src_init,
162 static const GInterfaceInfo urihandler_info = {
163 gst_gnome_vfs_src_uri_handler_init,
169 g_type_register_static (GST_TYPE_BASE_SRC,
170 "GstGnomeVFSSrc", &gnomevfssrc_info, 0);
171 g_type_add_interface_static (gnomevfssrc_type, GST_TYPE_URI_HANDLER,
174 return gnomevfssrc_type;
178 gst_gnome_vfs_src_base_init (gpointer g_class)
180 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
182 gst_element_class_add_static_pad_template (element_class, &srctemplate);
183 gst_element_class_set_details_simple (element_class,
184 "GnomeVFS Source", "Source/File",
185 "Read from any GnomeVFS-supported file",
186 "Bastien Nocera <hadess@hadess.net>, "
187 "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
189 GST_DEBUG_CATEGORY_INIT (gnomevfssrc_debug, "gnomevfssrc", 0,
194 gst_gnome_vfs_src_class_init (GstGnomeVFSSrcClass * klass)
196 GObjectClass *gobject_class;
197 GstBaseSrcClass *gstbasesrc_class;
199 gobject_class = G_OBJECT_CLASS (klass);
200 gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
202 parent_class = g_type_class_peek_parent (klass);
204 gobject_class->finalize = gst_gnome_vfs_src_finalize;
205 gobject_class->set_property = gst_gnome_vfs_src_set_property;
206 gobject_class->get_property = gst_gnome_vfs_src_get_property;
209 gst_element_class_install_std_props (GST_ELEMENT_CLASS (klass),
210 "location", ARG_LOCATION, G_PARAM_READWRITE, NULL);
211 g_object_class_install_property (gobject_class,
213 g_param_spec_boxed ("handle",
214 "GnomeVFSHandle", "Handle for GnomeVFS",
215 GST_TYPE_GNOME_VFS_HANDLE,
216 GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
217 G_PARAM_STATIC_STRINGS));
220 g_object_class_install_property (gobject_class,
222 g_param_spec_boolean ("iradio-mode",
224 "Enable internet radio mode (extraction of shoutcast/icecast metadata)",
225 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
226 g_object_class_install_property (gobject_class,
228 g_param_spec_string ("iradio-name",
229 "iradio-name", "Name of the stream", NULL,
230 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
231 g_object_class_install_property (gobject_class, ARG_IRADIO_GENRE,
232 g_param_spec_string ("iradio-genre", "iradio-genre",
233 "Genre of the stream", NULL,
234 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
235 g_object_class_install_property (gobject_class, ARG_IRADIO_URL,
236 g_param_spec_string ("iradio-url", "iradio-url",
237 "Homepage URL for radio stream", NULL,
238 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
239 g_object_class_install_property (gobject_class, ARG_IRADIO_TITLE,
240 g_param_spec_string ("iradio-title", "iradio-title",
241 "Name of currently playing song", NULL,
242 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
244 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_start);
245 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_stop);
246 gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_unlock);
247 gstbasesrc_class->unlock_stop =
248 GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_unlock_stop);
249 gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_get_size);
250 gstbasesrc_class->is_seekable =
251 GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_is_seekable);
252 gstbasesrc_class->check_get_range =
253 GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_check_get_range);
254 gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_create);
255 gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_gnome_vfs_src_query);
259 gst_gnome_vfs_src_init (GstGnomeVFSSrc * gnomevfssrc)
261 gnomevfssrc->uri = NULL;
262 gnomevfssrc->uri_name = NULL;
263 gnomevfssrc->context = NULL;
264 gnomevfssrc->handle = NULL;
265 gnomevfssrc->interrupted = FALSE;
266 gnomevfssrc->curoffset = 0;
267 gnomevfssrc->seekable = FALSE;
269 gnomevfssrc->iradio_mode = FALSE;
270 gnomevfssrc->http_callbacks_pushed = FALSE;
271 gnomevfssrc->iradio_name = NULL;
272 gnomevfssrc->iradio_genre = NULL;
273 gnomevfssrc->iradio_url = NULL;
274 gnomevfssrc->iradio_title = NULL;
276 g_static_mutex_lock (&count_lock);
277 if (ref_count == 0) {
278 /* gnome vfs engine init */
279 if (gnome_vfs_initialized () == FALSE) {
285 g_static_mutex_unlock (&count_lock);
289 gst_gnome_vfs_src_finalize (GObject * object)
291 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (object);
293 g_static_mutex_lock (&count_lock);
295 if (ref_count == 0 && vfs_owner) {
296 if (gnome_vfs_initialized () == TRUE) {
297 gnome_vfs_shutdown ();
300 g_static_mutex_unlock (&count_lock);
303 gnome_vfs_uri_unref (src->uri);
307 g_free (src->uri_name);
308 src->uri_name = NULL;
310 g_free (src->iradio_name);
311 src->iradio_name = NULL;
313 g_free (src->iradio_genre);
314 src->iradio_genre = NULL;
316 g_free (src->iradio_url);
317 src->iradio_url = NULL;
319 g_free (src->iradio_title);
320 src->iradio_title = NULL;
322 G_OBJECT_CLASS (parent_class)->finalize (object);
326 * URI interface support.
330 gst_gnome_vfs_src_uri_get_type (void)
336 gst_gnome_vfs_src_uri_get_protocols (void)
338 return gst_gnomevfs_get_supported_uris ();
342 gst_gnome_vfs_src_uri_get_uri (GstURIHandler * handler)
344 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (handler);
346 return src->uri_name;
350 gst_gnome_vfs_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
352 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (handler);
354 if (GST_STATE (src) == GST_STATE_PLAYING ||
355 GST_STATE (src) == GST_STATE_PAUSED)
358 g_object_set (G_OBJECT (src), "location", uri, NULL);
364 gst_gnome_vfs_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
366 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
368 iface->get_type = gst_gnome_vfs_src_uri_get_type;
369 iface->get_protocols = gst_gnome_vfs_src_uri_get_protocols;
370 iface->get_uri = gst_gnome_vfs_src_uri_get_uri;
371 iface->set_uri = gst_gnome_vfs_src_uri_set_uri;
375 gst_gnome_vfs_src_set_property (GObject * object, guint prop_id,
376 const GValue * value, GParamSpec * pspec)
380 src = GST_GNOME_VFS_SRC (object);
384 const gchar *new_location;
386 /* the element must be stopped or paused in order to do this */
387 if (GST_STATE (src) == GST_STATE_PLAYING ||
388 GST_STATE (src) == GST_STATE_PAUSED)
392 gnome_vfs_uri_unref (src->uri);
396 g_free (src->uri_name);
397 src->uri_name = NULL;
400 new_location = g_value_get_string (value);
402 src->uri_name = gst_gnome_vfs_location_to_uri_string (new_location);
403 src->uri = gnome_vfs_uri_new (src->uri_name);
408 if (GST_STATE (src) == GST_STATE_NULL ||
409 GST_STATE (src) == GST_STATE_READY) {
411 gnome_vfs_uri_unref (src->uri);
415 g_free (src->uri_name);
416 src->uri_name = NULL;
418 src->handle = g_value_get_boxed (value);
421 case ARG_IRADIO_MODE:
422 src->iradio_mode = g_value_get_boolean (value);
425 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
431 gst_gnome_vfs_src_get_property (GObject * object, guint prop_id, GValue * value,
436 src = GST_GNOME_VFS_SRC (object);
440 g_value_set_string (value, src->uri_name);
443 g_value_set_boxed (value, src->handle);
445 case ARG_IRADIO_MODE:
446 g_value_set_boolean (value, src->iradio_mode);
448 case ARG_IRADIO_NAME:
449 g_value_set_string (value, src->iradio_name);
451 case ARG_IRADIO_GENRE:
452 g_value_set_string (value, src->iradio_genre);
455 g_value_set_string (value, src->iradio_url);
457 case ARG_IRADIO_TITLE:
458 g_value_set_string (value, src->iradio_title);
461 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
467 gst_gnome_vfs_src_unicodify (const char *str)
469 const gchar *env_vars[] = { "GST_ICY_TAG_ENCODING",
470 "GST_TAG_ENCODING", NULL
473 return gst_tag_freeform_string_to_utf8 (str, -1, env_vars);
477 gst_gnome_vfs_src_send_additional_headers_callback (gconstpointer in,
478 gsize in_size, gpointer out, gsize out_size, gpointer callback_data)
480 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (callback_data);
481 GnomeVFSModuleCallbackAdditionalHeadersOut *out_args =
482 (GnomeVFSModuleCallbackAdditionalHeadersOut *) out;
484 if (!src->iradio_mode)
486 GST_DEBUG_OBJECT (src, "sending headers\n");
488 out_args->headers = g_list_append (out_args->headers,
489 g_strdup ("icy-metadata:1\r\n"));
493 gst_gnome_vfs_src_received_headers_callback (gconstpointer in,
494 gsize in_size, gpointer out, gsize out_size, gpointer callback_data)
498 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (callback_data);
499 GnomeVFSModuleCallbackReceivedHeadersIn *in_args =
500 (GnomeVFSModuleCallbackReceivedHeadersIn *) in;
502 /* This is only used for internet radio stuff right now */
503 if (!src->iradio_mode)
506 GST_DEBUG_OBJECT (src, "receiving internet radio metadata\n");
508 /* FIXME: Could we use "Accept-Ranges: bytes"
509 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.5
510 * to enable pull-mode?
513 for (i = in_args->headers; i; i = i->next) {
514 char *data = (char *) i->data;
515 char *value = strchr (data, ':');
526 GST_LOG_OBJECT (src, "data %s", data);
529 if (strncmp (data, "icy-metaint:", 12) == 0) { /* ugh */
530 if (sscanf (data + 12, "%d", &icy_metaint) == 1) {
531 if (icy_metaint > 0) {
534 icy_caps = gst_caps_new_simple ("application/x-icy",
535 "metadata-interval", G_TYPE_INT, icy_metaint, NULL);
536 gst_pad_set_caps (GST_BASE_SRC_PAD (src), icy_caps);
537 gst_caps_unref (icy_caps);
543 if (!strncmp (data, "icy-", 4))
548 GST_DEBUG_OBJECT (src, "key: %s", key);
549 if (!strncmp (key, "name", 4)) {
550 g_free (src->iradio_name);
551 src->iradio_name = gst_gnome_vfs_src_unicodify (value);
552 if (src->iradio_name)
553 g_object_notify (G_OBJECT (src), "iradio-name");
554 } else if (!strncmp (key, "genre", 5)) {
555 g_free (src->iradio_genre);
556 src->iradio_genre = gst_gnome_vfs_src_unicodify (value);
557 if (src->iradio_genre)
558 g_object_notify (G_OBJECT (src), "iradio-genre");
559 } else if (!strncmp (key, "url", 3)) {
560 g_free (src->iradio_url);
561 src->iradio_url = gst_gnome_vfs_src_unicodify (value);
563 g_object_notify (G_OBJECT (src), "iradio-url");
569 gst_gnome_vfs_src_push_callbacks (GstGnomeVFSSrc * src)
571 if (src->http_callbacks_pushed)
574 GST_DEBUG_OBJECT (src, "pushing callbacks");
575 gnome_vfs_module_callback_push
576 (GNOME_VFS_MODULE_CALLBACK_HTTP_SEND_ADDITIONAL_HEADERS,
577 gst_gnome_vfs_src_send_additional_headers_callback, src, NULL);
578 gnome_vfs_module_callback_push
579 (GNOME_VFS_MODULE_CALLBACK_HTTP_RECEIVED_HEADERS,
580 gst_gnome_vfs_src_received_headers_callback, src, NULL);
582 src->http_callbacks_pushed = TRUE;
586 gst_gnome_vfs_src_pop_callbacks (GstGnomeVFSSrc * src)
588 if (!src->http_callbacks_pushed)
591 GST_DEBUG_OBJECT (src, "popping callbacks");
592 gnome_vfs_module_callback_pop
593 (GNOME_VFS_MODULE_CALLBACK_HTTP_SEND_ADDITIONAL_HEADERS);
594 gnome_vfs_module_callback_pop
595 (GNOME_VFS_MODULE_CALLBACK_HTTP_RECEIVED_HEADERS);
597 src->http_callbacks_pushed = FALSE;
601 * Read a new buffer from src->reqoffset, takes care of events
602 * and seeking and such.
605 gst_gnome_vfs_src_create (GstBaseSrc * basesrc, guint64 offset, guint size,
610 GnomeVFSFileSize readbytes;
614 gboolean interrupted = FALSE;
616 src = GST_GNOME_VFS_SRC (basesrc);
618 GST_DEBUG ("now at %" G_GINT64_FORMAT ", reading from %" G_GUINT64_FORMAT
619 ", size %u", src->curoffset, offset, size);
621 /* seek if required */
622 if (G_UNLIKELY (src->curoffset != offset)) {
623 GST_DEBUG ("need to seek");
625 GST_DEBUG ("seeking to %" G_GUINT64_FORMAT, offset);
626 res = gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_START, offset);
627 if (res != GNOME_VFS_OK)
629 src->curoffset = offset;
635 buf = gst_buffer_try_new_and_alloc (size);
636 if (G_UNLIKELY (buf == NULL)) {
637 GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", size);
638 return GST_FLOW_ERROR;
641 data = GST_BUFFER_DATA (buf);
644 while (!src->interrupted && todo > 0) {
645 /* this can return less that we ask for */
647 gnome_vfs_read_cancellable (src->handle, data, todo, &readbytes,
650 if (G_UNLIKELY (res == GNOME_VFS_ERROR_CANCELLED)) {
651 GST_DEBUG_OBJECT (src, "interrupted");
653 /* Just take what we've so far gotten and return */
655 GST_BUFFER_SIZE (buf) = size;
661 if (G_UNLIKELY (res == GNOME_VFS_ERROR_EOF || (res == GNOME_VFS_OK
665 if (G_UNLIKELY (res != GNOME_VFS_OK))
668 if (readbytes < todo) {
669 data = &data[readbytes];
674 GST_LOG (" got size %" G_GUINT64_FORMAT, readbytes);
680 GST_BUFFER_OFFSET (buf) = src->curoffset;
681 src->curoffset += size;
683 /* we're done, return the buffer */
690 GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL),
691 ("Failed to seek to requested position %" G_GINT64_FORMAT ": %s",
692 offset, gnome_vfs_result_to_string (res)));
693 return GST_FLOW_ERROR;
697 GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL),
698 ("Requested seek from %" G_GINT64_FORMAT " to %" G_GINT64_FORMAT
699 " on non-seekable stream", src->curoffset, offset));
700 return GST_FLOW_ERROR;
704 gst_buffer_unref (buf);
705 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
706 ("Failed to read data: %s", gnome_vfs_result_to_string (res)));
707 return GST_FLOW_ERROR;
711 gst_buffer_unref (buf);
712 return GST_FLOW_WRONG_STATE;
716 gst_buffer_unref (buf);
717 GST_DEBUG_OBJECT (src, "Reading data gave EOS");
718 return GST_FLOW_UNEXPECTED;
723 gst_gnome_vfs_src_query (GstBaseSrc * basesrc, GstQuery * query)
725 gboolean ret = FALSE;
726 GstGnomeVFSSrc *src = GST_GNOME_VFS_SRC (basesrc);
728 switch (GST_QUERY_TYPE (query)) {
730 gst_query_set_uri (query, src->uri_name);
739 ret = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
745 gst_gnome_vfs_src_is_seekable (GstBaseSrc * basesrc)
749 src = GST_GNOME_VFS_SRC (basesrc);
751 return src->seekable;
755 gst_gnome_vfs_src_check_get_range (GstBaseSrc * basesrc)
758 const gchar *protocol;
760 src = GST_GNOME_VFS_SRC (basesrc);
762 if (src->uri == NULL) {
763 GST_WARNING_OBJECT (src, "no URI set yet");
767 if (gnome_vfs_uri_is_local (src->uri)) {
768 GST_LOG_OBJECT (src, "local URI (%s), assuming random access is possible",
769 GST_STR_NULL (src->uri_name));
773 /* blacklist certain protocols we know won't work getrange-based */
774 protocol = gnome_vfs_uri_get_scheme (src->uri);
775 if (protocol == NULL)
778 if (strcmp (protocol, "http") == 0 || strcmp (protocol, "https") == 0) {
779 GST_LOG_OBJECT (src, "blacklisted protocol '%s', no random access possible"
780 " (URI=%s)", protocol, GST_STR_NULL (src->uri_name));
784 /* fall through to undecided */
788 /* don't know what to do, let the basesrc class decide for us */
789 GST_LOG_OBJECT (src, "undecided about URI '%s', let base class handle it",
790 GST_STR_NULL (src->uri_name));
792 if (GST_BASE_SRC_CLASS (parent_class)->check_get_range)
793 return GST_BASE_SRC_CLASS (parent_class)->check_get_range (basesrc);
799 /* Interrupt a blocking request. */
801 gst_gnome_vfs_src_unlock (GstBaseSrc * basesrc)
805 src = GST_GNOME_VFS_SRC (basesrc);
806 GST_DEBUG_OBJECT (src, "unlock()");
807 src->interrupted = TRUE;
809 GnomeVFSCancellation *cancel =
810 gnome_vfs_context_get_cancellation (src->context);
812 gnome_vfs_cancellation_cancel (cancel);
817 /* Interrupt interrupt. */
819 gst_gnome_vfs_src_unlock_stop (GstBaseSrc * basesrc)
823 src = GST_GNOME_VFS_SRC (basesrc);
824 GST_DEBUG_OBJECT (src, "unlock_stop()");
826 src->interrupted = FALSE;
831 gst_gnome_vfs_src_get_size (GstBaseSrc * basesrc, guint64 * size)
834 GnomeVFSFileInfo *info;
835 GnomeVFSFileInfoOptions options;
838 src = GST_GNOME_VFS_SRC (basesrc);
841 info = gnome_vfs_file_info_new ();
842 options = GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS;
843 res = gnome_vfs_get_file_info_from_handle (src->handle, info, options);
844 if (res == GNOME_VFS_OK) {
845 if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) {
847 GST_DEBUG_OBJECT (src, "from handle: %" G_GUINT64_FORMAT " bytes", *size);
848 } else if (src->own_handle && gnome_vfs_uri_is_local (src->uri)) {
849 GST_DEBUG_OBJECT (src,
850 "file size not known, file local, trying fallback");
851 res = gnome_vfs_get_file_info_uri (src->uri, info, options);
852 if (res == GNOME_VFS_OK &&
853 (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) {
855 GST_DEBUG_OBJECT (src, "from uri: %" G_GUINT64_FORMAT " bytes", *size);
859 GST_WARNING_OBJECT (src, "getting info failed: %s",
860 gnome_vfs_result_to_string (res));
862 gnome_vfs_file_info_unref (info);
864 if (*size == (GnomeVFSFileSize) - 1)
867 GST_DEBUG_OBJECT (src, "return size %" G_GUINT64_FORMAT, *size);
872 /* open the file, do stuff necessary to go to PAUSED state */
874 gst_gnome_vfs_src_start (GstBaseSrc * basesrc)
879 src = GST_GNOME_VFS_SRC (basesrc);
881 gst_gnome_vfs_src_push_callbacks (src);
883 src->context = gnome_vfs_context_new ();
884 if (src->uri != NULL) {
885 GnomeVFSOpenMode mode = GNOME_VFS_OPEN_READ;
887 /* this can block... */
888 res = gnome_vfs_open_uri (&src->handle, src->uri, mode);
889 if (res != GNOME_VFS_OK)
891 src->own_handle = TRUE;
892 } else if (!src->handle) {
895 src->own_handle = FALSE;
898 if (gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_CURRENT, 0) == GNOME_VFS_OK) {
899 src->seekable = TRUE;
901 src->seekable = FALSE;
909 gchar *filename = gnome_vfs_uri_to_string (src->uri,
910 GNOME_VFS_URI_HIDE_PASSWORD);
912 gst_gnome_vfs_src_pop_callbacks (src);
914 if (res == GNOME_VFS_ERROR_NOT_FOUND ||
915 res == GNOME_VFS_ERROR_HOST_NOT_FOUND ||
916 res == GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE) {
917 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
918 ("Could not open vfs file \"%s\" for reading: %s (%d)",
919 filename, gnome_vfs_result_to_string (res), res));
921 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
922 ("Could not open vfs file \"%s\" for reading: %s (%d)",
923 filename, gnome_vfs_result_to_string (res), res));
930 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("No filename given"));
936 gst_gnome_vfs_src_stop (GstBaseSrc * basesrc)
940 src = GST_GNOME_VFS_SRC (basesrc);
942 gst_gnome_vfs_src_pop_callbacks (src);
944 if (src->own_handle) {
947 res = gnome_vfs_close (src->handle);
948 if (res != GNOME_VFS_OK) {
949 GST_ELEMENT_ERROR (src, RESOURCE, CLOSE, (NULL),
950 ("Could not close vfs handle: %s", gnome_vfs_result_to_string (res)));
955 src->interrupted = FALSE;
956 gnome_vfs_context_free (src->context);