Title: [288954] trunk/Source
Revision
288954
Author
[email protected]
Date
2022-02-02 08:57:05 -0800 (Wed, 02 Feb 2022)

Log Message

RealtimeVideoSource::adaptVideoSample should not create IOSurfaces when running in WebProcess
https://bugs.webkit.org/show_bug.cgi?id=236011
<rdar://88367968>

Reviewed by Eric Carlson.

Source/WebCore:

Add a way to not use IOSurfaces when using ImageTransferSessionVT.
Use this in RealtimeVideoSource to toggle IOSurface use on and off when downsampling samples.

Covered by existing tests.

* platform/graphics/cv/CVUtilities.h:
* platform/graphics/cv/CVUtilities.mm:
* platform/graphics/cv/ImageTransferSessionVT.h:
* platform/graphics/cv/ImageTransferSessionVT.mm:
* platform/mediastream/RealtimeVideoSource.cpp:
* platform/mediastream/RealtimeVideoSource.h:

Source/WebKit:

Disable IOSurface use for WebProcess RealtimeVideoSources.

* WebProcess/cocoa/UserMediaCaptureManager.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288953 => 288954)


--- trunk/Source/WebCore/ChangeLog	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebCore/ChangeLog	2022-02-02 16:57:05 UTC (rev 288954)
@@ -1,3 +1,23 @@
+2022-02-02  Youenn Fablet  <[email protected]>
+
+        RealtimeVideoSource::adaptVideoSample should not create IOSurfaces when running in WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=236011
+        <rdar://88367968>
+
+        Reviewed by Eric Carlson.
+
+        Add a way to not use IOSurfaces when using ImageTransferSessionVT.
+        Use this in RealtimeVideoSource to toggle IOSurface use on and off when downsampling samples.
+
+        Covered by existing tests.
+
+        * platform/graphics/cv/CVUtilities.h:
+        * platform/graphics/cv/CVUtilities.mm:
+        * platform/graphics/cv/ImageTransferSessionVT.h:
+        * platform/graphics/cv/ImageTransferSessionVT.mm:
+        * platform/mediastream/RealtimeVideoSource.cpp:
+        * platform/mediastream/RealtimeVideoSource.h:
+
 2022-02-02  Tyler Wilcock  <[email protected]>
 
         AX: Display startObject and anchorObject objectID when logging AccessibilitySearchCriteria from AXLogger

Modified: trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h (288953 => 288954)


--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h	2022-02-02 16:57:05 UTC (rev 288954)
@@ -41,6 +41,8 @@
 // These buffers can be for example sent through IPC.
 WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createIOSurfaceCVPixelBufferPool(size_t width, size_t height, OSType pixelFormat, unsigned minimumBufferCount = 0u);
 
+WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createInMemoryCVPixelBufferPool(size_t width, size_t height, OSType pixelFormat, unsigned minimumBufferCount = 0u);
+
 WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBufferFromPool(CVPixelBufferPoolRef);
 
 WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBuffer(IOSurfaceRef);

Modified: trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm (288953 => 288954)


--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm	2022-02-02 16:57:05 UTC (rev 288954)
@@ -34,18 +34,8 @@
 
 namespace WebCore {
 
-Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createIOSurfaceCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount)
+static Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createBufferPool(unsigned minimumBufferCount, NSDictionary *pixelAttributes)
 {
-    auto pixelAttributes = @{
-        (__bridge NSString *)kCVPixelBufferWidthKey : @(width),
-        (__bridge NSString *)kCVPixelBufferHeightKey : @(height),
-        (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(format),
-        (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey : @NO,
-#if PLATFORM(MAC)
-        (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
-#endif
-        (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
-    };
     NSDictionary *poolOptions = nullptr;
     if (minimumBufferCount) {
         poolOptions = @{
@@ -59,6 +49,33 @@
     return adoptCF(pool);
 }
 
+Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createIOSurfaceCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount)
+{
+    return createBufferPool(minimumBufferCount, @{
+        (__bridge NSString *)kCVPixelBufferWidthKey : @(width),
+        (__bridge NSString *)kCVPixelBufferHeightKey : @(height),
+        (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(format),
+        (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey : @NO,
+#if PLATFORM(MAC)
+        (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
+#endif
+        (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
+    });
+}
+
+Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createInMemoryCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount)
+{
+    return createBufferPool(minimumBufferCount, @{
+        (__bridge NSString *)kCVPixelBufferWidthKey : @(width),
+        (__bridge NSString *)kCVPixelBufferHeightKey : @(height),
+        (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(format),
+        (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey : @NO,
+#if PLATFORM(MAC)
+        (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
+#endif
+    });
+}
+
 Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBufferFromPool(CVPixelBufferPoolRef pixelBufferPool)
 {
     CVPixelBufferRef pixelBuffer = nullptr;

Modified: trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h (288953 => 288954)


--- trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h	2022-02-02 16:57:05 UTC (rev 288954)
@@ -42,9 +42,9 @@
 
 class ImageTransferSessionVT {
 public:
-    static std::unique_ptr<ImageTransferSessionVT> create(uint32_t pixelFormat)
+    static std::unique_ptr<ImageTransferSessionVT> create(uint32_t pixelFormat, bool shouldUseIOSurface = true)
     {
-        return std::unique_ptr<ImageTransferSessionVT>(new ImageTransferSessionVT(pixelFormat));
+        return std::unique_ptr<ImageTransferSessionVT>(new ImageTransferSessionVT(pixelFormat, shouldUseIOSurface));
     }
 
     RefPtr<MediaSample> convertMediaSample(MediaSample&, const IntSize&);
@@ -61,7 +61,7 @@
     uint32_t pixelFormat() const { return m_pixelFormat; }
 
 private:
-    WEBCORE_EXPORT explicit ImageTransferSessionVT(uint32_t pixelFormat);
+    WEBCORE_EXPORT ImageTransferSessionVT(uint32_t pixelFormat, bool shouldUseIOSurface);
 
 #if !PLATFORM(MACCATALYST)
     RetainPtr<CMSampleBufferRef> createCMSampleBuffer(IOSurfaceRef, const MediaTime&, const IntSize&);
@@ -79,7 +79,7 @@
 
     RetainPtr<VTPixelTransferSessionRef> m_transferSession;
     RetainPtr<CVPixelBufferPoolRef> m_outputBufferPool;
-    RetainPtr<CFDictionaryRef> m_ioSurfaceBufferAttributes;
+    bool m_shouldUseIOSurface { true };
     uint32_t m_pixelFormat;
     IntSize m_size;
 };

Modified: trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm (288953 => 288954)


--- trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm	2022-02-02 16:57:05 UTC (rev 288954)
@@ -44,7 +44,8 @@
 
 namespace WebCore {
 
-ImageTransferSessionVT::ImageTransferSessionVT(uint32_t pixelFormat)
+ImageTransferSessionVT::ImageTransferSessionVT(uint32_t pixelFormat, bool shouldUseIOSurface)
+    : m_shouldUseIOSurface(shouldUseIOSurface)
 {
     VTPixelTransferSessionRef transferSession;
     VTPixelTransferSessionCreate(kCFAllocatorDefault, &transferSession);
@@ -76,7 +77,7 @@
 {
     if (m_size == size && m_outputBufferPool)
         return true;
-    auto bufferPool = createIOSurfaceCVPixelBufferPool(size.width(), size.height(), m_pixelFormat, 6).value_or(nullptr);
+    auto bufferPool = m_shouldUseIOSurface ? createIOSurfaceCVPixelBufferPool(size.width(), size.height(), m_pixelFormat, 6).value_or(nullptr) : createInMemoryCVPixelBufferPool(size.width(), size.height(), m_pixelFormat, 6).value_or(nullptr);
     if (!bufferPool)
         return false;
     m_outputBufferPool = WTFMove(bufferPool);

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp (288953 => 288954)


--- trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp	2022-02-02 16:57:05 UTC (rev 288954)
@@ -34,10 +34,14 @@
 
 namespace WebCore {
 
-RealtimeVideoSource::RealtimeVideoSource(Ref<RealtimeVideoCaptureSource>&& source)
+RealtimeVideoSource::RealtimeVideoSource(Ref<RealtimeVideoCaptureSource>&& source, bool shouldUseIOSurface)
     : RealtimeMediaSource(Type::Video, String { source->name() }, String { source->persistentID() }, String { source->deviceIDHashSalt() })
     , m_source(WTFMove(source))
+#if PLATFORM(COCOA)
+    , m_shouldUseIOSurface(shouldUseIOSurface)
+#endif
 {
+    UNUSED_PARAM(shouldUseIOSurface);
     m_source->addObserver(*this);
     m_currentSettings = m_source->settings();
     setSize(m_source->size());
@@ -166,7 +170,7 @@
 RefPtr<MediaSample> RealtimeVideoSource::adaptVideoSample(MediaSample& sample)
 {
     if (!m_imageTransferSession || m_imageTransferSession->pixelFormat() != sample.videoPixelFormat())
-        m_imageTransferSession = ImageTransferSessionVT::create(sample.videoPixelFormat());
+        m_imageTransferSession = ImageTransferSessionVT::create(sample.videoPixelFormat(), m_shouldUseIOSurface);
 
     ASSERT(m_imageTransferSession);
     if (!m_imageTransferSession)

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.h (288953 => 288954)


--- trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.h	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.h	2022-02-02 16:57:05 UTC (rev 288954)
@@ -38,12 +38,12 @@
     , public RealtimeMediaSource::Observer
     , public RealtimeMediaSource::VideoSampleObserver {
 public:
-    static Ref<RealtimeVideoSource> create(Ref<RealtimeVideoCaptureSource>&& source) { return adoptRef(*new RealtimeVideoSource(WTFMove(source))); }
+    static Ref<RealtimeVideoSource> create(Ref<RealtimeVideoCaptureSource>&& source, bool shouldUseIOSurface = true) { return adoptRef(*new RealtimeVideoSource(WTFMove(source), shouldUseIOSurface)); }
 
     Vector<VideoPresetData> presetsData() { return m_source->presetsData(); }
 
 private:
-    WEBCORE_EXPORT explicit RealtimeVideoSource(Ref<RealtimeVideoCaptureSource>&&);
+    WEBCORE_EXPORT RealtimeVideoSource(Ref<RealtimeVideoCaptureSource>&&, bool shouldUseIOSurface);
     ~RealtimeVideoSource();
 
     // RealtimeMediaSource
@@ -86,6 +86,7 @@
     RealtimeMediaSourceSettings m_currentSettings;
 #if PLATFORM(COCOA)
     std::unique_ptr<ImageTransferSessionVT> m_imageTransferSession;
+    bool m_shouldUseIOSurface { true };
 #endif
     size_t m_frameDecimation { 1 };
     size_t m_frameDecimationCounter { 0 };

Modified: trunk/Source/WebKit/ChangeLog (288953 => 288954)


--- trunk/Source/WebKit/ChangeLog	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebKit/ChangeLog	2022-02-02 16:57:05 UTC (rev 288954)
@@ -1,5 +1,17 @@
 2022-02-02  Youenn Fablet  <[email protected]>
 
+        RealtimeVideoSource::adaptVideoSample should not create IOSurfaces when running in WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=236011
+        <rdar://88367968>
+
+        Reviewed by Eric Carlson.
+
+        Disable IOSurface use for WebProcess RealtimeVideoSources.
+
+        * WebProcess/cocoa/UserMediaCaptureManager.cpp:
+
+2022-02-02  Youenn Fablet  <[email protected]>
+
         LibWebRTCCodecs should not need to create IOSurfaces
         https://bugs.webkit.org/show_bug.cgi?id=235951
         <rdar://problem/88326654>

Modified: trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp (288953 => 288954)


--- trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp	2022-02-02 16:43:14 UTC (rev 288953)
+++ trunk/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp	2022-02-02 16:57:05 UTC (rev 288954)
@@ -237,12 +237,13 @@
         return CaptureSourceOrError { "Video capture in GPUProcess is not implemented"_s };
 #endif
 
-    return CaptureSourceOrError(RealtimeVideoSource::create(RemoteRealtimeVideoSource::create(device, constraints, { }, WTFMove(hashSalt), m_manager, m_shouldCaptureInGPUProcess)));
+    bool shouldUseIOSurface = false;
+    return CaptureSourceOrError(RealtimeVideoSource::create(RemoteRealtimeVideoSource::create(device, constraints, { }, WTFMove(hashSalt), m_manager, m_shouldCaptureInGPUProcess), shouldUseIOSurface));
 }
 
 CaptureSourceOrError UserMediaCaptureManager::DisplayFactory::createDisplayCaptureSource(const CaptureDevice& device, String&& hashSalt, const MediaConstraints* constraints)
 {
-    return CaptureSourceOrError(RemoteRealtimeDisplaySource::create(device, constraints, WTFMove(hashSalt), m_manager, false));
+    return RemoteRealtimeDisplaySource::create(device, constraints, WTFMove(hashSalt), m_manager, false);
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to