sys/xvimage/xvimagesink.c:

Original commit message from CVS:
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_destroy):
fix for non-shm xv. Original patch by Tim Ringenbach (fixes #147248)
This commit is contained in:
Tim Ringenbach 2004-07-15 21:18:11 +00:00 committed by Benjamin Otte
parent f4bbdba991
commit 5acca27963
2 changed files with 28 additions and 17 deletions

View File

@ -1,3 +1,9 @@
2004-07-15 Benjamin Otte <otte@gnome.org>
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_destroy):
fix for non-shm xv. Original patch by Tim Ringenbach (fixes #147248)
2004-07-15 Benjamin Otte <otte@gnome.org> 2004-07-15 Benjamin Otte <otte@gnome.org>
* ext/alsa/gstalsa.c: (gst_alsa_open_audio), * ext/alsa/gstalsa.c: (gst_alsa_open_audio),

View File

@ -109,15 +109,19 @@ gst_xvimagesink_handle_xerror (Display * display, XErrorEvent * xevent)
static gboolean static gboolean
gst_xvimagesink_check_xshm_calls (GstXContext * xcontext) gst_xvimagesink_check_xshm_calls (GstXContext * xcontext)
{ {
#ifndef HAVE_XSHM
return FALSE;
#else
GstXvImage *xvimage = NULL; GstXvImage *xvimage = NULL;
int (*handler) (Display *, XErrorEvent *); int (*handler) (Display *, XErrorEvent *);
gboolean result = FALSE;
g_return_val_if_fail (xcontext != NULL, FALSE); g_return_val_if_fail (xcontext != NULL, FALSE);
#ifdef HAVE_XSHM
xvimage = g_new0 (GstXvImage, 1); xvimage = g_new0 (GstXvImage, 1);
/* Setting an error handler to catch failure */ /* Setting an error handler to catch failure */
error_caught = FALSE;
handler = XSetErrorHandler (gst_xvimagesink_handle_xerror); handler = XSetErrorHandler (gst_xvimagesink_handle_xerror);
xvimage->size = (xcontext->bpp / 8); xvimage->size = (xcontext->bpp / 8);
@ -125,6 +129,8 @@ gst_xvimagesink_check_xshm_calls (GstXContext * xcontext)
/* Trying to create a 1x1 picture */ /* Trying to create a 1x1 picture */
xvimage->xvimage = XvShmCreateImage (xcontext->disp, xcontext->xv_port_id, xvimage->xvimage = XvShmCreateImage (xcontext->disp, xcontext->xv_port_id,
xcontext->im_format, NULL, 1, 1, &xvimage->SHMInfo); xcontext->im_format, NULL, 1, 1, &xvimage->SHMInfo);
if (!xvimage->xvimage)
goto out;
xvimage->SHMInfo.shmid = shmget (IPC_PRIVATE, xvimage->size, xvimage->SHMInfo.shmid = shmget (IPC_PRIVATE, xvimage->size,
IPC_CREAT | 0777); IPC_CREAT | 0777);
@ -134,32 +140,29 @@ gst_xvimagesink_check_xshm_calls (GstXContext * xcontext)
XShmAttach (xcontext->disp, &xvimage->SHMInfo); XShmAttach (xcontext->disp, &xvimage->SHMInfo);
error_caught = FALSE;
XSync (xcontext->disp, 0); XSync (xcontext->disp, 0);
XSetErrorHandler (handler); if (error_caught) {
/* Failed, detaching shared memory, destroying image and telling we can't
if (error_caught) { /* Failed, detaching shared memory, destroying image and telling we can't use XShm */
use XShm */
error_caught = FALSE; error_caught = FALSE;
XFree (xvimage->xvimage);
shmdt (xvimage->SHMInfo.shmaddr); shmdt (xvimage->SHMInfo.shmaddr);
shmctl (xvimage->SHMInfo.shmid, IPC_RMID, 0); shmctl (xvimage->SHMInfo.shmid, IPC_RMID, 0);
g_free (xvimage);
XSync (xcontext->disp, FALSE); XSync (xcontext->disp, FALSE);
return FALSE;
} else { } else {
XShmDetach (xcontext->disp, &xvimage->SHMInfo); XShmDetach (xcontext->disp, &xvimage->SHMInfo);
XFree (xvimage->xvimage);
shmdt (xvimage->SHMInfo.shmaddr); shmdt (xvimage->SHMInfo.shmaddr);
shmctl (xvimage->SHMInfo.shmid, IPC_RMID, 0); shmctl (xvimage->SHMInfo.shmid, IPC_RMID, 0);
g_free (xvimage); result = TRUE;
XSync (xcontext->disp, FALSE);
} }
out:
XSetErrorHandler (handler);
if (xvimage->xvimage)
XFree (xvimage->xvimage);
g_free (xvimage);
XSync (xcontext->disp, FALSE);
return result;
#endif /* HAVE_XSHM */ #endif /* HAVE_XSHM */
return TRUE;
} }
/* This function handles GstXvImage creation depending on XShm availability */ /* This function handles GstXvImage creation depending on XShm availability */
@ -212,7 +215,7 @@ gst_xvimagesink_xvimage_new (GstXvImageSink * xvimagesink,
xvimagesink->xcontext->im_format, xvimagesink->xcontext->im_format,
xvimage->data, xvimage->width, xvimage->height); xvimage->data, xvimage->width, xvimage->height);
xvimage->data = g_malloc (xvimage->xvimage->data_size); xvimage->xvimage->data = g_malloc (xvimage->xvimage->data_size);
XSync (xvimagesink->xcontext->disp, FALSE); XSync (xvimagesink->xcontext->disp, FALSE);
} }
@ -261,8 +264,10 @@ gst_xvimagesink_xvimage_destroy (GstXvImageSink * xvimagesink,
} else } else
#endif /* HAVE_XSHM */ #endif /* HAVE_XSHM */
{ {
if (xvimage->xvimage) if (xvimage->xvimage) {
g_free (xvimage->xvimage->data);
XFree (xvimage->xvimage); XFree (xvimage->xvimage);
}
} }
XSync (xvimagesink->xcontext->disp, FALSE); XSync (xvimagesink->xcontext->disp, FALSE);