/** * 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: 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_encoder_description: * @caps: the (fixed) #GstCaps for which an encoder description is needed * * Returns a localised string describing an encoder for the format specified * in @caps, for use in error dialogs or other messages to be seen by the user. * Should never return NULL unless @factory_name or @caps are invalid. * * This function is mainly for internal use, applications would typically * use gst_missing_plugin_message_get_description() to get a description of * a missing feature from a missing-plugin message. * * 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_encoder_description (const GstCaps * caps) { gchar *str, *ret; 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); /* special-case RTP caps */ if (caps_are_rtp_caps (tmp, "video", &str)) { ret = g_strdup_printf (_("%s video RTP payloader"), str); } else if (caps_are_rtp_caps (tmp, "audio", &str)) { ret = g_strdup_printf (_("%s audio RTP payloader"), str); } else if (caps_are_rtp_caps (tmp, "application", &str)) { ret = g_strdup_printf (_("%s RTP payloader"), str); } else { const FormatInfo *info; str = gst_pb_utils_get_codec_description (tmp); info = find_format_info (tmp); if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) { ret = g_strdup_printf (_("%s muxer"), str); } else { ret = g_strdup_printf (_("%s encoder"), str); } } g_free (str); gst_caps_unref (tmp); return ret; }
const gchar * pb_utils_get_file_extension_from_caps (const GstCaps * caps) { const FormatInfo *info; const gchar *ext = NULL; GstCaps *stripped_caps; g_assert (GST_IS_CAPS (caps)); stripped_caps = copy_and_clean_caps (caps); g_assert (gst_caps_is_fixed (stripped_caps)); info = find_format_info (stripped_caps); if (info && info->ext[0] != '\0') { ext = info->ext; } else if (info && info->desc == NULL) { const GstStructure *s; s = gst_caps_get_structure (stripped_caps, 0); /* cases where we have to evaluate the caps more closely */ if (strcmp (info->type, "audio/mpeg") == 0) { int version = 0, layer = 3; if (gst_structure_get_int (s, "mpegversion", &version)) { if (version == 2 || version == 4) { ext = "aac"; } else if (version == 1) { gst_structure_get_int (s, "layer", &layer); if (layer == 1) ext = "mp1"; else if (layer == 2) ext = "mp2"; else ext = "mp3"; } } } } gst_caps_unref (stripped_caps); return ext; }
gboolean pb_utils_is_tag (const GstCaps * caps) { const FormatInfo *info; GstCaps *stripped_caps; gboolean is_tag = FALSE; g_assert (GST_IS_CAPS (caps)); stripped_caps = copy_and_clean_caps (caps); g_assert (gst_caps_is_fixed (stripped_caps)); info = find_format_info (stripped_caps); if (info) { is_tag = (info->flags & FLAG_TAG) != 0; } gst_caps_unref (stripped_caps); return is_tag; }
/** * 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; }