3 * unit test for rtphdrext-colorspace elements
5 * Copyright (C) 2020-2021 Collabora Ltd.
6 * @author: Jakub Adam <jakub.adam@collabora.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include <gst/check/gstcheck.h>
25 #include <gst/check/gstharness.h>
26 #include <gst/video/video-color.h>
27 #include <gst/video/video-hdr.h>
28 #include <gst/rtp/gstrtphdrext-colorspace.h>
32 const GstVideoColorimetry expected_colorimetry = {
33 GST_VIDEO_COLOR_RANGE_0_255,
34 GST_VIDEO_COLOR_MATRIX_BT601,
35 GST_VIDEO_TRANSFER_BT2020_10,
36 GST_VIDEO_COLOR_PRIMARIES_BT2020
39 const GstVideoChromaSite expected_chroma_site = GST_VIDEO_CHROMA_SITE_MPEG2;
41 const GstVideoMasteringDisplayInfo expected_display_info = {
42 {{1, 2}, {3, 4}, {5, 6}},
48 const GstVideoContentLightLevel expected_content_light_level = {
52 const guint8 vp8_payload[] = {
53 0x30, 0x00, 0x00, 0x9d, 0x01, 0x2a, 0xb0, 0x00, 0x90, 0x00, 0x06, 0x47,
54 0x08, 0x85, 0x85, 0x88, 0x99, 0x84, 0x88, 0x21, 0x00
57 /* validate that upstream colorspace information get embedded into RTP packets
58 * as Color Space header extension and correctly reconstructed in depayloader's
59 * srccaps. This variant of the test case creates the one-byte form of the
60 * header (without HDR metadata).
62 GST_START_TEST (test_rtphdrext_colorspace_onebyte)
65 GstElement *pay, *depay;
66 GstVideoColorimetry colorimetry;
67 GstVideoChromaSite chroma_site;
68 gchar *colorimetry_str;
70 GstCaps *src_caps, *caps, *expected_caps;
73 GstRTPHeaderExtension *pay_ext, *depay_ext;
75 h = gst_harness_new_parse ("rtpvp8pay ! rtpvp8depay");
77 pay = gst_harness_find_element (h, "rtpvp8pay");
78 depay = gst_harness_find_element (h, "rtpvp8depay");
81 GST_RTP_HEADER_EXTENSION (gst_element_factory_make ("rtphdrextcolorspace",
84 GST_RTP_HEADER_EXTENSION (gst_element_factory_make ("rtphdrextcolorspace",
87 gst_rtp_header_extension_set_id (pay_ext, EXTMAP_ID);
88 gst_rtp_header_extension_set_id (depay_ext, EXTMAP_ID);
90 g_signal_emit_by_name (pay, "add-extension", pay_ext);
91 g_signal_emit_by_name (depay, "add-extension", depay_ext);
93 colorimetry_str = gst_video_colorimetry_to_string (&expected_colorimetry);
94 src_caps = gst_caps_new_simple ("video/x-vp8",
95 "colorimetry", G_TYPE_STRING, colorimetry_str,
96 "chroma-site", G_TYPE_STRING,
97 gst_video_chroma_to_string (expected_chroma_site), NULL);
99 gst_harness_set_src_caps (h, src_caps);
101 gst_harness_push (h, gst_buffer_new_wrapped (g_memdup (vp8_payload,
102 sizeof (vp8_payload)), sizeof (vp8_payload)));
104 /* verify depayloader correctly reconstructs colorspace information in
106 pad = gst_element_get_static_pad (depay, "src");
107 caps = gst_pad_get_current_caps (pad);
108 s = gst_caps_get_structure (caps, 0);
109 gst_object_unref (pad);
111 str = gst_structure_get_string (s, "colorimetry");
112 fail_unless (str != NULL);
113 gst_video_colorimetry_from_string (&colorimetry, str);
114 fail_unless (gst_video_colorimetry_is_equal (&colorimetry,
115 &expected_colorimetry));
117 str = gst_structure_get_string (s, "chroma-site");
118 fail_unless (str != NULL);
119 chroma_site = gst_video_chroma_from_string (str);
120 fail_unless_equals_int (chroma_site, expected_chroma_site);
122 gst_caps_unref (caps);
124 /* verify the presence of Color Space extmap in caps */
125 pad = gst_element_get_static_pad (pay, "src");
126 caps = gst_pad_get_current_caps (pad);
127 expected_caps = gst_caps_from_string ("application/x-rtp, "
128 "extmap-" G_STRINGIFY (EXTMAP_ID) "=" GST_RTP_HDREXT_COLORSPACE_URI);
129 fail_unless (gst_caps_is_subset (caps, expected_caps));
130 gst_object_unref (pad);
131 gst_caps_unref (caps);
132 gst_caps_unref (expected_caps);
134 g_free (colorimetry_str);
136 gst_object_unref (pay_ext);
137 gst_object_unref (depay_ext);
138 gst_object_unref (pay);
139 gst_object_unref (depay);
140 gst_harness_teardown (h);
145 /* validate that upstream colorspace information get embedded into RTP packets
146 * as Color Space header extension and correctly reconstructed in depayloader's
147 * srccaps. This variant of the test case creates the two-byte form of the
148 * header (including HDR metadata).
150 GST_START_TEST (test_rtphdrext_colorspace_twobyte)
153 GstElement *pay, *depay;
154 GstVideoColorimetry colorimetry;
155 GstVideoChromaSite chroma_site;
156 GstVideoMasteringDisplayInfo display_info;
157 GstVideoContentLightLevel content_light_level;
158 gchar *colorimetry_str;
160 GstCaps *src_caps, *caps, *expected_caps;
163 GstRTPHeaderExtension *pay_ext, *depay_ext;
165 h = gst_harness_new_parse ("rtpvp8pay ! rtpvp8depay");
167 pay = gst_harness_find_element (h, "rtpvp8pay");
168 depay = gst_harness_find_element (h, "rtpvp8depay");
171 GST_RTP_HEADER_EXTENSION (gst_element_factory_make ("rtphdrextcolorspace",
174 GST_RTP_HEADER_EXTENSION (gst_element_factory_make ("rtphdrextcolorspace",
177 gst_rtp_header_extension_set_id (pay_ext, EXTMAP_ID);
178 gst_rtp_header_extension_set_id (depay_ext, EXTMAP_ID);
180 g_signal_emit_by_name (pay, "add-extension", pay_ext);
181 g_signal_emit_by_name (depay, "add-extension", depay_ext);
183 colorimetry_str = gst_video_colorimetry_to_string (&expected_colorimetry);
184 src_caps = gst_caps_new_simple ("video/x-vp8",
185 "colorimetry", G_TYPE_STRING, colorimetry_str,
186 "chroma-site", G_TYPE_STRING,
187 gst_video_chroma_to_string (expected_chroma_site), NULL);
188 gst_video_mastering_display_info_add_to_caps (&expected_display_info,
190 gst_video_content_light_level_add_to_caps (&expected_content_light_level,
193 gst_harness_set_src_caps (h, src_caps);
195 gst_harness_push (h, gst_buffer_new_wrapped (g_memdup (vp8_payload,
196 sizeof (vp8_payload)), sizeof (vp8_payload)));
198 /* verify depayloader correctly reconstructs colorspace information in
200 pad = gst_element_get_static_pad (depay, "src");
201 caps = gst_pad_get_current_caps (pad);
202 s = gst_caps_get_structure (caps, 0);
203 gst_object_unref (pad);
205 str = gst_structure_get_string (s, "colorimetry");
206 fail_unless (str != NULL);
207 gst_video_colorimetry_from_string (&colorimetry, str);
208 fail_unless (gst_video_colorimetry_is_equal (&colorimetry,
209 &expected_colorimetry));
211 str = gst_structure_get_string (s, "chroma-site");
212 fail_unless (str != NULL);
213 chroma_site = gst_video_chroma_from_string (str);
214 fail_unless_equals_int (chroma_site, expected_chroma_site);
216 gst_video_mastering_display_info_from_caps (&display_info, caps);
217 fail_unless (gst_video_mastering_display_info_is_equal (&display_info,
218 &expected_display_info));
220 gst_video_content_light_level_from_caps (&content_light_level, caps);
221 fail_unless (gst_video_content_light_level_is_equal (&content_light_level,
222 &expected_content_light_level));
224 gst_caps_unref (caps);
226 /* verify the presence of Color Space extmap in caps */
227 pad = gst_element_get_static_pad (pay, "src");
228 caps = gst_pad_get_current_caps (pad);
229 expected_caps = gst_caps_from_string ("application/x-rtp, "
230 "extmap-" G_STRINGIFY (EXTMAP_ID) "=" GST_RTP_HDREXT_COLORSPACE_URI);
231 fail_unless (gst_caps_is_subset (caps, expected_caps));
232 gst_object_unref (pad);
233 gst_caps_unref (caps);
234 gst_caps_unref (expected_caps);
236 g_free (colorimetry_str);
238 gst_object_unref (pay_ext);
239 gst_object_unref (depay_ext);
240 gst_object_unref (pay);
241 gst_object_unref (depay);
242 gst_harness_teardown (h);
248 rtphdrext_colorspace_suite (void)
250 Suite *s = suite_create ("rtphdrext_colorspace");
251 TCase *tc_chain = tcase_create ("general");
253 suite_add_tcase (s, tc_chain);
255 tcase_add_test (tc_chain, test_rtphdrext_colorspace_onebyte);
256 tcase_add_test (tc_chain, test_rtphdrext_colorspace_twobyte);
261 GST_CHECK_MAIN (rtphdrext_colorspace)