<!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>[211596] trunk/Source/WebCore</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/211596">211596</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2017-02-02 15:01:54 -0800 (Thu, 02 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Mac] Add classes to manage audio samples
https://bugs.webkit.org/show_bug.cgi?id=167739

Reviewed by Jer Noble.

No new tests, this code isn't used yet.

* WebCore.xcodeproj/project.pbxproj:
* platform/audio/mac/AudioSampleBufferList.cpp: Added.
(WebCore::AudioSampleBufferList::create):
(WebCore::AudioSampleBufferList::AudioSampleBufferList):
(WebCore::AudioSampleBufferList::~AudioSampleBufferList):
(WebCore::AudioSampleBufferList::setSampleCount):
(WebCore::AudioSampleBufferList::applyGain):
(WebCore::AudioSampleBufferList::mixFrom):
(WebCore::AudioSampleBufferList::copyFrom):
(WebCore::AudioSampleBufferList::copyTo):
(WebCore::AudioSampleBufferList::reset):
(WebCore::AudioSampleBufferList::zero):
(WebCore::AudioSampleBufferList::zeroABL):
(WebCore::AudioSampleBufferList::convertInput):
(WebCore::AudioSampleBufferList::audioConverterCallback):
(WebCore::AudioSampleBufferList::configureBufferListForStream):
* platform/audio/mac/AudioSampleBufferList.h: Added.
(WebCore::AudioSampleBufferList::streamDescription):
(WebCore::AudioSampleBufferList::bufferList):
(WebCore::AudioSampleBufferList::sampleCapacity):
(WebCore::AudioSampleBufferList::sampleCount):
(WebCore::AudioSampleBufferList::timestamp):
(WebCore::AudioSampleBufferList::hostTime):
(WebCore::AudioSampleBufferList::setTimes):
(WebCore::AudioSampleBufferList::audioBufferListSizeForStream):
* platform/audio/mac/AudioSampleDataSource.cpp: Added.
(WebCore::AudioSampleDataSource::create):
(WebCore::AudioSampleDataSource::AudioSampleDataSource):
(WebCore::AudioSampleDataSource::~AudioSampleDataSource):
(WebCore::AudioSampleDataSource::setPaused):
(WebCore::AudioSampleDataSource::setupConverter):
(WebCore::AudioSampleDataSource::setInputFormat):
(WebCore::AudioSampleDataSource::setOutputFormat):
(WebCore::AudioSampleDataSource::hostTime):
(WebCore::AudioSampleDataSource::pushSamplesInternal):
(WebCore::AudioSampleDataSource::pushSamples):
(WebCore::AudioSampleDataSource::pullSamplesInternal):
(WebCore::AudioSampleDataSource::pullSamples):
* platform/audio/mac/AudioSampleDataSource.h: Added.
(WebCore::AudioSampleDataSource::setVolume):
(WebCore::AudioSampleDataSource::volume):
(WebCore::AudioSampleDataSource::setMuted):
(WebCore::AudioSampleDataSource::muted):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformaudiomacAudioSampleBufferListcpp">trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiomacAudioSampleBufferListh">trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiomacAudioSampleDataSourcecpp">trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiomacAudioSampleDataSourceh">trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (211595 => 211596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-02-02 22:45:59 UTC (rev 211595)
+++ trunk/Source/WebCore/ChangeLog        2017-02-02 23:01:54 UTC (rev 211596)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2017-02-02  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        [Mac] Add classes to manage audio samples
+        https://bugs.webkit.org/show_bug.cgi?id=167739
+
+        Reviewed by Jer Noble.
+
+        No new tests, this code isn't used yet.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/audio/mac/AudioSampleBufferList.cpp: Added.
+        (WebCore::AudioSampleBufferList::create):
+        (WebCore::AudioSampleBufferList::AudioSampleBufferList):
+        (WebCore::AudioSampleBufferList::~AudioSampleBufferList):
+        (WebCore::AudioSampleBufferList::setSampleCount):
+        (WebCore::AudioSampleBufferList::applyGain):
+        (WebCore::AudioSampleBufferList::mixFrom):
+        (WebCore::AudioSampleBufferList::copyFrom):
+        (WebCore::AudioSampleBufferList::copyTo):
+        (WebCore::AudioSampleBufferList::reset):
+        (WebCore::AudioSampleBufferList::zero):
+        (WebCore::AudioSampleBufferList::zeroABL):
+        (WebCore::AudioSampleBufferList::convertInput):
+        (WebCore::AudioSampleBufferList::audioConverterCallback):
+        (WebCore::AudioSampleBufferList::configureBufferListForStream):
+        * platform/audio/mac/AudioSampleBufferList.h: Added.
+        (WebCore::AudioSampleBufferList::streamDescription):
+        (WebCore::AudioSampleBufferList::bufferList):
+        (WebCore::AudioSampleBufferList::sampleCapacity):
+        (WebCore::AudioSampleBufferList::sampleCount):
+        (WebCore::AudioSampleBufferList::timestamp):
+        (WebCore::AudioSampleBufferList::hostTime):
+        (WebCore::AudioSampleBufferList::setTimes):
+        (WebCore::AudioSampleBufferList::audioBufferListSizeForStream):
+        * platform/audio/mac/AudioSampleDataSource.cpp: Added.
+        (WebCore::AudioSampleDataSource::create):
+        (WebCore::AudioSampleDataSource::AudioSampleDataSource):
+        (WebCore::AudioSampleDataSource::~AudioSampleDataSource):
+        (WebCore::AudioSampleDataSource::setPaused):
+        (WebCore::AudioSampleDataSource::setupConverter):
+        (WebCore::AudioSampleDataSource::setInputFormat):
+        (WebCore::AudioSampleDataSource::setOutputFormat):
+        (WebCore::AudioSampleDataSource::hostTime):
+        (WebCore::AudioSampleDataSource::pushSamplesInternal):
+        (WebCore::AudioSampleDataSource::pushSamples):
+        (WebCore::AudioSampleDataSource::pullSamplesInternal):
+        (WebCore::AudioSampleDataSource::pullSamples):
+        * platform/audio/mac/AudioSampleDataSource.h: Added.
+        (WebCore::AudioSampleDataSource::setVolume):
+        (WebCore::AudioSampleDataSource::volume):
+        (WebCore::AudioSampleDataSource::setMuted):
+        (WebCore::AudioSampleDataSource::muted):
+
</ins><span class="cx"> 2017-02-02  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Support Performance API (performance.now(), UserTiming) in Workers
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (211595 => 211596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-02-02 22:45:59 UTC (rev 211595)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-02-02 23:01:54 UTC (rev 211596)
</span><span class="lines">@@ -142,6 +142,10 @@
</span><span class="cx">                 073794FE19F5864E00E5A045 /* RTCNotifiersMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 073794F819F5864E00E5A045 /* RTCNotifiersMock.h */; };
</span><span class="cx">                 07394EC81BAB2CCD00BE99CD /* MediaDevicesRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07394EC71BAB2CCD00BE99CD /* MediaDevicesRequest.cpp */; };
</span><span class="cx">                 07394ECA1BAB2CD700BE99CD /* MediaDevicesRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 07394EC91BAB2CD700BE99CD /* MediaDevicesRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                073B87661E4385AC0071C0EC /* AudioSampleBufferList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 073B87621E43859D0071C0EC /* AudioSampleBufferList.cpp */; };
+                073B87671E4385AC0071C0EC /* AudioSampleBufferList.h in Headers */ = {isa = PBXBuildFile; fileRef = 073B87631E43859D0071C0EC /* AudioSampleBufferList.h */; };
+                073B87681E4385AC0071C0EC /* AudioSampleDataSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 073B87641E43859D0071C0EC /* AudioSampleDataSource.cpp */; };
+                073B87691E4385AC0071C0EC /* AudioSampleDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 073B87651E43859D0071C0EC /* AudioSampleDataSource.h */; };
</ins><span class="cx">                 073BE34017D17E01002BD431 /* JSNavigatorUserMedia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 073BE33E17D17E01002BD431 /* JSNavigatorUserMedia.cpp */; };
</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="lines">@@ -7233,6 +7237,10 @@
</span><span class="cx">                 073B87561E40DCE50071C0EC /* AudioStreamDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioStreamDescription.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 073B87571E40DCFD0071C0EC /* CAAudioStreamDescription.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CAAudioStreamDescription.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 073B87581E40DCFD0071C0EC /* CAAudioStreamDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CAAudioStreamDescription.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                073B87621E43859D0071C0EC /* AudioSampleBufferList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSampleBufferList.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                073B87631E43859D0071C0EC /* AudioSampleBufferList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSampleBufferList.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                073B87641E43859D0071C0EC /* AudioSampleDataSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSampleDataSource.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                073B87651E43859D0071C0EC /* AudioSampleDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSampleDataSource.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><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><span class="cx">                 0744ECEB1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockRealtimeAudioSourceMac.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -24845,7 +24853,6 @@
</span><span class="cx">                 FD31604012B026A300C1A359 /* audio */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><del>-                                073B87561E40DCE50071C0EC /* AudioStreamDescription.h */,
</del><span class="cx">                                 CD669D651D232DF4004D1866 /* cocoa */,
</span><span class="cx">                                 CD0EEE0D14743E48003EAFA2 /* ios */,
</span><span class="cx">                                 FD3160B012B0270700C1A359 /* mac */,
</span><span class="lines">@@ -24872,6 +24879,7 @@
</span><span class="cx">                                 CDA79821170A22DC00D45C55 /* AudioSession.h */,
</span><span class="cx">                                 FD31605312B026F700C1A359 /* AudioSourceProvider.h */,
</span><span class="cx">                                 FD62F52D145898D80094B0ED /* AudioSourceProviderClient.h */,
</span><ins>+                                073B87561E40DCE50071C0EC /* AudioStreamDescription.h */,
</ins><span class="cx">                                 FD31605412B026F700C1A359 /* AudioUtilities.cpp */,
</span><span class="cx">                                 FD31605512B026F700C1A359 /* AudioUtilities.h */,
</span><span class="cx">                                 FD31605612B026F700C1A359 /* Biquad.cpp */,
</span><span class="lines">@@ -24938,6 +24946,10 @@
</span><span class="cx">                 FD3160B012B0270700C1A359 /* mac */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                073B87621E43859D0071C0EC /* AudioSampleBufferList.cpp */,
+                                073B87631E43859D0071C0EC /* AudioSampleBufferList.h */,
+                                073B87641E43859D0071C0EC /* AudioSampleDataSource.cpp */,
+                                073B87651E43859D0071C0EC /* AudioSampleDataSource.h */,
</ins><span class="cx">                                 FD3160B512B0272A00C1A359 /* AudioBusMac.mm */,
</span><span class="cx">                                 FD3160B612B0272A00C1A359 /* AudioDestinationMac.cpp */,
</span><span class="cx">                                 FD3160B712B0272A00C1A359 /* AudioDestinationMac.h */,
</span><span class="lines">@@ -25502,6 +25514,7 @@
</span><span class="cx">                                 2D8FEBDD143E3EF70072502B /* CSSCrossfadeValue.h in Headers */,
</span><span class="cx">                                 AA21ECCD0ABF0FC6002B834C /* CSSCursorImageValue.h in Headers */,
</span><span class="cx">                                 9444CBE41D8861990073A074 /* CSSCustomIdentValue.h in Headers */,
</span><ins>+                                073B87691E4385AC0071C0EC /* AudioSampleDataSource.h in Headers */,
</ins><span class="cx">                                 BC779E141BB215BB00CAA8BF /* CSSCustomPropertyValue.h in Headers */,
</span><span class="cx">                                 4A9CC81816BB9AC600EC645A /* CSSDefaultStyleSheets.h in Headers */,
</span><span class="cx">                                 94476BDB1DFCAC0300690E23 /* CSSDeferredParser.h in Headers */,
</span><span class="lines">@@ -26683,6 +26696,7 @@
</span><span class="cx">                                 6C4C96DF1AD4483500363F64 /* JSReadableByteStreamController.h in Headers */,
</span><span class="cx">                                 7C4C96DD1AD4483500365A50 /* JSReadableStream.h in Headers */,
</span><span class="cx">                                 6C4C96DF1AD4483500365A50 /* JSReadableStreamDefaultController.h in Headers */,
</span><ins>+                                073B87671E4385AC0071C0EC /* AudioSampleBufferList.h in Headers */,
</ins><span class="cx">                                 7C4C96DF1AD4483500365A50 /* JSReadableStreamDefaultReader.h in Headers */,
</span><span class="cx">                                 4129DF861BB5B80C00322A16 /* JSReadableStreamPrivateConstructors.h in Headers */,
</span><span class="cx">                                 7E4C96DD1AD4483500365A51 /* JSReadableStreamSource.h in Headers */,
</span><span class="lines">@@ -28369,7 +28383,6 @@
</span><span class="cx">                                 BE913D80181EF92400DCB09E /* TrackPrivateBase.h in Headers */,
</span><span class="cx">                                 FFAC30FE184FB145008C4F1E /* TrailingObjects.h in Headers */,
</span><span class="cx">                                 516071321BD8308B00DBC4F2 /* TransactionOperation.h in Headers */,
</span><del>-                                07C046C21E425022007201E7 /* AudioSampleDataSource.h in Headers */,
</del><span class="cx">                                 49E911C40EF86D47009D0CAF /* TransformationMatrix.h in Headers */,
</span><span class="cx">                                 FB484F4D171F821E00040755 /* TransformFunctions.h in Headers */,
</span><span class="cx">                                 49E911CE0EF86D47009D0CAF /* TransformOperation.h in Headers */,
</span><span class="lines">@@ -29954,6 +29967,7 @@
</span><span class="cx">                                 51F798EF1BE880E7008AE491 /* IDBIndexInfo.cpp in Sources */,
</span><span class="cx">                                 51E269361DD3BD97006B6A58 /* IDBIterateCursorData.cpp in Sources */,
</span><span class="cx">                                 5185FC941BB4C4E80012898F /* IDBKey.cpp in Sources */,
</span><ins>+                                073B87661E4385AC0071C0EC /* AudioSampleBufferList.cpp in Sources */,
</ins><span class="cx">                                 5185FC961BB4C4E80012898F /* IDBKeyData.cpp in Sources */,
</span><span class="cx">                                 5185FC981BB4C4E80012898F /* IDBKeyPath.cpp in Sources */,
</span><span class="cx">                                 5185FC9A1BB4C4E80012898F /* IDBKeyRange.cpp in Sources */,
</span><span class="lines">@@ -29962,6 +29976,7 @@
</span><span class="cx">                                 5160712E1BD8307800DBC4F2 /* IDBObjectStoreInfo.cpp in Sources */,
</span><span class="cx">                                 5185FCA31BB4C4E80012898F /* IDBOpenDBRequest.cpp in Sources */,
</span><span class="cx">                                 5185FCA81BB4C4E80012898F /* IDBRequest.cpp in Sources */,
</span><ins>+                                073B87681E4385AC0071C0EC /* AudioSampleDataSource.cpp in Sources */,
</ins><span class="cx">                                 514129981C6976900059E714 /* IDBRequestCompletionEvent.cpp in Sources */,
</span><span class="cx">                                 510A58F91BACC7F200C19282 /* IDBRequestData.cpp in Sources */,
</span><span class="cx">                                 5145B1091BC48E2E00E86219 /* IDBResourceIdentifier.cpp in Sources */,
</span><span class="lines">@@ -30477,7 +30492,6 @@
</span><span class="cx">                                 E1284BB210449FFA00EAEB52 /* JSPageTransitionEvent.cpp in Sources */,
</span><span class="cx">                                 FDA15EB112B03EE1003A583A /* JSPannerNode.cpp in Sources */,
</span><span class="cx">                                 E51A81DF17298D7700BFCA61 /* JSPerformance.cpp in Sources */,
</span><del>-                                07C046C11E425022007201E7 /* AudioSampleDataSource.cpp in Sources */,
</del><span class="cx">                                 CB38FD511CCF938900592A3F /* JSPerformanceEntry.cpp in Sources */,
</span><span class="cx">                                 CB38FD571CD21E2A00592A3F /* JSPerformanceEntryCustom.cpp in Sources */,
</span><span class="cx">                                 A58C59D01E382EAC0047859C /* JSPerformanceMark.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiomacAudioSampleBufferListcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.cpp (0 => 211596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.cpp        2017-02-02 23:01:54 UTC (rev 211596)
</span><span class="lines">@@ -0,0 +1,340 @@
</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.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;AudioSampleBufferList.h&quot;
+
+#if ENABLE(MEDIA_STREAM)
+
+#include &quot;Logging.h&quot;
+#include &quot;VectorMath.h&quot;
+#include &lt;Accelerate/Accelerate.h&gt;
+#include &lt;AudioToolbox/AudioConverter.h&gt;
+
+namespace WebCore {
+
+using namespace VectorMath;
+
+Ref&lt;AudioSampleBufferList&gt; AudioSampleBufferList::create(const CAAudioStreamDescription&amp; format, size_t maximumSampleCount)
+{
+    return adoptRef(*new AudioSampleBufferList(format, maximumSampleCount));
+}
+
+AudioSampleBufferList::AudioSampleBufferList(const CAAudioStreamDescription&amp; format, size_t maximumSampleCount)
+{
+    m_internalFormat = std::make_unique&lt;CAAudioStreamDescription&gt;(format);
+
+    m_sampleCapacity = maximumSampleCount;
+    m_sampleCount = 0;
+    m_maxBufferSizePerChannel = maximumSampleCount * format.bytesPerFrame() / format.numberOfChannelStreams();
+
+    ASSERT(format.sampleRate() &gt;= 0);
+
+    size_t bufferSize = format.numberOfChannelStreams() * m_maxBufferSizePerChannel;
+    ASSERT(bufferSize &lt;= SIZE_MAX);
+    if (bufferSize &gt; SIZE_MAX)
+        return;
+
+    m_bufferListBaseSize = audioBufferListSizeForStream(format);
+    ASSERT(m_bufferListBaseSize &lt;= SIZE_MAX);
+    if (m_bufferListBaseSize &gt; SIZE_MAX)
+        return;
+
+    size_t allocSize = m_bufferListBaseSize + bufferSize;
+    m_bufferList = std::unique_ptr&lt;AudioBufferList&gt;(static_cast&lt;AudioBufferList*&gt;(::operator new (allocSize)));
+
+    reset();
+}
+
+AudioSampleBufferList::~AudioSampleBufferList()
+{
+    m_internalFormat = nullptr;
+    m_bufferList = nullptr;
+}
+
+void AudioSampleBufferList::setSampleCount(size_t count)
+{
+    ASSERT(count &lt;= m_sampleCapacity);
+    if (count &lt;= m_sampleCapacity)
+        m_sampleCount = count;
+}
+
+void AudioSampleBufferList::applyGain(AudioBufferList&amp; bufferList, float gain, AudioStreamDescription::PCMFormat format)
+{
+    for (uint32_t i = 0; i &lt; bufferList.mNumberBuffers; ++i) {
+        switch (format) {
+        case AudioStreamDescription::Int16: {
+            int16_t* buffer = static_cast&lt;int16_t*&gt;(bufferList.mBuffers[i].mData);
+            int frameCount = bufferList.mBuffers[i].mDataByteSize / sizeof(int16_t);
+            for (int i = 0; i &lt; frameCount; i++)
+                buffer[i] *= gain;
+            break;
+        }
+        case AudioStreamDescription::Int32: {
+            int32_t* buffer = static_cast&lt;int32_t*&gt;(bufferList.mBuffers[i].mData);
+            int frameCount = bufferList.mBuffers[i].mDataByteSize / sizeof(int32_t);
+            for (int i = 0; i &lt; frameCount; i++)
+                buffer[i] *= gain;
+            break;
+            break;
+        }
+        case AudioStreamDescription::Float32: {
+            float* buffer = static_cast&lt;float*&gt;(bufferList.mBuffers[i].mData);
+            vDSP_vsmul(buffer, 1, &amp;gain, buffer, 1, bufferList.mBuffers[i].mDataByteSize / sizeof(float));
+            break;
+        }
+        case AudioStreamDescription::Float64: {
+            double* buffer = static_cast&lt;double*&gt;(bufferList.mBuffers[i].mData);
+            double gainAsDouble = gain;
+            vDSP_vsmulD(buffer, 1, &amp;gainAsDouble, buffer, 1, bufferList.mBuffers[i].mDataByteSize / sizeof(double));
+            break;
+        }
+        case AudioStreamDescription::None:
+            ASSERT_NOT_REACHED();
+            break;
+        }
+    }
+}
+
+void AudioSampleBufferList::applyGain(float gain)
+{
+    applyGain(*m_bufferList, gain, m_internalFormat-&gt;format());
+}
+
+OSStatus AudioSampleBufferList::mixFrom(const AudioSampleBufferList&amp; source, size_t frameCount)
+{
+    ASSERT(source.streamDescription() == streamDescription());
+
+    if (source.streamDescription() != streamDescription())
+        return kAudio_ParamError;
+
+    if (frameCount &gt; source.sampleCount())
+        frameCount = source.sampleCount();
+
+    if (frameCount &gt; m_sampleCapacity)
+        return kAudio_ParamError;
+
+    m_sampleCount = frameCount;
+
+    AudioBufferList&amp; sourceBuffer = source.bufferList();
+    for (uint32_t i = 0; i &lt; m_bufferList-&gt;mNumberBuffers; i++) {
+        switch (m_internalFormat-&gt;format()) {
+        case AudioStreamDescription::Int16: {
+            int16_t* destination = static_cast&lt;int16_t*&gt;(m_bufferList-&gt;mBuffers[i].mData);
+            int16_t* source = static_cast&lt;int16_t*&gt;(sourceBuffer.mBuffers[i].mData);
+            for (size_t i = 0; i &lt; frameCount; i++)
+                destination[i] += source[i];
+            break;
+        }
+        case AudioStreamDescription::Int32: {
+            int32_t* destination = static_cast&lt;int32_t*&gt;(m_bufferList-&gt;mBuffers[i].mData);
+            vDSP_vaddi(destination, 1, reinterpret_cast&lt;int32_t*&gt;(sourceBuffer.mBuffers[i].mData), 1, destination, 1, frameCount);
+            break;
+        }
+        case AudioStreamDescription::Float32: {
+            float* destination = static_cast&lt;float*&gt;(m_bufferList-&gt;mBuffers[i].mData);
+            vDSP_vadd(destination, 1, reinterpret_cast&lt;float*&gt;(sourceBuffer.mBuffers[i].mData), 1, destination, 1, frameCount);
+            break;
+        }
+        case AudioStreamDescription::Float64: {
+            double* destination = static_cast&lt;double*&gt;(m_bufferList-&gt;mBuffers[i].mData);
+            vDSP_vaddD(destination, 1, reinterpret_cast&lt;double*&gt;(sourceBuffer.mBuffers[i].mData), 1, destination, 1, frameCount);
+            break;
+        }
+        case AudioStreamDescription::None:
+            ASSERT_NOT_REACHED();
+            break;
+        }
+    }
+
+    return 0;
+}
+
+OSStatus AudioSampleBufferList::copyFrom(const AudioSampleBufferList&amp; source, size_t frameCount)
+{
+    ASSERT(source.streamDescription() == streamDescription());
+
+    if (source.streamDescription() != streamDescription())
+        return kAudio_ParamError;
+
+    if (frameCount &gt; source.sampleCount())
+        frameCount = source.sampleCount();
+
+    if (frameCount &gt; m_sampleCapacity)
+        return kAudio_ParamError;
+
+    m_sampleCount = frameCount;
+
+    for (uint32_t i = 0; i &lt; m_bufferList-&gt;mNumberBuffers; i++) {
+        uint8_t* sourceData = static_cast&lt;uint8_t*&gt;(source.bufferList().mBuffers[i].mData);
+        uint8_t* destination = static_cast&lt;uint8_t*&gt;(m_bufferList-&gt;mBuffers[i].mData);
+        memcpy(destination, sourceData, frameCount * m_internalFormat-&gt;bytesPerPacket());
+    }
+
+    return 0;
+}
+
+OSStatus AudioSampleBufferList::copyTo(AudioBufferList&amp; buffer, size_t frameCount)
+{
+    if (frameCount &gt; m_sampleCount)
+        return kAudio_ParamError;
+    if (buffer.mNumberBuffers &gt; m_bufferList-&gt;mNumberBuffers)
+        return kAudio_ParamError;
+
+    for (uint32_t i = 0; i &lt; buffer.mNumberBuffers; i++) {
+        uint8_t* sourceData = static_cast&lt;uint8_t*&gt;(m_bufferList-&gt;mBuffers[i].mData);
+        uint8_t* destination = static_cast&lt;uint8_t*&gt;(buffer.mBuffers[i].mData);
+        memcpy(destination, sourceData, frameCount * m_internalFormat-&gt;bytesPerPacket());
+    }
+
+    return 0;
+}
+
+void AudioSampleBufferList::reset()
+{
+    m_sampleCount = 0;
+    m_timestamp = 0;
+    m_hostTime = -1;
+
+    uint8_t* data = reinterpret_cast&lt;uint8_t*&gt;(m_bufferList.get()) + m_bufferListBaseSize;
+    m_bufferList-&gt;mNumberBuffers = m_internalFormat-&gt;numberOfChannelStreams();
+    for (uint32_t i = 0; i &lt; m_bufferList-&gt;mNumberBuffers; ++i) {
+        auto&amp; buffer = m_bufferList-&gt;mBuffers[i];
+        buffer.mData = data;
+        buffer.mDataByteSize = m_maxBufferSizePerChannel;
+        buffer.mNumberChannels = m_internalFormat-&gt;numberOfInterleavedChannels();
+        data = data + m_maxBufferSizePerChannel;
+    }
+}
+
+void AudioSampleBufferList::zero()
+{
+    zeroABL(*m_bufferList, m_internalFormat-&gt;bytesPerPacket() * m_sampleCapacity);
+}
+
+void AudioSampleBufferList::zeroABL(AudioBufferList&amp; buffer, size_t byteCount)
+{
+    for (uint32_t i = 0; i &lt; buffer.mNumberBuffers; ++i)
+        memset(buffer.mBuffers[i].mData, 0, byteCount);
+}
+
+OSStatus AudioSampleBufferList::convertInput(UInt32* ioNumberDataPackets, AudioBufferList* ioData)
+{
+    if (!ioNumberDataPackets || !ioData || !m_converterInputBuffer) {
+        LOG_ERROR(&quot;AudioSampleBufferList::reconfigureInput(%p) invalid input to AudioConverterInput&quot;, this);
+        return kAudioConverterErr_UnspecifiedError;
+    }
+
+    size_t packetCount = m_converterInputBuffer-&gt;mBuffers[0].mDataByteSize / m_converterInputBytesPerPacket;
+    if (*ioNumberDataPackets &gt; m_sampleCapacity) {
+        LOG_ERROR(&quot;AudioSampleBufferList::convertInput(%p) not enough internal storage: needed = %u, available = %lu&quot;, this, *ioNumberDataPackets, m_sampleCapacity);
+        return kAudioConverterErr_InvalidInputSize;
+    }
+
+    *ioNumberDataPackets = static_cast&lt;UInt32&gt;(packetCount);
+    for (uint32_t i = 0; i &lt; ioData-&gt;mNumberBuffers; ++i) {
+        ioData-&gt;mBuffers[i].mData = m_converterInputBuffer-&gt;mBuffers[i].mData;
+        ioData-&gt;mBuffers[i].mDataByteSize = m_converterInputBuffer-&gt;mBuffers[i].mDataByteSize;
+    }
+
+    return 0;
+}
+
+OSStatus AudioSampleBufferList::audioConverterCallback(AudioConverterRef, UInt32* ioNumberDataPackets, AudioBufferList* ioData, AudioStreamPacketDescription**, void* inRefCon)
+{
+    return static_cast&lt;AudioSampleBufferList*&gt;(inRefCon)-&gt;convertInput(ioNumberDataPackets, ioData);
+}
+
+OSStatus AudioSampleBufferList::copyFrom(AudioBufferList&amp; source, AudioConverterRef converter)
+{
+    reset();
+
+    AudioStreamBasicDescription inputFormat;
+    UInt32 propertyDataSize = sizeof(inputFormat);
+    AudioConverterGetProperty(converter, kAudioConverterCurrentInputStreamDescription, &amp;propertyDataSize, &amp;inputFormat);
+    m_converterInputBytesPerPacket = inputFormat.mBytesPerPacket;
+    m_converterInputBuffer = &amp;source;
+
+    auto* outputData = m_bufferList.get();
+
+#if !LOG_DISABLED
+    AudioStreamBasicDescription outputFormat;
+    propertyDataSize = sizeof(outputFormat);
+    AudioConverterGetProperty(converter, kAudioConverterCurrentOutputStreamDescription, &amp;propertyDataSize, &amp;outputFormat);
+
+    ASSERT(outputFormat.mChannelsPerFrame == outputData-&gt;mNumberBuffers);
+    for (uint32_t i = 0; i &lt; outputData-&gt;mNumberBuffers; ++i) {
+        ASSERT(outputData-&gt;mBuffers[i].mData);
+        ASSERT(outputData-&gt;mBuffers[i].mDataByteSize);
+    }
+#endif
+
+    UInt32 samplesConverted = static_cast&lt;UInt32&gt;(m_sampleCapacity);
+    OSStatus err = AudioConverterFillComplexBuffer(converter, audioConverterCallback, this, &amp;samplesConverted, outputData, nullptr);
+    if (err) {
+        LOG_ERROR(&quot;AudioSampleBufferList::copyFrom(%p) AudioConverterFillComplexBuffer returned error %d (%.4s)&quot;, this, err, (char*)&amp;err);
+        m_sampleCount = std::min(m_sampleCapacity, static_cast&lt;size_t&gt;(samplesConverted));
+        zero();
+        return err;
+    }
+
+    m_sampleCount = samplesConverted;
+    return 0;
+}
+
+OSStatus AudioSampleBufferList::copyFrom(AudioSampleBufferList&amp; source, AudioConverterRef converter)
+{
+    return copyFrom(source.bufferList(), converter);
+}
+
+OSStatus AudioSampleBufferList::copyFrom(CARingBuffer&amp; ringBuffer, size_t sampleCount, uint64_t startFrame, CARingBuffer::FetchMode mode)
+{
+    reset();
+    if (ringBuffer.fetch(&amp;bufferList(), sampleCount, startFrame, mode) != CARingBuffer::Ok)
+        return kAudio_ParamError;
+
+    m_sampleCount = sampleCount;
+    return 0;
+}
+
+void AudioSampleBufferList::configureBufferListForStream(AudioBufferList&amp; bufferList, const CAAudioStreamDescription&amp; format, uint8_t* bufferData, size_t sampleCount)
+{
+    size_t bufferCount = format.numberOfChannelStreams();
+    size_t channelCount = format.numberOfInterleavedChannels();
+    size_t bytesPerChannel = sampleCount * format.bytesPerFrame();
+
+    bufferList.mNumberBuffers = bufferCount;
+    for (unsigned i = 0; i &lt; bufferCount; ++i) {
+        bufferList.mBuffers[i].mNumberChannels = channelCount;
+        bufferList.mBuffers[i].mDataByteSize = bytesPerChannel;
+        bufferList.mBuffers[i].mData = bufferData;
+        if (bufferData)
+            bufferData = bufferData + bytesPerChannel;
+    }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiomacAudioSampleBufferListh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.h (0 => 211596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.h                                (rev 0)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.h        2017-02-02 23:01:54 UTC (rev 211596)
</span><span class="lines">@@ -0,0 +1,106 @@
</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)
+
+#include &quot;CARingBuffer.h&quot;
+#include &lt;CoreAudio/CoreAudioTypes.h&gt;
+#include &lt;wtf/Lock.h&gt;
+#include &lt;wtf/RefCounted.h&gt;
+#include &lt;wtf/RefPtr.h&gt;
+
+typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
+typedef struct OpaqueAudioConverter* AudioConverterRef;
+
+namespace WebCore {
+
+class AudioSampleBufferList : public RefCounted&lt;AudioSampleBufferList&gt; {
+public:
+    static Ref&lt;AudioSampleBufferList&gt; create(const CAAudioStreamDescription&amp;, size_t);
+
+    ~AudioSampleBufferList();
+
+    static void configureBufferListForStream(AudioBufferList&amp;, const CAAudioStreamDescription&amp;, uint8_t*, size_t);
+    static inline size_t audioBufferListSizeForStream(const CAAudioStreamDescription&amp;);
+
+    static void applyGain(AudioBufferList&amp;, float, AudioStreamDescription::PCMFormat);
+    void applyGain(float);
+
+    OSStatus copyFrom(const AudioSampleBufferList&amp;, size_t count = SIZE_MAX);
+    OSStatus copyFrom(AudioBufferList&amp;, AudioConverterRef);
+    OSStatus copyFrom(AudioSampleBufferList&amp;, AudioConverterRef);
+    OSStatus copyFrom(CARingBuffer&amp;, size_t frameCount, uint64_t startFrame, CARingBuffer::FetchMode);
+
+    OSStatus mixFrom(const AudioSampleBufferList&amp;, size_t count = SIZE_MAX);
+
+    OSStatus copyTo(AudioBufferList&amp;, size_t count = SIZE_MAX);
+
+    const AudioStreamBasicDescription&amp; streamDescription() const { return m_internalFormat-&gt;streamDescription(); }
+    AudioBufferList&amp; bufferList() const { return *m_bufferList.get(); }
+
+    uint32_t sampleCapacity() const { return m_sampleCapacity; }
+    uint32_t sampleCount() const { return m_sampleCount; }
+    void setSampleCount(size_t);
+
+    uint64_t timestamp() const { return m_timestamp; }
+    double hostTime() const { return m_hostTime; }
+    void setTimes(uint64_t time, double hostTime) { m_timestamp = time; m_hostTime = hostTime; }
+
+    void reset();
+
+    static void zeroABL(AudioBufferList&amp;, size_t);
+    void zero();
+
+protected:
+    AudioSampleBufferList(const CAAudioStreamDescription&amp;, size_t);
+
+    static OSStatus audioConverterCallback(AudioConverterRef, UInt32*, AudioBufferList*, AudioStreamPacketDescription**, void*);
+    OSStatus convertInput(UInt32*, AudioBufferList*);
+
+    std::unique_ptr&lt;CAAudioStreamDescription&gt; m_internalFormat;
+
+    AudioSampleBufferList* m_converterInputBuffer2 { nullptr };
+    AudioBufferList* m_converterInputBuffer { nullptr };
+    uint32_t m_converterInputBytesPerPacket { 0 };
+
+    uint64_t m_timestamp { 0 };
+    double m_hostTime { -1 };
+    size_t m_sampleCount { 0 };
+    size_t m_sampleCapacity { 0 };
+    size_t m_maxBufferSizePerChannel { 0 };
+    size_t m_bufferListBaseSize { 0 };
+    std::unique_ptr&lt;AudioBufferList&gt; m_bufferList;
+};
+
+inline size_t AudioSampleBufferList::audioBufferListSizeForStream(const CAAudioStreamDescription&amp; description)
+{
+    return offsetof(AudioBufferList, mBuffers) + (sizeof(AudioBuffer) * std::max&lt;uint32_t&gt;(1, description.numberOfChannelStreams()));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiomacAudioSampleDataSourcecpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.cpp (0 => 211596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.cpp        2017-02-02 23:01:54 UTC (rev 211596)
</span><span class="lines">@@ -0,0 +1,338 @@
</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.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;AudioSampleDataSource.h&quot;
+
+#if ENABLE(MEDIA_STREAM)
+
+#include &quot;CAAudioStreamDescription.h&quot;
+#include &quot;CARingBuffer.h&quot;
+#include &quot;Logging.h&quot;
+#include &quot;MediaTimeAVFoundation.h&quot;
+#include &lt;AudioToolbox/AudioConverter.h&gt;
+#include &lt;mach/mach.h&gt;
+#include &lt;mach/mach_time.h&gt;
+#include &lt;mutex&gt;
+#include &lt;syslog.h&gt;
+#include &lt;wtf/CurrentTime.h&gt;
+#include &lt;wtf/StringPrintStream.h&gt;
+
+#include &quot;CoreMediaSoftLink.h&quot;
+
+namespace WebCore {
+
+using namespace JSC;
+
+Ref&lt;AudioSampleDataSource&gt; AudioSampleDataSource::create(size_t maximumSampleCount)
+{
+    return adoptRef(*new AudioSampleDataSource(maximumSampleCount));
+}
+
+AudioSampleDataSource::AudioSampleDataSource(size_t maximumSampleCount)
+    : m_inputSampleOffset(MediaTime::invalidTime())
+    , m_maximumSampleCount(maximumSampleCount)
+{
+}
+
+AudioSampleDataSource::~AudioSampleDataSource()
+{
+    m_inputDescription = nullptr;
+    m_outputDescription = nullptr;
+    m_ringBuffer = nullptr;
+    if (m_converter) {
+        AudioConverterDispose(m_converter);
+        m_converter = nullptr;
+    }
+}
+
+void AudioSampleDataSource::setPaused(bool paused)
+{
+    std::lock_guard&lt;Lock&gt; lock(m_lock);
+
+    if (paused == m_paused)
+        return;
+
+    m_transitioningFromPaused = m_paused;
+    m_paused = paused;
+}
+
+OSStatus AudioSampleDataSource::setupConverter()
+{
+    ASSERT(m_inputDescription &amp;&amp; m_outputDescription);
+
+    if (m_converter) {
+        AudioConverterDispose(m_converter);
+        m_converter = nullptr;
+    }
+
+    if (*m_inputDescription == *m_outputDescription)
+        return 0;
+
+    OSStatus err = AudioConverterNew(&amp;m_inputDescription-&gt;streamDescription(), &amp;m_outputDescription-&gt;streamDescription(), &amp;m_converter);
+    if (err)
+        LOG_ERROR(&quot;AudioSampleDataSource::setupConverter(%p) - AudioConverterNew returned error %d (%.4s)&quot;, this, err, (char*)&amp;err);
+
+    return err;
+
+}
+
+OSStatus AudioSampleDataSource::setInputFormat(const CAAudioStreamDescription&amp; format)
+{
+    ASSERT(format.sampleRate() &gt;= 0);
+
+    m_inputDescription = std::make_unique&lt;CAAudioStreamDescription&gt;(format);
+    if (m_outputDescription)
+        return setupConverter();
+
+    return 0;
+}
+
+OSStatus AudioSampleDataSource::setOutputFormat(const CAAudioStreamDescription&amp; format)
+{
+    ASSERT(m_inputDescription);
+    ASSERT(format.sampleRate() &gt;= 0);
+
+    m_outputDescription = std::make_unique&lt;CAAudioStreamDescription&gt;(format);
+    if (!m_ringBuffer)
+        m_ringBuffer = std::make_unique&lt;CARingBuffer&gt;();
+
+    m_ringBuffer-&gt;allocate(format, static_cast&lt;size_t&gt;(m_maximumSampleCount));
+    m_scratchBuffer = AudioSampleBufferList::create(m_outputDescription-&gt;streamDescription(), m_maximumSampleCount);
+
+    return setupConverter();
+}
+
+MediaTime AudioSampleDataSource::hostTime() const
+{
+    // Based on listing #2 from Apple Technical Q&amp;A QA1398, modified to be thread-safe.
+    static double frequency;
+    static mach_timebase_info_data_t timebaseInfo;
+    static std::once_flag initializeTimerOnceFlag;
+    std::call_once(initializeTimerOnceFlag, [] {
+        kern_return_t kr = mach_timebase_info(&amp;timebaseInfo);
+        frequency = 1e-9 * static_cast&lt;double&gt;(timebaseInfo.numer) / static_cast&lt;double&gt;(timebaseInfo.denom);
+        ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
+        ASSERT(timebaseInfo.denom);
+    });
+
+    return MediaTime::createWithDouble(mach_absolute_time() * frequency);
+}
+
+void AudioSampleDataSource::pushSamplesInternal(AudioBufferList&amp; bufferList, const MediaTime&amp; presentationTime, size_t sampleCount)
+{
+    ASSERT(m_lock.isHeld());
+
+    AudioBufferList* sampleBufferList;
+    if (m_converter) {
+        m_scratchBuffer-&gt;reset();
+        OSStatus err = m_scratchBuffer-&gt;copyFrom(bufferList, m_converter);
+        if (err)
+            return;
+
+        sampleBufferList = &amp;m_scratchBuffer-&gt;bufferList();
+    } else
+        sampleBufferList = &amp;bufferList;
+
+    MediaTime sampleTime = presentationTime;
+    if (m_inputSampleOffset == MediaTime::invalidTime()) {
+        m_inputSampleOffset = MediaTime(1 - sampleTime.timeValue(), sampleTime.timeScale());
+        if (m_inputSampleOffset.timeScale() != sampleTime.timeScale()) {
+            // FIXME: It should be possible to do this without calling CMTimeConvertScale.
+            m_inputSampleOffset = toMediaTime(CMTimeConvertScale(toCMTime(m_inputSampleOffset), sampleTime.timeScale(), kCMTimeRoundingMethod_Default));
+        }
+        LOG(MediaCaptureSamples, &quot;@@ pushSamples: input sample offset is %lld, m_maximumSampleCount = %zu&quot;, m_inputSampleOffset.timeValue(), m_maximumSampleCount);
+    }
+    sampleTime += m_inputSampleOffset;
+
+#if !LOG_DISABLED
+    uint64_t startFrame1 = 0;
+    uint64_t endFrame1 = 0;
+    m_ringBuffer-&gt;getCurrentFrameBounds(startFrame1, endFrame1);
+#endif
+
+    m_ringBuffer-&gt;store(sampleBufferList, sampleCount, sampleTime.timeValue());
+    m_timeStamp = sampleTime.timeValue();
+
+    LOG(MediaCaptureSamples, &quot;@@ pushSamples: added %ld samples for time = %s (was %s), mach time = %lld&quot;, sampleCount, toString(sampleTime).utf8().data(), toString(presentationTime).utf8().data(), mach_absolute_time());
+
+#if !LOG_DISABLED
+    uint64_t startFrame2 = 0;
+    uint64_t endFrame2 = 0;
+    m_ringBuffer-&gt;getCurrentFrameBounds(startFrame2, endFrame2);
+    LOG(MediaCaptureSamples, &quot;@@ pushSamples: buffered range was [%lld .. %lld], is [%lld .. %lld]&quot;, startFrame1, endFrame1, startFrame2, endFrame2);
+#endif
+}
+
+void AudioSampleDataSource::pushSamples(const AudioStreamBasicDescription&amp; sampleDescription, CMSampleBufferRef sampleBuffer)
+{
+    std::lock_guard&lt;Lock&gt; lock(m_lock);
+
+    ASSERT_UNUSED(sampleDescription, *m_inputDescription == sampleDescription);
+    ASSERT(m_ringBuffer);
+
+    size_t bufferSize = AudioSampleBufferList::audioBufferListSizeForStream(*m_inputDescription.get());
+    uint8_t bufferData[bufferSize];
+    AudioBufferList* bufferList = reinterpret_cast&lt;AudioBufferList*&gt;(bufferData);
+    bufferList-&gt;mNumberBuffers = m_inputDescription-&gt;numberOfInterleavedChannels();
+
+    CMBlockBufferRef buffer = nullptr;
+    OSStatus err = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, nullptr, bufferList, bufferSize, kCFAllocatorSystemDefault, kCFAllocatorSystemDefault, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &amp;buffer);
+    if (err) {
+        LOG_ERROR(&quot;AudioSampleDataSource::pushSamples(%p) - CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer returned error %d (%.4s)&quot;, this, err, (char*)&amp;err);
+        return;
+    }
+
+    pushSamplesInternal(*bufferList, toMediaTime(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)), CMSampleBufferGetNumSamples(sampleBuffer));
+}
+
+void AudioSampleDataSource::pushSamples(const AudioStreamBasicDescription&amp; sampleDescription, const MediaTime&amp; sampleTime, void* audioData, size_t sampleCount)
+{
+    std::unique_lock&lt;Lock&gt; lock(m_lock, std::try_to_lock);
+    ASSERT(*m_inputDescription == sampleDescription);
+
+    CAAudioStreamDescription description(sampleDescription);
+    size_t bufferSize = AudioSampleBufferList::audioBufferListSizeForStream(description);
+    uint8_t bufferData[bufferSize];
+    AudioBufferList* bufferList = reinterpret_cast&lt;AudioBufferList*&gt;(bufferData);
+
+    AudioSampleBufferList::configureBufferListForStream(*bufferList, description, reinterpret_cast&lt;uint8_t*&gt;(audioData), sampleCount);
+    pushSamplesInternal(*bufferList, sampleTime, sampleCount);
+}
+
+bool AudioSampleDataSource::pullSamplesInternal(AudioBufferList&amp; buffer, size_t&amp; sampleCount, uint64_t timeStamp, double /*hostTime*/, PullMode mode)
+{
+    ASSERT(m_lock.isHeld());
+
+    ASSERT(buffer.mNumberBuffers == m_ringBuffer-&gt;channelCount());
+    if (buffer.mNumberBuffers != m_ringBuffer-&gt;channelCount()) {
+        AudioSampleBufferList::zeroABL(buffer, sampleCount);
+        sampleCount = 0;
+        return false;
+    }
+
+    if (!m_ringBuffer || m_muted || m_inputSampleOffset == MediaTime::invalidTime()) {
+        AudioSampleBufferList::zeroABL(buffer, sampleCount);
+        sampleCount = 0;
+        return false;
+    }
+
+    uint64_t startFrame = 0;
+    uint64_t endFrame = 0;
+    m_ringBuffer-&gt;getCurrentFrameBounds(startFrame, endFrame);
+
+    if (m_transitioningFromPaused) {
+        uint64_t buffered = endFrame - m_timeStamp;
+        if (buffered &lt; sampleCount * 2) {
+            AudioSampleBufferList::zeroABL(buffer, sampleCount);
+            sampleCount = 0;
+            return false;
+        }
+
+        const double twentyMS = .02;
+        const double tenMS = .01;
+        const double fiveMS = .005;
+        double sampleRate = m_outputDescription-&gt;sampleRate();
+        if (buffered &gt; sampleRate * twentyMS)
+            m_outputSampleOffset = m_timeStamp - sampleRate * twentyMS;
+        else if (buffered &gt; sampleRate * tenMS)
+            m_outputSampleOffset = m_timeStamp - sampleRate * tenMS;
+        else if (buffered &gt; sampleRate * fiveMS)
+            m_outputSampleOffset = m_timeStamp - sampleRate * fiveMS;
+        else
+            m_outputSampleOffset = m_timeStamp;
+
+        m_transitioningFromPaused = false;
+    }
+
+    timeStamp += m_outputSampleOffset;
+
+    LOG(MediaCaptureSamples, &quot;** pullSamples: asking for %ld samples at time = %lld (was %lld)&quot;, sampleCount, timeStamp, timeStamp - m_outputSampleOffset);
+
+    int64_t framesAvailable = sampleCount;
+    if (timeStamp &lt; startFrame || timeStamp + sampleCount &gt; endFrame) {
+        if (timeStamp + sampleCount &lt; startFrame || timeStamp &gt; endFrame)
+            framesAvailable = 0;
+        else if (timeStamp &lt; startFrame)
+            framesAvailable = timeStamp + sampleCount - startFrame;
+        else
+            framesAvailable = timeStamp + sampleCount - endFrame;
+
+        LOG(MediaCaptureSamples, &quot;** pullSamplesInternal: sample %lld is not completely in range [%lld .. %lld], returning %lld frames&quot;, timeStamp, startFrame, endFrame, framesAvailable);
+
+        if (!framesAvailable) {
+            AudioSampleBufferList::zeroABL(buffer, sampleCount);
+            return false;
+        }
+    }
+
+    if (m_volume &gt;= .95) {
+        m_ringBuffer-&gt;fetch(&amp;buffer, sampleCount, timeStamp, mode == Copy ? CARingBuffer::Copy : CARingBuffer::Mix);
+        return true;
+    }
+
+    if (m_scratchBuffer-&gt;copyFrom(*m_ringBuffer.get(), sampleCount, timeStamp, mode == Copy ? CARingBuffer::Copy : CARingBuffer::Mix)) {
+        AudioSampleBufferList::zeroABL(buffer, sampleCount);
+        return false;
+    }
+
+    m_scratchBuffer-&gt;applyGain(m_volume);
+    if (m_scratchBuffer-&gt;copyTo(buffer, sampleCount))
+        AudioSampleBufferList::zeroABL(buffer, sampleCount);
+
+    return true;
+}
+
+bool AudioSampleDataSource::pullSamples(AudioBufferList&amp; buffer, size_t sampleCount, uint64_t timeStamp, double hostTime, PullMode mode)
+{
+    std::unique_lock&lt;Lock&gt; lock(m_lock, std::try_to_lock);
+    if (!lock.owns_lock() || !m_ringBuffer) {
+        AudioSampleBufferList::zeroABL(buffer, sampleCount);
+        return false;
+    }
+
+    return pullSamplesInternal(buffer, sampleCount, timeStamp, hostTime, mode);
+}
+
+bool AudioSampleDataSource::pullSamples(AudioSampleBufferList&amp; buffer, size_t sampleCount, uint64_t timeStamp, double hostTime, PullMode mode)
+{
+    std::unique_lock&lt;Lock&gt; lock(m_lock, std::try_to_lock);
+    if (!lock.owns_lock() || !m_ringBuffer) {
+        buffer.zero();
+        return false;
+    }
+
+    if (!pullSamplesInternal(buffer.bufferList(), sampleCount, timeStamp, hostTime, mode))
+        return false;
+
+    buffer.setTimes(timeStamp, hostTime);
+    buffer.setSampleCount(sampleCount);
+
+    return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiomacAudioSampleDataSourceh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.h (0 => 211596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.h                                (rev 0)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.h        2017-02-02 23:01:54 UTC (rev 211596)
</span><span class="lines">@@ -0,0 +1,104 @@
</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)
+
+#include &quot;AudioSampleBufferList.h&quot;
+#include &lt;CoreAudio/CoreAudioTypes.h&gt;
+#include &lt;wtf/Lock.h&gt;
+#include &lt;wtf/MediaTime.h&gt;
+#include &lt;wtf/RefCounted.h&gt;
+#include &lt;wtf/RefPtr.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
+typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
+
+namespace WebCore {
+
+class CAAudioStreamDescription;
+class CARingBuffer;
+
+class AudioSampleDataSource : public RefCounted&lt;AudioSampleDataSource&gt; {
+public:
+    static Ref&lt;AudioSampleDataSource&gt; create(size_t);
+
+    ~AudioSampleDataSource();
+
+    OSStatus setInputFormat(const CAAudioStreamDescription&amp;);
+    OSStatus setOutputFormat(const CAAudioStreamDescription&amp;);
+
+    void pushSamples(const AudioStreamBasicDescription&amp;, const MediaTime&amp;, void*, size_t);
+    void pushSamples(const AudioStreamBasicDescription&amp;, CMSampleBufferRef);
+
+    enum PullMode { Copy, Mix };
+    bool pullSamples(AudioSampleBufferList&amp;, size_t, uint64_t, double, PullMode);
+    bool pullSamples(AudioBufferList&amp;, size_t, uint64_t, double, PullMode);
+
+    void setPaused(bool);
+
+    void setVolume(float volume) { m_volume = volume; }
+    float volume() const { return m_volume; }
+
+    void setMuted(bool muted) { m_muted = muted; }
+    bool muted() const { return m_muted; }
+
+protected:
+    AudioSampleDataSource(size_t);
+
+    OSStatus setupConverter();
+    bool pullSamplesInternal(AudioBufferList&amp;, size_t&amp;, uint64_t, double, PullMode);
+
+    void pushSamplesInternal(AudioBufferList&amp;, const MediaTime&amp;, size_t frameCount);
+
+    std::unique_ptr&lt;CAAudioStreamDescription&gt; m_inputDescription;
+    std::unique_ptr&lt;CAAudioStreamDescription&gt; m_outputDescription;
+
+    MediaTime hostTime() const;
+
+    uint64_t m_timeStamp { 0 };
+    double m_hostTime { -1 };
+
+    MediaTime m_inputSampleOffset;
+    uint64_t m_outputSampleOffset { 0 };
+
+    AudioConverterRef m_converter;
+    RefPtr&lt;AudioSampleBufferList&gt; m_scratchBuffer;
+
+    std::unique_ptr&lt;CARingBuffer&gt; m_ringBuffer;
+    size_t m_maximumSampleCount { 0 };
+
+    Lock m_lock;
+    float m_volume { 1.0 };
+    bool m_muted { false };
+    bool m_paused { true };
+    bool m_transitioningFromPaused { true };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
</ins></span></pre>
</div>
</div>

</body>
</html>