player

package module
v0.0.0-...-a4e7972 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 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 plays goav media in a window, with pure-Go windowing and audio output (Ebitengine and oto: no cgo on macOS, Windows, or Linux).

The speaker is the master clock. Its played position is the clock the whole task runs on (runconfig.WithClock), so the realtime pacer delivers media exactly as fast as it is heard; video is presented against the heard audio position, late frames are dropped, early ones waited for. Pause, seek, and rate are the task's own controls.

w := player.New(player.Title("demo"))
rt := bundle.MustNew(w.RuntimeOption())
in := goav.Read("in.webm", f)
task, err := rt.Build(ctx,
	in.Video().Decode().To(w.Destination()),
	in.Audio().Decode().Resample(48000, 2).To(w.Destination()))
...
err = w.Run(ctx, task) // on the main goroutine

In a launch program the window is the play element (Window.Element): goav run 'file in.webm ! video ! decode ! play; file in.webm ! audio ! decode ! play'.

On Linux the window and the speaker load libX11/libGL and PulseAudio or libasound at run time; without an audio device playback continues silently on a free-running clock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Window)

Option configures a Window.

func Latency

func Latency(latency time.Duration) Option

Latency sets how much audio is buffered before playback starts and after a seek (default 200ms): more absorbs decode hiccups, less starts sooner.

func Size

func Size(width, height int) Option

Size sets the initial window size; without it the window takes the size of the first video frame.

func Title

func Title(title string) Option

Title sets the window title prefix (default "goav").

type Stats

type Stats struct {
	// Position is the media time being heard (without audio: shown).
	Position time.Duration
	// Presented and Dropped count video frames shown and discarded late.
	Presented, Dropped uint64
	// Underruns counts times the audio queue ran dry mid-playback.
	Underruns uint64
	// AVOffset is the heard position minus the last shown frame's time
	// (positive: the picture was late); MaxAVOffset is the largest magnitude.
	AVOffset, MaxAVOffset time.Duration
}

Stats is a point-in-time view of playback.

type Task

type Task interface {
	Run(context.Context) error
	Close() error
	Pause(context.Context) error
	Resume(context.Context) error
	Control(context.Context, control.Control) error
}

Task is the narrow view of a *goav.Task that a playback Window drives.

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window is a playback window and the speaker it plays through. Its Destination takes decoded video and audio; its Clock is the speaker's hardware clock, which the task should run on; Run shows the window.

func New

func New(opts ...Option) *Window

New prepares a window. Nothing opens until Run: building the task first is free, and a program that never routes to the window costs nothing.

func (*Window) Clock

func (w *Window) Clock() av.Clock

Clock is the speaker's clock. Build the runtime with runconfig.WithClock(w.Clock()) and runconfig.WithRealtime(true) so the task timeline runs in the speaker's time: media is then delivered exactly as fast as it is heard, and the task's Pause, Rate, and Seek drive playback.

func (*Window) Destination

func (w *Window) Destination() goav.Destination

Destination is the window as a goav destination: route decoded video and decoded audio to the same value and they play together. Audio of any rate and channel count is accepted (s16 or f32, interleaved); .Resample(48000, 2) before it gives the best quality.

func (*Window) Element

func (w *Window) Element() launch.Element

Element is the launch element "play [title=T] [size=WxH]": a destination that plays what reaches it in this window. Every use in a program is the same window, so video and audio statements ending in play play together.

func (*Window) Run

func (w *Window) Run(ctx context.Context, task Task) error

Run opens the speaker and the window, runs task, and returns when the media has played out, the window is closed, or ctx ends; closing the window closes the task. Space pauses, the arrows seek (←/→ 5s, ↓/↑ 30s), [ and ] change the rate, f toggles full screen, i the overlay, and q or Esc quits — all through the task's own Pause, Resume, and Control.

Run must be called from the main goroutine (the windowing systems require it) and at most once per process (one audio device context per process).

func (*Window) RuntimeOption

func (w *Window) RuntimeOption() runconfig.Option

RuntimeOption returns a single runtime option that paces a task against this window's hardware speaker clock in realtime mode:

rt := bundle.MustNew(w.RuntimeOption())

func (*Window) Stats

func (w *Window) Stats() Stats

Stats reports playback counters.

func (*Window) Used

func (w *Window) Used() bool

Used reports whether anything took the window's Destination (directly or through the play element), so a host knows whether to Run it.

Directories

Path Synopsis
internal
engine
Package engine is the player's media core, free of any window or audio backend: the audio renderer the device pulls from, the device clock, the audio-mastered video presenter, the goav sink that feeds them, and the Y'CbCr conversion.
Package engine is the player's media core, free of any window or audio backend: the audio renderer the device pulls from, the device clock, the audio-mastered video presenter, the goav sink that feeds them, and the Y'CbCr conversion.

Jump to

Keyboard shortcuts

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