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 HUDState
- type Observer
- type Player
- func (p *Player) Close() error
- func (p *Player) Format() (capture.Format, int, int)
- func (p *Player) Resize(w, h int) error
- func (p *Player) SetHUD(st HUDState)
- func (p *Player) SetObserver(obs Observer)
- 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 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 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) 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.
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.