Documentation
¶
Overview ¶
Package wire defines Planck protocol v1: control messages carried as length-prefixed frames on the QUIC control stream, and the plaintext layouts of media datagrams carried over AEAD-sealed UDP.
Index ¶
- Constants
- Variables
- func AppendMessage(b []byte, m Message) ([]byte, error)
- func WriteClip(w io.Writer, c *Clip) error
- func WriteMessage(w io.Writer, m Message) error
- type AudioCodec
- type AudioFlow
- type AudioHeader
- type AuthMethod
- type AuthRequest
- type AuthResponse
- type AuthStatus
- type Capabilities
- type Chroma
- type Clip
- type ClipFormat
- type Codec
- type CursorShape
- type CursorState
- type DisplayPhase
- type Feedback
- type Goodbye
- type GoodbyeReason
- type Hello
- type HostStats
- type Input
- type InputTrace
- type InputType
- type Message
- type MsgType
- type PLI
- type PeerState
- type Ping
- type Pong
- type ProbeDone
- type ProbeHeader
- type ProbeRequest
- type Profile
- type RefInvalidate
- type Resize
- type ResizeDisplay
- type Role
- type Rumble
- type SessionConfig
- type SessionReady
- type StatsReport
- type Stream
- type SwitchDisplay
- type VideoHeader
- type VideoInfo
Constants ¶
const ( // FeatureLANDatagram, from a client, says its route to the host is a // LAN interface with a 1500-byte MTU: the host may then use // MaxLANDatagram for the session. FeatureLANDatagram uint32 = 1 << 0 // FeatureInputDedup, from a host, says it drops input events whose Seq // it has seen, so the client may send redundant copies. FeatureInputDedup uint32 = 1 << 1 // FeatureCapabilities says the peer sends and reads Capabilities and // Profile. Both Hellos must carry it before either message is sent. FeatureCapabilities uint32 = 1 << 2 // FeatureResize, from a host, says it takes Resize: a stream on a // virtual display follows the client's window size. FeatureResize uint32 = 1 << 3 // FeaturePeerState says the peer reads PeerState. A peer sends it only // to a peer whose Hello carries this bit. FeaturePeerState uint32 = 1 << 4 // FeatureMic, from a host, says it accepts the client's microphone as // FlowMic audio datagrams. FeatureMic uint32 = 1 << 5 // FeatureClipboard says the peer reads clipboard streams. FeatureClipboard uint32 = 1 << 6 // FeatureHostStats, from a client, says it reads HostStats. FeatureHostStats uint32 = 1 << 8 // FeatureCursorState, from a client, says it reads CursorState. FeatureCursorState uint32 = 1 << 9 // FeatureStreamSwitch, from a client, says it follows a stream whose // codec, format or size changes mid-session: the host announces each // new stream in a Stream message and tags its frames with the epoch. FeatureStreamSwitch uint32 = 1 << 10 // FeatureResizeDisplay, from a host, says its Resize handler reads // Resize.Display. A client sends Display only to such a host: an // older one refuses the longer message. FeatureResizeDisplay uint32 = 1 << 11 // FeatureCursorShape, from a client, says it reads CursorShape. FeatureCursorShape uint32 = 1 << 12 // FeatureSwitchDisplay, from a host, says it takes SwitchDisplay: it // moves the stream to another of its displays and announces it in a // Stream message. FeatureSwitchDisplay uint32 = 1 << 13 // FeatureRefInvalidate, offered by both ends, says a client that loses // a frame sends RefInvalidate instead of PLI and skips frames up to // the host's next Recovery frame (or keyframe), and the host answers // it so; neither end then turns a lost frame into a keyframe request. FeatureRefInvalidate uint32 = 1 << 14 // FeatureRefInvalidateThrough, from a host, says it reads // RefInvalidate.Through. A client sends Through only to such a host: // an older one refuses the longer message. FeatureRefInvalidateThrough uint32 = 1 << 15 // FeatureDisplayPhase, from a host, says it reads DisplayPhase. FeatureDisplayPhase uint32 = 1 << 16 )
Hello feature bits. A peer that does not know a bit ignores it, so either side may set one without breaking an older peer.
const ( KindVideo byte = 0x11 KindAudio byte = 0x12 KindInput byte = 0x13 KindRumble byte = 0x14 KindPing byte = 0x15 KindPong byte = 0x16 KindFeedback byte = 0x17 )
Media datagram kinds, carried in the first plaintext byte.
const ( MaxSlices = 16 MaxBlocks = 32 MaxShards = 255 )
Video shard limits. A frame has up to MaxSlices codec slices; a slice is split into up to MaxBlocks Reed-Solomon blocks; a block has at most MaxShards data plus parity shards.
const ( PingLen = 16 PongLen = 32 )
const AudioHeaderLen = 16
AudioHeaderLen precedes one audio packet.
const ClipHeaderLen = 1 + 16 + 32 + 4
ClipHeaderLen is the frame header in front of each item's bytes.
const CursorCacheSize = 32
CursorCacheSize is how many shapes the host and the client each keep, the least recently used going first. Both see the same shapes in the same order, so a shape the host refers to by ID alone is still in the client's cache.
const FeatureCalibration uint32 = 1 << 17
FeatureCalibration, from a host, says it serves calibration: it answers ProbeRequest with a train of probe datagrams, and streams its synthetic pattern, not its screen, to a client whose capabilities ask for a calibration stream. A client sends ProbeRequest only to such a host.
const FeatureInputTrace uint32 = 1 << 18
FeatureInputTrace, from a host, says it reads InputTrace.
const FeedbackLen = 28
FeedbackLen is the fixed size of a feedback datagram.
const InputLen = 32
InputLen is the fixed size of an input datagram.
const KindProbe byte = 0x18
KindProbe is a probe datagram of a calibration train, host to client.
const MaxCapsJSON = 48 << 10
MaxCapsJSON bounds the JSON in Capabilities and Profile.
const MaxClip = 16 << 20
MaxClip bounds one clipboard item's bytes.
const MaxControlLen = 1 << 16
MaxControlLen bounds a control frame body, including its type byte.
const MaxCursorSide = 256
MaxCursorSide bounds a CursorShape's width and height, in pixels.
const MaxDatagram = 1152
MaxDatagram is the largest media UDP payload Planck sends by default: it fits Tailscale's 1280-byte tunnel MTU after IPv6, UDP and WireGuard overhead. Every sealed media datagram, header and AEAD tag included, must fit within it.
const MaxLANDatagram = 1452
MaxLANDatagram is the media UDP payload on a LAN path with a 1500-byte MTU, after IPv6 and UDP headers: 22% fewer datagrams per frame than MaxDatagram. Hosts use it only when both ends agree (FeatureLANDatagram).
const MaxProbeCount = 1 << 16
MaxProbeCount bounds the datagrams of one probe train.
const ProbeHeaderLen = 24
ProbeHeaderLen is the plaintext header of a probe datagram; padding fills the rest of it to the requested size.
const RumbleLen = 12
RumbleLen is the fixed size of a rumble datagram.
const StreamClipboard byte = 0x01
StreamClipboard is the first byte of a unidirectional QUIC stream that carries clipboard items. Each side opens one for what it sends.
const Version = 1
Version is the protocol version exchanged in Hello.
const VideoHeaderLen = 36
VideoHeaderLen is the plaintext header in front of every video shard.
Variables ¶
var ( ErrClipTooLarge = errors.New("wire: clipboard item too large") ErrClipHash = errors.New("wire: clipboard item does not match its hash") ErrClipFormat = errors.New("wire: unknown clipboard format") )
var ( ErrTooLarge = errors.New("wire: control message too large") ErrMalformed = errors.New("wire: malformed message") ErrUnknownMsg = errors.New("wire: unknown message type") )
var ErrBadDatagram = errors.New("wire: bad media datagram")
Functions ¶
func AppendMessage ¶
AppendMessage appends m as a control frame: a 32-bit big-endian length, then the type byte and the body.
Types ¶
type AudioCodec ¶
type AudioCodec uint8
const ( AudioOpus AudioCodec = iota // AudioPCM16 is raw little-endian int16 PCM. AudioPCM16 )
type AudioHeader ¶
type AudioHeader struct {
Flow AudioFlow
Codec AudioCodec
// FrameQuarterMs is the packet's frame length in quarter milliseconds;
// zero means 10 ms.
FrameQuarterMs uint8
Seq uint32
Timestamp int64
}
AudioHeader describes one audio packet. Hosts before the mic flow wrote zeros where Flow, Codec and FrameQuarterMs go: desktop Opus at the default frame length.
func ParseAudio ¶
func ParseAudio(b []byte) (AudioHeader, []byte, error)
ParseAudio returns the header and the payload, which aliases b.
func (*AudioHeader) Put ¶
func (h *AudioHeader) Put(b []byte)
type AuthMethod ¶
type AuthMethod uint8
const ( // AuthPaired: the client's certificate fingerprint was stored at pairing. AuthPaired AuthMethod = iota + 1 // AuthPIN: first pairing; PINProof binds a shared PIN to this TLS session. AuthPIN // AuthTailscale: the host resolves the client's identity with Tailscale WhoIs. AuthTailscale )
type AuthRequest ¶
type AuthRequest struct {
Method AuthMethod
DeviceName string
PINProof [32]byte
}
func (*AuthRequest) Type ¶
func (*AuthRequest) Type() MsgType
type AuthResponse ¶
type AuthResponse struct {
Status AuthStatus
Identity string
// PINProof is the host's proof of the PIN for AuthPIN, so the client
// also detects a host that does not know it.
PINProof [32]byte
Message string
}
func (*AuthResponse) Type ¶
func (*AuthResponse) Type() MsgType
type AuthStatus ¶
type AuthStatus uint8
const ( AuthOK AuthStatus = iota + 1 AuthDenied AuthPINRequired )
type Capabilities ¶
Capabilities carries JSON: pkg/defaults HostCapabilities from the host; from the client, {"v":1,"client":ClientCapabilities,"route":RouteInfo,"overrides":UserOverrides}. pkg/wire treats it as opaque, so the JSON schema can grow without a protocol bump.
func (*Capabilities) Type ¶
func (*Capabilities) Type() MsgType
type Clip ¶
type Clip struct {
Format ClipFormat
Origin [16]byte
Hash [32]byte
Data []byte
}
Clip is one clipboard item. Origin identifies the device that first copied it, so an item is never applied back where it came from; Hash is the SHA-256 of Data.
func NewClip ¶
func NewClip(f ClipFormat, origin [16]byte, data []byte) *Clip
NewClip makes an item from data and stamps its hash.
type ClipFormat ¶
type ClipFormat uint8
const ( // ClipText is UTF-8 text. ClipText ClipFormat = iota + 1 // ClipPNG is a PNG image. ClipPNG )
type CursorShape ¶
type CursorShape struct {
// ID names the shape: a hash of its size, hotspot, DPI and pixels.
ID uint64
// Width and Height are the image's size in pixels, up to
// MaxCursorSide, and HotX and HotY its hotspot on it. All are zero in
// a reference.
Width, Height uint16
HotX, HotY uint16
// DPI is the display's the host sized the cursor for; 96 is 100%.
DPI uint16
// RGBA is the image, not premultiplied, rows top down: Width * Height
// * 4 bytes. It is nil in a reference.
RGBA []byte
}
CursorShape is the host's cursor as the client draws it in place of its own over the picture. A shape with no image refers to one sent before, by ID.
func (*CursorShape) Ref ¶
func (m *CursorShape) Ref() bool
Ref reports whether m refers to a shape sent before.
func (*CursorShape) Type ¶
func (*CursorShape) Type() MsgType
type CursorState ¶
type CursorState struct {
Visible bool
// Captured is set while an app holds the mouse, as a game does: it
// confines the cursor to less than the desktop, or warps it back. A
// cursor hidden alone, as over a playing video, is not captured.
Captured bool
// HasPos says X and Y hold the cursor's place on the streamed display,
// from 0 at its left or top edge to 65535 at its right or bottom edge.
HasPos bool
X, Y uint16
}
CursorState is the host's system cursor. Neither capture path draws the cursor into the picture, so the client's own cursor stands in for a Visible one, drawn as the CursorShape a host sends.
func (*CursorState) Type ¶
func (*CursorState) Type() MsgType
type DisplayPhase ¶ added in v0.2.0
type DisplayPhase struct {
Valid, Locked bool
// Direct and Composited say how the client's system shows the
// pictures; neither is set while it cannot tell.
Direct, Composited bool
PeriodNs uint32
// ErrorNs is the median slack minus the target, wrapped into half a
// refresh either way: above 0 the pictures were ready early.
ErrorNs int32
SlackNs, TargetNs, JitterNs uint32
// LatePermille and CompositedPermille are the shares of pictures that
// missed their refresh and that a compositor showed a refresh or more
// later, in thousandths.
LatePermille, CompositedPermille uint16
// Oldest and Newest are the video frames measured.
Oldest, Newest uint32
}
DisplayPhase is the client display's refresh and how long before a refresh its last pictures were ready (pkg/phaselock Report): the host steers the phase of its frames with it.
func (*DisplayPhase) Type ¶ added in v0.2.0
func (*DisplayPhase) Type() MsgType
type Feedback ¶
type Feedback struct {
FrameID uint32
// ArrivalTS is the client's monotonic clock when the frame completed.
ArrivalTS int64
Bytes uint32
HasFinal bool
FinalOK bool
FinalFrameID uint32
FinalRecv uint16
FinalSent uint16
}
Feedback is the client's report for one fully received video frame. It also carries the final shard counts of the most recent frame that left the client's reassembly window, which the host uses as its loss signal.
type Goodbye ¶
type Goodbye struct {
Reason GoodbyeReason
Message string
}
type GoodbyeReason ¶
type GoodbyeReason uint8
const ( GoodbyeNormal GoodbyeReason = iota + 1 GoodbyeAuthFailed GoodbyeProtocolError GoodbyeTimeout )
type HostStats ¶
HostStats are the host's stage times the client cannot see in the video headers, which time a frame from its capture time: the p50 over the last frames of capture, from the system presenting a picture to the host acquiring it, and of encode, from acquiring it to the encoder finishing it.
type Input ¶
type Input struct {
Type InputType
Seq uint32
Timestamp int64
Code uint16
Mods uint16
Down bool
X, Y int32
Button uint8
Pad uint8
Buttons uint32
LT, RT uint8
LX, LY, RX, RY int16
}
Input is one input event from the client. Which fields count depends on Type: Key uses Code (USB HID usage), Mods and Down; MouseRel and Scroll use X and Y as deltas; MouseAbs uses X and Y in 0..65535 of the video frame; MouseButton uses Button and Down; Gamepad uses Pad and the stick, trigger and button state, which is absolute so a lost packet is healed by the next.
type InputTrace ¶ added in v0.2.1
type InputTrace struct {
On bool
}
InputTrace asks the host to trace its input and cursor while the client traces its own (pkg/inputtrace), or to stop.
func (*InputTrace) Type ¶ added in v0.2.1
func (*InputTrace) Type() MsgType
type Message ¶
type Message interface {
Type() MsgType
// contains filtered or unexported methods
}
Message is a control-stream message. The set is closed: only types in this package implement it.
func DecodeMessage ¶
DecodeMessage decodes a frame body: the type byte and the message fields. Trailing bytes are rejected so a frame has exactly one encoding.
type MsgType ¶
type MsgType uint8
const ( MsgHello MsgType = iota + 1 MsgAuthRequest MsgAuthResponse MsgSessionConfig MsgSessionReady MsgPLI MsgRefInvalidate MsgStatsReport MsgGoodbye // MsgCapabilities goes both ways, once, right after AuthOK. MsgCapabilities MsgType = 10 // MsgProfile goes host to client, right after SessionReady, and again // when a Resize changed the stream. MsgProfile MsgType = 11 // MsgResize goes client to host, only to a host whose Hello carries // FeatureResize. MsgResize MsgType = 12 // MsgPeerState goes both ways, to a peer with FeaturePeerState, at the // start of a session and whenever it changes. MsgPeerState MsgType = 13 // MsgHostStats goes host to client, in answer to each StatsReport, // only to a client whose Hello carries FeatureHostStats. MsgHostStats MsgType = 16 // MsgCursorState goes host to client, only to a client whose Hello // carries FeatureCursorState: at the start of a stream and whenever the // host's cursor shows, hides, or is captured or let go. MsgCursorState MsgType = 17 // MsgStream goes host to client, only to a client whose Hello carries // FeatureStreamSwitch, when a Resize settled a new stream. MsgStream MsgType = 18 // MsgCursorShape goes host to client, only to a client whose Hello // carries FeatureCursorShape: as a stream starts and whenever the // host's cursor changes shape. MsgCursorShape MsgType = 19 // MsgSwitchDisplay goes client to host, only to a host whose Hello // carries FeatureSwitchDisplay, from a client with FeatureStreamSwitch. MsgSwitchDisplay MsgType = 20 // MsgDisplayPhase goes client to host, only to a host whose Hello // carries FeatureDisplayPhase, a few times a second while pictures // reach the screen. MsgDisplayPhase MsgType = 21 )
const MsgInputTrace MsgType = 24
MsgInputTrace goes client to host, only to a host whose Hello carries FeatureInputTrace: once as the session starts and whenever the client's input trace turns on or off.
type PeerState ¶
type PeerState struct {
// ClipboardSend: this side sends its clipboard changes.
ClipboardSend bool
// ClipboardRecv: this side applies the peer's clipboard items.
ClipboardRecv bool
// MicDevice, from a host, is the virtual input device the client's
// microphone plays into; empty when it has none, and MicHint says why.
MicDevice string
MicHint string
}
PeerState is what one side does with the session's optional flows.
type Ping ¶
Ping carries the sender's clock; Pong echoes it with the responder's receive time (T1) and send time (T2), NTP style.
type ProbeDone ¶ added in v0.2.0
ProbeDone says the host sent Sent datagrams of train Train, the first to the last SendNs apart; Sent 0 is a refused request.
type ProbeHeader ¶ added in v0.2.0
ProbeHeader is datagram Index of the Count of train Train, sent at the host's monotonic SentTS.
func (*ProbeHeader) Parse ¶ added in v0.2.0
func (h *ProbeHeader) Parse(b []byte) error
func (*ProbeHeader) Put ¶ added in v0.2.0
func (h *ProbeHeader) Put(b []byte)
type ProbeRequest ¶ added in v0.2.0
ProbeRequest asks the host for a train of Count probe datagrams of Size bytes of plaintext each, paced at RateKbps, or back to back at 0.
func (*ProbeRequest) Type ¶ added in v0.2.0
func (*ProbeRequest) Type() MsgType
type Profile ¶
type Profile struct {
JSON []byte
}
Profile carries the host's pkg/defaults ResolvedProfile as JSON, for the client UI and player.
type RefInvalidate ¶
type RefInvalidate struct {
FrameID, Through uint32
}
RefInvalidate tells the host that FrameID and every later frame are unusable as references, so it can recover with a non-IDR frame. Through, when after FrameID, is the last frame the client lost in this gap; otherwise the gap is FrameID alone. Through 0 is unset, so a gap cannot end at frame 0: legacy peers send no Through at all, and a 4-byte body must not read as a wrapped range for a FrameID past 1<<31.
func (*RefInvalidate) Last ¶ added in v0.2.0
func (m *RefInvalidate) Last() uint32
Last is the last frame of the gap.
func (*RefInvalidate) Type ¶
func (*RefInvalidate) Type() MsgType
type Resize ¶
type Resize struct {
Width, Height uint16
// Display is the client display the window is on now, when Width is
// set; else the display offered at the start holds.
Display ResizeDisplay
}
Resize asks the host to stream at the client window's new size, in pixels. The host answers with a Profile once the stream changed, or keeps the stream as it is.
type ResizeDisplay ¶
ResizeDisplay is a client display: its size in pixels, backing scale in thousandths, refresh range and HDR.
type SessionConfig ¶
type SessionConfig struct {
Codec Codec
Chroma Chroma
Width uint16
Height uint16
FPS uint16
BitrateKbps uint32
Slices uint8
SubFrame bool
AudioSampleRate uint32
AudioChannels uint8
}
func (*SessionConfig) Type ¶
func (*SessionConfig) Type() MsgType
type SessionReady ¶
type SessionReady struct {
SessionID uint64
MediaPort uint16
// ShardSize is the video FEC shard payload size for this session.
ShardSize uint16
Config SessionConfig
}
func (*SessionReady) Type ¶
func (*SessionReady) Type() MsgType
type StatsReport ¶
type StatsReport struct {
RTTMicros uint32
JitterMicros uint32
LossPermille uint16
FramesReceived uint32
FramesDropped uint32
FramesRecovered uint32
DecodeMicros uint32
ReceivedKbps uint32
}
func (*StatsReport) Type ¶
func (*StatsReport) Type() MsgType
type Stream ¶
Stream announces the stream a Resize settled: Profile is its pkg/defaults ResolvedProfile as JSON, and every video frame of it carries Epoch.
type SwitchDisplay ¶
type SwitchDisplay struct {
DisplayID string
}
SwitchDisplay asks the host to stream its display with this ID, one of the HostCapabilities displays. The host answers with a Stream once the stream moved, and ignores an ID it does not have.
func (*SwitchDisplay) Type ¶
func (*SwitchDisplay) Type() MsgType
type VideoHeader ¶
type VideoHeader struct {
VideoInfo
SliceIndex uint8
BlockIndex uint8
BlockCount uint8
ShardIndex uint8
DataShards uint8
ParityShards uint8
ShardLen uint16
// BlockLen is the number of slice bytes the block's data shards carry;
// the last data shard is zero-padded to ShardLen.
BlockLen uint32
}
VideoHeader describes one shard of one Reed-Solomon block of one slice.
func (*VideoHeader) Parse ¶
func (h *VideoHeader) Parse(b []byte) error
Parse decodes a video header from a whole shard datagram and checks it against the datagram length.
func (*VideoHeader) Put ¶
func (h *VideoHeader) Put(b []byte)
type VideoInfo ¶
type VideoInfo struct {
FrameID uint32
Keyframe bool
// CaptureTS and EncodeTS are the host's monotonic clock in nanoseconds
// when the frame was captured and when its encode finished. The client
// maps them to its clock with the ping/pong offset.
CaptureTS int64
EncodeTS int64
SliceCount uint8
// Recovery marks the first frame encoded after a RefInvalidate: it
// predicts only from frames before the invalidated one, so a client
// that skipped the frames since decodes again from it.
Recovery bool
// Epoch is the stream the frame belongs to: 0 from the start, and the
// Epoch of each Stream message after it.
Epoch uint8
}
VideoInfo is the per-frame part of a video shard header.