}
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;
{
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:
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)
}
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 */
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:
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
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);
}
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;
{
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;
}
}
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);
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/")) {
/* 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;
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
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