summaryrefslogtreecommitdiff
path: root/sys/ximage
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2012-08-10 16:58:47 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2012-08-10 16:58:47 +0200
commit9b3849db1ccf4f6b985d8fd1eeb0913ae44bc6be (patch)
tree01a69f1162544671c71fe92c1ad4e17981bd520f /sys/ximage
parentda4884a8341fa32ed4a31bb939e286f6d024af0a (diff)
x11: fix alignment in non-XSHM case
Align the allocated memory to 16 bytes. When doing XSHM we are already aligned to a page boundary but without, we use plain g_malloc, which could allocate aligned on 8 bytes only. See https://bugzilla.gnome.org/show_bug.cgi?id=680796
Diffstat (limited to 'sys/ximage')
-rw-r--r--sys/ximage/ximagepool.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/sys/ximage/ximagepool.c b/sys/ximage/ximagepool.c
index e0f41d43b..85f7d2d79 100644
--- a/sys/ximage/ximagepool.c
+++ b/sys/ximage/ximagepool.c
@@ -100,7 +100,7 @@ gst_buffer_add_ximage_meta (GstBuffer * buffer, GstXImageBufferPool * xpool)
gboolean success = FALSE;
GstXContext *xcontext;
GstXImageMeta *meta;
- gint width, height;
+ gint width, height, align = 15, offset;
GstXImageBufferPoolPrivate *priv;
priv = xpool->priv;
@@ -165,7 +165,8 @@ gst_buffer_add_ximage_meta (GstBuffer * buffer, GstXImageBufferPool * xpool)
meta->size, width, meta->ximage->bytes_per_line);
/* get shared memory */
- meta->SHMInfo.shmid = shmget (IPC_PRIVATE, meta->size, IPC_CREAT | 0777);
+ meta->SHMInfo.shmid =
+ shmget (IPC_PRIVATE, meta->size + align, IPC_CREAT | 0777);
if (meta->SHMInfo.shmid == -1)
goto shmget_failed;
@@ -218,7 +219,7 @@ gst_buffer_add_ximage_meta (GstBuffer * buffer, GstXImageBufferPool * xpool)
allocsize =
GST_ROUND_UP_4 (meta->ximage->bytes_per_line) * meta->ximage->height;
- meta->ximage->data = g_malloc (allocsize);
+ meta->ximage->data = g_malloc (allocsize + align);
GST_LOG_OBJECT (ximagesink,
"non-XShm image size is %" G_GSIZE_FORMAT " (alloced: %u), width %d, "
"stride %d", meta->size, allocsize, width,
@@ -227,13 +228,19 @@ gst_buffer_add_ximage_meta (GstBuffer * buffer, GstXImageBufferPool * xpool)
XSync (xcontext->disp, FALSE);
}
+ if ((offset = ((guintptr) meta->ximage->data & align)))
+ offset = (align + 1) - offset;
+
+ GST_DEBUG_OBJECT (ximagesink, "memory %p, align %d, offset %d",
+ meta->ximage->data, align, offset);
+
/* Reset error handler */
error_caught = FALSE;
XSetErrorHandler (handler);
gst_buffer_append_memory (buffer,
gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, meta->ximage->data,
- meta->size, 0, meta->size, NULL, NULL));
+ meta->size + align, offset, meta->size, NULL, NULL));
g_mutex_unlock (ximagesink->x_lock);