pbutils: allow describing unfixed caps if they share the same media type
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Mon, 1 Jul 2013 09:39:02 +0000 (10:39 +0100)
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Mon, 1 Jul 2013 09:51:40 +0000 (10:51 +0100)
Caps description and missing plugin code does not really need caps to
be fixed, and indeed they may not be if giving encodebin unfixed caps
that correspond to an unknown encoder or muxer.

So we relax the check, and allow unfixed caps if all the structures
refer to the same media type.

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

index ac27e7d..9591f59 100644 (file)
@@ -839,7 +839,7 @@ gst_pb_utils_get_decoder_description (const GstCaps * caps)
 
   tmp = copy_and_clean_caps (caps);
 
-  g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
+  g_return_val_if_fail (has_single_media_type (tmp), NULL);
 
   /* special-case RTP caps */
   if (caps_are_rtp_caps (tmp, "video", &str)) {
@@ -890,7 +890,7 @@ gst_pb_utils_get_encoder_description (const GstCaps * caps)
   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);
+  g_return_val_if_fail (has_single_media_type (tmp), NULL);
 
   /* special-case RTP caps */
   if (caps_are_rtp_caps (tmp, "video", &str)) {
@@ -1021,7 +1021,7 @@ gst_pb_utils_get_codec_description (const GstCaps * caps)
   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);
+  g_return_val_if_fail (has_single_media_type (tmp), NULL);
 
   info = find_format_info (tmp);
 
index 7d7f2f4..6ff16d5 100644 (file)
@@ -156,6 +156,25 @@ copy_and_clean_caps (const GstCaps * caps)
   return ret;
 }
 
+gboolean
+has_single_media_type (const GstCaps * caps)
+{
+  guint n, ns;
+  const char *name0, *namen;
+
+  g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
+
+  name0 = gst_structure_get_name (gst_caps_get_structure (caps, 0));
+  ns = gst_caps_get_size (caps);
+  for (n = 1; n < ns; ++n) {
+    namen = gst_structure_get_name (gst_caps_get_structure (caps, n));
+    if (strcmp (name0, namen)) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
+
 /**
  * gst_missing_uri_source_message_new:
  * @element: the #GstElement posting the message
@@ -319,7 +338,7 @@ gst_missing_encoder_message_new (GstElement * element,
   g_return_val_if_fail (GST_IS_CAPS (encode_caps), NULL);
   g_return_val_if_fail (!gst_caps_is_any (encode_caps), NULL);
   g_return_val_if_fail (!gst_caps_is_empty (encode_caps), NULL);
-  g_return_val_if_fail (gst_caps_is_fixed (encode_caps), NULL);
+  g_return_val_if_fail (has_single_media_type (encode_caps), NULL);
 
   description = gst_pb_utils_get_encoder_description (encode_caps);
   caps = copy_and_clean_caps (encode_caps);
index 82fd22c..bb475a3 100644 (file)
@@ -107,3 +107,4 @@ struct _GstDiscovererInfo {
 /* missing-plugins.c */
 
 GstCaps *copy_and_clean_caps (const GstCaps * caps);
+gboolean has_single_media_type (const GstCaps * caps);