Closed Bug 1601034 Opened 5 years ago Closed 4 years ago

whereby.com results in audio video drift if you update the settings

Categories

(Core :: WebRTC: Audio/Video, defect, P2)

defect

Tracking

()

VERIFIED FIXED
mozilla73
Tracking Status
firefox71 --- wontfix
firefox72 --- verified
firefox73 --- verified

People

(Reporter: achronop, Assigned: pehrsons)

References

Details

Attachments

(4 files)

STR:
Connect to a room in the new whereby.com (mozilla.whereby.com).
Press the settings.
Change the microphone (assuming you have more than one)
Press "Apply Changes"
On the new gUM prompt press "Allow"
The remote party reports A/V delay, between 1 and 2 seconds.

I am testing on Linux but I don't know if that affects

Does the remote party report audio delay or video delay?

I have a hypothesis on what's happening, and if it holds it means that there is a video delay, and that this delay is roughly proportional to the time the user takes to approve the new gUM prompt.

We've observed both audio delays and video delays. Unclear exactly how this happens. But it smells to me like all tracks are stopped, new tracks get acquired through gUM (after user approval, can take a loooong time!), then tracks get replaced with sender.replaceTrack() and sending continues.

After this has finished it looks like the remote side's jitter buffers are very confused.

Could it be because we keep sending a video frame every second whereas we don't send audio at all, while blocked on the gUM prompt?

Byron, do you know how we handle/should handle A/V sync when something like this happens?

Flags: needinfo?(docfaraday)

I have been experimenting with this fiddle. It reproduces the error, which is sporadic. Also, the delay varies between tries.

The time to approve the second gUM affects but in an odd way. If the approve happens fast the problem occurs. If the approve happens after some time (10 secs) there is no error, the receiving stream is fine and A/V is in sync.

No, that stuff all happens down in the webrtc.org code.

Flags: needinfo?(docfaraday) → needinfo?(dminor)
Summary: whereby.com results in audio video drift if you update the setting → whereby.com results in audio video drift if you update the settings

Sorry, I'm a bit behind. I'll have a look at this later today or early next week.

I'm not entirely clear how Whereby do their switches yet, but assuming that they replaceTrack() an ended track with a live track I think I can fix this.

We can make each active RTCRtpSender hold a ForwardedInputTrack that doesn't end until the sender goes away for sure. Thus if the input track ends the ForwardedInputTrack is still producing silence for the peer connection's rtp stream.

Same concept as we did for DecodedStream in bug 1172394, and similar to bug 1586370 in that we run the graph even though no audio is being processed by it.

I have some WIP patches that seem to result in a massive improvement. Just as the new devices start flowing to the remote side, there's some video glitches visible there, but they recover fast. This is probably an artifact of the video jitter buffer, since we didn't send anything between stopping the old and acquiring the new camera. If whereby wouldn't stop the old camera until they acquire the new, this shouldn't be an issue.

Assignee: nobody → apehrson
Status: NEW → ASSIGNED
Flags: needinfo?(dminor)
See Also: → 1172394, 1586370
See Also: → 1602723

I forked Alex' fiddle for a corner case I found. If we just stop and replace audio, without touching video, that seems to result in silence on Nightly. I've fixed this.

Before this patch, if a send audio MediaStreamTrack ended, we ended up not
sending anything over the network. If replaceTrack() at that point replaced the
ended track with a live one, we'd start sending data again, but the rtp stream
would continue from where the previous track ended.

Having a gap in audio like that would confuse a receiver's video jitter
buffer, because it's trying to sync to an audio track that just had a massive
amount of "jitter" (it can't tell the difference).

This patch fixes this by adding a track layer in MediaPipelineTransmit that
remains active for as long as the MediaPipeline is active. Thus if the send
audio MediaStreamTrack ends, we continue sending silence over the network, which
the receiver can understand. If later replaced, the receiver sees real audio
instead of silence and continues gracefully.

I'm also testing with this fiddle that does sender.replaceTrack(null). Seems to reproduce in release 71 as well.

Component: Audio/Video: MediaStreamGraph → WebRTC: Audio/Video
Pushed by pehrsons@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/e17753103d27
Add a ProcessedMediaTrack layer in MediaPipelineTransmit to handle replaceTrack of ended tracks. r=dminor,padenot
https://hg.mozilla.org/integration/autoland/rev/6a429cfa6440
Only update the conduit in replaceTrack() if the track source changed between camera and non-camera. r=bwc

The STS thread dispatches SyncRunnables to main thread. There are two cases of
blocking affected here:

  • SyncRunnables from main to STS:
    Can cause a deadlock.
  • PR_Sleep on the main thread:
    Effectively sleeps STS too, if STS dispatches a SyncRunnable to main during
    main's sleep.

This patch gets rid of both of these.

Depends on D57001

Flags: needinfo?(apehrson)
Pushed by pehrsons@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/98212026404b
Add a ProcessedMediaTrack layer in MediaPipelineTransmit to handle replaceTrack of ended tracks. r=dminor,padenot
https://hg.mozilla.org/integration/autoland/rev/902cf0de82c3
Only update the conduit in replaceTrack() if the track source changed between camera and non-camera. r=bwc
https://hg.mozilla.org/integration/autoland/rev/715477743439
Set the MediaPipelineTransmit send track in a dedicated method to enable unit tests. r=bwc
https://hg.mozilla.org/integration/autoland/rev/313e96351327
Do not block main thread in mediapipeline_unittest.cpp. r=bwc

Comment on attachment 9114985 [details]
Bug 1601034 - Add a ProcessedMediaTrack layer in MediaPipelineTransmit to handle replaceTrack of ended tracks. r?dminor!,padenot!

Beta/Release Uplift Approval Request

  • User impact if declined: Users using webrtc services may appear with video a few seconds behind audio, on the other participants' screen.
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: Yes
  • If yes, steps to reproduce: See comment 0. Any whereby room should work now as they've rolled the new interface out everywhere (no mozilla subdomain needed).
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): This mainly shuffles some things on main thread around. The biggest risk is missing some event on the newly introduced MediaTrack that was only signaled on the old one, but I can't think of any more than the one (enabled/disabled) fixed in this patch.
  • String changes made/needed:
Attachment #9114985 - Flags: approval-mozilla-beta?
Attachment #9114986 - Flags: approval-mozilla-beta?
Attachment #9115602 - Flags: approval-mozilla-beta?
Attachment #9115604 - Flags: approval-mozilla-beta?
Flags: qe-verify+
QA Whiteboard: [qa-triaged]

Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0

I can't confirm the fix on my end - on Ubuntu 18.04 and Nightly 73.0a1 (20191216214733). I see a delay (audio and video), right after the microphone setting is done, but with no noticeable difference between Firefox 72 beta 7 and the latest Nightly 73.0a1 (also, after a short period of time video and audio get in sync)

Alex, please can you confirm whether this issue is still reproducible on the latest Nightly 73.0a1?

Flags: needinfo?(achronop)

Comment on attachment 9114985 [details]
Bug 1601034 - Add a ProcessedMediaTrack layer in MediaPipelineTransmit to handle replaceTrack of ended tracks. r?dminor!,padenot!

webrtc fix, approved for 72.0b8

Attachment #9114985 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9114986 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9115602 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9115604 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

Ok I just did some testing myself and I think bug 1586370 is playing some tricks on us (same symptoms, and it kicks in with the STR here).

Try this STR instead, it should rule out bug 1586370 by keeping the mic we are changing to on when the switch happens:

  1. Pick a whereby room to use, from here on called "the room"
  2. Make sure you have two microphones on your system, from here on called Mic A and Mic B
  3. Join the room with a separate machine, (or another browser instance on the same machine) -- mute camera and mic
  4. Go to https://mozilla.github.io/webrtc-landing/gum_test.html, click "Microphone", choose Mic A, mute the audio element
  5. Go to the room, make sure to select Mic B and any camera
  6. Continue the original STR:
    Press the settings.
    Change the microphone (assuming you have more than one)
    Press "Apply Changes"
    On the new gUM prompt press "Allow"
    The remote party reports A/V delay, between 1 and 2 seconds.

Expected: Audio and video stays in sync, even after waiting for some time

Flags: needinfo?(simona.marcu)

Thanks Andreas! With the provided steps, I was able to reproduce the initial issue. I can now confirm that audio and video stay in sync on the latest Nightly 73.0a1 and on Firefox 72 beta 8 - verified as fixed on Windows 10 x64 and Ubuntu 18.04.

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-triaged]
Flags: qe-verify+
Flags: needinfo?(simona.marcu)

This is now verified. Also, I have verified the fiddle from comment 4. I am clearing the NI.

Flags: needinfo?(achronop)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: