From c9d9077a5fa306a07a75fcf7ed033e56c1ab9231 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Wed, 4 May 2016 00:19:44 +1000 Subject: [PATCH] glbasememory: take a pointer as the wrapped gpu handle Allows passing arbitrary data to wrap the the specific memory implementation which is required for some memory implementations. --- docs/libs/gst-plugins-bad-libs-sections.txt | 1 + gst-libs/gst/gl/gstglbasememory.c | 2 +- gst-libs/gst/gl/gstglbasememory.h | 4 +- gst-libs/gst/gl/gstglmemory.c | 67 +++++++++++++++------ gst-libs/gst/gl/gstglmemory.h | 12 +++- gst-libs/gst/gl/gstglmemorypbo.c | 2 +- 6 files changed, 65 insertions(+), 23 deletions(-) diff --git a/docs/libs/gst-plugins-bad-libs-sections.txt b/docs/libs/gst-plugins-bad-libs-sections.txt index 5014d893f5..a0d2de4b95 100644 --- a/docs/libs/gst-plugins-bad-libs-sections.txt +++ b/docs/libs/gst-plugins-bad-libs-sections.txt @@ -1184,6 +1184,7 @@ gst_gl_video_allocation_params_free_data gst_gl_video_allocation_params_init_full gst_gl_video_allocation_params_new gst_gl_video_allocation_params_new_wrapped_data +gst_gl_video_allocation_params_new_wrapped_gl_handle gst_gl_video_allocation_params_new_wrapped_texture GstGLMemoryAllocator GstGLMemoryAllocatorClass diff --git a/gst-libs/gst/gl/gstglbasememory.c b/gst-libs/gst/gl/gstglbasememory.c index 7fc1d00501..915e19e3b5 100644 --- a/gst-libs/gst/gl/gstglbasememory.c +++ b/gst-libs/gst/gl/gstglbasememory.c @@ -606,7 +606,7 @@ gst_gl_allocation_params_init (GstGLAllocationParams * params, gsize struct_size, guint alloc_flags, GstGLAllocationParamsCopyFunc copy, GstGLAllocationParamsFreeFunc free, GstGLContext * context, gsize alloc_size, GstAllocationParams * alloc_params, - gpointer wrapped_data, guint gl_handle, gpointer user_data, + gpointer wrapped_data, gpointer gl_handle, gpointer user_data, GDestroyNotify notify) { memset (params, 0, sizeof (*params)); diff --git a/gst-libs/gst/gl/gstglbasememory.h b/gst-libs/gst/gl/gstglbasememory.h index f862c85c52..642684a542 100644 --- a/gst-libs/gst/gl/gstglbasememory.h +++ b/gst-libs/gst/gl/gstglbasememory.h @@ -173,7 +173,7 @@ struct _GstGLAllocationParams /* GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM only */ gpointer wrapped_data; /* GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE only */ - guint gl_handle; + gpointer gl_handle; }; gboolean gst_gl_allocation_params_init (GstGLAllocationParams * params, @@ -185,7 +185,7 @@ gboolean gst_gl_allocation_params_init (GstGLAllocationPara gsize alloc_size, GstAllocationParams * alloc_params, gpointer wrapped_data, - guint gl_handle, + gpointer gl_handle, gpointer user_data, GDestroyNotify notify); diff --git a/gst-libs/gst/gl/gstglmemory.c b/gst-libs/gst/gl/gstglmemory.c index f75a842a4e..8228ae5898 100644 --- a/gst-libs/gst/gl/gstglmemory.c +++ b/gst-libs/gst/gl/gstglmemory.c @@ -821,7 +821,7 @@ _default_gl_tex_alloc (GstGLMemoryAllocator * allocator, mem = g_new0 (GstGLMemory, 1); if (alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE) { - mem->tex_id = params->parent.gl_handle; + mem->tex_id = GPOINTER_TO_UINT (params->parent.gl_handle); mem->texture_wrapped = TRUE; } @@ -1080,7 +1080,7 @@ gst_gl_video_allocation_params_init_full (GstGLVideoAllocationParams * params, GstGLAllocationParamsFreeFunc free, GstGLContext * context, GstAllocationParams * alloc_params, GstVideoInfo * v_info, guint plane, GstVideoAlignment * valign, GstGLTextureTarget target, - gpointer wrapped_data, guint gl_handle, gpointer user_data, + gpointer wrapped_data, gpointer gl_handle, gpointer user_data, GDestroyNotify notify) { guint i; @@ -1187,6 +1187,50 @@ gst_gl_video_allocation_params_new_wrapped_data (GstGLContext * context, return params; } +/** + * gst_gl_video_allocation_params_new_wrapped_gl_handle: + * @context: a #GstGLContext + * @alloc_params: (allow-none): the #GstAllocationParams for @tex_id + * @v_info: the #GstVideoInfo for @tex_id + * @plane: the video plane @tex_id represents + * @valign: (allow-none): any #GstVideoAlignment applied to symem mappings of @tex_id + * @target: the #GstGLTextureTarget for @tex_id + * @gl_handle: the GL handle to wrap + * @user_data: (allow-none): user data to call @notify with + * @notify: (allow-none): a #GDestroyNotify + * + * @gl_handle is defined by the specific OpenGL handle being wrapped + * For #GstGLMemory and #GstGLMemoryPBO it is an OpenGL texture id. + * Other memory types may define it to require a different type of parameter. + * + * Returns: a new #GstGLVideoAllocationParams for wrapping @gl_handle + * + * Since: 1.8 + */ +GstGLVideoAllocationParams * +gst_gl_video_allocation_params_new_wrapped_gl_handle (GstGLContext * context, + GstAllocationParams * alloc_params, GstVideoInfo * v_info, guint plane, + GstVideoAlignment * valign, GstGLTextureTarget target, + gpointer gl_handle, gpointer user_data, GDestroyNotify notify) +{ + GstGLVideoAllocationParams *params = g_new0 (GstGLVideoAllocationParams, 1); + + if (!gst_gl_video_allocation_params_init_full (params, + sizeof (GstGLVideoAllocationParams), + GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE | + GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO, + (GstGLAllocationParamsCopyFunc) + gst_gl_video_allocation_params_copy_data, + (GstGLAllocationParamsFreeFunc) + gst_gl_video_allocation_params_free_data, context, alloc_params, + v_info, plane, valign, target, NULL, gl_handle, user_data, notify)) { + g_free (params); + return NULL; + } + + return params; +} + /** * gst_gl_video_allocation_params_new_wrapped_texture: * @context: a #GstGLContext @@ -1209,22 +1253,9 @@ gst_gl_video_allocation_params_new_wrapped_texture (GstGLContext * context, GstVideoAlignment * valign, GstGLTextureTarget target, guint tex_id, gpointer user_data, GDestroyNotify notify) { - GstGLVideoAllocationParams *params = g_new0 (GstGLVideoAllocationParams, 1); - - if (!gst_gl_video_allocation_params_init_full (params, - sizeof (GstGLVideoAllocationParams), - GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE | - GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO, - (GstGLAllocationParamsCopyFunc) - gst_gl_video_allocation_params_copy_data, - (GstGLAllocationParamsFreeFunc) - gst_gl_video_allocation_params_free_data, context, alloc_params, - v_info, plane, valign, target, NULL, tex_id, user_data, notify)) { - g_free (params); - return NULL; - } - - return params; + return gst_gl_video_allocation_params_new_wrapped_gl_handle (context, + alloc_params, v_info, plane, valign, target, GUINT_TO_POINTER (tex_id), + user_data, notify); } /** diff --git a/gst-libs/gst/gl/gstglmemory.h b/gst-libs/gst/gl/gstglmemory.h index b032a5ce7a..9a40d48f92 100644 --- a/gst-libs/gst/gl/gstglmemory.h +++ b/gst-libs/gst/gl/gstglmemory.h @@ -106,7 +106,7 @@ gboolean gst_gl_video_allocation_params_init_full (GstGLVideoAlloc GstVideoAlignment * valign, GstGLTextureTarget target, gpointer wrapped_data, - guint gl_handle, + gpointer gl_handle, gpointer user_data, GDestroyNotify notify); GstGLVideoAllocationParams * gst_gl_video_allocation_params_new (GstGLContext * context, @@ -135,6 +135,16 @@ GstGLVideoAllocationParams * gst_gl_video_allocation_params_new_wrapped_texture gpointer user_data, GDestroyNotify notify); +GstGLVideoAllocationParams * gst_gl_video_allocation_params_new_wrapped_gl_handle (GstGLContext * context, + GstAllocationParams * alloc_params, + GstVideoInfo * v_info, + guint plane, + GstVideoAlignment * valign, + GstGLTextureTarget target, + gpointer gl_handle, + gpointer user_data, + GDestroyNotify notify); + /* subclass usage */ void gst_gl_video_allocation_params_free_data (GstGLVideoAllocationParams * params); /* subclass usage */ diff --git a/gst-libs/gst/gl/gstglmemorypbo.c b/gst-libs/gst/gl/gstglmemorypbo.c index d8fa710624..f959dce080 100644 --- a/gst-libs/gst/gl/gstglmemorypbo.c +++ b/gst-libs/gst/gl/gstglmemorypbo.c @@ -674,7 +674,7 @@ _gl_mem_pbo_alloc (GstGLBaseMemoryAllocator * allocator, mem = g_new0 (GstGLMemoryPBO, 1); if (alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE) { - mem->mem.tex_id = params->parent.gl_handle; + mem->mem.tex_id = GPOINTER_TO_UINT (params->parent.gl_handle); mem->mem.texture_wrapped = TRUE; }