<!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>[217775] 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/217775">217775</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2017-06-04 13:56:58 -0700 (Sun, 04 Jun 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[MediaStream] Page capture state not reported correctly
https://bugs.webkit.org/show_bug.cgi?id=172897
<rdar://problem/32493318>

Reviewed by Youenn Fablet.

Source/WebCore:

Test: fast/mediastream/media-stream-track-muted.html

* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::mediaState): Test for audio and video mute on the tracks.
(WebCore::MediaStream::characteristicsChanged): Call statusDidChange when m_mediaState
changes instead of m_muted, so the page is informed when just audio or video mute state
changes.
* Modules/mediastream/MediaStream.h:

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

LayoutTests:

* fast/mediastream/media-stream-track-muted-expected.txt: Added.
* fast/mediastream/media-stream-track-muted.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<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="#trunkSourceWebCoreplatformmediastreamMediaStreamPrivatecpp">trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp</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>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastmediastreammediastreamtrackmutedexpectedtxt">trunk/LayoutTests/fast/mediastream/media-stream-track-muted-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastmediastreammediastreamtrackmutedhtml">trunk/LayoutTests/fast/mediastream/media-stream-track-muted.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (217774 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2017-06-04 18:19:16 UTC (rev 217774)
+++ trunk/LayoutTests/ChangeLog 2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2017-06-04  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Page capture state not reported correctly
+        https://bugs.webkit.org/show_bug.cgi?id=172897
+        <rdar://problem/32493318>
+
+        Reviewed by Youenn Fablet.
+
+        * fast/mediastream/media-stream-track-muted-expected.txt: Added.
+        * fast/mediastream/media-stream-track-muted.html: Added.
+
</ins><span class="cx"> 2017-06-03  Sam Weinig  <sam@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Can't use Object.defineProperty() to add an item to a DOMStringMap or Storage
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreammediastreamtrackmutedexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/media-stream-track-muted-expected.txt (0 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/media-stream-track-muted-expected.txt                         (rev 0)
+++ trunk/LayoutTests/fast/mediastream/media-stream-track-muted-expected.txt    2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+
+PASS Create stream 
+PASS Mute video track only 
+PASS Mute audio track only 
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastmediastreammediastreamtrackmutedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/media-stream-track-muted.html (0 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/media-stream-track-muted.html                         (rev 0)
+++ trunk/LayoutTests/fast/mediastream/media-stream-track-muted.html    2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -0,0 +1,79 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>Mute video and audio tracks independently, make sure page state updates correctly.</title>
+    <script src="../../resources/testharness.js"></script>
+    <script src="../../resources/testharnessreport.js"></script>
+    <script>
+
+    if (window.testRunner)
+        testRunner.setUserMediaPermission(true);
+
+    function waitForPageStateChange(numberOfTries, originalState, resolve, reject)
+    {
+        let newState = internals.pageMediaState();
+        if (newState != originalState) {
+            resolve(newState);
+            return;
+        }
+
+        if (numberOfTries <= 0) {
+            reject('Page state did not change in time.');
+            return;
+        }
+
+        setTimeout(() => { waitForPageStateChange(--numberOfTries, originalState, resolve, reject); }, 10);
+    }
+
+    function testTrack(track, title)
+    {
+        promise_test((test) => {
+            return new Promise((resolve, reject) => {
+                let isVideo = track.kind == "video";
+                if (window.internals) {
+                    assert_false(internals.pageMediaState().includes('HasMutedVideoCaptureDevice'));
+                    assert_false(internals.pageMediaState().includes('HasMutedAudioCaptureDevice'));
+                }
+
+                track.onunmute = () => reject("Got 'unmute' event unexpectedly!");
+                track.onmute = () => {
+                    new Promise((innerResolve, innerReject) => {
+                        waitForPageStateChange(10, internals.pageMediaState(), innerResolve, innerReject)
+                    }).then((pageMediaState) => {
+
+                        track.onunmute = (evt) => {
+                            waitForPageStateChange(10, internals.pageMediaState(), resolve, reject)
+                        }
+
+                        if (window.internals) {
+                            assert_true(pageMediaState.includes(isVideo ? 'HasMutedVideoCaptureDevice' : 'HasMutedAudioCaptureDevice'));
+                            assert_false(pageMediaState.includes(isVideo ? 'HasMutedAudioCaptureDevice' : 'HasMutedVideoCaptureDevice'));
+                            assert_true(pageMediaState.includes(isVideo ? 'HasActiveAudioCaptureDevice' : 'HasActiveVideoCaptureDevice'));
+                            assert_false(pageMediaState.includes(isVideo ? 'HasActiveVideoCaptureDevice' : 'HasActiveAudioCaptureDevice'));
+                            internals.setMediaStreamTrackMuted(track, false)
+                        }
+                    })
+                }
+
+                if (window.internals)
+                    internals.setMediaStreamTrackMuted(track, true);
+                setTimeout(() => reject("Muted state did not change in .5 second"), 500);
+            });
+        }, title);
+    }
+
+    promise_test((test) => {
+        return navigator.mediaDevices.getUserMedia({ video: true, audio: true})
+            .then((stream) => {
+                testTrack(stream.getVideoTracks()[0], "Mute video track only");
+                testTrack(stream.getAudioTracks()[0], "Mute audio track only");
+            });
+    }, "Create stream");
+
+
+    </script>
+</head>
+<body>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (217774 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-06-04 18:19:16 UTC (rev 217774)
+++ trunk/Source/WebCore/ChangeLog      2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2017-06-04  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Page capture state not reported correctly
+        https://bugs.webkit.org/show_bug.cgi?id=172897
+        <rdar://problem/32493318>
+
+        Reviewed by Youenn Fablet.
+
+        Test: fast/mediastream/media-stream-track-muted.html
+
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::mediaState): Test for audio and video mute on the tracks.
+        (WebCore::MediaStream::characteristicsChanged): Call statusDidChange when m_mediaState
+        changes instead of m_muted, so the page is informed when just audio or video mute state
+        changes.
+        * Modules/mediastream/MediaStream.h:
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::setMediaStreamTrackMuted): New.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
</ins><span class="cx"> 2017-06-03  Darin Adler  <darin@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Streamline handling of attributes, using references as much as possible
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamMediaStreamcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/MediaStream.cpp (217774 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediastream/MediaStream.cpp 2017-06-04 18:19:16 UTC (rev 217774)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStream.cpp    2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -341,20 +341,17 @@
</span><span class="cx">     if (!m_isActive)
</span><span class="cx">         return state;
</span><span class="cx"> 
</span><del>-    if (m_private->hasAudio()) {
-        state |= HasAudioOrVideo;
-        if (m_private->hasCaptureAudioSource()) {
-            if (m_private->muted())
</del><ins>+    for (const auto& track : m_trackSet.values()) {
+        if (!track->isCaptureTrack() || track->ended())
+            continue;
+
+        if (track->source().type() == RealtimeMediaSource::Type::Audio) {
+            if (track->muted())
</ins><span class="cx">                 state |= HasMutedAudioCaptureDevice;
</span><span class="cx">             else if (m_isProducingData && m_private->isProducingData())
</span><span class="cx">                 state |= HasActiveAudioCaptureDevice;
</span><del>-        }
-    }
-
-    if (m_private->hasVideo()) {
-        state |= HasAudioOrVideo;
-        if (m_private->hasCaptureVideoSource()) {
-            if (m_private->muted())
</del><ins>+        } else {
+            if (track->muted())
</ins><span class="cx">                 state |= HasMutedVideoCaptureDevice;
</span><span class="cx">             else if (m_isProducingData && m_private->isProducingData())
</span><span class="cx">                 state |= HasActiveVideoCaptureDevice;
</span><span class="lines">@@ -377,9 +374,9 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaStream::characteristicsChanged()
</span><span class="cx"> {
</span><del>-    bool muted = m_private->muted();
-    if (m_isMuted != muted) {
-        m_isMuted = muted;
</del><ins>+    MediaStateFlags state = mediaState();
+    if (m_state != state) {
+        m_state = state;
</ins><span class="cx">         statusDidChange();
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamMediaStreamh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/MediaStream.h (217774 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediastream/MediaStream.h   2017-06-04 18:19:16 UTC (rev 217774)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStream.h      2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -84,7 +84,7 @@
</span><span class="cx">     RefPtr<MediaStream> clone();
</span><span class="cx"> 
</span><span class="cx">     bool active() const { return m_isActive; }
</span><del>-    bool muted() const { return m_isMuted; }
</del><ins>+    bool muted() const { return m_private->muted(); }
</ins><span class="cx"> 
</span><span class="cx">     MediaStreamPrivate& privateStream() { return m_private.get(); }
</span><span class="cx"> 
</span><span class="lines">@@ -175,8 +175,9 @@
</span><span class="cx">     Vector<Observer*> m_observers;
</span><span class="cx">     std::unique_ptr<PlatformMediaSession> m_mediaSession;
</span><span class="cx"> 
</span><ins>+    MediaStateFlags m_state { IsNotPlaying };
+
</ins><span class="cx">     bool m_isActive { false };
</span><del>-    bool m_isMuted { true };
</del><span class="cx">     bool m_isProducingData { false };
</span><span class="cx">     bool m_isWaitingUntilMediaCanStart { false };
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamMediaStreamPrivatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp (217774 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp 2017-06-04 18:19:16 UTC (rev 217774)
+++ trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp    2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -137,6 +137,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     updateActiveState(notifyClientOption);
</span><ins>+    characteristicsChanged();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaStreamPrivate::removeTrack(MediaStreamTrackPrivate& track, NotifyClientOption notifyClientOption)
</span><span class="lines">@@ -152,6 +153,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     updateActiveState(NotifyClientOption::Notify);
</span><ins>+    characteristicsChanged();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaStreamPrivate::startProducingData()
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (217774 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp       2017-06-04 18:19:16 UTC (rev 217774)
+++ trunk/Source/WebCore/testing/Internals.cpp  2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -4088,6 +4088,11 @@
</span><span class="cx">     track.source().delaySamples(delay);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Internals::setMediaStreamTrackMuted(MediaStreamTrack& track, bool muted)
+{
+    track.source().setMuted(muted);
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (217774 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h 2017-06-04 18:19:16 UTC (rev 217774)
+++ trunk/Source/WebCore/testing/Internals.h    2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -582,6 +582,7 @@
</span><span class="cx">     using TrackFramePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
</span><span class="cx">     void grabNextMediaStreamTrackFrame(TrackFramePromise&&);
</span><span class="cx">     void delayMediaStreamTrackSamples(MediaStreamTrack&, float);
</span><ins>+    void setMediaStreamTrackMuted(MediaStreamTrack&, bool);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (217774 => 217775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl       2017-06-04 18:19:16 UTC (rev 217774)
+++ trunk/Source/WebCore/testing/Internals.idl  2017-06-04 20:56:58 UTC (rev 217775)
</span><span class="lines">@@ -543,4 +543,5 @@
</span><span class="cx">     [Conditional=MEDIA_STREAM] readonly attribute unsigned long trackVideoSampleCount;
</span><span class="cx">     [Conditional=MEDIA_STREAM, MayThrowException] void setMediaDeviceState(DOMString deviceID, DOMString property, boolean value);
</span><span class="cx">     [Conditional=MEDIA_STREAM] void delayMediaStreamTrackSamples(MediaStreamTrack track, float delay);
</span><ins>+    [Conditional=MEDIA_STREAM] void setMediaStreamTrackMuted(MediaStreamTrack track, boolean muted);
</ins><span class="cx"> };
</span></span></pre>
</div>
</div>

</body>
</html>