summaryrefslogtreecommitdiff
path: root/ext/gtk/gstgtksink.c
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.com>2015-06-11 12:10:23 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.com>2015-06-11 12:41:49 -0400
commitb14fea7fb8537bcd188a708ed8a36e0fbcc81955 (patch)
treea92e3b9f8c1c704a1d7115825f0c604fc3314f60 /ext/gtk/gstgtksink.c
parente2ce1eff36cb6c0c5fde6fc13ce57af3c89fa117 (diff)
downloadgstreamer-plugins-bad-b14fea7fb8537bcd188a708ed8a36e0fbcc81955.tar.gz
gstgtk: Allow doing gst-inspect-1.0 on these elements
This patch allow going gst-inspect-1.0 on these elements removing ugly crash that was previously occurring. The method consist of making the widget creation as lazy as possible. This way we don't endup doing gtk_init() before the application. We also ref_sink() the widget, so we don't crash if the parent widget is discarded, and cleanly error out with GL if the widget has no parent window, because calling gtk_widget_realized() can only be done if the widget has been parented to a window).
Diffstat (limited to 'ext/gtk/gstgtksink.c')
-rw-r--r--ext/gtk/gstgtksink.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/ext/gtk/gstgtksink.c b/ext/gtk/gstgtksink.c
index e60d1bb6f..b921ff02f 100644
--- a/ext/gtk/gstgtksink.c
+++ b/ext/gtk/gstgtksink.c
@@ -117,7 +117,6 @@ gst_gtk_sink_class_init (GstGtkSinkClass * klass)
static void
gst_gtk_sink_init (GstGtkSink * gtk_sink)
{
- gtk_sink->widget = (GtkGstWidget *) gtk_gst_widget_new ();
}
static void
@@ -141,6 +140,28 @@ gst_gtk_sink_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
+static GtkGstWidget *
+gst_gtk_sink_get_widget (GstGtkSink * gtk_sink)
+{
+ if (gtk_sink->widget != NULL)
+ return gtk_sink->widget;
+
+ /* Ensure GTK is initialized, this has no side effect if it was already
+ * initialized. Also, we do that lazylli, so the application can be first */
+ if (!gtk_init_check (NULL, NULL)) {
+ GST_ERROR_OBJECT (gtk_sink, "Could not ensure GTK initialization.");
+ return NULL;
+ }
+
+ gtk_sink->widget = (GtkGstWidget *) gtk_gst_widget_new ();
+
+ /* Take the floating ref, other wise the destruction of the container will
+ * make this widget disapear possibly before we are done. */
+ gst_object_ref_sink (gtk_sink->widget);
+
+ return gtk_sink->widget;
+}
+
static void
gst_gtk_sink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
@@ -151,7 +172,7 @@ gst_gtk_sink_get_property (GObject * object, guint prop_id,
switch (prop_id) {
case PROP_WIDGET:
- g_value_set_object (value, gtk_sink->widget);
+ g_value_set_object (value, gst_gtk_sink_get_widget (gtk_sink));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -191,6 +212,8 @@ gst_gtk_sink_change_state (GstElement * element, GstStateChange transition)
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
+ if (gst_gtk_sink_get_widget (gtk_sink) == NULL)
+ return GST_STATE_CHANGE_FAILURE;
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
break;