Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

6.2 KB
Raw Blame

Windows Capture Process

This isolated Windows process provides native capture for Piik App. It 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. A replacement process applies live changes while the Go session retains 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. It captures all output devices except the selected process tree, and retires when that process exits. The screen-audio contract 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. The App consumes the selected process or system-audio stream through its native media edge when the capability probe reports support. Build to the stable project build/go-check directory for a bounded capability run:

npm run check:native

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 -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 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. 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.