Bug 186889 - WebRTC MediaStreamTrack Enable / Disable causes video delay / lag
Summary: WebRTC MediaStreamTrack Enable / Disable causes video delay / lag
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari 11
Hardware: All All
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-06-21 09:08 PDT by Neil Kinnish
Modified: 2018-07-06 16:47 PDT (History)
4 users (show)

See Also:


Attachments
Patch (14.05 KB, patch)
2018-07-06 12:31 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (15.47 KB, patch)
2018-07-06 12:42 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (4.04 KB, patch)
2018-07-06 13:06 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (15.48 KB, patch)
2018-07-06 15:54 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Neil Kinnish 2018-06-21 09:08:18 PDT
This is a similar issue reported and fixed on chrome:

https://bugs.chromium.org/p/webrtc/issues/detail?id=4355

Enable / Disable a WebRTC MediaStreamTrack and the video is delayed and suffers lag, refreshing fixes so it definitely seems to be caused by this event. Disable / enable is used to mute the audio or video and is necessary.
Comment 1 Neil Kinnish 2018-06-21 09:09:46 PDT
To add more context... the video will be affected even if you are only changing an audio track.
Comment 2 Neil Kinnish 2018-06-21 09:41:20 PDT
In further tests, even without Video, just audio. Disabling and enabling causes Safari to lag remote streams and eventually fail. I'll try and get more information on the eventual fail by debugging a bit more.
Comment 3 Neil Kinnish 2018-06-21 09:51:04 PDT
I don't have the full info, but it appears the stream ends completely when you set enable to false, this is more noticeable when only video or audio as having two and one remaining enabled would keep the stream alive. 

Hope this helps.
Comment 4 Neil Kinnish 2018-06-21 10:30:16 PDT
To add... this seems intermittent, but easily reproducible if you just enable/disable (mute audio for example).
Comment 5 Neil Kinnish 2018-06-22 04:50:26 PDT
Further testing with both video + audio.

Video tracks set to enabled false cause less issues than audio set to enabled false. There is also a noticeable delay changing audio compared to video. Audio is also what seems to cause lag in video I haven't seen this when video tracks enabled/disabled.
Comment 6 Radar WebKit Bug Importer 2018-06-22 09:33:51 PDT
<rdar://problem/41370285>
Comment 7 youenn fablet 2018-06-22 09:38:28 PDT
Hi Neil, thanks for the report.
Can you clarify whether the issue is with capture tracks or remote tracks backed by a peer connection?
If you have a repel case that you could share,that would be great.
Comment 8 Radar WebKit Bug Importer 2018-06-22 09:38:39 PDT
<rdar://problem/41370427>
Comment 9 Neil Kinnish 2018-06-22 10:32:58 PDT
Hi

> Can you clarify whether the issue is with capture tracks or remote tracks backed by a peer connection?

Capture tracks, I'm not seeing the issues on remote tracks, at least I haven't seen anything as bad.

> If you have a repel case that you could share,that would be great.

I don't have anything I can share right now I'm afraid. If I get time I'll try and put something together but not sure when I will have time.

I think my report is essentially 2 issues (they may be connected):

1. The issue where the video track becomes delayed when you disable audio (lag) does seem to very similar to the issue chrome use to experience as per that link.

2. The intermittent stream fails (mainly when you only have video or audio – not both), don't get an error but it seems as nothing is being sent.

As per last comment it's really noticeable that disabling audio tracks is slow compared to video.

Thanks for responding.
Comment 10 Neil Kinnish 2018-06-22 13:18:10 PDT
Okay, I've done a lot more testing.

1. I restarted the IOS device which I was seeing the stream fails on and also got hold of another 2 IOS devices. I don't seem to be able to re-create that particular issue now, so could have just been a temp issue on the device!? 

2. The original issue – video delay after muting (disabling) audio track however is still present. The video being sent is noticeably delayed on the other end after muting.

I can't send you my project, but to test this case I just downloaded: https://github.com/shanet/WebRTC-Example

I added an audio toggle...

```
function toggleAudio() {
  if (localStream.getAudioTracks()[0].enabled) {
    localStream.getAudioTracks()[0].enabled = false;
  } else {
    localStream.getAudioTracks()[0].enabled = true;
  }
}
```

It causes the same issue, the more you mute the more delay.

Hope this helps, sorry for so many pings.
Comment 11 Neil Kinnish 2018-06-22 13:23:11 PDT
PS... I tested on IOS 11 and macOS 10.13.3, happened on both.
Comment 12 youenn fablet 2018-06-22 15:21:39 PDT
(In reply to Neil Kinnish from comment #11)
> PS... I tested on IOS 11 and macOS 10.13.3, happened on both.

Thanks Neil for all this information, this will help us figure out the issue.
Comment 13 Neil Kinnish 2018-07-04 08:42:10 PDT
Just to add, in further tests I've noticed that overtime the video will lag generally... this is exaggerated when the stream is enabled / disabled. Mainly tested on iOS.
Comment 14 youenn fablet 2018-07-06 12:31:01 PDT
Created attachment 344438 [details]
Patch
Comment 15 youenn fablet 2018-07-06 12:42:22 PDT
Created attachment 344441 [details]
Patch
Comment 16 youenn fablet 2018-07-06 13:06:14 PDT
Created attachment 344444 [details]
Patch
Comment 17 Eric Carlson 2018-07-06 14:02:03 PDT
Comment on attachment 344444 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=344444&action=review

> Source/ThirdParty/libwebrtc/ChangeLog:4
> +        https://bugs.webkit.org/show_bug.cgi?id=186889

Isn’t this the wrong bug title for this fix?
Comment 18 youenn fablet 2018-07-06 15:54:16 PDT
Created attachment 344470 [details]
Patch for landing
Comment 19 WebKit Commit Bot 2018-07-06 16:47:07 PDT
Comment on attachment 344470 [details]
Patch for landing

Clearing flags on attachment: 344470

Committed r233604: <https://trac.webkit.org/changeset/233604>
Comment 20 WebKit Commit Bot 2018-07-06 16:47:09 PDT
All reviewed patches have been landed.  Closing bug.