Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / examples / gio / giosrc-mounting.c
1 /* GStreamer
2  *
3  * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
4  * 
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <gst/gst.h>
22 #include <gtk/gtk.h>
23
24 #include <string.h>
25
26 static GstElement *pipeline = NULL;
27
28 static void
29 mount_cb (GObject * obj, GAsyncResult * res, gpointer user_data)
30 {
31   gboolean ret;
32   GError *err = NULL;
33
34   ret = g_file_mount_enclosing_volume_finish (G_FILE (obj), res, &err);
35
36   if (ret) {
37     g_print ("mounted successfully\n");
38     gst_bus_set_flushing ((GstBus *) user_data, FALSE);
39
40     gst_element_set_state (pipeline, GST_STATE_PLAYING);
41   } else {
42     g_print ("mounting failed: %s\n", err->message);
43     g_clear_error (&err);
44     gtk_main_quit ();
45   }
46 }
47
48 static gboolean
49 message_handler (GstBus * bus, GstMessage * message, gpointer user_data)
50 {
51
52   switch (message->type) {
53     case GST_MESSAGE_ELEMENT:{
54       const GstStructure *s = gst_message_get_structure (message);
55       const gchar *name = gst_structure_get_name (s);
56
57       if (strcmp (name, "not-mounted") == 0) {
58         GMountOperation *mop = gtk_mount_operation_new (NULL);
59         GFile *file =
60             G_FILE (g_value_get_object (gst_structure_get_value
61                 (message->structure, "file")));
62
63         g_print ("not-mounted\n");
64         gst_element_set_state (pipeline, GST_STATE_NULL);
65         gst_bus_set_flushing (bus, TRUE);
66
67         g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE,
68             mop, NULL, mount_cb, bus);
69
70         g_object_unref (mop);
71       }
72       break;
73     }
74
75     case GST_MESSAGE_EOS:
76       g_print ("EOS\n");
77       gtk_main_quit ();
78       break;
79     case GST_MESSAGE_ERROR:{
80       GError *err = NULL;
81
82       gst_message_parse_error (message, &err, NULL);
83       g_print ("error: %s\n", err->message);
84       g_clear_error (&err);
85
86       gtk_main_quit ();
87       break;
88     }
89     default:
90       break;
91   }
92
93   return TRUE;
94 }
95
96 int
97 main (int argc, char *argv[])
98 {
99   GstBus *bus;
100   gint watch_id;
101
102   if (argc != 2) {
103     g_print ("usage: giosrc-mounting URI\n");
104     return -1;
105   }
106
107   gst_init (NULL, NULL);
108   gtk_init (NULL, NULL);
109
110   pipeline = gst_element_factory_make ("playbin2", NULL);
111   g_assert (pipeline);
112   g_object_set (G_OBJECT (pipeline), "uri", argv[1], NULL);
113
114   bus = gst_element_get_bus (pipeline);
115   watch_id = gst_bus_add_watch (bus, message_handler, NULL);
116   gst_object_unref (bus);
117
118   gst_element_set_state (pipeline, GST_STATE_PLAYING);
119
120   gtk_main ();
121
122   g_source_remove (watch_id);
123   gst_element_set_state (pipeline, GST_STATE_NULL);
124   gst_object_unref (pipeline);
125
126   return 0;
127 }