Title: [291267] trunk
Revision
291267
Author
[email protected]
Date
2022-03-15 00:19:08 -0700 (Tue, 15 Mar 2022)

Log Message

AudioContext stops playing when minimizing or moving the macOS Safari window to the background.
https://bugs.webkit.org/show_bug.cgi?id=231105
<rdar://problem/83889697>

Reviewed by Eric Carlson.

Source/WebCore:

AudioContext was stopped when minimizing windows if not playing audio as a way to reduce CPU usage.
But this is visible to users (if AudioContext produces audio through a track) or to web pages (use of audio worklet or script processor node).
Remove that code.
Small refactoring to remove isOfflineContext checks that can only be false in AudioContext.

Covered by existing tests.

* Modules/webaudio/AudioContext.cpp:
* Modules/webaudio/AudioContext.h:

LayoutTests:

Use internals API to be working on iOS as well (this does not trigger enterBackground code path).

* webaudio/silent-audio-interrupted-in-background-expected.txt:
* webaudio/silent-audio-interrupted-in-background.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (291266 => 291267)


--- trunk/LayoutTests/ChangeLog	2022-03-15 04:16:28 UTC (rev 291266)
+++ trunk/LayoutTests/ChangeLog	2022-03-15 07:19:08 UTC (rev 291267)
@@ -1,3 +1,16 @@
+2022-03-15  Youenn Fablet  <[email protected]>
+
+        AudioContext stops playing when minimizing or moving the macOS Safari window to the background.
+        https://bugs.webkit.org/show_bug.cgi?id=231105
+        <rdar://problem/83889697>
+
+        Reviewed by Eric Carlson.
+
+        Use internals API to be working on iOS as well (this does not trigger enterBackground code path).
+
+        * webaudio/silent-audio-interrupted-in-background-expected.txt:
+        * webaudio/silent-audio-interrupted-in-background.html:
+
 2022-03-14  Lauro Moura  <[email protected]>
 
         [GLIB] Unreviewed, gardening crash and timeout

Modified: trunk/LayoutTests/webaudio/silent-audio-interrupted-in-background-expected.txt (291266 => 291267)


--- trunk/LayoutTests/webaudio/silent-audio-interrupted-in-background-expected.txt	2022-03-15 04:16:28 UTC (rev 291266)
+++ trunk/LayoutTests/webaudio/silent-audio-interrupted-in-background-expected.txt	2022-03-15 07:19:08 UTC (rev 291267)
@@ -1,4 +1,4 @@
-Tests that silent WebAudio rendering gets interrupted in hidden pages.
+Tests silent WebAudio rendering in hidden pages.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
@@ -5,9 +5,11 @@
 
 PASS context.state became 'running'
 * Setting page visibility to hidden
-PASS context.state became 'interrupted'
+PASS document.hidden is true
+PASS context.state is 'running'
 * Setting page visibility to visible
-PASS context.state became 'running'
+PASS document.hidden is false
+PASS context.state is 'running'
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/webaudio/silent-audio-interrupted-in-background.html (291266 => 291267)


--- trunk/LayoutTests/webaudio/silent-audio-interrupted-in-background.html	2022-03-15 04:16:28 UTC (rev 291266)
+++ trunk/LayoutTests/webaudio/silent-audio-interrupted-in-background.html	2022-03-15 07:19:08 UTC (rev 291267)
@@ -3,29 +3,35 @@
 <body>
 <script src=""
 <script>
-description("Tests that silent WebAudio rendering gets interrupted in hidden pages.");
+description("Tests silent WebAudio rendering in hidden pages.");
 jsTestIsAsync = true;
 
-document._onvisibilitychange_ = function() {
-    if (document.hidden) {
-        shouldBecomeEqual("context.state", "'interrupted'", showPage);
-    } else {
-        shouldBecomeEqual("context.state", "'running'", finishJSTest);
+let counter = 0;
+document._onvisibilitychange_ = async function() {
+    if (!counter) {
+         counter = 1;
+         shouldBeTrue("document.hidden");
+         shouldBe("context.state", "'running'");
+         showPage();
+         return;
     }
+    shouldBeFalse("document.hidden");
+    shouldBe("context.state", "'running'");
+    finishJSTest();
 }
 
 function showPage()
 {
     debug("* Setting page visibility to visible");
-    if (window.testRunner)
-        testRunner.setPageVisibility("visible");
+    if (window.internals)
+        internals.setPageVisibility(true);
 }
 
 function hidePage()
 {
     debug("* Setting page visibility to hidden");
-    if (window.testRunner)
-        testRunner.setPageVisibility("hidden");
+    if (window.internals)
+        internals.setPageVisibility(false);
 }
 
 _onload_ = function() {

Modified: trunk/Source/WebCore/ChangeLog (291266 => 291267)


--- trunk/Source/WebCore/ChangeLog	2022-03-15 04:16:28 UTC (rev 291266)
+++ trunk/Source/WebCore/ChangeLog	2022-03-15 07:19:08 UTC (rev 291267)
@@ -1,3 +1,21 @@
+2022-03-15  Youenn Fablet  <[email protected]>
+
+        AudioContext stops playing when minimizing or moving the macOS Safari window to the background.
+        https://bugs.webkit.org/show_bug.cgi?id=231105
+        <rdar://problem/83889697>
+
+        Reviewed by Eric Carlson.
+
+        AudioContext was stopped when minimizing windows if not playing audio as a way to reduce CPU usage.
+        But this is visible to users (if AudioContext produces audio through a track) or to web pages (use of audio worklet or script processor node).
+        Remove that code.
+        Small refactoring to remove isOfflineContext checks that can only be false in AudioContext.
+
+        Covered by existing tests.
+
+        * Modules/webaudio/AudioContext.cpp:
+        * Modules/webaudio/AudioContext.h:
+
 2022-03-14  Wenson Hsieh  <[email protected]>
 
         [Mail compose] Allow copied resources with remote (HTTP/HTTPS) URLs to be pasted as attachments

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (291266 => 291267)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2022-03-15 04:16:28 UTC (rev 291266)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2022-03-15 07:19:08 UTC (rev 291267)
@@ -122,7 +122,6 @@
     pageMutedStateDidChange();
 
     document.addAudioProducer(*this);
-    document.registerForVisibilityStateChangedCallbacks(*this);
 
     // Unlike OfflineAudioContext, AudioContext does not require calling resume() to start rendering.
     // Lazy initialization starts rendering so we schedule a task here to make sure lazy initialization
@@ -148,10 +147,8 @@
 
 AudioContext::~AudioContext()
 {
-    if (!isOfflineContext() && scriptExecutionContext()) {
-        document()->removeAudioProducer(*this);
-        document()->unregisterForVisibilityStateChangedCallbacks(*this);
-    }
+    if (auto* document = this->document())
+        document->removeAudioProducer(*this);
 }
 
 void AudioContext::uninitialize()
@@ -193,7 +190,7 @@
 
 void AudioContext::close(DOMPromiseDeferred<void>&& promise)
 {
-    if (isOfflineContext() || isStopped()) {
+    if (isStopped()) {
         promise.reject(InvalidStateError);
         return;
     }
@@ -216,11 +213,6 @@
 
 void AudioContext::suspendRendering(DOMPromiseDeferred<void>&& promise)
 {
-    if (isOfflineContext()) {
-        promise.reject(Exception { InvalidStateError, "Cannot call suspend() on an OfflineAudioContext"_s });
-        return;
-    }
-
     if (isStopped() || state() == State::Closed) {
         promise.reject(Exception { InvalidStateError, "Context is closed"_s });
         return;
@@ -247,11 +239,6 @@
 
 void AudioContext::resumeRendering(DOMPromiseDeferred<void>&& promise)
 {
-    if (isOfflineContext()) {
-        promise.reject(Exception { InvalidStateError, "Cannot call resume() on an OfflineAudioContext"_s });
-        return;
-    }
-
     if (isStopped() || state() == State::Closed) {
         promise.reject(Exception { InvalidStateError, "Context is closed"_s });
         return;
@@ -416,25 +403,6 @@
     return willBegin;
 }
 
-void AudioContext::visibilityStateChanged()
-{
-    // Do not suspend if audio is audible.
-    if (!document() || mediaState() == MediaProducerMediaState::IsPlayingAudio || isStopped())
-        return;
-
-    if (document()->hidden()) {
-        if (state() == State::Running) {
-            ALWAYS_LOG(LOGIDENTIFIER, "Suspending playback after going to the background");
-            m_mediaSession->beginInterruption(PlatformMediaSession::EnteringBackground);
-        }
-    } else {
-        if (state() == State::Interrupted) {
-            ALWAYS_LOG(LOGIDENTIFIER, "Resuming playback after entering foreground");
-            m_mediaSession->endInterruption(PlatformMediaSession::MayResumePlaying);
-        }
-    }
-}
-
 void AudioContext::suspend(ReasonForSuspension)
 {
     if (isClosed() || m_wasSuspendedByScript)

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (291266 => 291267)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2022-03-15 04:16:28 UTC (rev 291266)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2022-03-15 07:19:08 UTC (rev 291267)
@@ -30,7 +30,6 @@
 #include "MediaCanStartListener.h"
 #include "MediaProducer.h"
 #include "PlatformMediaSession.h"
-#include "VisibilityChangeClient.h"
 #include <wtf/UniqueRef.h>
 
 namespace WebCore {
@@ -48,8 +47,7 @@
     : public BaseAudioContext
     , public MediaProducer
     , public MediaCanStartListener
-    , private PlatformMediaSessionClient
-    , private VisibilityChangeClient {
+    , private PlatformMediaSessionClient {
     WTF_MAKE_ISO_ALLOCATED(AudioContext);
 public:
     // Create an AudioContext for rendering to the audio hardware.
@@ -136,9 +134,6 @@
     // MediaCanStartListener.
     void mediaCanStart(Document&) final;
 
-    // VisibilityChangeClient
-    void visibilityStateChanged() final;
-
     // ActiveDOMObject
     const char* activeDOMObjectName() const final;
     void suspend(ReasonForSuspension) final;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to