diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c index 63f348dc5a..1a37d6d0be 100644 --- a/ext/wayland/gstwaylandsink.c +++ b/ext/wayland/gstwaylandsink.c @@ -265,9 +265,7 @@ gst_wayland_sink_find_display (GstWaylandSink * sink) } else { /* inform the world about the new display */ context = - gst_context_new (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE, FALSE); - gst_structure_set (gst_context_writable_structure (context), - "handle", G_TYPE_POINTER, sink->display->display, NULL); + gst_wayland_display_handle_context_new (sink->display->display); msg = gst_message_new_have_context (GST_OBJECT_CAST (sink), context); gst_element_post_message (GST_ELEMENT_CAST (sink), msg); } @@ -345,13 +343,13 @@ gst_wayland_sink_set_context (GstElement * element, GstContext * context) if (gst_context_has_context_type (context, GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE)) { - const GstStructure *s; struct wl_display *display; GError *error = NULL; - s = gst_context_get_structure (context); - gst_structure_get (s, "handle", G_TYPE_POINTER, &display, NULL); + g_clear_object (&sink->display); + display = gst_wayland_display_handle_context_get_handle (context); sink->display = gst_wl_display_new_existing (display, FALSE, &error); + if (error) { GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE, ("Could not set display handle"), diff --git a/gst-libs/gst/wayland/wayland.c b/gst-libs/gst/wayland/wayland.c index 9ede5b8a02..81c673fc92 100644 --- a/gst-libs/gst/wayland/wayland.c +++ b/gst-libs/gst/wayland/wayland.c @@ -25,6 +25,45 @@ #include #include +gboolean +gst_is_wayland_display_handle_need_context_message (GstMessage * msg) +{ + const gchar *type = NULL; + + g_return_val_if_fail (GST_IS_MESSAGE (msg), FALSE); + + if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_NEED_CONTEXT && + gst_message_parse_context_type (msg, &type)) { + return !g_strcmp0 (type, GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE); + } + + return FALSE; +} + +GstContext * +gst_wayland_display_handle_context_new (struct wl_display * display) +{ + GstContext *context = + gst_context_new (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE, TRUE); + gst_structure_set (gst_context_writable_structure (context), + "handle", G_TYPE_POINTER, display, NULL); + return context; +} + +struct wl_display * +gst_wayland_display_handle_context_get_handle (GstContext * context) +{ + const GstStructure *s; + struct wl_display *display; + + g_return_val_if_fail (GST_IS_CONTEXT (context), NULL); + + s = gst_context_get_structure (context); + gst_structure_get (s, "handle", G_TYPE_POINTER, &display, NULL); + return display; +} + + G_DEFINE_INTERFACE (GstWaylandVideo, gst_wayland_video, GST_TYPE_VIDEO_OVERLAY); static void diff --git a/gst-libs/gst/wayland/wayland.h b/gst-libs/gst/wayland/wayland.h index 81611ccbc9..49e57a7410 100644 --- a/gst-libs/gst/wayland/wayland.h +++ b/gst-libs/gst/wayland/wayland.h @@ -30,6 +30,13 @@ G_BEGIN_DECLS * from the application to the sink */ #define GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE "GstWaylandDisplayHandleContextType" +gboolean gst_is_wayland_display_handle_need_context_message (GstMessage * msg); +GstContext * +gst_wayland_display_handle_context_new (struct wl_display * display); +struct wl_display * +gst_wayland_display_handle_context_get_handle (GstContext * context); + + #define GST_TYPE_WAYLAND_VIDEO \ (gst_wayland_video_get_type ()) #define GST_WAYLAND_VIDEO(obj) \