From a8a8d689c9d1b019e58b080d555c00e93636fec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 15 Feb 2008 11:58:06 +0000 Subject: [PATCH] ext/gio/: Improve debugging a bit. Original commit message from CVS: * ext/gio/gstgiobasesink.c: (close_stream_cb): * ext/gio/gstgiobasesrc.c: (close_stream_cb): Improve debugging a bit. * ext/gio/gstgiosink.c: (mount_cb), (gst_gio_sink_start): * ext/gio/gstgiosink.h: * ext/gio/gstgiosrc.c: (mount_cb), (gst_gio_src_start): * ext/gio/gstgiosrc.h: Try to mount the enclosing volume of a GFile if it isn't mounted yet. This requires us to wait for an async operation to finish, done with an nested GMainLoop. Authentication is not supported yet, will come later. --- ChangeLog | 15 +++++++++ ext/gio/gstgiobasesink.c | 9 ++++-- ext/gio/gstgiobasesrc.c | 9 ++++-- ext/gio/gstgiosink.c | 62 ++++++++++++++++++++++++++++++++++++ ext/gio/gstgiosink.h | 3 ++ ext/gio/gstgiosrc.c | 69 +++++++++++++++++++++++++++++++++++++--- ext/gio/gstgiosrc.h | 3 ++ 7 files changed, 160 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 399c4f4dc5..df2eb2b5fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-02-15 Sebastian Dröge + + * ext/gio/gstgiobasesink.c: (close_stream_cb): + * ext/gio/gstgiobasesrc.c: (close_stream_cb): + Improve debugging a bit. + + * ext/gio/gstgiosink.c: (mount_cb), (gst_gio_sink_start): + * ext/gio/gstgiosink.h: + * ext/gio/gstgiosrc.c: (mount_cb), (gst_gio_src_start): + * ext/gio/gstgiosrc.h: + Try to mount the enclosing volume of a GFile if it isn't mounted + yet. This requires us to wait for an async operation to finish, done + with an nested GMainLoop. Authentication is not supported yet, will + come later. + 2008-02-14 Wim Taymans * gst/playback/gstplaybin2.c: (gst_play_bin_class_init), diff --git a/ext/gio/gstgiobasesink.c b/ext/gio/gstgiobasesink.c index f692fa139c..9657ac3900 100644 --- a/ext/gio/gstgiobasesink.c +++ b/ext/gio/gstgiobasesink.c @@ -139,13 +139,16 @@ close_stream_cb (GObject * object, GAsyncResult * res, gpointer user_data) if (!success && !gst_gio_error (sink, "g_output_stream_close_async", &err, NULL)) { - GST_ELEMENT_ERROR (sink, RESOURCE, CLOSE, (NULL), + GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL), ("g_output_stream_close_async failed: %s", err->message)); g_clear_error (&err); + } else if (!success) { + GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL), + ("g_output_stream_close_async failed")); + } else { + GST_DEBUG_OBJECT (sink, "g_output_stream_close_async succeeded"); } - GST_DEBUG_OBJECT (sink, "closed stream"); - g_object_unref (sink); } diff --git a/ext/gio/gstgiobasesrc.c b/ext/gio/gstgiobasesrc.c index ec9f2fbc50..77ace23244 100644 --- a/ext/gio/gstgiobasesrc.c +++ b/ext/gio/gstgiobasesrc.c @@ -139,13 +139,16 @@ close_stream_cb (GObject * object, GAsyncResult * res, gpointer user_data) if (!success && !gst_gio_error (src, "g_input_stream_close_async", &err, NULL)) { - GST_ELEMENT_ERROR (src, RESOURCE, CLOSE, (NULL), + GST_ELEMENT_WARNING (src, RESOURCE, CLOSE, (NULL), ("g_input_stream_close_async failed: %s", err->message)); g_clear_error (&err); + } else if (!success) { + GST_ELEMENT_WARNING (src, RESOURCE, CLOSE, (NULL), + ("g_input_stream_close_async failed")); + } else { + GST_DEBUG_OBJECT (src, "g_input_stream_close_async succeeded"); } - GST_DEBUG_OBJECT (src, "closed stream"); - g_object_unref (src); } diff --git a/ext/gio/gstgiosink.c b/ext/gio/gstgiosink.c index 894c795d09..96f653a0f1 100644 --- a/ext/gio/gstgiosink.c +++ b/ext/gio/gstgiosink.c @@ -183,6 +183,34 @@ gst_gio_sink_get_property (GObject * object, guint prop_id, } } +static void +mount_cb (GObject * source, GAsyncResult * res, gpointer user_data) +{ + gboolean success; + GError *err = NULL; + GstGioSink *sink = GST_GIO_SINK (user_data); + + success = g_file_mount_enclosing_volume_finish (G_FILE (source), res, &err); + + if (!success + && !gst_gio_error (sink, "g_file_mount_enclosing_volume", &err, NULL)) { + GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL), + ("g_file_mount_enclosing_volume failed: %s", err->message)); + g_clear_error (&err); + } else if (!success) { + GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL), + ("g_file_mount_enclosing_volume failed")); + } else { + GST_DEBUG ("g_file_mount_enclosing_volume failed succeeded"); + } + + sink->mount_successful = success; + + g_main_loop_quit (sink->loop); + + g_object_unref (sink); +} + static gboolean gst_gio_sink_start (GstBaseSink * base_sink) { @@ -209,6 +237,40 @@ gst_gio_sink_start (GstBaseSink * base_sink) stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, cancel, &err)); + + if (stream == NULL && !gst_gio_error (sink, "g_file_read", &err, NULL) && + GST_GIO_ERROR_MATCHES (err, NOT_MOUNTED)) { + + GST_DEBUG ("Trying to mount enclosing volume for %s\n", sink->location); + g_clear_error (&err); + err = NULL; + + sink->loop = g_main_loop_new (NULL, TRUE); + if (!sink->loop) { + GST_ELEMENT_ERROR (sink, LIBRARY, INIT, + (NULL), ("Failed to start GMainLoop")); + } else { + sink->mount_successful = FALSE; + /* TODO: authentication: a GMountOperation property that apps can set + * and properties for user/password/etc that can be used more easily + */ + g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, NULL, cancel, + mount_cb, g_object_ref (sink)); + g_main_loop_run (sink->loop); + + g_main_loop_unref (sink->loop); + sink->loop = NULL; + + if (!sink->mount_successful) { + GST_DEBUG ("Mounting the enclosing volume failed for some reason"); + } else { + stream = + G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, cancel, + &err)); + } + } + } + success = (stream != NULL); g_object_unref (file); diff --git a/ext/gio/gstgiosink.h b/ext/gio/gstgiosink.h index cae0d5ff5e..fc2478a200 100644 --- a/ext/gio/gstgiosink.h +++ b/ext/gio/gstgiosink.h @@ -54,6 +54,9 @@ struct _GstGioSink /*< private >*/ gchar *location; + + GMainLoop *loop; + gboolean mount_successful; }; struct _GstGioSinkClass diff --git a/ext/gio/gstgiosrc.c b/ext/gio/gstgiosrc.c index cfa4da99eb..f00bd36d55 100644 --- a/ext/gio/gstgiosrc.c +++ b/ext/gio/gstgiosrc.c @@ -178,6 +178,34 @@ gst_gio_src_get_property (GObject * object, guint prop_id, } } +static void +mount_cb (GObject * source, GAsyncResult * res, gpointer user_data) +{ + gboolean success; + GError *err = NULL; + GstGioSrc *src = GST_GIO_SRC (user_data); + + success = g_file_mount_enclosing_volume_finish (G_FILE (source), res, &err); + + if (!success + && !gst_gio_error (src, "g_file_mount_enclosing_volume", &err, NULL)) { + GST_ELEMENT_ERROR (src, RESOURCE, CLOSE, (NULL), + ("g_file_mount_enclosing_volume failed: %s", err->message)); + g_clear_error (&err); + } else if (!success) { + GST_ELEMENT_WARNING (src, RESOURCE, CLOSE, (NULL), + ("g_file_mount_enclosing_volume failed")); + } else { + GST_DEBUG ("g_file_mount_enclosing_volume failed succeeded"); + } + + src->mount_successful = success; + + g_main_loop_quit (src->loop); + + g_object_unref (src); +} + static gboolean gst_gio_src_start (GstBaseSrc * base_src) { @@ -202,23 +230,56 @@ gst_gio_src_start (GstBaseSrc * base_src) stream = G_INPUT_STREAM (g_file_read (file, cancel, &err)); + if (stream == NULL && !gst_gio_error (src, "g_file_read", &err, NULL) && + GST_GIO_ERROR_MATCHES (err, NOT_MOUNTED)) { + + + GST_DEBUG ("Trying to mount enclosing volume for %s\n", src->location); + g_clear_error (&err); + err = NULL; + + src->loop = g_main_loop_new (NULL, TRUE); + if (!src->loop) { + GST_ELEMENT_ERROR (src, LIBRARY, INIT, + (NULL), ("Failed to start GMainLoop")); + } else { + src->mount_successful = FALSE; + /* TODO: authentication: a GMountOperation property that apps can set + * and properties for user/password/etc that can be used more easily + */ + g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, NULL, cancel, + mount_cb, g_object_ref (src)); + g_main_loop_run (src->loop); + + g_main_loop_unref (src->loop); + src->loop = NULL; + + if (!src->mount_successful) { + GST_ERROR ("Mounting the enclosing volume failed for some reason"); + } else { + stream = G_INPUT_STREAM (g_file_read (file, cancel, &err)); + } + } + } + + src->mount_successful = FALSE; + g_object_unref (file); if (stream == NULL && !gst_gio_error (src, "g_file_read", &err, NULL)) { - if (GST_GIO_ERROR_MATCHES (err, NOT_FOUND)) + if (GST_GIO_ERROR_MATCHES (err, NOT_FOUND)) { GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), ("Could not open location %s for reading: %s", src->location, err->message)); - else + } else { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("Could not open location %s for reading: %s", src->location, err->message)); + } g_clear_error (&err); - return FALSE; - } else if (stream == NULL) { return FALSE; } diff --git a/ext/gio/gstgiosrc.h b/ext/gio/gstgiosrc.h index 79918ae833..92d2b25cb4 100644 --- a/ext/gio/gstgiosrc.h +++ b/ext/gio/gstgiosrc.h @@ -54,6 +54,9 @@ struct _GstGioSrc /*< private >*/ gchar *location; + + GMainLoop *loop; + gboolean mount_successful; }; struct _GstGioSrcClass