From 065f1603b0f1d2adc8477bf1f3ebe2b154885d89 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Mon, 1 Jul 2013 10:39:02 +0100 Subject: [PATCH] pbutils: allow describing unfixed caps if they share the same media type 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 | 6 +++--- gst-libs/gst/pbutils/missing-plugins.c | 21 ++++++++++++++++++++- gst-libs/gst/pbutils/pbutils-private.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gst-libs/gst/pbutils/descriptions.c b/gst-libs/gst/pbutils/descriptions.c index ac27e7dfcc..9591f5906c 100644 --- a/gst-libs/gst/pbutils/descriptions.c +++ b/gst-libs/gst/pbutils/descriptions.c @@ -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); diff --git a/gst-libs/gst/pbutils/missing-plugins.c b/gst-libs/gst/pbutils/missing-plugins.c index 7d7f2f4f98..6ff16d5fb9 100644 --- a/gst-libs/gst/pbutils/missing-plugins.c +++ b/gst-libs/gst/pbutils/missing-plugins.c @@ -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); diff --git a/gst-libs/gst/pbutils/pbutils-private.h b/gst-libs/gst/pbutils/pbutils-private.h index 82fd22c890..bb475a337b 100644 --- a/gst-libs/gst/pbutils/pbutils-private.h +++ b/gst-libs/gst/pbutils/pbutils-private.h @@ -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);