Files
piik/native/capture/windows/README.md
T

102 lines
6.3 KiB
Markdown

# Windows Capture Process
This retained standalone Windows helper implements the 2.x capture-process
boundary. The current Rust App uses its
[Rust capture owner](../../../prototype/channel-native/src/capture). This helper
enumerates local displays and visible top-level windows, binds each window to
its PID and process creation time, and has independent modes for:
- capability discovery (`--probe`);
- process-tree inclusion/exclusion or default-device loopback PCM
(`--capture-audio`); or
- WGC/D3D11 screen/window video with adapter-bound Media Foundation H.264 or
libvpx VP8 output (`--capture-video --codec auto|h264|vp8`).
- bounded 320x180 BMP source previews (`--preview`), delivered once per target
over the local control connection rather than the media route.
The video command receives the current product resolution, frame-rate, bitrate,
and quality preference. In 2.x, a replacement process applied live changes while
the Go session retained its Pion source and connections.
Sharing and source previews request borderless access by default when Windows
exposes `IsBorderRequired` and `GraphicsCaptureAccess` (build 20348+, including
Windows 11). The probe advertises API availability; the source-picker preference
passes `--show-capture-border` when the Host wants the sharing border visible.
One capture-local owner applies completed access without waiting
for consent, and cancels pending access on retirement. Unsupported APIs, denial
or failure retain ordinary capture; another capture session may still require a
border. The property value is a preference, not proof that the border is invisible.
Consumer Windows 10 through build 19045 lacks this API; the current WGC capture
path keeps its system border there.
Video and audio run as separate bounded child processes. A source whose audio
loopback cannot be initialized keeps video available and reports audio
unavailable instead of failing the whole source. Process loopback is probed by
activation rather than inferred from a Windows build number; display sources
normally use the standard render-device loopback available on Windows 10 and
later. The optional `--capture-audio exclude <pid> <creation-time>` mode requires
a successful exclusion-mode probe, without an additional OS-version gate. Windows 10 isolation still
needs physical verification; see the [audio evidence](../../../docs/research/native-client-media.md#windows-audio-exclusion).
It captures all output devices
except the selected process tree, and retires when that process exits. The
[screen-audio contract](../../../docs/standards/media-quality.md#screen-audio)
owns selection and failure behavior.
Auto measures delivered frame cadence through the target-profile encoding
pipeline within a four-second selection budget; H.264 that sustains the target
needs no software comparison. The selected codec remains fixed across profile
and source changes. VP8 reads the existing
NV12 surface through one staging texture and uses the same encoded-frame
boundary. The process has no network fallback. Build to a stable project directory
for a bounded capability run:
```powershell
powershell -NoProfile -File native/capture/windows/build.ps1 -OutputDirectory build/native-check -Check
```
The checks include synthetic output-worker replacement and failure cases using
WARP and a test codec, plus preview cleanup when WGC rejects a hidden test window.
They do not capture a user screen or validate a physical encoder.
On a Windows machine with a physical D3D11 adapter, check SDR and HDR-to-SDR conversion:
```powershell
powershell -NoProfile -File native/capture/windows/build.ps1 -OutputDirectory build/color-check -CheckColor
```
This sends synthetic RGB, full/limited-range BT.601/BT.709 NV12 and FP16 HDR bars
through the production converters. It checks range/matrix, highlight detail,
SDR/HDR replacement, white-level changes and retained-frame ownership without
capturing the desktop. Decoded H.264/VP8, Browser reception and real HDR displays
remain separate media acceptance; [fidelity research](../../../docs/research/media-fidelity.md)
records current evidence and limits.
The implementation follows Microsoft's MIT-licensed reference samples and
official API contracts without copying their WIL framework. The retained MF
fixture compiles the same encoder source with `PIIK_H264_FIXTURE`; there is
not a second product MFT implementation.
Shared local outputs use stock WebRTC source/encoder adaptation. H264 keeps
native NV12 surfaces, while WebRTC VP8 reads back into I420. The existing capture
and output mailboxes retain source/generation ownership; adapted sizes and
timestamps cross the same media envelope. The encoder requests one temporal
layer where supported and low-latency mode where writable; these optional
properties do not replace the actual output and Auto cadence checks.
VBV sizing stays with the encoder, allowing bitrate increases within the active profile.
The build caches the pinned WebRTC SDK and matching official MSVC linker/runtime
libraries under `build/encoder-pool`. A newer installed MSVC keeps its own linker
and runtime; older installations use that pinned minimum, following
[Microsoft's binary compatibility rule](https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017).
The SDK supplies libvpx, replacing the
separate source build. Only statically linked code and required notices enter
the package, not the SDK/toolchain or another runtime service.
- <https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/ApplicationLoopback>
- <https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/tree/master/cpp/ScreenCaptureforHWND>
- <https://learn.microsoft.com/en-us/windows/win32/api/audioclientactivationparams/ns-audioclientactivationparams-audioclient_activation_params>
- <https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/screen-capture>
- <https://learn.microsoft.com/en-us/windows/win32/api/windows.graphics.capture.interop/nf-windows-graphics-capture-interop-igraphicscaptureiteminterop-createforwindow>
- <https://learn.microsoft.com/en-us/uwp/api/windows.graphics.capture.direct3d11captureframepool.createfreethreaded>
- <https://learn.microsoft.com/en-us/uwp/api/windows.graphics.capture.graphicscapturesession.isborderrequired>
- <https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/97#issuecomment-1015962518>