From: Tim-Philipp Müller Date: Sun, 13 Nov 2011 17:44:57 +0000 (+0000) Subject: elements: update fd + file sources and sinks for GstUriHandler changes X-Git-Tag: RELEASE-0.11.2~452 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dfa9bb808840468e49f51ccd9ba0d12d73e21f76;p=platform%2Fupstream%2Fgstreamer.git elements: update fd + file sources and sinks for GstUriHandler changes --- diff --git a/plugins/elements/gstfdsink.c b/plugins/elements/gstfdsink.c index 01edb3f..4441d96 100644 --- a/plugins/elements/gstfdsink.c +++ b/plugins/elements/gstfdsink.c @@ -315,7 +315,7 @@ write_error: } static gboolean -gst_fd_sink_check_fd (GstFdSink * fdsink, int fd) +gst_fd_sink_check_fd (GstFdSink * fdsink, int fd, GError ** error) { struct stat stat_results; off_t result; @@ -347,6 +347,8 @@ invalid: { GST_ELEMENT_ERROR (fdsink, RESOURCE, WRITE, (NULL), ("File descriptor %d is not valid: %s", fd, g_strerror (errno))); + g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_REFERENCE, + "File descriptor %d is not valid: %s", fd, g_strerror (errno)); return FALSE; } not_seekable: @@ -363,7 +365,7 @@ gst_fd_sink_start (GstBaseSink * basesink) GstPollFD fd = GST_POLL_FD_INIT; fdsink = GST_FD_SINK (basesink); - if (!gst_fd_sink_check_fd (fdsink, fdsink->fd)) + if (!gst_fd_sink_check_fd (fdsink, fdsink->fd, NULL)) return FALSE; if ((fdsink->fdset = gst_poll_new (TRUE)) == NULL) @@ -427,12 +429,15 @@ gst_fd_sink_unlock_stop (GstBaseSink * basesink) } static gboolean -gst_fd_sink_update_fd (GstFdSink * fdsink, int new_fd) +gst_fd_sink_update_fd (GstFdSink * fdsink, int new_fd, GError ** error) { - if (new_fd < 0) + if (new_fd < 0) { + g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_REFERENCE, + "File descriptor %d is not valid", new_fd); return FALSE; + } - if (!gst_fd_sink_check_fd (fdsink, new_fd)) + if (!gst_fd_sink_check_fd (fdsink, new_fd, error)) goto invalid; /* assign the fd */ @@ -474,7 +479,7 @@ gst_fd_sink_set_property (GObject * object, guint prop_id, int fd; fd = g_value_get_int (value); - gst_fd_sink_update_fd (fdsink, fd); + gst_fd_sink_update_fd (fdsink, fd, NULL); break; } default: @@ -594,32 +599,29 @@ gst_fd_sink_uri_get_protocols (GType type) return protocols; } -static const gchar * +static gchar * gst_fd_sink_uri_get_uri (GstURIHandler * handler) { GstFdSink *sink = GST_FD_SINK (handler); - return sink->uri; + /* FIXME: make thread-safe */ + return g_strdup (sink->uri); } static gboolean -gst_fd_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri) +gst_fd_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri, + GError ** error) { - gchar *protocol; GstFdSink *sink = GST_FD_SINK (handler); gint fd; - protocol = gst_uri_get_protocol (uri); - if (strcmp (protocol, "fd") != 0) { - g_free (protocol); + if (sscanf (uri, "fd://%d", &fd) != 1) { + g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI, + "File descriptor URI could not be parsed"); return FALSE; } - g_free (protocol); - - if (sscanf (uri, "fd://%d", &fd) != 1) - return FALSE; - return gst_fd_sink_update_fd (sink, fd); + return gst_fd_sink_update_fd (sink, fd, error); } static void diff --git a/plugins/elements/gstfdsrc.c b/plugins/elements/gstfdsrc.c index 5fd1b72..a54582a 100644 --- a/plugins/elements/gstfdsrc.c +++ b/plugins/elements/gstfdsrc.c @@ -613,16 +613,18 @@ gst_fd_src_uri_get_protocols (GType type) return protocols; } -static const gchar * +static gchar * gst_fd_src_uri_get_uri (GstURIHandler * handler) { GstFdSrc *src = GST_FD_SRC (handler); - return src->uri; + /* FIXME: make thread-safe */ + return g_strdup (src->uri); } static gboolean -gst_fd_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) +gst_fd_src_uri_set_uri (GstURIHandler * handler, const gchar * uri, + GError ** err) { gchar *protocol, *q; GstFdSrc *src = GST_FD_SRC (handler); diff --git a/plugins/elements/gstfilesink.c b/plugins/elements/gstfilesink.c index 02fee92..76a807d 100644 --- a/plugins/elements/gstfilesink.c +++ b/plugins/elements/gstfilesink.c @@ -269,7 +269,8 @@ gst_file_sink_dispose (GObject * object) } static gboolean -gst_file_sink_set_location (GstFileSink * sink, const gchar * location) +gst_file_sink_set_location (GstFileSink * sink, const gchar * location, + GError ** error) { if (sink->file) goto was_open; @@ -295,6 +296,9 @@ was_open: { g_warning ("Changing the `location' property on filesink when a file is " "open is not supported."); + g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_STATE, + "Changing the 'location' property on filesink when a file is " + "open is not supported"); return FALSE; } } @@ -307,7 +311,7 @@ gst_file_sink_set_property (GObject * object, guint prop_id, switch (prop_id) { case PROP_LOCATION: - gst_file_sink_set_location (sink, g_value_get_string (value)); + gst_file_sink_set_location (sink, g_value_get_string (value), NULL); break; case PROP_BUFFER_MODE: sink->buffer_mode = g_value_get_enum (value); @@ -693,28 +697,23 @@ gst_file_sink_uri_get_protocols (GType type) return protocols; } -static const gchar * +static gchar * gst_file_sink_uri_get_uri (GstURIHandler * handler) { GstFileSink *sink = GST_FILE_SINK (handler); - return sink->uri; + /* FIXME: make thread-safe */ + return g_strdup (sink->uri); } static gboolean -gst_file_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri) +gst_file_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri, + GError ** error) { - gchar *protocol, *location; + gchar *location; gboolean ret; GstFileSink *sink = GST_FILE_SINK (handler); - protocol = gst_uri_get_protocol (uri); - if (strcmp (protocol, "file") != 0) { - g_free (protocol); - return FALSE; - } - g_free (protocol); - /* allow file://localhost/foo/bar by stripping localhost but fail * for every other hostname */ if (g_str_has_prefix (uri, "file://localhost/")) { @@ -730,20 +729,26 @@ gst_file_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri) /* Special case for "file://" as this is used by some applications * to test with gst_element_make_from_uri if there's an element * that supports the URI protocol. */ - gst_file_sink_set_location (sink, NULL); + gst_file_sink_set_location (sink, NULL, NULL); return TRUE; } else { location = gst_uri_get_location (uri); } - if (!location) + if (!location) { + g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI, + "File URI without location"); return FALSE; + } + if (!g_path_is_absolute (location)) { + g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI, + "File URI location must be an absolute path"); g_free (location); return FALSE; } - ret = gst_file_sink_set_location (sink, location); + ret = gst_file_sink_set_location (sink, location, error); g_free (location); return ret; diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index 6d5fa46..02bd3f4 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -590,21 +590,22 @@ gst_file_src_uri_get_protocols (GType type) return protocols; } -static const gchar * +static gchar * gst_file_src_uri_get_uri (GstURIHandler * handler) { GstFileSrc *src = GST_FILE_SRC (handler); - return src->uri; + /* FIXME: make thread-safe */ + return g_strdup (src->uri); } static gboolean -gst_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) +gst_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri, + GError ** err) { gchar *location, *hostname = NULL; gboolean ret = FALSE; GstFileSrc *src = GST_FILE_SRC (handler); - GError *error = NULL; if (strcmp (uri, "file://") == 0) { /* Special case for "file://" as this is used by some applications @@ -614,22 +615,19 @@ gst_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) return TRUE; } - location = g_filename_from_uri (uri, &hostname, &error); + location = g_filename_from_uri (uri, &hostname, err); - if (!location || error) { - if (error) { - GST_WARNING_OBJECT (src, "Invalid URI '%s' for filesrc: %s", uri, - error->message); - g_error_free (error); - } else { - GST_WARNING_OBJECT (src, "Invalid URI '%s' for filesrc", uri); - } + if (!location || (err != NULL && *err != NULL)) { + GST_WARNING_OBJECT (src, "Invalid URI '%s' for filesrc: %s", uri, + (err != NULL && *err != NULL) ? (*err)->message : "unknown error"); goto beach; } if ((hostname) && (strcmp (hostname, "localhost"))) { /* Only 'localhost' is permitted */ GST_WARNING_OBJECT (src, "Invalid hostname '%s' for filesrc", hostname); + g_set_error (err, GST_URI_ERROR, GST_URI_ERROR_BAD_URI, + "File URI with invalid hostname '%s'", hostname); goto beach; } #ifdef G_OS_WIN32