uri: add error argument to gst_element_make_from_uri()

So callers can differentiate between there not being a
handler for the protocol, and them not accepting the URI
for some reason.

https://bugzilla.gnome.org/show_bug.cgi?id=645467
This commit is contained in:
Tim-Philipp Müller 2012-06-23 14:40:17 +01:00
parent b5a064850e
commit f8445bd293
2 changed files with 36 additions and 11 deletions

View file

@ -42,6 +42,7 @@
#endif
#include "gst_private.h"
#include "gst.h"
#include "gsturi.h"
#include "gstinfo.h"
#include "gstregistry.h"
@ -562,6 +563,7 @@ gst_uri_protocol_is_supported (const GstURIType type, const gchar * protocol)
* @type: Whether to create a source or a sink
* @uri: URI to create an element for
* @elementname: (allow-none): Name of created element, can be NULL.
* @error: (allow-none): address where to store error information, or NULL.
*
* Creates an element for handling the given URI.
*
@ -569,38 +571,55 @@ gst_uri_protocol_is_supported (const GstURIType type, const gchar * protocol)
*/
GstElement *
gst_element_make_from_uri (const GstURIType type, const gchar * uri,
const gchar * elementname)
const gchar * elementname, GError ** error)
{
GList *possibilities, *walk;
gchar *protocol;
GstElement *ret = NULL;
g_return_val_if_fail (gst_is_initialized (), NULL);
g_return_val_if_fail (GST_URI_TYPE_IS_VALID (type), NULL);
g_return_val_if_fail (gst_uri_is_valid (uri), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
GST_DEBUG ("type:%d, uri:%s, elementname:%s", type, uri, elementname);
protocol = gst_uri_get_protocol (uri);
possibilities = get_element_factories_from_uri_protocol (type, protocol);
g_free (protocol);
if (!possibilities) {
GST_DEBUG ("No %s for URI '%s'", type == GST_URI_SINK ? "sink" : "source",
uri);
/* The error message isn't great, but we don't expect applications to
* show that error to users, but call the missing plugins functions */
g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_UNSUPPORTED_PROTOCOL,
_("No URI handler for the %s protocol found"), protocol);
g_free (protocol);
return NULL;
}
g_free (protocol);
possibilities = g_list_sort (possibilities, (GCompareFunc) sort_by_rank);
walk = possibilities;
while (walk) {
if ((ret =
gst_element_factory_create (GST_ELEMENT_FACTORY_CAST (walk->data),
elementname)) != NULL) {
GstElementFactory *factory = walk->data;
GError *uri_err = NULL;
ret = gst_element_factory_create (factory, elementname);
if (ret != NULL) {
GstURIHandler *handler = GST_URI_HANDLER (ret);
if (gst_uri_handler_set_uri (handler, uri, NULL))
if (gst_uri_handler_set_uri (handler, uri, &uri_err))
break;
GST_WARNING ("element %s didn't accept the URI", GST_ELEMENT_NAME (ret));
GST_WARNING ("%s didn't accept URI '%s': %s", GST_OBJECT_NAME (ret), uri,
uri_err->message);
if (error != NULL && *error == NULL)
g_propagate_error (error, uri_err);
else
g_error_free (uri_err);
gst_object_unref (ret);
ret = NULL;
}
@ -610,6 +629,11 @@ gst_element_make_from_uri (const GstURIType type, const gchar * uri,
GST_LOG_OBJECT (ret, "created %s for URL '%s'",
type == GST_URI_SINK ? "sink" : "source", uri);
/* if the first handler didn't work, but we found another one that works */
if (ret != NULL)
g_clear_error (error);
return ret;
}
@ -741,7 +765,7 @@ gst_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri,
}
if (!found_protocol) {
g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_PROTOCOL,
g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_UNSUPPORTED_PROTOCOL,
_("URI scheme '%s' not supported"), protocol);
g_free (protocol);
return FALSE;

View file

@ -40,7 +40,7 @@ GQuark gst_uri_error_quark (void);
/**
* GstURIError:
* @GST_URI_ERROR_BAD_PROTOCOL: The protocol is not supported
* @GST_URI_ERROR_UNSUPPORTED_PROTOCOL: The protocol is not supported
* @GST_URI_ERROR_BAD_URI: There was a problem with the URI
* @GST_URI_ERROR_BAD_STATE: Could not set or change the URI because the
* URI handler was in a state where that is not possible or not permitted
@ -51,7 +51,7 @@ GQuark gst_uri_error_quark (void);
*/
typedef enum
{
GST_URI_ERROR_BAD_PROTOCOL,
GST_URI_ERROR_UNSUPPORTED_PROTOCOL,
GST_URI_ERROR_BAD_URI,
GST_URI_ERROR_BAD_STATE,
GST_URI_ERROR_BAD_REFERENCE
@ -138,7 +138,8 @@ gchar * gst_filename_to_uri (const gchar * filename,
GstElement * gst_element_make_from_uri (const GstURIType type,
const gchar * uri,
const gchar * elementname) G_GNUC_MALLOC;
const gchar * elementname,
GError ** error) G_GNUC_MALLOC;
/* accessing the interface */
GType gst_uri_handler_get_type (void);