pbutils: Use copy_and_clean_caps for description methods
authorEdward Hervey <bilboed@bilboed.com>
Tue, 28 Sep 2010 10:15:22 +0000 (12:15 +0200)
committerEdward Hervey <bilboed@bilboed.com>
Fri, 8 Oct 2010 13:27:39 +0000 (15:27 +0200)
This allows the various _get_*_description() methods to be more
forgiving with the provided caps.

gst-libs/gst/pbutils/descriptions.c
gst-libs/gst/pbutils/gstdiscoverer-private.h
gst-libs/gst/pbutils/missing-plugins.c

index 39eb411..77acf62 100644 (file)
@@ -43,6 +43,7 @@
 #include "gst/gst-i18n-plugin.h"
 
 #include "pbutils.h"
+#include "gstdiscoverer-private.h"
 
 #include <string.h>
 
@@ -780,23 +781,27 @@ gchar *
 gst_pb_utils_get_decoder_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);
-  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 */
-  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);
-  } 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);
-  } 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);
   } else {
     const FormatInfo *info;
 
-    str = gst_pb_utils_get_codec_description (caps);
-    info = find_format_info (caps);
+    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 demuxer"), str);
     } else {
@@ -805,6 +810,7 @@ gst_pb_utils_get_decoder_description (const GstCaps * caps)
   }
 
   g_free (str);
+  gst_caps_unref (tmp);
 
   return ret;
 }
@@ -828,23 +834,25 @@ 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);
-  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 */
-  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);
-  } 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);
-  } 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);
   } else {
     const FormatInfo *info;
 
-    str = gst_pb_utils_get_codec_description (caps);
-    info = find_format_info (caps);
+    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 {
@@ -853,6 +861,7 @@ gst_pb_utils_get_encoder_description (const GstCaps * caps)
   }
 
   g_free (str);
+  gst_caps_unref (tmp);
 
   return ret;
 }
@@ -942,17 +951,19 @@ 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);
-  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) {
-    str = format_info_get_desc (info, caps);
+    str = format_info_get_desc (info, tmp);
   } else {
-    str = gst_caps_to_string (caps);
+    str = gst_caps_to_string (tmp);
 
     /* cut off everything after the media type, if there is anything */
     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_caps_unref (tmp);
 
   return str;
 }
index 7b16014..c6a817d 100644 (file)
@@ -81,3 +81,7 @@ struct _GstDiscovererInfo {
 
   gpointer _reserved[GST_PADDING];
 };
+
+/* missing-plugins.c */
+
+GstCaps *copy_and_clean_caps (const GstCaps * caps);
index cc02bbf..0d732a3 100644 (file)
@@ -67,6 +67,7 @@
 #include "gst/gst-i18n-plugin.h"
 
 #include "pbutils.h"
+#include "gstdiscoverer-private.h"
 
 #include <string.h>
 
@@ -112,7 +113,7 @@ missing_structure_get_type (const GstStructure * s)
   return GST_MISSING_TYPE_UNKNOWN;
 }
 
-static GstCaps *
+GstCaps *
 copy_and_clean_caps (const GstCaps * caps)
 {
   GstStructure *s;