<!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>[215242] trunk/Source</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/215242">215242</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2017-04-11 11:27:01 -0700 (Tue, 11 Apr 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[MediaStream] Set correct audio session category when capturing audio
https://bugs.webkit.org/show_bug.cgi?id=170736
&lt;rdar://problem/31559405&gt;

Reviewed by Jer Noble.

Source/WebCore:

No new tests yet, filed bug 170737.

* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::MediaStream): Initialize m_mediaSession.
(WebCore::MediaStream::statusDidChange): Call canProduceAudioChanged.
(WebCore::MediaStream::mediaType): New. Return MediaStreamCapturingAudio when actively
capturing audio.
(WebCore::MediaStream::presentationType):
(WebCore::MediaStream::characteristics):
(WebCore::MediaStream::mayResumePlayback):
(WebCore::MediaStream::suspendPlayback):
(WebCore::MediaStream::sourceApplicationIdentifier):
(WebCore::MediaStream::canProduceAudio):
* Modules/mediastream/MediaStream.h:

* platform/audio/PlatformMediaSession.h: Add MediaStreamCapturingAudio.
* platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::has): Adjust assert for MediaStreamCapturingAudio.
(WebCore::PlatformMediaSessionManager::count): Ditto.
* platform/audio/cocoa/MediaSessionManagerCocoa.cpp:
(PlatformMediaSessionManager::updateSessionState): Set small preferred buffer size when
capturing audio. Set audio session category to PlayAndRecord whenever there is a media
stream that is capturing audio.

Source/WebKit2:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::isPlayingMediaDidChange):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediastreamMediaStreamcpp">trunk/Source/WebCore/Modules/mediastream/MediaStream.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediastreamMediaStreamh">trunk/Source/WebCore/Modules/mediastream/MediaStream.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioPlatformMediaSessionh">trunk/Source/WebCore/platform/audio/PlatformMediaSession.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioPlatformMediaSessionManagercpp">trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiococoaMediaSessionManagerCocoacpp">trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebCore/ChangeLog        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2017-04-11  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        [MediaStream] Set correct audio session category when capturing audio
+        https://bugs.webkit.org/show_bug.cgi?id=170736
+        &lt;rdar://problem/31559405&gt;
+
+        Reviewed by Jer Noble.
+
+        No new tests yet, filed bug 170737.
+
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::MediaStream): Initialize m_mediaSession.
+        (WebCore::MediaStream::statusDidChange): Call canProduceAudioChanged.
+        (WebCore::MediaStream::mediaType): New. Return MediaStreamCapturingAudio when actively
+        capturing audio.
+        (WebCore::MediaStream::presentationType):
+        (WebCore::MediaStream::characteristics):
+        (WebCore::MediaStream::mayResumePlayback):
+        (WebCore::MediaStream::suspendPlayback):
+        (WebCore::MediaStream::sourceApplicationIdentifier):
+        (WebCore::MediaStream::canProduceAudio):
+        * Modules/mediastream/MediaStream.h:
+
+        * platform/audio/PlatformMediaSession.h: Add MediaStreamCapturingAudio.
+        * platform/audio/PlatformMediaSessionManager.cpp:
+        (WebCore::PlatformMediaSessionManager::has): Adjust assert for MediaStreamCapturingAudio.
+        (WebCore::PlatformMediaSessionManager::count): Ditto.
+        * platform/audio/cocoa/MediaSessionManagerCocoa.cpp:
+        (PlatformMediaSessionManager::updateSessionState): Set small preferred buffer size when
+        capturing audio. Set audio session category to PlayAndRecord whenever there is a media
+        stream that is capturing audio.
+
</ins><span class="cx"> 2017-04-11  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WebCore][JSC] ResourceUsageData.{timeOfNextEdenCollection,timeOfNextFullCollection} should be MonotonicTime
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamMediaStreamcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/MediaStream.cpp (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediastream/MediaStream.cpp        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStream.cpp        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -33,9 +33,11 @@
</span><span class="cx"> #include &quot;Document.h&quot;
</span><span class="cx"> #include &quot;Event.h&quot;
</span><span class="cx"> #include &quot;EventNames.h&quot;
</span><ins>+#include &quot;Frame.h&quot;
</ins><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &quot;MediaStreamRegistry.h&quot;
</span><span class="cx"> #include &quot;MediaStreamTrackEvent.h&quot;
</span><ins>+#include &quot;NetworkingContext.h&quot;
</ins><span class="cx"> #include &quot;Page.h&quot;
</span><span class="cx"> #include &quot;RealtimeMediaSource.h&quot;
</span><span class="cx"> #include &quot;URL.h&quot;
</span><span class="lines">@@ -75,6 +77,7 @@
</span><span class="cx">     : ContextDestructionObserver(&amp;context)
</span><span class="cx">     , m_private(MediaStreamPrivate::create(createTrackPrivateVector(tracks)))
</span><span class="cx">     , m_activityEventTimer(*this, &amp;MediaStream::activityEventTimerFired)
</span><ins>+    , m_mediaSession(PlatformMediaSession::create(*this))
</ins><span class="cx"> {
</span><span class="cx">     // This constructor preserves MediaStreamTrack instances and must be used by calls originating
</span><span class="cx">     // from the JavaScript MediaStream constructor.
</span><span class="lines">@@ -94,6 +97,7 @@
</span><span class="cx">     : ContextDestructionObserver(&amp;context)
</span><span class="cx">     , m_private(WTFMove(streamPrivate))
</span><span class="cx">     , m_activityEventTimer(*this, &amp;MediaStream::activityEventTimerFired)
</span><ins>+    , m_mediaSession(PlatformMediaSession::create(*this))
</ins><span class="cx"> {
</span><span class="cx">     setIsActive(m_private-&gt;active());
</span><span class="cx">     if (document()-&gt;page() &amp;&amp; document()-&gt;page()-&gt;isMediaCaptureMuted())
</span><span class="lines">@@ -342,6 +346,8 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaStream::statusDidChange()
</span><span class="cx"> {
</span><ins>+    m_mediaSession-&gt;canProduceAudioChanged();
+
</ins><span class="cx">     if (Document* document = this-&gt;document()) {
</span><span class="cx">         if (m_isActive)
</span><span class="cx">             document-&gt;setHasActiveMediaStreamTrack();
</span><span class="lines">@@ -423,6 +429,63 @@
</span><span class="cx">     return downcast&lt;Document&gt;(scriptExecutionContext());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+PlatformMediaSession::MediaType MediaStream::mediaType() const
+{
+    // We only need to override the type when capturing audio, HTMLMediaElement and/or WebAudio
+    // will do the right thing when a stream is attached to a media element or an audio context.
+    if (m_private-&gt;hasAudio() &amp;&amp; m_private-&gt;isProducingData() &amp;&amp; m_private-&gt;hasCaptureAudioSource())
+        return PlatformMediaSession::MediaStreamCapturingAudio;
+
+    return PlatformMediaSession::None;
+}
+
+PlatformMediaSession::MediaType MediaStream::presentationType() const
+{
+    return mediaType();
+}
+
+PlatformMediaSession::CharacteristicsFlags MediaStream::characteristics() const
+{
+    PlatformMediaSession::CharacteristicsFlags state = PlatformMediaSession::HasNothing;
+
+    if (!m_private-&gt;isProducingData())
+        return state;
+
+    if (m_private-&gt;hasAudio())
+        state |= PlatformMediaSession::HasAudio;
+
+    if (m_private-&gt;hasVideo())
+        state |= PlatformMediaSession::HasVideo;
+
+    return state;
+}
+
+void MediaStream::mayResumePlayback(bool)
+{
+    // FIXME: should a media stream pay attention to this directly, or only when attached to a media element?
+}
+
+void MediaStream::suspendPlayback()
+{
+    // FIXME: should a media stream pay attention to this directly, or only when attached to a media element?
+}
+
+String MediaStream::sourceApplicationIdentifier() const
+{
+    Document* document = this-&gt;document();
+    if (document &amp;&amp; document-&gt;frame()) {
+        if (NetworkingContext* networkingContext = document-&gt;frame()-&gt;loader().networkingContext())
+            return networkingContext-&gt;sourceApplicationIdentifier();
+    }
+
+    return emptyString();
+}
+
+bool MediaStream::canProduceAudio() const
+{
+    return !muted() &amp;&amp; active() &amp;&amp; m_private-&gt;hasAudio() &amp;&amp; m_private-&gt;isProducingData();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(MEDIA_STREAM)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamMediaStreamh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/MediaStream.h (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediastream/MediaStream.h        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStream.h        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2011 Google Inc. All rights reserved.
</span><span class="cx">  * Copyright (C) 2011, 2015 Ericsson AB. All rights reserved.
</span><del>- * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> #include &quot;MediaProducer.h&quot;
</span><span class="cx"> #include &quot;MediaStreamPrivate.h&quot;
</span><span class="cx"> #include &quot;MediaStreamTrack.h&quot;
</span><ins>+#include &quot;PlatformMediaSession.h&quot;
</ins><span class="cx"> #include &quot;ScriptWrappable.h&quot;
</span><span class="cx"> #include &quot;Timer.h&quot;
</span><span class="cx"> #include &quot;URLRegistry.h&quot;
</span><span class="lines">@@ -55,6 +56,7 @@
</span><span class="cx">     , public MediaStreamPrivate::Observer
</span><span class="cx">     , private MediaProducer
</span><span class="cx">     , private MediaCanStartListener
</span><ins>+    , private PlatformMediaSessionClient
</ins><span class="cx">     , public RefCounted&lt;MediaStream&gt; {
</span><span class="cx"> public:
</span><span class="cx">     class Observer {
</span><span class="lines">@@ -134,6 +136,20 @@
</span><span class="cx">     // MediaCanStartListener
</span><span class="cx">     void mediaCanStart(Document&amp;) final;
</span><span class="cx"> 
</span><ins>+    // PlatformMediaSessionClient
+    PlatformMediaSession::MediaType mediaType() const final;
+    PlatformMediaSession::MediaType presentationType() const final;
+    PlatformMediaSession::CharacteristicsFlags characteristics() const final;
+    void mayResumePlayback(bool shouldResume) final;
+    void suspendPlayback() final;
+    bool canReceiveRemoteControlCommands() const final { return false; }
+    void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument*) final { }
+    bool supportsSeeking() const final { return false; }
+    bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const final { return false; }
+    String sourceApplicationIdentifier() const final;
+    bool canProduceAudio() const final;
+    const Document* hostingDocument() const final { return document(); }
+
</ins><span class="cx">     bool internalAddTrack(Ref&lt;MediaStreamTrack&gt;&amp;&amp;, StreamModifier);
</span><span class="cx">     bool internalRemoveTrack(const String&amp;, StreamModifier);
</span><span class="cx"> 
</span><span class="lines">@@ -154,6 +170,7 @@
</span><span class="cx">     Vector&lt;Ref&lt;Event&gt;&gt; m_scheduledActivityEvents;
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;Observer*&gt; m_observers;
</span><ins>+    std::unique_ptr&lt;PlatformMediaSession&gt; m_mediaSession;
</ins><span class="cx"> 
</span><span class="cx">     bool m_isActive { false };
</span><span class="cx">     bool m_isMuted { true };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioPlatformMediaSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -58,6 +58,7 @@
</span><span class="cx">         VideoAudio,
</span><span class="cx">         Audio,
</span><span class="cx">         WebAudio,
</span><ins>+        MediaStreamCapturingAudio,
</ins><span class="cx">     };
</span><span class="cx">     MediaType mediaType() const;
</span><span class="cx">     MediaType presentationType() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioPlatformMediaSessionManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx"> 
</span><span class="cx"> bool PlatformMediaSessionManager::has(PlatformMediaSession::MediaType type) const
</span><span class="cx"> {
</span><del>-    ASSERT(type &gt;= PlatformMediaSession::None &amp;&amp; type &lt;= PlatformMediaSession::WebAudio);
</del><ins>+    ASSERT(type &gt;= PlatformMediaSession::None &amp;&amp; type &lt;= PlatformMediaSession::MediaStreamCapturingAudio);
</ins><span class="cx"> 
</span><span class="cx">     return anyOfSessions([type] (PlatformMediaSession&amp; session, size_t) {
</span><span class="cx">         return session.mediaType() == type;
</span><span class="lines">@@ -96,7 +96,7 @@
</span><span class="cx"> 
</span><span class="cx"> int PlatformMediaSessionManager::count(PlatformMediaSession::MediaType type) const
</span><span class="cx"> {
</span><del>-    ASSERT(type &gt;= PlatformMediaSession::None &amp;&amp; type &lt;= PlatformMediaSession::WebAudio);
</del><ins>+    ASSERT(type &gt;= PlatformMediaSession::None &amp;&amp; type &lt;= PlatformMediaSession::MediaStreamCapturingAudio);
</ins><span class="cx"> 
</span><span class="cx">     int count = 0;
</span><span class="cx">     for (auto* session : m_sessions) {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiococoaMediaSessionManagerCocoacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx"> {
</span><span class="cx">     LOG(Media, &quot;PlatformMediaSessionManager::updateSessionState() - types: Video(%d), Audio(%d), WebAudio(%d)&quot;, count(PlatformMediaSession::Video), count(PlatformMediaSession::Audio), count(PlatformMediaSession::WebAudio));
</span><span class="cx"> 
</span><del>-    if (has(PlatformMediaSession::WebAudio))
</del><ins>+    if (has(PlatformMediaSession::WebAudio) || has(PlatformMediaSession::MediaStreamCapturingAudio))
</ins><span class="cx">         AudioSession::sharedSession().setPreferredBufferSize(kWebAudioBufferSize);
</span><span class="cx">     else if ((has(PlatformMediaSession::Video) || has(PlatformMediaSession::Audio)) &amp;&amp; Settings::lowPowerVideoAudioBufferSizeEnabled()) {
</span><span class="cx">         // FIXME: &lt;http://webkit.org/b/116725&gt; Figure out why enabling the code below
</span><span class="lines">@@ -62,14 +62,19 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     bool hasAudioMediaType = false;
</span><del>-    bool hasAudibleAudioOrVideoMediaType = anyOfSessions([this, hasAudioMediaType] (PlatformMediaSession&amp; session, size_t) mutable {
</del><ins>+    bool hasAudibleAudioOrVideoMediaType = false;
+    bool hasAudioCapture = anyOfSessions([this, hasAudioMediaType, hasAudibleAudioOrVideoMediaType] (PlatformMediaSession&amp; session, size_t) mutable {
</ins><span class="cx">         auto type = session.mediaType();
</span><span class="cx">         if (type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio || type == PlatformMediaSession::WebAudio)
</span><span class="cx">             hasAudioMediaType = true;
</span><del>-        return (type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio) &amp;&amp; session.canProduceAudio();
</del><ins>+        if ((type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio) &amp;&amp; session.canProduceAudio())
+            hasAudibleAudioOrVideoMediaType = true;
+        return (type == PlatformMediaSession::MediaStreamCapturingAudio);
</ins><span class="cx">     });
</span><span class="cx"> 
</span><del>-    if (hasAudibleAudioOrVideoMediaType)
</del><ins>+    if (hasAudioCapture)
+        AudioSession::sharedSession().setCategory(AudioSession::PlayAndRecord);
+    else if (hasAudibleAudioOrVideoMediaType)
</ins><span class="cx">         AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
</span><span class="cx">     else if (hasAudioMediaType)
</span><span class="cx">         AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebCore/testing/Internals.cpp        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -3201,6 +3201,8 @@
</span><span class="cx">         return PlatformMediaSession::VideoAudio;
</span><span class="cx">     if (equalLettersIgnoringASCIICase(mediaTypeString, &quot;webaudio&quot;))
</span><span class="cx">         return PlatformMediaSession::WebAudio;
</span><ins>+    if (equalLettersIgnoringASCIICase(mediaTypeString, &quot;mediastreamcapturingaudio&quot;))
+        return PlatformMediaSession::MediaStreamCapturingAudio;
</ins><span class="cx"> 
</span><span class="cx">     return PlatformMediaSession::None;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebKit2/ChangeLog        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2017-04-11  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        [MediaStream] Set correct audio session category when capturing audio
+        https://bugs.webkit.org/show_bug.cgi?id=170736
+        &lt;rdar://problem/31559405&gt;
+
+        Reviewed by Jer Noble.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::isPlayingMediaDidChange):
+
</ins><span class="cx"> 2017-04-11  Youenn Fablet  &lt;youenn@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Activate WebRTC data channel tests for WK1
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (215241 => 215242)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2017-04-11 18:25:42 UTC (rev 215241)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2017-04-11 18:27:01 UTC (rev 215242)
</span><span class="lines">@@ -6446,7 +6446,7 @@
</span><span class="cx">     if (state == m_mediaState)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    WebCore::MediaProducer::MediaStateFlags activeCaptureMask = WebCore::MediaProducer::HasActiveAudioCaptureDevice | WebCore::MediaProducer::HasActiveVideoCaptureDevice;
</del><ins>+    WebCore::MediaProducer::MediaStateFlags activeCaptureMask = WebCore::MediaProducer::HasActiveAudioCaptureDevice | WebCore::MediaProducer::HasActiveVideoCaptureDevice | WebCore::MediaProducer::HasMutedAudioCaptureDevice | WebCore::MediaProducer::HasMutedVideoCaptureDevice;
</ins><span class="cx"> #if ENABLE(MEDIA_STREAM)
</span><span class="cx">     WebCore::MediaProducer::MediaStateFlags oldMediaStateHasActiveCapture = m_mediaState &amp; activeCaptureMask;
</span><span class="cx">     WebCore::MediaProducer::MediaStateFlags newMediaStateHasActiveCapture = state &amp; activeCaptureMask;
</span></span></pre>
</div>
</div>

</body>
</html>