player

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 18 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 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

View Source
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

func New(surf *gpusurface.Surface, dec decode.Decoder, keep int) *Player

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

func Open(surf *gpusurface.Surface, cfg decode.Config, keep int) (*Player, error)

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

func (p *Player) Close() error

Close stops the present thread, gives every picture it holds back and closes the decoder. The surface stays open, without the HUD.

func (*Player) Format

func (p *Player) Format() (capture.Format, int, int)

Format is the format and visible size of the pictures decoded last.

func (*Player) Resize

func (p *Player) Resize(w, h int) error

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

func (p *Player) SetHUD(st HUDState)

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

func (p *Player) SetObserver(obs Observer)

SetObserver sets obs to see the present thread's work. Call it before the first Submit.

func (*Player) Stats

func (p *Player) Stats() Stats

func (*Player) Submit

func (p *Player) Submit(au []byte, pts int64) (Timing, error)

Submit decodes one access unit and leaves its picture for the present thread, giving back a picture still waiting there unshown. Its Timing has no Present: the Observer sees that.

func (*Player) Timings

func (p *Player) Timings() []Timing

Timings returns the recorded timings, oldest first.

type Signal

type Signal uint8

Signal is the state of the stream's path, the colour of the HUD's dot.

const (
	SignalDirect Signal = iota + 1
	SignalRelay
	SignalFault
)

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.

type Timing

type Timing struct {
	PTS int64
	// Decode is from Decode's call to the picture being ready; Present is
	// the time Present took to hand it to the GPU and the compositor.
	Decode, Present time.Duration
}

Timing is one picture's way through the player.

Jump to

Keyboard shortcuts

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