<!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>[203739] 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/203739">203739</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-26 14:52:27 -0700 (Tue, 26 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>HTMLVideoElement frames do not update on iOS when src is a MediaStream blob
https://bugs.webkit.org/show_bug.cgi?id=159833
&lt;rdar://problem/27379487&gt;

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

Source/WebCore:

Test: fast/mediastream/MediaStream-video-element-displays-buffer.html

* WebCore.xcodeproj/project.pbxproj:
* platform/cf/CoreMediaSoftLink.cpp: Add CMSampleBufferCreateReadyWithImageBuffer and CMVideoFormatDescriptionCreateForImageBuffer
softlink.
* platform/cf/CoreMediaSoftLink.h: Ditto.
* platform/cocoa/CoreVideoSoftLink.cpp: Add CVPixelBufferCreate, kCVPixelBufferCGBitmapContextCompatibilityKey, and
kCVPixelBufferCGImageCompatibilityKey.
* platform/cocoa/CoreVideoSoftLink.h: Ditto.
* platform/graphics/avfoundation/MediaSampleAVFObjC.h: Change create to return a Ref&lt;T&gt; instead
of RefPtr&lt;T&gt;.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: Make observer of
MediaStreamTrackPrivate and make MediaPlayer use an AVSampleBufferDisplayLayer instead of CALayer.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: Ditto.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::~MediaPlayerPrivateMediaStreamAVFObjC): Clean up
observers and AVSampleBufferDisplayLayer.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::isAvailable): Ensures AVSampleBufferDisplayLayer
is available.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueAudioSampleBufferFromTrack): Placeholder.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSampleBufferFromTrack): Responsible
for enqueuing sample buffers to the active video track.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::ensureLayer): Ensures that an AVSampleBufferDisplayLayer
exists.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::destroyLayer): Destroys the AVSampleBufferDisplayLayer.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::platformLayer): Replace CALayer with AVSampleBufferDisplayLayer.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::currentDisplayMode): Ditto.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::play): Call updateReadyState as a deferred task.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::currentReadyState): readyState is bumped to HAVE_ENOUGH_DATA
only when the MediaPlayerPrivateMediaStreamAVFObjC has received a media sample.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::sampleBufferUpdated): Called from MediaStreamTrackPrivate when a
new SampleBuffer is available.
(WebCore::updateTracksOfType): Manage adding and removing self as observer from tracks.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateTracks): Replace CALayer with AVSampleBufferDisplayLayer
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::acceleratedRenderingStateChanged): Copied from
MediaPlayerPrivateMediaSourceAVFObjC.mm
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::load): Deleted CALayer.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateDisplayMode): Deleted process of updating CALayer.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateIntrinsicSize): Deleted CALayer.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::createPreviewLayers): Deleted.
* platform/mediastream/MediaStreamPrivate.cpp:
(WebCore::MediaStreamPrivate::updateActiveVideoTrack): Remove redundant check.
* platform/mediastream/MediaStreamTrackPrivate.cpp:
(WebCore::MediaStreamTrackPrivate::sourceHasMoreMediaData): Called from RealtimeMediaSource when a new SampleBuffer
is available.
* platform/mediastream/MediaStreamTrackPrivate.h:
(WebCore::MediaStreamTrackPrivate::Observer::sampleBufferUpdated): Relays to MediaPlayerPrivateMediaStreamAVFObjC that
a new SampleBuffer is available to enqueue to the AVSampleBufferDisplayLayer.
* platform/mediastream/RealtimeMediaSource.cpp:
(WebCore::RealtimeMediaSource::settingsDidChange): Fix grammatical mistake in function name settingsDidChanged().
(WebCore::RealtimeMediaSource::mediaDataUpdated): Relays to all observers that a new SampleBuffer is available.
(WebCore::RealtimeMediaSource::settingsDidChanged): Deleted.
* platform/mediastream/RealtimeMediaSource.h:
* platform/mediastream/mac/AVVideoCaptureSource.mm:
(WebCore::AVVideoCaptureSource::processNewFrame): Calls mediaDataUpdated when a new SampleBuffer is captured.
* platform/mediastream/mac/MockRealtimeVideoSourceMac.h:
* platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
(WebCore::MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer): Convert CVPixelBuffer to CMSampleBuffer.
(WebCore::MockRealtimeVideoSourceMac::pixelBufferFromCGImage): Convert CGImage to CVPixelBuffer.
(WebCore::MockRealtimeVideoSourceMac::updateSampleBuffer): Creates a CMSampleBuffer from current imageBuffer and
sends the CMSampleBuffer to MediaPlayerPrivateMediaStreamAVFObjC
* platform/mock/MockRealtimeVideoSource.cpp:
(WebCore::MockRealtimeVideoSource::setFrameRate): Fix grammar of settingsDidChanged() to settingsDidChange().
(WebCore::MockRealtimeVideoSource::setSize): Ditto.
(WebCore::MockRealtimeVideoSource::generateFrame): Call updateSampleBuffer().
* platform/mock/MockRealtimeVideoSource.h: Change elapsedTime() from private to protected.
(WebCore::MockRealtimeVideoSource::updateSampleBuffer): Overriden by MockRealtimeVideoSourceMac.

LayoutTests:

* fast/mediastream/MediaStream-video-element-displays-buffer-expected.txt: Added.
* fast/mediastream/MediaStream-video-element-displays-buffer.html: Added. Checks that
a video element with a mediastream source displays frames that are neither black or transparent.
* fast/mediastream/resources/getUserMedia-helper.js:
(setupVideoElementWithStream): Sets up video element with global variable mediastream.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastmediastreamresourcesgetUserMediahelperjs">trunk/LayoutTests/fast/mediastream/resources/getUserMedia-helper.js</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreplatformcfCoreMediaSoftLinkcpp">trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformcfCoreMediaSoftLinkh">trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.h</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaCoreVideoSoftLinkcpp">trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaCoreVideoSoftLinkh">trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationMediaSampleAVFObjCh">trunk/Source/WebCore/platform/graphics/avfoundation/MediaSampleAVFObjC.h</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="#trunkSourceWebCoreplatformmediastreamMediaStreamPrivatecpp">trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreamMediaStreamTrackPrivatecpp">trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreamMediaStreamTrackPrivateh">trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h</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="#trunkSourceWebCoreplatformmediastreammacAVVideoCaptureSourcemm">trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacMockRealtimeVideoSourceMach">trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacMockRealtimeVideoSourceMacmm">trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmockMockRealtimeVideoSourcecpp">trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmockMockRealtimeVideoSourceh">trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastmediastreamMediaStreamvideoelementdisplaysbufferexpectedtxt">trunk/LayoutTests/fast/mediastream/MediaStream-video-element-displays-buffer-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastmediastreamMediaStreamvideoelementdisplaysbufferhtml">trunk/LayoutTests/fast/mediastream/MediaStream-video-element-displays-buffer.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/LayoutTests/ChangeLog        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-07-26  George Ruan  &lt;gruan@apple.com&gt;
+
+        HTMLVideoElement frames do not update on iOS when src is a MediaStream blob
+        https://bugs.webkit.org/show_bug.cgi?id=159833
+        &lt;rdar://problem/27379487&gt;
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/MediaStream-video-element-displays-buffer-expected.txt: Added.
+        * fast/mediastream/MediaStream-video-element-displays-buffer.html: Added. Checks that
+        a video element with a mediastream source displays frames that are neither black or transparent.
+        * fast/mediastream/resources/getUserMedia-helper.js:
+        (setupVideoElementWithStream): Sets up video element with global variable mediastream.
+
</ins><span class="cx"> 2016-07-26  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove the tests for legacy custom elements API
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamMediaStreamvideoelementdisplaysbufferexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/MediaStream-video-element-displays-buffer-expected.txt (0 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/MediaStream-video-element-displays-buffer-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/mediastream/MediaStream-video-element-displays-buffer-expected.txt        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+Tests that the stream displays captured buffers to the video element.
+
+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)
+video.play()
+
+ === checking pixels ===
+PASS isPixelTransparent(buffer) is true
+PASS isPixelTransparent(buffer) is false
+PASS isPixelBlack(buffer) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE

</ins></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamMediaStreamvideoelementdisplaysbufferhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/MediaStream-video-element-displays-buffer.html (0 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/MediaStream-video-element-displays-buffer.html                                (rev 0)
+++ trunk/LayoutTests/fast/mediastream/MediaStream-video-element-displays-buffer.html        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -0,0 +1,72 @@
</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 mediaStream;
+    let video;
+    
+    let buffer;
+    
+    function isPixelTransparent(pixel)
+    {
+        return pixel[0] === 0 &amp;&amp; pixel[1] === 0 &amp;&amp; pixel[2] === 0 &amp;&amp; pixel[3] === 0;
+    }
+
+    function isPixelBlack(pixel)
+    {
+        return pixel[0] === 0 &amp;&amp; pixel[1] === 0 &amp;&amp; pixel[2] === 0 &amp;&amp; pixel[3] === 255;
+    }
+
+    function verifyFramesBeingDisplayed()
+    {
+        let canvas = document.querySelector('canvas');
+        let context = canvas.getContext('2d');
+
+        debug('&lt;br&gt; === checking pixels ===');
+
+        context.clearRect(0, 0, canvas.width, canvas.height);
+
+        let x = canvas.width * .035;
+        let y = canvas.height * 0.6 + 2 + x;
+        
+        buffer = context.getImageData(x, y, 1, 1).data;
+        shouldBeTrue('isPixelTransparent(buffer)');
+        
+        context.drawImage(video, 0, 0, canvas.width, canvas.height);
+        
+        buffer = context.getImageData(x, y, 1, 1).data;
+        shouldBeFalse('isPixelTransparent(buffer)');
+        shouldBeFalse('isPixelBlack(buffer)');
+
+        finishJSTest();
+    }
+
+    function canplay()
+    {
+        evalAndLog('video.play()');
+    }
+
+    function start()
+    {
+        description(&quot;Tests that the stream displays captured buffers to the video element.&quot;);
+
+        video = document.querySelector('video');
+        video.addEventListener('canplay', canplay, false);
+        video.addEventListener('playing', verifyFramesBeingDisplayed, false);
+
+        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="trunkLayoutTestsfastmediastreamresourcesgetUserMediahelperjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/mediastream/resources/getUserMedia-helper.js (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/resources/getUserMedia-helper.js        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/LayoutTests/fast/mediastream/resources/getUserMedia-helper.js        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -24,3 +24,10 @@
</span><span class="cx">     testFailed('getUserMedia failed:' + e);
</span><span class="cx">     finishJSTest();
</span><span class="cx"> }
</span><ins>+
+function setupVideoElementWithStream(stream)
+{
+    mediaStream = stream;
+    testPassed('mediaDevices.getUserMedia generated a stream successfully.');
+    evalAndLog('video.src = window.URL.createObjectURL(mediaStream)');
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/ChangeLog        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -1,3 +1,78 @@
</span><ins>+2016-07-26  George Ruan  &lt;gruan@apple.com&gt;
+
+        HTMLVideoElement frames do not update on iOS when src is a MediaStream blob
+        https://bugs.webkit.org/show_bug.cgi?id=159833
+        &lt;rdar://problem/27379487&gt;
+
+        Reviewed by Eric Carlson.
+
+        Test: fast/mediastream/MediaStream-video-element-displays-buffer.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/cf/CoreMediaSoftLink.cpp: Add CMSampleBufferCreateReadyWithImageBuffer and CMVideoFormatDescriptionCreateForImageBuffer
+        softlink.
+        * platform/cf/CoreMediaSoftLink.h: Ditto.
+        * platform/cocoa/CoreVideoSoftLink.cpp: Add CVPixelBufferCreate, kCVPixelBufferCGBitmapContextCompatibilityKey, and
+        kCVPixelBufferCGImageCompatibilityKey.
+        * platform/cocoa/CoreVideoSoftLink.h: Ditto.
+        * platform/graphics/avfoundation/MediaSampleAVFObjC.h: Change create to return a Ref&lt;T&gt; instead
+        of RefPtr&lt;T&gt;.
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: Make observer of
+        MediaStreamTrackPrivate and make MediaPlayer use an AVSampleBufferDisplayLayer instead of CALayer.
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: Ditto.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::~MediaPlayerPrivateMediaStreamAVFObjC): Clean up
+        observers and AVSampleBufferDisplayLayer.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::isAvailable): Ensures AVSampleBufferDisplayLayer
+        is available.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueAudioSampleBufferFromTrack): Placeholder.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSampleBufferFromTrack): Responsible
+        for enqueuing sample buffers to the active video track.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::ensureLayer): Ensures that an AVSampleBufferDisplayLayer
+        exists.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::destroyLayer): Destroys the AVSampleBufferDisplayLayer.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::platformLayer): Replace CALayer with AVSampleBufferDisplayLayer.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::currentDisplayMode): Ditto.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::play): Call updateReadyState as a deferred task.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::currentReadyState): readyState is bumped to HAVE_ENOUGH_DATA
+        only when the MediaPlayerPrivateMediaStreamAVFObjC has received a media sample.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::sampleBufferUpdated): Called from MediaStreamTrackPrivate when a
+        new SampleBuffer is available.
+        (WebCore::updateTracksOfType): Manage adding and removing self as observer from tracks.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateTracks): Replace CALayer with AVSampleBufferDisplayLayer
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::acceleratedRenderingStateChanged): Copied from
+        MediaPlayerPrivateMediaSourceAVFObjC.mm
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::load): Deleted CALayer.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateDisplayMode): Deleted process of updating CALayer.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateIntrinsicSize): Deleted CALayer.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::createPreviewLayers): Deleted.
+        * platform/mediastream/MediaStreamPrivate.cpp:
+        (WebCore::MediaStreamPrivate::updateActiveVideoTrack): Remove redundant check.
+        * platform/mediastream/MediaStreamTrackPrivate.cpp:
+        (WebCore::MediaStreamTrackPrivate::sourceHasMoreMediaData): Called from RealtimeMediaSource when a new SampleBuffer
+        is available.
+        * platform/mediastream/MediaStreamTrackPrivate.h:
+        (WebCore::MediaStreamTrackPrivate::Observer::sampleBufferUpdated): Relays to MediaPlayerPrivateMediaStreamAVFObjC that
+        a new SampleBuffer is available to enqueue to the AVSampleBufferDisplayLayer.
+        * platform/mediastream/RealtimeMediaSource.cpp:
+        (WebCore::RealtimeMediaSource::settingsDidChange): Fix grammatical mistake in function name settingsDidChanged().
+        (WebCore::RealtimeMediaSource::mediaDataUpdated): Relays to all observers that a new SampleBuffer is available.
+        (WebCore::RealtimeMediaSource::settingsDidChanged): Deleted.
+        * platform/mediastream/RealtimeMediaSource.h:
+        * platform/mediastream/mac/AVVideoCaptureSource.mm:
+        (WebCore::AVVideoCaptureSource::processNewFrame): Calls mediaDataUpdated when a new SampleBuffer is captured.
+        * platform/mediastream/mac/MockRealtimeVideoSourceMac.h:
+        * platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
+        (WebCore::MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer): Convert CVPixelBuffer to CMSampleBuffer.
+        (WebCore::MockRealtimeVideoSourceMac::pixelBufferFromCGImage): Convert CGImage to CVPixelBuffer.
+        (WebCore::MockRealtimeVideoSourceMac::updateSampleBuffer): Creates a CMSampleBuffer from current imageBuffer and
+        sends the CMSampleBuffer to MediaPlayerPrivateMediaStreamAVFObjC
+        * platform/mock/MockRealtimeVideoSource.cpp:
+        (WebCore::MockRealtimeVideoSource::setFrameRate): Fix grammar of settingsDidChanged() to settingsDidChange().
+        (WebCore::MockRealtimeVideoSource::setSize): Ditto.
+        (WebCore::MockRealtimeVideoSource::generateFrame): Call updateSampleBuffer().
+        * platform/mock/MockRealtimeVideoSource.h: Change elapsedTime() from private to protected.
+        (WebCore::MockRealtimeVideoSource::updateSampleBuffer): Overriden by MockRealtimeVideoSourceMac.
+
</ins><span class="cx"> 2016-07-26  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Move ControlStates HashMap to RenderBox.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -985,6 +985,7 @@
</span><span class="cx">                 1AFE119A0CBFFCC4003017FA /* JSSQLResultSetRowList.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AFE11980CBFFCC4003017FA /* JSSQLResultSetRowList.h */; };
</span><span class="cx">                 1B124D8D1D380B7000ECDFB0 /* MediaSampleAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B124D8C1D380B7000ECDFB0 /* MediaSampleAVFObjC.h */; };
</span><span class="cx">                 1B124D8F1D380BB600ECDFB0 /* MediaSampleAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1B124D8E1D380BB600ECDFB0 /* MediaSampleAVFObjC.mm */; };
</span><ins>+                1BF9DB3C1D3973AD0026AEB7 /* MediaSample.h in Headers */ = {isa = PBXBuildFile; fileRef = CD641EC7181ED60100EE4C41 /* MediaSample.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 1C010700192594DF008A4201 /* InlineTextBoxStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C0106FE192594DF008A4201 /* InlineTextBoxStyle.cpp */; };
</span><span class="cx">                 1C010701192594DF008A4201 /* InlineTextBoxStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */; };
</span><span class="cx">                 1C0939EA1A13E12900B788E5 /* CachedSVGFont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C0939E81A13E12900B788E5 /* CachedSVGFont.cpp */; };
</span><span class="lines">@@ -27053,6 +27054,7 @@
</span><span class="cx">                                 75793EC90D0CE72D007FC0AC /* JSMessageEvent.h in Headers */,
</span><span class="cx">                                 E1ADEDDA0E76BD93004A1A5E /* JSMessagePort.h in Headers */,
</span><span class="cx">                                 41F584C7104652CB009CAA64 /* JSMessagePortCustom.h in Headers */,
</span><ins>+                                1BF9DB3C1D3973AD0026AEB7 /* MediaSample.h in Headers */,
</ins><span class="cx">                                 2D6F3E951C1F85550061DBD4 /* JSMockPageOverlay.h in Headers */,
</span><span class="cx">                                 E38838991BAD145F00D62EE3 /* JSModuleLoader.h in Headers */,
</span><span class="cx">                                 A86629D109DA2B48009633A5 /* JSMouseEvent.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcfCoreMediaSoftLinkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.cpp (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.cpp        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.cpp        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -80,6 +80,7 @@
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferCreate, OSStatus, (CFAllocatorRef allocator, CMBlockBufferRef dataBuffer, Boolean dataReady, CMSampleBufferMakeDataReadyCallback makeDataReadyCallback, void *makeDataReadyRefcon, CMFormatDescriptionRef formatDescription, CMItemCount numSamples, CMItemCount numSampleTimingEntries, const CMSampleTimingInfo *sampleTimingArray, CMItemCount numSampleSizeEntries, const size_t *sampleSizeArray, CMSampleBufferRef *sBufOut), (allocator, dataBuffer, dataReady, makeDataReadyCallback, makeDataReadyRefcon, formatDescription, numSamples, numSampleTimingEntries, sampleTimingArray, numSampleSizeEntries, sampleSizeArray, sBufOut))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferCreateCopy, OSStatus, (CFAllocatorRef allocator, CMSampleBufferRef sbuf, CMSampleBufferRef *sbufCopyOut), (allocator, sbuf, sbufCopyOut))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferCreateCopyWithNewTiming, OSStatus, (CFAllocatorRef allocator, CMSampleBufferRef originalSBuf, CMItemCount numSampleTimingEntries, const CMSampleTimingInfo *sampleTimingArray, CMSampleBufferRef *sBufCopyOut), (allocator, originalSBuf, numSampleTimingEntries, sampleTimingArray, sBufCopyOut))
</span><ins>+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferCreateReadyWithImageBuffer, OSStatus, (CFAllocatorRef allocator, CVImageBufferRef imageBuffer, CMVideoFormatDescriptionRef formatDescription, const CMSampleTimingInfo* sampleTiming, CMSampleBufferRef* sBufOut), (allocator, imageBuffer, formatDescription, sampleTiming, sBufOut))
</ins><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferGetDecodeTimeStamp, CMTime, (CMSampleBufferRef sbuf), (sbuf))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferGetDuration, CMTime, (CMSampleBufferRef sbuf), (sbuf))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferGetImageBuffer, CVImageBufferRef, (CMSampleBufferRef sbuf), (sbuf))
</span><span class="lines">@@ -93,6 +94,7 @@
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMTimebaseSetRate, OSStatus, (CMTimebaseRef timebase, Float64 rate), (timebase, rate))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMTimebaseSetTime, OSStatus, (CMTimebaseRef timebase, CMTime time), (timebase, time))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMTimeCopyAsDictionary, CFDictionaryRef, (CMTime time, CFAllocatorRef allocator), (time, allocator))
</span><ins>+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMVideoFormatDescriptionCreateForImageBuffer, OSStatus, (CFAllocatorRef allocator, CVImageBufferRef imageBuffer, CMVideoFormatDescriptionRef* outDesc), (allocator, imageBuffer, outDesc))
</ins><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMVideoFormatDescriptionGetDimensions, CMVideoDimensions, (CMVideoFormatDescriptionRef videoDesc), (videoDesc))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMVideoFormatDescriptionGetPresentationDimensions, CGSize, (CMVideoFormatDescriptionRef videoDesc, Boolean usePixelAspectRatio, Boolean useCleanAperture), (videoDesc, usePixelAspectRatio, useCleanAperture))
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcfCoreMediaSoftLinkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.h (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.h        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.h        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -127,6 +127,8 @@
</span><span class="cx"> #define CMSampleBufferCreateCopy softLink_CoreMedia_CMSampleBufferCreateCopy
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMSampleBufferCreateCopyWithNewTiming, OSStatus, (CFAllocatorRef allocator, CMSampleBufferRef originalSBuf, CMItemCount numSampleTimingEntries, const CMSampleTimingInfo *sampleTimingArray, CMSampleBufferRef *sBufCopyOut), (allocator, originalSBuf, numSampleTimingEntries, sampleTimingArray, sBufCopyOut))
</span><span class="cx"> #define CMSampleBufferCreateCopyWithNewTiming softLink_CoreMedia_CMSampleBufferCreateCopyWithNewTiming
</span><ins>+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMSampleBufferCreateReadyWithImageBuffer, OSStatus, (CFAllocatorRef allocator, CVImageBufferRef imageBuffer, CMVideoFormatDescriptionRef formatDescription, const CMSampleTimingInfo *sampleTiming, CMSampleBufferRef *sBufOut), (allocator, imageBuffer, formatDescription, sampleTiming, sBufOut))
+#define CMSampleBufferCreateReadyWithImageBuffer softLink_CoreMedia_CMSampleBufferCreateReadyWithImageBuffer
</ins><span class="cx"> SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMSampleBufferGetDecodeTimeStamp, CMTime, (CMSampleBufferRef sbuf), (sbuf))
</span><span class="cx"> #define CMSampleBufferGetDecodeTimeStamp softLink_CoreMedia_CMSampleBufferGetDecodeTimeStamp
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMSampleBufferGetDuration, CMTime, (CMSampleBufferRef sbuf), (sbuf))
</span><span class="lines">@@ -153,6 +155,8 @@
</span><span class="cx"> #define CMTimebaseSetTime softLink_CoreMedia_CMTimebaseSetTime
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMTimeCopyAsDictionary, CFDictionaryRef, (CMTime time, CFAllocatorRef allocator), (time, allocator))
</span><span class="cx"> #define CMTimeCopyAsDictionary softLink_CoreMedia_CMTimeCopyAsDictionary
</span><ins>+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMVideoFormatDescriptionCreateForImageBuffer, OSStatus, (CFAllocatorRef allocator, CVImageBufferRef imageBuffer, CMVideoFormatDescriptionRef *outDesc), (allocator, imageBuffer, outDesc))
+#define CMVideoFormatDescriptionCreateForImageBuffer softLink_CoreMedia_CMVideoFormatDescriptionCreateForImageBuffer
</ins><span class="cx"> SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMVideoFormatDescriptionGetDimensions, CMVideoDimensions, (CMVideoFormatDescriptionRef videoDesc), (videoDesc))
</span><span class="cx"> #define CMVideoFormatDescriptionGetDimensions softLink_CoreMedia_CMVideoFormatDescriptionGetDimensions
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMVideoFormatDescriptionGetPresentationDimensions, CGSize, (CMVideoFormatDescriptionRef videoDesc, Boolean usePixelAspectRatio, Boolean useCleanAperture), (videoDesc, usePixelAspectRatio, useCleanAperture))
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaCoreVideoSoftLinkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.cpp (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.cpp        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.cpp        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -46,6 +46,9 @@
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreVideo, CVOpenGLESTextureCacheFlush, void, (CVOpenGLESTextureCacheRef textureCache, CVOptionFlags options), (textureCache, options))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreVideo, CVOpenGLESTextureGetTarget, GLenum, (CVOpenGLESTextureRef image), (image))
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreVideo, CVOpenGLESTextureGetName, GLuint, (CVOpenGLESTextureRef image), (image))
</span><ins>+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreVideo, CVPixelBufferCreate, CVReturn, (CFAllocatorRef allocator, size_t width, size_t height, OSType pixelFormatType, CFDictionaryRef pixelBufferAttributes, CVPixelBufferRef *pixelBufferOut), (allocator, width, height, pixelFormatType, pixelBufferAttributes, pixelBufferOut))
+SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, CoreVideo, kCVPixelBufferCGBitmapContextCompatibilityKey, CFStringRef)
+SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, CoreVideo, kCVPixelBufferCGImageCompatibilityKey, CFStringRef)
</ins><span class="cx"> SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, CoreVideo, kCVPixelBufferIOSurfaceOpenGLESFBOCompatibilityKey, CFStringRef)
</span><span class="cx"> #else
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreVideo, CVOpenGLTextureCacheCreate, CVReturn, (CFAllocatorRef allocator, CFDictionaryRef cacheAttributes, CGLContextObj cglContext, CGLPixelFormatObj cglPixelFormat, CFDictionaryRef textureAttributes, CVOpenGLTextureCacheRef* cacheOut), (allocator, cacheAttributes, cglContext, cglPixelFormat, textureAttributes, cacheOut))
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaCoreVideoSoftLinkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.h (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.h        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.h        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -62,7 +62,13 @@
</span><span class="cx"> #define CVOpenGLESTextureGetTarget softLink_CoreVideo_CVOpenGLESTextureGetTarget
</span><span class="cx"> SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreVideo, CVOpenGLESTextureGetName, GLuint, (CVOpenGLESTextureRef image), (image))
</span><span class="cx"> #define CVOpenGLESTextureGetName softLink_CoreVideo_CVOpenGLESTextureGetName
</span><ins>+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreVideo, CVPixelBufferCreate, CVReturn, (CFAllocatorRef allocator, size_t width, size_t height, OSType pixelFormatType, CFDictionaryRef pixelBufferAttributes, CVPixelBufferRef *pixelBufferOut), (allocator, width, height, pixelFormatType, pixelBufferAttributes, pixelBufferOut))
+#define CVPixelBufferCreate softLink_CoreVideo_CVPixelBufferCreate
</ins><span class="cx"> 
</span><ins>+SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, CoreVideo, kCVPixelBufferCGBitmapContextCompatibilityKey, CFStringRef)
+#define kCVPixelBufferCGBitmapContextCompatibilityKey get_CoreVideo_kCVPixelBufferCGBitmapContextCompatibilityKey()
+SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, CoreVideo, kCVPixelBufferCGImageCompatibilityKey, CFStringRef)
+#define kCVPixelBufferCGImageCompatibilityKey get_CoreVideo_kCVPixelBufferCGImageCompatibilityKey()
</ins><span class="cx"> SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, CoreVideo, kCVPixelBufferIOSurfaceOpenGLESFBOCompatibilityKey, CFStringRef)
</span><span class="cx"> #define kCVPixelBufferIOSurfaceOpenGLESFBOCompatibilityKey get_CoreVideo_kCVPixelBufferIOSurfaceOpenGLESFBOCompatibilityKey()
</span><span class="cx"> #else
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationMediaSampleAVFObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/MediaSampleAVFObjC.h (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/MediaSampleAVFObjC.h        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/MediaSampleAVFObjC.h        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -32,8 +32,8 @@
</span><span class="cx"> 
</span><span class="cx"> class MediaSampleAVFObjC final : public MediaSample {
</span><span class="cx"> public:
</span><del>-    static RefPtr&lt;MediaSampleAVFObjC&gt; create(CMSampleBufferRef sample, int trackID) { return adoptRef(new MediaSampleAVFObjC(sample, trackID)); }
-    static RefPtr&lt;MediaSampleAVFObjC&gt; create(CMSampleBufferRef sample) { return adoptRef(new MediaSampleAVFObjC(sample)); }
</del><ins>+    static Ref&lt;MediaSampleAVFObjC&gt; create(CMSampleBufferRef sample, int trackID) { return adoptRef(*new MediaSampleAVFObjC(sample, trackID)); }
+    static Ref&lt;MediaSampleAVFObjC&gt; create(CMSampleBufferRef sample) { return adoptRef(*new MediaSampleAVFObjC(sample)); }
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     MediaSampleAVFObjC(CMSampleBufferRef sample)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #if ENABLE(MEDIA_STREAM) &amp;&amp; USE(AVFOUNDATION)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;MediaPlayerPrivate.h&quot;
</span><ins>+#include &quot;MediaSample.h&quot;
</ins><span class="cx"> #include &quot;MediaStreamPrivate.h&quot;
</span><span class="cx"> #include &lt;wtf/Function.h&gt;
</span><span class="cx"> #include &lt;wtf/MediaTime.h&gt;
</span><span class="lines">@@ -36,6 +37,7 @@
</span><span class="cx"> #include &lt;wtf/WeakPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> OBJC_CLASS AVSampleBufferAudioRenderer;
</span><ins>+OBJC_CLASS AVSampleBufferDisplayLayer;
</ins><span class="cx"> OBJC_CLASS AVStreamSession;
</span><span class="cx"> typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
</span><span class="cx"> 
</span><span class="lines">@@ -51,7 +53,7 @@
</span><span class="cx"> class VideoFullscreenLayerManager;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-class MediaPlayerPrivateMediaStreamAVFObjC : public MediaPlayerPrivateInterface, public MediaStreamPrivate::Observer {
</del><ins>+class MediaPlayerPrivateMediaStreamAVFObjC final : public MediaPlayerPrivateInterface, private MediaStreamPrivate::Observer, private MediaStreamTrackPrivate::Observer {
</ins><span class="cx"> public:
</span><span class="cx">     explicit MediaPlayerPrivateMediaStreamAVFObjC(MediaPlayer*);
</span><span class="cx">     virtual ~MediaPlayerPrivateMediaStreamAVFObjC();
</span><span class="lines">@@ -70,6 +72,9 @@
</span><span class="cx"> 
</span><span class="cx">     WeakPtr&lt;MediaPlayerPrivateMediaStreamAVFObjC&gt; createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
</span><span class="cx"> 
</span><ins>+    void ensureLayer();
+    void destroyLayer();
+
</ins><span class="cx"> private:
</span><span class="cx">     // MediaPlayerPrivateInterface
</span><span class="cx"> 
</span><span class="lines">@@ -117,10 +122,14 @@
</span><span class="cx"> 
</span><span class="cx">     void setSize(const IntSize&amp;) override { /* No-op */ }
</span><span class="cx"> 
</span><ins>+    void enqueueAudioSampleBufferFromTrack(MediaStreamTrackPrivate&amp;, PlatformSample);
+    void enqueueVideoSampleBufferFromTrack(MediaStreamTrackPrivate&amp;, PlatformSample);
+
</ins><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="cx">     bool metaDataAvailable() const { return m_mediaStreamPrivate &amp;&amp; m_readyState &gt;= MediaPlayer::HaveMetadata; }
</span><span class="cx"> 
</span><ins>+    void acceleratedRenderingStateChanged() override;
</ins><span class="cx">     bool supportsAcceleratedRendering() const override { return true; }
</span><span class="cx"> 
</span><span class="cx">     bool hasSingleSecurityOrigin() const override { return true; }
</span><span class="lines">@@ -139,7 +148,6 @@
</span><span class="cx">     void updateReadyState();
</span><span class="cx"> 
</span><span class="cx">     void updateIntrinsicSize(const FloatSize&amp;);
</span><del>-    void createPreviewLayers();
</del><span class="cx">     void updateTracks();
</span><span class="cx">     void renderingModeChanged();
</span><span class="cx"> 
</span><span class="lines">@@ -160,6 +168,13 @@
</span><span class="cx">     void didAddTrack(MediaStreamTrackPrivate&amp;) override;
</span><span class="cx">     void didRemoveTrack(MediaStreamTrackPrivate&amp;) override;
</span><span class="cx"> 
</span><ins>+    // MediaStreamPrivateTrack::Observer
+    void trackEnded(MediaStreamTrackPrivate&amp;) override { };
+    void trackMutedChanged(MediaStreamTrackPrivate&amp;) override { };
+    void trackSettingsChanged(MediaStreamTrackPrivate&amp;) override { };
+    void trackEnabledChanged(MediaStreamTrackPrivate&amp;) override { };
+    void sampleBufferUpdated(MediaStreamTrackPrivate&amp;, MediaSample&amp;) override;
+
</ins><span class="cx"> #if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
</span><span class="cx">     void setVideoFullscreenLayer(PlatformLayer*, std::function&lt;void()&gt; completionHandler) override;
</span><span class="cx">     void setVideoFullscreenFrame(FloatRect) override;
</span><span class="lines">@@ -168,8 +183,7 @@
</span><span class="cx">     MediaPlayer* m_player { nullptr };
</span><span class="cx">     WeakPtrFactory&lt;MediaPlayerPrivateMediaStreamAVFObjC&gt; m_weakPtrFactory;
</span><span class="cx">     RefPtr&lt;MediaStreamPrivate&gt; m_mediaStreamPrivate;
</span><del>-    mutable RetainPtr&lt;CALayer&gt; m_previewLayer;
-    mutable RetainPtr&lt;PlatformLayer&gt; m_videoBackgroundLayer;
</del><ins>+    RetainPtr&lt;AVSampleBufferDisplayLayer&gt; m_sampleBufferDisplayLayer;
</ins><span class="cx">     RetainPtr&lt;CGImageRef&gt; m_pausedImage;
</span><span class="cx">     std::unique_ptr&lt;Clock&gt; m_clock;
</span><span class="cx"> 
</span><span class="lines">@@ -185,6 +199,8 @@
</span><span class="cx">     bool m_muted { false };
</span><span class="cx">     bool m_haveEverPlayed { false };
</span><span class="cx">     bool m_ended { false };
</span><ins>+    bool m_hasEverEnqueuedVideoFrame { false };
+    bool m_hasReceivedMedia { 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 (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> #import &quot;Logging.h&quot;
</span><span class="cx"> #import &quot;MediaStreamPrivate.h&quot;
</span><span class="cx"> #import &quot;VideoTrackPrivateMediaStream.h&quot;
</span><ins>+#import &lt;AVFoundation/AVSampleBufferDisplayLayer.h&gt;
</ins><span class="cx"> #import &lt;QuartzCore/CALayer.h&gt;
</span><span class="cx"> #import &lt;QuartzCore/CATransaction.h&gt;
</span><span class="cx"> #import &lt;objc_runtime.h&gt;
</span><span class="lines">@@ -52,6 +53,8 @@
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
</span><span class="cx"> 
</span><ins>+SOFT_LINK_CLASS_OPTIONAL(AVFoundation, AVSampleBufferDisplayLayer)
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> #pragma mark -
</span><span class="lines">@@ -71,8 +74,17 @@
</span><span class="cx"> MediaPlayerPrivateMediaStreamAVFObjC::~MediaPlayerPrivateMediaStreamAVFObjC()
</span><span class="cx"> {
</span><span class="cx">     LOG(Media, &quot;MediaPlayerPrivateMediaStreamAVFObjC::~MediaPlayerPrivateMediaStreamAVFObjC(%p)&quot;, this);
</span><del>-    if (m_mediaStreamPrivate)
</del><ins>+    if (m_mediaStreamPrivate) {
</ins><span class="cx">         m_mediaStreamPrivate-&gt;removeObserver(*this);
</span><ins>+
+        for (auto&amp; track : m_mediaStreamPrivate-&gt;tracks())
+            track-&gt;removeObserver(*this);
+    }
+
+    m_audioTrackMap.clear();
+    m_videoTrackMap.clear();
+
+    destroyLayer();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #pragma mark -
</span><span class="lines">@@ -87,7 +99,7 @@
</span><span class="cx"> 
</span><span class="cx"> bool MediaPlayerPrivateMediaStreamAVFObjC::isAvailable()
</span><span class="cx"> {
</span><del>-    return AVFoundationLibrary() &amp;&amp; isCoreMediaFrameworkAvailable();
</del><ins>+    return AVFoundationLibrary() &amp;&amp; isCoreMediaFrameworkAvailable() &amp;&amp; getAVSampleBufferDisplayLayerClass();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::getSupportedTypes(HashSet&lt;String, ASCIICaseInsensitiveHash&gt;&amp; types)
</span><span class="lines">@@ -105,6 +117,60 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #pragma mark -
</span><ins>+#pragma mark AVSampleBuffer Methods
+
+void MediaPlayerPrivateMediaStreamAVFObjC::enqueueAudioSampleBufferFromTrack(MediaStreamTrackPrivate&amp;, PlatformSample)
+{
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=159836
+}
+
+void MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSampleBufferFromTrack(MediaStreamTrackPrivate&amp; track, PlatformSample platformSample)
+{
+    if (&amp;track != m_mediaStreamPrivate-&gt;activeVideoTrack())
+        return;
+
+    if (m_displayMode == LivePreview &amp;&amp; [m_sampleBufferDisplayLayer isReadyForMoreMediaData]) {
+        [m_sampleBufferDisplayLayer enqueueSampleBuffer:platformSample.sample.cmSampleBuffer];
+        
+        if (!m_hasEverEnqueuedVideoFrame) {
+            m_hasEverEnqueuedVideoFrame = true;
+            m_player-&gt;firstVideoFrameAvailable();
+        }
+    }
+}
+
+void MediaPlayerPrivateMediaStreamAVFObjC::ensureLayer()
+{
+    if (m_sampleBufferDisplayLayer)
+        return;
+    
+    m_sampleBufferDisplayLayer = adoptNS([allocAVSampleBufferDisplayLayerInstance() init]);
+#ifndef NDEBUG
+    [m_sampleBufferDisplayLayer setName:@&quot;MediaPlayerPrivateMediaStreamAVFObjC AVSampleBufferDisplayLayer&quot;];
+#endif
+    
+    renderingModeChanged();
+    
+#if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
+    m_videoFullscreenLayerManager-&gt;setVideoLayer(m_sampleBufferDisplayLayer.get(), snappedIntRect(m_player-&gt;client().mediaPlayerContentBoxRect()).size());
+#endif
+}
+
+void MediaPlayerPrivateMediaStreamAVFObjC::destroyLayer()
+{
+    if (!m_sampleBufferDisplayLayer)
+        return;
+    
+    [m_sampleBufferDisplayLayer flush];
+    m_sampleBufferDisplayLayer = nullptr;
+    renderingModeChanged();
+    
+#if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
+    m_videoFullscreenLayerManager-&gt;didDestroyVideoLayer();
+#endif
+}
+
+#pragma mark -
</ins><span class="cx"> #pragma mark MediaPlayerPrivateInterface Overrides
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::load(const String&amp;)
</span><span class="lines">@@ -129,7 +195,6 @@
</span><span class="cx"> {
</span><span class="cx">     LOG(Media, &quot;MediaPlayerPrivateMediaStreamAVFObjC::load(%p)&quot;, this);
</span><span class="cx"> 
</span><del>-    m_previewLayer = nullptr;
</del><span class="cx">     m_intrinsicSize = FloatSize();
</span><span class="cx"> 
</span><span class="cx">     m_mediaStreamPrivate = &amp;stream;
</span><span class="lines">@@ -157,19 +222,19 @@
</span><span class="cx"> 
</span><span class="cx"> PlatformLayer* MediaPlayerPrivateMediaStreamAVFObjC::platformLayer() const
</span><span class="cx"> {
</span><del>-    if (!m_videoBackgroundLayer || m_displayMode == None)
</del><ins>+    if (!m_sampleBufferDisplayLayer || m_displayMode == None)
</ins><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
</span><span class="cx">     return m_videoFullscreenLayerManager-&gt;videoInlineLayer();
</span><span class="cx"> #else
</span><del>-    return m_videoBackgroundLayer.get();
</del><ins>+    return m_sampleBufferDisplayLayer.get();
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> MediaPlayerPrivateMediaStreamAVFObjC::DisplayMode MediaPlayerPrivateMediaStreamAVFObjC::currentDisplayMode() const
</span><span class="cx"> {
</span><del>-    if (m_ended || m_intrinsicSize.isEmpty() || !metaDataAvailable() || !m_videoBackgroundLayer)
</del><ins>+    if (m_ended || m_intrinsicSize.isEmpty() || !metaDataAvailable() || !m_sampleBufferDisplayLayer)
</ins><span class="cx">         return None;
</span><span class="cx"> 
</span><span class="cx">     if (m_mediaStreamPrivate-&gt;activeVideoTrack() &amp;&amp; !m_mediaStreamPrivate-&gt;activeVideoTrack()-&gt;enabled())
</span><span class="lines">@@ -194,51 +259,6 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_displayMode == None)
</span><span class="cx">         return;
</span><del>-
-    [CATransaction begin];
-    [CATransaction setAnimationDuration:0];
-    [CATransaction setDisableActions:YES];
-
-    do {
-        if (m_displayMode &lt; LivePreview) {
-
-            if (m_displayMode == PausedImage) {
-                if (m_videoBackgroundLayer.get().contents)
-                    break;
-
-                RefPtr&lt;Image&gt; image = m_mediaStreamPrivate-&gt;currentFrameImage();
-                if (!image) {
-                    m_displayMode = PaintItBlack;
-                    continue;
-                }
-
-                m_pausedImage = image-&gt;getCGImageRef();
-                if (!m_pausedImage) {
-                    m_displayMode = PaintItBlack;
-                    continue;
-                }
-
-                m_videoBackgroundLayer.get().contents = (id)m_pausedImage.get();
-                m_videoBackgroundLayer.get().backgroundColor = nil;
-            } else {
-                m_videoBackgroundLayer.get().contents = nil;
-                m_videoBackgroundLayer.get().backgroundColor = cachedCGColor(Color::black);
-                m_pausedImage = nullptr;
-            }
-
-            m_previewLayer.get().hidden = true;
-
-        } else {
-
-            m_previewLayer.get().hidden = false;
-            m_videoBackgroundLayer.get().contents = nil;
-            m_pausedImage = nullptr;
-        }
-
-        break;
-    } while (1);
-
-    [CATransaction commit];
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::play()
</span><span class="lines">@@ -251,8 +271,9 @@
</span><span class="cx">     m_clock-&gt;start();
</span><span class="cx">     m_playing = true;
</span><span class="cx">     m_haveEverPlayed = true;
</span><del>-    updateDisplayMode();
-    updateReadyState();
</del><ins>+    scheduleDeferredTask([this] {
+        updateReadyState();
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::pause()
</span><span class="lines">@@ -341,7 +362,9 @@
</span><span class="cx">     if (!m_mediaStreamPrivate)
</span><span class="cx">         return MediaPlayer::ReadyState::HaveNothing;
</span><span class="cx"> 
</span><del>-    if (m_mediaStreamPrivate-&gt;active()) {
</del><ins>+    // https://w3c.github.io/mediacapture-main/ Change 8. from July 4, 2013.
+    // FIXME: Only update readyState to HAVE_ENOUGH_DATA when all active tracks have sent a sample buffer.
+    if (m_mediaStreamPrivate-&gt;active() &amp;&amp; m_hasReceivedMedia) {
</ins><span class="cx">         if (!m_haveEverPlayed)
</span><span class="cx">             return MediaPlayer::ReadyState::HaveFutureData;
</span><span class="cx">         return MediaPlayer::ReadyState::HaveEnoughData;
</span><span class="lines">@@ -387,46 +410,8 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_intrinsicSize = size;
</span><del>-
-    if (m_videoBackgroundLayer || !m_player || !m_player-&gt;client().mediaPlayerRenderingCanBeAccelerated(m_player))
-        return;
-
-    if (!m_mediaStreamPrivate || !m_mediaStreamPrivate-&gt;platformLayer())
-        return;
-
-    createPreviewLayers();
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaPlayerPrivateMediaStreamAVFObjC::createPreviewLayers()
-{
-    if (!m_videoBackgroundLayer) {
-        m_videoBackgroundLayer = adoptNS([[CALayer alloc] init]);
-        m_videoBackgroundLayer.get().name = @&quot;MediaPlayerPrivateMediaStreamAVFObjC preview background layer&quot;;
-
-#if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
-        m_videoFullscreenLayerManager-&gt;setVideoLayer(m_videoBackgroundLayer.get(), snappedIntRect(m_player-&gt;client().mediaPlayerContentBoxRect()).size());
-#endif
-    }
-
-    if (!m_previewLayer) {
-        m_previewLayer = m_mediaStreamPrivate-&gt;platformLayer();
-        if (m_previewLayer) {
-            m_previewLayer.get().contentsGravity = kCAGravityResizeAspect;
-            m_previewLayer.get().anchorPoint = CGPointZero;
-            if (!m_playing)
-                m_previewLayer.get().hidden = true;
-
-            [m_videoBackgroundLayer addSublayer:m_previewLayer.get()];
-#if PLATFORM(MAC)
-            [m_previewLayer setFrame:[m_videoBackgroundLayer bounds]];
-            [m_previewLayer setAutoresizingMask:(kCALayerWidthSizable | kCALayerHeightSizable)];
-#endif
-        }
-    }
-
-    renderingModeChanged();
-}
-
</del><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::renderingModeChanged()
</span><span class="cx"> {
</span><span class="cx">     updateDisplayMode();
</span><span class="lines">@@ -473,6 +458,29 @@
</span><span class="cx">     updateTracks();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MediaPlayerPrivateMediaStreamAVFObjC::sampleBufferUpdated(MediaStreamTrackPrivate&amp; track, MediaSample&amp; mediaSample)
+{
+    ASSERT(track.id() == mediaSample.trackID());
+    ASSERT(mediaSample.platformSample().type == PlatformSample::CMSampleBufferType);
+    ASSERT(m_mediaStreamPrivate);
+
+    switch (track.type()) {
+    case RealtimeMediaSource::None:
+        // Do nothing.
+        break;
+    case RealtimeMediaSource::Audio:
+        // FIXME: https://bugs.webkit.org/show_bug.cgi?id=159836
+        break;
+    case RealtimeMediaSource::Video:
+        enqueueVideoSampleBufferFromTrack(track, mediaSample.platformSample());
+        m_hasReceivedMedia = true;
+        scheduleDeferredTask([this] {
+            updateReadyState();
+        });
+        break;
+    }
+}
+
</ins><span class="cx"> #if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
</span><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::setVideoFullscreenLayer(PlatformLayer *videoFullscreenLayer, std::function&lt;void()&gt; completionHandler)
</span><span class="cx"> {
</span><span class="lines">@@ -486,7 +494,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename RefT, typename PassRefT&gt;
</span><del>-void updateTracksOfType(HashMap&lt;String, RefT&gt;&amp; trackMap, RealtimeMediaSource::Type trackType, MediaStreamTrackPrivateVector&amp; currentTracks, RefT (*itemFactory)(MediaStreamTrackPrivate&amp;), MediaPlayer* player, void (MediaPlayer::*removedFunction)(PassRefT), void (MediaPlayer::*addedFunction)(PassRefT), std::function&lt;void(RefT, int)&gt; configureCallback)
</del><ins>+void updateTracksOfType(HashMap&lt;String, RefT&gt;&amp; trackMap, RealtimeMediaSource::Type trackType, MediaStreamTrackPrivateVector&amp; currentTracks, RefT (*itemFactory)(MediaStreamTrackPrivate&amp;), MediaPlayer* player, void (MediaPlayer::*removedFunction)(PassRefT), void (MediaPlayer::*addedFunction)(PassRefT), std::function&lt;void(RefT, int)&gt; configureCallback, MediaStreamTrackPrivate::Observer* trackObserver)
</ins><span class="cx"> {
</span><span class="cx">     Vector&lt;RefT&gt; removedTracks;
</span><span class="cx">     Vector&lt;RefT&gt; addedTracks;
</span><span class="lines">@@ -519,17 +527,20 @@
</span><span class="cx">     for (const auto&amp; track : trackMap.values())
</span><span class="cx">         configureCallback(track, index++);
</span><span class="cx"> 
</span><del>-    for (auto&amp; track : removedTracks)
</del><ins>+    for (auto&amp; track : removedTracks) {
</ins><span class="cx">         (player-&gt;*removedFunction)(track);
</span><ins>+        track-&gt;streamTrack()-&gt;removeObserver(*trackObserver);
+    }
</ins><span class="cx"> 
</span><del>-    for (auto&amp; track : addedTracks)
</del><ins>+    for (auto&amp; track : addedTracks) {
</ins><span class="cx">         (player-&gt;*addedFunction)(track);
</span><ins>+        track-&gt;streamTrack()-&gt;addObserver(*trackObserver);
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateMediaStreamAVFObjC::updateTracks()
</span><span class="cx"> {
</span><span class="cx">     MediaStreamTrackPrivateVector currentTracks = m_mediaStreamPrivate-&gt;tracks();
</span><del>-    bool selectedVideoTrackChanged = false;
</del><span class="cx"> 
</span><span class="cx">     std::function&lt;void(RefPtr&lt;AudioTrackPrivateMediaStream&gt;, int)&gt; enableAudioTrack = [this](auto track, int index)
</span><span class="cx">     {
</span><span class="lines">@@ -536,24 +547,17 @@
</span><span class="cx">         track-&gt;setTrackIndex(index);
</span><span class="cx">         track-&gt;setEnabled(track-&gt;streamTrack()-&gt;enabled() &amp;&amp; !track-&gt;streamTrack()-&gt;muted());
</span><span class="cx">     };
</span><del>-    updateTracksOfType(m_audioTrackMap, RealtimeMediaSource::Audio, currentTracks, &amp;AudioTrackPrivateMediaStream::create, m_player, &amp;MediaPlayer::removeAudioTrack, &amp;MediaPlayer::addAudioTrack, enableAudioTrack);
</del><ins>+    updateTracksOfType(m_audioTrackMap, RealtimeMediaSource::Audio, currentTracks, &amp;AudioTrackPrivateMediaStream::create, m_player, &amp;MediaPlayer::removeAudioTrack, &amp;MediaPlayer::addAudioTrack, enableAudioTrack, (MediaStreamTrackPrivate::Observer*) this);
</ins><span class="cx"> 
</span><del>-    std::function&lt;void(RefPtr&lt;VideoTrackPrivateMediaStream&gt;, int)&gt; enableVideoTrack = [this, &amp;selectedVideoTrackChanged](auto track, int index)
</del><ins>+    std::function&lt;void(RefPtr&lt;VideoTrackPrivateMediaStream&gt;, int)&gt; enableVideoTrack = [this](auto track, int index)
</ins><span class="cx">     {
</span><del>-        bool wasSelected = track-&gt;selected();
</del><span class="cx">         track-&gt;setTrackIndex(index);
</span><span class="cx">         track-&gt;setSelected(track-&gt;streamTrack() == m_mediaStreamPrivate-&gt;activeVideoTrack());
</span><del>-        if (wasSelected != track-&gt;selected())
-            selectedVideoTrackChanged = true;
</del><ins>+
+        if (track-&gt;selected())
+            ensureLayer();
</ins><span class="cx">     };
</span><del>-    updateTracksOfType(m_videoTrackMap, RealtimeMediaSource::Video, currentTracks, &amp;VideoTrackPrivateMediaStream::create, m_player, &amp;MediaPlayer::removeVideoTrack, &amp;MediaPlayer::addVideoTrack, enableVideoTrack);
-
-    if (selectedVideoTrackChanged) {
-        if (m_previewLayer)
-            m_previewLayer = nullptr;
-
-        createPreviewLayers();
-    }
</del><ins>+    updateTracksOfType(m_videoTrackMap, RealtimeMediaSource::Video, currentTracks, &amp;VideoTrackPrivateMediaStream::create, m_player, &amp;MediaPlayer::removeVideoTrack, &amp;MediaPlayer::addVideoTrack, enableVideoTrack, (MediaStreamTrackPrivate::Observer*) this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;PlatformTimeRanges&gt; MediaPlayerPrivateMediaStreamAVFObjC::seekable() const
</span><span class="lines">@@ -593,6 +597,14 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MediaPlayerPrivateMediaStreamAVFObjC::acceleratedRenderingStateChanged()
+{
+    if (m_player-&gt;client().mediaPlayerRenderingCanBeAccelerated(m_player))
+        ensureLayer();
+    else
+        destroyLayer();
+}
+
</ins><span class="cx"> String MediaPlayerPrivateMediaStreamAVFObjC::engineDescription() const
</span><span class="cx"> {
</span><span class="cx">     static NeverDestroyed&lt;String&gt; description(ASCIILiteral(&quot;AVFoundation MediaStream Engine&quot;));
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamMediaStreamPrivatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -257,7 +257,7 @@
</span><span class="cx"> {
</span><span class="cx">     m_activeVideoTrack = nullptr;
</span><span class="cx">     for (auto&amp; track : m_trackSet.values()) {
</span><del>-        if (!track-&gt;ended() &amp;&amp; track-&gt;type() == RealtimeMediaSource::Type::Video &amp;&amp; !track-&gt;ended()) {
</del><ins>+        if (!track-&gt;ended() &amp;&amp; track-&gt;type() == RealtimeMediaSource::Type::Video) {
</ins><span class="cx">             m_activeVideoTrack = track.get();
</span><span class="cx">             break;
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamMediaStreamTrackPrivatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -213,6 +213,13 @@
</span><span class="cx">     return !m_isEnded;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MediaStreamTrackPrivate::sourceHasMoreMediaData(MediaSample&amp; mediaSample)
+{
+    mediaSample.setTrackID(id());
+    for (auto&amp; observer : m_observers)
+        observer-&gt;sampleBufferUpdated(*this, mediaSample);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(MEDIA_STREAM)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamMediaStreamTrackPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> 
</span><span class="cx"> class AudioSourceProvider;
</span><span class="cx"> class GraphicsContext;
</span><ins>+class MediaSample;
</ins><span class="cx"> class MediaSourceSettings;
</span><span class="cx"> class RealtimeMediaSourceCapabilities;
</span><span class="cx"> 
</span><span class="lines">@@ -50,6 +51,7 @@
</span><span class="cx">         virtual void trackMutedChanged(MediaStreamTrackPrivate&amp;) = 0;
</span><span class="cx">         virtual void trackSettingsChanged(MediaStreamTrackPrivate&amp;) = 0;
</span><span class="cx">         virtual void trackEnabledChanged(MediaStreamTrackPrivate&amp;) = 0;
</span><ins>+        virtual void sampleBufferUpdated(MediaStreamTrackPrivate&amp;, MediaSample&amp;) { };
</ins><span class="cx">     };
</span><span class="cx">     
</span><span class="cx">     static RefPtr&lt;MediaStreamTrackPrivate&gt; create(RefPtr&lt;RealtimeMediaSource&gt;&amp;&amp;);
</span><span class="lines">@@ -104,6 +106,7 @@
</span><span class="cx">     void sourceMutedChanged() final;
</span><span class="cx">     void sourceSettingsChanged() final;
</span><span class="cx">     bool preventSourceFromStopping() final;
</span><ins>+    void sourceHasMoreMediaData(MediaSample&amp;) final;
</ins><span class="cx"> 
</span><span class="cx">     Vector&lt;Observer*&gt; m_observers;
</span><span class="cx">     RefPtr&lt;RealtimeMediaSource&gt; m_source;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamRealtimeMediaSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -90,12 +90,18 @@
</span><span class="cx">         observer-&gt;sourceMutedChanged();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RealtimeMediaSource::settingsDidChanged()
</del><ins>+void RealtimeMediaSource::settingsDidChange()
</ins><span class="cx"> {
</span><span class="cx">     for (auto&amp; observer : m_observers)
</span><span class="cx">         observer-&gt;sourceSettingsChanged();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void RealtimeMediaSource::mediaDataUpdated(MediaSample&amp; mediaSample)
+{
+    for (auto&amp; observer : m_observers)
+        observer-&gt;sourceHasMoreMediaData(mediaSample);
+}
+
</ins><span class="cx"> bool RealtimeMediaSource::readonly() const
</span><span class="cx"> {
</span><span class="cx">     return m_readonly;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreamRealtimeMediaSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #include &quot;AudioSourceProvider.h&quot;
</span><span class="cx"> #include &quot;Image.h&quot;
</span><span class="cx"> #include &quot;MediaConstraints.h&quot;
</span><ins>+#include &quot;MediaSample.h&quot;
</ins><span class="cx"> #include &quot;PlatformLayer.h&quot;
</span><span class="cx"> #include &quot;RealtimeMediaSourceCapabilities.h&quot;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="lines">@@ -66,6 +67,9 @@
</span><span class="cx"> 
</span><span class="cx">         // Observer state queries.
</span><span class="cx">         virtual bool preventSourceFromStopping() = 0;
</span><ins>+        
+        // Media data changes.
+        virtual void sourceHasMoreMediaData(MediaSample&amp;) = 0;
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     virtual ~RealtimeMediaSource() { }
</span><span class="lines">@@ -86,7 +90,8 @@
</span><span class="cx"> 
</span><span class="cx">     virtual RefPtr&lt;RealtimeMediaSourceCapabilities&gt; capabilities() = 0;
</span><span class="cx">     virtual const RealtimeMediaSourceSettings&amp; settings() = 0;
</span><del>-    void settingsDidChanged();
</del><ins>+    void settingsDidChange();
+    void mediaDataUpdated(MediaSample&amp;);
</ins><span class="cx">     
</span><span class="cx">     bool stopped() const { return m_stopped; }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVVideoCaptureSourcemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #import &quot;IntRect.h&quot;
</span><span class="cx"> #import &quot;Logging.h&quot;
</span><span class="cx"> #import &quot;MediaConstraints.h&quot;
</span><ins>+#import &quot;MediaSampleAVFObjC.h&quot;
</ins><span class="cx"> #import &quot;NotImplemented.h&quot;
</span><span class="cx"> #import &quot;PlatformLayer.h&quot;
</span><span class="cx"> #import &quot;RealtimeMediaSourceCenter.h&quot;
</span><span class="lines">@@ -298,7 +299,9 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (settingsChanged)
</span><del>-        this-&gt;settingsDidChanged();
</del><ins>+        settingsDidChange();
+
+    mediaDataUpdated(MediaSampleAVFObjC::create(sampleBuffer.get()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AVVideoCaptureSource::captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutputType*, CMSampleBufferRef sampleBuffer, AVCaptureConnectionType*)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacMockRealtimeVideoSourceMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -37,6 +37,10 @@
</span><span class="cx"> #include &quot;MockRealtimeVideoSource.h&quot;
</span><span class="cx"> #include &lt;wtf/RunLoop.h&gt;
</span><span class="cx"> 
</span><ins>+typedef struct __CVBuffer *CVBufferRef;
+typedef CVBufferRef CVImageBufferRef;
+typedef CVImageBufferRef CVPixelBufferRef;
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class MockRealtimeVideoSourceMac final : public MockRealtimeVideoSource {
</span><span class="lines">@@ -48,8 +52,12 @@
</span><span class="cx">     friend class MockRealtimeVideoSource;
</span><span class="cx">     MockRealtimeVideoSourceMac();
</span><span class="cx"> 
</span><ins>+    RetainPtr&lt;CMSampleBufferRef&gt; CMSampleBufferFromPixelBuffer(CVPixelBufferRef);
+    RetainPtr&lt;CVPixelBufferRef&gt; pixelBufferFromCGImage(CGImageRef) const;
+
</ins><span class="cx">     PlatformLayer* platformLayer() const override;
</span><span class="cx">     void updatePlatformLayer() const override;
</span><ins>+    void updateSampleBuffer() override;
</ins><span class="cx"> 
</span><span class="cx">     mutable RetainPtr&lt;CGImageRef&gt; m_previewImage;
</span><span class="cx">     mutable RetainPtr&lt;PlatformLayer&gt; m_previewLayer;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacMockRealtimeVideoSourceMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #import &quot;GraphicsContextCG.h&quot;
</span><span class="cx"> #import &quot;ImageBuffer.h&quot;
</span><span class="cx"> #import &quot;MediaConstraints.h&quot;
</span><ins>+#import &quot;MediaSampleAVFObjC.h&quot;
</ins><span class="cx"> #import &quot;NotImplemented.h&quot;
</span><span class="cx"> #import &quot;PlatformLayer.h&quot;
</span><span class="cx"> #import &quot;RealtimeMediaSourceSettings.h&quot;
</span><span class="lines">@@ -42,6 +43,9 @@
</span><span class="cx"> #import &lt;QuartzCore/CATransaction.h&gt;
</span><span class="cx"> #import &lt;objc/runtime.h&gt;
</span><span class="cx"> 
</span><ins>+#import &quot;CoreMediaSoftLink.h&quot;
+#import &quot;CoreVideoSoftLink.h&quot;
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> Ref&lt;MockRealtimeVideoSource&gt; MockRealtimeVideoSource::create()
</span><span class="lines">@@ -54,6 +58,57 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RetainPtr&lt;CMSampleBufferRef&gt; MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer(CVPixelBufferRef pixelBuffer)
+{
+    if (!pixelBuffer)
+        return nullptr;
+
+    CMSampleTimingInfo timingInfo;
+
+    timingInfo.presentationTimeStamp = CMTimeMake(elapsedTime() * 1000, 1000);
+    timingInfo.decodeTimeStamp = kCMTimeInvalid;
+    timingInfo.duration = kCMTimeInvalid;
+
+    CMVideoFormatDescriptionRef formatDescription = nullptr;
+    OSStatus status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, &amp;formatDescription);
+    if (status != noErr) {
+        LOG_ERROR(&quot;Failed to initialize CMVideoFormatDescription with error code: %d&quot;, status);
+        return nullptr;
+    }
+
+    CMSampleBufferRef sampleBuffer;
+    status = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, formatDescription, &amp;timingInfo, &amp;sampleBuffer);
+    CFRelease(formatDescription);
+    if (status != noErr) {
+        LOG_ERROR(&quot;Failed to initialize CMSampleBuffer with error code: %d&quot;, status);
+        return nullptr;
+    }
+
+    return adoptCF(sampleBuffer);
+}
+
+RetainPtr&lt;CVPixelBufferRef&gt; MockRealtimeVideoSourceMac::pixelBufferFromCGImage(CGImageRef image) const
+{
+    CGSize frameSize = CGSizeMake(CGImageGetWidth(image), CGImageGetHeight(image));
+    CFDictionaryRef options = (__bridge CFDictionaryRef) @{
+        (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: @(NO),
+        (__bridge NSString *)kCVPixelBufferCGBitmapContextCompatibilityKey: @(NO)
+    };
+    CVPixelBufferRef pixelBuffer;
+    CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, frameSize.width, frameSize.height, kCVPixelFormatType_32ARGB, options, &amp;pixelBuffer);
+    if (status != kCVReturnSuccess)
+        return nullptr;
+
+    CVPixelBufferLockBaseAddress(pixelBuffer, 0);
+    void* data = CVPixelBufferGetBaseAddress(pixelBuffer);
+    auto rgbColorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
+    auto context = adoptCF(CGBitmapContextCreate(data, frameSize.width, frameSize.height, 8, CVPixelBufferGetBytesPerRow(pixelBuffer), rgbColorSpace.get(), (CGBitmapInfo) kCGImageAlphaNoneSkipFirst));
+    CGContextDrawImage(context.get(), CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image);
+    CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
+
+    return adoptCF(pixelBuffer);
+}
+
</ins><span class="cx"> PlatformLayer* MockRealtimeVideoSourceMac::platformLayer() const
</span><span class="cx"> {
</span><span class="cx">     if (m_previewLayer)
</span><span class="lines">@@ -97,6 +152,14 @@
</span><span class="cx">     [CATransaction commit];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MockRealtimeVideoSourceMac::updateSampleBuffer()
+{
+    auto pixelBuffer = pixelBufferFromCGImage(imageBuffer()-&gt;copyImage()-&gt;getCGImageRef());
+    auto sampleBuffer = CMSampleBufferFromPixelBuffer(pixelBuffer.get());
+    
+    mediaDataUpdated(MediaSampleAVFObjC::create(sampleBuffer.get()));
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(MEDIA_STREAM)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmockMockRealtimeVideoSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -134,7 +134,7 @@
</span><span class="cx">     if (m_timer.isActive())
</span><span class="cx">         m_timer.startRepeating(std::chrono::milliseconds(lround(1000 / m_frameRate)));
</span><span class="cx"> 
</span><del>-    settingsDidChanged();
</del><ins>+    settingsDidChange();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MockRealtimeVideoSource::setSize(const IntSize&amp; size)
</span><span class="lines">@@ -169,7 +169,7 @@
</span><span class="cx">     m_imageBuffer = nullptr;
</span><span class="cx">     updatePlatformLayer();
</span><span class="cx"> 
</span><del>-    settingsDidChanged();
</del><ins>+    settingsDidChange();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MockRealtimeVideoSource::drawAnimation(GraphicsContext&amp; context)
</span><span class="lines">@@ -331,6 +331,7 @@
</span><span class="cx">     drawBoxes(context);
</span><span class="cx"> 
</span><span class="cx">     updatePlatformLayer();
</span><ins>+    updateSampleBuffer();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ImageBuffer* MockRealtimeVideoSource::imageBuffer() const
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmockMockRealtimeVideoSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.h (203738 => 203739)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.h        2016-07-26 21:49:26 UTC (rev 203738)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.h        2016-07-26 21:52:27 UTC (rev 203739)
</span><span class="lines">@@ -59,9 +59,12 @@
</span><span class="cx"> protected:
</span><span class="cx">     MockRealtimeVideoSource(const String&amp; name = ASCIILiteral(&quot;Mock video device&quot;));
</span><span class="cx">     virtual void updatePlatformLayer() const { }
</span><ins>+    virtual void updateSampleBuffer() { }
</ins><span class="cx"> 
</span><span class="cx">     ImageBuffer* imageBuffer() const;
</span><span class="cx"> 
</span><ins>+    double elapsedTime();
+
</ins><span class="cx"> private:
</span><span class="cx">     void updateSettings(RealtimeMediaSourceSettings&amp;) override;
</span><span class="cx">     void initializeCapabilities(RealtimeMediaSourceCapabilities&amp;) override;
</span><span class="lines">@@ -80,8 +83,6 @@
</span><span class="cx"> 
</span><span class="cx">     void generateFrame();
</span><span class="cx"> 
</span><del>-    double elapsedTime();
-
</del><span class="cx">     float m_baseFontSize { 0 };
</span><span class="cx">     FontCascade m_timeFont;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>