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