3 * Copyright (C) 2007 Rene Stadler <mail@renestadler.de>
4 * Copyright (C) 2007 Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
27 #include "gstgiosink.h"
28 #include "gstgiosrc.h"
29 #include "gstgiostreamsink.h"
30 #include "gstgiostreamsrc.h"
34 GST_DEBUG_CATEGORY_STATIC (gst_gio_debug);
35 #define GST_CAT_DEFAULT gst_gio_debug
37 /* @func_name: Name of the GIO function, for debugging messages.
38 * @err: Error location. *err may be NULL, but err must be non-NULL.
39 * @ret: Flow return location. May be NULL. Is set to either #GST_FLOW_ERROR
40 * or #GST_FLOW_WRONG_STATE.
42 * Returns: TRUE to indicate a handled error. Error at given location err will
43 * be freed and *err will be set to NULL. A FALSE return indicates an unhandled
44 * error: The err location is unchanged and guaranteed to be != NULL. ret, if
45 * given, is set to GST_FLOW_ERROR.
48 gst_gio_error (gpointer element, const gchar * func_name, GError ** err,
51 gboolean handled = TRUE;
54 *ret = GST_FLOW_ERROR;
56 if (GST_GIO_ERROR_MATCHES (*err, CANCELLED)) {
57 GST_DEBUG_OBJECT (element, "blocking I/O call cancelled (%s)", func_name);
59 *ret = GST_FLOW_WRONG_STATE;
60 } else if (*err != NULL) {
63 GST_ELEMENT_ERROR (element, LIBRARY, FAILED, (NULL),
64 ("%s call failed without error set", func_name));
74 gst_gio_seek (gpointer element, GSeekable * stream, guint64 offset,
75 GCancellable * cancel)
81 GST_LOG_OBJECT (element, "seeking to offset %" G_GINT64_FORMAT, offset);
83 success = g_seekable_seek (stream, offset, G_SEEK_SET, cancel, &err);
87 else if (!gst_gio_error (element, "g_seekable_seek", &err, &ret)) {
88 GST_ELEMENT_ERROR (element, RESOURCE, SEEK, (NULL),
89 ("Could not seek: %s", err->message));
97 _internal_get_supported_protocols (gpointer data)
99 const gchar *const *schemes;
104 schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
105 num = g_strv_length ((gchar **) schemes);
108 GST_WARNING ("No GIO supported URI schemes found");
112 our_schemes = g_new0 (gchar *, num + 1);
114 /* - Filter http/https as we can't support the icy stuff with GIO.
115 * Use souphttpsrc if you need that.
116 * - Filter cdda as it doesn't support musicbrainz stuff and everything
117 * else one expects from a cdda source. Use cdparanoiasrc or cdiosrc
120 for (i = 0, j = 0; i < num; i++) {
121 if (strcmp (schemes[i], "http") == 0 || strcmp (schemes[i], "https") == 0
122 || strcmp (schemes[i], "cdda") == 0)
125 our_schemes[j] = g_strdup (schemes[i]);
133 gst_gio_get_supported_protocols (void)
135 static GOnce once = G_ONCE_INIT;
137 g_once (&once, _internal_get_supported_protocols, NULL);
138 return (gchar **) once.retval;
142 gst_gio_uri_handler_get_type_sink (void)
148 gst_gio_uri_handler_get_type_src (void)
154 gst_gio_uri_handler_get_protocols (void)
156 static gchar **protocols = NULL;
159 protocols = gst_gio_get_supported_protocols ();
165 gst_gio_uri_handler_get_uri (GstURIHandler * handler)
167 GstElement *element = GST_ELEMENT (handler);
170 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
172 g_object_get (G_OBJECT (element), "location", &uri, NULL);
178 gst_gio_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri)
180 GstElement *element = GST_ELEMENT (handler);
182 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
184 if (GST_STATE (element) == GST_STATE_PLAYING ||
185 GST_STATE (element) == GST_STATE_PAUSED)
188 g_object_set (G_OBJECT (element), "location", uri, NULL);
194 gst_gio_uri_handler_init (gpointer g_iface, gpointer iface_data)
196 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
197 gboolean sink = GPOINTER_TO_INT (iface_data); /* See in do_init below. */
200 iface->get_type = gst_gio_uri_handler_get_type_sink;
202 iface->get_type = gst_gio_uri_handler_get_type_src;
203 iface->get_protocols = gst_gio_uri_handler_get_protocols;
204 iface->get_uri = gst_gio_uri_handler_get_uri;
205 iface->set_uri = gst_gio_uri_handler_set_uri;
209 gst_gio_uri_handler_do_init (GType type)
211 GInterfaceInfo uri_handler_info = {
212 gst_gio_uri_handler_init,
217 /* Store information for uri_handler_init to use for distinguishing the
218 * element types. This lets us use a single interface implementation for both
220 uri_handler_info.interface_data = GINT_TO_POINTER (g_type_is_a (type,
221 GST_TYPE_BASE_SINK));
223 g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &uri_handler_info);
227 plugin_init (GstPlugin * plugin)
231 GST_DEBUG_CATEGORY_INIT (gst_gio_debug, "gio", 0, "GIO elements");
233 gst_plugin_add_dependency_simple (plugin, NULL, GIO_MODULE_DIR, NULL,
234 GST_PLUGIN_DEPENDENCY_FLAG_NONE);
235 gst_plugin_add_dependency_simple (plugin, "LD_LIBRARY_PATH", GIO_LIBDIR,
236 "gvfsd", GST_PLUGIN_DEPENDENCY_FLAG_NONE);
238 /* FIXME: Rank is MARGINAL for now, should be at least SECONDARY+1 in the future
239 * to replace gnomevfssink/src. For testing purposes PRIMARY+1 one makes sense
240 * so it gets autoplugged and preferred over filesrc/sink. */
242 ret &= gst_element_register (plugin, "giosink", GST_RANK_SECONDARY,
245 ret &= gst_element_register (plugin, "giosrc", GST_RANK_SECONDARY,
248 ret &= gst_element_register (plugin, "giostreamsink", GST_RANK_NONE,
249 GST_TYPE_GIO_STREAM_SINK);
251 ret &= gst_element_register (plugin, "giostreamsrc", GST_RANK_NONE,
252 GST_TYPE_GIO_STREAM_SRC);
257 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "gio",
258 "GIO elements", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,