diff options
author | Olivier CrĂȘte <olivier.crete@collabora.com> | 2021-03-26 20:55:36 -0400 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2021-04-12 17:55:07 -0400 |
commit | 5971a9610992d08746e9137ea5b8bc4e2b2b61ae (patch) | |
tree | 83821f975828671f52648bb9c3bfa02dcd6c3f01 /ext | |
parent | 2ca4cea5385d8fc63768dcf607cee460c7d0f79d (diff) | |
download | gstreamer-plugins-bad-5971a9610992d08746e9137ea5b8bc4e2b2b61ae.tar.gz |
webrtcbin: Try to match an existing transceiver on pad request
This should avoid creating extra transceivers that are duplicated.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2104>
Diffstat (limited to 'ext')
-rw-r--r-- | ext/webrtc/gstwebrtcbin.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index d439657a9..b21faa48b 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -6373,6 +6373,52 @@ gst_webrtc_bin_request_new_pad (GstElement * element, GstPadTemplate * templ, } } + /* Let's try to find a free transceiver that matches */ + if (!trans) { + GstWebRTCKind kind = GST_WEBRTC_KIND_UNKNOWN; + guint i; + + if (caps) + kind = _kind_from_caps (caps); + + for (i = 0; i < webrtc->priv->transceivers->len; i++) { + GstWebRTCRTPTransceiver *tmptrans = + g_ptr_array_index (webrtc->priv->transceivers, i); + GstWebRTCBinPad *pad2; + + /* Ignore transceivers with a non-matching kind */ + if (tmptrans->kind != GST_WEBRTC_KIND_UNKNOWN && + kind != GST_WEBRTC_KIND_UNKNOWN && tmptrans->kind != kind) + continue; + + /* Ignore stopped transmitters */ + if (tmptrans->stopped) + continue; + + /* Ignore transceivers that are only for receiving ... */ + if (tmptrans->direction == GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_RECVONLY + || tmptrans->direction == + GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_INACTIVE) + continue; + + /* Ignore transceivers that already have a pad allocated */ + pad2 = _find_pad_for_transceiver (webrtc, GST_PAD_SINK, tmptrans); + if (pad2) { + gst_object_unref (pad2); + continue; + } + + /* Ignore transceivers with non-matching caps */ + if (caps && tmptrans->codec_preferences && + !gst_caps_can_intersect (caps, tmptrans->codec_preferences)) { + continue; + } + + trans = tmptrans; + break; + } + } + if (!trans) { trans = GST_WEBRTC_RTP_TRANSCEIVER (_create_webrtc_transceiver (webrtc, GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDRECV, -1)); |