Title: [293530] trunk
Revision
293530
Author
eric.carl...@apple.com
Date
2022-04-27 13:18:06 -0700 (Wed, 27 Apr 2022)

Log Message

[iOS] unable to start playing audio when device is locked
https://bugs.webkit.org/show_bug.cgi?id=239812
<rdar://90642648>

Reviewed by Jer Noble.

Source/WebCore:

Updated media/audio-session-category.html.

* platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(WebCore::MediaSessionManagerCocoa::updateSessionState): Choose the appropriate
route sharing policy after choosing the audio session category because
setting MediaPlayback+Default makes a process ineligible for NowPlaying, and starting
playback in the background will be blocked.

* platform/audio/mac/AudioSessionMac.h:
* platform/audio/mac/AudioSessionMac.mm:
(WebCore::AudioSessionMac::setCategory): Updated for testing.

* testing/Internals.cpp:
(WebCore::Internals::routeSharingPolicy const): Added accessor for testing.
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* media/audio-session-category-expected.txt:
* media/audio-session-category.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (293529 => 293530)


--- trunk/LayoutTests/ChangeLog	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/LayoutTests/ChangeLog	2022-04-27 20:18:06 UTC (rev 293530)
@@ -1,3 +1,14 @@
+2022-04-27  Eric Carlson  <eric.carl...@apple.com>
+
+        [iOS] unable to start playing audio when device is locked
+        https://bugs.webkit.org/show_bug.cgi?id=239812
+        <rdar://90642648>
+
+        Reviewed by Jer Noble.
+
+        * media/audio-session-category-expected.txt:
+        * media/audio-session-category.html:
+
 2022-04-27  Karl Rackler  <rack...@apple.com>
 
         [ macOS Debug wk2 ] fast/css/identical-logical-height-decl.html is a flaky image failure

Modified: trunk/LayoutTests/media/audio-session-category-expected.txt (293529 => 293530)


--- trunk/LayoutTests/media/audio-session-category-expected.txt	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/LayoutTests/media/audio-session-category-expected.txt	2022-04-27 20:18:06 UTC (rev 293530)
@@ -14,19 +14,23 @@
 RUN(video.play())
 EVENT(playing)
 EXPECTED (internals.audioSessionCategory() == 'None') OK
+EXPECTED (internals.routeSharingPolicy() == 'Default') OK
 
 ** Check category when an unmuted element is playing.
 RUN(video.muted = false)
 EVENT(volumechange)
 EXPECTED (internals.audioSessionCategory() == 'MediaPlayback') OK
+EXPECTED (internals.routeSharingPolicy() == 'LongFormAudio') OK
 
 ** Mute the element, check again after 500ms.
 RUN(video.pause())
 RUN(video.muted = true)
 EXPECTED (internals.audioSessionCategory() == 'MediaPlayback') OK
+EXPECTED (internals.routeSharingPolicy() == 'LongFormAudio') OK
 
 ** And check again after 3 seconds.
 EXPECTED (internals.audioSessionCategory() == 'None') OK
+EXPECTED (internals.routeSharingPolicy() == 'Default') OK
 
 
 ** AudioContext test **
@@ -39,12 +43,15 @@
 
 ** Check category after starting oscillator.
 EXPECTED (internals.audioSessionCategory() == 'AmbientSound') OK
+EXPECTED (internals.routeSharingPolicy() == 'Default') OK
 
 ** Close the context, check again after 500ms.
 EXPECTED (internals.audioSessionCategory() == 'AmbientSound') OK
+EXPECTED (internals.routeSharingPolicy() == 'Default') OK
 
 ** And check again after 3 seconds.
 EXPECTED (internals.audioSessionCategory() == 'None') OK
+EXPECTED (internals.routeSharingPolicy() == 'Default') OK
 
 
 ** MediaStream test **
@@ -54,11 +61,13 @@
 
 ** Check category when capturing.
 EXPECTED (internals.audioSessionCategory() == 'PlayAndRecord') OK
+EXPECTED (internals.routeSharingPolicy() == 'Default') OK
 
 ** Check after MediaStream is attached to audio element.
 RUN(video.play())
 EVENT(playing)
 EXPECTED (internals.audioSessionCategory() == 'PlayAndRecord') OK
+EXPECTED (internals.routeSharingPolicy() == 'Default') OK
 
 ** Check after MediaStream muting audio track.
 EXPECTED (internals.audioSessionCategory() == 'PlayAndRecord') OK

Modified: trunk/LayoutTests/media/audio-session-category.html (293529 => 293530)


--- trunk/LayoutTests/media/audio-session-category.html	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/LayoutTests/media/audio-session-category.html	2022-04-27 20:18:06 UTC (rev 293530)
@@ -36,11 +36,13 @@
             runWithKeyDown(() => { run('video.play()') });
             await waitFor(video, 'playing');
             testExpected('internals.audioSessionCategory()', 'None');
-
+            testExpected('internals.routeSharingPolicy()', 'Default');
+            
             consoleWrite('<br>** Check category when an unmuted element is playing.');
             runWithKeyDown(() => { run('video.muted = false') });
             await waitFor(video, 'volumechange');
             testExpected('internals.audioSessionCategory()', 'MediaPlayback');
+            testExpected('internals.routeSharingPolicy()', 'LongFormAudio');
 
             consoleWrite('<br>** Mute the element, check again after 500ms.');
             run('video.pause()');
@@ -47,8 +49,11 @@
             runWithKeyDown(() => { run('video.muted = true') });
             await sleepFor(500);
             testExpected('internals.audioSessionCategory()', 'MediaPlayback');
+            testExpected('internals.routeSharingPolicy()', 'LongFormAudio');
 
             await waitForCategory('None', 3, '<br>** And check again after 3 seconds.');
+            testExpected('internals.routeSharingPolicy()', 'Default');
+
             video.src = '';
             video.load();
         }
@@ -77,13 +82,16 @@
             oscillator.start(0);
             await sleepFor(500);
             testExpected('internals.audioSessionCategory()', 'AmbientSound');
+            testExpected('internals.routeSharingPolicy()', 'Default');
 
             consoleWrite('<br>** Close the context, check again after 500ms.');
             await context.close();
             await sleepFor(500);
             testExpected('internals.audioSessionCategory()', 'AmbientSound');
+            testExpected('internals.routeSharingPolicy()', 'Default');
 
             await waitForCategory('None', 3, '<br>** And check again after 3 seconds.');
+            testExpected('internals.routeSharingPolicy()', 'Default');
         }
         
         async function testMediaStream()
@@ -94,6 +102,7 @@
             consoleWrite('<br>** Check category when capturing.');
             let stream = await navigator.mediaDevices.getUserMedia({audio : true});
             testExpected('internals.audioSessionCategory()', 'PlayAndRecord');
+            testExpected('internals.routeSharingPolicy()', 'Default');
 
             consoleWrite('<br>** Check after MediaStream is attached to audio element.');
             video.srcObject = stream;
@@ -100,6 +109,7 @@
             runWithKeyDown(() => { run('video.play()') });
             await waitFor(video, 'playing');
             testExpected('internals.audioSessionCategory()', 'PlayAndRecord');
+            testExpected('internals.routeSharingPolicy()', 'Default');
 
             consoleWrite('<br>** Check after MediaStream muting audio track.');
             const audioTrack = stream.getAudioTracks()[0];

Modified: trunk/Source/WebCore/ChangeLog (293529 => 293530)


--- trunk/Source/WebCore/ChangeLog	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/Source/WebCore/ChangeLog	2022-04-27 20:18:06 UTC (rev 293530)
@@ -1,3 +1,28 @@
+2022-04-27  Eric Carlson  <eric.carl...@apple.com>
+
+        [iOS] unable to start playing audio when device is locked
+        https://bugs.webkit.org/show_bug.cgi?id=239812
+        <rdar://90642648>
+
+        Reviewed by Jer Noble.
+
+        Updated media/audio-session-category.html.
+
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+        (WebCore::MediaSessionManagerCocoa::updateSessionState): Choose the appropriate
+        route sharing policy after choosing the audio session category because 
+        setting MediaPlayback+Default makes a process ineligible for NowPlaying, and starting
+        playback in the background will be blocked.
+
+        * platform/audio/mac/AudioSessionMac.h:
+        * platform/audio/mac/AudioSessionMac.mm:
+        (WebCore::AudioSessionMac::setCategory): Updated for testing.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::routeSharingPolicy const): Added accessor for testing.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2022-04-27  Tim Nguyen  <n...@apple.com>
 
         Make -webkit-transform-style an alias of transform-style

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


--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2022-04-27 20:18:06 UTC (rev 293530)
@@ -178,14 +178,12 @@
     if (!DeprecatedGlobalSettings::shouldManageAudioSessionCategory())
         return;
 
-    RouteSharingPolicy policy = RouteSharingPolicy::Default;
     auto category = AudioSession::CategoryType::None;
     if (captureCount || (isPlayingAudio && AudioSession::sharedSession().category() == AudioSession::CategoryType::PlayAndRecord))
         category = AudioSession::CategoryType::PlayAndRecord;
-    else if (hasAudibleAudioOrVideoMediaType) {
+    else if (hasAudibleAudioOrVideoMediaType)
         category = AudioSession::CategoryType::MediaPlayback;
-        policy = RouteSharingPolicy::LongFormAudio;
-    } else if (webAudioCount)
+    else if (webAudioCount)
         category = AudioSession::CategoryType::AmbientSound;
 
     if (category == AudioSession::CategoryType::None && m_previousCategory != AudioSession::CategoryType::None) {
@@ -197,9 +195,11 @@
     } else
         m_delayCategoryChangeTimer.stop();
 
+    RouteSharingPolicy policy = (category == AudioSession::CategoryType::MediaPlayback) ? RouteSharingPolicy::LongFormAudio : RouteSharingPolicy::Default;
+
+    ALWAYS_LOG(LOGIDENTIFIER, "setting category = ", category, ", policy = ", policy, ", previous category = ", m_previousCategory);
+
     m_previousCategory = category;
-
-    ALWAYS_LOG(LOGIDENTIFIER, "setting category = ", category, ", policy = ", policy);
     AudioSession::sharedSession().setCategory(category, policy);
 }
 

Modified: trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.h (293529 => 293530)


--- trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.h	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.h	2022-04-27 20:18:06 UTC (rev 293530)
@@ -50,6 +50,7 @@
 
     // AudioSession
     CategoryType category() const final { return m_category; }
+    RouteSharingPolicy routeSharingPolicy() const { return m_policy; }
     void audioOutputDeviceChanged() final;
     void setIsPlayingToBluetoothOverride(std::optional<bool>) final;
     void setCategory(CategoryType, RouteSharingPolicy) final;
@@ -58,7 +59,6 @@
     size_t numberOfOutputChannels() const final;
     size_t maximumNumberOfOutputChannels() const final;
     bool tryToSetActiveInternal(bool) final;
-    RouteSharingPolicy routeSharingPolicy() const final;
     String routingContextUID() const final;
     size_t preferredBufferSize() const final;
     void setPreferredBufferSize(size_t) final;
@@ -70,6 +70,7 @@
     std::optional<bool> m_lastMutedState;
     mutable WeakHashSet<ConfigurationChangeObserver> m_configurationChangeObservers;
     AudioSession::CategoryType m_category { AudioSession::CategoryType::None };
+    RouteSharingPolicy m_policy { RouteSharingPolicy::Default };
 #if ENABLE(ROUTING_ARBITRATION)
     bool m_setupArbitrationOngoing { false };
     bool m_inRoutingArbitration { false };

Modified: trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm (293529 => 293530)


--- trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm	2022-04-27 20:18:06 UTC (rev 293530)
@@ -209,7 +209,7 @@
 #endif
 }
 
-void AudioSessionMac::setCategory(CategoryType category, RouteSharingPolicy)
+void AudioSessionMac::setCategory(CategoryType category, RouteSharingPolicy policy)
 {
 #if ENABLE(ROUTING_ARBITRATION)
     bool playingToBluetooth = defaultDeviceTransportIsBluetooth();
@@ -217,6 +217,7 @@
         return;
 
     m_category = category;
+    m_policy = policy;
 
     if (m_setupArbitrationOngoing) {
         RELEASE_LOG_ERROR(Media, "AudioSessionMac::setCategory() - a beginArbitrationWithCategory is still ongoing");
@@ -254,6 +255,7 @@
     });
 #else
     m_category = category;
+    m_policy = policy;
 #endif
 }
 
@@ -368,11 +370,6 @@
     return true;
 }
 
-RouteSharingPolicy AudioSessionMac::routeSharingPolicy() const
-{
-    return RouteSharingPolicy::Default;
-}
-
 String AudioSessionMac::routingContextUID() const
 {
     return emptyString();

Modified: trunk/Source/WebCore/testing/Internals.cpp (293529 => 293530)


--- trunk/Source/WebCore/testing/Internals.cpp	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/Source/WebCore/testing/Internals.cpp	2022-04-27 20:18:06 UTC (rev 293530)
@@ -5683,6 +5683,15 @@
 #endif
 }
 
+auto Internals::routeSharingPolicy() const -> RouteSharingPolicy
+{
+#if USE(AUDIO_SESSION)
+    return AudioSession::sharedSession().routeSharingPolicy();
+#else
+    return RouteSharingPolicy::Default;
+#endif
+}
+
 #if ENABLE(VIDEO)
 auto Internals::categoryAtMostRecentPlayback(HTMLMediaElement& element) const -> AudioSessionCategory
 {

Modified: trunk/Source/WebCore/testing/Internals.h (293529 => 293530)


--- trunk/Source/WebCore/testing/Internals.h	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/Source/WebCore/testing/Internals.h	2022-04-27 20:18:06 UTC (rev 293530)
@@ -902,6 +902,7 @@
 
 #if USE(AUDIO_SESSION)
     using AudioSessionCategory = WebCore::AudioSessionCategory;
+    using RouteSharingPolicy = WebCore::RouteSharingPolicy;
 #else
     enum class AudioSessionCategory : uint8_t {
         None,
@@ -912,10 +913,18 @@
         PlayAndRecord,
         AudioProcessing,
     };
+
+    enum class RouteSharingPolicy : uint8_t {
+        Default,
+        LongFormAudio,
+        Independent,
+        LongFormVideo
+    };
 #endif
 
     bool supportsAudioSession() const;
     AudioSessionCategory audioSessionCategory() const;
+    RouteSharingPolicy routeSharingPolicy() const;
 #if ENABLE(VIDEO)
     AudioSessionCategory categoryAtMostRecentPlayback(HTMLMediaElement&) const;
 #endif

Modified: trunk/Source/WebCore/testing/Internals.idl (293529 => 293530)


--- trunk/Source/WebCore/testing/Internals.idl	2022-04-27 19:50:24 UTC (rev 293529)
+++ trunk/Source/WebCore/testing/Internals.idl	2022-04-27 20:18:06 UTC (rev 293530)
@@ -115,6 +115,13 @@
     "AudioProcessing"
 };
 
+enum RouteSharingPolicy {
+    "Default",
+    "LongFormAudio",
+    "Independent",
+    "LongFormVideo"
+};
+
 enum AutoplayPolicy {
     "Default",
     "Allow",
@@ -980,6 +987,7 @@
     readonly attribute boolean supportsAudioSession;
     AudioSessionCategory audioSessionCategory();
     [Conditional=VIDEO] AudioSessionCategory categoryAtMostRecentPlayback(HTMLMediaElement element);
+    RouteSharingPolicy routeSharingPolicy();
 
     double preferredAudioBufferSize();
     double currentAudioBufferSize();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to