Enable the possibility to do video capture in UIProcess
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Dec 2018 22:32:26 +0000 (22:32 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Dec 2018 22:32:26 +0000 (22:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192394

Reviewed by Eric Carlson.

Source/WebCore:

Create IOSurface-backed sample buffers so that we can easily send them through IPC.
Manually tested.

* platform/mediastream/mac/AVVideoCaptureSource.mm:
(WebCore::AVVideoCaptureSource::setSizeAndFrameRateWithPreset):

Source/WebKit:

Add two web preferences to toggle audio/video capture in UIProcess or WebProcess.
Add mechanism for video capture that was not implemented yet.

* Shared/WebPreferences.yaml:
* Shared/WebPreferencesDefaultValues.h:
* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetCaptureAudioInUIProcessEnabled):
(WKPreferencesGetCaptureAudioInUIProcessEnabled):
(WKPreferencesSetCaptureVideoInUIProcessEnabled):
(WKPreferencesGetCaptureVideoInUIProcessEnabled):
* UIProcess/API/C/WKPreferencesRef.h:
* UIProcess/WebPreferences.cpp:
(WebKit::WebPreferences::updateBoolValueForInternalDebugFeatureKey):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::initializeNewWebProcess):
(WebKit::WebProcessPool::createWebPage):
* WebProcess/cocoa/UserMediaCaptureManager.cpp:
(WebKit::UserMediaCaptureManager::initialize):

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/Shared/WebPreferencesDefaultValues.h
Source/WebKit/Shared/WebProcessCreationParameters.cpp
Source/WebKit/Shared/WebProcessCreationParameters.h
Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h
Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Source/WebKit/UIProcess/API/C/WKPreferencesRef.h
Source/WebKit/UIProcess/WebPreferences.cpp
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp

index a02c7b0..8eecac1 100644 (file)
@@ -1,5 +1,18 @@
 2018-12-05  Youenn Fablet  <youenn@apple.com>
 
+        Enable the possibility to do video capture in UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=192394
+
+        Reviewed by Eric Carlson.
+
+        Create IOSurface-backed sample buffers so that we can easily send them through IPC.
+        Manually tested.
+
+        * platform/mediastream/mac/AVVideoCaptureSource.mm:
+        (WebCore::AVVideoCaptureSource::setSizeAndFrameRateWithPreset):
+
+2018-12-05  Youenn Fablet  <youenn@apple.com>
+
         Update ServiceWorkerContainer::getRegistration lambdas
         https://bugs.webkit.org/show_bug.cgi?id=192376
 
index 4017961..55ebac8 100644 (file)
@@ -342,7 +342,8 @@ void AVVideoCaptureSource::setSizeAndFrameRateWithPreset(IntSize requestedSize,
                 auto settingsDictionary = @{
                     (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(avVideoCapturePixelBufferFormat()),
                     (__bridge NSString *)kCVPixelBufferWidthKey: @(avPreset->size.width()),
-                    (__bridge NSString *)kCVPixelBufferHeightKey: @(avPreset->size.height())
+                    (__bridge NSString *)kCVPixelBufferHeightKey: @(avPreset->size.height()),
+                    (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
                 };
                 [m_videoOutput setVideoSettings:settingsDictionary];
 #endif
index 58256a4..6db959a 100644 (file)
@@ -1,3 +1,34 @@
+2018-12-05  Youenn Fablet  <youenn@apple.com>
+
+        Enable the possibility to do video capture in UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=192394
+
+        Reviewed by Eric Carlson.
+
+        Add two web preferences to toggle audio/video capture in UIProcess or WebProcess.
+        Add mechanism for video capture that was not implemented yet.
+
+        * Shared/WebPreferences.yaml:
+        * Shared/WebPreferencesDefaultValues.h:
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/API/APIProcessPoolConfiguration.h:
+        * UIProcess/API/C/WKPreferences.cpp:
+        (WKPreferencesSetCaptureAudioInUIProcessEnabled):
+        (WKPreferencesGetCaptureAudioInUIProcessEnabled):
+        (WKPreferencesSetCaptureVideoInUIProcessEnabled):
+        (WKPreferencesGetCaptureVideoInUIProcessEnabled):
+        * UIProcess/API/C/WKPreferencesRef.h:
+        * UIProcess/WebPreferences.cpp:
+        (WebKit::WebPreferences::updateBoolValueForInternalDebugFeatureKey):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::initializeNewWebProcess):
+        (WebKit::WebProcessPool::createWebPage):
+        * WebProcess/cocoa/UserMediaCaptureManager.cpp:
+        (WebKit::UserMediaCaptureManager::initialize):
+
 2018-12-05  Alex Christensen  <achristensen@webkit.org>
 
         Make WebsiteDataStoreConfiguration a proper API object
index 6d25e71..b94b97c 100644 (file)
@@ -1474,3 +1474,20 @@ LayoutFormattingContextEnabled:
   webcoreBinding: RuntimeEnabledFeatures
   condition: ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+CaptureAudioInUIProcessEnabled:
+  type: bool
+  defaultValue: DEFAULT_CAPTURE_AUDIO_IN_UIPROCESS
+  humanReadableName: "Capture audio in UIProcess"
+  humanReadableDescription: "Enable audio capture in UIProcess"
+  category: internal
+  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)
index 7a88f21..1d07882 100644 (file)
 bool defaultPassiveTouchListenersAsDefaultOnDocument();
 bool defaultCustomPasteboardDataEnabled();
 
+#if PLATFORM(MAC)
+#define DEFAULT_CAPTURE_AUDIO_IN_UIPROCESS true
+#else
+#define DEFAULT_CAPTURE_AUDIO_IN_UIPROCESS false
+#endif
+
 #if PLATFORM(WATCHOS)
 #define DEFAULT_INPUT_TYPE_COLOR_ENABLED false
 #define DEFAULT_DATALIST_ELEMENT_ENABLED false
index 11fc195..475f208 100644 (file)
@@ -69,6 +69,7 @@ void WebProcessCreationParameters::encode(IPC::Encoder& encoder) const
 #if ENABLE(MEDIA_STREAM)
     encoder << audioCaptureExtensionHandle;
     encoder << shouldCaptureAudioInUIProcess;
+    encoder << shouldCaptureVideoInUIProcess;
     encoder << shouldCaptureDisplayInUIProcess;
 #endif
     encoder << shouldUseTestingNetworkSession;
@@ -261,6 +262,8 @@ bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreat
 
     if (!decoder.decode(parameters.shouldCaptureAudioInUIProcess))
         return false;
+    if (!decoder.decode(parameters.shouldCaptureVideoInUIProcess))
+        return false;
     if (!decoder.decode(parameters.shouldCaptureDisplayInUIProcess))
         return false;
 #endif
index a966849..7b67f89 100644 (file)
@@ -93,6 +93,7 @@ struct WebProcessCreationParameters {
 #if ENABLE(MEDIA_STREAM)
     SandboxExtension::Handle audioCaptureExtensionHandle;
     bool shouldCaptureAudioInUIProcess { false };
+    bool shouldCaptureVideoInUIProcess { false };
     bool shouldCaptureDisplayInUIProcess { false };
 #endif
     String mediaKeyStorageDirectory;
index c34573e..9881bd8 100644 (file)
@@ -138,6 +138,9 @@ public:
     bool shouldCaptureAudioInUIProcess() const { return m_shouldCaptureAudioInUIProcess; }
     void setShouldCaptureAudioInUIProcess(bool shouldCaptureAudioInUIProcess) { m_shouldCaptureAudioInUIProcess = shouldCaptureAudioInUIProcess; }
 
+    bool shouldCaptureVideoInUIProcess() const { return m_shouldCaptureVideoInUIProcess; }
+    void setShouldCaptureVideoInUIProcess(bool shouldCaptureVideoInUIProcess) { m_shouldCaptureVideoInUIProcess = shouldCaptureVideoInUIProcess; }
+
     bool shouldCaptureDisplayInUIProcess() const { return m_shouldCaptureDisplayInUIProcess; }
     void setShouldCaptureDisplayInUIProcess(bool shouldCaptureDisplayInUIProcess) { m_shouldCaptureDisplayInUIProcess = shouldCaptureDisplayInUIProcess; }
 
@@ -206,6 +209,7 @@ private:
     bool m_alwaysRunsAtBackgroundPriority { false };
     bool m_shouldTakeUIBackgroundAssertion { true };
     bool m_shouldCaptureAudioInUIProcess { false };
+    bool m_shouldCaptureVideoInUIProcess { false };
     bool m_shouldCaptureDisplayInUIProcess { DEFAULT_CAPTURE_DISPLAY_IN_UI_PROCESS };
     ProcessID m_presentingApplicationPID { getCurrentProcessID() };
     std::optional<bool> m_processSwapsOnNavigationFromClient;
index 823174a..9bc94b4 100644 (file)
@@ -2079,3 +2079,23 @@ bool WKPreferencesGetWebSQLDisabled(WKPreferencesRef preferencesRef)
 {
     return toImpl(preferencesRef)->webSQLDisabled();
 }
+
+void WKPreferencesSetCaptureAudioInUIProcessEnabled(WKPreferencesRef preferencesRef, bool flag)
+{
+    toImpl(preferencesRef)->setCaptureAudioInUIProcessEnabled(flag);
+}
+
+bool WKPreferencesGetCaptureAudioInUIProcessEnabled(WKPreferencesRef preferencesRef)
+{
+    return toImpl(preferencesRef)->captureAudioInUIProcessEnabled();
+}
+
+void WKPreferencesSetCaptureVideoInUIProcessEnabled(WKPreferencesRef preferencesRef, bool flag)
+{
+    toImpl(preferencesRef)->setCaptureVideoInUIProcessEnabled(flag);
+}
+
+bool WKPreferencesGetCaptureVideoInUIProcessEnabled(WKPreferencesRef preferencesRef)
+{
+    return toImpl(preferencesRef)->captureVideoInUIProcessEnabled();
+}
index 9716693..a06e53c 100644 (file)
@@ -332,6 +332,11 @@ WK_EXPORT void WKPreferencesSetProcessSwapOnNavigationEnabled(WKPreferencesRef p
 WK_EXPORT bool WKPreferencesGetWebSQLDisabled(WKPreferencesRef preferencesRef);
 WK_EXPORT void WKPreferencesSetWebSQLDisabled(WKPreferencesRef preferencesRef, bool enabled);
 
+WK_EXPORT void WKPreferencesSetCaptureAudioInUIProcessEnabled(WKPreferencesRef preferencesRef, bool flag);
+WK_EXPORT bool WKPreferencesGetCaptureAudioInUIProcessEnabled(WKPreferencesRef preferencesRef);
+WK_EXPORT void WKPreferencesSetCaptureVideoInUIProcessEnabled(WKPreferencesRef preferencesRef, bool flag);
+WK_EXPORT bool WKPreferencesGetCaptureVideoInUIProcessEnabled(WKPreferencesRef preferencesRef);
+
 #ifdef __cplusplus
 }
 #endif
index 44a0a02..7002db2 100644 (file)
@@ -139,6 +139,18 @@ void WebPreferences::updateBoolValueForInternalDebugFeatureKey(const String& key
 
         return;
     }
+    if (key == WebPreferencesKey::captureAudioInUIProcessEnabledKey()) {
+        for (auto* page : m_pages)
+            page->process().processPool().configuration().setShouldCaptureAudioInUIProcess(value);
+
+        return;
+    }
+    if (key == WebPreferencesKey::captureVideoInUIProcessEnabledKey()) {
+        for (auto* page : m_pages)
+            page->process().processPool().configuration().setShouldCaptureVideoInUIProcess(value);
+
+        return;
+    }
 
     update(); // FIXME: Only send over the changed key and value.
 }
index 2cd4c1a..2c371a3 100644 (file)
@@ -919,6 +919,7 @@ void WebProcessPool::initializeNewWebProcess(WebProcessProxy& process, WebsiteDa
     parameters.resourceLoadStatisticsEnabled = websiteDataStore.resourceLoadStatisticsEnabled();
 #if ENABLE(MEDIA_STREAM)
     parameters.shouldCaptureAudioInUIProcess = m_configuration->shouldCaptureAudioInUIProcess();
+    parameters.shouldCaptureVideoInUIProcess = m_configuration->shouldCaptureVideoInUIProcess();
     parameters.shouldCaptureDisplayInUIProcess = m_configuration->shouldCaptureDisplayInUIProcess();
 #endif
 
@@ -1146,6 +1147,8 @@ Ref<WebPageProxy> WebProcessPool::createWebPage(PageClient& pageClient, Ref<API:
 
     auto page = process->createWebPage(pageClient, WTFMove(pageConfiguration));
     m_configuration->setProcessSwapsOnNavigationFromExperimentalFeatures(page->preferences().processSwapOnCrossSiteNavigationEnabled());
+    m_configuration->setShouldCaptureAudioInUIProcess(page->preferences().captureAudioInUIProcessEnabled());
+    m_configuration->setShouldCaptureVideoInUIProcess(page->preferences().captureVideoInUIProcessEnabled());
 
     return page;
 }
index 7236a5b..9608e68 100644 (file)
@@ -219,6 +219,8 @@ void UserMediaCaptureManager::initialize(const WebProcessCreationParameters& par
 {
     if (parameters.shouldCaptureAudioInUIProcess)
         RealtimeMediaSourceCenter::setAudioFactory(*this);
+    if (parameters.shouldCaptureVideoInUIProcess)
+        RealtimeMediaSourceCenter::setVideoFactory(*this);
     if (parameters.shouldCaptureDisplayInUIProcess)
         RealtimeMediaSourceCenter::setDisplayCaptureFactory(*this);
 }