qt: return a different GstGLDisplay object when the first sink requests
authorMatthew Waters <matthew@centricular.com>
Mon, 3 May 2021 07:39:05 +0000 (17:39 +1000)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 11 May 2021 06:40:38 +0000 (06:40 +0000)
This allows the 'replace-gstreamer-opengl-context' context machinery to
correctly replace the OpenGL context used by the pipeline when the first
qmlglsink is added to the pipeline.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/982>

ext/qt/gstqtglutility.cc
ext/qt/gstqtglutility.h
ext/qt/gstqtoverlay.cc
ext/qt/qtitem.cc
ext/qt/qtwindow.cc

index d2c0922..6d413bc 100644 (file)
@@ -60,9 +60,10 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
 
 G_LOCK_DEFINE_STATIC (display_lock);
 static GWeakRef qt_display;
+static gboolean sink_retrieved = FALSE;
 
 GstGLDisplay *
-gst_qt_get_gl_display ()
+gst_qt_get_gl_display (gboolean sink)
 {
   GstGLDisplay *display = NULL;
   QGuiApplication *app = static_cast<QGuiApplication *> (QCoreApplication::instance ());
@@ -80,9 +81,14 @@ gst_qt_get_gl_display ()
   /* XXX: this assumes that only one display will ever be created by Qt */
   display = static_cast<GstGLDisplay *>(g_weak_ref_get (&qt_display));
   if (display) {
-    GST_INFO ("returning previously created display");
-    G_UNLOCK (display_lock);
-    return display;
+    if (sink_retrieved) {
+      GST_INFO ("returning previously created display");
+      G_UNLOCK (display_lock);
+      return display;
+    } else if (sink) {
+      sink_retrieved = sink;
+    }
+    gst_clear_object (&display);
   }
 
   GST_INFO ("QGuiApplication::instance()->platformName() %s", app->platformName().toUtf8().data());
index 9a50954..6b878ca 100644 (file)
@@ -28,7 +28,7 @@
 
 G_BEGIN_DECLS
 
-GstGLDisplay * gst_qt_get_gl_display ();
+GstGLDisplay * gst_qt_get_gl_display (gboolean sink);
 gboolean       gst_qt_get_gl_wrapcontext (GstGLDisplay * display,
     GstGLContext **wrap_glcontext, GstGLContext **context);
 
index 6a0e4e7..3b6dea3 100644 (file)
@@ -468,7 +468,7 @@ gst_qt_overlay_change_state (GstElement * element,
         return GST_STATE_CHANGE_FAILURE;
       }
 
-      display = gst_qt_get_gl_display ();
+      display = gst_qt_get_gl_display (FALSE);
 
       if (display != filter->display)
         /* always propagate. The application may need to choose between window
index 5b23714..726296d 100644 (file)
@@ -129,7 +129,7 @@ QtGLVideoItem::QtGLVideoItem()
 
   g_mutex_init (&this->priv->lock);
 
-  this->priv->display = gst_qt_get_gl_display();
+  this->priv->display = gst_qt_get_gl_display(TRUE);
 
   connect(this, SIGNAL(windowChanged(QQuickWindow*)), this,
           SLOT(handleWindowChanged(QQuickWindow*)));
index 7c44ac5..aec6ba7 100644 (file)
@@ -117,7 +117,7 @@ QtGLWindow::QtGLWindow ( QWindow * parent, QQuickWindow *src ) :
   g_mutex_init (&this->priv->lock);
   g_cond_init (&this->priv->update_cond);
 
-  this->priv->display = gst_qt_get_gl_display();
+  this->priv->display = gst_qt_get_gl_display(FALSE);
 
   connect (source, SIGNAL(beforeRendering()), this, SLOT(beforeRendering()), Qt::DirectConnection);
   connect (source, SIGNAL(afterRendering()), this, SLOT(afterRendering()), Qt::DirectConnection);