From 85151175737869e713dc2337351cd3cf66d9e77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 10 Jul 2009 11:42:51 +0200 Subject: [PATCH] gio: Add example application that shows how to handle the "not-mounted" message --- configure.ac | 1 + tests/examples/Makefile.am | 8 +- tests/examples/gio/Makefile.am | 8 ++ tests/examples/gio/giosrc-mounting.c | 132 +++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 tests/examples/gio/Makefile.am create mode 100644 tests/examples/gio/giosrc-mounting.c diff --git a/configure.ac b/configure.ac index 6eb41bae59..da8f5395b4 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/tests/examples/Makefile.am b/tests/examples/Makefile.am index e57d47a0bf..e9cb97536e 100644 --- a/tests/examples/Makefile.am +++ b/tests/examples/Makefile.am @@ -4,6 +4,10 @@ else FT2_SUBDIRS = endif -SUBDIRS = app $(FT2_SUBDIRS) volume dynamic +if USE_GIO +GIO_SUBDIRS = gio +endif -DIST_SUBDIRS = app seek volume dynamic snapshot +SUBDIRS = app $(FT2_SUBDIRS) $(GIO_SUBDIRS) volume dynamic + +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 index 0000000000..278edb7111 --- /dev/null +++ b/tests/examples/gio/Makefile.am @@ -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 index 0000000000..8181096a2d --- /dev/null +++ b/tests/examples/gio/giosrc-mounting.c @@ -0,0 +1,132 @@ +/* GStreamer + * + * Copyright (C) 2009 Sebastian Dröge + * + * 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 +#include + +#include + +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; +}