Title: [223412] trunk/Source/WebCore
Revision
223412
Author
[email protected]
Date
2017-10-16 09:40:48 -0700 (Mon, 16 Oct 2017)

Log Message

Make RealtimeIncomingAudioSources and RealtimeOutgoingAudioSources port agnostic
https://bugs.webkit.org/show_bug.cgi?id=177928

Patch by Alejandro G. Castro <[email protected]> on 2017-10-16
Reviewed by Youenn Fablet.

Refactor the RealtimeIncomingAudioSource and RealtimeOutgoingAudioSource classes,
move the mac specific code to a different class. This way we can use them from
other ports.

No new tests, we are not adding new functionality just refactoring.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/mediastream/RealtimeIncomingAudioSource.cpp: Copied from Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h. Just the port agnostic parts.
* platform/mediastream/RealtimeIncomingAudioSource.h: Copied from Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h. Ditto.
* platform/mediastream/RealtimeOutgoingAudioSource.cpp: Copied from Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp. Ditto.
* platform/mediastream/RealtimeOutgoingAudioSource.h: Copied from Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h. Ditto.
* platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp: Added, it adds Cocoa code parts from original Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp.
(WebCore::RealtimeIncomingAudioSource::create): Moved this function from the RealtimeOutgoingAudioSource.cpp file to avoid including the Cocoa file there.
* platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h: Added Cocoa code from original Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h.
* platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp: Added Cocoa code from original Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp.
(WebCore::RealtimeOutgoingAudioSource::create): Moved this function from the RealtimeOutgoingAudioSource.cpp file to avoid including the Cocoa file there.
* platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.h: Added Cocoa code from the original Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (223411 => 223412)


--- trunk/Source/WebCore/CMakeLists.txt	2017-10-16 16:38:15 UTC (rev 223411)
+++ trunk/Source/WebCore/CMakeLists.txt	2017-10-16 16:40:48 UTC (rev 223412)
@@ -2539,10 +2539,12 @@
     platform/mediastream/RealtimeMediaSourceSupportedConstraints.cpp
     platform/mediastream/RTCIceCandidateDescriptor.cpp
     platform/mediastream/RTCSessionDescriptionDescriptor.cpp
+    platform/mediastream/RealtimeIncomingAudioSource.cpp
     platform/mediastream/RealtimeIncomingVideoSource.cpp
     platform/mediastream/RealtimeMediaSource.cpp
     platform/mediastream/RealtimeMediaSourceCenter.cpp
     platform/mediastream/RealtimeMediaSourceSettings.cpp
+    platform/mediastream/RealtimeOutgoingAudioSource.cpp
     platform/mediastream/RealtimeOutgoingVideoSource.cpp
 
     platform/mediastream/libwebrtc/LibWebRTCProvider.cpp

Modified: trunk/Source/WebCore/ChangeLog (223411 => 223412)


--- trunk/Source/WebCore/ChangeLog	2017-10-16 16:38:15 UTC (rev 223411)
+++ trunk/Source/WebCore/ChangeLog	2017-10-16 16:40:48 UTC (rev 223412)
@@ -1,3 +1,29 @@
+2017-10-16  Alejandro G. Castro  <[email protected]>
+
+        Make RealtimeIncomingAudioSources and RealtimeOutgoingAudioSources port agnostic
+        https://bugs.webkit.org/show_bug.cgi?id=177928
+
+        Reviewed by Youenn Fablet.
+
+        Refactor the RealtimeIncomingAudioSource and RealtimeOutgoingAudioSource classes,
+        move the mac specific code to a different class. This way we can use them from
+        other ports.
+
+        No new tests, we are not adding new functionality just refactoring.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/mediastream/RealtimeIncomingAudioSource.cpp: Copied from Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h. Just the port agnostic parts.
+        * platform/mediastream/RealtimeIncomingAudioSource.h: Copied from Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h. Ditto.
+        * platform/mediastream/RealtimeOutgoingAudioSource.cpp: Copied from Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp. Ditto.
+        * platform/mediastream/RealtimeOutgoingAudioSource.h: Copied from Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h. Ditto.
+        * platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp: Added, it adds Cocoa code parts from original Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp.
+        (WebCore::RealtimeIncomingAudioSource::create): Moved this function from the RealtimeOutgoingAudioSource.cpp file to avoid including the Cocoa file there.
+        * platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h: Added Cocoa code from original Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h.
+        * platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp: Added Cocoa code from original Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp.
+        (WebCore::RealtimeOutgoingAudioSource::create): Moved this function from the RealtimeOutgoingAudioSource.cpp file to avoid including the Cocoa file there.
+        * platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.h: Added Cocoa code from the original Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h.
+
 2017-10-16  Wenson Hsieh  <[email protected]>
 
         Unreviewed, fix the tvOS build after r223340.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (223411 => 223412)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-10-16 16:38:15 UTC (rev 223411)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-10-16 16:40:48 UTC (rev 223412)
@@ -1675,8 +1675,12 @@
 		410B7E721045FAB000D8224F /* JSMessageEventCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */; };
 		41103AAB1E39791000769F03 /* RealtimeOutgoingAudioSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AA71E39790A00769F03 /* RealtimeOutgoingAudioSource.cpp */; };
 		41103AAC1E39791000769F03 /* RealtimeOutgoingAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 41103AA81E39790A00769F03 /* RealtimeOutgoingAudioSource.h */; };
+		41103AAB1E39791000769F14 /* RealtimeOutgoingAudioSourceCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AA71E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.cpp */; };
+		41103AAC1E39791000769F14 /* RealtimeOutgoingAudioSourceCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 41103AA81E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.h */; };
 		41103AAD1E39791000769F03 /* RealtimeIncomingAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 41103AA91E39790A00769F03 /* RealtimeIncomingAudioSource.h */; };
 		41103AAE1E39791000769F03 /* RealtimeIncomingAudioSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */; };
+		41103AAD1E39791000769F14 /* RealtimeIncomingAudioSourceCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 41103AA91E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.h */; };
+		41103AAE1E39791000769F14 /* RealtimeIncomingAudioSourceCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AAA1E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.cpp */; };
 		4123081B138C429700BCCFCA /* WebCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F19B1A08245E5A001E9ABC /* WebCore.framework */; };
 		41230913138C42FF00BCCFCA /* _javascript_Core.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8216299029F4FB501000131 /* _javascript_Core.framework */; };
 		4127D5370F8AAB1D00E424F5 /* ScriptState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */; };
@@ -9473,8 +9477,12 @@
 		410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMessageEventCustom.cpp; sourceTree = "<group>"; };
 		41103AA71E39790A00769F03 /* RealtimeOutgoingAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeOutgoingAudioSource.cpp; sourceTree = "<group>"; };
 		41103AA81E39790A00769F03 /* RealtimeOutgoingAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeOutgoingAudioSource.h; sourceTree = "<group>"; };
+		41103AA71E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeOutgoingAudioSourceCocoa.cpp; sourceTree = "<group>"; };
+		41103AA81E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeOutgoingAudioSourceCocoa.h; sourceTree = "<group>"; };
 		41103AA91E39790A00769F03 /* RealtimeIncomingAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeIncomingAudioSource.h; sourceTree = "<group>"; };
 		41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingAudioSource.cpp; sourceTree = "<group>"; };
+		41103AA91E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeIncomingAudioSourceCocoa.h; sourceTree = "<group>"; };
+		41103AAA1E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingAudioSourceCocoa.cpp; sourceTree = "<group>"; };
 		41189EF71AD8232800B90A0D /* ReadableStreamDefaultController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamDefaultController.idl; sourceTree = "<group>"; };
 		41189EF71AD8232800B93F64 /* ReadableByteStreamController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableByteStreamController.idl; sourceTree = "<group>"; };
 		41189EF71AD8232800B95672 /* ReadableStreamBYOBRequest.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamBYOBRequest.idl; sourceTree = "<group>"; };
@@ -16564,6 +16572,8 @@
 				07FFDE66181AED420072D409 /* MediaStreamTrackPrivate.cpp */,
 				07FFDE67181AED420072D409 /* MediaStreamTrackPrivate.h */,
 				5EBB89381C77BDA400C65D41 /* PeerMediaDescription.h */,
+				41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */,
+				41103AA91E39790A00769F03 /* RealtimeIncomingAudioSource.h */,
 				5CDD83391E4324BB00621E92 /* RealtimeIncomingVideoSource.cpp */,
 				5CDD833A1E4324BB00621E92 /* RealtimeIncomingVideoSource.h */,
 				4A4F656B1AA997F100E38CDD /* RealtimeMediaSource.cpp */,
@@ -16575,6 +16585,8 @@
 				4A4F656F1AA997F100E38CDD /* RealtimeMediaSourceSettings.h */,
 				2EC41DE21C0410A300D294FE /* RealtimeMediaSourceSupportedConstraints.cpp */,
 				07C1C0E41BFB60ED00BD2256 /* RealtimeMediaSourceSupportedConstraints.h */,
+				41103AA71E39790A00769F03 /* RealtimeOutgoingAudioSource.cpp */,
+				41103AA81E39790A00769F03 /* RealtimeOutgoingAudioSource.h */,
 				5CDD833B1E4324BB00621E92 /* RealtimeOutgoingVideoSource.cpp */,
 				5CDD833C1E4324BB00621E92 /* RealtimeOutgoingVideoSource.h */,
 				3135910C1E7DDCB600F30630 /* RTCBundlePolicy.h */,
@@ -16627,6 +16639,8 @@
 				07EE76EE1BEA619800F89133 /* MockRealtimeVideoSourceMac.mm */,
 				41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */,
 				41103AA91E39790A00769F03 /* RealtimeIncomingAudioSource.h */,
+				41103AAA1E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.cpp */,
+				41103AA91E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.h */,
 				5CDD83391E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.cpp */,
 				5CDD833A1E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.h */,
 				4A0FFAA31AAF5EF60062803B /* RealtimeMediaSourceCenterMac.cpp */,
@@ -16633,6 +16647,8 @@
 				4A0FFAA41AAF5EF60062803B /* RealtimeMediaSourceCenterMac.h */,
 				41103AA71E39790A00769F03 /* RealtimeOutgoingAudioSource.cpp */,
 				41103AA81E39790A00769F03 /* RealtimeOutgoingAudioSource.h */,
+				41103AA71E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.cpp */,
+				41103AA81E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.h */,
 				5CDD833B1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.cpp */,
 				5CDD833C1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.h */,
 				07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h */,
@@ -29772,6 +29788,7 @@
 				4129C9AB1F59C573009D7403 /* ReadableStreamSource.h in Headers */,
 				FD31603C12B0267600C1A359 /* RealtimeAnalyser.h in Headers */,
 				41103AAD1E39791000769F03 /* RealtimeIncomingAudioSource.h in Headers */,
+				41103AAD1E39791000769F14 /* RealtimeIncomingAudioSourceCocoa.h in Headers */,
 				4A4F65711AA997F100E38CDD /* RealtimeMediaSource.h in Headers */,
 				4A4F65721AA997F100E38CDD /* RealtimeMediaSourceCapabilities.h in Headers */,
 				4A0FFAA21AAF5EA20062803B /* RealtimeMediaSourceCenter.h in Headers */,
@@ -29779,6 +29796,7 @@
 				4A4F65741AA997F100E38CDD /* RealtimeMediaSourceSettings.h in Headers */,
 				07C1C0E51BFB60ED00BD2256 /* RealtimeMediaSourceSupportedConstraints.h in Headers */,
 				41103AAC1E39791000769F03 /* RealtimeOutgoingAudioSource.h in Headers */,
+				41103AAC1E39791000769F14 /* RealtimeOutgoingAudioSourceCocoa.h in Headers */,
 				91B952241F58A58F00931DC2 /* RecordingSwizzleTypes.h in Headers */,
 				BC4368E80C226E32005EFB5F /* Rect.h in Headers */,
 				FD45A958175D414C00C21EC8 /* RectangleShape.h in Headers */,
@@ -33752,6 +33770,7 @@
 				4129C98A1F587FEB009D7403 /* ReadableStreamSink.cpp in Sources */,
 				FD31603B12B0267600C1A359 /* RealtimeAnalyser.cpp in Sources */,
 				41103AAE1E39791000769F03 /* RealtimeIncomingAudioSource.cpp in Sources */,
+				41103AAE1E39791000769F14 /* RealtimeIncomingAudioSourceCocoa.cpp in Sources */,
 				5CDD833E1E4324DC00621E92 /* RealtimeIncomingVideoSource.cpp in Sources */,
 				5CDD833E1E4324DC00621E83 /* RealtimeIncomingVideoSourceCocoa.cpp in Sources */,
 				4A4F65701AA997F100E38CDD /* RealtimeMediaSource.cpp in Sources */,
@@ -33760,6 +33779,7 @@
 				4A4F65731AA997F100E38CDD /* RealtimeMediaSourceSettings.cpp in Sources */,
 				2EC41DE41C0410A300D294FE /* RealtimeMediaSourceSupportedConstraints.cpp in Sources */,
 				41103AAB1E39791000769F03 /* RealtimeOutgoingAudioSource.cpp in Sources */,
+				41103AAB1E39791000769F14 /* RealtimeOutgoingAudioSourceCocoa.cpp in Sources */,
 				5CDD833D1E4324D900621E92 /* RealtimeOutgoingVideoSource.cpp in Sources */,
 				5CDD833D1E4324D900621B83 /* RealtimeOutgoingVideoSourceCocoa.cpp in Sources */,
 				FD45A95A175D417100C21EC8 /* RectangleShape.cpp in Sources */,

Copied: trunk/Source/WebCore/platform/mediastream/RealtimeIncomingAudioSource.cpp (from rev 223411, trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h) (0 => 223412)


--- trunk/Source/WebCore/platform/mediastream/RealtimeIncomingAudioSource.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeIncomingAudioSource.cpp	2017-10-16 16:40:48 UTC (rev 223412)
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ * 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.
+ */
+
+#include "config.h"
+#include "RealtimeIncomingAudioSource.h"
+
+#if USE(LIBWEBRTC)
+
+#include "LibWebRTCAudioFormat.h"
+
+namespace WebCore {
+
+RealtimeIncomingAudioSource::RealtimeIncomingAudioSource(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
+    : RealtimeMediaSource(WTFMove(audioTrackId), RealtimeMediaSource::Type::Audio, String())
+    , m_audioTrack(WTFMove(audioTrack))
+{
+    notifyMutedChange(!m_audioTrack);
+}
+
+RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource()
+{
+    stop();
+}
+
+void RealtimeIncomingAudioSource::startProducingData()
+{
+    if (m_audioTrack)
+        m_audioTrack->AddSink(this);
+}
+
+void RealtimeIncomingAudioSource::stopProducingData()
+{
+    if (m_audioTrack)
+        m_audioTrack->RemoveSink(this);
+}
+
+void RealtimeIncomingAudioSource::setSourceTrack(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& track)
+{
+    ASSERT(!m_audioTrack);
+    ASSERT(track);
+
+    m_audioTrack = WTFMove(track);
+    notifyMutedChange(!m_audioTrack);
+    if (isProducingData())
+        m_audioTrack->AddSink(this);
+}
+
+const RealtimeMediaSourceCapabilities& RealtimeIncomingAudioSource::capabilities() const
+{
+    return RealtimeMediaSourceCapabilities::emptyCapabilities();
+}
+
+const RealtimeMediaSourceSettings& RealtimeIncomingAudioSource::settings() const
+{
+    return m_currentSettings;
+}
+
+}
+
+#endif // USE(LIBWEBRTC)

Copied: trunk/Source/WebCore/platform/mediastream/RealtimeIncomingAudioSource.h (from rev 223411, trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h) (0 => 223412)


--- trunk/Source/WebCore/platform/mediastream/RealtimeIncomingAudioSource.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeIncomingAudioSource.h	2017-10-16 16:40:48 UTC (rev 223412)
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ * 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 USE(LIBWEBRTC)
+
+#include "LibWebRTCMacros.h"
+#include "RealtimeMediaSource.h"
+#include <webrtc/api/mediastreaminterface.h>
+#include <wtf/RetainPtr.h>
+
+namespace WebCore {
+
+class RealtimeIncomingAudioSource : public RealtimeMediaSource, private webrtc::AudioTrackSinkInterface {
+public:
+    static Ref<RealtimeIncomingAudioSource> create(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&, String&&);
+
+    void setSourceTrack(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&);
+
+protected:
+    RealtimeIncomingAudioSource(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&, String&&);
+    ~RealtimeIncomingAudioSource();
+
+private:
+    // webrtc::AudioTrackSinkInterface API
+    virtual void OnData(const void* /* audioData */, int /* bitsPerSample */, int /* sampleRate */, size_t /* numberOfChannels */, size_t /* numberOfFrames */) { };
+
+    // RealtimeMediaSource API
+    void startProducingData() final;
+    void stopProducingData()  final;
+
+    const RealtimeMediaSourceCapabilities& capabilities() const final;
+    const RealtimeMediaSourceSettings& settings() const final;
+
+    RealtimeMediaSourceSettings m_currentSettings;
+    rtc::scoped_refptr<webrtc::AudioTrackInterface> m_audioTrack;
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)

Added: trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingAudioSource.cpp (0 => 223412)


--- trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingAudioSource.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingAudioSource.cpp	2017-10-16 16:40:48 UTC (rev 223412)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2017 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be 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 Apple 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 APPLE INC. AND ITS 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 APPLE INC. AND ITS 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 "RealtimeOutgoingAudioSource.h"
+
+#if USE(LIBWEBRTC)
+
+#include "LibWebRTCAudioFormat.h"
+#include "LibWebRTCProvider.h"
+
+namespace WebCore {
+
+RealtimeOutgoingAudioSource::RealtimeOutgoingAudioSource(Ref<MediaStreamTrackPrivate>&& audioSource)
+    : m_audioSource(WTFMove(audioSource))
+    , m_silenceAudioTimer(*this, &RealtimeOutgoingAudioSource::sendSilence)
+{
+    m_audioSource->addObserver(*this);
+    initializeConverter();
+}
+
+bool RealtimeOutgoingAudioSource::setSource(Ref<MediaStreamTrackPrivate>&& newSource)
+{
+    m_audioSource->removeObserver(*this);
+    m_audioSource = WTFMove(newSource);
+    m_audioSource->addObserver(*this);
+
+    initializeConverter();
+    return true;
+}
+
+void RealtimeOutgoingAudioSource::initializeConverter()
+{
+    m_muted = m_audioSource->muted();
+    m_enabled = m_audioSource->enabled();
+    handleMutedIfNeeded();
+}
+
+void RealtimeOutgoingAudioSource::stop()
+{
+    m_silenceAudioTimer.stop();
+    m_audioSource->removeObserver(*this);
+}
+
+void RealtimeOutgoingAudioSource::sourceMutedChanged()
+{
+    m_muted = m_audioSource->muted();
+    handleMutedIfNeeded();
+}
+
+void RealtimeOutgoingAudioSource::sourceEnabledChanged()
+{
+    m_enabled = m_audioSource->enabled();
+    handleMutedIfNeeded();
+}
+
+void RealtimeOutgoingAudioSource::handleMutedIfNeeded()
+{
+    bool isSilenced = m_muted || !m_enabled;
+    if (isSilenced && !m_silenceAudioTimer.isActive())
+        m_silenceAudioTimer.startRepeating(1_s);
+    if (!isSilenced && m_silenceAudioTimer.isActive())
+        m_silenceAudioTimer.stop();
+}
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)

Copied: trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingAudioSource.h (from rev 223411, trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h) (0 => 223412)


--- trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingAudioSource.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingAudioSource.h	2017-10-16 16:40:48 UTC (rev 223412)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2017 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be 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 Apple 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 APPLE INC. AND ITS 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 APPLE INC. AND ITS 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 USE(LIBWEBRTC)
+
+#include "LibWebRTCMacros.h"
+#include "MediaStreamTrackPrivate.h"
+#include "Timer.h"
+#include <webrtc/api/mediastreaminterface.h>
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace webrtc {
+class AudioTrackInterface;
+class AudioTrackSinkInterface;
+}
+
+namespace WebCore {
+
+class RealtimeOutgoingAudioSource : public ThreadSafeRefCounted<RealtimeOutgoingAudioSource>, public webrtc::AudioSourceInterface, private MediaStreamTrackPrivate::Observer {
+public:
+    static Ref<RealtimeOutgoingAudioSource> create(Ref<MediaStreamTrackPrivate>&& audioSource);
+
+    ~RealtimeOutgoingAudioSource() { stop(); }
+
+    void stop();
+
+    bool setSource(Ref<MediaStreamTrackPrivate>&&);
+    MediaStreamTrackPrivate& source() const { return m_audioSource.get(); }
+
+protected:
+    explicit RealtimeOutgoingAudioSource(Ref<MediaStreamTrackPrivate>&&);
+
+    virtual void handleMutedIfNeeded();
+    virtual void sendSilence() { };
+    virtual void pullAudioData() { };
+
+    Vector<webrtc::AudioTrackSinkInterface*> m_sinks;
+    bool m_muted { false };
+    bool m_enabled { true };
+
+private:
+    virtual void AddSink(webrtc::AudioTrackSinkInterface* sink) { m_sinks.append(sink); }
+    virtual void RemoveSink(webrtc::AudioTrackSinkInterface* sink) { m_sinks.removeFirst(sink); }
+
+    int AddRef() const final { ref(); return refCount(); }
+    int Release() const final { deref(); return refCount(); }
+    SourceState state() const final { return kLive; }
+    bool remote() const final { return false; }
+    void RegisterObserver(webrtc::ObserverInterface*) final { }
+    void UnregisterObserver(webrtc::ObserverInterface*) final { }
+
+    void sourceMutedChanged();
+    void sourceEnabledChanged();
+    virtual void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) { };
+
+    virtual bool isReachingBufferedAudioDataHighLimit() { return false; };
+    virtual bool isReachingBufferedAudioDataLowLimit() { return false; };
+    virtual bool hasBufferedEnoughData() { return false; };
+
+    // MediaStreamTrackPrivate::Observer API
+    void trackMutedChanged(MediaStreamTrackPrivate&) final { sourceMutedChanged(); }
+    void trackEnabledChanged(MediaStreamTrackPrivate&) final { sourceEnabledChanged(); }
+    void audioSamplesAvailable(MediaStreamTrackPrivate&, const MediaTime& mediaTime, const PlatformAudioData& data, const AudioStreamDescription& description, size_t sampleCount) { audioSamplesAvailable(mediaTime, data, description, sampleCount); }
+    void trackEnded(MediaStreamTrackPrivate&) final { }
+    void trackSettingsChanged(MediaStreamTrackPrivate&) final { }
+
+    void initializeConverter();
+
+    Ref<MediaStreamTrackPrivate> m_audioSource;
+
+    Timer m_silenceAudioTimer;
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)

Deleted: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp (223411 => 223412)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp	2017-10-16 16:38:15 UTC (rev 223411)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp	2017-10-16 16:40:48 UTC (rev 223412)
@@ -1,140 +0,0 @@
-/*
- * 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.
- * 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.
- */
-
-#include "config.h"
-#include "RealtimeIncomingAudioSource.h"
-
-#if USE(LIBWEBRTC)
-
-#include "AudioStreamDescription.h"
-#include "CAAudioStreamDescription.h"
-#include "LibWebRTCAudioFormat.h"
-#include "WebAudioBufferList.h"
-#include "WebAudioSourceProviderAVFObjC.h"
-#include <pal/avfoundation/MediaTimeAVFoundation.h>
-
-#include "CoreMediaSoftLink.h"
-
-namespace WebCore {
-
-Ref<RealtimeIncomingAudioSource> RealtimeIncomingAudioSource::create(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
-{
-    auto source = adoptRef(*new RealtimeIncomingAudioSource(WTFMove(audioTrack), WTFMove(audioTrackId)));
-    source->start();
-    return source;
-}
-
-RealtimeIncomingAudioSource::RealtimeIncomingAudioSource(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
-    : RealtimeMediaSource(WTFMove(audioTrackId), RealtimeMediaSource::Type::Audio, String())
-    , m_audioTrack(WTFMove(audioTrack))
-{
-    notifyMutedChange(!m_audioTrack);
-}
-
-RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource()
-{
-    stop();
-}
-
-
-static inline AudioStreamBasicDescription streamDescription(size_t sampleRate, size_t channelCount)
-{
-    AudioStreamBasicDescription streamFormat;
-    FillOutASBDForLPCM(streamFormat, sampleRate, channelCount, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::isFloat, LibWebRTCAudioFormat::isBigEndian, LibWebRTCAudioFormat::isNonInterleaved);
-    return streamFormat;
-}
-
-void RealtimeIncomingAudioSource::OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames)
-{
-    // We may receive OnData calls with empty sound data (mono, samples equal to zero and sampleRate equal to 16000) when starting the call.
-    // FIXME: For the moment we skip them, we should find a better solution at libwebrtc level to not be called until getting some real data.
-    if (sampleRate == 16000 && numberOfChannels == 1)
-        return;
-
-    ASSERT(bitsPerSample == 16);
-    ASSERT(numberOfChannels == 1 || numberOfChannels == 2);
-    ASSERT(sampleRate == 48000);
-
-    CMTime startTime = CMTimeMake(m_numberOfFrames, sampleRate);
-    auto mediaTime = PAL::toMediaTime(startTime);
-    m_numberOfFrames += numberOfFrames;
-
-    AudioStreamBasicDescription newDescription = streamDescription(sampleRate, numberOfChannels);
-
-    // FIXME: We should not need to do the extra memory allocation and copy.
-    // Instead, we should be able to directly pass audioData pointer.
-    WebAudioBufferList audioBufferList { CAAudioStreamDescription(newDescription), WTF::safeCast<uint32_t>(numberOfFrames) };
-    audioBufferList.buffer(0)->mDataByteSize = numberOfChannels * numberOfFrames * bitsPerSample / 8;
-    audioBufferList.buffer(0)->mNumberChannels = numberOfChannels;
-
-    if (muted())
-        memset(audioBufferList.buffer(0)->mData, 0, audioBufferList.buffer(0)->mDataByteSize);
-    else
-        memcpy(audioBufferList.buffer(0)->mData, audioData, audioBufferList.buffer(0)->mDataByteSize);
-
-    audioSamplesAvailable(mediaTime, audioBufferList, CAAudioStreamDescription(newDescription), numberOfFrames);
-}
-
-void RealtimeIncomingAudioSource::startProducingData()
-{
-    if (m_audioTrack)
-        m_audioTrack->AddSink(this);
-}
-
-void RealtimeIncomingAudioSource::stopProducingData()
-{
-    if (m_audioTrack)
-        m_audioTrack->RemoveSink(this);
-}
-
-void RealtimeIncomingAudioSource::setSourceTrack(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& track)
-{
-    ASSERT(!m_audioTrack);
-    ASSERT(track);
-
-    m_audioTrack = WTFMove(track);
-    notifyMutedChange(!m_audioTrack);
-    if (isProducingData())
-        m_audioTrack->AddSink(this);
-}
-
-const RealtimeMediaSourceCapabilities& RealtimeIncomingAudioSource::capabilities() const
-{
-    return RealtimeMediaSourceCapabilities::emptyCapabilities();
-}
-
-const RealtimeMediaSourceSettings& RealtimeIncomingAudioSource::settings() const
-{
-    return m_currentSettings;
-}
-
-}
-
-#endif // USE(LIBWEBRTC)

Deleted: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h (223411 => 223412)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h	2017-10-16 16:38:15 UTC (rev 223411)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h	2017-10-16 16:40:48 UTC (rev 223412)
@@ -1,75 +0,0 @@
-/*
- * 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.
- * 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 USE(LIBWEBRTC)
-
-#include "LibWebRTCMacros.h"
-#include "RealtimeMediaSource.h"
-#include <CoreAudio/CoreAudioTypes.h>
-#include <webrtc/api/mediastreaminterface.h>
-#include <wtf/RetainPtr.h>
-
-typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
-
-namespace WebCore {
-
-class WebAudioSourceProviderAVFObjC;
-
-class RealtimeIncomingAudioSource final : public RealtimeMediaSource, private webrtc::AudioTrackSinkInterface {
-public:
-    static Ref<RealtimeIncomingAudioSource> create(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&, String&&);
-
-    void setSourceTrack(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&);
-
-private:
-    RealtimeIncomingAudioSource(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&, String&&);
-    ~RealtimeIncomingAudioSource();
-
-    // webrtc::AudioTrackSinkInterface API
-    void OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames) final;
-
-    // RealtimeMediaSource API
-    void startProducingData() final;
-    void stopProducingData()  final;
-
-    const RealtimeMediaSourceCapabilities& capabilities() const final;
-    const RealtimeMediaSourceSettings& settings() const final;
-
-    RealtimeMediaSourceSettings m_currentSettings;
-    rtc::scoped_refptr<webrtc::AudioTrackInterface> m_audioTrack;
-
-    uint64_t m_numberOfFrames { 0 };
-};
-
-} // namespace WebCore
-
-#endif // USE(LIBWEBRTC)

Copied: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp (from rev 223411, trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp) (0 => 223412)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp	2017-10-16 16:40:48 UTC (rev 223412)
@@ -0,0 +1,101 @@
+/*
+ * 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 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.
+ */
+
+#include "config.h"
+#include "RealtimeIncomingAudioSourceCocoa.h"
+
+#if USE(LIBWEBRTC)
+
+#include "AudioStreamDescription.h"
+#include "CAAudioStreamDescription.h"
+#include "LibWebRTCAudioFormat.h"
+#include "WebAudioBufferList.h"
+#include "WebAudioSourceProviderAVFObjC.h"
+#include <pal/avfoundation/MediaTimeAVFoundation.h>
+
+#include "CoreMediaSoftLink.h"
+
+namespace WebCore {
+
+Ref<RealtimeIncomingAudioSource> RealtimeIncomingAudioSource::create(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
+{
+    auto source = RealtimeIncomingAudioSourceCocoa::create(WTFMove(audioTrack), WTFMove(audioTrackId));
+    source->start();
+    return WTFMove(source);
+}
+
+Ref<RealtimeIncomingAudioSourceCocoa> RealtimeIncomingAudioSourceCocoa::create(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
+{
+    return adoptRef(*new RealtimeIncomingAudioSourceCocoa(WTFMove(audioTrack), WTFMove(audioTrackId)));
+}
+
+RealtimeIncomingAudioSourceCocoa::RealtimeIncomingAudioSourceCocoa(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
+    : RealtimeIncomingAudioSource(WTFMove(audioTrack), WTFMove(audioTrackId))
+{
+}
+
+static inline AudioStreamBasicDescription streamDescription(size_t sampleRate, size_t channelCount)
+{
+    AudioStreamBasicDescription streamFormat;
+    FillOutASBDForLPCM(streamFormat, sampleRate, channelCount, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::isFloat, LibWebRTCAudioFormat::isBigEndian, LibWebRTCAudioFormat::isNonInterleaved);
+    return streamFormat;
+}
+
+void RealtimeIncomingAudioSourceCocoa::OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames)
+{
+    // We may receive OnData calls with empty sound data (mono, samples equal to zero and sampleRate equal to 16000) when starting the call.
+    // FIXME: For the moment we skip them, we should find a better solution at libwebrtc level to not be called until getting some real data.
+    if (sampleRate == 16000 && numberOfChannels == 1)
+        return;
+
+    ASSERT(bitsPerSample == 16);
+    ASSERT(numberOfChannels == 1 || numberOfChannels == 2);
+    ASSERT(sampleRate == 48000);
+
+    CMTime startTime = CMTimeMake(m_numberOfFrames, sampleRate);
+    auto mediaTime = PAL::toMediaTime(startTime);
+    m_numberOfFrames += numberOfFrames;
+
+    AudioStreamBasicDescription newDescription = streamDescription(sampleRate, numberOfChannels);
+
+    // FIXME: We should not need to do the extra memory allocation and copy.
+    // Instead, we should be able to directly pass audioData pointer.
+    WebAudioBufferList audioBufferList { CAAudioStreamDescription(newDescription), WTF::safeCast<uint32_t>(numberOfFrames) };
+    audioBufferList.buffer(0)->mDataByteSize = numberOfChannels * numberOfFrames * bitsPerSample / 8;
+    audioBufferList.buffer(0)->mNumberChannels = numberOfChannels;
+
+    if (muted())
+        memset(audioBufferList.buffer(0)->mData, 0, audioBufferList.buffer(0)->mDataByteSize);
+    else
+        memcpy(audioBufferList.buffer(0)->mData, audioData, audioBufferList.buffer(0)->mDataByteSize);
+
+    audioSamplesAvailable(mediaTime, audioBufferList, CAAudioStreamDescription(newDescription), numberOfFrames);
+}
+
+}
+
+#endif // USE(LIBWEBRTC)

Copied: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h (from rev 223411, trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h) (0 => 223412)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h	2017-10-16 16:40:48 UTC (rev 223412)
@@ -0,0 +1,57 @@
+/*
+ * 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 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 USE(LIBWEBRTC)
+
+#include "RealtimeIncomingAudioSource.h"
+
+#include <CoreAudio/CoreAudioTypes.h>
+
+typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
+
+namespace WebCore {
+
+class WebAudioSourceProviderAVFObjC;
+
+class RealtimeIncomingAudioSourceCocoa final : public RealtimeIncomingAudioSource {
+public:
+    static Ref<RealtimeIncomingAudioSourceCocoa> create(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&, String&&);
+
+private:
+    RealtimeIncomingAudioSourceCocoa(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&, String&&);
+
+    // webrtc::AudioTrackSinkInterface API
+    void OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames) final;
+
+    uint64_t m_numberOfFrames { 0 };
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)

Deleted: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp (223411 => 223412)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp	2017-10-16 16:38:15 UTC (rev 223411)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp	2017-10-16 16:40:48 UTC (rev 223412)
@@ -1,203 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted, provided that the following conditions
- * are required to be 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 Apple 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 APPLE INC. AND ITS 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 APPLE INC. AND ITS 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 "RealtimeOutgoingAudioSource.h"
-
-#if USE(LIBWEBRTC)
-
-#include "CAAudioStreamDescription.h"
-#include "LibWebRTCAudioFormat.h"
-#include "LibWebRTCProvider.h"
-
-namespace WebCore {
-
-static inline AudioStreamBasicDescription libwebrtcAudioFormat(Float64 sampleRate, size_t channelCount)
-{
-    // FIXME: Microphones can have more than two channels. In such case, we should do the mix down based on AudioChannelLayoutTag.
-    size_t libWebRTCChannelCount = channelCount >= 2 ? 2 : channelCount;
-    AudioStreamBasicDescription streamFormat;
-    FillOutASBDForLPCM(streamFormat, sampleRate, libWebRTCChannelCount, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::isFloat, LibWebRTCAudioFormat::isBigEndian, LibWebRTCAudioFormat::isNonInterleaved);
-    return streamFormat;
-}
-
-RealtimeOutgoingAudioSource::RealtimeOutgoingAudioSource(Ref<MediaStreamTrackPrivate>&& audioSource)
-    : m_audioSource(WTFMove(audioSource))
-    , m_sampleConverter(AudioSampleDataSource::create(LibWebRTCAudioFormat::sampleRate * 2))
-    , m_silenceAudioTimer(*this, &RealtimeOutgoingAudioSource::sendSilence)
-{
-    m_audioSource->addObserver(*this);
-    initializeConverter();
-}
-
-bool RealtimeOutgoingAudioSource::setSource(Ref<MediaStreamTrackPrivate>&& newSource)
-{
-    m_audioSource->removeObserver(*this);
-    m_audioSource = WTFMove(newSource);
-    m_audioSource->addObserver(*this);
-
-    initializeConverter();
-    return true;
-}
-
-void RealtimeOutgoingAudioSource::initializeConverter()
-{
-    m_muted = m_audioSource->muted();
-    m_enabled = m_audioSource->enabled();
-    handleMutedIfNeeded();
-}
-
-void RealtimeOutgoingAudioSource::stop()
-{
-    m_silenceAudioTimer.stop();
-    m_audioSource->removeObserver(*this);
-}
-
-void RealtimeOutgoingAudioSource::sourceMutedChanged()
-{
-    m_muted = m_audioSource->muted();
-    handleMutedIfNeeded();
-}
-
-void RealtimeOutgoingAudioSource::sourceEnabledChanged()
-{
-    m_enabled = m_audioSource->enabled();
-    handleMutedIfNeeded();
-}
-
-void RealtimeOutgoingAudioSource::handleMutedIfNeeded()
-{
-    bool isSilenced = m_muted || !m_enabled;
-    m_sampleConverter->setMuted(isSilenced);
-    if (isSilenced && !m_silenceAudioTimer.isActive())
-        m_silenceAudioTimer.startRepeating(1_s);
-    if (!isSilenced && m_silenceAudioTimer.isActive())
-        m_silenceAudioTimer.stop();
-}
-
-void RealtimeOutgoingAudioSource::sendSilence()
-{
-    LibWebRTCProvider::callOnWebRTCSignalingThread([this, protectedThis = makeRef(*this)] {
-        size_t chunkSampleCount = m_outputStreamDescription.sampleRate() / 100;
-        size_t bufferSize = chunkSampleCount * LibWebRTCAudioFormat::sampleByteSize * m_outputStreamDescription.numberOfChannels();
-
-        if (!bufferSize)
-            return;
-
-        m_audioBuffer.grow(bufferSize);
-        memset(m_audioBuffer.data(), 0, bufferSize);
-        for (auto sink : m_sinks)
-            sink->OnData(m_audioBuffer.data(), LibWebRTCAudioFormat::sampleSize, m_outputStreamDescription.sampleRate(), m_outputStreamDescription.numberOfChannels(), chunkSampleCount);
-    });
-}
-
-bool RealtimeOutgoingAudioSource::isReachingBufferedAudioDataHighLimit()
-{
-    auto writtenAudioDuration = m_writeCount / m_inputStreamDescription.sampleRate();
-    auto readAudioDuration = m_readCount / m_outputStreamDescription.sampleRate();
-
-    ASSERT(writtenAudioDuration >= readAudioDuration);
-    return writtenAudioDuration > readAudioDuration + 0.5;
-}
-
-bool RealtimeOutgoingAudioSource::isReachingBufferedAudioDataLowLimit()
-{
-    auto writtenAudioDuration = m_writeCount / m_inputStreamDescription.sampleRate();
-    auto readAudioDuration = m_readCount / m_outputStreamDescription.sampleRate();
-
-    ASSERT(writtenAudioDuration >= readAudioDuration);
-    return writtenAudioDuration < readAudioDuration + 0.1;
-}
-
-bool RealtimeOutgoingAudioSource::hasBufferedEngouhData()
-{
-    auto writtenAudioDuration = m_writeCount / m_inputStreamDescription.sampleRate();
-    auto readAudioDuration = m_readCount / m_outputStreamDescription.sampleRate();
-
-    ASSERT(writtenAudioDuration >= readAudioDuration);
-    return writtenAudioDuration >= readAudioDuration + 0.01;
-}
-
-void RealtimeOutgoingAudioSource::audioSamplesAvailable(const MediaTime&, const PlatformAudioData& audioData, const AudioStreamDescription& streamDescription, size_t sampleCount)
-{
-    if (m_inputStreamDescription != streamDescription) {
-        m_inputStreamDescription = toCAAudioStreamDescription(streamDescription);
-        auto status  = m_sampleConverter->setInputFormat(m_inputStreamDescription);
-        ASSERT_UNUSED(status, !status);
-
-        m_outputStreamDescription = libwebrtcAudioFormat(LibWebRTCAudioFormat::sampleRate, streamDescription.numberOfChannels());
-        status = m_sampleConverter->setOutputFormat(m_outputStreamDescription.streamDescription());
-        ASSERT(!status);
-    }
-
-    // Let's skip pushing samples if we are too slow pulling them.
-    if (m_skippingAudioData) {
-        if (!isReachingBufferedAudioDataLowLimit())
-            return;
-        m_skippingAudioData = false;
-    } else if (isReachingBufferedAudioDataHighLimit()) {
-        m_skippingAudioData = true;
-        return;
-    }
-
-    // If we change the audio track or its sample rate changes, the timestamp based on m_writeCount may be wrong.
-    // FIXME: We should update m_writeCount to be valid according the new sampleRate.
-    m_sampleConverter->pushSamples(MediaTime(m_writeCount, static_cast<uint32_t>(m_inputStreamDescription.sampleRate())), audioData, sampleCount);
-    m_writeCount += sampleCount;
-
-    if (!hasBufferedEngouhData())
-        return;
-
-    LibWebRTCProvider::callOnWebRTCSignalingThread([protectedThis = makeRef(*this)] {
-        protectedThis->pullAudioData();
-    });
-}
-
-void RealtimeOutgoingAudioSource::pullAudioData()
-{
-    // libwebrtc expects 10 ms chunks.
-    size_t chunkSampleCount = m_outputStreamDescription.sampleRate() / 100;
-    size_t bufferSize = chunkSampleCount * LibWebRTCAudioFormat::sampleByteSize * m_outputStreamDescription.numberOfChannels();
-    m_audioBuffer.grow(bufferSize);
-
-    AudioBufferList bufferList;
-    bufferList.mNumberBuffers = 1;
-    bufferList.mBuffers[0].mNumberChannels = m_outputStreamDescription.numberOfChannels();
-    bufferList.mBuffers[0].mDataByteSize = bufferSize;
-    bufferList.mBuffers[0].mData = m_audioBuffer.data();
-
-    m_sampleConverter->pullAvalaibleSamplesAsChunks(bufferList, chunkSampleCount, m_readCount, [this, chunkSampleCount] {
-        m_readCount += chunkSampleCount;
-        for (auto sink : m_sinks)
-            sink->OnData(m_audioBuffer.data(), LibWebRTCAudioFormat::sampleSize, m_outputStreamDescription.sampleRate(), m_outputStreamDescription.numberOfChannels(), chunkSampleCount);
-    });
-}
-
-} // namespace WebCore
-
-#endif // USE(LIBWEBRTC)

Deleted: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h (223411 => 223412)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h	2017-10-16 16:38:15 UTC (rev 223411)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h	2017-10-16 16:40:48 UTC (rev 223412)
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted, provided that the following conditions
- * are required to be 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 Apple 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 APPLE INC. AND ITS 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 APPLE INC. AND ITS 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 USE(LIBWEBRTC)
-
-#include "AudioSampleDataSource.h"
-#include "LibWebRTCMacros.h"
-#include "MediaStreamTrackPrivate.h"
-#include "Timer.h"
-#include <webrtc/api/mediastreaminterface.h>
-#include <wtf/ThreadSafeRefCounted.h>
-
-namespace webrtc {
-class AudioTrackInterface;
-class AudioTrackSinkInterface;
-}
-
-namespace WebCore {
-
-class RealtimeOutgoingAudioSource final : public ThreadSafeRefCounted<RealtimeOutgoingAudioSource>, public webrtc::AudioSourceInterface, private MediaStreamTrackPrivate::Observer {
-public:
-    static Ref<RealtimeOutgoingAudioSource> create(Ref<MediaStreamTrackPrivate>&& audioSource) { return adoptRef(*new RealtimeOutgoingAudioSource(WTFMove(audioSource))); }
-    ~RealtimeOutgoingAudioSource() { stop(); }
-
-    void stop();
-
-    bool setSource(Ref<MediaStreamTrackPrivate>&&);
-    MediaStreamTrackPrivate& source() const { return m_audioSource.get(); }
-
-private:
-    explicit RealtimeOutgoingAudioSource(Ref<MediaStreamTrackPrivate>&&);
-
-    virtual void AddSink(webrtc::AudioTrackSinkInterface* sink) { m_sinks.append(sink); }
-    virtual void RemoveSink(webrtc::AudioTrackSinkInterface* sink) { m_sinks.removeFirst(sink); }
-
-    int AddRef() const final { ref(); return refCount(); }
-    int Release() const final { deref(); return refCount(); }
-    SourceState state() const final { return kLive; }
-    bool remote() const final { return false; }
-    void RegisterObserver(webrtc::ObserverInterface*) final { }
-    void UnregisterObserver(webrtc::ObserverInterface*) final { }
-
-    void sourceMutedChanged();
-    void sourceEnabledChanged();
-    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t);
-
-    bool isReachingBufferedAudioDataHighLimit();
-    bool isReachingBufferedAudioDataLowLimit();
-    bool hasBufferedEngouhData();
-
-    // MediaStreamTrackPrivate::Observer API
-    void trackMutedChanged(MediaStreamTrackPrivate&) final { sourceMutedChanged(); }
-    void trackEnabledChanged(MediaStreamTrackPrivate&) final { sourceEnabledChanged(); }
-    void audioSamplesAvailable(MediaStreamTrackPrivate&, const MediaTime& mediaTime, const PlatformAudioData& data, const AudioStreamDescription& description, size_t sampleCount) final { audioSamplesAvailable(mediaTime, data, description, sampleCount); }
-    void trackEnded(MediaStreamTrackPrivate&) final { }
-    void trackSettingsChanged(MediaStreamTrackPrivate&) final { }
-
-    void pullAudioData();
-
-    void initializeConverter();
-    void handleMutedIfNeeded();
-    void sendSilence();
-
-    Vector<webrtc::AudioTrackSinkInterface*> m_sinks;
-    Ref<MediaStreamTrackPrivate> m_audioSource;
-    Ref<AudioSampleDataSource> m_sampleConverter;
-    CAAudioStreamDescription m_inputStreamDescription;
-    CAAudioStreamDescription m_outputStreamDescription;
-
-    Vector<uint8_t> m_audioBuffer;
-    uint64_t m_readCount { 0 };
-    uint64_t m_writeCount { 0 };
-    bool m_muted { false };
-    bool m_enabled { true };
-    bool m_skippingAudioData { false };
-    Timer m_silenceAudioTimer;
-};
-
-} // namespace WebCore
-
-#endif // USE(LIBWEBRTC)

Copied: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp (from rev 223411, trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp) (0 => 223412)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp	2017-10-16 16:40:48 UTC (rev 223412)
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2017 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be 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. AND ITS 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 APPLE INC. AND ITS 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 "RealtimeOutgoingAudioSourceCocoa.h"
+
+#if USE(LIBWEBRTC)
+
+#include "CAAudioStreamDescription.h"
+#include "LibWebRTCAudioFormat.h"
+#include "LibWebRTCProvider.h"
+
+namespace WebCore {
+
+static inline AudioStreamBasicDescription libwebrtcAudioFormat(Float64 sampleRate, size_t channelCount)
+{
+    // FIXME: Microphones can have more than two channels. In such case, we should do the mix down based on AudioChannelLayoutTag.
+    size_t libWebRTCChannelCount = channelCount >= 2 ? 2 : channelCount;
+    AudioStreamBasicDescription streamFormat;
+    FillOutASBDForLPCM(streamFormat, sampleRate, libWebRTCChannelCount, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::isFloat, LibWebRTCAudioFormat::isBigEndian, LibWebRTCAudioFormat::isNonInterleaved);
+    return streamFormat;
+}
+
+RealtimeOutgoingAudioSourceCocoa::RealtimeOutgoingAudioSourceCocoa(Ref<MediaStreamTrackPrivate>&& audioSource)
+    : RealtimeOutgoingAudioSource(WTFMove(audioSource))
+    , m_sampleConverter(AudioSampleDataSource::create(LibWebRTCAudioFormat::sampleRate * 2))
+{
+}
+
+Ref<RealtimeOutgoingAudioSource> RealtimeOutgoingAudioSource::create(Ref<MediaStreamTrackPrivate>&& audioSource)
+{
+    return RealtimeOutgoingAudioSourceCocoa::create(WTFMove(audioSource));
+}
+
+void RealtimeOutgoingAudioSourceCocoa::handleMutedIfNeeded()
+{
+    bool isSilenced = m_muted || !m_enabled;
+    m_sampleConverter->setMuted(isSilenced);
+
+    RealtimeOutgoingAudioSource::handleMutedIfNeeded();
+}
+
+void RealtimeOutgoingAudioSourceCocoa::sendSilence()
+{
+    LibWebRTCProvider::callOnWebRTCSignalingThread([this, protectedThis = makeRef(*this)] {
+        size_t chunkSampleCount = m_outputStreamDescription.sampleRate() / 100;
+        size_t bufferSize = chunkSampleCount * LibWebRTCAudioFormat::sampleByteSize * m_outputStreamDescription.numberOfChannels();
+
+        if (!bufferSize)
+            return;
+
+        m_audioBuffer.grow(bufferSize);
+        memset(m_audioBuffer.data(), 0, bufferSize);
+        for (auto sink : m_sinks)
+            sink->OnData(m_audioBuffer.data(), LibWebRTCAudioFormat::sampleSize, m_outputStreamDescription.sampleRate(), m_outputStreamDescription.numberOfChannels(), chunkSampleCount);
+    });
+}
+
+bool RealtimeOutgoingAudioSourceCocoa::isReachingBufferedAudioDataHighLimit()
+{
+    auto writtenAudioDuration = m_writeCount / m_inputStreamDescription.sampleRate();
+    auto readAudioDuration = m_readCount / m_outputStreamDescription.sampleRate();
+
+    ASSERT(writtenAudioDuration >= readAudioDuration);
+    return writtenAudioDuration > readAudioDuration + 0.5;
+}
+
+bool RealtimeOutgoingAudioSourceCocoa::isReachingBufferedAudioDataLowLimit()
+{
+    auto writtenAudioDuration = m_writeCount / m_inputStreamDescription.sampleRate();
+    auto readAudioDuration = m_readCount / m_outputStreamDescription.sampleRate();
+
+    ASSERT(writtenAudioDuration >= readAudioDuration);
+    return writtenAudioDuration < readAudioDuration + 0.1;
+}
+
+bool RealtimeOutgoingAudioSourceCocoa::hasBufferedEnoughData()
+{
+    auto writtenAudioDuration = m_writeCount / m_inputStreamDescription.sampleRate();
+    auto readAudioDuration = m_readCount / m_outputStreamDescription.sampleRate();
+
+    ASSERT(writtenAudioDuration >= readAudioDuration);
+    return writtenAudioDuration >= readAudioDuration + 0.01;
+}
+
+void RealtimeOutgoingAudioSourceCocoa::audioSamplesAvailable(const MediaTime&, const PlatformAudioData& audioData, const AudioStreamDescription& streamDescription, size_t sampleCount)
+{
+    if (m_inputStreamDescription != streamDescription) {
+        m_inputStreamDescription = toCAAudioStreamDescription(streamDescription);
+        auto status  = m_sampleConverter->setInputFormat(m_inputStreamDescription);
+        ASSERT_UNUSED(status, !status);
+
+        m_outputStreamDescription = libwebrtcAudioFormat(LibWebRTCAudioFormat::sampleRate, streamDescription.numberOfChannels());
+        status = m_sampleConverter->setOutputFormat(m_outputStreamDescription.streamDescription());
+        ASSERT(!status);
+    }
+
+    // Let's skip pushing samples if we are too slow pulling them.
+    if (m_skippingAudioData) {
+        if (!isReachingBufferedAudioDataLowLimit())
+            return;
+        m_skippingAudioData = false;
+    } else if (isReachingBufferedAudioDataHighLimit()) {
+        m_skippingAudioData = true;
+        return;
+    }
+
+    // If we change the audio track or its sample rate changes, the timestamp based on m_writeCount may be wrong.
+    // FIXME: We should update m_writeCount to be valid according the new sampleRate.
+    m_sampleConverter->pushSamples(MediaTime(m_writeCount, static_cast<uint32_t>(m_inputStreamDescription.sampleRate())), audioData, sampleCount);
+    m_writeCount += sampleCount;
+
+    if (!hasBufferedEnoughData())
+        return;
+
+    LibWebRTCProvider::callOnWebRTCSignalingThread([protectedThis = makeRef(*this)] {
+        protectedThis->pullAudioData();
+    });
+}
+
+void RealtimeOutgoingAudioSourceCocoa::pullAudioData()
+{
+    // libwebrtc expects 10 ms chunks.
+    size_t chunkSampleCount = m_outputStreamDescription.sampleRate() / 100;
+    size_t bufferSize = chunkSampleCount * LibWebRTCAudioFormat::sampleByteSize * m_outputStreamDescription.numberOfChannels();
+    m_audioBuffer.grow(bufferSize);
+
+    AudioBufferList bufferList;
+    bufferList.mNumberBuffers = 1;
+    bufferList.mBuffers[0].mNumberChannels = m_outputStreamDescription.numberOfChannels();
+    bufferList.mBuffers[0].mDataByteSize = bufferSize;
+    bufferList.mBuffers[0].mData = m_audioBuffer.data();
+
+    m_sampleConverter->pullAvalaibleSamplesAsChunks(bufferList, chunkSampleCount, m_readCount, [this, chunkSampleCount] {
+        m_readCount += chunkSampleCount;
+        for (auto sink : m_sinks)
+            sink->OnData(m_audioBuffer.data(), LibWebRTCAudioFormat::sampleSize, m_outputStreamDescription.sampleRate(), m_outputStreamDescription.numberOfChannels(), chunkSampleCount);
+    });
+}
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)

Added: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.h (0 => 223412)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.h	2017-10-16 16:40:48 UTC (rev 223412)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be 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. AND ITS 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 APPLE INC. AND ITS 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 USE(LIBWEBRTC)
+
+#include "AudioSampleDataSource.h"
+#include "RealtimeOutgoingAudioSource.h"
+
+namespace webrtc {
+class AudioTrackInterface;
+class AudioTrackSinkInterface;
+}
+
+namespace WebCore {
+
+class RealtimeOutgoingAudioSourceCocoa final : public RealtimeOutgoingAudioSource {
+public:
+    static Ref<RealtimeOutgoingAudioSourceCocoa> create(Ref<MediaStreamTrackPrivate>&& audioSource) { return adoptRef(*new RealtimeOutgoingAudioSourceCocoa(WTFMove(audioSource))); }
+
+private:
+    explicit RealtimeOutgoingAudioSourceCocoa(Ref<MediaStreamTrackPrivate>&&);
+
+    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
+
+    bool isReachingBufferedAudioDataHighLimit() final;
+    bool isReachingBufferedAudioDataLowLimit() final;
+    bool hasBufferedEnoughData() final;
+
+    void pullAudioData() final;
+
+    void handleMutedIfNeeded() final;
+    void sendSilence() final;
+
+    Ref<AudioSampleDataSource> m_sampleConverter;
+    CAAudioStreamDescription m_inputStreamDescription;
+    CAAudioStreamDescription m_outputStreamDescription;
+
+    Vector<uint8_t> m_audioBuffer;
+    uint64_t m_readCount { 0 };
+    uint64_t m_writeCount { 0 };
+    bool m_skippingAudioData { false };
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to