Skip to content

Commit a17bc29

Browse files
youennfmnutt
authored andcommitted
Allow mock capture rotation to use the new coordinator code path
https://bugs.webkit.org/show_bug.cgi?id=283569 rdar://problem/140418270 Reviewed by Jean-Yves Avenard. We update mock camera rotation testing to pass the camera ID. This allows to use the rotationAngleForHorizonLevelDisplayChanged code path when the camera ID is given. We update MockRealtimeVideoSource to support this, like done for AVVideoCaptureSource. This allows to write a test for the clone camera track bug https://bugs.webkit.org/show_bug.cgi?id=283480. * LayoutTests/fast/mediastream/video-rotation-clone-expected.txt: Added. * LayoutTests/fast/mediastream/video-rotation-clone.html: Added. * LayoutTests/platform/glib/TestExpectations: * LayoutTests/webrtc/routines.js: * Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp: (WebCore::MockRealtimeVideoSource::rotationAngleForHorizonLevelDisplayChanged): (WebCore::MockRealtimeVideoSource::orientationChanged): * Source/WebCore/platform/mock/MockRealtimeVideoSource.h: * Source/WebCore/testing/Internals.cpp: (WebCore::Internals::mediaStreamTrackPersistentId): * Source/WebCore/testing/Internals.h: * Source/WebCore/testing/Internals.idl: * Source/WebKit/UIProcess/API/C/WKPage.cpp: (WKPageSetMockCameraOrientationForTesting): (WKPageSetMockCameraOrientation): Deleted. * Source/WebKit/UIProcess/API/C/WKPagePrivate.h: * Source/WebKit/UIProcess/Cocoa/UserMediaPermissionRequestManagerProxy.mm: (-[WKRotationCoordinatorObserver isMonitoringCaptureDeviceRotation:]): (WebKit::UserMediaPermissionRequestManagerProxy::isMonitoringCaptureDeviceRotation): * Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h: * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::setMediaCaptureRotationForTesting): * Source/WebKit/UIProcess/WebPageProxy.h: * Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setMockCameraOrientation): * Tools/WebKitTestRunner/InjectedBundle/TestRunner.h: * Tools/WebKitTestRunner/TestController.cpp: (WTR::TestController::resetStateToConsistentValues): (WTR::TestController::setMockCameraOrientation): * Tools/WebKitTestRunner/TestController.h: * Tools/WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): Canonical link: https://commits.webkit.org/287518@main
1 parent 0793fab commit a17bc29

21 files changed

+125
-17
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
PASS Stopping a track clone should not prevent rotation handling
4+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Testing video rotation</title>
6+
<script src="../../resources/testharness.js"></script>
7+
<script src="../../resources/testharnessreport.js"></script>
8+
<script src="../../webrtc/routines.js"></script>
9+
</head>
10+
<body>
11+
<video id=video autoplay playsInline controls></video>
12+
<script>
13+
async function testRotation(testName)
14+
{
15+
if (!window.testRunner)
16+
return;
17+
testRunner.setMockCameraOrientation(90, internals.mediaStreamTrackPersistentId(video.srcObject.getVideoTracks()[0]));
18+
await waitForVideoSize(video, 200, 400, testName + " 90");
19+
20+
testRunner.setMockCameraOrientation(0, internals.mediaStreamTrackPersistentId(video.srcObject.getVideoTracks()[0]));
21+
await waitForVideoSize(video, 400, 200, testName + " 0");
22+
}
23+
24+
promise_test(async() => {
25+
video.srcObject = await navigator.mediaDevices.getUserMedia({video: {width: 400, height: 200} });
26+
await video.play();
27+
28+
const clone = video.srcObject.getVideoTracks()[0].clone();
29+
30+
await testRotation("before clone stopped");
31+
32+
clone.stop();
33+
await new Promise(resolve => setTimeout(resolve, 500));
34+
35+
await testRotation("after clone stopped");
36+
}, "Stopping a track clone should not prevent rotation handling");
37+
</script>
38+
</body>
39+
</html>

LayoutTests/platform/glib/TestExpectations

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,8 @@ fast/mediastream/video-rotation.html [ Skip ]
22292229
webrtc/video-rotation-no-cvo.html [ Failure Timeout ]
22302230
webrtc/video-rotation-black.html [ Crash Failure Pass Timeout ]
22312231

2232+
fast/mediastream/video-rotation-clone.html [ Skip ]
2233+
22322234
# No AudioSession category handling in WPE/GTK ports.
22332235
fast/mediastream/microphone-interruption-and-audio-session.html [ Skip ]
22342236

LayoutTests/webrtc/routines.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function waitFor(duration)
150150
return new Promise((resolve) => setTimeout(resolve, duration));
151151
}
152152

153-
async function waitForVideoSize(video, width, height, count)
153+
async function waitForVideoSize(video, width, height, testName, count)
154154
{
155155
if (video.requestVideoFrameCallback) {
156156
const frameMetadata = await new Promise(resolve => video.requestVideoFrameCallback((now, metadata) => {
@@ -164,11 +164,14 @@ async function waitForVideoSize(video, width, height, count)
164164

165165
if (count === undefined)
166166
count = 0;
167-
if (++count > 20)
168-
return Promise.reject("waitForVideoSize timed out, expected " + width + "x"+ height + " but got " + video.videoWidth + "x" + video.videoHeight);
167+
if (++count > 20) {
168+
if (!testName)
169+
testName = "waitForVideoSize";
170+
return Promise.reject(testName + " timed out, expected " + width + "x"+ height + " but got " + video.videoWidth + "x" + video.videoHeight);
171+
}
169172

170173
await waitFor(100);
171-
return waitForVideoSize(video, width, height, count);
174+
return waitForVideoSize(video, width, height, testName, count);
172175
}
173176

174177
async function doHumAnalysis(stream, expected)

Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,26 @@ bool MockRealtimeVideoSource::mockDisplayType(CaptureDevice::DeviceType type) co
700700
return std::get<MockDisplayProperties>(m_device.properties).type == type;
701701
}
702702

703+
void MockRealtimeVideoSource::rotationAngleForHorizonLevelDisplayChanged(const String& persistentID, VideoFrameRotation rotation)
704+
{
705+
if (this->persistentID() != persistentID) {
706+
ASSERT_NOT_REACHED();
707+
return;
708+
}
709+
710+
m_isUsingRotationAngleForHorizonLevelDisplayChanged = true;
711+
if (rotation == m_deviceOrientation)
712+
return;
713+
714+
m_deviceOrientation = rotation;
715+
notifySettingsDidChangeObservers({ RealtimeMediaSourceSettings::Flag::Width, RealtimeMediaSourceSettings::Flag::Height });
716+
}
717+
703718
void MockRealtimeVideoSource::orientationChanged(IntDegrees orientation)
704719
{
720+
if (m_isUsingRotationAngleForHorizonLevelDisplayChanged)
721+
return;
722+
705723
auto deviceOrientation = m_deviceOrientation;
706724
switch (orientation) {
707725
case 0:

Source/WebCore/platform/mock/MockRealtimeVideoSource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class MockRealtimeVideoSource : public RealtimeVideoCaptureSource, private Orien
9393

9494
// OrientationNotifier::Observer
9595
void orientationChanged(IntDegrees orientation) final;
96+
void rotationAngleForHorizonLevelDisplayChanged(const String&, VideoFrameRotation) final;
9697
void monitorOrientation(OrientationNotifier&) final;
9798

9899
void drawAnimation(GraphicsContext&);
@@ -172,6 +173,7 @@ class MockRealtimeVideoSource : public RealtimeVideoCaptureSource, private Orien
172173
std::optional<PhotoCapabilities> m_photoCapabilities;
173174
std::optional<PhotoSettings> m_photoSettings;
174175
bool m_beingConfigured { false };
176+
bool m_isUsingRotationAngleForHorizonLevelDisplayChanged { false };
175177
};
176178

177179
} // namespace WebCore

Source/WebCore/testing/Internals.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6247,6 +6247,11 @@ void Internals::setMediaStreamSourceInterrupted(MediaStreamTrack& track, bool in
62476247
track.source().setInterruptedForTesting(interrupted);
62486248
}
62496249

6250+
const String& Internals::mediaStreamTrackPersistentId(const MediaStreamTrack& track)
6251+
{
6252+
return track.source().persistentID();
6253+
}
6254+
62506255
bool Internals::isMediaStreamSourceInterrupted(MediaStreamTrack& track) const
62516256
{
62526257
return track.source().interrupted();

Source/WebCore/testing/Internals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ class Internals final
10121012
void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
10131013
void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
10141014
void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
1015+
const String& mediaStreamTrackPersistentId(const MediaStreamTrack&);
10151016
bool isMediaStreamSourceInterrupted(MediaStreamTrack&) const;
10161017
bool isMediaStreamSourceEnded(MediaStreamTrack&) const;
10171018
bool isMockRealtimeMediaSourceCenterEnabled();

Source/WebCore/testing/Internals.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ enum RenderingMode {
11641164
[Conditional=MEDIA_STREAM] boolean isMediaStreamSourceEnded(MediaStreamTrack track);
11651165
[Conditional=MEDIA_STREAM] boolean isMockRealtimeMediaSourceCenterEnabled();
11661166
[Conditional=MEDIA_STREAM] boolean shouldAudioTrackPlay(AudioTrack track);
1167+
[Conditional=MEDIA_STREAM] DOMString mediaStreamTrackPersistentId(MediaStreamTrack track);
11671168

11681169
[Conditional=WEB_RTC] readonly attribute DOMString rtcNetworkInterfaceName;
11691170

Source/WebKit/UIProcess/API/C/WKPage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,10 +3232,10 @@ void WKPageSetPrivateClickMeasurementAppBundleIDForTesting(WKPageRef pageRef, WK
32323232
});
32333233
}
32343234

3235-
void WKPageSetMockCameraOrientation(WKPageRef pageRef, uint64_t orientation)
3235+
void WKPageSetMockCameraOrientationForTesting(WKPageRef pageRef, uint64_t rotation, WKStringRef persistentId)
32363236
{
32373237
CRASH_IF_SUSPENDED;
3238-
toImpl(pageRef)->setOrientationForMediaCapture(orientation);
3238+
toImpl(pageRef)->setMediaCaptureRotationForTesting(rotation, toWTFString(persistentId));
32393239
}
32403240

32413241
bool WKPageIsMockRealtimeMediaSourceCenterEnabled(WKPageRef)

0 commit comments

Comments
 (0)