Title: [291268] trunk
Revision
291268
Author
[email protected]
Date
2022-03-15 00:28:45 -0700 (Tue, 15 Mar 2022)

Log Message

Make sure to end any pending AudioSession interruption when activating it
https://bugs.webkit.org/show_bug.cgi?id=237654
<rdar://88405081>

Reviewed by Eric Carlson.

Source/WebCore:

In some cases, we receive audio session interruptions without receiving any end of interruption notification.
In those cases, if we reactivate the audio session, we should end this pending interruption so that our WebCore code
gets its expected end of interruption message. This for instance allows to get back regular autoplay behavior.

Test: platform/ios/mediastream/getUserMedia-override-audio-session-interruption.html

* platform/audio/AudioSession.cpp:
* platform/audio/AudioSession.h:
* testing/Internals.cpp:
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* platform/ios/mediastream/getUserMedia-override-audio-session-interruption-expected.txt: Added.
* platform/ios/mediastream/getUserMedia-override-audio-session-interruption.html: Added.

Modified Paths

Added Paths

Diff

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


--- trunk/LayoutTests/ChangeLog	2022-03-15 07:19:08 UTC (rev 291267)
+++ trunk/LayoutTests/ChangeLog	2022-03-15 07:28:45 UTC (rev 291268)
@@ -1,5 +1,16 @@
 2022-03-15  Youenn Fablet  <[email protected]>
 
+        Make sure to end any pending AudioSession interruption when activating it
+        https://bugs.webkit.org/show_bug.cgi?id=237654
+        <rdar://88405081>
+
+        Reviewed by Eric Carlson.
+
+        * platform/ios/mediastream/getUserMedia-override-audio-session-interruption-expected.txt: Added.
+        * platform/ios/mediastream/getUserMedia-override-audio-session-interruption.html: Added.
+
+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>

Added: trunk/LayoutTests/platform/ios/mediastream/getUserMedia-override-audio-session-interruption-expected.txt (0 => 291268)


--- trunk/LayoutTests/platform/ios/mediastream/getUserMedia-override-audio-session-interruption-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/ios/mediastream/getUserMedia-override-audio-session-interruption-expected.txt	2022-03-15 07:28:45 UTC (rev 291268)
@@ -0,0 +1,4 @@
+
+
+PASS call getUserMedia, stop, interrupt and recall getUserMedia
+

Added: trunk/LayoutTests/platform/ios/mediastream/getUserMedia-override-audio-session-interruption.html (0 => 291268)


--- trunk/LayoutTests/platform/ios/mediastream/getUserMedia-override-audio-session-interruption.html	                        (rev 0)
+++ trunk/LayoutTests/platform/ios/mediastream/getUserMedia-override-audio-session-interruption.html	2022-03-15 07:28:45 UTC (rev 291268)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>override interruption with getUserMedia</title>
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <video id="video" autoplay playsinline muted></video>
+        <script>
+async function waitForVideoPlaying(video)
+{
+    let counter = 0;
+    while (video.paused && ++counter < 20)
+        await new Promise(resolve => setTimeout(resolve, 100));
+    return !video.paused;
+}
+
+promise_test(async () => {
+    if (window.internals)
+        internals.setMediaElementRestrictions(video, "invisibleautoplaynotpermitted");
+
+    let stream = await navigator.mediaDevices.getUserMedia({ audio: true });
+    video.srcObject = stream;
+    assert_true(await waitForVideoPlaying(video), "test before system interruption");
+
+    stream.getAudioTracks()[0].stop();
+    // Let's simulate an AudioSession interruption due to not using it during some time.
+    if (window.internals)
+        internals.beginAudioSessionInterruption();
+
+    video.srcObject = null;
+
+    stream = await navigator.mediaDevices.getUserMedia({ audio: true });
+    video.srcObject = stream;
+    assert_true(await waitForVideoPlaying(video), "test after system interruption");
+}, "call getUserMedia, stop, interrupt and recall getUserMedia");
+        </script>
+    </body>
+</html>

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


--- trunk/Source/WebCore/ChangeLog	2022-03-15 07:19:08 UTC (rev 291267)
+++ trunk/Source/WebCore/ChangeLog	2022-03-15 07:28:45 UTC (rev 291268)
@@ -1,5 +1,25 @@
 2022-03-15  Youenn Fablet  <[email protected]>
 
+        Make sure to end any pending AudioSession interruption when activating it
+        https://bugs.webkit.org/show_bug.cgi?id=237654
+        <rdar://88405081>
+
+        Reviewed by Eric Carlson.
+
+        In some cases, we receive audio session interruptions without receiving any end of interruption notification.
+        In those cases, if we reactivate the audio session, we should end this pending interruption so that our WebCore code
+        gets its expected end of interruption message. This for instance allows to get back regular autoplay behavior.
+
+        Test: platform/ios/mediastream/getUserMedia-override-audio-session-interruption.html
+
+        * platform/audio/AudioSession.cpp:
+        * platform/audio/AudioSession.h:
+        * testing/Internals.cpp:
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
+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>

Modified: trunk/Source/WebCore/platform/audio/AudioSession.cpp (291267 => 291268)


--- trunk/Source/WebCore/platform/audio/AudioSession.cpp	2022-03-15 07:19:08 UTC (rev 291267)
+++ trunk/Source/WebCore/platform/audio/AudioSession.cpp	2022-03-15 07:28:45 UTC (rev 291268)
@@ -100,6 +100,9 @@
         return false;
 
     m_active = active;
+    if (m_isInterrupted)
+        endInterruption(MayResume::Yes);
+
     return true;
 }
 
@@ -115,6 +118,8 @@
 
 void AudioSession::beginInterruption()
 {
+    ASSERT(!m_isInterrupted);
+    m_isInterrupted = true;
     for (auto& observer : m_interruptionObservers)
         observer.beginAudioSessionInterruption();
 }
@@ -121,6 +126,10 @@
 
 void AudioSession::endInterruption(MayResume mayResume)
 {
+    if (!m_isInterrupted)
+        return;
+    m_isInterrupted = false;
+
     for (auto& observer : m_interruptionObservers)
         observer.endAudioSessionInterruption(mayResume);
 }

Modified: trunk/Source/WebCore/platform/audio/AudioSession.h (291267 => 291268)


--- trunk/Source/WebCore/platform/audio/AudioSession.h	2022-03-15 07:19:08 UTC (rev 291267)
+++ trunk/Source/WebCore/platform/audio/AudioSession.h	2022-03-15 07:28:45 UTC (rev 291268)
@@ -144,6 +144,7 @@
     WeakPtr<AudioSessionRoutingArbitrationClient> m_routingArbitrationClient;
     AudioSession::CategoryType m_categoryOverride { AudioSession::CategoryType::None };
     bool m_active { false }; // Used only for testing.
+    bool m_isInterrupted { false };
 
     static bool s_shouldManageAudioSessionCategory;
 };

Modified: trunk/Source/WebCore/testing/Internals.cpp (291267 => 291268)


--- trunk/Source/WebCore/testing/Internals.cpp	2022-03-15 07:19:08 UTC (rev 291267)
+++ trunk/Source/WebCore/testing/Internals.cpp	2022-03-15 07:28:45 UTC (rev 291268)
@@ -4510,6 +4510,13 @@
     auto player = element.player();
     return player && player->muted();
 }
+
+void Internals::beginAudioSessionInterruption()
+{
+#if USE(AUDIO_SESSION)
+    AudioSession::sharedSession().beginInterruption();
+#endif
+}
 #endif // ENABLE(VIDEO)
 
 #if ENABLE(WEB_AUDIO)

Modified: trunk/Source/WebCore/testing/Internals.h (291267 => 291268)


--- trunk/Source/WebCore/testing/Internals.h	2022-03-15 07:19:08 UTC (rev 291267)
+++ trunk/Source/WebCore/testing/Internals.h	2022-03-15 07:28:45 UTC (rev 291268)
@@ -741,6 +741,7 @@
     bool elementIsBlockingDisplaySleep(const HTMLMediaElement&) const;
     bool isPlayerVisibleInViewport(const HTMLMediaElement&) const;
     bool isPlayerMuted(const HTMLMediaElement&) const;
+    void beginAudioSessionInterruption();
 #endif
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)

Modified: trunk/Source/WebCore/testing/Internals.idl (291267 => 291268)


--- trunk/Source/WebCore/testing/Internals.idl	2022-03-15 07:19:08 UTC (rev 291267)
+++ trunk/Source/WebCore/testing/Internals.idl	2022-03-15 07:28:45 UTC (rev 291268)
@@ -797,6 +797,7 @@
     [Conditional=WEB_AUDIO] undefined setAudioContextRestrictions(AudioContext context, DOMString restrictions);
     [Conditional=VIDEO] undefined postRemoteControlCommand(DOMString command, optional unrestricted float argument = 0);
     [Conditional=VIDEO] undefined activeAudioRouteDidChange(boolean shouldPause);
+    [Conditional=VIDEO] undefined beginAudioSessionInterruption();
 
     [Conditional=WIRELESS_PLAYBACK_TARGET] undefined setMockMediaPlaybackTargetPickerEnabled(boolean enabled);
     [Conditional=WIRELESS_PLAYBACK_TARGET] undefined setMockMediaPlaybackTargetPickerState(DOMString deviceName, DOMString deviceState);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to