• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer unit tests for libgstpbutils
2  *
3  * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24 
25 #include <gst/check/gstcheck.h>
26 #include <gst/pbutils/pbutils.h>
27 #include <gst/base/gstbitwriter.h>
28 
29 #include <stdio.h>
30 #include <glib/gstdio.h>
31 #include <glib/gprintf.h>
32 
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>          /* for chmod() and getpid () */
35 #endif
36 
37 #ifdef HAVE_SYS_STAT_H
38 #include <sys/stat.h>           /* for chmod() */
39 #endif
40 
41 #ifdef G_OS_UNIX
42 #include <unistd.h>             /* for getpid() */
43 #endif
44 
45 static void
missing_msg_check_getters(GstMessage * msg)46 missing_msg_check_getters (GstMessage * msg)
47 {
48   gchar *str;
49 
50   str = gst_missing_plugin_message_get_installer_detail (msg);
51   fail_unless (str != NULL);
52   fail_unless (*str != '\0');
53   fail_unless (g_str_has_prefix (str, "gstreamer|"));
54   g_free (str);
55 
56   str = gst_missing_plugin_message_get_description (msg);
57   fail_unless (str != NULL);
58   fail_unless (*str != '\0');
59   g_free (str);
60 }
61 
GST_START_TEST(test_pb_utils_post_missing_messages)62 GST_START_TEST (test_pb_utils_post_missing_messages)
63 {
64   const GstStructure *s;
65   GstElement *pipeline;
66   GstMessage *msg;
67   GstCaps *caps;
68   GstBus *bus;
69 
70   gst_pb_utils_init ();
71 
72   pipeline = gst_pipeline_new ("pipeline");
73   bus = gst_element_get_bus (pipeline);
74 
75   /* first, test common assertion failure cases */
76   ASSERT_CRITICAL (msg = gst_missing_uri_source_message_new (NULL, "http"));
77   ASSERT_CRITICAL (gst_missing_uri_source_message_new (pipeline, NULL));
78 
79   ASSERT_CRITICAL (gst_missing_uri_sink_message_new (NULL, "http"));
80   ASSERT_CRITICAL (gst_missing_uri_sink_message_new (pipeline, NULL));
81 
82   ASSERT_CRITICAL (gst_missing_element_message_new (NULL, "rgbfyltr"));
83   ASSERT_CRITICAL (gst_missing_element_message_new (pipeline, NULL));
84 
85   caps = gst_caps_new_empty_simple ("audio/x-dontexist");
86 
87   ASSERT_CRITICAL (gst_missing_decoder_message_new (NULL, caps));
88   ASSERT_CRITICAL (gst_missing_decoder_message_new (pipeline, NULL));
89 
90   ASSERT_CRITICAL (gst_missing_encoder_message_new (NULL, caps));
91   ASSERT_CRITICAL (gst_missing_encoder_message_new (pipeline, NULL));
92 
93   gst_caps_unref (caps);
94 
95   /* URI source (with existing protocol) */
96   msg = gst_missing_uri_source_message_new (pipeline, "http");
97   fail_unless (msg != NULL);
98   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
99   fail_unless (gst_message_get_structure (msg) != NULL);
100   s = gst_message_get_structure (msg);
101   fail_unless (gst_structure_has_name (s, "missing-plugin"));
102   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
103   fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource");
104   fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
105   fail_unless_equals_string (gst_structure_get_string (s, "detail"), "http");
106   missing_msg_check_getters (msg);
107   gst_message_unref (msg);
108 
109   /* URI sink (with existing protocol) */
110   msg = gst_missing_uri_sink_message_new (pipeline, "smb");
111   fail_unless (msg != NULL);
112   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
113   fail_unless (gst_message_get_structure (msg) != NULL);
114   s = gst_message_get_structure (msg);
115   fail_unless (gst_structure_has_name (s, "missing-plugin"));
116   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
117   fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisink");
118   fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
119   fail_unless_equals_string (gst_structure_get_string (s, "detail"), "smb");
120   missing_msg_check_getters (msg);
121   gst_message_unref (msg);
122 
123   /* URI source (with bogus protocol) */
124   msg = gst_missing_uri_source_message_new (pipeline, "chchck");
125   fail_unless (msg != NULL);
126   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
127   fail_unless (gst_message_get_structure (msg) != NULL);
128   s = gst_message_get_structure (msg);
129   fail_unless (gst_structure_has_name (s, "missing-plugin"));
130   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
131   fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource");
132   fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
133   fail_unless_equals_string (gst_structure_get_string (s, "detail"), "chchck");
134   missing_msg_check_getters (msg);
135   gst_message_unref (msg);
136 
137   /* URI sink (with bogus protocol) */
138   msg = gst_missing_uri_sink_message_new (pipeline, "chchck");
139   fail_unless (msg != NULL);
140   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
141   fail_unless (gst_message_get_structure (msg) != NULL);
142   s = gst_message_get_structure (msg);
143   fail_unless (gst_structure_has_name (s, "missing-plugin"));
144   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
145   fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisink");
146   fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
147   fail_unless_equals_string (gst_structure_get_string (s, "detail"), "chchck");
148   missing_msg_check_getters (msg);
149   gst_message_unref (msg);
150 
151   /* element */
152   msg = gst_missing_element_message_new (pipeline, "foobar");
153   fail_unless (msg != NULL);
154   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
155   fail_unless (gst_message_get_structure (msg) != NULL);
156   s = gst_message_get_structure (msg);
157   fail_unless (gst_structure_has_name (s, "missing-plugin"));
158   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
159   fail_unless_equals_string (gst_structure_get_string (s, "type"), "element");
160   fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
161   fail_unless_equals_string (gst_structure_get_string (s, "detail"), "foobar");
162   missing_msg_check_getters (msg);
163   gst_message_unref (msg);
164 
165   /* create bogus caps that don't exist */
166   caps = gst_caps_new_simple ("do/x-not", "exist", G_TYPE_BOOLEAN, FALSE, NULL);
167 
168   /* decoder (with unknown caps) */
169   msg = gst_missing_decoder_message_new (pipeline, caps);
170   fail_unless (msg != NULL);
171   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
172   fail_unless (gst_message_get_structure (msg) != NULL);
173   s = gst_message_get_structure (msg);
174   fail_unless (gst_structure_has_name (s, "missing-plugin"));
175   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
176   fail_unless_equals_string (gst_structure_get_string (s, "type"), "decoder");
177   fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS));
178   missing_msg_check_getters (msg);
179   gst_message_unref (msg);
180 
181   /* encoder (with unknown caps) */
182   msg = gst_missing_encoder_message_new (pipeline, caps);
183   fail_unless (msg != NULL);
184   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
185   fail_unless (gst_message_get_structure (msg) != NULL);
186   s = gst_message_get_structure (msg);
187   fail_unless (gst_structure_has_name (s, "missing-plugin"));
188   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
189   fail_unless_equals_string (gst_structure_get_string (s, "type"), "encoder");
190   fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS));
191   missing_msg_check_getters (msg);
192   gst_message_unref (msg);
193 
194   gst_caps_unref (caps);
195 
196   /* create caps that exist */
197   caps = gst_caps_new_empty_simple ("video/x-matroska");
198   /* decoder (with known caps) */
199   msg = gst_missing_decoder_message_new (pipeline, caps);
200   fail_unless (msg != NULL);
201   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
202   fail_unless (gst_message_get_structure (msg) != NULL);
203   s = gst_message_get_structure (msg);
204   fail_unless (gst_structure_has_name (s, "missing-plugin"));
205   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
206   fail_unless_equals_string (gst_structure_get_string (s, "type"), "decoder");
207   fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS));
208   fail_unless (gst_structure_has_field_typed (s, "name", G_TYPE_STRING));
209   fail_unless (gst_structure_get_string (s, "name") != NULL);
210   missing_msg_check_getters (msg);
211   gst_message_unref (msg);
212 
213   /* encoder (with known caps) */
214   msg = gst_missing_encoder_message_new (pipeline, caps);
215   fail_unless (msg != NULL);
216   fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
217   fail_unless (gst_message_get_structure (msg) != NULL);
218   s = gst_message_get_structure (msg);
219   fail_unless (gst_structure_has_name (s, "missing-plugin"));
220   fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
221   fail_unless_equals_string (gst_structure_get_string (s, "type"), "encoder");
222   fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS));
223   fail_unless (gst_structure_has_field_typed (s, "name", G_TYPE_STRING));
224   fail_unless (gst_structure_get_string (s, "name") != NULL);
225   missing_msg_check_getters (msg);
226   gst_message_unref (msg);
227 
228   gst_caps_unref (caps);
229 
230   gst_element_set_state (pipeline, GST_STATE_NULL);
231   gst_object_unref (pipeline);
232   gst_object_unref (bus);
233 }
234 
235 GST_END_TEST;
236 
GST_START_TEST(test_pb_utils_init)237 GST_START_TEST (test_pb_utils_init)
238 {
239   /* should be fine to call multiple times */
240   gst_pb_utils_init ();
241   gst_pb_utils_init ();
242   gst_pb_utils_init ();
243   gst_pb_utils_init ();
244 }
245 
246 GST_END_TEST;
247 
248 static const gchar *caps_strings[] = {
249   /* formats with static descriptions */
250   "application/ogg", "application/vnd.rn-realmedia", "video/x-fli",
251   "video/x-flv", "video/x-matroska", "video/x-ms-asf", "video/x-msvideo",
252   "video/x-quicktime", "video/quicktime", "audio/x-ac3", "audio/ac3",
253   "audio/x-private-ac3", "audio/x-private1-ac3", "audio/x-adpcm",
254   "audio/aiff", "audio/x-alaw", "audio/amr", "audio/AMR", "audio/AMR-WB",
255   "audio/iLBC-sh", "audio/ms-gsm", "audio/qcelp", "audio/x-adpcm",
256   "audio/x-aiff", "audio/x-alac", "audio/x-amr-nb-sh", "audio/x-amr-wb-sh",
257   "audio/x-au", "audio/x-cinepak", "audio/x-dpcm", "audio/x-dts",
258   "audio/x-dv", "audio/x-flac", "audio/x-gsm", "audio/x-iec958",
259   "audio/x-iLBC", "audio/x-ircam", "audio/x-lpcm", "audio/x-private1-lpcm",
260   "audio/x-m4a", "audio/x-mod", "audio/x-mulaw", "audio/x-musepack",
261   "audio/x-nist", "audio/x-nsf", "audio/x-paris", "audio/x-qdm2",
262   "audio/x-ralf-mpeg4-generic", "audio/x-sds", "audio/x-shorten",
263   "audio/x-sid", "audio/x-sipro", "audio/x-spc", "audio/x-speex",
264   "audio/x-svx", "audio/x-tta", "audio/x-ttafile",
265   "audio/x-vnd.sony.atrac3", "audio/x-vorbis", "audio/x-voc", "audio/x-w64",
266   "audio/x-wav", "audio/x-wavpack", "audio/x-wavpack-correction",
267   "audio/x-wms", "audio/x-voxware", "audio/x-xi", "video/sp5x", "video/vivo",
268   "video/x-4xm", "video/x-apple-video", "video/x-camtasia",
269   "video/x-cdxa", "video/x-cinepak", "video/x-cirrus-logic-accupak",
270   "video/x-compressed-yuv", "subpicture/x-dvd",
271   "video/x-ffv", "video/x-flash-screen", "video/x-flash-video",
272   "video/x-h261", "video/x-huffyuv", "video/x-intel-h263", "video/x-jpeg",
273   "video/x-mjpeg", "video/x-mjpeg-b", "video/mpegts", "video/x-mng",
274   "video/x-mszh", "video/x-msvideocodec", "video/x-mve", "video/x-nut",
275   "video/x-nuv", "video/x-qdrw", "video/x-raw", "video/x-smc",
276   "video/x-smoke", "video/x-tarkin", "video/x-theora", "video/x-rle",
277   "video/x-ultimotion", "video/x-vcd", "video/x-vmnc", "video/x-vp3",
278   "video/x-vp5", "video/x-vp6", "video/x-vp6-flash", "video/x-vp7",
279   "video/x-zlib", "image/bmp", "image/x-bmp",
280   "image/x-MS-bmp", "image/gif", "image/jpeg", "image/jng", "image/png",
281   "image/pbm", "image/ppm", "image/svg+xml", "image/tiff",
282   "image/x-cmu-raster", "image/x-icon", "image/x-xcf", "image/x-pixmap",
283   "image/x-xpixmap", "image/x-quicktime", "image/x-sun-raster",
284   "image/x-tga", "video/x-dv", "video/x-dv",
285   /* some RTP formats */
286   "application/x-rtp, media=(string)video, encoding-name=(string)TimVCodec",
287   "application/x-rtp, media=(string)audio, encoding-name=(string)TimACodec",
288   "application/x-rtp, media=(string)application, encoding-name=(string)TimMux",
289   "application/x-rtp, media=(string)woohoo, encoding-name=(string)TPM",
290   /* incomplete RTP formats */
291   "application/x-rtp, media=(string)woohoo",
292   "application/x-rtp, encoding-name=(string)TPM",
293   "application/x-rtp, media=(string)woohoo",
294   /* formats with dynamic descriptions */
295   "audio/x-adpcm",
296   "audio/x-adpcm, layout=(string)dvi",
297   "audio/x-adpcm, layout=(string)swf",
298   "audio/x-adpcm, layout=(string)microsoft",
299   "audio/x-adpcm, layout=(string)quicktime",
300   "audio/mpeg, mpegversion=(int)4",
301   "audio/mpeg, mpegversion=(int)1, layer=(int)1",
302   "audio/mpeg, mpegversion=(int)1, layer=(int)2",
303   "audio/mpeg, mpegversion=(int)1, layer=(int)3",
304   "audio/mpeg, mpegversion=(int)1, layer=(int)99",
305   "audio/mpeg, mpegversion=(int)99",
306   "video/mpeg, mpegversion=(int)2, systemstream=(boolean)TRUE",
307   "video/mpeg, systemstream=(boolean)FALSE",
308   "video/mpeg, mpegversion=(int)2",
309   "video/mpeg, mpegversion=(int)1, systemstream=(boolean)FALSE",
310   "video/mpeg, mpegversion=(int)2, systemstream=(boolean)FALSE",
311   "video/mpeg, mpegversion=(int)4, systemstream=(boolean)FALSE",
312   "video/mpeg, mpegversion=(int)99, systemstream=(boolean)TRUE",
313   "video/mpeg, mpegversion=(int)99, systemstream=(boolean)FALSE",
314   "video/mpeg, mpegversion=(int)4, systemstream=(boolean)FALSE, profile=main",
315   "video/mpeg, mpegversion=(int)4, systemstream=(boolean)FALSE, profile=adsfad",
316   "video/mpeg",
317   "video/x-indeo, indeoversion=(int)3",
318   "video/x-indeo, indeoversion=(int)5",
319   "video/x-indeo",
320   "video/x-wmv, wmvversion=(int)1",
321   "video/x-wmv, wmvversion=(int)2",
322   "video/x-wmv, wmvversion=(int)3",
323   "video/x-wmv, wmvversion=(int)99",
324   "video/x-wmv",
325   "audio/x-wma, wmaversion=(int)1",
326   "audio/x-wma, wmaversion=(int)2",
327   "audio/x-wma, wmaversion=(int)3",
328   "audio/x-wma, wmaversion=(int)99",
329   "audio/x-wma",
330   "video/x-dirac",
331   "video/x-dirac, profile=(string)vc2-low-delay",
332   "video/x-dirac, profile=(string)vc2-simple",
333   "video/x-dirac, profile=(string)vc2-main",
334   "video/x-dirac, profile=(string)main",
335   "video/x-dirac, profile=(string)czvja",
336   "video/x-divx, divxversion=(int)3",
337   "video/x-divx, divxversion=(int)4",
338   "video/x-divx, divxversion=(int)5",
339   "video/x-divx, divxversion=(int)99",
340   "video/x-divx",
341   "video/x-svq, svqversion=(int)1",
342   "video/x-svq, svqversion=(int)3",
343   "video/x-svq, svqversion=(int)99",
344   "video/x-svq",
345   "video/x-h265, profile=(string)main",
346   "video/x-h265, profile=(string)xafasdf",
347   "video/x-h265",
348   "video/x-h264, variant=(string)itu",
349   "video/x-h264, variant=(string)videosoft",
350   "video/x-h264, variant=(string)foobar",
351   "video/x-h264",
352   "video/x-h264, profile=(string)foobar",
353   "video/x-h264, profile=(string)high-4:4:4-intra",
354   "video/x-h264, profile=(string)high",
355   "video/x-h263, variant=(string)itu",
356   "video/x-h263, variant=(string)lead",
357   "video/x-h263, variant=(string)microsoft",
358   "video/x-h263, variant=(string)vdolive",
359   "video/x-h263, variant=(string)vivo",
360   "video/x-h263, variant=(string)xirlink",
361   "video/x-h263, variant=(string)foobar",
362   "video/x-h263",
363   "video/x-msmpeg, msmpegversion=(int)41",
364   "video/x-msmpeg, msmpegversion=(int)42",
365   "video/x-msmpeg, msmpegversion=(int)43",
366   "video/x-msmpeg, msmpegversion=(int)99",
367   "video/x-msmpeg",
368   "video/x-pn-realvideo, rmversion=(int)1",
369   "video/x-pn-realvideo, rmversion=(int)2",
370   "video/x-pn-realvideo, rmversion=(int)3",
371   "video/x-pn-realvideo, rmversion=(int)4",
372   "video/x-pn-realvideo, rmversion=(int)99",
373   "video/x-pn-realvideo",
374   "audio/x-pn-realaudio, raversion=(int)1",
375   "audio/x-pn-realaudio, raversion=(int)2",
376   "audio/x-pn-realaudio, raversion=(int)99",
377   "audio/x-pn-realaudio",
378   "audio/x-mace, maceversion=(int)3",
379   "audio/x-mace, maceversion=(int)6",
380   "audio/x-mace, maceversion=(int)99",
381   "audio/x-mace",
382   "video/x-truemotion, trueversion=(int)1",
383   "video/x-truemotion, trueversion=(int)2",
384   "video/x-truemotion, trueversion=(int)99",
385   "video/x-truemotion",
386   "video/x-asus, asusversion=(int)1",
387   "video/x-asus, asusversion=(int)2",
388   "video/x-asus, asusversion=(int)99",
389   "video/x-asus",
390   "video/x-xan, wcversion=(int)1",
391   "video/x-xan, wcversion=(int)99",
392   "video/x-xan",
393   "video/x-ati-vcr, vcrversion=(int)1",
394   "video/x-ati-vcr, vcrversion=(int)2",
395   "video/x-ati-vcr, vcrversion=(int)99",
396   "video/x-ati-vcr",
397   /* raw audio */
398   "audio/x-raw, format=(string)S16LE, rate=(int)44100, channels=(int)2",
399   "audio/x-raw, format=(string)F32,rate=(int)22050, channels=(int)2",
400   /* raw video */
401   "video/x-raw, format=(string)RGB16, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1",
402   "video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1",
403   /* and a made-up format */
404   "video/x-tpm"
405 };
406 
GST_START_TEST(test_pb_utils_get_codec_description)407 GST_START_TEST (test_pb_utils_get_codec_description)
408 {
409   gint i;
410 
411   gst_pb_utils_init ();
412 
413   for (i = 0; i < G_N_ELEMENTS (caps_strings); ++i) {
414     GstCaps *caps;
415     gchar *desc;
416 
417     caps = gst_caps_from_string (caps_strings[i]);
418     fail_unless (caps != NULL, "could not create caps from string '%s'",
419         caps_strings[i]);
420     GST_LOG ("Caps %s:", caps_strings[i]);
421     desc = gst_pb_utils_get_codec_description (caps);
422     fail_unless (desc != NULL);
423     GST_LOG (" - codec   : %s", desc);
424     fail_unless (g_utf8_validate (desc, -1, NULL));
425     g_free (desc);
426     desc = gst_pb_utils_get_decoder_description (caps);
427     fail_unless (desc != NULL);
428     GST_LOG (" - decoder : %s", desc);
429     fail_unless (g_utf8_validate (desc, -1, NULL));
430     g_free (desc);
431     desc = gst_pb_utils_get_encoder_description (caps);
432     fail_unless (desc != NULL);
433     GST_LOG (" - encoder : %s", desc);
434     fail_unless (g_utf8_validate (desc, -1, NULL));
435     g_free (desc);
436     gst_caps_unref (caps);
437   }
438 }
439 
440 GST_END_TEST;
441 
442 
GST_START_TEST(test_pb_utils_taglist_add_codec_info)443 GST_START_TEST (test_pb_utils_taglist_add_codec_info)
444 {
445   GstTagList *list;
446   GstCaps *caps, *bogus_caps;
447   gchar *res;
448 
449   gst_pb_utils_init ();
450   list = gst_tag_list_new_empty ();
451   caps = gst_caps_new_empty_simple ("video/x-theora");
452   ASSERT_CRITICAL (fail_if
453       (gst_pb_utils_add_codec_description_to_tag_list (NULL,
454               GST_TAG_VIDEO_CODEC, caps)));
455   ASSERT_CRITICAL (fail_if
456       (gst_pb_utils_add_codec_description_to_tag_list (list, "asdfa", caps)));
457   ASSERT_CRITICAL (fail_if
458       (gst_pb_utils_add_codec_description_to_tag_list (list,
459               GST_TAG_IMAGE, caps)));
460   ASSERT_CRITICAL (fail_if
461       (gst_pb_utils_add_codec_description_to_tag_list (list,
462               GST_TAG_VIDEO_CODEC, NULL)));
463 
464   /* Try adding bogus caps (should fail) */
465   bogus_caps = gst_caps_new_empty_simple ("bogus/format");
466   fail_if (gst_pb_utils_add_codec_description_to_tag_list (list,
467           GST_TAG_VIDEO_CODEC, bogus_caps));
468   gst_caps_unref (bogus_caps);
469 
470   /* Try adding valid caps with known tag */
471   fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list,
472           GST_TAG_VIDEO_CODEC, caps));
473   fail_if (gst_tag_list_is_empty (list));
474   fail_unless (gst_tag_list_get_string (list, GST_TAG_VIDEO_CODEC, &res));
475   g_free (res);
476   gst_tag_list_unref (list);
477 
478   /* Try adding valid caps with auto-tag (for video, audio, subtitle, generic) */
479   list = gst_tag_list_new_empty ();
480   fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
481           caps));
482   fail_if (gst_tag_list_is_empty (list));
483   fail_unless (gst_tag_list_get_string (list, GST_TAG_VIDEO_CODEC, &res));
484   g_free (res);
485   gst_tag_list_unref (list);
486   gst_caps_unref (caps);
487 
488   list = gst_tag_list_new_empty ();
489   caps = gst_caps_new_empty_simple ("audio/x-vorbis");
490   fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
491           caps));
492   fail_if (gst_tag_list_is_empty (list));
493   fail_unless (gst_tag_list_get_string (list, GST_TAG_AUDIO_CODEC, &res));
494   g_free (res);
495   gst_tag_list_unref (list);
496   gst_caps_unref (caps);
497 
498   list = gst_tag_list_new_empty ();
499   caps = gst_caps_new_empty_simple ("subtitle/x-kate");
500   fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
501           caps));
502   fail_if (gst_tag_list_is_empty (list));
503   fail_unless (gst_tag_list_get_string (list, GST_TAG_SUBTITLE_CODEC, &res));
504   g_free (res);
505   gst_tag_list_unref (list);
506   gst_caps_unref (caps);
507 
508   list = gst_tag_list_new_empty ();
509   caps = gst_caps_new_empty_simple ("application/ogg");
510   fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
511           caps));
512   fail_if (gst_tag_list_is_empty (list));
513   fail_unless (gst_tag_list_get_string (list, GST_TAG_CONTAINER_FORMAT, &res));
514   g_free (res);
515   gst_tag_list_unref (list);
516   gst_caps_unref (caps);
517 
518   list = gst_tag_list_new_empty ();
519   caps = gst_caps_new_empty_simple ("image/bmp");
520   fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
521           caps));
522   fail_if (gst_tag_list_is_empty (list));
523   fail_unless (gst_tag_list_get_string (list, GST_TAG_CODEC, &res));
524   g_free (res);
525   gst_tag_list_unref (list);
526   gst_caps_unref (caps);
527 }
528 
529 GST_END_TEST;
530 
531 static gint marker;
532 
533 static void
result_cb(GstInstallPluginsReturn result,gpointer user_data)534 result_cb (GstInstallPluginsReturn result, gpointer user_data)
535 {
536   GST_LOG ("result = %u, user_data = %p", result, user_data);
537 
538   fail_unless (user_data == (gpointer) & marker);
539 
540   marker = result;
541 }
542 
543 #define SCRIPT_NO_XID \
544     "#!/bin/sh\n"                                  \
545     "if test x$1 != xdetail1; then exit 21; fi;\n" \
546     "if test x$2 != xdetail2; then exit 22; fi;\n" \
547     "exit 1\n"
548 
549 #define SCRIPT_WITH_XID \
550     "#!/bin/sh\n"                                  \
551     "if test x$1 != 'x--transient-for=42'; then exit 21; fi;\n"      \
552     "if test x$2 != xdetail1; then exit 22; fi;\n" \
553     "if test x$3 != xdetail2; then exit 23; fi;\n" \
554     "exit 0\n"
555 
556 /* make sure our script gets called with the right parameters */
557 static void
test_pb_utils_install_plugins_do_callout(const gchar * const * details,GstInstallPluginsContext * ctx,const gchar * script,GstInstallPluginsReturn expected_result)558 test_pb_utils_install_plugins_do_callout (const gchar * const *details,
559     GstInstallPluginsContext * ctx, const gchar * script,
560     GstInstallPluginsReturn expected_result)
561 {
562 #ifdef G_OS_UNIX
563   GstInstallPluginsReturn ret;
564   GError *err = NULL;
565   gchar *path;
566 
567   path = g_strdup_printf ("%s/gst-plugins-base-unit-test-helper.%s.%lu",
568       g_get_tmp_dir (), (g_get_user_name ())? g_get_user_name () : "nobody",
569       (gulong) getpid ());
570 
571   if (!g_file_set_contents (path, script, -1, &err)) {
572     GST_DEBUG ("Failed to write test script to %s: %s", path, err->message);
573     g_error_free (err);
574     goto done;
575   }
576 
577   if (chmod (path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
578     GST_DEBUG ("Could not set mode u+rwx on '%s'", path);
579     goto done;
580   }
581 
582   /* test gst_install_plugins_supported() I */
583   g_setenv ("GST_INSTALL_PLUGINS_HELPER", "/i/do/not/ex.ist!", 1);
584   fail_if (gst_install_plugins_supported ());
585 
586   GST_LOG ("setting GST_INSTALL_PLUGINS_HELPER to '%s'", path);
587   g_setenv ("GST_INSTALL_PLUGINS_HELPER", path, 1);
588 
589   /* test gst_install_plugins_supported() II */
590   fail_unless (gst_install_plugins_supported ());
591 
592   /* test sync callout */
593   ret = gst_install_plugins_sync (details, ctx);
594   fail_unless (ret == GST_INSTALL_PLUGINS_HELPER_MISSING ||
595       ret == expected_result,
596       "gst_install_plugins_sync() failed with unexpected ret %d, which is "
597       "neither HELPER_MISSING nor %d", ret, expected_result);
598 
599   /* test async callout */
600   marker = -333;
601   ret = gst_install_plugins_async (details, ctx, result_cb,
602       (gpointer) & marker);
603   fail_unless (ret == GST_INSTALL_PLUGINS_HELPER_MISSING ||
604       ret == GST_INSTALL_PLUGINS_STARTED_OK,
605       "gst_install_plugins_async() failed with unexpected ret %d", ret);
606   if (ret == GST_INSTALL_PLUGINS_STARTED_OK) {
607     while (marker == -333) {
608       g_usleep (500);
609       g_main_context_iteration (NULL, FALSE);
610     }
611     /* and check that the callback was called with the expected code */
612     fail_unless_equals_int (marker, expected_result);
613   }
614 
615 done:
616 
617   g_unlink (path);
618   g_free (path);
619 #endif /* G_OS_UNIX */
620 }
621 
GST_START_TEST(test_pb_utils_install_plugins)622 GST_START_TEST (test_pb_utils_install_plugins)
623 {
624   GstInstallPluginsContext *ctx;
625   GstInstallPluginsReturn ret;
626   const gchar *details[] = { "detail1", "detail2", NULL };
627   const gchar *details_multi[] = { "detail1", "detail1", "detail2", NULL };
628 
629   ctx = gst_install_plugins_context_new ();
630 
631   ASSERT_CRITICAL (ret = gst_install_plugins_sync (NULL, ctx));
632   ASSERT_CRITICAL (ret =
633       gst_install_plugins_async (NULL, ctx, result_cb, (gpointer) & marker));
634   ASSERT_CRITICAL (ret =
635       gst_install_plugins_async (details, ctx, NULL, (gpointer) & marker));
636 
637   /* make sure the functions return the right error code if the helper does
638    * not exist */
639   g_setenv ("GST_INSTALL_PLUGINS_HELPER", "/does/not/ex/is.t", 1);
640   ret = gst_install_plugins_sync (details, NULL);
641   fail_unless_equals_int (ret, GST_INSTALL_PLUGINS_HELPER_MISSING);
642 
643   marker = -333;
644   ret =
645       gst_install_plugins_async (details, NULL, result_cb, (gpointer) & marker);
646   fail_unless_equals_int (ret, GST_INSTALL_PLUGINS_HELPER_MISSING);
647   /* and check that the callback wasn't called */
648   fail_unless_equals_int (marker, -333);
649 
650   /* now make sure our scripts are actually called as expected (if possible) */
651   test_pb_utils_install_plugins_do_callout (details, NULL, SCRIPT_NO_XID,
652       GST_INSTALL_PLUGINS_NOT_FOUND);
653 
654   /* and again with context */
655   gst_install_plugins_context_set_xid (ctx, 42);
656   test_pb_utils_install_plugins_do_callout (details, ctx, SCRIPT_WITH_XID,
657       GST_INSTALL_PLUGINS_SUCCESS);
658 
659   /* and make sure that duplicate detail strings get dropped */
660   test_pb_utils_install_plugins_do_callout (details_multi, NULL, SCRIPT_NO_XID,
661       GST_INSTALL_PLUGINS_NOT_FOUND);
662 
663   /* and the same again with context */
664   gst_install_plugins_context_set_xid (ctx, 42);
665   test_pb_utils_install_plugins_do_callout (details_multi, ctx, SCRIPT_WITH_XID,
666       GST_INSTALL_PLUGINS_SUCCESS);
667 
668   /* and free the context now that we don't need it any longer */
669   gst_install_plugins_context_free (ctx);
670 
671   /* completely silly test to check gst_install_plugins_return_get_name()
672    * is somewhat well-behaved */
673   {
674     gint i;
675 
676     for (i = -99; i < 16738; ++i) {
677       const gchar *s;
678 
679       s = gst_install_plugins_return_get_name ((GstInstallPluginsReturn) i);
680       fail_unless (s != NULL);
681       /* GST_LOG ("%5d = %s", i, s); */
682     }
683   }
684 }
685 
686 GST_END_TEST;
687 
GST_START_TEST(test_pb_utils_installer_details)688 GST_START_TEST (test_pb_utils_installer_details)
689 {
690   GstMessage *msg;
691   GstElement *el;
692   GstCaps *caps;
693   gchar *detail1, *detail2;
694 
695   el = gst_pipeline_new ("dummy-element");
696 
697   /* uri source */
698   detail1 = gst_missing_uri_source_installer_detail_new ("http");
699   fail_unless (detail1 != NULL);
700   fail_unless (g_str_has_prefix (detail1, "gstreamer|1.0|"));
701   fail_unless (g_str_has_suffix (detail1, "|urisource-http"));
702   msg = gst_missing_uri_source_message_new (el, "http");
703   fail_unless (msg != NULL);
704   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
705   fail_unless (detail2 != NULL);
706   gst_message_unref (msg);
707   fail_unless_equals_string (detail1, detail2);
708   g_free (detail1);
709   g_free (detail2);
710 
711   /* uri sink */
712   detail1 = gst_missing_uri_sink_installer_detail_new ("http");
713   fail_unless (detail1 != NULL);
714   fail_unless (g_str_has_prefix (detail1, "gstreamer|1.0|"));
715   fail_unless (g_str_has_suffix (detail1, "|urisink-http"));
716   msg = gst_missing_uri_sink_message_new (el, "http");
717   fail_unless (msg != NULL);
718   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
719   fail_unless (detail2 != NULL);
720   gst_message_unref (msg);
721   fail_unless_equals_string (detail1, detail2);
722   g_free (detail1);
723   g_free (detail2);
724 
725   /* element */
726   detail1 = gst_missing_element_installer_detail_new ("deinterlace");
727   fail_unless (detail1 != NULL);
728   fail_unless (g_str_has_prefix (detail1, "gstreamer|1.0|"));
729   fail_unless (g_str_has_suffix (detail1, "|element-deinterlace"));
730   msg = gst_missing_element_message_new (el, "deinterlace");
731   fail_unless (msg != NULL);
732   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
733   fail_unless (detail2 != NULL);
734   gst_message_unref (msg);
735   fail_unless_equals_string (detail1, detail2);
736   g_free (detail1);
737   g_free (detail2);
738 
739   /* decoder */
740   caps = gst_caps_new_simple ("audio/x-spiffy", "spiffyversion", G_TYPE_INT,
741       2, "channels", G_TYPE_INT, 6, NULL);
742   detail1 = gst_missing_decoder_installer_detail_new (caps);
743   fail_unless (detail1 != NULL);
744   fail_unless (g_str_has_prefix (detail1, "gstreamer|1.0|"));
745   fail_unless (g_str_has_suffix (detail1,
746           "|decoder-audio/x-spiffy, spiffyversion=(int)2"));
747   msg = gst_missing_decoder_message_new (el, caps);
748   fail_unless (msg != NULL);
749   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
750   fail_unless (detail2 != NULL);
751   gst_message_unref (msg);
752   gst_caps_unref (caps);
753   fail_unless_equals_string (detail1, detail2);
754   g_free (detail1);
755   g_free (detail2);
756 
757   /* encoder */
758   caps = gst_caps_new_simple ("audio/x-spiffy", "spiffyversion", G_TYPE_INT,
759       2, "channels", G_TYPE_INT, 6, NULL);
760   detail1 = gst_missing_encoder_installer_detail_new (caps);
761   fail_unless (g_str_has_prefix (detail1, "gstreamer|1.0|"));
762   fail_unless (g_str_has_suffix (detail1,
763           "|encoder-audio/x-spiffy, spiffyversion=(int)2"));
764   fail_unless (detail1 != NULL);
765   msg = gst_missing_encoder_message_new (el, caps);
766   fail_unless (msg != NULL);
767   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
768   fail_unless (detail2 != NULL);
769   gst_message_unref (msg);
770   gst_caps_unref (caps);
771   fail_unless_equals_string (detail1, detail2);
772   g_free (detail1);
773   g_free (detail2);
774 
775   gst_object_unref (el);
776 }
777 
778 GST_END_TEST;
779 
GST_START_TEST(test_pb_utils_versions)780 GST_START_TEST (test_pb_utils_versions)
781 {
782   gchar *s;
783   guint maj, min, mic, nano;
784 
785   gst_plugins_base_version (NULL, NULL, NULL, NULL);
786   gst_plugins_base_version (&maj, &min, &mic, &nano);
787   fail_unless_equals_int (maj, GST_PLUGINS_BASE_VERSION_MAJOR);
788   fail_unless_equals_int (min, GST_PLUGINS_BASE_VERSION_MINOR);
789   fail_unless_equals_int (mic, GST_PLUGINS_BASE_VERSION_MICRO);
790   fail_unless_equals_int (nano, GST_PLUGINS_BASE_VERSION_NANO);
791 
792   s = gst_plugins_base_version_string ();
793   if (GST_PLUGINS_BASE_VERSION_NANO == 0) {
794     fail_if (strstr (s, "GIT") || strstr (s, "git") || strstr (s, "prerel"));
795   }
796   if (GST_PLUGINS_BASE_VERSION_NANO == 1) {
797     fail_unless (strstr (s, "GIT") || strstr (s, "git"));
798   }
799   if (GST_PLUGINS_BASE_VERSION_NANO >= 2) {
800     fail_unless (strstr (s, "Prerelease") || strstr (s, "prerelease"));
801   }
802   g_free (s);
803 }
804 
805 GST_END_TEST;
806 
GST_START_TEST(test_pb_utils_aac_get_profile)807 GST_START_TEST (test_pb_utils_aac_get_profile)
808 {
809   const guint8 aac_config[] = { 0x11, 0x90, 0x56, 0xE5, 0x00 };
810   const guint8 aac_config_sre[] = { 0x17, 0x80, 0x91, 0xA2, 0x82, 0x00 };
811   const guint8 heaac_config[] = { 0x2B, 0x11, 0x88, 0x00, 0x06, 0x01, 0x02 };
812   const gchar *profile, *level;
813   guint sample_rate;
814   GstBitWriter *wr;
815   guint8 *buf;
816   guint buf_len;
817 
818   profile = gst_codec_utils_aac_get_profile (aac_config, sizeof (aac_config));
819   fail_unless (profile != NULL);
820   fail_unless_equals_string (profile, "lc");
821 
822   level = gst_codec_utils_aac_get_level (aac_config, sizeof (aac_config));
823   fail_unless_equals_string (level, "2");
824 
825   sample_rate =
826       gst_codec_utils_aac_get_sample_rate (aac_config, sizeof (aac_config));
827   fail_unless_equals_int (sample_rate, 48000);
828 
829   sample_rate =
830       gst_codec_utils_aac_get_sample_rate (aac_config_sre,
831       sizeof (aac_config_sre));
832   fail_unless_equals_int (sample_rate, 0x12345);
833 
834   profile =
835       gst_codec_utils_aac_get_profile (heaac_config, sizeof (heaac_config));
836   fail_unless (profile != NULL);
837   fail_unless_equals_string (profile, "lc");
838 
839   level = gst_codec_utils_aac_get_level (heaac_config, sizeof (heaac_config));
840   fail_unless_equals_string (level, "2");
841 
842   sample_rate =
843       gst_codec_utils_aac_get_sample_rate (heaac_config, sizeof (heaac_config));
844   fail_unless_equals_int (sample_rate, 48000);
845 
846   wr = gst_bit_writer_new ();
847   fail_if (wr == NULL);
848   gst_bit_writer_put_bits_uint8 (wr, 5, 5);     /* object_type = 5 (SBR) */
849   gst_bit_writer_put_bits_uint8 (wr, 3, 4);     /* freq_index = 3 (48KHz) */
850   gst_bit_writer_put_bits_uint8 (wr, 2, 4);     /* channel_config = 2 (L&R) */
851   gst_bit_writer_put_bits_uint8 (wr, 0x0f, 4);  /* freq_index extension */
852   gst_bit_writer_put_bits_uint32 (wr, 87654, 24);       /* freq */
853   gst_bit_writer_put_bits_uint8 (wr, 2, 5);     /* object_type = 2 (LC) */
854 
855   buf = gst_bit_writer_get_data (wr);
856   buf_len = gst_bit_writer_get_size (wr);
857   profile = gst_codec_utils_aac_get_profile (buf, buf_len);
858   fail_unless (profile != NULL);
859   fail_unless_equals_string (profile, "lc");
860   level = gst_codec_utils_aac_get_level (buf, buf_len);
861   fail_unless (level != NULL);
862   fail_unless_equals_string (level, "5");
863   sample_rate = gst_codec_utils_aac_get_sample_rate (buf, buf_len);
864   fail_unless_equals_int (sample_rate, 87654);
865   gst_bit_writer_free (wr);
866 }
867 
868 GST_END_TEST;
869 
870 #define SPS_LEN 3
871 #define SPS_CONSTRAINT_SET_FLAG_0 1 << 7
872 #define SPS_CONSTRAINT_SET_FLAG_1 (1 << 6)
873 #define SPS_CONSTRAINT_SET_FLAG_2 (1 << 5)
874 #define SPS_CONSTRAINT_SET_FLAG_3 (1 << 4)
875 #define SPS_CONSTRAINT_SET_FLAG_4 (1 << 3)
876 #define SPS_CONSTRAINT_SET_FLAG_5 (1 << 2)
877 
878 static void
fill_h264_sps(guint8 * sps,guint8 profile_idc,guint constraint_set_flags,guint8 level_idc)879 fill_h264_sps (guint8 * sps,
880     guint8 profile_idc, guint constraint_set_flags, guint8 level_idc)
881 {
882   memset (sps, 0x0, SPS_LEN);
883   /*
884    * * Bit 0:7   - Profile indication
885    * * Bit 8     - constraint_set0_flag
886    * * Bit 9     - constraint_set1_flag
887    * * Bit 10    - constraint_set2_flag
888    * * Bit 11    - constraint_set3_flag
889    * * Bit 12    - constraint_set4_flag
890    * * Bit 13    - constraint_set5_flag
891    * * Bit 14:15 - Reserved
892    * * Bit 16:24 - Level indication
893    * */
894   sps[0] = profile_idc;
895   sps[1] |= constraint_set_flags;
896   sps[2] = level_idc;
897 }
898 
GST_START_TEST(test_pb_utils_h264_profiles)899 GST_START_TEST (test_pb_utils_h264_profiles)
900 {
901   guint8 sps[SPS_LEN] = { 0, };
902   const gchar *profile;
903 
904   fill_h264_sps (sps, 66, 0, 0);
905   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
906   fail_unless_equals_string (profile, "baseline");
907 
908   fill_h264_sps (sps, 66, SPS_CONSTRAINT_SET_FLAG_1, 0);
909   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
910   fail_unless_equals_string (profile, "constrained-baseline");
911 
912   fill_h264_sps (sps, 77, 0, 0);
913   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
914   fail_unless_equals_string (profile, "main");
915 
916   fill_h264_sps (sps, 88, 0, 0);
917   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
918   fail_unless_equals_string (profile, "extended");
919 
920   fill_h264_sps (sps, 100, 0, 0);
921   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
922   fail_unless_equals_string (profile, "high");
923 
924   fill_h264_sps (sps, 100,
925       SPS_CONSTRAINT_SET_FLAG_4 | SPS_CONSTRAINT_SET_FLAG_5, 0);
926   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
927   fail_unless_equals_string (profile, "constrained-high");
928 
929   fill_h264_sps (sps, 100, SPS_CONSTRAINT_SET_FLAG_4, 0);
930   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
931   fail_unless_equals_string (profile, "progressive-high");
932 
933   fill_h264_sps (sps, 110, 0, 0);
934   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
935   fail_unless_equals_string (profile, "high-10");
936 
937   fill_h264_sps (sps, 110, SPS_CONSTRAINT_SET_FLAG_3, 0);
938   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
939   fail_unless_equals_string (profile, "high-10-intra");
940 
941   fill_h264_sps (sps, 110, SPS_CONSTRAINT_SET_FLAG_4, 0);
942   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
943   fail_unless_equals_string (profile, "progressive-high-10");
944 
945   fill_h264_sps (sps, 122, 0, 0);
946   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
947   fail_unless_equals_string (profile, "high-4:2:2");
948 
949   fill_h264_sps (sps, 122, SPS_CONSTRAINT_SET_FLAG_3, 0);
950   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
951   fail_unless_equals_string (profile, "high-4:2:2-intra");
952 
953   fill_h264_sps (sps, 244, 0, 0);
954   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
955   fail_unless_equals_string (profile, "high-4:4:4");
956 
957   fill_h264_sps (sps, 244, SPS_CONSTRAINT_SET_FLAG_3, 0);
958   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
959   fail_unless_equals_string (profile, "high-4:4:4-intra");
960 
961   fill_h264_sps (sps, 44, 0, 0);
962   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
963   fail_unless_equals_string (profile, "cavlc-4:4:4-intra");
964 
965   fill_h264_sps (sps, 118, 0, 0);
966   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
967   fail_unless_equals_string (profile, "multiview-high");
968 
969   fill_h264_sps (sps, 128, 0, 0);
970   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
971   fail_unless_equals_string (profile, "stereo-high");
972 
973   fill_h264_sps (sps, 83, 0, 0);
974   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
975   fail_unless_equals_string (profile, "scalable-baseline");
976 
977   fill_h264_sps (sps, 83, SPS_CONSTRAINT_SET_FLAG_5, 0);
978   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
979   fail_unless_equals_string (profile, "scalable-constrained-baseline");
980 
981   fill_h264_sps (sps, 86, 0, 0);
982   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
983   fail_unless_equals_string (profile, "scalable-high");
984 
985   fill_h264_sps (sps, 86, SPS_CONSTRAINT_SET_FLAG_3, 0);
986   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
987   fail_unless_equals_string (profile, "scalable-high-intra");
988 
989   fill_h264_sps (sps, 86, SPS_CONSTRAINT_SET_FLAG_5, 0);
990   profile = gst_codec_utils_h264_get_profile (sps, SPS_LEN);
991   fail_unless_equals_string (profile, "scalable-constrained-high");
992 
993 }
994 
995 GST_END_TEST;
996 
GST_START_TEST(test_pb_utils_h264_get_profile_flags_level)997 GST_START_TEST (test_pb_utils_h264_get_profile_flags_level)
998 {
999   gboolean ret = FALSE;
1000   guint codec_data_len = 7;
1001   guint8 codec_data[] = { 0x01, 0x64, 0x00, 0x32, 0x00, 0x00, 0x00 };
1002   guint8 codec_data_bad_version[] =
1003       { 0x00, 0x64, 0x00, 0x32, 0x00, 0x00, 0x00 };
1004   guint8 profile;
1005   guint8 flags;
1006   guint8 level;
1007 
1008   /* happy path */
1009   ret =
1010       gst_codec_utils_h264_get_profile_flags_level (codec_data, codec_data_len,
1011       &profile, &flags, &level);
1012   fail_unless (ret == TRUE);
1013   fail_unless (profile == 0x64);
1014   fail_unless (flags == 0x00);
1015   fail_unless (level == 0x32);
1016 
1017   /* happy path, return locations null */
1018   ret =
1019       gst_codec_utils_h264_get_profile_flags_level (codec_data, codec_data_len,
1020       NULL, NULL, NULL);
1021   fail_unless (ret == TRUE);
1022 
1023   /* data too short */
1024   ret =
1025       gst_codec_utils_h264_get_profile_flags_level (codec_data, 6, &profile,
1026       &flags, &level);
1027   fail_unless (ret == FALSE);
1028 
1029   /* wrong codec version */
1030   ret =
1031       gst_codec_utils_h264_get_profile_flags_level (codec_data_bad_version,
1032       codec_data_len, &profile, &flags, &level);
1033   fail_unless (ret == FALSE);
1034 }
1035 
1036 GST_END_TEST;
1037 
1038 #define PROFILE_TIER_LEVEL_LEN 11
1039 
1040 static void
fill_h265_profile(guint8 * profile_tier_level,guint8 profile_idc,guint8 max_14bit_flag,guint8 max_12bit_flag,guint8 max_10bit_flag,guint8 max_8bit_flag,guint8 max_422_flag,guint8 max_420_flag,guint8 max_mono_flag,guint8 intra_flag,guint8 one_pic_flag,guint8 lower_bit_rate_flag)1041 fill_h265_profile (guint8 * profile_tier_level,
1042     guint8 profile_idc, guint8 max_14bit_flag, guint8 max_12bit_flag,
1043     guint8 max_10bit_flag, guint8 max_8bit_flag, guint8 max_422_flag,
1044     guint8 max_420_flag, guint8 max_mono_flag, guint8 intra_flag,
1045     guint8 one_pic_flag, guint8 lower_bit_rate_flag)
1046 {
1047   /* Bit 0:1   - general_profile_space
1048    * Bit 2     - general_tier_flag
1049    * Bit 3:7   - general_profile_idc
1050    * Bit 8:39  - gernal_profile_compatibility_flags
1051    * Bit 40    - general_progressive_source_flag
1052    * Bit 41    - general_interlaced_source_flag
1053    * Bit 42    - general_non_packed_constraint_flag
1054    * Bit 43    - general_frame_only_constraint_flag
1055    */
1056 
1057   memset (profile_tier_level, 0x0, PROFILE_TIER_LEVEL_LEN);
1058 
1059   profile_tier_level[0] = profile_idc;
1060 
1061   if (profile_idc < 4)
1062     return;
1063 
1064   profile_tier_level[5] |= (max_12bit_flag << 3);
1065   profile_tier_level[5] |= (max_10bit_flag << 2);
1066   profile_tier_level[5] |= (max_8bit_flag << 1);
1067   profile_tier_level[5] |= max_422_flag;
1068   profile_tier_level[6] |= (max_420_flag << 7);
1069   profile_tier_level[6] |= (max_mono_flag << 6);
1070   profile_tier_level[6] |= (intra_flag << 5);
1071   profile_tier_level[6] |= (one_pic_flag << 4);
1072   profile_tier_level[6] |= (lower_bit_rate_flag << 3);
1073   profile_tier_level[6] |= (max_14bit_flag << 2);
1074 }
1075 
GST_START_TEST(test_pb_utils_h265_profiles)1076 GST_START_TEST (test_pb_utils_h265_profiles)
1077 {
1078   guint8 profile_tier_level[PROFILE_TIER_LEVEL_LEN] = { 0, };
1079   const gchar *profile;
1080 
1081   fill_h265_profile (profile_tier_level, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1082   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1083       sizeof (profile_tier_level));
1084   fail_unless_equals_string (profile, "main");
1085 
1086   fill_h265_profile (profile_tier_level, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1087   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1088       sizeof (profile_tier_level));
1089   fail_unless_equals_string (profile, "main-10");
1090 
1091   fill_h265_profile (profile_tier_level, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1092   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1093       sizeof (profile_tier_level));
1094   fail_unless_equals_string (profile, "main-still-picture");
1095 
1096   /* Format range extensions profiles */
1097   fill_h265_profile (profile_tier_level, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1098   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1099       sizeof (profile_tier_level));
1100   fail_unless (profile == NULL);
1101 
1102   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1);
1103   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1104       sizeof (profile_tier_level));
1105   fail_unless_equals_string (profile, "monochrome");
1106 
1107   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1);
1108   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1109       sizeof (profile_tier_level));
1110   fail_unless_equals_string (profile, "monochrome-10");
1111 
1112   fill_h265_profile (profile_tier_level, 4, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1);
1113   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1114       sizeof (profile_tier_level));
1115   fail_unless_equals_string (profile, "monochrome-12");
1116 
1117   fill_h265_profile (profile_tier_level, 4, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1);
1118   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1119       sizeof (profile_tier_level));
1120   fail_unless_equals_string (profile, "monochrome-16");
1121 
1122   fill_h265_profile (profile_tier_level, 4, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1);
1123   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1124       sizeof (profile_tier_level));
1125   fail_unless_equals_string (profile, "main-12");
1126 
1127   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1);
1128   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1129       sizeof (profile_tier_level));
1130   fail_unless_equals_string (profile, "main-422-10");
1131 
1132   fill_h265_profile (profile_tier_level, 4, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1);
1133   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1134       sizeof (profile_tier_level));
1135   fail_unless_equals_string (profile, "main-422-12");
1136 
1137   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1);
1138   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1139       sizeof (profile_tier_level));
1140   fail_unless_equals_string (profile, "main-444");
1141 
1142   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1);
1143   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1144       sizeof (profile_tier_level));
1145   fail_unless_equals_string (profile, "main-444-10");
1146 
1147   fill_h265_profile (profile_tier_level, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1);
1148   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1149       sizeof (profile_tier_level));
1150   fail_unless_equals_string (profile, "main-444-12");
1151 
1152   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0);
1153   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1154       sizeof (profile_tier_level));
1155   fail_unless_equals_string (profile, "main-intra");
1156 
1157   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0);
1158   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1159       sizeof (profile_tier_level));
1160   fail_unless_equals_string (profile, "main-10-intra");
1161 
1162   fill_h265_profile (profile_tier_level, 4, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0);
1163   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1164       sizeof (profile_tier_level));
1165   fail_unless_equals_string (profile, "main-12-intra");
1166 
1167   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0);
1168   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1169       sizeof (profile_tier_level));
1170   fail_unless_equals_string (profile, "main-422-10-intra");
1171 
1172   fill_h265_profile (profile_tier_level, 4, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0);
1173   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1174       sizeof (profile_tier_level));
1175   fail_unless_equals_string (profile, "main-422-12-intra");
1176 
1177   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0);
1178   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1179       sizeof (profile_tier_level));
1180   fail_unless_equals_string (profile, "main-444-intra");
1181 
1182   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0);
1183   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1184       sizeof (profile_tier_level));
1185   fail_unless_equals_string (profile, "main-444-10-intra");
1186 
1187   fill_h265_profile (profile_tier_level, 4, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0);
1188   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1189       sizeof (profile_tier_level));
1190   fail_unless_equals_string (profile, "main-444-12-intra");
1191 
1192   fill_h265_profile (profile_tier_level, 4, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0);
1193   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1194       sizeof (profile_tier_level));
1195   fail_unless_equals_string (profile, "main-444-16-intra");
1196 
1197   fill_h265_profile (profile_tier_level, 4, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0);
1198   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1199       sizeof (profile_tier_level));
1200   fail_unless_equals_string (profile, "main-444-still-picture");
1201 
1202   fill_h265_profile (profile_tier_level, 4, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0);
1203   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1204       sizeof (profile_tier_level));
1205   fail_unless_equals_string (profile, "main-444-16-still-picture");
1206 
1207   /* High Throughput profiles */
1208   fill_h265_profile (profile_tier_level, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1209   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1210       sizeof (profile_tier_level));
1211   fail_unless (profile == NULL);
1212 
1213   fill_h265_profile (profile_tier_level, 5, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1);
1214   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1215       sizeof (profile_tier_level));
1216   fail_unless_equals_string (profile, "high-throughput-444");
1217 
1218   fill_h265_profile (profile_tier_level, 5, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1);
1219   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1220       sizeof (profile_tier_level));
1221   fail_unless_equals_string (profile, "high-throughput-444-10");
1222 
1223   fill_h265_profile (profile_tier_level, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1);
1224   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1225       sizeof (profile_tier_level));
1226   fail_unless_equals_string (profile, "high-throughput-444-14");
1227 
1228   fill_h265_profile (profile_tier_level, 5, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0);
1229   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1230       sizeof (profile_tier_level));
1231   fail_unless_equals_string (profile, "high-throughput-444-16-intra");
1232 
1233   /* Multiview Main profile */
1234   fill_h265_profile (profile_tier_level, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1235   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1236       sizeof (profile_tier_level));
1237   fail_unless (profile == NULL);
1238 
1239   fill_h265_profile (profile_tier_level, 6, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1);
1240   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1241       sizeof (profile_tier_level));
1242   fail_unless_equals_string (profile, "multiview-main");
1243 
1244   /* Scalable Main profiles */
1245   fill_h265_profile (profile_tier_level, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1246   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1247       sizeof (profile_tier_level));
1248   fail_unless (profile == NULL);
1249 
1250   fill_h265_profile (profile_tier_level, 7, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1);
1251   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1252       sizeof (profile_tier_level));
1253   fail_unless_equals_string (profile, "scalable-main");
1254 
1255   fill_h265_profile (profile_tier_level, 7, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1);
1256   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1257       sizeof (profile_tier_level));
1258   fail_unless_equals_string (profile, "scalable-main-10");
1259 
1260   /* 3D Main profile */
1261   fill_h265_profile (profile_tier_level, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1262   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1263       sizeof (profile_tier_level));
1264   fail_unless (profile == NULL);
1265 
1266   fill_h265_profile (profile_tier_level, 8, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1);
1267   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1268       sizeof (profile_tier_level));
1269   fail_unless_equals_string (profile, "3d-main");
1270 
1271   /* Screen content coding extensions profiles */
1272   fill_h265_profile (profile_tier_level, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1273   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1274       sizeof (profile_tier_level));
1275   fail_unless (profile == NULL);
1276 
1277   fill_h265_profile (profile_tier_level, 9, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1);
1278   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1279       sizeof (profile_tier_level));
1280   fail_unless_equals_string (profile, "screen-extended-main");
1281 
1282   fill_h265_profile (profile_tier_level, 9, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1);
1283   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1284       sizeof (profile_tier_level));
1285   fail_unless_equals_string (profile, "screen-extended-main-10");
1286 
1287   fill_h265_profile (profile_tier_level, 9, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1);
1288   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1289       sizeof (profile_tier_level));
1290   fail_unless_equals_string (profile, "screen-extended-main-444");
1291 
1292   fill_h265_profile (profile_tier_level, 9, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1);
1293   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1294       sizeof (profile_tier_level));
1295   fail_unless_equals_string (profile, "screen-extended-main-444-10");
1296 
1297   fill_h265_profile (profile_tier_level, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1);
1298   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1299       sizeof (profile_tier_level));
1300   fail_unless_equals_string (profile, "screen-extended-high-throughput-444-14");
1301 
1302   /* Scalable format range extensions profiles */
1303   fill_h265_profile (profile_tier_level, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1304   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1305       sizeof (profile_tier_level));
1306   fail_unless (profile == NULL);
1307 
1308   fill_h265_profile (profile_tier_level, 10, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1);
1309   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1310       sizeof (profile_tier_level));
1311   fail_unless_equals_string (profile, "scalable-monochrome");
1312 
1313   fill_h265_profile (profile_tier_level, 10, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1);
1314   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1315       sizeof (profile_tier_level));
1316   fail_unless_equals_string (profile, "scalable-monochrome-12");
1317 
1318   fill_h265_profile (profile_tier_level, 10, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1);
1319   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1320       sizeof (profile_tier_level));
1321   fail_unless_equals_string (profile, "scalable-monochrome-16");
1322 
1323   fill_h265_profile (profile_tier_level, 10, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1);
1324   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1325       sizeof (profile_tier_level));
1326   fail_unless_equals_string (profile, "scalable-main-444");
1327 
1328   fill_h265_profile (profile_tier_level, 11, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1);
1329   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1330       sizeof (profile_tier_level));
1331   fail_unless_equals_string (profile, "screen-extended-main-444-10");
1332 
1333   fill_h265_profile (profile_tier_level, 11, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1);
1334   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1335       sizeof (profile_tier_level));
1336   fail_unless_equals_string (profile, "screen-extended-main-444");
1337 
1338   fill_h265_profile (profile_tier_level, 11, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1);
1339   profile = gst_codec_utils_h265_get_profile (profile_tier_level,
1340       sizeof (profile_tier_level));
1341   fail_unless_equals_string (profile, "screen-extended-high-throughput-444-14");
1342 }
1343 
1344 GST_END_TEST;
1345 
1346 static const guint8 h265_sample_codec_data[] = {
1347   0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d,
1348   0xf0, 0x00, 0xfc,
1349   0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x03, 0x20, 0x00, 0x01, 0x00, 0x18, 0x40,
1350   0x01, 0x0c, 0x01,
1351   0xff, 0xff, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00, 0xb0, 0x00, 0x00, 0x03, 0x00,
1352   0x00, 0x03, 0x00,
1353   0x5d, 0x15, 0xc0, 0x90, 0x21, 0x00, 0x01, 0x00, 0x22, 0x42, 0x01, 0x01, 0x01,
1354   0x60, 0x00, 0x00,
1355   0x03, 0x00, 0xb0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x5d, 0xa0, 0x0a,
1356   0x08, 0x0f, 0x16,
1357   0x20, 0x57, 0xb9, 0x16, 0x55, 0x35, 0x01, 0x01, 0x01, 0x00, 0x80, 0x22, 0x00,
1358   0x01, 0x00, 0x07,
1359   0x44, 0x01, 0xc0, 0x2c, 0xbc, 0x14, 0xc9
1360 };
1361 
GST_START_TEST(test_pb_utils_caps_get_mime_codec)1362 GST_START_TEST (test_pb_utils_caps_get_mime_codec)
1363 {
1364   GstCaps *caps = NULL;
1365   gchar *mime_codec = NULL;
1366   GstBuffer *buffer = NULL;
1367   guint8 *codec_data = NULL;
1368   gsize codec_data_len;
1369 
1370   /* h264 without codec data */
1371   caps = gst_caps_new_empty_simple ("video/x-h264");
1372   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1373   fail_unless_equals_string (mime_codec, "avc1");
1374   g_free (mime_codec);
1375   gst_caps_unref (caps);
1376 
1377   /* h264 with codec data */
1378   codec_data_len = sizeof (guint8) * 7;
1379   codec_data = g_malloc0 (codec_data_len);
1380   codec_data[0] = 0x01;
1381   codec_data[1] = 0x64;
1382   codec_data[2] = 0x00;
1383   codec_data[3] = 0x32;
1384   /* seven bytes is the minumum for a valid h264 codec_data, but in
1385    * gst_codec_utils_h264_get_profile_flags_level we only parse the first four
1386    * bytes */
1387   buffer = gst_buffer_new_wrapped (codec_data, codec_data_len);
1388   caps =
1389       gst_caps_new_simple ("video/x-h264", "codec_data", GST_TYPE_BUFFER,
1390       buffer, NULL);
1391   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1392   fail_unless_equals_string (mime_codec, "avc1.640032");
1393   g_free (mime_codec);
1394   gst_caps_unref (caps);
1395   gst_buffer_unref (buffer);
1396 
1397   /* h265 */
1398   buffer =
1399       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
1400       (gpointer) h265_sample_codec_data, sizeof (h265_sample_codec_data), 0,
1401       sizeof (h265_sample_codec_data), NULL, NULL);
1402   caps =
1403       gst_caps_new_simple ("video/x-h265", "stream-format", G_TYPE_STRING,
1404       "hvc1", "codec_data", GST_TYPE_BUFFER, buffer, NULL);
1405   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1406   fail_unless_equals_string (mime_codec, "hvc1.1.6.L93.B0");
1407   g_free (mime_codec);
1408   gst_caps_unref (caps);
1409   gst_buffer_unref (buffer);
1410 
1411   /* av1 */
1412   caps = gst_caps_new_empty_simple ("video/x-av1");
1413   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1414   fail_unless_equals_string (mime_codec, "av01");
1415   g_free (mime_codec);
1416   gst_caps_unref (caps);
1417 
1418   /* vp8 */
1419   caps = gst_caps_new_empty_simple ("video/x-vp8");
1420   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1421   fail_unless_equals_string (mime_codec, "vp08");
1422   g_free (mime_codec);
1423   gst_caps_unref (caps);
1424 
1425   /* vp9 */
1426   caps = gst_caps_new_empty_simple ("video/x-vp9");
1427   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1428   fail_unless_equals_string (mime_codec, "vp09");
1429   g_free (mime_codec);
1430   gst_caps_unref (caps);
1431 
1432   /* mjpeg */
1433   caps = gst_caps_new_empty_simple ("image/jpeg");
1434   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1435   fail_unless_equals_string (mime_codec, "mjpg");
1436   g_free (mime_codec);
1437   gst_caps_unref (caps);
1438 
1439   /* aac without codec data */
1440   caps = gst_caps_new_empty_simple ("audio/mpeg");
1441   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1442   fail_unless_equals_string (mime_codec, "mp4a.40");
1443   g_free (mime_codec);
1444   gst_caps_unref (caps);
1445 
1446   /* aac with codec data */
1447   codec_data_len = sizeof (guint8) * 2;
1448   codec_data = g_malloc0 (codec_data_len);
1449   codec_data[0] = 0x11;
1450   codec_data[1] = 0x88;
1451   buffer = gst_buffer_new_wrapped (codec_data, codec_data_len);
1452   caps =
1453       gst_caps_new_simple ("audio/mpeg", "codec_data", GST_TYPE_BUFFER, buffer,
1454       NULL);
1455   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1456   fail_unless_equals_string (mime_codec, "mp4a.40.2");
1457   g_free (mime_codec);
1458   gst_caps_unref (caps);
1459   gst_buffer_unref (buffer);
1460 
1461   /* opus */
1462   caps = gst_caps_new_empty_simple ("audio/x-opus");
1463   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1464   fail_unless_equals_string (mime_codec, "opus");
1465   g_free (mime_codec);
1466   gst_caps_unref (caps);
1467 
1468   /* mulaw */
1469   caps = gst_caps_new_empty_simple ("audio/x-mulaw");
1470   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1471   fail_unless_equals_string (mime_codec, "ulaw");
1472   g_free (mime_codec);
1473   gst_caps_unref (caps);
1474 
1475   /* g726 */
1476   caps =
1477       gst_caps_new_simple ("audio/x-adpcm", "layout", G_TYPE_STRING, "g726",
1478       NULL);
1479   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
1480   fail_unless_equals_string (mime_codec, "g726");
1481   g_free (mime_codec);
1482   gst_caps_unref (caps);
1483 }
1484 
1485 GST_END_TEST;
1486 
1487 static Suite *
libgstpbutils_suite(void)1488 libgstpbutils_suite (void)
1489 {
1490   Suite *s = suite_create ("pbutils library");
1491   TCase *tc_chain = tcase_create ("general");
1492 
1493   gst_pb_utils_init ();
1494 
1495   suite_add_tcase (s, tc_chain);
1496   tcase_add_test (tc_chain, test_pb_utils_init);
1497   tcase_add_test (tc_chain, test_pb_utils_post_missing_messages);
1498   tcase_add_test (tc_chain, test_pb_utils_taglist_add_codec_info);
1499   tcase_add_test (tc_chain, test_pb_utils_get_codec_description);
1500   tcase_add_test (tc_chain, test_pb_utils_install_plugins);
1501   tcase_add_test (tc_chain, test_pb_utils_installer_details);
1502   tcase_add_test (tc_chain, test_pb_utils_versions);
1503   tcase_add_test (tc_chain, test_pb_utils_aac_get_profile);
1504   tcase_add_test (tc_chain, test_pb_utils_h264_profiles);
1505   tcase_add_test (tc_chain, test_pb_utils_h264_get_profile_flags_level);
1506   tcase_add_test (tc_chain, test_pb_utils_h265_profiles);
1507   tcase_add_test (tc_chain, test_pb_utils_caps_get_mime_codec);
1508   return s;
1509 }
1510 
1511 GST_CHECK_MAIN (libgstpbutils);
1512