<!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>[237837] 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/237837">237837</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2018-11-05 16:45:01 -0800 (Mon, 05 Nov 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>[MediaStream] An audio track should be muted when capture is interrupted by the OS.
Source/WebCore:

https://bugs.webkit.org/show_bug.cgi?id= 191283
 <rdar://problem/45773103>

Patch by Eric Carlson <eric.carlson@apple.com> on 2018-11-05
Reviewed by Jon Lee.

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

* platform/mediastream/RealtimeMediaSource.cpp:
(WebCore::RealtimeMediaSource::setInterruptedForTesting):
* platform/mediastream/RealtimeMediaSource.h:
* platform/mediastream/mac/CoreAudioCaptureSource.cpp:
(WebCore::CoreAudioCaptureSource::beginInterruption):
(WebCore::CoreAudioCaptureSource::endInterruption):
* testing/Internals.cpp:
(WebCore::Internals::setMediaStreamSourceInterrupted):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

https://bugs.webkit.org/show_bug.cgi?id=191283
 <rdar://problem/45773103>

Patch by Eric Carlson <eric.carlson@apple.com> on 2018-11-05
Reviewed by Jon Lee.

* fast/mediastream/media-stream-track-interrupted-expected.txt: Added.
* fast/mediastream/media-stream-track-interrupted.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="#trunkSourceWebCoreplatformmediastreamRealtimeMediaSourcecpp">trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreamRealtimeMediaSourceh">trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacCoreAudioCaptureSourcecpp">trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.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="#trunkLayoutTestsfastmediastreammediastreamtrackinterruptedexpectedtxt">trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastmediastreammediastreamtrackinterruptedhtml">trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (237836 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/LayoutTests/ChangeLog 2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2018-11-05  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] An audio track should be muted when capture is interrupted by the OS.
+        https://bugs.webkit.org/show_bug.cgi?id=191283
+         <rdar://problem/45773103>
+
+        Reviewed by Jon Lee.
+
+        * fast/mediastream/media-stream-track-interrupted-expected.txt: Added.
+        * fast/mediastream/media-stream-track-interrupted.html: Added.
+
</ins><span class="cx"> 2018-11-05  Myles C. Maxfield  <mmaxfield@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Parsing support for text-underline-offset and text-decoration-thickness
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreammediastreamtrackinterruptedexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted-expected.txt (0 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted-expected.txt                           (rev 0)
+++ trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted-expected.txt      2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+
+
+PASS Create stream 
+PASS Interrupt video track 
+PASS Interrupt audio track 
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastmediastreammediastreamtrackinterruptedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted.html (0 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted.html                           (rev 0)
+++ trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted.html      2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -0,0 +1,84 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>Capture source interruption.</title>
+    <script src="../../resources/testharness.js"></script>
+    <script src="../../resources/testharnessreport.js"></script>
+ </head>
+<body>
+    <video width=320 height=240></video>
+
+    <script>
+
+    let video;
+
+   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.setMediaStreamSourceInterrupted(track, false)
+                        }
+                    })
+                }
+
+                if (window.internals)
+                    internals.setMediaStreamSourceInterrupted(track, true);
+                setTimeout(() => reject("Muted state did not change in 1 second"), 1000);
+            });
+        }, title);
+    }
+
+    promise_test((test) => {
+        return navigator.mediaDevices.getUserMedia({ video: true, audio: true})
+            .then((stream) => {
+                testTrack(stream.getVideoTracks()[0], "Interrupt video track");
+                testTrack(stream.getAudioTracks()[0], "Interrupt audio track");
+            });
+    }, "Create stream");
+
+
+    </script>
+
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (237836 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/ChangeLog      2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2018-11-05  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] An audio track should be muted when capture is interrupted by the OS.
+        https://bugs.webkit.org/show_bug.cgi?id= 191283
+         <rdar://problem/45773103>
+
+        Reviewed by Jon Lee.
+
+        Test: fast/mediastream/media-stream-track-interrupted.html
+
+        * platform/mediastream/RealtimeMediaSource.cpp:
+        (WebCore::RealtimeMediaSource::setInterruptedForTesting):
+        * platform/mediastream/RealtimeMediaSource.h:
+        * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
+        (WebCore::CoreAudioCaptureSource::beginInterruption):
+        (WebCore::CoreAudioCaptureSource::endInterruption):
+        * testing/Internals.cpp:
+        (WebCore::Internals::setMediaStreamSourceInterrupted):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
</ins><span class="cx"> 2018-11-05  Myles C. Maxfield  <mmaxfield@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Parsing support for text-underline-offset and text-decoration-thickness
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamRealtimeMediaSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp (237836 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp        2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp   2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -110,6 +110,11 @@
</span><span class="cx">     notifyMutedObservers();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void RealtimeMediaSource::setInterruptedForTesting(bool interrupted)
+{
+    notifyMutedChange(interrupted);
+}
+
</ins><span class="cx"> void RealtimeMediaSource::forEachObserver(const WTF::Function<void(Observer&)>& apply) const
</span><span class="cx"> {
</span><span class="cx">     Vector<Observer*> observersCopy;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamRealtimeMediaSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h (237836 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h  2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h     2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -172,6 +172,7 @@
</span><span class="cx"> 
</span><span class="cx">     // Testing only
</span><span class="cx">     virtual void delaySamples(Seconds) { };
</span><ins>+    void setInterruptedForTesting(bool);
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     RealtimeMediaSource(Type, String&& name, String&& deviceID = { }, String&& hashSalt = { });
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacCoreAudioCaptureSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp (237836 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp 2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp    2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -920,6 +920,7 @@
</span><span class="cx">     scheduleDeferredTask([this, &unit] {
</span><span class="cx">         m_suspendType = unit.isProducingData() ? SuspensionType::WhilePlaying : SuspensionType::WhilePaused;
</span><span class="cx">         unit.suspend();
</span><ins>+        notifyMutedChange(true);
</ins><span class="cx">         m_suspendPending = false;
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="lines">@@ -940,8 +941,10 @@
</span><span class="cx">     scheduleDeferredTask([this, type, &unit] {
</span><span class="cx">         if (m_reconfigurationState == ReconfigurationState::Required)
</span><span class="cx">             unit.reconfigureAudioUnit();
</span><del>-        if (type == SuspensionType::WhilePlaying)
</del><ins>+        if (type == SuspensionType::WhilePlaying) {
</ins><span class="cx">             unit.resume();
</span><ins>+            notifyMutedChange(false);
+        }
</ins><span class="cx">         m_reconfigurationState = ReconfigurationState::None;
</span><span class="cx">         m_resumePending = false;
</span><span class="cx">     });
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (237836 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp       2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/testing/Internals.cpp  2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -4512,6 +4512,12 @@
</span><span class="cx"> {
</span><span class="cx">     track.setIdForTesting(WTFMove(id));
</span><span class="cx"> }
</span><ins>+
+void Internals::setMediaStreamSourceInterrupted(MediaStreamTrack& track, bool interrupted)
+{
+    track.source().setInterruptedForTesting(interrupted);
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> String Internals::audioSessionCategory() const
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (237836 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h 2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/testing/Internals.h    2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -678,6 +678,7 @@
</span><span class="cx">     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
</span><span class="cx">     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
</span><span class="cx">     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
</span><ins>+    void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     String audioSessionCategory() const;
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (237836 => 237837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl       2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/testing/Internals.idl  2018-11-06 00:45:01 UTC (rev 237837)
</span><span class="lines">@@ -663,6 +663,7 @@
</span><span class="cx">     [Conditional=MEDIA_STREAM] void removeMediaStreamTrack(MediaStream stream, MediaStreamTrack track);
</span><span class="cx">     [Conditional=MEDIA_STREAM] void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack track);
</span><span class="cx">     [Conditional=MEDIA_STREAM] void setMediaStreamTrackIdentifier(MediaStreamTrack track, DOMString identifier);
</span><ins>+    [Conditional=MEDIA_STREAM] void setMediaStreamSourceInterrupted(MediaStreamTrack track, boolean interrupted);
</ins><span class="cx"> 
</span><span class="cx">     unsigned long long documentIdentifier(Document document);
</span><span class="cx">     boolean isDocumentAlive(unsigned long long documentIdentifier);
</span></span></pre>
</div>
</div>

</body>
</html>