gio, appsrc, appsink, cdaudiosrc: update for GstURIHandler API changes

This commit is contained in:
Tim-Philipp Müller 2011-11-13 18:22:06 +00:00
parent dbb48b1de0
commit 455f337e3d
7 changed files with 40 additions and 47 deletions

View file

@ -161,11 +161,11 @@ gst_gio_uri_handler_get_protocols (GType type)
return protocols;
}
static const gchar *
static gchar *
gst_gio_uri_handler_get_uri (GstURIHandler * handler)
{
GstElement *element = GST_ELEMENT (handler);
const gchar *uri;
gchar *uri;
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
@ -175,18 +175,22 @@ gst_gio_uri_handler_get_uri (GstURIHandler * handler)
}
static gboolean
gst_gio_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri)
gst_gio_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri,
GError ** error)
{
GstElement *element = GST_ELEMENT (handler);
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
if (GST_STATE (element) == GST_STATE_PLAYING ||
GST_STATE (element) == GST_STATE_PAUSED)
GST_STATE (element) == GST_STATE_PAUSED) {
g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_STATE,
"Changing the 'location' property while the element is running is "
"not supported");
return FALSE;
}
g_object_set (G_OBJECT (element), "location", uri, NULL);
return TRUE;
}

View file

@ -331,10 +331,11 @@ gst_gio_base_sink_query (GstBaseSink * bsink, GstQuery * query)
return TRUE;
case GST_QUERY_URI:
if (GST_IS_URI_HANDLER (sink)) {
const gchar *uri;
gchar *uri;
uri = gst_uri_handler_get_uri (GST_URI_HANDLER (sink));
gst_query_set_uri (query, uri);
g_free (uri);
return TRUE;
}
return FALSE;

View file

@ -416,8 +416,9 @@ gst_gio_base_src_query (GstBaseSrc * base_src, GstQuery * query)
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_URI:
if (GST_IS_URI_HANDLER (src)) {
const gchar *uri = gst_uri_handler_get_uri (GST_URI_HANDLER (src));
gchar *uri = gst_uri_handler_get_uri (GST_URI_HANDLER (src));
gst_query_set_uri (query, uri);
g_free (uri);
ret = TRUE;
}
break;

View file

@ -1372,23 +1372,18 @@ gst_app_sink_uri_get_protocols (GType type)
return protocols;
}
static const gchar *
static gchar *
gst_app_sink_uri_get_uri (GstURIHandler * handler)
{
return "appsink";
return g_strdup ("appsink");
}
static gboolean
gst_app_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri)
gst_app_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri,
GError ** error)
{
gchar *protocol;
gboolean ret;
protocol = gst_uri_get_protocol (uri);
ret = !strcmp (protocol, "appsink");
g_free (protocol);
return ret;
/* GstURIHandler checks the protocol for us */
return TRUE;
}
static void

View file

@ -1619,23 +1619,18 @@ gst_app_src_uri_get_protocols (GType type)
return protocols;
}
static const gchar *
static gchar *
gst_app_src_uri_get_uri (GstURIHandler * handler)
{
return "appsrc";
return g_strdup ("appsrc");
}
static gboolean
gst_app_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
gst_app_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
GError ** error)
{
gchar *protocol;
gboolean ret;
protocol = gst_uri_get_protocol (uri);
ret = !strcmp (protocol, "appsrc");
g_free (protocol);
return ret;
/* GstURIHandler checks the protocol for us */
return TRUE;
}
static void

View file

@ -905,13 +905,15 @@ gst_audio_cd_src_uri_get_protocols (GType type)
return protocols;
}
static const gchar *
static gchar *
gst_audio_cd_src_uri_get_uri (GstURIHandler * handler)
{
GstAudioCdSrc *src = GST_AUDIO_CD_SRC (handler);
GST_OBJECT_LOCK (src);
/* FIXME: can we get rid of all that here and just return a copy of the
* existing URI perhaps? */
g_free (src->uri);
if (GST_OBJECT_FLAG_IS_SET (GST_BASE_SRC (src), GST_BASE_SRC_STARTED)) {
@ -924,7 +926,7 @@ gst_audio_cd_src_uri_get_uri (GstURIHandler * handler)
GST_OBJECT_UNLOCK (src);
return src->uri;
return g_strdup (src->uri);
}
/* Note: gst_element_make_from_uri() might call us with just 'cdda://' as
@ -933,22 +935,15 @@ gst_audio_cd_src_uri_get_uri (GstURIHandler * handler)
/* We accept URIs of the format cdda://(device#track)|(track) */
static gboolean
gst_audio_cd_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
gst_audio_cd_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
GError ** error)
{
GstAudioCdSrc *src = GST_AUDIO_CD_SRC (handler);
gchar *protocol;
const gchar *location;
gchar *track_number;
GST_OBJECT_LOCK (src);
protocol = gst_uri_get_protocol (uri);
if (!protocol || g_ascii_strcasecmp (protocol, "cdda") != 0) {
g_free (protocol);
goto failed;
}
g_free (protocol);
location = uri + 7;
track_number = g_strrstr (location, "#");
src->uri_track = 0;
@ -998,6 +993,8 @@ failed:
{
GST_OBJECT_UNLOCK (src);
GST_DEBUG_OBJECT (src, "cannot handle URI '%s'", uri);
g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
"Could not handle CDDA URI");
return FALSE;
}
}

View file

@ -289,7 +289,7 @@ test_uri_parse (const gchar * uri, const gchar * device, gint track)
gint set_track = 0;
foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc");
fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), uri) == TRUE,
fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), uri, NULL),
"couldn't set uri %s", uri);
g_object_get (foosrc, "device", &set_device, "track", &set_track, NULL);
fail_unless (set_device != NULL);
@ -429,26 +429,26 @@ GST_START_TEST (test_uri_parsing)
/* wrong protocol */
foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc");
fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc),
"x://") == FALSE);
"x://", NULL) == FALSE);
fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc),
"cddaq://") == FALSE);
"cddaq://", NULL) == FALSE);
/* cdda://track */
test_uri_parse ("cdda://", "/dev/cdrom", 1);
test_uri_parse ("cdda://2", "/dev/cdrom", 2);
test_uri_parse ("cdda://47", "/dev/cdrom", 47);
fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc),
"cdda://-1") == FALSE);
"cdda://-1", NULL) == FALSE);
fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc),
"cdda://what") == FALSE);
"cdda://what", NULL) == FALSE);
/* cdda://device#track */
test_uri_parse ("cdda:///dev/hdb#1", "/dev/hdb", 1);
test_uri_parse ("cdda://anything#8", "anything", 8);
fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc),
"cdda:///dev/hdb#nonsense") == FALSE);
"cdda:///dev/hdb#nonsense", NULL) == FALSE);
fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc),
"cdda:///dev/hdb#-2") == FALSE);
"cdda:///dev/hdb#-2", NULL) == FALSE);
/* cdda://track#device (device should be ignored - FIXME 0.11) */
test_uri_parse ("cdda://8#/dev/hdb", "/dev/cdrom", 8);