2 * Copyright (C) <2010> Stefan Kost <ensonic@users.sf.net>
4 * gtk-xoverlay: demonstrate overlay handling using gtk
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
31 #include <gst/interfaces/xoverlay.h>
36 window_closed (GtkWidget * widget, GdkEvent * event, gpointer user_data)
38 GstElement *pipeline = user_data;
40 gtk_widget_hide (widget);
41 gst_element_set_state (pipeline, GST_STATE_NULL);
45 /* slightly convoluted way to find a working video sink that's not a bin,
46 * one could use autovideosink from gst-plugins-good instead
49 find_video_sink (void)
51 GstStateChangeReturn sret;
54 if ((sink = gst_element_factory_make ("xvimagesink", NULL))) {
55 sret = gst_element_set_state (sink, GST_STATE_READY);
56 if (sret == GST_STATE_CHANGE_SUCCESS)
59 gst_element_set_state (sink, GST_STATE_NULL);
61 gst_object_unref (sink);
63 if ((sink = gst_element_factory_make ("ximagesink", NULL))) {
64 sret = gst_element_set_state (sink, GST_STATE_READY);
65 if (sret == GST_STATE_CHANGE_SUCCESS)
68 gst_element_set_state (sink, GST_STATE_NULL);
70 gst_object_unref (sink);
72 if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") == 0 ||
73 strcmp (DEFAULT_VIDEOSINK, "ximagesink") == 0)
76 if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) {
77 if (GST_IS_BIN (sink)) {
78 gst_object_unref (sink);
82 sret = gst_element_set_state (sink, GST_STATE_READY);
83 if (sret == GST_STATE_CHANGE_SUCCESS)
86 gst_element_set_state (sink, GST_STATE_NULL);
88 gst_object_unref (sink);
93 main (int argc, char **argv)
95 GdkWindow *video_window_xwindow;
96 GtkWidget *window, *video_window;
97 GstElement *pipeline, *src, *sink;
99 GstStateChangeReturn sret;
101 #if !GLIB_CHECK_VERSION (2, 31, 0)
102 if (!g_thread_supported ())
103 g_thread_init (NULL);
106 gst_init (&argc, &argv);
107 gtk_init (&argc, &argv);
109 /* prepare the pipeline */
111 pipeline = gst_pipeline_new ("xvoverlay");
112 src = gst_element_factory_make ("videotestsrc", NULL);
113 sink = find_video_sink ();
116 g_error ("Couldn't find a working video sink.");
118 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
119 gst_element_link (src, sink);
123 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
124 g_signal_connect (G_OBJECT (window), "delete-event",
125 G_CALLBACK (window_closed), (gpointer) pipeline);
126 gtk_window_set_default_size (GTK_WINDOW (window), 320, 240);
127 gtk_window_set_title (GTK_WINDOW (window), "GstXOverlay Gtk+ demo");
129 video_window = gtk_drawing_area_new ();
130 gtk_widget_set_double_buffered (video_window, FALSE);
131 gtk_container_add (GTK_CONTAINER (window), video_window);
132 gtk_container_set_border_width (GTK_CONTAINER (window), 16);
134 gtk_widget_show_all (window);
135 gtk_widget_realize (window);
137 video_window_xwindow = gtk_widget_get_window (video_window);
138 embed_xid = GDK_WINDOW_XID (video_window_xwindow);
139 gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), embed_xid);
141 /* run the pipeline */
143 sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
144 if (sret == GST_STATE_CHANGE_FAILURE)
145 gst_element_set_state (pipeline, GST_STATE_NULL);
149 gst_object_unref (pipeline);