gst-libs/gst/wayland: handle display passing better

failure to pass a display in 'handle' would result in uninitialized value
being returned, which would often segfault later down the road when trying
to initialize gstreamer context with it.
Check the return value of gst_structure_get() to make sure we return valid
data.

Furthermore, the gstglimagesink in gst-plugins-base also has a similar
mechanism but uses 'display' as field name to pass the value; instead of
requiring the application to behave differently depending on what sink
was automatically detected just try to read both values here, with display
being the new default.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2292>
This commit is contained in:
Dominique Martinet 2021-06-01 08:40:17 +09:00 committed by GStreamer Marge Bot
parent be7e0600ec
commit ff6442f6f9

View file

@ -46,7 +46,7 @@ gst_wayland_display_handle_context_new (struct wl_display * display)
GstContext *context = GstContext *context =
gst_context_new (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE, TRUE); gst_context_new (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE, TRUE);
gst_structure_set (gst_context_writable_structure (context), gst_structure_set (gst_context_writable_structure (context),
"handle", G_TYPE_POINTER, display, NULL); "display", G_TYPE_POINTER, display, NULL);
return context; return context;
} }
@ -59,8 +59,11 @@ gst_wayland_display_handle_context_get_handle (GstContext * context)
g_return_val_if_fail (GST_IS_CONTEXT (context), NULL); g_return_val_if_fail (GST_IS_CONTEXT (context), NULL);
s = gst_context_get_structure (context); s = gst_context_get_structure (context);
gst_structure_get (s, "handle", G_TYPE_POINTER, &display, NULL); if (gst_structure_get (s, "display", G_TYPE_POINTER, &display, NULL))
return display; return display;
if (gst_structure_get (s, "handle", G_TYPE_POINTER, &display, NULL))
return display;
return NULL;
} }