fix(app): reject stale window frames before encoder reconfiguration

This commit is contained in:
AAA committed 2026-10-19 23:15:32 +08:00
1 parent e06a065c82
commit 392c1ff352
6 files changed
+34 -26

No files matched your search

+11
View File
@@ -293,6 +293,17 @@ reproduce the new v2.0.0 `app/capture/failed` report. That key reports a failed
Native source lifetime; the App's capture-process and share-ended diagnostics
are needed to identify which capture, codec or stream operation failed.
The 2026-10-19 window gate exposed a different restoration failure: WGC queued
a minimized 146x21 placeholder after the target had returned to 1251x1365.
Clearing the pool once still admitted it and H.264 rejected the resulting
encoder size. Frame admission now compares the
[rendered content size](https://learn.microsoft.com/en-us/uwp/api/windows.graphics.capture.direct3d11captureframe.contentsize)
with the [current target size](https://learn.microsoft.com/en-us/uwp/api/windows.graphics.capture.graphicscaptureitem.size)
before reconfiguring the pool or encoder, replacing the one-shot restoration
flag. The Auto/H.264 window gate then passed restoration, profile changes,
resizing, source replacement and source-exit recovery on the same media object.
This local reproduction does not identify the unmatched game/driver reports.
## Keyframe Request Ownership
A direct Native source delivers a requested physical output through its
+10 -13
View File
@@ -1989,10 +1989,7 @@ void RunVideoCapture(ProductArguments arguments) {
const HANDLE window_waits[] = {
process.get(), shutdown->get(), frame_ready->get()};
const HANDLE display_waits[] = {shutdown->get(), frame_ready->get()};
bool source_was_minimized = false;
for (;;) {
if (window_target && IsIconic(reinterpret_cast<HWND>(
static_cast<UINT_PTR>(arguments.source_id)))) source_was_minimized = true;
for (const auto& control : controls.Read()) {
if (control.kind == 'Q') {
cleanup();
@@ -2044,21 +2041,12 @@ void RunVideoCapture(ProductArguments arguments) {
latest = std::move(next);
}
if (!latest) continue;
// Minimized content is a placeholder, including queued frames after
// restoration. Retire that pool generation before admitting pictures.
// A minimized window has no capturable picture.
if (window_target && IsIconic(reinterpret_cast<HWND>(
static_cast<UINT_PTR>(arguments.source_id)))) {
source_was_minimized = true;
latest.Close();
continue;
}
if (source_was_minimized) {
latest.Close();
latest = nullptr;
pool.Recreate(capture_device, static_cast<DirectXPixelFormat>(pool_format), 2, pool_size);
source_was_minimized = false;
continue;
}
INT64 signed_timestamp = latest.SystemRelativeTime().count();
if (signed_timestamp <= 0) {
Fail("capture-timestamp", "captured frame has no QPC timestamp");
@@ -2072,6 +2060,15 @@ void RunVideoCapture(ProductArguments arguments) {
}
auto content_size = latest.ContentSize();
if (content_size.Width <= 0 || content_size.Height <= 0) continue;
// ContentSize belongs to the rendered frame; Size belongs to the current
// target. Queued minimize/resize frames must not reconfigure the encoder
// after the target has already changed again.
const auto target_size = item.Size();
if (content_size.Width != target_size.Width ||
content_size.Height != target_size.Height) {
latest.Close();
continue;
}
const auto color = display_color.Resolve();
if (content_size.Width != pool_size.Width ||
content_size.Height != pool_size.Height || color.Format() != pool_format) {
+7 -3
View File
@@ -781,6 +781,9 @@ async function main(): Promise<void> {
`document.querySelector('button[aria-controls="host-advanced-door"]')?.click()`,
Date.now() + 5_000,
);
await clickHostControl(cdp, host,
`document.querySelector('#host-advanced-door .lr-sharing-picture-details > summary')`,
);
result.preSharePreferenceEnabled = await waitForValue(
(deadline) => evaluate<boolean>(
cdp!,
@@ -799,10 +802,8 @@ async function main(): Promise<void> {
// ceilings. Native capture no longer pads/upscales every source to 16:9.
await clickHostControl(cdp, host, `document.querySelector('button.lr-chip[aria-label="1440p"]')`);
await clickHostControl(cdp, host, `document.querySelector('button[name="degradationPreference"][value="maintain-resolution"]')`);
await clickHostControl(cdp, host, `document.querySelector('.lr-sharing-technical > summary')`);
await clickHostControl(cdp, host,
`([...document.querySelectorAll('button.lr-chip')].find((button) =>
button.textContent?.trim() === ${JSON.stringify(requestedCodec.toUpperCase())}))`,
`document.querySelector('button[name="videoCodec"][value="${requestedCodec}"]')`,
);
await evaluate<void>(
cdp,
@@ -972,6 +973,9 @@ async function main(): Promise<void> {
result.livePresetChanges += 1;
}
stage = "native-quality-controls";
await clickHostControl(cdp, host,
`document.querySelector('#host-advanced-door .lr-sharing-picture-details > summary')`,
);
await waitForValue(
(deadline) => evaluate<boolean>(
cdp!,
+4 -8
View File
@@ -2545,15 +2545,13 @@ async function startHost(
5_000, "sharing settings", signal);
if (codecMode !== "auto") {
await evaluate(cdp, page, `(() => {
const technical = document.querySelector('#host-advanced-door .lr-sharing-technical');
if (technical instanceof HTMLDetailsElement && !technical.open) technical.querySelector('summary')?.click();
const picture = document.querySelector('#host-advanced-door .lr-sharing-picture-details');
if (picture instanceof HTMLDetailsElement && !picture.open) picture.querySelector('summary')?.click();
})()`);
await waitForPage(
cdp,
page,
`Array.from(document.querySelectorAll('#host-advanced-door button')).some(
(button) => button instanceof HTMLButtonElement && button.getAttribute('aria-label')?.startsWith('${codecMode.toUpperCase()}')
)`,
`document.querySelector('#host-advanced-door button[name="videoCodec"][value="${codecMode}"]') instanceof HTMLButtonElement`,
5_000,
`${codecMode} codec control`,
signal,
@@ -2562,9 +2560,7 @@ async function startHost(
cdp,
page,
`(() => {
const button = Array.from(document.querySelectorAll('#host-advanced-door button')).find(
(candidate) => candidate instanceof HTMLButtonElement && candidate.getAttribute('aria-label')?.startsWith('${codecMode.toUpperCase()}')
);
const button = document.querySelector('#host-advanced-door button[name="videoCodec"][value="${codecMode}"]');
if (!(button instanceof HTMLButtonElement)) throw new Error('Codec mode button missing');
button.click();
return true;
+1 -1
View File
@@ -158,7 +158,7 @@ export function ControlsPreview() {
<div className="lr-door-group">
<span className="lr-door-glyph"><Glyph name="puzzle" size={19} /><span>{vis ? null : t("host.advanced.codec")}</span></span>
<div className="lr-row-group" role="group" aria-label={t("host.advanced.codec")}>
{(["vp8", "auto", "h264"] as const).map(mode => <Chip key={mode} selected={mode === "auto"} disabled
{(["vp8", "auto", "h264"] as const).map(mode => <Chip key={mode} name="videoCodec" value={mode} selected={mode === "auto"} disabled
title={mode === "auto" ? t("host.advanced.codec.auto") : mode.toUpperCase()} hint="hint-codec">
{mode === "auto" && !vis ? t("host.advanced.codec.auto") : mode.toUpperCase()}
</Chip>)}
+1 -1
View File
@@ -3904,7 +3904,7 @@ export function HostPage({
<span className="lr-door-glyph"><Glyph name="puzzle" size={19} /><Cap k="host.advanced.codec" /></span>
<div className="lr-row-group" role="group" aria-label={t("host.advanced.codec")}>
{(["vp8", "auto", "h264"] as const).map(mode => (
<Chip key={mode} selected={displayedVideoCodecMode === mode}
<Chip key={mode} name="videoCodec" value={mode} selected={displayedVideoCodecMode === mode}
disabled={phase === "starting" || phase === "live"}
title={mode === "auto"
? resolvedVideoCodec