mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-07 16:05:47 +00:00
qml: implement the required multiple GL context synchonisation
From GStreamer's GL context into the QML context
This commit is contained in:
parent
69a90b5bfe
commit
6b8cf8419d
3 changed files with 40 additions and 5 deletions
|
@ -45,11 +45,13 @@ GstQSGTexture::GstQSGTexture ()
|
||||||
|
|
||||||
gst_video_info_init (&this->v_info);
|
gst_video_info_init (&this->v_info);
|
||||||
this->buffer_ = NULL;
|
this->buffer_ = NULL;
|
||||||
|
this->sync_buffer_ = gst_buffer_new ();
|
||||||
}
|
}
|
||||||
|
|
||||||
GstQSGTexture::~GstQSGTexture ()
|
GstQSGTexture::~GstQSGTexture ()
|
||||||
{
|
{
|
||||||
gst_buffer_replace (&this->buffer_, NULL);
|
gst_buffer_replace (&this->buffer_, NULL);
|
||||||
|
gst_buffer_replace (&this->sync_buffer_, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only called from the streaming thread with scene graph thread blocked */
|
/* only called from the streaming thread with scene graph thread blocked */
|
||||||
|
@ -62,18 +64,26 @@ GstQSGTexture::setCaps (GstCaps * caps)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only called from the streaming thread with scene graph thread blocked */
|
/* only called from the streaming thread with scene graph thread blocked */
|
||||||
void
|
gboolean
|
||||||
GstQSGTexture::setBuffer (GstBuffer * buffer)
|
GstQSGTexture::setBuffer (GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GST_LOG ("%p setBuffer %" GST_PTR_FORMAT, this, buffer);
|
GST_LOG ("%p setBuffer %" GST_PTR_FORMAT, this, buffer);
|
||||||
/* FIXME: update more state here */
|
/* FIXME: update more state here */
|
||||||
gst_buffer_replace (&this->buffer_, buffer);
|
if (!gst_buffer_replace (&this->buffer_, buffer))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
this->qt_context_ = gst_gl_context_get_current ();
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only called from qt's scene graph render thread */
|
/* only called from qt's scene graph render thread */
|
||||||
void
|
void
|
||||||
GstQSGTexture::bind ()
|
GstQSGTexture::bind ()
|
||||||
{
|
{
|
||||||
|
GstGLContext *context;
|
||||||
|
GstGLSyncMeta *sync_meta;
|
||||||
|
GstMemory *mem;
|
||||||
guint tex_id;
|
guint tex_id;
|
||||||
|
|
||||||
if (!this->buffer_)
|
if (!this->buffer_)
|
||||||
|
@ -81,6 +91,10 @@ GstQSGTexture::bind ()
|
||||||
if (GST_VIDEO_INFO_FORMAT (&this->v_info) == GST_VIDEO_FORMAT_UNKNOWN)
|
if (GST_VIDEO_INFO_FORMAT (&this->v_info) == GST_VIDEO_FORMAT_UNKNOWN)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
this->mem_ = gst_buffer_peek_memory (this->buffer_, 0);
|
||||||
|
if (!this->mem_)
|
||||||
|
return;
|
||||||
|
|
||||||
/* FIXME: should really lock the memory to prevent write access */
|
/* FIXME: should really lock the memory to prevent write access */
|
||||||
if (!gst_video_frame_map (&this->v_frame, &this->v_info, this->buffer_,
|
if (!gst_video_frame_map (&this->v_frame, &this->v_info, this->buffer_,
|
||||||
(GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
|
(GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
|
||||||
|
@ -88,6 +102,20 @@ GstQSGTexture::bind ()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mem = gst_buffer_peek_memory (this->buffer_, 0);
|
||||||
|
g_assert (gst_is_gl_memory (mem));
|
||||||
|
|
||||||
|
context = ((GstGLBaseBuffer *)mem)->context;
|
||||||
|
|
||||||
|
sync_meta = gst_buffer_get_gl_sync_meta (this->sync_buffer_);
|
||||||
|
if (!sync_meta)
|
||||||
|
sync_meta = gst_buffer_add_gl_sync_meta (context, this->sync_buffer_);
|
||||||
|
|
||||||
|
gst_gl_sync_meta_set_sync_point (sync_meta, context);
|
||||||
|
|
||||||
|
g_assert (this->qt_context_);
|
||||||
|
gst_gl_sync_meta_wait (sync_meta, this->qt_context_);
|
||||||
|
|
||||||
tex_id = *(guint *) this->v_frame.data[0];
|
tex_id = *(guint *) this->v_frame.data[0];
|
||||||
GST_LOG ("%p binding Qt texture %u", this, tex_id);
|
GST_LOG ("%p binding Qt texture %u", this, tex_id);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <QSGTexture>
|
#include <QSGTexture>
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
|
#include <gst/gl/gl.h>
|
||||||
|
|
||||||
class GstQSGTexture : public QSGTexture, protected QOpenGLFunctions
|
class GstQSGTexture : public QSGTexture, protected QOpenGLFunctions
|
||||||
{
|
{
|
||||||
|
@ -34,7 +35,7 @@ public:
|
||||||
~GstQSGTexture ();
|
~GstQSGTexture ();
|
||||||
|
|
||||||
void setCaps (GstCaps * caps);
|
void setCaps (GstCaps * caps);
|
||||||
void setBuffer (GstBuffer * buffer);
|
gboolean setBuffer (GstBuffer * buffer);
|
||||||
|
|
||||||
/* QSGTexture */
|
/* QSGTexture */
|
||||||
void bind ();
|
void bind ();
|
||||||
|
@ -45,6 +46,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GstBuffer * buffer_;
|
GstBuffer * buffer_;
|
||||||
|
GstBuffer * sync_buffer_;
|
||||||
|
GstGLContext * qt_context_;
|
||||||
|
GstMemory * mem_;
|
||||||
GstVideoInfo v_info;
|
GstVideoInfo v_info;
|
||||||
GstVideoFrame v_frame;
|
GstVideoFrame v_frame;
|
||||||
};
|
};
|
||||||
|
|
|
@ -171,6 +171,7 @@ QtGLVideoItem::updatePaintNode(QSGNode * oldNode,
|
||||||
GstQSGTexture *tex;
|
GstQSGTexture *tex;
|
||||||
|
|
||||||
g_mutex_lock (&this->priv->lock);
|
g_mutex_lock (&this->priv->lock);
|
||||||
|
gst_gl_context_activate (this->priv->other_context, TRUE);
|
||||||
|
|
||||||
GST_TRACE ("%p updatePaintNode", this);
|
GST_TRACE ("%p updatePaintNode", this);
|
||||||
|
|
||||||
|
@ -181,14 +182,15 @@ QtGLVideoItem::updatePaintNode(QSGNode * oldNode,
|
||||||
|
|
||||||
if (!texNode) {
|
if (!texNode) {
|
||||||
texNode = new QSGSimpleTextureNode ();
|
texNode = new QSGSimpleTextureNode ();
|
||||||
tex = new GstQSGTexture ();
|
texNode->setOwnsTexture (true);
|
||||||
texNode->setTexture (tex);
|
|
||||||
} else {
|
} else {
|
||||||
tex = static_cast<GstQSGTexture *> (texNode->texture());
|
tex = static_cast<GstQSGTexture *> (texNode->texture());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tex = new GstQSGTexture ();
|
||||||
tex->setCaps (this->priv->caps);
|
tex->setCaps (this->priv->caps);
|
||||||
tex->setBuffer (this->priv->buffer);
|
tex->setBuffer (this->priv->buffer);
|
||||||
|
texNode->setTexture (tex);
|
||||||
|
|
||||||
if (this->priv->force_aspect_ratio) {
|
if (this->priv->force_aspect_ratio) {
|
||||||
src.w = this->priv->display_width;
|
src.w = this->priv->display_width;
|
||||||
|
@ -209,6 +211,7 @@ QtGLVideoItem::updatePaintNode(QSGNode * oldNode,
|
||||||
|
|
||||||
texNode->setRect (QRectF (result.x, result.y, result.w, result.h));
|
texNode->setRect (QRectF (result.x, result.y, result.w, result.h));
|
||||||
|
|
||||||
|
gst_gl_context_activate (this->priv->other_context, FALSE);
|
||||||
g_mutex_unlock (&this->priv->lock);
|
g_mutex_unlock (&this->priv->lock);
|
||||||
|
|
||||||
return texNode;
|
return texNode;
|
||||||
|
|
Loading…
Reference in a new issue