gtksink: Avoid errors fetching widget property

Avoid errors when fetching the "widget" property and GTK initialisation
fails, such as when running in a non-graphical environment.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1088>
This commit is contained in:
Bastien Nocera 2021-10-11 10:22:41 +02:00 committed by GStreamer Marge Bot
parent 941c0e81dd
commit b0d4996380
2 changed files with 25 additions and 8 deletions

View file

@ -183,7 +183,7 @@ gst_gtk_base_sink_get_widget (GstGtkBaseSink * gtk_sink)
/* Ensure GTK is initialized, this has no side effect if it was already
* initialized. Also, we do that lazily, so the application can be first */
if (!gtk_init_check (NULL, NULL)) {
GST_ERROR_OBJECT (gtk_sink, "Could not ensure GTK initialization.");
GST_INFO_OBJECT (gtk_sink, "Could not ensure GTK initialization.");
return NULL;
}
@ -296,6 +296,11 @@ gst_gtk_base_sink_navigation_send_event (GstNavigation * navigation,
GtkGstBaseWidget *widget = gst_gtk_base_sink_get_widget (sink);
gdouble stream_x, stream_y;
if (widget == NULL) {
GST_ERROR_OBJECT (sink, "Could not ensure GTK initialization.");
return;
}
gtk_gst_base_widget_display_size_to_stream_size (widget,
x, y, &stream_x, &stream_y);
gst_structure_set (structure,
@ -333,8 +338,10 @@ gst_gtk_base_sink_start_on_main (GstBaseSink * bsink)
GstGtkBaseSinkClass *klass = GST_GTK_BASE_SINK_GET_CLASS (bsink);
GtkWidget *toplevel;
if (gst_gtk_base_sink_get_widget (gst_sink) == NULL)
if (gst_gtk_base_sink_get_widget (gst_sink) == NULL) {
GST_ERROR_OBJECT (bsink, "Could not ensure GTK initialization.");
return FALSE;
}
/* After this point, gtk_sink->widget will always be set */

View file

@ -139,9 +139,11 @@ gst_gtk_gl_sink_set_property (GObject * object, guint prop_id,
{
GtkWidget *widget =
gst_gtk_base_sink_acquire_widget (GST_GTK_BASE_SINK (object));
gtk_gst_gl_widget_set_rotate_method (GTK_GST_GL_WIDGET (widget),
g_value_get_enum (value), FALSE);
g_object_unref (widget);
if (widget != NULL) {
gtk_gst_gl_widget_set_rotate_method (GTK_GST_GL_WIDGET (widget),
g_value_get_enum (value), FALSE);
g_object_unref (widget);
}
break;
}
default:
@ -161,9 +163,13 @@ gst_gtk_gl_sink_get_property (GObject * object, guint prop_id,
GtkWidget *widget =
gst_gtk_base_sink_acquire_widget (GST_GTK_BASE_SINK (object));
g_value_set_enum (value,
gtk_gst_gl_widget_get_rotate_method (GTK_GST_GL_WIDGET (widget)));
g_object_unref (widget);
if (widget != NULL) {
g_value_set_enum (value,
gtk_gst_gl_widget_get_rotate_method (GTK_GST_GL_WIDGET (widget)));
g_object_unref (widget);
} else {
g_value_set_enum (value, GST_VIDEO_ORIENTATION_IDENTITY);
}
break;
}
@ -460,6 +466,10 @@ gst_gtk_gl_sink_event (GstBaseSink * sink, GstEvent * event)
widget = GTK_GST_GL_WIDGET
(gst_gtk_base_sink_acquire_widget (GST_GTK_BASE_SINK (sink)));
if (widget == NULL) {
GST_ERROR_OBJECT (sink, "Could not ensure GTK initialization.");
break;
}
gtk_gst_gl_widget_set_rotate_method (widget, orientation, TRUE);