convertframe: Add support for GL-memory backend GstFrame input
authorBastien Nocera <hadess@hadess.net>
Thu, 10 Mar 2022 09:25:53 +0000 (10:25 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 15 Mar 2022 20:31:24 +0000 (20:31 +0000)
Add "gldownload" early in the pipeline so that GL-memory backed raw
frames can be downloaded and processed on the CPU.

Closes: #1073
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1916>

subprojects/gst-plugins-base/gst-libs/gst/video/convertframe.c
subprojects/gst-plugins-base/meson.build

index bc55c6c..56db5d3 100644 (file)
@@ -24,6 +24,9 @@
 
 #include <string.h>
 #include "video.h"
+#ifdef HAVE_GL
+#include <gst/gl/gstglmemory.h>
+#endif
 
 static gboolean
 caps_are_raw (const GstCaps * caps)
@@ -117,8 +120,17 @@ build_convert_frame_pipeline (GstElement ** src_element,
 {
   GstElement *vcrop = NULL, *csp = NULL, *csp2 = NULL, *vscale = NULL;
   GstElement *src = NULL, *sink = NULL, *encoder = NULL, *pipeline;
+  GstElement *dl = NULL;
   GstVideoInfo info;
   GError *error = NULL;
+#ifdef HAVE_GL
+  GstCapsFeatures *features;
+
+  features = gst_caps_get_features (from_caps, 0);
+  if (gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY))
+    if (!create_element ("gldownload", &dl, &error))
+      goto no_elements;
+#endif
 
   if (cmeta) {
     if (!create_element ("videocrop", &vcrop, &error)) {
@@ -150,6 +162,8 @@ build_convert_frame_pipeline (GstElement ** src_element,
   gst_bin_add_many (GST_BIN (pipeline), src, csp, vscale, sink, NULL);
   if (vcrop)
     gst_bin_add_many (GST_BIN (pipeline), vcrop, csp2, NULL);
+  if (dl)
+    gst_bin_add (GST_BIN (pipeline), dl);
 
   /* set caps */
   g_object_set (src, "caps", from_caps, NULL);
@@ -168,9 +182,19 @@ build_convert_frame_pipeline (GstElement ** src_element,
 
   /* FIXME: linking is still way too expensive, profile this properly */
   if (vcrop) {
-    GST_DEBUG ("linking src->csp2");
-    if (!gst_element_link_pads (src, "src", csp2, "sink"))
-      goto link_failed;
+    if (!dl) {
+      GST_DEBUG ("linking src->csp2");
+      if (!gst_element_link_pads (src, "src", csp2, "sink"))
+        goto link_failed;
+    } else {
+      GST_DEBUG ("linking src->dl");
+      if (!gst_element_link_pads (src, "src", dl, "sink"))
+        goto link_failed;
+
+      GST_DEBUG ("linking dl->csp2");
+      if (!gst_element_link_pads (dl, "src", csp2, "sink"))
+        goto link_failed;
+    }
 
     GST_DEBUG ("linking csp2->vcrop");
     if (!gst_element_link_pads (csp2, "src", vcrop, "sink"))
@@ -181,8 +205,18 @@ build_convert_frame_pipeline (GstElement ** src_element,
       goto link_failed;
   } else {
     GST_DEBUG ("linking src->csp");
-    if (!gst_element_link_pads (src, "src", csp, "sink"))
-      goto link_failed;
+    if (!dl) {
+      if (!gst_element_link_pads (src, "src", csp, "sink"))
+        goto link_failed;
+    } else {
+      GST_DEBUG ("linking src->dl");
+      if (!gst_element_link_pads (src, "src", dl, "sink"))
+        goto link_failed;
+
+      GST_DEBUG ("linking dl->csp");
+      if (!gst_element_link_pads (dl, "src", csp, "sink"))
+        goto link_failed;
+    }
   }
 
   GST_DEBUG ("linking csp->vscale");
index cea8dff..57f59a2 100644 (file)
@@ -492,6 +492,7 @@ subdir('scripts')
 
 base_libraries = ['allocators', 'app', 'audio', 'fft', 'pbutils', 'riff', 'rtp', 'rtsp', 'sdp', 'tag', 'video']
 if build_gstgl
+  core_conf.set('HAVE_GL', 1)
   base_libraries += 'gl'
 endif