From e869185287fbe155be9ca86daeaf540cb29c61c4 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Mon, 15 Apr 2024 13:38:15 +0200 Subject: [PATCH] v4l2codecs: decoder: Reorder caps to prefer DMA_DRM ones Certain V4L2 fourccs don't (yet) have DRM counter parts, in which case we can't create DMA_DRM caps for them. This is usually the case for specific tilings, which are represented as modifiers for DMA formats. While using these tilings is generally preferable - because of e.g. lower memory usage - it can result in additional conversion steps when interacting with DMA based APIs such as GL, Vulkan or KMS. In such cases using a DMA compatible format usually ends up being the better option. Before the addition of DMA_DRM caps, this was what playbin3 ended up requesting in various cases - e.g. prefering NV12 over NV12_4L4 - but the addition of DMA_DRM caps seems to confuse the selection logic. As a simple and quite robust solution, assume that peers supporting DMA_DRM caps always prefer these and reorder the caps accordingly. In the future we plan to have a translation layer for cases where there is a matching fourcc+modifier pair for a V4L2 fourcc, ensuring optimal results. Part-of: --- .../sys/v4l2codecs/gstv4l2decoder.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2decoder.c b/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2decoder.c index 251ce48ee7..76022a3fdd 100644 --- a/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2decoder.c +++ b/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2decoder.c @@ -463,6 +463,20 @@ gst_v4l2_decoder_probe_caps_for_format (GstV4l2Decoder * self, return caps; } +static gboolean +filter_only_dmabuf_caps (GstCapsFeatures * features, + GstStructure * structure, gpointer user_data) +{ + return gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_DMABUF); +} + +static gboolean +filter_non_dmabuf_caps (GstCapsFeatures * features, + GstStructure * structure, gpointer user_data) +{ + return !gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_DMABUF); +} + GstCaps * gst_v4l2_decoder_enum_src_formats (GstV4l2Decoder * self, GstStaticCaps * static_filter) @@ -510,6 +524,11 @@ gst_v4l2_decoder_enum_src_formats (GstV4l2Decoder * self, gst_caps_unref (tmp); gst_caps_unref (filter); + tmp = gst_caps_copy (caps); + gst_caps_filter_and_map_in_place (caps, filter_only_dmabuf_caps, NULL); + gst_caps_filter_and_map_in_place (tmp, filter_non_dmabuf_caps, NULL); + gst_caps_append (caps, tmp); + GST_DEBUG_OBJECT (self, "Probed caps: %" GST_PTR_FORMAT, caps); return caps;