mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-22 14:06:23 +00:00
plugins: add gst_vaapi_plugin_base_find_gl_context()
Using the GstContext mechanism, it is possible to find if the pipeline shares a GstGLContext, even if we are not to negotiating GLTextureUpload meta. This is interesting because we could negotiate system memory caps feature, but enable DMABuf if the GstGLContext is EGL with some extensions. https://bugzilla.gnome.org/show_bug.cgi?id=766206
This commit is contained in:
parent
fabcb4dc06
commit
604986749e
3 changed files with 66 additions and 5 deletions
|
@ -206,6 +206,17 @@ error_create_proxy:
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_vaapi_plugin_base_find_gl_context (GstVaapiPluginBase * plugin)
|
||||
{
|
||||
GstObject *gl_context;
|
||||
|
||||
if (!gst_vaapi_find_gl_local_context (GST_ELEMENT_CAST (plugin), &gl_context))
|
||||
return;
|
||||
gst_vaapi_plugin_base_set_gl_context (plugin, gl_context);
|
||||
gst_object_unref (gl_context);
|
||||
}
|
||||
|
||||
void
|
||||
gst_vaapi_plugin_base_class_init (GstVaapiPluginBaseClass * klass)
|
||||
{
|
||||
|
@ -363,6 +374,10 @@ gst_vaapi_plugin_base_ensure_display (GstVaapiPluginBase * plugin)
|
|||
return TRUE;
|
||||
gst_vaapi_display_replace (&plugin->display, NULL);
|
||||
|
||||
/* Query for a local GstGL context. If it's found, it will be used
|
||||
* to create the VA display */
|
||||
gst_vaapi_plugin_base_find_gl_context (plugin);
|
||||
|
||||
if (!gst_vaapi_ensure_display (GST_ELEMENT (plugin),
|
||||
plugin->display_type_req))
|
||||
return FALSE;
|
||||
|
@ -750,10 +765,6 @@ gst_vaapi_plugin_base_decide_allocation (GstVaapiPluginBase * plugin,
|
|||
if (!caps)
|
||||
goto error_no_caps;
|
||||
|
||||
/* We don't need any GL context beyond this point if not requested
|
||||
so explicitly through GstVideoGLTextureUploadMeta */
|
||||
gst_object_replace (&plugin->gl_context, NULL);
|
||||
|
||||
pool_options = 0;
|
||||
if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL))
|
||||
pool_options |= GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_META;
|
||||
|
@ -766,7 +777,8 @@ gst_vaapi_plugin_base_decide_allocation (GstVaapiPluginBase * plugin,
|
|||
pool_options |= GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_GL_TEXTURE_UPLOAD;
|
||||
|
||||
#if USE_GST_GL_HELPERS
|
||||
if (pool_options & GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_GL_TEXTURE_UPLOAD) {
|
||||
if (!plugin->gl_context &&
|
||||
(pool_options & GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_GL_TEXTURE_UPLOAD)) {
|
||||
const GstStructure *params;
|
||||
GstObject *gl_context;
|
||||
|
||||
|
@ -1007,6 +1019,9 @@ gst_vaapi_plugin_base_set_gl_context (GstVaapiPluginBase * plugin,
|
|||
GstGLContext *const gl_context = GST_GL_CONTEXT (object);
|
||||
GstVaapiDisplayType display_type;
|
||||
|
||||
if (plugin->gl_context == object)
|
||||
return;
|
||||
|
||||
gst_object_replace (&plugin->gl_context, object);
|
||||
|
||||
switch (gst_gl_context_get_gl_platform (gl_context)) {
|
||||
|
@ -1024,6 +1039,7 @@ gst_vaapi_plugin_base_set_gl_context (GstVaapiPluginBase * plugin,
|
|||
display_type = plugin->display_type;
|
||||
break;
|
||||
}
|
||||
GST_INFO_OBJECT (plugin, "GL context: %" GST_PTR_FORMAT, plugin->gl_context);
|
||||
gst_vaapi_plugin_base_set_display_type (plugin, display_type);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
|
||||
#include "gstcompat.h"
|
||||
#include "gstvaapivideocontext.h"
|
||||
#if USE_GST_GL_HELPERS
|
||||
# include <gst/gl/gl.h>
|
||||
#endif
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
|
||||
|
||||
|
@ -233,3 +236,40 @@ gst_vaapi_video_context_propagate (GstElement * element,
|
|||
msg = gst_message_new_have_context (GST_OBJECT_CAST (element), context);
|
||||
gst_element_post_message (GST_ELEMENT_CAST (element), msg);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_vaapi_find_gl_local_context (GstElement * element,
|
||||
GstObject ** gl_context_ptr)
|
||||
{
|
||||
#if USE_GST_GL_HELPERS
|
||||
GstQuery *query;
|
||||
GstContext *context;
|
||||
const GstStructure *s;
|
||||
GstObject *gl_context;
|
||||
|
||||
g_return_val_if_fail (gl_context_ptr, FALSE);
|
||||
|
||||
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_GL_TYPE_CONTEXT, &gl_context, NULL);
|
||||
}
|
||||
}
|
||||
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_GL_TYPE_CONTEXT, &gl_context, NULL);
|
||||
}
|
||||
}
|
||||
gst_query_unref (query);
|
||||
if (gl_context) {
|
||||
*gl_context_ptr = gl_context;
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -56,4 +56,9 @@ void
|
|||
gst_vaapi_video_context_propagate (GstElement * element,
|
||||
GstVaapiDisplay * display);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gboolean
|
||||
gst_vaapi_find_gl_local_context (GstElement * element,
|
||||
GstObject ** gl_context_ptr);
|
||||
|
||||
#endif /* GST_VAAPI_VIDEO_CONTEXT_H */
|
||||
|
|
Loading…
Reference in a new issue