From 83e307ac96f30578ca0daf3749678802d6d36124 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Fri, 23 Jun 2023 20:01:04 +0800 Subject: [PATCH] va: basedec: Select the best format of the whole caps The current way only selects the best video format from the first structure of the caps. The caps like: video/x-raw(memory:VAMemory),drm-format=(string)NV12; \ video/x-raw(memory:VAMemory),format=(string){ NV12, Y210 } Will just choose NV12 as the result, even the bitstream is 10 bits. Part-of: --- .../gst-plugins-bad/sys/va/gstvabasedec.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabasedec.c b/subprojects/gst-plugins-bad/sys/va/gstvabasedec.c index 5f5990204e..8319fd2a39 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabasedec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvabasedec.c @@ -798,6 +798,7 @@ _caps_video_format_from_chroma (GstCaps * caps, GstCapsFeatures * features, GstCapsFeatures *feats; GstStructure *structure; const GValue *format; + GstVideoFormat fmt, ret_fmt = GST_VIDEO_FORMAT_UNKNOWN; num_structures = gst_caps_get_size (caps); for (i = 0; i < num_structures; i++) { @@ -806,10 +807,23 @@ _caps_video_format_from_chroma (GstCaps * caps, GstCapsFeatures * features, continue; structure = gst_caps_get_structure (caps, i); format = gst_structure_get_value (structure, "format"); - return _find_video_format_from_chroma (format, chroma_type); + + fmt = _find_video_format_from_chroma (format, chroma_type); + if (fmt == GST_VIDEO_FORMAT_UNKNOWN) + continue; + + /* Record the first valid format as the fallback if we can + not find a better one. */ + if (ret_fmt == GST_VIDEO_FORMAT_UNKNOWN) + ret_fmt = fmt; + + if (gst_va_chroma_from_video_format (fmt) == chroma_type) { + ret_fmt = fmt; + break; + } } - return GST_VIDEO_FORMAT_UNKNOWN; + return ret_fmt; } static GstVideoFormat