Title: [277676] trunk/Source/WebCore
Revision
277676
Author
[email protected]
Date
2021-05-18 13:59:35 -0700 (Tue, 18 May 2021)

Log Message

[GPUP] RemoteAudioSession calls into AVAudioSession when GPUP is enabled, causing hangs
https://bugs.webkit.org/show_bug.cgi?id=223564
<rdar://74750291>

Reviewed by Eric Carlson.

Now that AudioSession can have two different implementations at runtime, it should be an
actual virtual class, whose concrete, per-platform implementations are derivations of the
base class. Make AudioSessionIOS and AudioSessionMac true subclasses of AudioSession, and
allow RemoteAudioSession to derive from that same base class (rather than AudioSessionIOS
or AudioSessionMac).

Also ensure AudioSessionIOS or AudioSessionMac is not accidentally created when calling
AudioSession::setSharedSession() by making the NeverDestroyed object holding the session
an Optional, and only lazily creating the session from AudioSession::sharedSession() if
one has not been explicitly set already.

* platform/audio/AudioSession.cpp:
(WebCore::sharedAudioSession):
(WebCore::AudioSession::create):
(WebCore::AudioSession::sharedSession):
(WebCore::AudioSession::addInterruptionObserver):
(WebCore::AudioSession::removeInterruptionObserver):
(WebCore::AudioSession::beginInterruption):
(WebCore::AudioSession::endInterruption):
(WebCore::AudioSession::setIsPlayingToBluetoothOverride):
(WebCore::AudioSession::AudioSession): Deleted.
* platform/audio/AudioSession.h:
* platform/audio/ios/AudioSessionIOS.h: Added.
* platform/audio/ios/AudioSessionIOS.mm:
(WebCore::AudioSessionIOS::AudioSessionIOS):
(WebCore::AudioSessionIOS::~AudioSessionIOS):
(WebCore::AudioSessionIOS::setCategory):
(WebCore::AudioSessionIOS::category const):
(WebCore::AudioSessionIOS::routeSharingPolicy const):
(WebCore::AudioSessionIOS::routingContextUID const):
(WebCore::AudioSessionIOS::setCategoryOverride):
(WebCore::AudioSessionIOS::categoryOverride const):
(WebCore::AudioSessionIOS::sampleRate const):
(WebCore::AudioSessionIOS::bufferSize const):
(WebCore::AudioSessionIOS::numberOfOutputChannels const):
(WebCore::AudioSessionIOS::maximumNumberOfOutputChannels const):
(WebCore::AudioSessionIOS::tryToSetActiveInternal):
(WebCore::AudioSessionIOS::preferredBufferSize const):
(WebCore::AudioSessionIOS::setPreferredBufferSize):
(WebCore::AudioSessionIOS::isMuted const):
(WebCore::AudioSessionIOS::handleMutedStateChange):
(WebCore::AudioSessionIOS::addInterruptionObserver):
(WebCore::AudioSessionIOS::removeInterruptionObserver):
(WebCore::AudioSessionIOS::beginInterruption):
(WebCore::AudioSessionIOS::endInterruption):
(WebCore::AudioSessionPrivate::AudioSessionPrivate): Deleted.
(WebCore::AudioSessionPrivate::~AudioSessionPrivate): Deleted.
(WebCore::AudioSession::AudioSession): Deleted.
(WebCore::AudioSession::~AudioSession): Deleted.
(WebCore::AudioSession::setCategory): Deleted.
(WebCore::AudioSession::category const): Deleted.
(WebCore::AudioSession::routeSharingPolicy const): Deleted.
(WebCore::AudioSession::routingContextUID const): Deleted.
(WebCore::AudioSession::setCategoryOverride): Deleted.
(WebCore::AudioSession::categoryOverride const): Deleted.
(WebCore::AudioSession::sampleRate const): Deleted.
(WebCore::AudioSession::bufferSize const): Deleted.
(WebCore::AudioSession::numberOfOutputChannels const): Deleted.
(WebCore::AudioSession::maximumNumberOfOutputChannels const): Deleted.
(WebCore::AudioSession::tryToSetActiveInternal): Deleted.
(WebCore::AudioSession::preferredBufferSize const): Deleted.
(WebCore::AudioSession::setPreferredBufferSize): Deleted.
(WebCore::AudioSession::isMuted const): Deleted.
(WebCore::AudioSession::handleMutedStateChange): Deleted.
(WebCore::AudioSession::addInterruptionObserver): Deleted.
(WebCore::AudioSession::removeInterruptionObserver): Deleted.
(WebCore::AudioSession::beginInterruption): Deleted.
(WebCore::AudioSession::endInterruption): Deleted.
* platform/audio/mac/AudioSessionMac.h: Added.
* platform/audio/mac/AudioSessionMac.mm:
(WebCore::AudioSessionMac::addSampleRateObserverIfNeeded const):
(WebCore::AudioSessionMac::handleSampleRateChange):
(WebCore::AudioSessionMac::addBufferSizeObserverIfNeeded const):
(WebCore::AudioSessionMac::handleBufferSizeChange):
(WebCore::AudioSessionMac::audioOutputDeviceChanged):
(WebCore::AudioSessionMac::setIsPlayingToBluetoothOverride):
(WebCore::AudioSessionMac::setCategory):
(WebCore::AudioSessionMac::setCategoryOverride):
(WebCore::AudioSessionMac::sampleRate const):
(WebCore::AudioSessionMac::bufferSize const):
(WebCore::AudioSessionMac::numberOfOutputChannels const):
(WebCore::AudioSessionMac::maximumNumberOfOutputChannels const):
(WebCore::AudioSessionMac::tryToSetActiveInternal):
(WebCore::AudioSessionMac::routeSharingPolicy const):
(WebCore::AudioSessionMac::routingContextUID const):
(WebCore::AudioSessionMac::preferredBufferSize const):
(WebCore::AudioSessionMac::setPreferredBufferSize):
(WebCore::AudioSessionMac::isMuted const):
(WebCore::AudioSessionMac::handleMutedStateChange):
(WebCore::AudioSessionMac::addMutedStateObserver):
(WebCore::AudioSessionMac::removeMutedStateObserver):
(): Deleted.
(WebCore::AudioSessionPrivate::addSampleRateObserverIfNeeded): Deleted.
(WebCore::AudioSessionPrivate::handleSampleRateChange): Deleted.
(WebCore::AudioSessionPrivate::addBufferSizeObserverIfNeeded): Deleted.
(WebCore::AudioSessionPrivate::handleBufferSizeChange): Deleted.
(WebCore::AudioSession::AudioSession): Deleted.
(WebCore::AudioSession::category const): Deleted.
(WebCore::AudioSession::audioOutputDeviceChanged): Deleted.
(WebCore::AudioSession::setIsPlayingToBluetoothOverride): Deleted.
(WebCore::AudioSession::setCategory): Deleted.
(WebCore::AudioSession::categoryOverride const): Deleted.
(WebCore::AudioSession::setCategoryOverride): Deleted.
(WebCore::AudioSession::sampleRate const): Deleted.
(WebCore::AudioSession::bufferSize const): Deleted.
(WebCore::AudioSession::numberOfOutputChannels const): Deleted.
(WebCore::AudioSession::maximumNumberOfOutputChannels const): Deleted.
(WebCore::AudioSession::tryToSetActiveInternal): Deleted.
(WebCore::AudioSession::routeSharingPolicy const): Deleted.
(WebCore::AudioSession::routingContextUID const): Deleted.
(WebCore::AudioSession::preferredBufferSize const): Deleted.
(WebCore::AudioSession::setPreferredBufferSize): Deleted.
(WebCore::AudioSession::isMuted const): Deleted.
(WebCore::AudioSession::handleMutedStateChange): Deleted.
(WebCore::AudioSession::addMutedStateObserver): Deleted.
(WebCore::AudioSession::removeMutedStateObserver): Deleted.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277675 => 277676)


--- trunk/Source/WebCore/ChangeLog	2021-05-18 20:58:33 UTC (rev 277675)
+++ trunk/Source/WebCore/ChangeLog	2021-05-18 20:59:35 UTC (rev 277676)
@@ -1,3 +1,128 @@
+2021-05-18  Jer Noble  <[email protected]>
+
+        [GPUP] RemoteAudioSession calls into AVAudioSession when GPUP is enabled, causing hangs
+        https://bugs.webkit.org/show_bug.cgi?id=223564
+        <rdar://74750291>
+
+        Reviewed by Eric Carlson.
+
+        Now that AudioSession can have two different implementations at runtime, it should be an
+        actual virtual class, whose concrete, per-platform implementations are derivations of the
+        base class. Make AudioSessionIOS and AudioSessionMac true subclasses of AudioSession, and
+        allow RemoteAudioSession to derive from that same base class (rather than AudioSessionIOS
+        or AudioSessionMac).
+
+        Also ensure AudioSessionIOS or AudioSessionMac is not accidentally created when calling
+        AudioSession::setSharedSession() by making the NeverDestroyed object holding the session
+        an Optional, and only lazily creating the session from AudioSession::sharedSession() if
+        one has not been explicitly set already.
+
+        * platform/audio/AudioSession.cpp:
+        (WebCore::sharedAudioSession):
+        (WebCore::AudioSession::create):
+        (WebCore::AudioSession::sharedSession):
+        (WebCore::AudioSession::addInterruptionObserver):
+        (WebCore::AudioSession::removeInterruptionObserver):
+        (WebCore::AudioSession::beginInterruption):
+        (WebCore::AudioSession::endInterruption):
+        (WebCore::AudioSession::setIsPlayingToBluetoothOverride):
+        (WebCore::AudioSession::AudioSession): Deleted.
+        * platform/audio/AudioSession.h:
+        * platform/audio/ios/AudioSessionIOS.h: Added.
+        * platform/audio/ios/AudioSessionIOS.mm:
+        (WebCore::AudioSessionIOS::AudioSessionIOS):
+        (WebCore::AudioSessionIOS::~AudioSessionIOS):
+        (WebCore::AudioSessionIOS::setCategory):
+        (WebCore::AudioSessionIOS::category const):
+        (WebCore::AudioSessionIOS::routeSharingPolicy const):
+        (WebCore::AudioSessionIOS::routingContextUID const):
+        (WebCore::AudioSessionIOS::setCategoryOverride):
+        (WebCore::AudioSessionIOS::categoryOverride const):
+        (WebCore::AudioSessionIOS::sampleRate const):
+        (WebCore::AudioSessionIOS::bufferSize const):
+        (WebCore::AudioSessionIOS::numberOfOutputChannels const):
+        (WebCore::AudioSessionIOS::maximumNumberOfOutputChannels const):
+        (WebCore::AudioSessionIOS::tryToSetActiveInternal):
+        (WebCore::AudioSessionIOS::preferredBufferSize const):
+        (WebCore::AudioSessionIOS::setPreferredBufferSize):
+        (WebCore::AudioSessionIOS::isMuted const):
+        (WebCore::AudioSessionIOS::handleMutedStateChange):
+        (WebCore::AudioSessionIOS::addInterruptionObserver):
+        (WebCore::AudioSessionIOS::removeInterruptionObserver):
+        (WebCore::AudioSessionIOS::beginInterruption):
+        (WebCore::AudioSessionIOS::endInterruption):
+        (WebCore::AudioSessionPrivate::AudioSessionPrivate): Deleted.
+        (WebCore::AudioSessionPrivate::~AudioSessionPrivate): Deleted.
+        (WebCore::AudioSession::AudioSession): Deleted.
+        (WebCore::AudioSession::~AudioSession): Deleted.
+        (WebCore::AudioSession::setCategory): Deleted.
+        (WebCore::AudioSession::category const): Deleted.
+        (WebCore::AudioSession::routeSharingPolicy const): Deleted.
+        (WebCore::AudioSession::routingContextUID const): Deleted.
+        (WebCore::AudioSession::setCategoryOverride): Deleted.
+        (WebCore::AudioSession::categoryOverride const): Deleted.
+        (WebCore::AudioSession::sampleRate const): Deleted.
+        (WebCore::AudioSession::bufferSize const): Deleted.
+        (WebCore::AudioSession::numberOfOutputChannels const): Deleted.
+        (WebCore::AudioSession::maximumNumberOfOutputChannels const): Deleted.
+        (WebCore::AudioSession::tryToSetActiveInternal): Deleted.
+        (WebCore::AudioSession::preferredBufferSize const): Deleted.
+        (WebCore::AudioSession::setPreferredBufferSize): Deleted.
+        (WebCore::AudioSession::isMuted const): Deleted.
+        (WebCore::AudioSession::handleMutedStateChange): Deleted.
+        (WebCore::AudioSession::addInterruptionObserver): Deleted.
+        (WebCore::AudioSession::removeInterruptionObserver): Deleted.
+        (WebCore::AudioSession::beginInterruption): Deleted.
+        (WebCore::AudioSession::endInterruption): Deleted.
+        * platform/audio/mac/AudioSessionMac.h: Added.
+        * platform/audio/mac/AudioSessionMac.mm:
+        (WebCore::AudioSessionMac::addSampleRateObserverIfNeeded const):
+        (WebCore::AudioSessionMac::handleSampleRateChange):
+        (WebCore::AudioSessionMac::addBufferSizeObserverIfNeeded const):
+        (WebCore::AudioSessionMac::handleBufferSizeChange):
+        (WebCore::AudioSessionMac::audioOutputDeviceChanged):
+        (WebCore::AudioSessionMac::setIsPlayingToBluetoothOverride):
+        (WebCore::AudioSessionMac::setCategory):
+        (WebCore::AudioSessionMac::setCategoryOverride):
+        (WebCore::AudioSessionMac::sampleRate const):
+        (WebCore::AudioSessionMac::bufferSize const):
+        (WebCore::AudioSessionMac::numberOfOutputChannels const):
+        (WebCore::AudioSessionMac::maximumNumberOfOutputChannels const):
+        (WebCore::AudioSessionMac::tryToSetActiveInternal):
+        (WebCore::AudioSessionMac::routeSharingPolicy const):
+        (WebCore::AudioSessionMac::routingContextUID const):
+        (WebCore::AudioSessionMac::preferredBufferSize const):
+        (WebCore::AudioSessionMac::setPreferredBufferSize):
+        (WebCore::AudioSessionMac::isMuted const):
+        (WebCore::AudioSessionMac::handleMutedStateChange):
+        (WebCore::AudioSessionMac::addMutedStateObserver):
+        (WebCore::AudioSessionMac::removeMutedStateObserver):
+        (): Deleted.
+        (WebCore::AudioSessionPrivate::addSampleRateObserverIfNeeded): Deleted.
+        (WebCore::AudioSessionPrivate::handleSampleRateChange): Deleted.
+        (WebCore::AudioSessionPrivate::addBufferSizeObserverIfNeeded): Deleted.
+        (WebCore::AudioSessionPrivate::handleBufferSizeChange): Deleted.
+        (WebCore::AudioSession::AudioSession): Deleted.
+        (WebCore::AudioSession::category const): Deleted.
+        (WebCore::AudioSession::audioOutputDeviceChanged): Deleted.
+        (WebCore::AudioSession::setIsPlayingToBluetoothOverride): Deleted.
+        (WebCore::AudioSession::setCategory): Deleted.
+        (WebCore::AudioSession::categoryOverride const): Deleted.
+        (WebCore::AudioSession::setCategoryOverride): Deleted.
+        (WebCore::AudioSession::sampleRate const): Deleted.
+        (WebCore::AudioSession::bufferSize const): Deleted.
+        (WebCore::AudioSession::numberOfOutputChannels const): Deleted.
+        (WebCore::AudioSession::maximumNumberOfOutputChannels const): Deleted.
+        (WebCore::AudioSession::tryToSetActiveInternal): Deleted.
+        (WebCore::AudioSession::routeSharingPolicy const): Deleted.
+        (WebCore::AudioSession::routingContextUID const): Deleted.
+        (WebCore::AudioSession::preferredBufferSize const): Deleted.
+        (WebCore::AudioSession::setPreferredBufferSize): Deleted.
+        (WebCore::AudioSession::isMuted const): Deleted.
+        (WebCore::AudioSession::handleMutedStateChange): Deleted.
+        (WebCore::AudioSession::addMutedStateObserver): Deleted.
+        (WebCore::AudioSession::removeMutedStateObserver): Deleted.
+
 2021-05-18  Chris Dumez  <[email protected]>
 
         Use UTF-8 internally from Strings inside SQLiteStatement

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (277675 => 277676)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-18 20:58:33 UTC (rev 277675)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-18 20:59:35 UTC (rev 277676)
@@ -4311,6 +4311,7 @@
 		CD336F6717FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD336F6517FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp */; };
 		CD336F6817FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6617FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h */; };
 		CD36C16B260A65CC00C8C529 /* SharedRoutingArbitrator.h in Headers */ = {isa = PBXBuildFile; fileRef = CD36C168260A63D300C8C529 /* SharedRoutingArbitrator.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		CD36C1622607E78600C8C529 /* AudioSessionIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = CD36C1612607E78600C8C529 /* AudioSessionIOS.h */; };
 		CD3A495F17A9D01B00274E42 /* MediaSource.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495617A9D01B00274E42 /* MediaSource.h */; };
 		CD3A496217A9D01B00274E42 /* SourceBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495917A9D01B00274E42 /* SourceBuffer.h */; };
 		CD3A496517A9D01B00274E42 /* SourceBufferList.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495C17A9D01B00274E42 /* SourceBufferList.h */; };
@@ -14854,6 +14855,8 @@
 		CD336F6617FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoTrackPrivateAVFObjC.h; sourceTree = "<group>"; };
 		CD36C168260A63D300C8C529 /* SharedRoutingArbitrator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedRoutingArbitrator.h; sourceTree = "<group>"; };
 		CD36C169260A63D400C8C529 /* SharedRoutingArbitrator.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedRoutingArbitrator.mm; sourceTree = "<group>"; };
+		CD36C15F26067C1F00C8C529 /* AudioSessionMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioSessionMac.h; sourceTree = "<group>"; };
+		CD36C1612607E78600C8C529 /* AudioSessionIOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioSessionIOS.h; sourceTree = "<group>"; };
 		CD37B37415C1A7E1006DC898 /* DiagnosticLoggingKeys.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DiagnosticLoggingKeys.cpp; sourceTree = "<group>"; };
 		CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiagnosticLoggingKeys.h; sourceTree = "<group>"; };
 		CD3A495517A9D01B00274E42 /* MediaSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaSource.cpp; sourceTree = "<group>"; };
@@ -28196,6 +28199,7 @@
 				CD55968F1475B678001D0BD0 /* AudioFileReaderIOS.cpp */,
 				CD5596901475B678001D0BD0 /* AudioFileReaderIOS.h */,
 				CD0EEE0B14743E35003EAFA2 /* AudioOutputUnitAdaptorIOS.cpp */,
+				CD36C1612607E78600C8C529 /* AudioSessionIOS.h */,
 				CDA79825170A279000D45C55 /* AudioSessionIOS.mm */,
 				CD875A742411B79800B09F58 /* MediaSessionHelperIOS.h */,
 				CD875A752411B79800B09F58 /* MediaSessionHelperIOS.mm */,
@@ -31274,6 +31278,7 @@
 				CD2F4A2518D8A3490063746D /* AudioHardwareListenerMac.cpp */,
 				CD2F4A2618D8A3490063746D /* AudioHardwareListenerMac.h */,
 				FD3160B612B0272A00C1A359 /* AudioOutputUnitAdaptorMac.cpp */,
+				CD36C15F26067C1F00C8C529 /* AudioSessionMac.h */,
 				CD54DE4917469C6D005E5B36 /* AudioSessionMac.mm */,
 				FD3160BA12B0272A00C1A359 /* FFTFrameMac.cpp */,
 				CD36C168260A63D300C8C529 /* SharedRoutingArbitrator.h */,
@@ -31597,6 +31602,7 @@
 				073B87691E4385AC0071C0EC /* AudioSampleDataSource.h in Headers */,
 				FD8C46EC154608E700A5910C /* AudioScheduledSourceNode.h in Headers */,
 				CDA7982A170A3D0000D45C55 /* AudioSession.h in Headers */,
+				CD36C1622607E78600C8C529 /* AudioSessionIOS.h in Headers */,
 				FD31608912B026F700C1A359 /* AudioSourceProvider.h in Headers */,
 				CD8A7BBC197735FE00CBD643 /* AudioSourceProviderAVFObjC.h in Headers */,
 				FD62F52E145898D80094B0ED /* AudioSourceProviderClient.h in Headers */,

Modified: trunk/Source/WebCore/platform/audio/AudioSession.cpp (277675 => 277676)


--- trunk/Source/WebCore/platform/audio/AudioSession.cpp	2021-05-18 20:58:33 UTC (rev 277675)
+++ trunk/Source/WebCore/platform/audio/AudioSession.cpp	2021-05-18 20:59:35 UTC (rev 277676)
@@ -31,22 +31,41 @@
 #include "NotImplemented.h"
 #include <wtf/NeverDestroyed.h>
 
+#if PLATFORM(MAC)
+#include "AudioSessionMac.h"
+#endif
+
+#if PLATFORM(IOS_FAMILY)
+#include "AudioSessionIOS.h"
+#endif
+
 namespace WebCore {
 
-static UniqueRef<AudioSession>& sharedAudioSession()
+static Optional<UniqueRef<AudioSession>>& sharedAudioSession()
 {
-    static NeverDestroyed<UniqueRef<AudioSession>> session = AudioSession::create();
+    static NeverDestroyed<Optional<UniqueRef<AudioSession>>> session;
     return session.get();
 }
 
 UniqueRef<AudioSession> AudioSession::create()
 {
+#if PLATFORM(MAC)
+    return makeUniqueRef<AudioSessionMac>();
+#elif PLATFORM(IOS_FAMILY)
+    return makeUniqueRef<AudioSessionIOS>();
+#else
     return makeUniqueRef<AudioSession>();
+#endif
 }
 
+AudioSession::AudioSession() = default;
+AudioSession::~AudioSession() = default;
+
 AudioSession& AudioSession::sharedSession()
 {
-    return sharedAudioSession();
+    if (!sharedAudioSession())
+        sharedAudioSession() = AudioSession::create();
+    return *sharedAudioSession();
 }
 
 void AudioSession::setSharedSession(UniqueRef<AudioSession>&& session)
@@ -63,37 +82,26 @@
     return true;
 }
 
-#if !PLATFORM(IOS_FAMILY)
 void AudioSession::addInterruptionObserver(InterruptionObserver&)
 {
+    notImplemented();
 }
 
 void AudioSession::removeInterruptionObserver(InterruptionObserver&)
 {
+    notImplemented();
 }
 
 void AudioSession::beginInterruption()
 {
+    notImplemented();
 }
 
 void AudioSession::endInterruption(MayResume)
 {
-}
-#endif
-
-#if !PLATFORM(COCOA)
-class AudioSessionPrivate {
-    WTF_MAKE_FAST_ALLOCATED;
-};
-
-AudioSession::AudioSession()
-    : m_private(nullptr)
-{
     notImplemented();
 }
 
-AudioSession::~AudioSession() = default;
-
 void AudioSession::setCategory(CategoryType, RouteSharingPolicy)
 {
     notImplemented();
@@ -167,9 +175,6 @@
     return emptyString();
 }
 
-#endif // !PLATFORM(COCOA)
-
-#if !PLATFORM(MAC)
 void AudioSession::audioOutputDeviceChanged()
 {
     notImplemented();
@@ -179,9 +184,7 @@
 {
     notImplemented();
 }
-#endif // !PLATFORM(COCOA)
 
-
 String convertEnumerationToString(RouteSharingPolicy enumerationValue)
 {
     static const NeverDestroyed<String> values[] = {

Modified: trunk/Source/WebCore/platform/audio/AudioSession.h (277675 => 277676)


--- trunk/Source/WebCore/platform/audio/AudioSession.h	2021-05-18 20:58:33 UTC (rev 277675)
+++ trunk/Source/WebCore/platform/audio/AudioSession.h	2021-05-18 20:59:35 UTC (rev 277676)
@@ -38,8 +38,6 @@
 
 namespace WebCore {
 
-class AudioSessionPrivate;
-
 enum class RouteSharingPolicy : uint8_t {
     Default,
     LongFormAudio,
@@ -72,8 +70,8 @@
     virtual void setCategory(CategoryType, RouteSharingPolicy);
     virtual CategoryType category() const;
 
-    void setCategoryOverride(CategoryType);
-    CategoryType categoryOverride() const;
+    virtual void setCategoryOverride(CategoryType);
+    virtual CategoryType categoryOverride() const;
 
     virtual RouteSharingPolicy routeSharingPolicy() const;
     virtual String routingContextUID() const;
@@ -95,18 +93,18 @@
         virtual void hardwareMutedStateDidChange(AudioSession*) = 0;
     };
 
-    void addMutedStateObserver(MutedStateObserver*);
-    void removeMutedStateObserver(MutedStateObserver*);
+    virtual void addMutedStateObserver(MutedStateObserver*) { }
+    virtual void removeMutedStateObserver(MutedStateObserver*) { }
 
-    void audioOutputDeviceChanged();
-    void setIsPlayingToBluetoothOverride(Optional<bool>);
+    virtual void audioOutputDeviceChanged();
+    virtual void setIsPlayingToBluetoothOverride(Optional<bool>);
 
-    virtual bool isMuted() const;
-    virtual void handleMutedStateChange();
+    virtual bool isMuted() const { return false; }
+    virtual void handleMutedStateChange() { }
 
-    void beginInterruption();
+    virtual void beginInterruption();
     enum class MayResume { No, Yes };
-    void endInterruption(MayResume);
+    virtual void endInterruption(MayResume);
 
     class InterruptionObserver : public CanMakeWeakPtr<InterruptionObserver> {
     public:
@@ -115,12 +113,12 @@
         virtual void beginAudioSessionInterruption() = 0;
         virtual void endAudioSessionInterruption(MayResume) = 0;
     };
-    void addInterruptionObserver(InterruptionObserver&);
-    void removeInterruptionObserver(InterruptionObserver&);
+    virtual void addInterruptionObserver(InterruptionObserver&);
+    virtual void removeInterruptionObserver(InterruptionObserver&);
 
     virtual bool isActive() const { return m_active; }
 
-    void setRoutingArbitrationClient(WeakPtr<AudioSessionRoutingArbitrationClient>&& client) { m_routingArbitrationClient = client; }
+    virtual void setRoutingArbitrationClient(WeakPtr<AudioSessionRoutingArbitrationClient>&& client) { m_routingArbitrationClient = client; }
 
 protected:
     friend class NeverDestroyed<AudioSession>;
@@ -128,7 +126,6 @@
 
     virtual bool tryToSetActiveInternal(bool);
 
-    std::unique_ptr<AudioSessionPrivate> m_private;
     HashSet<MutedStateObserver*> m_observers;
 #if PLATFORM(IOS_FAMILY)
     WeakHashSet<InterruptionObserver> m_interruptionObservers;

Added: trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h (0 => 277676)


--- trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h	2021-05-18 20:59:35 UTC (rev 277676)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2021 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 USE(AUDIO_SESSION) && PLATFORM(IOS_FAMILY)
+
+#include "AudioSession.h"
+
+OBJC_CLASS WebInterruptionObserverHelper;
+
+namespace WTF {
+class WorkQueue;
+}
+
+namespace WebCore {
+
+class AudioSessionIOS final : public AudioSession {
+public:
+    AudioSessionIOS();
+    virtual ~AudioSessionIOS();
+
+private:
+    // AudioSession
+    CategoryType category() const final;
+    void setCategory(CategoryType, RouteSharingPolicy) final;
+    AudioSession::CategoryType categoryOverride() const final;
+    void setCategoryOverride(CategoryType) final;
+    float sampleRate() const final;
+    size_t bufferSize() const final;
+    size_t numberOfOutputChannels() const final;
+    size_t maximumNumberOfOutputChannels() const final;
+    bool tryToSetActiveInternal(bool) final;
+    RouteSharingPolicy routeSharingPolicy() const final;
+    String routingContextUID() const final;
+    size_t preferredBufferSize() const final;
+    void setPreferredBufferSize(size_t) final;
+    bool isMuted() const final;
+    void handleMutedStateChange() final;
+    void addInterruptionObserver(InterruptionObserver&) final;
+    void removeInterruptionObserver(InterruptionObserver&) final;
+    void beginInterruption() final;
+    void endInterruption(MayResume) final;
+
+    AudioSession::CategoryType m_categoryOverride { AudioSession::CategoryType::None };
+    RefPtr<WTF::WorkQueue> m_workQueue;
+    RetainPtr<WebInterruptionObserverHelper> m_interruptionObserverHelper;
+};
+
+}
+
+#endif

Modified: trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm (277675 => 277676)


--- trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm	2021-05-18 20:58:33 UTC (rev 277675)
+++ trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm	2021-05-18 20:59:35 UTC (rev 277676)
@@ -24,7 +24,7 @@
  */
 
 #import "config.h"
-#import "AudioSession.h"
+#import "AudioSessionIOS.h"
 
 #if USE(AUDIO_SESSION) && PLATFORM(IOS_FAMILY)
 
@@ -96,41 +96,20 @@
 
 namespace WebCore {
 
-class AudioSessionPrivate {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    explicit AudioSessionPrivate(AudioSession*);
-    ~AudioSessionPrivate();
-
-    AudioSession::CategoryType m_categoryOverride;
-    RefPtr<WorkQueue> m_workQueue;
-    RetainPtr<WebInterruptionObserverHelper> m_interruptionObserverHelper;
-};
-
-AudioSessionPrivate::AudioSessionPrivate(AudioSession* session)
-    : m_categoryOverride(AudioSession::CategoryType::None)
+AudioSessionIOS::AudioSessionIOS()
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS
-    m_interruptionObserverHelper = adoptNS([[WebInterruptionObserverHelper alloc] initWithCallback:session]);
+    m_interruptionObserverHelper = adoptNS([[WebInterruptionObserverHelper alloc] initWithCallback:this]);
     END_BLOCK_OBJC_EXCEPTIONS
 }
 
-AudioSessionPrivate::~AudioSessionPrivate()
+AudioSessionIOS::~AudioSessionIOS()
 {
     [m_interruptionObserverHelper clearCallback];
 }
 
-AudioSession::AudioSession()
-    : m_private(makeUnique<AudioSessionPrivate>(this))
+void AudioSessionIOS::setCategory(CategoryType newCategory, RouteSharingPolicy policy)
 {
-}
-
-AudioSession::~AudioSession()
-{
-}
-
-void AudioSession::setCategory(CategoryType newCategory, RouteSharingPolicy policy)
-{
 #if !HAVE(ROUTE_SHARING_POLICY_LONG_FORM_VIDEO)
     if (policy == RouteSharingPolicy::LongFormVideo)
         policy = RouteSharingPolicy::LongFormAudio;
@@ -180,7 +159,7 @@
 #endif
 }
 
-AudioSession::CategoryType AudioSession::category() const
+AudioSession::CategoryType AudioSessionIOS::category() const
 {
     NSString *categoryString = [[PAL::getAVAudioSessionClass() sharedInstance] category];
     if ([categoryString isEqual:AVAudioSessionCategoryAmbient])
@@ -198,7 +177,7 @@
     return CategoryType::None;
 }
 
-RouteSharingPolicy AudioSession::routeSharingPolicy() const
+RouteSharingPolicy AudioSessionIOS::routeSharingPolicy() const
 {
     static_assert(static_cast<size_t>(RouteSharingPolicy::Default) == static_cast<size_t>(AVAudioSessionRouteSharingPolicyDefault), "RouteSharingPolicy::Default is not AVAudioSessionRouteSharingPolicyDefault as expected");
 #if HAVE(ROUTE_SHARING_POLICY_LONG_FORM_VIDEO)
@@ -216,7 +195,7 @@
     return static_cast<RouteSharingPolicy>(policy);
 }
 
-String AudioSession::routingContextUID() const
+String AudioSessionIOS::routingContextUID() const
 {
 #if !PLATFORM(IOS_FAMILY_SIMULATOR) && !PLATFORM(MACCATALYST) && !PLATFORM(WATCHOS)
     return [[PAL::getAVAudioSessionClass() sharedInstance] routingContextUID];
@@ -225,44 +204,44 @@
 #endif
 }
 
-void AudioSession::setCategoryOverride(CategoryType category)
+void AudioSessionIOS::setCategoryOverride(CategoryType category)
 {
-    if (m_private->m_categoryOverride == category)
+    if (m_categoryOverride == category)
         return;
 
-    m_private->m_categoryOverride = category;
+    m_categoryOverride = category;
     setCategory(category, RouteSharingPolicy::Default);
 }
 
-AudioSession::CategoryType AudioSession::categoryOverride() const
+AudioSession::CategoryType AudioSessionIOS::categoryOverride() const
 {
-    return m_private->m_categoryOverride;
+    return m_categoryOverride;
 }
 
-float AudioSession::sampleRate() const
+float AudioSessionIOS::sampleRate() const
 {
     return [[PAL::getAVAudioSessionClass() sharedInstance] sampleRate];
 }
 
-size_t AudioSession::bufferSize() const
+size_t AudioSessionIOS::bufferSize() const
 {
     return [[PAL::getAVAudioSessionClass() sharedInstance] IOBufferDuration] * sampleRate();
 }
 
-size_t AudioSession::numberOfOutputChannels() const
+size_t AudioSessionIOS::numberOfOutputChannels() const
 {
     return [[PAL::getAVAudioSessionClass() sharedInstance] outputNumberOfChannels];
 }
 
-size_t AudioSession::maximumNumberOfOutputChannels() const
+size_t AudioSessionIOS::maximumNumberOfOutputChannels() const
 {
     return [[PAL::getAVAudioSessionClass() sharedInstance] maximumOutputNumberOfChannels];
 }
 
-bool AudioSession::tryToSetActiveInternal(bool active)
+bool AudioSessionIOS::tryToSetActiveInternal(bool active)
 {
-    if (!m_private->m_workQueue)
-        m_private->m_workQueue = WorkQueue::create("AudioSession Activation Queue");
+    if (!m_workQueue)
+        m_workQueue = WorkQueue::create("AudioSession Activation Queue");
 
     // We need to deactivate the session on another queue because the AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation option
     // means that AVAudioSession may synchronously unduck previously ducked clients. Activation needs to complete before this method
@@ -269,7 +248,7 @@
     // returns, so do it synchronously on the same serial queue.
     if (active) {
         bool success = false;
-        m_private->m_workQueue->dispatchSync([&success] {
+        m_workQueue->dispatchSync([&success] {
             NSError *error = nil;
             [[PAL::getAVAudioSessionClass() sharedInstance] setActive:YES withOptions:0 error:&error];
             success = !error;
@@ -277,7 +256,7 @@
         return success;
     }
 
-    m_private->m_workQueue->dispatch([] {
+    m_workQueue->dispatch([] {
         NSError *error = nil;
         [[PAL::getAVAudioSessionClass() sharedInstance] setActive:NO withOptions:0 error:&error];
     });
@@ -285,12 +264,12 @@
     return true;
 }
 
-size_t AudioSession::preferredBufferSize() const
+size_t AudioSessionIOS::preferredBufferSize() const
 {
     return [[PAL::getAVAudioSessionClass() sharedInstance] preferredIOBufferDuration] * sampleRate();
 }
 
-void AudioSession::setPreferredBufferSize(size_t bufferSize)
+void AudioSessionIOS::setPreferredBufferSize(size_t bufferSize)
 {
     NSError *error = nil;
     float duration = bufferSize / sampleRate();
@@ -298,32 +277,32 @@
     ASSERT(!error);
 }
 
-bool AudioSession::isMuted() const
+bool AudioSessionIOS::isMuted() const
 {
     return false;
 }
 
-void AudioSession::handleMutedStateChange()
+void AudioSessionIOS::handleMutedStateChange()
 {
 }
 
-void AudioSession::addInterruptionObserver(InterruptionObserver& observer)
+void AudioSessionIOS::addInterruptionObserver(InterruptionObserver& observer)
 {
     m_interruptionObservers.add(observer);
 }
 
-void AudioSession::removeInterruptionObserver(InterruptionObserver& observer)
+void AudioSessionIOS::removeInterruptionObserver(InterruptionObserver& observer)
 {
     m_interruptionObservers.remove(observer);
 }
 
-void AudioSession::beginInterruption()
+void AudioSessionIOS::beginInterruption()
 {
     for (auto& observer : m_interruptionObservers)
         observer.beginAudioSessionInterruption();
 }
 
-void AudioSession::endInterruption(MayResume mayResume)
+void AudioSessionIOS::endInterruption(MayResume mayResume)
 {
     for (auto& observer : m_interruptionObservers)
         observer.endAudioSessionInterruption(mayResume);

Added: trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.h (0 => 277676)


--- trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.h	2021-05-18 20:59:35 UTC (rev 277676)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2021 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 USE(AUDIO_SESSION) && PLATFORM(MAC)
+
+#include "AudioSession.h"
+
+typedef UInt32 AudioObjectID;
+typedef struct AudioObjectPropertyAddress AudioObjectPropertyAddress;
+
+namespace WebCore {
+
+class AudioSessionMac final : public AudioSession {
+public:
+    AudioSessionMac() = default;
+    virtual ~AudioSessionMac() = default;
+
+private:
+    void addSampleRateObserverIfNeeded() const;
+    void addBufferSizeObserverIfNeeded() const;
+
+    static OSStatus handleSampleRateChange(AudioObjectID, UInt32, const AudioObjectPropertyAddress*, void* inClientData);
+    static OSStatus handleBufferSizeChange(AudioObjectID, UInt32, const AudioObjectPropertyAddress*, void* inClientData);
+
+    // AudioSession
+    CategoryType category() const final { return m_category; }
+    void audioOutputDeviceChanged() final;
+    void setIsPlayingToBluetoothOverride(Optional<bool>) final;
+    void setCategory(CategoryType, RouteSharingPolicy) final;
+    AudioSession::CategoryType categoryOverride() const final { return m_categoryOverride; }
+    void setCategoryOverride(CategoryType) final;
+    float sampleRate() const final;
+    size_t bufferSize() const final;
+    size_t numberOfOutputChannels() const final;
+    size_t maximumNumberOfOutputChannels() const final;
+    bool tryToSetActiveInternal(bool) final;
+    RouteSharingPolicy routeSharingPolicy() const final;
+    String routingContextUID() const final;
+    size_t preferredBufferSize() const final;
+    void setPreferredBufferSize(size_t) final;
+    bool isMuted() const final;
+    void handleMutedStateChange() final;
+    void addMutedStateObserver(MutedStateObserver*) final;
+    void removeMutedStateObserver(MutedStateObserver*) final;
+
+    Optional<bool> m_lastMutedState;
+    AudioSession::CategoryType m_category { AudioSession::CategoryType::None };
+#if ENABLE(ROUTING_ARBITRATION)
+    bool m_setupArbitrationOngoing { false };
+    bool m_inRoutingArbitration { false };
+    Optional<bool> m_playingToBluetooth;
+    Optional<bool> m_playingToBluetoothOverride;
+#endif
+    AudioSession::CategoryType m_categoryOverride { AudioSession::CategoryType::None };
+    mutable bool m_hasSampleRateObserver { false };
+    mutable bool m_hasBufferSizeObserver { false };
+    mutable Optional<double> m_sampleRate;
+    mutable Optional<size_t> m_bufferSize;
+};
+
+}
+
+#endif

Modified: trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm (277675 => 277676)


--- trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm	2021-05-18 20:58:33 UTC (rev 277675)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.mm	2021-05-18 20:59:35 UTC (rev 277676)
@@ -24,7 +24,7 @@
  */
 
 #import "config.h"
-#import "AudioSession.h"
+#import "AudioSessionMac.h"
 
 #if USE(AUDIO_SESSION) && PLATFORM(MAC)
 
@@ -90,37 +90,11 @@
 }
 #endif
 
-class AudioSessionPrivate {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    explicit AudioSessionPrivate() = default;
-
-    void addSampleRateObserverIfNeeded();
-    void addBufferSizeObserverIfNeeded();
-
-    static OSStatus handleSampleRateChange(AudioObjectID, UInt32, const AudioObjectPropertyAddress*, void* inClientData);
-    static OSStatus handleBufferSizeChange(AudioObjectID, UInt32, const AudioObjectPropertyAddress*, void* inClientData);
-
-    Optional<bool> lastMutedState;
-    AudioSession::CategoryType category { AudioSession::CategoryType::None };
-#if ENABLE(ROUTING_ARBITRATION)
-    bool setupArbitrationOngoing { false };
-    Optional<bool> playingToBluetooth;
-    Optional<bool> playingToBluetoothOverride;
-#endif
-    AudioSession::CategoryType m_categoryOverride;
-    bool inRoutingArbitration { false };
-    bool hasSampleRateObserver { false };
-    bool hasBufferSizeObserver { false };
-    Optional<double> sampleRate;
-    Optional<size_t> bufferSize;
-};
-
-void AudioSessionPrivate::addSampleRateObserverIfNeeded()
+void AudioSessionMac::addSampleRateObserverIfNeeded() const
 {
-    if (hasSampleRateObserver)
+    if (m_hasSampleRateObserver)
         return;
-    hasSampleRateObserver = true;
+    m_hasSampleRateObserver = true;
 
     AudioObjectPropertyAddress nominalSampleRateAddress = {
         kAudioDevicePropertyNominalSampleRate,
@@ -133,16 +107,16 @@
         ALLOW_DEPRECATED_DECLARATIONS_END
 #endif
     };
-    AudioObjectAddPropertyListener(defaultDevice(), &nominalSampleRateAddress, handleSampleRateChange, this);
+    AudioObjectAddPropertyListener(defaultDevice(), &nominalSampleRateAddress, handleSampleRateChange, const_cast<AudioSessionMac*>(this));
 }
 
-OSStatus AudioSessionPrivate::handleSampleRateChange(AudioObjectID device, UInt32, const AudioObjectPropertyAddress* sampleRateAddress, void* inClientData)
+OSStatus AudioSessionMac::handleSampleRateChange(AudioObjectID device, UInt32, const AudioObjectPropertyAddress* sampleRateAddress, void* inClientData)
 {
     ASSERT(inClientData);
     if (!inClientData)
         return noErr;
 
-    auto* sessionPrivate = static_cast<AudioSessionPrivate*>(inClientData);
+    auto* session = static_cast<AudioSessionMac*>(inClientData);
 
     Float64 nominalSampleRate;
     UInt32 nominalSampleRateSize = sizeof(Float64);
@@ -150,14 +124,15 @@
     if (result)
         return result;
 
-    sessionPrivate->sampleRate = narrowPrecisionToFloat(nominalSampleRate);
+    session->m_sampleRate = narrowPrecisionToFloat(nominalSampleRate);
     return noErr;
 }
 
-void AudioSessionPrivate::addBufferSizeObserverIfNeeded()
+void AudioSessionMac::addBufferSizeObserverIfNeeded() const
 {
-    if (hasBufferSizeObserver)
+    if (m_hasBufferSizeObserver)
         return;
+    m_hasBufferSizeObserver = true;
 
     AudioObjectPropertyAddress bufferSizeAddress = {
         kAudioDevicePropertyBufferFrameSize,
@@ -170,16 +145,16 @@
         ALLOW_DEPRECATED_DECLARATIONS_END
 #endif
     };
-    AudioObjectAddPropertyListener(defaultDevice(), &bufferSizeAddress, handleBufferSizeChange, this);
+    AudioObjectAddPropertyListener(defaultDevice(), &bufferSizeAddress, handleBufferSizeChange, const_cast<AudioSessionMac*>(this));
 }
 
-OSStatus AudioSessionPrivate::handleBufferSizeChange(AudioObjectID device, UInt32, const AudioObjectPropertyAddress* bufferSizeAddress, void* inClientData)
+OSStatus AudioSessionMac::handleBufferSizeChange(AudioObjectID device, UInt32, const AudioObjectPropertyAddress* bufferSizeAddress, void* inClientData)
 {
     ASSERT(inClientData);
     if (!inClientData)
         return noErr;
 
-    auto* sessionPrivate = static_cast<AudioSessionPrivate*>(inClientData);
+    auto* session = static_cast<AudioSessionMac*>(inClientData);
 
     UInt32 bufferSize;
     UInt32 bufferSizeSize = sizeof(bufferSize);
@@ -187,33 +162,21 @@
     if (result)
         return result;
 
-    sessionPrivate->bufferSize = bufferSize;
+    session->m_bufferSize = bufferSize;
     return noErr;
 }
 
-AudioSession::AudioSession()
-    : m_private(makeUnique<AudioSessionPrivate>())
+void AudioSessionMac::audioOutputDeviceChanged()
 {
-}
-
-AudioSession::~AudioSession() = default;
-
-AudioSession::CategoryType AudioSession::category() const
-{
-    return m_private->category;
-}
-
-void AudioSession::audioOutputDeviceChanged()
-{
 #if ENABLE(ROUTING_ARBITRATION)
-    if (!m_private->playingToBluetooth || *m_private->playingToBluetooth == defaultDeviceTransportIsBluetooth())
+    if (!m_playingToBluetooth || *m_playingToBluetooth == defaultDeviceTransportIsBluetooth())
         return;
 
-    m_private->playingToBluetooth = WTF::nullopt;
+    m_playingToBluetooth = WTF::nullopt;
 #endif
 }
 
-void AudioSession::setIsPlayingToBluetoothOverride(Optional<bool> value)
+void AudioSessionMac::setIsPlayingToBluetoothOverride(Optional<bool> value)
 {
 #if ENABLE(ROUTING_ARBITRATION)
     isPlayingToBluetoothOverride = value;
@@ -222,17 +185,17 @@
 #endif
 }
 
-void AudioSession::setCategory(CategoryType category, RouteSharingPolicy)
+void AudioSessionMac::setCategory(CategoryType category, RouteSharingPolicy)
 {
 #if ENABLE(ROUTING_ARBITRATION)
     bool playingToBluetooth = defaultDeviceTransportIsBluetooth();
-    if (category == m_private->category && m_private->playingToBluetooth && *m_private->playingToBluetooth == playingToBluetooth)
+    if (category == m_category && m_playingToBluetooth && *m_playingToBluetooth == playingToBluetooth)
         return;
 
-    m_private->category = category;
+    m_category = category;
 
-    if (m_private->setupArbitrationOngoing) {
-        RELEASE_LOG_ERROR(Media, "AudioSession::setCategory() - a beginArbitrationWithCategory is still ongoing");
+    if (m_setupArbitrationOngoing) {
+        RELEASE_LOG_ERROR(Media, "AudioSessionMac::setCategory() - a beginArbitrationWithCategory is still ongoing");
         return;
     }
 
@@ -239,8 +202,8 @@
     if (!m_routingArbitrationClient)
         return;
 
-    if (m_private->inRoutingArbitration) {
-        m_private->inRoutingArbitration = false;
+    if (m_inRoutingArbitration) {
+        m_inRoutingArbitration = false;
         m_routingArbitrationClient->leaveRoutingAbritration();
     }
 
@@ -250,44 +213,39 @@
     using RoutingArbitrationError = AudioSessionRoutingArbitrationClient::RoutingArbitrationError;
     using DefaultRouteChanged = AudioSessionRoutingArbitrationClient::DefaultRouteChanged;
 
-    m_private->playingToBluetooth = playingToBluetooth;
-    m_private->setupArbitrationOngoing = true;
-    m_routingArbitrationClient->beginRoutingArbitrationWithCategory(m_private->category, [this] (RoutingArbitrationError error, DefaultRouteChanged defaultRouteChanged) {
-        m_private->setupArbitrationOngoing = false;
+    m_playingToBluetooth = playingToBluetooth;
+    m_setupArbitrationOngoing = true;
+    m_routingArbitrationClient->beginRoutingArbitrationWithCategory(m_category, [this] (RoutingArbitrationError error, DefaultRouteChanged defaultRouteChanged) {
+        m_setupArbitrationOngoing = false;
         if (error != RoutingArbitrationError::None) {
-            RELEASE_LOG_ERROR(Media, "AudioSession::setCategory() - beginArbitrationWithCategory:%s failed with error %s", convertEnumerationToString(m_private->category).ascii().data(), convertEnumerationToString(error).ascii().data());
+            RELEASE_LOG_ERROR(Media, "AudioSessionMac::setCategory() - beginArbitrationWithCategory:%s failed with error %s", convertEnumerationToString(m_category).ascii().data(), convertEnumerationToString(error).ascii().data());
             return;
         }
 
-        m_private->inRoutingArbitration = true;
+        m_inRoutingArbitration = true;
 
         // FIXME: Do we need to reset sample rate and buffer size for the new default device?
         if (defaultRouteChanged == DefaultRouteChanged::Yes)
-            LOG(Media, "AudioSession::setCategory() - defaultRouteChanged!");
+            LOG(Media, "AudioSessionMac::setCategory() - defaultRouteChanged!");
     });
 #else
-    m_private->category = category;
+    m_category = category;
 #endif
 }
 
-AudioSession::CategoryType AudioSession::categoryOverride() const
+void AudioSessionMac::setCategoryOverride(CategoryType category)
 {
-    return m_private->m_categoryOverride;
-}
-
-void AudioSession::setCategoryOverride(CategoryType category)
-{
-    if (m_private->m_categoryOverride == category)
+    if (m_categoryOverride == category)
         return;
 
-    m_private->m_categoryOverride = category;
+    m_categoryOverride = category;
     setCategory(category, RouteSharingPolicy::Default);
 }
 
-float AudioSession::sampleRate() const
+float AudioSessionMac::sampleRate() const
 {
-    if (!m_private->sampleRate) {
-        m_private->addSampleRateObserverIfNeeded();
+    if (!m_sampleRate) {
+        addSampleRateObserverIfNeeded();
 
         Float64 nominalSampleRate;
         UInt32 nominalSampleRateSize = sizeof(Float64);
@@ -305,25 +263,25 @@
         };
         OSStatus result = AudioObjectGetPropertyData(defaultDevice(), &nominalSampleRateAddress, 0, 0, &nominalSampleRateSize, (void*)&nominalSampleRate);
         if (result != noErr) {
-            RELEASE_LOG_ERROR(Media, "AudioSession::sampleRate() - AudioObjectGetPropertyData() failed with error %d", result);
+            RELEASE_LOG_ERROR(Media, "AudioSessionMac::sampleRate() - AudioObjectGetPropertyData() failed with error %d", result);
             return 44100;
         }
 
-        m_private->sampleRate = narrowPrecisionToFloat(nominalSampleRate);
-        if (!*m_private->sampleRate) {
-            RELEASE_LOG_ERROR(Media, "AudioSession::sampleRate() - AudioObjectGetPropertyData() return an invalid sample rate");
-            m_private->sampleRate = 44100;
+        m_sampleRate = narrowPrecisionToFloat(nominalSampleRate);
+        if (!*m_sampleRate) {
+            RELEASE_LOG_ERROR(Media, "AudioSessionMac::sampleRate() - AudioObjectGetPropertyData() return an invalid sample rate");
+            m_sampleRate = 44100;
         }
     }
-    return *m_private->sampleRate;
+    return *m_sampleRate;
 }
 
-size_t AudioSession::bufferSize() const
+size_t AudioSessionMac::bufferSize() const
 {
-    if (m_private->bufferSize)
-        return *m_private->bufferSize;
+    if (m_bufferSize)
+        return *m_bufferSize;
 
-    m_private->addBufferSizeObserverIfNeeded();
+    addBufferSizeObserverIfNeeded();
 
     UInt32 bufferSize;
     UInt32 bufferSizeSize = sizeof(bufferSize);
@@ -344,18 +302,18 @@
     if (result)
         return 0;
 
-    m_private->bufferSize = bufferSize;
+    m_bufferSize = bufferSize;
 
     return bufferSize;
 }
 
-size_t AudioSession::numberOfOutputChannels() const
+size_t AudioSessionMac::numberOfOutputChannels() const
 {
     notImplemented();
     return 0;
 }
 
-size_t AudioSession::maximumNumberOfOutputChannels() const
+size_t AudioSessionMac::maximumNumberOfOutputChannels() const
 {
     AudioObjectPropertyAddress sizeAddress = {
         kAudioDevicePropertyStreamConfiguration,
@@ -387,30 +345,30 @@
     return channels;
 }
 
-bool AudioSession::tryToSetActiveInternal(bool)
+bool AudioSessionMac::tryToSetActiveInternal(bool)
 {
     notImplemented();
     return true;
 }
 
-RouteSharingPolicy AudioSession::routeSharingPolicy() const
+RouteSharingPolicy AudioSessionMac::routeSharingPolicy() const
 {
     return RouteSharingPolicy::Default;
 }
 
-String AudioSession::routingContextUID() const
+String AudioSessionMac::routingContextUID() const
 {
     return emptyString();
 }
 
-size_t AudioSession::preferredBufferSize() const
+size_t AudioSessionMac::preferredBufferSize() const
 {
     return bufferSize();
 }
 
-void AudioSession::setPreferredBufferSize(size_t bufferSize)
+void AudioSessionMac::setPreferredBufferSize(size_t bufferSize)
 {
-    if (m_private->bufferSize == bufferSize)
+    if (m_bufferSize == bufferSize)
         return;
 
     AudioValueRange bufferSizeRange = {0, 0};
@@ -449,17 +407,17 @@
     result = AudioObjectSetPropertyData(defaultDevice(), &preferredBufferSizeAddress, 0, 0, sizeof(bufferSizeOut), (void*)&bufferSizeOut);
 
     if (!result)
-        m_private->bufferSize = bufferSizeOut;
+        m_bufferSize = bufferSizeOut;
 
 #if !LOG_DISABLED
     if (result)
-        LOG(Media, "AudioSession::setPreferredBufferSize(%zu) - failed with error %d", bufferSize, static_cast<int>(result));
+        LOG(Media, "AudioSessionMac::setPreferredBufferSize(%zu) - failed with error %d", bufferSize, static_cast<int>(result));
     else
-        LOG(Media, "AudioSession::setPreferredBufferSize(%zu)", bufferSize);
+        LOG(Media, "AudioSessionMac::setPreferredBufferSize(%zu)", bufferSize);
 #endif
 }
 
-bool AudioSession::isMuted() const
+bool AudioSessionMac::isMuted() const
 {
     UInt32 mute = 0;
     UInt32 muteSize = sizeof(mute);
@@ -495,22 +453,19 @@
     return noErr;
 }
 
-void AudioSession::handleMutedStateChange()
+void AudioSessionMac::handleMutedStateChange()
 {
-    if (!m_private)
-        return;
-
     bool isCurrentlyMuted = isMuted();
-    if (m_private->lastMutedState && *m_private->lastMutedState == isCurrentlyMuted)
+    if (m_lastMutedState && *m_lastMutedState == isCurrentlyMuted)
         return;
 
     for (auto* observer : m_observers)
         observer->hardwareMutedStateDidChange(this);
 
-    m_private->lastMutedState = isCurrentlyMuted;
+    m_lastMutedState = isCurrentlyMuted;
 }
 
-void AudioSession::addMutedStateObserver(MutedStateObserver* observer)
+void AudioSessionMac::addMutedStateObserver(MutedStateObserver* observer)
 {
     m_observers.add(observer);
 
@@ -531,7 +486,7 @@
     AudioObjectAddPropertyListener(defaultDevice(), &muteAddress, handleMutePropertyChange, this);
 }
 
-void AudioSession::removeMutedStateObserver(MutedStateObserver* observer)
+void AudioSessionMac::removeMutedStateObserver(MutedStateObserver* observer)
 {
     if (m_observers.size() == 1) {
         AudioObjectPropertyAddress muteAddress = {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to