<!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>[203901] 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/203901">203901</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-29 10:00:00 -0700 (Fri, 29 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>HTMLVideoElement with MediaStream src shows paused image when all video tracks are disabled
https://bugs.webkit.org/show_bug.cgi?id=160222
&lt;rdar://problem/27557313&gt;

Patch by George Ruan &lt;gruan@apple.com&gt; on 2016-07-29
Reviewed by Eric Carlson.

Source/WebCore:

Tests: fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled.html
       fast/mediastream/MediaStream-video-element-video-tracks-disabled.html

* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSampleBufferFromTrack): Change criteria to enqueue a
Sample Buffer to the AVSampleBufferDisplayLayer to allow an initial frame to be shown.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::shouldEnqueueVideoSampleBuffer): Allow an initial frame to be shown.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::flushAndRemoveVideoSampleBuffers): Removes all buffers from the
AVSampleBufferDisplayLayer.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::ensureLayer): Make the AVSampleBufferDisplayLayer's background black.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateDisplayMode): Remove all buffers from the AVSampleBufferDisplayLayer
when state of MediaPlayerPrivateMediaStreamAVFObjC is changed to None of PaintItBlack.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updatePausedImage): Updates paused image.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::pause): Calls updatePausedImage.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::paintCurrentFrameInContext): Allow an initial frame to be painted to canvas.

LayoutTests:

* fast/mediastream/MediaStream-video-element-video-tracks-disabled-expected.html: Added.
* fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled-expected.txt: Added.
* fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled.html: Added. Checks
that the video frames display captured media if all video tracks were disabled and then a single
video track is re-enabled. This test also checks that an initial frame is painted to
canvas if the video has not yet been played.
* fast/mediastream/MediaStream-video-element-video-tracks-disabled.html: Added. Reference tests the
frames of the video to be black, since the canvas is painted black regardless of the state of the video frames
if displayMode of MediaPlayerPrivateMediaStreamAVFObjC is PaintItBlack.
* platform/mac-wk2/TestExpectations: MediaStream-video-element-video-tracks-disabled.html fails on El
Capitan due to incorrect behavior of AVSampleBufferDisplayLayer's API call flushAndRemoveImage.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk2TestExpectations">trunk/LayoutTests/platform/mac-wk2/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCh">trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCmm">trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastmediastreamMediaStreamvideoelementvideotracksdisabledexpectedhtml">trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastmediastreamMediaStreamvideoelementvideotracksdisabledthenenabledexpectedtxt">trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastmediastreamMediaStreamvideoelementvideotracksdisabledthenenabledhtml">trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled.html</a></li>
<li><a href="#trunkLayoutTestsfastmediastreamMediaStreamvideoelementvideotracksdisabledhtml">trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (203900 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-07-29 14:12:03 UTC (rev 203900)
+++ trunk/LayoutTests/ChangeLog        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2016-07-29  George Ruan  &lt;gruan@apple.com&gt;
+
+        HTMLVideoElement with MediaStream src shows paused image when all video tracks are disabled
+        https://bugs.webkit.org/show_bug.cgi?id=160222
+        &lt;rdar://problem/27557313&gt;
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/MediaStream-video-element-video-tracks-disabled-expected.html: Added.
+        * fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled-expected.txt: Added.
+        * fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled.html: Added. Checks
+        that the video frames display captured media if all video tracks were disabled and then a single
+        video track is re-enabled. This test also checks that an initial frame is painted to
+        canvas if the video has not yet been played.
+        * fast/mediastream/MediaStream-video-element-video-tracks-disabled.html: Added. Reference tests the
+        frames of the video to be black, since the canvas is painted black regardless of the state of the video frames
+        if displayMode of MediaPlayerPrivateMediaStreamAVFObjC is PaintItBlack.
+        * platform/mac-wk2/TestExpectations: MediaStream-video-element-video-tracks-disabled.html fails on El
+        Capitan due to incorrect behavior of AVSampleBufferDisplayLayer's API call flushAndRemoveImage.
+
</ins><span class="cx"> 2016-07-29  Youenn Fablet  &lt;youenn@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         CrossOrigin preflight checker should compute the right Access-Control-Request-Headers value
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamMediaStreamvideoelementvideotracksdisabledexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-expected.html (0 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-expected.html        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        .video {
+            position: absolute;
+            left: 10px;
+            top: 50px;
+            height: 360px;
+            width: 680px;
+            background-color: black;
+            will-change: transform;
+        }
+        
+        .masker {
+            position: absolute;
+            left: 10px;
+            top: 50px;
+            height: 360px;
+            width: 680px;
+            border-top: 50px solid white;
+            border-right: 300px solid white;
+            border-bottom: 50px solid white;
+            border-left: 300px solid white;
+            box-sizing: border-box;
+        }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;p&gt;Tests that the video frames of an HTMLVideoElement are black if no video MediaStreamTrack is enabled.&lt;/p&gt;
+&lt;div class=&quot;video&quot;&gt;&lt;/div&gt;
+&lt;div class=&quot;masker&quot;&gt;&lt;/div&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamMediaStreamvideoelementvideotracksdisabledthenenabledexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled-expected.txt (0 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled-expected.txt        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -0,0 +1,32 @@
</span><ins>+Tests that re-enabling a video MediaStreamTrack when all tracks were previously disabled causes captured media to display.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS mediaDevices.getUserMedia generated a stream successfully.
+video.src = window.URL.createObjectURL(mediaStream)
+
+ === beginning round of pixel tests ===
+PASS pixel was white
+
+ === all video tracks disabled ===
+PASS pixel was black.
+
+ === video track reenabled ===
+PASS pixel was white.
+
+ ===== play video =====
+video.play()
+
+ === beginning round of pixel tests ===
+PASS pixel was white
+
+ === all video tracks disabled ===
+PASS pixel was black.
+
+ === video track reenabled ===
+PASS pixel was white.
+PASS successfullyParsed is true
+
+TEST COMPLETE

</ins></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamMediaStreamvideoelementvideotracksdisabledthenenabledhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled.html (0 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled.html                                (rev 0)
+++ trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled.html        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -0,0 +1,128 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+    &lt;script src=&quot;./resources/getUserMedia-helper.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;start()&quot;&gt;
+&lt;p id=&quot;description&quot;&gt;&lt;/p&gt;
+&lt;div id=&quot;console&quot;&gt;&lt;/div&gt;
+&lt;video controls width=&quot;680&quot; height=&quot;360&quot;&gt;&lt;/video&gt;
+&lt;canvas width=&quot;680&quot; height=&quot;360&quot;&gt;&lt;/canvas&gt;
+&lt;script&gt;
+    let canvas;
+    let context;
+    let mediaStream;
+    let video;
+    
+    let buffer;
+
+    function isPixelBlack(pixel)
+    {
+        return pixel[0] === 0 &amp;&amp; pixel[1] === 0 &amp;&amp; pixel[2] === 0 &amp;&amp; pixel[3] === 255;
+    }
+
+    function isPixelTransparent(pixel)
+    {
+        return pixel[0] === 0 &amp;&amp; pixel[1] === 0 &amp;&amp; pixel[2] === 0 &amp;&amp; pixel[3] === 0;
+    }
+
+    function isPixelWhite(pixel)
+    {
+        return pixel[0] === 255 &amp;&amp; pixel[1] === 255 &amp;&amp; pixel[2] === 255 &amp;&amp; pixel[3] === 255;
+    }
+
+    function attempt(numberOfTries, call, callback, successMessage)
+    {
+        if (numberOfTries &lt;= 0) {
+            testFailed('Pixel check did not succeed after multiple tries.');
+            return;
+        }
+
+        let attemptSucceeded = call();
+        if (attemptSucceeded) {
+            testPassed(successMessage);
+            callback();
+
+            return;
+        }
+        
+        setTimeout(() =&gt; { attempt(--numberOfTries, call, callback, successMessage); }, 50);
+    }
+
+    function repeatWithVideoPlayingAndFinishTest()
+    {
+        if (video.paused) {
+            debug('&lt;br&gt; ===== play video =====');
+            evalAndLog('video.play()');
+            beginTestRound();
+        } else
+            finishJSTest();
+    }
+
+    function reenableTrack()
+    {
+        mediaStream.getVideoTracks()[0].enabled = true;
+        debug('&lt;br&gt; === video track reenabled ===');
+
+        // The video is not guaranteed to render non-black frames before the canvas is drawn to and the pixels are checked.
+        // A timeout is used to ensure that the pixel check is done after the video renders non-black frames.
+        attempt(10, checkPixels, repeatWithVideoPlayingAndFinishTest, 'pixel was white.');
+    }
+
+    function checkPixels()
+    {
+        context.clearRect(0, 0, canvas.width, canvas.height);
+        buffer = context.getImageData(30, 242, 1, 1).data;
+        if(!isPixelTransparent(buffer)) {
+            testFailed('pixel was not transparent after clearing canvas.');
+        }
+
+        context.drawImage(video, 0, 0, canvas.width, canvas.height);
+        buffer = context.getImageData(30, 242, 1, 1).data;
+
+        if (mediaStream.getVideoTracks()[0].enabled)
+            return isPixelWhite(buffer);
+        else
+            return isPixelBlack(buffer);
+    }
+
+    function disableAllTracks()
+    {
+        mediaStream.getVideoTracks()[0].enabled = false;
+        debug('&lt;br&gt; === all video tracks disabled ===');
+        
+        // The video is not guaranteed to render black frames before the canvas is drawn to and the pixels are checked.
+        // A timeout is used to ensure that the pixel check is done after the video renders black frames.
+        attempt(10, checkPixels, reenableTrack, 'pixel was black.');
+    }
+
+    function beginTestRound()
+    {
+        debug('&lt;br&gt; === beginning round of pixel tests ===');
+        attempt(1, checkPixels, disableAllTracks, 'pixel was white');
+    }
+
+    function canplay()
+    {
+        canvas = document.querySelector('canvas');
+        context = canvas.getContext('2d');
+
+        beginTestRound();
+    }
+
+    function start()
+    {
+        description(&quot;Tests that re-enabling a video MediaStreamTrack when all tracks were previously disabled causes captured media to display.&quot;);
+
+        video = document.querySelector('video');
+        video.addEventListener('canplay', canplay);
+
+        getUserMedia(&quot;allow&quot;, {video:true}, setupVideoElementWithStream);
+    }
+
+    window.jsTestIsAsync = true;
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamMediaStreamvideoelementvideotracksdisabledhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled.html (0 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled.html                                (rev 0)
+++ trunk/LayoutTests/fast/mediastream/MediaStream-video-element-video-tracks-disabled.html        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -0,0 +1,81 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        video {
+            position: absolute;
+            left: 10px;
+            top: 50px;
+        }
+        
+        .masker {
+            position: absolute;
+            left: 10px;
+            top: 50px;
+            height: 360px;
+            width: 680px;
+            border-top: 50px solid white;
+            border-right: 300px solid white;
+            border-bottom: 50px solid white;
+            border-left: 300px solid white;
+            box-sizing: border-box;
+        }
+    &lt;/style&gt;
+&lt;/head&gt;
+
+&lt;body&gt;
+&lt;p&gt;Tests that the video frames of an HTMLVideoElement are black if no video MediaStreamTrack is enabled.&lt;/p&gt;
+&lt;video controls width=&quot;680&quot; height=&quot;360&quot;&gt;&lt;/video&gt;
+&lt;div class=&quot;masker&quot;&gt;&lt;/div&gt;
+
+&lt;script&gt;
+    let mediaStream;
+    let video;
+
+    function debug(msg)
+    {
+        let span = document.createElement('span');
+        document.body.appendChild(span);
+        span.innerHTML = `${msg} &lt;br /&gt;`;
+    }
+
+    function canplaythrough()
+    {    
+        mediaStream.getVideoTracks()[0].enabled = false;
+        window.testRunner.notifyDone();
+    }
+
+    function canplay()
+    {
+        video.play();
+    }
+
+    function setupStream(stream)
+    {
+        mediaStream = stream;
+        video.src = window.URL.createObjectURL(mediaStream);
+    }
+
+    function failedToSetupStream()
+    {
+        debug('Failed to setup stream');
+    }
+
+    function start()
+    {
+        video = document.querySelector('video');
+        video.addEventListener('canplay', canplay, false);
+        video.addEventListener('canplaythrough', canplaythrough, false);
+        navigator.mediaDevices.getUserMedia({video:true})
+            .then(setupStream)
+            .catch(failedToSetupStream);
+    }
+
+    if (window.testRunner) {
+        window.testRunner.waitUntilDone();
+        window.testRunner.setUserMediaPermission(true);
+        start();
+    }
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2TestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (203900 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/TestExpectations        2016-07-29 14:12:03 UTC (rev 203900)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -373,6 +373,9 @@
</span><span class="cx"> 
</span><span class="cx"> [ Debug ] editing/undo/remove-css-property-and-remove-style.html [ Pass Failure ]
</span><span class="cx"> 
</span><ins>+# This test fails every time on El Capitan
+[ ElCapitan ] fast/mediastream/MediaStream-video-element-video-tracks-disabled.html [ Skip ]
+
</ins><span class="cx"> ### END OF (3) Unclassified failures
</span><span class="cx"> ########################################
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (203900 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-07-29 14:12:03 UTC (rev 203900)
+++ trunk/Source/WebCore/ChangeLog        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-07-29  George Ruan  &lt;gruan@apple.com&gt;
+
+        HTMLVideoElement with MediaStream src shows paused image when all video tracks are disabled
+        https://bugs.webkit.org/show_bug.cgi?id=160222
+        &lt;rdar://problem/27557313&gt;
+
+        Reviewed by Eric Carlson.
+
+        Tests: fast/mediastream/MediaStream-video-element-video-tracks-disabled-then-enabled.html
+               fast/mediastream/MediaStream-video-element-video-tracks-disabled.html
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSampleBufferFromTrack): Change criteria to enqueue a
+        Sample Buffer to the AVSampleBufferDisplayLayer to allow an initial frame to be shown.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::shouldEnqueueVideoSampleBuffer): Allow an initial frame to be shown.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::flushAndRemoveVideoSampleBuffers): Removes all buffers from the
+        AVSampleBufferDisplayLayer.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::ensureLayer): Make the AVSampleBufferDisplayLayer's background black.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateDisplayMode): Remove all buffers from the AVSampleBufferDisplayLayer
+        when state of MediaPlayerPrivateMediaStreamAVFObjC is changed to None of PaintItBlack.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updatePausedImage): Updates paused image.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::pause): Calls updatePausedImage.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::paintCurrentFrameInContext): Allow an initial frame to be painted to canvas.
+
</ins><span class="cx"> 2016-07-29  Youenn Fablet  &lt;youenn@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Fetch API] Activate credentials mode
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h (203900 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h        2016-07-29 14:12:03 UTC (rev 203900)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -124,6 +124,8 @@
</span><span class="cx"> 
</span><span class="cx">     void enqueueAudioSampleBufferFromTrack(MediaStreamTrackPrivate&amp;, PlatformSample);
</span><span class="cx">     void enqueueVideoSampleBufferFromTrack(MediaStreamTrackPrivate&amp;, PlatformSample);
</span><ins>+    bool shouldEnqueueVideoSampleBuffer() const;
+    void flushAndRemoveVideoSampleBuffers();
</ins><span class="cx"> 
</span><span class="cx">     void paint(GraphicsContext&amp;, const FloatRect&amp;) override;
</span><span class="cx">     void paintCurrentFrameInContext(GraphicsContext&amp;, const FloatRect&amp;) override;
</span><span class="lines">@@ -161,6 +163,7 @@
</span><span class="cx">     };
</span><span class="cx">     DisplayMode currentDisplayMode() const;
</span><span class="cx">     void updateDisplayMode();
</span><ins>+    void updatePausedImage();
</ins><span class="cx"> 
</span><span class="cx">     // MediaStreamPrivate::Observer
</span><span class="cx">     void activeStatusChanged() override;
</span><span class="lines">@@ -201,6 +204,7 @@
</span><span class="cx">     bool m_ended { false };
</span><span class="cx">     bool m_hasEverEnqueuedVideoFrame { false };
</span><span class="cx">     bool m_hasReceivedMedia { false };
</span><ins>+    bool m_isFrameDisplayed { false };
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
</span><span class="cx">     std::unique_ptr&lt;VideoFullscreenLayerManager&gt; m_videoFullscreenLayerManager;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm (203900 => 203901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm        2016-07-29 14:12:03 UTC (rev 203900)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm        2016-07-29 17:00:00 UTC (rev 203901)
</span><span class="lines">@@ -129,16 +129,39 @@
</span><span class="cx">     if (&amp;track != m_mediaStreamPrivate-&gt;activeVideoTrack())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (m_displayMode == LivePreview &amp;&amp; [m_sampleBufferDisplayLayer isReadyForMoreMediaData]) {
</del><ins>+    if (shouldEnqueueVideoSampleBuffer()) {
</ins><span class="cx">         [m_sampleBufferDisplayLayer enqueueSampleBuffer:platformSample.sample.cmSampleBuffer];
</span><ins>+        m_isFrameDisplayed = true;
</ins><span class="cx">         
</span><span class="cx">         if (!m_hasEverEnqueuedVideoFrame) {
</span><span class="cx">             m_hasEverEnqueuedVideoFrame = true;
</span><span class="cx">             m_player-&gt;firstVideoFrameAvailable();
</span><ins>+
+            updatePausedImage();
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool MediaPlayerPrivateMediaStreamAVFObjC::shouldEnqueueVideoSampleBuffer() const
+{
+    if (![m_sampleBufferDisplayLayer isReadyForMoreMediaData])
+        return false;
+
+    if (m_displayMode == LivePreview)
+        return true;
+
+    if (m_displayMode == PausedImage &amp;&amp; !m_isFrameDisplayed)
+        return true;
+
+    return false;
+}
+
+void MediaPlayerPrivateMediaStreamAVFObjC::flushAndRemoveVideoSampleBuffers()
+{
+    [m_sampleBufferDisplayLayer flushAndRemoveImage];
+    m_isFrameDisplayed = false;
+}
+
</ins><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::ensureLayer()
</span><span class="cx"> {
</span><span class="cx">     if (m_sampleBufferDisplayLayer)
</span><span class="lines">@@ -148,6 +171,7 @@
</span><span class="cx"> #ifndef NDEBUG
</span><span class="cx">     [m_sampleBufferDisplayLayer setName:@&quot;MediaPlayerPrivateMediaStreamAVFObjC AVSampleBufferDisplayLayer&quot;];
</span><span class="cx"> #endif
</span><ins>+    m_sampleBufferDisplayLayer.get().backgroundColor = cachedCGColor(Color::black);
</ins><span class="cx">     
</span><span class="cx">     renderingModeChanged();
</span><span class="cx">     
</span><span class="lines">@@ -257,8 +281,24 @@
</span><span class="cx">         return;
</span><span class="cx">     m_displayMode = displayMode;
</span><span class="cx"> 
</span><del>-    if (m_displayMode == None)
</del><ins>+    if (m_displayMode &lt; PausedImage &amp;&amp; m_sampleBufferDisplayLayer)
+        flushAndRemoveVideoSampleBuffers();
+}
+
+void MediaPlayerPrivateMediaStreamAVFObjC::updatePausedImage()
+{
+    ASSERT(m_displayMode == currentDisplayMode());
+
+    if (m_displayMode &lt; PausedImage)
</ins><span class="cx">         return;
</span><ins>+
+    RefPtr&lt;Image&gt; image = m_mediaStreamPrivate-&gt;currentFrameImage();
+    ASSERT(image);
+    if (!image)
+        return;
+
+    m_pausedImage = image-&gt;getCGImageRef();
+    ASSERT(m_pausedImage);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::play()
</span><span class="lines">@@ -286,6 +326,7 @@
</span><span class="cx">     m_clock-&gt;stop();
</span><span class="cx">     m_playing = false;
</span><span class="cx">     updateDisplayMode();
</span><ins>+    updatePausedImage();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool MediaPlayerPrivateMediaStreamAVFObjC::paused() const
</span><span class="lines">@@ -577,10 +618,9 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::paintCurrentFrameInContext(GraphicsContext&amp; context, const FloatRect&amp; rect)
</span><span class="cx"> {
</span><del>-    if (m_displayMode == None || !metaDataAvailable() || context.paintingDisabled() || !m_haveEverPlayed)
</del><ins>+    if (m_displayMode == None || !metaDataAvailable() || context.paintingDisabled())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-
</del><span class="cx">     if (m_displayMode == LivePreview)
</span><span class="cx">         m_mediaStreamPrivate-&gt;paintCurrentFrameInContext(context, rect);
</span><span class="cx">     else {
</span></span></pre>
</div>
</div>

</body>
</html>