Follow-up to bug 171710: use more references and reject if either audio or video...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 May 2017 05:14:32 +0000 (05:14 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 May 2017 05:14:32 +0000 (05:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171824

Patch by Youenn Fablet <youenn@apple.com> on 2017-05-08
Reviewed by Alex Christensen.

Source/WebCore:

Refactoring to use more references.
Only behavioral change is the rejection of the getUserMedia promise if either audio or video source creation is
failing. Previously, if audio source creation was failing, the promise would still resolve if video source was
sucessfully created.

* platform/mediastream/RealtimeMediaSourceCenter.cpp:
(WebCore::RealtimeMediaSourceCenter::audioFactory):
(WebCore::RealtimeMediaSourceCenter::videoFactory):
(WebCore::RealtimeMediaSourceCenter::audioCaptureDeviceManager):
(WebCore::RealtimeMediaSourceCenter::videoCaptureDeviceManager):
* platform/mediastream/RealtimeMediaSourceCenter.h:
(WebCore::RealtimeMediaSourceCenter::defaultAudioFactory): Deleted.
(WebCore::RealtimeMediaSourceCenter::defaultVideoFactory): Deleted.
(WebCore::RealtimeMediaSourceCenter::defaultAudioCaptureDeviceManager): Deleted.
(WebCore::RealtimeMediaSourceCenter::defaultVideoCaptureDeviceManager): Deleted.
* platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp:
(WebCore::RealtimeMediaSourceCenterMac::createMediaStream):
(WebCore::RealtimeMediaSourceCenterMac::getMediaStreamDevices):
(WebCore::RealtimeMediaSourceCenterMac::bestSourcesForTypeAndConstraints):
(WebCore::RealtimeMediaSourceCenterMac::defaultAudioFactory):
(WebCore::RealtimeMediaSourceCenterMac::defaultVideoFactory):
(WebCore::RealtimeMediaSourceCenterMac::defaultAudioCaptureDeviceManager):
(WebCore::RealtimeMediaSourceCenterMac::defaultVideoCaptureDeviceManager):
* platform/mediastream/mac/RealtimeMediaSourceCenterMac.h:
* platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.h:
* platform/mock/MockRealtimeMediaSourceCenter.cpp:
(WebCore::MockRealtimeMediaSourceCenter::defaultAudioFactory):
(WebCore::MockRealtimeMediaSourceCenter::defaultVideoFactory):
(WebCore::MockRealtimeMediaSourceCenter::defaultAudioCaptureDeviceManager):
(WebCore::MockRealtimeMediaSourceCenter::defaultVideoCaptureDeviceManager):
* platform/mock/MockRealtimeMediaSourceCenter.h:

Source/WebKit2:

* UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
(WebKit::UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstraints):

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

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
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/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.h
Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp

index b198d77..e9c3a47 100644 (file)
@@ -2386,6 +2386,7 @@ set(WebCore_SOURCES
     platform/graphics/transforms/TransformationMatrix.cpp
     platform/graphics/transforms/TranslateTransformOperation.cpp
 
+    platform/mediastream/CaptureDeviceManager.cpp
     platform/mediastream/MediaConstraints.cpp
     platform/mediastream/MediaEndpointConfiguration.cpp
     platform/mediastream/MediaStreamPrivate.cpp
index 7ff2c35..dfc3c84 100644 (file)
@@ -1,3 +1,42 @@
+2017-05-08  Youenn Fablet  <youenn@apple.com>
+
+        Follow-up to bug 171710: use more references and reject if either audio or video source creation is failing
+        https://bugs.webkit.org/show_bug.cgi?id=171824
+
+        Reviewed by Alex Christensen.
+
+        Refactoring to use more references.
+        Only behavioral change is the rejection of the getUserMedia promise if either audio or video source creation is
+        failing. Previously, if audio source creation was failing, the promise would still resolve if video source was
+        sucessfully created.
+
+        * platform/mediastream/RealtimeMediaSourceCenter.cpp:
+        (WebCore::RealtimeMediaSourceCenter::audioFactory):
+        (WebCore::RealtimeMediaSourceCenter::videoFactory):
+        (WebCore::RealtimeMediaSourceCenter::audioCaptureDeviceManager):
+        (WebCore::RealtimeMediaSourceCenter::videoCaptureDeviceManager):
+        * platform/mediastream/RealtimeMediaSourceCenter.h:
+        (WebCore::RealtimeMediaSourceCenter::defaultAudioFactory): Deleted.
+        (WebCore::RealtimeMediaSourceCenter::defaultVideoFactory): Deleted.
+        (WebCore::RealtimeMediaSourceCenter::defaultAudioCaptureDeviceManager): Deleted.
+        (WebCore::RealtimeMediaSourceCenter::defaultVideoCaptureDeviceManager): Deleted.
+        * platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp:
+        (WebCore::RealtimeMediaSourceCenterMac::createMediaStream):
+        (WebCore::RealtimeMediaSourceCenterMac::getMediaStreamDevices):
+        (WebCore::RealtimeMediaSourceCenterMac::bestSourcesForTypeAndConstraints):
+        (WebCore::RealtimeMediaSourceCenterMac::defaultAudioFactory):
+        (WebCore::RealtimeMediaSourceCenterMac::defaultVideoFactory):
+        (WebCore::RealtimeMediaSourceCenterMac::defaultAudioCaptureDeviceManager):
+        (WebCore::RealtimeMediaSourceCenterMac::defaultVideoCaptureDeviceManager):
+        * platform/mediastream/mac/RealtimeMediaSourceCenterMac.h:
+        * platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.h:
+        * platform/mock/MockRealtimeMediaSourceCenter.cpp:
+        (WebCore::MockRealtimeMediaSourceCenter::defaultAudioFactory):
+        (WebCore::MockRealtimeMediaSourceCenter::defaultVideoFactory):
+        (WebCore::MockRealtimeMediaSourceCenter::defaultAudioCaptureDeviceManager):
+        (WebCore::MockRealtimeMediaSourceCenter::defaultVideoCaptureDeviceManager):
+        * platform/mock/MockRealtimeMediaSourceCenter.h:
+
 2017-05-08  Chris Dumez  <cdumez@apple.com>
 
         Drop [CEReactions] from CharacterData operations
index a0bb53b..72b9028 100644 (file)
@@ -78,9 +78,9 @@ void RealtimeMediaSourceCenter::unsetAudioFactory(RealtimeMediaSource::AudioCapt
         m_audioFactory = nullptr;
 }
 
-RealtimeMediaSource::AudioCaptureFactory* RealtimeMediaSourceCenter::audioFactory()
+RealtimeMediaSource::AudioCaptureFactory& RealtimeMediaSourceCenter::audioFactory()
 {
-    return m_audioFactory ? m_audioFactory: defaultAudioFactory();
+    return m_audioFactory ? *m_audioFactory : defaultAudioFactory();
 }
 
 void RealtimeMediaSourceCenter::setVideoFactory(RealtimeMediaSource::VideoCaptureFactory& factory)
@@ -94,9 +94,9 @@ void RealtimeMediaSourceCenter::unsetVideoFactory(RealtimeMediaSource::VideoCapt
         m_videoFactory = nullptr;
 }
 
-RealtimeMediaSource::VideoCaptureFactory* RealtimeMediaSourceCenter::videoFactory()
+RealtimeMediaSource::VideoCaptureFactory& RealtimeMediaSourceCenter::videoFactory()
 {
-    return m_videoFactory ? m_videoFactory : defaultVideoFactory();
+    return m_videoFactory ? *m_videoFactory : defaultVideoFactory();
 }
 
 void RealtimeMediaSourceCenter::setAudioCaptureDeviceManager(CaptureDeviceManager& deviceManager)
@@ -110,9 +110,9 @@ void RealtimeMediaSourceCenter::unsetAudioCaptureDeviceManager(CaptureDeviceMana
         m_audioCaptureDeviceManager = nullptr;
 }
 
-CaptureDeviceManager* RealtimeMediaSourceCenter::audioCaptureDeviceManager()
+CaptureDeviceManager& RealtimeMediaSourceCenter::audioCaptureDeviceManager()
 {
-    return m_audioCaptureDeviceManager ? m_audioCaptureDeviceManager : defaultAudioCaptureDeviceManager();
+    return m_audioCaptureDeviceManager ? *m_audioCaptureDeviceManager : defaultAudioCaptureDeviceManager();
 }
 
 void RealtimeMediaSourceCenter::setVideoCaptureDeviceManager(CaptureDeviceManager& deviceManager)
@@ -126,9 +126,9 @@ void RealtimeMediaSourceCenter::unsetVideoCaptureDeviceManager(CaptureDeviceMana
         m_videoCaptureDeviceManager = nullptr;
 }
 
-CaptureDeviceManager* RealtimeMediaSourceCenter::videoCaptureDeviceManager()
+CaptureDeviceManager& RealtimeMediaSourceCenter::videoCaptureDeviceManager()
 {
-    return m_videoCaptureDeviceManager ? m_videoCaptureDeviceManager : defaultVideoCaptureDeviceManager();
+    return m_videoCaptureDeviceManager ? *m_videoCaptureDeviceManager : defaultVideoCaptureDeviceManager();
 }
 
 static void addStringToSHA1(SHA1& sha1, const String& string)
index f758999..540ad21 100644 (file)
@@ -66,27 +66,27 @@ public:
     
     virtual const RealtimeMediaSourceSupportedConstraints& supportedConstraints() { return m_supportedConstraints; }
 
-    virtual RealtimeMediaSource::AudioCaptureFactory* defaultAudioFactory() { return nullptr; }
-    virtual RealtimeMediaSource::VideoCaptureFactory* defaultVideoFactory() { return nullptr; }
+    virtual RealtimeMediaSource::AudioCaptureFactory& defaultAudioFactory() = 0;
+    virtual RealtimeMediaSource::VideoCaptureFactory& defaultVideoFactory() = 0;
 
     WEBCORE_EXPORT void setAudioFactory(RealtimeMediaSource::AudioCaptureFactory&);
     WEBCORE_EXPORT void unsetAudioFactory(RealtimeMediaSource::AudioCaptureFactory&);
-    WEBCORE_EXPORT RealtimeMediaSource::AudioCaptureFactory* audioFactory();
+    WEBCORE_EXPORT RealtimeMediaSource::AudioCaptureFactory& audioFactory();
 
     WEBCORE_EXPORT void setVideoFactory(RealtimeMediaSource::VideoCaptureFactory&);
     WEBCORE_EXPORT void unsetVideoFactory(RealtimeMediaSource::VideoCaptureFactory&);
-    WEBCORE_EXPORT RealtimeMediaSource::VideoCaptureFactory* videoFactory();
+    WEBCORE_EXPORT RealtimeMediaSource::VideoCaptureFactory& videoFactory();
 
-    virtual CaptureDeviceManager* defaultAudioCaptureDeviceManager() { return nullptr; }
-    virtual CaptureDeviceManager* defaultVideoCaptureDeviceManager() { return nullptr; }
+    virtual CaptureDeviceManager& defaultAudioCaptureDeviceManager() = 0;
+    virtual CaptureDeviceManager& defaultVideoCaptureDeviceManager() = 0;
 
     WEBCORE_EXPORT void setAudioCaptureDeviceManager(CaptureDeviceManager&);
     WEBCORE_EXPORT void unsetAudioCaptureDeviceManager(CaptureDeviceManager&);
-    CaptureDeviceManager* audioCaptureDeviceManager();
+    CaptureDeviceManager& audioCaptureDeviceManager();
 
     WEBCORE_EXPORT void setVideoCaptureDeviceManager(CaptureDeviceManager&);
     WEBCORE_EXPORT void unsetVideoCaptureDeviceManager(CaptureDeviceManager&);
-    CaptureDeviceManager* videoCaptureDeviceManager();
+    CaptureDeviceManager& videoCaptureDeviceManager();
 
     String hashStringWithSalt(const String& id, const String& hashSalt);
     WEBCORE_EXPORT std::optional<CaptureDevice> captureDeviceWithUniqueID(const String& id, const String& hashSalt);
index 419d3d5..74284e8 100644 (file)
@@ -112,40 +112,42 @@ void RealtimeMediaSourceCenterMac::createMediaStream(NewMediaStreamHandler&& com
     Vector<Ref<RealtimeMediaSource>> videoSources;
     String invalidConstraint;
 
-    if (!audioDeviceID.isEmpty() && audioFactory()) {
-        auto audioSource = audioFactory()->createAudioCaptureSource(audioDeviceID, audioConstraints);
+    if (!audioDeviceID.isEmpty()) {
+        auto audioSource = audioFactory().createAudioCaptureSource(audioDeviceID, audioConstraints);
         if (audioSource)
             audioSources.append(audioSource.source());
+        else {
 #if !LOG_DISABLED
-        if (!audioSource.errorMessage.isEmpty())
-            LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), audio constraints failed to apply: %s", this, audioSource.errorMessage.utf8().data());
+            if (!audioSource.errorMessage.isEmpty())
+                LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), audio constraints failed to apply: %s", this, audioSource.errorMessage.utf8().data());
 #endif
+            completionHandler(nullptr);
+            return;
+        }
     }
-    if (!videoDeviceID.isEmpty() && videoFactory()) {
-        auto videoSource = videoFactory()->createVideoCaptureSource(videoDeviceID, videoConstraints);
+    if (!videoDeviceID.isEmpty()) {
+        auto videoSource = videoFactory().createVideoCaptureSource(videoDeviceID, videoConstraints);
         if (videoSource)
             videoSources.append(videoSource.source());
+        else {
 #if !LOG_DISABLED
-        if (!videoSource.errorMessage.isEmpty())
-            LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), video constraints failed to apply: %s", this, videoSource.errorMessage.utf8().data());
+            if (!videoSource.errorMessage.isEmpty())
+                LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), video constraints failed to apply: %s", this, videoSource.errorMessage.utf8().data());
 #endif
+            completionHandler(nullptr);
+            return;
+        }
     }
 
-    if (videoSources.isEmpty() && audioSources.isEmpty())
-        completionHandler(nullptr);
-    else
-        completionHandler(MediaStreamPrivate::create(audioSources, videoSources));
+    completionHandler(MediaStreamPrivate::create(audioSources, videoSources));
 }
 
 Vector<CaptureDevice> RealtimeMediaSourceCenterMac::getMediaStreamDevices()
 {
     Vector<CaptureDevice> result;
 
-    if (auto audioDeviceManager = audioCaptureDeviceManager())
-        result.appendVector(audioDeviceManager->getAudioSourcesInfo());
-
-    if (auto videoDeviceManager = videoCaptureDeviceManager())
-        result.appendVector(videoDeviceManager->getVideoSourcesInfo());
+    result.appendVector(audioCaptureDeviceManager().getAudioSourcesInfo());
+    result.appendVector(videoCaptureDeviceManager().getVideoSourcesInfo());
 
     return result;
 }
@@ -167,10 +169,10 @@ Vector<String> RealtimeMediaSourceCenterMac::bestSourcesForTypeAndConstraints(Re
             continue;
 
         CaptureSourceOrError sourceOrError;
-        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 (type == RealtimeMediaSource::Type::Video)
+            sourceOrError = videoFactory().createVideoCaptureSource(captureDevice.persistentId(), &constraints);
+        else if (type == RealtimeMediaSource::Type::Audio)
+            sourceOrError = audioFactory().createAudioCaptureSource(captureDevice.persistentId(), &constraints);
 
         if (!sourceOrError) {
             // FIXME: Handle the case of invalid constraints on more than one device.
@@ -192,30 +194,30 @@ Vector<String> RealtimeMediaSourceCenterMac::bestSourcesForTypeAndConstraints(Re
     return sourceUIDs;
 }
 
-RealtimeMediaSource::AudioCaptureFactory* RealtimeMediaSourceCenterMac::defaultAudioFactory()
+RealtimeMediaSource::AudioCaptureFactory& RealtimeMediaSourceCenterMac::defaultAudioFactory()
 {
-    return m_useAVFoundationAudioCapture ? &AVAudioCaptureSource::factory() : &CoreAudioCaptureSource::factory();
+    return m_useAVFoundationAudioCapture ? AVAudioCaptureSource::factory() : CoreAudioCaptureSource::factory();
 }
 
-RealtimeMediaSource::VideoCaptureFactory* RealtimeMediaSourceCenterMac::defaultVideoFactory()
+RealtimeMediaSource::VideoCaptureFactory& RealtimeMediaSourceCenterMac::defaultVideoFactory()
 {
-    return &AVVideoCaptureSource::factory();
+    return AVVideoCaptureSource::factory();
 }
 
-CaptureDeviceManager* RealtimeMediaSourceCenterMac::defaultAudioCaptureDeviceManager()
+CaptureDeviceManager& RealtimeMediaSourceCenterMac::defaultAudioCaptureDeviceManager()
 {
     if (m_useAVFoundationAudioCapture)
-        return &AVCaptureDeviceManager::singleton();
+        return AVCaptureDeviceManager::singleton();
 #if PLATFORM(MAC)
-    return &CoreAudioCaptureDeviceManager::singleton();
+    return CoreAudioCaptureDeviceManager::singleton();
 #else
-    return &AVAudioSessionCaptureDeviceManager::singleton();
+    return AVAudioSessionCaptureDeviceManager::singleton();
 #endif
 }
 
-CaptureDeviceManager* RealtimeMediaSourceCenterMac::defaultVideoCaptureDeviceManager()
+CaptureDeviceManager& RealtimeMediaSourceCenterMac::defaultVideoCaptureDeviceManager()
 {
-    return &AVCaptureDeviceManager::singleton();
+    return AVCaptureDeviceManager::singleton();
 }
 
 } // namespace WebCore
index ca70ade..7c2230f 100644 (file)
@@ -56,11 +56,11 @@ private:
 
     Vector<String> bestSourcesForTypeAndConstraints(RealtimeMediaSource::Type, const MediaConstraints&, String& invalidConstraint);
 
-    RealtimeMediaSource::AudioCaptureFactory* defaultAudioFactory() final;
-    RealtimeMediaSource::VideoCaptureFactory* defaultVideoFactory() final;
+    RealtimeMediaSource::AudioCaptureFactory& defaultAudioFactory() final;
+    RealtimeMediaSource::VideoCaptureFactory& defaultVideoFactory() final;
 
-    CaptureDeviceManager* defaultAudioCaptureDeviceManager() final;
-    CaptureDeviceManager* defaultVideoCaptureDeviceManager() final;
+    CaptureDeviceManager& defaultAudioCaptureDeviceManager() final;
+    CaptureDeviceManager& defaultVideoCaptureDeviceManager() final;
 
     bool m_useAVFoundationAudioCapture { false };
 };
index e638078..3285187 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RealtimeMediaSourceCenterOwr_h
-#define RealtimeMediaSourceCenterOwr_h
+#pragma once
 
 #if ENABLE(MEDIA_STREAM) && USE(OPENWEBRTC)
 
+#include "CaptureDeviceManager.h"
 #include "RealtimeMediaSourceCenter.h"
-
 #include "RealtimeMediaSourceOwr.h"
 #include <wtf/PassRefPtr.h>
 
@@ -63,15 +62,40 @@ public:
     void mediaSourcesAvailable(GList* sources);
 
 private:
+    RealtimeMediaSource::AudioCaptureFactory& defaultAudioFactory() final { return m_defaultAudioFactory; }
+    RealtimeMediaSource::VideoCaptureFactory& defaultVideoFactory() final { return m_defaultVideoFactory; }
+    CaptureDeviceManager& defaultAudioCaptureDeviceManager() final { return m_defaultAudioCaptureDeviceManager; }
+    CaptureDeviceManager& defaultVideoCaptureDeviceManager() final { return m_defaultVideoCaptureDeviceManager; }
+
     PassRefPtr<RealtimeMediaSource> firstSource(RealtimeMediaSource::Type);
     RealtimeMediaSourceOwrMap m_sourceMap;
     ValidConstraintsHandler m_validConstraintsHandler;
     InvalidConstraintsHandler m_invalidConstraintsHandler;
     NewMediaStreamHandler m_completionHandler;
+
+    class AudioCaptureFactoryOwr : public RealtimeMediaSource::AudioCaptureFactory {
+    private:
+        CaptureSourceOrError createAudioCaptureSource(const String&, const MediaConstraints*) final { return { }; }
+    };
+
+    class VideoCaptureFactoryOwr : public RealtimeMediaSource::VideoCaptureFactory {
+    private:
+        CaptureSourceOrError createVideoCaptureSource(const String&, const MediaConstraints*) final { return { }; }
+    };
+
+    class CaptureDeviceManagerOwr : public CaptureDeviceManager {
+    private:
+        Vector<CaptureDevice>& captureDevices() final { return m_devices; }
+
+        Vector<CaptureDevice> m_devices;
+    };
+
+    AudioCaptureFactoryOwr m_defaultAudioFactory;
+    VideoCaptureFactoryOwr m_defaultVideoFactory;
+    CaptureDeviceManagerOwr m_defaultAudioCaptureDeviceManager;
+    CaptureDeviceManagerOwr m_defaultVideoCaptureDeviceManager;
 };
 
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM) && USE(OPENWEBRTC)
-
-#endif // RealtimeMediaSourceCenterOwr_h
index 7c35912..f3b01e9 100644 (file)
@@ -184,14 +184,24 @@ Vector<CaptureDevice> MockRealtimeMediaSourceCenter::getMediaStreamDevices()
     return sources;
 }
 
-RealtimeMediaSource::AudioCaptureFactory* MockRealtimeMediaSourceCenter::defaultAudioFactory()
+RealtimeMediaSource::AudioCaptureFactory& MockRealtimeMediaSourceCenter::defaultAudioFactory()
 {
-    return &MockRealtimeAudioSource::factory();
+    return MockRealtimeAudioSource::factory();
 }
 
-RealtimeMediaSource::VideoCaptureFactory* MockRealtimeMediaSourceCenter::defaultVideoFactory()
+RealtimeMediaSource::VideoCaptureFactory& MockRealtimeMediaSourceCenter::defaultVideoFactory()
 {
-    return &MockRealtimeVideoSource::factory();
+    return MockRealtimeVideoSource::factory();
+}
+
+CaptureDeviceManager& MockRealtimeMediaSourceCenter::defaultAudioCaptureDeviceManager()
+{
+    return m_defaultAudioCaptureDeviceManager;
+}
+
+CaptureDeviceManager& MockRealtimeMediaSourceCenter::defaultVideoCaptureDeviceManager()
+{
+    return m_defaultVideoCaptureDeviceManager;
 }
 
 ExceptionOr<void> MockRealtimeMediaSourceCenter::setDeviceEnabled(const String& id, bool enabled)
index c3c605d..e57d30c 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(MEDIA_STREAM)
 
+#include "CaptureDeviceManager.h"
 #include "RealtimeMediaSourceCenter.h"
 
 namespace WebCore {
@@ -44,10 +45,22 @@ private:
     Vector<CaptureDevice> getMediaStreamDevices() final;
     void createMediaStream(NewMediaStreamHandler&&, const String& audioDeviceID, const String& videoDeviceID, const MediaConstraints* audioConstraints, const MediaConstraints* videoConstraints) final;
 
-    RealtimeMediaSource::AudioCaptureFactory* defaultAudioFactory() final;
-    RealtimeMediaSource::VideoCaptureFactory* defaultVideoFactory() final;
+    RealtimeMediaSource::AudioCaptureFactory& defaultAudioFactory() final;
+    RealtimeMediaSource::VideoCaptureFactory& defaultVideoFactory() final;
+    CaptureDeviceManager& defaultAudioCaptureDeviceManager() final;
+    CaptureDeviceManager& defaultVideoCaptureDeviceManager() final;
 
     ExceptionOr<void> setDeviceEnabled(const String& persistentID, bool) final;
+
+    class MockCaptureDeviceManager final : public CaptureDeviceManager {
+    private:
+        Vector<CaptureDevice>& captureDevices() final { return m_devices; }
+
+        Vector<CaptureDevice> m_devices;
+    };
+
+    MockCaptureDeviceManager m_defaultAudioCaptureDeviceManager;
+    MockCaptureDeviceManager m_defaultVideoCaptureDeviceManager;
 };
 
 }
index b28c978..71c8bfb 100644 (file)
@@ -1,3 +1,13 @@
+2017-05-08  Youenn Fablet  <youenn@apple.com>
+
+        Follow-up to bug 171710: use more references and reject if either audio or video source creation is failing
+        https://bugs.webkit.org/show_bug.cgi?id=171824
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
+        (WebKit::UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstraints):
+
 2017-05-08  Brent Fulgham  <bfulgham@apple.com>
 
         REGRESSION(r213564): Flash video playback failures
index b7c8ae8..6cdba1f 100644 (file)
@@ -131,10 +131,10 @@ void UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstrai
     auto constraints = MediaConstraintsImpl::create(MediaConstraintsData(constraintsData));
     switch (type) {
     case WebCore::RealtimeMediaSource::Type::Audio:
-        sourceOrError = RealtimeMediaSourceCenter::singleton().audioFactory()->createAudioCaptureSource(deviceID, constraints.ptr());
+        sourceOrError = RealtimeMediaSourceCenter::singleton().audioFactory().createAudioCaptureSource(deviceID, constraints.ptr());
         break;
     case WebCore::RealtimeMediaSource::Type::Video:
-        sourceOrError = RealtimeMediaSourceCenter::singleton().videoFactory()->createVideoCaptureSource(deviceID, constraints.ptr());
+        sourceOrError = RealtimeMediaSourceCenter::singleton().videoFactory().createVideoCaptureSource(deviceID, constraints.ptr());
         break;
     case WebCore::RealtimeMediaSource::Type::None:
         ASSERT_NOT_REACHED();