From 93be216910d9307e34cc6c700219ccf988a01938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Wed, 14 Aug 2024 10:51:13 +0200 Subject: [PATCH] pbutils: descriptions: use subsampling factor to get YUV subsampling The algorithm used to determine the YUV subsampling string uses width and height subsampling factor, not the raw subsampling. Otherwise all 4:2:0 YUV frames will be detected as 4:4:4 Part-of: --- .../gst-libs/gst/pbutils/descriptions.c | 4 +-- .../tests/check/libs/pbutils.c | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/descriptions.c b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/descriptions.c index 7e85b14ad0..e8a8827e91 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/descriptions.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/descriptions.c @@ -471,8 +471,8 @@ format_info_get_desc (const FormatInfo * info, const GstCaps * caps) const gchar *subs; gint w_sub, h_sub, n_semi; - w_sub = GST_VIDEO_FORMAT_INFO_W_SUB (finfo, 1); - h_sub = GST_VIDEO_FORMAT_INFO_H_SUB (finfo, 1); + w_sub = 1 << GST_VIDEO_FORMAT_INFO_W_SUB (finfo, 1); + h_sub = 1 << GST_VIDEO_FORMAT_INFO_H_SUB (finfo, 1); if (w_sub == 1 && h_sub == 1) { subs = "4:4:4"; diff --git a/subprojects/gst-plugins-base/tests/check/libs/pbutils.c b/subprojects/gst-plugins-base/tests/check/libs/pbutils.c index 37eea09208..b7b7245e2c 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/pbutils.c +++ b/subprojects/gst-plugins-base/tests/check/libs/pbutils.c @@ -453,10 +453,36 @@ static const gchar *caps_strings[] = { /* raw video */ "video/x-raw, format=(string)RGB16, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1", "video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1", + "video/x-raw, format=(string)I420, width=(int)320, height=(int)240, framerate=(fraction)30/1", + "video/x-raw, format=(string)AYUV, width=(int)320, height=(int)240, framerate=(fraction)30/1", /* and a made-up format */ "video/x-tpm" }; +static gboolean +validate_video_subsampling (GstCaps * caps, gchar * desc) +{ + GstStructure *st; + const gchar *format; + + st = gst_caps_get_structure (caps, 0); + if (!gst_structure_has_name (st, "video/x-raw")) + return TRUE; + + format = gst_structure_get_string (st, "format"); + if (!format) + return TRUE; + + if (g_strcmp0 (format, "YUY2") == 0) + return g_str_has_suffix (desc, "4:2:2"); + if (g_strcmp0 (format, "I420") == 0) + return g_str_has_suffix (desc, "4:2:0"); + if (g_strcmp0 (format, "AYUV") == 0) + return g_str_has_suffix (desc, "4:4:4"); + + return TRUE; +} + GST_START_TEST (test_pb_utils_get_codec_description) { gint i; @@ -475,6 +501,7 @@ GST_START_TEST (test_pb_utils_get_codec_description) fail_unless (desc != NULL); GST_LOG (" - codec : %s", desc); fail_unless (g_utf8_validate (desc, -1, NULL)); + fail_unless (validate_video_subsampling (caps, desc)); g_free (desc); desc = gst_pb_utils_get_decoder_description (caps); fail_unless (desc != NULL);