<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211240] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211240">211240</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2017-01-26 16:38:22 -0800 (Thu, 26 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Autoplay muted videos stop playback of any streaming app in the background
https://bugs.webkit.org/show_bug.cgi?id=163993
&lt;rdar://problem/29020431&gt;

Reviewed by Eric Carlson.

Source/WebCore:

Added test in TestWebKitAPI, WebKit1.AudioSessionCategoryIOS.

Previously, we would set the audio session category to &quot;playback&quot; if there was a media-
element-type media session, and if there was a session capable of playing audio. But because
this was an &quot;or&quot; operation, we would incorrectly set the category to &quot;playback&quot; 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 &quot;and&quot; operation; there must be a media element capable
of rendering audio in order to switch the audio session category to &quot;playback&quot;.

Additionally, we no longer cache the value of &quot;canProduceAudio()&quot;; 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):

Tools:

* 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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModuleswebaudioAudioContextcpp">trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebaudioAudioContexth">trunk/Source/WebCore/Modules/webaudio/AudioContext.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementh">trunk/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioPlatformMediaSessioncpp">trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioPlatformMediaSessionh">trunk/Source/WebCore/platform/audio/PlatformMediaSession.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiococoaMediaSessionManagerCocoacpp">trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitiosAudioSessionCategoryIOSmm">trunk/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitiosvideowithmutedaudioandwebaudiohtml">trunk/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Source/WebCore/ChangeLog        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2017-01-26  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        Autoplay muted videos stop playback of any streaming app in the background
+        https://bugs.webkit.org/show_bug.cgi?id=163993
+        &lt;rdar://problem/29020431&gt;
+
+        Reviewed by Eric Carlson.
+
+        Added test in TestWebKitAPI, WebKit1.AudioSessionCategoryIOS.
+
+        Previously, we would set the audio session category to &quot;playback&quot; if there was a media-
+        element-type media session, and if there was a session capable of playing audio. But because
+        this was an &quot;or&quot; operation, we would incorrectly set the category to &quot;playback&quot; 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 &quot;and&quot; operation; there must be a media element capable
+        of rendering audio in order to switch the audio session category to &quot;playback&quot;.
+
+        Additionally, we no longer cache the value of &quot;canProduceAudio()&quot;; 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):
+
</ins><span class="cx"> 2017-01-26  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         EventTarget should visit the JSEventListeners using visitAdditionalChildren
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebaudioAudioContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -181,8 +181,6 @@
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     addBehaviorRestriction(RequirePageConsentForAudioStartRestriction);
</span><span class="cx"> #endif
</span><del>-
-    m_mediaSession-&gt;setCanProduceAudio(true);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> AudioContext::~AudioContext()
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebaudioAudioContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -317,6 +317,7 @@
</span><span class="cx">     bool supportsSeeking() const override { return false; }
</span><span class="cx">     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override { return false; }
</span><span class="cx">     String sourceApplicationIdentifier() const override;
</span><ins>+    bool canProduceAudio() const final { return true; }
</ins><span class="cx"> 
</span><span class="cx">     // EventTarget
</span><span class="cx">     void refEventTarget() override { ref(); }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -832,6 +832,7 @@
</span><span class="cx">     if (!m_explicitlyMuted) {
</span><span class="cx">         m_explicitlyMuted = true;
</span><span class="cx">         m_muted = hasAttributeWithoutSynchronization(mutedAttr);
</span><ins>+        m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return InsertionShouldCallFinishedInsertingSubtree;
</span><span class="lines">@@ -1485,6 +1486,7 @@
</span><span class="cx">     if (!m_explicitlyMuted) {
</span><span class="cx">         m_explicitlyMuted = true;
</span><span class="cx">         m_muted = hasAttributeWithoutSynchronization(mutedAttr);
</span><ins>+        m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     updateVolume();
</span><span class="lines">@@ -3330,6 +3332,7 @@
</span><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="cx">         updateMediaState(UpdateState::Asynchronously);
</span><span class="cx"> #endif
</span><ins>+        m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     scheduleUpdatePlaybackControlsManager();
</span><span class="lines">@@ -4663,8 +4666,6 @@
</span><span class="cx">     if (!paused() &amp;&amp; !m_mediaSession-&gt;playbackPermitted(*this))
</span><span class="cx">         pauseInternal();
</span><span class="cx"> 
</span><del>-    m_mediaSession-&gt;setCanProduceAudio(m_player &amp;&amp; m_readyState &gt;= HAVE_METADATA &amp;&amp; hasAudio());
-
</del><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     document().updateIsPlayingMedia(m_elementID);
</span><span class="cx"> #else
</span><span class="lines">@@ -5082,8 +5083,8 @@
</span><span class="cx">         configureTextTrackDisplay();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    m_mediaSession-&gt;setCanProduceAudio(false);
</del><span class="cx">     m_mediaSession-&gt;clientCharacteristicsChanged();
</span><ins>+    m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx"> 
</span><span class="cx">     updateSleepDisabling();
</span><span class="cx"> }
</span><span class="lines">@@ -5274,8 +5275,7 @@
</span><span class="cx">     configureMediaControls();
</span><span class="cx">     scheduleEvent(eventNames().webkitcurrentplaybacktargetiswirelesschangedEvent);
</span><span class="cx">     m_mediaSession-&gt;isPlayingToWirelessPlaybackTargetChanged(m_isPlayingToWirelessTarget);
</span><del>-    if (m_isPlayingToWirelessTarget)
-        m_mediaSession-&gt;setCanProduceAudio(true);
</del><ins>+    m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx">     updateMediaState(UpdateState::Asynchronously);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -6819,7 +6819,7 @@
</span><span class="cx"> PlatformMediaSession::MediaType HTMLMediaElement::presentationType() const
</span><span class="cx"> {
</span><span class="cx">     if (hasTagName(HTMLNames::videoTag))
</span><del>-        return PlatformMediaSession::VideoAudio;
</del><ins>+        return muted() ? PlatformMediaSession::Video : PlatformMediaSession::VideoAudio;
</ins><span class="cx"> 
</span><span class="cx">     return PlatformMediaSession::Audio;
</span><span class="cx"> }
</span><span class="lines">@@ -6851,6 +6851,21 @@
</span><span class="cx">     return state;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+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 &amp;&amp; m_readyState &gt;= HAVE_METADATA &amp;&amp; hasAudio();
+}
+
</ins><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><span class="cx"> size_t HTMLMediaElement::maximumSourceBufferSize(const SourceBuffer&amp; buffer) const
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.h        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -776,6 +776,7 @@
</span><span class="cx">     bool supportsSeeking() const override;
</span><span class="cx">     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override;
</span><span class="cx">     bool shouldOverrideBackgroundLoadingRestriction() const override;
</span><ins>+    bool canProduceAudio() const final;
</ins><span class="cx"> 
</span><span class="cx">     void pageMutedStateDidChange() override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioPlatformMediaSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -329,15 +329,16 @@
</span><span class="cx">         return false;
</span><span class="cx">     if (state() != PlatformMediaSession::State::Playing)
</span><span class="cx">         return false;
</span><del>-    return m_canProduceAudio;
</del><ins>+    return canProduceAudio();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PlatformMediaSession::setCanProduceAudio(bool canProduceAudio)
</del><ins>+bool PlatformMediaSession::canProduceAudio() const
</ins><span class="cx"> {
</span><del>-    if (m_canProduceAudio == canProduceAudio)
-        return;
-    m_canProduceAudio = canProduceAudio;
</del><ins>+    return m_client.canProduceAudio();
+}
</ins><span class="cx"> 
</span><ins>+void PlatformMediaSession::canProduceAudioChanged()
+{
</ins><span class="cx">     PlatformMediaSessionManager::sharedManager().sessionCanProduceAudioChanged(*this);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioPlatformMediaSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -162,8 +162,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     bool activeAudioSessionRequired();
</span><del>-    bool canProduceAudio() const { return m_canProduceAudio; }
-    void setCanProduceAudio(bool);
</del><ins>+    bool canProduceAudio() const;
+    void canProduceAudioChanged();
</ins><span class="cx"> 
</span><span class="cx">     void scheduleClientDataBufferingCheck();
</span><span class="cx">     virtual void resetPlaybackSessionState() { }
</span><span class="lines">@@ -186,7 +186,6 @@
</span><span class="cx">     int m_interruptionCount { 0 };
</span><span class="cx">     bool m_notifyingClient;
</span><span class="cx">     bool m_isPlayingToWirelessPlaybackTarget { false };
</span><del>-    bool m_canProduceAudio { false };
</del><span class="cx"> 
</span><span class="cx">     friend class PlatformMediaSessionManager;
</span><span class="cx"> };
</span><span class="lines">@@ -217,6 +216,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void setShouldBufferData(bool) { }
</span><span class="cx">     virtual bool elementIsHidden() const { return false; }
</span><ins>+    virtual bool canProduceAudio() const { return false; }
</ins><span class="cx"> 
</span><span class="cx">     virtual bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const = 0;
</span><span class="cx">     virtual bool shouldOverrideBackgroundLoadingRestriction() const { return false; }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiococoaMediaSessionManagerCocoacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;AudioSession.h&quot;
</span><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><ins>+#include &lt;wtf/Function.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="lines">@@ -60,13 +61,20 @@
</span><span class="cx">     if (!Settings::shouldManageAudioSessionCategory())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    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))
</del><ins>+    bool hasAudioMediaType = false;
+    bool hasAudibleAudioOrVideoMediaType = anyOfSessions([this, hasAudioMediaType] (PlatformMediaSession&amp; 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) &amp;&amp; session.canProduceAudio();
+    });
+
+    if (hasAudibleAudioOrVideoMediaType)
+        AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
+    else if (hasAudioMediaType)
</ins><span class="cx">         AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
</span><ins>+    else
+        AudioSession::sharedSession().setCategory(AudioSession::None);
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Tools/ChangeLog        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2017-01-26  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        Autoplay muted videos stop playback of any streaming app in the background
+        https://bugs.webkit.org/show_bug.cgi?id=163993
+        &lt;rdar://problem/29020431&gt;
+
+        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.
+
</ins><span class="cx"> 2017-01-26  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Disable API test WebKit2.WebsitePoliciesPlayAfterPreventedAutoplay.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -512,6 +512,7 @@
</span><span class="cx">                 C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */; };
</span><span class="cx">                 C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */; };
</span><span class="cx">                 C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */; };
</span><ins>+                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
</ins><span class="cx">                 CD59F53419E9110D00CF1835 /* file-with-mse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53219E910AA00CF1835 /* file-with-mse.html */; };
</span><span class="cx">                 CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53319E910BC00CF1835 /* test-mse.mp4 */; };
</span><span class="cx">                 CD78E11D1DB7EA660014A2DE /* FullscreenDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */; };
</span><span class="lines">@@ -613,6 +614,7 @@
</span><span class="cx">                                 C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */,
</span><span class="cx">                                 C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */,
</span><span class="cx">                                 C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */,
</span><ins>+                                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */,
</ins><span class="cx">                                 C95984F71E36BCEF002C0D45 /* test-without-audio-track.mp4 in Copy Resources */,
</span><span class="cx">                                 C95984F41E36BC6B002C0D45 /* autoplay-check.html in Copy Resources */,
</span><span class="cx">                                 C95984F51E36BC6B002C0D45 /* autoplay-no-audio-check.html in Copy Resources */,
</span><span class="lines">@@ -1284,6 +1286,7 @@
</span><span class="cx">                 C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;js-play-with-controls.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;no-autoplay-with-controls.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;video-with-muted-audio-and-webaudio.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 CD5393C71757BA9700C07123 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD5393C91757BAC400C07123 /* SHA1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SHA1.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD5451E919E41F9D0016936F /* CSSParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSParser.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -2235,6 +2238,7 @@
</span><span class="cx">                                 CDC8E48B1BC5C96200594FEC /* video-without-audio.html */,
</span><span class="cx">                                 CDC8E48C1BC5C96200594FEC /* video-without-audio.mp4 */,
</span><span class="cx">                                 CDB411591E09DA8E00EAD352 /* video-with-muted-audio.html */,
</span><ins>+                                CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = Resources;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitiosAudioSessionCategoryIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm (211239 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm        2017-01-27 00:14:50 UTC (rev 211239)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -97,6 +97,14 @@
</span><span class="cx">     Util::run(&amp;didBeginPlaying);
</span><span class="cx"> 
</span><span class="cx">     EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
</span><ins>+
+    didBeginPlaying = false;
+
+    [uiWebView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;video-with-muted-audio-and-webaudio&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]]];
+
+    Util::run(&amp;didBeginPlaying);
+
+    EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitiosvideowithmutedaudioandwebaudiohtml"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html (0 => 211240)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html        2017-01-27 00:38:22 UTC (rev 211240)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+    &lt;head&gt;
+        &lt;script&gt;
+        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) { }
+        }
+        &lt;/script&gt;
+    &lt;/head&gt;
+    &lt;body onload=&quot;go()&quot;&gt;
+        &lt;video src=&quot;video-with-audio.mp4&quot; muted webkit-playsinline&gt;&lt;/video&gt;
+    &lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre>
</div>
</div>

</body>
</html>