Bug 236363 - (Safari 15 - iOS15): Increased audio latency on streaming via webrtc
Summary: (Safari 15 - iOS15): Increased audio latency on streaming via webrtc
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari 15
Hardware: iPhone / iPad iOS 15
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-09 07:03 PST by asanand
Modified: 2022-06-29 10:30 PDT (History)
13 users (show)

See Also:


Attachments
Patch (4.96 KB, patch)
2022-04-07 04:29 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 asanand 2022-02-09 07:03:40 PST
We are observing noticeable increase in audio latency in Safari browser iOS 15.4 beta.

Our Client side implementation plays webrtc audio/video stream received from server on video element.


We have looked in the mediaserverd logs(presented below) and here is our finding



default	12:34:35.138370+0530	mediaserverd	-CMVAEndptMgr- vaemSetDeviceBufferDuration: duration = 0.085, sampleRate = 48000.000, numPCMSamples = 4095, NearestPowerOf2 = 4096, UseQuietBufferSizeProperty = ‘NO’


When we play the same after enabling the "AudioContext", we are getting following log
  
default	12:42:35.257580+0530	mediaserverd	-CMVAEndptMgr- vaemSetDeviceBufferDuration: duration = 0.003, sampleRate = 48000.000, numPCMSamples = 127, NearestPowerOf2 = 128, UseQuietBufferSizeProperty = ‘NO’

the numPCMSamples in case of AudioContext is reducing down to 127 and its having direct impact on our audio latency.
Comment 1 Alexey Proskuryakov 2022-02-10 10:32:30 PST
Could you please clarify if this is a new issue in Safari 15.4 beta, or if it affects shipping Safari too?
Comment 2 youenn fablet 2022-02-10 10:53:27 PST
Also, is the application capturing microphone?
It is not unexpected that web audio will get you the lowest latency.
Comment 3 asanand 2022-02-10 20:21:25 PST
(In reply to Alexey Proskuryakov from comment #1)
> Could you please clarify if this is a new issue in Safari 15.4 beta, or if
> it affects shipping Safari too?

It affects shipping safari too
Comment 4 asanand 2022-02-10 20:25:06 PST
(In reply to youenn fablet from comment #2)
> Also, is the application capturing microphone?
> It is not unexpected that web audio will get you the lowest latency.

The application is not capturing microphone.

What should be the difference in latency between playing with and without WebAudio.
Comment 5 youenn fablet 2022-02-11 01:03:17 PST
(In reply to asanand from comment #4)
> (In reply to youenn fablet from comment #2)
> > Also, is the application capturing microphone?
> > It is not unexpected that web audio will get you the lowest latency.
> 
> The application is not capturing microphone.
> 
> What should be the difference in latency between playing with and without
> WebAudio.

A small latency is better for reactiveness, less so for battery life and stability.
With WebAudio, spec mentions a small audio quantum so we tune the audio renderer accordingly.
For regular audio, we do a different set up but I can see some applications wanting to get low latency for incoming WebRTC audio.

We could look at implementing https://w3c.github.io/webrtc-extensions/#dom-rtcrtpreceiver-playoutdelay so that your application could provide a hint about this.

Can you provide more info on your usecase?
Comment 6 asanand 2022-02-14 05:04:34 PST
(In reply to youenn fablet from comment #5)
> (In reply to asanand from comment #4)
> > (In reply to youenn fablet from comment #2)
> > > Also, is the application capturing microphone?
> > > It is not unexpected that web audio will get you the lowest latency.
> > 
> > The application is not capturing microphone.
> > 
> > What should be the difference in latency between playing with and without
> > WebAudio.
> 
> A small latency is better for reactiveness, less so for battery life and
> stability.
> With WebAudio, spec mentions a small audio quantum so we tune the audio
> renderer accordingly.
> For regular audio, we do a different set up but I can see some applications
> wanting to get low latency for incoming WebRTC audio.
> 
> We could look at implementing
> https://w3c.github.io/webrtc-extensions/#dom-rtcrtpreceiver-playoutdelay so
> that your application could provide a hint about this.
> 
> Can you provide more info on your usecase?
We are having application for cloud gaming where we stream audio/video with optional upstream(mic streams)
Comment 7 Radar WebKit Bug Importer 2022-02-15 09:32:08 PST
<rdar://problem/88969850>
Comment 8 asanand 2022-03-16 06:18:30 PDT
(In reply to youenn fablet from comment #5)
> (In reply to asanand from comment #4)
> > (In reply to youenn fablet from comment #2)
> > > Also, is the application capturing microphone?
> > > It is not unexpected that web audio will get you the lowest latency.
> > 
> > The application is not capturing microphone.
> > 
> > What should be the difference in latency between playing with and without
> > WebAudio.
> 
> A small latency is better for reactiveness, less so for battery life and
> stability.
> With WebAudio, spec mentions a small audio quantum so we tune the audio
> renderer accordingly.
> For regular audio, we do a different set up but I can see some applications
> wanting to get low latency for incoming WebRTC audio.
> 
> We could look at implementing
> https://w3c.github.io/webrtc-extensions/#dom-rtcrtpreceiver-playoutdelay so
> that your application could provide a hint about this.
> 
> Can you provide more info on your usecase?

When can we expect a fix for this issue where we could provide a hint as mentioned here
> We could look at implementing
> https://w3c.github.io/webrtc-extensions/#dom-rtcrtpreceiver-playoutdelay so
> that your application could provide a hint about this.
Comment 9 Virginia Farley 2022-03-29 14:20:08 PDT
Youenn, could you please provide an update on the fix for this?
Comment 10 youenn fablet 2022-04-07 04:29:13 PDT
Created attachment 456906 [details]
Patch
Comment 11 EWS 2022-04-07 13:59:46 PDT
Committed r292563 (249401@main): <https://commits.webkit.org/249401@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 456906 [details].
Comment 12 asanand 2022-04-07 21:08:51 PDT
(In reply to youenn fablet from comment #10)
> Created attachment 456906 [details]
> Patch

Which Safari version should have this fix ?
Comment 13 Brent Fulgham 2022-05-26 15:05:23 PDT
This fix shipped with Safari 15.5 (all platforms).
Comment 14 Virginia Farley 2022-06-24 14:02:11 PDT
Still observing an additional ~50ms of latency after this patch.  Could we please reevaluate whether the preferred buffer size could be further reduced to address the audio latency, or whether a different approach could be considered to resolve this?