qt: return a different GstGLDisplay object when the first sink requests

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>
This commit is contained in:
Matthew Waters 2021-05-03 17:39:05 +10:00 committed by GStreamer Marge Bot
parent 0ff50d6723
commit c7181bedac
5 changed files with 14 additions and 8 deletions

View 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());

View 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);

View 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

View 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*)));

View 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);