diff options
author | Dmitry Shusharin <pmdvsh@gmail.com> | 2021-07-30 16:52:23 +0700 |
---|---|---|
committer | GStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2021-08-16 11:25:58 +0000 |
commit | a338ed98d65e40f22e62e4531cb18e52d2065003 (patch) | |
tree | ce8d34c5706538fabcef53f2cc7ac26cdc7e92c8 | |
parent | b8cb9ae5260124c8e3b4fa4b37b53bcaf81da030 (diff) | |
download | gstreamer-plugins-good-a338ed98d65e40f22e62e4531cb18e52d2065003.tar.gz |
gstqmlgl: wrap raw GstGLContext into GWeakRef
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/1032>
-rw-r--r-- | ext/qt/gstqsgtexture.cc | 19 | ||||
-rw-r--r-- | ext/qt/gstqsgtexture.h | 2 |
2 files changed, 13 insertions, 8 deletions
diff --git a/ext/qt/gstqsgtexture.cc b/ext/qt/gstqsgtexture.cc index fb85dfb5c..663696bc5 100644 --- a/ext/qt/gstqsgtexture.cc +++ b/ext/qt/gstqsgtexture.cc @@ -45,16 +45,18 @@ GstQSGTexture::GstQSGTexture () g_once_init_leave (&_debug, 1); } + g_weak_ref_init (&this->qt_context_ref_, NULL); 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; } GstQSGTexture::~GstQSGTexture () { + g_weak_ref_clear (&this->qt_context_ref_); gst_buffer_replace (&this->buffer_, NULL); gst_buffer_replace (&this->sync_buffer_, NULL); this->buffer_was_bound = FALSE; @@ -83,7 +85,8 @@ GstQSGTexture::setBuffer (GstBuffer * buffer) return FALSE; this->buffer_was_bound = FALSE; - this->qt_context_ = gst_gl_context_get_current (); + + g_weak_ref_set (&this->qt_context_ref_, gst_gl_context_get_current ()); return TRUE; } @@ -107,13 +110,14 @@ void GstQSGTexture::bind () { const GstGLFuncs *gl; - GstGLContext *context; + GstGLContext *context, *qt_context; GstGLSyncMeta *sync_meta; GstMemory *mem; guint tex_id; gboolean use_dummy_tex = TRUE; - if (!GST_IS_GL_CONTEXT(this->qt_context_)) + qt_context = GST_GL_CONTEXT (g_weak_ref_get (&this->qt_context_ref_)); + if (!qt_context) goto out; if (!this->buffer_) @@ -125,8 +129,7 @@ GstQSGTexture::bind () if (!this->mem_) goto out; - g_assert (this->qt_context_); - gl = this->qt_context_->gl_vtable; + gl = qt_context->gl_vtable; /* FIXME: should really lock the memory to prevent write access */ if (!gst_video_frame_map (&this->v_frame, &this->v_info, this->buffer_, @@ -146,7 +149,7 @@ GstQSGTexture::bind () gst_gl_sync_meta_set_sync_point (sync_meta, context); - gst_gl_sync_meta_wait (sync_meta, this->qt_context_); + gst_gl_sync_meta_wait (sync_meta, qt_context); tex_id = *(guint *) this->v_frame.data[0]; GST_LOG ("%p binding Qt texture %u", this, tex_id); @@ -162,6 +165,8 @@ GstQSGTexture::bind () this->buffer_was_bound = TRUE; out: + gst_clear_object (&qt_context); + if (G_UNLIKELY (use_dummy_tex)) { QOpenGLContext *qglcontext = QOpenGLContext::currentContext (); QOpenGLFunctions *funcs = qglcontext->functions (); diff --git a/ext/qt/gstqsgtexture.h b/ext/qt/gstqsgtexture.h index ec4a16f57..d61b1cdea 100644 --- a/ext/qt/gstqsgtexture.h +++ b/ext/qt/gstqsgtexture.h @@ -51,7 +51,7 @@ private: GstBuffer * buffer_; gboolean buffer_was_bound; GstBuffer * sync_buffer_; - GstGLContext * qt_context_; + GWeakRef qt_context_ref_; GstMemory * mem_; GLuint dummy_tex_id_; GstVideoInfo v_info; |