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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
25 #include <gst/video/videooverlay.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 (GstVideoOverlay * ov)
99 static gboolean events_toggled;
101 gst_video_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 (GstVideoOverlay * 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_video_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 GstVideoOverlay *ov = NULL;
147 if (!gst_is_video_overlay_prepare_window_handle_message (message))
150 ov = GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message));
152 g_print ("Creating our own window\n");
156 g_timeout_add (50, (GSourceFunc) resize_window, pipeline);
157 g_timeout_add (50, (GSourceFunc) move_window, pipeline);
158 g_timeout_add (100, (GSourceFunc) cycle_window, ov);
159 g_timeout_add_seconds (2, (GSourceFunc) toggle_events, ov);
161 gst_message_unref (message);
167 terminate_playback (GstElement * pipeline)
169 g_print ("Terminating playback\n");
170 g_main_loop_quit (loop);
176 pause_playback (GstElement * pipeline)
178 g_print ("Pausing playback\n");
179 gst_element_set_state (pipeline, GST_STATE_PAUSED);
184 start_playback (GstElement * pipeline)
186 g_print ("Starting playback\n");
187 gst_element_set_state (pipeline, GST_STATE_PLAYING);
192 main (int argc, char **argv)
194 GstElement *pipeline;
197 #ifndef GST_DISABLE_PARSE
198 GError *error = NULL;
201 gst_init (&argc, &argv);
204 g_print ("Usage: %s \"pipeline description with launch format\"\n",
207 ("The pipeline should contain an element implementing GstVideoOverlay.\n");
208 g_print ("Example: %s \"videotestsrc ! ximagesink\"\n", argv[0]);
211 #ifdef GST_DISABLE_PARSE
212 g_print ("GStreamer was built without pipeline parsing capabilities.\n");
214 ("Please rebuild GStreamer with pipeline parsing capabilities activated to use this example.\n");
217 pipeline = gst_parse_launch (argv[1], &error);
219 g_print ("Error while parsing pipeline description: %s\n", error->message);
224 loop = g_main_loop_new (NULL, FALSE);
228 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
229 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, pipeline,
232 gst_element_set_state (pipeline, GST_STATE_PLAYING);
234 /* We want to get out after */
235 //g_timeout_add (500000, (GSourceFunc) terminate_playback, pipeline);
236 g_timeout_add_seconds (10, (GSourceFunc) pause_playback, pipeline);
237 g_timeout_add_seconds (20, (GSourceFunc) start_playback, pipeline);
239 g_main_loop_run (loop);
243 g_main_loop_unref (loop);
245 gst_object_unref (bus);