Title: [211511] branches/safari-603-branch

Diff

Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (211510 => 211511)


--- branches/safari-603-branch/Source/WebCore/ChangeLog	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog	2017-02-01 21:26:17 UTC (rev 211511)
@@ -1,5 +1,57 @@
 2017-01-31  Matthew Hanson  <matthew_han...@apple.com>
 
+        Merge r211240. rdar://problem/30247467b
+
+    2017-01-26  Jer Noble  <jer.no...@apple.com>
+
+            Autoplay muted videos stop playback of any streaming app in the background
+            https://bugs.webkit.org/show_bug.cgi?id=163993
+            <rdar://problem/29020431>
+
+            Reviewed by Eric Carlson.
+
+            Added test in TestWebKitAPI, WebKit1.AudioSessionCategoryIOS.
+
+            Previously, we would set the audio session category to "playback" if there was a media-
+            element-type media session, and if there was a session capable of playing audio. But because
+            this was an "or" operation, we would incorrectly set the category to "playback" if there was
+            a video element incapable of rendering audio (due to being muted, without an audio track,
+            etc.), and also a session capable of producing audio, such as WebAudio.
+
+            With this change, this turns into an "and" operation; there must be a media element capable
+            of rendering audio in order to switch the audio session category to "playback".
+
+            Additionally, we no longer cache the value of "canProduceAudio()"; it's queried directly
+            whenever updateSessionState() is called.
+
+            * Modules/webaudio/AudioContext.cpp:
+            (WebCore::AudioContext::constructCommon):
+            * Modules/webaudio/AudioContext.h:
+            * html/HTMLMediaElement.cpp:
+            (WebCore::HTMLMediaElement::insertedInto):
+            (WebCore::HTMLMediaElement::loadResource):
+            (WebCore::HTMLMediaElement::setMuted):
+            (WebCore::HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged):
+            (WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):
+            (WebCore::HTMLMediaElement::clearMediaPlayer):
+            (WebCore::HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged):
+            (WebCore::HTMLMediaElement::presentationType):
+            (WebCore::HTMLMediaElement::characteristics):
+            (WebCore::HTMLMediaElement::canProduceAudio):
+            * html/HTMLMediaElement.h:
+            * platform/audio/PlatformMediaSession.cpp:
+            (WebCore::PlatformMediaSession::activeAudioSessionRequired):
+            (WebCore::PlatformMediaSession::canProduceAudio):
+            (WebCore::PlatformMediaSession::canProduceAudioChanged):
+            (WebCore::PlatformMediaSession::setCanProduceAudio): Deleted.
+            * platform/audio/PlatformMediaSession.h:
+            (WebCore::PlatformMediaSessionClient::canProduceAudio):
+            (WebCore::PlatformMediaSession::canProduceAudio): Deleted.
+            * platform/audio/cocoa/MediaSessionManagerCocoa.cpp:
+            (PlatformMediaSessionManager::updateSessionState):
+
+2017-01-31  Matthew Hanson  <matthew_han...@apple.com>
+
         Merge r210217. rdar://problem/30260068
 
         Committed on behalf of Chris Dumez.

Modified: branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.cpp (211510 => 211511)


--- branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.cpp	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.cpp	2017-02-01 21:26:17 UTC (rev 211511)
@@ -181,8 +181,6 @@
 #if PLATFORM(COCOA)
     addBehaviorRestriction(RequirePageConsentForAudioStartRestriction);
 #endif
-
-    m_mediaSession->setCanProduceAudio(true);
 }
 
 AudioContext::~AudioContext()

Modified: branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.h (211510 => 211511)


--- branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.h	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.h	2017-02-01 21:26:17 UTC (rev 211511)
@@ -317,6 +317,7 @@
     bool supportsSeeking() const override { return false; }
     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override { return false; }
     String sourceApplicationIdentifier() const override;
+    bool canProduceAudio() const final { return true; }
 
     // EventTarget
     void refEventTarget() override { ref(); }

Modified: branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.cpp (211510 => 211511)


--- branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.cpp	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.cpp	2017-02-01 21:26:17 UTC (rev 211511)
@@ -829,6 +829,7 @@
     if (!m_explicitlyMuted) {
         m_explicitlyMuted = true;
         m_muted = hasAttributeWithoutSynchronization(mutedAttr);
+        m_mediaSession->canProduceAudioChanged();
     }
 
     return InsertionShouldCallFinishedInsertingSubtree;
@@ -1487,6 +1488,7 @@
     if (!m_explicitlyMuted) {
         m_explicitlyMuted = true;
         m_muted = hasAttributeWithoutSynchronization(mutedAttr);
+        m_mediaSession->canProduceAudioChanged();
     }
 
     updateVolume();
@@ -3317,6 +3319,7 @@
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
         updateMediaState(UpdateState::Asynchronously);
 #endif
+        m_mediaSession->canProduceAudioChanged();
     }
 
     scheduleUpdatePlaybackControlsManager();
@@ -4650,8 +4653,6 @@
     if (!paused() && !m_mediaSession->playbackPermitted(*this))
         pauseInternal();
 
-    m_mediaSession->setCanProduceAudio(m_player && m_readyState >= HAVE_METADATA && hasAudio());
-
 #if ENABLE(MEDIA_SESSION)
     document().updateIsPlayingMedia(m_elementID);
 #else
@@ -5069,8 +5070,8 @@
         configureTextTrackDisplay();
 #endif
 
-    m_mediaSession->setCanProduceAudio(false);
     m_mediaSession->clientCharacteristicsChanged();
+    m_mediaSession->canProduceAudioChanged();
 
     updateSleepDisabling();
 }
@@ -5261,8 +5262,7 @@
     configureMediaControls();
     scheduleEvent(eventNames().webkitcurrentplaybacktargetiswirelesschangedEvent);
     m_mediaSession->isPlayingToWirelessPlaybackTargetChanged(m_isPlayingToWirelessTarget);
-    if (m_isPlayingToWirelessTarget)
-        m_mediaSession->setCanProduceAudio(true);
+    m_mediaSession->canProduceAudioChanged();
     updateMediaState(UpdateState::Asynchronously);
 }
 
@@ -6797,7 +6797,7 @@
 PlatformMediaSession::MediaType HTMLMediaElement::presentationType() const
 {
     if (hasTagName(HTMLNames::videoTag))
-        return PlatformMediaSession::VideoAudio;
+        return muted() ? PlatformMediaSession::Video : PlatformMediaSession::VideoAudio;
 
     return PlatformMediaSession::Audio;
 }
@@ -6829,6 +6829,21 @@
     return state;
 }
 
+bool HTMLMediaElement::canProduceAudio() const
+{
+#if ENABLE(WIRELESS_PLAYBACK_TARGET)
+    // Because the remote target could unmute playback without notifying us, we must assume
+    // that we may be playing audio.
+    if (m_isPlayingToWirelessTarget)
+        return true;
+#endif
+
+    if (muted())
+        return false;
+
+    return m_player && m_readyState >= HAVE_METADATA && hasAudio();
+}
+
 #if ENABLE(MEDIA_SOURCE)
 size_t HTMLMediaElement::maximumSourceBufferSize(const SourceBuffer& buffer) const
 {

Modified: branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.h (211510 => 211511)


--- branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.h	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.h	2017-02-01 21:26:17 UTC (rev 211511)
@@ -776,6 +776,7 @@
     bool supportsSeeking() const override;
     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override;
     bool shouldOverrideBackgroundLoadingRestriction() const override;
+    bool canProduceAudio() const final;
 
     void pageMutedStateDidChange() override;
 

Modified: branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.cpp (211510 => 211511)


--- branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2017-02-01 21:26:17 UTC (rev 211511)
@@ -329,15 +329,16 @@
         return false;
     if (state() != PlatformMediaSession::State::Playing)
         return false;
-    return m_canProduceAudio;
+    return canProduceAudio();
 }
 
-void PlatformMediaSession::setCanProduceAudio(bool canProduceAudio)
+bool PlatformMediaSession::canProduceAudio() const
 {
-    if (m_canProduceAudio == canProduceAudio)
-        return;
-    m_canProduceAudio = canProduceAudio;
+    return m_client.canProduceAudio();
+}
 
+void PlatformMediaSession::canProduceAudioChanged()
+{
     PlatformMediaSessionManager::sharedManager().sessionCanProduceAudioChanged(*this);
 }
 

Modified: branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.h (211510 => 211511)


--- branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.h	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.h	2017-02-01 21:26:17 UTC (rev 211511)
@@ -162,8 +162,8 @@
 #endif
 
     bool activeAudioSessionRequired();
-    bool canProduceAudio() const { return m_canProduceAudio; }
-    void setCanProduceAudio(bool);
+    bool canProduceAudio() const;
+    void canProduceAudioChanged();
 
     void scheduleClientDataBufferingCheck();
     virtual void resetPlaybackSessionState() { }
@@ -186,7 +186,6 @@
     int m_interruptionCount { 0 };
     bool m_notifyingClient;
     bool m_isPlayingToWirelessPlaybackTarget { false };
-    bool m_canProduceAudio { false };
 
     friend class PlatformMediaSessionManager;
 };
@@ -217,6 +216,7 @@
 
     virtual void setShouldBufferData(bool) { }
     virtual bool elementIsHidden() const { return false; }
+    virtual bool canProduceAudio() const { return false; }
 
     virtual bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const = 0;
     virtual bool shouldOverrideBackgroundLoadingRestriction() const { return false; }

Modified: branches/safari-603-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp (211510 => 211511)


--- branches/safari-603-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp	2017-02-01 21:26:17 UTC (rev 211511)
@@ -31,6 +31,7 @@
 #include "AudioSession.h"
 #include "Logging.h"
 #include "Settings.h"
+#include <wtf/Function.h>
 
 using namespace WebCore;
 
@@ -60,13 +61,20 @@
     if (!Settings::shouldManageAudioSessionCategory())
         return;
 
-    if (has(PlatformMediaSession::VideoAudio) || has(PlatformMediaSession::Audio)) {
-        if (canProduceAudio())
-            AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
-        else
-            AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
-    } else if (has(PlatformMediaSession::WebAudio))
+    bool hasAudioMediaType = false;
+    bool hasAudibleAudioOrVideoMediaType = anyOfSessions([this, hasAudioMediaType] (PlatformMediaSession& session, size_t) mutable {
+        auto type = session.mediaType();
+        if (type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio || type == PlatformMediaSession::WebAudio)
+            hasAudioMediaType = true;
+        return (type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio) && session.canProduceAudio();
+    });
+
+    if (hasAudibleAudioOrVideoMediaType)
+        AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
+    else if (hasAudioMediaType)
         AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
+    else
+        AudioSession::sharedSession().setCategory(AudioSession::None);
 #endif
 }
 

Modified: branches/safari-603-branch/Tools/ChangeLog (211510 => 211511)


--- branches/safari-603-branch/Tools/ChangeLog	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Tools/ChangeLog	2017-02-01 21:26:17 UTC (rev 211511)
@@ -1,3 +1,20 @@
+2017-01-31  Matthew Hanson  <matthew_han...@apple.com>
+
+        Merge r211240. rdar://problem/30247467b
+
+    2017-01-26  Jer Noble  <jer.no...@apple.com>
+
+            Autoplay muted videos stop playback of any streaming app in the background
+            https://bugs.webkit.org/show_bug.cgi?id=163993
+            <rdar://problem/29020431>
+
+            Reviewed by Eric Carlson.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm:
+            (TestWebKitAPI::TEST):
+            * TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html: Added.
+
 2017-01-25  Matthew Hanson  <matthew_han...@apple.com>
 
         Merge r211137. rdar://problem/29896656

Modified: branches/safari-603-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (211510 => 211511)


--- branches/safari-603-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-02-01 21:26:17 UTC (rev 211511)
@@ -502,6 +502,7 @@
 		C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C540F783152E5A7800A40C8C /* verboseMarkup.html */; };
 		C54237F116B8957D00E638FC /* PasteboardNotifications_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C54237ED16B8955800E638FC /* PasteboardNotifications_Bundle.cpp */; };
 		C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C5E1AFFD16B22179006CC1F2 /* execCopy.html */; };
+		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 */; };
 		CD78E11D1DB7EA660014A2DE /* FullscreenDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */; };
@@ -599,6 +600,7 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */,
 				7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */,
 				CDB4115A1E0B00DB00EAD352 /* video-with-muted-audio.html in Copy Resources */,
 				9BD4239C1E04C01C00200395 /* chinese-character-with-image.html in Copy Resources */,
@@ -1256,6 +1258,7 @@
 		C5E1AFFD16B22179006CC1F2 /* execCopy.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = execCopy.html; sourceTree = "<group>"; };
 		C95501BE19AD2FAF0049BE3E /* Preferences.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Preferences.mm; sourceTree = "<group>"; };
 		CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
+		CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "video-with-muted-audio-and-webaudio.html"; sourceTree = "<group>"; };
 		CD5393C71757BA9700C07123 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = "<group>"; };
 		CD5393C91757BAC400C07123 /* SHA1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SHA1.cpp; sourceTree = "<group>"; };
 		CD5451E919E41F9D0016936F /* CSSParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSParser.cpp; sourceTree = "<group>"; };
@@ -2194,6 +2197,7 @@
 				CDC8E48B1BC5C96200594FEC /* video-without-audio.html */,
 				CDC8E48C1BC5C96200594FEC /* video-without-audio.mp4 */,
 				CDB411591E09DA8E00EAD352 /* video-with-muted-audio.html */,
+				CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */,
 			);
 			name = Resources;
 			sourceTree = "<group>";

Modified: branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm (211510 => 211511)


--- branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm	2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm	2017-02-01 21:26:17 UTC (rev 211511)
@@ -97,6 +97,14 @@
     Util::run(&didBeginPlaying);
 
     EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
+
+    didBeginPlaying = false;
+
+    [uiWebView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"video-with-muted-audio-and-webaudio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+
+    Util::run(&didBeginPlaying);
+
+    EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
 }
 
 }

Added: branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html (0 => 211511)


--- branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html	                        (rev 0)
+++ branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html	2017-02-01 21:26:17 UTC (rev 211511)
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script>
+        function go() {
+            var audioContext = new webkitAudioContext();
+            audioContext.resume();
+
+            var video = document.getElementsByTagName('video')[0];
+            video.play().then(playing).catch(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()">
+        <video src="" muted webkit-playsinline></video>
+    </body>
+</html>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to