Title: [253275] trunk
Revision
253275
Author
[email protected]
Date
2019-12-08 11:10:02 -0800 (Sun, 08 Dec 2019)

Log Message

Support different resolutions for video tracks captured from UIProcess
https://bugs.webkit.org/show_bug.cgi?id=204945

Reviewed by Eric Carlson.

Source/WebCore:

Remove whether the a source is remote or not.
Previously we were doing the distinction as resizing would happen in WebProcess and not in UIProcess.
We are now moving away from doing resizing in WebProcess.
Covered by existing tests.

* platform/mediastream/RealtimeMediaSource.h:
* platform/mediastream/RealtimeMediaSourceFactory.h:
* platform/mediastream/RealtimeVideoCaptureSource.cpp:
(WebCore::RealtimeVideoCaptureSource::adaptVideoSample):
For remote tracks, we also update the size for observers.
* platform/mediastream/RealtimeVideoSource.cpp:
(WebCore::m_source):
(WebCore::RealtimeVideoSource::sourceSettingsChanged):
Update computation of size based on rotation.
This makes sure we have resizing done right.
* platform/mediastream/RealtimeVideoSource.h:
* platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp:
(WebCore::DisplayCaptureSourceCocoa::emitFrame):

Source/WebKit:

Change video capture in uiprocess to an experimental flag.
Add support for remote video source cloning by sending some IPC to UIProcess and cloning the source there.
This triggers IPC for both cloning and cloned sources but this allows to do resizing in UIProcess instead of WebProcess.
We thus disable video capture resizing in WebProcess.

* Shared/WebPreferences.yaml:
* UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
(WebKit::UserMediaCaptureManagerProxy::SourceProxy::start):
(WebKit::UserMediaCaptureManagerProxy::SourceProxy::stop):
(WebKit::UserMediaCaptureManagerProxy::SourceProxy::requestToEnd):
(WebKit::UserMediaCaptureManagerProxy::SourceProxy::preventSourceFromStopping):
(WebKit::UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstraints):
(WebKit::UserMediaCaptureManagerProxy::startProducingData):
(WebKit::UserMediaCaptureManagerProxy::stopProducingData):
(WebKit::UserMediaCaptureManagerProxy::clone):
(WebKit::UserMediaCaptureManagerProxy::requestToEnd):
* UIProcess/Cocoa/UserMediaCaptureManagerProxy.h:
* UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in:
* WebProcess/cocoa/UserMediaCaptureManager.cpp:
(WebKit::UserMediaCaptureManager::Source::sourceID const):
(WebKit::UserMediaCaptureManager::Source::settings const):
(WebKit::UserMediaCaptureManager::Source::remoteVideoSampleAvailable):
(WebKit::UserMediaCaptureManager::Source::requestToEnd):
(WebKit::UserMediaCaptureManager::Source::stopBeingObserved):
(WebKit::UserMediaCaptureManager::cloneSource):
(WebKit::UserMediaCaptureManager::cloneVideoSource):
(WebKit::UserMediaCaptureManager::requestToEnd):
(WebKit::UserMediaCaptureManager::VideoFactory::setVideoCapturePageState):
* WebProcess/cocoa/UserMediaCaptureManager.h:

LayoutTests:

* fast/mediastream/mediastreamtrack-video-clone-expected.txt:
* fast/mediastream/mediastreamtrack-video-clone.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (253274 => 253275)


--- trunk/LayoutTests/ChangeLog	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/LayoutTests/ChangeLog	2019-12-08 19:10:02 UTC (rev 253275)
@@ -1,3 +1,13 @@
+2019-12-08  youenn fablet  <[email protected]>
+
+        Support different resolutions for video tracks captured from UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=204945
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/mediastreamtrack-video-clone-expected.txt:
+        * fast/mediastream/mediastreamtrack-video-clone.html:
+
 2019-12-07  Wenson Hsieh  <[email protected]>
 
         [iOS] WKWebView touch event gesture recognition should not block the application process main thread when possible

Modified: trunk/LayoutTests/fast/mediastream/mediastreamtrack-video-clone-expected.txt (253274 => 253275)


--- trunk/LayoutTests/fast/mediastream/mediastreamtrack-video-clone-expected.txt	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/LayoutTests/fast/mediastream/mediastreamtrack-video-clone-expected.txt	2019-12-08 19:10:02 UTC (rev 253275)
@@ -1,4 +1,4 @@
-   
+    
 
 PASS Setup for width test 
 PASS Setup for height test 

Modified: trunk/LayoutTests/fast/mediastream/mediastreamtrack-video-clone.html (253274 => 253275)


--- trunk/LayoutTests/fast/mediastream/mediastreamtrack-video-clone.html	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/LayoutTests/fast/mediastream/mediastreamtrack-video-clone.html	2019-12-08 19:10:02 UTC (rev 253275)
@@ -1,4 +1,3 @@
-<!-- webkit-test-runner [ enableCaptureVideoInUIProcess=false ] -->
 <!DOCTYPE html>
 <html>
 <head>

Modified: trunk/Source/WebCore/ChangeLog (253274 => 253275)


--- trunk/Source/WebCore/ChangeLog	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebCore/ChangeLog	2019-12-08 19:10:02 UTC (rev 253275)
@@ -1,3 +1,29 @@
+2019-12-08  youenn fablet  <[email protected]>
+
+        Support different resolutions for video tracks captured from UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=204945
+
+        Reviewed by Eric Carlson.
+
+        Remove whether the a source is remote or not.
+        Previously we were doing the distinction as resizing would happen in WebProcess and not in UIProcess.
+        We are now moving away from doing resizing in WebProcess.
+        Covered by existing tests.
+
+        * platform/mediastream/RealtimeMediaSource.h:
+        * platform/mediastream/RealtimeMediaSourceFactory.h:
+        * platform/mediastream/RealtimeVideoCaptureSource.cpp:
+        (WebCore::RealtimeVideoCaptureSource::adaptVideoSample):
+        For remote tracks, we also update the size for observers.
+        * platform/mediastream/RealtimeVideoSource.cpp:
+        (WebCore::m_source):
+        (WebCore::RealtimeVideoSource::sourceSettingsChanged):
+        Update computation of size based on rotation.
+        This makes sure we have resizing done right.
+        * platform/mediastream/RealtimeVideoSource.h:
+        * platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp:
+        (WebCore::DisplayCaptureSourceCocoa::emitFrame):
+
 2019-12-08  Antti Koivisto  <[email protected]>
 
         [LFC][Integration] Collect overflow from lines

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h (253274 => 253275)


--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h	2019-12-08 19:10:02 UTC (rev 253275)
@@ -183,9 +183,6 @@
     virtual bool isIncomingAudioSource() const { return false; }
     virtual bool isIncomingVideoSource() const { return false; }
 
-    void setIsRemote(bool isRemote) { m_isRemote = isRemote; }
-    bool isRemote() const { return m_isRemote; }
-
 #if !RELEASE_LOG_DISABLED
     void setLogger(const Logger&, const void*);
     const Logger* loggerPtr() const { return m_logger.get(); }
@@ -268,7 +265,6 @@
     bool m_isProducingData { false };
     bool m_interrupted { false };
     bool m_captureDidFailed { false };
-    bool m_isRemote { false };
     bool m_isEnded { false };
 };
 

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceFactory.h (253274 => 253275)


--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceFactory.h	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceFactory.h	2019-12-08 19:10:02 UTC (rev 253275)
@@ -42,6 +42,8 @@
 public:
     WEBCORE_EXPORT void setActiveSource(RealtimeMediaSource&);
     WEBCORE_EXPORT void unsetActiveSource(RealtimeMediaSource&);
+
+protected:
     RealtimeMediaSource* activeSource() { return m_activeSource; }
 
 private:

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeVideoCaptureSource.cpp (253274 => 253275)


--- trunk/Source/WebCore/platform/mediastream/RealtimeVideoCaptureSource.cpp	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeVideoCaptureSource.cpp	2019-12-08 19:10:02 UTC (rev 253275)
@@ -395,19 +395,18 @@
     auto mediaSample = makeRefPtr(&sample);
 
 #if PLATFORM(COCOA)
-    if (!isRemote()) {
-        auto size = this->size();
-        if (!size.isEmpty() && size != expandedIntSize(sample.presentationSize())) {
+    auto size = this->size();
+    if (!size.isEmpty() && size != expandedIntSize(sample.presentationSize())) {
 
-            if (!m_imageTransferSession || m_imageTransferSession->pixelFormat() != sample.videoPixelFormat())
-                m_imageTransferSession = ImageTransferSessionVT::create(sample.videoPixelFormat());
+        if (!m_imageTransferSession || m_imageTransferSession->pixelFormat() != sample.videoPixelFormat())
+            m_imageTransferSession = ImageTransferSessionVT::create(sample.videoPixelFormat());
 
-            if (m_imageTransferSession) {
-                mediaSample = m_imageTransferSession->convertMediaSample(sample, size);
-                if (!mediaSample) {
-                    ASSERT_NOT_REACHED();
-                    return nullptr;
-                }
+        ASSERT(m_imageTransferSession);
+        if (m_imageTransferSession) {
+            mediaSample = m_imageTransferSession->convertMediaSample(sample, size);
+            if (!mediaSample) {
+                ASSERT_NOT_REACHED();
+                return nullptr;
             }
         }
     }

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp (253274 => 253275)


--- trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp	2019-12-08 19:10:02 UTC (rev 253275)
@@ -36,6 +36,8 @@
 {
     m_source->addObserver(*this);
     m_currentSettings = m_source->settings();
+    m_rotation = m_source->sampleRotation();
+    setSize(m_source->size());
 }
 
 RealtimeVideoSource::~RealtimeVideoSource()
@@ -91,12 +93,29 @@
 
 void RealtimeVideoSource::sourceSettingsChanged()
 {
-    auto rotation = m_source->sampleRotation();
     auto size = this->size();
     if (size.isEmpty())
         size = m_source->size();
-    if (rotation == MediaSample::VideoRotation::Left || rotation == MediaSample::VideoRotation::Right)
-        size = size.transposedSize();
+
+    auto rotation = m_source->sampleRotation();
+    if (m_rotation != rotation) {
+        bool shouldTransposeSize = false;
+        switch (m_rotation) {
+        case MediaSample::VideoRotation::None:
+        case MediaSample::VideoRotation::UpsideDown:
+            shouldTransposeSize = rotation == MediaSample::VideoRotation::Left || rotation == MediaSample::VideoRotation::Right;
+            break;
+        case MediaSample::VideoRotation::Left:
+        case MediaSample::VideoRotation::Right:
+            shouldTransposeSize = rotation == MediaSample::VideoRotation::None || rotation == MediaSample::VideoRotation::UpsideDown;
+        }
+        m_rotation = rotation;
+        if (shouldTransposeSize) {
+            size = size.transposedSize();
+            setSize(size);
+        }
+    }
+
     m_currentSettings.setWidth(size.width());
     m_currentSettings.setHeight(size.height());
 

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.h (253274 => 253275)


--- trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.h	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.h	2019-12-08 19:10:02 UTC (rev 253275)
@@ -64,6 +64,7 @@
     bool preventSourceFromStopping() final;
     void videoSampleAvailable(MediaSample&) final;
 
+    MediaSample::VideoRotation m_rotation { MediaSample::VideoRotation::None };
     Ref<RealtimeVideoCaptureSource> m_source;
     RealtimeMediaSourceSettings m_currentSettings;
 };

Modified: trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp (253274 => 253275)


--- trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp	2019-12-08 19:10:02 UTC (rev 253275)
@@ -186,7 +186,7 @@
 
     setIntrinsicSize(imageSize);
 
-    auto mediaSampleSize = isRemote() ? imageSize : frameSize();
+    auto mediaSampleSize = frameSize();
 
     RefPtr<MediaSample> sample = WTF::switchOn(frame,
         [this, sampleTime, mediaSampleSize](RetainPtr<IOSurfaceRef> surface) -> RefPtr<MediaSample> {

Modified: trunk/Source/WebKit/ChangeLog (253274 => 253275)


--- trunk/Source/WebKit/ChangeLog	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebKit/ChangeLog	2019-12-08 19:10:02 UTC (rev 253275)
@@ -1,5 +1,42 @@
 2019-12-08  youenn fablet  <[email protected]>
 
+        Support different resolutions for video tracks captured from UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=204945
+
+        Reviewed by Eric Carlson.
+
+        Change video capture in uiprocess to an experimental flag.
+        Add support for remote video source cloning by sending some IPC to UIProcess and cloning the source there.
+        This triggers IPC for both cloning and cloned sources but this allows to do resizing in UIProcess instead of WebProcess.
+        We thus disable video capture resizing in WebProcess.
+
+        * Shared/WebPreferences.yaml:
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
+        (WebKit::UserMediaCaptureManagerProxy::SourceProxy::start):
+        (WebKit::UserMediaCaptureManagerProxy::SourceProxy::stop):
+        (WebKit::UserMediaCaptureManagerProxy::SourceProxy::requestToEnd):
+        (WebKit::UserMediaCaptureManagerProxy::SourceProxy::preventSourceFromStopping):
+        (WebKit::UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstraints):
+        (WebKit::UserMediaCaptureManagerProxy::startProducingData):
+        (WebKit::UserMediaCaptureManagerProxy::stopProducingData):
+        (WebKit::UserMediaCaptureManagerProxy::clone):
+        (WebKit::UserMediaCaptureManagerProxy::requestToEnd):
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.h:
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in:
+        * WebProcess/cocoa/UserMediaCaptureManager.cpp:
+        (WebKit::UserMediaCaptureManager::Source::sourceID const):
+        (WebKit::UserMediaCaptureManager::Source::settings const):
+        (WebKit::UserMediaCaptureManager::Source::remoteVideoSampleAvailable):
+        (WebKit::UserMediaCaptureManager::Source::requestToEnd):
+        (WebKit::UserMediaCaptureManager::Source::stopBeingObserved):
+        (WebKit::UserMediaCaptureManager::cloneSource):
+        (WebKit::UserMediaCaptureManager::cloneVideoSource):
+        (WebKit::UserMediaCaptureManager::requestToEnd):
+        (WebKit::UserMediaCaptureManager::VideoFactory::setVideoCapturePageState):
+        * WebProcess/cocoa/UserMediaCaptureManager.h:
+
+2019-12-08  youenn fablet  <[email protected]>
+
         Tighten Mac sandbox by removing microphone access
         https://bugs.webkit.org/show_bug.cgi?id=204939
 

Modified: trunk/Source/WebKit/Shared/WebPreferences.yaml (253274 => 253275)


--- trunk/Source/WebKit/Shared/WebPreferences.yaml	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebKit/Shared/WebPreferences.yaml	2019-12-08 19:10:02 UTC (rev 253275)
@@ -1498,6 +1498,16 @@
   category: experimental
   webcoreName: genericCueAPIEnabled
 
+CaptureVideoInUIProcessEnabled:
+  type: bool
+  defaultValue: false
+  humanReadableName: "Capture video in UIProcess"
+  humanReadableDescription: "Enable video capture in UIProcess"
+  category: experimental
+  webcoreBinding: none
+  condition: ENABLE(MEDIA_STREAM)
+
+
 # For internal features:
 # The type should be boolean.
 # You must provide a humanReadableName and humanReadableDescription for all debug features. They
@@ -1681,15 +1691,6 @@
   webcoreBinding: none
   condition: ENABLE(MEDIA_STREAM)
 
-CaptureVideoInUIProcessEnabled:
-  type: bool
-  defaultValue: false
-  humanReadableName: "Capture video in UIProcess"
-  humanReadableDescription: "Enable video capture in UIProcess"
-  category: internal
-  webcoreBinding: none
-  condition: ENABLE(MEDIA_STREAM)
-
 RestrictedHTTPResponseAccess:
   type: bool
   defaultValue: true

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp (253274 => 253275)


--- trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp	2019-12-08 19:10:02 UTC (rev 253275)
@@ -68,6 +68,25 @@
     CAAudioStreamDescription& description() { return m_description; }
     int64_t numberOfFrames() { return m_numberOfFrames; }
 
+    void start()
+    {
+        m_isEnded = false;
+        m_source->start();
+    }
+
+    void stop()
+    {
+        m_isEnded = true;
+        m_source->stop();
+    }
+
+    void requestToEnd()
+    {
+        m_isEnded = true;
+        m_source->requestToEnd(*this);
+    }
+
+private:
     void sourceStopped() final {
         if (m_source->captureDidFail()) {
             m_connection->send(Messages::UserMediaCaptureManager::CaptureFailed(m_id), 0);
@@ -121,7 +140,12 @@
         m_connection->send(Messages::UserMediaCaptureManager::StorageChanged(m_id, handle, m_description, m_numberOfFrames), 0);
     }
 
-protected:
+    bool preventSourceFromStopping()
+    {
+        // Do not allow the source to stop if we are still using it.
+        return !m_isEnded;
+    }
+
     uint64_t m_id;
     Ref<IPC::Connection> m_connection;
     Ref<RealtimeMediaSource> m_source;
@@ -128,6 +152,7 @@
     CARingBuffer m_ringBuffer;
     CAAudioStreamDescription m_description { };
     int64_t m_numberOfFrames { 0 };
+    bool m_isEnded { false };
 };
 
 UserMediaCaptureManagerProxy::UserMediaCaptureManagerProxy(WebProcessProxy& process)
@@ -169,7 +194,6 @@
     WebCore::RealtimeMediaSourceSettings settings;
     if (sourceOrError) {
         auto source = sourceOrError.source();
-        source->setIsRemote(true);
         settings = source->settings();
         ASSERT(!m_proxies.contains(id));
         m_proxies.add(id, makeUnique<SourceProxy>(id, *m_process.connection(), WTFMove(source)));
@@ -182,7 +206,7 @@
 {
     MESSAGE_CHECK_CONTEXTID(id);
     if (auto* proxy = m_proxies.get(id))
-        proxy->source().start();
+        proxy->start();
 }
 
 void UserMediaCaptureManagerProxy::stopProducingData(uint64_t id)
@@ -189,7 +213,7 @@
 {
     MESSAGE_CHECK_CONTEXTID(id);
     if (auto* proxy = m_proxies.get(id))
-        proxy->source().stop();
+        proxy->stop();
 }
 
 void UserMediaCaptureManagerProxy::end(uint64_t id)
@@ -229,6 +253,20 @@
         m_process.send(Messages::UserMediaCaptureManager::ApplyConstraintsFailed(id, result->badConstraint, result->message), 0);
 }
 
+void UserMediaCaptureManagerProxy::clone(uint64_t clonedID, uint64_t newSourceID)
+{
+    ASSERT(m_proxies.contains(clonedID));
+    ASSERT(!m_proxies.contains(newSourceID));
+    if (auto* proxy = m_proxies.get(clonedID))
+        m_proxies.add(newSourceID, makeUnique<SourceProxy>(newSourceID, *m_process.connection(), proxy->source().clone()));
+}
+
+void UserMediaCaptureManagerProxy::requestToEnd(uint64_t sourceID)
+{
+    if (auto* proxy = m_proxies.get(sourceID))
+        proxy->requestToEnd();
+}
+
 void UserMediaCaptureManagerProxy::clear()
 {
     m_proxies.clear();

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h (253274 => 253275)


--- trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h	2019-12-08 19:10:02 UTC (rev 253275)
@@ -61,6 +61,8 @@
     void capabilities(uint64_t, CompletionHandler<void(WebCore::RealtimeMediaSourceCapabilities&&)>&&);
     void setMuted(uint64_t, bool);
     void applyConstraints(uint64_t, const WebCore::MediaConstraints&);
+    void clone(uint64_t clonedID, uint64_t cloneID);
+    void requestToEnd(uint64_t);
 
     class SourceProxy;
     friend class SourceProxy;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in (253274 => 253275)


--- trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.messages.in	2019-12-08 19:10:02 UTC (rev 253275)
@@ -31,6 +31,8 @@
     Capabilities(uint64_t id) -> (WebCore::RealtimeMediaSourceCapabilities capabilities) Synchronous
     SetMuted(uint64_t id, bool muted)
     ApplyConstraints(uint64_t id, struct WebCore::MediaConstraints constraints)
+    Clone(uint64_t clonedID, uint64_t cloneID)
+    RequestToEnd(uint64_t sourceID)
 }
 
 #endif

Modified: trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp (253274 => 253275)


--- trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp	2019-12-08 19:10:02 UTC (rev 253275)
@@ -110,6 +110,21 @@
         return static_cast<SharedRingBufferStorage&>(m_ringBuffer->storage());
     }
 
+    Ref<RealtimeMediaSource> clone() final
+    {
+        return m_manager.cloneSource(*this);
+    }
+
+    uint64_t sourceID() const
+    {
+        return m_id;
+    }
+
+    const RealtimeMediaSourceSettings& settings() const
+    {
+        return m_settings;
+    }
+
     const RealtimeMediaSourceCapabilities& capabilities() final
     {
         if (!m_capabilities)
@@ -165,17 +180,8 @@
     {
         ASSERT(type() == Type::Video);
 
-        auto remoteSampleSize = remoteSample.size();
-        setIntrinsicSize(remoteSampleSize);
+        setIntrinsicSize(remoteSample.size());
 
-        auto videoSampleSize = IntSize(m_settings.width(), m_settings.height());
-        if (videoSampleSize.isZero())
-            videoSampleSize = remoteSampleSize;
-        else if (!videoSampleSize.height())
-            videoSampleSize.setHeight(videoSampleSize.width() * (remoteSampleSize.height() / static_cast<double>(remoteSampleSize.width())));
-        else if (!videoSampleSize.width())
-            videoSampleSize.setWidth(videoSampleSize.height() * (remoteSampleSize.width() / static_cast<double>(remoteSampleSize.height())));
-
         if (!m_imageTransferSession || m_imageTransferSession->pixelFormat() != remoteSample.videoFormat())
             m_imageTransferSession = ImageTransferSessionVT::create(remoteSample.videoFormat());
 
@@ -184,7 +190,7 @@
             return;
         }
 
-        auto sampleRef = m_imageTransferSession->createMediaSample(remoteSample.surface(), remoteSample.time(), videoSampleSize);
+        auto sampleRef = m_imageTransferSession->createMediaSample(remoteSample.surface(), remoteSample.time(), remoteSample.size());
         if (!sampleRef) {
             ASSERT_NOT_REACHED();
             return;
@@ -208,11 +214,12 @@
         callback(ApplyConstraintsError { WTFMove(failedConstraint), WTFMove(errorMessage) });
     }
 
+    CaptureDevice::DeviceType deviceType() const final { return m_deviceType; }
+
 private:
     void startProducingData() final { m_manager.startProducingData(m_id); }
     void stopProducingData() final { m_manager.stopProducingData(m_id); }
     bool isCaptureSource() const final { return true; }
-    CaptureDevice::DeviceType deviceType() const final { return m_deviceType; }
 
     // RealtimeMediaSource
     void beginConfiguration() final { }
@@ -225,6 +232,16 @@
         m_pendingApplyConstraintsCallbacks.append(WTFMove(completionHandler));
     }
 
+    void requestToEnd(RealtimeMediaSource::Observer&)
+    {
+        m_manager.requestToEnd(m_id);
+    }
+
+    void stopBeingObserved()
+    {
+        m_manager.requestToEnd(m_id);
+    }
+
     uint64_t m_id;
     UserMediaCaptureManager& m_manager;
     mutable Optional<RealtimeMediaSourceCapabilities> m_capabilities;
@@ -400,17 +417,51 @@
         source->applyConstraintsFailed(WTFMove(failedConstraint), WTFMove(message));
 }
 
+Ref<RealtimeMediaSource> UserMediaCaptureManager::cloneSource(Source& source)
+{
+    switch (source.type()) {
+    case RealtimeMediaSource::Type::Video:
+        return cloneVideoSource(source);
+    case RealtimeMediaSource::Type::Audio:
+        break;
+    case RealtimeMediaSource::Type::None:
+        ASSERT_NOT_REACHED();
+    }
+    return makeRef(source);
+}
+
+Ref<RealtimeMediaSource> UserMediaCaptureManager::cloneVideoSource(Source& source)
+{
+    uint64_t id = nextSessionID();
+    if (!m_process.send(Messages::UserMediaCaptureManagerProxy::Clone { source.sourceID(), id }, 0))
+        return makeRef(source);
+
+    auto settings = source.settings();
+    auto cloneSource = adoptRef(*new Source(String::number(id), source.type(), source.deviceType(), String { settings.label().string() }, source.deviceIDHashSalt(), id, *this));
+    cloneSource->setSettings(WTFMove(settings));
+    m_sources.add(id, cloneSource.copyRef());
+    return cloneSource;
+}
+
+void UserMediaCaptureManager::requestToEnd(uint64_t sourceID)
+{
+    m_process.send(Messages::UserMediaCaptureManagerProxy::RequestToEnd { sourceID }, 0);
+}
+
 #if PLATFORM(IOS_FAMILY)
 void UserMediaCaptureManager::AudioFactory::setAudioCapturePageState(bool interrupted, bool pageMuted)
 {
-    if (auto* activeSource = static_cast<AudioCaptureFactory*>(this)->activeSource())
+    if (auto* activeSource = this->activeSource())
         activeSource->setInterrupted(interrupted, pageMuted);
 }
 
 void UserMediaCaptureManager::VideoFactory::setVideoCapturePageState(bool interrupted, bool pageMuted)
 {
-    if (auto* activeSource = static_cast<VideoCaptureFactory*>(this)->activeSource())
-        activeSource->setInterrupted(interrupted, pageMuted);
+    // In case of cloning, we might have more than a single source.
+    for (auto& source : m_manager.m_sources.values()) {
+        if (source->deviceType() == CaptureDevice::DeviceType::Camera)
+            source->setInterrupted(interrupted, pageMuted);
+    }
 }
 #endif
 

Modified: trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.h (253274 => 253275)


--- trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.h	2019-12-08 16:41:09 UTC (rev 253274)
+++ trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.h	2019-12-08 19:10:02 UTC (rev 253275)
@@ -134,6 +134,11 @@
 
     class Source;
     friend class Source;
+
+    void requestToEnd(uint64_t sourceID);
+    Ref<WebCore::RealtimeMediaSource> cloneSource(Source&);
+    Ref<WebCore::RealtimeMediaSource> cloneVideoSource(Source&);
+
     HashMap<uint64_t, RefPtr<Source>> m_sources;
     WebProcess& m_process;
     NoOpCaptureDeviceManager m_noOpCaptureDeviceManager;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to