Title: [293885] trunk/Source
Revision
293885
Author
[email protected]
Date
2022-05-06 01:44:54 -0700 (Fri, 06 May 2022)

Log Message

Remove usage of PixelBufferConformer in RealtimeOutgoingVideoSourceCocoa
https://bugs.webkit.org/show_bug.cgi?id=240118

Reviewed by Eric Carlson.

Source/ThirdParty/libwebrtc:

Add a routine to convert RGB CVPixelBuffer to YUV webrtc VideoFrameBuffer.

* Configurations/libwebrtc.iOS.exp:
* Configurations/libwebrtc.iOSsim.exp:
* Configurations/libwebrtc.mac.exp:
* Source/webrtc/sdk/WebKit/WebKitUtilities.h:
* Source/webrtc/sdk/WebKit/WebKitUtilities.mm:
(webrtc::convertBGRAToYUV):

Source/WebCore:

Remove RealtimeOutgoingVideoSourceCocoa::convertToYUV, instead use libyuv based converter routine.
Covered by existing canvas -> peer connection tests.

* platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp:
* platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h:
* platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm:

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/libwebrtc/ChangeLog (293884 => 293885)


--- trunk/Source/ThirdParty/libwebrtc/ChangeLog	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/ThirdParty/libwebrtc/ChangeLog	2022-05-06 08:44:54 UTC (rev 293885)
@@ -1,3 +1,19 @@
+2022-05-06  Youenn Fablet  <[email protected]>
+
+        Remove usage of PixelBufferConformer in RealtimeOutgoingVideoSourceCocoa
+        https://bugs.webkit.org/show_bug.cgi?id=240118
+
+        Reviewed by Eric Carlson.
+
+        Add a routine to convert RGB CVPixelBuffer to YUV webrtc VideoFrameBuffer.
+
+        * Configurations/libwebrtc.iOS.exp:
+        * Configurations/libwebrtc.iOSsim.exp:
+        * Configurations/libwebrtc.mac.exp:
+        * Source/webrtc/sdk/WebKit/WebKitUtilities.h:
+        * Source/webrtc/sdk/WebKit/WebKitUtilities.mm:
+        (webrtc::convertBGRAToYUV):
+
 2022-04-30  Jer Noble  <[email protected]>
 
         [Mac] VTVideoDecoderClass object pointers can become unaligned on x86

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp (293884 => 293885)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp	2022-05-06 08:44:54 UTC (rev 293885)
@@ -337,3 +337,4 @@
 __ZN6webrtc32createPixelBufferFromFrameBufferERNS_16VideoFrameBufferERKNSt3__18functionIFP10__CVBuffermmNS_10BufferTypeEEEE
 __ZN6webrtc25CreateTaskQueueGcdFactoryEv
 __ZN6webrtc27CreatePeerConnectionFactoryEPN3rtc6ThreadES2_S2_NS0_13scoped_refptrINS_17AudioDeviceModuleEEENS3_INS_19AudioEncoderFactoryEEENS3_INS_19AudioDecoderFactoryEEENSt3__110unique_ptrINS_19VideoEncoderFactoryENSA_14default_deleteISC_EEEENSB_INS_19VideoDecoderFactoryENSD_ISG_EEEENS3_INS_10AudioMixerEEENS3_INS_15AudioProcessingEEEPNS_19AudioFrameProcessorENSB_INS_16TaskQueueFactoryENSD_ISP_EEEE
+__ZN6webrtc16convertBGRAToYUVEP10__CVBufferS1_

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp (293884 => 293885)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp	2022-05-06 08:44:54 UTC (rev 293885)
@@ -337,3 +337,4 @@
 __ZN6webrtc32createPixelBufferFromFrameBufferERNS_16VideoFrameBufferERKNSt3__18functionIFP10__CVBuffermmNS_10BufferTypeEEEE
 __ZN6webrtc25CreateTaskQueueGcdFactoryEv
 __ZN6webrtc27CreatePeerConnectionFactoryEPN3rtc6ThreadES2_S2_NS0_13scoped_refptrINS_17AudioDeviceModuleEEENS3_INS_19AudioEncoderFactoryEEENS3_INS_19AudioDecoderFactoryEEENSt3__110unique_ptrINS_19VideoEncoderFactoryENSA_14default_deleteISC_EEEENSB_INS_19VideoDecoderFactoryENSD_ISG_EEEENS3_INS_10AudioMixerEEENS3_INS_15AudioProcessingEEEPNS_19AudioFrameProcessorENSB_INS_16TaskQueueFactoryENSD_ISP_EEEE
+__ZN6webrtc16convertBGRAToYUVEP10__CVBufferS1_

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp (293884 => 293885)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp	2022-05-06 08:44:54 UTC (rev 293885)
@@ -337,3 +337,4 @@
 __ZN6webrtc32createPixelBufferFromFrameBufferERNS_16VideoFrameBufferERKNSt3__18functionIFP10__CVBuffermmNS_10BufferTypeEEEE
 __ZN6webrtc25CreateTaskQueueGcdFactoryEv
 __ZN6webrtc27CreatePeerConnectionFactoryEPN3rtc6ThreadES2_S2_NS0_13scoped_refptrINS_17AudioDeviceModuleEEENS3_INS_19AudioEncoderFactoryEEENS3_INS_19AudioDecoderFactoryEEENSt3__110unique_ptrINS_19VideoEncoderFactoryENSA_14default_deleteISC_EEEENSB_INS_19VideoDecoderFactoryENSD_ISG_EEEENS3_INS_10AudioMixerEEENS3_INS_15AudioProcessingEEEPNS_19AudioFrameProcessorENSB_INS_16TaskQueueFactoryENSD_ISP_EEEE
+__ZN6webrtc16convertBGRAToYUVEP10__CVBufferS1_

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.h (293884 => 293885)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.h	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.h	2022-05-06 08:44:54 UTC (rev 293885)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "api/video/video_frame_buffer.h"
+#include "api/video/video_rotation.h"
 #include "api/scoped_refptr.h"
 #include <CoreFoundation/CFBase.h>
 #include <functional>
@@ -55,6 +56,8 @@
 
 typedef CVPixelBufferRef (*GetBufferCallback)(void*);
 typedef void (*ReleaseBufferCallback)(void*);
-rtc::scoped_refptr<webrtc::VideoFrameBuffer> toWebRTCVideoFrameBuffer(void*, GetBufferCallback, ReleaseBufferCallback, int width, int height);
+rtc::scoped_refptr<VideoFrameBuffer> toWebRTCVideoFrameBuffer(void*, GetBufferCallback, ReleaseBufferCallback, int width, int height);
 void* videoFrameBufferProvider(const VideoFrame&);
+
+bool convertBGRAToYUV(CVPixelBufferRef sourceBuffer, CVPixelBufferRef destinationBuffer);
 }

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.mm (293884 => 293885)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.mm	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.mm	2022-05-06 08:44:54 UTC (rev 293885)
@@ -25,6 +25,7 @@
 
 #include "WebKitUtilities.h"
 
+#include "api/video/i420_buffer.h"
 #include "api/video/video_frame.h"
 #include "native/src/objc_frame_buffer.h"
 #include "rtc_base/logging.h"
@@ -240,4 +241,36 @@
     return false;
 }
 
+bool convertBGRAToYUV(CVPixelBufferRef sourceBuffer, CVPixelBufferRef destinationBuffer)
+{
+    int width = CVPixelBufferGetWidth(sourceBuffer);
+    int height = CVPixelBufferGetHeight(sourceBuffer);
+
+    CVPixelBufferLockBaseAddress(destinationBuffer, 0);
+    CVPixelBufferLockBaseAddress(sourceBuffer, kCVPixelBufferLock_ReadOnly);
+
+    auto* destinationY = static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(destinationBuffer, 0));
+    auto* destinationUV = static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(destinationBuffer, 1));
+    uint32_t bytesPerRowDestinationY = CVPixelBufferGetBytesPerRowOfPlane(destinationBuffer, 0);
+    uint32_t bytesPerRowDestinationUV = CVPixelBufferGetBytesPerRowOfPlane(destinationBuffer, 1);
+
+    auto result = libyuv::ARGBToNV12(
+        static_cast<uint8_t*>(CVPixelBufferGetBaseAddress(sourceBuffer)),
+        CVPixelBufferGetBytesPerRow(sourceBuffer),
+        destinationY,
+        bytesPerRowDestinationY,
+        destinationUV,
+        bytesPerRowDestinationUV,
+        width,
+        height);
+
+    CVPixelBufferUnlockBaseAddress(sourceBuffer, kCVPixelBufferLock_ReadOnly);
+    CVPixelBufferUnlockBaseAddress(destinationBuffer, 0);
+
+    if (result)
+        return false;
+
+    return true;
 }
+
+}

Modified: trunk/Source/WebCore/ChangeLog (293884 => 293885)


--- trunk/Source/WebCore/ChangeLog	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/WebCore/ChangeLog	2022-05-06 08:44:54 UTC (rev 293885)
@@ -1,3 +1,17 @@
+2022-05-06  Youenn Fablet  <[email protected]>
+
+        Remove usage of PixelBufferConformer in RealtimeOutgoingVideoSourceCocoa
+        https://bugs.webkit.org/show_bug.cgi?id=240118
+
+        Reviewed by Eric Carlson.
+
+        Remove RealtimeOutgoingVideoSourceCocoa::convertToYUV, instead use libyuv based converter routine.
+        Covered by existing canvas -> peer connection tests.
+
+        * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp:
+        * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h:
+        * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm:
+
 2022-05-05  Yusuke Suzuki  <[email protected]>
 
         Make readArrayBufferViewImpl defensive

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp (293884 => 293885)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp	2022-05-06 08:44:54 UTC (rev 293885)
@@ -102,13 +102,31 @@
         }
     }
 
-    auto pixelBuffer = videoFrame.pixelBuffer();
-    auto pixelFormatType = CVPixelBufferGetPixelFormatType(pixelBuffer);
+    auto pixelFormat = videoFrame.pixelFormat();
+    if (pixelFormat == kCVPixelFormatType_32BGRA) {
+        auto size = videoFrame.presentationSize();
+        auto pixelBufferPool = this->pixelBufferPool(size.width(), size.height());
+        if (!pixelBufferPool)
+            return;
+        CVPixelBufferRef newPixelBuffer = nullptr;
+        auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, pixelBufferPool, &newPixelBuffer);
+        if (status != kCVReturnSuccess) {
+            RELEASE_LOG_ERROR(WebRTC, "RealtimeOutgoingVideoSourceCocoa failed creating a pixel buffer with error %d", status);
+            return;
+        }
 
-    RetainPtr<CVPixelBufferRef> convertedBuffer = pixelBuffer;
-    if (pixelFormatType != preferedPixelBufferFormat())
-        convertedBuffer = convertToYUV(pixelBuffer);
+        auto convertedBuffer = adoptCF(newPixelBuffer);
+        ASSERT(!m_currentRotation);
+        if (webrtc::convertBGRAToYUV(videoFrame.pixelBuffer(), convertedBuffer.get()))
+            sendFrame(webrtc::pixelBufferToFrame(convertedBuffer.get()));
+        else
+            RELEASE_LOG_ERROR(WebRTC, "Unable to convert BGRA video frame to YUV");
+        return;
+    }
 
+    // FIXME: For other pixel formats, we should use a pixel conformer.
+    ASSERT(pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange);
+    RetainPtr<CVPixelBufferRef> convertedBuffer = videoFrame.pixelBuffer();
     if (shouldApplyRotation)
         convertedBuffer = rotatePixelBuffer(convertedBuffer.get(), m_currentRotation);
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h (293884 => 293885)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h	2022-05-06 08:44:54 UTC (rev 293885)
@@ -28,9 +28,11 @@
 #if USE(LIBWEBRTC)
 
 #include "RealtimeOutgoingVideoSource.h"
-#include "PixelBufferConformerCV.h"
 #include <webrtc/api/video/video_rotation.h>
 
+using CVPixelBufferPoolRef = struct __CVPixelBufferPool*;
+using CVPixelBufferRef = struct __CVBuffer*;
+
 namespace WebCore {
 
 class ImageRotationSessionVT;
@@ -47,10 +49,9 @@
     // RealtimeMediaSource::VideoFrameObserver API
     void videoFrameAvailable(VideoFrame&, VideoFrameTimeMetadata) final;
 
-    RetainPtr<CVPixelBufferRef> convertToYUV(CVPixelBufferRef);
     RetainPtr<CVPixelBufferRef> rotatePixelBuffer(CVPixelBufferRef, webrtc::VideoRotation);
+    CVPixelBufferPoolRef pixelBufferPool(size_t width, size_t height);
 
-    std::unique_ptr<PixelBufferConformerCV> m_pixelBufferConformer;
     std::unique_ptr<ImageRotationSessionVT> m_rotationSession;
     webrtc::VideoRotation m_currentRotationSessionAngle { webrtc::kVideoRotation_0 };
     size_t m_rotatedWidth { 0 };
@@ -57,6 +58,10 @@
     size_t m_rotatedHeight { 0 };
     OSType m_rotatedFormat;
 
+    RetainPtr<CVPixelBufferPoolRef> m_pixelBufferPool;
+    size_t m_pixelBufferPoolWidth { 0 };
+    size_t m_pixelBufferPoolHeight { 0 };
+
 #if !RELEASE_LOG_DISABLED
     size_t m_numberOfFrames { 0 };
 #endif

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm (293884 => 293885)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm	2022-05-06 08:18:54 UTC (rev 293884)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm	2022-05-06 08:44:54 UTC (rev 293885)
@@ -29,9 +29,9 @@
 #if USE(LIBWEBRTC)
 
 #import "AffineTransform.h"
+#import "CVUtilities.h"
 #import "ImageRotationSessionVT.h"
 #import "Logging.h"
-#import "PixelBufferConformerCV.h"
 #import "RealtimeVideoUtilities.h"
 #import <pal/cf/CoreMediaSoftLink.h>
 #import "CoreVideoSoftLink.h"
@@ -39,17 +39,6 @@
 
 namespace WebCore {
 
-RetainPtr<CVPixelBufferRef> RealtimeOutgoingVideoSourceCocoa::convertToYUV(CVPixelBufferRef pixelBuffer)
-{
-    if (!pixelBuffer)
-        return nullptr;
-
-    if (!m_pixelBufferConformer)
-        m_pixelBufferConformer = makeUnique<PixelBufferConformerCV>((__bridge CFDictionaryRef)@{ (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(preferedPixelBufferFormat()) });
-
-    return m_pixelBufferConformer->convert(pixelBuffer);
-}
-
 static inline unsigned rotationToAngle(webrtc::VideoRotation rotation)
 {
     switch (rotation) {
@@ -86,6 +75,22 @@
     return m_rotationSession->rotate(pixelBuffer);
 }
 
+CVPixelBufferPoolRef RealtimeOutgoingVideoSourceCocoa::pixelBufferPool(size_t width, size_t height)
+{
+    if (!m_pixelBufferPool || m_pixelBufferPoolWidth != width || m_pixelBufferPoolHeight != height) {
+        auto result = createInMemoryCVPixelBufferPool(width, height, preferedPixelBufferFormat());
+        if (!result) {
+            RELEASE_LOG_ERROR(WebRTC, "RealtimeOutgoingVideoSourceCocoa failed creating buffer pool with error %d", result.error());
+            return nullptr;
+        }
+
+        m_pixelBufferPool = WTFMove(*result);
+        m_pixelBufferPoolWidth = width;
+        m_pixelBufferPoolHeight = height;
+    }
+    return m_pixelBufferPool.get();
+}
+
 } // namespace WebCore
 
 #endif // USE(LIBWEBRTC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to