Skip to main content

run_capture

Function run_capture 

Source
pub fn run_capture<F>(
    settings: RustCaptureSettings,
    controls: Arc<Controls>,
    encode_tid_tx: Sender<ThreadId>,
    on_frame: &mut F,
) -> Option<Result<(), String>>
where F: FnMut(Vec<EncodedStripe>),
Expand description

Run the zero-copy X11 capture until controls.stop is set, or report that it cannot start.

None means NvFBC cannot serve this session and nothing was delivered, which is the caller’s signal to run the XShm path instead. Anything else means the capture ran — every frame going from the driver’s video-memory buffer into NVENC without a copy — and carries how it ended.

Each iteration:

  1. Paces to the live target frame rate, which is re-read every tick, so a rate change applies immediately and the loop never runs ahead of the session’s contract.
  2. Applies the cross-thread controls on the thread that owns the sessions: a requested key frame, a rate change, live tunables, a cursor toggle, or a region change (the last two are session parameters, so they restart the capture session in place).
  3. Grabs the next frame, which returns immediately when one is already waiting and otherwise waits for one until the frame deadline.
  4. Follows the geometry: a framebuffer resize restarts the capture session at the new size and reconfigures NVENC in place.
  5. Encodes through the same send / quality / key-frame policy every full-frame encoder obeys, with the driver’s own “this frame is new” report standing in for the damage signal and a hash of the new frame’s bands on the GPU (NvencEncoder::band_hashes) saying how much of it changed, so a blinking caret stays a small change while directly rendered GL, which the X server may not report, reads as the motion it is; and hands the bitstream to the recording sink and the delivery callback.