summaryrefslogtreecommitdiff
path: root/gst-libs
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2015-12-16 18:23:31 +1100
committerMatthew Waters <matthew@centricular.com>2015-12-17 13:49:56 +1100
commitbfb4c446bc4ccc221e00e092ae16dae135bf8b43 (patch)
treefc06fcb9f25ee21af78192736e12b0ee9df94cf4 /gst-libs
parent650e5c4fe52f81a152f31b0bc6b49b2b09d4c7a4 (diff)
downloadgstreamer-plugins-bad-bfb4c446bc4ccc221e00e092ae16dae135bf8b43.tar.gz
glbuffer: implements GstGLBaseMemory::alloc
Create GstGLBufferAllocationParams which is subclass of GstGLAllocationParams
Diffstat (limited to 'gst-libs')
-rw-r--r--gst-libs/gst/gl/gstglbuffer.c67
-rw-r--r--gst-libs/gst/gl/gstglbuffer.h18
2 files changed, 84 insertions, 1 deletions
diff --git a/gst-libs/gst/gl/gstglbuffer.c b/gst-libs/gst/gl/gstglbuffer.c
index 5d8db2ede..42f24633b 100644
--- a/gst-libs/gst/gl/gstglbuffer.c
+++ b/gst-libs/gst/gl/gstglbuffer.c
@@ -299,7 +299,7 @@ static GstMemory *
_gl_buffer_alloc (GstAllocator * allocator, gsize size,
GstAllocationParams * params)
{
- g_critical ("Need to use gst_gl_buffer_alloc() to allocate from "
+ g_critical ("Need to use gst_gl_base_memory_alloc() to allocate from "
"this allocator");
return NULL;
@@ -313,6 +313,70 @@ _gl_buffer_destroy (GstGLBuffer * mem)
gl->DeleteBuffers (1, &mem->id);
}
+static void
+_gst_gl_buffer_allocation_params_copy_data (GstGLBufferAllocationParams * src,
+ GstGLBufferAllocationParams * dest)
+{
+ memset (dest, 0, sizeof (*dest));
+
+ gst_gl_allocation_params_copy_data (&src->parent, &dest->parent);
+
+ dest->gl_target = src->gl_target;
+ dest->gl_usage = src->gl_usage;
+}
+
+static void
+_gst_gl_buffer_allocation_params_free_data (GstGLBufferAllocationParams *
+ params)
+{
+ gst_gl_allocation_params_free_data (&params->parent);
+}
+
+GstGLBufferAllocationParams *
+gst_gl_buffer_allocation_params_new (GstGLContext * context, gsize alloc_size,
+ GstAllocationParams * alloc_params, guint gl_target, guint gl_usage)
+{
+ GstGLBufferAllocationParams *params;
+
+ g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL);
+ g_return_val_if_fail (alloc_size > 0, NULL);
+
+ params = g_new0 (GstGLBufferAllocationParams, 1);
+
+ if (!gst_gl_allocation_params_init (&params->parent, sizeof (*params),
+ GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_BUFFER |
+ GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_ALLOC,
+ (GstGLAllocationParamsCopyFunc)
+ _gst_gl_buffer_allocation_params_copy_data,
+ (GstGLAllocationParamsFreeFunc)
+ _gst_gl_buffer_allocation_params_free_data, context, alloc_size,
+ alloc_params, NULL, NULL, NULL, 0)) {
+ g_free (params);
+ return NULL;
+ }
+
+ params->gl_target = gl_target;
+ params->gl_usage = gl_usage;
+
+ return params;
+}
+
+static GstGLBuffer *
+_gl_buffer_alloc_mem (GstGLBufferAllocator * allocator,
+ GstGLBufferAllocationParams * params)
+{
+ guint alloc_flags = params->parent.alloc_flags;
+
+ g_return_val_if_fail (alloc_flags &
+ GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_BUFFER, NULL);
+ g_return_val_if_fail (alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_ALLOC,
+ NULL);
+
+ return _gl_buffer_new (GST_ALLOCATOR (allocator), NULL,
+ params->parent.context, params->gl_target, params->gl_usage,
+ params->parent.alloc_params, params->parent.alloc_size);
+}
+
G_DEFINE_TYPE (GstGLBufferAllocator, gst_gl_buffer_allocator,
GST_TYPE_GL_BASE_MEMORY_ALLOCATOR);
@@ -324,6 +388,7 @@ gst_gl_buffer_allocator_class_init (GstGLBufferAllocatorClass * klass)
gl_base = (GstGLBaseMemoryAllocatorClass *) klass;
+ gl_base->alloc = (GstGLBaseMemoryAllocatorAllocFunction) _gl_buffer_alloc_mem;
gl_base->create = (GstGLBaseMemoryAllocatorCreateFunction) _gl_buffer_create;
gl_base->map = (GstGLBaseMemoryAllocatorMapFunction) _gl_buffer_map;
gl_base->unmap = (GstGLBaseMemoryAllocatorUnmapFunction) _gl_buffer_unmap;
diff --git a/gst-libs/gst/gl/gstglbuffer.h b/gst-libs/gst/gl/gstglbuffer.h
index 313cb6984..306ac3800 100644
--- a/gst-libs/gst/gl/gstglbuffer.h
+++ b/gst-libs/gst/gl/gstglbuffer.h
@@ -57,6 +57,24 @@ struct _GstGLBuffer
guint usage_hints; /* XXX: put this in the allocator? */
};
+typedef struct _GstGLBufferAllocationParams GstGLBufferAllocationParams;
+
+#define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_BUFFER (1 << 4)
+
+struct _GstGLBufferAllocationParams
+{
+ GstGLAllocationParams parent;
+
+ guint gl_target;
+ guint gl_usage;
+};
+
+GstGLBufferAllocationParams * gst_gl_buffer_allocation_params_new (GstGLContext * context,
+ gsize alloc_size,
+ GstAllocationParams * alloc_params,
+ guint gl_target,
+ guint gl_usage);
+
/**
* GstGLBufferAllocator
*