Skip to content

Commit

Permalink
RemoteRealtimeMediaSourceProxy should use latest successful constrain…
Browse files Browse the repository at this point in the history
…ts when creating the remote source

https://bugs.webkit.org/show_bug.cgi?id=265232
rdar://118708700

Reviewed by Eric Carlson and Jean-Yves Avenard.

In case of GPUProcess crash, we are recreating a remote source by calling RemoteRealtimeMediaSourceProxy::createRemoteMediaSource.
createRemoteMediaSource is currently using the constraints used initially (via getUserMedia).
But it should in fact use the last successful constraints applied to the previous remote source (via applyConstraints).
Update the code accordingly and update API test to cover that case.

Canonical link: https://commits.webkit.org/271074@main
  • Loading branch information
youennf committed Nov 23, 2023
1 parent e7ce012 commit 6abef00
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void RemoteRealtimeMediaSourceProxy::createRemoteCloneSource(WebCore::RealtimeMe

void RemoteRealtimeMediaSourceProxy::applyConstraints(const MediaConstraints& constraints, RealtimeMediaSource::ApplyConstraintsHandler&& completionHandler)
{
m_pendingApplyConstraintsCallbacks.append(WTFMove(completionHandler));
m_pendingApplyConstraintsRequests.append(std::make_pair(WTFMove(completionHandler), constraints));
// FIXME: Use sendAsyncWithReply.
m_connection->send(Messages::UserMediaCaptureManagerProxy::ApplyConstraints { m_identifier, constraints }, 0);
}
Expand Down Expand Up @@ -140,21 +140,22 @@ Ref<WebCore::RealtimeMediaSource::PhotoSettingsNativePromise> RemoteRealtimeMedi

void RemoteRealtimeMediaSourceProxy::applyConstraintsSucceeded()
{
auto callback = m_pendingApplyConstraintsCallbacks.takeFirst();
callback({ });
auto request = m_pendingApplyConstraintsRequests.takeFirst();
m_constraints = WTFMove(request.second);
request.first({ });
}

void RemoteRealtimeMediaSourceProxy::applyConstraintsFailed(String&& failedConstraint, String&& errorMessage)
{
auto callback = m_pendingApplyConstraintsCallbacks.takeFirst();
auto callback = m_pendingApplyConstraintsRequests.takeFirst().first;
callback(RealtimeMediaSource::ApplyConstraintsError { WTFMove(failedConstraint), WTFMove(errorMessage) });
}

void RemoteRealtimeMediaSourceProxy::failApplyConstraintCallbacks(const String& errorMessage)
{
auto callbacks = WTFMove(m_pendingApplyConstraintsCallbacks);
while (!callbacks.isEmpty())
callbacks.takeFirst()(RealtimeMediaSource::ApplyConstraintsError { { }, errorMessage });
auto requests = WTFMove(m_pendingApplyConstraintsRequests);
while (!requests.isEmpty())
requests.takeFirst().first(RealtimeMediaSource::ApplyConstraintsError { { }, errorMessage });
}

void RemoteRealtimeMediaSourceProxy::end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RemoteRealtimeMediaSourceProxy {
bool m_shouldCaptureInGPUProcess { false };

WebCore::MediaConstraints m_constraints;
Deque<WebCore::RealtimeMediaSource::ApplyConstraintsHandler> m_pendingApplyConstraintsCallbacks;
Deque<std::pair<WebCore::RealtimeMediaSource::ApplyConstraintsHandler, WebCore::MediaConstraints>> m_pendingApplyConstraintsRequests;
bool m_isReady { false };
CompletionHandler<void(WebCore::CaptureSourceError&&)> m_callback;
WebCore::CaptureSourceError m_failureReason;
Expand Down
4 changes: 4 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKit/GetUserMedia.mm
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,10 @@ bool waitUntilMicrophoneState(WKWebView *webView, WKMediaCaptureState expectedSt
[webView stringByEvaluatingJavaScript:@"changeConstraints()"];
TestWebKitAPI::Util::run(&done);

done = false;
[webView stringByEvaluatingJavaScript:@"applyBadConstraintsToAudio()"];
TestWebKitAPI::Util::run(&done);

auto webViewPID = [webView _webProcessIdentifier];

// The GPU process should get launched.
Expand Down
11 changes: 11 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKit/getUserMedia.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@
});
}

function applyBadConstraintsToAudio() {
async function doApplyBadConstraintsToAudio() {
const audioTrack = stream.getAudioTracks()[0];
await audioTrack.applyConstraints({ echoCancellation: false, sampleRate: { exact: 10 } });
}
doApplyBadConstraintsToAudio().then(() => {
window.webkit.messageHandlers.gum.postMessage("FAIL applyBadConstraintsToAudio succeeded");
}, (e) => {
window.webkit.messageHandlers.gum.postMessage("PASS");
});
}

function captureOrientation() {
let settings = stream.getVideoTracks()[0].getSettings();
Expand Down

0 comments on commit 6abef00

Please sign in to comment.