From 3c2574998b34778e979a5e6982ffab4925f1aff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 26 Dec 2012 10:34:21 +0100 Subject: [PATCH] eglglessink: Fix crash when closing internal X11 window --- ext/eglgles/gsteglglessink.c | 4 ++-- ext/eglgles/gsteglglessink.h | 2 ++ ext/eglgles/video_platform_wrapper.c | 27 +++++++++++++++++++++------ ext/eglgles/video_platform_wrapper.h | 6 ++---- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ext/eglgles/gsteglglessink.c b/ext/eglgles/gsteglglessink.c index 185fe754dd..c0689de7b1 100644 --- a/ext/eglgles/gsteglglessink.c +++ b/ext/eglgles/gsteglglessink.c @@ -810,7 +810,7 @@ gst_eglglessink_stop (GstEglGlesSink * eglglessink) if (eglglessink->using_own_window) { platform_destroy_native_window (eglglessink->eglglesctx.display, - eglglessink->eglglesctx.used_window); + eglglessink->eglglesctx.used_window, &eglglessink->own_window_data); eglglessink->eglglesctx.used_window = 0; eglglessink->have_window = FALSE; } @@ -866,7 +866,7 @@ gst_eglglessink_create_window (GstEglGlesSink * eglglessink, gint width, } else GST_INFO_OBJECT (eglglessink, "Attempting internal window creation"); - window = platform_create_native_window (width, height); + window = platform_create_native_window (width, height, &eglglessink->own_window_data); if (!window) { GST_ERROR_OBJECT (eglglessink, "Could not create window"); return window; diff --git a/ext/eglgles/gsteglglessink.h b/ext/eglgles/gsteglglessink.h index d24273be1a..caa4d246f0 100644 --- a/ext/eglgles/gsteglglessink.h +++ b/ext/eglgles/gsteglglessink.h @@ -204,6 +204,8 @@ struct _GstEglGlesSink gboolean have_texture; gboolean egl_started; + gpointer own_window_data; + GThread *thread; gboolean thread_running; GstDataQueue *queue; diff --git a/ext/eglgles/video_platform_wrapper.c b/ext/eglgles/video_platform_wrapper.c index 8fab9d6f92..1cea3a4d4b 100644 --- a/ext/eglgles/video_platform_wrapper.c +++ b/ext/eglgles/video_platform_wrapper.c @@ -73,13 +73,17 @@ platform_wrapper_init (void) } #ifdef HAVE_X11 +typedef struct { + Display *display; +} X11WindowData; + EGLNativeWindowType -platform_create_native_window (gint width, gint height) +platform_create_native_window (gint width, gint height, gpointer * window_data) { Display *d; Window w; - //XEvent e; int s; + X11WindowData *data; d = XOpenDisplay (NULL); if (d == NULL) { @@ -93,15 +97,26 @@ platform_create_native_window (gint width, gint height) XStoreName (d, w, "eglglessink"); XMapWindow (d, w); XFlush (d); + + *window_data = data = g_slice_new0 (X11WindowData); + data->display = d; + return (EGLNativeWindowType) w; } gboolean platform_destroy_native_window (EGLNativeDisplayType display, - EGLNativeWindowType window) + EGLNativeWindowType window, gpointer * window_data) { + X11WindowData *data = *window_data; + /* XXX: Should proly catch BadWindow */ - XDestroyWindow (display, window); + XDestroyWindow (data->display, window); + XSync (data->display, FALSE); + XCloseDisplay (data->display); + + g_slice_free (X11WindowData, data); + *window_data = NULL; return TRUE; } #endif @@ -109,7 +124,7 @@ platform_destroy_native_window (EGLNativeDisplayType display, #if !defined(HAVE_X11) /* Dummy functions for creating a native Window */ EGLNativeWindowType -platform_create_native_window (gint width, gint height) +platform_create_native_window (gint width, gint height, gpointer * window_data) { GST_ERROR ("Can't create native window"); return (EGLNativeWindowType) 0; @@ -117,7 +132,7 @@ platform_create_native_window (gint width, gint height) gboolean platform_destroy_native_window (EGLNativeDisplayType display, - EGLNativeWindowType window) + EGLNativeWindowType window, gpointer * window_data) { GST_ERROR ("Can't destroy native window"); return TRUE; diff --git a/ext/eglgles/video_platform_wrapper.h b/ext/eglgles/video_platform_wrapper.h index aabb8ebefc..c348aef624 100644 --- a/ext/eglgles/video_platform_wrapper.h +++ b/ext/eglgles/video_platform_wrapper.h @@ -54,11 +54,9 @@ #include gboolean platform_wrapper_init (void); -EGLNativeWindowType platform_create_native_window (gint width, gint height); +EGLNativeWindowType platform_create_native_window (gint width, gint height, gpointer * window_data); gboolean platform_destroy_native_window (EGLNativeDisplayType display, - EGLNativeWindowType w); -EGLint *platform_crate_native_image_buffer (EGLNativeWindowType win, - EGLConfig config, EGLNativeDisplayType display, const EGLint * egl_attribs); + EGLNativeWindowType w, gpointer * window_data); #endif