2 * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gst/interfaces/xoverlay.h>
28 #include <X11/Xutil.h>
33 static GMainLoop *loop;
36 static Window root, win = 0;
38 static gint width = 320, height = 240, x = 0, y = 0;
39 static gint disp_width, disp_height;
46 gettimeofday (&tv, NULL);
47 return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
55 disp = XOpenDisplay (NULL);
56 root = DefaultRootWindow (disp);
57 screen_num = DefaultScreen (disp);
58 disp_width = DisplayWidth (disp, screen_num);
59 disp_height = DisplayHeight (disp, screen_num);
69 resize_window (GstPipeline * pipeline)
71 width = (sin (myclock () / 300.0) * 200) + 640;
72 height = (sin (myclock () / 300.0) * 200) + 480;
74 XResizeWindow (disp, win, width, height);
82 move_window (GstPipeline * pipeline)
85 y = disp_height - height + (sin (myclock () / 300.0) * height);
89 XMoveWindow (disp, win, x, y);
97 toggle_events (GstXOverlay * ov)
99 static gboolean events_toggled;
101 gst_x_overlay_handle_events (ov, events_toggled);
103 if (events_toggled) {
104 g_print ("Events are handled\n");
105 events_toggled = FALSE;
107 g_print ("Events are NOT handled\n");
108 events_toggled = TRUE;
115 cycle_window (GstXOverlay * ov)
118 Window old_win = win;
121 win = XCreateSimpleWindow (disp, root, 0, 0, width, height, 0, 0, 0);
123 XSetWindowBackgroundPixmap (disp, win, None);
125 gc = XCreateGC (disp, win, 0, &values);
127 XMapRaised (disp, win);
131 gst_x_overlay_set_window_handle (ov, win);
134 XDestroyWindow (disp, old_win);
135 XFreeGC (disp, old_gc);
142 static GstBusSyncReply
143 create_window (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
145 const GstStructure *s;
146 GstXOverlay *ov = NULL;
148 s = gst_message_get_structure (message);
149 if (s == NULL || !gst_structure_has_name (s, "prepare-xwindow-id")) {
153 ov = GST_X_OVERLAY (GST_MESSAGE_SRC (message));
155 g_print ("Creating our own window\n");
159 g_timeout_add (50, (GSourceFunc) resize_window, pipeline);
160 g_timeout_add (50, (GSourceFunc) move_window, pipeline);
161 g_timeout_add (100, (GSourceFunc) cycle_window, ov);
162 g_timeout_add (2000, (GSourceFunc) toggle_events, ov);
164 gst_message_unref (message);
170 terminate_playback (GstElement * pipeline)
172 g_print ("Terminating playback\n");
173 g_main_loop_quit (loop);
179 pause_playback (GstElement * pipeline)
181 g_print ("Pausing playback\n");
182 gst_element_set_state (pipeline, GST_STATE_PAUSED);
187 start_playback (GstElement * pipeline)
189 g_print ("Starting playback\n");
190 gst_element_set_state (pipeline, GST_STATE_PLAYING);
195 main (int argc, char **argv)
197 GstElement *pipeline;
200 #ifndef GST_DISABLE_PARSE
201 GError *error = NULL;
204 gst_init (&argc, &argv);
207 g_print ("Usage: %s \"pipeline description with launch format\"\n",
209 g_print ("The pipeline should contain an element implementing XOverlay.\n");
210 g_print ("Example: %s \"videotestsrc ! ximagesink\"\n", argv[0]);
213 #ifdef GST_DISABLE_PARSE
214 g_print ("GStreamer was built without pipeline parsing capabilities.\n");
216 ("Please rebuild GStreamer with pipeline parsing capabilities activated to use this example.\n");
219 pipeline = gst_parse_launch (argv[1], &error);
221 g_print ("Error while parsing pipeline description: %s\n", error->message);
226 loop = g_main_loop_new (NULL, FALSE);
230 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
231 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, pipeline);
233 gst_element_set_state (pipeline, GST_STATE_PLAYING);
235 /* We want to get out after */
236 //g_timeout_add (500000, (GSourceFunc) terminate_playback, pipeline);
237 g_timeout_add (10000, (GSourceFunc) pause_playback, pipeline);
238 g_timeout_add (20000, (GSourceFunc) start_playback, pipeline);
240 g_main_loop_run (loop);
244 g_main_loop_unref (loop);