From 6d641640bba89c4070bced561da937535a868129 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Thu, 17 Jul 2008 13:57:33 +0000 Subject: [PATCH] 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. --- ChangeLog | 12 ++++++++++++ sys/ximage/ximagesink.c | 26 ++++++++++++++++---------- sys/xvimage/xvimagesink.c | 37 +++++++++++++++++++++++-------------- 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae1986c..cb326f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-07-17 Jan Schmidt + + * 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 * gst/audiotestsrc/gstaudiotestsrc.c: diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c index 0f530af..220d306 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 966cb84..acc5a8b 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 -- 2.7.4