capture

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package capture defines the screen capture contract shared by the platform backends: DXGI Desktop Duplication on Windows, ScreenCaptureKit on macOS, and PipeWire or KMS on Linux.

Index

Constants

View Source
const (
	FourccNV12     uint32 = 'N' | 'V'<<8 | '1'<<16 | '2'<<24
	FourccP010     uint32 = 'P' | '0'<<8 | '1'<<16 | '0'<<24
	FourccXRGB8888 uint32 = 'X' | 'R'<<8 | '2'<<16 | '4'<<24
	FourccARGB8888 uint32 = 'A' | 'R'<<8 | '2'<<16 | '4'<<24
	FourccXBGR8888 uint32 = 'X' | 'B'<<8 | '2'<<16 | '4'<<24
	FourccABGR8888 uint32 = 'A' | 'B'<<8 | '2'<<16 | '4'<<24
)

DRM fourcc codes (drm_fourcc.h) of the layouts DMABuf carries.

View Source
const (
	ModifierLinear  uint64 = 0
	ModifierInvalid uint64 = 1<<56 - 1
)

ModifierLinear is DRM_FORMAT_MOD_LINEAR; ModifierInvalid says the producer gave none, and the importer picks the driver's implicit one.

Variables

View Source
var ErrAccessLost = errors.New("capture: access lost")

ErrAccessLost means the source must be reopened (mode change, secure desktop, fullscreen switch).

View Source
var ErrTimeout = errors.New("capture: no new frame")

ErrTimeout means no new image arrived in the wait window: the screen did not change. It is not a failure.

Functions

This section is empty.

Types

type DMABuf added in v0.2.0

type DMABuf struct {
	Fourcc   uint32
	Modifier uint64
	// Width and Height are the visible picture; the planes may be larger.
	Width, Height int
	Planes        int
	FDs           [4]int32
	Offsets       [4]uint32
	Pitches       [4]uint32
	CPU           [4]unsafe.Pointer
	// Memory says FDs are memfds holding the CPU planes, linear, which a
	// Wayland compositor maps as wl_shm buffers.
	Memory bool
	// Serial tells pictures of one pool apart for a consumer that caches
	// what it made of them; a producer changes it whenever the buffers
	// behind the descriptor change.
	Serial uint64
}

DMABuf is a picture on Linux: Frame.Surface, here and in package decode, points to one (see Handle and DMABufOf). Its producer owns it in a pool and keeps it, and its file descriptors, alive until the frame is released; consumers dup what they keep longer.

FDs hold the GPU buffer of each plane, which may be one object for all planes. CPU, when set, holds the same planes in memory, row by row at Pitches: a producer fills it when its consumer cannot import DMA-BUFs (an X11 window, a compositor drawing in software, a headless test). A picture can have CPU planes and no FDs at all.

func DMABufOf added in v0.2.0

func DMABufOf(surface uintptr) *DMABuf

DMABufOf is the DMABuf a Frame.Surface points to, nil for 0.

func MemoryDMABuf added in v0.2.0

func MemoryDMABuf(fourcc uint32, width, height int, planes [][]byte, pitches []int) *DMABuf

MemoryDMABuf describes planes in Go memory, rows at pitches, as a software source (a synthetic pattern, a test) hands them on. The caller keeps the descriptor, and so the planes, alive while frames point to it.

func (*DMABuf) Handle added in v0.2.0

func (d *DMABuf) Handle() uintptr

Handle is d as a Frame.Surface.

func (*DMABuf) HasCPU added in v0.2.0

func (d *DMABuf) HasCPU() bool

HasCPU reports whether d's planes are in memory.

func (*DMABuf) HasFDs added in v0.2.0

func (d *DMABuf) HasFDs() bool

HasFDs reports whether d's planes are in DMA-BUF objects. A descriptor without them leaves FDs zero: fd 0 is never one.

type Display

type Display struct {
	ID      string
	Name    string
	Adapter gpu.Adapter
	// X and Y are the display's top-left corner on the desktop, in pixels
	// (Windows; 0, 0 for the primary display).
	X, Y    int
	Width   int
	Height  int
	Refresh float64
	HDR     bool
	Primary bool
}

Display describes one capturable output.

type Format

type Format uint8

Format is the pixel layout of a captured surface.

const (
	FormatBGRA8   Format = iota + 1 // 8-bit SDR desktop
	FormatRGB10A2                   // 10-bit SDR or HDR10 (PQ) desktop
	FormatRGBA16F                   // scRGB HDR desktop
	FormatNV12                      // capture already converted to 4:2:0 8-bit
	FormatP010                      // capture already converted to 4:2:0 10-bit
)

func (Format) String

func (f Format) String() string

type Frame

type Frame struct {
	Surface uintptr
	Adapter gpu.LUID
	Format  Format
	Width   int
	Height  int
	// Presented is when the compositor showed this image, on the monotonic
	// clock of the platform (QPC on Windows, mach_absolute_time on macOS).
	Presented time.Duration
	// Acquired is when the source handed the frame to the caller, same clock.
	Acquired time.Duration
	// Dirty lists changed rectangles when the backend reports them; nil means
	// the whole frame may have changed.
	Dirty []Rect
}

Frame is a GPU surface owned by the source until Release is called on it. Surface is the platform handle: an ID3D11Texture2D* on Windows, a CVPixelBufferRef (IOSurface backed) on macOS.

type Rect

type Rect struct{ X, Y, W, H int }

type Source

type Source interface {
	// Next blocks for up to timeout for a new frame. The returned frame stays
	// valid until Release.
	Next(timeout time.Duration) (Frame, error)
	Release() error
	Close() error
}

Source produces frames from one display.

Directories

Path Synopsis
Package cursor reads the host's system cursor: whether it shows, whether an app holds the mouse, and where it is.
Package cursor reads the host's system cursor: whether it shows, whether an app holds the mouse, and where it is.
Package display lists the capturable displays of this machine and opens one with the platform's capture backend: DXGI Desktop Duplication on Windows, ScreenCaptureKit on macOS, and MIT-SHM or the desktop portal's PipeWire stream on Linux.
Package display lists the capturable displays of this machine and opens one with the platform's capture backend: DXGI Desktop Duplication on Windows, ScreenCaptureKit on macOS, and MIT-SHM or the desktop portal's PipeWire stream on Linux.
Package dxgi captures a Windows display with DXGI Desktop Duplication.
Package dxgi captures a Windows display with DXGI Desktop Duplication.
Package pipewire captures a Wayland desktop through the XDG desktop portal's ScreenCast interface: the portal asks the user which monitor to share (once, with a restore token after that) and hands over a PipeWire node, which a PipeWire stream (libpipewire-0.3, loaded with purego) consumes as DMA-BUFs or shared memory.
Package pipewire captures a Wayland desktop through the XDG desktop portal's ScreenCast interface: the portal asks the user which monitor to share (once, with a restore token after that) and hands over a PipeWire node, which a PipeWire stream (libpipewire-0.3, loaded with purego) consumes as DMA-BUFs or shared memory.
Package sck captures a macOS display with ScreenCaptureKit through purego, with no cgo.
Package sck captures a macOS display with ScreenCaptureKit through purego, with no cgo.
Package x11 captures an Xorg (or XWayland) screen with MIT-SHM: each frame is one XShmGetImage of a monitor's rectangle of the root window into shared memory, which the encoder reads in place.
Package x11 captures an Xorg (or XWayland) screen with MIT-SHM: each frame is one XShmGetImage of a monitor's rectangle of the root window into shared memory, which the encoder reads in place.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL