pbutils: descriptions: add meta/x-klv
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-base / tests / check / libs / pbutils.c
index e90f6b4..e22fdd1 100644 (file)
@@ -245,6 +245,59 @@ GST_START_TEST (test_pb_utils_init)
 
 GST_END_TEST;
 
+#define F_AUDIO GST_PBUTILS_CAPS_DESCRIPTION_FLAG_AUDIO
+#define F_VIDEO GST_PBUTILS_CAPS_DESCRIPTION_FLAG_VIDEO
+#define F_SUB GST_PBUTILS_CAPS_DESCRIPTION_FLAG_SUBTITLE
+#define F_IMAGE GST_PBUTILS_CAPS_DESCRIPTION_FLAG_IMAGE
+#define F_AV (F_AUDIO | F_VIDEO)
+#define F_AVS (F_AUDIO | F_VIDEO | F_SUB)
+#define F_AVSI (F_AUDIO | F_VIDEO | F_SUB | F_IMAGE)
+#define F_CONTAINER GST_PBUTILS_CAPS_DESCRIPTION_FLAG_CONTAINER
+#define F_AV_CONTAINER (F_CONTAINER | F_AV)
+#define F_AVS_CONTAINER (F_CONTAINER | F_AVS)
+#define F_AVSI_CONTAINER (F_CONTAINER | F_AVSI)
+#define F_META GST_PBUTILS_CAPS_DESCRIPTION_FLAG_METADATA
+#define F_TAG GST_PBUTILS_CAPS_DESCRIPTION_FLAG_TAG
+
+/* *INDENT-OFF* */
+static const struct FlagDescEntry
+{
+  const gchar *caps_string;
+  GstPbUtilsCapsDescriptionFlags flags;
+} flag_descs[] = {
+  {"application/x-binary", 0},
+  {"audio/x-wav", F_AUDIO | F_CONTAINER},
+  {"video/quicktime", F_AVSI_CONTAINER},
+  {"video/x-flv", F_AV_CONTAINER},
+  {"video/x-h264", F_VIDEO},
+  {"audio/mpeg,mpegversion=4", F_AUDIO},
+  {"image/jpeg", F_IMAGE | F_VIDEO},
+  {"meta/x-klv", F_META},
+  {"application/x-onvif-metadata", F_META},
+  {"random/x-nonsense, sense=false", 0},
+};
+/* *INDENT-ON* */
+
+GST_START_TEST (test_pb_utils_get_caps_description_flags)
+{
+  int i;
+
+  for (i = 0; i < G_N_ELEMENTS (flag_descs); ++i) {
+    GstPbUtilsCapsDescriptionFlags flags;
+    const struct FlagDescEntry *e;
+    GstCaps *caps;
+
+    e = &flag_descs[i];
+    caps = gst_caps_from_string (e->caps_string);
+    flags = gst_pb_utils_get_caps_description_flags (caps);
+    gst_caps_unref (caps);
+    GST_DEBUG ("%s: expecting 0x%x, got 0x%x", e->caps_string, e->flags, flags);
+    fail_unless_equals_int (flags, e->flags);
+  }
+}
+
+GST_END_TEST;
+
 static const gchar *caps_strings[] = {
   /* formats with static descriptions */
   "application/ogg", "application/vnd.rn-realmedia", "video/x-fli",
@@ -1343,9 +1396,26 @@ GST_START_TEST (test_pb_utils_h265_profiles)
 
 GST_END_TEST;
 
-GST_START_TEST (test_pb_utils_caps_get_mime_codec)
+static const guint8 h265_sample_codec_data[] = {
+  0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d,
+  0xf0, 0x00, 0xfc,
+  0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x03, 0x20, 0x00, 0x01, 0x00, 0x18, 0x40,
+  0x01, 0x0c, 0x01,
+  0xff, 0xff, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00, 0xb0, 0x00, 0x00, 0x03, 0x00,
+  0x00, 0x03, 0x00,
+  0x5d, 0x15, 0xc0, 0x90, 0x21, 0x00, 0x01, 0x00, 0x22, 0x42, 0x01, 0x01, 0x01,
+  0x60, 0x00, 0x00,
+  0x03, 0x00, 0xb0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x5d, 0xa0, 0x0a,
+  0x08, 0x0f, 0x16,
+  0x20, 0x57, 0xb9, 0x16, 0x55, 0x35, 0x01, 0x01, 0x01, 0x00, 0x80, 0x22, 0x00,
+  0x01, 0x00, 0x07,
+  0x44, 0x01, 0xc0, 0x2c, 0xbc, 0x14, 0xc9
+};
+
+GST_START_TEST (test_pb_utils_caps_mime_codec)
 {
   GstCaps *caps = NULL;
+  GstCaps *caps2 = NULL;
   gchar *mime_codec = NULL;
   GstBuffer *buffer = NULL;
   guint8 *codec_data = NULL;
@@ -1355,6 +1425,9 @@ GST_START_TEST (test_pb_utils_caps_get_mime_codec)
   caps = gst_caps_new_empty_simple ("video/x-h264");
   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
   fail_unless_equals_string (mime_codec, "avc1");
+  caps2 = gst_codec_utils_caps_from_mime_codec (mime_codec);
+  fail_unless (gst_caps_is_equal_fixed (caps, caps2));
+  gst_caps_unref (caps2);
   g_free (mime_codec);
   gst_caps_unref (caps);
 
@@ -1379,16 +1452,26 @@ GST_START_TEST (test_pb_utils_caps_get_mime_codec)
   gst_buffer_unref (buffer);
 
   /* h265 */
-  caps = gst_caps_new_empty_simple ("video/x-h265");
+  buffer =
+      gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
+      (gpointer) h265_sample_codec_data, sizeof (h265_sample_codec_data), 0,
+      sizeof (h265_sample_codec_data), NULL, NULL);
+  caps =
+      gst_caps_new_simple ("video/x-h265", "stream-format", G_TYPE_STRING,
+      "hvc1", "codec_data", GST_TYPE_BUFFER, buffer, NULL);
   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
-  fail_unless_equals_string (mime_codec, "hev1");
+  fail_unless_equals_string (mime_codec, "hvc1.1.6.L93.B0");
   g_free (mime_codec);
   gst_caps_unref (caps);
+  gst_buffer_unref (buffer);
 
   /* av1 */
   caps = gst_caps_new_empty_simple ("video/x-av1");
   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
   fail_unless_equals_string (mime_codec, "av01");
+  caps2 = gst_codec_utils_caps_from_mime_codec (mime_codec);
+  fail_unless (gst_caps_is_equal_fixed (caps, caps2));
+  gst_caps_unref (caps2);
   g_free (mime_codec);
   gst_caps_unref (caps);
 
@@ -1396,6 +1479,9 @@ GST_START_TEST (test_pb_utils_caps_get_mime_codec)
   caps = gst_caps_new_empty_simple ("video/x-vp8");
   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
   fail_unless_equals_string (mime_codec, "vp08");
+  caps2 = gst_codec_utils_caps_from_mime_codec (mime_codec);
+  fail_unless (gst_caps_is_equal_fixed (caps, caps2));
+  gst_caps_unref (caps2);
   g_free (mime_codec);
   gst_caps_unref (caps);
 
@@ -1403,6 +1489,9 @@ GST_START_TEST (test_pb_utils_caps_get_mime_codec)
   caps = gst_caps_new_empty_simple ("video/x-vp9");
   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
   fail_unless_equals_string (mime_codec, "vp09");
+  caps2 = gst_codec_utils_caps_from_mime_codec (mime_codec);
+  fail_unless (gst_caps_is_equal_fixed (caps, caps2));
+  gst_caps_unref (caps2);
   g_free (mime_codec);
   gst_caps_unref (caps);
 
@@ -1439,6 +1528,9 @@ GST_START_TEST (test_pb_utils_caps_get_mime_codec)
   caps = gst_caps_new_empty_simple ("audio/x-opus");
   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
   fail_unless_equals_string (mime_codec, "opus");
+  caps2 = gst_codec_utils_caps_from_mime_codec (mime_codec);
+  fail_unless (gst_caps_is_equal_fixed (caps, caps2));
+  gst_caps_unref (caps2);
   g_free (mime_codec);
   gst_caps_unref (caps);
 
@@ -1446,6 +1538,9 @@ GST_START_TEST (test_pb_utils_caps_get_mime_codec)
   caps = gst_caps_new_empty_simple ("audio/x-mulaw");
   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
   fail_unless_equals_string (mime_codec, "ulaw");
+  caps2 = gst_codec_utils_caps_from_mime_codec (mime_codec);
+  fail_unless (gst_caps_is_equal_fixed (caps, caps2));
+  gst_caps_unref (caps2);
   g_free (mime_codec);
   gst_caps_unref (caps);
 
@@ -1455,13 +1550,9 @@ GST_START_TEST (test_pb_utils_caps_get_mime_codec)
       NULL);
   mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
   fail_unless_equals_string (mime_codec, "g726");
-  g_free (mime_codec);
-  gst_caps_unref (caps);
-
-  /* raw */
-  caps = gst_caps_new_empty_simple ("audio/x-raw");
-  mime_codec = gst_codec_utils_caps_get_mime_codec (caps);
-  fail_unless_equals_string (mime_codec, "raw");
+  caps2 = gst_codec_utils_caps_from_mime_codec (mime_codec);
+  fail_unless (gst_caps_is_equal_fixed (caps, caps2));
+  gst_caps_unref (caps2);
   g_free (mime_codec);
   gst_caps_unref (caps);
 }
@@ -1474,10 +1565,13 @@ libgstpbutils_suite (void)
   Suite *s = suite_create ("pbutils library");
   TCase *tc_chain = tcase_create ("general");
 
+  gst_pb_utils_init ();
+
   suite_add_tcase (s, tc_chain);
   tcase_add_test (tc_chain, test_pb_utils_init);
   tcase_add_test (tc_chain, test_pb_utils_post_missing_messages);
   tcase_add_test (tc_chain, test_pb_utils_taglist_add_codec_info);
+  tcase_add_test (tc_chain, test_pb_utils_get_caps_description_flags);
   tcase_add_test (tc_chain, test_pb_utils_get_codec_description);
   tcase_add_test (tc_chain, test_pb_utils_install_plugins);
   tcase_add_test (tc_chain, test_pb_utils_installer_details);
@@ -1486,7 +1580,7 @@ libgstpbutils_suite (void)
   tcase_add_test (tc_chain, test_pb_utils_h264_profiles);
   tcase_add_test (tc_chain, test_pb_utils_h264_get_profile_flags_level);
   tcase_add_test (tc_chain, test_pb_utils_h265_profiles);
-  tcase_add_test (tc_chain, test_pb_utils_caps_get_mime_codec);
+  tcase_add_test (tc_chain, test_pb_utils_caps_mime_codec);
   return s;
 }