<!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 <eric.carlson@apple.com>
+
+ [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 <pecoraro@apple.com>
</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 = "<group>"; };
</span><span class="cx">                 073B87571E40DCFD0071C0EC /* CAAudioStreamDescription.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CAAudioStreamDescription.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 073B87581E40DCFD0071C0EC /* CAAudioStreamDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CAAudioStreamDescription.h; sourceTree = "<group>"; };
</span><ins>+                073B87621E43859D0071C0EC /* AudioSampleBufferList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSampleBufferList.cpp; sourceTree = "<group>"; };
+                073B87631E43859D0071C0EC /* AudioSampleBufferList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSampleBufferList.h; sourceTree = "<group>"; };
+                073B87641E43859D0071C0EC /* AudioSampleDataSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSampleDataSource.cpp; sourceTree = "<group>"; };
+                073B87651E43859D0071C0EC /* AudioSampleDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSampleDataSource.h; sourceTree = "<group>"; };
</ins><span class="cx">                 073BE33E17D17E01002BD431 /* JSNavigatorUserMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNavigatorUserMedia.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 073BE33F17D17E01002BD431 /* JSNavigatorUserMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNavigatorUserMedia.h; sourceTree = "<group>"; };
</span><span class="cx">                 0744ECEB1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockRealtimeAudioSourceMac.h; sourceTree = "<group>"; };
</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 "config.h"
+#include "AudioSampleBufferList.h"
+
+#if ENABLE(MEDIA_STREAM)
+
+#include "Logging.h"
+#include "VectorMath.h"
+#include <Accelerate/Accelerate.h>
+#include <AudioToolbox/AudioConverter.h>
+
+namespace WebCore {
+
+using namespace VectorMath;
+
+Ref<AudioSampleBufferList> AudioSampleBufferList::create(const CAAudioStreamDescription& format, size_t maximumSampleCount)
+{
+ return adoptRef(*new AudioSampleBufferList(format, maximumSampleCount));
+}
+
+AudioSampleBufferList::AudioSampleBufferList(const CAAudioStreamDescription& format, size_t maximumSampleCount)
+{
+ m_internalFormat = std::make_unique<CAAudioStreamDescription>(format);
+
+ m_sampleCapacity = maximumSampleCount;
+ m_sampleCount = 0;
+ m_maxBufferSizePerChannel = maximumSampleCount * format.bytesPerFrame() / format.numberOfChannelStreams();
+
+ ASSERT(format.sampleRate() >= 0);
+
+ size_t bufferSize = format.numberOfChannelStreams() * m_maxBufferSizePerChannel;
+ ASSERT(bufferSize <= SIZE_MAX);
+ if (bufferSize > SIZE_MAX)
+ return;
+
+ m_bufferListBaseSize = audioBufferListSizeForStream(format);
+ ASSERT(m_bufferListBaseSize <= SIZE_MAX);
+ if (m_bufferListBaseSize > SIZE_MAX)
+ return;
+
+ size_t allocSize = m_bufferListBaseSize + bufferSize;
+ m_bufferList = std::unique_ptr<AudioBufferList>(static_cast<AudioBufferList*>(::operator new (allocSize)));
+
+ reset();
+}
+
+AudioSampleBufferList::~AudioSampleBufferList()
+{
+ m_internalFormat = nullptr;
+ m_bufferList = nullptr;
+}
+
+void AudioSampleBufferList::setSampleCount(size_t count)
+{
+ ASSERT(count <= m_sampleCapacity);
+ if (count <= m_sampleCapacity)
+ m_sampleCount = count;
+}
+
+void AudioSampleBufferList::applyGain(AudioBufferList& bufferList, float gain, AudioStreamDescription::PCMFormat format)
+{
+ for (uint32_t i = 0; i < bufferList.mNumberBuffers; ++i) {
+ switch (format) {
+ case AudioStreamDescription::Int16: {
+ int16_t* buffer = static_cast<int16_t*>(bufferList.mBuffers[i].mData);
+ int frameCount = bufferList.mBuffers[i].mDataByteSize / sizeof(int16_t);
+ for (int i = 0; i < frameCount; i++)
+ buffer[i] *= gain;
+ break;
+ }
+ case AudioStreamDescription::Int32: {
+ int32_t* buffer = static_cast<int32_t*>(bufferList.mBuffers[i].mData);
+ int frameCount = bufferList.mBuffers[i].mDataByteSize / sizeof(int32_t);
+ for (int i = 0; i < frameCount; i++)
+ buffer[i] *= gain;
+ break;
+ break;
+ }
+ case AudioStreamDescription::Float32: {
+ float* buffer = static_cast<float*>(bufferList.mBuffers[i].mData);
+ vDSP_vsmul(buffer, 1, &gain, buffer, 1, bufferList.mBuffers[i].mDataByteSize / sizeof(float));
+ break;
+ }
+ case AudioStreamDescription::Float64: {
+ double* buffer = static_cast<double*>(bufferList.mBuffers[i].mData);
+ double gainAsDouble = gain;
+ vDSP_vsmulD(buffer, 1, &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->format());
+}
+
+OSStatus AudioSampleBufferList::mixFrom(const AudioSampleBufferList& source, size_t frameCount)
+{
+ ASSERT(source.streamDescription() == streamDescription());
+
+ if (source.streamDescription() != streamDescription())
+ return kAudio_ParamError;
+
+ if (frameCount > source.sampleCount())
+ frameCount = source.sampleCount();
+
+ if (frameCount > m_sampleCapacity)
+ return kAudio_ParamError;
+
+ m_sampleCount = frameCount;
+
+ AudioBufferList& sourceBuffer = source.bufferList();
+ for (uint32_t i = 0; i < m_bufferList->mNumberBuffers; i++) {
+ switch (m_internalFormat->format()) {
+ case AudioStreamDescription::Int16: {
+ int16_t* destination = static_cast<int16_t*>(m_bufferList->mBuffers[i].mData);
+ int16_t* source = static_cast<int16_t*>(sourceBuffer.mBuffers[i].mData);
+ for (size_t i = 0; i < frameCount; i++)
+ destination[i] += source[i];
+ break;
+ }
+ case AudioStreamDescription::Int32: {
+ int32_t* destination = static_cast<int32_t*>(m_bufferList->mBuffers[i].mData);
+ vDSP_vaddi(destination, 1, reinterpret_cast<int32_t*>(sourceBuffer.mBuffers[i].mData), 1, destination, 1, frameCount);
+ break;
+ }
+ case AudioStreamDescription::Float32: {
+ float* destination = static_cast<float*>(m_bufferList->mBuffers[i].mData);
+ vDSP_vadd(destination, 1, reinterpret_cast<float*>(sourceBuffer.mBuffers[i].mData), 1, destination, 1, frameCount);
+ break;
+ }
+ case AudioStreamDescription::Float64: {
+ double* destination = static_cast<double*>(m_bufferList->mBuffers[i].mData);
+ vDSP_vaddD(destination, 1, reinterpret_cast<double*>(sourceBuffer.mBuffers[i].mData), 1, destination, 1, frameCount);
+ break;
+ }
+ case AudioStreamDescription::None:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ }
+
+ return 0;
+}
+
+OSStatus AudioSampleBufferList::copyFrom(const AudioSampleBufferList& source, size_t frameCount)
+{
+ ASSERT(source.streamDescription() == streamDescription());
+
+ if (source.streamDescription() != streamDescription())
+ return kAudio_ParamError;
+
+ if (frameCount > source.sampleCount())
+ frameCount = source.sampleCount();
+
+ if (frameCount > m_sampleCapacity)
+ return kAudio_ParamError;
+
+ m_sampleCount = frameCount;
+
+ for (uint32_t i = 0; i < m_bufferList->mNumberBuffers; i++) {
+ uint8_t* sourceData = static_cast<uint8_t*>(source.bufferList().mBuffers[i].mData);
+ uint8_t* destination = static_cast<uint8_t*>(m_bufferList->mBuffers[i].mData);
+ memcpy(destination, sourceData, frameCount * m_internalFormat->bytesPerPacket());
+ }
+
+ return 0;
+}
+
+OSStatus AudioSampleBufferList::copyTo(AudioBufferList& buffer, size_t frameCount)
+{
+ if (frameCount > m_sampleCount)
+ return kAudio_ParamError;
+ if (buffer.mNumberBuffers > m_bufferList->mNumberBuffers)
+ return kAudio_ParamError;
+
+ for (uint32_t i = 0; i < buffer.mNumberBuffers; i++) {
+ uint8_t* sourceData = static_cast<uint8_t*>(m_bufferList->mBuffers[i].mData);
+ uint8_t* destination = static_cast<uint8_t*>(buffer.mBuffers[i].mData);
+ memcpy(destination, sourceData, frameCount * m_internalFormat->bytesPerPacket());
+ }
+
+ return 0;
+}
+
+void AudioSampleBufferList::reset()
+{
+ m_sampleCount = 0;
+ m_timestamp = 0;
+ m_hostTime = -1;
+
+ uint8_t* data = reinterpret_cast<uint8_t*>(m_bufferList.get()) + m_bufferListBaseSize;
+ m_bufferList->mNumberBuffers = m_internalFormat->numberOfChannelStreams();
+ for (uint32_t i = 0; i < m_bufferList->mNumberBuffers; ++i) {
+ auto& buffer = m_bufferList->mBuffers[i];
+ buffer.mData = data;
+ buffer.mDataByteSize = m_maxBufferSizePerChannel;
+ buffer.mNumberChannels = m_internalFormat->numberOfInterleavedChannels();
+ data = data + m_maxBufferSizePerChannel;
+ }
+}
+
+void AudioSampleBufferList::zero()
+{
+ zeroABL(*m_bufferList, m_internalFormat->bytesPerPacket() * m_sampleCapacity);
+}
+
+void AudioSampleBufferList::zeroABL(AudioBufferList& buffer, size_t byteCount)
+{
+ for (uint32_t i = 0; i < buffer.mNumberBuffers; ++i)
+ memset(buffer.mBuffers[i].mData, 0, byteCount);
+}
+
+OSStatus AudioSampleBufferList::convertInput(UInt32* ioNumberDataPackets, AudioBufferList* ioData)
+{
+ if (!ioNumberDataPackets || !ioData || !m_converterInputBuffer) {
+ LOG_ERROR("AudioSampleBufferList::reconfigureInput(%p) invalid input to AudioConverterInput", this);
+ return kAudioConverterErr_UnspecifiedError;
+ }
+
+ size_t packetCount = m_converterInputBuffer->mBuffers[0].mDataByteSize / m_converterInputBytesPerPacket;
+ if (*ioNumberDataPackets > m_sampleCapacity) {
+ LOG_ERROR("AudioSampleBufferList::convertInput(%p) not enough internal storage: needed = %u, available = %lu", this, *ioNumberDataPackets, m_sampleCapacity);
+ return kAudioConverterErr_InvalidInputSize;
+ }
+
+ *ioNumberDataPackets = static_cast<UInt32>(packetCount);
+ for (uint32_t i = 0; i < ioData->mNumberBuffers; ++i) {
+ ioData->mBuffers[i].mData = m_converterInputBuffer->mBuffers[i].mData;
+ ioData->mBuffers[i].mDataByteSize = m_converterInputBuffer->mBuffers[i].mDataByteSize;
+ }
+
+ return 0;
+}
+
+OSStatus AudioSampleBufferList::audioConverterCallback(AudioConverterRef, UInt32* ioNumberDataPackets, AudioBufferList* ioData, AudioStreamPacketDescription**, void* inRefCon)
+{
+ return static_cast<AudioSampleBufferList*>(inRefCon)->convertInput(ioNumberDataPackets, ioData);
+}
+
+OSStatus AudioSampleBufferList::copyFrom(AudioBufferList& source, AudioConverterRef converter)
+{
+ reset();
+
+ AudioStreamBasicDescription inputFormat;
+ UInt32 propertyDataSize = sizeof(inputFormat);
+ AudioConverterGetProperty(converter, kAudioConverterCurrentInputStreamDescription, &propertyDataSize, &inputFormat);
+ m_converterInputBytesPerPacket = inputFormat.mBytesPerPacket;
+ m_converterInputBuffer = &source;
+
+ auto* outputData = m_bufferList.get();
+
+#if !LOG_DISABLED
+ AudioStreamBasicDescription outputFormat;
+ propertyDataSize = sizeof(outputFormat);
+ AudioConverterGetProperty(converter, kAudioConverterCurrentOutputStreamDescription, &propertyDataSize, &outputFormat);
+
+ ASSERT(outputFormat.mChannelsPerFrame == outputData->mNumberBuffers);
+ for (uint32_t i = 0; i < outputData->mNumberBuffers; ++i) {
+ ASSERT(outputData->mBuffers[i].mData);
+ ASSERT(outputData->mBuffers[i].mDataByteSize);
+ }
+#endif
+
+ UInt32 samplesConverted = static_cast<UInt32>(m_sampleCapacity);
+ OSStatus err = AudioConverterFillComplexBuffer(converter, audioConverterCallback, this, &samplesConverted, outputData, nullptr);
+ if (err) {
+ LOG_ERROR("AudioSampleBufferList::copyFrom(%p) AudioConverterFillComplexBuffer returned error %d (%.4s)", this, err, (char*)&err);
+ m_sampleCount = std::min(m_sampleCapacity, static_cast<size_t>(samplesConverted));
+ zero();
+ return err;
+ }
+
+ m_sampleCount = samplesConverted;
+ return 0;
+}
+
+OSStatus AudioSampleBufferList::copyFrom(AudioSampleBufferList& source, AudioConverterRef converter)
+{
+ return copyFrom(source.bufferList(), converter);
+}
+
+OSStatus AudioSampleBufferList::copyFrom(CARingBuffer& ringBuffer, size_t sampleCount, uint64_t startFrame, CARingBuffer::FetchMode mode)
+{
+ reset();
+ if (ringBuffer.fetch(&bufferList(), sampleCount, startFrame, mode) != CARingBuffer::Ok)
+ return kAudio_ParamError;
+
+ m_sampleCount = sampleCount;
+ return 0;
+}
+
+void AudioSampleBufferList::configureBufferListForStream(AudioBufferList& bufferList, const CAAudioStreamDescription& 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 < 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 "CARingBuffer.h"
+#include <CoreAudio/CoreAudioTypes.h>
+#include <wtf/Lock.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
+typedef struct OpaqueAudioConverter* AudioConverterRef;
+
+namespace WebCore {
+
+class AudioSampleBufferList : public RefCounted<AudioSampleBufferList> {
+public:
+ static Ref<AudioSampleBufferList> create(const CAAudioStreamDescription&, size_t);
+
+ ~AudioSampleBufferList();
+
+ static void configureBufferListForStream(AudioBufferList&, const CAAudioStreamDescription&, uint8_t*, size_t);
+ static inline size_t audioBufferListSizeForStream(const CAAudioStreamDescription&);
+
+ static void applyGain(AudioBufferList&, float, AudioStreamDescription::PCMFormat);
+ void applyGain(float);
+
+ OSStatus copyFrom(const AudioSampleBufferList&, size_t count = SIZE_MAX);
+ OSStatus copyFrom(AudioBufferList&, AudioConverterRef);
+ OSStatus copyFrom(AudioSampleBufferList&, AudioConverterRef);
+ OSStatus copyFrom(CARingBuffer&, size_t frameCount, uint64_t startFrame, CARingBuffer::FetchMode);
+
+ OSStatus mixFrom(const AudioSampleBufferList&, size_t count = SIZE_MAX);
+
+ OSStatus copyTo(AudioBufferList&, size_t count = SIZE_MAX);
+
+ const AudioStreamBasicDescription& streamDescription() const { return m_internalFormat->streamDescription(); }
+ AudioBufferList& 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&, size_t);
+ void zero();
+
+protected:
+ AudioSampleBufferList(const CAAudioStreamDescription&, size_t);
+
+ static OSStatus audioConverterCallback(AudioConverterRef, UInt32*, AudioBufferList*, AudioStreamPacketDescription**, void*);
+ OSStatus convertInput(UInt32*, AudioBufferList*);
+
+ std::unique_ptr<CAAudioStreamDescription> 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<AudioBufferList> m_bufferList;
+};
+
+inline size_t AudioSampleBufferList::audioBufferListSizeForStream(const CAAudioStreamDescription& description)
+{
+ return offsetof(AudioBufferList, mBuffers) + (sizeof(AudioBuffer) * std::max<uint32_t>(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 "config.h"
+#include "AudioSampleDataSource.h"
+
+#if ENABLE(MEDIA_STREAM)
+
+#include "CAAudioStreamDescription.h"
+#include "CARingBuffer.h"
+#include "Logging.h"
+#include "MediaTimeAVFoundation.h"
+#include <AudioToolbox/AudioConverter.h>
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+#include <mutex>
+#include <syslog.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/StringPrintStream.h>
+
+#include "CoreMediaSoftLink.h"
+
+namespace WebCore {
+
+using namespace JSC;
+
+Ref<AudioSampleDataSource> 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<Lock> lock(m_lock);
+
+ if (paused == m_paused)
+ return;
+
+ m_transitioningFromPaused = m_paused;
+ m_paused = paused;
+}
+
+OSStatus AudioSampleDataSource::setupConverter()
+{
+ ASSERT(m_inputDescription && m_outputDescription);
+
+ if (m_converter) {
+ AudioConverterDispose(m_converter);
+ m_converter = nullptr;
+ }
+
+ if (*m_inputDescription == *m_outputDescription)
+ return 0;
+
+ OSStatus err = AudioConverterNew(&m_inputDescription->streamDescription(), &m_outputDescription->streamDescription(), &m_converter);
+ if (err)
+ LOG_ERROR("AudioSampleDataSource::setupConverter(%p) - AudioConverterNew returned error %d (%.4s)", this, err, (char*)&err);
+
+ return err;
+
+}
+
+OSStatus AudioSampleDataSource::setInputFormat(const CAAudioStreamDescription& format)
+{
+ ASSERT(format.sampleRate() >= 0);
+
+ m_inputDescription = std::make_unique<CAAudioStreamDescription>(format);
+ if (m_outputDescription)
+ return setupConverter();
+
+ return 0;
+}
+
+OSStatus AudioSampleDataSource::setOutputFormat(const CAAudioStreamDescription& format)
+{
+ ASSERT(m_inputDescription);
+ ASSERT(format.sampleRate() >= 0);
+
+ m_outputDescription = std::make_unique<CAAudioStreamDescription>(format);
+ if (!m_ringBuffer)
+ m_ringBuffer = std::make_unique<CARingBuffer>();
+
+ m_ringBuffer->allocate(format, static_cast<size_t>(m_maximumSampleCount));
+ m_scratchBuffer = AudioSampleBufferList::create(m_outputDescription->streamDescription(), m_maximumSampleCount);
+
+ return setupConverter();
+}
+
+MediaTime AudioSampleDataSource::hostTime() const
+{
+ // Based on listing #2 from Apple Technical Q&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(&timebaseInfo);
+ frequency = 1e-9 * static_cast<double>(timebaseInfo.numer) / static_cast<double>(timebaseInfo.denom);
+ ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
+ ASSERT(timebaseInfo.denom);
+ });
+
+ return MediaTime::createWithDouble(mach_absolute_time() * frequency);
+}
+
+void AudioSampleDataSource::pushSamplesInternal(AudioBufferList& bufferList, const MediaTime& presentationTime, size_t sampleCount)
+{
+ ASSERT(m_lock.isHeld());
+
+ AudioBufferList* sampleBufferList;
+ if (m_converter) {
+ m_scratchBuffer->reset();
+ OSStatus err = m_scratchBuffer->copyFrom(bufferList, m_converter);
+ if (err)
+ return;
+
+ sampleBufferList = &m_scratchBuffer->bufferList();
+ } else
+ sampleBufferList = &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, "@@ pushSamples: input sample offset is %lld, m_maximumSampleCount = %zu", m_inputSampleOffset.timeValue(), m_maximumSampleCount);
+ }
+ sampleTime += m_inputSampleOffset;
+
+#if !LOG_DISABLED
+ uint64_t startFrame1 = 0;
+ uint64_t endFrame1 = 0;
+ m_ringBuffer->getCurrentFrameBounds(startFrame1, endFrame1);
+#endif
+
+ m_ringBuffer->store(sampleBufferList, sampleCount, sampleTime.timeValue());
+ m_timeStamp = sampleTime.timeValue();
+
+ LOG(MediaCaptureSamples, "@@ pushSamples: added %ld samples for time = %s (was %s), mach time = %lld", 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->getCurrentFrameBounds(startFrame2, endFrame2);
+ LOG(MediaCaptureSamples, "@@ pushSamples: buffered range was [%lld .. %lld], is [%lld .. %lld]", startFrame1, endFrame1, startFrame2, endFrame2);
+#endif
+}
+
+void AudioSampleDataSource::pushSamples(const AudioStreamBasicDescription& sampleDescription, CMSampleBufferRef sampleBuffer)
+{
+ std::lock_guard<Lock> 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<AudioBufferList*>(bufferData);
+ bufferList->mNumberBuffers = m_inputDescription->numberOfInterleavedChannels();
+
+ CMBlockBufferRef buffer = nullptr;
+ OSStatus err = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, nullptr, bufferList, bufferSize, kCFAllocatorSystemDefault, kCFAllocatorSystemDefault, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &buffer);
+ if (err) {
+ LOG_ERROR("AudioSampleDataSource::pushSamples(%p) - CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer returned error %d (%.4s)", this, err, (char*)&err);
+ return;
+ }
+
+ pushSamplesInternal(*bufferList, toMediaTime(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)), CMSampleBufferGetNumSamples(sampleBuffer));
+}
+
+void AudioSampleDataSource::pushSamples(const AudioStreamBasicDescription& sampleDescription, const MediaTime& sampleTime, void* audioData, size_t sampleCount)
+{
+ std::unique_lock<Lock> 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<AudioBufferList*>(bufferData);
+
+ AudioSampleBufferList::configureBufferListForStream(*bufferList, description, reinterpret_cast<uint8_t*>(audioData), sampleCount);
+ pushSamplesInternal(*bufferList, sampleTime, sampleCount);
+}
+
+bool AudioSampleDataSource::pullSamplesInternal(AudioBufferList& buffer, size_t& sampleCount, uint64_t timeStamp, double /*hostTime*/, PullMode mode)
+{
+ ASSERT(m_lock.isHeld());
+
+ ASSERT(buffer.mNumberBuffers == m_ringBuffer->channelCount());
+ if (buffer.mNumberBuffers != m_ringBuffer->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->getCurrentFrameBounds(startFrame, endFrame);
+
+ if (m_transitioningFromPaused) {
+ uint64_t buffered = endFrame - m_timeStamp;
+ if (buffered < 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->sampleRate();
+ if (buffered > sampleRate * twentyMS)
+ m_outputSampleOffset = m_timeStamp - sampleRate * twentyMS;
+ else if (buffered > sampleRate * tenMS)
+ m_outputSampleOffset = m_timeStamp - sampleRate * tenMS;
+ else if (buffered > sampleRate * fiveMS)
+ m_outputSampleOffset = m_timeStamp - sampleRate * fiveMS;
+ else
+ m_outputSampleOffset = m_timeStamp;
+
+ m_transitioningFromPaused = false;
+ }
+
+ timeStamp += m_outputSampleOffset;
+
+ LOG(MediaCaptureSamples, "** pullSamples: asking for %ld samples at time = %lld (was %lld)", sampleCount, timeStamp, timeStamp - m_outputSampleOffset);
+
+ int64_t framesAvailable = sampleCount;
+ if (timeStamp < startFrame || timeStamp + sampleCount > endFrame) {
+ if (timeStamp + sampleCount < startFrame || timeStamp > endFrame)
+ framesAvailable = 0;
+ else if (timeStamp < startFrame)
+ framesAvailable = timeStamp + sampleCount - startFrame;
+ else
+ framesAvailable = timeStamp + sampleCount - endFrame;
+
+ LOG(MediaCaptureSamples, "** pullSamplesInternal: sample %lld is not completely in range [%lld .. %lld], returning %lld frames", timeStamp, startFrame, endFrame, framesAvailable);
+
+ if (!framesAvailable) {
+ AudioSampleBufferList::zeroABL(buffer, sampleCount);
+ return false;
+ }
+ }
+
+ if (m_volume >= .95) {
+ m_ringBuffer->fetch(&buffer, sampleCount, timeStamp, mode == Copy ? CARingBuffer::Copy : CARingBuffer::Mix);
+ return true;
+ }
+
+ if (m_scratchBuffer->copyFrom(*m_ringBuffer.get(), sampleCount, timeStamp, mode == Copy ? CARingBuffer::Copy : CARingBuffer::Mix)) {
+ AudioSampleBufferList::zeroABL(buffer, sampleCount);
+ return false;
+ }
+
+ m_scratchBuffer->applyGain(m_volume);
+ if (m_scratchBuffer->copyTo(buffer, sampleCount))
+ AudioSampleBufferList::zeroABL(buffer, sampleCount);
+
+ return true;
+}
+
+bool AudioSampleDataSource::pullSamples(AudioBufferList& buffer, size_t sampleCount, uint64_t timeStamp, double hostTime, PullMode mode)
+{
+ std::unique_lock<Lock> 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& buffer, size_t sampleCount, uint64_t timeStamp, double hostTime, PullMode mode)
+{
+ std::unique_lock<Lock> 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 "AudioSampleBufferList.h"
+#include <CoreAudio/CoreAudioTypes.h>
+#include <wtf/Lock.h>
+#include <wtf/MediaTime.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+#include <wtf/text/WTFString.h>
+
+typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
+typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
+
+namespace WebCore {
+
+class CAAudioStreamDescription;
+class CARingBuffer;
+
+class AudioSampleDataSource : public RefCounted<AudioSampleDataSource> {
+public:
+ static Ref<AudioSampleDataSource> create(size_t);
+
+ ~AudioSampleDataSource();
+
+ OSStatus setInputFormat(const CAAudioStreamDescription&);
+ OSStatus setOutputFormat(const CAAudioStreamDescription&);
+
+ void pushSamples(const AudioStreamBasicDescription&, const MediaTime&, void*, size_t);
+ void pushSamples(const AudioStreamBasicDescription&, CMSampleBufferRef);
+
+ enum PullMode { Copy, Mix };
+ bool pullSamples(AudioSampleBufferList&, size_t, uint64_t, double, PullMode);
+ bool pullSamples(AudioBufferList&, 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&, size_t&, uint64_t, double, PullMode);
+
+ void pushSamplesInternal(AudioBufferList&, const MediaTime&, size_t frameCount);
+
+ std::unique_ptr<CAAudioStreamDescription> m_inputDescription;
+ std::unique_ptr<CAAudioStreamDescription> 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<AudioSampleBufferList> m_scratchBuffer;
+
+ std::unique_ptr<CARingBuffer> 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>