Video frame resizing should be using Trim
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 May 2019 17:43:19 +0000 (17:43 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 May 2019 17:43:19 +0000 (17:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197722
<rdar://problem/50602188>

Reviewed by Eric Carlson.

Source/WebCore:

Move from letter box to trim mode for resizing.
This ensures no black stripes are present when rendering the stream.

Test: fast/mediastream/resize-trim.html

* platform/cocoa/VideoToolboxSoftLink.cpp:
* platform/cocoa/VideoToolboxSoftLink.h:
* platform/graphics/cv/ImageTransferSessionVT.mm:
(WebCore::ImageTransferSessionVT::ImageTransferSessionVT):

LayoutTests:

* fast/mediastream/resize-trim-expected.txt: Renamed from LayoutTests/fast/mediastream/resize-letterbox-expected.txt.
* fast/mediastream/resize-trim.html: Renamed from LayoutTests/fast/mediastream/resize-letterbox.html.
* platform/gtk/TestExpectations:

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

LayoutTests/ChangeLog
LayoutTests/fast/mediastream/resize-trim-expected.txt [moved from LayoutTests/fast/mediastream/resize-letterbox-expected.txt with 100% similarity]
LayoutTests/fast/mediastream/resize-trim.html [moved from LayoutTests/fast/mediastream/resize-letterbox.html with 50% similarity]
LayoutTests/platform/gtk/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/cocoa/VideoToolboxSoftLink.cpp
Source/WebCore/platform/cocoa/VideoToolboxSoftLink.h
Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm

index 452ebf2..309e7b3 100644 (file)
@@ -1,3 +1,15 @@
+2019-05-14  Youenn Fablet  <youenn@apple.com>
+
+        Video frame resizing should be using Trim
+        https://bugs.webkit.org/show_bug.cgi?id=197722
+        <rdar://problem/50602188>
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/resize-trim-expected.txt: Renamed from LayoutTests/fast/mediastream/resize-letterbox-expected.txt.
+        * fast/mediastream/resize-trim.html: Renamed from LayoutTests/fast/mediastream/resize-letterbox.html.
+        * platform/gtk/TestExpectations:
+
 2019-05-14  Antoine Quint  <graouts@apple.com>
 
         [Pointer Events] The pointerenter and pointerleave events target the wrong element on iOS
@@ -7,46 +7,11 @@
         <script src="../../resources/testharnessreport.js"></script>
         <script>
 
-const canvas = document.getElementById("canvas");
-const video = document.getElementById("video");
-
-function isPixelBlack(pixel)
-{
-    return pixel[0] === 0 && pixel[1] === 0 && pixel[2] === 0 && pixel[3] === 255;
-}
-
 function isPixelGray(pixel)
 {
     return pixel[0] === 128 && pixel[1] === 128 && pixel[2] === 128 && pixel[3] === 255;
 }
 
-function logPixel(name, pixel)
-{
-    console.log(`${name}: ${pixel[0]}, ${pixel[1]}, ${pixel[2]}, ${pixel[3]}`);
-}
-
-function checkCanvas(canvas, stream)
-{
-    return new Promise((resolve, reject) => {
-        video.srcObject = stream;
-        video.onplay = () => {
-            const ctx = canvas.getContext("2d");
-            ctx.drawImage(video, 0 ,0);
-
-            try {
-                setTimeout(() => {
-                    assert_true(isPixelBlack(ctx.getImageData(5, 5, 1, 1).data), "Pixel at 5x5 is NOT from camera.");
-                    assert_true(isPixelGray(ctx.getImageData(50, 200, 1, 1).data), "Pixel at 50x200 is from camera.");
-                    resolve();
-                }, 500);
-            } catch(err) {
-                reject(err);
-                return;
-            }
-        }
-    });
-}
-
 promise_test(async () => {
     let stream = await navigator.mediaDevices.getUserMedia({ video: true });
     stream = null;
@@ -57,9 +22,14 @@ promise_test(async () => {
     assert_true(cameraID !== undefined, "Found camera2");
     
     stream = await navigator.mediaDevices.getUserMedia({ video: { deviceId: { exact: cameraID }, width: 480, height: 480 } });
+    video.srcObject = stream;
+    await video.play();
     
-    return checkCanvas(canvas, stream);
+    const ctx = canvas.getContext("2d");
+    ctx.drawImage(video, 0 ,0);
 
+    assert_true(isPixelGray(ctx.getImageData(5, 5, 1, 1).data), "Pixel at 5x5 is not black.");
+    assert_true(isPixelGray(ctx.getImageData(10, 200, 1, 1).data), "Pixel at 10x200 is not black.");
 }, "Video frames are resized in letterbox-mode when captured at non-native size.");
 
         </script>
index 4fcdaee..334e851 100644 (file)
@@ -3709,7 +3709,7 @@ webkit.org/b/192883 fast/cookies/cookie-averse-document.html [ Failure ]
 webkit.org/b/192883 fast/cookies/local-file-can-set-cookies.html [ Failure ]
 
 webkit.org/b/192886 fast/mediastream/media-stream-renders-first-frame.html [ Failure ]
-webkit.org/b/192888 fast/mediastream/resize-letterbox.html [ Failure ]
+webkit.org/b/192888 fast/mediastream/resize-trim.html [ Failure ]
 
 webkit.org/b/192900 imported/w3c/web-platform-tests/eventsource/format-mime-bogus.htm [ Failure ]
 
index 767f327..53df7a7 100644 (file)
@@ -1,3 +1,21 @@
+2019-05-14  Youenn Fablet  <youenn@apple.com>
+
+        Video frame resizing should be using Trim
+        https://bugs.webkit.org/show_bug.cgi?id=197722
+        <rdar://problem/50602188>
+
+        Reviewed by Eric Carlson.
+
+        Move from letter box to trim mode for resizing.
+        This ensures no black stripes are present when rendering the stream.
+
+        Test: fast/mediastream/resize-trim.html
+
+        * platform/cocoa/VideoToolboxSoftLink.cpp:
+        * platform/cocoa/VideoToolboxSoftLink.h:
+        * platform/graphics/cv/ImageTransferSessionVT.mm:
+        (WebCore::ImageTransferSessionVT::ImageTransferSessionVT):
+
 2019-05-14  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] Shrink sizeof(UnlinkedFunctionExecutable) more
index 5971d39..1d56365 100644 (file)
@@ -64,6 +64,7 @@ SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, VideoToolbox, VTPixelTransferSessionTrans
 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_Letterbox, 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)
index ac49247..f156547 100644 (file)
@@ -91,6 +91,8 @@ SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, VideoToolbox, kVTPixelTransferPropertyKey
 #define kVTPixelTransferPropertyKey_ScalingMode get_VideoToolbox_kVTPixelTransferPropertyKey_ScalingMode()
 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, VideoToolbox, kVTScalingMode_Letterbox, CFStringRef)
 #define kVTScalingMode_Letterbox get_VideoToolbox_kVTScalingMode_Letterbox()
+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)
index 9c21be7..24aa48c 100644 (file)
@@ -59,7 +59,7 @@ ImageTransferSessionVT::ImageTransferSessionVT(uint32_t pixelFormat)
     ASSERT(transferSession);
     m_transferSession = adoptCF(transferSession);
 
-    auto status = VTSessionSetProperty(transferSession, kVTPixelTransferPropertyKey_ScalingMode, kVTScalingMode_Letterbox);
+    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));