Refactoring: Remove AudioSourceObserverObjC and AudioCaptureSourceProviderObjC
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2017 21:33:39 +0000 (21:33 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2017 21:33:39 +0000 (21:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168520

Reviewed by Youenn Fablet.

Having AudioCaptureSourceProviderObjC as the type provided to WebAudioSourceProviderAVFObjC
(and only ever to WebAudioSourceProviderAVFObjC) makes it impossible for that class to add
an observer on RealtimeMediaSource, of which all classes inheriting from
WebAudioSourceProviderAVFObjC are subclasses. There is no need to treat
WebAudioSourceProviderAVFObjC as an "observer", since the only thing it will ever observe is
the object which created it and hold an explicit reference to it. So replace all instances
of the "observer" pattern with direct calls to the necessary (newly non-virtual) methods.
This allows WebAudioSourceProviderAVFObjC to register as an observer directly on
RealtimeMediaSource, to listen for audioSamplesAvailable() instead of process(), and remove
a lot of unnecessary conversion code and observer duplication.

* WebCore.xcodeproj/project.pbxproj:
* platform/mediastream/RealtimeMediaSource.h:
(WebCore::RealtimeMediaSource::Observer::sourceStopped):
(WebCore::RealtimeMediaSource::Observer::sourceMutedChanged):
(WebCore::RealtimeMediaSource::Observer::sourceEnabledChanged):
(WebCore::RealtimeMediaSource::Observer::sourceSettingsChanged):
(WebCore::RealtimeMediaSource::Observer::preventSourceFromStopping):
* platform/mediastream/mac/AVAudioCaptureSource.h:
* platform/mediastream/mac/AVAudioCaptureSource.mm:
(WebCore::AVAudioCaptureSource::shutdownCaptureSession):
(WebCore::AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection):
(WebCore::AVAudioCaptureSource::addObserver): Deleted.
(WebCore::AVAudioCaptureSource::removeObserver): Deleted.
(WebCore::AVAudioCaptureSource::start): Deleted.
* platform/mediastream/mac/AudioCaptureSourceProviderObjC.h: Removed.
* platform/mediastream/mac/AudioSourceObserverObjC.h: Removed.
* platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h:
* platform/mediastream/mac/MockRealtimeAudioSourceMac.h:
* platform/mediastream/mac/MockRealtimeAudioSourceMac.mm:
(WebCore::MockRealtimeAudioSourceMac::emitSampleBuffers):
(WebCore::MockRealtimeAudioSourceMac::reconfigure):
(WebCore::MockRealtimeAudioSourceMac::audioSourceProvider):
(WebCore::MockRealtimeAudioSourceMac::addObserver): Deleted.
(WebCore::MockRealtimeAudioSourceMac::removeObserver): Deleted.
(WebCore::MockRealtimeAudioSourceMac::start): Deleted.
* platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:
(WebCore::RealtimeIncomingAudioSource::audioSourceProvider):
(WebCore::RealtimeIncomingAudioSource::addObserver): Deleted.
(WebCore::RealtimeIncomingAudioSource::removeObserver): Deleted.
(WebCore::RealtimeIncomingAudioSource::start): Deleted.
* platform/mediastream/mac/RealtimeIncomingAudioSource.h:
* platform/mediastream/mac/RealtimeOutgoingAudioSource.h:
* platform/mediastream/mac/RealtimeOutgoingVideoSource.h:
* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h:
* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
(WebCore::WebAudioSourceProviderAVFObjC::create):
(WebCore::WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC):
(WebCore::WebAudioSourceProviderAVFObjC::setClient):
(WebCore::WebAudioSourceProviderAVFObjC::audioSamplesAvailable):
(WebCore::WebAudioSourceProviderAVFObjC::process): Deleted.

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/mediastream/RealtimeMediaSource.h
Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h
Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm
Source/WebCore/platform/mediastream/mac/AudioCaptureSourceProviderObjC.h [deleted file]
Source/WebCore/platform/mediastream/mac/AudioSourceObserverObjC.h [deleted file]
Source/WebCore/platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h
Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.h
Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.mm
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h
Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h
Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h
Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h
Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm

index 48f8b0d..f8e7b9b 100644 (file)
@@ -1,3 +1,62 @@
+2017-02-17  Jer Noble  <jer.noble@apple.com>
+
+        Refactoring: Remove AudioSourceObserverObjC and AudioCaptureSourceProviderObjC
+        https://bugs.webkit.org/show_bug.cgi?id=168520
+
+        Reviewed by Youenn Fablet.
+
+        Having AudioCaptureSourceProviderObjC as the type provided to WebAudioSourceProviderAVFObjC
+        (and only ever to WebAudioSourceProviderAVFObjC) makes it impossible for that class to add
+        an observer on RealtimeMediaSource, of which all classes inheriting from
+        WebAudioSourceProviderAVFObjC are subclasses. There is no need to treat
+        WebAudioSourceProviderAVFObjC as an "observer", since the only thing it will ever observe is
+        the object which created it and hold an explicit reference to it. So replace all instances
+        of the "observer" pattern with direct calls to the necessary (newly non-virtual) methods.
+        This allows WebAudioSourceProviderAVFObjC to register as an observer directly on
+        RealtimeMediaSource, to listen for audioSamplesAvailable() instead of process(), and remove
+        a lot of unnecessary conversion code and observer duplication.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/mediastream/RealtimeMediaSource.h:
+        (WebCore::RealtimeMediaSource::Observer::sourceStopped):
+        (WebCore::RealtimeMediaSource::Observer::sourceMutedChanged):
+        (WebCore::RealtimeMediaSource::Observer::sourceEnabledChanged):
+        (WebCore::RealtimeMediaSource::Observer::sourceSettingsChanged):
+        (WebCore::RealtimeMediaSource::Observer::preventSourceFromStopping):
+        * platform/mediastream/mac/AVAudioCaptureSource.h:
+        * platform/mediastream/mac/AVAudioCaptureSource.mm:
+        (WebCore::AVAudioCaptureSource::shutdownCaptureSession):
+        (WebCore::AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection):
+        (WebCore::AVAudioCaptureSource::addObserver): Deleted.
+        (WebCore::AVAudioCaptureSource::removeObserver): Deleted.
+        (WebCore::AVAudioCaptureSource::start): Deleted.
+        * platform/mediastream/mac/AudioCaptureSourceProviderObjC.h: Removed.
+        * platform/mediastream/mac/AudioSourceObserverObjC.h: Removed.
+        * platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h:
+        * platform/mediastream/mac/MockRealtimeAudioSourceMac.h:
+        * platform/mediastream/mac/MockRealtimeAudioSourceMac.mm:
+        (WebCore::MockRealtimeAudioSourceMac::emitSampleBuffers):
+        (WebCore::MockRealtimeAudioSourceMac::reconfigure):
+        (WebCore::MockRealtimeAudioSourceMac::audioSourceProvider):
+        (WebCore::MockRealtimeAudioSourceMac::addObserver): Deleted.
+        (WebCore::MockRealtimeAudioSourceMac::removeObserver): Deleted.
+        (WebCore::MockRealtimeAudioSourceMac::start): Deleted.
+        * platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:
+        (WebCore::RealtimeIncomingAudioSource::audioSourceProvider):
+        (WebCore::RealtimeIncomingAudioSource::addObserver): Deleted.
+        (WebCore::RealtimeIncomingAudioSource::removeObserver): Deleted.
+        (WebCore::RealtimeIncomingAudioSource::start): Deleted.
+        * platform/mediastream/mac/RealtimeIncomingAudioSource.h:
+        * platform/mediastream/mac/RealtimeOutgoingAudioSource.h:
+        * platform/mediastream/mac/RealtimeOutgoingVideoSource.h:
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h:
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
+        (WebCore::WebAudioSourceProviderAVFObjC::create):
+        (WebCore::WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC):
+        (WebCore::WebAudioSourceProviderAVFObjC::setClient):
+        (WebCore::WebAudioSourceProviderAVFObjC::audioSamplesAvailable):
+        (WebCore::WebAudioSourceProviderAVFObjC::process): Deleted.
+
 2017-02-17  Antoine Quint  <graouts@apple.com>
 
         REGRESSION: Subtitles menu in media controls allows multiple items to be selected
index 5487543..a4588b9 100644 (file)
                076970871463AD8700F502CF /* TextTrackList.h in Headers */ = {isa = PBXBuildFile; fileRef = 076970851463AD8700F502CF /* TextTrackList.h */; };
                076EC1331E44F56D00E5D813 /* AudioTrackPrivateMediaStreamCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 076EC1321E44F2CB00E5D813 /* AudioTrackPrivateMediaStreamCocoa.cpp */; };
                076F0D0E12B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 076F0D0A12B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.h */; };
-               07707CB01E205EE300005BF7 /* AudioSourceObserverObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 07707CAF1E205EC400005BF7 /* AudioSourceObserverObjC.h */; };
                077664FC183E6B5C00133B92 /* JSQuickTimePluginReplacement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 077664FA183E6B5C00133B92 /* JSQuickTimePluginReplacement.cpp */; };
                077664FD183E6B5C00133B92 /* JSQuickTimePluginReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 077664FB183E6B5C00133B92 /* JSQuickTimePluginReplacement.h */; };
                0779BF0E18453168000B6AE7 /* HTMLMediaElementMediaStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 0779BF0B18453168000B6AE7 /* HTMLMediaElementMediaStream.h */; };
                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>"; };
-               07707CAF1E205EC400005BF7 /* AudioSourceObserverObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSourceObserverObjC.h; sourceTree = "<group>"; };
-               07707CB11E20649C00005BF7 /* AudioCaptureSourceProviderObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioCaptureSourceProviderObjC.h; sourceTree = "<group>"; };
                077664FA183E6B5C00133B92 /* JSQuickTimePluginReplacement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSQuickTimePluginReplacement.cpp; sourceTree = "<group>"; };
                077664FB183E6B5C00133B92 /* JSQuickTimePluginReplacement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSQuickTimePluginReplacement.h; sourceTree = "<group>"; };
                0779BF0B18453168000B6AE7 /* HTMLMediaElementMediaStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLMediaElementMediaStream.h; sourceTree = "<group>"; };
                0729B14D17CFCCA0004F1D60 /* mac */ = {
                        isa = PBXGroup;
                        children = (
-                               07707CB11E20649C00005BF7 /* AudioCaptureSourceProviderObjC.h */,
-                               07707CAF1E205EC400005BF7 /* AudioSourceObserverObjC.h */,
                                076EC1321E44F2CB00E5D813 /* AudioTrackPrivateMediaStreamCocoa.cpp */,
                                07C046C61E42512F007201E7 /* AudioTrackPrivateMediaStreamCocoa.h */,
                                070363D8181A1CDC00C074A5 /* AVAudioCaptureSource.h */,
                                073B87691E4385AC0071C0EC /* AudioSampleDataSource.h in Headers */,
                                FD8C46EC154608E700A5910C /* AudioScheduledSourceNode.h in Headers */,
                                CDA7982A170A3D0000D45C55 /* AudioSession.h in Headers */,
-                               07707CB01E205EE300005BF7 /* AudioSourceObserverObjC.h in Headers */,
                                FD31608912B026F700C1A359 /* AudioSourceProvider.h in Headers */,
                                CD8A7BBC197735FE00CBD643 /* AudioSourceProviderAVFObjC.h in Headers */,
                                FD62F52E145898D80094B0ED /* AudioSourceProviderClient.h in Headers */,
index c48a19a..29d3d83 100644 (file)
@@ -67,13 +67,13 @@ public:
         virtual ~Observer() { }
         
         // Source state changes.
-        virtual void sourceStopped() = 0;
-        virtual void sourceMutedChanged() = 0;
-        virtual void sourceEnabledChanged() = 0;
-        virtual void sourceSettingsChanged() = 0;
+        virtual void sourceStopped() { }
+        virtual void sourceMutedChanged() { }
+        virtual void sourceEnabledChanged() { }
+        virtual void sourceSettingsChanged() { }
 
         // Observer state queries.
-        virtual bool preventSourceFromStopping() = 0;
+        virtual bool preventSourceFromStopping() { return false; }
         
         // Called on the main thread.
         virtual void videoSampleAvailable(MediaSample&) { }
index 9e5c856..4549abb 100644 (file)
@@ -29,7 +29,6 @@
 #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
 
 #include "AVMediaCaptureSource.h"
-#include "AudioCaptureSourceProviderObjC.h"
 #include "CAAudioStreamDescription.h"
 #include <wtf/Lock.h>
 
@@ -42,7 +41,7 @@ namespace WebCore {
 class WebAudioBufferList;
 class WebAudioSourceProviderAVFObjC;
 
-class AVAudioCaptureSource : public AVMediaCaptureSource, public AudioCaptureSourceProviderObjC {
+class AVAudioCaptureSource : public AVMediaCaptureSource {
 public:
 
     static RefPtr<AVMediaCaptureSource> create(AVCaptureDevice*, const AtomicString&, const MediaConstraints*, String&);
@@ -50,11 +49,6 @@ public:
 private:
     AVAudioCaptureSource(AVCaptureDevice*, const AtomicString&);
     virtual ~AVAudioCaptureSource();
-    
-    // AudioCaptureSourceProviderObjC
-    void addObserver(AudioSourceObserverObjC&) final;
-    void removeObserver(AudioSourceObserverObjC&) final;
-    void start() final;
 
     void initializeCapabilities(RealtimeMediaSourceCapabilities&) override;
     void initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints&) override;
@@ -71,7 +65,6 @@ private:
 
     RefPtr<WebAudioSourceProviderAVFObjC> m_audioSourceProvider;
     std::unique_ptr<CAAudioStreamDescription> m_inputDescription;
-    Vector<AudioSourceObserverObjC*> m_observers;
     Lock m_lock;
 };
 
index 3a613b0..8793ea8 100644 (file)
@@ -29,7 +29,6 @@
 #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
 
 #import "AudioSampleBufferList.h"
-#import "AudioSourceObserverObjC.h"
 #import "CAAudioStreamDescription.h"
 #import "Logging.h"
 #import "MediaConstraints.h"
@@ -117,25 +116,6 @@ void AVAudioCaptureSource::updateSettings(RealtimeMediaSourceSettings& settings)
     settings.setDeviceId(id());
 }
 
-void AVAudioCaptureSource::addObserver(AudioSourceObserverObjC& observer)
-{
-    LockHolder lock(m_lock);
-    m_observers.append(&observer);
-    if (m_inputDescription)
-        observer.prepare(&m_inputDescription->streamDescription());
-}
-
-void AVAudioCaptureSource::removeObserver(AudioSourceObserverObjC& observer)
-{
-    LockHolder lock(m_lock);
-    m_observers.removeFirst(&observer);
-}
-
-void AVAudioCaptureSource::start()
-{
-    startProducingData();
-}
-
 void AVAudioCaptureSource::setupCaptureSession()
 {
     RetainPtr<AVCaptureDeviceInputType> audioIn = adoptNS([allocAVCaptureDeviceInputInstance() initWithDevice:device() error:nil]);
@@ -165,9 +145,8 @@ void AVAudioCaptureSource::shutdownCaptureSession()
         m_audioConnection = nullptr;
         m_inputDescription = nullptr;
 
-        for (auto& observer : m_observers)
-            observer->unprepare();
-        m_observers.shrink(0);
+        if (m_audioSourceProvider)
+            m_audioSourceProvider->unprepare();
     }
 
     // Don't hold the lock when destroying the audio provider, it will call back into this object
@@ -194,20 +173,12 @@ void AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection(AVCa
     if (!m_inputDescription || *m_inputDescription != *streamDescription) {
         m_inputDescription = std::make_unique<CAAudioStreamDescription>(*streamDescription);
 
-        if (!m_observers.isEmpty()) {
-            for (auto& observer : m_observers)
-                observer->prepare(streamDescription);
-        }
+        if (m_audioSourceProvider)
+            m_audioSourceProvider->prepare(streamDescription);
     }
 
     m_list = std::make_unique<WebAudioBufferList>(*m_inputDescription, sampleBuffer);
     audioSamplesAvailable(toMediaTime(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)), *m_list, CAAudioStreamDescription(*streamDescription), CMSampleBufferGetNumSamples(sampleBuffer));
-
-    if (m_observers.isEmpty())
-        return;
-
-    for (auto& observer : m_observers)
-        observer->process(formatDescription, sampleBuffer);
 }
 
 AudioSourceProvider* AVAudioCaptureSource::audioSourceProvider()
diff --git a/Source/WebCore/platform/mediastream/mac/AudioCaptureSourceProviderObjC.h b/Source/WebCore/platform/mediastream/mac/AudioCaptureSourceProviderObjC.h
deleted file mode 100644 (file)
index edcbfb8..0000000
+++ /dev/null
@@ -1,50 +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.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
-
-typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
-typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
-typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
-
-namespace WebCore {
-
-class AudioSourceObserverObjC;
-
-class AudioCaptureSourceProviderObjC {
-public:
-    virtual ~AudioCaptureSourceProviderObjC() = default;
-
-    virtual void addObserver(AudioSourceObserverObjC&) = 0;
-    virtual void removeObserver(AudioSourceObserverObjC&) = 0;
-
-    virtual void start() = 0;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mediastream/mac/AudioSourceObserverObjC.h b/Source/WebCore/platform/mediastream/mac/AudioSourceObserverObjC.h
deleted file mode 100644 (file)
index 8097e7f..0000000
+++ /dev/null
@@ -1,47 +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.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
-
-typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
-typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
-typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
-
-namespace WebCore {
-
-class AudioSourceObserverObjC {
-public:
-    virtual ~AudioSourceObserverObjC() = default;
-
-    virtual void prepare(const AudioStreamBasicDescription*) = 0;
-    virtual void unprepare() = 0;
-    virtual void process(CMFormatDescriptionRef, CMSampleBufferRef) = 0;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
index 3aa38d5..48c1623 100644 (file)
@@ -27,7 +27,6 @@
 
 #if ENABLE(VIDEO_TRACK) && ENABLE(MEDIA_STREAM)
 
-#include "AudioSourceObserverObjC.h"
 #include "AudioTrackPrivateMediaStream.h"
 #include <AudioToolbox/AudioToolbox.h>
 #include <CoreAudio/CoreAudioTypes.h>
@@ -63,10 +62,6 @@ private:
 
     // RealtimeMediaSource::Observer
     void sourceStopped() final;
-    void sourceMutedChanged()  final { }
-    void sourceEnabledChanged() final { }
-    void sourceSettingsChanged() final { }
-    bool preventSourceFromStopping() final { return false; }
     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
 
     static OSStatus inputProc(void*, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32 inBusNumber, UInt32 numberOfFrames, AudioBufferList*);
index 915ce5f..c620199 100644 (file)
@@ -32,7 +32,6 @@
 
 #if ENABLE(MEDIA_STREAM)
 
-#include "AudioCaptureSourceProviderObjC.h"
 #include "FontCascade.h"
 #include "MockRealtimeAudioSource.h"
 #include <CoreAudio/CoreAudioTypes.h>
@@ -46,14 +45,7 @@ namespace WebCore {
 class WebAudioBufferList;
 class WebAudioSourceProviderAVFObjC;
 
-class MockRealtimeAudioSourceMac final : public MockRealtimeAudioSource, public AudioCaptureSourceProviderObjC {
-public:
-
-    // AudioCaptureSourceProviderObjC
-    void addObserver(AudioSourceObserverObjC&) final;
-    void removeObserver(AudioSourceObserverObjC&) final;
-    void start() final;
-
+class MockRealtimeAudioSourceMac final : public MockRealtimeAudioSource {
 private:
     friend class MockRealtimeAudioSource;
     MockRealtimeAudioSourceMac(const String&);
@@ -77,7 +69,6 @@ private:
     RetainPtr<CMFormatDescriptionRef> m_formatDescription;
     AudioStreamBasicDescription m_streamFormat;
     RefPtr<WebAudioSourceProviderAVFObjC> m_audioSourceProvider;
-    Vector<AudioSourceObserverObjC*> m_observers;
 };
 
 } // namespace WebCore
index 39940e6..0101dfb 100644 (file)
@@ -78,24 +78,6 @@ RefPtr<MockRealtimeAudioSource> MockRealtimeAudioSource::createMuted(const Strin
     return source;
 }
 
-void MockRealtimeAudioSourceMac::addObserver(AudioSourceObserverObjC& observer)
-{
-    m_observers.append(&observer);
-    if (m_streamFormat.mSampleRate)
-        observer.prepare(&m_streamFormat);
-}
-
-void MockRealtimeAudioSourceMac::removeObserver(AudioSourceObserverObjC& observer)
-{
-    m_observers.removeFirst(&observer);
-}
-
-void MockRealtimeAudioSourceMac::start()
-{
-    startProducingData();
-}
-
-
 void MockRealtimeAudioSourceMac::emitSampleBuffers(uint32_t frameCount)
 {
     ASSERT(m_formatDescription);
@@ -104,24 +86,6 @@ void MockRealtimeAudioSourceMac::emitSampleBuffers(uint32_t frameCount)
     m_bytesEmitted += frameCount;
 
     audioSamplesAvailable(toMediaTime(startTime), *m_audioBufferList, CAAudioStreamDescription(m_streamFormat), frameCount);
-
-    CMSampleBufferRef sampleBuffer;
-    OSStatus result = CMAudioSampleBufferCreateWithPacketDescriptions(nullptr, nullptr, true, nullptr, nullptr, m_formatDescription.get(), frameCount, startTime, nullptr, &sampleBuffer);
-    ASSERT(sampleBuffer);
-    ASSERT(!result);
-
-    if (!sampleBuffer)
-        return;
-
-    auto buffer = adoptCF(sampleBuffer);
-    result = CMSampleBufferSetDataBufferFromAudioBufferList(sampleBuffer, kCFAllocatorDefault, kCFAllocatorDefault, 0, m_audioBufferList->list());
-    ASSERT(!result);
-
-    result = CMSampleBufferSetDataReady(sampleBuffer);
-    ASSERT(!result);
-
-    for (const auto& observer : m_observers)
-        observer->process(m_formatDescription.get(), sampleBuffer);
 }
 
 void MockRealtimeAudioSourceMac::reconfigure()
@@ -142,9 +106,6 @@ void MockRealtimeAudioSourceMac::reconfigure()
     CMFormatDescriptionRef formatDescription;
     CMAudioFormatDescriptionCreate(NULL, &m_streamFormat, 0, NULL, 0, NULL, NULL, &formatDescription);
     m_formatDescription = adoptCF(formatDescription);
-
-    for (auto& observer : m_observers)
-        observer->prepare(&m_streamFormat);
 }
 
 void MockRealtimeAudioSourceMac::render(double delta)
@@ -222,8 +183,10 @@ bool MockRealtimeAudioSourceMac::applySampleRate(int sampleRate)
 
 AudioSourceProvider* MockRealtimeAudioSourceMac::audioSourceProvider()
 {
-    if (!m_audioSourceProvider)
+    if (!m_audioSourceProvider) {
         m_audioSourceProvider = WebAudioSourceProviderAVFObjC::create(*this);
+        m_audioSourceProvider->prepare(&m_streamFormat);
+    }
 
     return m_audioSourceProvider.get();
 }
index 9732b73..a57a9f1 100644 (file)
@@ -97,31 +97,13 @@ RealtimeMediaSourceSupportedConstraints& RealtimeIncomingAudioSource::supportedC
     return m_supportedConstraints;
 }
 
-void RealtimeIncomingAudioSource::addObserver(AudioSourceObserverObjC& observer)
-{
-    m_audioSourceObservers.append(observer);
-    if (m_formatDescription) {
-        const auto* description = CMAudioFormatDescriptionGetStreamBasicDescription(m_formatDescription.get());
-        observer.prepare(description);
-    }
-}
-
-void RealtimeIncomingAudioSource::removeObserver(AudioSourceObserverObjC& observer)
-{
-    m_audioSourceObservers.removeFirstMatching([&observer](const auto& registeredObserver) {
-        return &observer == &registeredObserver.get();
-    });
-}
-
-void RealtimeIncomingAudioSource::start()
-{
-    startProducingData();
-}
-
 AudioSourceProvider* RealtimeIncomingAudioSource::audioSourceProvider()
 {
-    if (!m_audioSourceProvider)
+    if (!m_audioSourceProvider) {
         m_audioSourceProvider = WebAudioSourceProviderAVFObjC::create(*this);
+        const auto* description = CMAudioFormatDescriptionGetStreamBasicDescription(m_formatDescription.get());
+        m_audioSourceProvider->prepare(description);
+    }
 
     return m_audioSourceProvider.get();
 }
index 32b146b..ce4faa2 100644 (file)
 
 #if USE(LIBWEBRTC)
 
-#include "AudioCaptureSourceProviderObjC.h"
 #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, private AudioCaptureSourceProviderObjC {
+class RealtimeIncomingAudioSource final : public RealtimeMediaSource, private webrtc::AudioTrackSinkInterface {
 public:
     static Ref<RealtimeIncomingAudioSource> create(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&, String&&);
 
@@ -67,11 +68,6 @@ private:
 
     AudioSourceProvider* audioSourceProvider() final;
 
-    // AudioCaptureSourceProviderObjC API
-    void addObserver(AudioSourceObserverObjC&) final;
-    void removeObserver(AudioSourceObserverObjC&) final;
-    void start() final;
-
     RealtimeMediaSourceSettings m_currentSettings;
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
     RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
@@ -81,7 +77,6 @@ private:
 
     RefPtr<WebAudioSourceProviderAVFObjC> m_audioSourceProvider;
     RetainPtr<CMFormatDescriptionRef> m_formatDescription;
-    Vector<std::reference_wrapper<AudioSourceObserverObjC>> m_audioSourceObservers;
 };
 
 } // namespace WebCore
index 0a5507d..f24036d 100644 (file)
@@ -63,11 +63,8 @@ private:
     void UnregisterObserver(webrtc::ObserverInterface*) final { }
 
     // RealtimeMediaSource::Observer API
-    void sourceStopped() final { }
     void sourceMutedChanged() final;
     void sourceEnabledChanged() final;
-    void sourceSettingsChanged() final { }
-    bool preventSourceFromStopping() final { return false; }
     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
 
     void pullAudioData();
index 3e6b7bd..4c6dc71 100644 (file)
@@ -66,11 +66,8 @@ private:
     void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>*) final;
 
     // RealtimeMediaSource::Observer API
-    bool preventSourceFromStopping() final { return false; }
-    void sourceStopped() final { }
     void sourceMutedChanged() final;
     void sourceEnabledChanged() final;
-    void sourceSettingsChanged() final { }
     void videoSampleAvailable(MediaSample&) final;
 
     Vector<rtc::VideoSinkInterface<webrtc::VideoFrame>*> m_sinks;
index 64a3e92..f906662 100644 (file)
@@ -27,9 +27,8 @@
 
 #if ENABLE(WEB_AUDIO) && ENABLE(MEDIA_STREAM)
 
-#include "AudioCaptureSourceProviderObjC.h"
-#include "AudioSourceObserverObjC.h"
 #include "AudioSourceProvider.h"
+#include "RealtimeMediaSource.h"
 #include <wtf/Lock.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -44,22 +43,23 @@ namespace WebCore {
 
 class CARingBuffer;
 
-class WebAudioSourceProviderAVFObjC : public RefCounted<WebAudioSourceProviderAVFObjC>, public AudioSourceProvider, public AudioSourceObserverObjC {
+class WebAudioSourceProviderAVFObjC : public RefCounted<WebAudioSourceProviderAVFObjC>, public AudioSourceProvider, RealtimeMediaSource::Observer {
 public:
-    static Ref<WebAudioSourceProviderAVFObjC> create(AudioCaptureSourceProviderObjC&);
+    static Ref<WebAudioSourceProviderAVFObjC> create(RealtimeMediaSource&);
     virtual ~WebAudioSourceProviderAVFObjC();
 
+    void prepare(const AudioStreamBasicDescription *);
+    void unprepare();
+
 private:
-    WebAudioSourceProviderAVFObjC(AudioCaptureSourceProviderObjC&);
+    WebAudioSourceProviderAVFObjC(RealtimeMediaSource&);
 
     // AudioSourceProvider
     void provideInput(AudioBus*, size_t) override;
     void setClient(AudioSourceProviderClient*) override;
 
-    // AudioSourceObserverObjC
-    void prepare(const AudioStreamBasicDescription *) final;
-    void unprepare() final;
-    void process(CMFormatDescriptionRef, CMSampleBufferRef) final;
+    // RealtimeMediaSource::Observer
+    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
 
     size_t m_listBufferSize { 0 };
     std::unique_ptr<AudioBufferList> m_list;
@@ -71,7 +71,7 @@ private:
     uint64_t m_writeCount { 0 };
     uint64_t m_readCount { 0 };
     AudioSourceProviderClient* m_client { nullptr };
-    AudioCaptureSourceProviderObjC* m_captureSource { nullptr };
+    RealtimeMediaSource* m_captureSource { nullptr };
     Lock m_mutex;
     bool m_connected { false };
 };
index 39b5df3..8ce694c 100644 (file)
@@ -34,6 +34,7 @@
 #import "CARingBuffer.h"
 #import "Logging.h"
 #import "MediaTimeAVFoundation.h"
+#import "WebAudioBufferList.h"
 #import <AudioToolbox/AudioToolbox.h>
 #import <objc/runtime.h>
 #import <wtf/MainThread.h>
@@ -53,12 +54,12 @@ namespace WebCore {
 
 static const double kRingBufferDuration = 1;
 
-Ref<WebAudioSourceProviderAVFObjC> WebAudioSourceProviderAVFObjC::create(AudioCaptureSourceProviderObjC& source)
+Ref<WebAudioSourceProviderAVFObjC> WebAudioSourceProviderAVFObjC::create(RealtimeMediaSource& source)
 {
     return adoptRef(*new WebAudioSourceProviderAVFObjC(source));
 }
 
-WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC(AudioCaptureSourceProviderObjC& source)
+WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC(RealtimeMediaSource& source)
     : m_captureSource(&source)
 {
 }
@@ -130,7 +131,7 @@ void WebAudioSourceProviderAVFObjC::setClient(AudioSourceProviderClient* client)
     if (m_client && !m_connected) {
         m_connected = true;
         m_captureSource->addObserver(*this);
-        m_captureSource->start();
+        m_captureSource->startProducingData();
     } else if (!m_client && m_connected) {
         m_captureSource->removeObserver(*this);
         m_connected = false;
@@ -219,24 +220,14 @@ void WebAudioSourceProviderAVFObjC::unprepare()
     }
 }
 
-void WebAudioSourceProviderAVFObjC::process(CMFormatDescriptionRef, CMSampleBufferRef sampleBuffer)
+void WebAudioSourceProviderAVFObjC::audioSamplesAvailable(const MediaTime&, const PlatformAudioData& data, const AudioStreamDescription&, size_t frameCount)
 {
-    std::lock_guard<Lock> lock(m_mutex);
-
-    if (!m_ringBuffer)
+    if (!m_ringBuffer || !is<WebAudioBufferList>(data))
         return;
 
-    CMItemCount frameCount = CMSampleBufferGetNumSamples(sampleBuffer);
-    CMBlockBufferRef buffer = nil;
-
-    OSStatus err = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, nullptr, m_list.get(), m_listBufferSize, kCFAllocatorSystemDefault, kCFAllocatorSystemDefault, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &buffer);
-
-    if (err) {
-        LOG(Media, "WebAudioSourceProviderAVFObjC::process(%p) - CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer returned error %i", this, err);
-        return;
-    }
+    auto& bufferList = downcast<WebAudioBufferList>(data);
 
-    m_ringBuffer->store(m_list.get(), frameCount, m_writeCount);
+    m_ringBuffer->store(bufferList.list(), frameCount, m_writeCount);
     m_writeCount += frameCount;
 }