[Mac] Audio capture fails when shouldCaptureAudioInUIProcess is set.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 May 2017 20:03:46 +0000 (20:03 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 May 2017 20:03:46 +0000 (20:03 +0000)
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):

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

Source/WebCore/ChangeLog
Source/WebCore/page/Settings.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h
Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp
Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp

index 992cab7..f24b782 100644 (file)
@@ -1,3 +1,35 @@
+2017-05-08  Jer Noble  <jer.noble@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_tan@apple.com>
 
         Search events should not fire synchronously for search type input elements with incremental attribute set
index 2da3b84..0eaf526 100644 (file)
@@ -630,7 +630,7 @@ void Settings::setUseAVFoundationAudioCapture(bool useAVFoundationAudioCapture)
 {
     gUseAVFoundationAudioCapture = useAVFoundationAudioCapture;
 #if USE(AVFOUNDATION)
-    RealtimeMediaSourceCenterMac::setUseAVFoundationAudioCapture(useAVFoundationAudioCapture);
+    RealtimeMediaSourceCenterMac::singleton().setUseAVFoundationAudioCapture(useAVFoundationAudioCapture);
 #endif
 }
 #endif
index b9d3d47..a0bb53b 100644 (file)
@@ -78,6 +78,11 @@ void RealtimeMediaSourceCenter::unsetAudioFactory(RealtimeMediaSource::AudioCapt
         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 @@ void RealtimeMediaSourceCenter::unsetVideoFactory(RealtimeMediaSource::VideoCapt
         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 @@ void RealtimeMediaSourceCenter::unsetAudioCaptureDeviceManager(CaptureDeviceMana
         m_audioCaptureDeviceManager = nullptr;
 }
 
+CaptureDeviceManager* RealtimeMediaSourceCenter::audioCaptureDeviceManager()
+{
+    return m_audioCaptureDeviceManager ? m_audioCaptureDeviceManager : defaultAudioCaptureDeviceManager();
+}
+
 void RealtimeMediaSourceCenter::setVideoCaptureDeviceManager(CaptureDeviceManager& deviceManager)
 {
     m_videoCaptureDeviceManager = &deviceManager;
@@ -111,6 +126,11 @@ void RealtimeMediaSourceCenter::unsetVideoCaptureDeviceManager(CaptureDeviceMana
         m_videoCaptureDeviceManager = nullptr;
 }
 
+CaptureDeviceManager* RealtimeMediaSourceCenter::videoCaptureDeviceManager()
+{
+    return m_videoCaptureDeviceManager ? m_videoCaptureDeviceManager : defaultVideoCaptureDeviceManager();
+}
+
 static void addStringToSHA1(SHA1& sha1, const String& string)
 {
     if (string.isEmpty())
index c0f40f4..f758999 100644 (file)
@@ -71,22 +71,22 @@ public:
 
     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; }
 
     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);
index 6cc43f2..419d3d5 100644 (file)
@@ -47,33 +47,21 @@ namespace WebCore {
 
 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;
     return center;
 }
 
+RealtimeMediaSourceCenter& RealtimeMediaSourceCenter::platformCenter()
+{
+    return RealtimeMediaSourceCenterMac::singleton();
+}
+
 RealtimeMediaSourceCenterMac::RealtimeMediaSourceCenterMac()
 {
     m_supportedConstraints.setSupportsWidth(true);
@@ -87,17 +75,6 @@ RealtimeMediaSourceCenterMac::RealtimeMediaSourceCenterMac()
     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 @@ void RealtimeMediaSourceCenterMac::createMediaStream(NewMediaStreamHandler&& com
     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 @@ void RealtimeMediaSourceCenterMac::createMediaStream(NewMediaStreamHandler&& com
             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> RealtimeMediaSourceCenterMac::getMediaStreamDevices()
 {
     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 @@ Vector<String> RealtimeMediaSourceCenterMac::bestSourcesForTypeAndConstraints(Re
             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 @@ Vector<String> RealtimeMediaSourceCenterMac::bestSourcesForTypeAndConstraints(Re
 
 RealtimeMediaSource::AudioCaptureFactory* RealtimeMediaSourceCenterMac::defaultAudioFactory()
 {
-    return &CoreAudioCaptureSource::factory();
+    return m_useAVFoundationAudioCapture ? &AVAudioCaptureSource::factory() : &CoreAudioCaptureSource::factory();
 }
 
 RealtimeMediaSource::VideoCaptureFactory* RealtimeMediaSourceCenterMac::defaultVideoFactory()
@@ -225,6 +202,22 @@ RealtimeMediaSource::VideoCaptureFactory* RealtimeMediaSourceCenterMac::defaultV
     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)
index 921fa8e..ca70ade 100644 (file)
@@ -42,10 +42,12 @@ namespace WebCore {
 
 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 @@ private:
 
     RealtimeMediaSource::AudioCaptureFactory* defaultAudioFactory() final;
     RealtimeMediaSource::VideoCaptureFactory* defaultVideoFactory() final;
+
+    CaptureDeviceManager* defaultAudioCaptureDeviceManager() final;
+    CaptureDeviceManager* defaultVideoCaptureDeviceManager() final;
+
+    bool m_useAVFoundationAudioCapture { false };
 };
 
 } // namespace WebCore
index ea55ca5..495b816 100644 (file)
@@ -1,3 +1,15 @@
+2017-05-08  Jer Noble  <jer.noble@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  <aestes@apple.com>
 
         [macOS] com.macromedia.Flash Player ESR.plugin.sb is installed outside of PlugInSandboxProfiles
index daf92e9..8384282 100644 (file)
@@ -366,7 +366,7 @@ void UserMediaPermissionRequestManagerProxy::syncWithWebCorePrefs() const
 
 #if USE(AVFOUNDATION)
     bool useAVFoundationAudioCapture = m_page.preferences().useAVFoundationAudioCapture();
-    WebCore::RealtimeMediaSourceCenterMac::setUseAVFoundationAudioCapture(useAVFoundationAudioCapture);
+    WebCore::RealtimeMediaSourceCenterMac::singleton().setUseAVFoundationAudioCapture(useAVFoundationAudioCapture);
 #endif
 #endif
 }