Split AudioTrackPrivateMediaStreamCocoa to implement remote audio rendering
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2020 20:21:23 +0000 (20:21 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2020 20:21:23 +0000 (20:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206172

Reviewed by Eric Carlson.

Refactor code to allow in the future rendering of media stream audio tracks in a remote process.
For that purpose, split AudioTrackPrivateMediaStreamCocoa functionality in two parts.
The first part is moved back to AudioTrackPrivateMediaStream.
The second part is platform specific and is defined in terms of an interface AudioMediaStreamTrackRenderer
and an in process implementation named AudioMediaStreamTrackRendererCocoa.

Make TrackPrivateBase and MediaStreamTrackPrivate public LoggerHelper.
This allows making AudioMediaStreamTrackRenderer and AudioSampleDataSource to take a LoggerHelper instead of a derived instance.

No change of behavior.

* Sources.txt:
* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/audio/mac/AudioSampleDataSource.h:
* platform/audio/mac/AudioSampleDataSource.mm:
(WebCore::AudioSampleDataSource::create):
(WebCore::AudioSampleDataSource::AudioSampleDataSource):
* platform/graphics/TrackPrivateBase.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateTracks):
* platform/mediastream/AudioMediaStreamTrackRenderer.h: Added.
(WebCore::AudioMediaStreamTrackRenderer::setMuted):
(WebCore::AudioMediaStreamTrackRenderer::setVolume):
(WebCore::AudioMediaStreamTrackRenderer::volume const):
(WebCore::AudioMediaStreamTrackRenderer::isMuted const):
* platform/mediastream/AudioTrackPrivateMediaStream.cpp: Added.
(WebCore::AudioTrackPrivateMediaStream::setLogger):
(WebCore::AudioTrackPrivateMediaStream::AudioTrackPrivateMediaStream):
(WebCore::AudioTrackPrivateMediaStream::~AudioTrackPrivateMediaStream):
(WebCore::AudioTrackPrivateMediaStream::clear):
(WebCore::AudioTrackPrivateMediaStream::playInternal):
(WebCore::AudioTrackPrivateMediaStream::play):
(WebCore::AudioTrackPrivateMediaStream::pause):
(WebCore::AudioTrackPrivateMediaStream::setVolume):
(WebCore::AudioTrackPrivateMediaStream::volume const):
(WebCore::AudioTrackPrivateMediaStream::audioSamplesAvailable):
(WebCore::AudioTrackPrivateMediaStream::trackMutedChanged):
(WebCore::AudioTrackPrivateMediaStream::trackEnabledChanged):
(WebCore::AudioTrackPrivateMediaStream::updateRendererMutedState):
(WebCore::AudioTrackPrivateMediaStream::trackEnded):
* platform/mediastream/AudioTrackPrivateMediaStream.h:
* platform/mediastream/MediaStreamTrackPrivate.h:
* platform/mediastream/mac/AudioMediaStreamTrackRendererCocoa.cpp: Added.
(WebCore::AudioMediaStreamTrackRendererCocoa::stop):
(WebCore::AudioMediaStreamTrackRendererCocoa::clear):
(WebCore::AudioMediaStreamTrackRendererCocoa::setPaused):
(WebCore::AudioMediaStreamTrackRendererCocoa::createAudioUnit):
(WebCore::AudioMediaStreamTrackRendererCocoa::pushSamples):
(WebCore::AudioMediaStreamTrackRendererCocoa::render):
(WebCore::AudioMediaStreamTrackRendererCocoa::inputProc):
* platform/mediastream/mac/AudioMediaStreamTrackRendererCocoa.h: Added.
* platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h: Removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254446 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/audio/mac/AudioSampleDataSource.h
Source/WebCore/platform/audio/mac/AudioSampleDataSource.mm
Source/WebCore/platform/graphics/TrackPrivateBase.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
Source/WebCore/platform/mediastream/AudioMediaStreamTrackRenderer.cpp [new file with mode: 0644]
Source/WebCore/platform/mediastream/AudioMediaStreamTrackRenderer.h [new file with mode: 0644]
Source/WebCore/platform/mediastream/AudioTrackPrivateMediaStream.cpp [new file with mode: 0644]
Source/WebCore/platform/mediastream/AudioTrackPrivateMediaStream.h
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h
Source/WebCore/platform/mediastream/mac/AudioMediaStreamTrackRendererCocoa.cpp [moved from Source/WebCore/platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.cpp with 69% similarity]
Source/WebCore/platform/mediastream/mac/AudioMediaStreamTrackRendererCocoa.h [moved from Source/WebCore/platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h with 62% similarity]

index 7efded1..3d0bfa3 100644 (file)
@@ -1,3 +1,65 @@
+2020-01-13  youenn fablet  <youenn@apple.com>
+
+        Split AudioTrackPrivateMediaStreamCocoa to implement remote audio rendering
+        https://bugs.webkit.org/show_bug.cgi?id=206172
+
+        Reviewed by Eric Carlson.
+
+        Refactor code to allow in the future rendering of media stream audio tracks in a remote process.
+        For that purpose, split AudioTrackPrivateMediaStreamCocoa functionality in two parts.
+        The first part is moved back to AudioTrackPrivateMediaStream.
+        The second part is platform specific and is defined in terms of an interface AudioMediaStreamTrackRenderer
+        and an in process implementation named AudioMediaStreamTrackRendererCocoa.
+
+        Make TrackPrivateBase and MediaStreamTrackPrivate public LoggerHelper.
+        This allows making AudioMediaStreamTrackRenderer and AudioSampleDataSource to take a LoggerHelper instead of a derived instance.
+
+        No change of behavior.
+
+        * Sources.txt:
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/audio/mac/AudioSampleDataSource.h:
+        * platform/audio/mac/AudioSampleDataSource.mm:
+        (WebCore::AudioSampleDataSource::create):
+        (WebCore::AudioSampleDataSource::AudioSampleDataSource):
+        * platform/graphics/TrackPrivateBase.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateTracks):
+        * platform/mediastream/AudioMediaStreamTrackRenderer.h: Added.
+        (WebCore::AudioMediaStreamTrackRenderer::setMuted):
+        (WebCore::AudioMediaStreamTrackRenderer::setVolume):
+        (WebCore::AudioMediaStreamTrackRenderer::volume const):
+        (WebCore::AudioMediaStreamTrackRenderer::isMuted const):
+        * platform/mediastream/AudioTrackPrivateMediaStream.cpp: Added.
+        (WebCore::AudioTrackPrivateMediaStream::setLogger):
+        (WebCore::AudioTrackPrivateMediaStream::AudioTrackPrivateMediaStream):
+        (WebCore::AudioTrackPrivateMediaStream::~AudioTrackPrivateMediaStream):
+        (WebCore::AudioTrackPrivateMediaStream::clear):
+        (WebCore::AudioTrackPrivateMediaStream::playInternal):
+        (WebCore::AudioTrackPrivateMediaStream::play):
+        (WebCore::AudioTrackPrivateMediaStream::pause):
+        (WebCore::AudioTrackPrivateMediaStream::setVolume):
+        (WebCore::AudioTrackPrivateMediaStream::volume const):
+        (WebCore::AudioTrackPrivateMediaStream::audioSamplesAvailable):
+        (WebCore::AudioTrackPrivateMediaStream::trackMutedChanged):
+        (WebCore::AudioTrackPrivateMediaStream::trackEnabledChanged):
+        (WebCore::AudioTrackPrivateMediaStream::updateRendererMutedState):
+        (WebCore::AudioTrackPrivateMediaStream::trackEnded):
+        * platform/mediastream/AudioTrackPrivateMediaStream.h:
+        * platform/mediastream/MediaStreamTrackPrivate.h:
+        * platform/mediastream/mac/AudioMediaStreamTrackRendererCocoa.cpp: Added.
+        (WebCore::AudioMediaStreamTrackRendererCocoa::stop):
+        (WebCore::AudioMediaStreamTrackRendererCocoa::clear):
+        (WebCore::AudioMediaStreamTrackRendererCocoa::setPaused):
+        (WebCore::AudioMediaStreamTrackRendererCocoa::createAudioUnit):
+        (WebCore::AudioMediaStreamTrackRendererCocoa::pushSamples):
+        (WebCore::AudioMediaStreamTrackRendererCocoa::render):
+        (WebCore::AudioMediaStreamTrackRendererCocoa::inputProc):
+        * platform/mediastream/mac/AudioMediaStreamTrackRendererCocoa.h: Added.
+        * platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h: Removed.
+
 2020-01-06  Jiewen Tan  <jiewen_tan@apple.com>
 
         [WebAuthn] Support CTAP Client Pin
index 4112155..d85b179 100644 (file)
@@ -1970,6 +1970,8 @@ platform/mediacapabilities/MediaCapabilitiesLogging.cpp
 
 platform/mediarecorder/MediaRecorderPrivateMock.cpp
 
+platform/mediastream/AudioMediaStreamTrackRenderer.cpp
+platform/mediastream/AudioTrackPrivateMediaStream.cpp
 platform/mediastream/CaptureDeviceManager.cpp
 platform/mediastream/MediaConstraints.cpp
 platform/mediastream/MediaEndpointConfiguration.cpp
index e453d89..e6f817a 100644 (file)
@@ -489,7 +489,7 @@ platform/mediastream/ios/AVAudioSessionCaptureDevice.mm
 platform/mediastream/ios/AVAudioSessionCaptureDeviceManager.mm @no-unify
 platform/mediastream/ios/CoreAudioCaptureSourceIOS.mm @no-unify
 
-platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.cpp
+platform/mediastream/mac/AudioMediaStreamTrackRendererCocoa.cpp
 platform/mediastream/mac/AVCaptureDeviceManager.mm @no-unify
 platform/mediastream/mac/AVVideoCaptureSource.mm @no-unify
 platform/mediastream/mac/MockRealtimeVideoSourceMac.mm
index 9bb8431..e05536f 100644 (file)
                372C00D9129619F8005C9575 /* FindOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 372C00D8129619F8005C9575 /* FindOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                372D3E54216578AE00C5E021 /* DataURLDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A007821B820EC8002C5A6E /* DataURLDecoder.h */; };
                372D3E55216578AE00C5E021 /* ScriptModuleLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */; };
-               372D3E56216578AE00C5E021 /* AudioTrackPrivateMediaStreamCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 07C046C61E42512F007201E7 /* AudioTrackPrivateMediaStreamCocoa.h */; };
                372D3E57216578AE00C5E021 /* NavigatorCredentials.h in Headers */ = {isa = PBXBuildFile; fileRef = 57D846261FE895F800CA3682 /* NavigatorCredentials.h */; };
                375CD232119D43C800A2A859 /* Hyphenation.h in Headers */ = {isa = PBXBuildFile; fileRef = 375CD231119D43C800A2A859 /* Hyphenation.h */; };
                3774ABA50FA21EB400AD7DE9 /* OverlapTestRequestClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 3774ABA30FA21EB400AD7DE9 /* OverlapTestRequestClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4161E2D51FE48DC500EC2E96 /* FetchLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B51C89912600A7E715 /* FetchLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4162A451101145AE00DFF3ED /* DedicatedWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 4162A44E101145AE00DFF3ED /* DedicatedWorkerGlobalScope.h */; };
                4162A4581011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 4162A4561011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h */; };
+               416A06A123CCAD0300347109 /* AudioMediaStreamTrackRenderer.h in Headers */ = {isa = PBXBuildFile; fileRef = 416A069623CCAA9F00347109 /* AudioMediaStreamTrackRenderer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                416D75A220C651A500D02D2C /* NetworkLoadInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = 416D759F20C6441300D02D2C /* NetworkLoadInformation.h */; settings = {ATTRIBUTES = (Private, ); }; };
                416E0B3A209BC3CB004A95D9 /* FetchIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 416E0B37209BC3C2004A95D9 /* FetchIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
                416E29A6102FA962007FC14E /* WorkerReportingProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 416E29A5102FA962007FC14E /* WorkerReportingProxy.h */; };
                076970841463AD8700F502CF /* TextTrackList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextTrackList.cpp; sourceTree = "<group>"; };
                076970851463AD8700F502CF /* TextTrackList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackList.h; sourceTree = "<group>"; };
                076E11BE1F683E0D00177395 /* TrackPrivateBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrackPrivateBase.cpp; sourceTree = "<group>"; };
-               076EC1321E44F2CB00E5D813 /* AudioTrackPrivateMediaStreamCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioTrackPrivateMediaStreamCocoa.cpp; 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>"; };
                077664FA183E6B5C00133B92 /* JSQuickTimePluginReplacement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSQuickTimePluginReplacement.cpp; sourceTree = "<group>"; };
                07B7116C1D899E63009F0FFB /* CaptureDeviceManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CaptureDeviceManager.h; sourceTree = "<group>"; };
                07B93FF923B92AAA0036F8EA /* MIMETypeCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MIMETypeCache.h; sourceTree = "<group>"; };
                07B93FFB23B92AAB0036F8EA /* MIMETypeCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MIMETypeCache.cpp; sourceTree = "<group>"; };
-               07C046C61E42512F007201E7 /* AudioTrackPrivateMediaStreamCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioTrackPrivateMediaStreamCocoa.h; sourceTree = "<group>"; };
                07C1C0E01BFB600100BD2256 /* MediaTrackSupportedConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaTrackSupportedConstraints.h; sourceTree = "<group>"; };
                07C1C0E11BFB600100BD2256 /* MediaTrackSupportedConstraints.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MediaTrackSupportedConstraints.idl; sourceTree = "<group>"; };
                07C1C0E41BFB60ED00BD2256 /* RealtimeMediaSourceSupportedConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeMediaSourceSupportedConstraints.h; sourceTree = "<group>"; };
                4162A44F101145AE00DFF3ED /* DedicatedWorkerGlobalScope.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DedicatedWorkerGlobalScope.idl; sourceTree = "<group>"; };
                4162A4551011464700DFF3ED /* JSDedicatedWorkerGlobalScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDedicatedWorkerGlobalScope.cpp; sourceTree = "<group>"; };
                4162A4561011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDedicatedWorkerGlobalScope.h; sourceTree = "<group>"; };
+               416A069223CCAA9300347109 /* AudioMediaStreamTrackRendererCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioMediaStreamTrackRendererCocoa.h; sourceTree = "<group>"; };
+               416A069323CCAA9400347109 /* AudioMediaStreamTrackRendererCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioMediaStreamTrackRendererCocoa.cpp; sourceTree = "<group>"; };
+               416A069423CCAA9E00347109 /* AudioTrackPrivateMediaStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioTrackPrivateMediaStream.cpp; sourceTree = "<group>"; };
+               416A069523CCAA9E00347109 /* AudioMediaStreamTrackRenderer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioMediaStreamTrackRenderer.cpp; sourceTree = "<group>"; };
+               416A069623CCAA9F00347109 /* AudioMediaStreamTrackRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioMediaStreamTrackRenderer.h; sourceTree = "<group>"; };
                416CE4A4229DF12E00A8A686 /* RealtimeMediaSourceCenterMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RealtimeMediaSourceCenterMac.mm; sourceTree = "<group>"; };
                416D759F20C6441300D02D2C /* NetworkLoadInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkLoadInformation.h; sourceTree = "<group>"; };
                416E0B37209BC3C2004A95D9 /* FetchIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchIdentifier.h; sourceTree = "<group>"; };
                                CDC6751F1EAEA99600727C84 /* ios */,
                                415747421E38698000E914D8 /* libwebrtc */,
                                0729B14D17CFCCA0004F1D60 /* mac */,
+                               416A069523CCAA9E00347109 /* AudioMediaStreamTrackRenderer.cpp */,
+                               416A069623CCAA9F00347109 /* AudioMediaStreamTrackRenderer.h */,
+                               416A069423CCAA9E00347109 /* AudioTrackPrivateMediaStream.cpp */,
                                07D6A4F61BF2307D00174146 /* AudioTrackPrivateMediaStream.h */,
                                07B7116A1D899E63009F0FFB /* CaptureDevice.h */,
                                07B7116B1D899E63009F0FFB /* CaptureDeviceManager.cpp */,
                0729B14D17CFCCA0004F1D60 /* mac */ = {
                        isa = PBXGroup;
                        children = (
-                               076EC1321E44F2CB00E5D813 /* AudioTrackPrivateMediaStreamCocoa.cpp */,
-                               07C046C61E42512F007201E7 /* AudioTrackPrivateMediaStreamCocoa.h */,
+                               416A069323CCAA9400347109 /* AudioMediaStreamTrackRendererCocoa.cpp */,
+                               416A069223CCAA9300347109 /* AudioMediaStreamTrackRendererCocoa.h */,
                                070363DA181A1CDC00C074A5 /* AVCaptureDeviceManager.h */,
                                070363DB181A1CDC00C074A5 /* AVCaptureDeviceManager.mm */,
                                070363DE181A1CDC00C074A5 /* AVVideoCaptureSource.h */,
                                CD2F4A2818D8A3490063746D /* AudioHardwareListenerMac.h in Headers */,
                                FDE2D55B159E66EB00DCCCF8 /* AudioIOCallback.h in Headers */,
                                FD31601012B0267600C1A359 /* AudioListener.h in Headers */,
+                               416A06A123CCAD0300347109 /* AudioMediaStreamTrackRenderer.h in Headers */,
                                FD31601312B0267600C1A359 /* AudioNode.h in Headers */,
                                FD31601612B0267600C1A359 /* AudioNodeInput.h in Headers */,
                                FD31601812B0267600C1A359 /* AudioNodeOutput.h in Headers */,
                                CDE3A85817F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h in Headers */,
                                CD54A763180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.h in Headers */,
                                07D6A4F81BF2307D00174146 /* AudioTrackPrivateMediaStream.h in Headers */,
-                               372D3E56216578AE00C5E021 /* AudioTrackPrivateMediaStreamCocoa.h in Headers */,
                                FD31608B12B026F700C1A359 /* AudioUtilities.h in Headers */,
                                7EE6846112D26E3800E79415 /* AuthenticationChallenge.h in Headers */,
                                934F713A0D5A6F1000018D69 /* AuthenticationChallengeBase.h in Headers */,
index aa568c2..326c9bc 100644 (file)
@@ -42,7 +42,6 @@ namespace WebCore {
 
 class CAAudioStreamDescription;
 class CARingBuffer;
-class MediaStreamTrackPrivate;
 
 class AudioSampleDataSource : public ThreadSafeRefCounted<AudioSampleDataSource, WTF::DestructionThread::MainRunLoop>
 #if !RELEASE_LOG_DISABLED
@@ -50,7 +49,7 @@ class AudioSampleDataSource : public ThreadSafeRefCounted<AudioSampleDataSource,
 #endif
     {
 public:
-    static Ref<AudioSampleDataSource> create(size_t, MediaStreamTrackPrivate&);
+    static Ref<AudioSampleDataSource> create(size_t, WTF::LoggerHelper&);
 
     ~AudioSampleDataSource();
 
@@ -81,7 +80,7 @@ public:
 #endif
 
 private:
-    AudioSampleDataSource(size_t, MediaStreamTrackPrivate&);
+    AudioSampleDataSource(size_t, LoggerHelper&);
 
     OSStatus setupConverter();
     bool pullSamplesInternal(AudioBufferList&, size_t&, uint64_t, double, PullMode);
index 41afe39..add6d60 100644 (file)
@@ -46,19 +46,22 @@ namespace WebCore {
 using namespace PAL;
 using namespace JSC;
 
-Ref<AudioSampleDataSource> AudioSampleDataSource::create(size_t maximumSampleCount, MediaStreamTrackPrivate& track)
+Ref<AudioSampleDataSource> AudioSampleDataSource::create(size_t maximumSampleCount, LoggerHelper& loggerHelper)
 {
-    return adoptRef(*new AudioSampleDataSource(maximumSampleCount, track));
+    return adoptRef(*new AudioSampleDataSource(maximumSampleCount, loggerHelper));
 }
 
-AudioSampleDataSource::AudioSampleDataSource(size_t maximumSampleCount, MediaStreamTrackPrivate& track)
+AudioSampleDataSource::AudioSampleDataSource(size_t maximumSampleCount, LoggerHelper& loggerHelper)
     : m_inputSampleOffset(MediaTime::invalidTime())
     , m_maximumSampleCount(maximumSampleCount)
 #if !RELEASE_LOG_DISABLED
-    , m_logger(track.logger())
-    , m_logIdentifier(track.logIdentifier())
+    , m_logger(loggerHelper.logger())
+    , m_logIdentifier(loggerHelper.logIdentifier())
 #endif
 {
+#if RELEASE_LOG_DISABLED
+    UNUSED_PARAM(loggerHelper);
+#endif
 }
 
 AudioSampleDataSource::~AudioSampleDataSource()
index ed7993d..0efbf33 100644 (file)
@@ -48,7 +48,7 @@ public:
 class TrackPrivateBase
     : public ThreadSafeRefCounted<TrackPrivateBase, WTF::DestructionThread::Main>
 #if !RELEASE_LOG_DISABLED
-    , private LoggerHelper
+    , public LoggerHelper
 #endif
 {
     WTF_MAKE_NONCOPYABLE(TrackPrivateBase);
@@ -73,7 +73,7 @@ public:
     }
 
 #if !RELEASE_LOG_DISABLED
-    void setLogger(const Logger&, const void*);
+    virtual void setLogger(const Logger&, const void*);
     const Logger& logger() const final { ASSERT(m_logger); return *m_logger.get(); }
     const void* logIdentifier() const final { return m_logIdentifier; }
     WTFLogChannel& logChannel() const final;
index bc5f391..2fd3e73 100644 (file)
@@ -51,7 +51,7 @@ class Clock;
 
 namespace WebCore {
 
-class AudioTrackPrivateMediaStreamCocoa;
+class AudioTrackPrivateMediaStream;
 class AVVideoCaptureSource;
 class MediaSourcePrivateClient;
 class PixelBufferConformerCV;
@@ -249,7 +249,7 @@ private:
     };
     CurrentFramePainter m_imagePainter;
 
-    HashMap<String, RefPtr<AudioTrackPrivateMediaStreamCocoa>> m_audioTrackMap;
+    HashMap<String, RefPtr<AudioTrackPrivateMediaStream>> m_audioTrackMap;
     HashMap<String, RefPtr<VideoTrackPrivateMediaStream>> m_videoTrackMap;
     PendingSampleQueue m_pendingVideoSampleQueue;
 
index 6c5f50b..c5ed0a6 100644 (file)
@@ -28,7 +28,7 @@
 
 #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
 
-#import "AudioTrackPrivateMediaStreamCocoa.h"
+#import "AudioTrackPrivateMediaStream.h"
 #import "GraphicsContextCG.h"
 #import "Logging.h"
 #import "MediaStreamPrivate.h"
@@ -1033,7 +1033,7 @@ void MediaPlayerPrivateMediaStreamAVFObjC::updateTracks()
 {
     MediaStreamTrackPrivateVector currentTracks = m_mediaStreamPrivate->tracks();
 
-    auto setAudioTrackState = [this](AudioTrackPrivateMediaStreamCocoa& track, int index, TrackState state)
+    auto setAudioTrackState = [this](AudioTrackPrivateMediaStream& track, int index, TrackState state)
     {
         switch (state) {
         case TrackState::Remove:
@@ -1052,7 +1052,7 @@ void MediaPlayerPrivateMediaStreamAVFObjC::updateTracks()
             break;
         }
     };
-    updateTracksOfType(m_audioTrackMap, RealtimeMediaSource::Type::Audio, currentTracks, &AudioTrackPrivateMediaStreamCocoa::create, WTFMove(setAudioTrackState));
+    updateTracksOfType(m_audioTrackMap, RealtimeMediaSource::Type::Audio, currentTracks, &AudioTrackPrivateMediaStream::create, WTFMove(setAudioTrackState));
 
     auto setVideoTrackState = [this](VideoTrackPrivateMediaStream& track, int index, TrackState state)
     {
diff --git a/Source/WebCore/platform/mediastream/AudioMediaStreamTrackRenderer.cpp b/Source/WebCore/platform/mediastream/AudioMediaStreamTrackRenderer.cpp
new file mode 100644 (file)
index 0000000..b51649a
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2020 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. 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. OR 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 "AudioMediaStreamTrackRenderer.h"
+
+#if ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
+
+#if PLATFORM(COCOA)
+#include "AudioMediaStreamTrackRendererCocoa.h"
+#endif
+
+namespace WTF {
+class MediaTime;
+}
+
+namespace WebCore {
+
+AudioMediaStreamTrackRenderer::RendererCreator AudioMediaStreamTrackRenderer::m_rendererCreator = nullptr;
+void AudioMediaStreamTrackRenderer::setCreator(RendererCreator creator)
+{
+    m_rendererCreator = creator;
+}
+
+std::unique_ptr<AudioMediaStreamTrackRenderer> AudioMediaStreamTrackRenderer::create()
+{
+    if (m_rendererCreator)
+        return m_rendererCreator();
+
+#if PLATFORM(COCOA)
+    return makeUnique<AudioMediaStreamTrackRendererCocoa>();
+#else
+    return nullptr;
+#endif
+}
+
+#if !RELEASE_LOG_DISABLED
+void AudioMediaStreamTrackRenderer::setLogger(const Logger& logger, const void* identifier)
+{
+    m_logger = &logger;
+    m_logIdentifier = identifier;
+}
+
+WTFLogChannel& AudioMediaStreamTrackRenderer::logChannel() const
+{
+    return LogMedia;
+}
+#endif
+
+}
+
+#endif // ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mediastream/AudioMediaStreamTrackRenderer.h b/Source/WebCore/platform/mediastream/AudioMediaStreamTrackRenderer.h
new file mode 100644 (file)
index 0000000..800a930
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2020 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. 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. OR 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 ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
+
+#include <wtf/LoggerHelper.h>
+
+namespace WTF {
+class MediaTime;
+}
+
+namespace WebCore {
+
+class AudioStreamDescription;
+class PlatformAudioData;
+
+class WEBCORE_EXPORT AudioMediaStreamTrackRenderer : public LoggerHelper {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    static std::unique_ptr<AudioMediaStreamTrackRenderer> create();
+    virtual ~AudioMediaStreamTrackRenderer() = default;
+
+    virtual void setPaused(bool) = 0;
+    virtual void stop() = 0;
+    virtual void clear() = 0;
+    // May be called on a background thread.
+    virtual void pushSamples(const WTF::MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) = 0;
+
+    virtual void setMuted(bool);
+    virtual void setVolume(float);
+    float volume() const;
+
+#if !RELEASE_LOG_DISABLED
+    void setLogger(const Logger&, const void*);
+#endif
+
+    using RendererCreator = std::unique_ptr<AudioMediaStreamTrackRenderer> (*)();
+    static void setCreator(RendererCreator);
+
+protected:
+#if !RELEASE_LOG_DISABLED
+    const Logger& logger() const final;
+    const void* logIdentifier() const final;
+
+    const char* logClassName() const final;
+    WTFLogChannel& logChannel() const final;
+#endif
+
+    bool isMuted() const;
+
+private:
+    static RendererCreator m_rendererCreator;
+
+    // Main thread writable members
+    bool m_muted { false };
+    float m_volume { 1 };
+
+#if !RELEASE_LOG_DISABLED
+    RefPtr<const Logger> m_logger;
+    const void* m_logIdentifier;
+#endif
+};
+
+inline void AudioMediaStreamTrackRenderer::setMuted(bool value)
+{
+    m_muted = value;
+}
+
+inline void AudioMediaStreamTrackRenderer::setVolume(float volume)
+{
+    m_volume = volume;
+}
+
+inline float AudioMediaStreamTrackRenderer::volume() const
+{
+    return m_volume;
+}
+
+
+inline bool AudioMediaStreamTrackRenderer::isMuted() const
+{
+    return m_muted;
+}
+
+#if !RELEASE_LOG_DISABLED
+inline const Logger& AudioMediaStreamTrackRenderer::logger() const
+{
+    return *m_logger;
+    
+}
+
+inline const void* AudioMediaStreamTrackRenderer::logIdentifier() const
+{
+    return m_logIdentifier;
+}
+
+inline const char* AudioMediaStreamTrackRenderer::logClassName() const
+{
+    return "AudioMediaStreamTrackRenderer";
+}
+#endif
+
+}
+
+#endif // ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mediastream/AudioTrackPrivateMediaStream.cpp b/Source/WebCore/platform/mediastream/AudioTrackPrivateMediaStream.cpp
new file mode 100644 (file)
index 0000000..97d9e69
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2017-2020 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. 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. OR 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 "AudioTrackPrivateMediaStream.h"
+
+#if ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
+
+#include "AudioMediaStreamTrackRenderer.h"
+#include "Logging.h"
+
+namespace WebCore {
+
+AudioTrackPrivateMediaStream::AudioTrackPrivateMediaStream(MediaStreamTrackPrivate& track)
+    : m_streamTrack(track)
+    , m_id(track.id())
+    , m_label(track.label())
+    , m_timelineOffset(MediaTime::invalidTime())
+    , m_renderer { AudioMediaStreamTrackRenderer::create() }
+{
+    track.addObserver(*this);
+}
+
+AudioTrackPrivateMediaStream::~AudioTrackPrivateMediaStream()
+{
+    clear();
+}
+
+#if !RELEASE_LOG_DISABLED
+void AudioTrackPrivateMediaStream::setLogger(const Logger& logger, const void* identifier)
+{
+    TrackPrivateBase::setLogger(logger, identifier);
+    m_renderer->setLogger(logger, identifier);
+}
+#endif
+
+void AudioTrackPrivateMediaStream::clear()
+{
+    if (m_isCleared)
+        return;
+
+    m_isCleared = true;
+    streamTrack().removeObserver(*this);
+
+    m_renderer->clear();
+}
+
+void AudioTrackPrivateMediaStream::playInternal()
+{
+    ASSERT(isMainThread());
+
+    if (m_isPlaying)
+        return;
+
+    m_isPlaying = true;
+    m_autoPlay = false;
+
+    m_renderer->setPaused(false);
+}
+
+void AudioTrackPrivateMediaStream::play()
+{
+    playInternal();
+}
+
+void AudioTrackPrivateMediaStream::pause()
+{
+    ASSERT(isMainThread());
+
+    if (!m_isPlaying)
+        return;
+
+    m_isPlaying = false;
+    m_autoPlay = false;
+
+    m_renderer->setPaused(true);
+}
+
+void AudioTrackPrivateMediaStream::setVolume(float volume)
+{
+    m_renderer->setVolume(volume);
+}
+
+float AudioTrackPrivateMediaStream::volume() const
+{
+    return m_renderer->volume();
+}
+
+// May get called on a background thread.
+void AudioTrackPrivateMediaStream::audioSamplesAvailable(MediaStreamTrackPrivate&, const MediaTime& sampleTime, const PlatformAudioData& audioData, const AudioStreamDescription& description, size_t sampleCount)
+{
+    if (!m_isPlaying) {
+        m_renderer->stop();
+        return;
+    }
+
+    m_renderer->pushSamples(sampleTime, audioData, description, sampleCount);
+
+    if (m_autoPlay && !m_hasStartedAutoplay) {
+        m_hasStartedAutoplay = true;
+        callOnMainThread([this, protectedThis = makeRef(*this)] {
+            if (m_autoPlay)
+                playInternal();
+        });
+    }
+}
+
+void AudioTrackPrivateMediaStream::trackMutedChanged(MediaStreamTrackPrivate&)
+{
+    updateRendererMutedState();
+}
+
+void AudioTrackPrivateMediaStream::trackEnabledChanged(MediaStreamTrackPrivate&)
+{
+    updateRendererMutedState();
+}
+
+void AudioTrackPrivateMediaStream::updateRendererMutedState()
+{
+    m_renderer->setMuted(m_isPlaying && !streamTrack().muted() && !streamTrack().ended() && streamTrack().enabled());
+}
+
+void AudioTrackPrivateMediaStream::trackEnded(MediaStreamTrackPrivate&)
+{
+    pause();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
index dcd3aec..f325c6d 100644 (file)
 
 namespace WebCore {
 
-class AudioTrackPrivateMediaStream : public AudioTrackPrivate {
+class AudioMediaStreamTrackRenderer;
+
+class AudioTrackPrivateMediaStream final : public AudioTrackPrivate, private MediaStreamTrackPrivate::Observer {
     WTF_MAKE_NONCOPYABLE(AudioTrackPrivateMediaStream)
 public:
     static RefPtr<AudioTrackPrivateMediaStream> create(MediaStreamTrackPrivate& streamTrack)
     {
         return adoptRef(*new AudioTrackPrivateMediaStream(streamTrack));
     }
-
-    Kind kind() const override { return Kind::Main; }
-    AtomString id() const override { return m_id; }
-    AtomString label() const override { return m_label; }
-    AtomString language() const override { return emptyAtom(); }
-    int trackIndex() const override { return m_index; }
+    ~AudioTrackPrivateMediaStream();
 
     void setTrackIndex(int index) { m_index = index; }
 
@@ -53,20 +50,57 @@ public:
     MediaTime timelineOffset() const { return m_timelineOffset; }
     void setTimelineOffset(const MediaTime& offset) { m_timelineOffset = offset; }
 
+    void clear();
+
+    void play();
+    void pause();
+    bool isPlaying() { return m_isPlaying; }
+
+    void setVolume(float);
+    float volume() const;
+
+    void setMuted(bool muted) { m_muted = muted; }
+    bool muted() const { return m_muted; }
+
+#if !RELEASE_LOG_DISABLED
+    void setLogger(const Logger&, const void*) final;
+    const char* logClassName() const final { return "AudioTrackPrivateMediaStream"; }
+#endif
+
 protected:
-    AudioTrackPrivateMediaStream(MediaStreamTrackPrivate& track)
-        : m_streamTrack(track)
-        , m_id(track.id())
-        , m_label(track.label())
-        , m_timelineOffset(MediaTime::invalidTime())
-    {
-    }
+    explicit AudioTrackPrivateMediaStream(MediaStreamTrackPrivate&);
+
+    // AudioTrackPrivate
+    Kind kind() const final { return Kind::Main; }
+    AtomString id() const final { return m_id; }
+    AtomString label() const final { return m_label; }
+    int trackIndex() const final { return m_index; }
+
+    // MediaStreamTrackPrivate::Observer
+    void audioSamplesAvailable(MediaStreamTrackPrivate&, const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
+    void trackEnded(MediaStreamTrackPrivate&) final;
+    void trackMutedChanged(MediaStreamTrackPrivate&)  final;
+    void trackEnabledChanged(MediaStreamTrackPrivate&)  final;
+    void trackSettingsChanged(MediaStreamTrackPrivate&) final { }
+
+    void playInternal();
+    void updateRendererMutedState();
+
+    // Main thread writable members
+    bool m_isPlaying { false };
+    bool m_autoPlay { false };
+    bool m_muted { false };
+    bool m_isCleared { false };
 
     Ref<MediaStreamTrackPrivate> m_streamTrack;
     AtomString m_id;
     AtomString m_label;
     int m_index { 0 };
     MediaTime m_timelineOffset;
+
+    // Audio thread members
+    std::unique_ptr<AudioMediaStreamTrackRenderer> m_renderer;
+    bool m_hasStartedAutoplay { false };
 };
 
 }
index 00716fd..10b6703 100644 (file)
@@ -47,7 +47,7 @@ class MediaStreamTrackPrivate final
     , public CanMakeWeakPtr<MediaStreamTrackPrivate, WeakPtrFactoryInitialization::Eager>
     , public RealtimeMediaSource::Observer
 #if !RELEASE_LOG_DISABLED
-    , private LoggerHelper
+    , public LoggerHelper
 #endif
 {
 public:
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -24,7 +24,9 @@
  */
 
 #include "config.h"
-#include "AudioTrackPrivateMediaStreamCocoa.h"
+#include "AudioMediaStreamTrackRendererCocoa.h"
+
+#if ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
 
 #include "AudioSampleBufferList.h"
 #include "AudioSampleDataSource.h"
 #include <pal/cf/CoreMediaSoftLink.h>
 #include <pal/spi/cocoa/AudioToolboxSPI.h>
 
-#if ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
-
 namespace WebCore {
 
-AudioTrackPrivateMediaStreamCocoa::AudioTrackPrivateMediaStreamCocoa(MediaStreamTrackPrivate& track)
-    : AudioTrackPrivateMediaStream(track)
-{
-    track.source().addObserver(*this);
-}
+AudioMediaStreamTrackRendererCocoa::AudioMediaStreamTrackRendererCocoa() = default;
 
-AudioTrackPrivateMediaStreamCocoa::~AudioTrackPrivateMediaStreamCocoa()
-{
-    clear();
-}
+AudioMediaStreamTrackRendererCocoa::~AudioMediaStreamTrackRendererCocoa() = default;
 
-void AudioTrackPrivateMediaStreamCocoa::clear()
+void AudioMediaStreamTrackRendererCocoa::stop()
 {
-    if (m_isCleared)
+    if (!m_isAudioUnitStarted)
         return;
 
-    m_isCleared = true;
-    streamTrack().source().removeObserver(*this);
+    if (m_remoteIOUnit)
+        AudioOutputUnitStop(m_remoteIOUnit);
+}
 
+void AudioMediaStreamTrackRendererCocoa::clear()
+{
     if (m_dataSource)
         m_dataSource->setPaused(true);
 
@@ -72,47 +68,14 @@ void AudioTrackPrivateMediaStreamCocoa::clear()
     m_outputDescription = nullptr;
 }
 
-void AudioTrackPrivateMediaStreamCocoa::playInternal()
+void AudioMediaStreamTrackRendererCocoa::setPaused(bool value)
 {
-    ASSERT(isMainThread());
-
-    if (m_isPlaying)
-        return;
-
-    m_isPlaying = true;
-    m_autoPlay = false;
-
+    m_paused = value;
     if (m_dataSource)
-        m_dataSource->setPaused(false);
-}
-
-void AudioTrackPrivateMediaStreamCocoa::play()
-{
-    playInternal();
+        m_dataSource->setPaused(value);
 }
 
-void AudioTrackPrivateMediaStreamCocoa::pause()
-{
-    ASSERT(isMainThread());
-
-    if (!m_isPlaying)
-        return;
-
-    m_isPlaying = false;
-    m_autoPlay = false;
-
-    if (m_dataSource)
-        m_dataSource->setPaused(true);
-}
-
-void AudioTrackPrivateMediaStreamCocoa::setVolume(float volume)
-{
-    m_volume = volume;
-    if (m_dataSource)
-        m_dataSource->setVolume(m_volume);
-}
-
-AudioComponentInstance AudioTrackPrivateMediaStreamCocoa::createAudioUnit(CAAudioStreamDescription& outputDescription)
+AudioComponentInstance AudioMediaStreamTrackRendererCocoa::createAudioUnit(CAAudioStreamDescription& outputDescription)
 {
     AudioComponentInstance remoteIOUnit { nullptr };
 
@@ -177,19 +140,10 @@ AudioComponentInstance AudioTrackPrivateMediaStreamCocoa::createAudioUnit(CAAudi
 }
 
 // May get called on a background thread.
-void AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable(const MediaTime& sampleTime, const PlatformAudioData& audioData, const AudioStreamDescription& description, size_t sampleCount)
+void AudioMediaStreamTrackRendererCocoa::pushSamples(const MediaTime& sampleTime, const PlatformAudioData& audioData, const AudioStreamDescription& description, size_t sampleCount)
 {
     ASSERT(description.platformDescription().type == PlatformDescription::CAAudioStreamBasicType);
 
-    if (!m_isPlaying) {
-        if (m_isAudioUnitStarted) {
-            if (m_remoteIOUnit)
-                AudioOutputUnitStop(m_remoteIOUnit);
-            m_isAudioUnitStarted = false;
-        }
-        return;
-    }
-
     if (!m_inputDescription || *m_inputDescription != description) {
         m_isAudioUnitStarted = false;
 
@@ -212,7 +166,7 @@ void AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable(const MediaTime& s
         m_inputDescription = makeUnique<CAAudioStreamDescription>(inputDescription);
         m_outputDescription = makeUnique<CAAudioStreamDescription>(outputDescription);
 
-        m_dataSource = AudioSampleDataSource::create(description.sampleRate() * 2, streamTrack());
+        m_dataSource = AudioSampleDataSource::create(description.sampleRate() * 2, *this);
 
         if (m_dataSource->setInputFormat(inputDescription) || m_dataSource->setOutputFormat(outputDescription)) {
             AudioComponentInstanceDispose(remoteIOUnit);
@@ -228,20 +182,12 @@ void AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable(const MediaTime& s
 
         m_isAudioUnitStarted = true;
 
-        m_dataSource->setVolume(m_volume);
+        m_dataSource->setVolume(volume());
         m_remoteIOUnit = remoteIOUnit;
     }
 
     m_dataSource->pushSamples(sampleTime, audioData, sampleCount);
 
-    if (m_autoPlay && !m_hasStartedAutoplay) {
-        m_hasStartedAutoplay = true;
-        callOnMainThread([this, protectedThis = makeRef(*this)] {
-            if (m_autoPlay)
-                playInternal();
-        });
-    }
-
     if (!m_isAudioUnitStarted) {
         if (auto error = AudioOutputUnitStart(m_remoteIOUnit)) {
             ERROR_LOG(LOGIDENTIFIER, "AudioOutputUnitStart failed, error = ", error, " (", (const char*)&error, ")");
@@ -251,18 +197,9 @@ void AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable(const MediaTime& s
     }
 }
 
-void AudioTrackPrivateMediaStreamCocoa::sourceStopped()
+OSStatus AudioMediaStreamTrackRendererCocoa::render(UInt32 sampleCount, AudioBufferList& ioData, UInt32 /*inBusNumber*/, const AudioTimeStamp& timeStamp, AudioUnitRenderActionFlags& actionFlags)
 {
-    pause();
-}
-
-OSStatus AudioTrackPrivateMediaStreamCocoa::render(UInt32 sampleCount, AudioBufferList& ioData, UInt32 /*inBusNumber*/, const AudioTimeStamp& timeStamp, AudioUnitRenderActionFlags& actionFlags)
-{
-    // This function is called on a high-priority background thread. The following protectedThis object ensures the object is not
-    // destroyed on the main thread before this function exits.
-    Ref<AudioTrackPrivateMediaStreamCocoa> protectedThis { *this };
-
-    if (!m_isPlaying || m_muted || !m_dataSource || streamTrack().muted() || streamTrack().ended() || !streamTrack().enabled()) {
+    if (isMuted() || m_paused || !m_dataSource) {
         AudioSampleBufferList::zeroABL(ioData, static_cast<size_t>(sampleCount * m_outputDescription->bytesPerFrame()));
         actionFlags = kAudioUnitRenderAction_OutputIsSilence;
         return 0;
@@ -273,9 +210,9 @@ OSStatus AudioTrackPrivateMediaStreamCocoa::render(UInt32 sampleCount, AudioBuff
     return 0;
 }
 
-OSStatus AudioTrackPrivateMediaStreamCocoa::inputProc(void* userData, AudioUnitRenderActionFlags* actionFlags, const AudioTimeStamp* timeStamp, UInt32 inBusNumber, UInt32 sampleCount, AudioBufferList* ioData)
+OSStatus AudioMediaStreamTrackRendererCocoa::inputProc(void* userData, AudioUnitRenderActionFlags* actionFlags, const AudioTimeStamp* timeStamp, UInt32 inBusNumber, UInt32 sampleCount, AudioBufferList* ioData)
 {
-    return static_cast<AudioTrackPrivateMediaStreamCocoa*>(userData)->render(sampleCount, *ioData, inBusNumber, *timeStamp, *actionFlags);
+    return static_cast<AudioMediaStreamTrackRendererCocoa*>(userData)->render(sampleCount, *ioData, inBusNumber, *timeStamp, *actionFlags);
 }
 
 
@@ -27,7 +27,9 @@
 
 #if ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
 
-#include "AudioTrackPrivateMediaStream.h"
+#include "AudioMediaStreamTrackRenderer.h"
+#include "Logging.h"
+
 #include <AudioToolbox/AudioToolbox.h>
 #include <CoreAudio/CoreAudioTypes.h>
 
@@ -37,62 +39,33 @@ class AudioSampleDataSource;
 class AudioSampleBufferList;
 class CAAudioStreamDescription;
 
-class AudioTrackPrivateMediaStreamCocoa final : public AudioTrackPrivateMediaStream, private RealtimeMediaSource::Observer {
-    WTF_MAKE_NONCOPYABLE(AudioTrackPrivateMediaStreamCocoa)
+class AudioMediaStreamTrackRendererCocoa : public AudioMediaStreamTrackRenderer {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
-    static RefPtr<AudioTrackPrivateMediaStreamCocoa> create(MediaStreamTrackPrivate& streamTrack)
-    {
-        return adoptRef(*new AudioTrackPrivateMediaStreamCocoa(streamTrack));
-    }
-
-    void clear();
-
-    void play();
-    void pause();
-    bool isPlaying() { return m_isPlaying; }
-
-    void setVolume(float);
-    float volume() const { return m_volume; }
-
-    void setMuted(bool muted) { m_muted = muted; }
-    bool muted() const { return m_muted; }
+    AudioMediaStreamTrackRendererCocoa();
+    ~AudioMediaStreamTrackRendererCocoa();
 
 private:
-    AudioTrackPrivateMediaStreamCocoa(MediaStreamTrackPrivate&);
-    ~AudioTrackPrivateMediaStreamCocoa();
-
-    // RealtimeMediaSource::Observer
-    void sourceStopped() final;
-    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
+    // AudioMediaStreamTrackRenderer
+    void pushSamples(const WTF::MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
+    void stop() final;
+    void clear() final;
+    void setPaused(bool) final;
 
     static OSStatus inputProc(void*, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32 inBusNumber, UInt32 numberOfFrames, AudioBufferList*);
     OSStatus render(UInt32 sampleCount, AudioBufferList&, UInt32 inBusNumber, const AudioTimeStamp&, AudioUnitRenderActionFlags&);
 
     AudioComponentInstance createAudioUnit(CAAudioStreamDescription&);
-    void cleanup();
-    void zeroBufferList(AudioBufferList&, size_t);
-    void playInternal();
-
-#if !RELEASE_LOG_DISABLED
-    const char* logClassName() const final { return "AudioTrackPrivateMediaStreamCocoa"; }
-#endif
 
     // Audio thread members
     AudioComponentInstance m_remoteIOUnit { nullptr };
     std::unique_ptr<CAAudioStreamDescription> m_inputDescription;
     std::unique_ptr<CAAudioStreamDescription> m_outputDescription;
-    bool m_isAudioUnitStarted { false };
-    bool m_hasStartedAutoplay { false };
 
     // Cross thread members
     RefPtr<AudioSampleDataSource> m_dataSource;
-
-    // Main thread writable members
-    float m_volume { 1 };
-    bool m_isPlaying { false };
-    bool m_autoPlay { false };
-    bool m_muted { false };
-    bool m_isCleared { false };
+    bool m_isAudioUnitStarted { false };
+    bool m_paused { false };
 };
 
 }