play: Fix object construction
authorSebastian Dröge <sebastian@centricular.com>
Sat, 13 Aug 2022 08:49:08 +0000 (11:49 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Sat, 13 Aug 2022 09:16:16 +0000 (12:16 +0300)
Ideally new() functions should simply call g_object_new() and not much
else, so let's do that here and handle all the construction properly in
a GObject way.

Now a play object created via g_object_new() is actually usable.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2880>

subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c

index c26cc70..63bbf64 100644 (file)
@@ -212,6 +212,8 @@ static void gst_play_constructed (GObject * object);
 
 static gpointer gst_play_main (gpointer data);
 
 
 static gpointer gst_play_main (gpointer data);
 
+static void gst_play_set_playbin_video_sink (GstPlay * self);
+
 static void gst_play_seek_internal_locked (GstPlay * self);
 static void gst_play_stop_internal (GstPlay * self, gboolean transient);
 static gboolean gst_play_pause_internal (gpointer user_data);
 static void gst_play_seek_internal_locked (GstPlay * self);
 static void gst_play_stop_internal (GstPlay * self, gboolean transient);
 static gboolean gst_play_pause_internal (gpointer user_data);
@@ -509,6 +511,8 @@ gst_play_constructed (GObject * object)
   self->thread = g_thread_new ("GstPlay", gst_play_main, self);
   while (!self->loop || !g_main_loop_is_running (self->loop))
     g_cond_wait (&self->cond, &self->lock);
   self->thread = g_thread_new ("GstPlay", gst_play_main, self);
   while (!self->loop || !g_main_loop_is_running (self->loop))
     g_cond_wait (&self->cond, &self->lock);
+
+  gst_play_set_playbin_video_sink (self);
   g_mutex_unlock (&self->lock);
 
   G_OBJECT_CLASS (parent_class)->constructed (object);
   g_mutex_unlock (&self->lock);
 
   G_OBJECT_CLASS (parent_class)->constructed (object);
@@ -612,7 +616,14 @@ gst_play_set_property (GObject * object, guint prop_id,
       g_mutex_lock (&self->lock);
       g_clear_object (&self->video_renderer);
       self->video_renderer = g_value_dup_object (value);
       g_mutex_lock (&self->lock);
       g_clear_object (&self->video_renderer);
       self->video_renderer = g_value_dup_object (value);
-      gst_play_set_playbin_video_sink (self);
+
+      // When the video_renderer is a GstPlayerWrappedVideoRenderer it cannot be set
+      // at construction time because it requires a valid pipeline which is created
+      // only after GstPlay has been constructed. That is why the video renderer is
+      // set *after* GstPlay has been constructed.
+      if (self->thread) {
+        gst_play_set_playbin_video_sink (self);
+      }
       g_mutex_unlock (&self->lock);
       break;
     case PROP_URI:{
       g_mutex_unlock (&self->lock);
       break;
     case PROP_URI:{
@@ -2648,15 +2659,8 @@ gst_play_new (GstPlayVideoRenderer * video_renderer)
 
   g_once (&once, gst_play_init_once, NULL);
 
 
   g_once (&once, gst_play_init_once, NULL);
 
-  self = g_object_new (GST_TYPE_PLAY, NULL);
+  self = g_object_new (GST_TYPE_PLAY, "video-renderer", video_renderer, NULL);
 
 
-  // When the video_renderer is a GstPlayerWrappedVideoRenderer it cannot be set
-  // at construction time because it requires a valid pipeline which is created
-  // only after GstPlay has been constructed. That is why the video renderer is
-  // set *after* GstPlay has been constructed.
-  if (video_renderer != NULL) {
-    g_object_set (self, "video-renderer", video_renderer, NULL);
-  }
   gst_object_ref_sink (self);
 
   if (video_renderer)
   gst_object_ref_sink (self);
 
   if (video_renderer)