From 2753b4243edcfb060704cfad4190d95123c4bacb Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Wed, 4 May 2016 01:16:51 +1000 Subject: [PATCH] glmemory: add wrapped data pointers to setup_buffer Allows creating wrapped memories with GstGLAllocationParams. The wrapped pointers will be set in the parameters before being passed to the memory allocation function. --- gst-libs/gst/gl/gstglbufferpool.c | 2 +- gst-libs/gst/gl/gstglmemory.c | 19 +++++++++++++------ gst-libs/gst/gl/gstglmemory.h | 5 +++-- gst-libs/gst/gl/gstglupload.c | 20 +++++++++++--------- gst-libs/gst/gl/gstglviewconvert.c | 2 +- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/gst-libs/gst/gl/gstglbufferpool.c b/gst-libs/gst/gl/gstglbufferpool.c index 90536b0372..5a2a820293 100644 --- a/gst-libs/gst/gl/gstglbufferpool.c +++ b/gst-libs/gst/gl/gstglbufferpool.c @@ -291,7 +291,7 @@ gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer, #endif alloc = GST_GL_MEMORY_ALLOCATOR (priv->allocator); - if (!gst_gl_memory_setup_buffer (alloc, buf, priv->gl_params)) + if (!gst_gl_memory_setup_buffer (alloc, buf, priv->gl_params, NULL, 0)) goto mem_create_failed; if (priv->add_glsyncmeta) diff --git a/gst-libs/gst/gl/gstglmemory.c b/gst-libs/gst/gl/gstglmemory.c index 8228ae5898..20e1a64fc0 100644 --- a/gst-libs/gst/gl/gstglmemory.c +++ b/gst-libs/gst/gl/gstglmemory.c @@ -1320,18 +1320,14 @@ gst_gl_video_allocation_params_copy_data (GstGLVideoAllocationParams * src_vid, */ gboolean gst_gl_memory_setup_buffer (GstGLMemoryAllocator * allocator, - GstBuffer * buffer, GstGLVideoAllocationParams * params) + GstBuffer * buffer, GstGLVideoAllocationParams * params, + gpointer * wrapped_data, gsize n_wrapped_pointers) { GstGLBaseMemoryAllocator *base_allocator; guint n_mem, i, v, views; guint alloc_flags = params->parent.alloc_flags; g_return_val_if_fail (params != NULL, FALSE); - g_return_val_if_fail ((alloc_flags & - GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM) - == 0, FALSE); - g_return_val_if_fail ((params->parent.alloc_flags & - GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE) == 0, FALSE); g_return_val_if_fail (alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO, FALSE); @@ -1344,11 +1340,22 @@ gst_gl_memory_setup_buffer (GstGLMemoryAllocator * allocator, else views = 1; + g_return_val_if_fail (!wrapped_data + || views * n_mem != n_wrapped_pointers, FALSE); + for (v = 0; v < views; v++) { for (i = 0; i < n_mem; i++) { GstGLMemory *gl_mem; params->plane = i; + if (alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM) { + g_return_val_if_fail (wrapped_data != NULL, FALSE); + params->parent.wrapped_data = wrapped_data[i]; + } else if (alloc_flags & + GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE) { + g_return_val_if_fail (wrapped_data != NULL, FALSE); + params->parent.gl_handle = wrapped_data[i]; + } if (!(gl_mem = (GstGLMemory *) gst_gl_base_memory_alloc (base_allocator, (GstGLAllocationParams *) params))) diff --git a/gst-libs/gst/gl/gstglmemory.h b/gst-libs/gst/gl/gstglmemory.h index 9a40d48f92..c180c8342c 100644 --- a/gst-libs/gst/gl/gstglmemory.h +++ b/gst-libs/gst/gl/gstglmemory.h @@ -226,8 +226,9 @@ guint gst_gl_memory_get_texture_id (GstGLMemory * gl_me gboolean gst_gl_memory_setup_buffer (GstGLMemoryAllocator * allocator, GstBuffer * buffer, - GstGLVideoAllocationParams * params); - + GstGLVideoAllocationParams * params, + gpointer *wrapped_data, + gsize n_wrapped_pointers); GstGLMemoryAllocator * gst_gl_memory_allocator_get_default (GstGLContext *context); diff --git a/gst-libs/gst/gl/gstglupload.c b/gst-libs/gst/gl/gstglupload.c index 0f11e0415b..a1c558bb87 100644 --- a/gst-libs/gst/gl/gstglupload.c +++ b/gst-libs/gst/gl/gstglupload.c @@ -315,8 +315,8 @@ _gl_memory_upload_propose_allocation (gpointer impl, GstQuery * decide_query, gst_allocation_params_init (¶ms); allocator = - GST_ALLOCATOR (gst_gl_memory_allocator_get_default (upload-> - upload->context)); + GST_ALLOCATOR (gst_gl_memory_allocator_get_default (upload->upload-> + context)); gst_query_add_allocation_param (query, allocator, ¶ms); gst_object_unref (allocator); } @@ -585,7 +585,8 @@ _egl_image_upload_perform_gl_thread (GstGLContext * context, *image->outbuf = gst_buffer_new (); gst_buffer_add_parent_buffer_meta (*image->outbuf, image->buffer); - gst_gl_memory_setup_buffer (allocator, *image->outbuf, image->params); + gst_gl_memory_setup_buffer (allocator, *image->outbuf, image->params, NULL, + 0); gst_object_unref (allocator); n = gst_buffer_n_memory (image->buffer); @@ -856,7 +857,8 @@ _dma_buf_upload_perform_gl_thread (GstGLContext * context, /* FIXME: buffer pool */ dmabuf->outbuf = gst_buffer_new (); - gst_gl_memory_setup_buffer (allocator, dmabuf->outbuf, dmabuf->params); + gst_gl_memory_setup_buffer (allocator, dmabuf->outbuf, dmabuf->params, NULL, + 0); gst_object_unref (allocator); n = gst_buffer_n_memory (dmabuf->outbuf); @@ -1042,11 +1044,11 @@ _upload_meta_upload_propose_allocation (gpointer impl, GstQuery * decide_query, gpointer handle; gl_apis = - gst_gl_api_to_string (gst_gl_context_get_gl_api (upload->upload-> - context)); - platform = - gst_gl_platform_to_string (gst_gl_context_get_gl_platform (upload-> + gst_gl_api_to_string (gst_gl_context_get_gl_api (upload-> upload->context)); + platform = + gst_gl_platform_to_string (gst_gl_context_get_gl_platform + (upload->upload->context)); handle = (gpointer) gst_gl_context_get_gl_context (upload->upload->context); gl_context = @@ -1101,7 +1103,7 @@ _upload_meta_upload_perform (gpointer impl, GstBuffer * buffer, /* FIXME: buffer pool */ *outbuf = gst_buffer_new (); - gst_gl_memory_setup_buffer (allocator, *outbuf, upload->params); + gst_gl_memory_setup_buffer (allocator, *outbuf, upload->params, NULL, 0); gst_object_unref (allocator); for (i = 0; i < GST_GL_UPLOAD_MAX_PLANES; i++) { diff --git a/gst-libs/gst/gl/gstglviewconvert.c b/gst-libs/gst/gl/gstglviewconvert.c index be940aab60..3b983ad9d9 100644 --- a/gst-libs/gst/gl/gstglviewconvert.c +++ b/gst-libs/gst/gl/gstglviewconvert.c @@ -1955,7 +1955,7 @@ _gen_buffer (GstGLViewConvert * viewconvert, GstBuffer ** target) params = gst_gl_video_allocation_params_new (viewconvert->context, NULL, &viewconvert->out_info, 0, NULL, viewconvert->to_texture_target); - if (!gst_gl_memory_setup_buffer (mem_allocator, *target, params)) { + if (!gst_gl_memory_setup_buffer (mem_allocator, *target, params, NULL, 0)) { gst_gl_allocation_params_free ((GstGLAllocationParams *) params); gst_object_unref (allocator); return FALSE;