From c7107fd940a09f02b077516966b3d4dd7b7e171e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Wed, 31 Mar 2021 11:40:28 -0400 Subject: [PATCH] webrtcbin: Ensure that query caps method returns valid caps 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: --- ext/webrtc/gstwebrtcbin.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index c92e4ad724..18e722243e 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -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++) {