From: Matthew Waters Date: Tue, 15 Dec 2015 03:14:36 +0000 (+1100) Subject: glbasememory: don't unconditionally add the alignment bytes to the size X-Git-Tag: 1.19.3~507^2~7389 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8dacd50bfc8f7b94793089b3c38dac2ae52174d;p=platform%2Fupstream%2Fgstreamer.git glbasememory: don't unconditionally add the alignment bytes to the size e.g when wrapping a data pointer we don't want to map/unmap off the end of pointer with the alignment bytes. Instead track that information separately as maxsize is used for mapping by GstMemory and thus represents a size without any alignment padding bytes. --- diff --git a/gst-libs/gst/gl/gstglbasememory.c b/gst-libs/gst/gl/gstglbasememory.c index a93ffb8..a55603a 100644 --- a/gst-libs/gst/gl/gstglbasememory.c +++ b/gst-libs/gst/gl/gstglbasememory.c @@ -109,15 +109,39 @@ gst_gl_base_memory_init (GstGLBaseMemory * mem, GstAllocator * allocator, GstMemory * parent, GstGLContext * context, GstAllocationParams * params, gsize size, gpointer user_data, GDestroyNotify notify) { - gsize align = gst_memory_alignment, offset = 0, maxsize = size; + gsize align = gst_memory_alignment, offset = 0, maxsize; GstMemoryFlags flags = 0; struct create_data data; + /* A note on sizes. + * gl_mem->alloc_size: the size to allocate when we control the allocation. + * Size of the unaligned allocation. + * mem->maxsize: the size that is used by GstMemory for mapping, to map the + * entire memory. The size of the aligned allocation + * mem->size: represents the size of the valid data. Can be reduced with + * gst_memory_resize() + * + * It holds that: + * mem->size + mem->offset <= mem->maxsize + * and + * mem->maxsize + alignment offset <= gl_mem->alloc_size + * + * We need to add the alignment mask to the allocated size in order to have + * the freedom to align the gl_mem->data pointer correctly which may be offset + * by at most align bytes in the alloc_data pointer. + * + * maxsize is not suitable for this as it is used by GstMemory as the size + * to map with. + */ + mem->alloc_size = maxsize = size; if (params) { flags = params->flags; align |= params->align; offset = params->prefix; - maxsize += params->prefix + params->padding + align; + maxsize += params->prefix + params->padding; + + /* deals with any alignment */ + mem->alloc_size = maxsize + align; } gst_memory_init (GST_MEMORY_CAST (mem), flags, allocator, parent, maxsize, @@ -168,8 +192,8 @@ gst_gl_base_memory_alloc_data (GstGLBaseMemory * gl_mem) return TRUE; GST_CAT_LOG (GST_CAT_GL_BASE_MEMORY, "%p attempting allocation of data " - "pointer of size %" G_GSIZE_FORMAT, gl_mem, mem->maxsize); - gl_mem->alloc_data = g_try_malloc (mem->maxsize); + "pointer of size %" G_GSIZE_FORMAT, gl_mem, gl_mem->alloc_size); + gl_mem->alloc_data = g_try_malloc (gl_mem->alloc_size); if (gl_mem->alloc_data == NULL) return FALSE; diff --git a/gst-libs/gst/gl/gstglbasememory.h b/gst-libs/gst/gl/gstglbasememory.h index 6ecf40b..ad9f68f 100644 --- a/gst-libs/gst/gl/gstglbasememory.h +++ b/gst-libs/gst/gl/gstglbasememory.h @@ -91,6 +91,7 @@ struct _GstGLBaseMemory gpointer data; /* */ + gsize alloc_size; /* because maxsize is used for mapping */ gpointer alloc_data; GDestroyNotify notify;