video.go RawHistoryFolder
1package pipewire
2
3import (
4 "github.com/bnema/purego-pipewire/internal/core"
5 "github.com/bnema/purego-pipewire/spa"
6)
7
8// VideoFormat is a SPA raw video format (BGRx=8, BGRA=12).
9type VideoFormat = spa.VideoFormat
10
11// Supported video formats. They map to wl_shm XRGB8888 (BGRx) and ARGB8888
12// (BGRA).
13const (
14 VideoFormatBGRx = spa.VideoFormatBGRx
15 VideoFormatBGRA = spa.VideoFormatBGRA
16)
17
18// pw_stream_state values reported to VideoHandler.StateChanged.
19const (
20 StreamStateError int32 = -1
21 StreamStateUnconnected int32 = 0
22 StreamStateConnecting int32 = 1
23 StreamStatePaused int32 = 2
24 StreamStateStreaming int32 = 3
25)
26
27// Errors returned by NewVideoSource and VideoSource, for errors.Is.
28var (
29 ErrVideoConfig = core.ErrVideoConfig
30 ErrVideoTableFull = core.ErrVideoTableFull
31 ErrVideoStreamCreate = core.ErrVideoStreamCreate
32 ErrVideoConnect = core.ErrVideoConnect
33 ErrVideoResize = core.ErrVideoResize
34 ErrVideoBorrowed = core.ErrVideoBorrowed
35)
36
37// VideoConfig configures a VideoSource: the node name, the initial size, the
38// maximum frame rate (60 when zero) and the accepted formats (BGRx when
39// empty, else BGRx and/or BGRA; the first is preferred).
40type VideoConfig = core.VideoConfig
41
42// VideoHandler receives VideoSource events. Every method runs on the loop
43// thread, inside Loop.Iterate (or, for the first events, inside the call that
44// triggered them). Implementations must not block and must not allocate.
45type VideoHandler interface {
46 // StateChanged reports a stream state change; see the StreamState
47 // constants. nodeID is the PipeWire node id once known (0 before). err
48 // carries the message when state is StreamStateError.
49 StateChanged(state int32, nodeID uint32, err string)
50 // FormatChanged reports the negotiated format and its row stride.
51 FormatChanged(f VideoFormat, w, h, stride int)
52 // BuffersChanged is called after a buffer was added or removed;
53 // Dequeue may now return a buffer.
54 BuffersChanged()
55}
56
57// VideoBuffer is a buffer handed out by VideoSource.Dequeue. Data aliases a
58// mapped memfd owned by the source; it is valid until the buffer is given back
59// with Queue or Release. The value is owned by the source: do not copy it or
60// keep it after giving it back.
61type VideoBuffer = core.VideoBuffer
62
63// VideoSource is a PipeWire Video/Source node that drives the graph and
64// exposes shared-memory (memfd) buffers. All methods run on the loop thread.
65//
66// Produce a frame with Dequeue, write Data, Queue, then Trigger — in that
67// order: the buffer must be queued before Trigger. A steady-state cycle
68// performs no heap allocation.
69//
70// b := src.Dequeue() // nil: no buffer is free
71// // ... fill b.Data (b.Stride bytes per row) ...
72// src.Queue(b, seq, pts, false)
73// src.Trigger()
74//
75// Buffers PipeWire removes (renegotiation, Resize, Destroy, consumer
76// disconnect) stay mapped while borrowed and are unmapped when given back with
77// Queue or Release. Resize fails with ErrVideoBorrowed while a buffer is
78// borrowed; Destroy is best called when none is. DMA-BUF is not supported.
79type VideoSource = core.VideoSource