Commit 6d641640 authored by Jan Schmidt's avatar Jan Schmidt
Browse files

sys/: it's not legal to ask the

Original commit message from CVS:
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new):
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new):
Apparently on Solaris and OS/X (at least), it's not legal to ask the
X server to attach to a shared memory segment after we've deleted it,
with the result that MIT-SHM is disabled. Instead, remove it only after
X succeeds in attaching too.
parent cc74285d
2008-07-17 Jan Schmidt <Jan.Schmidt@sun.com>
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new):
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new):
Apparently on Solaris and OS/X (at least), it's not legal to ask the
X server to attach to a shared memory segment after we've deleted it,
with the result that MIT-SHM is disabled. Instead, remove it only after
X succeeds in attaching too.
2008-07-16 David Schleef <ds@schleef.org>
 
* gst/audiotestsrc/gstaudiotestsrc.c:
......@@ -361,22 +361,24 @@ gst_ximagesink_check_xshm_calls (GstXImageSink * ximagesink,
goto beach;
}
/* Delete the shared memory segment as soon as we manage to attach.
* This way, it will be deleted as soon as we detach later, and not
* leaked if we crash. */
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
ximage->data = SHMInfo.shmaddr;
SHMInfo.readOnly = FALSE;
if (XShmAttach (xcontext->disp, &SHMInfo) == 0) {
GST_WARNING ("Failed to XShmAttach");
/* Clean up shm seg */
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
goto beach;
}
/* Sync to ensure we see any errors we caused */
XSync (xcontext->disp, FALSE);
/* Delete the shared memory segment as soon as everyone is attached.
* This way, it will be deleted as soon as we detach later, and not
* leaked if we crash. */
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
if (!error_caught) {
did_attach = TRUE;
/* store whether we succeeded in result */
......@@ -480,15 +482,13 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps)
goto beach;
}
/* Now that we've attached, we can delete the shared memory segment.
* This way, it will be deleted as soon as we detach later, and not
* leaked if we crash. */
shmctl (ximage->SHMInfo.shmid, IPC_RMID, NULL);
ximage->ximage->data = ximage->SHMInfo.shmaddr;
ximage->SHMInfo.readOnly = FALSE;
if (XShmAttach (ximagesink->xcontext->disp, &ximage->SHMInfo) == 0) {
/* Clean up shm seg */
shmctl (ximage->SHMInfo.shmid, IPC_RMID, NULL);
g_mutex_unlock (ximagesink->x_lock);
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
("Failed to create output image buffer of %dx%d pixels",
......@@ -497,6 +497,12 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps)
}
XSync (ximagesink->xcontext->disp, FALSE);
/* Now that everyone has attached, we can delete the shared memory segment.
* This way, it will be deleted as soon as we detach later, and not
* leaked if we crash. */
shmctl (ximage->SHMInfo.shmid, IPC_RMID, NULL);
} else
#endif /* HAVE_XSHM */
{
......
......@@ -426,9 +426,9 @@ gst_xvimagesink_check_xshm_calls (GstXContext * xcontext)
handler = XSetErrorHandler (gst_xvimagesink_handle_xerror);
/* Trying to create a 1x1 picture */
GST_DEBUG ("XvShmCreateImage of 1x1");
GST_DEBUG ("XvShmCreateImage of 100x100");
xvimage = XvShmCreateImage (xcontext->disp, xcontext->xv_port_id,
xcontext->im_format, NULL, 1, 1, &SHMInfo);
xcontext->im_format, NULL, 100, 100, &SHMInfo);
/* Might cause an error, sync to ensure it is noticed */
XSync (xcontext->disp, FALSE);
......@@ -452,29 +452,34 @@ gst_xvimagesink_check_xshm_calls (GstXContext * xcontext)
goto beach;
}
/* Delete the shared memory segment as soon as we manage to attach.
* This way, it will be deleted as soon as we detach later, and not
* leaked if we crash. */
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
xvimage->data = SHMInfo.shmaddr;
SHMInfo.readOnly = FALSE;
if (XShmAttach (xcontext->disp, &SHMInfo) == 0) {
GST_WARNING ("Failed to XShmAttach");
/* Clean up the shared memory segment */
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
goto beach;
}
/* Sync to ensure we see any errors we caused */
XSync (xcontext->disp, FALSE);
GST_DEBUG ("XServer ShmAttached to 0x%x, id 0x%lx", SHMInfo.shmid,
SHMInfo.shmseg);
/* Delete the shared memory segment as soon as everyone is attached.
* This way, it will be deleted as soon as we detach later, and not
* leaked if we crash. */
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
if (!error_caught) {
GST_DEBUG ("XServer ShmAttached to 0x%x, id 0x%lx", SHMInfo.shmid,
SHMInfo.shmseg);
did_attach = TRUE;
/* store whether we succeeded in result */
result = TRUE;
} else {
GST_WARNING ("MIT-SHM extension check failed at XShmAttach. "
"Not using shared memory.");
}
beach:
......@@ -626,15 +631,13 @@ gst_xvimagesink_xvimage_new (GstXvImageSink * xvimagesink, GstCaps * caps)
goto beach_unlocked;
}
/* Delete the shared memory segment as soon as we manage to attach.
* This way, it will be deleted as soon as we detach later, and not
* leaked if we crash. */
shmctl (xvimage->SHMInfo.shmid, IPC_RMID, NULL);
xvimage->xvimage->data = xvimage->SHMInfo.shmaddr;
xvimage->SHMInfo.readOnly = FALSE;
if (XShmAttach (xvimagesink->xcontext->disp, &xvimage->SHMInfo) == 0) {
/* Clean up the shared memory segment */
shmctl (xvimage->SHMInfo.shmid, IPC_RMID, NULL);
g_mutex_unlock (xvimagesink->x_lock);
GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
("Failed to create output image buffer of %dx%d pixels",
......@@ -643,6 +646,12 @@ gst_xvimagesink_xvimage_new (GstXvImageSink * xvimagesink, GstCaps * caps)
}
XSync (xvimagesink->xcontext->disp, FALSE);
/* Delete the shared memory segment as soon as we everyone is attached.
* This way, it will be deleted as soon as we detach later, and not
* leaked if we crash. */
shmctl (xvimage->SHMInfo.shmid, IPC_RMID, NULL);
GST_DEBUG_OBJECT (xvimagesink, "XServer ShmAttached to 0x%x, id 0x%lx",
xvimage->SHMInfo.shmid, xvimage->SHMInfo.shmseg);
} else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment