⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 269134 in webkit


Ignore:
Timestamp:
Oct 28, 2020, 7:40:31 PM (6 years ago)
Author:
Chris Dumez
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):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r269124 r269134  
     12020-10-28  Chris Dumez  <cdumez@apple.com>
     2
     3        Web Audio broken on iOS 14 after switching app
     4        https://bugs.webkit.org/show_bug.cgi?id=217606
     5        <rdar://problem/70231769>
     6
     7        Reviewed by Eric Carlson.
     8
     9        When we call AudioOutputUnitStart(), AVFoundation checks if we are allowed to play by
     10        making sure that our application is foreground. In order to do that, AVFoundation
     11        needs the PID of our hosting application. We provide this PID whenever the following
     12        function is called:
     13        MediaSessionManageriOS::providePresentingApplicationPIDIfNecessary()
     14
     15        The issue was that we were not calling providePresentingApplicationPIDIfNecessary()
     16        before starting WebAudio playback. As a result, AVFoundation was relying on the
     17        visibility of the WebContent process itself. This was causing a race because
     18        RunningBoard gets notified that the WebContent process is visible a little later
     19        than for the UIProcess. When the UIProcess would become foreground, we would send
     20        the SetApplicationState IPC to the WebProcess, which would update the page's
     21        visibility and cause us to stop the media session interruption. This would cause
     22        us to call AudioOutputUnitStart(), which would fail because AVFoundation would
     23        ask RunningBoard if the WebContent process is foreground. At this point,
     24        RunningBoard would not necessarily know yet that the WebContent process is
     25        visible. However, RunningBoard reliably knows the UIProcess is visible at this
     26        point.
     27
     28        We now call this function inside MediaSessionManageriOS::sessionWillBeginPlayback()
     29        since this gets called by WebAudio code before starting the playback.
     30
     31        * platform/audio/cocoa/AudioOutputUnitAdaptor.cpp:
     32        (WebCore::AudioOutputUnitAdaptor::start):
     33        Add some error logging when the call to AudioOutputUnitStart() fails to facilitate
     34        debugging such issues in the future.
     35
     36        * platform/audio/ios/MediaSessionManagerIOS.mm:
     37        (WebCore::MediaSessionManageriOS::sessionWillBeginPlayback):
     38
    1392020-10-28  Conrad Shultz  <conrad_shultz@apple.com>
    240
  • trunk/Source/WebCore/platform/audio/cocoa/AudioOutputUnitAdaptor.cpp

    r268632 r269134  
    4545OSStatus AudioOutputUnitAdaptor::start()
    4646{
    47     return AudioOutputUnitStart(m_outputUnit);
     47    auto result = AudioOutputUnitStart(m_outputUnit);
     48    if (result != noErr)
     49        WTFLogAlways("ERROR: AudioOutputUnitStart() call failed with error code: %ld", static_cast<long>(result));
     50    return result;
    4851}
    4952
  • trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm

    r267198 r269134  
    153153#endif
    154154
     155    providePresentingApplicationPIDIfNecessary();
     156
    155157    return true;
    156158}
Note: See TracChangeset for help on using the changeset viewer.