From 28dbe4fffc1cf3f48f6ee09f1ceeef26211f4671 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Fri, 18 Dec 2015 13:17:34 +1100 Subject: [PATCH] glmemory: add gst_gl_memory_allocator_get_default Add gst_gl_memory_allocator_get_default to get the default allocator based on the opengl version. Allows us to stop hardcoding the PBO allocator which isn't supported on gles2. Fixes GL upload on iOS9 among other things. --- ext/gl/gstgloverlay.c | 8 ++++---- gst-libs/gst/gl/gstglbufferpool.c | 3 ++- gst-libs/gst/gl/gstglmemory.c | 19 +++++++++++++++++++ gst-libs/gst/gl/gstglmemory.h | 3 +++ gst-libs/gst/gl/gstgloverlaycompositor.c | 3 ++- gst-libs/gst/gl/gstglupload.c | 12 ++++++------ gst-libs/gst/gl/gstglviewconvert.c | 7 +++++-- 7 files changed, 41 insertions(+), 14 deletions(-) diff --git a/ext/gl/gstgloverlay.c b/ext/gl/gstgloverlay.c index c23412d..fa6c6c1 100644 --- a/ext/gl/gstgloverlay.c +++ b/ext/gl/gstgloverlay.c @@ -698,8 +698,8 @@ gst_gl_overlay_load_jpeg (GstGLOverlay * overlay, FILE * fp) gst_video_info_align (&v_info, &v_align); mem_allocator = - GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find - (GST_GL_MEMORY_PBO_ALLOCATOR_NAME)); + GST_GL_BASE_MEMORY_ALLOCATOR (gst_gl_memory_allocator_get_default + (GST_GL_BASE_FILTER (overlay)->context)); params = gst_gl_video_allocation_params_new (GST_GL_BASE_FILTER (overlay)->context, NULL, &v_info, 0, &v_align, GST_GL_TEXTURE_TARGET_2D); @@ -813,8 +813,8 @@ gst_gl_overlay_load_png (GstGLOverlay * overlay, FILE * fp) gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA, width, height); mem_allocator = - GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find - (GST_GL_MEMORY_PBO_ALLOCATOR_NAME)); + GST_GL_BASE_MEMORY_ALLOCATOR (gst_gl_memory_allocator_get_default + (GST_GL_BASE_FILTER (overlay)->context)); params = gst_gl_video_allocation_params_new (GST_GL_BASE_FILTER (overlay)->context, NULL, &v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D); diff --git a/gst-libs/gst/gl/gstglbufferpool.c b/gst-libs/gst/gl/gstglbufferpool.c index 091142d..16b5c9e 100644 --- a/gst-libs/gst/gl/gstglbufferpool.c +++ b/gst-libs/gst/gl/gstglbufferpool.c @@ -122,7 +122,8 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config) if (allocator /* && GST_IS_GL_MEMORY_ALLOCATOR (allocator) FIXME EGLImage */ ) { priv->allocator = gst_object_ref (allocator); } else { - priv->allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME); + priv->allocator = + GST_ALLOCATOR (gst_gl_memory_allocator_get_default (glpool->context)); g_assert (priv->allocator); } diff --git a/gst-libs/gst/gl/gstglmemory.c b/gst-libs/gst/gl/gstglmemory.c index 466ce4d..229b5a2 100644 --- a/gst-libs/gst/gl/gstglmemory.c +++ b/gst-libs/gst/gl/gstglmemory.c @@ -1173,3 +1173,22 @@ gst_gl_memory_setup_buffer (GstGLMemoryAllocator * allocator, return TRUE; } + +GstGLMemoryAllocator * +gst_gl_memory_allocator_get_default (GstGLContext * context) +{ + GstGLMemoryAllocator *allocator = NULL; + + g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL); + + if (USING_OPENGL (context) || USING_OPENGL3 (context) + || USING_GLES3 (context)) { + allocator = (GstGLMemoryAllocator *) + gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME); + } else { + allocator = (GstGLMemoryAllocator *) + gst_allocator_find (GST_GL_MEMORY_ALLOCATOR_NAME); + } + + return allocator; +} diff --git a/gst-libs/gst/gl/gstglmemory.h b/gst-libs/gst/gl/gstglmemory.h index 7185a2d..3dbf0ed 100644 --- a/gst-libs/gst/gl/gstglmemory.h +++ b/gst-libs/gst/gl/gstglmemory.h @@ -216,6 +216,9 @@ gboolean gst_gl_memory_setup_buffer (GstGLMemoryAllocato GstBuffer * buffer, GstGLVideoAllocationParams * params); + +GstGLMemoryAllocator * gst_gl_memory_allocator_get_default (GstGLContext *context); + G_END_DECLS #endif /* _GST_GL_MEMORY_H_ */ diff --git a/gst-libs/gst/gl/gstgloverlaycompositor.c b/gst-libs/gst/gl/gstgloverlaycompositor.c index 2f0a56b..f7d0639 100644 --- a/gst-libs/gst/gl/gstgloverlaycompositor.c +++ b/gst-libs/gst/gl/gstgloverlaycompositor.c @@ -348,7 +348,8 @@ gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay, GstGLBaseMemoryAllocator *mem_allocator; GstAllocator *allocator; - allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME); + allocator = + GST_ALLOCATOR (gst_gl_memory_allocator_get_default (overlay->context)); mem_allocator = GST_GL_BASE_MEMORY_ALLOCATOR (allocator); gst_gl_composition_overlay_add_transformation (overlay, buf); diff --git a/gst-libs/gst/gl/gstglupload.c b/gst-libs/gst/gl/gstglupload.c index 447c998..f70fae9 100644 --- a/gst-libs/gst/gl/gstglupload.c +++ b/gst-libs/gst/gl/gstglupload.c @@ -223,7 +223,9 @@ _gl_memory_upload_propose_allocation (gpointer impl, GstQuery * decide_query, GstAllocationParams params; gst_allocation_params_init (¶ms); - allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME); + allocator = + GST_ALLOCATOR (gst_gl_memory_allocator_get_default (upload-> + upload->context)); gst_query_add_allocation_param (query, allocator, ¶ms); gst_object_unref (allocator); } @@ -696,9 +698,7 @@ _upload_meta_upload_perform (gpointer impl, GstBuffer * buffer, guint max_planes = GST_VIDEO_INFO_N_PLANES (in_info); GstGLMemoryAllocator *allocator; - allocator = - GST_GL_MEMORY_ALLOCATOR (gst_allocator_find - (GST_GL_MEMORY_PBO_ALLOCATOR_NAME)); + allocator = gst_gl_memory_allocator_get_default (upload->upload->context); /* Support stereo views for separated multiview mode */ if (GST_VIDEO_INFO_MULTIVIEW_MODE (in_info) == @@ -916,8 +916,8 @@ _raw_data_upload_perform (gpointer impl, GstBuffer * buffer, guint n_mem = GST_VIDEO_INFO_N_PLANES (in_info); allocator = - GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find - (GST_GL_MEMORY_PBO_ALLOCATOR_NAME)); + GST_GL_BASE_MEMORY_ALLOCATOR (gst_gl_memory_allocator_get_default + (raw->upload->context)); /* FIXME Use a buffer pool to cache the generated textures */ /* FIXME: multiview support with separated left/right frames? */ diff --git a/gst-libs/gst/gl/gstglviewconvert.c b/gst-libs/gst/gl/gstglviewconvert.c index 7ebbd62..c2776cb 100644 --- a/gst-libs/gst/gl/gstglviewconvert.c +++ b/gst-libs/gst/gl/gstglviewconvert.c @@ -1897,7 +1897,9 @@ _gen_buffer (GstGLViewConvert * viewconvert, GstBuffer ** target) *target = gst_buffer_new (); - allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME); + allocator = + GST_ALLOCATOR (gst_gl_memory_allocator_get_default + (viewconvert->context)); mem_allocator = GST_GL_MEMORY_ALLOCATOR (allocator); params = gst_gl_video_allocation_params_new (viewconvert->context, NULL, &viewconvert->out_info, 0, NULL, viewconvert->to_texture_target); @@ -2037,7 +2039,8 @@ _do_view_convert (GstGLContext * context, GstGLViewConvert * viewconvert) gst_video_info_set_format (&temp_info, GST_VIDEO_FORMAT_RGBA, out_width, out_height); - allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME); + allocator = + GST_ALLOCATOR (gst_gl_memory_allocator_get_default (context)); base_mem_allocator = GST_GL_BASE_MEMORY_ALLOCATOR (allocator); params = gst_gl_video_allocation_params_new (context, NULL, &temp_info, 0, NULL, viewconvert->to_texture_target); -- 2.7.4