Title: [289297] branches/safari-613-branch
Revision
289297
Author
[email protected]
Date
2022-02-07 18:54:50 -0800 (Mon, 07 Feb 2022)

Log Message

Cherry-pick r288466. rdar://problem/82554226

    REGRESSION (iOS 15): HTMLAudioElement fails to load new audio when device is locked or safari is in background
    https://bugs.webkit.org/show_bug.cgi?id=229688
    <rdar://problem/82554226>

    Reviewed by Jer Noble.
    Source/WebCore:

    An iOS application loses its NowPlaying status as soon as the AudioSession category
    is set to Ambient, and it can only get it back again by changing the category
    to Playback *and* starting playback. When an application is in the background, however,
    it can't start playback unless it *already* has NowPlaying status. So, ipso facto,
    background playback will always fail once the category is set to Ambient.

    If an AudioSession's category is set to Playback when it is activated, it will
    interrupt another application playing audio, activate Bluetooth routes, etc.
    This means WebKit has to relinquish Playback when a page is unable to produce audio
    because AVFoundation automatically activates the audio session when playback starts
    - even if the AVPlayer is muted or has no audio.

    To allow pages that were playing audio when WebKit went into the background to
    continue to play after switching urls or activating another media element, add a
    grace period when switch from Playback to Ambient.

    Test: media/audio-session-category.html

    * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
    (WebCore::MediaSessionManagerCocoa::updateSessionState):

    Source/WebKit:

    * WebProcess/GPU/media/RemoteAudioSession.cpp:
    (WebKit::RemoteAudioSession::category const): Return the most recently set category
    on all platforms so it is possible to test.

    LayoutTests:

    * fast/mediasession/metadata/audio-track-enabled.html: Wait longer for the audio session
    category to be reset.
    * media/audio-session-category-expected.txt: Added.
    * media/audio-session-category.html: Added.
    * platform/gtk/TestExpectations: Skip new test.
    * platform/mac-wk1/TestExpectations: Skip new test, MediaStream isn't supported
    on WK1.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288466 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (289296 => 289297)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-02-08 02:54:50 UTC (rev 289297)
@@ -1,5 +1,72 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288466. rdar://problem/82554226
+
+    REGRESSION (iOS 15): HTMLAudioElement fails to load new audio when device is locked or safari is in background
+    https://bugs.webkit.org/show_bug.cgi?id=229688
+    <rdar://problem/82554226>
+    
+    Reviewed by Jer Noble.
+    Source/WebCore:
+    
+    An iOS application loses its NowPlaying status as soon as the AudioSession category
+    is set to Ambient, and it can only get it back again by changing the category
+    to Playback *and* starting playback. When an application is in the background, however,
+    it can't start playback unless it *already* has NowPlaying status. So, ipso facto,
+    background playback will always fail once the category is set to Ambient.
+    
+    If an AudioSession's category is set to Playback when it is activated, it will
+    interrupt another application playing audio, activate Bluetooth routes, etc.
+    This means WebKit has to relinquish Playback when a page is unable to produce audio
+    because AVFoundation automatically activates the audio session when playback starts
+    - even if the AVPlayer is muted or has no audio.
+    
+    To allow pages that were playing audio when WebKit went into the background to
+    continue to play after switching urls or activating another media element, add a
+    grace period when switch from Playback to Ambient.
+    
+    Test: media/audio-session-category.html
+    
+    * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+    (WebCore::MediaSessionManagerCocoa::updateSessionState):
+    
+    Source/WebKit:
+    
+    * WebProcess/GPU/media/RemoteAudioSession.cpp:
+    (WebKit::RemoteAudioSession::category const): Return the most recently set category
+    on all platforms so it is possible to test.
+    
+    LayoutTests:
+    
+    * fast/mediasession/metadata/audio-track-enabled.html: Wait longer for the audio session
+    category to be reset.
+    * media/audio-session-category-expected.txt: Added.
+    * media/audio-session-category.html: Added.
+    * platform/gtk/TestExpectations: Skip new test.
+    * platform/mac-wk1/TestExpectations: Skip new test, MediaStream isn't supported
+    on WK1.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288466 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-24  Eric Carlson  <[email protected]>
+
+            REGRESSION (iOS 15): HTMLAudioElement fails to load new audio when device is locked or safari is in background
+            https://bugs.webkit.org/show_bug.cgi?id=229688
+            <rdar://problem/82554226>
+
+            Reviewed by Jer Noble.
+
+            * fast/mediasession/metadata/audio-track-enabled.html: Wait longer for the audio session
+            category to be reset.
+            * media/audio-session-category-expected.txt: Added.
+            * media/audio-session-category.html: Added.
+            * platform/gtk/TestExpectations: Skip new test.
+            * platform/mac-wk1/TestExpectations: Skip new test, MediaStream isn't supported
+            on WK1.
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288362. rdar://problem/87832940
 
     WPT version of css/css-cascade/parsing/layer-import-parsing.html crashes with nullptr

Modified: branches/safari-613-branch/LayoutTests/fast/mediastream/audio-track-enabled.html (289296 => 289297)


--- branches/safari-613-branch/LayoutTests/fast/mediastream/audio-track-enabled.html	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/LayoutTests/fast/mediastream/audio-track-enabled.html	2022-02-08 02:54:50 UTC (rev 289297)
@@ -32,10 +32,10 @@
     assert_equals(internals.audioSessionCategory(), "PlayAndRecord");
 
     audioTrack.stop();
-    const maxTries = 100;
+    const maxTries = 300;
     let counter = 0;
     while (++counter < maxTries) {
-        if (internals.audioSessionCategory() != "PlayAndRecord")
+        if (internals.audioSessionCategory() == defaultCategory)
             break;
         await new Promise(resolve => setTimeout(resolve, 10));
     }

Added: branches/safari-613-branch/LayoutTests/media/audio-session-category-expected.txt (0 => 289297)


--- branches/safari-613-branch/LayoutTests/media/audio-session-category-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/media/audio-session-category-expected.txt	2022-02-08 02:54:50 UTC (rev 289297)
@@ -0,0 +1,72 @@
+
+
+
+** <audio> element test **
+
+** Check category before anything has loaded.
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+
+** Check category when a muted, paused, element has loaded.
+EVENT(canplaythrough)
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+
+** Check category when a muted element is playing.
+RUN(video.play())
+EVENT(playing)
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+
+** Check category when an unmuted element is playing.
+RUN(video.muted = false)
+EVENT(volumechange)
+EXPECTED (internals.audioSessionCategory() == 'MediaPlayback') OK
+
+** Mute the element, check again after 500ms.
+RUN(video.pause())
+RUN(video.muted = true)
+EXPECTED (internals.audioSessionCategory() == 'MediaPlayback') OK
+
+** And check again after 3 seconds.
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+
+
+** AudioContext test **
+
+** Check category before creating AudioContext.
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+
+** Check category after oscillator graph has been connected but not started.
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+
+** Check category after starting oscillator.
+EXPECTED (internals.audioSessionCategory() == 'AmbientSound') OK
+
+** Close the context, check again after 500ms.
+EXPECTED (internals.audioSessionCategory() == 'AmbientSound') OK
+
+** And check again after 3 seconds.
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+
+
+** MediaStream test **
+
+** Check category before capture begins.
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+
+** Check category when capturing.
+EXPECTED (internals.audioSessionCategory() == 'PlayAndRecord') OK
+
+** Check after MediaStream is attached to audio element.
+RUN(video.play())
+EVENT(playing)
+EXPECTED (internals.audioSessionCategory() == 'PlayAndRecord') OK
+
+** Check after MediaStream muting audio track.
+EXPECTED (internals.audioSessionCategory() == 'PlayAndRecord') OK
+
+** Check 500ms after MediaStream stopping capture.
+EXPECTED (internals.audioSessionCategory() == 'PlayAndRecord') OK
+
+** And check again after 3 seconds.
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+END OF TEST
+

Added: branches/safari-613-branch/LayoutTests/media/audio-session-category.html (0 => 289297)


--- branches/safari-613-branch/LayoutTests/media/audio-session-category.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/media/audio-session-category.html	2022-02-08 02:54:50 UTC (rev 289297)
@@ -0,0 +1,142 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>audio-session-category</title>
+    <script src=''></script>
+    <script src=''></script>
+    <script>
+
+        async function waitForCategory(category, duration, message)
+        {
+            consoleWrite(message);
+
+            const maxTries = duration * 1000 / 10;
+            let counter = 0;
+            while (++counter < maxTries) {
+                if (internals.audioSessionCategory() == category)
+                    break;
+                await new Promise(resolve => setTimeout(resolve, 10));
+            }
+
+            testExpected('internals.audioSessionCategory()', category);
+        }
+        
+        async function testAudioElement()
+        {
+            consoleWrite('<br><br>** &lt;audio> element test **');
+            await waitForCategory('None', 10, '<br>** Check category before anything has loaded.');
+
+            consoleWrite('<br>** Check category when a muted, paused, element has loaded.');
+            video.src = "" 'content/test');
+
+            await waitFor(video, 'canplaythrough');
+            testExpected('internals.audioSessionCategory()', 'None');
+
+            consoleWrite('<br>** Check category when a muted element is playing.');
+            runWithKeyDown(() => { run('video.play()') });
+            await waitFor(video, 'playing');
+            testExpected('internals.audioSessionCategory()', 'None');
+
+            consoleWrite('<br>** Check category when an unmuted element is playing.');
+            runWithKeyDown(() => { run('video.muted = false') });
+            await waitFor(video, 'volumechange');
+            testExpected('internals.audioSessionCategory()', 'MediaPlayback');
+
+            consoleWrite('<br>** Mute the element, check again after 500ms.');
+            run('video.pause()');
+            runWithKeyDown(() => { run('video.muted = true') });
+            await sleepFor(500);
+            testExpected('internals.audioSessionCategory()', 'MediaPlayback');
+
+            await waitForCategory('None', 3, '<br>** And check again after 3 seconds.');
+            video.src = '';
+            video.load();
+        }
+
+        async function testWebAudio()
+        {
+            consoleWrite('<br><br>** AudioContext test **');
+            await waitForCategory('None', 10, '<br>** Check category before creating AudioContext.');
+
+            consoleWrite('<br>** Check category after oscillator graph has been connected but not started.');
+            let context = new AudioContext();
+            let oscillator = null;
+            let gainNode = context.createGain();
+
+            oscillator = context.createOscillator();
+            oscillator.type = 'square';
+            oscillator.frequency.setValueAtTime(440, context.currentTime);
+
+            oscillator.connect(gainNode);
+            gainNode.connect(context.destination);
+            gainNode.gain.value = 0.1
+            testExpected('internals.audioSessionCategory()', 'None');
+
+            consoleWrite('<br>** Check category after starting oscillator.');
+            oscillator.start(0);
+            await sleepFor(500);
+            testExpected('internals.audioSessionCategory()', 'AmbientSound');
+
+            consoleWrite('<br>** Close the context, check again after 500ms.');
+            await context.close();
+            await sleepFor(500);
+            testExpected('internals.audioSessionCategory()', 'AmbientSound');
+
+            await waitForCategory('None', 3, '<br>** And check again after 3 seconds.');
+        }
+        
+        async function testMediaStream()
+        {
+            consoleWrite('<br><br>** MediaStream test **');
+            await waitForCategory('None', 10, '<br>** Check category before capture begins.');
+
+            consoleWrite('<br>** Check category when capturing.');
+            let stream = await navigator.mediaDevices.getUserMedia({audio : true});
+            testExpected('internals.audioSessionCategory()', 'PlayAndRecord');
+
+            consoleWrite('<br>** Check after MediaStream is attached to audio element.');
+            video.srcObject = stream;
+            runWithKeyDown(() => { run('video.play()') });
+            await waitFor(video, 'playing');
+            testExpected('internals.audioSessionCategory()', 'PlayAndRecord');
+
+            consoleWrite('<br>** Check after MediaStream muting audio track.');
+            const audioTrack = stream.getAudioTracks()[0];
+            audioTrack.enabled = false;
+            await sleepFor(500);
+            testExpected('internals.audioSessionCategory()', 'PlayAndRecord');
+
+            consoleWrite('<br>** Check 500ms after MediaStream stopping capture.');
+            audioTrack.stop();
+            await sleepFor(500);
+            testExpected('internals.audioSessionCategory()', 'PlayAndRecord');
+
+            await waitForCategory('None', 3, '<br>** And check again after 3 seconds.');
+            video.src = '';
+            video.load();
+        }
+
+
+        window.addEventListener('load', async event => {
+            if (!window.internals) {
+                failTest(`<br>This test requires internals!`);
+                return;
+            }
+
+            internals.settings.setShouldManageAudioSessionCategory(true);
+
+            video = document.getElementsByTagName('audio')[0];
+
+            failTestIn(20000);
+            await testAudioElement();
+            await testWebAudio();
+            await testMediaStream();
+
+            endTest();
+        });
+    </script>
+</head>
+<body>
+    <audio muted controls></audio>
+</body>
+</html>
\ No newline at end of file

Modified: branches/safari-613-branch/LayoutTests/platform/gtk/TestExpectations (289296 => 289297)


--- branches/safari-613-branch/LayoutTests/platform/gtk/TestExpectations	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/LayoutTests/platform/gtk/TestExpectations	2022-02-08 02:54:50 UTC (rev 289297)
@@ -1010,6 +1010,9 @@
 # End of Crashing tests
 #////////////////////////////////////////////////////////////////////////////////////////
 
+# Tests behavior specific to MediaSessionManagerCocoa
+media/audio-session-category.html [ Skip ]
+
 #////////////////////////////////////////////////////////////////////////////////////////
 # 4. FLAKY TESTS
 #////////////////////////////////////////////////////////////////////////////////////////

Modified: branches/safari-613-branch/LayoutTests/platform/mac-wk1/TestExpectations (289296 => 289297)


--- branches/safari-613-branch/LayoutTests/platform/mac-wk1/TestExpectations	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/LayoutTests/platform/mac-wk1/TestExpectations	2022-02-08 02:54:50 UTC (rev 289297)
@@ -64,6 +64,7 @@
 inspector/page/overrideSetting-MockCaptureDevicesEnabled.html [ Skip ]
 http/tests/navigation/page-cache-getUserMedia-pending-promise.html [ Skip ]
 http/tests/navigation/page-cache-mediastream.html [ Skip ]
+media/audio-session-category.html [ Skip ]
 
 http/wpt/mediarecorder [ Skip ]
 imported/w3c/web-platform-tests/mediacapture-record [ Skip ]

Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (289296 => 289297)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-02-08 02:54:50 UTC (rev 289297)
@@ -1,5 +1,85 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288466. rdar://problem/82554226
+
+    REGRESSION (iOS 15): HTMLAudioElement fails to load new audio when device is locked or safari is in background
+    https://bugs.webkit.org/show_bug.cgi?id=229688
+    <rdar://problem/82554226>
+    
+    Reviewed by Jer Noble.
+    Source/WebCore:
+    
+    An iOS application loses its NowPlaying status as soon as the AudioSession category
+    is set to Ambient, and it can only get it back again by changing the category
+    to Playback *and* starting playback. When an application is in the background, however,
+    it can't start playback unless it *already* has NowPlaying status. So, ipso facto,
+    background playback will always fail once the category is set to Ambient.
+    
+    If an AudioSession's category is set to Playback when it is activated, it will
+    interrupt another application playing audio, activate Bluetooth routes, etc.
+    This means WebKit has to relinquish Playback when a page is unable to produce audio
+    because AVFoundation automatically activates the audio session when playback starts
+    - even if the AVPlayer is muted or has no audio.
+    
+    To allow pages that were playing audio when WebKit went into the background to
+    continue to play after switching urls or activating another media element, add a
+    grace period when switch from Playback to Ambient.
+    
+    Test: media/audio-session-category.html
+    
+    * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+    (WebCore::MediaSessionManagerCocoa::updateSessionState):
+    
+    Source/WebKit:
+    
+    * WebProcess/GPU/media/RemoteAudioSession.cpp:
+    (WebKit::RemoteAudioSession::category const): Return the most recently set category
+    on all platforms so it is possible to test.
+    
+    LayoutTests:
+    
+    * fast/mediasession/metadata/audio-track-enabled.html: Wait longer for the audio session
+    category to be reset.
+    * media/audio-session-category-expected.txt: Added.
+    * media/audio-session-category.html: Added.
+    * platform/gtk/TestExpectations: Skip new test.
+    * platform/mac-wk1/TestExpectations: Skip new test, MediaStream isn't supported
+    on WK1.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288466 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-24  Eric Carlson  <[email protected]>
+
+            REGRESSION (iOS 15): HTMLAudioElement fails to load new audio when device is locked or safari is in background
+            https://bugs.webkit.org/show_bug.cgi?id=229688
+            <rdar://problem/82554226>
+
+            Reviewed by Jer Noble.
+
+            An iOS application loses its NowPlaying status as soon as the AudioSession category
+            is set to Ambient, and it can only get it back again by changing the category
+            to Playback *and* starting playback. When an application is in the background, however,
+            it can't start playback unless it *already* has NowPlaying status. So, ipso facto,
+            background playback will always fail once the category is set to Ambient.
+
+            If an AudioSession's category is set to Playback when it is activated, it will
+            interrupt another application playing audio, activate Bluetooth routes, etc.
+            This means WebKit has to relinquish Playback when a page is unable to produce audio
+            because AVFoundation automatically activates the audio session when playback starts
+            - even if the AVPlayer is muted or has no audio.
+
+            To allow pages that were playing audio when WebKit went into the background to
+            continue to play after switching urls or activating another media element, add a
+            grace period when switch from Playback to Ambient.
+
+            Test: media/audio-session-category.html
+
+            * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+            (WebCore::MediaSessionManagerCocoa::updateSessionState):
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288463. rdar://problem/87977499
 
     file.stream() is slow and CPU-bound

Modified: branches/safari-613-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h (289296 => 289297)


--- branches/safari-613-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h	2022-02-08 02:54:50 UTC (rev 289297)
@@ -28,9 +28,11 @@
 #if PLATFORM(COCOA)
 
 #include "AudioHardwareListener.h"
+#include "AudioSession.h"
 #include "NowPlayingManager.h"
 #include "PlatformMediaSessionManager.h"
 #include "RemoteCommandListener.h"
+#include <wtf/RunLoop.h>
 
 namespace WebCore {
 
@@ -106,6 +108,8 @@
     void audioHardwareDidBecomeInactive() final { }
     void audioOutputDeviceChanged() final;
 
+    void possiblyChangeAudioCategory();
+
     bool m_nowPlayingActive { false };
     bool m_registeredAsNowPlayingApplication { false };
     bool m_haveEverRegisteredAsNowPlayingApplication { false };
@@ -121,6 +125,10 @@
 
     AudioHardwareListener::BufferSizeRange m_supportedAudioHardwareBufferSizes;
     size_t m_defaultBufferSize;
+
+    RunLoop::Timer<MediaSessionManagerCocoa> m_delayCategoryChangeTimer;
+    AudioSession::CategoryType m_previousCategory { AudioSession::CategoryType::None };
+    bool m_previousHadAudibleAudioOrVideoMediaType { false };
 };
 
 }

Modified: branches/safari-613-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm (289296 => 289297)


--- branches/safari-613-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2022-02-08 02:54:50 UTC (rev 289297)
@@ -28,7 +28,6 @@
 
 #if USE(AUDIO_SESSION) && PLATFORM(COCOA)
 
-#import "AudioSession.h"
 #import "AudioUtilities.h"
 #import "DeprecatedGlobalSettings.h"
 #import "HTMLMediaElement.h"
@@ -60,6 +59,7 @@
 MediaSessionManagerCocoa::MediaSessionManagerCocoa()
     : m_nowPlayingManager(platformStrategies()->mediaStrategy().createNowPlayingManager())
     , m_defaultBufferSize(AudioSession::sharedSession().preferredBufferSize())
+    , m_delayCategoryChangeTimer(RunLoop::main(), this, &MediaSessionManagerCocoa::possiblyChangeAudioCategory)
 {
     ensureCodecsRegistered();
 }
@@ -94,6 +94,7 @@
 
 void MediaSessionManagerCocoa::updateSessionState()
 {
+    static const Seconds delayBeforeSettingCategoryNone = { 2_s };
     int videoCount = 0;
     int videoAudioCount = 0;
     int audioCount = 0;
@@ -164,10 +165,28 @@
     } else if (webAudioCount)
         category = AudioSession::CategoryType::AmbientSound;
 
+    if (category == AudioSession::CategoryType::None && m_previousCategory != AudioSession::CategoryType::None) {
+        if (!m_delayCategoryChangeTimer.isActive()) {
+            m_delayCategoryChangeTimer.startOneShot(delayBeforeSettingCategoryNone);
+            ALWAYS_LOG(LOGIDENTIFIER, "setting timer");
+        }
+        category = m_previousCategory;
+    } else
+        m_delayCategoryChangeTimer.stop();
+
+    m_previousCategory = category;
+
     ALWAYS_LOG(LOGIDENTIFIER, "setting category = ", category, ", policy = ", policy);
     AudioSession::sharedSession().setCategory(category, policy);
 }
 
+void MediaSessionManagerCocoa::possiblyChangeAudioCategory()
+{
+    ALWAYS_LOG(LOGIDENTIFIER);
+    m_previousCategory = AudioSession::CategoryType::None;
+    updateSessionState();
+}
+
 void MediaSessionManagerCocoa::beginInterruption(PlatformMediaSession::InterruptionType type)
 {
     if (type == PlatformMediaSession::InterruptionType::SystemInterruption) {

Modified: branches/safari-613-branch/Source/WebKit/ChangeLog (289296 => 289297)


--- branches/safari-613-branch/Source/WebKit/ChangeLog	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog	2022-02-08 02:54:50 UTC (rev 289297)
@@ -1,5 +1,68 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288466. rdar://problem/82554226
+
+    REGRESSION (iOS 15): HTMLAudioElement fails to load new audio when device is locked or safari is in background
+    https://bugs.webkit.org/show_bug.cgi?id=229688
+    <rdar://problem/82554226>
+    
+    Reviewed by Jer Noble.
+    Source/WebCore:
+    
+    An iOS application loses its NowPlaying status as soon as the AudioSession category
+    is set to Ambient, and it can only get it back again by changing the category
+    to Playback *and* starting playback. When an application is in the background, however,
+    it can't start playback unless it *already* has NowPlaying status. So, ipso facto,
+    background playback will always fail once the category is set to Ambient.
+    
+    If an AudioSession's category is set to Playback when it is activated, it will
+    interrupt another application playing audio, activate Bluetooth routes, etc.
+    This means WebKit has to relinquish Playback when a page is unable to produce audio
+    because AVFoundation automatically activates the audio session when playback starts
+    - even if the AVPlayer is muted or has no audio.
+    
+    To allow pages that were playing audio when WebKit went into the background to
+    continue to play after switching urls or activating another media element, add a
+    grace period when switch from Playback to Ambient.
+    
+    Test: media/audio-session-category.html
+    
+    * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+    (WebCore::MediaSessionManagerCocoa::updateSessionState):
+    
+    Source/WebKit:
+    
+    * WebProcess/GPU/media/RemoteAudioSession.cpp:
+    (WebKit::RemoteAudioSession::category const): Return the most recently set category
+    on all platforms so it is possible to test.
+    
+    LayoutTests:
+    
+    * fast/mediasession/metadata/audio-track-enabled.html: Wait longer for the audio session
+    category to be reset.
+    * media/audio-session-category-expected.txt: Added.
+    * media/audio-session-category.html: Added.
+    * platform/gtk/TestExpectations: Skip new test.
+    * platform/mac-wk1/TestExpectations: Skip new test, MediaStream isn't supported
+    on WK1.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288466 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-24  Eric Carlson  <[email protected]>
+
+            REGRESSION (iOS 15): HTMLAudioElement fails to load new audio when device is locked or safari is in background
+            https://bugs.webkit.org/show_bug.cgi?id=229688
+            <rdar://problem/82554226>
+
+            Reviewed by Jer Noble.
+
+            * WebProcess/GPU/media/RemoteAudioSession.cpp:
+            (WebKit::RemoteAudioSession::category const): Return the most recently set category
+            on all platforms so it is possible to test.
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288387. rdar://problem/87468788
 
     Inject Launch Services database before NSApplication is initialized

Modified: branches/safari-613-branch/Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.cpp (289296 => 289297)


--- branches/safari-613-branch/Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.cpp	2022-02-08 02:54:45 UTC (rev 289296)
+++ branches/safari-613-branch/Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.cpp	2022-02-08 02:54:50 UTC (rev 289297)
@@ -141,11 +141,7 @@
 
 AudioSession::CategoryType RemoteAudioSession::category() const
 {
-#if PLATFORM(COCOA)
     return m_category;
-#else
-    return AudioSession::CategoryType::None;
-#endif
 }
 
 void RemoteAudioSession::configurationChanged(RemoteAudioSessionConfiguration&& configuration)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to