From b8063133961334e3c9b8b89caaaa3789723ab7a7 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Fri, 23 May 2014 13:09:27 +0300 Subject: [PATCH] wayland: add public API for creating & using the display handle GstContext --- ext/wayland/gstwaylandsink.c | 10 ++++------ gst-libs/gst/wayland/wayland.c | 39 +++++++++++++++++++++++++++++++++++++++ gst-libs/gst/wayland/wayland.h | 7 +++++++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c index 63f348d..1a37d6d 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 9ede5b8..81c673f 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 81611cc..49e57a7 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) \ -- 2.7.4