Title: [289283] branches/safari-613-branch/Source
Revision
289283
Author
[email protected]
Date
2022-02-07 18:53:58 -0800 (Mon, 07 Feb 2022)

Log Message

Cherry-pick r288185. rdar://problem/87709485

    [Cocoa] Do not change preferred AudioSession buffer size when VPIO is running
    https://bugs.webkit.org/show_bug.cgi?id=235317
    <rdar://87709485>

    Reviewed by Eric Carlson.

    Source/WebCore:

    Add infra to be notified when audio capture unit is stopped.
    Add a check to return early with microphone sample callback if microphone samples are not to be processed.

    Manually tested.

    * platform/mediastream/mac/BaseAudioSharedUnit.cpp:
    * platform/mediastream/mac/BaseAudioSharedUnit.h:
    * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
    * platform/mediastream/mac/CoreAudioCaptureSource.h:

    Source/WebKit:

    When we stop capturing, we might still use the VPIO unit to render audio.
    In that case, it might be problematic to increase the preferred buffer size as:
    - Audio unit might stop running, hence stopping audio rendering
    - Increasing the preferred buffer size might increase latency which is not a good thing in VPIO usecases.

    * GPUProcess/media/RemoteAudioSessionProxy.cpp:
    * GPUProcess/media/RemoteAudioSessionProxyManager.cpp:
    * GPUProcess/media/RemoteAudioSessionProxyManager.h:

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

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (289282 => 289283)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-02-08 02:53:58 UTC (rev 289283)
@@ -1,5 +1,59 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288185. rdar://problem/87709485
+
+    [Cocoa] Do not change preferred AudioSession buffer size when VPIO is running
+    https://bugs.webkit.org/show_bug.cgi?id=235317
+    <rdar://87709485>
+    
+    Reviewed by Eric Carlson.
+    
+    Source/WebCore:
+    
+    Add infra to be notified when audio capture unit is stopped.
+    Add a check to return early with microphone sample callback if microphone samples are not to be processed.
+    
+    Manually tested.
+    
+    * platform/mediastream/mac/BaseAudioSharedUnit.cpp:
+    * platform/mediastream/mac/BaseAudioSharedUnit.h:
+    * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
+    * platform/mediastream/mac/CoreAudioCaptureSource.h:
+    
+    Source/WebKit:
+    
+    When we stop capturing, we might still use the VPIO unit to render audio.
+    In that case, it might be problematic to increase the preferred buffer size as:
+    - Audio unit might stop running, hence stopping audio rendering
+    - Increasing the preferred buffer size might increase latency which is not a good thing in VPIO usecases.
+    
+    * GPUProcess/media/RemoteAudioSessionProxy.cpp:
+    * GPUProcess/media/RemoteAudioSessionProxyManager.cpp:
+    * GPUProcess/media/RemoteAudioSessionProxyManager.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288185 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-19  Youenn Fablet  <[email protected]>
+
+            [Cocoa] Do not change preferred AudioSession buffer size when VPIO is running
+            https://bugs.webkit.org/show_bug.cgi?id=235317
+            <rdar://87709485>
+
+            Reviewed by Eric Carlson.
+
+            Add infra to be notified when audio capture unit is stopped.
+            Add a check to return early with microphone sample callback if microphone samples are not to be processed.
+
+            Manually tested.
+
+            * platform/mediastream/mac/BaseAudioSharedUnit.cpp:
+            * platform/mediastream/mac/BaseAudioSharedUnit.h:
+            * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
+            * platform/mediastream/mac/CoreAudioCaptureSource.h:
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288132. rdar://problem/87569029
 
     CSP: Improve handling of multiple policies

Modified: branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.cpp (289282 => 289283)


--- branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.cpp	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.cpp	2022-02-08 02:53:58 UTC (rev 289283)
@@ -186,6 +186,10 @@
 
     stopInternal();
     cleanupAudioUnit();
+
+    auto callbacks = std::exchange(m_whenNotRunningCallbacks, { });
+    for (auto& callback : callbacks)
+        callback();
 }
 
 void BaseAudioSharedUnit::setIsProducingMicrophoneSamples(bool value)
@@ -277,6 +281,15 @@
     }
 }
 
+void BaseAudioSharedUnit::whenAudioCaptureUnitIsNotRunning(Function<void()>&& callback)
+{
+    if (!isProducingData()) {
+        callback();
+        return;
+    }
+    m_whenNotRunningCallbacks.append(WTFMove(callback));
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)

Modified: branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.h (289282 => 289283)


--- branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.h	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.h	2022-02-08 02:53:58 UTC (rev 289283)
@@ -79,6 +79,7 @@
     virtual CapabilityValueOrRange sampleRateCapacities() const = 0;
 
     void devicesChanged(const Vector<CaptureDevice>&);
+    void whenAudioCaptureUnitIsNotRunning(Function<void()>&&);
 
 protected:
     void forEachClient(const Function<void(CoreAudioCaptureSource&)>&) const;
@@ -125,6 +126,7 @@
     Lock m_audioThreadClientsLock;
 
     bool m_isProducingMicrophoneSamples { true };
+    Vector<Function<void()>> m_whenNotRunningCallbacks;
 };
 
 } // namespace WebCore

Modified: branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp (289282 => 289283)


--- branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp	2022-02-08 02:53:58 UTC (rev 289283)
@@ -397,6 +397,9 @@
 
     ++m_microphoneProcsCalled;
 
+    if (!isProducingMicrophoneSamples())
+        return noErr;
+
     double adjustedHostTime = m_DTSConversionRatio * timeStamp.mHostTime;
     uint64_t sampleTime = timeStamp.mSampleTime;
 #if !LOG_DISABLED
@@ -738,6 +741,11 @@
     return CoreAudioSharedUnit::unit().isRunning();
 }
 
+void CoreAudioCaptureSourceFactory::whenAudioCaptureUnitIsNotRunning(Function<void()>&& callback)
+{
+    return CoreAudioSharedUnit::unit().whenAudioCaptureUnitIsNotRunning(WTFMove(callback));
+}
+
 CoreAudioCaptureSource::CoreAudioCaptureSource(String&& deviceID, String&& label, String&& hashSalt, uint32_t captureDeviceID, BaseAudioSharedUnit* overrideUnit)
     : RealtimeMediaSource(RealtimeMediaSource::Type::Audio, WTFMove(label), WTFMove(deviceID), WTFMove(hashSalt))
     , m_captureDeviceID(captureDeviceID)

Modified: branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h (289282 => 289283)


--- branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h	2022-02-08 02:53:58 UTC (rev 289283)
@@ -126,6 +126,7 @@
     WEBCORE_EXPORT void registerSpeakerSamplesProducer(CoreAudioSpeakerSamplesProducer&);
     WEBCORE_EXPORT void unregisterSpeakerSamplesProducer(CoreAudioSpeakerSamplesProducer&);
     WEBCORE_EXPORT bool isAudioCaptureUnitRunning();
+    WEBCORE_EXPORT void whenAudioCaptureUnitIsNotRunning(Function<void()>&&);
 
 private:
     CaptureSourceOrError createAudioCaptureSource(const CaptureDevice&, String&&, const MediaConstraints*) override;

Modified: branches/safari-613-branch/Source/WebKit/ChangeLog (289282 => 289283)


--- branches/safari-613-branch/Source/WebKit/ChangeLog	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog	2022-02-08 02:53:58 UTC (rev 289283)
@@ -1,5 +1,58 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288185. rdar://problem/87709485
+
+    [Cocoa] Do not change preferred AudioSession buffer size when VPIO is running
+    https://bugs.webkit.org/show_bug.cgi?id=235317
+    <rdar://87709485>
+    
+    Reviewed by Eric Carlson.
+    
+    Source/WebCore:
+    
+    Add infra to be notified when audio capture unit is stopped.
+    Add a check to return early with microphone sample callback if microphone samples are not to be processed.
+    
+    Manually tested.
+    
+    * platform/mediastream/mac/BaseAudioSharedUnit.cpp:
+    * platform/mediastream/mac/BaseAudioSharedUnit.h:
+    * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
+    * platform/mediastream/mac/CoreAudioCaptureSource.h:
+    
+    Source/WebKit:
+    
+    When we stop capturing, we might still use the VPIO unit to render audio.
+    In that case, it might be problematic to increase the preferred buffer size as:
+    - Audio unit might stop running, hence stopping audio rendering
+    - Increasing the preferred buffer size might increase latency which is not a good thing in VPIO usecases.
+    
+    * GPUProcess/media/RemoteAudioSessionProxy.cpp:
+    * GPUProcess/media/RemoteAudioSessionProxyManager.cpp:
+    * GPUProcess/media/RemoteAudioSessionProxyManager.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288185 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-19  Youenn Fablet  <[email protected]>
+
+            [Cocoa] Do not change preferred AudioSession buffer size when VPIO is running
+            https://bugs.webkit.org/show_bug.cgi?id=235317
+            <rdar://87709485>
+
+            Reviewed by Eric Carlson.
+
+            When we stop capturing, we might still use the VPIO unit to render audio.
+            In that case, it might be problematic to increase the preferred buffer size as:
+            - Audio unit might stop running, hence stopping audio rendering
+            - Increasing the preferred buffer size might increase latency which is not a good thing in VPIO usecases.
+
+            * GPUProcess/media/RemoteAudioSessionProxy.cpp:
+            * GPUProcess/media/RemoteAudioSessionProxyManager.cpp:
+            * GPUProcess/media/RemoteAudioSessionProxyManager.h:
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288178. rdar://problem/79296770
 
     REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus

Modified: branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxy.cpp (289282 => 289283)


--- branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxy.cpp	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxy.cpp	2022-02-08 02:53:58 UTC (rev 289283)
@@ -85,7 +85,7 @@
 void RemoteAudioSessionProxy::setPreferredBufferSize(uint64_t size)
 {
     m_preferredBufferSize = size;
-    audioSessionManager().setPreferredBufferSizeForProcess(*this, size);
+    audioSessionManager().updatePreferredBufferSizeForProcess();
 }
 
 void RemoteAudioSessionProxy::tryToSetActive(bool active, SetActiveCompletion&& completion)

Modified: branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp (289282 => 289283)


--- branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp	2022-02-08 02:53:58 UTC (rev 289283)
@@ -32,6 +32,7 @@
 #include "GPUProcessConnectionMessages.h"
 #include "RemoteAudioSessionProxy.h"
 #include <WebCore/AudioSession.h>
+#include <WebCore/CoreAudioCaptureSource.h>
 #include <wtf/HashCountedSet.h>
 
 namespace WebKit {
@@ -111,14 +112,25 @@
     AudioSession::sharedSession().setCategory(category, policy);
 }
 
-void RemoteAudioSessionProxyManager::setPreferredBufferSizeForProcess(RemoteAudioSessionProxy& proxy, size_t preferredBufferSize)
+void RemoteAudioSessionProxyManager::updatePreferredBufferSizeForProcess()
 {
-    for (auto& otherProxy : m_proxies) {
-        if (otherProxy.preferredBufferSize() && otherProxy.preferredBufferSize() < preferredBufferSize)
-            preferredBufferSize = otherProxy.preferredBufferSize();
+#if ENABLE(MEDIA_STREAM)
+    if (CoreAudioCaptureSourceFactory::singleton().isAudioCaptureUnitRunning()) {
+        CoreAudioCaptureSourceFactory::singleton().whenAudioCaptureUnitIsNotRunning([weakThis = WeakPtr { *this }] {
+            if (weakThis)
+                weakThis->updatePreferredBufferSizeForProcess();
+        });
+        return;
     }
+#endif
+    size_t preferredBufferSize = std::numeric_limits<size_t>::max();
+    for (auto& proxy : m_proxies) {
+        if (proxy.preferredBufferSize() && proxy.preferredBufferSize() < preferredBufferSize)
+            preferredBufferSize = proxy.preferredBufferSize();
+    }
 
-    AudioSession::sharedSession().setPreferredBufferSize(preferredBufferSize);
+    if (preferredBufferSize != std::numeric_limits<size_t>::max())
+        AudioSession::sharedSession().setPreferredBufferSize(preferredBufferSize);
 }
 
 bool RemoteAudioSessionProxyManager::tryToSetActiveForProcess(RemoteAudioSessionProxy& proxy, bool active)

Modified: branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.h (289282 => 289283)


--- branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.h	2022-02-08 02:53:53 UTC (rev 289282)
+++ branches/safari-613-branch/Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.h	2022-02-08 02:53:58 UTC (rev 289283)
@@ -37,7 +37,7 @@
 class RemoteAudioSessionProxy;
 
 class RemoteAudioSessionProxyManager
-    : private WebCore::AudioSession::InterruptionObserver
+    : public WebCore::AudioSession::InterruptionObserver
     , private WebCore::AudioSession::ConfigurationChangeObserver {
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -48,7 +48,7 @@
     void removeProxy(RemoteAudioSessionProxy&);
 
     void updateCategory();
-    void setPreferredBufferSizeForProcess(RemoteAudioSessionProxy&, size_t);
+    void updatePreferredBufferSizeForProcess();
 
     bool tryToSetActiveForProcess(RemoteAudioSessionProxy&, bool);
 
@@ -57,6 +57,9 @@
 
     void updatePresentingProcesses();
 
+    using WebCore::AudioSession::InterruptionObserver::weakPtrFactory;
+    using WeakValueType = WebCore::AudioSession::InterruptionObserver::WeakValueType;
+
 private:
     void beginAudioSessionInterruption() final;
     void endAudioSessionInterruption(WebCore::AudioSession::MayResume) final;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to