Bug 239978 - replaceTrack with different constraints stops sending packets
Summary: replaceTrack with different constraints stops sending packets
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari 15
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-05-02 12:19 PDT by makarand
Modified: 2022-05-06 03:27 PDT (History)
11 users (show)

See Also:


Attachments
Patch (1.98 KB, patch)
2022-05-04 04:15 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (1.98 KB, patch)
2022-05-04 23:48 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 makarand 2022-05-02 12:19:04 PDT
One of our (twilio) customers noticed this bug. They found it on iOS 15.4, but I see that we can reproduce it on Safari 15.4 running on MacOS as well.  

Easy repro steps using 

https://codepen.io/makarand-patwardhan/pen/yLvyJgB

1. Click on Start Demo:
   This will establish webrtc between two peer connection with one party publishing an audio track

2. Notice that packets are flowing nicely between Peers.

3. Check on Music Mode and click on Update Track 
   This will cause a new audio track to get acquired using different constrains than used originally. 
   This new track is then used to replaceTrack (https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/replaceTrack)

At this point notice that the packets stop flowing and after about 20 seconds you see an error "A MediaStreamTrack ended due to a capture failure" on console.


Notice that in Step 3 if you did not change the music Mode (that is use the same constraints as before you do not see this error)
Comment 1 youenn fablet 2022-05-02 12:26:56 PDT
This might be related or similar to https://bugs.webkit.org/show_bug.cgi?id=239956, probably a fall out of using VPIO for audio rendering.
Comment 2 Radar WebKit Bug Importer 2022-05-02 12:27:10 PDT
<rdar://problem/92624773>
Comment 3 youenn fablet 2022-05-04 04:15:39 PDT
Created attachment 458788 [details]
Patch
Comment 4 Eric Carlson 2022-05-04 08:27:31 PDT
Comment on attachment 458788 [details]
Patch

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

> Source/WebCore/ChangeLog:9
> +        We should always reconfigure thr microphone processor even if we are not using it,

s/thr/the/
Comment 5 makarand 2022-05-04 09:27:47 PDT
Hello Youenn,

Thank you for looking at this - Can you please let us know which version will have the fix ? And in the meanwhile what can our customer do to workaround this?
Comment 6 youenn fablet 2022-05-04 23:39:40 PDT
In the fiddle, the workaround is to not stop the audio track before getting another one (or stop it after getting the new one).

Another approach is to stop audio rendering just before starting capture. And restart audio rendering once capture started.
Comment 7 youenn fablet 2022-05-04 23:48:28 PDT
Created attachment 458853 [details]
Patch for landing
Comment 8 EWS 2022-05-05 02:50:07 PDT
Committed r293827 (250300@main): <https://commits.webkit.org/250300@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 458853 [details].
Comment 9 Ostap 2022-05-06 03:27:30 PDT
Hello,

Which version will have the fix?

We have tried one of the latest builds in https://webkit.org/build-archives/#mac-monterey-x86_64%20arm64 MAY 6, 2022, 12:25 PM GMT+3, and we could still reproduce the issue.