Skip to content

Commit

Permalink
Navigator.mediaDevices.getSupportedConstraints mistakenly reports tor…
Browse files Browse the repository at this point in the history
…ch as false.

rdar://124372654
https://bugs.webkit.org/show_bug.cgi?id=270779

Reviewed by Eric Carlson.

As per spec, MediaTrackConstraints member must be true if present.
Each individual source may still or may not support a particular constraint.
We remove RealtimeMediaSourceCenter::m_supportedConstraints and instead make all MediaTrackSupportedConstraints members true by default.
Covered by updated tests.

* LayoutTests/fast/mediastream/MediaDevices-getSupportedConstraints-expected.txt:
* LayoutTests/fast/mediastream/MediaDevices-getSupportedConstraints.html:
* LayoutTests/imported/w3c/web-platform-tests/mediacapture-streams/MediaDevices-getSupportedConstraints.https-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/mediacapture-streams/MediaDevices-getUserMedia.https-expected.txt:
* Source/WebCore/Modules/mediastream/MediaDevices.cpp:
(WebCore::MediaDevices::getSupportedConstraints):
* Source/WebCore/Modules/mediastream/MediaTrackSupportedConstraints.h:
* Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp:
(WebCore::RealtimeMediaSourceCenter::RealtimeMediaSourceCenter):
* Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h:

Canonical link: https://commits.webkit.org/275945@main
  • Loading branch information
youennf authored and karlcow committed Mar 12, 2024
1 parent c9e7ab3 commit 8153861
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@ PASS supportedConstraints.deviceId is true
PASS supportedConstraints.echoCancellation is true
PASS supportedConstraints.facingMode is true
PASS supportedConstraints.frameRate is true
PASS supportedConstraints.groupId is false
PASS supportedConstraints.groupId is true
PASS supportedConstraints.height is true
PASS supportedConstraints.sampleRate is false
PASS supportedConstraints.sampleSize is false
PASS supportedConstraints.sampleRate is true
PASS supportedConstraints.sampleSize is true
PASS supportedConstraints.volume is true
PASS supportedConstraints.width is true
PASS supportedConstraints.zoom is true

PASS supportedConstraints["aspectRatio"] is true
PASS supportedConstraints["deviceId"] is true
PASS supportedConstraints["displaySurface"] is true
PASS supportedConstraints["echoCancellation"] is true
PASS supportedConstraints["facingMode"] is true
PASS supportedConstraints["frameRate"] is true
PASS supportedConstraints["groupId"] is true
PASS supportedConstraints["height"] is true
PASS supportedConstraints["sampleRate"] is true
PASS supportedConstraints["sampleSize"] is true
PASS supportedConstraints["torch"] is true
PASS supportedConstraints["volume"] is true
PASS supportedConstraints["whiteBalanceMode"] is true
PASS supportedConstraints["width"] is true
PASS supportedConstraints["zoom"] is true
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
shouldBeTrue("supportedConstraints.echoCancellation");
shouldBeTrue("supportedConstraints.facingMode");
shouldBeTrue("supportedConstraints.frameRate");
shouldBeFalse("supportedConstraints.groupId");
shouldBeTrue("supportedConstraints.groupId");
shouldBeTrue("supportedConstraints.height");
shouldBeFalse("supportedConstraints.sampleRate");
shouldBeFalse("supportedConstraints.sampleSize");
shouldBeTrue("supportedConstraints.sampleRate");
shouldBeTrue("supportedConstraints.sampleSize");
shouldBeTrue("supportedConstraints.volume");
shouldBeTrue("supportedConstraints.width");
shouldBeTrue("supportedConstraints.zoom");
debug("");

for (const key of Object.keys(supportedConstraints))
shouldBeTrue(`supportedConstraints["${key}"]`);

finishJSTest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ PASS aspectRatio is supported
PASS frameRate is supported
PASS facingMode is supported
FAIL resizeMode is supported assert_true: expected true got undefined
FAIL sampleRate is supported assert_true: expected true got false
FAIL sampleSize is supported assert_true: expected true got false
PASS sampleRate is supported
PASS sampleSize is supported
PASS echoCancellation is supported
FAIL autoGainControl is supported assert_true: expected true got undefined
FAIL noiseSuppression is supported assert_true: expected true got undefined
FAIL latency is supported assert_true: expected true got undefined
FAIL channelCount is supported assert_true: expected true got undefined
PASS deviceId is supported
FAIL groupId is supported assert_true: expected true got false
PASS groupId is supported

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This test checks for the presence of the navigator.mediaDevices.getUserMedia met


PASS mediaDevices.getUserMedia() is present on navigator
FAIL groupId is correctly supported by getUserMedia() for video devices assert_true: groupId should be supported expected true got false
FAIL groupId is correctly supported by getUserMedia() for audio devices assert_true: groupId should be supported expected true got false
FAIL groupId is correctly supported by getUserMedia() for video devices assert_equals: expected "groupId" but got ""
FAIL groupId is correctly supported by getUserMedia() for audio devices assert_equals: expected "groupId" but got ""
FAIL getUserMedia() supports setting none as resizeMode. assert_true: resizeMode should be supported expected true got undefined
FAIL getUserMedia() supports setting crop-and-scale as resizeMode. assert_true: resizeMode should be supported expected true got undefined
FAIL getUserMedia() fails with exact invalid resizeMode. assert_true: resizeMode should be supported expected true got undefined
Expand Down
19 changes: 1 addition & 18 deletions Source/WebCore/Modules/mediastream/MediaDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,24 +362,7 @@ void MediaDevices::enumerateDevices(EnumerateDevicesPromise&& promise)

MediaTrackSupportedConstraints MediaDevices::getSupportedConstraints()
{
auto& supported = RealtimeMediaSourceCenter::singleton().supportedConstraints();
MediaTrackSupportedConstraints result;
result.width = supported.supportsWidth();
result.height = supported.supportsHeight();
result.aspectRatio = supported.supportsAspectRatio();
result.frameRate = supported.supportsFrameRate();
result.facingMode = supported.supportsFacingMode();
result.whiteBalanceMode = supported.supportsWhiteBalanceMode();
result.volume = supported.supportsVolume();
result.sampleRate = supported.supportsSampleRate();
result.sampleSize = supported.supportsSampleSize();
result.echoCancellation = supported.supportsEchoCancellation();
result.deviceId = supported.supportsDeviceId();
result.groupId = supported.supportsGroupId();
result.displaySurface = supported.supportsDisplaySurface();
result.zoom = supported.supportsZoom();

return result;
return { };
}

void MediaDevices::scheduledEventTimerFired()
Expand Down
30 changes: 15 additions & 15 deletions Source/WebCore/Modules/mediastream/MediaTrackSupportedConstraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@
namespace WebCore {

struct MediaTrackSupportedConstraints {
bool width;
bool height;
bool aspectRatio;
bool frameRate;
bool facingMode;
bool volume;
bool sampleRate;
bool sampleSize;
bool echoCancellation;
bool deviceId;
bool groupId;
bool displaySurface;
bool whiteBalanceMode;
bool zoom;
bool torch;
bool width { true };
bool height { true };
bool aspectRatio { true };
bool frameRate { true };
bool facingMode { true };
bool volume { true };
bool sampleRate { true };
bool sampleSize { true };
bool echoCancellation { true };
bool deviceId { true };
bool groupId { true };
bool displaySurface { true };
bool whiteBalanceMode { true };
bool zoom { true };
bool torch { true };
};

} // namespace WebCore
Expand Down
13 changes: 0 additions & 13 deletions Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ RealtimeMediaSourceCenter& RealtimeMediaSourceCenter::singleton()
RealtimeMediaSourceCenter::RealtimeMediaSourceCenter()
: m_debounceTimer(RunLoop::main(), this, &RealtimeMediaSourceCenter::triggerDevicesChangedObservers)
{
m_supportedConstraints.setSupportsEchoCancellation(true);
m_supportedConstraints.setSupportsWidth(true);
m_supportedConstraints.setSupportsHeight(true);
m_supportedConstraints.setSupportsAspectRatio(true);
m_supportedConstraints.setSupportsFrameRate(true);
m_supportedConstraints.setSupportsFacingMode(true);
m_supportedConstraints.setSupportsVolume(true);
m_supportedConstraints.setSupportsDeviceId(true);
m_supportedConstraints.setSupportsDisplaySurface(true);

m_supportedConstraints.setSupportsWhiteBalanceMode(true);
m_supportedConstraints.setSupportsZoom(true);
m_supportedConstraints.setSupportsTorch(true);
}

RealtimeMediaSourceCenter::~RealtimeMediaSourceCenter() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "ExceptionOr.h"
#include "MediaStreamRequest.h"
#include "RealtimeMediaSource.h"
#include "RealtimeMediaSourceSupportedConstraints.h"
#include <wtf/Function.h>
#include <wtf/RefPtr.h>
#include <wtf/RunLoop.h>
Expand All @@ -53,7 +52,6 @@ namespace WebCore {
class CaptureDevice;
class CaptureDeviceManager;
class RealtimeMediaSourceSettings;
class RealtimeMediaSourceSupportedConstraints;
class TrackSourceInfo;

struct MediaConstraints;
Expand Down Expand Up @@ -82,8 +80,6 @@ class WEBCORE_EXPORT RealtimeMediaSourceCenter : public ThreadSafeRefCounted<Rea
WEBCORE_EXPORT void getMediaStreamDevices(CompletionHandler<void(Vector<CaptureDevice>&&)>&&);
WEBCORE_EXPORT std::optional<RealtimeMediaSourceCapabilities> getCapabilities(const CaptureDevice&);

const RealtimeMediaSourceSupportedConstraints& supportedConstraints() { return m_supportedConstraints; }

WEBCORE_EXPORT AudioCaptureFactory& audioCaptureFactory();
WEBCORE_EXPORT void setAudioCaptureFactory(AudioCaptureFactory&);
WEBCORE_EXPORT void unsetAudioCaptureFactory(AudioCaptureFactory&);
Expand Down Expand Up @@ -134,8 +130,6 @@ class WEBCORE_EXPORT RealtimeMediaSourceCenter : public ThreadSafeRefCounted<Rea
void validateRequestConstraintsAfterEnumeration(ValidConstraintsHandler&&, InvalidConstraintsHandler&&, const MediaStreamRequest&, MediaDeviceHashSalts&&);
void enumerateDevices(bool shouldEnumerateCamera, bool shouldEnumerateDisplay, bool shouldEnumerateMicrophone, bool shouldEnumerateSpeakers, CompletionHandler<void()>&&);

RealtimeMediaSourceSupportedConstraints m_supportedConstraints;

RunLoop::Timer m_debounceTimer;
void triggerDevicesChangedObservers();

Expand Down

0 comments on commit 8153861

Please sign in to comment.