gio: Add example application that shows how to handle the "not-mounted" message
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 10 Jul 2009 09:42:51 +0000 (11:42 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 10 Jul 2009 09:42:51 +0000 (11:42 +0200)
configure.ac
tests/examples/Makefile.am
tests/examples/gio/Makefile.am [new file with mode: 0644]
tests/examples/gio/giosrc-mounting.c [new file with mode: 0644]

index 6eb41ba..da8f539 100644 (file)
@@ -797,6 +797,7 @@ tests/examples/dynamic/Makefile
 tests/examples/seek/Makefile
 tests/examples/volume/Makefile
 tests/examples/snapshot/Makefile
+tests/examples/gio/Makefile
 tests/icles/Makefile
 docs/Makefile
 docs/design/Makefile
index e57d47a..e9cb975 100644 (file)
@@ -4,6 +4,10 @@ else
 FT2_SUBDIRS =
 endif
 
-SUBDIRS = app $(FT2_SUBDIRS) volume dynamic
+if USE_GIO
+GIO_SUBDIRS = gio
+endif
+
+SUBDIRS = app $(FT2_SUBDIRS) $(GIO_SUBDIRS) volume dynamic
 
-DIST_SUBDIRS = app seek volume dynamic snapshot
+DIST_SUBDIRS = app seek volume dynamic snapshot gio
diff --git a/tests/examples/gio/Makefile.am b/tests/examples/gio/Makefile.am
new file mode 100644 (file)
index 0000000..278edb7
--- /dev/null
@@ -0,0 +1,8 @@
+if HAVE_GTK
+if USE_GIO
+noinst_PROGRAMS = giosrc-mounting
+giosrc_mounting_SOURCES = giosrc-mounting.c
+giosrc_mounting_CFLAGS = $(GTK_CFLAGS) $(GIO_CFLAGS) $(GST_CFLAGS)
+giosrc_mounting_LDFLAGS = $(GTK_LIBS) $(GIO_LIBS) $(GST_LIBS)
+endif
+endif
diff --git a/tests/examples/gio/giosrc-mounting.c b/tests/examples/gio/giosrc-mounting.c
new file mode 100644 (file)
index 0000000..8181096
--- /dev/null
@@ -0,0 +1,132 @@
+/* GStreamer
+ *
+ * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gst/gst.h>
+#include <gtk/gtk.h>
+
+#include <string.h>
+
+static GstElement *pipeline = NULL;
+
+static void
+mount_cb (GObject * obj, GAsyncResult * res, gpointer user_data)
+{
+  gboolean ret;
+  GError *err = NULL;
+
+  ret = g_file_mount_enclosing_volume_finish (G_FILE (obj), res, &err);
+
+  if (ret) {
+    const gchar *uri;
+
+    g_print ("mounted successfully\n");
+    gst_bus_set_flushing ((GstBus *) user_data, FALSE);
+
+    /* FIXME: This works around bug #588078 */
+    g_object_get (G_OBJECT (pipeline), "uri", &uri, NULL);
+    g_object_set (G_OBJECT (pipeline), "uri", uri, NULL);
+
+    gst_element_set_state (pipeline, GST_STATE_PLAYING);
+  } else {
+    g_print ("mounting failed: %s\n", err->message);
+    g_clear_error (&err);
+    gtk_main_quit ();
+  }
+}
+
+gboolean
+message_handler (GstBus * bus, GstMessage * message, gpointer user_data)
+{
+
+  switch (message->type) {
+    case GST_MESSAGE_ELEMENT:{
+      const GstStructure *s = gst_message_get_structure (message);
+      const gchar *name = gst_structure_get_name (s);
+
+      if (strcmp (name, "not-mounted") == 0) {
+        GMountOperation *mop = gtk_mount_operation_new (NULL);
+        GFile *file =
+            G_FILE (g_value_get_object (gst_structure_get_value
+                (message->structure, "file")));
+
+        g_print ("not-mounted\n");
+        gst_element_set_state (pipeline, GST_STATE_NULL);
+        gst_bus_set_flushing (bus, TRUE);
+
+        g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE,
+            mop, NULL, mount_cb, bus);
+
+        g_object_unref (mop);
+      }
+      break;
+    }
+
+    case GST_MESSAGE_EOS:
+      g_print ("EOS\n");
+      gtk_main_quit ();
+      break;
+    case GST_MESSAGE_ERROR:{
+      GError *err = NULL;
+
+      gst_message_parse_error (message, &err, NULL);
+      g_print ("error: %s\n", err->message);
+      g_clear_error (&err);
+
+      gtk_main_quit ();
+      break;
+    }
+    default:
+      break;
+  }
+
+  return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+  GstBus *bus;
+  gint watch_id;
+
+  if (argc != 2) {
+    g_print ("usage: giosrc-mounting URI\n");
+    return -1;
+  }
+
+  gst_init (NULL, NULL);
+  gtk_init (NULL, NULL);
+
+  pipeline = gst_element_factory_make ("playbin2", NULL);
+  g_assert (pipeline);
+  g_object_set (G_OBJECT (pipeline), "uri", argv[1], NULL);
+
+  bus = gst_element_get_bus (pipeline);
+  watch_id = gst_bus_add_watch (bus, message_handler, NULL);
+  gst_object_unref (bus);
+
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+
+  gtk_main ();
+
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (pipeline);
+
+  return 0;
+}