Title: [291744] trunk/Source/WebCore
Revision
291744
Author
[email protected]
Date
2022-03-23 06:54:42 -0700 (Wed, 23 Mar 2022)

Log Message

VideoFrame does not need to inherit from MediaSample
https://bugs.webkit.org/show_bug.cgi?id=238071

Reviewed by Eric Carlson.

Update MediaSample, MediaSampleAVFObjC and VideoFrame according the separation.
This is a refactoring, covered by existing tests.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/MediaSample.h:
* platform/VideoFrame.cpp:
* platform/VideoFrame.h:
* platform/VideoFrame.mm: Added.
* platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h:
* platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
* platform/graphics/gstreamer/VideoFrameGStreamer.cpp:
* platform/graphics/gstreamer/VideoFrameGStreamer.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291743 => 291744)


--- trunk/Source/WebCore/ChangeLog	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/ChangeLog	2022-03-23 13:54:42 UTC (rev 291744)
@@ -1,3 +1,24 @@
+2022-03-23  Youenn Fablet  <[email protected]>
+
+        VideoFrame does not need to inherit from MediaSample
+        https://bugs.webkit.org/show_bug.cgi?id=238071
+
+        Reviewed by Eric Carlson.
+
+        Update MediaSample, MediaSampleAVFObjC and VideoFrame according the separation.
+        This is a refactoring, covered by existing tests.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/MediaSample.h:
+        * platform/VideoFrame.cpp:
+        * platform/VideoFrame.h:
+        * platform/VideoFrame.mm: Added.
+        * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h:
+        * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
+        * platform/graphics/gstreamer/VideoFrameGStreamer.cpp:
+        * platform/graphics/gstreamer/VideoFrameGStreamer.h:
+
 2022-03-23  Víctor Manuel Jáquez Leal  <[email protected]>
 
         REGRESSION(r291611): Fix GTK/WPE build

Modified: trunk/Source/WebCore/SourcesCocoa.txt (291743 => 291744)


--- trunk/Source/WebCore/SourcesCocoa.txt	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2022-03-23 13:54:42 UTC (rev 291744)
@@ -232,6 +232,7 @@
 page/scrolling/mac/ScrollingTreeMac.mm
 page/scrolling/mac/ScrollingTreeOverflowScrollingNodeMac.mm
 page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm
+platform/VideoFrame.mm
 platform/audio/AudioSession.cpp
 platform/audio/cocoa/AudioDestinationCocoa.cpp
 platform/audio/cocoa/AudioFileReaderCocoa.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (291743 => 291744)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-03-23 13:54:42 UTC (rev 291744)
@@ -1076,6 +1076,7 @@
 		4114FE3225BEBD19009D9F20 /* RTCRtcpParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 4114FE2F25BEBD18009D9F20 /* RTCRtcpParameters.h */; };
 		4123081B138C429700BCCFCA /* WebCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F19B1A08245E5A001E9ABC /* WebCore.framework */; };
 		41230913138C42FF00BCCFCA /* _javascript_Core.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8216299029F4FB501000131 /* _javascript_Core.framework */; };
+		412827B227E4AC3C005ADDE2 /* VideoFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B5A3DAD27ABF8C4006C6F97 /* VideoFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4129C9971F59B963009D7403 /* FetchBodySource.h in Headers */ = {isa = PBXBuildFile; fileRef = 413015D61C7B570400091C6F /* FetchBodySource.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4129C9A91F59C56B009D7403 /* ReadableStreamDefaultController.h in Headers */ = {isa = PBXBuildFile; fileRef = 418C395F1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4129C9AB1F59C573009D7403 /* ReadableStreamSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 418C395B1C8F0A610051C8A3 /* ReadableStreamSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -2421,7 +2422,6 @@
 		7AF9B20F18CFB5F400C64BEF /* JSVTTRegionList.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AF9B20B18CFB5F300C64BEF /* JSVTTRegionList.h */; };
 		7B10339E2549721700C8C1AC /* GraphicsContextGLCV.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B10339D2549720100C8C1AC /* GraphicsContextGLCV.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7B10339F2549721E00C8C1AC /* GraphicsContextGLCVCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B10339C2549720100C8C1AC /* GraphicsContextGLCVCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		7B5A3DAF27ABF8C5006C6F97 /* VideoFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B5A3DAD27ABF8C4006C6F97 /* VideoFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7B6094DD270C44BD0064835C /* ANGLEUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A1625345CB200029D08 /* ANGLEUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7B6DC81925712E9200380C70 /* GraphicsContextGLIOSurfaceSwapChain.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6DC81725712E9200380C70 /* GraphicsContextGLIOSurfaceSwapChain.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7B720B0C2743DBA70008ABED /* GraphicsLayerContentsDisplayDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B720B0A2743DBA60008ABED /* GraphicsLayerContentsDisplayDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -8590,6 +8590,7 @@
 		41209E94216EA69A00A73A12 /* RTCCertificate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCCertificate.cpp; sourceTree = "<group>"; };
 		41209E95216EC34E00A73A12 /* LibWebRTCCertificateGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCCertificateGenerator.h; path = libwebrtc/LibWebRTCCertificateGenerator.h; sourceTree = "<group>"; };
 		41209E96216EC34F00A73A12 /* LibWebRTCCertificateGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCCertificateGenerator.cpp; path = libwebrtc/LibWebRTCCertificateGenerator.cpp; sourceTree = "<group>"; };
+		412827B027E4A9C3005ADDE2 /* VideoFrame.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoFrame.mm; sourceTree = "<group>"; };
 		4129C9801F5861C7009D7403 /* ReadableStreamSink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamSink.h; sourceTree = "<group>"; };
 		4129C9811F5861C7009D7403 /* ReadableStreamSink.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamSink.idl; sourceTree = "<group>"; };
 		4129C9871F58662D009D7403 /* ReadableStreamSink.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStreamSink.cpp; sourceTree = "<group>"; };
@@ -30259,6 +30260,7 @@
 				83C45B8D1DC2B67C008871BA /* ValidationBubble.h */,
 				7B5A3DAB27ABF8C4006C6F97 /* VideoFrame.cpp */,
 				7B5A3DAD27ABF8C4006C6F97 /* VideoFrame.h */,
+				412827B027E4A9C3005ADDE2 /* VideoFrame.mm */,
 				41DEEFB42719BA1900CB8D74 /* VideoFrameMetadata.h */,
 				416049312743B0E700A86FA0 /* VideoFrameTimeMetadata.h */,
 				515F79511CFCA3C700CCED93 /* WebCoreCrossThreadCopier.cpp */,
@@ -37966,7 +37968,7 @@
 				0F1A0C38229A481800D37ADB /* VelocityData.h in Headers */,
 				BCA257151293C010007A263D /* VerticalPositionCache.h in Headers */,
 				CD3EEF3B25799FA1006563BB /* VideoConfiguration.h in Headers */,
-				7B5A3DAF27ABF8C5006C6F97 /* VideoFrame.h in Headers */,
+				412827B227E4AC3C005ADDE2 /* VideoFrame.h in Headers */,
 				7BE37F8727BBB708007A6CD3 /* VideoFrameCV.h in Headers */,
 				41EB797E27C3E45E001C3E3E /* VideoFrameLibWebRTC.h in Headers */,
 				41DEEFB62719BA1A00CB8D74 /* VideoFrameMetadata.h in Headers */,

Modified: trunk/Source/WebCore/platform/MediaSample.h (291743 => 291744)


--- trunk/Source/WebCore/platform/MediaSample.h	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/platform/MediaSample.h	2022-03-23 13:54:42 UTC (rev 291744)
@@ -29,10 +29,10 @@
 #include "FourCC.h"
 #include "PlatformVideoColorSpace.h"
 #include "SharedBuffer.h"
-#include <_javascript_Core/TypedArrays.h>
 #include <functional>
 #include <wtf/EnumTraits.h>
 #include <wtf/MediaTime.h>
+#include <wtf/PrintStream.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/text/AtomString.h>
 
@@ -56,8 +56,7 @@
         MockSampleBoxType,
         CMSampleBufferType,
         GStreamerSampleType,
-        ByteRangeSampleType,
-        VideoFrameType, // FIXME: To be removed when VideoFrame is not MediaSample.
+        ByteRangeSampleType
     } type;
     union {
         const MockSampleBox* mockSampleBox;
@@ -92,8 +91,6 @@
     }
     virtual Ref<MediaSample> createNonDisplayingCopy() const = 0;
 
-    virtual RefPtr<JSC::Uint8ClampedArray> getRGBAImageData() const { return nullptr; }
-
     enum SampleFlags {
         None = 0,
         IsSync = 1 << 0,
@@ -111,20 +108,6 @@
     };
     virtual std::optional<ByteRange> byteRange() const { return std::nullopt; }
 
-    enum class VideoRotation {
-        None = 0,
-        UpsideDown = 180,
-        Right = 90,
-        Left = 270,
-    };
-    virtual VideoRotation rotation() const { return VideoRotation::None; }
-    virtual bool isMirrored() const { return false; }
-    virtual uint32_t pixelFormat() const { return 0; }
-#if PLATFORM(COCOA)
-    virtual CVPixelBufferRef pixelBuffer() const { return nullptr; };
-#endif
-    virtual void setOwnershipIdentity(const ProcessIdentity&) { }
-
     bool isSync() const { return flags() & IsSync; }
     bool isNonDisplaying() const { return flags() & IsNonDisplaying; }
     bool hasAlpha() const { return flags() & HasAlpha; }
@@ -191,7 +174,6 @@
     FloatSize displaySize;
     uint8_t bitDepth { 8 };
     PlatformVideoColorSpace colorSpace;
-    MediaSample::VideoRotation rotation { MediaSample::VideoRotation::None };
 
     RefPtr<SharedBuffer> atomData;
 
@@ -201,7 +183,7 @@
     bool equalTo(const TrackInfo& otherVideoInfo) const final
     {
         auto& other = downcast<const VideoInfo>(otherVideoInfo);
-        return size == other.size && displaySize == other.displaySize && bitDepth == other.bitDepth && colorSpace == other.colorSpace && rotation == other.rotation && ((!atomData && !other.atomData) || (atomData && other.atomData && *atomData == *other.atomData));
+        return size == other.size && displaySize == other.displaySize && bitDepth == other.bitDepth && colorSpace == other.colorSpace && ((!atomData && !other.atomData) || (atomData && other.atomData && *atomData == *other.atomData));
     }
 };
 
@@ -276,16 +258,6 @@
 
 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
-    >;
-};
-
 template<typename Type> struct LogArgument;
 template <>
 struct LogArgument<WebCore::MediaSample> {

Modified: trunk/Source/WebCore/platform/VideoFrame.cpp (291743 => 291744)


--- trunk/Source/WebCore/platform/VideoFrame.cpp	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/platform/VideoFrame.cpp	2022-03-23 13:54:42 UTC (rev 291744)
@@ -26,15 +26,15 @@
 #include "config.h"
 #include "VideoFrame.h"
 
-#if PLATFORM(COCOA)
-#include "VideoFrameCV.h"
+#if ENABLE(VIDEO)
+
+#if USE(GSTREAMER)
+#include "VideoFrameGStreamer.h"
 #endif
 
-#if ENABLE(VIDEO)
-
 namespace WebCore {
 
-VideoFrame::VideoFrame(MediaTime presentationTime, bool isMirrored, VideoRotation rotation)
+VideoFrame::VideoFrame(MediaTime presentationTime, bool isMirrored, Rotation rotation)
     : m_presentationTime(presentationTime)
     , m_isMirrored(isMirrored)
     , m_rotation(rotation)
@@ -41,99 +41,25 @@
 {
 }
 
-VideoFrame::~VideoFrame() = default;
-
-MediaTime VideoFrame::presentationTime() const
+void VideoFrame::initializeCharacteristics(MediaTime presentationTime, bool isMirrored, Rotation rotation)
 {
-    return m_presentationTime;
-}
-
-VideoFrame::Rotation VideoFrame::rotation() const
-{
-    return m_rotation;
-}
-
-bool VideoFrame::isMirrored() const
-{
-    return m_isMirrored;
-}
-
-WebCore::PlatformSample VideoFrame::platformSample() const
-{
-    return { WebCore::PlatformSample::VideoFrameType, { } };
-}
-
-PlatformSample::Type VideoFrame::platformSampleType() const
-{
-    return WebCore::PlatformSample::VideoFrameType;
-}
-
-MediaTime VideoFrame::decodeTime() const
-{
-    ASSERT_NOT_REACHED();
-    return { };
-}
-
-MediaTime VideoFrame::duration() const
-{
-    ASSERT_NOT_REACHED();
-    return { };
-}
-
-AtomString VideoFrame::trackID() const
-{
-    ASSERT_NOT_REACHED();
-    return { };
-}
-
-size_t VideoFrame::sizeInBytes() const
-{
-    ASSERT_NOT_REACHED();
-    return 0;
-}
-
-void VideoFrame::offsetTimestampsBy(const MediaTime&)
-{
-    ASSERT_NOT_REACHED();
-}
-
-void VideoFrame::setTimestamps(const MediaTime&, const MediaTime&)
-{
-    ASSERT_NOT_REACHED();
-}
-
-Ref<WebCore::MediaSample> VideoFrame::createNonDisplayingCopy() const
-{
-    CRASH();
-}
-
-MediaSample::SampleFlags VideoFrame::flags() const
-{
-    return MediaSample::SampleFlags::None;
-}
-
-void VideoFrame::dump(PrintStream&) const
-{
-}
-
-void VideoFrame::initializeCharacteristics(MediaTime presentationTime, bool isMirrored, VideoRotation rotation)
-{
     const_cast<MediaTime&>(m_presentationTime) = presentationTime;
     const_cast<bool&>(m_isMirrored) = isMirrored;
-    const_cast<VideoRotation&>(m_rotation) = rotation;
+    const_cast<Rotation&>(m_rotation) = rotation;
 }
 
-#if PLATFORM(COCOA)
-RefPtr<VideoFrameCV> VideoFrame::asVideoFrameCV()
+#if !PLATFORM(COCOA)
+RefPtr<JSC::Uint8ClampedArray> VideoFrame::getRGBAImageData() const
 {
-    auto buffer = pixelBuffer();
-    if (!buffer)
-        return nullptr;
-
-    return VideoFrameCV::create(presentationTime(), isMirrored(), rotation(), buffer);
+#if USE(GSTREAMER)
+    if (isGStreamer())
+        return static_cast<const VideoFrameGStreamer*>(this)->computeRGBAImageData();
+#endif
+    // FIXME: Add support.
+    return nullptr;
 }
 #endif
 
 }
 
-#endif
+#endif // ENABLE(VIDEO)

Modified: trunk/Source/WebCore/platform/VideoFrame.h (291743 => 291744)


--- trunk/Source/WebCore/platform/VideoFrame.h	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/platform/VideoFrame.h	2022-03-23 13:54:42 UTC (rev 291744)
@@ -27,65 +27,80 @@
 
 #if ENABLE(VIDEO)
 
-#include "MediaSample.h"
+#include "FloatSize.h"
+#include <_javascript_Core/TypedArrays.h>
+#include <wtf/MediaTime.h>
+#include <wtf/ThreadSafeRefCounted.h>
 
+typedef struct __CVBuffer *CVPixelBufferRef;
+
 namespace WebCore {
 
+class ProcessIdentity;
 #if USE(AVFOUNDATION) && PLATFORM(COCOA)
 class VideoFrameCV;
 #endif
 
 // A class representing a video frame from a decoder, capture source, or similar.
-// FIXME: Currently for implementation purposes inherts from MediaSample until capture code
-// stops referring to MediaSample
-class VideoFrame : public MediaSample {
+class VideoFrame : public ThreadSafeRefCounted<VideoFrame> {
 public:
-    WEBCORE_EXPORT ~VideoFrame();
+    virtual ~VideoFrame() = default;
 
-    using Rotation = MediaSample::VideoRotation;
+    enum class Rotation {
+        None = 0,
+        UpsideDown = 180,
+        Right = 90,
+        Left = 270,
+    };
 
-    // WebCore::MediaSample overrides.
-    WEBCORE_EXPORT MediaTime presentationTime() const final;
-    WEBCORE_EXPORT Rotation rotation() const final;
-    WEBCORE_EXPORT bool isMirrored() const final;
-    // FIXME: When VideoFrame is not MediaSample, these will not be needed.
-    WEBCORE_EXPORT WebCore::PlatformSample platformSample() const final;
-    WEBCORE_EXPORT PlatformSample::Type platformSampleType() const final;
+    MediaTime presentationTime() const { return m_presentationTime; }
+    Rotation rotation() const { return m_rotation; }
+    bool isMirrored() const { return m_isMirrored; }
 
+#if PLATFORM(COCOA) && USE(AVFOUNDATION)
+    WEBCORE_EXPORT RefPtr<VideoFrameCV> asVideoFrameCV();
+#endif
+    WEBCORE_EXPORT RefPtr<JSC::Uint8ClampedArray> getRGBAImageData() const;
+
+    virtual FloatSize presentationSize() const = 0;
+    virtual uint32_t pixelFormat() const = 0;
+
     virtual bool isRemoteProxy() const { return false; }
     virtual bool isLibWebRTC() const { return false; }
-#if USE(AVFOUNDATION)
     virtual bool isCV() const { return false; }
+#if USE(GSTREAMER)
+    virtual bool isGStreamer() const { return false; }
+#endif
 #if PLATFORM(COCOA)
-    WEBCORE_EXPORT virtual RefPtr<VideoFrameCV> asVideoFrameCV();
+    virtual CVPixelBufferRef pixelBuffer() const { return nullptr; };
 #endif
-#endif
+    WEBCORE_EXPORT virtual void setOwnershipIdentity(const ProcessIdentity&) { }
 
-    void initializeCharacteristics(MediaTime presentationTime, bool isMirrored, VideoRotation);
+    void initializeCharacteristics(MediaTime presentationTime, bool isMirrored, Rotation);
 
 protected:
-    WEBCORE_EXPORT VideoFrame(MediaTime presentationTime, bool isMirrored, VideoRotation);
+    WEBCORE_EXPORT VideoFrame(MediaTime presentationTime, bool isMirrored, Rotation);
+
+private:
     const MediaTime m_presentationTime;
     const bool m_isMirrored;
-    const VideoRotation m_rotation;
+    const Rotation m_rotation;
+};
 
-private:
-    // FIXME: These are not intended to be used for these objects.
-    // WebCore::MediaSample overrides.
-    WEBCORE_EXPORT MediaTime decodeTime() const final;
-    WEBCORE_EXPORT MediaTime duration() const final;
-    WEBCORE_EXPORT AtomString trackID() const final;
-    WEBCORE_EXPORT size_t sizeInBytes() const final;
-    WEBCORE_EXPORT void offsetTimestampsBy(const MediaTime&) final;
-    WEBCORE_EXPORT void setTimestamps(const MediaTime&, const MediaTime&) final;
-    WEBCORE_EXPORT Ref<WebCore::MediaSample> createNonDisplayingCopy() const final;
-    WEBCORE_EXPORT SampleFlags flags() const final;
-    WEBCORE_EXPORT void dump(PrintStream&) const final;
+}
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::VideoFrame::Rotation> {
+    using values = EnumValues<
+        WebCore::VideoFrame::Rotation,
+        WebCore::VideoFrame::Rotation::None,
+        WebCore::VideoFrame::Rotation::UpsideDown,
+        WebCore::VideoFrame::Rotation::Right,
+        WebCore::VideoFrame::Rotation::Left
+    >;
 };
 
 }
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::VideoFrame)
-    static bool isType(const WebCore::MediaSample& mediaSample) { return mediaSample.platformSampleType() == WebCore::PlatformSample::VideoFrameType; }
-SPECIALIZE_TYPE_TRAITS_END()
-#endif
+#endif // ENABLE(VIDEO)

Added: trunk/Source/WebCore/platform/VideoFrame.mm (0 => 291744)


--- trunk/Source/WebCore/platform/VideoFrame.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/VideoFrame.mm	2022-03-23 13:54:42 UTC (rev 291744)
@@ -0,0 +1,74 @@
+/*
+ * 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 "VideoFrame.h"
+
+#if ENABLE(VIDEO) && PLATFORM(COCOA)
+
+#import "PixelBufferConformerCV.h"
+#include "VideoFrameCV.h"
+#import <_javascript_Core/TypedArrayInlines.h>
+
+#import <pal/cf/CoreMediaSoftLink.h>
+#import "CoreVideoSoftLink.h"
+
+namespace WebCore {
+
+RefPtr<JSC::Uint8ClampedArray> VideoFrame::getRGBAImageData() const
+{
+    PixelBufferConformerCV pixelBufferConformer((__bridge CFDictionaryRef)@{ (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32RGBA) });
+
+    auto pixelBuffer = this->pixelBuffer();
+    auto rgbaPixelBuffer = pixelBufferConformer.convert(pixelBuffer);
+    auto status = CVPixelBufferLockBaseAddress(rgbaPixelBuffer.get(), kCVPixelBufferLock_ReadOnly);
+    ASSERT_UNUSED(status, status == noErr);
+
+    void* data = "" 0);
+    size_t byteLength = CVPixelBufferGetHeight(pixelBuffer) * CVPixelBufferGetWidth(pixelBuffer) * 4;
+    auto result = JSC::Uint8ClampedArray::tryCreate(JSC::ArrayBuffer::create(data, byteLength), 0, byteLength);
+
+    status = CVPixelBufferUnlockBaseAddress(rgbaPixelBuffer.get(), kCVPixelBufferLock_ReadOnly);
+    ASSERT(status == noErr);
+
+    return result;
+}
+
+#if USE(AVFOUNDATION)
+RefPtr<VideoFrameCV> VideoFrame::asVideoFrameCV()
+{
+    if (isCV())
+        return downcast<VideoFrameCV>(this);
+
+    auto buffer = pixelBuffer();
+    if (!buffer)
+        return nullptr;
+    return VideoFrameCV::create(presentationTime(), isMirrored(), rotation(), buffer);
+}
+#endif // USE(AVFOUNDATION)
+
+}
+
+#endif // ENABLE(VIDEO) && PLATFORM(COCOA)

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h (291743 => 291744)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h	2022-03-23 13:54:42 UTC (rev 291744)
@@ -43,10 +43,7 @@
 public:
     static Ref<MediaSampleAVFObjC> create(CMSampleBufferRef sample, uint64_t trackID) { return adoptRef(*new MediaSampleAVFObjC(sample, trackID)); }
     static Ref<MediaSampleAVFObjC> create(CMSampleBufferRef sample, AtomString 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)); }
 
-    WEBCORE_EXPORT RefPtr<JSC::Uint8ClampedArray> getRGBAImageData() const override;
-
     MediaTime presentationTime() const override;
     MediaTime decodeTime() const override;
     MediaTime duration() const override;
@@ -65,12 +62,6 @@
     WEBCORE_EXPORT std::pair<RefPtr<MediaSample>, RefPtr<MediaSample>> divide(const MediaTime& presentationTime, UseEndTime) override;
     WEBCORE_EXPORT Ref<MediaSample> createNonDisplayingCopy() const override;
 
-    VideoRotation rotation() const override { return m_rotation; }
-    bool isMirrored() const override { return m_mirrored; }
-    WEBCORE_EXPORT uint32_t pixelFormat() const final;
-    WEBCORE_EXPORT CVPixelBufferRef pixelBuffer() const final;
-    WEBCORE_EXPORT void setOwnershipIdentity(const ProcessIdentity&) final;
-
     CMSampleBufferRef sampleBuffer() const { return m_sample.get(); }
 
     bool isHomogeneous() const;
@@ -83,20 +74,15 @@
     KeyIDs& keyIDs() { return m_keyIDs; }
 #endif
 
-    // FIXME: To be removed once VideoFrame is not a MediaSample.
-    WEBCORE_EXPORT RefPtr<VideoFrameCV> videoFrame() const;
 protected:
     WEBCORE_EXPORT MediaSampleAVFObjC(RetainPtr<CMSampleBufferRef>&&);
     WEBCORE_EXPORT MediaSampleAVFObjC(CMSampleBufferRef);
     WEBCORE_EXPORT MediaSampleAVFObjC(CMSampleBufferRef, AtomString trackID);
     WEBCORE_EXPORT MediaSampleAVFObjC(CMSampleBufferRef, uint64_t trackID);
-    WEBCORE_EXPORT MediaSampleAVFObjC(CMSampleBufferRef, VideoRotation, bool mirrored);
     WEBCORE_EXPORT virtual ~MediaSampleAVFObjC();
 
     RetainPtr<CMSampleBufferRef> m_sample;
     AtomString m_id;
-    VideoRotation m_rotation { VideoRotation::None };
-    bool m_mirrored { false };
 
 #if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
     Vector<Ref<FragmentedSharedBuffer>> m_keyIDs;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm (291743 => 291744)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm	2022-03-23 13:54:42 UTC (rev 291744)
@@ -66,12 +66,6 @@
     , m_id(AtomString::number(trackID))
 {
 }
-MediaSampleAVFObjC::MediaSampleAVFObjC(CMSampleBufferRef sample, VideoRotation rotation, bool mirrored)
-    : m_sample(sample)
-    , m_rotation(rotation)
-    , m_mirrored(mirrored)
-{
-}
 
 MediaSampleAVFObjC::~MediaSampleAVFObjC() = default;
 
@@ -110,22 +104,6 @@
     return sample;
 }
 
-uint32_t MediaSampleAVFObjC::pixelFormat() const
-{
-    auto pixelBuffer = static_cast<CVPixelBufferRef>(PAL::CMSampleBufferGetImageBuffer(m_sample.get()));
-    return CVPixelBufferGetPixelFormatType(pixelBuffer);
-}
-
-RefPtr<VideoFrameCV> MediaSampleAVFObjC::videoFrame() const
-{
-    if (!m_sample)
-        return nullptr;
-    auto pixelBuffer = static_cast<CVPixelBufferRef>(PAL::CMSampleBufferGetImageBuffer(m_sample.get()));
-    if (!pixelBuffer)
-        return nullptr;
-    return VideoFrameCV::create(presentationTime(), m_mirrored, m_rotation, RetainPtr { pixelBuffer });
-}
-
 static bool isCMSampleBufferAttachmentRandomAccess(CFDictionaryRef attachmentDict)
 {
     return !CFDictionaryContainsKey(attachmentDict, PAL::kCMSampleAttachmentKey_NotSync);
@@ -312,39 +290,6 @@
     return MediaSampleAVFObjC::create(adoptCF(newSampleBuffer).get(), m_id);
 }
 
-RefPtr<JSC::Uint8ClampedArray> MediaSampleAVFObjC::getRGBAImageData() const
-{
-    const OSType imageFormat = kCVPixelFormatType_32RGBA;
-    RetainPtr<CFNumberRef> imageFormatNumber = adoptCF(CFNumberCreate(nullptr,  kCFNumberIntType,  &imageFormat));
-
-    RetainPtr<CFMutableDictionaryRef> conformerOptions = adoptCF(CFDictionaryCreateMutable(0, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-    CFDictionarySetValue(conformerOptions.get(), kCVPixelBufferPixelFormatTypeKey, imageFormatNumber.get());
-    PixelBufferConformerCV pixelBufferConformer(conformerOptions.get());
-
-    auto pixelBuffer = static_cast<CVPixelBufferRef>(PAL::CMSampleBufferGetImageBuffer(m_sample.get()));
-    auto rgbaPixelBuffer = pixelBufferConformer.convert(pixelBuffer);
-    auto status = CVPixelBufferLockBaseAddress(rgbaPixelBuffer.get(), kCVPixelBufferLock_ReadOnly);
-    ASSERT_UNUSED(status, status == noErr);
-
-    void* data = "" 0);
-    size_t byteLength = CVPixelBufferGetHeight(pixelBuffer) * CVPixelBufferGetWidth(pixelBuffer) * 4;
-    auto result = JSC::Uint8ClampedArray::tryCreate(JSC::ArrayBuffer::create(data, byteLength), 0, byteLength);
-
-    status = CVPixelBufferUnlockBaseAddress(rgbaPixelBuffer.get(), kCVPixelBufferLock_ReadOnly);
-    ASSERT(status == noErr);
-
-    return result;
-}
-
-static inline void setSampleBufferAsDisplayImmediately(CMSampleBufferRef sampleBuffer)
-{
-    CFArrayRef attachmentsArray = PAL::CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true);
-    for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
-        CFMutableDictionaryRef attachments = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(attachmentsArray, i));
-        CFDictionarySetValue(attachments, PAL::kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
-    }
-}
-
 bool MediaSampleAVFObjC::isHomogeneous() const
 {
     CFArrayRef attachmentsArray = PAL::CMSampleBufferGetSampleAttachmentsArray(m_sample.get(), true);
@@ -415,17 +360,4 @@
     return samples;
 }
 
-CVPixelBufferRef MediaSampleAVFObjC::pixelBuffer() const
-{
-    return static_cast<CVPixelBufferRef>(PAL::CMSampleBufferGetImageBuffer(m_sample.get()));
 }
-
-void MediaSampleAVFObjC::setOwnershipIdentity(const ProcessIdentity& resourceOwner)
-{
-    ASSERT(resourceOwner);
-    auto buffer = pixelBuffer();
-    ASSERT(buffer);
-    setOwnershipIdentityForCVPixelBuffer(buffer, resourceOwner);
-}
-
-}

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp (291743 => 291744)


--- trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp	2022-03-23 13:54:42 UTC (rev 291744)
@@ -104,7 +104,7 @@
 {
 }
 
-RefPtr<JSC::Uint8ClampedArray> VideoFrameGStreamer::getRGBAImageData() const
+RefPtr<JSC::Uint8ClampedArray> VideoFrameGStreamer::computeRGBAImageData() const
 {
     auto* caps = gst_sample_get_caps(m_sample.get());
     GstVideoInfo inputInfo;

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.h (291743 => 291744)


--- trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.h	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.h	2022-03-23 13:54:42 UTC (rev 291744)
@@ -23,7 +23,10 @@
 
 #include "VideoFrame.h"
 #include "VideoFrameMetadataGStreamer.h"
+#include <wtf/glib/GRefPtr.h>
 
+typedef struct _GstSample GstSample;
+
 namespace WebCore {
 
 class PixelBuffer;
@@ -43,6 +46,7 @@
     static Ref<VideoFrameGStreamer> createFromPixelBuffer(PixelBuffer&&, const MediaTime& presentationTime = MediaTime::invalidTime(), const IntSize& destinationSize = { }, double frameRate = 1, Rotation videoRotation = Rotation::None, bool videoMirrored = false, std::optional<VideoFrameTimeMetadata>&& metadata = std::nullopt);
 
     GstSample* sample() const { return m_sample.get(); }
+    RefPtr<JSC::Uint8ClampedArray> computeRGBAImageData() const;
 
 private:
     VideoFrameGStreamer(GRefPtr<GstSample>&&, const FloatSize& presentationSize, const MediaTime& presentationTime = MediaTime::invalidTime(), Rotation = Rotation::None, bool videoMirrored = false, std::optional<VideoFrameTimeMetadata>&& = std::nullopt);
@@ -49,8 +53,8 @@
     VideoFrameGStreamer(const GRefPtr<GstSample>&, const MediaTime& presentationTime, Rotation = Rotation::None);
 
     FloatSize presentationSize() const final { return m_presentationSize; }
-    RefPtr<JSC::Uint8ClampedArray> getRGBAImageData() const final;
     uint32_t pixelFormat() const final { return 0; }
+    bool isGStreamer() const final { return true; }
 
     GRefPtr<GstSample> m_sample;
     FloatSize m_presentationSize;

Modified: trunk/Source/WebCore/platform/mediastream/gstreamer/RealtimeIncomingVideoSourceGStreamer.cpp (291743 => 291744)


--- trunk/Source/WebCore/platform/mediastream/gstreamer/RealtimeIncomingVideoSourceGStreamer.cpp	2022-03-23 13:10:48 UTC (rev 291743)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/RealtimeIncomingVideoSourceGStreamer.cpp	2022-03-23 13:54:42 UTC (rev 291744)
@@ -22,6 +22,7 @@
 #if USE(GSTREAMER_WEBRTC)
 #include "RealtimeIncomingVideoSourceGStreamer.h"
 
+#include "GStreamerCommon.h"
 #include "VideoFrameGStreamer.h"
 #include "VideoFrameMetadataGStreamer.h"
 #include <gst/rtp/rtp.h>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to