From a3bd3d676d4048985be88d6fc150632dc45f8466 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 9 Sep 2024 16:27:43 -0400 Subject: [PATCH] wayland: Fix ABI break in WL context type name While transforming the internals of waylandsink into a library, the context type name was accidentally changed, causing an ABI break. Change it back to its original (as used by the libgstgl), and add support for the misnamed version as a backward compatibility measure. Part-of: --- .../ext/wayland/gstwaylandsink.c | 65 ++++++++++++++----- .../gst-libs/gst/wayland/gstwlcontext.c | 4 +- .../gst-libs/gst/wayland/gstwlcontext.h | 5 +- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/wayland/gstwaylandsink.c b/subprojects/gst-plugins-bad/ext/wayland/gstwaylandsink.c index 1bf537c9f3..a6613a103f 100644 --- a/subprojects/gst-plugins-bad/ext/wayland/gstwaylandsink.c +++ b/subprojects/gst-plugins-bad/ext/wayland/gstwaylandsink.c @@ -365,35 +365,62 @@ gst_wayland_sink_set_display_from_context (GstWaylandSink * self, } static gboolean -gst_wayland_sink_find_display (GstWaylandSink * self) +gst_wayland_sink_query_context (GstWaylandSink * self, const gchar * type) { GstQuery *query; + gboolean ret; + + query = gst_query_new_context (type); + ret = gst_pad_peer_query (GST_VIDEO_SINK_PAD (self), query); + + if (ret) { + GstContext *context = NULL; + gst_query_parse_context (query, &context); + gst_wayland_sink_set_display_from_context (self, context); + } + + gst_query_unref (query); + return ret; +} + +static gboolean +gst_wayland_sink_post_need_context (GstWaylandSink * self, const gchar * type) +{ GstMessage *msg; - GstContext *context = NULL; + + /* now ask the application to set the display handle */ + msg = gst_message_new_need_context (GST_OBJECT_CAST (self), type); + + g_mutex_unlock (&self->display_lock); + gst_element_post_message (GST_ELEMENT_CAST (self), msg); + /* at this point we expect gst_wayland_sink_set_context + * to get called and fill self->display */ + g_mutex_lock (&self->display_lock); + + return self->display != NULL; +} + +static gboolean +gst_wayland_sink_find_display (GstWaylandSink * self) +{ GError *error = NULL; gboolean ret = TRUE; g_mutex_lock (&self->display_lock); if (!self->display) { - /* first query upstream for the needed display handle */ - query = gst_query_new_context (GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE); - if (gst_pad_peer_query (GST_VIDEO_SINK_PAD (self), query)) { - gst_query_parse_context (query, &context); - gst_wayland_sink_set_display_from_context (self, context); + if (!gst_wayland_sink_query_context (self, + GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE)) { + gst_wayland_sink_query_context (self, + GST_WL_DISPLAY_HANDLE_LEGACY_CONTEXT_TYPE); } - gst_query_unref (query); if (G_LIKELY (!self->display)) { - /* now ask the application to set the display handle */ - msg = gst_message_new_need_context (GST_OBJECT_CAST (self), - GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE); - - g_mutex_unlock (&self->display_lock); - gst_element_post_message (GST_ELEMENT_CAST (self), msg); - /* at this point we expect gst_wayland_sink_set_context - * to get called and fill self->display */ - g_mutex_lock (&self->display_lock); + if (!gst_wayland_sink_post_need_context (self, + GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE)) { + gst_wayland_sink_post_need_context (self, + GST_WL_DISPLAY_HANDLE_LEGACY_CONTEXT_TYPE); + } if (!self->display) { /* if the application didn't set a display, let's create it ourselves */ @@ -480,7 +507,9 @@ gst_wayland_sink_set_context (GstElement * element, GstContext * context) GstWaylandSink *self = GST_WAYLAND_SINK (element); if (gst_context_has_context_type (context, - GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE)) { + GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE) || + gst_context_has_context_type (context, + GST_WL_DISPLAY_HANDLE_LEGACY_CONTEXT_TYPE)) { g_mutex_lock (&self->display_lock); if (G_LIKELY (!self->display)) { gst_wayland_sink_set_display_from_context (self, context); diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlcontext.c b/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlcontext.c index 43fd1df6be..e0f0496bf3 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlcontext.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlcontext.c @@ -33,7 +33,8 @@ gst_is_wl_display_handle_need_context_message (GstMessage * msg) if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_NEED_CONTEXT && gst_message_parse_context_type (msg, &type)) { - return !g_strcmp0 (type, GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE); + return !g_strcmp0 (type, GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE) || + !g_strcmp0 (type, GST_WL_DISPLAY_HANDLE_LEGACY_CONTEXT_TYPE); } return FALSE; @@ -60,6 +61,7 @@ gst_wl_display_handle_context_get_handle (GstContext * context) s = gst_context_get_structure (context); if (gst_structure_get (s, "display", G_TYPE_POINTER, &display, NULL)) return display; + /* backward compatibility */ if (gst_structure_get (s, "handle", G_TYPE_POINTER, &display, NULL)) return display; return NULL; diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlcontext.h b/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlcontext.h index a7b703394f..e7b802b952 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlcontext.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlcontext.h @@ -26,7 +26,10 @@ G_BEGIN_DECLS /* The type of GstContext used to pass the wl_display pointer * from the application to the sink */ -#define GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE "GstWlDisplayHandleContextType" +#define GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE "GstWaylandDisplayHandleContextType" + +/* Accidental naming, used for implementing backward compatibility */ +#define GST_WL_DISPLAY_HANDLE_LEGACY_CONTEXT_TYPE "GstWlDisplayHandleContextType" GST_WL_API gboolean gst_is_wl_display_handle_need_context_message (GstMessage * msg);