2003-10-10 12:47:41 +00:00
|
|
|
/* GStreamer X-based Overlay
|
|
|
|
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
|
|
|
*
|
2005-11-21 20:28:23 +00:00
|
|
|
* x-overlay.c: X-based overlay interface design
|
2003-10-10 12:47:41 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2005-11-28 13:06:05 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstxoverlay
|
|
|
|
* @short_description: Interface for setting/getting a Window on elements
|
2005-12-01 01:29:46 +00:00
|
|
|
* supporting it
|
2005-11-28 13:06:05 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <para>
|
|
|
|
* The XOverlay interface is used for 2 main purposes :
|
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
|
|
|
* To get a grab on the Window where the video sink element is going to render.
|
|
|
|
* This is achieved by either being informed about the Window identifier that
|
|
|
|
* the video sink element generated, or by forcing the video sink element to use
|
|
|
|
* a specific Window identifier for rendering.
|
|
|
|
* </para>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
2006-06-07 11:03:03 +00:00
|
|
|
* To force a redrawing of the latest video frame the video sink element
|
2005-11-28 13:06:05 +00:00
|
|
|
* displayed on the Window. Indeed if the #GstPipeline is in #GST_STATE_PAUSED
|
|
|
|
* state, moving the Window around will damage its content. Application
|
2006-06-07 11:03:03 +00:00
|
|
|
* developers will want to handle the Expose events themselves and force the
|
2005-11-28 13:06:05 +00:00
|
|
|
* video sink element to refresh the Window's content.
|
|
|
|
* </para>
|
|
|
|
* </listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* Using the Window created by the video sink is probably the simplest scenario,
|
2006-06-07 11:03:03 +00:00
|
|
|
* in some cases, though, it might not be flexible enough for application
|
2005-11-28 13:06:05 +00:00
|
|
|
* developers if they need to catch events such as mouse moves and button
|
|
|
|
* clicks.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* Setting a specific Window identifier on the video sink element is the most
|
|
|
|
* flexible solution but it has some issues. Indeed the application needs to set
|
|
|
|
* its Window identifier at the right time to avoid internal Window creation
|
|
|
|
* from the video sink element. To solve this issue a #GstMessage is posted on
|
2006-06-07 11:03:03 +00:00
|
|
|
* the bus to inform the application that it should set the Window identifier
|
2005-11-28 13:06:05 +00:00
|
|
|
* immediately. Here is an example on how to do that correctly:
|
|
|
|
* <programlisting>
|
|
|
|
* static GstBusSyncReply
|
|
|
|
* create_window (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
|
|
|
|
* {
|
2006-01-22 14:50:53 +00:00
|
|
|
* // ignore anything but 'prepare-xwindow-id' element messages
|
|
|
|
* if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
|
|
|
|
* return GST_BUS_PASS;
|
|
|
|
*
|
|
|
|
* if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
|
2005-11-28 13:06:05 +00:00
|
|
|
* return GST_BUS_PASS;
|
|
|
|
*
|
|
|
|
* win = XCreateSimpleWindow (disp, root, 0, 0, 320, 240, 0, 0, 0);
|
|
|
|
*
|
|
|
|
* XSetWindowBackgroundPixmap (disp, win, None);
|
|
|
|
*
|
|
|
|
* XMapRaised (disp, win);
|
|
|
|
*
|
|
|
|
* XSync (disp, FALSE);
|
|
|
|
*
|
|
|
|
* gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
|
|
|
|
* win);
|
|
|
|
*
|
2006-10-06 19:20:53 +00:00
|
|
|
* gst_message_unref (message);
|
|
|
|
*
|
2005-11-28 13:06:05 +00:00
|
|
|
* return GST_BUS_DROP;
|
|
|
|
* }
|
|
|
|
* ...
|
|
|
|
* int
|
|
|
|
* main (int argc, char **argv)
|
|
|
|
* {
|
|
|
|
* ...
|
|
|
|
* bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
|
|
|
* gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, pipeline);
|
|
|
|
* ...
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2003-10-10 12:47:41 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "xoverlay.h"
|
|
|
|
|
2003-11-19 22:40:59 +00:00
|
|
|
static void gst_x_overlay_base_init (gpointer g_class);
|
2003-10-10 12:47:41 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_x_overlay_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gst_x_overlay_type = 0;
|
|
|
|
|
|
|
|
if (!gst_x_overlay_type) {
|
|
|
|
static const GTypeInfo gst_x_overlay_info = {
|
|
|
|
sizeof (GstXOverlayClass),
|
2003-11-17 16:29:38 +00:00
|
|
|
gst_x_overlay_base_init,
|
2003-10-10 12:47:41 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
gst_x_overlay_type = g_type_register_static (G_TYPE_INTERFACE,
|
2004-03-15 19:32:28 +00:00
|
|
|
"GstXOverlay", &gst_x_overlay_info, 0);
|
2003-10-10 12:47:41 +00:00
|
|
|
g_type_interface_add_prerequisite (gst_x_overlay_type,
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_TYPE_IMPLEMENTS_INTERFACE);
|
2003-10-10 12:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gst_x_overlay_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-17 16:29:38 +00:00
|
|
|
gst_x_overlay_base_init (gpointer g_class)
|
2003-10-10 12:47:41 +00:00
|
|
|
{
|
2003-12-07 22:39:03 +00:00
|
|
|
GstXOverlayClass *overlay_class = (GstXOverlayClass *) g_class;
|
2003-12-07 12:11:30 +00:00
|
|
|
|
2003-12-07 22:39:03 +00:00
|
|
|
overlay_class->set_xwindow_id = NULL;
|
2003-10-10 12:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-11-17 16:29:38 +00:00
|
|
|
/**
|
|
|
|
* gst_x_overlay_set_xwindow_id:
|
|
|
|
* @overlay: a #GstXOverlay to set the XWindow on.
|
|
|
|
* @xwindow_id: a #XID referencing the XWindow.
|
|
|
|
*
|
|
|
|
* This will call the video overlay's set_xwindow_id method. You should
|
|
|
|
* use this method to tell to a XOverlay to display video output to a
|
ext/ffmpeg/gstffmpegcolorspace.c: Implementing gst_pad_alloc_buffer to use optimized buffer allocation.
Original commit message from CVS:
* ext/ffmpeg/gstffmpegcolorspace.c: (gst_ffmpegcsp_chain):
Implementing gst_pad_alloc_buffer to use optimized buffer allocation.
* gst-libs/gst/xoverlay/xoverlay.c:
(gst_x_overlay_got_desired_size): Updating doc for the xid being 0.
* gst/videoscale/gstvideoscale.c: (gst_videoscale_chain):
Implementing gst_pad_alloc_buffer to use optimized buffer allocation.
* gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_get):
Implementing gst_pad_alloc_buffer to use optimized buffer allocation.
* sys/ximage/ximagesink.c: (gst_ximagesink_chain),
(gst_ximagesink_buffer_free), (gst_ximagesink_buffer_alloc),
(gst_ximagesink_set_xwindow_id), (gst_ximagesink_init): Implementing
the bufferalloc_function to replace bufferpools, fixing the XOverlay
interface implementation to handle xid being 0 and fix some bugs
triggered by Benjamin's testcase.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_chain),
(gst_xvimagesink_buffer_free), (gst_xvimagesink_buffer_alloc),
(gst_xvimagesink_set_xwindow_id), (gst_xvimagesink_init): Implementing
the bufferalloc_function to replace bufferpools, fixing the XOverlay
interface implementation to handle xid being 0 and fix some bugs
triggered by Benjamin's testcase.
2004-01-09 18:05:57 +00:00
|
|
|
* specific XWindow. Passing 0 as the xwindow_id will tell the overlay to
|
|
|
|
* stop using that window and create an internal one.
|
2003-11-17 16:29:38 +00:00
|
|
|
*/
|
2003-10-10 12:47:41 +00:00
|
|
|
void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_x_overlay_set_xwindow_id (GstXOverlay * overlay, gulong xwindow_id)
|
2003-10-10 12:47:41 +00:00
|
|
|
{
|
2006-10-08 16:59:31 +00:00
|
|
|
GstXOverlayClass *klass;
|
|
|
|
|
|
|
|
g_return_if_fail (overlay != NULL);
|
|
|
|
g_return_if_fail (GST_IS_X_OVERLAY (overlay));
|
|
|
|
|
|
|
|
klass = GST_X_OVERLAY_GET_CLASS (overlay);
|
2003-10-10 12:47:41 +00:00
|
|
|
|
|
|
|
if (klass->set_xwindow_id) {
|
|
|
|
klass->set_xwindow_id (overlay, xwindow_id);
|
|
|
|
}
|
|
|
|
}
|
2003-11-17 16:29:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_x_overlay_got_xwindow_id:
|
|
|
|
* @overlay: a #GstXOverlay which got a XWindow.
|
|
|
|
* @xwindow_id: a #XID referencing the XWindow.
|
|
|
|
*
|
2005-11-21 20:28:23 +00:00
|
|
|
* This will post a "have-xwindow-id" element message on the bus.
|
2003-11-17 16:29:38 +00:00
|
|
|
*
|
2005-11-21 20:28:23 +00:00
|
|
|
* This function should only be used by video overlay plugin developers.
|
2003-11-17 16:29:38 +00:00
|
|
|
*/
|
|
|
|
void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_x_overlay_got_xwindow_id (GstXOverlay * overlay, gulong xwindow_id)
|
2003-11-17 16:29:38 +00:00
|
|
|
{
|
2005-11-21 20:28:23 +00:00
|
|
|
GstStructure *s;
|
|
|
|
GstMessage *msg;
|
|
|
|
|
2003-11-17 16:29:38 +00:00
|
|
|
g_return_if_fail (overlay != NULL);
|
|
|
|
g_return_if_fail (GST_IS_X_OVERLAY (overlay));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2005-11-21 20:28:23 +00:00
|
|
|
GST_LOG_OBJECT (GST_OBJECT (overlay), "xwindow_id = %lu", xwindow_id);
|
|
|
|
s = gst_structure_new ("have-xwindow-id", "xwindow-id", G_TYPE_ULONG,
|
|
|
|
xwindow_id, NULL);
|
|
|
|
msg = gst_message_new_element (GST_OBJECT (overlay), s);
|
|
|
|
gst_element_post_message (GST_ELEMENT (overlay), msg);
|
2004-01-04 18:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-11-21 20:28:23 +00:00
|
|
|
* gst_x_overlay_prepare_xwindow_id:
|
|
|
|
* @overlay: a #GstXOverlay which does not yet have an XWindow.
|
2004-01-04 18:02:30 +00:00
|
|
|
*
|
2005-11-21 20:28:23 +00:00
|
|
|
* This will post a "prepare-xwindow-id" element message on the bus
|
|
|
|
* to give applications an opportunity to call
|
|
|
|
* gst_x_overlay_set_xwindow_id() before a plugin creates its own
|
|
|
|
* window.
|
2004-01-04 18:02:30 +00:00
|
|
|
*
|
2005-11-21 20:28:23 +00:00
|
|
|
* This function should only be used by video overlay plugin developers.
|
2004-01-04 18:02:30 +00:00
|
|
|
*/
|
|
|
|
void
|
2005-11-21 20:28:23 +00:00
|
|
|
gst_x_overlay_prepare_xwindow_id (GstXOverlay * overlay)
|
2004-01-04 18:02:30 +00:00
|
|
|
{
|
2005-11-21 20:28:23 +00:00
|
|
|
GstStructure *s;
|
|
|
|
GstMessage *msg;
|
|
|
|
|
|
|
|
g_return_if_fail (overlay != NULL);
|
2004-01-04 18:02:30 +00:00
|
|
|
g_return_if_fail (GST_IS_X_OVERLAY (overlay));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2005-11-21 20:28:23 +00:00
|
|
|
GST_LOG_OBJECT (GST_OBJECT (overlay), "prepare xwindow_id");
|
|
|
|
s = gst_structure_new ("prepare-xwindow-id", NULL);
|
|
|
|
msg = gst_message_new_element (GST_OBJECT (overlay), s);
|
|
|
|
gst_element_post_message (GST_ELEMENT (overlay), msg);
|
2004-01-04 18:02:30 +00:00
|
|
|
}
|
2004-02-03 23:05:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_x_overlay_expose:
|
|
|
|
* @overlay: a #GstXOverlay to expose.
|
|
|
|
*
|
|
|
|
* Tell an overlay that it has been exposed. This will redraw the current frame
|
|
|
|
* in the drawable even if the pipeline is PAUSED.
|
|
|
|
*/
|
|
|
|
void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_x_overlay_expose (GstXOverlay * overlay)
|
2004-02-03 23:05:46 +00:00
|
|
|
{
|
2006-10-08 16:59:31 +00:00
|
|
|
GstXOverlayClass *klass;
|
|
|
|
|
|
|
|
g_return_if_fail (overlay != NULL);
|
|
|
|
|
|
|
|
klass = GST_X_OVERLAY_GET_CLASS (overlay);
|
2004-02-03 23:05:46 +00:00
|
|
|
|
|
|
|
if (klass->expose) {
|
|
|
|
klass->expose (overlay);
|
|
|
|
}
|
|
|
|
}
|
Add a method to the XOverlay interface to allow disabling of event handling in x[v]imagesink elements. This will let ...
Original commit message from CVS:
2007-01-04 Julien MOUTTE <julien@moutte.net>
* gst-libs/gst/interfaces/xoverlay.c:
(gst_x_overlay_handle_events):
* gst-libs/gst/interfaces/xoverlay.h:
* sys/ximage/ximagesink.c: (gst_ximagesink_xwindow_new),
(gst_ximagesink_set_xwindow_id),
(gst_ximagesink_set_event_handling),
(gst_ximagesink_xoverlay_init), (gst_ximagesink_set_property),
(gst_ximagesink_get_property), (gst_ximagesink_init),
(gst_ximagesink_class_init):
* sys/ximage/ximagesink.h:
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_xwindow_new),
(gst_xvimagesink_set_xwindow_id),
(gst_xvimagesink_set_event_handling),
(gst_xvimagesink_xoverlay_init), (gst_xvimagesink_set_property),
(gst_xvimagesink_get_property), (gst_xvimagesink_init),
(gst_xvimagesink_class_init):
* sys/xvimage/xvimagesink.h:
* tests/icles/stress-xoverlay.c: (toggle_events),
(create_window):
Add a method to the XOverlay interface to allow disabling of
event handling in x[v]imagesink elements. This will let X events
propagate to parent windows which can be usefull in some cases.
Be carefull that the application is then responsible of pushing
navigation events and expose events to the video sink.
Fixes: #387138.
2007-01-04 11:30:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_x_overlay_handle_events:
|
|
|
|
* @overlay: a #GstXOverlay to expose.
|
|
|
|
* @handle_events: a #gboolean indicating if events should be handled or not.
|
|
|
|
*
|
|
|
|
* Tell an overlay that it should handle events from the window system. These
|
|
|
|
* events are forwared upstream as navigation events. In some window system,
|
|
|
|
* events are not propagated in the window hierarchy if a client is listening
|
|
|
|
* for them. This method allows you to disable events handling completely
|
|
|
|
* from the XOverlay.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_x_overlay_handle_events (GstXOverlay * overlay, gboolean handle_events)
|
|
|
|
{
|
|
|
|
GstXOverlayClass *klass;
|
|
|
|
|
|
|
|
g_return_if_fail (overlay != NULL);
|
|
|
|
|
|
|
|
klass = GST_X_OVERLAY_GET_CLASS (overlay);
|
|
|
|
|
|
|
|
if (klass->handle_events) {
|
|
|
|
klass->handle_events (overlay, handle_events);
|
|
|
|
}
|
|
|
|
}
|