Documentation
¶
Index ¶
- Constants
- Variables
- func LoadPairedClients(dir string) (map[string]PairedClient, error)
- func LocalDisplays() []defaults.HostDisplay
- func ParseChroma(s string) (encode.Chroma, error)
- func ParseCodec(s string) (encode.Codec, error)
- func ParseProfile(b []byte) (*defaults.ResolvedProfile, error)
- func PrivacyModeProblem() string
- func ProbeClientCapabilities() defaults.ClientCapabilities
- func RevokePairedClients(dir string, fingerprints []string) error
- type CalibrationMode
- type Client
- func (c *Client) Close()
- func (c *Client) Connect(ctx context.Context, t Target) error
- func (c *Client) Disconnect()
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Err() error
- func (c *Client) HostCapabilities() *defaults.HostCapabilities
- func (c *Client) HostDisplays() []defaults.HostDisplay
- func (c *Client) HostOS() string
- func (c *Client) Ping(ctx context.Context, n int, every time.Duration) ([]time.Duration, error)
- func (c *Client) Probe(ctx context.Context, spec transport.ProbeSpec) (transport.ProbeTrain, error)
- func (c *Client) RequestKeyframe() error
- func (c *Client) ResetStats()
- func (c *Client) Resize(w, h int) error
- func (c *Client) ResizeOn(w, h int, d defaults.ClientDisplay) error
- func (c *Client) SendInput(ev input.Event) error
- func (c *Client) SetClipboard(cfg ClipboardConfig)
- func (c *Client) SetMicMuted(muted bool) error
- func (c *Client) SetPreferLAN(on bool)
- func (c *Client) SetQuality(ctx context.Context, q Quality) error
- func (c *Client) SetVolume(v float64)
- func (c *Client) Stats() ClientStats
- func (c *Client) StreamedDisplay() string
- func (c *Client) SwitchDisplay(id string) error
- type ClientConfig
- type ClientStats
- type ClipboardConfig
- type ClipboardStats
- type GamepadHostSettings
- type GamepadProfile
- type GamepadPump
- func (p *GamepadPump) Attach(send func(input.Event) error) uint64
- func (p *GamepadPump) CancelLearn()
- func (p *GamepadPump) Close()
- func (p *GamepadPump) Detach(id uint64)
- func (p *GamepadPump) Learn(id int, target gamepad.Input, done func(gamepad.Binding))
- func (p *GamepadPump) Rumble(r wire.Rumble)
- func (p *GamepadPump) SetProfile(pr GamepadProfile)
- func (p *GamepadPump) TestRumble(id int, d time.Duration) error
- func (p *GamepadPump) Watch() []PadSnapshot
- type GamepadSource
- type Host
- func (h *Host) Addr() net.Addr
- func (h *Host) ConnectedClient() string
- func (h *Host) DiscoveryAddr() net.Addr
- func (h *Host) Done() <-chan struct{}
- func (h *Host) Err() error
- func (h *Host) Fingerprint() string
- func (h *Host) GamepadSettings() GamepadHostSettings
- func (h *Host) GamepadSlots() [gamepad.MaxVirtualPads]int
- func (h *Host) HostID() string
- func (h *Host) KickClient() error
- func (h *Host) MediaPort() int
- func (h *Host) Name() string
- func (h *Host) PIN() string
- func (h *Host) PairedClients() map[string]PairedClient
- func (h *Host) ReorderGamepadSlot(from, to int) error
- func (h *Host) ResetGamepadSlots() error
- func (h *Host) RevokeAllClients() error
- func (h *Host) RevokeClient(fingerprint string) error
- func (h *Host) SessionSettings() SessionSettings
- func (h *Host) SetClipboard(c ClipboardConfig)
- func (h *Host) SetGamepadSettings(s GamepadHostSettings) error
- func (h *Host) SetName(name string) error
- func (h *Host) SetSessionSettings(s SessionSettings)
- func (h *Host) Start(ctx context.Context) error
- func (h *Host) Stats() HostStats
- func (h *Host) Stop()
- type HostConfig
- type HostDeniedError
- type HostStats
- type Knobs
- type Latency
- type MicStats
- type NullSink
- type PadInjector
- type PadSnapshot
- type PairedClient
- type PathInfoer
- type Quality
- type RouteConfig
- type SessionEvent
- type SessionSettings
- type Sink
- type SinkOpener
- type SystemHooks
- type Target
- type VideoInfo
- type VideoOpener
- type VideoParams
- type VideoPipe
- type VirtualDisplay
- type VirtualPadSlots
- type WhoIser
Constants ¶
const ( DefaultProbeInterval = 4 * time.Second DefaultStallTimeout = 2500 * time.Millisecond )
const FrameTimeRing = 120
FrameTimeRing is how many frame times ClientStats keeps.
const MaxHostNameLen = 64
MaxHostNameLen is the longest name SetName takes, in bytes.
const PairedClientsFile = "paired-clients.json"
PairedClientsFile holds the client certificates a host trusts, beside host.json.
Variables ¶
var ErrNoAnswer = errors.New("the host did not answer on any route")
ErrNoAnswer is a connect to a host that answered on none of its routes.
var ErrNoClient = errors.New("session: no client is streaming")
ErrNoClient is a kick with no client streaming.
var ErrNoDisplaySwitch = errors.New("session: this host cannot switch displays")
ErrNoDisplaySwitch is SwitchDisplay's answer from a host that cannot move a stream to another display.
var ErrNoVirtualPads = errors.New("session: no virtual controllers are plugged in")
ErrNoVirtualPads is ReorderGamepadSlot's error while no client controller is plugged in.
var ErrNotConnected = errors.New("session: not connected")
var ErrNotPaired = errors.New("session: no paired client has that fingerprint")
ErrNotPaired is a revoke of a fingerprint the host does not trust.
var ErrPrivacyMode = errors.New("privacy mode needs a virtual display, which needs a Windows host with SudoVDA")
ErrPrivacyMode is why privacy mode cannot work on this machine.
Functions ¶
func LoadPairedClients ¶
func LoadPairedClients(dir string) (map[string]PairedClient, error)
LoadPairedClients reads the clients a host with config directory dir trusts, for when it is not running.
func LocalDisplays ¶
func LocalDisplays() []defaults.HostDisplay
LocalDisplays lists this machine's displays, which a host captures.
func ParseChroma ¶
ParseChroma reads a chroma flag value: nv12, p010, yuv444 or yuv444p10.
func ParseCodec ¶
ParseCodec reads a codec flag value: h264, hevc, av1 or pyrowave.
func ParseProfile ¶
func ParseProfile(b []byte) (*defaults.ResolvedProfile, error)
ParseProfile reads a wire.Profile body.
func PrivacyModeProblem ¶
func PrivacyModeProblem() string
PrivacyModeProblem is why privacy mode cannot work on this machine, "" when it can.
func ProbeClientCapabilities ¶
func ProbeClientCapabilities() defaults.ClientCapabilities
ProbeClientCapabilities reads this device's main display and hardware decoders.
func RevokePairedClients ¶
RevokePairedClients is Host.RevokeClient, or with fingerprints nil RevokeAllClients, for a host that is not running.
Types ¶
type CalibrationMode ¶ added in v0.2.0
type CalibrationMode string
CalibrationMode is the stream a calibration session asks for.
const ( // CalibrateNetwork streams nothing: the session carries probe trains. CalibrateNetwork CalibrationMode = "network" // CalibrateVideo streams the host's synthetic pattern, encoded as the // resolved profile says, in place of its screen. CalibrateVideo CalibrationMode = "video" )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to one host at a time.
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
NewClient prepares a client; the identity is created on first Connect.
func (*Client) Connect ¶
Connect dials the host, authenticates, pins the host on first approval and starts playback.
func (*Client) Disconnect ¶
func (c *Client) Disconnect()
Disconnect says goodbye to the host and stops playback.
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done is closed when the current stream ends, which a route change does not; nil without one.
func (*Client) HostCapabilities ¶ added in v0.2.0
func (c *Client) HostCapabilities() *defaults.HostCapabilities
HostCapabilities are what the host streaming now said it can do, nil without a stream or from an older host.
func (*Client) HostDisplays ¶
func (c *Client) HostDisplays() []defaults.HostDisplay
HostDisplays lists the displays the host streaming now advertised, nil without a stream or from an older host.
func (*Client) HostOS ¶
HostOS is the GOOS of the host streaming now, as it said, "" without a stream or from an older host.
func (*Client) Ping ¶ added in v0.2.0
Ping measures n round trips on the live session (transport.Session.Ping).
func (*Client) Probe ¶ added in v0.2.0
Probe runs a probe train on the live session of a calibration stream (transport.Session.Probe).
func (*Client) RequestKeyframe ¶
RequestKeyframe asks the host for an IDR frame.
func (*Client) ResetStats ¶ added in v0.2.0
func (c *Client) ResetStats()
ResetStats starts the stream's latency windows and frame counts afresh, so Stats sums up only what comes after.
func (*Client) Resize ¶
Resize offers the host a w x h pixel window to stream at, on the display offered last. See ResizeOn.
func (*Client) ResizeOn ¶
func (c *Client) ResizeOn(w, h int, d defaults.ClientDisplay) error
ResizeOn offers the host a w x h pixel window to stream at, on display d; a d without a size is the display offered last. It sends nothing unless the stream is on a virtual display at Resolution auto and the host takes Resize, nor when the size, made even and in bounds, and the display are the ones offered last. A host that does not read a Resize's display gets the size alone. The host may answer with a new stream in another codec (switchStream).
func (*Client) SetClipboard ¶
func (c *Client) SetClipboard(cfg ClipboardConfig)
SetClipboard changes what this client shares, at once.
func (*Client) SetMicMuted ¶
SetMicMuted mutes or unmutes this client's microphone on the host. Each stream starts muted. Unmuting fails when the host has no virtual mic to play it into.
func (*Client) SetPreferLAN ¶
SetPreferLAN turns the move of a stream on a tailnet route to the LAN on or off, for the stream now and later ones.
func (*Client) SetQuality ¶
SetQuality changes the requested stream. Protocol v1 fixes the config at the handshake, so a live session reconnects with the new one.
func (*Client) SetVolume ¶
SetVolume sets the stream's playback level, from 0 (silent) to 1 (as the host sent it), at once and for every stream after.
func (*Client) Stats ¶
func (c *Client) Stats() ClientStats
Stats is a snapshot of the current session; Connected is false without one.
func (*Client) StreamedDisplay ¶
StreamedDisplay is the ID of the host display streaming now, "" on a virtual display or without a stream.
func (*Client) SwitchDisplay ¶
SwitchDisplay asks the host to stream its display id, one of HostDisplays, in this session. The host answers with a new stream (switchStream), which shows from its first keyframe.
type ClientConfig ¶
type ClientConfig struct {
// ConfigDir holds client.json (the pinned hosts) and the client
// identity. Empty uses config.Dir().
ConfigDir string
// Name is the device name the host shows and pairs under.
Name string
Quality Quality
// Overrides go to a host that resolves the stream from both ends'
// capabilities; an older host gets Quality only.
Overrides defaults.UserOverrides
// Capabilities replaces the probe of this device's display and
// decoders.
Capabilities func() defaults.ClientCapabilities
// ViewSize is the size in pixels of the window the stream shows in;
// nil, as headless, has none. A stream on a virtual display at
// Resolution auto starts at this size and follows Resize.
ViewSize func() (w, h int)
// PIN is the host's pairing PIN, needed the first time unless both
// devices belong to the same Tailscale user.
PIN string
NoAudio bool
// OpenSink makes the video sink; nil decodes headless (OpenDecodeSink).
OpenSink SinkOpener
// OpenAudioPlayer replaces the default output device.
OpenAudioPlayer func() (audio.Player, error)
// OpenMic replaces audio.NewMicCapturer.
OpenMic func() (audio.MicCapturer, error)
// Clipboard is what this client shares: Send is client to host,
// Receive host to client.
Clipboard ClipboardConfig
// OpenClipboard replaces clipboard.Open.
OpenClipboard func() (clipboard.Board, error)
// Tailscale replaces the local daemon client for path detection.
Tailscale PathInfoer
// OnRumble receives gamepad rumble from the host.
OnRumble func(input.RumbleEvent)
// Gamepads sends this device's controllers while a stream runs, and
// plays the host's rumble on them.
Gamepads *GamepadPump
// OnCursor receives the host's cursor state, from a host that sends it.
OnCursor func(wire.CursorState)
// OnCursorShape receives the host's cursor image, whole, from a host
// that sends it; setting it asks the host for it.
OnCursorShape func(wire.CursorShape)
HandshakeTimeout time.Duration
SimulateLoss float64
// Route says how a live stream moves between the host's routes.
Route RouteConfig
// Calibrate dials a calibration session, which only a host with
// wire.FeatureCalibration accepts (transport.ErrCalibrationUnsupported
// otherwise); it takes no calibration kept for the host. Without it, a
// stream on a route the host was calibrated on asks for what that
// calibration picked wherever Overrides leave a knob auto.
Calibrate CalibrationMode
Logf func(format string, args ...any)
}
ClientConfig configures a Client.
type ClientStats ¶
type ClientStats struct {
Connected bool
HostName string
HostID string
Identity string
Addr string
Path string
Codec string
Chroma string
// Profile is what the host resolved the stream to, nil from an older
// host.
Profile *defaults.ResolvedProfile
Width int
Height int
FPS float64
Kbps float64
// DatagramBytes is the largest media datagram of the route, and
// MaxBitrateKbps the bitrate the host accepted on it.
DatagramBytes int
MaxBitrateKbps int
// RouteSwitches counts the moves to another route.
RouteSwitches uint64
EncodeMs float64
NetworkMs float64
RTTMs float64
DecodeMs float64
PresentMs float64
E2EMs float64
E2E Latency
Network Latency
// Encode, Decode and Present summarize the last frames' stage times.
Encode Latency
Decode Latency
Present Latency
// Glass is from the present call to the picture reaching the screen,
// and E2EGlass from the host's capture to that: what a viewer sees.
// Only a sink that presents on macOS reports them.
Glass Latency
E2EGlass Latency
// Phase is how the last pictures lined up with the client display's
// refreshes, and whether the system scanned them out directly or
// composited them; not Valid from a sink that cannot tell. PhaseSent
// says the host takes the reports, so it can steer by them.
Phase phaselock.Report
PhaseSent bool
// CaptureMs and HostEncodeMs split Encode where the host acquired the
// picture, as p50s; both are 0 from a host that does not send
// HostStats.
CaptureMs float64
HostEncodeMs float64
// FECParityPct is the parity share of the video datagrams received,
// estimated from datagram counts.
FECParityPct float64
LossPct float64
FramesReceived uint64
FramesLost uint64
FramesDropped uint64
// FramesPartial counts PyroWave frames shown with chunks missing.
FramesPartial uint64
SlicesRecovered uint64
SinkErrors uint64
// Keyframes counts the keyframes decoded, and FrameTimesMs holds the
// gaps between the last FrameTimeRing pictures decoded, oldest first.
Keyframes uint64
FrameTimesMs []float64
// HostPolicy is what the host's owner forces on clients, which beats
// this client's overrides; all auto from a host that sent none.
HostPolicy defaults.UserOverrides
// HostDisplays are the displays the host advertised, which
// SwitchDisplay moves the stream between; nil from an older host.
HostDisplays []defaults.HostDisplay
AudioBufferMs float64
AudioPackets uint64
InputSent uint64
Mic MicStats
Clipboard ClipboardStats
}
ClientStats is a live snapshot. Latencies are milliseconds; Encode is on the host's clock, the rest map host stamps onto the client's clock with the ping/pong offset.
type ClipboardConfig ¶
type ClipboardConfig struct {
// Send shares this device's clipboard changes with the peer.
Send bool
// Receive applies the peer's clipboard changes here.
Receive bool
}
ClipboardConfig is one side's clipboard sharing, per direction.
type ClipboardStats ¶
type ClipboardStats struct {
Sent, Received, Skipped uint64
}
ClipboardStats count items; contents are never logged or kept.
type GamepadHostSettings ¶
type GamepadHostSettings struct {
// Allow plugs clients' controllers into virtual ones; off, their
// gamepad input is dropped and nothing is plugged in.
Allow bool
// Type is what the virtual controllers appear as to games.
Type gamepad.PadType
}
GamepadHostSettings are what a host does with its clients' controllers.
func GamepadHostSettingsOf ¶
func GamepadHostSettingsOf(c config.GamepadConfig) GamepadHostSettings
GamepadHostSettingsOf reads gamepad.json's hosting half; an unknown virtual type is an Xbox 360 pad, as config.Validate allows none.
type GamepadProfile ¶
type GamepadProfile struct {
Calibration gamepad.Calibration
// Mappings are the saved mappings by lower-case SDL GUID; other
// controllers use their source's default.
Mappings map[string]gamepad.Mapping
}
GamepadProfile is the user's processing of their controllers.
type GamepadPump ¶
type GamepadPump struct {
// contains filtered or unexported fields
}
GamepadPump reads this device's controllers in one goroutine, which runs only while a stream is attached or Settings watches. It maps and calibrates each controller, sends a stream the states that change, plays the host's rumble, and keeps a snapshot for Settings to read each frame without touching the controllers itself. Safe from any goroutine.
func NewGamepadPump ¶
func NewGamepadPump(open func() (GamepadSource, error), onChange func(), logf func(string, ...any)) *GamepadPump
NewGamepadPump reads the controllers open gives it, opened on first use in the pump's goroutine. onChange hears the snapshot change while Settings watches.
func (*GamepadPump) Attach ¶
func (p *GamepadPump) Attach(send func(input.Event) error) uint64
Attach sends each controller's state to send, a stream's SendInput, from now on, as the pad index of its slot. It returns the id Detach takes.
func (*GamepadPump) CancelLearn ¶
func (p *GamepadPump) CancelLearn()
CancelLearn stops waiting for a control to move.
func (*GamepadPump) Close ¶
func (p *GamepadPump) Close()
Close stops the pump and closes its source.
func (*GamepadPump) Detach ¶
func (p *GamepadPump) Detach(id uint64)
Detach stops sending for attachment id, after letting go of every input it sent held and stopping the rumble it played.
func (*GamepadPump) Learn ¶
Learn waits up to ten seconds for a control of controller id to move, then gives done the binding for target. Another Learn replaces it.
func (*GamepadPump) Rumble ¶
func (p *GamepadPump) Rumble(r wire.Rumble)
Rumble plays a host's rumble on the controller in pad's slot, scaled by the calibration; a rumble older than the last one heard is dropped.
func (*GamepadPump) SetProfile ¶
func (p *GamepadPump) SetProfile(pr GamepadProfile)
func (*GamepadPump) TestRumble ¶
func (p *GamepadPump) TestRumble(id int, d time.Duration) error
TestRumble shakes controller id for d at the calibration's strength.
func (*GamepadPump) Watch ¶
func (p *GamepadPump) Watch() []PadSnapshot
Watch keeps the pump reading for a second more and returns its last snapshot, for a Settings page drawn each frame.
type GamepadSource ¶
type GamepadSource interface {
Controllers() []gamepad.ControllerInfo
Read(id int, raw *gamepad.RawState) error
Rumble(id int, large, small uint8) error
DefaultMapping(id int) gamepad.Mapping
}
GamepadSource reads a device's controllers; *gamepad.Capture is one.
func OpenGamepads ¶
func OpenGamepads() (GamepadSource, error)
OpenGamepads is NewGamepadPump's open for this device's controllers.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host serves one client at a time; a new client takes over.
func NewHost ¶
func NewHost(cfg HostConfig) (*Host, error)
NewHost loads or creates the host's identity and paired clients.
func (*Host) ConnectedClient ¶
ConnectedClient is the certificate fingerprint (hex) of the client streaming now, "" without one.
func (*Host) DiscoveryAddr ¶
DiscoveryAddr is the discovery socket's address, or nil when off.
func (*Host) Done ¶
func (h *Host) Done() <-chan struct{}
Done closes once the host stopped, by Stop or on its own; Err then says why it stopped on its own.
func (*Host) Fingerprint ¶
Fingerprint is the lowercase hex SHA-256 of the host certificate, which clients pin.
func (*Host) GamepadSettings ¶
func (h *Host) GamepadSettings() GamepadHostSettings
GamepadSettings are what the host does with clients' controllers now.
func (*Host) GamepadSlots ¶
func (h *Host) GamepadSlots() [gamepad.MaxVirtualPads]int
GamepadSlots are the client controller in each virtual controller slot, by its pad index, -1 for a free slot. They are all free until a client controller has plugged one in.
func (*Host) KickClient ¶
KickClient disconnects the client streaming now; it may connect again.
func (*Host) PairedClients ¶
func (h *Host) PairedClients() map[string]PairedClient
PairedClients lists the trusted client certificates by fingerprint.
func (*Host) ReorderGamepadSlot ¶
ReorderGamepadSlot swaps the client controllers in slots from and to, counted from 0, so a game's player order changes without a replug.
func (*Host) ResetGamepadSlots ¶
ResetGamepadSlots unplugs every virtual controller; the client's controllers take slots again in the order they next send input.
func (*Host) RevokeAllClients ¶
RevokeAllClients forgets every paired client and ends the stream.
func (*Host) RevokeClient ¶
RevokeClient forgets the paired client with this certificate fingerprint (hex) and ends its stream if it is connected; it needs the PIN to pair again.
func (*Host) SessionSettings ¶
func (h *Host) SessionSettings() SessionSettings
SessionSettings are the live ones.
func (*Host) SetClipboard ¶
func (h *Host) SetClipboard(c ClipboardConfig)
SetClipboard changes what the host shares, at once.
func (*Host) SetGamepadSettings ¶
func (h *Host) SetGamepadSettings(s GamepadHostSettings) error
SetGamepadSettings applies s at once. Turning gamepads off, or another virtual type, unplugs the virtual controllers: games see them go, and each client controller plugs in again, as the new type, on its next input.
func (*Host) SetName ¶
SetName renames the host in host.json and, at once, in its discovery replies, its next beacon and later handshakes. An empty name advertises the machine's own name.
func (*Host) SetSessionSettings ¶
func (h *Host) SetSessionSettings(s SessionSettings)
SetSessionSettings changes the session settings at once: the stay awake hold, the speakers of the stream running, and the idle timeout. Privacy mode takes effect from the next virtual display.
type HostConfig ¶
type HostConfig struct {
// ConfigDir holds host.json, the host identity and the paired clients.
// Empty uses config.Dir().
ConfigDir string
// Name overrides host.json's name for this run; SetName renames for
// good.
Name string
// ListenAddr is the QUIC control address; empty means ":41001".
ListenAddr string
// MediaPort is the UDP media port; 0 picks a free one per session.
MediaPort int
// DiscoveryAddr answers LAN probes and sends beacons; empty means
// ":41000", "off" disables discovery.
DiscoveryAddr string
Display string
// Adapter picks the encoding GPU by a substring of its name or its
// vendor ("NVIDIA", "AMD", "Intel"); empty encodes on the GPU that owns
// the frames.
Adapter string
// Codec and Chroma zero take the client's request, then HEVC 4:2:0.
Codec encode.Codec
Chroma encode.Chroma
Width int
Height int
FPS int
BitrateKbps int
Slices int
SubFrame bool
// Split is split-frame encode; SplitAuto applies encode.Config's rule
// on LAN paths and stays off elsewhere, where the extra bits cost more
// than the time saved.
Split encode.Split
// Synth streams a generated pattern at Width x Height and FPS on the
// Adapter GPU instead of a display, for benchmarks without a monitor.
Synth bool
// Policy is the host owner's overrides for clients that send their
// capabilities; it beats theirs. It is merged over host.json's policy.
// Codec through Split above apply to older clients only.
Policy defaults.UserOverrides
// VDDPrimary makes a session's virtual display the primary one, so
// games open on it; off, it extends the desktop.
VDDPrimary bool
// PIN is a fixed pairing PIN; empty generates one that changes after
// each pairing.
PIN string
NoAudio bool
// InjectInput replays client input as real OS events. Off by default:
// tests must never move the cursor of the machine they run on.
InjectInput bool
// NoTailscale turns off trusting devices of the same tailnet user.
NoTailscale bool
// OpenVideo replaces DefaultVideoOpener.
OpenVideo VideoOpener
// OpenVirtualDisplay replaces SudoVDA: it makes a session's virtual
// display for p, with a stable ID from seed.
OpenVirtualDisplay func(p VideoParams, seed []byte, primary bool) (VirtualDisplay, error)
// Capabilities replaces the probe of this machine's encoders, displays
// and virtual display driver. Without it, a host with its own
// OpenVideo does not offer wire.FeatureCapabilities: it cannot know
// what that pipeline does, so clients get the legacy negotiation.
Capabilities func() defaults.HostCapabilities
// OpenAudio replaces the platform loopback capturer.
OpenAudio func() (audio.Capturer, error)
// AudioExcludePIDs are processes, such as a voice chat app, whose
// audio the stream leaves out besides Planck's own (macOS only).
AudioExcludePIDs []int
// AudioExcludeApps are apps by name whose processes each session
// leaves out of the sound, as AudioExcludePIDs (macOS only).
AudioExcludeApps []string
// AudioDevice records one output device by audio.Device ID, Planck
// included (Windows); empty records everything but Planck.
AudioDevice string
// Session is what hosting does around a session; SetSessionSettings
// changes it live. System replaces the OS actions it takes.
Session SessionSettings
System SystemHooks
// NoMic refuses the client's microphone.
NoMic bool
// MicDevice picks the virtual input device the client's microphone
// plays into by a substring of its name; empty finds a known one.
MicDevice string
// FindVirtualMic and OpenMicSink replace audio.FindVirtualMic and
// audio.OpenMicSink.
FindVirtualMic func(want string) (audio.VirtualMic, error)
OpenMicSink func(audio.VirtualMic) (audio.MicSink, error)
// Clipboard is what the host shares: Send is host to client, Receive
// client to host.
Clipboard ClipboardConfig
// OpenClipboard replaces clipboard.Open.
OpenClipboard func() (clipboard.Board, error)
// Injector replaces the platform injector when InjectInput is set.
Injector input.Injector
// OnInput sees every valid input event, injected or not.
OnInput func(input.Event)
// OnSession hears each client's stream start and end, from the
// stream's goroutine.
OnSession func(SessionEvent)
// ReadCursor replaces cursor.Read, the host's system cursor that
// clients reading wire.CursorState hear of.
ReadCursor func() (cursor.State, error)
// ReadCursorShape replaces cursor.ReadShape, the image of the cursor
// clients reading wire.CursorShape see.
ReadCursorShape func(cursor.State) (cursor.Shape, error)
// WhoIs replaces the local Tailscale daemon client.
WhoIs WhoIser
// FECMinLoss keeps parity for at least this loss rate.
FECMinLoss float64
// SimulateLoss drops this fraction of outgoing media datagrams.
SimulateLoss float64
Logf func(format string, args ...any)
}
HostConfig configures a Host. The zero value of each field is usable; DefaultHostConfig has the production ports.
func DefaultHostConfig ¶
func DefaultHostConfig() HostConfig
DefaultHostConfig is the configuration of cmd/planck-host before flags.
func (HostConfig) FromStored ¶
func (c HostConfig) FromStored(s config.HostConfig) HostConfig
FromStored is c with the hosting settings host.json keeps: the ports and discovery, the capture display, the encoding GPU, the virtual display's primary flag, a fixed PIN, what clients may do, the sound and the virtual mic, and the session settings. NewHost reads the name, the policy and the trust settings itself.
type HostDeniedError ¶
HostDeniedError is a connect the host refused, which errors.Is finds as transport.ErrAuthDenied, with the fingerprint (hex) of the certificate the host presented: the one to check on both screens before pairing.
func (*HostDeniedError) Error ¶
func (e *HostDeniedError) Error() string
func (*HostDeniedError) Unwrap ¶
func (e *HostDeniedError) Unwrap() error
type HostStats ¶
type HostStats struct {
Connected bool
Client string
ClientAddr string
Path string
Video VideoInfo
FPS float64
SentKbps float64
TargetKbps int
EncodeMs Latency
RTTMs float64
// FECLossPct is the smoothed pre-FEC loss the parity is sized for, and
// FECParityPct the parity it added to the last frame.
FECLossPct float64
FECParityPct float64
Frames uint64
Keyframes uint64
Dropped uint64
PLIs uint64
AudioPackets uint64
Mic MicStats
Clipboard ClipboardStats
InputEvents uint64
InputErrors uint64
// Report is the client's last StatsReport.
Report wire.StatsReport
// Profile is what the session resolved to, nil for an older client;
// VirtualDisplay is the GDI name of its virtual display, if any.
Profile *defaults.ResolvedProfile
VirtualDisplay string
Sessions uint64
LastError string
}
HostStats is a snapshot of the host and its current client.
type Knobs ¶
type Knobs struct {
Codec, Chroma, BitDepth, Resolution, FPS, Slices string
VDD, VDDGPU, Split, Direct, VSync, Route string
PhaseLock string
// Display picks a host display by ID, and HDR10 is auto or off.
Display, HDR10 string
BitrateMbps int
}
Knobs are the stream override flags planck-host and planck-client share, as typed. An empty field was not given.
type Latency ¶
Latency is a rolling p50/p95/p99 summary in milliseconds.
func MeasureEncoder ¶
func MeasureEncoder(ctx context.Context, open VideoOpener, adapter string, frames int) (Latency, error)
MeasureEncoder encodes frames synthetic 1080p120 HEVC pictures on the GPU adapter names (a part of its name, as HostConfig.Adapter) and returns the encode time, from each picture's present to its packet. open nil is DefaultVideoOpener.
type MicStats ¶
type MicStats struct {
// Device is the host's virtual input device apps record the client
// from; Hint says why there is none.
Device string
Hint string
Muted bool
// Packets sent (client) or received (host); Concealed frames the host
// filled in for lost or late ones.
Packets uint64
Concealed uint64
}
MicStats describe the client's microphone on either end.
type NullSink ¶
type NullSink struct {
Units atomic.Uint64
Bytes atomic.Uint64
// OnUnit, when set, sees every access unit; au is valid only during the
// call.
OnUnit func(au []byte, pts int64)
}
NullSink accepts every access unit without decoding it.
type PadInjector ¶
type PadInjector interface {
SetGamepadType(gamepad.PadType)
VirtualPads() (VirtualPadSlots, error)
}
PadInjector is an injector that plugs gamepad events into virtual controllers. VirtualPads opens them on first use.
type PadSnapshot ¶
type PadSnapshot struct {
Info gamepad.ControllerInfo
// Raw is its inputs before mapping, and State after mapping and
// calibration: what a stream sends.
Raw gamepad.RawState
State gamepad.State
// Mapping is the one in use; Custom says it is a saved one.
Mapping gamepad.Mapping
Custom bool
// Learning is the input Learn waits on for this controller.
Learning gamepad.Input
IsLearning bool
}
PadSnapshot is one controller as the pump last read it.
type PairedClient ¶
type PairedClient struct {
Name string `json:"name"`
Method string `json:"method"`
PairedAt time.Time `json:"pairedAt"`
// LastSeen is when the client last connected; zero before the first
// connect after pairing was recorded.
LastSeen time.Time `json:"lastSeen,omitzero"`
}
PairedClient is one client certificate the host trusts.
func (PairedClient) TrustedViaTailnet ¶
func (c PairedClient) TrustedViaTailnet() bool
TrustedViaTailnet reports whether the client paired by its Tailscale identity rather than a PIN.
type PathInfoer ¶
type PathInfoer interface {
PathInfo(ctx context.Context, peerIP netip.Addr) (tailscale.PathInfo, error)
}
PathInfoer reports how the tailnet reaches a peer; *tailscale.Client is one.
type Quality ¶
type Quality struct {
Codec encode.Codec
Chroma encode.Chroma
Width int
Height int
FPS int
BitrateKbps int
Slices int
}
Quality is what the client asks the host to stream.
type RouteConfig ¶
type RouteConfig struct {
PreferLAN bool
// ProbeInterval is how often the LAN is probed from a tailnet route;
// zero is DefaultProbeInterval.
ProbeInterval time.Duration
// StallTimeout is how long a route may deliver nothing before the
// stream leaves it; zero is DefaultStallTimeout. The host pings four
// times a second, so a live route is never quiet this long.
StallTimeout time.Duration
}
RouteConfig tunes the route monitor that runs beside each stream. A stream whose route stalls or drops moves to another candidate that answers, and a stream on a tailnet route moves to the LAN when PreferLAN is set and a LAN candidate answers lanUpgradeAfter probes in a row. Each move dials the host again on the new route, so the media path takes that route's datagram size and bitrate ceiling, while the video sink, the decoder and audio play-out carry on.
type SessionEvent ¶
SessionEvent is a client's stream starting or ending: its codec and the kind of route, nothing of who the client is.
type SessionSettings ¶
type SessionSettings struct {
// StayAwake keeps the machine and its display awake while hosting.
StayAwake bool
// LockOnDisconnect locks the machine when a client leaves or is
// disconnected for idling; not when the host's own user ends it.
LockOnDisconnect bool
// MuteSpeakers mutes the default output while a client streams, and
// puts its mute back after.
MuteSpeakers bool
// PrivacyMode turns the machine's own displays off while a client
// streams from a virtual display, from the next one opened.
PrivacyMode bool
// IdleTimeout disconnects a client that sent no input for that long;
// 0 is never.
IdleTimeout time.Duration
}
SessionSettings are what hosting does around a client's session. Each is off in the zero value: tests must never lock, mute or blank the machine they run on. Host.SetSessionSettings changes them live.
type Sink ¶
Sink takes the client's access units in order. *player.Player is a Sink that decodes into a window surface; OpenDecodeSink decodes without showing; NullSink only counts. Submit returns decode.ErrNoFrame when the access unit gave no picture yet. The client calls Submit and Close from one goroutine; a sink bound to a UI thread hands the call over itself.
type SinkOpener ¶
SinkOpener opens the sink once the negotiated codec and size are known.
func NullSinkOpener ¶
func NullSinkOpener(s *NullSink) SinkOpener
NullSinkOpener returns s for every session.
type SystemHooks ¶
type SystemHooks struct {
KeepAwake func() (release func(), err error)
Lock func() error
MuteSpeakers func() (restore func() error, err error)
// Isolate leaves the display capture opens, by name, the only one on.
Isolate func(display string) (restore func() error, err error)
// AppPIDs finds the processes of HostConfig.AudioExcludeApps.
AppPIDs func(names []string) ([]int, error)
// SendSAS asks the system for Ctrl+Alt+Del, which injected keys
// cannot give.
SendSAS func() error
}
SystemHooks are the OS actions SessionSettings take. A nil field uses the platform's.
type Target ¶
type Target struct {
Candidates []discovery.Candidate
Addr string
// HostID and Fingerprint, when known from a beacon, key the pin and
// must match the host on first contact.
HostID string
Fingerprint string
}
Target says where to connect: discovery candidates, raced LAN direct first, then Tailscale direct, then DERP; or an explicit host:port, which is also the fallback when no candidate answers.
func TargetFromAnnouncement ¶
func TargetFromAnnouncement(a discovery.Announcement) Target
TargetFromAnnouncement connects to a host found by discovery.
type VideoInfo ¶
type VideoInfo struct {
Width, Height, FPS int
Codec encode.Codec
Chroma encode.Chroma
Adapter gpu.Adapter
Power gpu.PowerMode
// GPUPriority is the encoding device's GPU thread priority, -7 to 7.
GPUPriority int
Source string
// Display is where the captured display sits on the host's desktop,
// and Desktop the bounds of every display, for absolute pointer moves;
// zero where the source is no display or the platform does not say.
Display, Desktop input.Rect
}
VideoInfo describes an open pipeline.
type VideoOpener ¶
type VideoOpener func(VideoParams) (VideoPipe, error)
VideoOpener opens a pipeline. The host calls it once per client session and again after capture.ErrAccessLost.
type VideoParams ¶
type VideoParams struct {
Display string
// Adapter is a case-insensitive substring of the encoding GPU's name
// ("NVIDIA", "Radeon", "UHD"). Empty encodes on the GPU that owns the
// frames.
Adapter string
Codec encode.Codec
Chroma encode.Chroma
Width int
Height int
FPS int
BitrateKbps int
Slices int
SubFrame bool
Split encode.Split
// Synth replaces display capture with generated frames on Adapter's GPU.
Synth bool
// VirtualDisplay asks for a SudoVDA display of Width x Height at FPS
// on Adapter's GPU, captured in place of Display.
VirtualDisplay bool
// ScalePct is the Windows display scale a virtual display takes, in
// percent: the client display's (100 for a 1x display).
ScalePct int
// ChunkLen is the shard size PyroWave frames its chunks in.
ChunkLen int
// HDR10 streams an HDR desktop as BT.2020 PQ, when capture delivers
// it 10-bit; an 8-bit capture encodes SDR.
HDR10 bool
}
VideoParams is what the host asks a video pipeline for once a client's session is negotiated.
type VideoPipe ¶
type VideoPipe interface {
// Next waits up to timeout for the next picture and encodes it into dst.
// captureTS is when the picture was presented, on transport.Mono.
// capture.ErrTimeout means the screen did not change; capture.ErrAccessLost
// means the pipe must be closed and opened again; encode.ErrDropped means
// the encoder skipped the picture.
Next(timeout time.Duration, forceKey bool, dst []byte) (pkt encode.Packet, captureTS int64, err error)
SetBitrate(kbps int) error
// InvalidateRefs stops prediction from the picture with this PTS and
// later ones; encode.ErrUnsupported means only a keyframe recovers.
InvalidateRefs(pts int64) error
Info() VideoInfo
Close() error
}
VideoPipe is one open capture-to-bitstream pipeline.
func DefaultVideoOpener ¶
func DefaultVideoOpener(p VideoParams) (VideoPipe, error)
DefaultVideoOpener captures a display, or the synthetic pattern when p.Synth is set, and encodes on the GPU that holds the frames.
type VirtualDisplay ¶
type VirtualDisplay interface {
// Name is the display capture opens: a GDI name on Windows.
Name() string
// Resize gives the display a new size; on an error it is gone.
Resize(w, h int) error
Close() error
}
VirtualDisplay is a session's virtual display, which the pipeline captures.
type VirtualPadSlots ¶
type VirtualPadSlots interface {
Slots() [gamepad.MaxVirtualPads]int
ResetSlots() error
ReorderSlot(from, to int) error
SetRumbleHandler(gamepad.RumbleFunc)
}
VirtualPadSlots are an injector's plugged-in virtual controllers, as *gamepad.VirtualPads keeps them.