glmemory: add gst_gl_memory_allocator_get_default
authorAlessandro Decina <alessandro.d@gmail.com>
Fri, 18 Dec 2015 02:17:34 +0000 (13:17 +1100)
committerAlessandro Decina <alessandro.d@gmail.com>
Fri, 18 Dec 2015 03:25:32 +0000 (14:25 +1100)
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
gst-libs/gst/gl/gstglbufferpool.c
gst-libs/gst/gl/gstglmemory.c
gst-libs/gst/gl/gstglmemory.h
gst-libs/gst/gl/gstgloverlaycompositor.c
gst-libs/gst/gl/gstglupload.c
gst-libs/gst/gl/gstglviewconvert.c
sys/applemedia/videotexturecache.m

index c23412d36898391f91f8b74dd2d0bea63e200ad5..fa6c6c116fbe141dec2914f2dab8d9fe9e80b714 100644 (file)
@@ -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);
index 091142daeed5339da396f2be20d3dd7faa526b3e..16b5c9e843f41da71404ed4f096779722bbf364f 100644 (file)
@@ -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);
   }
 
index 466ce4de35349a56043955653e08c1247640269e..229b5a2dec36ead2c4b5028d0e10e782def104a3 100644 (file)
@@ -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;
+}
index 7185a2d7bc9c18791557442adb46985973bd7039..3dbf0ed1bffbda9775abcef5a17e24297800f38b 100644 (file)
@@ -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_ */
index 2f0a56b5a915ecab3e674241fd729547ccbf1af9..f7d0639d137b589cf29b7a8b39b03aab901aba49 100644 (file)
@@ -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);
index 447c9980dbaccd70330f12493fbc608595b55d9b..f70fae9769c9f03fa69dce80ce2ac0cd122cbb43 100644 (file)
@@ -223,7 +223,9 @@ _gl_memory_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
     GstAllocationParams params;
     gst_allocation_params_init (&params);
 
-    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, &params);
     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? */
index 7ebbd62b5d4ec73fc358d8542eb18b3fbb27ce34..c2776cba1001794e0776a12018599cbee9ab440b 100644 (file)
@@ -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);
index 223b40e1f3ac2dfc315bc227ff5884c7d1bdc530..091339f91e58dd20e2bb407aac805f383f86f30a 100644 (file)
@@ -155,7 +155,7 @@ gl_mem_from_buffer (GstVideoTextureCache * cache,
   GstGLBaseMemoryAllocator *base_mem_alloc;
   GstGLVideoAllocationParams *params;
 
-  base_mem_alloc = GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME));
+  base_mem_alloc = GST_GL_BASE_MEMORY_ALLOCATOR (gst_gl_memory_allocator_get_default (cache->ctx));
 
   *mem1 = NULL;
   *mem2 = NULL;