/** * gst_pb_utils_add_codec_description_to_tag_list: * @taglist: a #GstTagList * @codec_tag: a GStreamer codec tag such as #GST_TAG_AUDIO_CODEC, * #GST_TAG_VIDEO_CODEC or #GST_TAG_CODEC * @caps: the (fixed) #GstCaps for which a codec tag should be added. * * Adds a codec tag describing the format specified by @caps to @taglist. * * Returns: TRUE if a codec tag was added, FALSE otherwise. */ gboolean gst_pb_utils_add_codec_description_to_tag_list (GstTagList * taglist, const gchar * codec_tag, const GstCaps * caps) { const FormatInfo *info; gchar *desc; g_return_val_if_fail (taglist != NULL, FALSE); g_return_val_if_fail (GST_IS_TAG_LIST (taglist), FALSE); g_return_val_if_fail (codec_tag != NULL, FALSE); g_return_val_if_fail (gst_tag_exists (codec_tag), FALSE); g_return_val_if_fail (gst_tag_get_type (codec_tag) == G_TYPE_STRING, FALSE); g_return_val_if_fail (caps != NULL, FALSE); g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); info = find_format_info (caps); if (info == NULL) return FALSE; desc = format_info_get_desc (info, caps); gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, codec_tag, desc, NULL); g_free (desc); return TRUE; }
/** * gst_pb_utils_get_codec_description: * @caps: the (fixed) #GstCaps for which an format description is needed * * Returns a localised (as far as this is possible) string describing the * media format specified in @caps, for use in error dialogs or other messages * to be seen by the user. Should never return NULL unless @caps is invalid. * * Also see the convenience function * gst_pb_utils_add_codec_description_to_tag_list(). * * Returns: a newly-allocated description string, or NULL on error. Free * string with g_free() when not needed any longer. */ gchar * gst_pb_utils_get_codec_description (const GstCaps * caps) { const FormatInfo *info; gchar *str, *comma; GstCaps *tmp; g_return_val_if_fail (caps != NULL, NULL); g_return_val_if_fail (GST_IS_CAPS (caps), NULL); tmp = copy_and_clean_caps (caps); g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL); info = find_format_info (tmp); if (info) { str = format_info_get_desc (info, tmp); } else { str = gst_caps_to_string (tmp); /* cut off everything after the media type, if there is anything */ if ((comma = strchr (str, ','))) { *comma = '\0'; g_strchomp (str); /* we could do something more elaborate here, like taking into account * audio/, video/, image/ and application/ prefixes etc. */ } GST_WARNING ("No description available for media type: %s", str); } gst_caps_unref (tmp); return str; }
/** * gst_pb_utils_add_codec_description_to_tag_list: * @taglist: a #GstTagList * @codec_tag: (allow-none): a GStreamer codec tag such as #GST_TAG_AUDIO_CODEC, * #GST_TAG_VIDEO_CODEC or #GST_TAG_CODEC. If none is specified, * the function will attempt to detect the appropriate category. * @caps: the (fixed) #GstCaps for which a codec tag should be added. * * Adds a codec tag describing the format specified by @caps to @taglist. * * Returns: TRUE if a codec tag was added, FALSE otherwise. */ gboolean gst_pb_utils_add_codec_description_to_tag_list (GstTagList * taglist, const gchar * codec_tag, const GstCaps * caps) { const FormatInfo *info; gchar *desc; g_return_val_if_fail (taglist != NULL, FALSE); g_return_val_if_fail (GST_IS_TAG_LIST (taglist), FALSE); g_return_val_if_fail (codec_tag == NULL || (gst_tag_exists (codec_tag) && gst_tag_get_type (codec_tag) == G_TYPE_STRING), FALSE); g_return_val_if_fail (caps != NULL, FALSE); g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); info = find_format_info (caps); if (info == NULL) return FALSE; /* Attempt to find tag classification */ if (codec_tag == NULL) { if (info->flags & FLAG_CONTAINER) codec_tag = GST_TAG_CONTAINER_FORMAT; else if (info->flags & FLAG_AUDIO) codec_tag = GST_TAG_AUDIO_CODEC; else if (info->flags & FLAG_VIDEO) codec_tag = GST_TAG_VIDEO_CODEC; else if (info->flags & FLAG_SUB) codec_tag = GST_TAG_SUBTITLE_CODEC; else codec_tag = GST_TAG_CODEC; } desc = format_info_get_desc (info, caps); gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, codec_tag, desc, NULL); g_free (desc); return TRUE; }