summaryrefslogtreecommitdiff
path: root/ext/qt/gstqsgtexture.cc
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2020-11-03 15:58:30 +0200
committerTim-Philipp Müller <tim@centricular.com>2021-06-11 10:46:13 +0100
commit20cb300706d16d570bd93322fd3b7ad6664daa34 (patch)
tree066da44a78bca722e41649d54051fd1bcacc1e37 /ext/qt/gstqsgtexture.cc
parentbeba0254d8aa60f5f03eedacaec2955a6c896c31 (diff)
downloadgstreamer-plugins-good-20cb300706d16d570bd93322fd3b7ad6664daa34.tar.gz
qmlglsink: Keep old buffers around a bit longer if they were bound by QML
We don't know exactly when QML will stop using them but it should be safe to unref them after at least 2 more buffers were bound. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/1009>
Diffstat (limited to 'ext/qt/gstqsgtexture.cc')
-rw-r--r--ext/qt/gstqsgtexture.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/qt/gstqsgtexture.cc b/ext/qt/gstqsgtexture.cc
index bfa79cda0..00e2ddad0 100644
--- a/ext/qt/gstqsgtexture.cc
+++ b/ext/qt/gstqsgtexture.cc
@@ -47,6 +47,7 @@ GstQSGTexture::GstQSGTexture ()
gst_video_info_init (&this->v_info);
this->buffer_ = NULL;
+ this->buffer_was_bound = FALSE;
this->qt_context_ = NULL;
this->sync_buffer_ = gst_buffer_new ();
this->dummy_tex_id_ = 0;
@@ -56,6 +57,7 @@ GstQSGTexture::~GstQSGTexture ()
{
gst_buffer_replace (&this->buffer_, NULL);
gst_buffer_replace (&this->sync_buffer_, NULL);
+ this->buffer_was_bound = FALSE;
if (this->dummy_tex_id_ && QOpenGLContext::currentContext ()) {
QOpenGLContext::currentContext ()->functions ()->glDeleteTextures (1,
&this->dummy_tex_id_);
@@ -80,11 +82,26 @@ GstQSGTexture::setBuffer (GstBuffer * buffer)
if (!gst_buffer_replace (&this->buffer_, buffer))
return FALSE;
+ this->buffer_was_bound = FALSE;
this->qt_context_ = gst_gl_context_get_current ();
return TRUE;
}
+/* only called from the streaming thread with scene graph thread blocked */
+GstBuffer *
+GstQSGTexture::getBuffer (gboolean * was_bound)
+{
+ GstBuffer *buffer = NULL;
+
+ if (this->buffer_)
+ buffer = gst_buffer_ref (this->buffer_);
+ if (was_bound)
+ *was_bound = this->buffer_was_bound;
+
+ return buffer;
+}
+
/* only called from qt's scene graph render thread */
void
GstQSGTexture::bind ()
@@ -142,6 +159,8 @@ GstQSGTexture::bind ()
* to use the dummy texture */
use_dummy_tex = FALSE;
+ this->buffer_was_bound = TRUE;
+
out:
if (G_UNLIKELY (use_dummy_tex)) {
QOpenGLContext *qglcontext = QOpenGLContext::currentContext ();