From d84d1708b72aba35b821fbafefc7fdfdbbc5572c Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 1 Dec 2015 18:09:25 -0500 Subject: [PATCH] glupload: Only offer custom allocator with caps features To use GLMemory and EGLImage allocators, one need to know the libgstgl API. This is only expected if the associated caps features have been negotiated. Generic element that otherwise receive those allocators may fail, resulting in broken pieline. We don't want to force all generic element to check if the allocator is a custom allocator or a normal allocator (which implement the _alloc method). https://bugzilla.gnome.org/show_bug.cgi?id=758877 --- gst-libs/gst/gl/gstglupload.c | 39 ++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/gst-libs/gst/gl/gstglupload.c b/gst-libs/gst/gl/gstglupload.c index 411d02afd3..ed5c09178f 100644 --- a/gst-libs/gst/gl/gstglupload.c +++ b/gst-libs/gst/gl/gstglupload.c @@ -209,16 +209,24 @@ _gl_memory_upload_propose_allocation (gpointer impl, GstQuery * decide_query, GstQuery * query) { struct GLMemoryUpload *upload = impl; - GstAllocationParams params; - GstAllocator *allocator; GstBufferPool *pool = NULL; guint n_pools, i; + GstCaps *caps; + GstCapsFeatures *features; - gst_allocation_params_init (¶ms); + gst_query_parse_allocation (query, &caps, NULL); + features = gst_caps_get_features (caps, 0); - allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR); - gst_query_add_allocation_param (query, allocator, ¶ms); - gst_object_unref (allocator); + /* Only offer our custom allocator if that type of memory was negotiated. */ + if (gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY)) { + GstAllocator *allocator; + GstAllocationParams params; + gst_allocation_params_init (¶ms); + + allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR); + gst_query_add_allocation_param (query, allocator, ¶ms); + gst_object_unref (allocator); + } n_pools = gst_query_get_n_allocation_pools (query); for (i = 0; i < n_pools; i++) { @@ -232,10 +240,8 @@ _gl_memory_upload_propose_allocation (gpointer impl, GstQuery * decide_query, if (!pool) { GstStructure *config; GstVideoInfo info; - GstCaps *caps; gsize size; - gst_query_parse_allocation (query, &caps, NULL); if (!gst_video_info_from_caps (&info, caps)) goto invalid_caps; @@ -424,13 +430,22 @@ _egl_image_upload_propose_allocation (gpointer impl, GstQuery * decide_query, GstQuery * query) { struct EGLImageUpload *image = impl; - GstAllocationParams params; - GstAllocator *allocator; + GstCaps *caps; + GstCapsFeatures *features; - gst_allocation_params_init (¶ms); + gst_query_parse_allocation (query, &caps, NULL); + features = gst_caps_get_features (caps, 0); - if (gst_gl_context_check_feature (image->upload->context, + /* Only offer our custom allocator if that type of memory was negotiated. */ + if (gst_caps_features_contains (features, + GST_CAPS_FEATURE_MEMORY_EGL_IMAGE) && + gst_gl_context_check_feature (image->upload->context, "EGL_KHR_image_base")) { + GstAllocationParams params; + GstAllocator *allocator; + + gst_allocation_params_init (¶ms); + allocator = gst_allocator_find (GST_EGL_IMAGE_MEMORY_TYPE); gst_query_add_allocation_param (query, allocator, ¶ms); gst_object_unref (allocator);