#include "config.h"
#endif
+/* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
+ * with newer GTK versions (>= 3.3.0) */
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+
#include <stdlib.h>
#include <string.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
-#include <X11/Xlib.h>
-
#include <gst/gst.h>
-#include <gst/interfaces/xoverlay.h>
-#include <gst/interfaces/propertyprobe.h>
+#include <gst/video/videooverlay.h>
static GtkWidget *video_window = NULL;
static GstElement *sink = NULL;
static gulong embed_xid = 0;
-static GdkGC *trans_gc = NULL;
+static GdkColor trans_color;
+static gboolean trans_color_set = FALSE;
static void
redraw_overlay (GtkWidget * widget)
{
- gdk_draw_rectangle (widget->window, widget->style->white_gc, TRUE,
- 0, 0, widget->allocation.width, widget->allocation.height);
+ GtkAllocation allocation;
+ GdkWindow *window = gtk_widget_get_window (widget);
+ cairo_t *cr;
+
+ cr = gdk_cairo_create (window);
+ gtk_widget_get_allocation (widget, &allocation);
- if (trans_gc) {
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
+ cairo_fill (cr);
+
+ if (trans_color_set) {
guint x, y;
- guint h = widget->allocation.height * 0.75;
+ guint h = allocation.height * 0.75;
- gdk_draw_rectangle (widget->window, trans_gc, TRUE,
- 0, 0, widget->allocation.width, h);
+ gdk_cairo_set_source_color (cr, &trans_color);
+ cairo_rectangle (cr, 0, 0, allocation.width, h);
+ cairo_fill (cr);
- for (y = h; y < widget->allocation.height; y++) {
- for (x = 0; x < widget->allocation.width; x++) {
+ for (y = h; y < allocation.height; y++) {
+ for (x = 0; x < allocation.width; x++) {
if (((x & 1) || (y & 1)) && (x & 1) != (y & 1)) {
- gdk_draw_point (widget->window, trans_gc, x, y);
+ cairo_move_to (cr, x, y);
+ cairo_paint (cr);
}
}
}
}
static gboolean
-handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
+draw_cb (GtkWidget * widget, cairo_t * cr, gpointer data)
{
redraw_overlay (widget);
return FALSE;
static void
realize_cb (GtkWidget * widget, gpointer data)
{
+ GdkWindow *window = gtk_widget_get_window (widget);
+
/* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
* as well */
- if (!gdk_window_ensure_native (widget->window))
+ if (!gdk_window_ensure_native (window))
g_error ("Couldn't create native window needed for GstXOverlay!");
- embed_xid = GDK_WINDOW_XID (video_window->window);
- g_print ("Window realize: got XID %lu\n", embed_xid);
+ embed_xid = GDK_WINDOW_XID (window);
+ g_print ("Window realize: video window XID = %lu\n", embed_xid);
}
static void
/* When state of the pipeline changes to paused or playing we start updating scale */
switch (GST_STATE_TRANSITION (old, new)) {
- case GST_STATE_CHANGE_READY_TO_PAUSED:
+ case GST_STATE_CHANGE_READY_TO_PAUSED:{
g_object_get (G_OBJECT (sink), "colorkey", &color, NULL);
if (color != -1) {
- GdkColor trans_color = { 0,
- (color & 0xff0000) >> 8,
- (color & 0xff00),
- (color & 0xff) << 8
- };
-
- trans_gc = gdk_gc_new (video_window->window);
- gdk_gc_set_rgb_fg_color (trans_gc, &trans_color);
+ trans_color.red = (color & 0xff0000) >> 8;
+ trans_color.green = (color & 0xff00);
+ trans_color.blue = (color & 0xff) << 8;
+ trans_color_set = TRUE;
+ } else {
+ trans_color_set = FALSE;
}
handle_resize_cb (video_window, NULL, NULL);
break;
+ }
default:
break;
}
GstElement *pipeline = user_data;
g_print ("stopping\n");
- gtk_widget_hide_all (widget);
+ gtk_widget_hide (widget);
gst_element_set_state (pipeline, GST_STATE_NULL);
gtk_main_quit ();
}
GstElement *pipeline, *src;
GstBus *bus;
GstStateChangeReturn sret;
+#if 0
GstPropertyProbe *probe;
GValueArray *arr;
-
- if (!g_thread_supported ())
- g_thread_init (NULL);
-
- if (!XInitThreads ()) {
- g_print ("XInitThreads failed\n");
- exit (-1);
- }
+#endif
gst_init (&argc, &argv);
gtk_init (&argc, &argv);
gst_object_unref (pipeline);
return -1;
}
-
+#if 0
probe = GST_PROPERTY_PROBE (sink);
if (!probe) {
g_printerr ("Can't probe sink\n");
}
if (arr)
g_value_array_free (arr);
+#endif
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
video_window = gtk_drawing_area_new ();
g_signal_connect (G_OBJECT (video_window), "configure-event",
G_CALLBACK (handle_resize_cb), NULL);
- g_signal_connect (G_OBJECT (video_window), "expose-event",
- G_CALLBACK (handle_expose_cb), NULL);
+ g_signal_connect (G_OBJECT (video_window), "draw",
+ G_CALLBACK (draw_cb), NULL);
g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL);
gtk_widget_set_double_buffered (video_window, FALSE);
gtk_container_add (GTK_CONTAINER (window), video_window);
g_assert (embed_xid != 0);
/* we know what the video sink is in this case (xvimagesink), so we can
- * just set it directly here now (instead of waiting for a prepare-xwindow-id
- * element message in a sync bus handler and setting it there) */
+ * just set it directly here now (instead of waiting for a
+ * prepare-window-handle element message in a sync bus handler and setting
+ * it there) */
g_print ("setting XID %lu\n", embed_xid);
- gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (sink), embed_xid);
+ gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (sink), embed_xid);
g_idle_add (start_pipeline, pipeline);
gtk_main ();