Title: [269134] trunk/Source/WebCore
Revision
269134
Author
[email protected]
Date
2020-10-28 19:40:31 -0700 (Wed, 28 Oct 2020)

Log Message

Web Audio broken on iOS 14 after switching app
https://bugs.webkit.org/show_bug.cgi?id=217606
<rdar://problem/70231769>

Reviewed by Eric Carlson.

When we call AudioOutputUnitStart(), AVFoundation checks if we are allowed to play by
making sure that our application is foreground. In order to do that, AVFoundation
needs the PID of our hosting application. We provide this PID whenever the following
function is called:
MediaSessionManageriOS::providePresentingApplicationPIDIfNecessary()

The issue was that we were not calling providePresentingApplicationPIDIfNecessary()
before starting WebAudio playback. As a result, AVFoundation was relying on the
visibility of the WebContent process itself. This was causing a race because
RunningBoard gets notified that the WebContent process is visible a little later
than for the UIProcess. When the UIProcess would become foreground, we would send
the SetApplicationState IPC to the WebProcess, which would update the page's
visibility and cause us to stop the media session interruption. This would cause
us to call AudioOutputUnitStart(), which would fail because AVFoundation would
ask RunningBoard if the WebContent process is foreground. At this point,
RunningBoard would not necessarily know yet that the WebContent process is
visible. However, RunningBoard reliably knows the UIProcess is visible at this
point.

We now call this function inside MediaSessionManageriOS::sessionWillBeginPlayback()
since this gets called by WebAudio code before starting the playback.

* platform/audio/cocoa/AudioOutputUnitAdaptor.cpp:
(WebCore::AudioOutputUnitAdaptor::start):
Add some error logging when the call to AudioOutputUnitStart() fails to facilitate
debugging such issues in the future.

* platform/audio/ios/MediaSessionManagerIOS.mm:
(WebCore::MediaSessionManageriOS::sessionWillBeginPlayback):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (269133 => 269134)


--- trunk/Source/WebCore/ChangeLog	2020-10-29 00:51:55 UTC (rev 269133)
+++ trunk/Source/WebCore/ChangeLog	2020-10-29 02:40:31 UTC (rev 269134)
@@ -1,3 +1,41 @@
+2020-10-28  Chris Dumez  <[email protected]>
+
+        Web Audio broken on iOS 14 after switching app
+        https://bugs.webkit.org/show_bug.cgi?id=217606
+        <rdar://problem/70231769>
+
+        Reviewed by Eric Carlson.
+
+        When we call AudioOutputUnitStart(), AVFoundation checks if we are allowed to play by
+        making sure that our application is foreground. In order to do that, AVFoundation
+        needs the PID of our hosting application. We provide this PID whenever the following
+        function is called:
+        MediaSessionManageriOS::providePresentingApplicationPIDIfNecessary()
+
+        The issue was that we were not calling providePresentingApplicationPIDIfNecessary()
+        before starting WebAudio playback. As a result, AVFoundation was relying on the
+        visibility of the WebContent process itself. This was causing a race because
+        RunningBoard gets notified that the WebContent process is visible a little later
+        than for the UIProcess. When the UIProcess would become foreground, we would send
+        the SetApplicationState IPC to the WebProcess, which would update the page's
+        visibility and cause us to stop the media session interruption. This would cause
+        us to call AudioOutputUnitStart(), which would fail because AVFoundation would
+        ask RunningBoard if the WebContent process is foreground. At this point,
+        RunningBoard would not necessarily know yet that the WebContent process is
+        visible. However, RunningBoard reliably knows the UIProcess is visible at this
+        point.
+
+        We now call this function inside MediaSessionManageriOS::sessionWillBeginPlayback()
+        since this gets called by WebAudio code before starting the playback.
+
+        * platform/audio/cocoa/AudioOutputUnitAdaptor.cpp:
+        (WebCore::AudioOutputUnitAdaptor::start):
+        Add some error logging when the call to AudioOutputUnitStart() fails to facilitate
+        debugging such issues in the future.
+
+        * platform/audio/ios/MediaSessionManagerIOS.mm:
+        (WebCore::MediaSessionManageriOS::sessionWillBeginPlayback):
+
 2020-10-28  Conrad Shultz  <[email protected]>
 
         Remove diagnostic logging for plug-ins

Modified: trunk/Source/WebCore/platform/audio/cocoa/AudioOutputUnitAdaptor.cpp (269133 => 269134)


--- trunk/Source/WebCore/platform/audio/cocoa/AudioOutputUnitAdaptor.cpp	2020-10-29 00:51:55 UTC (rev 269133)
+++ trunk/Source/WebCore/platform/audio/cocoa/AudioOutputUnitAdaptor.cpp	2020-10-29 02:40:31 UTC (rev 269134)
@@ -44,7 +44,10 @@
 
 OSStatus AudioOutputUnitAdaptor::start()
 {
-    return AudioOutputUnitStart(m_outputUnit);
+    auto result = AudioOutputUnitStart(m_outputUnit);
+    if (result != noErr)
+        WTFLogAlways("ERROR: AudioOutputUnitStart() call failed with error code: %ld", static_cast<long>(result));
+    return result;
 }
 
 OSStatus AudioOutputUnitAdaptor::stop()

Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (269133 => 269134)


--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm	2020-10-29 00:51:55 UTC (rev 269133)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm	2020-10-29 02:40:31 UTC (rev 269134)
@@ -152,6 +152,8 @@
     session.setShouldPlayToPlaybackTarget(m_playbackTargetSupportsAirPlayVideo);
 #endif
 
+    providePresentingApplicationPIDIfNecessary();
+
     return true;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to