[iOS] Muted media playback can interrupt out-of-process audio
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Mar 2018 22:54:20 +0000 (22:54 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Mar 2018 22:54:20 +0000 (22:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183606
<rdar://problem/37466253>

Reviewed by Eric Carlson.

Source/WebCore:

Test: Updated TestWebKitAPI test to verify the correct AVAudioSession category is set.

A non-playing, non-muted media element will cause the AVAudioSession category to be set to
"playing" when a muted media element begins playback. Ignore these non-playing elements for
the purposes of determining the AVAudioSession category.

* platform/audio/cocoa/MediaSessionManagerCocoa.cpp:
(PlatformMediaSessionManager::updateSessionState):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitLegacy/ios/AudioSessionCategoryIOS.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-paused-audio-and-playing-muted.html: Added.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/AudioSessionCategoryIOS.mm
Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-paused-audio-and-playing-muted.html [new file with mode: 0644]

index b5be5be..aae645f 100644 (file)
@@ -1,3 +1,20 @@
+2018-03-13  Jer Noble  <jer.noble@apple.com>
+
+        [iOS] Muted media playback can interrupt out-of-process audio
+        https://bugs.webkit.org/show_bug.cgi?id=183606
+        <rdar://problem/37466253>
+
+        Reviewed by Eric Carlson.
+
+        Test: Updated TestWebKitAPI test to verify the correct AVAudioSession category is set.
+
+        A non-playing, non-muted media element will cause the AVAudioSession category to be set to
+        "playing" when a muted media element begins playback. Ignore these non-playing elements for
+        the purposes of determining the AVAudioSession category.
+
+        * platform/audio/cocoa/MediaSessionManagerCocoa.cpp:
+        (PlatformMediaSessionManager::updateSessionState):
+
 2018-03-13  Youenn Fablet  <youenn@apple.com>
 
         Calling removeTrack with RTCRtpSender does not set SenderTrack to null
index 6c3e514..3fe59cf 100644 (file)
@@ -70,7 +70,7 @@ void PlatformMediaSessionManager::updateSessionState()
         auto type = session.mediaType();
         if (type == PlatformMediaSession::WebAudio)
             hasWebAudioType = true;
-        if ((type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio) && session.canProduceAudio())
+        if ((type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio) && session.canProduceAudio() && session.state() == PlatformMediaSession::Playing)
             hasAudibleAudioOrVideoMediaType = true;
         return (type == PlatformMediaSession::MediaStreamCapturingAudio);
     });
index 402f0ce..e189388 100644 (file)
@@ -1,3 +1,16 @@
+2018-03-13  Jer Noble  <jer.noble@apple.com>
+
+        [iOS] Muted media playback can interrupt out-of-process audio
+        https://bugs.webkit.org/show_bug.cgi?id=183606
+        <rdar://problem/37466253>
+
+        Reviewed by Eric Carlson.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitLegacy/ios/AudioSessionCategoryIOS.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-paused-audio-and-playing-muted.html: Added.
+
 2018-03-13  Ross Kirsling  <ross.kirsling@sony.com>
 
         [Win] Layout Test fast/html/menuitem-element.html is failing.
index cd5d5dc..36c6db1 100644 (file)
                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
                CD59F53419E9110D00CF1835 /* file-with-mse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53219E910AA00CF1835 /* file-with-mse.html */; };
                CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53319E910BC00CF1835 /* test-mse.mp4 */; };
+               CD758A6F20572EA00071834A /* video-with-paused-audio-and-playing-muted.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD758A6E20572D540071834A /* video-with-paused-audio-and-playing-muted.html */; };
                CD78E11D1DB7EA660014A2DE /* FullscreenDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */; };
                CD78E11E1DB7EE2A0014A2DE /* FullscreenDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */; };
                CD9E292E1C90C33F000BB800 /* audio-only.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD9E292D1C90C1BA000BB800 /* audio-only.html */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
+                               CD758A6F20572EA00071834A /* video-with-paused-audio-and-playing-muted.html in Copy Resources */,
                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
                                379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
                                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */,
                CD5497B315857F0C00B5BC30 /* MediaTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaTime.cpp; sourceTree = "<group>"; };
                CD59F53219E910AA00CF1835 /* file-with-mse.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "file-with-mse.html"; sourceTree = "<group>"; };
                CD59F53319E910BC00CF1835 /* test-mse.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "test-mse.mp4"; sourceTree = "<group>"; };
+               CD758A6E20572D540071834A /* video-with-paused-audio-and-playing-muted.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "video-with-paused-audio-and-playing-muted.html"; sourceTree = "<group>"; };
                CD773F711C5057DB0002257C /* FeatureDefines.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = FeatureDefines.xcconfig; sourceTree = "<group>"; };
                CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FullscreenDelegate.mm; sourceTree = "<group>"; };
                CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FullscreenDelegate.html; sourceTree = "<group>"; };
                                CDC8E4891BC5C96200594FEC /* video-with-audio.html */,
                                CDC8E48A1BC5C96200594FEC /* video-with-audio.mp4 */,
                                CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */,
+                               CD758A6E20572D540071834A /* video-with-paused-audio-and-playing-muted.html */,
                                CDB411591E09DA8E00EAD352 /* video-with-muted-audio.html */,
                                CDC8E48B1BC5C96200594FEC /* video-without-audio.html */,
                                CDC8E48C1BC5C96200594FEC /* video-without-audio.mp4 */,
index c5264ec..72c5dac 100644 (file)
@@ -101,6 +101,14 @@ TEST(WebKitLegacy, AudioSessionCategoryIOS)
     Util::run(&didBeginPlaying);
 
     EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
+
+    didBeginPlaying = false;
+
+    [uiWebView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"video-with-paused-audio-and-playing-muted" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+
+    Util::run(&didBeginPlaying);
+
+    EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
 }
 
 }
diff --git a/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-paused-audio-and-playing-muted.html b/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-paused-audio-and-playing-muted.html
new file mode 100644 (file)
index 0000000..a48524f
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script>
+        function go() {
+            var video1 = document.createElement('video');
+            document.body.appendChild(video1);
+            video1.setAttribute('webkit-playsinline', '');
+            video1.src = 'video-with-audio.mp4';
+            video1.play().then(() => {
+                video1.pause();
+                var video2 = document.createElement('video');
+                document.body.appendChild(video2);
+                video2.setAttribute('webkit-playsinline', '');
+                video2.muted = true;
+                video2.src = 'video-with-audio.mp4';
+                video2.play().then(playing, notPlaying);
+            });
+        }
+
+        function playing() {
+            try {
+                window.webkit.messageHandlers.testHandler.postMessage('playing');
+            } catch(e) {
+                window.location = 'callback:playing';
+            }
+        }
+
+        function notPlaying() {
+            try {
+                window.webkit.messageHandlers.testHandler.postMessage('not playing');
+            } catch(e) { }
+        }
+        </script>
+    </head>
+    <body onload="go()">
+    </body>
+</html>