From 392c1ff3526f2bfe5d68bb5c60ab3d3fa60dbdfb Mon Sep 17 00:00:00 2001 From: AAA <35992542+TNTcraftHIM@users.noreply.github.com> Date: Mon, 19 Oct 2026 23:15:32 +0800 Subject: [PATCH] fix(app): reject stale window frames before encoder reconfiguration --- docs/research/native-client-lifecycle.md | 11 +++++++++++ native/capture/windows/main.cpp | 23 ++++++++++------------- scripts/app-native-host-gate.ts | 10 +++++++--- scripts/peer-assisted-benchmark.ts | 12 ++++-------- src/client/pages/ControlsPreview.tsx | 2 +- src/client/pages/HostPage.tsx | 2 +- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/docs/research/native-client-lifecycle.md b/docs/research/native-client-lifecycle.md index 1689a854a..cfb29dc23 100644 --- a/docs/research/native-client-lifecycle.md +++ b/docs/research/native-client-lifecycle.md @@ -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 diff --git a/native/capture/windows/main.cpp b/native/capture/windows/main.cpp index 446fc175b..3b0e6c357 100644 --- a/native/capture/windows/main.cpp +++ b/native/capture/windows/main.cpp @@ -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( - static_cast(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( static_cast(arguments.source_id)))) { - source_was_minimized = true; latest.Close(); continue; } - if (source_was_minimized) { - latest.Close(); - latest = nullptr; - pool.Recreate(capture_device, static_cast(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) { diff --git a/scripts/app-native-host-gate.ts b/scripts/app-native-host-gate.ts index 68003168c..cce5eb814 100644 --- a/scripts/app-native-host-gate.ts +++ b/scripts/app-native-host-gate.ts @@ -781,6 +781,9 @@ async function main(): Promise { `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( cdp!, @@ -799,10 +802,8 @@ async function main(): Promise { // 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( cdp, @@ -972,6 +973,9 @@ async function main(): Promise { 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( cdp!, diff --git a/scripts/peer-assisted-benchmark.ts b/scripts/peer-assisted-benchmark.ts index 609471c43..737043c6b 100644 --- a/scripts/peer-assisted-benchmark.ts +++ b/scripts/peer-assisted-benchmark.ts @@ -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; diff --git a/src/client/pages/ControlsPreview.tsx b/src/client/pages/ControlsPreview.tsx index 5da4de506..c68d832fa 100644 --- a/src/client/pages/ControlsPreview.tsx +++ b/src/client/pages/ControlsPreview.tsx @@ -158,7 +158,7 @@ export function ControlsPreview() {
{vis ? null : t("host.advanced.codec")}
- {(["vp8", "auto", "h264"] as const).map(mode => {mode === "auto" && !vis ? t("host.advanced.codec.auto") : mode.toUpperCase()} )} diff --git a/src/client/pages/HostPage.tsx b/src/client/pages/HostPage.tsx index cc3d24f5f..0834befcf 100644 --- a/src/client/pages/HostPage.tsx +++ b/src/client/pages/HostPage.tsx @@ -3904,7 +3904,7 @@ export function HostPage({
{(["vp8", "auto", "h264"] as const).map(mode => ( -