Diff
Modified: trunk/Source/WebCore/ChangeLog (293885 => 293886)
--- trunk/Source/WebCore/ChangeLog 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebCore/ChangeLog 2022-05-06 09:52:39 UTC (rev 293886)
@@ -1,5 +1,26 @@
2022-05-06 Youenn Fablet <[email protected]>
+ Allow MediaPlayerPrivateMediaStreamAVFObjC to avoid pixel conformers if IOSurfaces are not allowed
+ https://bugs.webkit.org/show_bug.cgi?id=240113
+ rdar://92629845
+
+ Reviewed by Eric Carlson.
+
+ Add a callback in MediaPlayerPrivateMediaStreamAVFObjC to allow use a custom way to create a NativeImage from a VideoFrame.
+ Small refactoring in PixelBufferConformerCV to share more code with WebKit.
+ Make sure that SharedVideoFrameReader/Writer support kCVPixelFormatType_420YpCbCr10BiPlanarFullRange.
+ Covered by existing tests.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/cocoa/SharedVideoFrameInfo.mm:
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+ * platform/graphics/cv/CVUtilities.h:
+ * platform/graphics/cv/PixelBufferConformerCV.cpp:
+ * platform/graphics/cv/PixelBufferConformerCV.h:
+
+2022-05-06 Youenn Fablet <[email protected]>
+
Remove usage of PixelBufferConformer in RealtimeOutgoingVideoSourceCocoa
https://bugs.webkit.org/show_bug.cgi?id=240118
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (293885 => 293886)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-05-06 09:52:39 UTC (rev 293886)
@@ -462,7 +462,7 @@
14DCF3B31B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 14DCF3B11B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h */; };
14E8378E09F85D4F00B85AE4 /* JSEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 14E8378D09F85D4F00B85AE4 /* JSEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
14FFE31D0AE1963300136BF5 /* HTMLFrameElementBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 14FFE31B0AE1963300136BF5 /* HTMLFrameElementBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
- 150524F41B712FF600696AA9 /* MediaPlayerPrivateMediaStreamAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 150524F01B712FF000696AA9 /* MediaPlayerPrivateMediaStreamAVFObjC.h */; };
+ 150524F41B712FF600696AA9 /* MediaPlayerPrivateMediaStreamAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 150524F01B712FF000696AA9 /* MediaPlayerPrivateMediaStreamAVFObjC.h */; settings = {ATTRIBUTES = (Private, ); }; };
15145B901B3A1CE000662BF7 /* MediaDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 15145B8F1B3A1B3E00662BF7 /* MediaDeviceInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
15739BBB1B42012D00D258C1 /* JSMediaDevices.h in Headers */ = {isa = PBXBuildFile; fileRef = 15739BB91B42012200D258C1 /* JSMediaDevices.h */; };
159741DB1B7D140100201C92 /* JSMediaDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 157CC2621B7C1CA400D8D075 /* JSMediaDeviceInfo.h */; };
Modified: trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.mm (293885 => 293886)
--- trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.mm 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.mm 2022-05-06 09:52:39 UTC (rev 293886)
@@ -51,17 +51,18 @@
SharedVideoFrameInfo SharedVideoFrameInfo::fromCVPixelBuffer(CVPixelBufferRef pixelBuffer)
{
auto type = CVPixelBufferGetPixelFormatType(pixelBuffer);
- if (type == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || type == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
- return { type, static_cast<uint32_t>(CVPixelBufferGetWidthOfPlane(pixelBuffer, 0)), static_cast<uint32_t>(CVPixelBufferGetHeightOfPlane(pixelBuffer, 0)), static_cast<uint32_t>(CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0)), static_cast<uint32_t>(CVPixelBufferGetWidthOfPlane(pixelBuffer, 1)), static_cast<uint32_t>(CVPixelBufferGetHeightOfPlane(pixelBuffer, 1)), static_cast<uint32_t>(CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 1)) };
- return { type, static_cast<uint32_t>(CVPixelBufferGetWidth(pixelBuffer)), static_cast<uint32_t>(CVPixelBufferGetHeight(pixelBuffer)), static_cast<uint32_t>(CVPixelBufferGetBytesPerRow(pixelBuffer)) };
+ if (type == kCVPixelFormatType_32BGRA)
+ return { type, static_cast<uint32_t>(CVPixelBufferGetWidth(pixelBuffer)), static_cast<uint32_t>(CVPixelBufferGetHeight(pixelBuffer)), static_cast<uint32_t>(CVPixelBufferGetBytesPerRow(pixelBuffer)) };
+ return { type, static_cast<uint32_t>(CVPixelBufferGetWidthOfPlane(pixelBuffer, 0)), static_cast<uint32_t>(CVPixelBufferGetHeightOfPlane(pixelBuffer, 0)), static_cast<uint32_t>(CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0)), static_cast<uint32_t>(CVPixelBufferGetWidthOfPlane(pixelBuffer, 1)), static_cast<uint32_t>(CVPixelBufferGetHeightOfPlane(pixelBuffer, 1)), static_cast<uint32_t>(CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 1)) };
}
bool SharedVideoFrameInfo::isReadWriteSupported() const
{
- return m_bufferType == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
- || m_bufferType == kCVPixelFormatType_32BGRA
+ return m_bufferType == kCVPixelFormatType_32BGRA
|| m_bufferType == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
- || m_bufferType == kCVPixelFormatType_420YpCbCr10BiPlanarFullRange;
+ || m_bufferType == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
+ || m_bufferType == kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
+ || m_bufferType == kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange;
}
size_t SharedVideoFrameInfo::storageSize() const
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h (293885 => 293886)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h 2022-05-06 09:52:39 UTC (rev 293886)
@@ -63,6 +63,9 @@
static void registerMediaEngine(MediaEngineRegistrar);
+ using NativeImageCreator = RefPtr<NativeImage> (*)(const VideoFrame&);
+ WEBCORE_EXPORT static void setNativeImageCreator(NativeImageCreator&&);
+
// MediaPlayer Factory Methods
static bool isAvailable();
static void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& types);
@@ -290,8 +293,10 @@
Seconds m_presentationTime { 0 };
FloatSize m_videoFrameSize;
VideoFrameTimeMetadata m_sampleMetadata;
+
+ static NativeImageCreator m_nativeImageCreator;
};
-
+
}
#endif // ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm (293885 => 293886)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm 2022-05-06 09:52:39 UTC (rev 293886)
@@ -127,6 +127,12 @@
#pragma mark -
#pragma mark MediaPlayerPrivateMediaStreamAVFObjC
+MediaPlayerPrivateMediaStreamAVFObjC::NativeImageCreator MediaPlayerPrivateMediaStreamAVFObjC::m_nativeImageCreator = nullptr;
+void MediaPlayerPrivateMediaStreamAVFObjC::setNativeImageCreator(NativeImageCreator&& callback)
+{
+ m_nativeImageCreator = WTFMove(callback);
+}
+
MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC(MediaPlayer* player)
: m_player(player)
, m_logger(player->mediaPlayerLogger())
@@ -996,6 +1002,11 @@
if (m_imagePainter.cgImage || !m_imagePainter.videoFrame)
return;
+ if (m_nativeImageCreator) {
+ m_imagePainter.cgImage = m_nativeImageCreator(*m_imagePainter.videoFrame);
+ return;
+ }
+
if (!m_imagePainter.pixelBufferConformer)
m_imagePainter.pixelBufferConformer = makeUnique<PixelBufferConformerCV>((__bridge CFDictionaryRef)@{ (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA) });
Modified: trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h (293885 => 293886)
--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h 2022-05-06 09:52:39 UTC (rev 293886)
@@ -49,7 +49,7 @@
WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBuffer(IOSurfaceRef);
-RetainPtr<CGColorSpaceRef> createCGColorSpaceForCVPixelBuffer(CVPixelBufferRef);
+WEBCORE_EXPORT RetainPtr<CGColorSpaceRef> createCGColorSpaceForCVPixelBuffer(CVPixelBufferRef);
// Should be called with non-empty ProcessIdentity.
WEBCORE_EXPORT void setOwnershipIdentityForCVPixelBuffer(CVPixelBufferRef, const ProcessIdentity&);
Modified: trunk/Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.cpp (293885 => 293886)
--- trunk/Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.cpp 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.cpp 2022-05-06 09:52:39 UTC (rev 293886)
@@ -147,8 +147,6 @@
RetainPtr<CGImageRef> PixelBufferConformerCV::createImageFromPixelBuffer(CVPixelBufferRef rawBuffer)
{
RetainPtr<CVPixelBufferRef> buffer { rawBuffer };
- size_t width = CVPixelBufferGetWidth(buffer.get());
- size_t height = CVPixelBufferGetHeight(buffer.get());
if (!VTPixelBufferConformerIsConformantPixelBuffer(m_pixelConformer.get(), buffer.get())) {
CVPixelBufferRef outputBuffer = nullptr;
@@ -158,6 +156,15 @@
buffer = adoptCF(outputBuffer);
}
+ auto colorSpace = createCGColorSpaceForCVPixelBuffer(rawBuffer);
+ return imageFrom32BGRAPixelBuffer(WTFMove(buffer), colorSpace.get());
+}
+
+RetainPtr<CGImageRef> PixelBufferConformerCV::imageFrom32BGRAPixelBuffer(RetainPtr<CVPixelBufferRef>&& buffer, CGColorSpaceRef colorSpace)
+{
+ size_t width = CVPixelBufferGetWidth(buffer.get());
+ size_t height = CVPixelBufferGetHeight(buffer.get());
+
CGBitmapInfo bitmapInfo = static_cast<CGBitmapInfo>(kCGBitmapByteOrder32Little) | static_cast<CGBitmapInfo>(kCGImageAlphaFirst);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(buffer.get());
size_t byteLength = bytesPerRow * height;
@@ -166,8 +173,6 @@
if (!byteLength)
return nullptr;
- auto colorSpace = createCGColorSpaceForCVPixelBuffer(rawBuffer);
-
CVPixelBufferInfo* info = new CVPixelBufferInfo();
info->pixelBuffer = WTFMove(buffer);
info->lockCount = 0;
@@ -175,7 +180,7 @@
CGDataProviderDirectCallbacks providerCallbacks = { 0, CVPixelBufferGetBytePointerCallback, CVPixelBufferReleaseBytePointerCallback, 0, CVPixelBufferReleaseInfoCallback };
RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateDirect(info, byteLength, &providerCallbacks));
- return adoptCF(CGImageCreate(width, height, 8, 32, bytesPerRow, colorSpace.get(), bitmapInfo, provider.get(), nullptr, false, kCGRenderingIntentDefault));
+ return adoptCF(CGImageCreate(width, height, 8, 32, bytesPerRow, colorSpace, bitmapInfo, provider.get(), nullptr, false, kCGRenderingIntentDefault));
}
}
Modified: trunk/Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.h (293885 => 293886)
--- trunk/Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.h 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.h 2022-05-06 09:52:39 UTC (rev 293886)
@@ -27,8 +27,9 @@
#include <wtf/RetainPtr.h>
+typedef struct CGColorSpace *CGColorSpaceRef;
+typedef struct CGImage* CGImageRef;
typedef struct OpaqueVTPixelBufferConformer* VTPixelBufferConformerRef;
-typedef struct CGImage* CGImageRef;
typedef struct __CVBuffer *CVPixelBufferRef;
namespace WebCore {
@@ -39,6 +40,7 @@
WEBCORE_EXPORT PixelBufferConformerCV(CFDictionaryRef attributes);
WEBCORE_EXPORT RetainPtr<CVPixelBufferRef> convert(CVPixelBufferRef);
WEBCORE_EXPORT RetainPtr<CGImageRef> createImageFromPixelBuffer(CVPixelBufferRef);
+ static WEBCORE_EXPORT RetainPtr<CGImageRef> imageFrom32BGRAPixelBuffer(RetainPtr<CVPixelBufferRef>&&, CGColorSpaceRef);
private:
RetainPtr<VTPixelBufferConformerRef> m_pixelConformer;
Modified: trunk/Source/WebKit/ChangeLog (293885 => 293886)
--- trunk/Source/WebKit/ChangeLog 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/ChangeLog 2022-05-06 09:52:39 UTC (rev 293886)
@@ -1,3 +1,27 @@
+2022-05-06 Youenn Fablet <[email protected]>
+
+ Allow MediaPlayerPrivateMediaStreamAVFObjC to avoid pixel conformers if IOSurfaces are not allowed
+ https://bugs.webkit.org/show_bug.cgi?id=240113
+ rdar://92629845
+
+ Reviewed by Eric Carlson.
+
+ Implement VideoFrame conversion to BGRA by sending IPC to GPUProcess, use pixel conformer in GPUProcess and send back the results to WebProcess.
+ This goes through RemoteVideoFrameObjectHeapProxy/RemoteVideoFrameObjectHeapProxyProcessor which exchanges with RemoteVideoFrameObjectHeap.
+ Make use of this conversion code path for MediaPlayerPrivateMediaStreamAVFObjC by setting MediaPlayerPrivateMediaStreamAVFObjC nativeImageCreator callback.
+
+ * GPUProcess/media/RemoteVideoFrameObjectHeap.cpp:
+ * GPUProcess/media/RemoteVideoFrameObjectHeap.h:
+ * GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in:
+ * GPUProcess/media/RemoteVideoFrameObjectHeap.mm: Added.
+ * SourcesCocoa.txt:
+ * WebKit.xcodeproj/project.pbxproj:
+ * WebProcess/GPU/media/RemoteMediaPlayerManager.cpp:
+ * WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxy.h:
+ * WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp:
+ * WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h:
+ * WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.messages.in:
+
2022-05-05 Jean-Yves Avenard <[email protected]>
[EME] CDM and friends should be using SharedBuffer rather FragmentedSharedBuffer
Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp (293885 => 293886)
--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp 2022-05-06 09:52:39 UTC (rev 293886)
@@ -27,6 +27,7 @@
#include "RemoteVideoFrameObjectHeap.h"
#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
+#include "Logging.h"
#include "RemoteVideoFrameObjectHeapMessages.h"
#include "RemoteVideoFrameObjectHeapProxyProcessorMessages.h"
#include "RemoteVideoFrameProxy.h"
@@ -33,6 +34,7 @@
#include <wtf/WorkQueue.h>
#if PLATFORM(COCOA)
+#include <WebCore/PixelBufferConformerCV.h>
#include <WebCore/VideoFrameCV.h>
#include <pal/cf/CoreMediaSoftLink.h>
#endif
@@ -133,6 +135,41 @@
ASSERT(pixelBuffer);
completionHandler(WTFMove(pixelBuffer));
}
+
+void RemoteVideoFrameObjectHeap::convertBuffer(SharedVideoFrame::Buffer&& buffer)
+{
+ auto pixelBuffer = m_sharedVideoFrameReader.readBuffer(WTFMove(buffer));
+ if (!pixelBuffer) {
+ m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::NewConvertedVideoFrameBuffer { { } }, 0);
+ return;
+ }
+
+ createPixelConformerIfNeeded();
+ auto convertedBuffer = m_pixelBufferConformer->convert(pixelBuffer.get());
+ if (!convertedBuffer) {
+ RELEASE_LOG_ERROR(WebRTC, "RemoteVideoFrameObjectHeap::convertBuffer conformer failed");
+ m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::NewConvertedVideoFrameBuffer { { } }, 0);
+ return;
+ }
+
+ bool canSendIOSurface = false;
+ auto result = m_sharedVideoFrameWriter.writeBuffer(convertedBuffer.get(),
+ [&](auto& semaphore) { m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::SetSharedVideoFrameSemaphore { semaphore }, 0); },
+ [&](auto& handle) { m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::SetSharedVideoFrameMemory { handle }, 0); },
+ canSendIOSurface);
+ m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::NewConvertedVideoFrameBuffer { result }, 0);
+}
+
+void RemoteVideoFrameObjectHeap::setSharedVideoFrameSemaphore(IPC::Semaphore&& semaphore)
+{
+ m_sharedVideoFrameReader.setSemaphore(WTFMove(semaphore));
+}
+
+void RemoteVideoFrameObjectHeap::setSharedVideoFrameMemory(const SharedMemory::IPCHandle& ipcHandle)
+{
+ m_sharedVideoFrameReader.setSharedMemory(ipcHandle);
+}
+
#endif
}
Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h (293885 => 293886)
--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h 2022-05-06 09:52:39 UTC (rev 293886)
@@ -35,6 +35,10 @@
#include "SharedVideoFrame.h"
#endif
+namespace WebCore {
+class PixelBufferConformerCV;
+}
+
namespace WebKit {
// Holds references to all VideoFrame instances that are mapped from GPU process to Web process.
@@ -61,12 +65,19 @@
#if PLATFORM(COCOA)
void getVideoFrameBuffer(RemoteVideoFrameReadReference&&, bool canSendIOSurface);
void pixelBuffer(RemoteVideoFrameReadReference&&, CompletionHandler<void(RetainPtr<CVPixelBufferRef>)>&&);
+ void convertBuffer(SharedVideoFrame::Buffer&&);
+ void setSharedVideoFrameSemaphore(IPC::Semaphore&&);
+ void setSharedVideoFrameMemory(const SharedMemory::IPCHandle&);
#endif
+ void createPixelConformerIfNeeded();
+
const Ref<IPC::Connection> m_connection;
ThreadSafeObjectHeap<RemoteVideoFrameIdentifier, RefPtr<WebCore::VideoFrame>> m_heap;
#if PLATFORM(COCOA)
SharedVideoFrameWriter m_sharedVideoFrameWriter;
+ SharedVideoFrameReader m_sharedVideoFrameReader;
+ std::unique_ptr<WebCore::PixelBufferConformerCV> m_pixelBufferConformer;
#endif
bool m_isClosed { false };
};
Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in (293885 => 293886)
--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in 2022-05-06 09:52:39 UTC (rev 293886)
@@ -26,6 +26,9 @@
#if PLATFORM(COCOA)
GetVideoFrameBuffer(WebKit::RemoteVideoFrameReadReference read, bool canSendIOSurface)
PixelBuffer(WebKit::RemoteVideoFrameReadReference read) -> (RetainPtr<CVPixelBufferRef> result) Synchronous
+ SetSharedVideoFrameSemaphore(IPC::Semaphore semaphore)
+ SetSharedVideoFrameMemory(WebKit::SharedMemory::IPCHandle storageHandle)
+ ConvertBuffer(struct WebKit::SharedVideoFrame::Buffer buffer)
#endif
ReleaseVideoFrame(WebKit::RemoteVideoFrameWriteReference write)
}
Copied: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.mm (from rev 293885, trunk/Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.h) (0 => 293886)
--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.mm (rev 0)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.mm 2022-05-06 09:52:39 UTC (rev 293886)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteVideoFrameObjectHeap.h"
+
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO) && PLATFORM(COCOA)
+
+#include <WebCore/PixelBufferConformerCV.h>
+#include <WebCore/CoreVideoSoftLink.h>
+
+namespace WebKit {
+
+void RemoteVideoFrameObjectHeap::createPixelConformerIfNeeded()
+{
+ if (!m_pixelBufferConformer)
+ m_pixelBufferConformer = makeUnique<WebCore::PixelBufferConformerCV>((__bridge CFDictionaryRef)@{ (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA) });
+}
+
+}
+
+#endif
Modified: trunk/Source/WebKit/SourcesCocoa.txt (293885 => 293886)
--- trunk/Source/WebKit/SourcesCocoa.txt 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/SourcesCocoa.txt 2022-05-06 09:52:39 UTC (rev 293886)
@@ -73,6 +73,7 @@
GPUProcess/mac/LocalAudioSessionRoutingArbitrator.cpp
GPUProcess/media/RemoteAudioSourceProviderProxy.cpp
GPUProcess/media/RemoteImageDecoderAVFProxy.cpp
+GPUProcess/media/RemoteVideoFrameObjectHeap.mm
GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm
GPUProcess/media/ios/RemoteMediaSessionHelperProxy.cpp
GPUProcess/webrtc/LibWebRTCCodecsProxy.mm @no-unify
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (293885 => 293886)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2022-05-06 09:52:39 UTC (rev 293886)
@@ -4407,6 +4407,7 @@
4103FBA22061BDB800C2EAF8 /* NetworkLoadChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkLoadChecker.cpp; sourceTree = "<group>"; };
410482CB1DDD2FB500F006D0 /* RTCNetwork.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCNetwork.cpp; sourceTree = "<group>"; };
410482CC1DDD2FB500F006D0 /* RTCNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCNetwork.h; sourceTree = "<group>"; };
+ 410AD2E12823BD9F009C93C8 /* RemoteVideoFrameObjectHeap.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteVideoFrameObjectHeap.mm; sourceTree = "<group>"; };
410BA139257135F2002E2F8A /* NetworkRTCTCPSocketCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkRTCTCPSocketCocoa.mm; sourceTree = "<group>"; };
410BA13A257135F2002E2F8A /* NetworkRTCTCPSocketCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NetworkRTCTCPSocketCocoa.h; sourceTree = "<group>"; };
4111436320F677B10026F912 /* InjectUserScriptImmediately.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectUserScriptImmediately.h; sourceTree = "<group>"; };
@@ -7579,6 +7580,7 @@
7B5A3DA827A7DCBC006C6F97 /* RemoteVideoFrameObjectHeap.cpp */,
7B5A3DA727A7DCBC006C6F97 /* RemoteVideoFrameObjectHeap.h */,
413C542227C90F4C002FCDA8 /* RemoteVideoFrameObjectHeap.messages.in */,
+ 410AD2E12823BD9F009C93C8 /* RemoteVideoFrameObjectHeap.mm */,
071BC58423CC2C0900680D7C /* RemoteVideoTrackProxy.cpp */,
071BC58523CC2C0900680D7C /* RemoteVideoTrackProxy.h */,
07E19F0523D4DC880094FFB4 /* TextTrackPrivateRemoteConfiguration.h */,
Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteMediaPlayerManager.cpp (293885 => 293886)
--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteMediaPlayerManager.cpp 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteMediaPlayerManager.cpp 2022-05-06 09:52:39 UTC (rev 293886)
@@ -43,6 +43,10 @@
#include <wtf/HashMap.h>
#include <wtf/StdLibExtras.h>
+#if PLATFORM(COCOA)
+#include <WebCore/MediaPlayerPrivateMediaStreamAVFObjC.h>
+#endif
+
namespace WebKit {
using namespace PAL;
@@ -263,6 +267,9 @@
WebCore::SampleBufferDisplayLayer::setCreator([](auto& client) {
return WebProcess::singleton().ensureGPUProcessConnection().sampleBufferDisplayLayerManager().createLayer(client);
});
+ WebCore::MediaPlayerPrivateMediaStreamAVFObjC::setNativeImageCreator([](auto& videoFrame) {
+ return WebProcess::singleton().ensureGPUProcessConnection().videoFrameObjectHeapProxy().getNativeImage(videoFrame);
+ });
}
#endif
}
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxy.h (293885 => 293886)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxy.h 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxy.h 2022-05-06 09:52:39 UTC (rev 293886)
@@ -50,6 +50,7 @@
#if PLATFORM(COCOA)
void getVideoFrameBuffer(const RemoteVideoFrameProxy& proxy, bool canUseIOSurface, RemoteVideoFrameObjectHeapProxyProcessor::Callback&& callback) { m_processor->getVideoFrameBuffer(proxy, canUseIOSurface, WTFMove(callback)); }
+ RefPtr<WebCore::NativeImage> getNativeImage(const WebCore::VideoFrame& frame) { return m_processor->getNativeImage(frame); }
#endif
private:
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp (293885 => 293886)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp 2022-05-06 09:52:39 UTC (rev 293886)
@@ -32,6 +32,8 @@
#include "RemoteVideoFrameObjectHeapMessages.h"
#include "RemoteVideoFrameObjectHeapProxyProcessorMessages.h"
#include "RemoteVideoFrameProxy.h"
+#include "WebCoreArgumentCoders.h"
+#include <WebCore/PixelBufferConformerCV.h>
namespace WebKit {
@@ -119,6 +121,33 @@
IPC::Connection::send(m_connectionID, Messages::RemoteVideoFrameObjectHeap::GetVideoFrameBuffer(frame.newReadReference(), canUseIOSurface), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
}
+void RemoteVideoFrameObjectHeapProxyProcessor::newConvertedVideoFrameBuffer(std::optional<SharedVideoFrame::Buffer>&& buffer)
+{
+ ASSERT(!m_convertedBuffer);
+ if (buffer)
+ m_convertedBuffer = m_sharedVideoFrameReader.readBuffer(WTFMove(*buffer));
+ m_conversionSemaphore.signal();
}
+RefPtr<NativeImage> RemoteVideoFrameObjectHeapProxyProcessor::getNativeImage(const WebCore::VideoFrame& videoFrame)
+{
+ auto& connection = WebProcess::singleton().ensureGPUProcessConnection().connection();
+
+ auto nativePixelBuffer = videoFrame.pixelBuffer();
+ auto colorSpace = createCGColorSpaceForCVPixelBuffer(nativePixelBuffer);
+ auto buffer = m_sharedVideoFrameWriter.writeBuffer(nativePixelBuffer,
+ [&](auto& semaphore) { connection.send(Messages::RemoteVideoFrameObjectHeap::SetSharedVideoFrameSemaphore { semaphore }, 0); },
+ [&](auto& handle) { connection.send(Messages::RemoteVideoFrameObjectHeap::SetSharedVideoFrameMemory { handle }, 0); });
+ if (!buffer)
+ return nullptr;
+
+ connection.send(Messages::RemoteVideoFrameObjectHeap::ConvertBuffer { WTFMove(*buffer) }, 0);
+ m_conversionSemaphore.wait();
+
+ auto pixelBuffer = WTFMove(m_convertedBuffer);
+ return pixelBuffer ? NativeImage::create(PixelBufferConformerCV::imageFrom32BGRAPixelBuffer(WTFMove(pixelBuffer), colorSpace.get())) : nullptr;
+}
+
+}
+
#endif
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h (293885 => 293886)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h 2022-05-06 09:52:39 UTC (rev 293886)
@@ -37,6 +37,7 @@
#include <wtf/HashMap.h>
#include <wtf/Lock.h>
#include <wtf/WorkQueue.h>
+#include <wtf/threads/BinarySemaphore.h>
using CVPixelBufferPoolRef = struct __CVPixelBufferPool*;
@@ -45,6 +46,11 @@
class Decoder;
}
+namespace WebCore {
+class NativeImage;
+class VideoFrame;
+}
+
namespace WebKit {
class RemoteVideoFrameProxy;
@@ -56,6 +62,7 @@
using Callback = Function<void(RetainPtr<CVPixelBufferRef>&&)>;
void getVideoFrameBuffer(const RemoteVideoFrameProxy&, bool canUseIOSurfce, Callback&&);
+ RefPtr<WebCore::NativeImage> getNativeImage(const WebCore::VideoFrame&);
private:
explicit RemoteVideoFrameObjectHeapProxyProcessor(GPUProcessConnection&);
@@ -66,6 +73,7 @@
void setSharedVideoFrameSemaphore(IPC::Semaphore&&);
void setSharedVideoFrameMemory(const SharedMemory::IPCHandle&);
void newVideoFrameBuffer(RemoteVideoFrameIdentifier, std::optional<SharedVideoFrame::Buffer>&&);
+ void newConvertedVideoFrameBuffer(std::optional<SharedVideoFrame::Buffer>&&);
// GPUProcessConnection::Client
void gpuProcessConnectionDidClose(GPUProcessConnection&);
@@ -80,6 +88,10 @@
HashMap<RemoteVideoFrameIdentifier, Callback> m_callbacks WTF_GUARDED_BY_LOCK(m_callbacksLock);
Ref<WorkQueue> m_queue;
SharedVideoFrameReader m_sharedVideoFrameReader;
+
+ SharedVideoFrameWriter m_sharedVideoFrameWriter;
+ RetainPtr<CVPixelBufferRef> m_convertedBuffer;
+ BinarySemaphore m_conversionSemaphore;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.messages.in (293885 => 293886)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.messages.in 2022-05-06 08:44:54 UTC (rev 293885)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.messages.in 2022-05-06 09:52:39 UTC (rev 293886)
@@ -26,6 +26,7 @@
SetSharedVideoFrameSemaphore(IPC::Semaphore semaphore)
SetSharedVideoFrameMemory(WebKit::SharedMemory::IPCHandle storageHandle)
NewVideoFrameBuffer(WebKit::RemoteVideoFrameIdentifier identifier, std::optional<WebKit::SharedVideoFrame::Buffer> frame)
+ NewConvertedVideoFrameBuffer(std::optional<WebKit::SharedVideoFrame::Buffer> frame)
}
#endif