summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.net>2007-05-03 16:29:10 +0000
committerTim-Philipp Müller <tim@centricular.net>2007-05-03 16:29:10 +0000
commitcb73a6e792fa12257573a9ad47489d92f48b52ab (patch)
treea08984d49da43736844fb8e801fbd1637d017025 /sys
parent03e4592e41fd4738407bffeb8439ed7cd116e9d4 (diff)
sys/ximage/ximagesink.c: When XShm is not available, we might get row strides that are not rounded up to multiples of...
Original commit message from CVS: * sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new): When XShm is not available, we might get row strides that are not rounded up to multiples of four; this is bad, because virtually every RGB-processing element in GStreamer assumes rowstrides are rounded up to multiples of four, so let's allocate at least enough memory to avoid crashes in this case. The image will still be displayed distorted though if this happens, so that still needs fixing (maybe by allocating a bigger image with an 'even' width and then clipping it appropriately when rendering - something for Xlib aficionados in any case).
Diffstat (limited to 'sys')
-rw-r--r--sys/ximage/ximagesink.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c
index af50cc0f..321a1fc0 100644
--- a/sys/ximage/ximagesink.c
+++ b/sys/ximage/ximagesink.c
@@ -500,6 +500,8 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps)
} else
#endif /* HAVE_XSHM */
{
+ guint allocsize;
+
ximage->ximage = XCreateImage (ximagesink->xcontext->disp,
ximagesink->xcontext->visual,
ximagesink->xcontext->depth,
@@ -519,9 +521,27 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps)
goto beach;
}
+ /* upstream will assume that rowstrides are multiples of 4, but this
+ * doesn't always seem to be the case with XCreateImage() */
+ if ((ximage->ximage->bytes_per_line % 4) != 0) {
+ GST_WARNING_OBJECT (ximagesink, "returned stride not a multiple of 4 as "
+ "usually assumed");
+ }
+
/* we have to use the returned bytes_per_line for our image size */
ximage->size = ximage->ximage->bytes_per_line * ximage->ximage->height;
- ximage->ximage->data = g_malloc (ximage->size);
+
+ /* alloc a bit more for unexpected strides to avoid crashes upstream.
+ * FIXME: if we get an unrounded stride, the image will be displayed
+ * distorted, since all upstream elements assume a rounded stride */
+ allocsize =
+ GST_ROUND_UP_4 (ximage->ximage->bytes_per_line) *
+ ximage->ximage->height;
+ ximage->ximage->data = g_malloc (allocsize);
+ GST_LOG_OBJECT (ximagesink,
+ "non-XShm image size is %" G_GSIZE_FORMAT " (alloced: %u), width %d, "
+ "stride %d", ximage->size, allocsize, ximage->width,
+ ximage->ximage->bytes_per_line);
XSync (ximagesink->xcontext->disp, FALSE);
}