<!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>[210742] 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/210742">210742</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2017-01-13 13:27:30 -0800 (Fri, 13 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[MediaStream, Mac] Add mock audio source
https://bugs.webkit.org/show_bug.cgi?id=166974

Reviewed by Jer Noble.
Source/WebCore:

Add a mock audio source for testing media streams.

No new tests, updated webaudio/mediastreamaudiosourcenode.html.

* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueAudioSample):
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample):

* platform/mediastream/mac/AVAudioCaptureSource.h:
(WebCore::AVAudioCaptureSource::Observer::~Observer): Deleted.

* platform/mediastream/mac/AVAudioCaptureSource.mm:
(WebCore::AVAudioCaptureSource::addObserver):
(WebCore::AVAudioCaptureSource::removeObserver):
(WebCore::AVAudioCaptureSource::start):

* platform/mediastream/mac/MockRealtimeAudioSourceMac.h: Added.
* platform/mediastream/mac/MockRealtimeAudioSourceMac.mm: Added.
(WebCore::MockRealtimeAudioSource::create):
(WebCore::MockRealtimeAudioSourceMac::MockRealtimeAudioSourceMac):
(WebCore::MockRealtimeAudioSource::createMuted):
(WebCore::MockRealtimeAudioSourceMac::addObserver):
(WebCore::MockRealtimeAudioSourceMac::removeObserver):
(WebCore::MockRealtimeAudioSourceMac::start):
(WebCore::MockRealtimeAudioSourceMac::emitSampleBuffers):
(WebCore::MockRealtimeAudioSourceMac::reconfigure):
(WebCore::MockRealtimeAudioSourceMac::render):
(WebCore::MockRealtimeAudioSourceMac::applySampleRate):
(WebCore::MockRealtimeAudioSourceMac::audioSourceProvider):

* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h:
* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
(WebCore::WebAudioSourceProviderAVFObjC::create):
(WebCore::WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC):
(WebCore::WebAudioSourceProviderAVFObjC::~WebAudioSourceProviderAVFObjC):
(WebCore::WebAudioSourceProviderAVFObjC::provideInput):
(WebCore::WebAudioSourceProviderAVFObjC::setClient):
(WebCore::WebAudioSourceProviderAVFObjC::startProducingData): Deleted.
(WebCore::WebAudioSourceProviderAVFObjC::stopProducingData): Deleted.

* platform/mock/MockRealtimeAudioSource.cpp:
(WebCore::MockRealtimeAudioSource::MockRealtimeAudioSource):
(WebCore::MockRealtimeAudioSource::startProducingData):
(WebCore::MockRealtimeAudioSource::stopProducingData):
(WebCore::MockRealtimeAudioSource::elapsedTime):
(WebCore::MockRealtimeAudioSource::tick):

* platform/mock/MockRealtimeAudioSource.h:
(WebCore::MockRealtimeAudioSource::render):
(WebCore::MockRealtimeAudioSource::renderInterval):
(WebCore::MockRealtimeAudioSource::~MockRealtimeAudioSource): Deleted.

LayoutTests:

* webaudio/mediastreamaudiosourcenode-expected.txt:
* webaudio/mediastreamaudiosourcenode.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestswebaudiomediastreamaudiosourcenodeexpectedtxt">trunk/LayoutTests/webaudio/mediastreamaudiosourcenode-expected.txt</a></li>
<li><a href="#trunkLayoutTestswebaudiomediastreamaudiosourcenodehtml">trunk/LayoutTests/webaudio/mediastreamaudiosourcenode.html</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="#trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCmm">trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVAudioCaptureSourceh">trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVAudioCaptureSourcemm">trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacWebAudioSourceProviderAVFObjCh">trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacWebAudioSourceProviderAVFObjCmm">trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmockMockRealtimeAudioSourcecpp">trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmockMockRealtimeAudioSourceh">trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAudioCaptureSourceProviderObjCh">trunk/Source/WebCore/platform/mediastream/mac/AudioCaptureSourceProviderObjC.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAudioSourceObserverObjCh">trunk/Source/WebCore/platform/mediastream/mac/AudioSourceObserverObjC.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacMockRealtimeAudioSourceMach">trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacMockRealtimeAudioSourceMacmm">trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/LayoutTests/ChangeLog        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2017-01-13  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        [MediaStream, Mac] Add mock audio source
+        https://bugs.webkit.org/show_bug.cgi?id=166974
+
+        Reviewed by Jer Noble.
+
+        * webaudio/mediastreamaudiosourcenode-expected.txt:
+        * webaudio/mediastreamaudiosourcenode.html:
+
</ins><span class="cx"> 2017-01-13  Sam Weinig  &lt;sam@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [WebIDL] Remove custom bindings for DeviceMotionEvent and DeviceOrientationEvent
</span></span></pre></div>
<a id="trunkLayoutTestswebaudiomediastreamaudiosourcenodeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/webaudio/mediastreamaudiosourcenode-expected.txt (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webaudio/mediastreamaudiosourcenode-expected.txt        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/LayoutTests/webaudio/mediastreamaudiosourcenode-expected.txt        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -3,14 +3,15 @@
</span><span class="cx"> On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
</span><span class="cx"> 
</span><span class="cx"> PASS {audio:true} generated stream
</span><del>-PASS s.getAudioTracks().length is 1
-PASS s.getVideoTracks().length is 0
</del><ins>+PASS stream.getAudioTracks().length is 1
+PASS stream.getVideoTracks().length is 0
</ins><span class="cx"> PASS Source AudioNode has no inputs.
</span><span class="cx"> PASS Source AudioNode has one output.
</span><del>-PASS connect() exception thrown for illegal destination AudioNode.
-PASS connect() exception thrown for illegal output index.
-PASS connect() exception thrown for illegal input index.
</del><ins>+PASS connect() exception {&quot;TypeError&quot;, &quot;Argument 1 ('destination') to AudioNode.connect must be an instance of AudioNode&quot;} thrown for illegal destination AudioNode
+PASS connect() exception {&quot;IndexSizeError&quot;, &quot;The index is not in the allowed range.&quot;} thrown for illegal output index
+PASS connect() exception {&quot;IndexSizeError&quot;, &quot;The index is not in the allowed range.&quot;} thrown for illegal input index
</ins><span class="cx"> PASS mediaStreamSource.connect(context.destination) succeeded.
</span><ins>+PASS onaudioprocess was called
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestswebaudiomediastreamaudiosourcenodehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/webaudio/mediastreamaudiosourcenode.html (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webaudio/mediastreamaudiosourcenode.html        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/LayoutTests/webaudio/mediastreamaudiosourcenode.html        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -1,96 +1,114 @@
</span><span class="cx"> &lt;!DOCTYPE html&gt;
</span><del>-
</del><span class="cx"> &lt;html&gt;
</span><del>-&lt;head&gt;
-&lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
-&lt;script src=&quot;resources/audio-testing.js&quot;&gt;&lt;/script&gt;
-&lt;/head&gt;
</del><ins>+    &lt;head&gt;
+        &lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+    &lt;/head&gt;
</ins><span class="cx"> 
</span><del>-&lt;body&gt;
-&lt;div id=&quot;description&quot;&gt;&lt;/div&gt;
-&lt;div id=&quot;console&quot;&gt;&lt;/div&gt;
</del><ins>+    &lt;body&gt;
+        &lt;div id=&quot;description&quot;&gt;&lt;/div&gt;
+        &lt;div id=&quot;console&quot;&gt;&lt;/div&gt;
</ins><span class="cx"> 
</span><del>-&lt;script&gt;
-description(&quot;Basic tests for MediaStreamAudioSourceNode API.&quot;);
</del><ins>+        &lt;script&gt;
+            description(&quot;Basic tests for MediaStreamAudioSourceNode API.&quot;);
</ins><span class="cx"> 
</span><del>-var context = 0;
</del><ins>+            let context;
+            let stream;
+            let finished = false;
+            const numberOfOutputChannels = 2;
+            const numberOfInputChannels = 2;
+            const bufferSize = 512;
</ins><span class="cx"> 
</span><del>-function error() {
-    testFailed('Stream generation failed.');
-    finishJSTest();
-}
</del><ins>+            function processAudioData(event) 
+            {
+                if (finished)
+                    return;
</ins><span class="cx"> 
</span><del>-function getUserMedia(dictionary, callback) {
-    try {
-        navigator.webkitGetUserMedia(dictionary, callback, error);
-    } catch (e) {
-        testFailed('webkitGetUserMedia threw exception :' + e);
-        finishJSTest();
-    }
-}
</del><ins>+                if (event.inputBuffer.numberOfChannels != numberOfInputChannels)
+                    testFailed(`numberOfInputChannels doesn't match: have ${event.inputBuffer.numberOfChannels}, expect ${numberOfInputChannels}!`);
</ins><span class="cx"> 
</span><del>-function gotStream(stream) {
-    s = stream;
-    testPassed('{audio:true} generated stream');
-    shouldBe('s.getAudioTracks().length', '1');
-    shouldBe('s.getVideoTracks().length', '0');
</del><ins>+                if (event.outputBuffer.numberOfChannels != numberOfOutputChannels)
+                    testFailed(`numberOfOutputChannels doesn't match: have ${event.outputBuffer.numberOfChannels}, expect ${numberOfOutputChannels}!`);
</ins><span class="cx"> 
</span><del>-    context = new webkitAudioContext();
</del><ins>+                stream.getAudioTracks()[0].stop();
+                testPassed(&quot;onaudioprocess was called&quot;);
+                finishJSTest();
+                finished = true;
+            }
</ins><span class="cx"> 
</span><del>-    // Create an AudioNode from the stream.
-    var mediaStreamSource = context.createMediaStreamSource(stream);
</del><ins>+            function gotStream(s)
+            {
+                stream = s;
+                testPassed('{audio:true} generated stream');
+                shouldBe('stream.getAudioTracks().length', '1');
+                shouldBe('stream.getVideoTracks().length', '0');
</ins><span class="cx"> 
</span><del>-    // Check number of inputs and outputs.
-    if (mediaStreamSource.numberOfInputs == 0)
-        testPassed(&quot;Source AudioNode has no inputs.&quot;);
-    else
-        testFailed(&quot;Source AudioNode should not have inputs.&quot;);
</del><ins>+                context = new webkitAudioContext();
</ins><span class="cx"> 
</span><del>-    if (mediaStreamSource.numberOfOutputs == 1)
-        testPassed(&quot;Source AudioNode has one output.&quot;);
-    else
-        testFailed(&quot;Source AudioNode should have one output.&quot;);
</del><ins>+                // Create an AudioNode from the stream.
+                let mediaStreamSource = context.createMediaStreamSource(stream);
</ins><span class="cx"> 
</span><del>-    // Try calling connect() method with illegal values.
</del><ins>+                // Check number of inputs and outputs.
+                if (mediaStreamSource.numberOfInputs == 0)
+                    testPassed(&quot;Source AudioNode has no inputs.&quot;);
+                else
+                    testFailed(&quot;Source AudioNode should not have inputs.&quot;);
</ins><span class="cx"> 
</span><del>-    try {
-        mediaStreamSource.connect(0, 0, 0);
-        testFailed(&quot;connect() exception should be thrown for illegal destination AudioNode.&quot;);
-    } catch(e) {
-        testPassed(&quot;connect() exception thrown for illegal destination AudioNode.&quot;);
-    }
</del><ins>+                if (mediaStreamSource.numberOfOutputs == 1)
+                    testPassed(&quot;Source AudioNode has one output.&quot;);
+                else
+                    testFailed(&quot;Source AudioNode should have one output.&quot;);
</ins><span class="cx"> 
</span><del>-    try {
-        mediaStreamSource.connect(context.destination, 5, 0);
-        testFailed(&quot;connect() exception should be thrown for illegal output index.&quot;);
-    } catch(e) {
-        testPassed(&quot;connect() exception thrown for illegal output index.&quot;);
-    }
</del><ins>+                // Try calling connect() method with illegal values.
+                try {
+                    mediaStreamSource.connect(0, 0, 0);
+                    testFailed(&quot;connect() exception should be thrown for illegal destination AudioNode.&quot;);
+                } catch(err) {
+                    testPassed(`connect() exception {&quot;${err.name}&quot;, &quot;${err.message}&quot;} thrown for illegal destination AudioNode`);
+                }
</ins><span class="cx"> 
</span><del>-    try {
-        mediaStreamSource.connect(context.destination, 0, 5);
-        testFailed(&quot;connect() exception should be thrown for illegal input index.&quot;);
-    } catch(e) {
-        testPassed(&quot;connect() exception thrown for illegal input index.&quot;);
-    }
</del><ins>+                try {
+                    mediaStreamSource.connect(context.destination, 5, 0);
+                    testFailed(&quot;connect() exception should be thrown for illegal output index.&quot;);
+                } catch(err) {
+                    testPassed(`connect() exception {&quot;${err.name}&quot;, &quot;${err.message}&quot;} thrown for illegal output index`);
+                }
</ins><span class="cx"> 
</span><del>-    // Try calling connect() with proper values.
-    try {
-        mediaStreamSource.connect(context.destination, 0, 0);
-        testPassed(&quot;mediaStreamSource.connect(context.destination) succeeded.&quot;);
-    } catch(e) {
-        testFailed(&quot;mediaStreamSource.connect(context.destination) failed.&quot;);
-    }
</del><ins>+                try {
+                    mediaStreamSource.connect(context.destination, 0, 5);
+                    testFailed(&quot;connect() exception should be thrown for illegal input index.&quot;);
+                } catch(err) {
+                    testPassed(`connect() exception {&quot;${err.name}&quot;, &quot;${err.message}&quot;} thrown for illegal input index`);
+                }
</ins><span class="cx"> 
</span><del>-    finishJSTest();
-}
</del><ins>+                // Try calling connect() with legal values.
+                try {
+                    mediaStreamSource.connect(context.destination, 0, 0);
+                    testPassed(&quot;mediaStreamSource.connect(context.destination) succeeded.&quot;);
+                } catch(err) {
+                    testFailed(`mediaStreamSource.connect(context.destination) failed with &quot;${err.name}&quot;: &quot;${err.message}&quot;`);
+                }
</ins><span class="cx"> 
</span><del>-getUserMedia({audio:true}, gotStream);
-window.jsTestIsAsync = true;
-window.successfullyParsed = true;
</del><ins>+                let scriptProcessorNode = context.createScriptProcessor(bufferSize, numberOfInputChannels, numberOfOutputChannels);
+                scriptProcessorNode.onaudioprocess = processAudioData;
</ins><span class="cx"> 
</span><del>-&lt;/script&gt;
</del><ins>+                mediaStreamSource.connect(scriptProcessorNode);
+                scriptProcessorNode.connect(context.destination);
+            }
</ins><span class="cx"> 
</span><del>-&lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
-&lt;/body&gt;
</del><ins>+            if (window.testRunner)
+                testRunner.setUserMediaPermission(true);
+
+            navigator.mediaDevices.getUserMedia({audio:true})
+                .then(stream =&gt; gotStream(stream))
+                .catch(function(err) {
+                    testFailed(`mediaDevices.getUserMedia() failed with &quot;${err.name}&quot;: &quot;${err.message}&quot;`);
+                    finishJSTest();
+                });
+
+            window.jsTestIsAsync = true;
+            window.successfullyParsed = true;
+        &lt;/script&gt;
+        &lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+
+    &lt;/body&gt;
</ins><span class="cx"> &lt;/html&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/ChangeLog        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -1,3 +1,63 @@
</span><ins>+2017-01-13  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        [MediaStream, Mac] Add mock audio source
+        https://bugs.webkit.org/show_bug.cgi?id=166974
+
+        Reviewed by Jer Noble.
+        
+        Add a mock audio source for testing media streams.
+
+        No new tests, updated webaudio/mediastreamaudiosourcenode.html.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueAudioSample):
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample):
+
+        * platform/mediastream/mac/AVAudioCaptureSource.h:
+        (WebCore::AVAudioCaptureSource::Observer::~Observer): Deleted.
+
+        * platform/mediastream/mac/AVAudioCaptureSource.mm:
+        (WebCore::AVAudioCaptureSource::addObserver):
+        (WebCore::AVAudioCaptureSource::removeObserver):
+        (WebCore::AVAudioCaptureSource::start):
+
+        * platform/mediastream/mac/MockRealtimeAudioSourceMac.h: Added.
+        * platform/mediastream/mac/MockRealtimeAudioSourceMac.mm: Added.
+        (WebCore::MockRealtimeAudioSource::create):
+        (WebCore::MockRealtimeAudioSourceMac::MockRealtimeAudioSourceMac):
+        (WebCore::MockRealtimeAudioSource::createMuted):
+        (WebCore::MockRealtimeAudioSourceMac::addObserver):
+        (WebCore::MockRealtimeAudioSourceMac::removeObserver):
+        (WebCore::MockRealtimeAudioSourceMac::start):
+        (WebCore::MockRealtimeAudioSourceMac::emitSampleBuffers):
+        (WebCore::MockRealtimeAudioSourceMac::reconfigure):
+        (WebCore::MockRealtimeAudioSourceMac::render):
+        (WebCore::MockRealtimeAudioSourceMac::applySampleRate):
+        (WebCore::MockRealtimeAudioSourceMac::audioSourceProvider):
+
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h:
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
+        (WebCore::WebAudioSourceProviderAVFObjC::create):
+        (WebCore::WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC):
+        (WebCore::WebAudioSourceProviderAVFObjC::~WebAudioSourceProviderAVFObjC):
+        (WebCore::WebAudioSourceProviderAVFObjC::provideInput):
+        (WebCore::WebAudioSourceProviderAVFObjC::setClient):
+        (WebCore::WebAudioSourceProviderAVFObjC::startProducingData): Deleted.
+        (WebCore::WebAudioSourceProviderAVFObjC::stopProducingData): Deleted.
+
+        * platform/mock/MockRealtimeAudioSource.cpp:
+        (WebCore::MockRealtimeAudioSource::MockRealtimeAudioSource):
+        (WebCore::MockRealtimeAudioSource::startProducingData):
+        (WebCore::MockRealtimeAudioSource::stopProducingData):
+        (WebCore::MockRealtimeAudioSource::elapsedTime):
+        (WebCore::MockRealtimeAudioSource::tick):
+
+        * platform/mock/MockRealtimeAudioSource.h:
+        (WebCore::MockRealtimeAudioSource::render):
+        (WebCore::MockRealtimeAudioSource::renderInterval):
+        (WebCore::MockRealtimeAudioSource::~MockRealtimeAudioSource): Deleted.
+
</ins><span class="cx"> 2017-01-13  Sam Weinig  &lt;sam@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [WebIDL] Remove custom bindings for DeviceMotionEvent and DeviceOrientationEvent
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -146,6 +146,7 @@
</span><span class="cx">                 073BE34117D17E01002BD431 /* JSNavigatorUserMedia.h in Headers */ = {isa = PBXBuildFile; fileRef = 073BE33F17D17E01002BD431 /* JSNavigatorUserMedia.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 073BE34E17D180B2002BD431 /* RTCSessionDescriptionDescriptor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07221BAB17CF0AD400848E51 /* RTCSessionDescriptionDescriptor.cpp */; };
</span><span class="cx">                 073BE34F17D18183002BD431 /* RTCIceCandidateDescriptor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07221BA617CF0AD400848E51 /* RTCIceCandidateDescriptor.cpp */; };
</span><ins>+                0744ECED1E0C4E30000D0944 /* MockRealtimeAudioSourceMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0744ECEC1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.mm */; };
</ins><span class="cx">                 074E82BA18A69F0E007EF54C /* PlatformTimeRanges.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 074E82B818A69F0E007EF54C /* PlatformTimeRanges.cpp */; };
</span><span class="cx">                 074E82BB18A69F0E007EF54C /* PlatformTimeRanges.h in Headers */ = {isa = PBXBuildFile; fileRef = 074E82B918A69F0E007EF54C /* PlatformTimeRanges.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 0753860214489E9800B78452 /* CachedTextTrack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0753860014489E9800B78452 /* CachedTextTrack.cpp */; };
</span><span class="lines">@@ -155,6 +156,7 @@
</span><span class="cx">                 076970861463AD8700F502CF /* TextTrackList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 076970841463AD8700F502CF /* TextTrackList.cpp */; };
</span><span class="cx">                 076970871463AD8700F502CF /* TextTrackList.h in Headers */ = {isa = PBXBuildFile; fileRef = 076970851463AD8700F502CF /* TextTrackList.h */; };
</span><span class="cx">                 076F0D0E12B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 076F0D0A12B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.h */; };
</span><ins>+                07707CB01E205EE300005BF7 /* AudioSourceObserverObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 07707CAF1E205EC400005BF7 /* AudioSourceObserverObjC.h */; };
</ins><span class="cx">                 077664FC183E6B5C00133B92 /* JSQuickTimePluginReplacement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 077664FA183E6B5C00133B92 /* JSQuickTimePluginReplacement.cpp */; };
</span><span class="cx">                 077664FD183E6B5C00133B92 /* JSQuickTimePluginReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 077664FB183E6B5C00133B92 /* JSQuickTimePluginReplacement.h */; };
</span><span class="cx">                 0779BF0D18453168000B6AE7 /* HTMLMediaElementMediaStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0779BF0A18453168000B6AE7 /* HTMLMediaElementMediaStream.cpp */; };
</span><span class="lines">@@ -7156,6 +7158,8 @@
</span><span class="cx">                 07394EC91BAB2CD700BE99CD /* MediaDevicesRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaDevicesRequest.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 073BE33E17D17E01002BD431 /* JSNavigatorUserMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNavigatorUserMedia.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 073BE33F17D17E01002BD431 /* JSNavigatorUserMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNavigatorUserMedia.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                0744ECEB1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockRealtimeAudioSourceMac.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                0744ECEC1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MockRealtimeAudioSourceMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 074E82B818A69F0E007EF54C /* PlatformTimeRanges.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformTimeRanges.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 074E82B918A69F0E007EF54C /* PlatformTimeRanges.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformTimeRanges.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 0753860014489E9800B78452 /* CachedTextTrack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedTextTrack.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -7166,6 +7170,8 @@
</span><span class="cx">                 076970851463AD8700F502CF /* TextTrackList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackList.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 076F0D0912B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaPlayerPrivateAVFoundation.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 076F0D0A12B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerPrivateAVFoundation.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                07707CAF1E205EC400005BF7 /* AudioSourceObserverObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSourceObserverObjC.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                07707CB11E20649C00005BF7 /* AudioCaptureSourceProviderObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioCaptureSourceProviderObjC.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 077664FA183E6B5C00133B92 /* JSQuickTimePluginReplacement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSQuickTimePluginReplacement.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 077664FB183E6B5C00133B92 /* JSQuickTimePluginReplacement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSQuickTimePluginReplacement.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 0779BF0A18453168000B6AE7 /* HTMLMediaElementMediaStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLMediaElementMediaStream.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -15219,6 +15225,10 @@
</span><span class="cx">                 0729B14D17CFCCA0004F1D60 /* mac */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                07707CB11E20649C00005BF7 /* AudioCaptureSourceProviderObjC.h */,
+                                07707CAF1E205EC400005BF7 /* AudioSourceObserverObjC.h */,
+                                0744ECEB1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.h */,
+                                0744ECEC1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.mm */,
</ins><span class="cx">                                 070363D8181A1CDC00C074A5 /* AVAudioCaptureSource.h */,
</span><span class="cx">                                 070363D9181A1CDC00C074A5 /* AVAudioCaptureSource.mm */,
</span><span class="cx">                                 070363DA181A1CDC00C074A5 /* AVCaptureDeviceManager.h */,
</span><span class="lines">@@ -25931,6 +25941,7 @@
</span><span class="cx">                                 5185FCAD1BB4C4E80012898F /* IDBTransaction.h in Headers */,
</span><span class="cx">                                 5198F7AD1BBDD3EB00E2CC5F /* IDBTransactionInfo.h in Headers */,
</span><span class="cx">                                 838EF5381DC149E2008F0C39 /* IDBTransactionMode.h in Headers */,
</span><ins>+                                07707CB01E205EE300005BF7 /* AudioSourceObserverObjC.h in Headers */,
</ins><span class="cx">                                 516103AF1CADBA770016B4C7 /* IDBValue.h in Headers */,
</span><span class="cx">                                 5185FCB01BB4C4E80012898F /* IDBVersionChangeEvent.h in Headers */,
</span><span class="cx">                                 E4A814E01C7338EB00BF85AC /* IdChangeInvalidation.h in Headers */,
</span><span class="lines">@@ -30348,6 +30359,7 @@
</span><span class="cx">                                 B2FA3DC80AB75A6F000E5AC4 /* JSSVGPathSegCurvetoQuadraticRel.cpp in Sources */,
</span><span class="cx">                                 B2FA3DCA0AB75A6F000E5AC4 /* JSSVGPathSegCurvetoQuadraticSmoothAbs.cpp in Sources */,
</span><span class="cx">                                 B2FA3DCC0AB75A6F000E5AC4 /* JSSVGPathSegCurvetoQuadraticSmoothRel.cpp in Sources */,
</span><ins>+                                0744ECED1E0C4E30000D0944 /* MockRealtimeAudioSourceMac.mm in Sources */,
</ins><span class="cx">                                 B2C96D8D0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp in Sources */,
</span><span class="cx">                                 B2FA3DCE0AB75A6F000E5AC4 /* JSSVGPathSegLinetoAbs.cpp in Sources */,
</span><span class="cx">                                 B2FA3DD00AB75A6F000E5AC4 /* JSSVGPathSegLinetoHorizontalAbs.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateMediaStreamAVFObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -326,7 +326,7 @@
</span><span class="cx">     if (timelineOffset == MediaTime::invalidTime()) {
</span><span class="cx">         timelineOffset = calculateTimelineOffset(sample, rendererLatency);
</span><span class="cx">         audioTrack-&gt;setTimelineOffset(timelineOffset);
</span><del>-        LOG(MediaCaptureSamples, &quot;MediaPlayerPrivateMediaStreamAVFObjC::enqueueAudioSample: timeline offset for track %s set to (%lld/%d)&quot;, track.id().utf8().data(), timelineOffset.timeValue(), timelineOffset.timeScale());
</del><ins>+        LOG(MediaCaptureSamples, &quot;MediaPlayerPrivateMediaStreamAVFObjC::enqueueAudioSample: timeline offset for track %s set to %s&quot;, track.id().utf8().data(), toString(timelineOffset).utf8().data());
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     updateSampleTimes(sample, timelineOffset, &quot;MediaPlayerPrivateMediaStreamAVFObjC::enqueueAudioSample&quot;);
</span><span class="lines">@@ -359,7 +359,7 @@
</span><span class="cx">     if (timelineOffset == MediaTime::invalidTime()) {
</span><span class="cx">         timelineOffset = calculateTimelineOffset(sample, rendererLatency);
</span><span class="cx">         videoTrack-&gt;setTimelineOffset(timelineOffset);
</span><del>-        LOG(MediaCaptureSamples, &quot;MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample: timeline offset for track %s set to %f&quot;, track.id().utf8().data(), timelineOffset.toDouble());
</del><ins>+        LOG(MediaCaptureSamples, &quot;MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample: timeline offset for track %s set to %s&quot;, track.id().utf8().data(), toString(timelineOffset).utf8().data());
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     updateSampleTimes(sample, timelineOffset, &quot;MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVAudioCaptureSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h        2017-01-13 21:27:30 UTC (rev 210742)
</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;AVMediaCaptureSource.h&quot;
</span><ins>+#include &quot;AudioCaptureSourceProviderObjC.h&quot;
</ins><span class="cx"> #include &lt;wtf/Lock.h&gt;
</span><span class="cx"> 
</span><span class="cx"> typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
</span><span class="lines">@@ -38,26 +39,20 @@
</span><span class="cx"> 
</span><span class="cx"> class WebAudioSourceProviderAVFObjC;
</span><span class="cx"> 
</span><del>-class AVAudioCaptureSource : public AVMediaCaptureSource {
</del><ins>+class AVAudioCaptureSource : public AVMediaCaptureSource, public AudioCaptureSourceProviderObjC {
</ins><span class="cx"> public:
</span><span class="cx"> 
</span><del>-    class Observer {
-    public:
-        virtual ~Observer() { }
-        virtual void prepare(const AudioStreamBasicDescription *) = 0;
-        virtual void unprepare() = 0;
-        virtual void process(CMFormatDescriptionRef, CMSampleBufferRef) = 0;
-    };
-
</del><span class="cx">     static RefPtr&lt;AVMediaCaptureSource&gt; create(AVCaptureDevice*, const AtomicString&amp;, const MediaConstraints*, String&amp;);
</span><span class="cx"> 
</span><del>-    void addObserver(Observer*);
-    void removeObserver(Observer*);
-
</del><span class="cx"> private:
</span><span class="cx">     AVAudioCaptureSource(AVCaptureDevice*, const AtomicString&amp;);
</span><span class="cx">     virtual ~AVAudioCaptureSource();
</span><span class="cx">     
</span><ins>+    // AudioCaptureSourceProviderObjC
+    void addObserver(AudioSourceObserverObjC&amp;) final;
+    void removeObserver(AudioSourceObserverObjC&amp;) final;
+    void start() final;
+
</ins><span class="cx">     void initializeCapabilities(RealtimeMediaSourceCapabilities&amp;) override;
</span><span class="cx">     void initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints&amp;) override;
</span><span class="cx"> 
</span><span class="lines">@@ -72,7 +67,7 @@
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;WebAudioSourceProviderAVFObjC&gt; m_audioSourceProvider;
</span><span class="cx">     std::unique_ptr&lt;AudioStreamBasicDescription&gt; m_inputDescription;
</span><del>-    Vector&lt;Observer*&gt; m_observers;
</del><ins>+    Vector&lt;AudioSourceObserverObjC*&gt; m_observers;
</ins><span class="cx">     Lock m_lock;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVAudioCaptureSourcemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_STREAM) &amp;&amp; USE(AVFOUNDATION)
</span><span class="cx"> 
</span><ins>+#import &quot;AudioSourceObserverObjC.h&quot;
</ins><span class="cx"> #import &quot;Logging.h&quot;
</span><span class="cx"> #import &quot;MediaConstraints.h&quot;
</span><span class="cx"> #import &quot;MediaSampleAVFObjC.h&quot;
</span><span class="lines">@@ -115,22 +116,25 @@
</span><span class="cx">     settings.setDeviceId(id());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void AVAudioCaptureSource::addObserver(AVAudioCaptureSource::Observer* observer)
</del><ins>+void AVAudioCaptureSource::addObserver(AudioSourceObserverObjC&amp; observer)
</ins><span class="cx"> {
</span><span class="cx">     LockHolder lock(m_lock);
</span><del>-    m_observers.append(observer);
</del><ins>+    m_observers.append(&amp;observer);
</ins><span class="cx">     if (m_inputDescription-&gt;mSampleRate)
</span><del>-        observer-&gt;prepare(m_inputDescription.get());
</del><ins>+        observer.prepare(m_inputDescription.get());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void AVAudioCaptureSource::removeObserver(AVAudioCaptureSource::Observer* observer)
</del><ins>+void AVAudioCaptureSource::removeObserver(AudioSourceObserverObjC&amp; observer)
</ins><span class="cx"> {
</span><span class="cx">     LockHolder lock(m_lock);
</span><del>-    size_t pos = m_observers.find(observer);
-    if (pos != notFound)
-        m_observers.remove(pos);
</del><ins>+    m_observers.removeFirst(&amp;observer);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void AVAudioCaptureSource::start()
+{
+    startProducingData();
+}
+
</ins><span class="cx"> void AVAudioCaptureSource::setupCaptureSession()
</span><span class="cx"> {
</span><span class="cx">     RetainPtr&lt;AVCaptureDeviceInputType&gt; audioIn = adoptNS([allocAVCaptureDeviceInputInstance() initWithDevice:device() error:nil]);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAudioCaptureSourceProviderObjCh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/mediastream/mac/AudioCaptureSourceProviderObjC.h (0 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AudioCaptureSourceProviderObjC.h                                (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/AudioCaptureSourceProviderObjC.h        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -0,0 +1,50 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(MEDIA_STREAM) &amp;&amp; USE(AVFOUNDATION)
+
+typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
+typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
+typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
+
+namespace WebCore {
+
+class AudioSourceObserverObjC;
+
+class AudioCaptureSourceProviderObjC {
+public:
+    virtual ~AudioCaptureSourceProviderObjC() = default;
+
+    virtual void addObserver(AudioSourceObserverObjC&amp;) = 0;
+    virtual void removeObserver(AudioSourceObserverObjC&amp;) = 0;
+
+    virtual void start() = 0;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAudioSourceObserverObjCh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/mediastream/mac/AudioSourceObserverObjC.h (0 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AudioSourceObserverObjC.h                                (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/AudioSourceObserverObjC.h        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -0,0 +1,47 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(MEDIA_STREAM) &amp;&amp; USE(AVFOUNDATION)
+
+typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
+typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
+typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
+
+namespace WebCore {
+
+class AudioSourceObserverObjC {
+public:
+    virtual ~AudioSourceObserverObjC() = default;
+
+    virtual void prepare(const AudioStreamBasicDescription*) = 0;
+    virtual void unprepare() = 0;
+    virtual void process(CMFormatDescriptionRef, CMSampleBufferRef) = 0;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacMockRealtimeAudioSourceMachfromrev210741trunkSourceWebCoreplatformmockMockRealtimeAudioSourceh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.h (from rev 210741, trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.h) (0 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.h                                (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.h        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -0,0 +1,86 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer
+ *    in the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of Ericsson nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(MEDIA_STREAM)
+
+#include &quot;AudioCaptureSourceProviderObjC.h&quot;
+#include &quot;FontCascade.h&quot;
+#include &quot;MockRealtimeAudioSource.h&quot;
+#include &lt;CoreAudio/CoreAudioTypes.h&gt;
+
+OBJC_CLASS AVAudioPCMBuffer;
+typedef struct AudioBufferList AudioBufferList;
+typedef struct OpaqueCMClock* CMClockRef;
+typedef const struct opaqueCMFormatDescription* CMFormatDescriptionRef;
+
+namespace WebCore {
+
+class WebAudioSourceProviderAVFObjC;
+
+class MockRealtimeAudioSourceMac final : public MockRealtimeAudioSource, public AudioCaptureSourceProviderObjC {
+public:
+
+    // AudioCaptureSourceProviderObjC
+    void addObserver(AudioSourceObserverObjC&amp;) final;
+    void removeObserver(AudioSourceObserverObjC&amp;) final;
+    void start() final;
+
+private:
+    friend class MockRealtimeAudioSource;
+    MockRealtimeAudioSourceMac(const String&amp;);
+
+    bool applySampleRate(int) final;
+    bool applySampleSize(int) final { return false; }
+
+    void emitSampleBuffers(uint32_t);
+    void render(double) final;
+    void reconfigure();
+
+    AudioSourceProvider* audioSourceProvider() final;
+
+    size_t m_audioBufferListBufferSize { 0 };
+    std::unique_ptr&lt;AudioBufferList&gt; m_audioBufferList;
+
+    uint32_t m_maximiumFrameCount;
+    uint32_t m_sampleRate { 44100 };
+    double m_bytesPerFrame { sizeof(Float32) };
+
+    RetainPtr&lt;CMFormatDescriptionRef&gt; m_formatDescription;
+    AudioStreamBasicDescription m_streamFormat;
+    RefPtr&lt;WebAudioSourceProviderAVFObjC&gt; m_audioSourceProvider;
+    Vector&lt;AudioSourceObserverObjC*&gt; m_observers;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
+
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacMockRealtimeAudioSourceMacmm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.mm (0 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.mm                                (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.mm        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -0,0 +1,236 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer
+ *    in the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of Google Inc. nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;config.h&quot;
+#import &quot;MockRealtimeAudioSourceMac.h&quot;
+
+#if ENABLE(MEDIA_STREAM)
+#import &quot;MediaConstraints.h&quot;
+#import &quot;MediaSampleAVFObjC.h&quot;
+#import &quot;NotImplemented.h&quot;
+#import &quot;RealtimeMediaSourceSettings.h&quot;
+#import &quot;WebAudioSourceProviderAVFObjC.h&quot;
+#import &lt;AVFoundation/AVAudioBuffer.h&gt;
+#import &lt;AudioToolbox/AudioConverter.h&gt;
+#import &lt;CoreAudio/CoreAudioTypes.h&gt;
+
+#import &quot;CoreMediaSoftLink.h&quot;
+
+SOFT_LINK_FRAMEWORK(AudioToolbox)
+
+SOFT_LINK(AudioToolbox, AudioConverterNew, OSStatus, (const AudioStreamBasicDescription* inSourceFormat, const AudioStreamBasicDescription* inDestinationFormat, AudioConverterRef* outAudioConverter), (inSourceFormat, inDestinationFormat, outAudioConverter))
+
+namespace WebCore {
+
+RefPtr&lt;MockRealtimeAudioSource&gt; MockRealtimeAudioSource::create(const String&amp; name, const MediaConstraints* constraints)
+{
+    auto source = adoptRef(new MockRealtimeAudioSourceMac(name));
+    if (constraints &amp;&amp; source-&gt;applyConstraints(*constraints))
+        source = nullptr;
+
+    return source;
+}
+
+MockRealtimeAudioSourceMac::MockRealtimeAudioSourceMac(const String&amp; name)
+    : MockRealtimeAudioSource(name)
+{
+}
+
+RefPtr&lt;MockRealtimeAudioSource&gt; MockRealtimeAudioSource::createMuted(const String&amp; name)
+{
+    auto source = adoptRef(new MockRealtimeAudioSource(name));
+    source-&gt;m_muted = true;
+    return source;
+}
+
+void MockRealtimeAudioSourceMac::addObserver(AudioSourceObserverObjC&amp; observer)
+{
+    m_observers.append(&amp;observer);
+    if (m_streamFormat.mSampleRate)
+        observer.prepare(&amp;m_streamFormat);
+}
+
+void MockRealtimeAudioSourceMac::removeObserver(AudioSourceObserverObjC&amp; observer)
+{
+    m_observers.removeFirst(&amp;observer);
+}
+
+void MockRealtimeAudioSourceMac::start()
+{
+    startProducingData();
+}
+
+
+void MockRealtimeAudioSourceMac::emitSampleBuffers(uint32_t frameCount)
+{
+    ASSERT(m_formatDescription);
+
+    CMTime startTime = CMTimeMake(elapsedTime() * m_sampleRate, m_sampleRate);
+    CMSampleBufferRef sampleBuffer;
+    OSStatus result = CMAudioSampleBufferCreateWithPacketDescriptions(nullptr, nullptr, true, nullptr, nullptr, m_formatDescription.get(), frameCount, startTime, nullptr, &amp;sampleBuffer);
+    ASSERT(sampleBuffer);
+    ASSERT(!result);
+
+    if (!sampleBuffer)
+        return;
+
+    auto buffer = adoptCF(sampleBuffer);
+    result = CMSampleBufferSetDataBufferFromAudioBufferList(sampleBuffer, kCFAllocatorDefault, kCFAllocatorDefault, 0, m_audioBufferList.get());
+    ASSERT(!result);
+
+    result = CMSampleBufferSetDataReady(sampleBuffer);
+    ASSERT(!result);
+
+    mediaDataUpdated(MediaSampleAVFObjC::create(sampleBuffer));
+
+    for (auto&amp; observer : m_observers)
+        observer-&gt;process(m_formatDescription.get(), sampleBuffer);
+}
+
+void MockRealtimeAudioSourceMac::reconfigure()
+{
+    m_maximiumFrameCount = WTF::roundUpToPowerOfTwo(renderInterval() / 1000. * m_sampleRate * 2);
+    ASSERT(m_maximiumFrameCount);
+
+    // AudioBufferList is a variable-length struct, so create on the heap with a generic new() operator
+    // with a custom size, and initialize the struct manually.
+    uint32_t bufferDataSize = m_bytesPerFrame * m_maximiumFrameCount;
+    uint32_t baseSize = offsetof(AudioBufferList, mBuffers) + sizeof(AudioBuffer);
+    uint64_t bufferListSize = baseSize + bufferDataSize;
+    ASSERT(bufferListSize &lt;= SIZE_MAX);
+    if (bufferListSize &gt; SIZE_MAX)
+        return;
+
+    m_audioBufferListBufferSize = static_cast&lt;size_t&gt;(bufferListSize);
+    m_audioBufferList = std::unique_ptr&lt;AudioBufferList&gt;(static_cast&lt;AudioBufferList*&gt;(::operator new (m_audioBufferListBufferSize)));
+    memset(m_audioBufferList.get(), 0, m_audioBufferListBufferSize);
+
+    m_audioBufferList-&gt;mNumberBuffers = 1;
+    auto&amp; buffer = m_audioBufferList-&gt;mBuffers[0];
+    buffer.mNumberChannels = 1;
+    buffer.mDataByteSize = bufferDataSize;
+    buffer.mData = reinterpret_cast&lt;uint8_t*&gt;(m_audioBufferList.get()) + baseSize;
+
+    const int bytesPerFloat = sizeof(Float32);
+    const int bitsPerByte = 8;
+    m_streamFormat = { };
+    m_streamFormat.mSampleRate = m_sampleRate;
+    m_streamFormat.mFormatID = kAudioFormatLinearPCM;
+    m_streamFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
+    m_streamFormat.mBytesPerPacket = bytesPerFloat;
+    m_streamFormat.mFramesPerPacket = 1;
+    m_streamFormat.mBytesPerFrame = bytesPerFloat;
+    m_streamFormat.mChannelsPerFrame = 1;
+    m_streamFormat.mBitsPerChannel = bitsPerByte * bytesPerFloat;
+
+    CMFormatDescriptionRef formatDescription;
+    CMAudioFormatDescriptionCreate(NULL, &amp;m_streamFormat, 0, NULL, 0, NULL, NULL, &amp;formatDescription);
+    m_formatDescription = adoptCF(formatDescription);
+
+    for (auto&amp; observer : m_observers)
+        observer-&gt;prepare(&amp;m_streamFormat);
+}
+
+void MockRealtimeAudioSourceMac::render(double delta)
+{
+    static double theta;
+    static const double frequencies[] = { 1500., 500. };
+
+    if (!m_audioBufferList)
+        reconfigure();
+
+    uint32_t totalFrameCount = delta * m_sampleRate;
+    uint32_t frameCount = std::min(totalFrameCount, m_maximiumFrameCount);
+    double elapsed = elapsedTime();
+    while (frameCount) {
+        float *buffer = static_cast&lt;float *&gt;(m_audioBufferList-&gt;mBuffers[0].mData);
+        for (uint32_t frame = 0; frame &lt; frameCount; ++frame) {
+            int phase = fmod(elapsed, 2) * 15;
+            double increment = 0;
+            bool silent = true;
+
+            switch (phase) {
+            case 0:
+            case 14: {
+                int index = fmod(elapsed, 1) * 2;
+                increment = 2.0 * M_PI * frequencies[index] / m_sampleRate;
+                silent = false;
+                break;
+            }
+            default:
+                break;
+            }
+
+            if (silent) {
+                buffer[frame] = 0;
+                continue;
+            }
+
+            buffer[frame] = sin(theta) * 0.25;
+            theta += increment;
+            if (theta &gt; 2.0 * M_PI)
+                theta -= 2.0 * M_PI;
+            elapsed += 1 / m_sampleRate;
+        }
+
+        m_audioBufferList-&gt;mBuffers[0].mDataByteSize = frameCount * sizeof(float);
+        emitSampleBuffers(frameCount);
+        totalFrameCount -= frameCount;
+        frameCount = std::min(totalFrameCount, m_maximiumFrameCount);
+    }
+}
+
+bool MockRealtimeAudioSourceMac::applySampleRate(int sampleRate)
+{
+    if (sampleRate &lt; 44100 || sampleRate &gt; 48000)
+        return false;
+
+    if (static_cast&lt;uint32_t&gt;(sampleRate) == m_sampleRate)
+        return true;
+
+    m_sampleRate = sampleRate;
+    m_formatDescription = nullptr;
+    m_audioBufferList = nullptr;
+    m_audioBufferListBufferSize = 0;
+
+    return true;
+}
+
+AudioSourceProvider* MockRealtimeAudioSourceMac::audioSourceProvider()
+{
+    if (!m_audioSourceProvider)
+        m_audioSourceProvider = WebAudioSourceProviderAVFObjC::create(*this);
+
+    return m_audioSourceProvider.get();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacWebAudioSourceProviderAVFObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -28,9 +28,9 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(WEB_AUDIO) &amp;&amp; ENABLE(MEDIA_STREAM)
</span><span class="cx"> 
</span><del>-#include &quot;AVAudioCaptureSource.h&quot;
</del><ins>+#include &quot;AudioCaptureSourceProviderObjC.h&quot;
+#include &quot;AudioSourceObserverObjC.h&quot;
</ins><span class="cx"> #include &quot;AudioSourceProvider.h&quot;
</span><del>-#include &lt;wtf/Lock.h&gt;
</del><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -42,28 +42,24 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-class AVAudioCaptureSource;
</del><span class="cx"> class CARingBuffer;
</span><span class="cx"> 
</span><del>-class WebAudioSourceProviderAVFObjC : public RefCounted&lt;WebAudioSourceProviderAVFObjC&gt;, public AudioSourceProvider, public AVAudioCaptureSource::Observer {
</del><ins>+class WebAudioSourceProviderAVFObjC : public RefCounted&lt;WebAudioSourceProviderAVFObjC&gt;, public AudioSourceProvider, public AudioSourceObserverObjC {
</ins><span class="cx"> public:
</span><del>-    static Ref&lt;WebAudioSourceProviderAVFObjC&gt; create(AVAudioCaptureSource&amp;);
</del><ins>+    static Ref&lt;WebAudioSourceProviderAVFObjC&gt; create(AudioCaptureSourceProviderObjC&amp;);
</ins><span class="cx">     virtual ~WebAudioSourceProviderAVFObjC();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    WebAudioSourceProviderAVFObjC(AVAudioCaptureSource&amp;);
</del><ins>+    WebAudioSourceProviderAVFObjC(AudioCaptureSourceProviderObjC&amp;);
</ins><span class="cx"> 
</span><del>-    void startProducingData();
-    void stopProducingData();
-
</del><span class="cx">     // AudioSourceProvider
</span><span class="cx">     void provideInput(AudioBus*, size_t) override;
</span><span class="cx">     void setClient(AudioSourceProviderClient*) override;
</span><span class="cx"> 
</span><del>-    // AVAudioCaptureSource::Observer
-    void prepare(const AudioStreamBasicDescription *) override;
-    void unprepare() override;
-    void process(CMFormatDescriptionRef, CMSampleBufferRef) override;
</del><ins>+    // AudioSourceObserverObjC
+    void prepare(const AudioStreamBasicDescription *) final;
+    void unprepare() final;
+    void process(CMFormatDescriptionRef, CMSampleBufferRef) final;
</ins><span class="cx"> 
</span><span class="cx">     size_t m_listBufferSize { 0 };
</span><span class="cx">     std::unique_ptr&lt;AudioBufferList&gt; m_list;
</span><span class="lines">@@ -76,7 +72,7 @@
</span><span class="cx">     uint64_t m_writeCount { 0 };
</span><span class="cx">     uint64_t m_readCount { 0 };
</span><span class="cx">     AudioSourceProviderClient* m_client { nullptr };
</span><del>-    AVAudioCaptureSource* m_captureSource { nullptr };
</del><ins>+    AudioCaptureSourceProviderObjC* m_captureSource { nullptr };
</ins><span class="cx">     bool m_connected { false };
</span><span class="cx"> };
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacWebAudioSourceProviderAVFObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -53,12 +53,12 @@
</span><span class="cx"> 
</span><span class="cx"> static const double kRingBufferDuration = 1;
</span><span class="cx"> 
</span><del>-Ref&lt;WebAudioSourceProviderAVFObjC&gt; WebAudioSourceProviderAVFObjC::create(AVAudioCaptureSource&amp; source)
</del><ins>+Ref&lt;WebAudioSourceProviderAVFObjC&gt; WebAudioSourceProviderAVFObjC::create(AudioCaptureSourceProviderObjC&amp; source)
</ins><span class="cx"> {
</span><span class="cx">     return adoptRef(*new WebAudioSourceProviderAVFObjC(source));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC(AVAudioCaptureSource&amp; source)
</del><ins>+WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC(AudioCaptureSourceProviderObjC&amp; source)
</ins><span class="cx">     : m_captureSource(&amp;source)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -71,19 +71,9 @@
</span><span class="cx">         m_converter = nullptr;
</span><span class="cx">     }
</span><span class="cx">     if (m_connected)
</span><del>-        m_captureSource-&gt;removeObserver(this);
</del><ins>+        m_captureSource-&gt;removeObserver(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebAudioSourceProviderAVFObjC::startProducingData()
-{
-    m_captureSource-&gt;startProducingData();
-}
-
-void WebAudioSourceProviderAVFObjC::stopProducingData()
-{
-    m_captureSource-&gt;stopProducingData();
-}
-
</del><span class="cx"> void WebAudioSourceProviderAVFObjC::provideInput(AudioBus* bus, size_t framesToProcess)
</span><span class="cx"> {
</span><span class="cx">     if (!m_ringBuffer) {
</span><span class="lines">@@ -107,6 +97,10 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT(bus-&gt;numberOfChannels() == m_ringBuffer-&gt;channelCount());
</span><ins>+    if (bus-&gt;numberOfChannels() != m_ringBuffer-&gt;channelCount()) {
+        bus-&gt;zero();
+        return;
+    }
</ins><span class="cx"> 
</span><span class="cx">     for (unsigned i = 0; i &lt; m_list-&gt;mNumberBuffers; ++i) {
</span><span class="cx">         AudioChannel&amp; channel = *bus-&gt;channel(i);
</span><span class="lines">@@ -132,10 +126,10 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_client &amp;&amp; !m_connected) {
</span><span class="cx">         m_connected = true;
</span><del>-        m_captureSource-&gt;addObserver(this);
-        m_captureSource-&gt;startProducingData();
</del><ins>+        m_captureSource-&gt;addObserver(*this);
+        m_captureSource-&gt;start();
</ins><span class="cx">     } else if (!m_client &amp;&amp; m_connected) {
</span><del>-        m_captureSource-&gt;removeObserver(this);
</del><ins>+        m_captureSource-&gt;removeObserver(*this);
</ins><span class="cx">         m_connected = false;
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmockMockRealtimeAudioSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+#if !PLATFORM(MAC) &amp;&amp; !PLATFORM(IOS)
</ins><span class="cx"> RefPtr&lt;MockRealtimeAudioSource&gt; MockRealtimeAudioSource::create(const String&amp; name, const MediaConstraints* constraints)
</span><span class="cx"> {
</span><span class="cx">     auto source = adoptRef(new MockRealtimeAudioSource(name));
</span><span class="lines">@@ -55,9 +56,11 @@
</span><span class="cx">     source-&gt;m_muted = true;
</span><span class="cx">     return source;
</span><span class="cx"> }
</span><del>-
</del><ins>+#endif
+    
</ins><span class="cx"> MockRealtimeAudioSource::MockRealtimeAudioSource(const String&amp; name)
</span><span class="cx">     : MockRealtimeMediaSource(createCanonicalUUIDString(), RealtimeMediaSource::Audio, name)
</span><ins>+    , m_timer(RunLoop::current(), this, &amp;MockRealtimeAudioSource::tick)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -82,6 +85,41 @@
</span><span class="cx">     supportedConstraints.setSupportsSampleRate(true);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MockRealtimeAudioSource::startProducingData()
+{
+    MockRealtimeMediaSource::startProducingData();
+
+    m_startTime = monotonicallyIncreasingTime();
+    m_timer.startRepeating(std::chrono::milliseconds(renderInterval()));
+}
+
+void MockRealtimeAudioSource::stopProducingData()
+{
+    MockRealtimeMediaSource::stopProducingData();
+    m_timer.stop();
+    m_elapsedTime += monotonicallyIncreasingTime() - m_startTime;
+    m_startTime = NAN;
+}
+
+double MockRealtimeAudioSource::elapsedTime()
+{
+    if (std::isnan(m_startTime))
+        return m_elapsedTime;
+
+    return m_elapsedTime + (monotonicallyIncreasingTime() - m_startTime);
+}
+
+void MockRealtimeAudioSource::tick()
+{
+    if (std::isnan(m_lastRenderTime))
+        m_lastRenderTime = monotonicallyIncreasingTime();
+
+    double now = monotonicallyIncreasingTime();
+    double delta = now - m_lastRenderTime;
+    m_lastRenderTime = now;
+    render(delta);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(MEDIA_STREAM)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmockMockRealtimeAudioSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.h (210741 => 210742)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.h        2017-01-13 21:19:55 UTC (rev 210741)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeAudioSource.h        2017-01-13 21:27:30 UTC (rev 210742)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,8 +28,7 @@
</span><span class="cx">  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef MockRealtimeAudioSource_h
-#define MockRealtimeAudioSource_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_STREAM)
</span><span class="cx"> 
</span><span class="lines">@@ -36,6 +35,7 @@
</span><span class="cx"> #include &quot;FontCascade.h&quot;
</span><span class="cx"> #include &quot;ImageBuffer.h&quot;
</span><span class="cx"> #include &quot;MockRealtimeMediaSource.h&quot;
</span><ins>+#include &lt;wtf/RunLoop.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -45,11 +45,19 @@
</span><span class="cx">     static RefPtr&lt;MockRealtimeAudioSource&gt; create(const String&amp;, const MediaConstraints*);
</span><span class="cx">     static RefPtr&lt;MockRealtimeAudioSource&gt; createMuted(const String&amp; name);
</span><span class="cx"> 
</span><del>-    virtual ~MockRealtimeAudioSource() { }
</del><ins>+    virtual ~MockRealtimeAudioSource() = default;
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     MockRealtimeAudioSource(const String&amp; name = ASCIILiteral(&quot;Mock audio device&quot;));
</span><span class="cx"> 
</span><ins>+    void startProducingData() final;
+    void stopProducingData() final;
+
+    virtual void render(double) { }
+
+    double elapsedTime();
+    static int renderInterval() { return 125; }
+
</ins><span class="cx"> private:
</span><span class="cx"> 
</span><span class="cx">     bool applyVolume(double) override { return true; }
</span><span class="lines">@@ -60,10 +68,15 @@
</span><span class="cx">     void updateSettings(RealtimeMediaSourceSettings&amp;) override;
</span><span class="cx">     void initializeCapabilities(RealtimeMediaSourceCapabilities&amp;) override;
</span><span class="cx">     void initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints&amp;) override;
</span><ins>+
+    void tick();
+
+    RunLoop::Timer&lt;MockRealtimeAudioSource&gt; m_timer;
+    double m_startTime { NAN };
+    double m_lastRenderTime { NAN };
+    double m_elapsedTime { 0 };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(MEDIA_STREAM)
</span><del>-
-#endif // MockRealtimeAudioSource_h
</del></span></pre>
</div>
</div>

</body>
</html>