<!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>[214928] 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/214928">214928</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-04-04 21:48:03 -0700 (Tue, 04 Apr 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>Canvas is tainted when painting a video with MediaStreamTrack
https://bugs.webkit.org/show_bug.cgi?id=170486
Patch by Youenn Fablet <youenn@apple.com> on 2017-04-04
Reviewed by Eric Carlson.
Source/WebCore:
Test: http/tests/media/media-stream/getusermedia-with-canvas.html
Adding the notion of isolated source so that we can later on implement WebRTC isolated tracks.
For now, canvas will not be tainted if painted from a MediaStreamTrack.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::didPassCORSAccessCheck):
* platform/mediastream/MediaStreamTrackPrivate.h:
(WebCore::MediaStreamTrackPrivate::isIsolated):
* platform/mediastream/RealtimeMediaSource.h:
LayoutTests:
* http/tests/media/media-stream/getusermedia-with-canvas-expected.txt: Added.
* http/tests/media/media-stream/getusermedia-with-canvas.html: Added.
* http/tests/media/media-stream/resources/getUserMedia-helper.js: Added.
(reject):
(getUserMedia):
(defaultRejectOrCatch):
(setupVideoElementWithStream):</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="#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>
<li><a href="#trunkSourceWebCoreplatformmediastreamMediaStreamTrackPrivateh">trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreamRealtimeMediaSourceh">trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestsmediamediastreamgetusermediawithcanvasexpectedtxt">trunk/LayoutTests/http/tests/media/media-stream/getusermedia-with-canvas-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsmediamediastreamgetusermediawithcanvashtml">trunk/LayoutTests/http/tests/media/media-stream/getusermedia-with-canvas.html</a></li>
<li><a href="#trunkLayoutTestshttptestsmediamediastreamresourcesgetUserMediahelperjs">trunk/LayoutTests/http/tests/media/media-stream/resources/getUserMedia-helper.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (214927 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-04-05 03:50:07 UTC (rev 214927)
+++ trunk/LayoutTests/ChangeLog        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -1,5 +1,20 @@
</span><span class="cx"> 2017-04-04 Youenn Fablet <youenn@apple.com>
</span><span class="cx">
</span><ins>+ Canvas is tainted when painting a video with MediaStreamTrack
+ https://bugs.webkit.org/show_bug.cgi?id=170486
+
+ Reviewed by Eric Carlson.
+
+ * http/tests/media/media-stream/getusermedia-with-canvas-expected.txt: Added.
+ * http/tests/media/media-stream/getusermedia-with-canvas.html: Added.
+ * http/tests/media/media-stream/resources/getUserMedia-helper.js: Added.
+ (reject):
+ (getUserMedia):
+ (defaultRejectOrCatch):
+ (setupVideoElementWithStream):
+
+2017-04-04 Youenn Fablet <youenn@apple.com>
+
</ins><span class="cx"> [Mac] Add back web audio support for getUserMedia MediaStreamTrack
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=170482
</span><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsmediamediastreamgetusermediawithcanvasexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/media/media-stream/getusermedia-with-canvas-expected.txt (0 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/media/media-stream/getusermedia-with-canvas-expected.txt         (rev 0)
+++ trunk/LayoutTests/http/tests/media/media-stream/getusermedia-with-canvas-expected.txt        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -0,0 +1,33 @@
</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 "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS mediaDevices.getUserMedia generated a stream successfully.
+video.srcObject = mediaStream
+
+ === beginning round of pixel tests ===
+PASS pixel was black.
+
+ === all video tracks disabled ===
+PASS pixel was black.
+
+ === video track reenabled, should NOT render current frame ===
+PASS pixel was black.
+
+ ===== play video =====
+video.play()
+
+ === beginning round of pixel tests ===
+PASS pixel was white.
+
+ === all video tracks disabled ===
+PASS pixel was black.
+
+ === video track reenabled, should render current frame ===
+PASS pixel was white.
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsmediamediastreamgetusermediawithcanvashtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/media/media-stream/getusermedia-with-canvas.html (0 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/media/media-stream/getusermedia-with-canvas.html         (rev 0)
+++ trunk/LayoutTests/http/tests/media/media-stream/getusermedia-with-canvas.html        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -0,0 +1,137 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/js-test-pre.js"></script>
+ <script src="./resources/getUserMedia-helper.js"></script>
+</head>
+<body onload="start()">
+<p id="description"></p>
+<div id="console"></div>
+<video controls width="680" height="360"></video>
+<canvas width="680" height="360"></canvas>
+<script>
+ let canvas;
+ let context;
+ let mediaStream;
+ let video;
+ let havePlayed = false;
+
+ let buffer;
+
+ function isPixelBlack(pixel)
+ {
+ return pixel[0] === 0 && pixel[1] === 0 && pixel[2] === 0 && pixel[3] === 255;
+ }
+
+ function isPixelTransparent(pixel)
+ {
+ return pixel[0] === 0 && pixel[1] === 0 && pixel[2] === 0 && pixel[3] === 0;
+ }
+
+ function isPixelWhite(pixel)
+ {
+ return pixel[0] === 255 && pixel[1] === 255 && pixel[2] === 255 && pixel[3] === 255;
+ }
+
+ function canvasShouldBeBlack()
+ {
+ return !(mediaStream.getVideoTracks()[0].enabled && havePlayed);
+ }
+
+ function attempt(numberOfTries, call, callback)
+ {
+ if (numberOfTries <= 0) {
+ testFailed('Pixel check did not succeed after multiple tries.');
+ return;
+ }
+
+ let attemptSucceeded = call();
+ if (attemptSucceeded) {
+ testPassed(canvasShouldBeBlack() ? 'pixel was black.' : 'pixel was white.');
+ callback();
+
+ return;
+ }
+
+ setTimeout(() => { attempt(--numberOfTries, call, callback); }, 50);
+ }
+
+ function repeatWithVideoPlayingAndFinishTest()
+ {
+ if (video.paused) {
+ debug('<br> ===== play video =====');
+ evalAndLog('video.play()');
+ havePlayed = true;
+ beginTestRound();
+ } else {
+ debug('');
+ video.pause();
+ finishJSTest();
+ }
+ }
+
+ function reenableTrack()
+ {
+ mediaStream.getVideoTracks()[0].enabled = true;
+ debug(`<br> === video track reenabled, should${havePlayed ? "" : " NOT"} render current frame ===`);
+
+ // 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);
+ }
+
+ 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 (!canvasShouldBeBlack())
+ return isPixelWhite(buffer);
+ else
+ return isPixelBlack(buffer);
+ }
+
+ function disableAllTracks()
+ {
+ mediaStream.getVideoTracks()[0].enabled = false;
+ debug('<br> === 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);
+ }
+
+ function beginTestRound()
+ {
+ debug('<br> === beginning round of pixel tests ===');
+ attempt(10, checkPixels, disableAllTracks);
+ }
+
+ function canplay()
+ {
+ canvas = document.querySelector('canvas');
+ context = canvas.getContext('2d');
+
+ beginTestRound();
+ }
+
+ function start()
+ {
+ description("Tests that re-enabling a video MediaStreamTrack when all tracks were previously disabled causes captured media to display.");
+
+ video = document.querySelector('video');
+ video.addEventListener('canplay', canplay);
+
+ getUserMedia("allow", {video:true}, setupVideoElementWithStream);
+ }
+
+ window.jsTestIsAsync = true;
+</script>
+<script src="/resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsmediamediastreamresourcesgetUserMediahelperjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/media/media-stream/resources/getUserMedia-helper.js (0 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/media/media-stream/resources/getUserMedia-helper.js         (rev 0)
+++ trunk/LayoutTests/http/tests/media/media-stream/resources/getUserMedia-helper.js        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+function getUserMedia(permission, constraints, successCallback, errorCallback) {
+ if (window.testRunner)
+ testRunner.setUserMediaPermission(permission == "allow");
+ else {
+ debug("This test can not be run without the testRunner");
+ finishJSTest();
+ return;
+ }
+
+ navigator.mediaDevices
+ .getUserMedia(constraints)
+ .then(successCallback, reject)
+ .catch(defaultRejectOrCatch);
+
+ function reject(e) {
+ if (errorCallback)
+ errorCallback(e);
+ else
+ defaultRejectOrCatch(e);
+ }
+}
+
+function defaultRejectOrCatch(e) {
+ testFailed('getUserMedia failed:' + e);
+ finishJSTest();
+}
+
+function setupVideoElementWithStream(stream)
+{
+ mediaStream = stream;
+ testPassed('mediaDevices.getUserMedia generated a stream successfully.');
+ evalAndLog('video.srcObject = mediaStream');
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (214927 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-04-05 03:50:07 UTC (rev 214927)
+++ trunk/Source/WebCore/ChangeLog        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2017-04-04 Youenn Fablet <youenn@apple.com>
+
+ Canvas is tainted when painting a video with MediaStreamTrack
+ https://bugs.webkit.org/show_bug.cgi?id=170486
+
+ Reviewed by Eric Carlson.
+
+ Test: http/tests/media/media-stream/getusermedia-with-canvas.html
+
+ Adding the notion of isolated source so that we can later on implement WebRTC isolated tracks.
+ For now, canvas will not be tainted if painted from a MediaStreamTrack.
+
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+ (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::didPassCORSAccessCheck):
+ * platform/mediastream/MediaStreamTrackPrivate.h:
+ (WebCore::MediaStreamTrackPrivate::isIsolated):
+ * platform/mediastream/RealtimeMediaSource.h:
+
</ins><span class="cx"> 2017-04-04 Commit Queue <commit-queue@webkit.org>
</span><span class="cx">
</span><span class="cx"> Unreviewed, rolling out r214894, r214895, r214907, r214912,
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h (214927 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h        2017-04-05 03:50:07 UTC (rev 214927)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -91,6 +91,8 @@
</span><span class="cx">
</span><span class="cx"> // FIXME(146853): Implement necessary conformations to standard in HTMLMediaElement for MediaStream
</span><span class="cx">
</span><ins>+ bool didPassCORSAccessCheck() const final;
+
</ins><span class="cx"> void load(const String&) override;
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><span class="cx"> void load(const String&, MediaSourcePrivateClient*) override;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm (214927 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm        2017-04-05 03:50:07 UTC (rev 214927)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -553,6 +553,14 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool MediaPlayerPrivateMediaStreamAVFObjC::didPassCORSAccessCheck() const
+{
+ // We are only doing a check on the active video track since the sole consumer of this API is canvas.
+ // FIXME: We should change the name of didPassCORSAccessCheck if it is expected to stay like this.
+ const auto* track = m_mediaStreamPrivate->activeVideoTrack();
+ return !track || !track->isIsolated();
+}
+
</ins><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::cancelLoad()
</span><span class="cx"> {
</span><span class="cx"> LOG(Media, "MediaPlayerPrivateMediaStreamAVFObjC::cancelLoad(%p)", this);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamMediaStreamTrackPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h (214927 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h        2017-04-05 03:50:07 UTC (rev 214927)
+++ trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -66,6 +66,8 @@
</span><span class="cx"> void stopProducingData() { m_source->stopProducingData(); }
</span><span class="cx"> bool isProducingData() { return m_source->isProducingData(); }
</span><span class="cx">
</span><ins>+ bool isIsolated() const { return m_source->isIsolated(); }
+
</ins><span class="cx"> bool muted() const;
</span><span class="cx"> void setMuted(bool muted) { m_source->setMuted(muted); }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamRealtimeMediaSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h (214927 => 214928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h        2017-04-05 03:50:07 UTC (rev 214927)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h        2017-04-05 04:48:03 UTC (rev 214928)
</span><span class="lines">@@ -120,6 +120,8 @@
</span><span class="cx">
</span><span class="cx"> virtual void settingsDidChange();
</span><span class="cx">
</span><ins>+ virtual bool isIsolated() const { return false; }
+
</ins><span class="cx"> void videoSampleAvailable(MediaSample&);
</span><span class="cx"> void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t);
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>