summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJan Schmidt <thaytan@mad.scientist.com>2008-07-17 13:57:33 +0000
committerJan Schmidt <thaytan@mad.scientist.com>2008-07-17 13:57:33 +0000
commit6d641640bba89c4070bced561da937535a868129 (patch)
treec864bc935a21d1fd6439b7ff2f484226ca3485a2 /sys
parentcc74285d1280852887c6a4107c657968bdbd2e34 (diff)
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/ximage/ximagesink.c26
-rw-r--r--sys/xvimage/xvimagesink.c37
2 files changed, 39 insertions, 24 deletions
diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c
index 0f530af4..220d306a 100644
--- a/sys/ximage/ximagesink.c
+++ b/sys/ximage/ximagesink.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 */
{
diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c
index 966cb847..acc5a8b0 100644
--- a/sys/xvimage/xvimagesink.c
+++ b/sys/xvimage/xvimagesink.c
@@ -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