player

package
v0.0.0-...-bf6d460 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: GPL-3.0 Imports: 11 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer contains piece of decoded PCM data with some metadata attached.

type BufferRing

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

BufferRing is a ring buffer organized by the list of fixed-size reusable buffers. BufferRing is a thread safe, however it is designed to work with only one writer and one reader. This schema suits well for audio decode-output loop when there is the only one decoder thread and one output thread that handles it.

func NewBufferRing

func NewBufferRing(bufsz int, nbuf int) *BufferRing

NewBufferRing creates new BufferRing instance managing `nbuf` buffers of `bufsz` bytes each. So the total amount of data which can be stored equals to `bufsz * nbuf` bytes.

func (*BufferRing) Close

func (r *BufferRing) Close(flush bool)

Close closes BufferRing. Consumer is still allowed to consume all data contained by BufferRing as usual. After that all next Peek() calls will return nil signalling end of the data. `flush` flag discards unconsumed data in the ring.

func (*BufferRing) Offer

func (r *BufferRing) Offer(b *Buffer)

Offer marks buffer as containing data and available for the consumer. Panics if BufferRing is closed.

func (*BufferRing) OfferFree

func (r *BufferRing) OfferFree(b *Buffer)

OfferFree marks buffer as free. After the buffer is freed it becomes available to be returned by PeekFree().

func (*BufferRing) Open

func (r *BufferRing) Open()

Open opens BufferRing and make it available for the usage.

func (*BufferRing) Peek

func (r *BufferRing) Peek() *Buffer

Peek returns the first non-emtpy buffer with data. If no buffer is available Peek blocks and waits for the one. Returns nil if cache is closed.

func (*BufferRing) PeekFree

func (r *BufferRing) PeekFree() *Buffer

PeekFree returns the first empty buffer. If no empty buffer is available PeekFree blocks till it will become one. Retruns nil if BufferRing is closed.

type Engine

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

Engine is a core of playing process. It manages decoding source file and pass decoded samples to the output driver.

func NewEngine

func NewEngine(fmts []format.Format, output Output) *Engine

func (*Engine) Close

func (e *Engine) Close() error

func (*Engine) Next

func (e *Engine) Next() error

func (*Engine) Pause

func (e *Engine) Pause() error

func (*Engine) Play

func (e *Engine) Play(plist *Playlist, pos int) error

func (*Engine) Prev

func (e *Engine) Prev() error

func (*Engine) Seek

func (e *Engine) Seek(pos int, rel bool) error

func (*Engine) SetStatusHandler

func (e *Engine) SetStatusHandler(h func(*Status))

func (*Engine) Start

func (e *Engine) Start()

func (*Engine) Status

func (e *Engine) Status() *Status

func (*Engine) Stop

func (e *Engine) Stop() error

func (*Engine) Volume

func (e *Engine) Volume(vol int) error

type Event

type Event interface {
	Name() string
	Serialize() []serialize.Serializable
}

type Output

type Output interface {
	// Open opens output audio device.
	Open() error
	// Set new value for sample rate parameter.
	// TODO: Handle error by client.
	SetSampleRate(rate int) error
	// Set number of channels.
	// TODO: Handle error by client.
	SetChannels(channels int) error
	// Write new portion of data into buffer.
	Write(buf []byte) (written int, err error)
	// Reset empties ouput buffer.
	Flush() error
	// Pause pauses or resumes playback process.
	Pause() error
	// Close closes output audio device.
	Close() error
	// Returns current volume level.
	Volume() (int, error)
	// Set output volume level.
	SetVolume(vol int) error
}

Output interface represents audio autput driver (ALSA, OSS, ...).

type Player

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

func New

func New(fmts []format.Format, output Output) *Player

func (*Player) Append

func (p *Player) Append(name string, path *vfs.Path) error

func (*Player) Clear

func (p *Player) Clear(name string) error

func (*Player) Close

func (p *Player) Close() error

func (*Player) Create

func (p *Player) Create(name string) error

func (*Player) Delete

func (p *Player) Delete(name string) error

func (*Player) Events

func (p *Player) Events() <-chan Event

func (*Player) Next

func (p *Player) Next() error

func (*Player) Pause

func (p *Player) Pause() error

func (*Player) Play

func (p *Player) Play(path *vfs.Path) error

func (*Player) Playlist

func (p *Player) Playlist(name string) (*Playlist, error)

func (*Player) Playlists

func (p *Player) Playlists() []*Playlist

func (*Player) Prev

func (p *Player) Prev() error

func (*Player) Rename

func (p *Player) Rename(from string, to string) error

func (*Player) Seek

func (p *Player) Seek(pos int, rel bool) error

func (*Player) SetVolume

func (p *Player) SetVolume(vol int, rel bool) error

func (*Player) Status

func (p *Player) Status() *Status

func (*Player) Stop

func (p *Player) Stop() error

func (*Player) Volume

func (p *Player) Volume() int

type Playlist

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

func NewPlaylist

func NewPlaylist(name string) *Playlist

func (*Playlist) Append

func (pl *Playlist) Append(tracks ...*vfs.Track) *Playlist

func (*Playlist) Clear

func (pl *Playlist) Clear() *Playlist

func (*Playlist) Duration

func (pl *Playlist) Duration() int

func (*Playlist) Get

func (pl *Playlist) Get(i int) *vfs.Track

func (*Playlist) Len

func (pl *Playlist) Len() int

func (*Playlist) Name

func (pl *Playlist) Name() string

func (*Playlist) Serialize

func (pl *Playlist) Serialize() string

func (*Playlist) SetName

func (pl *Playlist) SetName(name string) *Playlist

func (*Playlist) Tracks

func (pl *Playlist) Tracks() []*vfs.Track

type PlistCreateEvent

type PlistCreateEvent struct {
	Plist string
}

func (*PlistCreateEvent) Name

func (e *PlistCreateEvent) Name() string

func (*PlistCreateEvent) Serialize

func (e *PlistCreateEvent) Serialize() []serialize.Serializable

type PlistDeleteEvent

type PlistDeleteEvent struct {
	Plist string
}

func (*PlistDeleteEvent) Name

func (e *PlistDeleteEvent) Name() string

func (*PlistDeleteEvent) Serialize

func (e *PlistDeleteEvent) Serialize() []serialize.Serializable

type PlistRenameEvent

type PlistRenameEvent struct {
	From string
	To   string
}

func (*PlistRenameEvent) Name

func (e *PlistRenameEvent) Name() string

func (*PlistRenameEvent) Serialize

func (e *PlistRenameEvent) Serialize() []serialize.Serializable

type State

type State int
const (
	StatePaused State = iota
	StatePlaying
	StateStopped
)

func (State) String

func (s State) String() string

type Status

type Status struct {
	State    State
	Plist    *Playlist
	PlistPos int
	Pos      int
}

type StatusEvent

type StatusEvent struct {
	State    State
	Volume   int
	Plist    *Playlist
	PlistPos int
	Track    *vfs.Track
	TrackPos int
}

func (*StatusEvent) Name

func (e *StatusEvent) Name() string

func (*StatusEvent) Serialize

func (e *StatusEvent) Serialize() []serialize.Serializable

Jump to

Keyboard shortcuts

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