Skip to content

WebRTC - ICE candidate raciness

The ICE gathering state can change to complete before all the ICE candidates are output, if libnice has upnp disabled, with a sequence like:

  1. app sets the remote description
  2. _create_transport_channel() queues an update_ice_gathering_state_task() that will run later
  3. webrtcbin calls gst_webrtc_ice_gather_candidates() which calls nice_agent_gather_candidates()
  4. nice_agent_gather_candidates() synchronously emits ICE candidates (normally async if gupnp is available) and they are queued for emission from the webrtcbin main loop
  5. GstWebRTCICEStream gets the candidate-gathering-done signal which queues an update_ice_gathering_state_task()
  6. The first update_ice_gathering_state_task() runs, and concludes that the ICE gathering state is complete, even though there are queued candidates.

This MR fixes that, and also a potential crash using the existing remote ICE candidates array by protecting it with a new mutex.

Merge request reports