Documentation
¶
Overview ¶
Package player shows a stream of encoded pictures in a window: a hardware decoder on the window surface's own GPU device, each picture presented from the decoder's texture with no copy.
Decoding and presenting run on different threads. Submit decodes every access unit on the caller's goroutine, so reference pictures stay intact, and leaves the picture in a mailbox of one; the player's present thread shows the newest picture in it. A present that waits for a drawable never holds up decoding, and a picture superseded before it was shown goes straight back to the decoder instead of queueing.
Index ¶
- Constants
- type GPUObserver
- type HUDState
- type Observer
- type Pacing
- type Player
- func (p *Player) Close() error
- func (p *Player) Format() (capture.Format, int, int)
- func (p *Player) Phase() phaselock.Report
- func (p *Player) ResetPhase()
- func (p *Player) Resize(w, h int) error
- func (p *Player) SetHUD(st HUDState)
- func (p *Player) SetObserver(obs Observer)
- func (p *Player) SetPacing(m Pacing)
- func (p *Player) Stats() Stats
- func (p *Player) Submit(au []byte, pts int64) (Timing, error)
- func (p *Player) Timings() []Timing
- type Signal
- type Stats
- type Timing
Constants ¶
const ( HUDPillTopPt = 12 HUDPillHeightPt = 32 HUDPillRadiusPt = 16 HUDPillPadPt = 12 )
Pill geometry, in points, shared with the window's own HUD so that the two pills lie exactly on one another.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GPUObserver ¶ added in v0.2.0
GPUObserver is an Observer that also hears, where the platform tells (macOS), how long before reaching the screen the GPU finished drawing each picture.
type HUDState ¶
type HUDState struct {
Visible bool
Signal Signal
Route string // "LAN", "Tailscale", "Relay"
FPS float64
LatencyMs float64 // glass to glass p50
Mbps float64
Codec string // "PyroWave", "HEVC 10-bit", ...
}
HUDState is what the HUD pill shows.
type Observer ¶
type Observer interface {
// Presented runs on the present thread after each present, with the
// present's error.
Presented(t Timing, err error)
// Glass runs when a presented picture reached the screen, on the
// platform's thread: glass is from the present call to the screen,
// since how long before this call that was. Only macOS reports it,
// and not for pictures a newer one replaced first.
Glass(pts int64, glass, since time.Duration)
}
Observer sees the present thread's work. Its methods must return quickly.
type Pacing ¶ added in v0.2.0
type Pacing uint8
Pacing is when the present thread shows each decoded picture.
const ( // PaceLowestLatency shows each picture as soon as it is decoded; one // that comes within a refresh of the last replaces it unshown. PaceLowestLatency Pacing = iota // PaceSmooth shows one picture a display refresh, in step with it: a // picture that comes within a refresh of the last waits for the next // refresh instead of replacing it. While pictures come in pairs that // costs up to a refresh of latency, and a backlog that lasts // catchUpTicks drops a picture to win it back. Where the refresh times // are not known (Windows) or not regular (a variable refresh rate) it // is PaceLowestLatency. PaceSmooth )
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player decodes and presents. Submit, Format and Close are called from one goroutine; Resize, Stats and Timings from any.
func New ¶
New shows pictures from dec, which must decode onto surf's device (see Open), in surf, from a present thread of its own. It keeps the timing of the last keep pictures shown.
func Open ¶
Open makes the platform's hardware decoder on surf's device and a player of it. Close the player, then the surface.
func (*Player) Close ¶
Close stops the present thread, gives every picture it holds back and closes the decoder. The surface stays open, without the HUD.
func (*Player) Phase ¶ added in v0.2.0
Phase reports how the last pictures that reached the screen lined up with its refreshes, and whether it showed them directly: see phaselock.Estimator. Call it at a steady rate, as a few times a second.
func (*Player) ResetPhase ¶ added in v0.2.0
func (p *Player) ResetPhase()
ResetPhase starts the phase and the scan-out mode afresh, from the pictures presented phaseSettle after it. Call it when the surface changes how it reaches the screen, as gpusurface.Surface.SetDirect does.
func (*Player) Resize ¶
Resize resizes the surface to w x h pixels (zero: the window's size on Windows) on the present thread and shows the current picture again at the new size. It returns once done.
func (*Player) SetHUD ¶
SetHUD shows st in the pill drawn into the frames, or hides it. A change of Visible shows at once; other changes at most four times a second, the newest winning. Call it from any goroutine.
func (*Player) SetObserver ¶
SetObserver sets obs to see the present thread's work. Call it before the first Submit.
func (*Player) SetPacing ¶ added in v0.2.0
SetPacing chooses when pictures are shown; PaceLowestLatency at first.
type Signal ¶
type Signal uint8
Signal is the state of the stream's path, the colour of the HUD's dot.
type Stats ¶
type Stats struct {
// Pictures counts the pictures decoded.
Pictures int
// NoPicture counts access units that gave no picture in time.
NoPicture int
// FormatChanges counts changes of format or size, the first included.
FormatChanges int
// Presented counts the pictures shown; Superseded those a newer
// picture replaced in the mailbox before they were shown.
Presented, Superseded int
PresentErrors int
}
Stats counts what the player did.