From 36f653fdc53b03cbeeee0a3c758572e726a6b60b Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Mon, 27 Nov 2023 10:36:01 +0000 Subject: [PATCH] pbutils: Don't include default vp9 parameters in resulting codec mime string According to the document defining the vp9 codec string, the optional fields should all be present only if at least one of them has a non-default value. Part-of: --- .../gst-libs/gst/pbutils/codec-utils.c | 18 ++++++++++++------ .../gst-plugins-base/tests/check/libs/pbutils.c | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/codec-utils.c b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/codec-utils.c index a89f3b0..71d9180 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/codec-utils.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/codec-utils.c @@ -2471,7 +2471,8 @@ vp9_caps_get_mime_codec (GstCaps * caps) GstStructure *caps_st; const char *profile_str, *chroma_format_str, *colorimetry_str; guint bitdepth_luma, bitdepth_chroma; - guint8 profile = -1, chroma_format = -1, level = -1; + guint8 profile = -1, chroma_format = -1, level = -1, color_primaries = + -1, color_transfer = -1, color_matrix = -1; gboolean video_full_range; GstVideoColorimetry cinfo = { 0, }; GString *codec_string; @@ -2539,11 +2540,16 @@ vp9_caps_get_mime_codec (GstCaps * caps) goto done; } - /* optional but all or nothing */ - g_string_append_printf (codec_string, ".%02u.%02u.%02u.%02u.%02u", - chroma_format, gst_video_color_primaries_to_iso (cinfo.primaries), - gst_video_transfer_function_to_iso (cinfo.transfer), - gst_video_color_matrix_to_iso (cinfo.matrix), video_full_range); + /* optional but all or nothing. Include them if any parameter differs from the default value */ + color_primaries = gst_video_color_primaries_to_iso (cinfo.primaries); + color_transfer = gst_video_transfer_function_to_iso (cinfo.transfer); + color_matrix = gst_video_color_matrix_to_iso (cinfo.matrix); + if (chroma_format != 1 || color_primaries != 1 || color_transfer != 1 + || color_matrix != 1 || video_full_range) { + g_string_append_printf (codec_string, ".%02u.%02u.%02u.%02u.%02u", + chroma_format, color_primaries, color_transfer, color_matrix, + video_full_range); + } done: return g_string_free (codec_string, FALSE); diff --git a/subprojects/gst-plugins-base/tests/check/libs/pbutils.c b/subprojects/gst-plugins-base/tests/check/libs/pbutils.c index e22fdd1..37eea09 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/pbutils.c +++ b/subprojects/gst-plugins-base/tests/check/libs/pbutils.c @@ -1495,6 +1495,28 @@ GST_START_TEST (test_pb_utils_caps_mime_codec) g_free (mime_codec); gst_caps_unref (caps); + /* vp9 with default chroma subsampling, color primaries, color transfer, color + * matrix and luma/chroma encoded in the "legal" range*/ + caps = + gst_caps_from_string + ("video/x-vp9, width=(int)640, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)bt709, alignment=(string)super-frame, profile=(string)0, codec-alpha=(boolean)false"); + mime_codec = gst_codec_utils_caps_get_mime_codec (caps); + fail_unless_equals_string (mime_codec, "vp09.00.10.08"); + g_free (mime_codec); + gst_caps_unref (caps); + + /* vp9 with non-default chroma subsampling */ + caps = gst_caps_from_string ("video/x-vp9, width=(int)640, height=(int)480, " + "pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1, " + "chroma-format=(string)4:2:2, bit-depth-luma=(uint)8, " + "bit-depth-chroma=(uint)8, colorimetry=(string)bt709, " + "alignment=(string)super-frame, profile=(string)0, " + "codec-alpha=(boolean)false"); + mime_codec = gst_codec_utils_caps_get_mime_codec (caps); + fail_unless_equals_string (mime_codec, "vp09.00.10.08.02.01.01.01.00"); + g_free (mime_codec); + gst_caps_unref (caps); + /* mjpeg */ caps = gst_caps_new_empty_simple ("image/jpeg"); mime_codec = gst_codec_utils_caps_get_mime_codec (caps); -- 2.7.4