gst_video_info_init (&this->v_info);
this->buffer_ = NULL;
+ this->sync_buffer_ = gst_buffer_new ();
}
GstQSGTexture::~GstQSGTexture ()
{
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 */
-void
+gboolean
GstQSGTexture::setBuffer (GstBuffer * buffer)
{
GST_LOG ("%p setBuffer %" GST_PTR_FORMAT, this, buffer);
/* 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 */
void
GstQSGTexture::bind ()
{
+ GstGLContext *context;
+ GstGLSyncMeta *sync_meta;
+ GstMemory *mem;
guint tex_id;
if (!this->buffer_)
if (GST_VIDEO_INFO_FORMAT (&this->v_info) == GST_VIDEO_FORMAT_UNKNOWN)
return;
+ this->mem_ = gst_buffer_peek_memory (this->buffer_, 0);
+ if (!this->mem_)
+ return;
+
/* FIXME: should really lock the memory to prevent write access */
if (!gst_video_frame_map (&this->v_frame, &this->v_info, this->buffer_,
(GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
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];
GST_LOG ("%p binding Qt texture %u", this, tex_id);
#include <QSGTexture>
#include <QOpenGLFunctions>
#include <gst/video/video.h>
+#include <gst/gl/gl.h>
class GstQSGTexture : public QSGTexture, protected QOpenGLFunctions
{
~GstQSGTexture ();
void setCaps (GstCaps * caps);
- void setBuffer (GstBuffer * buffer);
+ gboolean setBuffer (GstBuffer * buffer);
/* QSGTexture */
void bind ();
private:
GstBuffer * buffer_;
+ GstBuffer * sync_buffer_;
+ GstGLContext * qt_context_;
+ GstMemory * mem_;
GstVideoInfo v_info;
GstVideoFrame v_frame;
};
GstQSGTexture *tex;
g_mutex_lock (&this->priv->lock);
+ gst_gl_context_activate (this->priv->other_context, TRUE);
GST_TRACE ("%p updatePaintNode", this);
if (!texNode) {
texNode = new QSGSimpleTextureNode ();
- tex = new GstQSGTexture ();
- texNode->setTexture (tex);
+ texNode->setOwnsTexture (true);
} else {
tex = static_cast<GstQSGTexture *> (texNode->texture());
}
+ tex = new GstQSGTexture ();
tex->setCaps (this->priv->caps);
tex->setBuffer (this->priv->buffer);
+ texNode->setTexture (tex);
if (this->priv->force_aspect_ratio) {
src.w = this->priv->display_width;
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);
return texNode;