glimagesink: balance the creation/destruction of the overlay compositor

Fixes some leaks/possible segfault on when failing to create the compositor.
This commit is contained in:
Matthew Waters 2015-11-11 13:37:59 +11:00 committed by Tim-Philipp Müller
parent 117fc0409a
commit 7c52793e7c

View file

@ -951,9 +951,6 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
return GST_STATE_CHANGE_FAILURE;
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
glimage_sink->overlay_compositor =
gst_gl_overlay_compositor_new (glimage_sink->context);
g_atomic_int_set (&glimage_sink->to_quit, 0);
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
@ -1011,6 +1008,11 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
break;
}
case GST_STATE_CHANGE_READY_TO_NULL:
if (glimage_sink->overlay_compositor) {
gst_object_unref (glimage_sink->overlay_compositor);
glimage_sink->overlay_compositor = NULL;
}
if (glimage_sink->context) {
GstGLWindow *window = gst_gl_context_get_window (glimage_sink->context);
@ -1028,9 +1030,6 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
g_signal_handler_disconnect (window, glimage_sink->mouse_sig_id);
glimage_sink->mouse_sig_id = 0;
gst_object_unref (glimage_sink->overlay_compositor);
glimage_sink->overlay_compositor = NULL;
gst_object_unref (window);
gst_object_unref (glimage_sink->context);
glimage_sink->context = NULL;
@ -1335,6 +1334,14 @@ prepare_next_buffer (GstGLImageSink * glimage_sink)
info = &glimage_sink->in_info;
}
if (!glimage_sink->overlay_compositor) {
if (!(glimage_sink->overlay_compositor =
gst_gl_overlay_compositor_new (glimage_sink->context))) {
gst_buffer_unref (next_buffer);
goto fail;
}
}
gst_gl_overlay_compositor_upload_overlays (glimage_sink->overlay_compositor,
next_buffer);