<!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>[266121] 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/266121">266121</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2020-08-25 09:15:32 -0700 (Tue, 25 Aug 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>[macOS] Update audio arbitration manager when audio transport changes
https://bugs.webkit.org/show_bug.cgi?id=215781
<rdar://problem/65920613>

Reviewed by Jer Noble.

Source/WebCore:

No new tests, updated AudioRoutingArbitration API test.

* platform/audio/AudioSession.cpp:
(WebCore::AudioSession::audioOutputDeviceChanged): Add empty method.
(WebCore::setIsPlayingToBluetoothOverride): Ditto.
* platform/audio/AudioSession.h:

* platform/audio/cocoa/MediaSessionManagerCocoa.h:
* platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(WebCore::MediaSessionManagerCocoa::audioOutputDeviceChanged): Call AudioSession::audioOutputDeviceChanged.

* platform/audio/mac/AudioSessionMac.mm:
(WebCore::defaultDeviceTransportIsBluetooth): New.
(WebCore::AudioSession::audioOutputDeviceChanged): Clear m_private->playingToBluetooth
if bluetooth transport has changed since the last arbitration update.
(WebCore::AudioSession::setIsPlayingToBluetoothOverride): Allow override of bluetooth
transport for testing.
(WebCore::AudioSession::setCategory): Update routing arbitration if audio session category
or bluetooth transport changes.

* testing/Internals.cpp:
(WebCore::Internals::setIsPlayingToBluetoothOverride):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

* UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _audioRoutingArbitrationUpdateTime]):

* UIProcess/Media/AudioSessionRoutingArbitratorProxy.h:
(WebKit::AudioSessionRoutingArbitratorProxy::arbitrationUpdateTime const):

* UIProcess/Media/cocoa/AudioSessionRoutingArbitratorProxyCocoa.mm:
(WebKit::AudioSessionRoutingArbitratorProxy::beginRoutingArbitrationWithCategory):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/AudioRoutingArbitration.mm:
(AudioRoutingArbitration::statusShouldBecomeEqualTo): Add message string to help
debugging when the test fails.
* TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-audio.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioAudioSessioncpp">trunk/Source/WebCore/platform/audio/AudioSession.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioAudioSessionh">trunk/Source/WebCore/platform/audio/AudioSession.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiococoaMediaSessionManagerCocoah">trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiococoaMediaSessionManagerCocoamm">trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiomacAudioSessionMacmm">trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsidl">trunk/Source/WebCore/testing/Internals.idl</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewPrivateForTestingh">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewTestingmm">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessMediaAudioSessionRoutingArbitratorProxyh">trunk/Source/WebKit/UIProcess/Media/AudioSessionRoutingArbitratorProxy.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessMediacocoaAudioSessionRoutingArbitratorProxyCocoamm">trunk/Source/WebKit/UIProcess/Media/cocoa/AudioSessionRoutingArbitratorProxyCocoa.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaAudioRoutingArbitrationmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AudioRoutingArbitration.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitLegacyiosvideowithaudiohtml">trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-audio.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/ChangeLog      2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2020-08-25  Eric Carlson  <eric.carlson@apple.com>
+
+        [macOS] Update audio arbitration manager when audio transport changes
+        https://bugs.webkit.org/show_bug.cgi?id=215781
+        <rdar://problem/65920613>
+
+        Reviewed by Jer Noble.
+
+        No new tests, updated AudioRoutingArbitration API test.
+
+        * platform/audio/AudioSession.cpp:
+        (WebCore::AudioSession::audioOutputDeviceChanged): Add empty method.
+        (WebCore::setIsPlayingToBluetoothOverride): Ditto.
+        * platform/audio/AudioSession.h:
+
+        * platform/audio/cocoa/MediaSessionManagerCocoa.h:
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+        (WebCore::MediaSessionManagerCocoa::audioOutputDeviceChanged): Call AudioSession::audioOutputDeviceChanged.
+
+        * platform/audio/mac/AudioSessionMac.mm:
+        (WebCore::defaultDeviceTransportIsBluetooth): New.
+        (WebCore::AudioSession::audioOutputDeviceChanged): Clear m_private->playingToBluetooth
+        if bluetooth transport has changed since the last arbitration update.
+        (WebCore::AudioSession::setIsPlayingToBluetoothOverride): Allow override of bluetooth
+        transport for testing.
+        (WebCore::AudioSession::setCategory): Update routing arbitration if audio session category
+        or bluetooth transport changes.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::setIsPlayingToBluetoothOverride):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
</ins><span class="cx"> 2020-08-25  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Generated bindings for derived dictionaries are not regenerated when the base dictionary changes
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioAudioSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/AudioSession.cpp (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/AudioSession.cpp     2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/platform/audio/AudioSession.cpp        2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -163,6 +163,19 @@
</span><span class="cx"> 
</span><span class="cx"> #endif // !PLATFORM(COCOA)
</span><span class="cx"> 
</span><ins>+#if !PLATFORM(MAC)
+void AudioSession::audioOutputDeviceChanged()
+{
+    notImplemented();
+}
+
+void AudioSession::setIsPlayingToBluetoothOverride(Optional<bool>)
+{
+    notImplemented();
+}
+#endif // !PLATFORM(COCOA)
+
+
</ins><span class="cx"> String convertEnumerationToString(RouteSharingPolicy enumerationValue)
</span><span class="cx"> {
</span><span class="cx">     static const NeverDestroyed<String> values[] = {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioAudioSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/AudioSession.h (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/AudioSession.h       2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/platform/audio/AudioSession.h  2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -97,6 +97,9 @@
</span><span class="cx">     void addMutedStateObserver(MutedStateObserver*);
</span><span class="cx">     void removeMutedStateObserver(MutedStateObserver*);
</span><span class="cx"> 
</span><ins>+    void audioOutputDeviceChanged();
+    void setIsPlayingToBluetoothOverride(Optional<bool>);
+
</ins><span class="cx">     virtual bool isMuted() const;
</span><span class="cx">     virtual void handleMutedStateChange();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiococoaMediaSessionManagerCocoah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h     2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h        2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -96,7 +96,7 @@
</span><span class="cx">     // AudioHardwareListenerClient
</span><span class="cx">     void audioHardwareDidBecomeActive() final { }
</span><span class="cx">     void audioHardwareDidBecomeInactive() final { }
</span><del>-    void audioOutputDeviceChanged() final { updateSessionState(); }
</del><ins>+    void audioOutputDeviceChanged() final;
</ins><span class="cx"> 
</span><span class="cx">     // PAL::SystemSleepListener
</span><span class="cx">     void systemWillSleep() final { processSystemWillSleep(); }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiococoaMediaSessionManagerCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm    2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm       2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -366,6 +366,12 @@
</span><span class="cx">     END_BLOCK_OBJC_EXCEPTIONS
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MediaSessionManagerCocoa::audioOutputDeviceChanged()
+{
+    AudioSession::sharedSession().audioOutputDeviceChanged();
+    updateSessionState();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // USE(AUDIO_SESSION) && PLATFORM(COCOA)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiomacAudioSessionMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm       2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm  2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -54,6 +54,28 @@
</span><span class="cx">     return deviceID;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(ROUTING_ARBITRATION)
+static Optional<bool> isPlayingToBluetoothOverride;
+
+static float defaultDeviceTransportIsBluetooth()
+{
+    if (isPlayingToBluetoothOverride)
+        return *isPlayingToBluetoothOverride;
+
+    static const AudioObjectPropertyAddress audioDeviceTransportTypeProperty = {
+        kAudioDevicePropertyTransportType,
+        kAudioObjectPropertyScopeGlobal,
+        kAudioObjectPropertyElementMaster,
+    };
+    UInt32 transportType = kAudioDeviceTransportTypeUnknown;
+    UInt32 transportSize = sizeof(transportType);
+    if (AudioObjectGetPropertyData(defaultDevice(), &audioDeviceTransportTypeProperty, 0, 0, &transportSize, &transportType))
+        return false;
+
+    return transportType == kAudioDeviceTransportTypeBluetooth || transportType == kAudioDeviceTransportTypeBluetoothLE;
+}
+#endif
+
</ins><span class="cx"> class AudioSessionPrivate {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="lines">@@ -62,6 +84,8 @@
</span><span class="cx">     AudioSession::CategoryType category { AudioSession::None };
</span><span class="cx"> #if ENABLE(ROUTING_ARBITRATION)
</span><span class="cx">     bool setupArbitrationOngoing { false };
</span><ins>+    Optional<bool> playingToBluetooth;
+    Optional<bool> playingToBluetoothOverride;
</ins><span class="cx"> #endif
</span><span class="cx">     AudioSession::CategoryType m_categoryOverride;
</span><span class="cx">     bool inRoutingArbitration { false };
</span><span class="lines">@@ -79,11 +103,32 @@
</span><span class="cx">     return m_private->category;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void AudioSession::audioOutputDeviceChanged()
+{
+#if ENABLE(ROUTING_ARBITRATION)
+    if (!m_private->playingToBluetooth || *m_private->playingToBluetooth == defaultDeviceTransportIsBluetooth())
+        return;
+
+    m_private->playingToBluetooth = WTF::nullopt;
+#endif
+}
+
+void AudioSession::setIsPlayingToBluetoothOverride(Optional<bool> value)
+{
+#if ENABLE(ROUTING_ARBITRATION)
+    isPlayingToBluetoothOverride = value;
+#else
+    UNUSED_PARAM(value);
+#endif
+}
+
</ins><span class="cx"> void AudioSession::setCategory(CategoryType category, RouteSharingPolicy)
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(ROUTING_ARBITRATION)
</span><del>-    if (category == m_private->category)
</del><ins>+    bool playingToBluetooth = defaultDeviceTransportIsBluetooth();
+    if (category == m_private->category && m_private->playingToBluetooth && *m_private->playingToBluetooth == playingToBluetooth)
</ins><span class="cx">         return;
</span><ins>+
</ins><span class="cx">     m_private->category = category;
</span><span class="cx"> 
</span><span class="cx">     if (m_private->setupArbitrationOngoing) {
</span><span class="lines">@@ -105,6 +150,7 @@
</span><span class="cx">     using RoutingArbitrationError = AudioSessionRoutingArbitrationClient::RoutingArbitrationError;
</span><span class="cx">     using DefaultRouteChanged = AudioSessionRoutingArbitrationClient::DefaultRouteChanged;
</span><span class="cx"> 
</span><ins>+    m_private->playingToBluetooth = playingToBluetooth;
</ins><span class="cx">     m_private->setupArbitrationOngoing = true;
</span><span class="cx">     m_routingArbitrationClient->beginRoutingArbitrationWithCategory(m_private->category, [this] (RoutingArbitrationError error, DefaultRouteChanged defaultRouteChanged) {
</span><span class="cx">         m_private->setupArbitrationOngoing = false;
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp       2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/testing/Internals.cpp  2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -4936,6 +4936,17 @@
</span><span class="cx"> 
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+ExceptionOr<void> Internals::setIsPlayingToBluetoothOverride(Optional<bool> isPlaying)
+{
+#if ENABLE(ROUTING_ARBITRATION)
+    AudioSession::sharedSession().setIsPlayingToBluetoothOverride(isPlaying);
+    return { };
+#else
+    UNUSED_PARAM(isPlaying);
+    return Exception { NotSupportedError };
+#endif
+}
+
</ins><span class="cx"> void Internals::reportBacktrace()
</span><span class="cx"> {
</span><span class="cx">     WTFReportBacktrace();
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h 2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/testing/Internals.h    2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -623,6 +623,8 @@
</span><span class="cx">     double privatePlayerVolume(const HTMLMediaElement&);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    ExceptionOr<void> setIsPlayingToBluetoothOverride(Optional<bool>);
+
</ins><span class="cx">     bool isSelectPopupVisible(HTMLSelectElement&);
</span><span class="cx"> 
</span><span class="cx">     ExceptionOr<String> captionsStyleSheetOverride();
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl       2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebCore/testing/Internals.idl  2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -651,6 +651,8 @@
</span><span class="cx">     [Conditional=VIDEO] DOMString elementBufferingPolicy(HTMLMediaElement media);
</span><span class="cx">     [Conditional=VIDEO] double privatePlayerVolume(HTMLMediaElement media);
</span><span class="cx"> 
</span><ins>+    [MayThrowException] void setIsPlayingToBluetoothOverride(optional boolean? isPlaying = null);
+
</ins><span class="cx">     [Conditional=LEGACY_ENCRYPTED_MEDIA] void initializeMockCDM();
</span><span class="cx">     [Conditional=ENCRYPTED_MEDIA] MockCDMFactory registerMockCDM();
</span><span class="cx">     void enableMockMediaCapabilities();
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebKit/ChangeLog       2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2020-08-25  Eric Carlson  <eric.carlson@apple.com>
+
+        [macOS] Update audio arbitration manager when audio transport changes
+        https://bugs.webkit.org/show_bug.cgi?id=215781
+        <rdar://problem/65920613>
+
+        Reviewed by Jer Noble.
+
+        * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
+        * UIProcess/API/Cocoa/WKWebViewTesting.mm:
+        (-[WKWebView _audioRoutingArbitrationUpdateTime]):
+
+        * UIProcess/Media/AudioSessionRoutingArbitratorProxy.h:
+        (WebKit::AudioSessionRoutingArbitratorProxy::arbitrationUpdateTime const):
+
+        * UIProcess/Media/cocoa/AudioSessionRoutingArbitratorProxyCocoa.mm:
+        (WebKit::AudioSessionRoutingArbitratorProxy::beginRoutingArbitrationWithCategory):
+
</ins><span class="cx"> 2020-08-25  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add support for MediaRecorder bitrate options
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewPrivateForTestingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h     2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h        2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -74,4 +74,5 @@
</span><span class="cx"> 
</span><span class="cx"> - (BOOL)_hasSleepDisabler;
</span><span class="cx"> - (WKWebViewAudioRoutingArbitrationStatus)_audioRoutingArbitrationStatus;
</span><ins>+- (double)_audioRoutingArbitrationUpdateTime;
</ins><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewTestingmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm      2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm 2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -262,4 +262,13 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (double)_audioRoutingArbitrationUpdateTime
+{
+#if ENABLE(ROUTING_ARBITRATION)
+    return _page->process().audioSessionRoutingArbitrator().arbitrationUpdateTime().secondsSinceEpoch().seconds();
+#else
+    return 0;
+#endif
+}
+
</ins><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessMediaAudioSessionRoutingArbitratorProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/Media/AudioSessionRoutingArbitratorProxy.h (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/Media/AudioSessionRoutingArbitratorProxy.h 2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebKit/UIProcess/Media/AudioSessionRoutingArbitratorProxy.h    2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include "MessageReceiver.h"
</span><span class="cx"> #include <WebCore/AudioSession.h>
</span><ins>+#include <wtf/WallTime.h>
</ins><span class="cx"> #include <wtf/WeakPtr.h>
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -59,6 +60,7 @@
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     ArbitrationStatus arbitrationStatus() const { return m_arbitrationStatus; }
</span><ins>+    WallTime arbitrationUpdateTime() const { return m_arbitrationUpdateTime; }
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     // IPC::MessageReceiver
</span><span class="lines">@@ -71,6 +73,7 @@
</span><span class="cx">     WebProcessProxy& m_process;
</span><span class="cx">     WebCore::AudioSession::CategoryType m_category { WebCore::AudioSession::None };
</span><span class="cx">     ArbitrationStatus m_arbitrationStatus { ArbitrationStatus::None };
</span><ins>+    WallTime m_arbitrationUpdateTime;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessMediacocoaAudioSessionRoutingArbitratorProxyCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/Media/cocoa/AudioSessionRoutingArbitratorProxyCocoa.mm (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/Media/cocoa/AudioSessionRoutingArbitratorProxyCocoa.mm     2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Source/WebKit/UIProcess/Media/cocoa/AudioSessionRoutingArbitratorProxyCocoa.mm        2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -178,6 +178,7 @@
</span><span class="cx"> {
</span><span class="cx">     m_category = category;
</span><span class="cx">     m_arbitrationStatus = ArbitrationStatus::Pending;
</span><ins>+    m_arbitrationUpdateTime = WallTime::now();
</ins><span class="cx">     SharedArbitrator::sharedInstance().beginRoutingArbitrationForArbitrator(*this, [weakThis = makeWeakPtr(*this), callback = WTFMove(callback)] (RoutingArbitrationError error, DefaultRouteChanged routeChanged) mutable {
</span><span class="cx">         if (weakThis)
</span><span class="cx">             weakThis->m_arbitrationStatus = error == RoutingArbitrationError::None ? ArbitrationStatus::Active : ArbitrationStatus::None;
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Tools/ChangeLog       2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2020-08-25  Eric Carlson  <eric.carlson@apple.com>
+
+        [macOS] Update audio arbitration manager when audio transport changes
+        https://bugs.webkit.org/show_bug.cgi?id=215781
+        <rdar://problem/65920613>
+
+        Reviewed by Jer Noble.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/AudioRoutingArbitration.mm:
+        (AudioRoutingArbitration::statusShouldBecomeEqualTo): Add message string to help
+        debugging when the test fails.
+        * TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-audio.html:
+
</ins><span class="cx"> 2020-08-25  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Generated bindings for derived dictionaries are not regenerated when the base dictionary changes
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaAudioRoutingArbitrationmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AudioRoutingArbitration.mm (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AudioRoutingArbitration.mm   2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AudioRoutingArbitration.mm      2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #import <WebKit/WKWebViewConfigurationPrivate.h>
</span><span class="cx"> #import <WebKit/WKWebViewPrivate.h>
</span><span class="cx"> #import <WebKit/WKWebViewPrivateForTesting.h>
</span><ins>+#import <wtf/WallTime.h>
</ins><span class="cx"> 
</span><span class="cx"> class AudioRoutingArbitration : public testing::Test {
</span><span class="cx"> public:
</span><span class="lines">@@ -41,6 +42,8 @@
</span><span class="cx">     void SetUp() final
</span><span class="cx">     {
</span><span class="cx">         auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
</span><ins>+        WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+        configuration.get().processPool = (WKProcessPool *)context.get();
</ins><span class="cx">         configuration.get()._mediaDataLoadsAutomatically = YES;
</span><span class="cx">         configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
</span><span class="cx">         webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:configuration.get() addToWindow:YES]);
</span><span class="lines">@@ -56,7 +59,7 @@
</span><span class="cx">         [webView _close];
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatus status)
</del><ins>+    void statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatus status, const char* message)
</ins><span class="cx">     {
</span><span class="cx">         int tries = 0;
</span><span class="cx">         do {
</span><span class="lines">@@ -66,54 +69,86 @@
</span><span class="cx">             TestWebKitAPI::Util::sleep(0.1);
</span><span class="cx">         } while (++tries <= 100);
</span><span class="cx"> 
</span><del>-        EXPECT_EQ(status, [webView _audioRoutingArbitrationStatus]);
</del><ins>+        EXPECT_EQ(status, [webView _audioRoutingArbitrationStatus]) << message;
</ins><span class="cx">     }
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> TEST_F(AudioRoutingArbitration, Basic)
</span><span class="cx"> {
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Basic");
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST_F(AudioRoutingArbitration, Mute)
</span><span class="cx"> {
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Mute 1");
</ins><span class="cx"> 
</span><span class="cx">     [webView objectByEvaluatingJavaScriptWithUserGesture:@"document.querySelector('video').muted = true"];
</span><span class="cx"> 
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusNone);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusNone, "Mute 2");
</ins><span class="cx"> 
</span><span class="cx">     [webView objectByEvaluatingJavaScriptWithUserGesture:@"document.querySelector('video').muted = false"];
</span><span class="cx"> 
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Mute 3");
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST_F(AudioRoutingArbitration, Navigation)
</span><span class="cx"> {
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Navigation 1");
</ins><span class="cx"> 
</span><span class="cx">     [webView synchronouslyLoadHTMLString:@"<html>no contents</html>"];
</span><span class="cx"> 
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusNone);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusNone, "Navigation 2");
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST_F(AudioRoutingArbitration, Deletion)
</span><span class="cx"> {
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Deletion 1");
</ins><span class="cx"> 
</span><span class="cx">     [webView objectByEvaluatingJavaScriptWithUserGesture:@"document.querySelector('video').parentNode.innerHTML = ''"];
</span><span class="cx"> 
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusNone);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusNone, "Deletion 2");
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST_F(AudioRoutingArbitration, Close)
</span><span class="cx"> {
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Close 1");
</ins><span class="cx"> 
</span><span class="cx">     [webView _close];
</span><span class="cx"> 
</span><del>-    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusNone);
</del><ins>+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusNone, "Close 2");
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST_F(AudioRoutingArbitration, Updating)
+{
+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Updating 1");
</ins><span class="cx"> 
</span><ins>+    [webView evaluateJavaScript:@"document.querySelector('video').pause()" completionHandler:nil];
+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Updating 2");
+
+    auto start = WallTime::now().secondsSinceEpoch().seconds();
+    auto arbitrationUpdateTime = [webView _audioRoutingArbitrationUpdateTime];
+    ASSERT_TRUE(arbitrationUpdateTime < start);
+
+    [webView evaluateJavaScript:@"document.querySelector('video').play()" completionHandler:nil];
+    EXPECT_EQ(arbitrationUpdateTime, [webView _audioRoutingArbitrationUpdateTime]) << "Arbitration was unexpectedly updated";
+    statusShouldBecomeEqualTo(WKWebViewAudioRoutingArbitrationStatusActive, "Updating 3");
+
+    [webView evaluateJavaScript:@"document.querySelector('video').pause()" completionHandler:nil];
+    [webView stringByEvaluatingJavaScript:@"window.internals.setIsPlayingToBluetoothOverride(true)"];
+
+    [webView evaluateJavaScript:@"document.querySelector('video').play()" completionHandler:nil];
+
+    int tries = 0;
+    do {
+        if ([webView _audioRoutingArbitrationUpdateTime] > arbitrationUpdateTime)
+            break;
+
+        TestWebKitAPI::Util::sleep(0.1);
+    } while (++tries <= 100);
+
+    EXPECT_LT(arbitrationUpdateTime, [webView _audioRoutingArbitrationUpdateTime]) << "Arbitration was not updated";
+
+    [webView stringByEvaluatingJavaScript:@"window.internals.setIsPlayingToBluetoothOverride()"];
+}
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitLegacyiosvideowithaudiohtml"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-audio.html (266120 => 266121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-audio.html   2020-08-25 16:08:21 UTC (rev 266120)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/video-with-audio.html      2020-08-25 16:15:32 UTC (rev 266121)
</span><span class="lines">@@ -2,8 +2,6 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script>
</span><del>-    var timeout;
-
</del><span class="cx">     function go() {
</span><span class="cx">         var video = document.getElementsByTagName('video')[0];
</span><span class="cx">         video.play().then(playing).catch(notPlaying);
</span><span class="lines">@@ -29,6 +27,16 @@
</span><span class="cx">         } catch(e) { }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    function pause() {
+        let video = document.getElementsByTagName('video')[0];
+        video.addEventListener("pause", paused, { once: true });
+        video.pause();
+    }
+
+    function play() {
+        go();
+    }
+
</ins><span class="cx">     document.addEventListener('pageshow', go);
</span><span class="cx">    </script>
</span><span class="cx"> </head>
</span></span></pre>
</div>
</div>

</body>
</html>