Title: [292563] trunk/Source/WebCore
Revision
292563
Author
[email protected]
Date
2022-04-07 13:58:35 -0700 (Thu, 07 Apr 2022)

Log Message

(Safari 15 - iOS15):  Increased audio latency on streaming via webrtc
https://bugs.webkit.org/show_bug.cgi?id=236363
<rdar://problem/88969850>

Reviewed by Eric Carlson.

On macOS 12.3, the default preferred buffer size is roughly 100 ms.
This is ok for regular audio playback but is not desirable when playing realtime audio.
To reduce the perceived latency, we now reduce the preferred buffer size to 20ms
whenever playing an audio MediaStreamTrack, similarly to when capturing audio.

Manually tested.

* platform/audio/PlatformMediaSession.cpp:
* platform/audio/PlatformMediaSession.h:
* platform/audio/cocoa/MediaSessionManagerCocoa.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292562 => 292563)


--- trunk/Source/WebCore/ChangeLog	2022-04-07 20:36:29 UTC (rev 292562)
+++ trunk/Source/WebCore/ChangeLog	2022-04-07 20:58:35 UTC (rev 292563)
@@ -1,3 +1,22 @@
+2022-04-07  Youenn Fablet  <[email protected]>
+
+        (Safari 15 - iOS15):  Increased audio latency on streaming via webrtc
+        https://bugs.webkit.org/show_bug.cgi?id=236363
+        <rdar://problem/88969850>
+
+        Reviewed by Eric Carlson.
+
+        On macOS 12.3, the default preferred buffer size is roughly 100 ms.
+        This is ok for regular audio playback but is not desirable when playing realtime audio.
+        To reduce the perceived latency, we now reduce the preferred buffer size to 20ms
+        whenever playing an audio MediaStreamTrack, similarly to when capturing audio.
+
+        Manually tested.
+
+        * platform/audio/PlatformMediaSession.cpp:
+        * platform/audio/PlatformMediaSession.h:
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+
 2022-04-07  Antoine Quint  <[email protected]>
 
         [web-animations] REGRESSION (r287881): loading performance for diply.com regressed

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp (292562 => 292563)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2022-04-07 20:36:29 UTC (rev 292562)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2022-04-07 20:58:35 UTC (rev 292563)
@@ -365,6 +365,11 @@
     return m_client.canProduceAudio();
 }
 
+bool PlatformMediaSession::hasMediaStreamSource() const
+{
+    return m_client.hasMediaStreamSource();
+}
+
 void PlatformMediaSession::canProduceAudioChanged()
 {
     PlatformMediaSessionManager::sharedManager().sessionCanProduceAudioChanged();

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (292562 => 292563)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2022-04-07 20:36:29 UTC (rev 292562)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2022-04-07 20:58:35 UTC (rev 292563)
@@ -179,6 +179,7 @@
 
     bool activeAudioSessionRequired() const;
     bool canProduceAudio() const;
+    bool hasMediaStreamSource() const;
     void canProduceAudioChanged();
 
     virtual void resetPlaybackSessionState() { }

Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm (292562 => 292563)


--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2022-04-07 20:36:29 UTC (rev 292562)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2022-04-07 20:58:35 UTC (rev 292563)
@@ -113,6 +113,7 @@
     int videoAudioCount = 0;
     int audioCount = 0;
     int webAudioCount = 0;
+    int audioMediaStreamTrackCount = 0;
     int captureCount = countActiveAudioCaptureSources();
     bool hasAudibleAudioOrVideoMediaType = false;
     bool isPlayingAudio = false;
@@ -126,9 +127,13 @@
             break;
         case PlatformMediaSession::MediaType::VideoAudio:
             ++videoAudioCount;
+            if (session.canProduceAudio() && session.hasMediaStreamSource())
+                ++audioMediaStreamTrackCount;
             break;
         case PlatformMediaSession::MediaType::Audio:
             ++audioCount;
+            if (session.canProduceAudio() && session.hasMediaStreamSource())
+                ++audioMediaStreamTrackCount;
             break;
         case PlatformMediaSession::MediaType::WebAudio:
             if (session.canProduceAudio()) {
@@ -152,6 +157,7 @@
 
     ALWAYS_LOG(LOGIDENTIFIER, "types: "
         "AudioCapture(", captureCount, "), "
+        "AudioTrack(", audioMediaStreamTrackCount, "), "
         "Video(", videoCount, "), "
         "Audio(", audioCount, "), "
         "VideoAudio(", videoAudioCount, "), "
@@ -160,8 +166,8 @@
     size_t bufferSize = m_defaultBufferSize;
     if (webAudioCount)
         bufferSize = AudioUtilities::renderQuantumSize;
-    else if (captureCount) {
-        // In case of audio capture, we want to grab 20 ms chunks to limit the latency so that it is not noticeable by users
+    else if (captureCount || audioMediaStreamTrackCount) {
+        // In case of audio capture or audio MediaStreamTrack playing, we want to grab 20 ms chunks to limit the latency so that it is not noticeable by users
         // while having a large enough buffer so that the audio rendering remains stable, hence a computation based on sample rate.
         bufferSize = AudioSession::sharedSession().sampleRate() / 50;
     } else if (m_supportedAudioHardwareBufferSizes && DeprecatedGlobalSettings::lowPowerVideoAudioBufferSizeEnabled())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to