Title: [246049] trunk
Revision
246049
Author
[email protected]
Date
2019-06-03 14:07:45 -0700 (Mon, 03 Jun 2019)

Log Message

Allow resizing of camera video feeds to very small resolutions
https://bugs.webkit.org/show_bug.cgi?id=198421

Reviewed by Alex Christensen.

Source/WebCore:

Before the patch, the minimum capture resolution was set to 120.
Since this is a bit arbitrary and there are some use cases for lower resolution,
We now allow down to 1x1 resolution.

Test: fast/mediastream/getUserMedia-video-rescaling.html

* platform/mediastream/RealtimeVideoSource.cpp:
(WebCore::RealtimeVideoSource::updateCapabilities):
Allow 1x1 when computing min/max resolutions.
(WebCore::RealtimeVideoSource::bestSupportedSizeAndFrameRate):
In case width and height are provided, we pick the closest preset that matches and resize accordingly.
If width or height is provided, we pick the closest preset tat matches and applies its aspect ratio.

LayoutTests:

Update tests to expect 1x1 minimum capture resolution.

* fast/mediastream/MediaStreamTrack-getCapabilities-expected.txt:
* fast/mediastream/apply-constraints-video-expected.txt:
* fast/mediastream/apply-constraints-video.html:
* fast/mediastream/get-user-media-constraints-expected.txt:
* fast/mediastream/getUserMedia-video-rescaling-expected.txt: Added.
* fast/mediastream/getUserMedia-video-rescaling.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (246048 => 246049)


--- trunk/LayoutTests/ChangeLog	2019-06-03 21:07:06 UTC (rev 246048)
+++ trunk/LayoutTests/ChangeLog	2019-06-03 21:07:45 UTC (rev 246049)
@@ -1,3 +1,19 @@
+2019-06-03  Youenn Fablet  <[email protected]>
+
+        Allow resizing of camera video feeds to very small resolutions
+        https://bugs.webkit.org/show_bug.cgi?id=198421
+
+        Reviewed by Alex Christensen.
+
+        Update tests to expect 1x1 minimum capture resolution.
+
+        * fast/mediastream/MediaStreamTrack-getCapabilities-expected.txt:
+        * fast/mediastream/apply-constraints-video-expected.txt:
+        * fast/mediastream/apply-constraints-video.html:
+        * fast/mediastream/get-user-media-constraints-expected.txt:
+        * fast/mediastream/getUserMedia-video-rescaling-expected.txt: Added.
+        * fast/mediastream/getUserMedia-video-rescaling.html: Added.
+
 2019-06-03  Devin Rousso  <[email protected]>
 
         Web Inspector: remove RemoteObject.prototype.getPropertyDescriptorsAsObject

Modified: trunk/LayoutTests/fast/mediastream/MediaStreamTrack-getCapabilities-expected.txt (246048 => 246049)


--- trunk/LayoutTests/fast/mediastream/MediaStreamTrack-getCapabilities-expected.txt	2019-06-03 21:07:06 UTC (rev 246048)
+++ trunk/LayoutTests/fast/mediastream/MediaStreamTrack-getCapabilities-expected.txt	2019-06-03 21:07:45 UTC (rev 246049)
@@ -8,8 +8,8 @@
   capabilities.deviceId = <UUID>
   capabilities.facingMode = [ user ]
   capabilities.frameRate = { max: 30, min: 5 }
-  capabilities.height = { max: 720, min: 112 }
-  capabilities.width = { max: 1280, min: 112 }
+  capabilities.height = { max: 720, min: 1 }
+  capabilities.width = { max: 1280, min: 1 }
 
 audio track capabilities:
   capabilities.deviceId = <UUID>

Modified: trunk/LayoutTests/fast/mediastream/apply-constraints-video-expected.txt (246048 => 246049)


--- trunk/LayoutTests/fast/mediastream/apply-constraints-video-expected.txt	2019-06-03 21:07:06 UTC (rev 246048)
+++ trunk/LayoutTests/fast/mediastream/apply-constraints-video-expected.txt	2019-06-03 21:07:45 UTC (rev 246049)
@@ -52,14 +52,14 @@
 ** Constraint: {"width":5000} - ideal width is greater than track capability, should be clamped to the maximum value.
 PASS settings['width'] is 1280
 
-** Constraint: {"width":100,"height":100,"frameRate":4} - all values are less than track capabilities, should be clamped to the minimum values.
-PASS settings['width'] is 112
-PASS settings['height'] is 112
+** Constraint: {"width":100,"height":100,"frameRate":4} - frameRate value is less than track capabilities, should be clamped to the minimum values.
+PASS settings['width'] is 100
+PASS settings['height'] is 100
 PASS settings['frameRate'] is 5
 
 ** Constraint: {"frameRate":20} - set frame rate, width and height should remain unchanged
-PASS settings['width'] is 112
-PASS settings['height'] is 112
+PASS settings['width'] is 100
+PASS settings['height'] is 100
 PASS settings['frameRate'] is 20
 
 ** Constraint: {"facingMode":"xnvironment","height":720} - illegal facing mode value should be ignored, height should change.

Modified: trunk/LayoutTests/fast/mediastream/apply-constraints-video.html (246048 => 246049)


--- trunk/LayoutTests/fast/mediastream/apply-constraints-video.html	2019-06-03 21:07:06 UTC (rev 246048)
+++ trunk/LayoutTests/fast/mediastream/apply-constraints-video.html	2019-06-03 21:07:45 UTC (rev 246049)
@@ -55,14 +55,14 @@
                     expected: { width: 1280},
                 },
                 {
-                    message: "all values are less than track capabilities, should be clamped to the minimum values.",
+                    message: "frameRate value is less than track capabilities, should be clamped to the minimum values.",
                     constraint: { width: 100, height: 100, frameRate: 4 },
-                    expected: { width: 112, height: 112, frameRate: 5 },
+                    expected: { width: 100, height: 100, frameRate: 5 },
                 },
                 {
                     message: "set frame rate, width and height should remain unchanged",
-                    constraint: { frameRate: 20 }, 
-                    expected: { width: 112, height: 112, frameRate: 20 },
+                    constraint: { frameRate: 20 },
+                    expected: { width: 100, height: 100, frameRate: 20 },
                 },
                 {
                     message: "illegal facing mode value should be ignored, height should change.",

Modified: trunk/LayoutTests/fast/mediastream/get-user-media-constraints-expected.txt (246048 => 246049)


--- trunk/LayoutTests/fast/mediastream/get-user-media-constraints-expected.txt	2019-06-03 21:07:06 UTC (rev 246048)
+++ trunk/LayoutTests/fast/mediastream/get-user-media-constraints-expected.txt	2019-06-03 21:07:45 UTC (rev 246049)
@@ -1,4 +1,4 @@
 
 
-FAIL Ideal deviceId constraints promise_test: Unhandled rejection with value: object "Error: Invalid constraint"
+PASS Ideal deviceId constraints 
 

Added: trunk/LayoutTests/fast/mediastream/getUserMedia-video-rescaling-expected.txt (0 => 246049)


--- trunk/LayoutTests/fast/mediastream/getUserMedia-video-rescaling-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/getUserMedia-video-rescaling-expected.txt	2019-06-03 21:07:45 UTC (rev 246049)
@@ -0,0 +1,6 @@
+
+
+PASS wdith 100 height 100 video 
+PASS width 100 video 
+PASS height 100 video  
+

Added: trunk/LayoutTests/fast/mediastream/getUserMedia-video-rescaling.html (0 => 246049)


--- trunk/LayoutTests/fast/mediastream/getUserMedia-video-rescaling.html	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/getUserMedia-video-rescaling.html	2019-06-03 21:07:45 UTC (rev 246049)
@@ -0,0 +1,43 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing video capture resizing</title>
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <video id="video" autoplay=""></video>
+        <script>
+promise_test(async (test) => {
+    const localStream = await navigator.mediaDevices.getUserMedia({video: { width : { exact : 100 }, height : { exact : 100 }, facingMode: "environment" } });
+
+    video.srcObject = localStream;
+    await video.play();
+
+    assert_equals(video.videoWidth, 100, "width");
+    assert_equals(video.videoHeight, 100, "height");
+}, "wdith 100 height 100 video");
+
+promise_test(async (test) => {
+    const localStream = await navigator.mediaDevices.getUserMedia({video: { width : { exact : 100 }, facingMode: "environment" } });
+
+    video.srcObject = localStream;
+    await video.play();
+
+    assert_equals(video.videoWidth, 100, "width");
+    assert_equals(video.videoHeight, 75, "height");
+}, "width 100 video");
+
+promise_test(async (test) => {
+    const localStream = await navigator.mediaDevices.getUserMedia({video: { height : { exact : 100 }, facingMode: "environment" } });
+
+    video.srcObject = localStream;
+    await video.play();
+
+    assert_equals(video.videoWidth, 133, "width");
+    assert_equals(video.videoHeight, 100, "height");
+}, "height 100 video ");
+        </script>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (246048 => 246049)


--- trunk/Source/WebCore/ChangeLog	2019-06-03 21:07:06 UTC (rev 246048)
+++ trunk/Source/WebCore/ChangeLog	2019-06-03 21:07:45 UTC (rev 246049)
@@ -1,3 +1,23 @@
+2019-06-03  Youenn Fablet  <[email protected]>
+
+        Allow resizing of camera video feeds to very small resolutions
+        https://bugs.webkit.org/show_bug.cgi?id=198421
+
+        Reviewed by Alex Christensen.
+
+        Before the patch, the minimum capture resolution was set to 120.
+        Since this is a bit arbitrary and there are some use cases for lower resolution,
+        We now allow down to 1x1 resolution.
+
+        Test: fast/mediastream/getUserMedia-video-rescaling.html
+
+        * platform/mediastream/RealtimeVideoSource.cpp:
+        (WebCore::RealtimeVideoSource::updateCapabilities):
+        Allow 1x1 when computing min/max resolutions.
+        (WebCore::RealtimeVideoSource::bestSupportedSizeAndFrameRate):
+        In case width and height are provided, we pick the closest preset that matches and resize accordingly.
+        If width or height is provided, we pick the closest preset tat matches and applies its aspect ratio.
+
 2019-06-03  Wenson Hsieh  <[email protected]>
 
         Implement an internal switch to turn idempotent text autosizing and viewport rules off

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp (246048 => 246049)


--- trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp	2019-06-03 21:07:06 UTC (rev 246048)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp	2019-06-03 21:07:45 UTC (rev 246049)
@@ -177,12 +177,11 @@
     }
 
     if (canResizeVideoFrames()) {
+        minimumWidth = 1;
+        minimumHeight = 1;
         for (auto& size : standardVideoSizes()) {
-            if (size.width() < minimumWidth || size.height() < minimumHeight) {
-                minimumWidth = std::min(minimumWidth, size.width());
-                minimumHeight = std::min(minimumHeight, size.height());
+            if (size.width() < minimumWidth || size.height() < minimumHeight)
                 minimumAspectRatio = std::min(minimumAspectRatio, static_cast<double>(size.width()) / size.height());
-            }
         }
     }
 
@@ -307,13 +306,13 @@
         if (exactSizePreset || aspectRatioPreset)
             continue;
 
+        if ((requestedWidth && requestedWidth.value() > preset->size.width()) || (requestedHeight && requestedHeight.value() > preset->size.height()))
+            continue;
+
         if (requestedWidth && requestedHeight) {
-            const auto& minStandardSize = standardVideoSizes()[0];
-            if (requestedWidth.value() >= minStandardSize.width() && requestedHeight.value() >= minStandardSize.height()) {
-                if (!resizePreset || shouldUsePreset(*resizePreset, preset)) {
-                    resizePreset = &preset.get();
-                    resizeSize = { requestedWidth.value(), requestedHeight.value() };
-                }
+            if (!resizePreset || shouldUsePreset(*resizePreset, preset)) {
+                resizePreset = &preset.get();
+                resizeSize = { requestedWidth.value(), requestedHeight.value() };
             }
         } else {
             for (auto& standardSize : standardVideoSizes()) {
@@ -327,6 +326,14 @@
                     resizeSize = standardSize;
                 }
             }
+
+            if (!resizePreset || shouldUsePreset(*resizePreset, preset)) {
+                resizePreset = &preset.get();
+                if (requestedWidth)
+                    resizeSize = { requestedWidth.value(), requestedWidth.value() * preset->size.height() / preset->size.width()};
+                else
+                    resizeSize = { requestedHeight.value() * preset->size.width() / preset->size.height(), requestedHeight.value() };
+            }
         }
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to