summaryrefslogtreecommitdiff
path: root/tests/examples
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2015-05-31 15:40:15 +1000
committerMatthew Waters <matthew@centricular.com>2015-05-31 16:09:34 +1000
commit21cbf763b056b00262593bf642bdfa7fac3c6b79 (patch)
treeab198228535915f4088b7f5c9a52bc27981cbc72 /tests/examples
parente385adc241da19242574214d4129233098d277f8 (diff)
downloadgstreamer-plugins-bad-21cbf763b056b00262593bf642bdfa7fac3c6b79.tar.gz
gl/examples: update gtk examples for wayland
Diffstat (limited to 'tests/examples')
-rw-r--r--tests/examples/gl/gtk/filtervideooverlay/main.cpp52
-rw-r--r--tests/examples/gl/gtk/switchvideooverlay/main.cpp64
2 files changed, 100 insertions, 16 deletions
diff --git a/tests/examples/gl/gtk/filtervideooverlay/main.cpp b/tests/examples/gl/gtk/filtervideooverlay/main.cpp
index 8ca402d8b..70b4b00f4 100644
--- a/tests/examples/gl/gtk/filtervideooverlay/main.cpp
+++ b/tests/examples/gl/gtk/filtervideooverlay/main.cpp
@@ -27,6 +27,11 @@
static GstBusSyncReply create_window (GstBus* bus, GstMessage* message, GtkWidget* widget)
{
+ GtkAllocation allocation;
+
+ if (gst_gtk_handle_need_context (bus, message, NULL))
+ return GST_BUS_DROP;
+
// ignore anything but 'prepare-window-handle' element messages
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS;
@@ -38,22 +43,55 @@ static GstBusSyncReply create_window (GstBus* bus, GstMessage* message, GtkWidge
gst_video_overlay_set_gtk_window (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)), widget);
+ gtk_widget_get_allocation (widget, &allocation);
+ gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)), allocation.x, allocation.y, allocation.width, allocation.height);
+
gst_message_unref (message);
return GST_BUS_DROP;
}
-
-static void end_stream_cb(GstBus* bus, GstMessage* message, GstElement* pipeline)
+static gboolean
+resize_cb (GtkWidget * widget, GdkEvent * event, gpointer sink)
{
- g_print("End of stream\n");
+ GtkAllocation allocation;
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_object_unref(pipeline);
+ gtk_widget_get_allocation (widget, &allocation);
+ gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (sink), allocation.x, allocation.y, allocation.width, allocation.height);
- gtk_main_quit();
+ return G_SOURCE_CONTINUE;
}
+static void end_stream_cb(GstBus* bus, GstMessage* message, GstElement* pipeline)
+{
+ GError *error = NULL;
+ gchar *details;
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_ERROR:
+ gst_message_parse_error (message, &error, &details);
+
+ g_print("Error %s\n", error->message);
+ g_print("Details %s\n", details);
+ /* fallthrough */
+ case GST_MESSAGE_EOS:
+ g_print("End of stream\n");
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+ gst_object_unref(pipeline);
+
+ gtk_main_quit();
+ break;
+ case GST_MESSAGE_WARNING:
+ gst_message_parse_warning (message, &error, &details);
+
+ g_print("Warning %s\n", error->message);
+ g_print("Details %s\n", details);
+ break;
+ default:
+ break;
+ }
+}
static gboolean expose_cb(GtkWidget* widget, cairo_t *cr, GstElement* videosink)
{
@@ -211,6 +249,7 @@ gint main (gint argc, gchar *argv[])
//area where the video is drawn
GtkWidget* area = gtk_drawing_area_new();
+ gtk_widget_set_redraw_on_allocate (area, TRUE);
gtk_container_add (GTK_CONTAINER (window), area);
gtk_widget_realize(area);
@@ -227,6 +266,7 @@ gint main (gint argc, gchar *argv[])
//needed when being in GST_STATE_READY, GST_STATE_PAUSED
//or resizing/obscuring the window
g_signal_connect(area, "draw", G_CALLBACK(expose_cb), videosink);
+ g_signal_connect(area, "configure-event", G_CALLBACK(resize_cb), videosink);
//start
GstStateChangeReturn ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
diff --git a/tests/examples/gl/gtk/switchvideooverlay/main.cpp b/tests/examples/gl/gtk/switchvideooverlay/main.cpp
index e8378b8f8..ea53ea1f6 100644
--- a/tests/examples/gl/gtk/switchvideooverlay/main.cpp
+++ b/tests/examples/gl/gtk/switchvideooverlay/main.cpp
@@ -27,6 +27,11 @@
static GstBusSyncReply create_window (GstBus* bus, GstMessage* message, GtkWidget* widget)
{
+ GtkAllocation allocation;
+
+ if (gst_gtk_handle_need_context (bus, message, NULL))
+ return GST_BUS_DROP;
+
// ignore anything but 'prepare-window-handle' element messages
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS;
@@ -38,22 +43,55 @@ static GstBusSyncReply create_window (GstBus* bus, GstMessage* message, GtkWidge
gst_video_overlay_set_gtk_window (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)), widget);
+ gtk_widget_get_allocation (widget, &allocation);
+ gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)), allocation.x, allocation.y, allocation.width, allocation.height);
+
gst_message_unref (message);
return GST_BUS_DROP;
}
-
-static void end_stream_cb(GstBus* bus, GstMessage* message, GstElement* pipeline)
+static gboolean
+resize_cb (GtkWidget * widget, GdkEvent * event, gpointer sink)
{
- g_print("End of stream\n");
+ GtkAllocation allocation;
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_object_unref(pipeline);
+ gtk_widget_get_allocation (widget, &allocation);
+ gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (sink), allocation.x, allocation.y, allocation.width, allocation.height);
- gtk_main_quit();
+ return G_SOURCE_CONTINUE;
}
+static void end_stream_cb(GstBus* bus, GstMessage* message, GstElement* pipeline)
+{
+ GError *error = NULL;
+ gchar *details;
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_ERROR:
+ gst_message_parse_error (message, &error, &details);
+
+ g_print("Error %s\n", error->message);
+ g_print("Details %s\n", details);
+ /* fallthrough */
+ case GST_MESSAGE_EOS:
+ g_print("End of stream\n");
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+ gst_object_unref(pipeline);
+
+ gtk_main_quit();
+ break;
+ case GST_MESSAGE_WARNING:
+ gst_message_parse_warning (message, &error, &details);
+
+ g_print("Warning %s\n", error->message);
+ g_print("Details %s\n", details);
+ break;
+ default:
+ break;
+ }
+}
static gboolean expose_cb(GtkWidget* widget, cairo_t *cr, GstElement* videosink)
{
@@ -65,9 +103,14 @@ static gboolean expose_cb(GtkWidget* widget, cairo_t *cr, GstElement* videosink)
static gboolean on_click_drawing_area(GtkWidget* widget, GdkEventButton* event, GstElement* videosink)
{
+ GtkAllocation allocation;
+
g_print ("switch the drawing area %p\n", widget);
gst_video_overlay_set_gtk_window (GST_VIDEO_OVERLAY (videosink), widget);
- gst_video_overlay_expose (GST_VIDEO_OVERLAY (videosink));
+
+ gtk_widget_get_allocation (widget, &allocation);
+ gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (videosink), allocation.x, allocation.y, allocation.width, allocation.height);
+
return FALSE;
}
@@ -115,9 +158,6 @@ static void area_realize_cb(GtkWidget* widget, gpointer data)
g_print ("realize %p\n", widget);
if (!gdk_window_ensure_native (gtk_widget_get_window (widget)))
g_error ("Failed to create native window!");
-
- //avoid flickering when resizing or obscuring the main window
- gtk_widget_set_app_paintable(widget, TRUE);
}
@@ -214,6 +254,8 @@ gint main (gint argc, gchar *argv[])
g_signal_connect(area_top_left, "realize", G_CALLBACK(area_realize_cb), NULL);
g_signal_connect(area_top_right, "realize", G_CALLBACK(area_realize_cb), NULL);
+ gtk_widget_set_redraw_on_allocate (area_top_left, TRUE);
+ gtk_widget_set_redraw_on_allocate (area_top_right, TRUE);
gtk_widget_realize(area_top_left);
gtk_widget_realize(area_top_right);
@@ -228,7 +270,9 @@ gint main (gint argc, gchar *argv[])
//needed when being in GST_STATE_READY, GST_STATE_PAUSED
//or resizing/obscuring the window
g_signal_connect(area_top_left, "draw", G_CALLBACK(expose_cb), videosink);
+ g_signal_connect(area_top_left, "configure-event", G_CALLBACK(resize_cb), videosink);
g_signal_connect(area_top_right, "draw", G_CALLBACK(expose_cb), videosink);
+ g_signal_connect(area_top_right, "configure-event", G_CALLBACK(resize_cb), videosink);
//switch the drawing area
g_signal_connect(area_top_left, "button-press-event", G_CALLBACK(on_click_drawing_area), videosink);