Title: [216446] trunk/Source
Revision
216446
Author
jer.no...@apple.com
Date
2017-05-08 13:03:46 -0700 (Mon, 08 May 2017)

Log Message

[Mac] Audio capture fails when shouldCaptureAudioInUIProcess is set.
https://bugs.webkit.org/show_bug.cgi?id=171710

Reviewed by Eric Carlson.

Source/WebCore:

Both the shouldCaptureAudioInUIProcess setting and useAVFoundationAudioCapture setting were trying to set
the audio factory for RealtimeMediaSourceCenter, and were stomping on each others' changes. Change the way
the useAVFoundationAudioCapture works so that it only affects the defaultAudioFactory, allowing that default
to be overridden by the shuoldCaptureAudioInUIProcess setting when it calls setAudioFactory().

* page/Settings.cpp:
(WebCore::Settings::setUseAVFoundationAudioCapture):
* platform/mediastream/RealtimeMediaSourceCenter.cpp:
(WebCore::RealtimeMediaSourceCenter::audioFactory):
(WebCore::RealtimeMediaSourceCenter::videoFactory):
(WebCore::RealtimeMediaSourceCenter::audioCaptureDeviceManager):
(WebCore::RealtimeMediaSourceCenter::videoCaptureDeviceManager):
* platform/mediastream/RealtimeMediaSourceCenter.h:
(WebCore::RealtimeMediaSourceCenter::audioFactory): Deleted.
(WebCore::RealtimeMediaSourceCenter::videoFactory): Deleted.
(WebCore::RealtimeMediaSourceCenter::audioCaptureDeviceManager): Deleted.
(WebCore::RealtimeMediaSourceCenter::videoCaptureDeviceManager): Deleted.
* platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp:
(WebCore::RealtimeMediaSourceCenterMac::setUseAVFoundationAudioCapture):
(WebCore::RealtimeMediaSourceCenterMac::singleton):
(WebCore::RealtimeMediaSourceCenter::platformCenter):
(WebCore::RealtimeMediaSourceCenterMac::defaultAudioFactory):
(WebCore::RealtimeMediaSourceCenterMac::defaultAudioCaptureDeviceManager):
* platform/mediastream/mac/RealtimeMediaSourceCenterMac.h:

Source/WebKit2:

RealtimeMediaSourceCenterMac's setUseAVFoundationAudioCapture() is now accessed via a singleton.

* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::UserMediaPermissionRequestManagerProxy::syncWithWebCorePrefs):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (216445 => 216446)


--- trunk/Source/WebCore/ChangeLog	2017-05-08 19:57:21 UTC (rev 216445)
+++ trunk/Source/WebCore/ChangeLog	2017-05-08 20:03:46 UTC (rev 216446)
@@ -1,3 +1,35 @@
+2017-05-08  Jer Noble  <jer.no...@apple.com>
+
+        [Mac] Audio capture fails when shouldCaptureAudioInUIProcess is set.
+        https://bugs.webkit.org/show_bug.cgi?id=171710
+
+        Reviewed by Eric Carlson.
+
+        Both the shouldCaptureAudioInUIProcess setting and useAVFoundationAudioCapture setting were trying to set
+        the audio factory for RealtimeMediaSourceCenter, and were stomping on each others' changes. Change the way
+        the useAVFoundationAudioCapture works so that it only affects the defaultAudioFactory, allowing that default
+        to be overridden by the shuoldCaptureAudioInUIProcess setting when it calls setAudioFactory().
+
+        * page/Settings.cpp:
+        (WebCore::Settings::setUseAVFoundationAudioCapture):
+        * platform/mediastream/RealtimeMediaSourceCenter.cpp:
+        (WebCore::RealtimeMediaSourceCenter::audioFactory):
+        (WebCore::RealtimeMediaSourceCenter::videoFactory):
+        (WebCore::RealtimeMediaSourceCenter::audioCaptureDeviceManager):
+        (WebCore::RealtimeMediaSourceCenter::videoCaptureDeviceManager):
+        * platform/mediastream/RealtimeMediaSourceCenter.h:
+        (WebCore::RealtimeMediaSourceCenter::audioFactory): Deleted.
+        (WebCore::RealtimeMediaSourceCenter::videoFactory): Deleted.
+        (WebCore::RealtimeMediaSourceCenter::audioCaptureDeviceManager): Deleted.
+        (WebCore::RealtimeMediaSourceCenter::videoCaptureDeviceManager): Deleted.
+        * platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp:
+        (WebCore::RealtimeMediaSourceCenterMac::setUseAVFoundationAudioCapture):
+        (WebCore::RealtimeMediaSourceCenterMac::singleton):
+        (WebCore::RealtimeMediaSourceCenter::platformCenter):
+        (WebCore::RealtimeMediaSourceCenterMac::defaultAudioFactory):
+        (WebCore::RealtimeMediaSourceCenterMac::defaultAudioCaptureDeviceManager):
+        * platform/mediastream/mac/RealtimeMediaSourceCenterMac.h:
+
 2017-05-04  Jiewen Tan  <jiewen_...@apple.com>
 
         Search events should not fire synchronously for search type input elements with incremental attribute set

Modified: trunk/Source/WebCore/page/Settings.cpp (216445 => 216446)


--- trunk/Source/WebCore/page/Settings.cpp	2017-05-08 19:57:21 UTC (rev 216445)
+++ trunk/Source/WebCore/page/Settings.cpp	2017-05-08 20:03:46 UTC (rev 216446)
@@ -630,7 +630,7 @@
 {
     gUseAVFoundationAudioCapture = useAVFoundationAudioCapture;
 #if USE(AVFOUNDATION)
-    RealtimeMediaSourceCenterMac::setUseAVFoundationAudioCapture(useAVFoundationAudioCapture);
+    RealtimeMediaSourceCenterMac::singleton().setUseAVFoundationAudioCapture(useAVFoundationAudioCapture);
 #endif
 }
 #endif

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp (216445 => 216446)


--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp	2017-05-08 19:57:21 UTC (rev 216445)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp	2017-05-08 20:03:46 UTC (rev 216446)
@@ -78,6 +78,11 @@
         m_audioFactory = nullptr;
 }
 
+RealtimeMediaSource::AudioCaptureFactory* RealtimeMediaSourceCenter::audioFactory()
+{
+    return m_audioFactory ? m_audioFactory: defaultAudioFactory();
+}
+
 void RealtimeMediaSourceCenter::setVideoFactory(RealtimeMediaSource::VideoCaptureFactory& factory)
 {
     m_videoFactory = &factory;
@@ -89,6 +94,11 @@
         m_videoFactory = nullptr;
 }
 
+RealtimeMediaSource::VideoCaptureFactory* RealtimeMediaSourceCenter::videoFactory()
+{
+    return m_videoFactory ? m_videoFactory : defaultVideoFactory();
+}
+
 void RealtimeMediaSourceCenter::setAudioCaptureDeviceManager(CaptureDeviceManager& deviceManager)
 {
     m_audioCaptureDeviceManager = &deviceManager;
@@ -100,6 +110,11 @@
         m_audioCaptureDeviceManager = nullptr;
 }
 
+CaptureDeviceManager* RealtimeMediaSourceCenter::audioCaptureDeviceManager()
+{
+    return m_audioCaptureDeviceManager ? m_audioCaptureDeviceManager : defaultAudioCaptureDeviceManager();
+}
+
 void RealtimeMediaSourceCenter::setVideoCaptureDeviceManager(CaptureDeviceManager& deviceManager)
 {
     m_videoCaptureDeviceManager = &deviceManager;
@@ -111,6 +126,11 @@
         m_videoCaptureDeviceManager = nullptr;
 }
 
+CaptureDeviceManager* RealtimeMediaSourceCenter::videoCaptureDeviceManager()
+{
+    return m_videoCaptureDeviceManager ? m_videoCaptureDeviceManager : defaultVideoCaptureDeviceManager();
+}
+
 static void addStringToSHA1(SHA1& sha1, const String& string)
 {
     if (string.isEmpty())

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h (216445 => 216446)


--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h	2017-05-08 19:57:21 UTC (rev 216445)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h	2017-05-08 20:03:46 UTC (rev 216446)
@@ -71,11 +71,11 @@
 
     WEBCORE_EXPORT void setAudioFactory(RealtimeMediaSource::AudioCaptureFactory&);
     WEBCORE_EXPORT void unsetAudioFactory(RealtimeMediaSource::AudioCaptureFactory&);
-    RealtimeMediaSource::AudioCaptureFactory* audioFactory() const { return m_audioFactory; }
+    WEBCORE_EXPORT RealtimeMediaSource::AudioCaptureFactory* audioFactory();
 
     WEBCORE_EXPORT void setVideoFactory(RealtimeMediaSource::VideoCaptureFactory&);
     WEBCORE_EXPORT void unsetVideoFactory(RealtimeMediaSource::VideoCaptureFactory&);
-    RealtimeMediaSource::VideoCaptureFactory* videoFactory() const { return m_videoFactory; }
+    WEBCORE_EXPORT RealtimeMediaSource::VideoCaptureFactory* videoFactory();
 
     virtual CaptureDeviceManager* defaultAudioCaptureDeviceManager() { return nullptr; }
     virtual CaptureDeviceManager* defaultVideoCaptureDeviceManager() { return nullptr; }
@@ -82,11 +82,11 @@
 
     WEBCORE_EXPORT void setAudioCaptureDeviceManager(CaptureDeviceManager&);
     WEBCORE_EXPORT void unsetAudioCaptureDeviceManager(CaptureDeviceManager&);
-    CaptureDeviceManager* audioCaptureDeviceManager() const { return m_audioCaptureDeviceManager; }
+    CaptureDeviceManager* audioCaptureDeviceManager();
 
     WEBCORE_EXPORT void setVideoCaptureDeviceManager(CaptureDeviceManager&);
     WEBCORE_EXPORT void unsetVideoCaptureDeviceManager(CaptureDeviceManager&);
-    CaptureDeviceManager* videoCaptureDeviceManager() const { return m_videoCaptureDeviceManager; }
+    CaptureDeviceManager* videoCaptureDeviceManager();
 
     String hashStringWithSalt(const String& id, const String& hashSalt);
     WEBCORE_EXPORT std::optional<CaptureDevice> captureDeviceWithUniqueID(const String& id, const String& hashSalt);

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp (216445 => 216446)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp	2017-05-08 19:57:21 UTC (rev 216445)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp	2017-05-08 20:03:46 UTC (rev 216446)
@@ -47,27 +47,10 @@
 
 void RealtimeMediaSourceCenterMac::setUseAVFoundationAudioCapture(bool enabled)
 {
-    static std::optional<bool> active = std::nullopt;
-    if (active && active.value() == enabled)
-        return;
-
-    active = enabled;
-    if (active.value()) {
-        RealtimeMediaSourceCenter::singleton().setAudioFactory(AVAudioCaptureSource::factory());
-        RealtimeMediaSourceCenter::singleton().setAudioCaptureDeviceManager(AVCaptureDeviceManager::singleton());
-    } else {
-        RealtimeMediaSourceCenter::singleton().setAudioFactory(CoreAudioCaptureSource::factory());
-#if PLATFORM(MAC)
-        RealtimeMediaSourceCenter::singleton().setAudioCaptureDeviceManager(CoreAudioCaptureDeviceManager::singleton());
-#else
-        RealtimeMediaSourceCenter::singleton().setAudioCaptureDeviceManager(AVAudioSessionCaptureDeviceManager::singleton());
-#endif
-    }
+    m_useAVFoundationAudioCapture = enabled;
 }
 
-
-
-RealtimeMediaSourceCenter& RealtimeMediaSourceCenter::platformCenter()
+RealtimeMediaSourceCenterMac& RealtimeMediaSourceCenterMac::singleton()
 {
     ASSERT(isMainThread());
     static NeverDestroyed<RealtimeMediaSourceCenterMac> center;
@@ -74,6 +57,11 @@
     return center;
 }
 
+RealtimeMediaSourceCenter& RealtimeMediaSourceCenter::platformCenter()
+{
+    return RealtimeMediaSourceCenterMac::singleton();
+}
+
 RealtimeMediaSourceCenterMac::RealtimeMediaSourceCenterMac()
 {
     m_supportedConstraints.setSupportsWidth(true);
@@ -87,17 +75,6 @@
     m_supportedConstraints.setSupportsEchoCancellation(false);
     m_supportedConstraints.setSupportsDeviceId(true);
     m_supportedConstraints.setSupportsGroupId(true);
-
-    m_audioFactory = &CoreAudioCaptureSource::factory();
-    m_videoFactory = &AVVideoCaptureSource::factory();
-
-#if PLATFORM(MAC)
-    m_audioCaptureDeviceManager = &CoreAudioCaptureDeviceManager::singleton();
-#else
-    // FIXME 170861: Use AVAudioSession to enumerate audio capture devices on iOS
-    m_audioCaptureDeviceManager = &AVCaptureDeviceManager::singleton();
-#endif
-    m_videoCaptureDeviceManager = &AVCaptureDeviceManager::singleton();
 }
 
 RealtimeMediaSourceCenterMac::~RealtimeMediaSourceCenterMac()
@@ -135,8 +112,8 @@
     Vector<Ref<RealtimeMediaSource>> videoSources;
     String invalidConstraint;
 
-    if (!audioDeviceID.isEmpty() && m_audioFactory) {
-        auto audioSource = m_audioFactory->createAudioCaptureSource(audioDeviceID, audioConstraints);
+    if (!audioDeviceID.isEmpty() && audioFactory()) {
+        auto audioSource = audioFactory()->createAudioCaptureSource(audioDeviceID, audioConstraints);
         if (audioSource)
             audioSources.append(audioSource.source());
 #if !LOG_DISABLED
@@ -144,8 +121,8 @@
             LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), audio constraints failed to apply: %s", this, audioSource.errorMessage.utf8().data());
 #endif
     }
-    if (!videoDeviceID.isEmpty() && m_videoFactory) {
-        auto videoSource = m_videoFactory->createVideoCaptureSource(videoDeviceID, videoConstraints);
+    if (!videoDeviceID.isEmpty() && videoFactory()) {
+        auto videoSource = videoFactory()->createVideoCaptureSource(videoDeviceID, videoConstraints);
         if (videoSource)
             videoSources.append(videoSource.source());
 #if !LOG_DISABLED
@@ -164,11 +141,11 @@
 {
     Vector<CaptureDevice> result;
 
-    if (m_audioCaptureDeviceManager)
-        result.appendVector(m_audioCaptureDeviceManager->getAudioSourcesInfo());
+    if (auto audioDeviceManager = audioCaptureDeviceManager())
+        result.appendVector(audioDeviceManager->getAudioSourcesInfo());
 
-    if (m_videoCaptureDeviceManager)
-        result.appendVector(m_videoCaptureDeviceManager->getVideoSourcesInfo());
+    if (auto videoDeviceManager = videoCaptureDeviceManager())
+        result.appendVector(videoDeviceManager->getVideoSourcesInfo());
 
     return result;
 }
@@ -190,10 +167,10 @@
             continue;
 
         CaptureSourceOrError sourceOrError;
-        if (type == RealtimeMediaSource::Type::Video && m_videoFactory)
-            sourceOrError = m_videoFactory->createVideoCaptureSource(captureDevice.persistentId(), &constraints);
-        else if (type == RealtimeMediaSource::Type::Audio && m_audioFactory)
-            sourceOrError = m_audioFactory->createAudioCaptureSource(captureDevice.persistentId(), &constraints);
+        if (type == RealtimeMediaSource::Type::Video && videoFactory())
+            sourceOrError = videoFactory()->createVideoCaptureSource(captureDevice.persistentId(), &constraints);
+        else if (type == RealtimeMediaSource::Type::Audio && audioFactory())
+            sourceOrError = audioFactory()->createAudioCaptureSource(captureDevice.persistentId(), &constraints);
 
         if (!sourceOrError) {
             // FIXME: Handle the case of invalid constraints on more than one device.
@@ -217,7 +194,7 @@
 
 RealtimeMediaSource::AudioCaptureFactory* RealtimeMediaSourceCenterMac::defaultAudioFactory()
 {
-    return &CoreAudioCaptureSource::factory();
+    return m_useAVFoundationAudioCapture ? &AVAudioCaptureSource::factory() : &CoreAudioCaptureSource::factory();
 }
 
 RealtimeMediaSource::VideoCaptureFactory* RealtimeMediaSourceCenterMac::defaultVideoFactory()
@@ -225,6 +202,22 @@
     return &AVVideoCaptureSource::factory();
 }
 
+CaptureDeviceManager* RealtimeMediaSourceCenterMac::defaultAudioCaptureDeviceManager()
+{
+    if (m_useAVFoundationAudioCapture)
+        return &AVCaptureDeviceManager::singleton();
+#if PLATFORM(MAC)
+    return &CoreAudioCaptureDeviceManager::singleton();
+#else
+    return &AVAudioSessionCaptureDeviceManager::singleton();
+#endif
+}
+
+CaptureDeviceManager* RealtimeMediaSourceCenterMac::defaultVideoCaptureDeviceManager()
+{
+    return &AVCaptureDeviceManager::singleton();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.h (216445 => 216446)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.h	2017-05-08 19:57:21 UTC (rev 216445)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.h	2017-05-08 20:03:46 UTC (rev 216446)
@@ -42,10 +42,12 @@
 
 class RealtimeMediaSourceCenterMac final : public RealtimeMediaSourceCenter {
 public:
-    RealtimeMediaSourceCenterMac();
+    WEBCORE_EXPORT static RealtimeMediaSourceCenterMac& singleton();
 
-    WEBCORE_EXPORT static void setUseAVFoundationAudioCapture(bool enabled);
+    WEBCORE_EXPORT void setUseAVFoundationAudioCapture(bool enabled);
 private:
+    friend class NeverDestroyed<RealtimeMediaSourceCenterMac>;
+    RealtimeMediaSourceCenterMac();
     ~RealtimeMediaSourceCenterMac();
 
     void validateRequestConstraints(ValidConstraintsHandler&& validHandler, InvalidConstraintsHandler&& invalidHandler, const MediaConstraints& audioConstraints, const MediaConstraints& videoConstraints) final;
@@ -56,6 +58,11 @@
 
     RealtimeMediaSource::AudioCaptureFactory* defaultAudioFactory() final;
     RealtimeMediaSource::VideoCaptureFactory* defaultVideoFactory() final;
+
+    CaptureDeviceManager* defaultAudioCaptureDeviceManager() final;
+    CaptureDeviceManager* defaultVideoCaptureDeviceManager() final;
+
+    bool m_useAVFoundationAudioCapture { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit2/ChangeLog (216445 => 216446)


--- trunk/Source/WebKit2/ChangeLog	2017-05-08 19:57:21 UTC (rev 216445)
+++ trunk/Source/WebKit2/ChangeLog	2017-05-08 20:03:46 UTC (rev 216446)
@@ -1,3 +1,15 @@
+2017-05-08  Jer Noble  <jer.no...@apple.com>
+
+        [Mac] Audio capture fails when shouldCaptureAudioInUIProcess is set.
+        https://bugs.webkit.org/show_bug.cgi?id=171710
+
+        Reviewed by Eric Carlson.
+
+        RealtimeMediaSourceCenterMac's setUseAVFoundationAudioCapture() is now accessed via a singleton.
+
+        * UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
+        (WebKit::UserMediaPermissionRequestManagerProxy::syncWithWebCorePrefs):
+
 2017-05-08  Andy Estes  <aes...@apple.com>
 
         [macOS] com.macromedia.Flash Player ESR.plugin.sb is installed outside of PlugInSandboxProfiles

Modified: trunk/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp (216445 => 216446)


--- trunk/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp	2017-05-08 19:57:21 UTC (rev 216445)
+++ trunk/Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp	2017-05-08 20:03:46 UTC (rev 216446)
@@ -366,7 +366,7 @@
 
 #if USE(AVFOUNDATION)
     bool useAVFoundationAudioCapture = m_page.preferences().useAVFoundationAudioCapture();
-    WebCore::RealtimeMediaSourceCenterMac::setUseAVFoundationAudioCapture(useAVFoundationAudioCapture);
+    WebCore::RealtimeMediaSourceCenterMac::singleton().setUseAVFoundationAudioCapture(useAVFoundationAudioCapture);
 #endif
 #endif
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to