glmemorypbo: remove our own alloc()/wrapped()/etc functions

replaced by equivalent functionality within gst_gl_base_memory_alloc()
This commit is contained in:
Matthew Waters 2015-12-16 18:41:06 +11:00
parent 78fb4326eb
commit 779dc3132c
11 changed files with 305 additions and 315 deletions

View file

@ -668,6 +668,8 @@ user_warning_fn (png_structp png_ptr, png_const_charp warning_msg)
static gboolean
gst_gl_overlay_load_jpeg (GstGLOverlay * overlay, FILE * fp)
{
GstGLBaseMemoryAllocator *mem_allocator;
GstGLVideoAllocationParams *params;
GstVideoInfo v_info;
GstVideoAlignment v_align;
GstMapInfo map_info;
@ -695,9 +697,17 @@ gst_gl_overlay_load_jpeg (GstGLOverlay * overlay, FILE * fp)
v_align.stride_align[0] = 32 - 1;
gst_video_info_align (&v_info, &v_align);
mem_allocator =
GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find
(GST_GL_MEMORY_PBO_ALLOCATOR_NAME));
params =
gst_gl_video_allocation_params_new (GST_GL_BASE_FILTER (overlay)->context,
NULL, &v_info, 0, &v_align, GST_GL_TEXTURE_TARGET_2D);
overlay->image_memory = (GstGLMemory *)
gst_gl_memory_pbo_alloc (GST_GL_BASE_FILTER (overlay)->context,
GST_GL_TEXTURE_TARGET_2D, NULL, &v_info, 0, &v_align);
gst_gl_base_memory_alloc (mem_allocator,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (mem_allocator);
if (!gst_memory_map ((GstMemory *) overlay->image_memory, &map_info,
GST_MAP_WRITE)) {
@ -720,6 +730,8 @@ gst_gl_overlay_load_jpeg (GstGLOverlay * overlay, FILE * fp)
static gboolean
gst_gl_overlay_load_png (GstGLOverlay * overlay, FILE * fp)
{
GstGLBaseMemoryAllocator *mem_allocator;
GstGLVideoAllocationParams *params;
GstVideoInfo v_info;
GstMapInfo map_info;
@ -800,9 +812,17 @@ gst_gl_overlay_load_png (GstGLOverlay * overlay, FILE * fp)
overlay->image_height = height;
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));
params =
gst_gl_video_allocation_params_new (GST_GL_BASE_FILTER (overlay)->context,
NULL, &v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D);
overlay->image_memory = (GstGLMemory *)
gst_gl_memory_pbo_alloc (GST_GL_BASE_FILTER (overlay)->context,
GST_GL_TEXTURE_TARGET_2D, NULL, &v_info, 0, NULL);
gst_gl_base_memory_alloc (mem_allocator,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (mem_allocator);
if (!gst_memory_map ((GstMemory *) overlay->image_memory, &map_info,
GST_MAP_WRITE)) {

View file

@ -2006,15 +2006,27 @@ _do_convert_one_view (GstGLContext * context, GstGLColorConvert * convert,
/* Luminance formats are not color renderable */
/* renderering to a framebuffer only renders the intersection of all
* the attachments i.e. the smallest attachment size */
GstVideoInfo temp_info;
if (!convert->priv->out_tex[j]) {
GstGLVideoAllocationParams *params;
GstGLBaseMemoryAllocator *base_mem_allocator;
GstAllocator *allocator;
GstVideoInfo temp_info;
gst_video_info_set_format (&temp_info, GST_VIDEO_FORMAT_RGBA, out_width,
out_height);
gst_video_info_set_format (&temp_info, GST_VIDEO_FORMAT_RGBA, out_width,
out_height);
allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR_NAME);
base_mem_allocator = GST_GL_BASE_MEMORY_ALLOCATOR (allocator);
params = gst_gl_video_allocation_params_new (context, NULL, &temp_info,
0, NULL, convert->priv->to_texture_target);
if (!convert->priv->out_tex[j])
convert->priv->out_tex[j] =
(GstGLMemory *) gst_gl_memory_pbo_alloc (context,
convert->priv->to_texture_target, NULL, &temp_info, 0, NULL);
(GstGLMemory *) gst_gl_base_memory_alloc (base_mem_allocator,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (allocator);
}
} else {
convert->priv->out_tex[j] = out_tex;
}
@ -2106,6 +2118,9 @@ _do_convert (GstGLContext * context, GstGLColorConvert * convert)
gint views, v;
GstVideoOverlayCompositionMeta *composition_meta;
GstGLSyncMeta *sync_meta;
GstGLVideoAllocationParams *params;
GstGLMemoryAllocator *mem_allocator;
GstAllocator *allocator;
convert->outbuf = NULL;
@ -2119,12 +2134,21 @@ _do_convert (GstGLContext * context, GstGLColorConvert * convert)
gst_gl_sync_meta_wait (sync_meta, convert->context);
convert->outbuf = gst_buffer_new ();
if (!gst_gl_memory_pbo_setup_buffer (convert->context,
convert->priv->to_texture_target, NULL, &convert->out_info, NULL,
convert->outbuf)) {
allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR_NAME);
mem_allocator = GST_GL_MEMORY_ALLOCATOR (allocator);
params =
gst_gl_video_allocation_params_new (context, NULL, &convert->out_info, 0,
NULL, convert->priv->to_texture_target);
if (!gst_gl_memory_setup_buffer (mem_allocator, convert->outbuf, params)) {
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (allocator);
convert->priv->result = FALSE;
return;
}
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (allocator);
if (GST_VIDEO_INFO_MULTIVIEW_MODE (in_info) ==
GST_VIDEO_MULTIVIEW_MODE_SEPARATED)

View file

@ -827,106 +827,6 @@ gst_gl_memory_pbo_copy_into_texture (GstGLMemoryPBO * gl_mem, guint tex_id,
return copy_params.result;
}
/**
* gst_gl_memory_pbo_wrapped_texture:
* @context: a #GstGLContext
* @texture_id: the GL texture handle
* @texture_target: the GL texture target
* @info: the #GstVideoInfo of the memory
* @plane: The plane this memory will represent
* @user_data: user data
* @notify: Destroy callback for the user data
*
* Wraps a texture handle into a #GstGLMemoryPBO.
*
* Returns: a newly allocated #GstGLMemoryPBO
*/
GstGLMemoryPBO *
gst_gl_memory_pbo_wrapped_texture (GstGLContext * context,
guint texture_id, GstGLTextureTarget target,
GstVideoInfo * info, guint plane, GstVideoAlignment * valign,
gpointer user_data, GDestroyNotify notify)
{
GstGLMemoryPBO *mem;
mem = g_slice_new0 (GstGLMemoryPBO);
mem->mem.tex_id = texture_id;
mem->mem.texture_wrapped = TRUE;
_gl_mem_init (mem, _gl_allocator, NULL, context, target, NULL, info, valign,
plane, user_data, notify);
GST_MINI_OBJECT_FLAG_SET (mem, GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD);
return mem;
}
/**
* gst_gl_memory_pbo_alloc:
* @context:a #GstGLContext
* @params: a #GstAllocationParams
* @info: the #GstVideoInfo of the memory
* @plane: the plane this memory will represent
* @valign: the #GstVideoAlignment applied to @info
*
* Allocated a new #GstGlMemory.
*
* Returns: a #GstMemory object with a GL texture specified by @vinfo
* from @context
*/
GstMemory *
gst_gl_memory_pbo_alloc (GstGLContext * context, GstGLTextureTarget target,
GstAllocationParams * params, GstVideoInfo * info, guint plane,
GstVideoAlignment * valign)
{
GstGLMemoryPBO *mem;
mem =
_gl_mem_new (_gl_allocator, NULL, context, target, params, info, valign,
plane, NULL, NULL);
return (GstMemory *) mem;
}
/**
* gst_gl_memory_pbo_wrapped:
* @context:a #GstGLContext
* @info: the #GstVideoInfo of the memory and data
* @plane: the plane this memory will represent
* @valign: the #GstVideoAlignment applied to @info
* @data: the data to wrap
* @user_data: data called with for @notify
* @notify: function called with @user_data when @data needs to be freed
*
* Wrapped @data into a #GstGLMemoryPBO. This version will account for padding
* added to the allocation and expressed through @valign.
*
* Returns: a #GstGLMemoryPBO object with a GL texture specified by @v_info
* from @context and contents specified by @data
*/
GstGLMemoryPBO *
gst_gl_memory_pbo_wrapped (GstGLContext * context, GstGLTextureTarget target,
GstVideoInfo * info, guint plane, GstVideoAlignment * valign, gpointer data,
gpointer user_data, GDestroyNotify notify)
{
GstGLMemoryPBO *mem;
mem = _gl_mem_new (_gl_allocator, NULL, context, target, NULL, info, valign,
plane, user_data, notify);
if (!mem)
return NULL;
mem->pbo->mem.data = data;
GST_MINI_OBJECT_FLAG_SET (mem, GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD);
if (mem->pbo)
GST_MINI_OBJECT_FLAG_SET (mem->pbo,
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD);
return mem;
}
static void
_download_transfer (GstGLContext * context, GstGLMemoryPBO * gl_mem)
{
@ -1012,85 +912,3 @@ gst_is_gl_memory_pbo (GstMemory * mem)
&& g_type_is_a (G_OBJECT_TYPE (mem->allocator),
GST_TYPE_GL_MEMORY_PBO_ALLOCATOR);
}
/**
* gst_gl_memory_pbo_setup_buffer:
* @context: a #GstGLContext
* @params: a #GstAllocationParams
* @info: a #GstVideoInfo
* @valign: the #GstVideoAlignment applied to @info
* @buffer: a #GstBuffer
*
* Adds the required #GstGLMemoryPBO<!-- -->s with the correct configuration to
* @buffer based on @info. This version handles padding through @valign.
*
* Returns: whether the memory's were sucessfully added.
*/
gboolean
gst_gl_memory_pbo_setup_buffer (GstGLContext * context,
GstGLTextureTarget target, GstAllocationParams * params,
GstVideoInfo * info, GstVideoAlignment * valign, GstBuffer * buffer)
{
GstGLMemoryPBO *gl_mem[GST_VIDEO_MAX_PLANES] = { NULL, };
guint n_mem, i, v, views;
n_mem = GST_VIDEO_INFO_N_PLANES (info);
if (GST_VIDEO_INFO_MULTIVIEW_MODE (info) ==
GST_VIDEO_MULTIVIEW_MODE_SEPARATED)
views = info->views;
else
views = 1;
for (v = 0; v < views; v++) {
for (i = 0; i < n_mem; i++) {
gl_mem[i] =
(GstGLMemoryPBO *) gst_gl_memory_pbo_alloc (context, target, params,
info, i, valign);
if (gl_mem[i] == NULL)
return FALSE;
gst_buffer_append_memory (buffer, (GstMemory *) gl_mem[i]);
}
gst_buffer_add_video_meta_full (buffer, v,
GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info),
GST_VIDEO_INFO_HEIGHT (info), n_mem, info->offset, info->stride);
}
return TRUE;
}
/**
* gst_gl_memory_pbo_setup_wrapped:
* @context: a #GstGLContext
* @info: a #GstVideoInfo
* @valign: a #GstVideoInfo
* @data: a list of per plane data pointers
* @textures: (transfer out): a list of #GstGLMemoryPBO
* @user_data: user data for the destroy function
* @notify: A function called each time a memory is freed
*
* Wraps per plane data pointer in @data into the corresponding entry in
* @textures based on @info and padding from @valign. Note that the @notify
* will be called as many time as there is planes.
*
* Returns: whether the memory's were sucessfully created.
*/
gboolean
gst_gl_memory_pbo_setup_wrapped (GstGLContext * context,
GstGLTextureTarget target, GstVideoInfo * info, GstVideoAlignment * valign,
gpointer data[GST_VIDEO_MAX_PLANES],
GstGLMemoryPBO * textures[GST_VIDEO_MAX_PLANES], gpointer user_data,
GDestroyNotify notify)
{
gint i;
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (info); i++) {
textures[i] =
(GstGLMemoryPBO *) gst_gl_memory_pbo_wrapped (context, target, info, i,
valign, data[i], user_data, notify);
}
return TRUE;
}

View file

@ -64,29 +64,6 @@ struct _GstGLMemoryPBO
void gst_gl_memory_pbo_init_once (void);
gboolean gst_is_gl_memory_pbo (GstMemory * mem);
GstMemory * gst_gl_memory_pbo_alloc (GstGLContext * context,
GstGLTextureTarget target,
GstAllocationParams *params,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign);
GstGLMemoryPBO * gst_gl_memory_pbo_wrapped (GstGLContext * context,
GstGLTextureTarget target,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign,
gpointer data,
gpointer user_data,
GDestroyNotify notify);
GstGLMemoryPBO * gst_gl_memory_pbo_wrapped_texture (GstGLContext * context,
guint texture_id,
GstGLTextureTarget target,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign,
gpointer user_data,
GDestroyNotify notify);
void gst_gl_memory_pbo_download_transfer (GstGLMemoryPBO * gl_mem);
void gst_gl_memory_pbo_upload_transfer (GstGLMemoryPBO * gl_mem);
@ -99,21 +76,6 @@ gboolean gst_gl_memory_pbo_copy_into_texture (GstGLMemoryPBO *gl_mem,
gint stride,
gboolean respecify);
gboolean gst_gl_memory_pbo_setup_buffer (GstGLContext * context,
GstGLTextureTarget target,
GstAllocationParams * params,
GstVideoInfo * info,
GstVideoAlignment *valign,
GstBuffer * buffer);
gboolean gst_gl_memory_pbo_setup_wrapped (GstGLContext * context,
GstGLTextureTarget target,
GstVideoInfo * info,
GstVideoAlignment *valign,
gpointer data[GST_VIDEO_MAX_PLANES],
GstGLMemoryPBO *textures[GST_VIDEO_MAX_PLANES],
gpointer user_data,
GDestroyNotify notify);
/**
* GstGLAllocator
*

View file

@ -344,12 +344,25 @@ gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay,
vinfo.stride[0] = vmeta->stride[0];
if (gst_video_frame_map (comp_frame, &vinfo, comp_buffer, GST_MAP_READ)) {
GstGLVideoAllocationParams *params;
GstGLBaseMemoryAllocator *mem_allocator;
GstAllocator *allocator;
allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
mem_allocator = GST_GL_BASE_MEMORY_ALLOCATOR (allocator);
gst_gl_composition_overlay_add_transformation (overlay, buf);
params = gst_gl_video_allocation_params_new_wrapped_data (overlay->context,
NULL, &comp_frame->info, 0, NULL, GST_GL_TEXTURE_TARGET_2D,
comp_frame->data[0], _video_frame_unmap_and_free, comp_frame);
comp_gl_memory =
(GstGLMemory *) gst_gl_memory_pbo_wrapped (overlay->context,
GST_GL_TEXTURE_TARGET_2D, &comp_frame->info, 0, NULL,
comp_frame->data[0], comp_frame, _video_frame_unmap_and_free);
(GstGLMemory *) gst_gl_base_memory_alloc (mem_allocator,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (allocator);
overlay_buffer = gst_buffer_new ();
gst_buffer_append_memory (overlay_buffer, (GstMemory *) comp_gl_memory);

View file

@ -346,6 +346,7 @@ struct EGLImageUpload
GstGLUpload *upload;
GstBuffer *buffer;
GstBuffer **outbuf;
GstGLVideoAllocationParams *params;
};
static gpointer
@ -403,6 +404,14 @@ _egl_image_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps,
if (!ret)
return FALSE;
if (image->params)
gst_gl_allocation_params_free ((GstGLAllocationParams *) image->params);
if (!(image->params =
gst_gl_video_allocation_params_new (image->upload->context, NULL,
&image->upload->priv->in_info, -1, NULL,
GST_GL_TEXTURE_TARGET_2D)))
return FALSE;
if (buffer) {
GstVideoInfo *in_info = &image->upload->priv->in_info;
guint expected_memories = GST_VIDEO_INFO_N_PLANES (in_info);
@ -457,13 +466,17 @@ static void
_egl_image_upload_perform_gl_thread (GstGLContext * context,
struct EGLImageUpload *image)
{
GstGLMemoryAllocator *allocator;
guint i, n;
allocator =
GST_GL_MEMORY_ALLOCATOR (gst_allocator_find
(GST_GL_MEMORY_PBO_ALLOCATOR_NAME));
/* FIXME: buffer pool */
*image->outbuf = gst_buffer_new ();
gst_gl_memory_pbo_setup_buffer (image->upload->context,
GST_GL_TEXTURE_TARGET_2D, NULL, &image->upload->priv->out_info, NULL,
*image->outbuf);
gst_gl_memory_setup_buffer (allocator, *image->outbuf, image->params);
gst_object_unref (allocator);
n = gst_buffer_n_memory (image->buffer);
for (i = 0; i < n; i++) {
@ -481,8 +494,8 @@ _egl_image_upload_perform_gl_thread (GstGLContext * context,
}
if (GST_IS_GL_BUFFER_POOL (image->buffer->pool))
gst_gl_buffer_pool_replace_last_buffer (GST_GL_BUFFER_POOL (image->
buffer->pool), image->buffer);
gst_gl_buffer_pool_replace_last_buffer (GST_GL_BUFFER_POOL (image->buffer->
pool), image->buffer);
}
static GstGLUploadReturn
@ -506,6 +519,11 @@ _egl_image_upload_perform (gpointer impl, GstBuffer * buffer,
static void
_egl_image_upload_free (gpointer impl)
{
struct EGLImageUpload *image = impl;
if (image->params)
gst_gl_allocation_params_free ((GstGLAllocationParams *) image->params);
g_free (impl);
}
@ -533,6 +551,7 @@ struct GLUploadMeta
gboolean result;
GstVideoGLTextureUploadMeta *meta;
guint texture_ids[GST_GL_UPLOAD_MAX_PLANES];
GstGLVideoAllocationParams *params;
};
static gpointer
@ -594,6 +613,14 @@ _upload_meta_upload_accept (gpointer impl, GstBuffer * buffer,
if (!ret)
return ret;
if (upload->params)
gst_gl_allocation_params_free ((GstGLAllocationParams *) upload->params);
if (!(upload->params =
gst_gl_video_allocation_params_new (upload->upload->context, NULL,
&upload->upload->priv->in_info, -1, NULL,
GST_GL_TEXTURE_TARGET_2D)))
return FALSE;
if (buffer) {
if ((meta = gst_buffer_get_video_gl_texture_upload_meta (buffer)) == NULL)
return FALSE;
@ -623,11 +650,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 =
@ -667,6 +694,11 @@ _upload_meta_upload_perform (gpointer impl, GstBuffer * buffer,
int i;
GstVideoInfo *in_info = &upload->upload->priv->in_info;
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));
/* Support stereo views for separated multiview mode */
if (GST_VIDEO_INFO_MULTIVIEW_MODE (in_info) ==
@ -679,9 +711,8 @@ _upload_meta_upload_perform (gpointer impl, GstBuffer * buffer,
/* FIXME: buffer pool */
*outbuf = gst_buffer_new ();
gst_gl_memory_pbo_setup_buffer (upload->upload->context,
GST_GL_TEXTURE_TARGET_2D, NULL, &upload->upload->priv->in_info, NULL,
*outbuf);
gst_gl_memory_setup_buffer (allocator, *outbuf, upload->params);
gst_object_unref (allocator);
for (i = 0; i < GST_GL_UPLOAD_MAX_PLANES; i++) {
guint tex_id = 0;
@ -723,6 +754,10 @@ _upload_meta_upload_free (gpointer impl)
gst_gl_context_del_texture (upload->upload->context,
&upload->texture_ids[i]);
}
if (upload->params)
gst_gl_allocation_params_free ((GstGLAllocationParams *) upload->params);
g_free (upload);
}
@ -752,6 +787,7 @@ struct RawUpload
{
GstGLUpload *upload;
struct RawUploadFrame *in_frame;
GstGLVideoAllocationParams *params;
};
static struct RawUploadFrame *
@ -850,6 +886,15 @@ _raw_data_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps,
_raw_upload_frame_unref (raw->in_frame);
raw->in_frame = _raw_upload_frame_new (raw, buffer);
if (raw->params)
gst_gl_allocation_params_free ((GstGLAllocationParams *) raw->params);
if (!(raw->params =
gst_gl_video_allocation_params_new_wrapped_data (raw->upload->context,
NULL, &raw->upload->priv->in_info, -1, NULL,
GST_GL_TEXTURE_TARGET_2D, NULL,
(GDestroyNotify) _raw_upload_frame_unref, raw->in_frame)))
return FALSE;
return (raw->in_frame != NULL);
}
@ -864,28 +909,39 @@ static GstGLUploadReturn
_raw_data_upload_perform (gpointer impl, GstBuffer * buffer,
GstBuffer ** outbuf)
{
GstGLMemory *in_tex[GST_GL_UPLOAD_MAX_PLANES] = { 0, };
GstGLBaseMemoryAllocator *allocator;
struct RawUpload *raw = impl;
int i;
GstVideoInfo *in_info = &raw->upload->priv->in_info;
guint max_planes = GST_VIDEO_INFO_N_PLANES (in_info);
guint n_mem = GST_VIDEO_INFO_N_PLANES (in_info);
/* Support stereo views for separated multiview mode */
if (GST_VIDEO_INFO_MULTIVIEW_MODE (in_info) ==
GST_VIDEO_MULTIVIEW_MODE_SEPARATED)
max_planes *= GST_VIDEO_INFO_VIEWS (in_info);
gst_gl_memory_pbo_setup_wrapped (raw->upload->context,
GST_GL_TEXTURE_TARGET_2D, &raw->upload->priv->in_info, NULL,
raw->in_frame->frame.data, (GstGLMemoryPBO **) in_tex, raw->in_frame,
(GDestroyNotify) _raw_upload_frame_unref);
allocator =
GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find
(GST_GL_MEMORY_PBO_ALLOCATOR_NAME));
/* FIXME Use a buffer pool to cache the generated textures */
/* FIXME: multiview support with separated left/right frames? */
*outbuf = gst_buffer_new ();
for (i = 0; i < max_planes; i++) {
for (i = 0; i < n_mem; i++) {
GstGLBaseMemory *tex;
raw->params->parent.wrapped_data = raw->in_frame->frame.data[i];
raw->params->plane = i;
tex =
gst_gl_base_memory_alloc (allocator,
(GstGLAllocationParams *) raw->params);
if (!tex) {
gst_buffer_unref (*outbuf);
*outbuf = NULL;
GST_ERROR_OBJECT (raw->upload, "Failed to allocate wrapped texture");
return GST_GL_UPLOAD_ERROR;
}
_raw_upload_frame_ref (raw->in_frame);
gst_buffer_append_memory (*outbuf, (GstMemory *) in_tex[i]);
gst_buffer_append_memory (*outbuf, (GstMemory *) tex);
}
gst_object_unref (allocator);
_raw_upload_frame_unref (raw->in_frame);
raw->in_frame = NULL;
@ -897,6 +953,9 @@ _raw_data_upload_free (gpointer impl)
{
struct RawUpload *raw = impl;
if (raw->params)
gst_gl_allocation_params_free ((GstGLAllocationParams *) raw->params);
g_free (raw);
}

View file

@ -1891,12 +1891,25 @@ _do_view_convert_draw (GstGLContext * context, GstGLViewConvert * viewconvert)
static gboolean
_gen_buffer (GstGLViewConvert * viewconvert, GstBuffer ** target)
{
GstGLVideoAllocationParams *params;
GstGLMemoryAllocator *mem_allocator;
GstAllocator *allocator;
*target = gst_buffer_new ();
if (!gst_gl_memory_pbo_setup_buffer (viewconvert->context,
viewconvert->to_texture_target, NULL, &viewconvert->out_info, NULL,
*target)) {
allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
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);
if (!gst_gl_memory_setup_buffer (mem_allocator, *target, params)) {
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (allocator);
return FALSE;
}
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (allocator);
gst_buffer_add_video_meta_full (*target, 0,
GST_VIDEO_INFO_FORMAT (&viewconvert->out_info),
GST_VIDEO_INFO_WIDTH (&viewconvert->out_info),
@ -2015,10 +2028,27 @@ _do_view_convert (GstGLContext * context, GstGLViewConvert * viewconvert)
/* Luminance formats are not color renderable */
/* renderering to a framebuffer only renders the intersection of all
* the attachments i.e. the smallest attachment size */
if (!priv->out_tex[j])
if (!priv->out_tex[j]) {
GstGLVideoAllocationParams *params;
GstGLBaseMemoryAllocator *base_mem_allocator;
GstAllocator *allocator;
GstVideoInfo temp_info;
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);
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);
priv->out_tex[j] =
(GstGLMemory *) gst_gl_memory_pbo_alloc (context,
viewconvert->to_texture_target, NULL, &temp_info, 0, NULL);
(GstGLMemory *) gst_gl_base_memory_alloc (base_mem_allocator,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_object_unref (allocator);
}
} else {
priv->out_tex[j] = out_tex;
}

View file

@ -152,6 +152,10 @@ gl_mem_from_buffer (GstVideoTextureCache * cache,
CVOpenGLESTextureRef texture = NULL;
CVPixelBufferRef pixel_buf = cv_pixel_buffer_from_gst_buffer (buffer);
GstGLTextureTarget gl_target;
GstGLBaseMemoryAllocator *base_mem_alloc;
GstGLVideoAllocationParams *params;
base_memory_alloc = GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME));
*mem1 = NULL;
*mem2 = NULL;
@ -169,10 +173,14 @@ gl_mem_from_buffer (GstVideoTextureCache * cache,
goto error;
gl_target = gst_gl_texture_target_from_gl (CVOpenGLESTextureGetTarget (texture));
params = gst_gl_video_allocation_params_new_wrapped_texture (cache->ctx,
NULL, &cache->input_info, 0, NULL, gl_target,
CVOpenGLTextureGetName (texture), (GDestroyNotify) CFRelease,
texture);
*mem1 = (GstMemory *) gst_gl_memory_pbo_wrapped_texture (cache->ctx,
CVOpenGLESTextureGetName (texture), gl_target,
&cache->input_info, 0, NULL, texture, (GDestroyNotify) CFRelease);
*mem1 = (GstMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
break;
case GST_VIDEO_FORMAT_NV12: {
GstVideoGLTextureType textype;
@ -191,9 +199,14 @@ gl_mem_from_buffer (GstVideoTextureCache * cache,
goto error;
gl_target = gst_gl_texture_target_from_gl (CVOpenGLESTextureGetTarget (texture));
*mem1 = (GstMemory *) gst_gl_memory_pbo_wrapped_texture (cache->ctx,
CVOpenGLESTextureGetName (texture), gl_target,
&cache->input_info, 0, NULL, texture, (GDestroyNotify) CFRelease);
params = gst_gl_video_allocation_paramc_new_wrapped_texture (cache->ctx,
NULL, &cache->input_info, 0, NULL, gl_target,
CVOpenGLTextureGetName (texture), (GDestroyNotify) CFRelease,
texture);
*mem1 = (GstMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
textype = gst_gl_texture_type_from_format (cache->ctx, GST_VIDEO_FORMAT_NV12, 1);
texifmt = gst_gl_format_from_gl_texture_type (textype);
@ -207,9 +220,14 @@ gl_mem_from_buffer (GstVideoTextureCache * cache,
goto error;
gl_target = gst_gl_texture_target_from_gl (CVOpenGLESTextureGetTarget (texture));
*mem2 = (GstMemory *) gst_gl_memory_pbo_wrapped_texture (cache->ctx,
CVOpenGLESTextureGetName (texture), gl_target,
&cache->input_info, 0, NULL, texture, (GDestroyNotify) CFRelease);
params = gst_gl_video_allocation_params_new_wrapped_texture (cache->ctx,
NULL, &cache->input_info, 1, NULL, gl_target,
CVOpenGLTextureGetName (texture), (GDestroyNotify) CFRelease,
texture);
*mem1 = (GstMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
break;
}
default:
@ -217,15 +235,10 @@ gl_mem_from_buffer (GstVideoTextureCache * cache,
goto error;
}
return TRUE;
gst_object_unref (base_mem_alloc);
error:
if (*mem1)
gst_memory_unref (*mem1);
if (*mem2)
gst_memory_unref (*mem2);
return FALSE;
return ret;
}
#else /* !HAVE_IOS */

View file

@ -116,17 +116,20 @@ _frame_unref (gpointer user_data)
static void
check_conversion (TestFrame * frames, guint size)
{
GstGLBaseMemoryAllocator *base_mem_alloc;
gint i, j, k, l;
gint ref_count = 0;
base_mem_alloc =
GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find
(GST_GL_MEMORY_ALLOCATOR_NAME));
for (i = 0; i < size; i++) {
GstBuffer *inbuf;
GstVideoInfo in_info;
gint in_width = frames[i].width;
gint in_height = frames[i].height;
GstVideoFormat in_v_format = frames[i].v_format;
gchar *in_data[GST_VIDEO_MAX_PLANES] = { 0 };
GstGLMemory *in_mem[GST_VIDEO_MAX_PLANES] = { 0 };
GstVideoFrame in_frame;
GstCaps *in_caps;
@ -135,19 +138,22 @@ check_conversion (TestFrame * frames, guint size)
gst_caps_set_features (in_caps, 0,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
for (j = 0; j < GST_VIDEO_INFO_N_PLANES (&in_info); j++) {
in_data[j] = frames[i].data[j];
}
/* create GL buffer */
ref_count += GST_VIDEO_INFO_N_PLANES (&in_info);
inbuf = gst_buffer_new ();
fail_unless (gst_gl_memory_pbo_setup_wrapped (context,
GST_GL_TEXTURE_TARGET_2D, &in_info, NULL, (gpointer *) in_data,
(GstGLMemoryPBO **) in_mem, &ref_count, _frame_unref));
for (j = 0; j < GST_VIDEO_INFO_N_PLANES (&in_info); j++) {
gst_buffer_append_memory (inbuf, (GstMemory *) in_mem[j]);
GstGLVideoAllocationParams *params;
GstGLBaseMemory *mem;
ref_count++;
params = gst_gl_video_allocation_params_new_wrapped_data (context, NULL,
&in_info, j, NULL, GST_GL_TEXTURE_TARGET_2D, frames[i].data[j],
_frame_unref, &ref_count);
mem = gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_buffer_append_memory (inbuf, GST_MEMORY_CAST (mem));
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
}
fail_unless (gst_video_frame_map (&in_frame, &in_info, inbuf,
@ -156,8 +162,8 @@ check_conversion (TestFrame * frames, guint size)
/* sanity check that the correct values were wrapped */
for (j = 0; j < GST_VIDEO_INFO_N_PLANES (&in_info); j++) {
for (k = 0; k < _video_info_plane_size (&in_info, j); k++) {
if (in_data[j][k] != IGNORE_MAGIC)
fail_unless (((gchar *) in_frame.data[j])[k] == in_data[j][k]);
if (frames[i].data[j][k] != IGNORE_MAGIC)
fail_unless (((gchar *) in_frame.data[j])[k] == frames[i].data[j][k]);
}
}
@ -215,6 +221,8 @@ check_conversion (TestFrame * frames, guint size)
fail_unless_equals_int (ref_count, 0);
}
gst_object_unref (base_mem_alloc);
}
GST_START_TEST (test_reorder_buffer)

View file

@ -54,14 +54,16 @@ GST_START_TEST (test_basic)
GstMemory *mem, *mem2;
GstGLMemory *gl_mem, *gl_mem2;
GstAllocator *gl_allocator;
GstGLBaseMemoryAllocator *base_mem_alloc;
gint i, j;
static GstVideoFormat formats[] = {
GST_VIDEO_FORMAT_RGBA, GST_VIDEO_FORMAT_RGB,
GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_I420
};
gl_allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
gl_allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR_NAME);
fail_if (gl_allocator == NULL);
base_mem_alloc = GST_GL_BASE_MEMORY_ALLOCATOR (gl_allocator);
/* test allocator creation */
ASSERT_WARNING (mem = gst_allocator_alloc (gl_allocator, 0, NULL));
@ -73,9 +75,13 @@ GST_START_TEST (test_basic)
gst_video_info_set_format (&v_info, formats[i], width, height);
for (j = 0; j < GST_VIDEO_INFO_N_PLANES (&v_info); j++) {
mem =
gst_gl_memory_pbo_alloc (context, GST_GL_TEXTURE_TARGET_2D, NULL,
&v_info, j, NULL);
GstGLVideoAllocationParams *params;
params = gst_gl_video_allocation_params_new (context, NULL, &v_info, j,
NULL, GST_GL_TEXTURE_TARGET_2D);
mem = (GstMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
fail_if (mem == NULL);
gl_mem = (GstGLMemory *) mem;
@ -98,6 +104,7 @@ GST_START_TEST (test_basic)
printf ("%s\n", gst_gl_context_get_error ());
fail_if (gst_gl_context_get_error () != NULL);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
gst_memory_unref (mem);
gst_memory_unref (mem2);
}
@ -113,31 +120,41 @@ static gchar rgba_pixel[] = {
0xff, 0x00, 0x00, 0xff,
};
GST_START_TEST (test_transfer)
static void
test_transfer_allocator (const gchar * allocator_name)
{
GstAllocator *gl_allocator;
GstGLBaseMemoryAllocator *base_mem_alloc;
GstVideoInfo v_info;
GstMemory *mem, *mem2, *mem3;
GstMapInfo map_info;
GstGLVideoAllocationParams *params;
gl_allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
gl_allocator = gst_allocator_find (allocator_name);
fail_if (gl_allocator == NULL);
base_mem_alloc = GST_GL_BASE_MEMORY_ALLOCATOR (gl_allocator);
gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA, 1, 1);
params = gst_gl_video_allocation_params_new (context, NULL, &v_info, 0,
NULL, GST_GL_TEXTURE_TARGET_2D);
/* texture creation */
mem =
(GstMemory *) gst_gl_memory_pbo_alloc (context, GST_GL_TEXTURE_TARGET_2D,
NULL, &v_info, 0, NULL);
mem = (GstMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
/* test wrapping raw data */
params = gst_gl_video_allocation_params_new_wrapped_data (context, NULL,
&v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D, rgba_pixel, NULL, NULL);
mem2 =
(GstMemory *) gst_gl_memory_pbo_wrapped (context,
GST_GL_TEXTURE_TARGET_2D, &v_info, 0, NULL, rgba_pixel, NULL, NULL);
(GstMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
fail_if (mem == NULL);
fail_unless (GST_MEMORY_FLAG_IS_SET (mem2,
@ -146,9 +163,13 @@ GST_START_TEST (test_transfer)
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
/* wrapped texture creation */
mem3 = (GstMemory *) gst_gl_memory_pbo_wrapped_texture (context,
((GstGLMemory *) mem)->tex_id, GST_GL_TEXTURE_TARGET_2D, &v_info, 0, NULL,
params = gst_gl_video_allocation_params_new_wrapped_texture (context, NULL,
&v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D, ((GstGLMemory *) mem)->tex_id,
NULL, NULL);
mem3 =
(GstMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem3,
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (GST_MEMORY_FLAG_IS_SET (mem3,
@ -251,10 +272,19 @@ GST_START_TEST (test_transfer)
gst_object_unref (gl_allocator);
}
GST_START_TEST (test_transfer)
{
test_transfer_allocator (GST_GL_MEMORY_ALLOCATOR_NAME);
test_transfer_allocator (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
}
GST_END_TEST;
GST_START_TEST (test_separate_transfer)
{
GstGLBaseMemoryAllocator *base_mem_alloc;
GstGLVideoAllocationParams *params;
GstAllocator *gl_allocator;
GstVideoInfo v_info;
GstMemory *mem;
@ -262,12 +292,16 @@ GST_START_TEST (test_separate_transfer)
gl_allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
fail_if (gl_allocator == NULL);
base_mem_alloc = GST_GL_BASE_MEMORY_ALLOCATOR (gl_allocator);
gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA, 1, 1);
params = gst_gl_video_allocation_params_new_wrapped_data (context, NULL,
&v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D, rgba_pixel, NULL, NULL);
mem =
(GstMemory *) gst_gl_memory_pbo_wrapped (context,
GST_GL_TEXTURE_TARGET_2D, &v_info, 0, NULL, rgba_pixel, NULL, NULL);
(GstMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
fail_if (mem == NULL);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));

View file

@ -195,6 +195,8 @@ GST_END_TEST;
GST_START_TEST (test_upload_buffer)
{
GstGLBaseMemoryAllocator *base_mem_alloc;
GstGLVideoAllocationParams *params;
GstBuffer *buffer, *outbuf;
GstGLMemory *gl_mem;
GstCaps *in_caps, *out_caps;
@ -203,14 +205,20 @@ GST_START_TEST (test_upload_buffer)
gint i = 0;
gboolean res;
base_mem_alloc =
GST_GL_BASE_MEMORY_ALLOCATOR (gst_allocator_find
(GST_GL_MEMORY_ALLOCATOR_NAME));
in_caps = gst_caps_from_string ("video/x-raw,format=RGBA,width=10,height=10");
gst_video_info_from_caps (&in_info, in_caps);
/* create GL buffer */
buffer = gst_buffer_new ();
gl_mem =
(GstGLMemory *) gst_gl_memory_pbo_wrapped (context,
GST_GL_TEXTURE_TARGET_2D, &in_info, 0, NULL, rgba_data, NULL, NULL);
params = gst_gl_video_allocation_params_new_wrapped_data (context, NULL,
&in_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D, rgba_data, NULL, NULL);
gl_mem = (GstGLMemory *) gst_gl_base_memory_alloc (base_mem_alloc,
(GstGLAllocationParams *) params);
gst_gl_allocation_params_free ((GstGLAllocationParams *) params);
res =
gst_memory_map ((GstMemory *) gl_mem, &map_info,
@ -245,6 +253,7 @@ GST_START_TEST (test_upload_buffer)
gst_caps_unref (out_caps);
gst_buffer_unref (buffer);
gst_buffer_unref (outbuf);
gst_object_unref (base_mem_alloc);
}
GST_END_TEST;