From 7ea1579a4df24d7a2d4bbb1ded764ca47000e299 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 1 Nov 2023 11:49:45 -0400 Subject: [PATCH 51/68] v4l2codecs: format: Allow matching planar format variants This is to allow matching formats that simply have different numbrer of planes like NV12 and NV12M. This avoids the spurious S_FMT when this is the only difference reported by the driver. Upstream-Status: Pending --- sys/v4l2codecs/gstv4l2encoder.c | 2 +- sys/v4l2codecs/gstv4l2format.c | 20 ++++++++++++++++++++ sys/v4l2codecs/gstv4l2format.h | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/sys/v4l2codecs/gstv4l2encoder.c b/sys/v4l2codecs/gstv4l2encoder.c index cded8bf..0886d15 100644 --- a/sys/v4l2codecs/gstv4l2encoder.c +++ b/sys/v4l2codecs/gstv4l2encoder.c @@ -617,7 +617,7 @@ gst_v4l2_encoder_set_src_fmt (GstV4l2Encoder * self, GstVideoInfo * info, return FALSE; } - if (pix_fmt != fmt.fmt.pix_mp.pixelformat + if (!gst_v4l2_format_equivalent (pix_fmt, fmt.fmt.pix_mp.pixelformat) || fmt.fmt.pix_mp.width != width || fmt.fmt.pix_mp.height != height) { GST_DEBUG_OBJECT (self, "Trying to use peer format: %" GST_FOURCC_FORMAT " %ix%i", diff --git a/sys/v4l2codecs/gstv4l2format.c b/sys/v4l2codecs/gstv4l2format.c index bbfdee2..e029d7d 100644 --- a/sys/v4l2codecs/gstv4l2format.c +++ b/sys/v4l2codecs/gstv4l2format.c @@ -209,3 +209,23 @@ gst_v4l2_format_from_video_format (GstVideoFormat format, guint32 * out_pix_fmt) *out_pix_fmt = entry->v4l2_pix_fmt; return TRUE; } + +gboolean +gst_v4l2_format_equivalent (guint32 pix_fmt_a, guint32 pix_fmt_b) +{ + struct FormatEntry *entry_a, *entry_b; + + if (pix_fmt_a == pix_fmt_b) + return TRUE; + + entry_a = lookup_v4l2_fmt (pix_fmt_a); + entry_b = lookup_v4l2_fmt (pix_fmt_b); + + if (!entry_a || !entry_b) + return FALSE; + + if (entry_a->gst_fmt == entry_b->gst_fmt) + return TRUE; + + return FALSE; +} diff --git a/sys/v4l2codecs/gstv4l2format.h b/sys/v4l2codecs/gstv4l2format.h index dd1e1ea..1f634ee 100644 --- a/sys/v4l2codecs/gstv4l2format.h +++ b/sys/v4l2codecs/gstv4l2format.h @@ -35,4 +35,6 @@ gboolean gst_v4l2_format_to_video_format (guint32 pix_fmt, gboolean gst_v4l2_format_from_video_format (GstVideoFormat format, guint32 * out_pix_fmt); +gboolean gst_v4l2_format_equivalent (guint32 pix_fmt_a, guint32 pix_fmt_b); + #endif /* __GST_V4L2_FORMAT_H__ */ -- 2.25.1