From c52c66b575626c7ea76277831f53c81512ed33b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Tue, 3 Jan 2023 18:06:56 -0500 Subject: [PATCH] rtpopuspay: Return upstream channel filter based on OPUS vs MULTICAPS Only allow 1 or 2 channels if the caps are OPUS, or 3+ if they are MULTIOPUS. Part-of: --- .../gst-plugins-good/gst/rtp/gstrtpopuspay.c | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-good/gst/rtp/gstrtpopuspay.c b/subprojects/gst-plugins-good/gst/rtp/gstrtpopuspay.c index e3b0d946e9..4167949b06 100644 --- a/subprojects/gst-plugins-good/gst/rtp/gstrtpopuspay.c +++ b/subprojects/gst-plugins-good/gst/rtp/gstrtpopuspay.c @@ -371,9 +371,9 @@ static GstCaps * gst_rtp_opus_pay_getcaps (GstRTPBasePayload * payload, GstPad * pad, GstCaps * filter) { - GstCaps *caps, *peercaps, *tcaps; GstStructure *s; const gchar *stereo; + GstCaps *caps, *peercaps, *tcaps, *tempcaps; if (pad == GST_RTP_BASE_PAYLOAD_SRCPAD (payload)) return @@ -394,6 +394,40 @@ gst_rtp_opus_pay_getcaps (GstRTPBasePayload * payload, caps = gst_pad_get_pad_template_caps (GST_RTP_BASE_PAYLOAD_SINKPAD (payload)); + tempcaps = gst_caps_from_string ("application/x-rtp, " + "encoding-name=(string) { \"OPUS\", \"X-GST-OPUS-DRAFT-SPITTKA-00\"}"); + if (!gst_caps_can_intersect (peercaps, tempcaps)) { + GstCaps *multiopuscaps = gst_caps_new_simple ("audio/x-opus", + "channel-mapping-family", G_TYPE_INT, 1, + "channels", GST_TYPE_INT_RANGE, 3, 255, + NULL); + GstCaps *intersect_caps; + + intersect_caps = gst_caps_intersect_full (caps, multiopuscaps, + GST_CAPS_INTERSECT_FIRST); + gst_caps_unref (caps); + gst_caps_unref (multiopuscaps); + caps = intersect_caps; + } + gst_caps_unref (tempcaps); + + tempcaps = gst_caps_new_simple ("application/x-rtp", + "encoding-name", G_TYPE_STRING, "MULTIOPUS", NULL); + if (!gst_caps_can_intersect (peercaps, tempcaps)) { + GstCaps *opuscaps = gst_caps_new_simple ("audio/x-opus", + "channel-mapping-family", G_TYPE_INT, 0, + "channels", GST_TYPE_INT_RANGE, 1, 2, + NULL); + GstCaps *intersect_caps; + + intersect_caps = gst_caps_intersect_full (caps, opuscaps, + GST_CAPS_INTERSECT_FIRST); + gst_caps_unref (caps); + gst_caps_unref (opuscaps); + caps = intersect_caps; + } + gst_caps_unref (tempcaps); + s = gst_caps_get_structure (peercaps, 0); stereo = gst_structure_get_string (s, "stereo"); if (stereo != NULL) {