wpevideosrc: Implement basic heuristic for raw caps negotiation
authorPhilippe Normand <philn@igalia.com>
Sun, 29 Aug 2021 09:30:53 +0000 (10:30 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 31 Aug 2021 17:59:06 +0000 (17:59 +0000)
Before this patch raw caps could be negotiated already with a capsfilter, but in
cases where wpesrc is being auto-plugged this approach can't be used.

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

ext/wpe/gstwpevideosrc.cpp

index 0bab056..9b00d78 100644 (file)
@@ -140,22 +140,22 @@ GST_DEBUG_CATEGORY_EXTERN (wpe_video_src_debug);
 #define gst_wpe_video_src_parent_class parent_class
 G_DEFINE_TYPE(GstWpeVideoSrc, gst_wpe_video_src, GST_TYPE_GL_BASE_SRC);
 
-#define WPE_RAW_CAPS "; video/x-raw, "          \
+#define WPE_RAW_CAPS "video/x-raw, "            \
   "format = (string) BGRA, "                    \
   "width = " GST_VIDEO_SIZE_RANGE ", "          \
   "height = " GST_VIDEO_SIZE_RANGE ", "         \
   "framerate = " GST_VIDEO_FPS_RANGE ", "       \
   "pixel-aspect-ratio = (fraction)1/1"
 
-#define WPE_BASIC_CAPS "video/x-raw(memory:GLMemory), " \
+#define WPE_GL_CAPS "video/x-raw(memory:GLMemory), "    \
   "format = (string) RGBA, "                            \
   "width = " GST_VIDEO_SIZE_RANGE ", "                  \
   "height = " GST_VIDEO_SIZE_RANGE ", "                 \
   "framerate = " GST_VIDEO_FPS_RANGE ", "               \
   "pixel-aspect-ratio = (fraction)1/1, texture-target = (string)2D"
 
-#define WPE_VIDEO_SRC_CAPS WPE_BASIC_CAPS WPE_RAW_CAPS
-#define WPE_VIDEO_SRC_DOC_CAPS WPE_BASIC_CAPS "; video/x-raw, format = (string) BGRA"
+#define WPE_VIDEO_SRC_CAPS WPE_GL_CAPS "; " WPE_RAW_CAPS
+#define WPE_VIDEO_SRC_DOC_CAPS WPE_GL_CAPS "; video/x-raw, format = (string) BGRA"
 
 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
@@ -373,13 +373,24 @@ gst_wpe_video_src_stop (GstBaseSrc * base_src)
 }
 
 static GstCaps *
-gst_wpe_video_src_fixate (GstBaseSrc * base_src, GstCaps * caps)
+gst_wpe_video_src_fixate (GstBaseSrc * base_src, GstCaps * combined_caps)
 {
   GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (base_src);
   GstStructure *structure;
   gint width, height;
+  GstCaps *caps;
+
+  /* In situation where software GL support is explicitly requested, select raw
+   * caps, otherwise perform default caps negotiation. Unfortunately at this
+   * point we don't know yet if a GL context will be usable or not, so we can't
+   * check the element GstContext.
+   */
+  if (!g_strcmp0 (g_getenv ("LIBGL_ALWAYS_SOFTWARE"), "true")) {
+    caps = gst_caps_from_string (WPE_RAW_CAPS);
+  } else {
+    caps = gst_caps_make_writable (combined_caps);
+  }
 
-  caps = gst_caps_make_writable (caps);
   structure = gst_caps_get_structure (caps, 0);
 
   gst_structure_fixate_field_nearest_int (structure, "width", DEFAULT_WIDTH);