35 if (g_once_init_enter (&_debug)) {
37 "Qt Scenegraph Texture");
38 g_once_init_leave (&_debug, 1);
41 gst_video_info_init (&this->v_info);
44 this->sync_buffer_ = gst_buffer_new ();
45 this->dummy_tex_ =
nullptr;
47 this->window_ = item->window();
93 GstGLContext *qt_context = NULL;
94 gboolean buffer_changed;
96 GST_LOG (
"%p setBuffer %" GST_PTR_FORMAT,
this, buffer);
98 buffer_changed = gst_buffer_replace (&this->buffer_, buffer);
100 if (buffer_changed) {
101 GstGLContext *context;
102 GstGLSyncMeta *sync_meta;
105 QQuickWindow::CreateTextureOptions options = QQuickWindow::TextureHasAlphaChannel;
109 qt_context = gst_gl_context_get_current();
115 if (GST_VIDEO_INFO_FORMAT (&this->v_info) == GST_VIDEO_FORMAT_UNKNOWN)
118 this->mem_ = gst_buffer_peek_memory (this->buffer_, 0);
123 if (!gst_video_frame_map (&this->v_frame, &this->v_info, this->buffer_,
124 (GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
127 GST_ERROR (
"Failed to map video frame");
131 mem = gst_buffer_peek_memory (this->buffer_, 0);
132 g_assert (gst_is_gl_memory (mem));
134 context = ((GstGLBaseMemory *)mem)->context;
136 sync_meta = gst_buffer_get_gl_sync_meta (this->sync_buffer_);
138 sync_meta = gst_buffer_add_gl_sync_meta (context, this->sync_buffer_);
140 gst_gl_sync_meta_set_sync_point (sync_meta, context);
142 gst_gl_sync_meta_wait (sync_meta, qt_context);
144 tex_id = *(guint *) this->v_frame.data[0];
145 GST_LOG (
"%p binding Qt texture %u",
this, tex_id);
147 texSize = QSize(GST_VIDEO_FRAME_WIDTH (&this->v_frame), GST_VIDEO_FRAME_HEIGHT (&this->v_frame));
150 texture = QNativeInterface::QSGOpenGLTexture::fromNative(tex_id, this->window_, texSize, options);
153 setOwnsTexture(
true);
154 markDirty(QSGNode::DirtyMaterial);
156 gst_video_frame_unmap (&this->v_frame);
165 if (this->dummy_tex_ ==
nullptr) {
171 const int tex_sidelength = 64;
172 QImage image(tex_sidelength, tex_sidelength, QImage::Format_ARGB32);
173 image.fill(QColor(0, 0, 0, 255));
175 this->dummy_tex_ = this->window_->createTextureFromImage(image);
178 g_assert (this->dummy_tex_ !=
nullptr);
180 if (
texture() != this->dummy_tex_) {
181 setTexture(this->dummy_tex_);
182 setOwnsTexture(
false);
183 markDirty(QSGNode::DirtyMaterial);
186 GST_LOG (
"%p binding fallback dummy Qt texture %p",
this, this->dummy_tex_);