pbutils: Expose functions for getting a file extension for caps and flags for describ...
authorSebastian Dröge <sebastian@centricular.com>
Thu, 1 Jul 2021 09:41:11 +0000 (12:41 +0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 18 Aug 2021 12:06:16 +0000 (12:06 +0000)
This information was available internally already but not available from
the outside.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1221>

gst-libs/gst/pbutils/descriptions.c
gst-libs/gst/pbutils/descriptions.h

index d79a6cc..8caa116 100644 (file)
@@ -1287,6 +1287,72 @@ pb_utils_get_file_extension_from_caps (const GstCaps * caps)
   return ext;
 }
 
+/**
+ * gst_pb_utils_get_file_extension_from_caps:
+ * @caps: the (fixed) #GstCaps for which a file extension is needed
+ *
+ * Returns a possible file extension for the given caps, if known.
+ *
+ * Returns: (nullable): a newly-allocated file extension string, or NULL on error. Free
+ *          string with g_free() when not needed any longer.
+ *
+ * Since: 1.20
+ */
+gchar *
+gst_pb_utils_get_file_extension_from_caps (const GstCaps * caps)
+{
+  return g_strdup (pb_utils_get_file_extension_from_caps (caps));
+}
+
+/**
+ * gst_pb_utils_get_caps_description_flags:
+ * @caps: the (fixed) #GstCaps for which flags are requested
+ *
+ * Returns flags that describe the format of the caps if known. No flags are
+ * set for unknown caps.
+ *
+ * Returns: #GstPbUtilsCapsDescriptionFlags that describe @caps, or no flags
+ *          if the caps are unknown.
+ *
+ * Since: 1.20
+ */
+GstPbUtilsCapsDescriptionFlags
+gst_pb_utils_get_caps_description_flags (const GstCaps * caps)
+{
+  GstCaps *tmp;
+  const FormatInfo *info;
+  GstPbUtilsCapsDescriptionFlags flags = 0;
+
+  g_return_val_if_fail (caps != NULL, 0);
+  g_return_val_if_fail (GST_IS_CAPS (caps), 0);
+  tmp = copy_and_clean_caps (caps);
+  g_return_val_if_fail (gst_caps_is_fixed (tmp), 0);
+
+  info = find_format_info (tmp);
+  /* A separate flags type is used because internally more flags are needed
+   * for filtering purposes, e.g. the SYSTEMSTREAM flag */
+  if (info) {
+    if ((info->flags | FLAG_CONTAINER))
+      flags |= GST_PBUTILS_CAPS_DESCRIPTION_FLAG_CONTAINER;
+    if ((info->flags | FLAG_AUDIO))
+      flags |= GST_PBUTILS_CAPS_DESCRIPTION_FLAG_AUDIO;
+    if ((info->flags | FLAG_VIDEO))
+      flags |= GST_PBUTILS_CAPS_DESCRIPTION_FLAG_VIDEO;
+    if ((info->flags | FLAG_IMAGE))
+      flags |= GST_PBUTILS_CAPS_DESCRIPTION_FLAG_IMAGE;
+    if ((info->flags | FLAG_SUB))
+      flags |= GST_PBUTILS_CAPS_DESCRIPTION_FLAG_SUBTITLE;
+    if ((info->flags | FLAG_TAG))
+      flags |= GST_PBUTILS_CAPS_DESCRIPTION_FLAG_TAG;
+    if ((info->flags | FLAG_GENERIC))
+      flags |= GST_PBUTILS_CAPS_DESCRIPTION_FLAG_GENERIC;
+  }
+
+  gst_caps_unref (tmp);
+
+  return flags;
+}
+
 gboolean
 pb_utils_is_tag (const GstCaps * caps)
 {
index c03f46a..8b28bf7 100644 (file)
 
 G_BEGIN_DECLS
 
+/**
+ * GstPbUtilsCapsDescriptionFlags:
+ * @GST_PBUTILS_CAPS_DESCRIPTION_FLAG_CONTAINER: Caps describe a container format.
+ * @GST_PBUTILS_CAPS_DESCRIPTION_FLAG_AUDIO: Caps describe an audio format, or a
+ *     container format that can store audio.
+ * @GST_PBUTILS_CAPS_DESCRIPTION_FLAG_VIDEO: Caps describe an video format, or a
+ *     container format that can store video.
+ * @GST_PBUTILS_CAPS_DESCRIPTION_FLAG_IMAGE: Caps describe an image format, or a
+ *     container format that can store image.
+ * @GST_PBUTILS_CAPS_DESCRIPTION_FLAG_SUBTITLE: Caps describe an subtitle format, or a
+ *     container format that can store subtitles.
+ * @GST_PBUTILS_CAPS_DESCRIPTION_FLAG_TAG: Container format is a tags container.
+ * @GST_PBUTILS_CAPS_DESCRIPTION_FLAG_GENERIC: Container format can store any kind of
+ *     stream type.
+ *
+ * Flags that are returned by gst_pb_utils_get_caps_description_flags() and
+ * describe the format of the caps.
+ *
+ * Since: 1.20
+ */
+typedef enum {
+  GST_PBUTILS_CAPS_DESCRIPTION_FLAG_CONTAINER = 1 << 0,
+  GST_PBUTILS_CAPS_DESCRIPTION_FLAG_AUDIO     = 1 << 1,
+  GST_PBUTILS_CAPS_DESCRIPTION_FLAG_VIDEO     = 1 << 2,
+  GST_PBUTILS_CAPS_DESCRIPTION_FLAG_IMAGE     = 1 << 3,
+  GST_PBUTILS_CAPS_DESCRIPTION_FLAG_SUBTITLE  = 1 << 4,
+  GST_PBUTILS_CAPS_DESCRIPTION_FLAG_TAG       = 1 << 5,
+  GST_PBUTILS_CAPS_DESCRIPTION_FLAG_GENERIC   = 1 << 6,
+} GstPbUtilsCapsDescriptionFlags;
+
 /*
  * functions for use by demuxers or decoders to add CODEC tags to tag lists
  * from caps
@@ -59,6 +89,11 @@ gchar    * gst_pb_utils_get_encoder_description (const GstCaps * caps);
 GST_PBUTILS_API
 gchar    * gst_pb_utils_get_element_description (const gchar * factory_name);
 
+GST_PBUTILS_API
+GstPbUtilsCapsDescriptionFlags gst_pb_utils_get_caps_description_flags (const GstCaps * caps);
+
+GST_PBUTILS_API
+gchar * gst_pb_utils_get_file_extension_from_caps (const GstCaps *caps);
 
 G_END_DECLS