1 /* GStreamer X-based Overlay
2 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * x-overlay.c: X-based overlay interface design
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.
24 * @short_description: Interface for setting/getting a Window on elements
29 * The XOverlay interface is used for 2 main purposes :
33 * To get a grab on the Window where the video sink element is going to render.
34 * This is achieved by either being informed about the Window identifier that
35 * the video sink element generated, or by forcing the video sink element to use
36 * a specific Window identifier for rendering.
41 * To force a redrawing of the latest video frame the video sink element
42 * displayed on the Window. Indeed if the #GstPipeline is in #GST_STATE_PAUSED
43 * state, moving the Window around will damage its content. Application
44 * developers will want to handle the Expose events themselves and force the
45 * video sink element to refresh the Window's content.
51 * Using the Window created by the video sink is probably the simplest scenario,
52 * in some cases, though, it might not be flexible enough for application
53 * developers if they need to catch events such as mouse moves and button
57 * Setting a specific Window identifier on the video sink element is the most
58 * flexible solution but it has some issues. Indeed the application needs to set
59 * its Window identifier at the right time to avoid internal Window creation
60 * from the video sink element. To solve this issue a #GstMessage is posted on
61 * the bus to inform the application that it should set the Window identifier
62 * immediately. Here is an example on how to do that correctly:
64 * static GstBusSyncReply
65 * create_window (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
69 * // ignore anything but 'prepare-xwindow-id' element messages
70 * if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
71 * return GST_BUS_PASS;
73 * if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
74 * return GST_BUS_PASS;
76 * win = XCreateSimpleWindow (disp, root, 0, 0, 320, 240, 0, 0, 0);
78 * XSetWindowBackgroundPixmap (disp, win, None);
80 * gc = XCreateGC (disp, win, 0, &values);
82 * XMapRaised (disp, win);
84 * XSync (disp, FALSE);
86 * gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
89 * return GST_BUS_DROP;
93 * main (int argc, char **argv)
96 * bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
97 * gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, pipeline);
109 #include "xoverlay.h"
111 static void gst_x_overlay_base_init (gpointer g_class);
114 gst_x_overlay_get_type (void)
116 static GType gst_x_overlay_type = 0;
118 if (!gst_x_overlay_type) {
119 static const GTypeInfo gst_x_overlay_info = {
120 sizeof (GstXOverlayClass),
121 gst_x_overlay_base_init,
131 gst_x_overlay_type = g_type_register_static (G_TYPE_INTERFACE,
132 "GstXOverlay", &gst_x_overlay_info, 0);
133 g_type_interface_add_prerequisite (gst_x_overlay_type,
134 GST_TYPE_IMPLEMENTS_INTERFACE);
137 return gst_x_overlay_type;
141 gst_x_overlay_base_init (gpointer g_class)
143 GstXOverlayClass *overlay_class = (GstXOverlayClass *) g_class;
145 overlay_class->set_xwindow_id = NULL;
149 * gst_x_overlay_set_xwindow_id:
150 * @overlay: a #GstXOverlay to set the XWindow on.
151 * @xwindow_id: a #XID referencing the XWindow.
153 * This will call the video overlay's set_xwindow_id method. You should
154 * use this method to tell to a XOverlay to display video output to a
155 * specific XWindow. Passing 0 as the xwindow_id will tell the overlay to
156 * stop using that window and create an internal one.
159 gst_x_overlay_set_xwindow_id (GstXOverlay * overlay, gulong xwindow_id)
161 GstXOverlayClass *klass = GST_X_OVERLAY_GET_CLASS (overlay);
163 if (klass->set_xwindow_id) {
164 klass->set_xwindow_id (overlay, xwindow_id);
169 * gst_x_overlay_got_xwindow_id:
170 * @overlay: a #GstXOverlay which got a XWindow.
171 * @xwindow_id: a #XID referencing the XWindow.
173 * This will post a "have-xwindow-id" element message on the bus.
175 * This function should only be used by video overlay plugin developers.
178 gst_x_overlay_got_xwindow_id (GstXOverlay * overlay, gulong xwindow_id)
183 g_return_if_fail (overlay != NULL);
184 g_return_if_fail (GST_IS_X_OVERLAY (overlay));
186 GST_LOG_OBJECT (GST_OBJECT (overlay), "xwindow_id = %lu", xwindow_id);
187 s = gst_structure_new ("have-xwindow-id", "xwindow-id", G_TYPE_ULONG,
189 msg = gst_message_new_element (GST_OBJECT (overlay), s);
190 gst_element_post_message (GST_ELEMENT (overlay), msg);
194 * gst_x_overlay_prepare_xwindow_id:
195 * @overlay: a #GstXOverlay which does not yet have an XWindow.
197 * This will post a "prepare-xwindow-id" element message on the bus
198 * to give applications an opportunity to call
199 * gst_x_overlay_set_xwindow_id() before a plugin creates its own
202 * This function should only be used by video overlay plugin developers.
205 gst_x_overlay_prepare_xwindow_id (GstXOverlay * overlay)
210 g_return_if_fail (overlay != NULL);
211 g_return_if_fail (GST_IS_X_OVERLAY (overlay));
213 GST_LOG_OBJECT (GST_OBJECT (overlay), "prepare xwindow_id");
214 s = gst_structure_new ("prepare-xwindow-id", NULL);
215 msg = gst_message_new_element (GST_OBJECT (overlay), s);
216 gst_element_post_message (GST_ELEMENT (overlay), msg);
220 * gst_x_overlay_expose:
221 * @overlay: a #GstXOverlay to expose.
223 * Tell an overlay that it has been exposed. This will redraw the current frame
224 * in the drawable even if the pipeline is PAUSED.
227 gst_x_overlay_expose (GstXOverlay * overlay)
229 GstXOverlayClass *klass = GST_X_OVERLAY_GET_CLASS (overlay);
232 klass->expose (overlay);