diff --git a/ext/gl/gstglimagesink.c b/ext/gl/gstglimagesink.c index db21faede5..15ab2846f3 100644 --- a/ext/gl/gstglimagesink.c +++ b/ext/gl/gstglimagesink.c @@ -2326,89 +2326,86 @@ static gboolean gst_glimage_sink_redisplay (GstGLImageSink * gl_sink) { GstGLWindow *window; - gboolean alive; GstBuffer *old_stored_buffer[2], *old_sync; + gulong handler_id; window = gst_gl_context_get_window (gl_sink->context); if (!window) return FALSE; - if (gst_gl_window_is_running (window)) { - gulong handler_id = - g_signal_handler_find (GST_ELEMENT_PARENT (gl_sink), G_SIGNAL_MATCH_ID, - gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW], 0, - NULL, NULL, NULL); + handler_id = + g_signal_handler_find (GST_ELEMENT_PARENT (gl_sink), G_SIGNAL_MATCH_ID, + gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW], 0, + NULL, NULL, NULL); - if (G_UNLIKELY (!gl_sink->redisplay_shader) && (!handler_id - || !gl_sink->other_context)) { - gst_gl_window_send_message (window, - GST_GL_WINDOW_CB (gst_glimage_sink_thread_init_redisplay), gl_sink); + if (G_UNLIKELY (!gl_sink->redisplay_shader) && (!handler_id + || !gl_sink->other_context)) { + gst_gl_window_send_message (window, + GST_GL_WINDOW_CB (gst_glimage_sink_thread_init_redisplay), gl_sink); - /* if the shader is still null it means it failed to be useable */ - if (G_UNLIKELY (!gl_sink->redisplay_shader)) { - gst_object_unref (window); - return FALSE; - } - - gst_gl_window_set_preferred_size (window, GST_VIDEO_SINK_WIDTH (gl_sink), - GST_VIDEO_SINK_HEIGHT (gl_sink)); - gst_gl_window_show (window); - } - - /* Recreate the output texture if needed */ - GST_GLIMAGE_SINK_LOCK (gl_sink); - if (gl_sink->window_resized) { - gl_sink->window_resized = FALSE; - GST_GLIMAGE_SINK_UNLOCK (gl_sink); - GST_DEBUG_OBJECT (gl_sink, "Sending reconfigure event on sinkpad."); - gst_pad_push_event (GST_BASE_SINK (gl_sink)->sinkpad, - gst_event_new_reconfigure ()); - GST_GLIMAGE_SINK_LOCK (gl_sink); - } - - if (gl_sink->output_mode_changed && gl_sink->input_buffer != NULL) { - GST_DEBUG ("Recreating output after mode/size change"); - update_output_format (gl_sink); - prepare_next_buffer (gl_sink); - } - - if (gl_sink->next_buffer == NULL) { - /* Nothing to display yet */ - GST_GLIMAGE_SINK_UNLOCK (gl_sink); + /* if the shader is still null it means it failed to be useable */ + if (G_UNLIKELY (!gl_sink->redisplay_shader)) { gst_object_unref (window); - return TRUE; + return FALSE; } - /* Avoid to release the texture while drawing */ - gl_sink->redisplay_texture = gl_sink->next_tex; - old_stored_buffer[0] = gl_sink->stored_buffer[0]; - old_stored_buffer[1] = gl_sink->stored_buffer[1]; - gl_sink->stored_buffer[0] = gst_buffer_ref (gl_sink->next_buffer); - if (gl_sink->next_buffer2) - gl_sink->stored_buffer[1] = gst_buffer_ref (gl_sink->next_buffer2); - else - gl_sink->stored_buffer[1] = NULL; - - old_sync = gl_sink->stored_sync; - if (gl_sink->next_sync) - gl_sink->stored_sync = gst_buffer_ref (gl_sink->next_sync); - else - gl_sink->stored_sync = NULL; - gl_sink->stored_sync_meta = gl_sink->next_sync_meta; - GST_GLIMAGE_SINK_UNLOCK (gl_sink); - - gst_buffer_replace (old_stored_buffer, NULL); - gst_buffer_replace (old_stored_buffer + 1, NULL); - if (old_sync) - gst_buffer_unref (old_sync); - - /* Drawing is asynchronous: gst_gl_window_draw is not blocking - * It means that it does not wait for stuff to be executed in other threads - */ - gst_gl_window_draw (window); + gst_gl_window_set_preferred_size (window, GST_VIDEO_SINK_WIDTH (gl_sink), + GST_VIDEO_SINK_HEIGHT (gl_sink)); + gst_gl_window_show (window); } - alive = gst_gl_window_is_running (window); + + /* Recreate the output texture if needed */ + GST_GLIMAGE_SINK_LOCK (gl_sink); + if (gl_sink->window_resized) { + gl_sink->window_resized = FALSE; + GST_GLIMAGE_SINK_UNLOCK (gl_sink); + GST_DEBUG_OBJECT (gl_sink, "Sending reconfigure event on sinkpad."); + gst_pad_push_event (GST_BASE_SINK (gl_sink)->sinkpad, + gst_event_new_reconfigure ()); + GST_GLIMAGE_SINK_LOCK (gl_sink); + } + + if (gl_sink->output_mode_changed && gl_sink->input_buffer != NULL) { + GST_DEBUG ("Recreating output after mode/size change"); + update_output_format (gl_sink); + prepare_next_buffer (gl_sink); + } + + if (gl_sink->next_buffer == NULL) { + /* Nothing to display yet */ + GST_GLIMAGE_SINK_UNLOCK (gl_sink); + gst_object_unref (window); + return TRUE; + } + + /* Avoid to release the texture while drawing */ + gl_sink->redisplay_texture = gl_sink->next_tex; + old_stored_buffer[0] = gl_sink->stored_buffer[0]; + old_stored_buffer[1] = gl_sink->stored_buffer[1]; + gl_sink->stored_buffer[0] = gst_buffer_ref (gl_sink->next_buffer); + if (gl_sink->next_buffer2) + gl_sink->stored_buffer[1] = gst_buffer_ref (gl_sink->next_buffer2); + else + gl_sink->stored_buffer[1] = NULL; + + old_sync = gl_sink->stored_sync; + if (gl_sink->next_sync) + gl_sink->stored_sync = gst_buffer_ref (gl_sink->next_sync); + else + gl_sink->stored_sync = NULL; + gl_sink->stored_sync_meta = gl_sink->next_sync_meta; + GST_GLIMAGE_SINK_UNLOCK (gl_sink); + + gst_buffer_replace (old_stored_buffer, NULL); + gst_buffer_replace (old_stored_buffer + 1, NULL); + if (old_sync) + gst_buffer_unref (old_sync); + + /* Drawing is asynchronous: gst_gl_window_draw is not blocking + * It means that it does not wait for stuff to be executed in other threads + */ + gst_gl_window_draw (window); gst_object_unref (window); - return alive; + return TRUE; } diff --git a/gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m b/gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m index 72e10e5fa9..0c005af9d3 100644 --- a/gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m +++ b/gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m @@ -329,14 +329,12 @@ gst_gl_cocoa_draw_cb (GstGLWindowCocoa *window_cocoa) GstGLWindowCocoaPrivate *priv = window_cocoa->priv; GstGLWindow *window = GST_GL_WINDOW (window_cocoa); - if (gst_gl_window_is_running (window)) { - if (![priv->internal_win_id isClosed]) { - GstGLWindow *window = GST_GL_WINDOW (window_cocoa); + if (window_cocoa->priv->internal_win_id && ![priv->internal_win_id isClosed]) { + GstGLWindow *window = GST_GL_WINDOW (window_cocoa); - /* draw opengl scene in the back buffer */ - if (window->draw) - window->draw (window->draw_data); - } + /* draw opengl scene in the back buffer */ + if (window->draw) + window->draw (window->draw_data); } } @@ -348,7 +346,7 @@ gst_gl_cocoa_resize_cb (GstGLNSView * view, guint width, guint height) GstGLWindow *window = GST_GL_WINDOW (window_cocoa); GstGLContext *context = gst_gl_window_get_context (window); - if (gst_gl_window_is_running (window) && ![window_cocoa->priv->internal_win_id isClosed]) { + if (window_cocoa->priv->internal_win_id && ![window_cocoa->priv->internal_win_id isClosed]) { const GstGLFuncs *gl; NSRect bounds = [view bounds]; NSRect visibleRect = [view visibleRect]; diff --git a/gst-libs/gst/gl/gstglcontext.c b/gst-libs/gst/gl/gstglcontext.c index af5b25e9a8..1024b3936e 100644 --- a/gst-libs/gst/gl/gstglcontext.c +++ b/gst-libs/gst/gl/gstglcontext.c @@ -897,12 +897,8 @@ gst_gl_context_set_window (GstGLContext * context, GstGLWindow * window) if (context->priv->alive) return FALSE; - if (window) { - if (gst_gl_window_is_running (window)) - return FALSE; - + if (window) g_weak_ref_set (&window->context_ref, context); - } if (context->window) gst_object_unref (context->window); diff --git a/gst-libs/gst/gl/gstglwindow.c b/gst-libs/gst/gl/gstglwindow.c index 57dc931ce9..8e0f880865 100644 --- a/gst-libs/gst/gl/gstglwindow.c +++ b/gst-libs/gst/gl/gstglwindow.c @@ -782,22 +782,6 @@ gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback, GST_GL_WINDOW_UNLOCK (window); } -/** - * gst_gl_window_is_running: - * @window: a #GstGLWindow - * - * Whether the runloop is running - * - * Since: 1.4 - */ -gboolean -gst_gl_window_is_running (GstGLWindow * window) -{ - GstGLWindowPrivate *priv = window->priv; - return priv->alive && (!priv->loop - || g_main_loop_is_running (window->priv->loop)); -} - /** * gst_gl_window_get_display: * @window: a #GstGLWindow diff --git a/gst-libs/gst/gl/gstglwindow.h b/gst-libs/gst/gl/gstglwindow.h index c3a58ceff5..aa20c281fc 100644 --- a/gst-libs/gst/gl/gstglwindow.h +++ b/gst-libs/gst/gl/gstglwindow.h @@ -111,9 +111,10 @@ struct _GstGLWindow { * GstGLWindowClass: * @parent_class: Parent class * @get_display: Gets the current windowing system display connection - * @set_window_handle: Set a window to render into - * @get_window_handle: Gets the current window that this #GstGLWindow is - * rendering into + * @set_window_handle: Set a window handle to render into + * @get_window_handle: Gets the current window handle that this #GstGLWindow is + * rendering into. This may return a different value to + * what is passed into @set_window_handle * @draw: redraw the window with the specified dimensions * @run: run the mainloop * @quit: send a quit to the mainloop @@ -186,8 +187,6 @@ void gst_gl_window_run (GstGLWindow *window); GST_EXPORT void gst_gl_window_quit (GstGLWindow *window); GST_EXPORT -gboolean gst_gl_window_is_running (GstGLWindow *window); -GST_EXPORT void gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointer data); diff --git a/gst-libs/gst/gl/x11/gstglwindow_x11.c b/gst-libs/gst/gl/x11/gstglwindow_x11.c index 800315a33b..63d1d35551 100644 --- a/gst-libs/gst/gl/x11/gstglwindow_x11.c +++ b/gst-libs/gst/gl/x11/gstglwindow_x11.c @@ -363,11 +363,10 @@ draw_cb (gpointer data) { GstGLWindowX11 *window_x11 = data; GstGLWindow *window = GST_GL_WINDOW (window_x11); + guint width, height; + XWindowAttributes attr; - if (gst_gl_window_is_running (window)) { - guint width, height; - XWindowAttributes attr; - + if (window_x11->internal_win_id) { XGetWindowAttributes (window_x11->device, window_x11->internal_win_id, &attr); GST_TRACE_OBJECT (window, "window size %ux%u", attr.width, attr.height);