pbutils: Use copy_and_clean_caps for description methods

This allows the various _get_*_description() methods to be more
forgiving with the provided caps.
This commit is contained in:
Edward Hervey 2010-09-28 12:15:22 +02:00
parent 95ec2a7b19
commit 3bc73c9d0f
3 changed files with 34 additions and 17 deletions

View File

@ -43,6 +43,7 @@
#include "gst/gst-i18n-plugin.h" #include "gst/gst-i18n-plugin.h"
#include "pbutils.h" #include "pbutils.h"
#include "gstdiscoverer-private.h"
#include <string.h> #include <string.h>
@ -780,23 +781,27 @@ gchar *
gst_pb_utils_get_decoder_description (const GstCaps * caps) gst_pb_utils_get_decoder_description (const GstCaps * caps)
{ {
gchar *str, *ret; gchar *str, *ret;
GstCaps *tmp;
g_return_val_if_fail (caps != NULL, NULL); g_return_val_if_fail (caps != NULL, NULL);
g_return_val_if_fail (GST_IS_CAPS (caps), NULL); g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
tmp = copy_and_clean_caps (caps);
g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
/* special-case RTP caps */ /* special-case RTP caps */
if (caps_are_rtp_caps (caps, "video", &str)) { if (caps_are_rtp_caps (tmp, "video", &str)) {
ret = g_strdup_printf (_("%s video RTP depayloader"), str); ret = g_strdup_printf (_("%s video RTP depayloader"), str);
} else if (caps_are_rtp_caps (caps, "audio", &str)) { } else if (caps_are_rtp_caps (tmp, "audio", &str)) {
ret = g_strdup_printf (_("%s audio RTP depayloader"), str); ret = g_strdup_printf (_("%s audio RTP depayloader"), str);
} else if (caps_are_rtp_caps (caps, "application", &str)) { } else if (caps_are_rtp_caps (tmp, "application", &str)) {
ret = g_strdup_printf (_("%s RTP depayloader"), str); ret = g_strdup_printf (_("%s RTP depayloader"), str);
} else { } else {
const FormatInfo *info; const FormatInfo *info;
str = gst_pb_utils_get_codec_description (caps); str = gst_pb_utils_get_codec_description (tmp);
info = find_format_info (caps); info = find_format_info (tmp);
if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) { if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) {
ret = g_strdup_printf (_("%s demuxer"), str); ret = g_strdup_printf (_("%s demuxer"), str);
} else { } else {
@ -805,6 +810,7 @@ gst_pb_utils_get_decoder_description (const GstCaps * caps)
} }
g_free (str); g_free (str);
gst_caps_unref (tmp);
return ret; return ret;
} }
@ -828,23 +834,25 @@ gchar *
gst_pb_utils_get_encoder_description (const GstCaps * caps) gst_pb_utils_get_encoder_description (const GstCaps * caps)
{ {
gchar *str, *ret; gchar *str, *ret;
GstCaps *tmp;
g_return_val_if_fail (caps != NULL, NULL); g_return_val_if_fail (caps != NULL, NULL);
g_return_val_if_fail (GST_IS_CAPS (caps), NULL); g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
g_return_val_if_fail (gst_caps_is_fixed (caps), NULL); tmp = copy_and_clean_caps (caps);
g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
/* special-case RTP caps */ /* special-case RTP caps */
if (caps_are_rtp_caps (caps, "video", &str)) { if (caps_are_rtp_caps (tmp, "video", &str)) {
ret = g_strdup_printf (_("%s video RTP payloader"), str); ret = g_strdup_printf (_("%s video RTP payloader"), str);
} else if (caps_are_rtp_caps (caps, "audio", &str)) { } else if (caps_are_rtp_caps (tmp, "audio", &str)) {
ret = g_strdup_printf (_("%s audio RTP payloader"), str); ret = g_strdup_printf (_("%s audio RTP payloader"), str);
} else if (caps_are_rtp_caps (caps, "application", &str)) { } else if (caps_are_rtp_caps (tmp, "application", &str)) {
ret = g_strdup_printf (_("%s RTP payloader"), str); ret = g_strdup_printf (_("%s RTP payloader"), str);
} else { } else {
const FormatInfo *info; const FormatInfo *info;
str = gst_pb_utils_get_codec_description (caps); str = gst_pb_utils_get_codec_description (tmp);
info = find_format_info (caps); info = find_format_info (tmp);
if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) { if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) {
ret = g_strdup_printf (_("%s muxer"), str); ret = g_strdup_printf (_("%s muxer"), str);
} else { } else {
@ -853,6 +861,7 @@ gst_pb_utils_get_encoder_description (const GstCaps * caps)
} }
g_free (str); g_free (str);
gst_caps_unref (tmp);
return ret; return ret;
} }
@ -942,17 +951,19 @@ gst_pb_utils_get_codec_description (const GstCaps * caps)
{ {
const FormatInfo *info; const FormatInfo *info;
gchar *str, *comma; gchar *str, *comma;
GstCaps *tmp;
g_return_val_if_fail (caps != NULL, NULL); g_return_val_if_fail (caps != NULL, NULL);
g_return_val_if_fail (GST_IS_CAPS (caps), NULL); g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
g_return_val_if_fail (gst_caps_is_fixed (caps), NULL); tmp = copy_and_clean_caps (caps);
g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
info = find_format_info (caps); info = find_format_info (tmp);
if (info) { if (info) {
str = format_info_get_desc (info, caps); str = format_info_get_desc (info, tmp);
} else { } else {
str = gst_caps_to_string (caps); str = gst_caps_to_string (tmp);
/* cut off everything after the media type, if there is anything */ /* cut off everything after the media type, if there is anything */
if ((comma = strchr (str, ','))) { if ((comma = strchr (str, ','))) {
@ -964,6 +975,7 @@ gst_pb_utils_get_codec_description (const GstCaps * caps)
GST_WARNING ("No description available for media type: %s", str); GST_WARNING ("No description available for media type: %s", str);
} }
gst_caps_unref (tmp);
return str; return str;
} }

View File

@ -81,3 +81,7 @@ struct _GstDiscovererInfo {
gpointer _reserved[GST_PADDING]; gpointer _reserved[GST_PADDING];
}; };
/* missing-plugins.c */
GstCaps *copy_and_clean_caps (const GstCaps * caps);

View File

@ -67,6 +67,7 @@
#include "gst/gst-i18n-plugin.h" #include "gst/gst-i18n-plugin.h"
#include "pbutils.h" #include "pbutils.h"
#include "gstdiscoverer-private.h"
#include <string.h> #include <string.h>
@ -112,7 +113,7 @@ missing_structure_get_type (const GstStructure * s)
return GST_MISSING_TYPE_UNKNOWN; return GST_MISSING_TYPE_UNKNOWN;
} }
static GstCaps * GstCaps *
copy_and_clean_caps (const GstCaps * caps) copy_and_clean_caps (const GstCaps * caps)
{ {
GstStructure *s; GstStructure *s;