webrtcbin: Source pads for unknown ssrc values are not added properly
When webrtcbin receives a new ssrc from rtpbin it tries to set up a source pad for the matching ssrc in the current SDP (on_rtpbin_pad_added: stream->remote_ssrcmap). If the ssrc is unknown (such as when the RTP packet is received before the SDP is updated with the remote ssrc) then the wrong media_idx might get used. When this occurs a critical error is generated (Padname src_0 is not unique in element X, not adding) and the RTP stream for this ssrc can not be received.
Additionally, if the SDP is being updated when this occurs then the process will sometimes crash with a null pointer error depending on the timing. It appears that the pad variable in the on_rtpbin_pad_added function can become NULL but the code continues executing (it only calls g_warn_if_reached if pad is NULL). This seems to be a race condition but I haven't been able to track it down yet.
A log for the critical error is below. This is using GStreamer 1.19.2 on Windows.
0:00:30.508853271 6516 02B85DF8 INFO webrtcbin gstwebrtcbin.c:6358:on_rtpbin_new_ssrc:<sendrecv> session 0 ssrc 292811685 new ssrc
0:00:30.514024891 6516 02B85DF8 WARN rtpsource rtpsource.c:1242:update_receiver_stats: probation: seqnr 4 != expected 3 (SSRC 292811685 curr_probation 1 probation 2)
0:00:30.603546289 6516 02B85DF8 INFO webrtcbin gstwebrtcbin.c:6421:on_rtpbin_new_jitterbuffer:<sendrecv> new jitterbuffer <rtpjitterbuffer1> for session 0 ssrc 292811685
0:00:30.604330461 6516 02B85DF8 TRACE webrtcbin gstwebrtcbin.c:599:_find_transport_for_session:<sendrecv> Found transport <transportstream0> for session 0
0:00:30.604922775 6516 02B85DF8 INFO webrtcbin gstwebrtcbin.c:6386:on_rtpbin_ssrc_validated:<sendrecv> session 0 ssrc 292811685 validated
0:00:30.709809219 6516 04F731E0 TRACE webrtcbin gstwebrtcbin.c:599:_find_transport_for_session:<sendrecv> Found transport <transportstream0> for session 0
0:00:30.710698710 6516 04F731E0 TRACE webrtcbin gstwebrtcbin.c:5953:on_rtpbin_pad_added:<sendrecv> new rtpbin pad recv_rtp_src_0_292811685_100
0:00:30.711088143 6516 04F731E0 TRACE webrtcbin gstwebrtcbin.c:599:_find_transport_for_session:<sendrecv> Found transport <transportstream0> for session 0
0:00:30.711271837 6516 04F731E0 WARN webrtcbin gstwebrtcbin.c:5986:on_rtpbin_pad_added:<sendrecv> Could not find ssrc 292811685
0:00:30.711452675 6516 04F731E0 TRACE webrtcbin gstwebrtcbin.c:560:_find_transceiver_for_mline:<sendrecv> Found transceiver <webrtctransceiver0> for mlineindex 0
0:00:30.711784142 6516 04F731E0 TRACE webrtcbin gstwebrtcbin.c:5998:on_rtpbin_pad_added:<sendrecv> found pad <sendrecv:src_0> for rtpbin pad name recv_rtp_src_0_292811685_100
0:00:30.712046213 6516 04F731E0 DEBUG webrtcbin gstwebrtcbin.c:5801:copy_sticky_events:<sendrecv:src_0> store sticky event stream-start event: 02B848C0, time 99:99:99.999999999, seq-num 272, GstEventStreamStart, stream-id=(string)f6cfb94213f4df2a9f178922e510520b, flags=(GstStreamFlags)GST_STREAM_FLAG_NONE, group-id=(uint)3;
0:00:30.712294813 6516 04F731E0 DEBUG webrtcbin gstwebrtcbin.c:5801:copy_sticky_events:<sendrecv:src_0> store sticky event caps event: 04FDE210, time 99:99:99.999999999, seq-num 747, GstEventCaps, caps=(GstCaps)"application/x-rtp\,\ media\=\(string\)video\,\ payload\=\(int\)100\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)VP8\,\ ssrc\=\(uint\)292811685";
0:00:30.712556884 6516 04F731E0 DEBUG webrtcbin gstwebrtcbin.c:5801:copy_sticky_events:<sendrecv:src_0> store sticky event segment event: 02B84908, time 99:99:99.999999999, seq-num 251, GstEventSegment, segment=(GstSegment)"segment, flags=(GstSegmentFlags)GST_SEGMENT_FLAG_NONE, rate=(double)1, applied-rate=(double)1, format=(GstFormat)time, base=(guint64)0, offset=(guint64)0, start=(guint64)0, stop=(guint64)18446744073709551615, time=(guint64)0, position=(guint64)0, duration=(guint64)18446744073709551615;";
(Test.exe:6516): GStreamer-CRITICAL **: 14:59:28.703: Padname src_0 is not unique in element sendrecv, not adding
0:00:30.951394366 6516 02B85DF8 INFO webrtcbin gstwebrtcbin.c:6365:on_rtpbin_ssrc_active:<sendrecv> session 0 ssrc 292811685 active