pipewire

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 16 Imported by: 1 module, 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 pipewire is the PipeWire video producer a ScreenCast portal streams through: a node exported over PipeWire's native protocol (a client-node, as libpipewire's pw_stream exports one), which drives its own graph: a cycle runs when a captured frame is ready, stamped with the header, transform and damage metas. The protocol, the shared memory and the realtime cycle are spoken here in Go; no libpipewire.

Index

Constants

View Source
const CursorBitmapSide = 256

CursorBitmapSide is the largest cursor image a stream's buffers have room for, in pixels each way; a larger one is cropped.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Application is the client's application.name, the program the
	// server and its tools list the stream under. Required.
	Application string
	// Name is the node name the consumer sees and links to, and the
	// name of the stream's shared-memory buffers. Required.
	Name                  string
	Width, Height, Stride uint32
	Format                VideoFormat
	// FPS is the most frames a second the stream sends, advertised as its
	// maximum and paced. The rate is variable: a frame goes out when the
	// source has one, not on a clock. A consumer may ask for less. Required.
	FPS uint32
	// Transform is the constant spa_meta_videotransform value (the
	// output's wl_output transform; 0 for a window).
	Transform uint32
	Source    Source
	// Cursor, when set, is the pointer the buffers carry as a cursor meta
	// (see Cursor); the frames then hold no pointer of their own.
	Cursor Cursor
}

Config is one producer's identity and fixed stream geometry.

type Cursor

type Cursor interface {
	// CursorState is the pointer now.
	CursorState() CursorState
	// CursorBitmap writes the image of shape into dst as rows of pixels
	// without padding, cropped from the top left to at most side x side
	// pixels and to what dst holds, and says how it laid it out. It
	// reports false when shape is no longer the pointer's.
	CursorBitmap(shape uint64, dst []byte, side int) (CursorBitmap, bool)
	// NotifyCursor is called once, before any read. The cursor calls
	// wake, from any goroutine and without blocking, whenever its state
	// changed.
	NotifyCursor(wake func())
}

Cursor is the pointer a stream carries beside its frames as an SPA_META_Cursor, the ScreenCast portal's metadata cursor mode: every buffer says where the pointer is, a buffer carries the pointer's bitmap only when its shape changed, and a change of the pointer alone sends a buffer that holds no frame (a zero-size, corrupted chunk).

type CursorBitmap

type CursorBitmap struct {
	Format        VideoFormat
	Width, Height uint32
	Stride        uint32
}

CursorBitmap is how a Cursor laid out the image it wrote.

type CursorState

type CursorState struct {
	// Visible is whether the pointer is over the frames; the rest means
	// nothing while it is not.
	Visible bool
	// X and Y are where the pointer's hotspot is, in frame pixels.
	X, Y int32
	// HotspotX and HotspotY are the hotspot's place in the bitmap.
	HotspotX, HotspotY int32
	// Shape numbers the pointer's image, which changes only with it; 0 is
	// no image yet.
	Shape uint64
}

CursorState is where the pointer is over the stream's frames.

type Dmabuf

type Dmabuf interface {
	Fd() int
	Offset() uint32
	Stride() uint32
	Release()
}

Dmabuf is one GPU buffer's single plane.

type DmabufPreparer

type DmabufPreparer interface {
	PrepareDmabuf(Dmabuf)
}

DmabufPreparer is a DmabufSource whose fills land apart from the graph (FillDmabuf false while one runs). PrepareDmabuf starts filling the buffer the next cycle's FillDmabuf gets, so a frame goes out each cycle and not every other one. It must not block.

type DmabufSource

type DmabufSource interface {
	Source
	Modifier() fourcc.Modifier
	// DmabufVideoFormat is the GPU buffers' format, which need not be
	// the shared-memory one (a GPU compositor hands out 24-bit shm and
	// 32-bit dmabufs).
	DmabufVideoFormat() VideoFormat
	AllocDmabuf() (Dmabuf, error)
	FillDmabuf(Dmabuf) (damage []Rect, ok bool)
}

DmabufSource is a Source that also fills GPU buffers: the producer offers its modifier's format first and, when the consumer takes it, binds one buffer from AllocDmabuf to each PipeWire buffer for the stream's life and fills it in place (zero copy). A consumer that takes the plain format gets producer-allocated shared memory, filled through Fill.

type FrameNotifier

type FrameNotifier interface {
	NotifyFrames(wake func())
}

FrameNotifier is a DmabufSource whose GPU frames land on their own time. On those buffers the producer does not poll it: it calls NotifyFrames once, before any fill, and the source calls wake, from any goroutine and without blocking, whenever FillDmabuf may now produce a frame or a copy it started has ended.

type Producer

type Producer struct {
	// contains filtered or unexported fields
}

Producer is one running PipeWire video output stream. Its Source is called from one goroutine at a time.

func Start

func Start(cfg Config) (*Producer, error)

Start exports the stream's node and returns once the server has registered it, so a consumer can link to NodeID.

func (*Producer) Close

func (p *Producer) Close()

Close stops the stream and releases everything it holds.

func (*Producer) Done

func (p *Producer) Done() <-chan struct{}

Done is closed once the stream has ended: closed, or cut off by the server (Err says why).

func (*Producer) Err

func (p *Producer) Err() error

Err is why the stream ended by itself; nil while it runs and after Close.

func (*Producer) NodeID

func (p *Producer) NodeID() uint32

NodeID is the node the consumer connects to.

func (*Producer) Serial

func (p *Producer) Serial() uint64

Serial is the node's object.serial, which a consumer targets (PW_KEY_TARGET_OBJECT) instead of NodeID: ids are reused once a node goes, serials never are.

type Rect

type Rect struct{ X, Y, Width, Height int }

Rect is a damaged region in buffer pixels.

func ClampDamage

func ClampDamage(out, rects []Rect, width, height, max int) []Rect

ClampDamage clips rects to the frame into out; none, none left, or more than max collapse to the whole frame. It appends at most max rects to out[:0], so an out of that capacity never grows.

type Resizable

type Resizable interface {
	Source
	Size() (width, height, stride uint32)
}

Resizable is a Source whose frames change size (a window being resized): Size is the layout of the frames it has now. When that differs from the stream's, the producer offers the new size and holds frames back until the consumer has renegotiated.

type Restarter

type Restarter interface {
	Restart()
}

Restarter is a Source that must know when the consumer's buffers are dropped: the buffers that replace them hold nothing, so the next fill has to produce a frame even if the source has not changed.

type ServerError

type ServerError struct {
	// Object is the id of the object the error is about.
	Object uint32
	// Errno is the server's negative errno, as a positive Errno.
	Errno unix.Errno
	// Message is the server's description.
	Message string
}

ServerError is an error the server reported on one of the connection's objects (core error event).

func (*ServerError) Error

func (e *ServerError) Error() string

type Source

type Source interface {
	Fill(dst []byte) (damage []Rect, ok bool)
}

Source fills one frame: Fill copies stride-byte rows into dst and reports what changed (nil or empty is the whole frame); ok false skips this cycle (nothing new, or the capture failed).

type VideoFormat

type VideoFormat uint32

VideoFormat is an spa_video_format.

const (
	VideoRGBx VideoFormat = 7
	VideoBGRx VideoFormat = 8
	VideoRGBA VideoFormat = 11
	VideoBGRA VideoFormat = 12
	// The packed 24-bit formats GPU renderers offer over shm.
	VideoRGB VideoFormat = 15
	VideoBGR VideoFormat = 16
)

The packed 8-bit formats compositors hand out.

Directories

Path Synopsis
Package pwtest starts a private PipeWire daemon for tests, so producers and consumers link without touching the user's session, and runs libpipewire consumers against it as the reference a producer is checked by.
Package pwtest starts a private PipeWire daemon for tests, so producers and consumers link without touching the user's session, and runs libpipewire consumers against it as the reference a producer is checked by.

Jump to

Keyboard shortcuts

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