qml: don't use buffers that have invalid contents
authorMatthew Waters <matthew@centricular.com>
Tue, 11 May 2021 10:41:38 +0000 (20:41 +1000)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 12 May 2021 02:55:51 +0000 (02:55 +0000)
If the GL context is not shareable, ignore it.

A future change may also not output the relevant output either.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/983>

ext/qt/gstqtoverlay.cc

index 3b6dea3..75de99e 100644 (file)
@@ -409,9 +409,33 @@ gst_qt_overlay_prepare_output_buffer (GstBaseTransform * btrans,
   GstGLMemory *out_mem;
   GstGLSyncMeta *sync_meta;
 
+  if (gst_buffer_n_memory (buffer) <= 0) {
+    GST_ELEMENT_ERROR (btrans, RESOURCE, NOT_FOUND,
+        (NULL), ("Buffer must have a memory object"));
+    return GST_FLOW_ERROR;
+  }
+
   if (qt_overlay->widget) {
-    qt_overlay->widget->setCaps (bfilter->in_caps); 
-    qt_overlay->widget->setBuffer (buffer);
+    GstMemory *mem;
+    GstGLMemory *gl_mem;
+
+    qt_overlay->widget->setCaps (bfilter->in_caps);
+
+    mem = gst_buffer_peek_memory (buffer, 0);
+    if (!gst_is_gl_memory (mem)) {
+      GST_ELEMENT_ERROR (btrans, RESOURCE, NOT_FOUND,
+          (NULL), ("Input memory must be a GstGLMemory"));
+      return GST_FLOW_ERROR;
+    }
+    gl_mem = (GstGLMemory *) mem;
+    if (!gst_gl_context_can_share (gl_mem->mem.context, bfilter->context)) {
+      GST_WARNING_OBJECT (bfilter, "Cannot use the current input texture "
+          "(input buffer GL context %" GST_PTR_FORMAT " cannot share "
+          "resources with the configured OpenGL context %" GST_PTR_FORMAT ")",
+          gl_mem->mem.context, bfilter->context);
+    } else {
+      qt_overlay->widget->setBuffer (buffer);
+    }
   }
 
   /* XXX: is this the correct ts to drive the animation */