Diff
Modified: trunk/Source/WebCore/ChangeLog (289364 => 289365)
--- trunk/Source/WebCore/ChangeLog 2022-02-08 11:59:07 UTC (rev 289364)
+++ trunk/Source/WebCore/ChangeLog 2022-02-08 12:26:39 UTC (rev 289365)
@@ -1,3 +1,26 @@
+2022-02-08 Youenn Fablet <[email protected]>
+
+ RealtimeOutgoingVideoSourceCocoa rotation session should not use IOSurface
+ https://bugs.webkit.org/show_bug.cgi?id=236139
+
+ Reviewed by Eric Carlson.
+
+ Introduce a parameter to use IOSurface or not in ImageRotationSessionVT.
+ Make use of that parameter in RealtimeOutgoingVideoSourceCocoa to disable IOSurface use.
+
+ Covered by existing tests.
+
+ * platform/graphics/cv/CVUtilities.h:
+ * platform/graphics/cv/CVUtilities.mm:
+ (WebCore::createIOSurfaceCVPixelBufferPool):
+ (WebCore::createInMemoryCVPixelBufferPool):
+ * platform/graphics/cv/ImageRotationSessionVT.h:
+ * platform/graphics/cv/ImageRotationSessionVT.mm:
+ (WebCore::ImageRotationSessionVT::ImageRotationSessionVT):
+ (WebCore::ImageRotationSessionVT::rotate):
+ * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm:
+ (WebCore::RealtimeOutgoingVideoSourceCocoa::rotatePixelBuffer):
+
2022-02-08 Kimmo Kinnunen <[email protected]>
Adding new files fails to compile after SharedWorkerObjectConnection.h changes
Modified: trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h (289364 => 289365)
--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h 2022-02-08 11:59:07 UTC (rev 289364)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h 2022-02-08 12:26:39 UTC (rev 289365)
@@ -39,10 +39,12 @@
// Creates CVPixelBufferPool that creates CVPixelBuffers backed by IOSurfaces.
// 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> createIOSurfaceCVPixelBufferPool(size_t width, size_t height, OSType pixelFormat, unsigned minimumBufferCount = 0u, bool isCGImageCompatible = false);
-WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createInMemoryCVPixelBufferPool(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, bool isCGImageCompatible = false);
+WEBCORE_EXPORT Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createCVPixelBufferPool(size_t width, size_t height, OSType pixelFormat, unsigned minimumBufferCount = 0u, bool isCGImageCompatible = false, bool shouldUseIOSUrface = true);
+
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 (289364 => 289365)
--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm 2022-02-08 11:59:07 UTC (rev 289364)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm 2022-02-08 12:26:39 UTC (rev 289365)
@@ -49,13 +49,13 @@
return adoptCF(pool);
}
-Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createIOSurfaceCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount)
+Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createIOSurfaceCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount, bool isCGImageCompatible)
{
return createBufferPool(minimumBufferCount, @{
(__bridge NSString *)kCVPixelBufferWidthKey : @(width),
(__bridge NSString *)kCVPixelBufferHeightKey : @(height),
(__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(format),
- (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey : @NO,
+ (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey : isCGImageCompatible ? @YES : @NO,
#if PLATFORM(MAC)
(__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
#endif
@@ -63,13 +63,13 @@
});
}
-Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createInMemoryCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount)
+Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createInMemoryCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount, bool isCGImageCompatible)
{
return createBufferPool(minimumBufferCount, @{
(__bridge NSString *)kCVPixelBufferWidthKey : @(width),
(__bridge NSString *)kCVPixelBufferHeightKey : @(height),
(__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(format),
- (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey : @NO,
+ (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey : isCGImageCompatible ? @YES : @NO,
#if PLATFORM(MAC)
(__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
#endif
@@ -76,6 +76,11 @@
});
}
+Expected<RetainPtr<CVPixelBufferPoolRef>, CVReturn> createCVPixelBufferPool(size_t width, size_t height, OSType format, unsigned minimumBufferCount, bool isCGImageCompatible, bool shouldUseIOSurfacePool)
+{
+ return shouldUseIOSurfacePool ? createIOSurfaceCVPixelBufferPool(width, height, format, minimumBufferCount, isCGImageCompatible) : createInMemoryCVPixelBufferPool(width, height, format, minimumBufferCount, isCGImageCompatible);
+}
+
Expected<RetainPtr<CVPixelBufferRef>, CVReturn> createCVPixelBufferFromPool(CVPixelBufferPoolRef pixelBufferPool)
{
CVPixelBufferRef pixelBuffer = nullptr;
Modified: trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.h (289364 => 289365)
--- trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.h 2022-02-08 11:59:07 UTC (rev 289364)
+++ trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.h 2022-02-08 12:26:39 UTC (rev 289365)
@@ -47,13 +47,11 @@
bool isIdentity() const { return !flipX && !flipY && !angle; }
};
- enum class IsCGImageCompatible {
- No,
- Yes,
- };
+ enum class IsCGImageCompatible { No, Yes };
+ enum class ShouldUseIOSurface { No, Yes };
- ImageRotationSessionVT(AffineTransform&&, FloatSize, IsCGImageCompatible);
- ImageRotationSessionVT(const RotationProperties&, FloatSize, IsCGImageCompatible);
+ ImageRotationSessionVT(AffineTransform&&, FloatSize, IsCGImageCompatible, ShouldUseIOSurface = ShouldUseIOSurface::Yes);
+ ImageRotationSessionVT(const RotationProperties&, FloatSize, IsCGImageCompatible, ShouldUseIOSurface = ShouldUseIOSurface::Yes);
ImageRotationSessionVT() = default;
const std::optional<AffineTransform>& transform() const { return m_transform; }
@@ -75,6 +73,7 @@
FloatSize m_rotatedSize;
RetainPtr<VTImageRotationSessionRef> m_rotationSession;
RetainPtr<CVPixelBufferPoolRef> m_rotationPool;
+ bool m_shouldUseIOSurface { true };
};
inline bool operator==(const ImageRotationSessionVT::RotationProperties& rotation1, const ImageRotationSessionVT::RotationProperties& rotation2)
Modified: trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm (289364 => 289365)
--- trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm 2022-02-08 11:59:07 UTC (rev 289364)
+++ trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm 2022-02-08 12:26:39 UTC (rev 289365)
@@ -27,6 +27,7 @@
#import "ImageRotationSessionVT.h"
#import "AffineTransform.h"
+#import "CVUtilities.h"
#import "Logging.h"
#import "MediaSample.h"
@@ -59,13 +60,14 @@
return rotation;
}
-ImageRotationSessionVT::ImageRotationSessionVT(AffineTransform&& transform, FloatSize size, IsCGImageCompatible isCGImageCompatible)
- : ImageRotationSessionVT(transformToRotationProperties(transform), size, isCGImageCompatible)
+ImageRotationSessionVT::ImageRotationSessionVT(AffineTransform&& transform, FloatSize size, IsCGImageCompatible isCGImageCompatible, ShouldUseIOSurface shouldUseIOSurface)
+ : ImageRotationSessionVT(transformToRotationProperties(transform), size, isCGImageCompatible, shouldUseIOSurface)
{
m_transform = WTFMove(transform);
}
-ImageRotationSessionVT::ImageRotationSessionVT(const RotationProperties& rotation, FloatSize size, IsCGImageCompatible isCGImageCompatible)
+ImageRotationSessionVT::ImageRotationSessionVT(const RotationProperties& rotation, FloatSize size, IsCGImageCompatible isCGImageCompatible, ShouldUseIOSurface shouldUseIOSurface)
+ : m_shouldUseIOSurface(shouldUseIOSurface == ShouldUseIOSurface::Yes)
{
initialize(rotation, size, isCGImageCompatible);
}
@@ -97,21 +99,14 @@
auto pixelFormat = CVPixelBufferGetPixelFormatType(pixelBuffer);
if (pixelFormat != m_pixelFormat || !m_rotationPool) {
m_pixelFormat = pixelFormat;
- auto pixelAttributes = @{
- (__bridge NSString *)kCVPixelBufferWidthKey: @(m_rotatedSize.width()),
- (__bridge NSString *)kCVPixelBufferHeightKey: @(m_rotatedSize.height()),
- (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(m_pixelFormat),
- (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: (m_isCGImageCompatible == IsCGImageCompatible::Yes ? @YES : @NO),
- (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
- };
+ auto bufferPool = createCVPixelBufferPool(m_rotatedSize.width(), m_rotatedSize.height(), m_pixelFormat, 0u, m_isCGImageCompatible == IsCGImageCompatible::Yes, m_shouldUseIOSurface);
- CVPixelBufferPoolRef rawPool = nullptr;
- if (auto err = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &rawPool); err != noErr) {
- RELEASE_LOG_ERROR(WebRTC, "ImageRotationSessionVT failed creating buffer pool with error %d", err);
+ if (!bufferPool) {
+ RELEASE_LOG_ERROR(WebRTC, "ImageRotationSessionVT failed creating buffer pool with error %d", (int)bufferPool.error());
return nullptr;
}
- m_rotationPool = adoptCF(rawPool);
+ m_rotationPool = WTFMove(*bufferPool);
}
RetainPtr<CVPixelBufferRef> result;
Modified: trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm (289364 => 289365)
--- trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm 2022-02-08 11:59:07 UTC (rev 289364)
+++ trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm 2022-02-08 12:26:39 UTC (rev 289365)
@@ -77,7 +77,7 @@
{
if (m_size == size && m_outputBufferPool)
return true;
- 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);
+ auto bufferPool = createCVPixelBufferPool(size.width(), size.height(), m_pixelFormat, 6, false, m_shouldUseIOSurface).value_or(nullptr);
if (!bufferPool)
return false;
m_outputBufferPool = WTFMove(bufferPool);
Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm (289364 => 289365)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm 2022-02-08 11:59:07 UTC (rev 289364)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm 2022-02-08 12:26:39 UTC (rev 289365)
@@ -77,7 +77,7 @@
RELEASE_LOG_INFO(WebRTC, "RealtimeOutgoingVideoSourceCocoa::rotatePixelBuffer creating rotation session for rotation %u", rotationToAngle(rotation));
AffineTransform transform;
transform.rotate(rotationToAngle(rotation));
- m_rotationSession = makeUnique<ImageRotationSessionVT>(WTFMove(transform), FloatSize { static_cast<float>(pixelWidth), static_cast<float>(pixelHeight) }, ImageRotationSessionVT::IsCGImageCompatible::No);
+ m_rotationSession = makeUnique<ImageRotationSessionVT>(WTFMove(transform), FloatSize { static_cast<float>(pixelWidth), static_cast<float>(pixelHeight) }, ImageRotationSessionVT::IsCGImageCompatible::No, ImageRotationSessionVT::ShouldUseIOSurface::No);
m_currentRotationSessionAngle = rotation;
m_rotatedWidth = pixelWidth;