Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: fdc1fa6d65eadd301ae44497e2dce31645437fe1
https://github.com/WebKit/WebKit/commit/fdc1fa6d65eadd301ae44497e2dce31645437fe1
Author: Ahmad Saleem <[email protected]>
Date: 2026-07-28 (Tue, 28 Jul 2026)
Changed paths:
A
LayoutTests/fast/mediastream/apply-constraints-framerate-range-expected.txt
A LayoutTests/fast/mediastream/apply-constraints-framerate-range.html
M Source/WebCore/platform/mediastream/MediaConstraints.h
M Tools/TestWebKitAPI/CMakeLists.txt
M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
A Tools/TestWebKitAPI/Tests/WebCore/MediaConstraintsTests.cpp
Log Message:
-----------
NumericConstraint::valueForCapabilityRange() ignores a valid current value
when both min and max constraints are set
https://bugs.webkit.org/show_bug.cgi?id=320037
rdar://problem/182968516
Reviewed by Youenn Fablet.
When a numeric constraint (width, height, frameRate, zoom, aspectRatio, ...)
has both min and max set but no ideal, valueForCapabilityRange() first computes
a value that preserves the current setting if it already satisfies the min
constraint, then unconditionally overwrites that value with the max constraint
in the following block. This forces applyConstraints() to jump the setting to
the max bound even when the current value already lies within [min, max],
e.g. applyConstraints({width: {min: 640, max: 1920}}) with a current width of
1280 incorrectly changes width to 1920 instead of leaving it unchanged.
Fix the max block to clamp the already-computed value down to max only when
it exceeds max, instead of always replacing it with the max constraint value.
The same problem also existed when only max is set (no min): the max block
unconditionally set the value to the max constraint, ignoring a current value
that already satisfied it. Apply the same current-preserving fix there. The
min-only case was already correct, since the min block has always preserved
a valid current value independently of the max block.
In the max-only case, only preserve current when it is itself a valid value
for the capability (current >= capabilityMin). Otherwise a sentinel/default
current of 0, such as the RealtimeMediaSource width/height before any frame
has been produced, is always less than a positive max constraint and would be
incorrectly preserved as the resolved value, collapsing width/height to 0.
This was caught by fast/mediastream/getDisplayMedia-max-constraints2.html,
getDisplayMedia-max-constraints4.html, and
getDisplayMedia-max-constraints5.html,
which asserted in RealtimeMediaSource::addVideoFrameObserver() because the
zeroed size threw off UserMediaCaptureManagerProxySourceProxy's observer
bookkeeping. The min-only case does not need the same guard, since a current
of 0 is never greater than a positive min constraint.
* Source/WebCore/platform/mediastream/MediaConstraints.h:
(WebCore::NumericConstraint::valueForCapabilityRange const):
* Tools/TestWebKitAPI/CMakeLists.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebCore/MediaConstraintsTests.cpp: Added.
(TestWebKitAPI::TEST(MediaConstraintsTest,
ValueForCapabilityRangeMinMaxPreservesValidCurrent)):
(TestWebKitAPI::TEST(MediaConstraintsTest,
ValueForCapabilityRangeMinMaxClampsAboveMax)):
(TestWebKitAPI::TEST(MediaConstraintsTest,
ValueForCapabilityRangeMinMaxClampsBelowMin)):
(TestWebKitAPI::TEST(MediaConstraintsTest,
ValueForCapabilityRangeMaxOnlyClampsAboveMax)):
(TestWebKitAPI::TEST(MediaConstraintsTest,
ValueForCapabilityRangeMaxOnlyPreservesValidCurrent)):
(TestWebKitAPI::TEST(MediaConstraintsTest,
ValueForCapabilityRangeMaxOnlyIgnoresCurrentBelowCapabilityMin)):
(TestWebKitAPI::TEST(MediaConstraintsTest,
ValueForCapabilityRangeMinOnlyPreservesValidCurrent)):
(TestWebKitAPI::TEST(MediaConstraintsTest,
ValueForCapabilityRangeMinMaxIdealIsUnaffected)):
* LayoutTests/fast/mediastream/apply-constraints-framerate-range.html: Added.
* LayoutTests/fast/mediastream/apply-constraints-framerate-range-expected.txt:
Added.
Canonical link: https://commits.webkit.org/318046@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications