elements: update fd + file sources and sinks for GstUriHandler changes

This commit is contained in:
Tim-Philipp Müller 2011-11-13 17:44:57 +00:00
parent 682704750c
commit dfa9bb8088
4 changed files with 57 additions and 50 deletions

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -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