From 957b4cf08bfba9de7a88f99e6687a7a483062269 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Mon, 3 Jun 2013 18:15:45 +1000 Subject: [PATCH] [692/906] window_x11: add XError trapping some functions in GLX can fail if the implementation does not support certain features we ask for (i.e. GL 3) bringing down the entire application --- gst-libs/gst/gl/x11/gstglwindow_x11.c | 74 ++++++++++++++++++++++++++--------- gst-libs/gst/gl/x11/gstglwindow_x11.h | 3 ++ 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/gst-libs/gst/gl/x11/gstglwindow_x11.c b/gst-libs/gst/gl/x11/gstglwindow_x11.c index 982297e..c52a334 100644 --- a/gst-libs/gst/gl/x11/gstglwindow_x11.c +++ b/gst-libs/gst/gl/x11/gstglwindow_x11.c @@ -45,6 +45,10 @@ #define gst_gl_window_x11_parent_class parent_class G_DEFINE_ABSTRACT_TYPE (GstGLWindowX11, gst_gl_window_x11, GST_GL_TYPE_WINDOW); +/* X error trap */ +static int TrappedErrorCode = 0; +static int (*old_error_handler) (Display *, XErrorEvent *); + enum { ARG_0, @@ -607,13 +611,13 @@ gst_gl_window_x11_run (GstGLWindow * window) if (window_x11->running) { #if SIZEOF_VOID_P == 8 GstGLWindowCB custom_cb = - (GstGLWindowCB) (((event.xclient.data. - l[0] & 0xffffffff) << 32) | (event.xclient.data. - l[1] & 0xffffffff)); + (GstGLWindowCB) (((event.xclient. + data.l[0] & 0xffffffff) << 32) | (event.xclient. + data.l[1] & 0xffffffff)); gpointer custom_data = - (gpointer) (((event.xclient.data. - l[2] & 0xffffffff) << 32) | (event.xclient.data. - l[3] & 0xffffffff)); + (gpointer) (((event.xclient. + data.l[2] & 0xffffffff) << 32) | (event.xclient. + data.l[3] & 0xffffffff)); #else GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0]; gpointer custom_data = (gpointer) event.xclient.data.l[1]; @@ -642,13 +646,13 @@ gst_gl_window_x11_run (GstGLWindow * window) && event.xclient.message_type == wm_quit_loop) { #if SIZEOF_VOID_P == 8 GstGLWindowCB destroy_cb = - (GstGLWindowCB) (((event.xclient.data. - l[0] & 0xffffffff) << 32) | (event.xclient.data. - l[1] & 0xffffffff)); + (GstGLWindowCB) (((event.xclient. + data.l[0] & 0xffffffff) << 32) | (event.xclient. + data.l[1] & 0xffffffff)); gpointer destroy_data = - (gpointer) (((event.xclient.data. - l[2] & 0xffffffff) << 32) | (event.xclient.data. - l[3] & 0xffffffff)); + (gpointer) (((event.xclient. + data.l[2] & 0xffffffff) << 32) | (event.xclient. + data.l[3] & 0xffffffff)); #else GstGLWindowCB destroy_cb = (GstGLWindowCB) event.xclient.data.l[0]; gpointer destroy_data = (gpointer) event.xclient.data.l[1]; @@ -666,13 +670,13 @@ gst_gl_window_x11_run (GstGLWindow * window) &pending_event)) { #if SIZEOF_VOID_P == 8 GstGLWindowCB custom_cb = - (GstGLWindowCB) (((event.xclient.data. - l[0] & 0xffffffff) << 32) | (event.xclient.data. - l[1] & 0xffffffff)); + (GstGLWindowCB) (((event.xclient. + data.l[0] & 0xffffffff) << 32) | (event.xclient. + data.l[1] & 0xffffffff)); gpointer custom_data = - (gpointer) (((event.xclient.data. - l[2] & 0xffffffff) << 32) | (event.xclient.data. - l[3] & 0xffffffff)); + (gpointer) (((event.xclient. + data.l[2] & 0xffffffff) << 32) | (event.xclient. + data.l[3] & 0xffffffff)); #else GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0]; gpointer custom_data = (gpointer) event.xclient.data.l[1]; @@ -826,3 +830,37 @@ gst_gl_window_x11_send_message (GstGLWindow * window, GstGLWindowCB callback, GST_GL_WINDOW_GET_LOCK (window)); } } + +static int +error_handler (Display * xdpy, XErrorEvent * error) +{ + TrappedErrorCode = error->error_code; + return 0; +} + +/** + * gst_gl_window_x11_trap_x_errors: + * + * Traps every X error until gst_gl_window_x11_untrap_x_errors() is called. + */ +void +gst_gl_window_x11_trap_x_errors (void) +{ + TrappedErrorCode = 0; + old_error_handler = XSetErrorHandler (error_handler); +} + +/** + * gst_gl_window_x11_untrap_x_errors: + * + * Removes the X error trap and returns the current status. + * + * Return value: the trapped error code, or 0 for success + */ +gint +gst_gl_window_x11_untrap_x_errors (void) +{ + XSetErrorHandler (old_error_handler); + + return TrappedErrorCode; +} diff --git a/gst-libs/gst/gl/x11/gstglwindow_x11.h b/gst-libs/gst/gl/x11/gstglwindow_x11.h index 8ce25f1..8271640 100644 --- a/gst-libs/gst/gl/x11/gstglwindow_x11.h +++ b/gst-libs/gst/gl/x11/gstglwindow_x11.h @@ -97,6 +97,9 @@ GType gst_gl_window_x11_get_type (void); GstGLWindowX11 * gst_gl_window_x11_new (void); +void gst_gl_window_x11_trap_x_errors (void); +gint gst_gl_window_x11_untrap_x_errors (void); + G_END_DECLS #endif /* __GST_GL_WINDOW_X11_H__ */ -- 2.7.4