MockRealtimeVideoSourceMac should produce kCVPixelFormatType_420YpCbCr8Planar buffers
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Apr 2018 17:34:04 +0000 (17:34 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Apr 2018 17:34:04 +0000 (17:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184304

Reviewed by Eric Carlson.

Allows covering RealtimeOutgoingVideoSourceMac code path handling native buffers produced by capture video sources.
ARGB buffer coverage is done through canvas capture streams.

* platform/mediastream/mac/MockRealtimeVideoSourceMac.h:
* platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
(WebCore::MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230262 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h
Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm

index 53e8183..b16aef1 100644 (file)
@@ -1,5 +1,19 @@
 2018-04-04  Youenn Fablet  <youenn@apple.com>
 
+        MockRealtimeVideoSourceMac should produce kCVPixelFormatType_420YpCbCr8Planar buffers
+        https://bugs.webkit.org/show_bug.cgi?id=184304
+
+        Reviewed by Eric Carlson.
+
+        Allows covering RealtimeOutgoingVideoSourceMac code path handling native buffers produced by capture video sources.
+        ARGB buffer coverage is done through canvas capture streams.
+
+        * platform/mediastream/mac/MockRealtimeVideoSourceMac.h:
+        * platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
+        (WebCore::MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer):
+
+2018-04-04  Youenn Fablet  <youenn@apple.com>
+
         Introduce a ThreadSafeRefCounted parameter to ensure being destroyed on the main thread
         https://bugs.webkit.org/show_bug.cgi?id=183988
 
index 065904a..68e6765 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "MockRealtimeVideoSource.h"
 #include "OrientationNotifier.h"
+#include "PixelBufferConformerCV.h"
 
 typedef struct __CVBuffer *CVBufferRef;
 typedef CVBufferRef CVImageBufferRef;
@@ -64,6 +65,7 @@ private:
     mutable RetainPtr<PlatformLayer> m_previewLayer;
     mutable RetainPtr<CVPixelBufferPoolRef> m_bufferPool;
     MediaSample::VideoRotation m_deviceOrientation { MediaSample::VideoRotation::None };
+    std::unique_ptr<PixelBufferConformerCV> m_pixelBufferConformer;
 };
 
 } // namespace WebCore
index 8a63fd3..272e668 100644 (file)
@@ -68,21 +68,26 @@ MockRealtimeVideoSourceMac::MockRealtimeVideoSourceMac(const String& deviceID, c
 
 RetainPtr<CMSampleBufferRef> MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer(CVPixelBufferRef pixelBuffer)
 {
-        if (!pixelBuffer)
+    if (!pixelBuffer)
         return nullptr;
 
+    if (!m_pixelBufferConformer)
+        m_pixelBufferConformer = std::make_unique<PixelBufferConformerCV>((CFDictionaryRef)@{ (NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_420YpCbCr8Planar) });
+
+    auto convertedPixelBuffer = m_pixelBufferConformer->convert(pixelBuffer);
+
     CMTime sampleTime = CMTimeMake(((elapsedTime() + 100_ms) * videoSampleRate).seconds(), videoSampleRate);
     CMSampleTimingInfo timingInfo = { kCMTimeInvalid, sampleTime, sampleTime };
 
     CMVideoFormatDescriptionRef formatDescription = nullptr;
-    OSStatus status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, &formatDescription);
+    OSStatus status = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)convertedPixelBuffer, &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);
+    status = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)convertedPixelBuffer, formatDescription, &timingInfo, &sampleBuffer);
     CFRelease(formatDescription);
     if (status != noErr) {
         LOG_ERROR("Failed to initialize CMSampleBuffer with error code: %d", status);