plugin: remove custom GstGL context handling

Instead of using our own context handling for looking for GstGL
parameters (display, context and other context), this patch changes
the logic to use the utility function offered by GstGL.

https://bugzilla.gnome.org/show_bug.cgi?id=793643
This commit is contained in:
Víctor Manuel Jáquez Leal 2018-04-26 18:15:47 +02:00
parent 86bf89d16d
commit 59579a9cb3
4 changed files with 33 additions and 49 deletions

View file

@ -1215,10 +1215,8 @@ gst_vaapi_plugin_base_create_gl_context (GstVaapiPluginBase * plugin)
GstGLContext *gl_other_context = NULL, *gl_context = NULL; GstGLContext *gl_other_context = NULL, *gl_context = NULL;
GstGLDisplay *gl_display = NULL; GstGLDisplay *gl_display = NULL;
if (!gst_gl_ensure_element_data (plugin, if (!plugin->gl_display)
(GstGLDisplay **) & plugin->gl_display, return NULL;
(GstGLContext **) & plugin->gl_other_context))
goto no_valid_gl_display;
gl_display = (GstGLDisplay *) plugin->gl_display; gl_display = (GstGLDisplay *) plugin->gl_display;
if (gst_gl_display_get_handle_type (gl_display) == GST_GL_DISPLAY_TYPE_ANY) if (gst_gl_display_get_handle_type (gl_display) == GST_GL_DISPLAY_TYPE_ANY)

View file

@ -246,9 +246,7 @@ gst_vaapi_create_display_from_gl_context (GstObject * gl_context_object)
static void static void
gst_vaapi_find_gl_context (GstElement * element) gst_vaapi_find_gl_context (GstElement * element)
{ {
GstObject *gl_context;
GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element); GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element);
GstPadDirection direction = GST_PAD_UNKNOWN;
/* if the element is vaapisink or any vaapi encoder it doesn't need /* if the element is vaapisink or any vaapi encoder it doesn't need
* to know a GstGLContext in order to create an appropriate * to know a GstGLContext in order to create an appropriate
@ -257,15 +255,32 @@ gst_vaapi_find_gl_context (GstElement * element)
if (GST_IS_VIDEO_SINK (element) || GST_IS_VIDEO_ENCODER (element)) if (GST_IS_VIDEO_SINK (element) || GST_IS_VIDEO_ENCODER (element))
return; return;
gl_context = NULL; if (!gst_gl_ensure_element_data (plugin,
if (!gst_vaapi_find_gl_local_context (element, &gl_context, &direction)) (GstGLDisplay **) & plugin->gl_display,
gl_context = gst_vaapi_plugin_base_create_gl_context (plugin); (GstGLContext **) & plugin->gl_other_context))
goto no_valid_gl_display;
if (gl_context) { gst_vaapi_find_gl_local_context (element, &plugin->gl_context);
gst_vaapi_plugin_base_set_gl_context (plugin, gl_context);
if (direction == GST_PAD_SRC) if (plugin->gl_context) {
gst_vaapi_plugin_base_set_srcpad_can_dmabuf (plugin, gl_context); gst_vaapi_plugin_base_set_srcpad_can_dmabuf (plugin, plugin->gl_context);
gst_object_unref (gl_context); } else {
GstObject *gl_context;
gl_context = gst_vaapi_plugin_base_create_gl_context (plugin);
if (gl_context) {
gst_vaapi_plugin_base_set_gl_context (plugin, gl_context);
gst_object_unref (gl_context);
}
}
/* ERRORS */
no_valid_gl_display:
{
GST_INFO_OBJECT (plugin, "No valid GL display found");
gst_object_replace (&plugin->gl_display, NULL);
gst_object_replace (&plugin->gl_other_context, NULL);
return;
} }
} }

View file

@ -321,8 +321,6 @@ gst_vaapi_video_context_propagate (GstElement * element,
* @element: the #GstElement where the search begins * @element: the #GstElement where the search begins
* @gl_context_ptr: the pointer where the GstGL context is going to be * @gl_context_ptr: the pointer where the GstGL context is going to be
* stored * stored
* @direction_ptr: the pointer of the #GstPadDirection where the GstGL
* context was found
* *
* Query the pipeline, downstream and upstream for a GstGL context * Query the pipeline, downstream and upstream for a GstGL context
* *
@ -330,42 +328,15 @@ gst_vaapi_video_context_propagate (GstElement * element,
**/ **/
gboolean gboolean
gst_vaapi_find_gl_local_context (GstElement * element, gst_vaapi_find_gl_local_context (GstElement * element,
GstObject ** gl_context_ptr, GstPadDirection * direction_ptr) GstObject ** gl_context_ptr)
{ {
#if USE_GST_GL_HELPERS #if USE_GST_GL_HELPERS
GstQuery *query; GstGLContext **context_ptr = (GstGLContext **) gl_context_ptr;
GstContext *context;
const GstStructure *s;
GstObject *gl_context;
GstPadDirection direction;
g_return_val_if_fail (gl_context_ptr, FALSE); if (gst_gl_query_local_gl_context (element, GST_PAD_SRC, context_ptr))
return TRUE;
direction = GST_PAD_UNKNOWN; if (gst_gl_query_local_gl_context (element, GST_PAD_SINK, context_ptr))
gl_context = NULL;
query = gst_query_new_context ("gst.gl.local_context");
if (_gst_context_run_query (element, query, GST_PAD_SRC)) {
gst_query_parse_context (query, &context);
if (context) {
s = gst_context_get_structure (context);
gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &gl_context, NULL);
direction = GST_PAD_SRC;
}
}
if (!gl_context && _gst_context_run_query (element, query, GST_PAD_SINK)) {
gst_query_parse_context (query, &context);
if (context) {
s = gst_context_get_structure (context);
gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &gl_context, NULL);
direction = GST_PAD_SINK;
}
}
gst_query_unref (query);
if (gl_context) {
*gl_context_ptr = gl_context;
*direction_ptr = direction;
return TRUE; return TRUE;
}
#endif #endif
return FALSE; return FALSE;
} }

View file

@ -60,6 +60,6 @@ gst_vaapi_video_context_propagate (GstElement * element,
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean
gst_vaapi_find_gl_local_context (GstElement * element, gst_vaapi_find_gl_local_context (GstElement * element,
GstObject ** gl_context_ptr, GstPadDirection * direction); GstObject ** gl_context_ptr);
#endif /* GST_VAAPI_VIDEO_CONTEXT_H */ #endif /* GST_VAAPI_VIDEO_CONTEXT_H */