Diff
Modified: trunk/Source/WebCore/ChangeLog (237235 => 237236)
--- trunk/Source/WebCore/ChangeLog 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/ChangeLog 2018-10-17 21:55:36 UTC (rev 237236)
@@ -1,5 +1,82 @@
2018-10-17 Eric Carlson <eric.carl...@apple.com>
+ [MediaStream] Consolidate all image conversion and resizing into one class
+ https://bugs.webkit.org/show_bug.cgi?id=190519
+ <rdar://problem/45224307>
+
+ Reviewed by Youenn Fablet.
+
+ No new tests, no functional change.
+
+ * SourcesCocoa.txt: Add ImageTransferSessionVT.
+ * WebCore.xcodeproj/project.pbxproj: Ditto.
+
+ * platform/MediaSample.h:
+ (WebCore::MediaSample::videoPixelFormat const): New.
+
+ * platform/cocoa/VideoToolboxSoftLink.cpp: Add new kVTPixelTransferProperty keys.
+ * platform/cocoa/VideoToolboxSoftLink.h:
+
+ * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h:
+ (WebCore::MediaSampleAVFObjC::create): Remove unimplemented variant.
+ * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
+ (WebCore::MediaSampleAVFObjC::videoPixelFormat const): New.
+
+ * platform/graphics/cv/ImageTransferSessionVT.h: Added.
+ (WebCore::ImageTransferSessionVT::create):
+ * platform/graphics/cv/ImageTransferSessionVT.mm: Added.
+ (WebCore::ImageTransferSessionVT::ImageTransferSessionVT):
+ (WebCore::ImageTransferSessionVT::~ImageTransferSessionVT):
+ (WebCore::ImageTransferSessionVT::setSize):
+ (WebCore::ImageTransferSessionVT::createPixelBuffer):
+ (WebCore::ImageTransferSessionVT::createCMSampleBuffer):
+ (WebCore::roundUpToMacroblockMultiple):
+ (WebCore::ImageTransferSessionVT::ioSurfacePixelBufferCreationOptions):
+ (WebCore::ImageTransferSessionVT::createMediaSample):
+
+ * platform/graphics/cv/PixelBufferResizer.h: Removed.
+ * platform/graphics/cv/PixelBufferResizer.mm: Removed.
+
+ * platform/mediastream/mac/AVVideoCaptureSource.h:
+ * platform/mediastream/mac/AVVideoCaptureSource.mm:
+ (WebCore::AVVideoCaptureSource::prefersPreset):
+ (WebCore::AVVideoCaptureSource::captureOutputDidOutputSampleBufferFromConnection): Remove
+ the resizing logic, it is handled by the base class.
+
+ * platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp:
+ (WebCore::DisplayCaptureSourceCocoa::capabilities):
+ (WebCore::DisplayCaptureSourceCocoa::settingsDidChange):
+ (WebCore::DisplayCaptureSourceCocoa::setIntrinsicSize):
+ (WebCore::DisplayCaptureSourceCocoa::emitFrame): Remove resizing logic, just use a transfer
+ session to create an image from the capture source native output format.
+ (WebCore::DisplayCaptureSourceCocoa::sampleBufferFromPixelBuffer): Deleted.
+ (WebCore::roundUpToMacroblockMultiple): Deleted.
+ (WebCore::DisplayCaptureSourceCocoa::pixelBufferFromIOSurface): Deleted.
+ * platform/mediastream/mac/DisplayCaptureSourceCocoa.h:
+
+ * platform/mediastream/mac/MockRealtimeVideoSourceMac.h:
+ * platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
+ (WebCore::MockRealtimeVideoSourceMac::updateSampleBuffer): Use image transfer session.
+ (WebCore::MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer): Deleted.
+ (WebCore::MockRealtimeVideoSourceMac::pixelBufferFromCGImage const): Deleted.
+ (WebCore::MockRealtimeVideoSourceMac::setSizeAndFrameRateWithPreset): Deleted.
+
+ * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h:
+ * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:
+ (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream):
+ (WebCore::ScreenDisplayCaptureSourceMac::generateFrame): Return the IOSurface directly.
+
+ * platform/mediastream/mac/WindowDisplayCaptureSourceMac.h:
+ * platform/mediastream/mac/WindowDisplayCaptureSourceMac.mm:
+ (WebCore::WindowDisplayCaptureSourceMac::generateFrame): Return the CGImage directly.
+ (WebCore::WindowDisplayCaptureSourceMac::pixelBufferFromCGImage): Deleted.
+
+ * platform/mock/MockRealtimeVideoSource.cpp:
+ (WebCore::MockRealtimeVideoSource::capabilities): Only the camera supports device ID.
+ (WebCore::MockRealtimeVideoSource::settings): Ditto.
+
+2018-10-17 Eric Carlson <eric.carl...@apple.com>
+
[MediaStream] Clean up capture source factory management
https://bugs.webkit.org/show_bug.cgi?id=190502
<rdar://problem/45212447>
Modified: trunk/Source/WebCore/SourcesCocoa.txt (237235 => 237236)
--- trunk/Source/WebCore/SourcesCocoa.txt 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2018-10-17 21:55:36 UTC (rev 237236)
@@ -314,8 +314,8 @@
platform/graphics/cocoa/WebMetalLayer.mm
platform/graphics/cocoa/TextTrackRepresentationCocoa.mm
+platform/graphics/cv/ImageTransferSessionVT.mm
platform/graphics/cv/PixelBufferConformerCV.cpp
-platform/graphics/cv/PixelBufferResizer.mm
platform/graphics/cv/TextureCacheCV.mm
platform/graphics/cv/VideoTextureCopierCV.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (237235 => 237236)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-10-17 21:55:36 UTC (rev 237236)
@@ -169,6 +169,7 @@
078E43DA1ABB6C7E001C2FA6 /* MediaPlaybackTargetPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = 078E43D81ABB6C7E001C2FA6 /* MediaPlaybackTargetPicker.h */; settings = {ATTRIBUTES = (Private, ); }; };
078E43DD1ABB6F6F001C2FA6 /* MediaPlaybackTargetPickerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 078E43DB1ABB6F6F001C2FA6 /* MediaPlaybackTargetPickerMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
078E43DE1ABB6F6F001C2FA6 /* MediaPlaybackTargetPickerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 078E43DC1ABB6F6F001C2FA6 /* MediaPlaybackTargetPickerMac.mm */; };
+ 078ED193216D079500775B33 /* ImageTransferSessionVT.h in Headers */ = {isa = PBXBuildFile; fileRef = 0746D30C2146EA38003DDF84 /* ImageTransferSessionVT.h */; settings = {ATTRIBUTES = (Private, ); }; };
079216551AA560AA00A3C049 /* MediaPlaybackTargetClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 079216531AA560AA00A3C049 /* MediaPlaybackTargetClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
07941791166E855F009416C2 /* InbandTextTrack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0794178F166E855F009416C2 /* InbandTextTrack.cpp */; };
07941792166E855F009416C2 /* InbandTextTrack.h in Headers */ = {isa = PBXBuildFile; fileRef = 07941790166E855F009416C2 /* InbandTextTrack.h */; };
@@ -5368,8 +5369,8 @@
073B87651E43859D0071C0EC /* AudioSampleDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSampleDataSource.h; sourceTree = "<group>"; };
0744ECEB1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockRealtimeAudioSourceMac.h; sourceTree = "<group>"; };
0744ECEC1E0C4AE5000D0944 /* MockRealtimeAudioSourceMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MockRealtimeAudioSourceMac.mm; sourceTree = "<group>"; };
- 0746D30A2146EA37003DDF84 /* PixelBufferResizer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PixelBufferResizer.mm; sourceTree = "<group>"; };
- 0746D30C2146EA38003DDF84 /* PixelBufferResizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PixelBufferResizer.h; sourceTree = "<group>"; };
+ 0746D30A2146EA37003DDF84 /* ImageTransferSessionVT.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ImageTransferSessionVT.mm; sourceTree = "<group>"; };
+ 0746D30C2146EA38003DDF84 /* ImageTransferSessionVT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageTransferSessionVT.h; sourceTree = "<group>"; };
074E82B818A69F0E007EF54C /* PlatformTimeRanges.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformTimeRanges.cpp; sourceTree = "<group>"; };
074E82B918A69F0E007EF54C /* PlatformTimeRanges.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformTimeRanges.h; sourceTree = "<group>"; };
0753860014489E9800B78452 /* CachedTextTrack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedTextTrack.cpp; sourceTree = "<group>"; };
@@ -25095,10 +25096,10 @@
CD9D827C1C7BB2ED006FF066 /* cv */ = {
isa = PBXGroup;
children = (
+ 0746D30C2146EA38003DDF84 /* ImageTransferSessionVT.h */,
+ 0746D30A2146EA37003DDF84 /* ImageTransferSessionVT.mm */,
CD7D33411C7A123F00041293 /* PixelBufferConformerCV.cpp */,
CD7D33421C7A123F00041293 /* PixelBufferConformerCV.h */,
- 0746D30C2146EA38003DDF84 /* PixelBufferResizer.h */,
- 0746D30A2146EA37003DDF84 /* PixelBufferResizer.mm */,
CD9D82741C7AE535006FF066 /* TextureCacheCV.h */,
CD9D82731C7AE535006FF066 /* TextureCacheCV.mm */,
CD9D82771C7B8EE1006FF066 /* VideoTextureCopierCV.cpp */,
@@ -28720,6 +28721,7 @@
7C193BC11F5E0EED0088F3E6 /* ImageSmoothingQuality.h in Headers */,
5546757B1FD212A9003B10B0 /* ImageSource.h in Headers */,
4B3480940EEF50D400AC1B41 /* ImageSourceCG.h in Headers */,
+ 078ED193216D079500775B33 /* ImageTransferSessionVT.h in Headers */,
5550CB421E955E3C00111AA0 /* ImageTypes.h in Headers */,
26F756B31B3B66F70005DD79 /* ImmutableNFA.h in Headers */,
26F756B51B3B68F20005DD79 /* ImmutableNFANodeBuilder.h in Headers */,
Modified: trunk/Source/WebCore/platform/MediaSample.h (237235 => 237236)
--- trunk/Source/WebCore/platform/MediaSample.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/MediaSample.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -28,6 +28,7 @@
#include "FloatSize.h"
#include <_javascript_Core/TypedArrays.h>
+#include <wtf/EnumTraits.h>
#include <wtf/MediaTime.h>
#include <wtf/RefCounted.h>
#include <wtf/text/AtomicString.h>
@@ -100,6 +101,20 @@
virtual void dump(PrintStream&) const = 0;
};
-}
+} // namespace WebCore
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::MediaSample::VideoRotation> {
+ using values = EnumValues<
+ WebCore::MediaSample::VideoRotation,
+ WebCore::MediaSample::VideoRotation::None,
+ WebCore::MediaSample::VideoRotation::UpsideDown,
+ WebCore::MediaSample::VideoRotation::Right,
+ WebCore::MediaSample::VideoRotation::Left
+ >;
+};
+
+} // namespace WTF
+
#endif
Modified: trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.cpp (237235 => 237236)
--- trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.cpp 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.cpp 2018-10-17 21:55:36 UTC (rev 237236)
@@ -92,4 +92,6 @@
SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, CoreVideo, kCVPixelBufferOpenGLCompatibilityKey, CFStringRef)
#endif
+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreVideo, CVPixelBufferCreateWithIOSurface, CVReturn, (CFAllocatorRef allocator, IOSurfaceRef surface, CFDictionaryRef pixelBufferAttributes, CVPixelBufferRef * pixelBufferOut), (allocator, surface, pixelBufferAttributes, pixelBufferOut))
+
#endif // HAVE(CORE_VIDEO)
Modified: trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.h (237235 => 237236)
--- trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/cocoa/CoreVideoSoftLink.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -147,4 +147,7 @@
#define kCVPixelBufferOpenGLCompatibilityKey get_CoreVideo_kCVPixelBufferOpenGLCompatibilityKey()
#endif
+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreVideo, CVPixelBufferCreateWithIOSurface, CVReturn, (CFAllocatorRef allocator, IOSurfaceRef surface, CFDictionaryRef pixelBufferAttributes, CVPixelBufferRef * pixelBufferOut), (allocator, surface, pixelBufferAttributes, pixelBufferOut))
+#define CVPixelBufferCreateWithIOSurface softLink_CoreVideo_CVPixelBufferCreateWithIOSurface
+
#endif // HAVE(CORE_VIDEO)
Modified: trunk/Source/WebCore/platform/cocoa/VideoToolboxSoftLink.cpp (237235 => 237236)
--- trunk/Source/WebCore/platform/cocoa/VideoToolboxSoftLink.cpp 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/cocoa/VideoToolboxSoftLink.cpp 2018-10-17 21:55:36 UTC (rev 237236)
@@ -59,6 +59,9 @@
SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, VideoToolbox, VTSessionSetProperty, OSStatus, (VTSessionRef session, CFStringRef propertyKey, CFTypeRef propertyValue), (session, propertyKey, propertyValue))
SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, VideoToolbox, kVTPixelTransferPropertyKey_ScalingMode, CFStringRef)
SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, VideoToolbox, kVTScalingMode_Trim, CFStringRef)
+SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, VideoToolbox, kVTPixelTransferPropertyKey_EnableHardwareAcceleratedTransfer, CFStringRef)
+SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, VideoToolbox, kVTPixelTransferPropertyKey_EnableHighSpeedTransfer, CFStringRef)
+SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, VideoToolbox, kVTPixelTransferPropertyKey_RealTime, CFStringRef)
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE(WebCore, VideoToolbox, kVTHEVCDecoderCapability_SupportedProfiles, CFStringRef)
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE(WebCore, VideoToolbox, kVTHEVCDecoderCapability_PerProfileSupport, CFStringRef)
Modified: trunk/Source/WebCore/platform/cocoa/VideoToolboxSoftLink.h (237235 => 237236)
--- trunk/Source/WebCore/platform/cocoa/VideoToolboxSoftLink.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/cocoa/VideoToolboxSoftLink.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -85,6 +85,12 @@
#define kVTPixelTransferPropertyKey_ScalingMode get_VideoToolbox_kVTPixelTransferPropertyKey_ScalingMode()
SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, VideoToolbox, kVTScalingMode_Trim, CFStringRef)
#define kVTScalingMode_Trim get_VideoToolbox_kVTScalingMode_Trim()
+SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, VideoToolbox, kVTPixelTransferPropertyKey_EnableHardwareAcceleratedTransfer, CFStringRef)
+#define kVTPixelTransferPropertyKey_EnableHardwareAcceleratedTransfer get_VideoToolbox_kVTPixelTransferPropertyKey_EnableHardwareAcceleratedTransfer()
+SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, VideoToolbox, kVTPixelTransferPropertyKey_EnableHighSpeedTransfer, CFStringRef)
+#define kVTPixelTransferPropertyKey_EnableHighSpeedTransfer get_VideoToolbox_kVTPixelTransferPropertyKey_EnableHighSpeedTransfer()
+SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, VideoToolbox, kVTPixelTransferPropertyKey_RealTime, CFStringRef)
+#define kVTPixelTransferPropertyKey_RealTime get_VideoToolbox_kVTPixelTransferPropertyKey_RealTime()
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(WebCore, VideoToolbox, kVTHEVCDecoderCapability_SupportedProfiles, CFStringRef)
#define kVTHEVCDecoderCapability_SupportedProfiles get_VideoToolbox_kVTHEVCDecoderCapability_SupportedProfiles()
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h (237235 => 237236)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -31,13 +31,12 @@
#include <wtf/Forward.h>
namespace WebCore {
-
+
class MediaSampleAVFObjC : public MediaSample {
public:
static Ref<MediaSampleAVFObjC> create(CMSampleBufferRef sample, int trackID) { return adoptRef(*new MediaSampleAVFObjC(sample, trackID)); }
static Ref<MediaSampleAVFObjC> create(CMSampleBufferRef sample, AtomicString trackID) { return adoptRef(*new MediaSampleAVFObjC(sample, trackID)); }
static Ref<MediaSampleAVFObjC> create(CMSampleBufferRef sample, VideoRotation rotation = VideoRotation::None, bool mirrored = false) { return adoptRef(*new MediaSampleAVFObjC(sample, rotation, mirrored)); }
- static RefPtr<MediaSampleAVFObjC> createImageSample(Ref<JSC::Uint8ClampedArray>&&, unsigned long width, unsigned long height);
static RefPtr<MediaSampleAVFObjC> createImageSample(Vector<uint8_t>&&, unsigned long width, unsigned long height);
RefPtr<JSC::Uint8ClampedArray> getRGBAImageData() const override;
@@ -65,6 +64,7 @@
VideoRotation videoRotation() const override { return m_rotation; }
bool videoMirrored() const override { return m_mirrored; }
+ uint32_t videoPixelFormat() const;
CMSampleBufferRef sampleBuffer() const { return m_sample.get(); }
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm (237235 => 237236)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm 2018-10-17 21:55:36 UTC (rev 237236)
@@ -113,6 +113,12 @@
return sample;
}
+uint32_t MediaSampleAVFObjC::videoPixelFormat() const
+{
+ auto pixelBuffer = static_cast<CVPixelBufferRef>(CMSampleBufferGetImageBuffer(m_sample.get()));
+ return CVPixelBufferGetPixelFormatType(pixelBuffer);
+}
+
static bool CMSampleBufferIsRandomAccess(CMSampleBufferRef sample)
{
CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sample, false);
Added: trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h (0 => 237236)
--- trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#pragma once
+
+#if USE(VIDEOTOOLBOX)
+
+#include "IntSize.h"
+#include "MediaSample.h"
+#include <wtf/RetainPtr.h>
+
+typedef struct CGImage *CGImageRef;
+typedef struct OpaqueVTPixelTransferSession* VTPixelTransferSessionRef;
+typedef struct __CVBuffer *CVPixelBufferRef;
+typedef struct __CVPixelBufferPool *CVPixelBufferPoolRef;
+typedef struct __IOSurface *IOSurfaceRef;
+typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
+
+namespace WebCore {
+
+class ImageTransferSessionVT {
+public:
+ static std::unique_ptr<ImageTransferSessionVT> create(uint32_t pixelFormat)
+ {
+ return std::unique_ptr<ImageTransferSessionVT>(new ImageTransferSessionVT(pixelFormat));
+ }
+
+ RefPtr<MediaSample> convertMediaSample(MediaSample&, const IntSize&);
+ RefPtr<MediaSample> createMediaSample(CGImageRef, const MediaTime&, const IntSize&, MediaSample::VideoRotation = MediaSample::VideoRotation::None, bool mirrored = false);
+ RefPtr<MediaSample> createMediaSample(CMSampleBufferRef, const IntSize&, MediaSample::VideoRotation = MediaSample::VideoRotation::None, bool mirrored = false);
+
+#if HAVE(IOSURFACE)
+ RefPtr<MediaSample> createMediaSample(IOSurfaceRef, const MediaTime&, const IntSize&, MediaSample::VideoRotation = MediaSample::VideoRotation::None, bool mirrored = false);
+#endif
+
+private:
+ WEBCORE_EXPORT explicit ImageTransferSessionVT(uint32_t pixelFormat);
+
+#if HAVE(IOSURFACE)
+ CFDictionaryRef ioSurfacePixelBufferCreationOptions(IOSurfaceRef);
+ RetainPtr<CMSampleBufferRef> createCMSampleBuffer(IOSurfaceRef, const MediaTime&, const IntSize&);
+ RetainPtr<CVPixelBufferRef> createPixelBuffer(IOSurfaceRef, const IntSize&);
+#endif
+
+ RetainPtr<CMSampleBufferRef> convertCMSampleBuffer(CMSampleBufferRef, const IntSize&);
+ RetainPtr<CMSampleBufferRef> createCMSampleBuffer(CVPixelBufferRef, const MediaTime&, const IntSize&);
+ RetainPtr<CMSampleBufferRef> createCMSampleBuffer(CGImageRef, const MediaTime&, const IntSize&);
+
+ RetainPtr<CVPixelBufferRef> convertPixelBuffer(CVPixelBufferRef, const IntSize&);
+ RetainPtr<CVPixelBufferRef> createPixelBuffer(CMSampleBufferRef, const IntSize&);
+ RetainPtr<CVPixelBufferRef> createPixelBuffer(CGImageRef, const IntSize&);
+
+ bool setSize(const IntSize&);
+
+ RetainPtr<VTPixelTransferSessionRef> m_transferSession;
+ RetainPtr<CVPixelBufferPoolRef> m_outputBufferPool;
+ RetainPtr<CFDictionaryRef> m_ioSurfaceBufferAttributes;
+ uint32_t m_pixelFormat;
+ IntSize m_size;
+};
+
+}
+
+#endif // USE(VIDEOTOOLBOX)
Added: trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm (0 => 237236)
--- trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm 2018-10-17 21:55:36 UTC (rev 237236)
@@ -0,0 +1,384 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#import "config.h"
+#import "ImageTransferSessionVT.h"
+
+#if USE(VIDEOTOOLBOX)
+
+#import "Logging.h"
+#import "MediaSampleAVFObjC.h"
+#import <CoreMedia/CMFormatDescription.h>
+#import <CoreMedia/CMSampleBuffer.h>
+#import <pal/cf/CoreMediaSoftLink.h>
+
+#if HAVE(IOSURFACE)
+#include <pal/spi/cocoa/IOSurfaceSPI.h>
+#endif
+
+#import "CoreVideoSoftLink.h"
+
+namespace WebCore {
+using namespace PAL;
+
+static inline CFStringRef cvPixelFormatOpenGLKey()
+{
+#if PLATFORM(IOS) && !PLATFORM(IOSMAC)
+ return kCVPixelFormatOpenGLESCompatibility;
+#else
+ return kCVPixelBufferOpenGLCompatibilityKey;
+#endif
+}
+
+ImageTransferSessionVT::ImageTransferSessionVT(uint32_t pixelFormat)
+{
+ VTPixelTransferSessionRef transferSession;
+ VTPixelTransferSessionCreate(kCFAllocatorDefault, &transferSession);
+ ASSERT(transferSession);
+ m_transferSession = adoptCF(transferSession);
+
+ auto status = VTSessionSetProperty(transferSession, kVTPixelTransferPropertyKey_ScalingMode, kVTScalingMode_Trim);
+ if (status != kCVReturnSuccess)
+ RELEASE_LOG(Media, "ImageTransferSessionVT::ImageTransferSessionVT: VTSessionSetProperty(kVTPixelTransferPropertyKey_ScalingMode) failed with error %d", static_cast<int>(status));
+
+ status = VTSessionSetProperty(transferSession, kVTPixelTransferPropertyKey_EnableHighSpeedTransfer, @(YES));
+ if (status != kCVReturnSuccess)
+ RELEASE_LOG(Media, "ImageTransferSessionVT::ImageTransferSessionVT: VTSessionSetProperty(kVTPixelTransferPropertyKey_EnableHighSpeedTransfer) failed with error %d", static_cast<int>(status));
+
+ status = VTSessionSetProperty(transferSession, kVTPixelTransferPropertyKey_RealTime, @(YES));
+ if (status != kCVReturnSuccess)
+ RELEASE_LOG(Media, "ImageTransferSessionVT::ImageTransferSessionVT: VTSessionSetProperty(kVTPixelTransferPropertyKey_RealTime) failed with error %d", static_cast<int>(status));
+
+#if PLATFORM(IOS) && !PLATFORM(IOSMAC)
+ status = VTSessionSetProperty(transferSession, kVTPixelTransferPropertyKey_EnableHardwareAcceleratedTransfer, @(YES));
+ if (status != kCVReturnSuccess)
+ RELEASE_LOG(Media, "ImageTransferSessionVT::ImageTransferSessionVT: VTSessionSetProperty(kVTPixelTransferPropertyKey_EnableHardwareAcceleratedTransfer) failed with error %d", static_cast<int>(status));
+#endif
+
+ m_pixelFormat = pixelFormat;
+}
+
+bool ImageTransferSessionVT::setSize(const IntSize& size)
+{
+ if (m_size == size && m_outputBufferPool)
+ return true;
+
+ CFDictionaryRef pixelBufferOptions = (__bridge CFDictionaryRef) @{
+ (__bridge NSString *)kCVPixelBufferWidthKey :@(size.width()),
+ (__bridge NSString *)kCVPixelBufferHeightKey:@(size.height()),
+ (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey:@(m_pixelFormat),
+ (__bridge NSString *)cvPixelFormatOpenGLKey() : @(YES),
+ (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ /*empty dictionary*/ },
+ };
+
+ CFDictionaryRef pixelBufferPoolOptions = (__bridge CFDictionaryRef) @{
+ (__bridge NSString *)kCVPixelBufferPoolMinimumBufferCountKey : @(6)
+ };
+
+ CVPixelBufferPoolRef bufferPool;
+ auto status = CVPixelBufferPoolCreate(kCFAllocatorDefault, pixelBufferPoolOptions, pixelBufferOptions, &bufferPool);
+ ASSERT(!status);
+ if (status != kCVReturnSuccess)
+ return false;
+
+ m_outputBufferPool = adoptCF(bufferPool);
+ m_size = size;
+ m_ioSurfaceBufferAttributes = nullptr;
+
+ return true;
+}
+
+RetainPtr<CVPixelBufferRef> ImageTransferSessionVT::convertPixelBuffer(CVPixelBufferRef sourceBuffer, const IntSize& size)
+{
+ if (sourceBuffer && m_size == IntSize(CVPixelBufferGetWidth(sourceBuffer), CVPixelBufferGetHeight(sourceBuffer)) && m_pixelFormat == CVPixelBufferGetPixelFormatType(sourceBuffer))
+ return retainPtr(sourceBuffer);
+
+ if (!sourceBuffer || !setSize(size))
+ return nullptr;
+
+ CVPixelBufferRef outputBuffer = nullptr;
+ auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_outputBufferPool.get(), &outputBuffer);
+ if (status) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::convertPixelBuffer, CVPixelBufferPoolCreatePixelBuffer failed with error %d", static_cast<int>(status));
+ return nullptr;
+ }
+ auto result = adoptCF(outputBuffer);
+
+ auto err = VTPixelTransferSessionTransferImage(m_transferSession.get(), sourceBuffer, outputBuffer);
+ if (err) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::convertPixelBuffer, VTPixelTransferSessionTransferImage failed with error %d", static_cast<int>(err));
+ return nullptr;
+ }
+
+ return result;
+}
+
+RetainPtr<CVPixelBufferRef> ImageTransferSessionVT::createPixelBuffer(CMSampleBufferRef sourceBuffer, const IntSize& size)
+{
+ return convertPixelBuffer(CMSampleBufferGetImageBuffer(sourceBuffer), size);
+}
+
+RetainPtr<CMSampleBufferRef> ImageTransferSessionVT::convertCMSampleBuffer(CMSampleBufferRef sourceBuffer, const IntSize& size)
+{
+ if (!sourceBuffer)
+ return nullptr;
+
+ auto description = CMSampleBufferGetFormatDescription(sourceBuffer);
+ auto sourceSize = FloatSize(CMVideoFormatDescriptionGetPresentationDimensions(description, true, true));
+ auto pixelBuffer = static_cast<CVPixelBufferRef>(CMSampleBufferGetImageBuffer(sourceBuffer));
+ if (size == roundedIntSize(sourceSize) && m_pixelFormat == CVPixelBufferGetPixelFormatType(pixelBuffer))
+ return retainPtr(sourceBuffer);
+
+ if (!setSize(size))
+ return nullptr;
+
+ auto convertedPixelBuffer = createPixelBuffer(sourceBuffer, size);
+ if (!convertedPixelBuffer)
+ return nullptr;
+
+ CMItemCount itemCount = 0;
+ auto status = CMSampleBufferGetSampleTimingInfoArray(sourceBuffer, 1, nullptr, &itemCount);
+ if (status != noErr) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::convertCMSampleBuffer: CMSampleBufferGetSampleTimingInfoArray failed with error code: %d", static_cast<int>(status));
+ return nullptr;
+ }
+ Vector<CMSampleTimingInfo> timingInfoArray;
+ CMSampleTimingInfo* timeingInfoPtr = nullptr;
+ if (itemCount) {
+ timingInfoArray.grow(itemCount);
+ status = CMSampleBufferGetSampleTimingInfoArray(sourceBuffer, itemCount, timingInfoArray.data(), nullptr);
+ if (status != noErr) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::convertCMSampleBuffer: CMSampleBufferGetSampleTimingInfoArray failed with error code: %d", static_cast<int>(status));
+ return nullptr;
+ }
+ timeingInfoPtr = timingInfoArray.data();
+ }
+
+ CMVideoFormatDescriptionRef formatDescription = nullptr;
+ status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, convertedPixelBuffer.get(), &formatDescription);
+ if (status != noErr) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::convertCMSampleBuffer: CMVideoFormatDescriptionCreateForImageBuffer returned: %d", static_cast<int>(status));
+ return nullptr;
+ }
+
+ CMSampleBufferRef resizedSampleBuffer;
+ status = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, convertedPixelBuffer.get(), formatDescription, timeingInfoPtr, &resizedSampleBuffer);
+ CFRelease(formatDescription);
+ if (status != noErr) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::convertCMSampleBuffer: failed to create CMSampleBuffer with error code: %d", static_cast<int>(status));
+ return nullptr;
+ }
+
+ return adoptCF(resizedSampleBuffer);
+}
+
+RetainPtr<CVPixelBufferRef> ImageTransferSessionVT::createPixelBuffer(CGImageRef image, const IntSize& size)
+{
+ if (!image || !setSize(size))
+ return nullptr;
+
+ CVPixelBufferRef rgbBuffer;
+ auto imageSize = IntSize(CGImageGetWidth(image), CGImageGetHeight(image));
+ auto status = CVPixelBufferCreate(kCFAllocatorDefault, imageSize.width(), imageSize.height(), kCVPixelFormatType_32ARGB, nullptr, &rgbBuffer);
+ if (status != kCVReturnSuccess) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::createPixelBuffer: CVPixelBufferCreate failed with error code: %d", static_cast<int>(status));
+ return nullptr;
+ }
+
+ CVPixelBufferLockBaseAddress(rgbBuffer, 0);
+ void* data = ""
+ auto retainedRGBBuffer = adoptCF(rgbBuffer);
+ auto context = CGBitmapContextCreate(data, imageSize.width(), imageSize.height(), 8, CVPixelBufferGetBytesPerRow(rgbBuffer), sRGBColorSpaceRef(), (CGBitmapInfo) kCGImageAlphaNoneSkipFirst);
+ if (!context) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::createPixelBuffer: CGBitmapContextCreate returned nullptr");
+ return nullptr;
+ }
+
+ auto retainedContext = adoptCF(context);
+ CGContextDrawImage(context, CGRectMake(0, 0, imageSize.width(), imageSize.height()), image);
+ CVPixelBufferUnlockBaseAddress(rgbBuffer, 0);
+
+ return convertPixelBuffer(rgbBuffer, size);
+}
+
+RetainPtr<CMSampleBufferRef> ImageTransferSessionVT::createCMSampleBuffer(CVPixelBufferRef sourceBuffer, const MediaTime& sampleTime, const IntSize& size)
+{
+ if (!sourceBuffer || !setSize(size))
+ return nullptr;
+
+ auto bufferSize = IntSize(CVPixelBufferGetWidth(sourceBuffer), CVPixelBufferGetHeight(sourceBuffer));
+ RetainPtr<CVPixelBufferRef> inputBuffer = sourceBuffer;
+ if (bufferSize != m_size || m_pixelFormat != CVPixelBufferGetPixelFormatType(sourceBuffer)) {
+ inputBuffer = convertPixelBuffer(sourceBuffer, m_size);
+ if (!inputBuffer)
+ return nullptr;
+ }
+
+ CMVideoFormatDescriptionRef formatDescription = nullptr;
+ auto status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)inputBuffer.get(), &formatDescription);
+ if (status) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::convertPixelBuffer: failed to initialize CMVideoFormatDescription with error code: %d", static_cast<int>(status));
+ return nullptr;
+ }
+
+ CMSampleBufferRef sampleBuffer;
+ auto cmTime = toCMTime(sampleTime);
+ CMSampleTimingInfo timingInfo = { kCMTimeInvalid, cmTime, cmTime };
+ status = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)inputBuffer.get(), formatDescription, &timingInfo, &sampleBuffer);
+ CFRelease(formatDescription);
+ if (status) {
+ RELEASE_LOG(Media, "ImageTransferSessionVT::convertPixelBuffer: failed to initialize CMSampleBuffer with error code: %d", static_cast<int>(status));
+ return nullptr;
+ }
+
+ return adoptCF(sampleBuffer);
+}
+
+RetainPtr<CMSampleBufferRef> ImageTransferSessionVT::createCMSampleBuffer(CGImageRef image, const MediaTime& sampleTime, const IntSize& size)
+{
+ auto pixelBuffer = createPixelBuffer(image, size);
+ if (!pixelBuffer)
+ return nullptr;
+
+ return createCMSampleBuffer(pixelBuffer.get(), sampleTime, size);
+}
+
+#if HAVE(IOSURFACE)
+
+#if PLATFORM(MAC)
+static int32_t roundUpToMacroblockMultiple(int32_t size)
+{
+ return (size + 15) & ~15;
+}
+#endif
+
+CFDictionaryRef ImageTransferSessionVT::ioSurfacePixelBufferCreationOptions(IOSurfaceRef surface)
+{
+ if (m_ioSurfaceBufferAttributes)
+ return m_ioSurfaceBufferAttributes.get();
+
+ m_ioSurfaceBufferAttributes = (__bridge CFDictionaryRef) @{
+ (__bridge NSString *)cvPixelFormatOpenGLKey() : @(YES),
+ };
+
+#if PLATFORM(MAC)
+ auto format = IOSurfaceGetPixelFormat(surface);
+ auto width = IOSurfaceGetWidth(surface);
+ auto height = IOSurfaceGetHeight(surface);
+ auto extendedRight = roundUpToMacroblockMultiple(width) - width;
+ auto extendedBottom = roundUpToMacroblockMultiple(height) - height;
+
+ if ((format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
+ && (IOSurfaceGetBytesPerRowOfPlane(surface, 0) >= width + extendedRight)
+ && (IOSurfaceGetBytesPerRowOfPlane(surface, 1) >= width + extendedRight)
+ && (IOSurfaceGetAllocSize(surface) >= (height + extendedBottom) * IOSurfaceGetBytesPerRowOfPlane(surface, 0) * 3 / 2)) {
+ m_ioSurfaceBufferAttributes = (__bridge CFDictionaryRef) @{
+ (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @(YES),
+ (__bridge NSString *)kCVPixelBufferExtendedPixelsRightKey : @(extendedRight),
+ (__bridge NSString *)kCVPixelBufferExtendedPixelsBottomKey : @(extendedBottom)
+ };
+ }
+#else
+ UNUSED_PARAM(surface);
+#endif
+
+ return m_ioSurfaceBufferAttributes.get();
+}
+
+RetainPtr<CVPixelBufferRef> ImageTransferSessionVT::createPixelBuffer(IOSurfaceRef surface, const IntSize& size)
+{
+ if (!surface || !setSize(size))
+ return nullptr;
+
+ CVPixelBufferRef pixelBuffer;
+ auto status = CVPixelBufferCreateWithIOSurface(kCFAllocatorDefault, surface, ioSurfacePixelBufferCreationOptions(surface), &pixelBuffer);
+ if (status) {
+ RELEASE_LOG(Media, "CVPixelBufferCreateWithIOSurface failed with error code: %d", static_cast<int>(status));
+ return nullptr;
+ }
+
+ auto retainedBuffer = adoptCF(pixelBuffer);
+ if (m_size == IntSize(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer)) && m_pixelFormat == CVPixelBufferGetPixelFormatType(pixelBuffer))
+ return retainedBuffer;
+
+ return convertPixelBuffer(pixelBuffer, size);
+}
+
+RetainPtr<CMSampleBufferRef> ImageTransferSessionVT::createCMSampleBuffer(IOSurfaceRef surface, const MediaTime& sampleTime, const IntSize& size)
+{
+ auto pixelBuffer = createPixelBuffer(surface, size);
+ if (!pixelBuffer)
+ return nullptr;
+
+ return createCMSampleBuffer(pixelBuffer.get(), sampleTime, size);
+}
+#endif
+
+RefPtr<MediaSample> ImageTransferSessionVT::convertMediaSample(MediaSample& sample, const IntSize& size)
+{
+ ASSERT(sample.platformSample().type == PlatformSample::CMSampleBufferType);
+
+ if (size == roundedIntSize(sample.presentationSize()))
+ return &sample;
+
+ auto resizedBuffer = convertCMSampleBuffer(sample.platformSample().sample.cmSampleBuffer, size);
+ if (!resizedBuffer)
+ return nullptr;
+
+ return MediaSampleAVFObjC::create(resizedBuffer.get(), sample.videoRotation(), sample.videoMirrored());
+}
+
+#if HAVE(IOSURFACE)
+RefPtr<MediaSample> ImageTransferSessionVT::createMediaSample(IOSurfaceRef surface, const MediaTime& sampleTime, const IntSize& size, MediaSample::VideoRotation rotation, bool mirrored)
+{
+ auto sampleBuffer = createCMSampleBuffer(surface, sampleTime, size);
+ if (!sampleBuffer)
+ return nullptr;
+
+ return MediaSampleAVFObjC::create(sampleBuffer.get(), rotation, mirrored);
+}
+#endif
+
+RefPtr<MediaSample> ImageTransferSessionVT::createMediaSample(CGImageRef image, const MediaTime& sampleTime, const IntSize& size, MediaSample::VideoRotation rotation, bool mirrored)
+{
+ auto sampleBuffer = createCMSampleBuffer(image, sampleTime, size);
+ if (!sampleBuffer)
+ return nullptr;
+
+ return MediaSampleAVFObjC::create(sampleBuffer.get(), rotation, mirrored);
+}
+
+RefPtr<MediaSample> ImageTransferSessionVT::createMediaSample(CMSampleBufferRef buffer, const IntSize& size, MediaSample::VideoRotation rotation, bool mirrored)
+{
+ auto sampleBuffer = convertCMSampleBuffer(buffer, size);
+ if (!sampleBuffer)
+ return nullptr;
+
+ return MediaSampleAVFObjC::create(sampleBuffer.get(), rotation, mirrored);
+}
+
+} // namespace WebCore
+
+#endif // USE(VIDEOTOOLBOX)
Deleted: trunk/Source/WebCore/platform/graphics/cv/PixelBufferResizer.h (237235 => 237236)
--- trunk/Source/WebCore/platform/graphics/cv/PixelBufferResizer.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/graphics/cv/PixelBufferResizer.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2018 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.
- */
-
-#pragma once
-
-#if USE(VIDEOTOOLBOX)
-
-#include "IntSize.h"
-#include <wtf/RetainPtr.h>
-
-typedef struct OpaqueVTPixelTransferSession* VTPixelTransferSessionRef;
-typedef struct __CVBuffer *CVPixelBufferRef;
-typedef struct __CVPixelBufferPool *CVPixelBufferPoolRef;
-typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
-
-namespace WebCore {
-
-class PixelBufferResizer {
-public:
- PixelBufferResizer(IntSize, OSType);
-
- RetainPtr<CVPixelBufferRef> resize(CVPixelBufferRef);
- RetainPtr<CMSampleBufferRef> resize(CMSampleBufferRef);
- bool canResizeTo(IntSize size) { return size == m_size; }
-
-private:
- RetainPtr<VTPixelTransferSessionRef> m_transferSession;
- RetainPtr<CVPixelBufferPoolRef> m_bufferPool;
- IntSize m_size;
-};
-
-}
-
-#endif // USE(VIDEOTOOLBOX)
Deleted: trunk/Source/WebCore/platform/graphics/cv/PixelBufferResizer.mm (237235 => 237236)
--- trunk/Source/WebCore/platform/graphics/cv/PixelBufferResizer.mm 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/graphics/cv/PixelBufferResizer.mm 2018-10-17 21:55:36 UTC (rev 237236)
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2018 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.
- */
-
-#import "config.h"
-#import "PixelBufferResizer.h"
-
-#if USE(VIDEOTOOLBOX)
-
-#import "Logging.h"
-#import <wtf/SoftLinking.h>
-
-#import "CoreVideoSoftLink.h"
-#import "VideoToolboxSoftLink.h"
-
-namespace WebCore {
-
-PixelBufferResizer::PixelBufferResizer(IntSize size, OSType videoFormat)
-{
- VTPixelTransferSessionRef transferSession;
- VTPixelTransferSessionCreate(NULL, &transferSession);
- ASSERT(transferSession);
- m_transferSession = adoptCF(transferSession);
-
- VTSessionSetProperty(transferSession, kVTPixelTransferPropertyKey_ScalingMode, kVTScalingMode_Trim);
-
- CFDictionaryRef sourcePixelBufferOptions = (__bridge CFDictionaryRef) @{
- (__bridge NSString *)kCVPixelBufferWidthKey :@(size.width()),
- (__bridge NSString *)kCVPixelBufferHeightKey:@(size.height()),
- (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey:@(videoFormat),
-#if PLATFORM(IOS) && !PLATFORM(IOSMAC)
- (__bridge NSString *)kCVPixelFormatOpenGLESCompatibility : @(YES),
-#else
- (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @(YES),
-#endif
- (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ /*empty dictionary*/ },
- };
- CVPixelBufferPoolRef bufferPool;
- auto status = CVPixelBufferPoolCreate(kCFAllocatorDefault, NULL, sourcePixelBufferOptions, &bufferPool);
- ASSERT(!status);
- if (status != kCVReturnSuccess)
- return;
-
- m_bufferPool = adoptCF(bufferPool);
- m_size = size;
-}
-
-RetainPtr<CVPixelBufferRef> PixelBufferResizer::resize(CVPixelBufferRef inputBuffer)
-{
- ASSERT(m_bufferPool && !m_size.isEmpty());
- if (!m_bufferPool || m_size.isEmpty())
- return nullptr;
-
- RetainPtr<CVPixelBufferRef> result;
- CVPixelBufferRef outputBuffer = nullptr;
-
- auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_bufferPool.get(), &outputBuffer);
- if (status) {
- RELEASE_LOG(Media, "PixelBufferResizer::resize, CVPixelBufferPoolCreatePixelBuffer failed with error %d", static_cast<int>(status));
- return nullptr;
- }
- result = adoptCF(outputBuffer);
-
- auto err = VTPixelTransferSessionTransferImage(m_transferSession.get(), inputBuffer, outputBuffer);
- if (err) {
- RELEASE_LOG(Media, "PixelBufferResizer::resize, VTPixelTransferSessionTransferImage failed with error %d", static_cast<int>(err));
- return nullptr;
- }
-
- return result;
-}
-
-RetainPtr<CMSampleBufferRef> PixelBufferResizer::resize(CMSampleBufferRef sampleBuffer)
-{
- auto convertedPixelBuffer = resize(CMSampleBufferGetImageBuffer(sampleBuffer));
- if (!convertedPixelBuffer)
- return nullptr;
-
- CMVideoFormatDescriptionRef formatDescription = nullptr;
- auto status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, convertedPixelBuffer.get(), &formatDescription);
- if (status != noErr) {
- RELEASE_LOG(Media, "PixelBufferResizer::resize: failed to create CMVideoFormatDescription with error code: %d", static_cast<int>(status));
- return nullptr;
- }
-
- CMItemCount itemCount = 0;
- status = CMSampleBufferGetSampleTimingInfoArray(sampleBuffer, 1, nullptr, &itemCount);
- if (status != noErr) {
- RELEASE_LOG(Media, "PixelBufferResizer::resize: CMSampleBufferGetSampleTimingInfoArray failed with error code: %d", static_cast<int>(status));
- return nullptr;
- }
- Vector<CMSampleTimingInfo> timingInfoArray;
- CMSampleTimingInfo* timeingInfoPtr = nullptr;
- if (itemCount) {
- timingInfoArray.grow(itemCount);
- status = CMSampleBufferGetSampleTimingInfoArray(sampleBuffer, itemCount, timingInfoArray.data(), nullptr);
- if (status != noErr) {
- RELEASE_LOG(Media, "PixelBufferResizer::resize: CMSampleBufferGetSampleTimingInfoArray failed with error code: %d", static_cast<int>(status));
- return nullptr;
- }
- timeingInfoPtr = timingInfoArray.data();
- }
-
- CMSampleBufferRef resizedSampleBuffer;
- status = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, convertedPixelBuffer.get(), formatDescription, timeingInfoPtr, &resizedSampleBuffer);
- CFRelease(formatDescription);
- if (status != noErr) {
- RELEASE_LOG(Media, "PixelBufferResizer::resize: failed to create CMSampleBuffer with error code: %d", static_cast<int>(status));
- return nullptr;
- }
-
- return adoptCF(resizedSampleBuffer);
-}
-
-} // namespace WebCore
-
-#endif // USE(VIDEOTOOLBOX)
Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp 2018-10-17 21:55:36 UTC (rev 237236)
@@ -133,10 +133,6 @@
});
}
-void RealtimeMediaSource::settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>)
-{
-}
-
void RealtimeMediaSource::notifySettingsDidChangeObservers(OptionSet<RealtimeMediaSourceSettings::Flag> flags)
{
ASSERT(isMainThread());
Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -200,7 +200,7 @@
private:
virtual void startProducingData() { }
virtual void stopProducingData() { }
- virtual void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>);
+ virtual void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>) { }
void forEachObserver(const WTF::Function<void(Observer&)>&) const;
Modified: trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -49,7 +49,7 @@
namespace WebCore {
class AVVideoPreset;
-class PixelBufferResizer;
+class ImageTransferSessionVT;
class AVVideoCaptureSource : public RealtimeVideoSource, private OrientationNotifier::Observer {
public:
@@ -103,13 +103,14 @@
bool setFrameRateConstraint(double minFrameRate, double maxFrameRate);
- void processNewFrame(RetainPtr<CMSampleBufferRef>, RetainPtr<AVCaptureConnection>);
+ void processNewFrame(Ref<MediaSample>&&);
IntSize sizeForPreset(NSString*);
AVCaptureDevice* device() const { return m_device.get(); }
- RetainPtr<CMSampleBufferRef> m_buffer;
+ RefPtr<MediaSample> m_buffer;
RetainPtr<AVCaptureVideoDataOutput> m_videoOutput;
+ std::unique_ptr<ImageTransferSessionVT> m_imageTransferSession;
IntSize m_requestedSize;
int32_t m_width { 0 };
@@ -118,7 +119,6 @@
int m_deviceOrientation { 0 };
MediaSample::VideoRotation m_sampleRotation { MediaSample::VideoRotation::None };
- std::unique_ptr<PixelBufferResizer> m_pixelBufferResizer;
std::optional<RealtimeMediaSourceSettings> m_currentSettings;
std::optional<RealtimeMediaSourceCapabilities> m_capabilities;
RetainPtr<WebCoreAVVideoCaptureSourceObserver> m_objcObserver;
Modified: trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm 2018-10-17 21:55:36 UTC (rev 237236)
@@ -29,11 +29,11 @@
#if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
#import "ImageBuffer.h"
+#import "ImageTransferSessionVT.h"
#import "IntRect.h"
#import "Logging.h"
#import "MediaConstraints.h"
#import "MediaSampleAVFObjC.h"
-#import "PixelBufferResizer.h"
#import "PlatformLayer.h"
#import "RealtimeMediaSourceCenterMac.h"
#import "RealtimeMediaSourceSettings.h"
@@ -299,7 +299,7 @@
bool AVVideoCaptureSource::prefersPreset(VideoPreset& preset)
{
#if PLATFORM(IOS)
- return ![static_cast<AVVideoPreset*>(&preset)->format.get() isVideoBinned];
+ return [static_cast<AVVideoPreset*>(&preset)->format.get() isVideoBinned];
#else
UNUSED_PARAM(preset);
#endif
@@ -519,27 +519,23 @@
}
}
-void AVVideoCaptureSource::processNewFrame(RetainPtr<CMSampleBufferRef> sampleBuffer, RetainPtr<AVCaptureConnectionType> connection)
+void AVVideoCaptureSource::processNewFrame(Ref<MediaSample>&& sample)
{
if (!isProducingData() || muted())
return;
- CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer.get());
- if (!formatDescription)
- return;
-
- m_buffer = sampleBuffer;
- CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
+ m_buffer = &sample.get();
+ auto dimensions = roundedIntSize(sample->presentationSize());
if (m_sampleRotation == MediaSample::VideoRotation::Left || m_sampleRotation == MediaSample::VideoRotation::Right)
- std::swap(dimensions.width, dimensions.height);
+ dimensions = { dimensions.height(), dimensions.width() };
- if (dimensions.width != m_width || dimensions.height != m_height) {
- m_width = dimensions.width;
- m_height = dimensions.height;
- setSize({ dimensions.width, dimensions.height });
+ if (dimensions.width() != m_width || dimensions.height() != m_height) {
+ m_width = dimensions.width();
+ m_height = dimensions.height();
+ setSize(dimensions);
}
- videoSampleAvailable(MediaSampleAVFObjC::create(m_buffer.get(), m_sampleRotation, [connection isVideoMirrored]));
+ dispatchMediaSampleToObservers(WTFMove(sample));
}
void AVVideoCaptureSource::captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutputType*, CMSampleBufferRef sampleBuffer, AVCaptureConnectionType* captureConnection)
@@ -549,24 +545,22 @@
return;
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
+ RefPtr<MediaSample> sample;
if (dimensions.width != m_requestedSize.width() || dimensions.height != m_requestedSize.height()) {
- if (m_pixelBufferResizer && !m_pixelBufferResizer->canResizeTo(m_requestedSize))
- m_pixelBufferResizer = nullptr;
- if (!m_pixelBufferResizer)
- m_pixelBufferResizer = std::make_unique<PixelBufferResizer>(m_requestedSize, avVideoCapturePixelBufferFormat());
- } else
- m_pixelBufferResizer = nullptr;
+ if (!m_imageTransferSession)
+ m_imageTransferSession = ImageTransferSessionVT::create(avVideoCapturePixelBufferFormat());
- auto buffer = retainPtr(sampleBuffer);
- if (m_pixelBufferResizer) {
- buffer = m_pixelBufferResizer->resize(sampleBuffer);
- if (!buffer)
+ sample = m_imageTransferSession->createMediaSample(sampleBuffer, m_requestedSize, m_sampleRotation, [captureConnection isVideoMirrored]);
+ if (!sample) {
+ ASSERT_NOT_REACHED();
return;
- }
+ }
+ } else
+ sample = MediaSampleAVFObjC::create(sampleBuffer, m_sampleRotation, [captureConnection isVideoMirrored]);
- scheduleDeferredTask([this, buffer, connection = retainPtr(captureConnection)] {
- this->processNewFrame(buffer, connection);
+ scheduleDeferredTask([this, sample = WTFMove(sample)] () mutable {
+ processNewFrame(sample.releaseNonNull());
});
}
Modified: trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp 2018-10-17 21:55:36 UTC (rev 237236)
@@ -31,7 +31,6 @@
#include "Logging.h"
#include "MediaSampleAVFObjC.h"
#include "PixelBufferConformerCV.h"
-#include "PixelBufferResizer.h"
#include "RealtimeMediaSource.h"
#include "RealtimeMediaSourceCenter.h"
#include "RealtimeMediaSourceSettings.h"
@@ -42,6 +41,8 @@
#include <pal/avfoundation/MediaTimeAVFoundation.h>
#include <pal/cf/CoreMediaSoftLink.h>
#include <pal/spi/cf/CoreAudioSPI.h>
+#include <pal/spi/cg/CoreGraphicsSPI.h>
+#include <pal/spi/cocoa/IOSurfaceSPI.h>
#include <sys/time.h>
#include <wtf/MainThread.h>
#include <wtf/NeverDestroyed.h>
@@ -72,7 +73,7 @@
// FIXME: what should these be?
capabilities.setWidth(CapabilityValueOrRange(72, 2880));
capabilities.setHeight(CapabilityValueOrRange(45, 1800));
- capabilities.setFrameRate(CapabilityValueOrRange(.01, 60.0));
+ capabilities.setFrameRate(CapabilityValueOrRange(.01, 30.0));
m_capabilities = WTFMove(capabilities);
}
@@ -111,10 +112,8 @@
if (settings.contains(RealtimeMediaSourceSettings::Flag::FrameRate) && m_timer.isActive())
m_timer.startRepeating(1_s / frameRate());
- if (settings.containsAny({ RealtimeMediaSourceSettings::Flag::Width, RealtimeMediaSourceSettings::Flag::Height })) {
+ if (settings.containsAny({ RealtimeMediaSourceSettings::Flag::Width, RealtimeMediaSourceSettings::Flag::Height }))
m_bufferAttributes = nullptr;
- m_lastSampleBuffer = nullptr;
- }
m_currentSettings = { };
}
@@ -159,133 +158,51 @@
return;
m_intrinsicSize = size;
- m_lastSampleBuffer = nullptr;
+ notifySettingsDidChangeObservers({ RealtimeMediaSourceSettings::Flag::Width, RealtimeMediaSourceSettings::Flag::Height });
+
}
void DisplayCaptureSourceCocoa::emitFrame()
{
+#if PLATFORM(COCOA) && !PLATFORM(IOS_FAMILY_SIMULATOR)
if (muted())
return;
- auto pixelBuffer = generateFrame();
- if (!pixelBuffer)
- return;
+ if (!m_imageTransferSession)
+ m_imageTransferSession = ImageTransferSessionVT::create(preferedPixelBufferFormat());
- if (m_lastSampleBuffer && m_lastFullSizedPixelBuffer && CFEqual(m_lastFullSizedPixelBuffer.get(), pixelBuffer.get())) {
- videoSampleAvailable(MediaSampleAVFObjC::create(m_lastSampleBuffer.get()));
- return;
- }
+ auto sampleTime = MediaTime::createWithDouble((elapsedTime() + 100_ms).seconds());
+ auto frame = generateFrame();
+ IntSize imageSize;
+ RefPtr<MediaSample> sample = WTF::switchOn(frame,
+ [this, sampleTime, &imageSize](RetainPtr<IOSurfaceRef> surface) -> RefPtr<MediaSample> {
+ if (!surface)
+ return nullptr;
- m_lastFullSizedPixelBuffer = pixelBuffer;
+ imageSize = IntSize(IOSurfaceGetWidth(surface.get()), IOSurfaceGetHeight(surface.get()));
+ return m_imageTransferSession->createMediaSample(surface.get(), sampleTime, imageSize);
+ },
+ [this, sampleTime, &imageSize](RetainPtr<CGImageRef> image) -> RefPtr<MediaSample> {
+ if (!image)
+ return nullptr;
- int width = WTF::safeCast<int>(CVPixelBufferGetWidth(pixelBuffer.get()));
- int height = WTF::safeCast<int>(CVPixelBufferGetHeight(pixelBuffer.get()));
- auto requestedSize = frameSize();
- if (width != requestedSize.width() || height != requestedSize.height()) {
- if (m_pixelBufferResizer && !m_pixelBufferResizer->canResizeTo(requestedSize))
- m_pixelBufferResizer = nullptr;
-
- if (!m_pixelBufferResizer)
- m_pixelBufferResizer = std::make_unique<PixelBufferResizer>(requestedSize, preferedPixelBufferFormat());
-
- pixelBuffer = m_pixelBufferResizer->resize(pixelBuffer.get());
- } else {
- m_pixelBufferResizer = nullptr;
-
- auto pixelFormatType = CVPixelBufferGetPixelFormatType(pixelBuffer.get());
- if (pixelFormatType != preferedPixelBufferFormat()) {
- if (!m_pixelBufferConformer) {
- auto preferredFromat = preferedPixelBufferFormat();
- auto conformerAttributes = adoptCF(CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
- auto videoType = adoptCF(CFNumberCreate(nullptr, kCFNumberSInt32Type, &preferredFromat));
- CFDictionarySetValue(conformerAttributes.get(), kCVPixelBufferPixelFormatTypeKey, videoType.get());
-
- m_pixelBufferConformer = std::make_unique<PixelBufferConformerCV>(conformerAttributes.get());
- }
-
- pixelBuffer = m_pixelBufferConformer->convert(pixelBuffer.get());
+ imageSize = IntSize(CGImageGetWidth(image.get()), CGImageGetHeight(image.get()));
+ return m_imageTransferSession->createMediaSample(image.get(), sampleTime, imageSize);
}
- }
- if (!pixelBuffer)
- return;
+ );
- m_lastSampleBuffer = sampleBufferFromPixelBuffer(pixelBuffer.get());
- if (!m_lastSampleBuffer)
+ if (!sample) {
+ ASSERT_NOT_REACHED();
return;
-
- videoSampleAvailable(MediaSampleAVFObjC::create(m_lastSampleBuffer.get()));
-}
-
-RetainPtr<CMSampleBufferRef> DisplayCaptureSourceCocoa::sampleBufferFromPixelBuffer(CVPixelBufferRef pixelBuffer)
-{
- if (!pixelBuffer)
- return nullptr;
-
- CMTime sampleTime = CMTimeMake(((elapsedTime() + 100_ms) * 100).seconds(), 100);
- CMSampleTimingInfo timingInfo = { kCMTimeInvalid, sampleTime, sampleTime };
-
- CMVideoFormatDescriptionRef formatDescription = nullptr;
- auto status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, &formatDescription);
- if (status) {
- RELEASE_LOG(Media, "Failed to initialize CMVideoFormatDescription with error code: %d", static_cast<int>(status));
- return nullptr;
}
- CMSampleBufferRef sampleBuffer;
- status = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, formatDescription, &timingInfo, &sampleBuffer);
- CFRelease(formatDescription);
- if (status) {
- RELEASE_LOG(Media, "Failed to initialize CMSampleBuffer with error code: %d", static_cast<int>(status));
- return nullptr;
- }
+ if (m_intrinsicSize != imageSize)
+ setIntrinsicSize(imageSize);
- return adoptCF(sampleBuffer);
+ videoSampleAvailable(*sample.get());
+#endif
}
-#if HAVE(IOSURFACE) && PLATFORM(MAC)
-static int32_t roundUpToMacroblockMultiple(int32_t size)
-{
- return (size + 15) & ~15;
-}
-
-RetainPtr<CVPixelBufferRef> DisplayCaptureSourceCocoa::pixelBufferFromIOSurface(IOSurfaceRef surface)
-{
- if (!m_bufferAttributes) {
- m_bufferAttributes = adoptCF(CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-
- auto format = IOSurfaceGetPixelFormat(surface);
- if (format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
-
- // If the width x height isn't a multiple of 16 x 16 and the surface has extra memory in the planes, set pixel buffer attributes to reflect it.
- auto width = IOSurfaceGetWidth(surface);
- auto height = IOSurfaceGetHeight(surface);
- int32_t extendedRight = roundUpToMacroblockMultiple(width) - width;
- int32_t extendedBottom = roundUpToMacroblockMultiple(height) - height;
-
- if ((IOSurfaceGetBytesPerRowOfPlane(surface, 0) >= width + extendedRight)
- && (IOSurfaceGetBytesPerRowOfPlane(surface, 1) >= width + extendedRight)
- && (IOSurfaceGetAllocSize(surface) >= (height + extendedBottom) * IOSurfaceGetBytesPerRowOfPlane(surface, 0) * 3 / 2)) {
- auto cfInt = adoptCF(CFNumberCreate(nullptr, kCFNumberIntType, &extendedRight));
- CFDictionarySetValue(m_bufferAttributes.get(), kCVPixelBufferExtendedPixelsRightKey, cfInt.get());
- cfInt = adoptCF(CFNumberCreate(nullptr, kCFNumberIntType, &extendedBottom));
- CFDictionarySetValue(m_bufferAttributes.get(), kCVPixelBufferExtendedPixelsBottomKey, cfInt.get());
- }
- }
-
- CFDictionarySetValue(m_bufferAttributes.get(), kCVPixelBufferOpenGLCompatibilityKey, kCFBooleanTrue);
- }
-
- CVPixelBufferRef pixelBuffer;
- auto status = CVPixelBufferCreateWithIOSurface(kCFAllocatorDefault, surface, m_bufferAttributes.get(), &pixelBuffer);
- if (status) {
- RELEASE_LOG(Media, "CVPixelBufferCreateWithIOSurface failed with error code: %d", static_cast<int>(status));
- return nullptr;
- }
-
- return adoptCF(pixelBuffer);
-}
-#endif
-
} // namespace WebCore
#endif // ENABLE(MEDIA_STREAM)
Modified: trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.h (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -28,6 +28,7 @@
#if ENABLE(MEDIA_STREAM)
#include "CaptureDevice.h"
+#include "ImageTransferSessionVT.h"
#include "RealtimeMediaSource.h"
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
@@ -34,6 +35,7 @@
#include <wtf/RunLoop.h>
#include <wtf/text/WTFString.h>
+typedef struct CGImage *CGImageRef;
typedef struct __CVBuffer *CVPixelBufferRef;
typedef struct __IOSurface *IOSurfaceRef;
@@ -44,8 +46,8 @@
namespace WebCore {
class CaptureDeviceInfo;
+class ImageTransferSessionVT;
class PixelBufferConformerCV;
-class PixelBufferResizer;
class DisplayCaptureSourceCocoa : public RealtimeMediaSource {
public:
@@ -54,7 +56,9 @@
DisplayCaptureSourceCocoa(String&& name);
virtual ~DisplayCaptureSourceCocoa();
- virtual RetainPtr<CVPixelBufferRef> generateFrame() = 0;
+ using DisplayFrameType = WTF::Variant<RetainPtr<CGImageRef>, RetainPtr<IOSurfaceRef>>;
+ virtual DisplayFrameType generateFrame() = 0;
+
virtual RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const = 0;
void startProducingData() override;
@@ -62,11 +66,6 @@
Seconds elapsedTime();
- RetainPtr<CMSampleBufferRef> sampleBufferFromPixelBuffer(CVPixelBufferRef);
-#if HAVE(IOSURFACE)
- RetainPtr<CVPixelBufferRef> pixelBufferFromIOSurface(IOSurfaceRef);
-#endif
-
void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>) override;
const IntSize& intrinsicSize() const { return m_intrinsicSize; }
@@ -93,10 +92,7 @@
RetainPtr<CFMutableDictionaryRef> m_bufferAttributes;
RunLoop::Timer<DisplayCaptureSourceCocoa> m_timer;
- std::unique_ptr<PixelBufferResizer> m_pixelBufferResizer;
- std::unique_ptr<PixelBufferConformerCV> m_pixelBufferConformer;
- RetainPtr<CVPixelBufferRef> m_lastFullSizedPixelBuffer;
- RetainPtr<CMSampleBufferRef> m_lastSampleBuffer;
+ std::unique_ptr<ImageTransferSessionVT> m_imageTransferSession;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -43,7 +43,7 @@
namespace WebCore {
-class PixelBufferResizer;
+class ImageTransferSessionVT;
class MockRealtimeVideoSourceMac final : public MockRealtimeVideoSource, private OrientationNotifier::Observer {
public:
@@ -53,22 +53,15 @@
friend class MockRealtimeVideoSource;
MockRealtimeVideoSourceMac(String&& deviceID, String&& name, String&& hashSalt);
- RetainPtr<CMSampleBufferRef> CMSampleBufferFromPixelBuffer(CVPixelBufferRef);
- RetainPtr<CVPixelBufferRef> pixelBufferFromCGImage(CGImageRef) const;
-
PlatformLayer* platformLayer() const;
void updateSampleBuffer() final;
- void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>) final;
bool canResizeVideoFrames() const final { return true; }
- void setSizeAndFrameRateWithPreset(IntSize, double, RefPtr<VideoPreset>) final;
void orientationChanged(int orientation) final;
void monitorOrientation(OrientationNotifier&) final;
- mutable RetainPtr<CVPixelBufferPoolRef> m_bufferPool;
MediaSample::VideoRotation m_deviceOrientation { MediaSample::VideoRotation::None };
- std::unique_ptr<PixelBufferConformerCV> m_pixelBufferConformer;
- std::unique_ptr<PixelBufferResizer> m_pixelBufferResizer;
+ std::unique_ptr<ImageTransferSessionVT> m_imageTransferSession;
IntSize m_presetSize;
};
Modified: trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm 2018-10-17 21:55:36 UTC (rev 237236)
@@ -34,10 +34,10 @@
#if ENABLE(MEDIA_STREAM)
#import "GraphicsContextCG.h"
#import "ImageBuffer.h"
+#import "ImageTransferSessionVT.h"
#import "MediaConstraints.h"
#import "MediaSampleAVFObjC.h"
#import "NotImplemented.h"
-#import "PixelBufferResizer.h"
#import "PlatformLayer.h"
#import "RealtimeMediaSourceSettings.h"
#import "RealtimeVideoUtilities.h"
@@ -51,8 +51,6 @@
namespace WebCore {
using namespace PAL;
-static const int videoSampleRate = 90000;
-
CaptureSourceOrError MockRealtimeVideoSource::create(String&& deviceID, String&& name, String&& hashSalt, const MediaConstraints* constraints)
{
#ifndef NDEBUG
@@ -75,76 +73,6 @@
{
}
-RetainPtr<CMSampleBufferRef> MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer(CVPixelBufferRef pixelBuffer)
-{
- if (!pixelBuffer)
- return nullptr;
-
- CMTime sampleTime = CMTimeMake(((elapsedTime() + 100_ms) * videoSampleRate).seconds(), videoSampleRate);
- CMSampleTimingInfo timingInfo = { kCMTimeInvalid, sampleTime, sampleTime };
-
- CMVideoFormatDescriptionRef formatDescription = nullptr;
- OSStatus status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, &formatDescription);
- if (status != noErr) {
- LOG_ERROR("Failed to initialize CMVideoFormatDescription with error code: %d", status);
- return nullptr;
- }
-
- CMSampleBufferRef sampleBuffer;
- status = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, formatDescription, &timingInfo, &sampleBuffer);
- CFRelease(formatDescription);
- if (status != noErr) {
- LOG_ERROR("Failed to initialize CMSampleBuffer with error code: %d", status);
- return nullptr;
- }
-
- return adoptCF(sampleBuffer);
-}
-
-RetainPtr<CVPixelBufferRef> MockRealtimeVideoSourceMac::pixelBufferFromCGImage(CGImageRef image) const
-{
- static CGColorSpaceRef sRGBColorSpace = sRGBColorSpaceRef();
-
- CGSize imageSize = CGSizeMake(CGImageGetWidth(image), CGImageGetHeight(image));
- if (!m_bufferPool) {
- CVPixelBufferPoolRef bufferPool;
- CFDictionaryRef sourcePixelBufferOptions = (__bridge CFDictionaryRef) @{
- (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32ARGB),
- (__bridge NSString *)kCVPixelBufferWidthKey : @(imageSize.width),
- (__bridge NSString *)kCVPixelBufferHeightKey : @(imageSize.height),
-#if PLATFORM(IOS)
- (__bridge NSString *)kCVPixelFormatOpenGLESCompatibility : @(YES),
-#else
- (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @(YES),
-#endif
- (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{/*empty dictionary*/}
- };
-
- CFDictionaryRef pixelBufferPoolOptions = (__bridge CFDictionaryRef) @{
- (__bridge NSString *)kCVPixelBufferPoolMinimumBufferCountKey : @(4)
- };
-
- CVReturn status = CVPixelBufferPoolCreate(kCFAllocatorDefault, pixelBufferPoolOptions, sourcePixelBufferOptions, &bufferPool);
- if (status != kCVReturnSuccess)
- return nullptr;
-
- m_bufferPool = adoptCF(bufferPool);
- }
-
- CVPixelBufferRef pixelBuffer;
- CVReturn status = CVPixelBufferPoolCreatePixelBuffer(nullptr, m_bufferPool.get(), &pixelBuffer);
- if (status != kCVReturnSuccess)
- return nullptr;
-
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
- void* data = ""
- auto context = adoptCF(CGBitmapContextCreate(data, imageSize.width, imageSize.height, 8, CVPixelBufferGetBytesPerRow(pixelBuffer), sRGBColorSpace, (CGBitmapInfo) kCGImageAlphaNoneSkipFirst));
- CGContextDrawImage(context.get(), CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image);
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
-
- return adoptCF(pixelBuffer);
-}
-
void MockRealtimeVideoSourceMac::updateSampleBuffer()
{
auto imageBuffer = this->imageBuffer();
@@ -151,31 +79,18 @@
if (!imageBuffer)
return;
- auto pixelBuffer = pixelBufferFromCGImage(imageBuffer->copyImage()->nativeImage().get());
- if (m_pixelBufferResizer)
- pixelBuffer = m_pixelBufferResizer->resize(pixelBuffer.get());
- else {
- if (!m_pixelBufferConformer) {
- m_pixelBufferConformer = std::make_unique<PixelBufferConformerCV>((__bridge CFDictionaryRef)@{
- (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(preferedPixelBufferFormat())
- });
- }
+ if (!m_imageTransferSession)
+ m_imageTransferSession = ImageTransferSessionVT::create(preferedPixelBufferFormat());
- pixelBuffer = m_pixelBufferConformer->convert(pixelBuffer.get());
- }
- auto sampleBuffer = CMSampleBufferFromPixelBuffer(pixelBuffer.get());
+ auto sampleTime = MediaTime::createWithDouble((elapsedTime() + 100_ms).seconds());
+ auto sampleBuffer = m_imageTransferSession->createMediaSample(imageBuffer->copyImage()->nativeImage().get(), sampleTime, size(), m_deviceOrientation);
+ if (!sampleBuffer)
+ return;
// We use m_deviceOrientation to emulate sensor orientation
- dispatchMediaSampleToObservers(MediaSampleAVFObjC::create(sampleBuffer.get(), m_deviceOrientation));
+ dispatchMediaSampleToObservers(*sampleBuffer);
}
-void MockRealtimeVideoSourceMac::settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag> settings)
-{
- if (settings.containsAny({ RealtimeMediaSourceSettings::Flag::Width, RealtimeMediaSourceSettings::Flag::Height }))
- m_bufferPool = nullptr;
- MockRealtimeVideoSource::settingsDidChange(settings);
-}
-
void MockRealtimeVideoSourceMac::orientationChanged(int orientation)
{
// FIXME: Do something with m_deviceOrientation. See bug 169822.
@@ -203,21 +118,6 @@
orientationChanged(notifier.orientation());
}
-void MockRealtimeVideoSourceMac::setSizeAndFrameRateWithPreset(IntSize requestedSize, double, RefPtr<VideoPreset> preset)
-{
- if (!preset)
- return;
-
- if (preset->size != requestedSize) {
- if (m_pixelBufferResizer && !m_pixelBufferResizer->canResizeTo(requestedSize))
- m_pixelBufferResizer = nullptr;
-
- if (!m_pixelBufferResizer)
- m_pixelBufferResizer = std::make_unique<PixelBufferResizer>(requestedSize, preferedPixelBufferFormat());
- } else
- m_pixelBufferResizer = nullptr;
-}
-
} // namespace WebCore
#endif // ENABLE(MEDIA_STREAM)
Modified: trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -56,7 +56,7 @@
void frameAvailable(CGDisplayStreamFrameStatus, uint64_t, IOSurfaceRef, CGDisplayStreamUpdateRef);
- RetainPtr<CVPixelBufferRef> generateFrame() final;
+ DisplayCaptureSourceCocoa::DisplayFrameType generateFrame() final;
RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const final { return RealtimeMediaSourceSettings::DisplaySurfaceType::Monitor; }
void startProducingData() final;
Modified: trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm 2018-10-17 21:55:36 UTC (rev 237236)
@@ -36,6 +36,7 @@
#include "NotImplemented.h"
#include "PlatformLayer.h"
#include "RealtimeMediaSourceSettings.h"
+#include "RealtimeVideoUtilities.h"
#include "CoreVideoSoftLink.h"
@@ -166,7 +167,7 @@
});
auto size = frameSize();
- m_displayStream = adoptCF(CGDisplayStreamCreateWithDispatchQueue(m_displayID, size.width(), size.height(), kCVPixelFormatType_420YpCbCr8Planar, streamOptions.get(), m_captureQueue.get(), m_frameAvailableBlock));
+ m_displayStream = adoptCF(CGDisplayStreamCreateWithDispatchQueue(m_displayID, size.width(), size.height(), preferedPixelBufferFormat(), streamOptions.get(), m_captureQueue.get(), m_frameAvailableBlock));
if (!m_displayStream) {
RELEASE_LOG(Media, "ScreenDisplayCaptureSourceMac::createDisplayStream: CGDisplayStreamCreate failed");
captureFailed();
@@ -205,11 +206,8 @@
m_isRunning = false;
}
-RetainPtr<CVPixelBufferRef> ScreenDisplayCaptureSourceMac::generateFrame()
+DisplayCaptureSourceCocoa::DisplayFrameType ScreenDisplayCaptureSourceMac::generateFrame()
{
- if (!m_currentFrame.ioSurface())
- return nullptr;
-
DisplaySurface currentFrame;
{
LockHolder lock(m_currentFrameMutex);
@@ -216,7 +214,7 @@
currentFrame = m_currentFrame.ioSurface();
}
- return pixelBufferFromIOSurface(currentFrame.ioSurface());
+ return DisplayCaptureSourceCocoa::DisplayFrameType { RetainPtr<IOSurfaceRef> { currentFrame.ioSurface() } };
}
void ScreenDisplayCaptureSourceMac::startDisplayStream()
Modified: trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCaptureSourceMac.h (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCaptureSourceMac.h 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCaptureSourceMac.h 2018-10-17 21:55:36 UTC (rev 237236)
@@ -49,11 +49,10 @@
WindowDisplayCaptureSourceMac(uint32_t, String&&);
virtual ~WindowDisplayCaptureSourceMac() = default;
- RetainPtr<CVPixelBufferRef> generateFrame() final;
+ DisplayCaptureSourceCocoa::DisplayFrameType generateFrame() final;
RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const final { return RealtimeMediaSourceSettings::DisplaySurfaceType::Window; }
RetainPtr<CGImageRef> windowImage();
- RetainPtr<CVPixelBufferRef> pixelBufferFromCGImage(CGImageRef);
IntSize m_windowSize;
CGWindowID m_windowID { 0 };
Modified: trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCaptureSourceMac.mm (237235 => 237236)
--- trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCaptureSourceMac.mm 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCaptureSourceMac.mm 2018-10-17 21:55:36 UTC (rev 237236)
@@ -139,71 +139,11 @@
return image;
}
-RetainPtr<CVPixelBufferRef> WindowDisplayCaptureSourceMac::generateFrame()
+DisplayCaptureSourceCocoa::DisplayFrameType WindowDisplayCaptureSourceMac::generateFrame()
{
- auto image = windowImage();
- if (!image)
- return nullptr;
-
- if (m_lastImage && m_lastPixelBuffer && CFEqual(m_lastImage.get(), image.get()))
- return m_lastPixelBuffer.get();
-
- m_lastImage = WTFMove(image);
- return pixelBufferFromCGImage(m_lastImage.get());
+ return DisplayCaptureSourceCocoa::DisplayFrameType { RetainPtr<CGImageRef> { windowImage() } };
}
-RetainPtr<CVPixelBufferRef> WindowDisplayCaptureSourceMac::pixelBufferFromCGImage(CGImageRef image)
-{
- static CGColorSpaceRef sRGBColorSpace = sRGBColorSpaceRef();
-
- auto imageSize = IntSize(CGImageGetWidth(image), CGImageGetHeight(image));
- if (imageSize != intrinsicSize()) {
- m_bufferPool = nullptr;
- m_lastImage = nullptr;
- m_lastPixelBuffer = nullptr;
- }
-
- if (!m_bufferPool) {
- CVPixelBufferPoolRef bufferPool;
- CFDictionaryRef sourcePixelBufferOptions = (__bridge CFDictionaryRef) @{
- (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32ARGB),
- (__bridge NSString *)kCVPixelBufferWidthKey : @(imageSize.width()),
- (__bridge NSString *)kCVPixelBufferHeightKey : @(imageSize.height()),
-#if PLATFORM(IOS)
- (__bridge NSString *)kCVPixelFormatOpenGLESCompatibility : @(YES),
-#else
- (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @(YES),
-#endif
- (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ /*empty dictionary*/ }
- };
-
- CFDictionaryRef pixelBufferPoolOptions = (__bridge CFDictionaryRef) @{
- (__bridge NSString *)kCVPixelBufferPoolMinimumBufferCountKey : @(3)
- };
-
- CVReturn status = CVPixelBufferPoolCreate(kCFAllocatorDefault, pixelBufferPoolOptions, sourcePixelBufferOptions, &bufferPool);
- if (status != kCVReturnSuccess)
- return nullptr;
-
- m_bufferPool = adoptCF(bufferPool);
- setIntrinsicSize(imageSize);
- }
-
- CVPixelBufferRef pixelBuffer;
- CVReturn status = CVPixelBufferPoolCreatePixelBuffer(nullptr, m_bufferPool.get(), &pixelBuffer);
- if (status != kCVReturnSuccess)
- return nullptr;
-
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
- void* data = ""
- auto context = adoptCF(CGBitmapContextCreate(data, imageSize.width(), imageSize.height(), 8, CVPixelBufferGetBytesPerRow(pixelBuffer), sRGBColorSpace, (CGBitmapInfo) kCGImageAlphaNoneSkipFirst));
- CGContextDrawImage(context.get(), CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image);
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
-
- m_lastPixelBuffer = adoptCF(pixelBuffer);
- return m_lastPixelBuffer;
-}
-
std::optional<CaptureDevice> WindowDisplayCaptureSourceMac::windowCaptureDeviceWithPersistentID(const String& idString)
{
bool ok;
Modified: trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp (237235 => 237236)
--- trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp 2018-10-17 21:09:40 UTC (rev 237235)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp 2018-10-17 21:55:36 UTC (rev 237236)
@@ -126,6 +126,7 @@
capabilities.addFacingMode(WTF::get<MockCameraProperties>(m_device.properties).facingMode);
capabilities.setDeviceId(hashedId());
updateCapabilities(capabilities);
+ capabilities.setDeviceId(hashedId());
} else {
capabilities.setWidth(CapabilityValueOrRange(72, 2880));
capabilities.setHeight(CapabilityValueOrRange(45, 1800));
@@ -159,14 +160,14 @@
settings.setAspectRatio(aspectRatio());
RealtimeMediaSourceSupportedConstraints supportedConstraints;
- supportedConstraints.setSupportsDeviceId(true);
supportedConstraints.setSupportsFrameRate(true);
supportedConstraints.setSupportsWidth(true);
supportedConstraints.setSupportsHeight(true);
supportedConstraints.setSupportsAspectRatio(true);
- if (mockCamera())
+ if (mockCamera()) {
+ supportedConstraints.setSupportsDeviceId(true);
supportedConstraints.setSupportsFacingMode(true);
- else {
+ } else {
supportedConstraints.setSupportsDisplaySurface(true);
supportedConstraints.setSupportsLogicalSurface(true);
}