pbutils: Expose functions for getting a file extension for caps and flags for describing the format of the caps

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>
This commit is contained in:
Sebastian Dröge 2021-07-01 12:41:11 +03:00 committed by GStreamer Marge Bot
parent 52bca104e4
commit bf71ef17e3
2 changed files with 101 additions and 0 deletions

View 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)
{

View file

@ -26,6 +26,36 @@
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