mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
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
This commit is contained in:
parent
da4884a834
commit
9b3849db1c
2 changed files with 22 additions and 8 deletions
sys
|
@ -100,7 +100,7 @@ gst_buffer_add_ximage_meta (GstBuffer * buffer, GstXImageBufferPool * xpool)
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
GstXContext *xcontext;
|
GstXContext *xcontext;
|
||||||
GstXImageMeta *meta;
|
GstXImageMeta *meta;
|
||||||
gint width, height;
|
gint width, height, align = 15, offset;
|
||||||
GstXImageBufferPoolPrivate *priv;
|
GstXImageBufferPoolPrivate *priv;
|
||||||
|
|
||||||
priv = xpool->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);
|
meta->size, width, meta->ximage->bytes_per_line);
|
||||||
|
|
||||||
/* get shared memory */
|
/* 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)
|
if (meta->SHMInfo.shmid == -1)
|
||||||
goto shmget_failed;
|
goto shmget_failed;
|
||||||
|
|
||||||
|
@ -218,7 +219,7 @@ gst_buffer_add_ximage_meta (GstBuffer * buffer, GstXImageBufferPool * xpool)
|
||||||
allocsize =
|
allocsize =
|
||||||
GST_ROUND_UP_4 (meta->ximage->bytes_per_line) * meta->ximage->height;
|
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,
|
GST_LOG_OBJECT (ximagesink,
|
||||||
"non-XShm image size is %" G_GSIZE_FORMAT " (alloced: %u), width %d, "
|
"non-XShm image size is %" G_GSIZE_FORMAT " (alloced: %u), width %d, "
|
||||||
"stride %d", meta->size, allocsize, width,
|
"stride %d", meta->size, allocsize, width,
|
||||||
|
@ -227,13 +228,19 @@ gst_buffer_add_ximage_meta (GstBuffer * buffer, GstXImageBufferPool * xpool)
|
||||||
XSync (xcontext->disp, FALSE);
|
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 */
|
/* Reset error handler */
|
||||||
error_caught = FALSE;
|
error_caught = FALSE;
|
||||||
XSetErrorHandler (handler);
|
XSetErrorHandler (handler);
|
||||||
|
|
||||||
gst_buffer_append_memory (buffer,
|
gst_buffer_append_memory (buffer,
|
||||||
gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, meta->ximage->data,
|
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);
|
g_mutex_unlock (ximagesink->x_lock);
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ gst_buffer_add_xvimage_meta (GstBuffer * buffer, GstXvImageBufferPool * xvpool)
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
GstXContext *xcontext;
|
GstXContext *xcontext;
|
||||||
GstXvImageMeta *meta;
|
GstXvImageMeta *meta;
|
||||||
gint width, height, im_format;
|
gint width, height, im_format, align = 15, offset;
|
||||||
GstXvImageBufferPoolPrivate *priv;
|
GstXvImageBufferPoolPrivate *priv;
|
||||||
|
|
||||||
priv = xvpool->priv;
|
priv = xvpool->priv;
|
||||||
|
@ -220,7 +220,8 @@ gst_buffer_add_xvimage_meta (GstBuffer * buffer, GstXvImageBufferPool * xvpool)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get shared memory */
|
/* 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)
|
if (meta->SHMInfo.shmid == -1)
|
||||||
goto shmget_failed;
|
goto shmget_failed;
|
||||||
|
|
||||||
|
@ -256,18 +257,24 @@ gst_buffer_add_xvimage_meta (GstBuffer * buffer, GstXvImageBufferPool * xvpool)
|
||||||
|
|
||||||
/* we have to use the returned data_size for our image size */
|
/* we have to use the returned data_size for our image size */
|
||||||
meta->size = meta->xvimage->data_size;
|
meta->size = meta->xvimage->data_size;
|
||||||
meta->xvimage->data = g_malloc (meta->size);
|
meta->xvimage->data = g_malloc (meta->size + align);
|
||||||
|
|
||||||
XSync (xcontext->disp, FALSE);
|
XSync (xcontext->disp, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((offset = ((guintptr) meta->xvimage->data & align)))
|
||||||
|
offset = (align + 1) - offset;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (xvimagesink, "memory %p, align %d, offset %d",
|
||||||
|
meta->xvimage->data, align, offset);
|
||||||
|
|
||||||
/* Reset error handler */
|
/* Reset error handler */
|
||||||
error_caught = FALSE;
|
error_caught = FALSE;
|
||||||
XSetErrorHandler (handler);
|
XSetErrorHandler (handler);
|
||||||
|
|
||||||
gst_buffer_append_memory (buffer,
|
gst_buffer_append_memory (buffer,
|
||||||
gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, meta->xvimage->data,
|
gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, meta->xvimage->data,
|
||||||
meta->size, 0, meta->size, NULL, NULL));
|
meta->size + align, offset, meta->size, NULL, NULL));
|
||||||
|
|
||||||
g_mutex_unlock (xvimagesink->x_lock);
|
g_mutex_unlock (xvimagesink->x_lock);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue