defaults

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 7 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 defaults picks a session's stream settings from what the host, the client and the route between them can do, with user overrides on top. Resolve is pure: no I/O, no clock, no map iteration.

Index

Constants

View Source
const (
	MinCustomWidth  = 640
	MaxCustomWidth  = 7680
	MinCustomHeight = 360
	MaxCustomHeight = 4320
	MaxBitrateMbps  = 3000
)
View Source
const (
	APINVENC        = "NVENC"
	APIAMF          = "AMF"
	APIOneVPL       = "oneVPL"
	APIVAAPI        = "VA-API"
	APIVideoToolbox = "VideoToolbox"
	APIPyroWave     = "PyroWave"
)
View Source
const Auto = "auto"
View Source
const MaxDisplayIDLen = 256

MaxDisplayIDLen bounds UserOverrides.Display.

Variables

This section is empty.

Functions

func ViewSize

func ViewSize(w, h int) (int, int)

ViewSize is the virtual display size for a w x h pixel stream window: even, and within the custom size bounds.

Types

type BitDepthPref

type BitDepthPref string // auto | 8 | 10

Every knob is a string enum; "" and "auto" both mean auto.

type ChromaPref

type ChromaPref string // auto | 420 | 444

Every knob is a string enum; "" and "auto" both mean auto.

type ClientCapabilities

type ClientCapabilities struct {
	OS       string        `json:"os"`
	Display  ClientDisplay `json:"display"`
	Decoders []CodecCap    `json:"decoders"` // hardware only, from the startup probe
	// Present10Bit: the client surface can show BGR10A2 (WS2).
	Present10Bit  bool `json:"present10Bit"`
	DirectDisplay bool `json:"directDisplay"` // the platform has a full-screen direct path (macOS WS2)
	// PresentHDR10: the client presents BT.2020 PQ pictures as HDR on a
	// display whose HDR is set (macOS EDR).
	PresentHDR10 bool `json:"presentHDR10,omitempty"`
	Link         Link `json:"link"`
}

type ClientDisplay

type ClientDisplay struct {
	WidthPx  int     `json:"widthPx"` // native backing pixels (3024x1964 on a 14" MacBook Pro)
	HeightPx int     `json:"heightPx"`
	Scale    float64 `json:"scale"` // backing scale factor
	MaxHz    int     `json:"maxHz"` // ProMotion: 120
	MinHz    int     `json:"minHz"` // ProMotion: 24
	HDR      bool    `json:"hdr"`
	// ViewWidthPx and ViewHeightPx are the stream window's size in pixels;
	// 0 = no window, as a headless client. A virtual display with
	// Resolution auto takes this size.
	ViewWidthPx  int `json:"viewWidthPx,omitempty"`
	ViewHeightPx int `json:"viewHeightPx,omitempty"`
}

type Codec

type Codec uint8

Codec values equal pkg/wire Codec values.

const (
	CodecH264 Codec = iota + 1
	CodecHEVC
	CodecAV1
	CodecPyroWave
)

func (Codec) String

func (c Codec) String() string

type CodecCap

type CodecCap struct {
	Codec     Codec `json:"codec"`
	TenBit    bool  `json:"tenBit"`
	Chroma444 bool  `json:"chroma444"` // at the depths TenBit allows
	MaxWidth  int   `json:"maxWidth"`  // 0 = no limit
	MaxHeight int   `json:"maxHeight"` // 0 = no limit
}

type CodecPref

type CodecPref string // auto | pyrowave | hevc | av1 | h264

Every knob is a string enum; "" and "auto" both mean auto.

type Decision

type Decision struct {
	Knob   string `json:"knob"` // "codec", "fps", ...
	Value  string `json:"value"`
	Source Source `json:"source"`
	Why    string `json:"why"` // one line for the UI: "serialization 9.1 ms > 1.7 ms budget"
}

type EncoderCap

type EncoderCap struct {
	Adapter  gpu.Adapter `json:"adapter"`
	API      string      `json:"api"`     // "NVENC" | "AMF" | "oneVPL" | "VideoToolbox" | "PyroWave"
	Codecs   []CodecCap  `json:"codecs"`  // sorted by Codec
	Engines  int         `json:"engines"` // hardware encode engines (NVENC split needs >= 2)
	SubFrame bool        `json:"subFrame"`
	// MaxPixelRate is width*height*fps the encoder sustains in real time.
	// The startup probe measures it. The seed table in resolve.go is used
	// until then.
	MaxPixelRate int64 `json:"maxPixelRate"`
	// EncodeP50Micros is the startup probe's 1080p p50 encode time. 0 = not measured.
	EncodeP50Micros int  `json:"encodeP50Micros"`
	DrivesDisplay   bool `json:"drivesDisplay"` // has an active physical output
}

type FECProfile

type FECProfile struct {
	Adaptive              bool `json:"adaptive"`
	MinParityPercent      int  `json:"minParityPercent"`
	KeyframeParityPercent int  `json:"keyframeParityPercent"`
	CriticalParityPercent int  `json:"criticalParityPercent"` // PyroWave critical slices; at least 2 shards
}

type FPSPref

type FPSPref string // auto | 60 | 120 | 144 | 240

Every knob is a string enum; "" and "auto" both mean auto.

type HostCapabilities

type HostCapabilities struct {
	OS       string        `json:"os"`
	Encoders []EncoderCap  `json:"encoders"` // one per adapter with a working backend; PyroWave is its own entry per adapter
	Displays []HostDisplay `json:"displays"`
	// PinnedDisplay is HostConfig.Display. If it is set, physical capture wins over VDD.
	PinnedDisplay string        `json:"pinnedDisplay,omitempty"`
	VDD           VDDCap        `json:"vdd"`
	Link          Link          `json:"link"`
	Forced        UserOverrides `json:"forced"` // host owner's policy; beats the client
}

type HostDisplay

type HostDisplay struct {
	ID string `json:"id"` // GDI name or CGDirectDisplayID
	// Name is what the host's OS calls the display, "" when it has no name.
	Name      string   `json:"name,omitempty"`
	Width     int      `json:"width"`
	Height    int      `json:"height"`
	RefreshHz int      `json:"refreshHz"`
	Adapter   gpu.LUID `json:"adapter"`
	Primary   bool     `json:"primary"`
	// HDR: the desktop on this display is in HDR10 (BT.2020 PQ), which
	// capture can take as 10-bit.
	HDR bool `json:"hdr,omitempty"`
}
type Link struct {
	Wired     bool `json:"wired"`     // Ethernet or Thunderbolt Ethernet, not Wi-Fi
	SpeedMbps int  `json:"speedMbps"` // 0 = unknown
}

Link is one end's interface toward the peer.

type ReceiveQueue added in v0.2.0

type ReceiveQueue struct {
	Bytes     int `json:"bytes"`
	DrainMbps int `json:"drainMbps"`
}

ReceiveQueue is a receiver that keeps Bytes of a burst and drains the rest at no more than DrainMbps (transport.ReceiveQueue). Bytes 0 is a receiver calibration saw drop nothing of any burst it sent.

type ResolutionPref

type ResolutionPref string // auto | 1080p | 1440p | 4k | custom

Every knob is a string enum; "" and "auto" both mean auto.

type ResolvedProfile

type ResolvedProfile struct {
	Route       RouteKind `json:"route"`
	MaxDatagram int       `json:"maxDatagram"` // 1452 or 1152
	LinkMbps    int       `json:"linkMbps"`    // min of both ends, 0 = unknown
	Wired       bool      `json:"wired"`       // both ends

	EncodeAdapter  gpu.Adapter `json:"encodeAdapter"`
	EncoderAPI     string      `json:"encoderAPI"`
	VirtualDisplay bool        `json:"virtualDisplay"`
	CaptureDisplay string      `json:"captureDisplay,omitempty"` // physical capture only

	Codec     Codec `json:"codec"`
	Chroma444 bool  `json:"chroma444"`
	BitDepth  int   `json:"bitDepth"` // 8 | 10
	// HDR10 is a 10-bit BT.2020 PQ stream from an HDR desktop.
	HDR10  bool `json:"hdr10,omitempty"`
	Width  int  `json:"width"`
	Height int  `json:"height"`
	FPS    int  `json:"fps"`

	BitrateKbps    int `json:"bitrateKbps"`    // start
	MaxBitrateKbps int `json:"maxBitrateKbps"` // ratectl ceiling

	Slices   int  `json:"slices"` // codec slices; PyroWave: 0 (its packetizer slices itself)
	SubFrame bool `json:"subFrame"`
	Split    bool `json:"split"` // NVENC 2-engine split

	DirectDisplay bool `json:"directDisplay"` // allowed; the client applies it only in full screen with the drawer closed
	VSync         bool `json:"vsync"`
	// PhaseLock: the client reports its display's phase and the host
	// steers its frames by it, where its source can move them.
	PhaseLock bool `json:"phaseLock,omitempty"`

	FEC FECProfile `json:"fec"`

	Decisions []Decision `json:"decisions"` // in resolve order
	Warnings  []string   `json:"warnings"`  // overrides that fell back
}

func Resolve

func Resolve(host HostCapabilities, client ClientCapabilities, route RouteInfo, overrides UserOverrides) ResolvedProfile

Resolve is pure. Precedence per knob: host.Forced > client override > auto. An override the hardware or route cannot honour falls back to the auto value with a SourceFallback Decision and a Warning. Resolve never errors: HEVC 4:2:0 8-bit at the capture size is always reachable.

type RouteInfo

type RouteInfo struct {
	Kind RouteKind `json:"kind"`
	// LANDatagram: both ends agreed on wire.MaxLANDatagram (1452).
	LANDatagram bool `json:"lanDatagram"`
	RTTMicros   int  `json:"rttMicros"`
	ProbedMbps  int  `json:"probedMbps"` // 0 = not probed
	// ReceiveQueue is the client's path below its socket as calibration
	// measured it on this route; nil when not calibrated.
	ReceiveQueue *ReceiveQueue `json:"receiveQueue,omitempty"`
}

type RouteKind

type RouteKind uint8
const (
	RouteLAN             RouteKind = iota + 1 // discovery.PathLANDirect
	RouteTailscaleDirect                      // discovery.PathTailscaleDirect
	RouteWAN                                  // discovery.PathTailscaleDERP, or any other path
)

func (RouteKind) String

func (k RouteKind) String() string

type RoutePref

type RoutePref string // auto | lan | tailscale

Every knob is a string enum; "" and "auto" both mean auto.

type SlicesPref

type SlicesPref string // auto | 1 | 4 | 8

Every knob is a string enum; "" and "auto" both mean auto.

type Source

type Source uint8
const (
	SourceAuto     Source = iota + 1
	SourceUser            // client override applied
	SourceHost            // host Forced applied
	SourceFallback        // override asked for something impossible; auto value used
)

type Toggle

type Toggle string // auto | on | off

Every knob is a string enum; "" and "auto" both mean auto.

const (
	ToggleOn  Toggle = "on"
	ToggleOff Toggle = "off"
)

type UserOverrides

type UserOverrides struct {
	Codec        CodecPref      `json:"codec,omitempty"`
	Chroma       ChromaPref     `json:"chroma,omitempty"`
	BitDepth     BitDepthPref   `json:"bitDepth,omitempty"`
	Resolution   ResolutionPref `json:"resolution,omitempty"`
	CustomWidth  int            `json:"customWidth,omitempty"`  // with Resolution "custom": even, 640..7680
	CustomHeight int            `json:"customHeight,omitempty"` // even, 360..4320
	FPS          FPSPref        `json:"fps,omitempty"`
	BitrateMbps  int            `json:"bitrateMbps,omitempty"` // 0 = auto, else 1..3000

	VirtualDisplay Toggle `json:"virtualDisplay,omitempty"`
	// VirtualDisplayGPU picks the GPU that renders the virtual display and
	// encodes (they must match for zero copy): a substring of the adapter
	// name, matched case-insensitively ("4080", "Radeon"). "" = auto. A LUID
	// is not stored because it changes on every boot.
	VirtualDisplayGPU  string     `json:"virtualDisplayGPU,omitempty"`
	SubFrameSlices     SlicesPref `json:"subFrameSlices,omitempty"`
	NVENC2EngineSplit  Toggle     `json:"nvenc2EngineSplit,omitempty"`
	MetalDirectDisplay Toggle     `json:"metalDirectDisplay,omitempty"`
	VSyncMode          Toggle     `json:"vsyncMode,omitempty"` // auto = off
	// PhaseLock lets the host move its frames' phase so that they reach
	// the client a little before its display refreshes (pkg/phaselock).
	PhaseLock   Toggle    `json:"phaseLock,omitempty"` // auto = on
	RoutePolicy RoutePref `json:"routePolicy,omitempty"`
	// Display is the host display to capture, by HostDisplay.ID; "" lets
	// the host choose. Picking one streams that physical display, not a
	// virtual one.
	Display string `json:"display,omitempty"`
	HDR10   Toggle `json:"hdr10,omitempty"` // auto | off
}

func Merge

func Merge(base, top UserOverrides) UserOverrides

Merge returns base with every non-auto field of top replacing base's. CustomWidth and CustomHeight travel with Resolution.

func (UserOverrides) Normalize

func (o UserOverrides) Normalize() UserOverrides

Normalize turns every "" knob into "auto".

func (UserOverrides) Validate

func (o UserOverrides) Validate() error

type VDDCap

type VDDCap struct {
	Available           bool   `json:"available"` // driver present AND openable by this user
	Protocol            string `json:"protocol"`  // "0.2.1"
	CanSetRenderAdapter bool   `json:"canSetRenderAdapter"`
	RegistryGPU         string `json:"registryGPU"` // HKLM gpuName, information only
}

Jump to

Keyboard shortcuts

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