sys/ximage/ximagesink.c: Improve the errors produced on bad output, including some human readable description strings.

Original commit message from CVS:
* sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new),
(gst_ximagesink_xcontext_get), (gst_ximagesink_show_frame):
Improve the errors produced on bad output, including some human
readable description strings.
Handle the (theoretical for ximagesink) case where the XServer
has a different idea about the size required for a particular
frame and gives us too small a memory allocation.
This commit is contained in:
Jan Schmidt 2006-05-26 11:17:57 +00:00
parent 58ae1bccaf
commit 63bd38cd2b
2 changed files with 43 additions and 12 deletions

View file

@ -1,3 +1,13 @@
2006-05-26 Jan Schmidt <thaytan@mad.scientist.com>
* sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new),
(gst_ximagesink_xcontext_get), (gst_ximagesink_show_frame):
Improve the errors produced on bad output, including some human
readable description strings.
Handle the (theoretical for ximagesink) case where the XServer
has a different idea about the size required for a particular
frame and gives us too small a memory allocation.
2006-05-26 Jan Schmidt <thaytan@mad.scientist.com>
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_xvimage_new),

View file

@ -418,8 +418,11 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps)
ximagesink->xcontext->depth,
ZPixmap, NULL, &ximage->SHMInfo, ximage->width, ximage->height);
if (!ximage->ximage) {
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE, (NULL),
("could not XShmCreateImage a %dx%d image"));
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
("Failed to create output image buffer of %dx%d pixels",
ximage->width, ximage->height),
("could not XShmCreateImage a %dx%d image",
ximage->width, ximage->height));
goto beach;
}
@ -431,14 +434,18 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps)
ximage->SHMInfo.shmid = shmget (IPC_PRIVATE, ximage->size,
IPC_CREAT | 0777);
if (ximage->SHMInfo.shmid == -1) {
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE, (NULL),
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
("Failed to create output image buffer of %dx%d pixels",
ximage->width, ximage->height),
("could not get shared memory of %d bytes", ximage->size));
goto beach;
}
ximage->SHMInfo.shmaddr = shmat (ximage->SHMInfo.shmid, 0, 0);
if (ximage->SHMInfo.shmaddr == ((void *) -1)) {
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE, (NULL),
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
("Failed to create output image buffer of %dx%d pixels",
ximage->width, ximage->height),
("Failed to shmat: %s", g_strerror (errno)));
/* Clean up the shared memory segment */
shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0);
@ -454,8 +461,9 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps)
ximage->SHMInfo.readOnly = FALSE;
if (XShmAttach (ximagesink->xcontext->disp, &ximage->SHMInfo) == 0) {
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE, (NULL),
("Failed to XShmAttach"));
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
("Failed to create output image buffer of %dx%d pixels",
ximage->width, ximage->height), ("Failed to XShmAttach"));
goto beach;
}
@ -469,8 +477,11 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps)
ZPixmap, 0, NULL,
ximage->width, ximage->height, ximagesink->xcontext->bpp, 0);
if (!ximage->ximage) {
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE, (NULL),
("could not XCreateImage a %dx%d image"));
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
("Failed to create output image buffer of %dx%d pixels",
ximage->width, ximage->height),
("could not XCreateImage a %dx%d image",
ximage->width, ximage->height));
goto beach;
}
@ -1022,8 +1033,8 @@ gst_ximagesink_xcontext_get (GstXImageSink * ximagesink)
if (!xcontext->disp) {
g_mutex_unlock (ximagesink->x_lock);
g_free (xcontext);
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE, (NULL),
("Could not open display"));
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
("Could not initialise X output"), ("Could not open display"));
return NULL;
}
@ -1423,7 +1434,19 @@ gst_ximagesink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
ximagesink->ximage = gst_ximagesink_ximage_new (ximagesink,
GST_BUFFER_CAPS (buf));
if (!ximagesink->ximage)
/* The create method should have posted an informative error */
goto no_ximage;
if (ximagesink->ximage->size < GST_BUFFER_SIZE (buf)) {
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
("Failed to create output image buffer of %dx%d pixels",
ximagesink->ximage->width, ximagesink->ximage->height),
("XServer allocated buffer size did not match input buffer"));
gst_ximagesink_ximage_destroy (ximagesink, ximagesink->ximage);
ximagesink->ximage = NULL;
goto no_ximage;
}
}
memcpy (GST_BUFFER_DATA (ximagesink->ximage), GST_BUFFER_DATA (buf),
MIN (GST_BUFFER_SIZE (buf), ximagesink->ximage->size));
@ -1437,8 +1460,6 @@ no_ximage:
{
/* No image available. That's very bad ! */
GST_DEBUG ("could not create image");
GST_ELEMENT_ERROR (ximagesink, CORE, NEGOTIATION, (NULL),
("Failed creating an XImage in ximagesink chain function."));
return GST_FLOW_ERROR;
}
}