mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 01:30:38 +00:00
glutils: use gst_element_set_context for setting display/other_context
1. So we get tracking inside GstElement properly when e.g. adding to a bin 2. Removes redundant code. Now only one place where GstContext->GstGLDisplay/GstGLContext transformation occurs 3. Fixes a memory leak in the process 4. Make the retrieval of debug categories thread safe
This commit is contained in:
parent
977c335460
commit
0580536fa1
1 changed files with 31 additions and 83 deletions
|
@ -453,6 +453,19 @@ gst_gl_display_found (GstElement * element, GstGLDisplay * display)
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
|
||||||
|
|
||||||
|
static void
|
||||||
|
_init_context_debug (void)
|
||||||
|
{
|
||||||
|
#ifndef GST_DISABLE_GST_DEBUG
|
||||||
|
static volatile gsize _init = 0;
|
||||||
|
|
||||||
|
if (g_once_init_enter (&_init)) {
|
||||||
|
GST_DEBUG_CATEGORY_GET (GST_CAT_CONTEXT, "GST_CONTEXT");
|
||||||
|
g_once_init_leave (&_init, 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
pad_query (const GValue * item, GValue * value, gpointer user_data)
|
pad_query (const GValue * item, GValue * value, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
@ -460,6 +473,8 @@ pad_query (const GValue * item, GValue * value, gpointer user_data)
|
||||||
GstQuery *query = user_data;
|
GstQuery *query = user_data;
|
||||||
gboolean res;
|
gboolean res;
|
||||||
|
|
||||||
|
_init_context_debug ();
|
||||||
|
|
||||||
res = gst_pad_peer_query (pad, query);
|
res = gst_pad_peer_query (pad, query);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -496,13 +511,14 @@ gst_gl_run_query (GstElement * element, GstQuery * query,
|
||||||
return g_value_get_boolean (&res);
|
return g_value_get_boolean (&res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstQuery *
|
static void
|
||||||
_gst_context_query (GstElement * element,
|
_gst_context_query (GstElement * element, const gchar * display_type)
|
||||||
gpointer ptr, const gchar * display_type)
|
|
||||||
{
|
{
|
||||||
GstQuery *query;
|
GstQuery *query;
|
||||||
GstContext *ctxt;
|
GstContext *ctxt;
|
||||||
|
|
||||||
|
_init_context_debug ();
|
||||||
|
|
||||||
/* 2a) Query downstream with GST_QUERY_CONTEXT for the context and
|
/* 2a) Query downstream with GST_QUERY_CONTEXT for the context and
|
||||||
* check if downstream already has a context of the specific type
|
* check if downstream already has a context of the specific type
|
||||||
* 2b) Query upstream as above.
|
* 2b) Query upstream as above.
|
||||||
|
@ -540,103 +556,33 @@ _gst_context_query (GstElement * element,
|
||||||
* is required to update the display_ptr or call gst_gl_handle_set_context().
|
* is required to update the display_ptr or call gst_gl_handle_set_context().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return query;
|
gst_query_unref (query);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_display_context_query (GstElement * element, GstGLDisplay ** display_ptr)
|
gst_gl_display_context_query (GstElement * element, GstGLDisplay ** display_ptr)
|
||||||
{
|
{
|
||||||
GstContext *ctxt = NULL;
|
_gst_context_query (element, GST_GL_DISPLAY_CONTEXT_TYPE);
|
||||||
GstQuery *query = NULL;
|
|
||||||
|
|
||||||
#ifndef GST_DISABLE_GST_DEBUG
|
|
||||||
if (!GST_CAT_CONTEXT)
|
|
||||||
GST_DEBUG_CATEGORY_GET (GST_CAT_CONTEXT, "GST_CONTEXT");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
query =
|
|
||||||
_gst_context_query (element, display_ptr, GST_GL_DISPLAY_CONTEXT_TYPE);
|
|
||||||
gst_query_parse_context (query, &ctxt);
|
|
||||||
|
|
||||||
if (ctxt && gst_context_has_context_type (ctxt, GST_GL_DISPLAY_CONTEXT_TYPE)) {
|
|
||||||
GstGLDisplay *tmp_disp = NULL;
|
|
||||||
if (gst_context_get_gl_display (ctxt, &tmp_disp) && tmp_disp)
|
|
||||||
*display_ptr = tmp_disp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*display_ptr)
|
if (*display_ptr)
|
||||||
goto out;
|
return;
|
||||||
|
|
||||||
#if GST_GL_HAVE_WINDOW_X11
|
#if GST_GL_HAVE_WINDOW_X11
|
||||||
gst_query_unref (query);
|
_gst_context_query (element, "gst.x11.display.handle");
|
||||||
query = _gst_context_query (element, display_ptr, "gst.x11.display.handle");
|
|
||||||
gst_query_parse_context (query, &ctxt);
|
|
||||||
if (ctxt && gst_context_has_context_type (ctxt, "gst.x11.display.handle")) {
|
|
||||||
const GstStructure *s;
|
|
||||||
Display *display;
|
|
||||||
|
|
||||||
s = gst_context_get_structure (ctxt);
|
|
||||||
if (gst_structure_get (s, "display", G_TYPE_POINTER, &display, NULL)
|
|
||||||
&& display) {
|
|
||||||
*display_ptr =
|
|
||||||
(GstGLDisplay *) gst_gl_display_x11_new_with_display (display);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*display_ptr)
|
if (*display_ptr)
|
||||||
goto out;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GST_GL_HAVE_WINDOW_WAYLAND
|
#if GST_GL_HAVE_WINDOW_WAYLAND
|
||||||
gst_query_unref (query);
|
_gst_context_query (element, "GstWaylandDisplayHandleContextType");
|
||||||
query =
|
|
||||||
_gst_context_query (element, display_ptr,
|
|
||||||
"GstWaylandDisplayHandleContextType");
|
|
||||||
gst_query_parse_context (query, &ctxt);
|
|
||||||
if (ctxt
|
|
||||||
&& gst_context_has_context_type (ctxt,
|
|
||||||
"GstWaylandDisplayHandleContextType")) {
|
|
||||||
const GstStructure *s;
|
|
||||||
struct wl_display *display;
|
|
||||||
|
|
||||||
s = gst_context_get_structure (ctxt);
|
|
||||||
if (gst_structure_get (s, "display", G_TYPE_POINTER, &display, NULL)
|
|
||||||
&& display) {
|
|
||||||
*display_ptr =
|
|
||||||
(GstGLDisplay *) gst_gl_display_wayland_new_with_display (display);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*display_ptr)
|
if (*display_ptr)
|
||||||
goto out;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
out:
|
|
||||||
gst_query_unref (query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_context_query (GstElement * element, GstGLContext ** context_ptr)
|
gst_gl_context_query (GstElement * element)
|
||||||
{
|
{
|
||||||
GstContext *ctxt;
|
_gst_context_query (element, "gst.gl.app_context");
|
||||||
GstQuery *query;
|
|
||||||
|
|
||||||
#ifndef GST_DISABLE_GST_DEBUG
|
|
||||||
if (!GST_CAT_CONTEXT)
|
|
||||||
GST_DEBUG_CATEGORY_GET (GST_CAT_CONTEXT, "GST_CONTEXT");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
query = _gst_context_query (element, context_ptr, "gst.gl.app_context");
|
|
||||||
gst_query_parse_context (query, &ctxt);
|
|
||||||
if (ctxt && gst_context_has_context_type (ctxt, "gst.gl.app_context")) {
|
|
||||||
const GstStructure *s = gst_context_get_structure (ctxt);
|
|
||||||
GstGLContext *tmp_ctx = NULL;
|
|
||||||
if (gst_structure_get (s, "context", GST_GL_TYPE_CONTEXT, &tmp_ctx, NULL)
|
|
||||||
&& tmp_ctx)
|
|
||||||
*context_ptr = tmp_ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_query_unref (query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 4) Create a context by itself and post a GST_MESSAGE_HAVE_CONTEXT
|
/* 4) Create a context by itself and post a GST_MESSAGE_HAVE_CONTEXT
|
||||||
|
@ -653,6 +599,8 @@ gst_gl_display_context_propagate (GstElement * element, GstGLDisplay * display)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_init_context_debug ();
|
||||||
|
|
||||||
context = gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
|
context = gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
|
||||||
gst_context_set_gl_display (context, display);
|
gst_context_set_gl_display (context, display);
|
||||||
|
|
||||||
|
@ -698,7 +646,7 @@ get_gl_context:
|
||||||
if (*context_ptr)
|
if (*context_ptr)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
gst_gl_context_query (element, context_ptr);
|
gst_gl_context_query (element);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
return *display_ptr != NULL;
|
return *display_ptr != NULL;
|
||||||
|
|
Loading…
Reference in a new issue