webrtcbin: Ensure that query caps method returns valid caps
authorOlivier Crête <olivier.crete@collabora.com>
Wed, 31 Mar 2021 15:40:28 +0000 (11:40 -0400)
committerOlivier Crête <olivier.crete@collabora.com>
Mon, 12 Apr 2021 22:37:27 +0000 (18:37 -0400)
This means rejecting any caps that aren't fixed. Also, use a filter
that will create unfixed caps if the other side just returns ANY.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2104>

ext/webrtc/gstwebrtcbin.c

index c92e4ad..18e7222 100644 (file)
@@ -1511,9 +1511,28 @@ _find_codec_preferences (GstWebRTCBin * webrtc,
         GST_LOG_OBJECT (webrtc, "Using current pad caps: %" GST_PTR_FORMAT,
             caps);
       } else {
-        if ((caps = gst_pad_peer_query_caps (GST_PAD (pad), NULL)))
-          GST_LOG_OBJECT (webrtc, "Using peer query caps: %" GST_PTR_FORMAT,
-              caps);
+        static GstStaticCaps static_filter =
+            GST_STATIC_CAPS ("application/x-rtp, "
+            "media = (string) { audio, video }, payload = (int) [ 0, 127 ]");
+        GstCaps *filter = gst_static_caps_get (&static_filter);
+
+        filter = gst_caps_make_writable (filter);
+
+        if (rtp_trans->kind == GST_WEBRTC_KIND_AUDIO)
+          gst_caps_set_simple (filter, "media", G_TYPE_STRING, "audio", NULL);
+        else if (rtp_trans->kind == GST_WEBRTC_KIND_VIDEO)
+          gst_caps_set_simple (filter, "media", G_TYPE_STRING, "video", NULL);
+
+        caps = gst_pad_peer_query_caps (GST_PAD (pad), filter);
+        GST_LOG_OBJECT (webrtc, "Using peer query caps: %" GST_PTR_FORMAT,
+            caps);
+
+        if (!gst_caps_is_fixed (caps) || gst_caps_is_equal_fixed (caps, filter)
+            || gst_caps_is_empty (caps) || gst_caps_is_any (caps)) {
+          gst_caps_unref (caps);
+          caps = NULL;
+        }
+        gst_caps_unref (filter);
       }
       if (caps) {
         if (trans)
@@ -1539,6 +1558,9 @@ _add_supported_attributes_to_caps (GstWebRTCBin * webrtc,
   GstCaps *ret;
   guint i;
 
+  if (caps == NULL)
+    return NULL;
+
   ret = gst_caps_make_writable (caps);
 
   for (i = 0; i < gst_caps_get_size (ret); i++) {