-
Notifications
You must be signed in to change notification settings - Fork 214
Description
We're seeing high latency (up to 2.0 seconds) between speaking into the microphone of the remote peer and playing the audio at the receiving peer . We think it is caused by a growing webrtc jitter buffer for the inbound audio track, however we are still trying to investigate and learn more.
To Reproduce
(1) Unity Peer1 on machine1 connect to C++ webrtc server
(2) Chrome browswer Peer2 on machine2 connect to C++ webrtc server
(3) Note: server does spatialization mixing and relays results to Peer1 and Peer2
(4) Peer1 speaks into mic...
(5) Peer2 hears audio with low latency (0.25 - 0.5 seconds)
(6) Peer2 speaks into mic ...
(7) ... Peer1 hears audio with high latency (1.0 - 2.0 seconds) BUG!
It is intermittent! Sometimes we can get a lower latency (0.25 - 0.5 seconds) by doing the following:
(8) Mute the mic on peer2 and wait several seconds.
(9) Unmute the mic on Peer2 and speak...
(10) ... Peer1 sometimes hears audio with lower latency but eventually the latency grows to high levels again.
Note: we also tested on Windows but there only noticed high latency: we couldn't use the mute/unmute trick to get intermittent low latency audio. We didn't try this for very hard: two or three times. We mostly just wanted to verify that it wasn't a linux-only problem.
Expected behavior
The latency for audio from Peer1 to Peer2 is low (0.25 - 0.5 seconds). We would expect similar latency in the other direction: Peer2 to Peer1.
Theory: is Unity draining webrtc's audio buffer too aggresively?
The behavior suggests the unity plugin is sometimes asking for audio from webrtc's inbound audio buffer too often, or in a bursty fashion, which could cause webrtc to supply "fake" audio data and grow its jitter buffer to compensate. When inbound audio is muted webrtc has an opportunity to flush its jitter buffer to be smaller which is maybe why it sometimes shows up as low latency for a while.
We are trying to investigate. The plan is to harvest webrtc stats to make a histogram of jitter buffer state. If we learn more we will post updates.
Environment:
- OS: Ubunutu-20.04
- Browser: Chrome 92.0.4515.159 (for Peer2)
- Unity Version: 2020.3.17f1
- Package version: 2.4.0-exp.4