provider

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 14 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 provider maps a track reference to the audio bytes and metadata the engine needs. It is the one seam that makes a non-file source possible without the engine importing a network library: a provider may speak to a service, but only bytes and a description cross back into the engine.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoProvider = errors.New("provider: no provider matches the reference")

ErrNoProvider means a session with providers configured was handed a reference no provider claimed. It is never returned when the provider list is empty: an empty list is the legacy local-only path, which is behaviourally LocalAudio.

Functions

This section is empty.

Types

type AudioProvider

type AudioProvider interface {
	// Name identifies the provider in logs and in a UI list.
	Name() string

	// Match reports whether ref belongs to this provider. It must be cheap and
	// must not open anything: the session calls it for every queued ref.
	Match(ref string) bool

	// Open resolves ref. It may block on the network, so the session runs it on
	// the build worker, never on the control loop. The session cancels ctx only
	// on Close, and Close then waits for the worker, so an implementation that
	// ignores ctx can block Close forever with no timeout. Respect it: return
	// ctx.Err() from a long wait, and close the stop channel passed to the
	// Opener when it fires.
	Open(ctx context.Context, ref string) (Source, error)
}

AudioProvider resolves references it owns into a playable Source. Providers are tried in order, so a URL provider claims its own scheme and LocalAudio stays the last-resort fallback.

func Defaults added in v1.1.0

func Defaults() []AudioProvider

Defaults returns the built-in provider list in priority order: a direct http/https URL first, then the local filesystem fallback. A caller that wants extra sources prepends them; a caller that wants none passes an explicit list to the player. The local provider is last because its Match always succeeds.

type LocalAudio

type LocalAudio struct{}

LocalAudio is the default provider: a filesystem path through the decode registry. Match always returns true, so it must stay last in the list. It is exported so a consumer can add it explicitly as a fallback after a URL provider without giving up the local path's behaviour.

func (LocalAudio) Match

func (LocalAudio) Match(string) bool

Match always reports true: any ref the earlier providers did not claim is treated as a local path, which is how the engine behaved before this seam.

func (LocalAudio) Name

func (LocalAudio) Name() string

Name identifies LocalAudio. It matches the historic local path.

func (LocalAudio) Open

func (LocalAudio) Open(ctx context.Context, ref string) (Source, error)

Open resolves ref through the process-wide decode registry. It sets Local so the session keeps its own resolver, prober and decoder preference, and leaves Meta and Probe nil: duplicating them here would fork the local behaviour.

type NetworkProvider added in v1.1.0

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

NetworkProvider resolves http and https references into a playable Source. It is the built-in provider for a URL that points straight at an audio file, the network counterpart of LocalAudio: the reference is a URL, the bytes arrive over HTTP, and the container is decoded by the same registry every local file uses. It implements AudioProvider.

Bytes are read through ranged GETs ([httpRangeReader]), not fetched whole, so the source stays seekable and a seek costs a Range request rather than a re-download. Only factories that implement decode.ReaderOpener can serve a stream, today the Ogg Opus and WebM/Opus readers; a URL holding anything else fails at open with a clear error instead of being misread.

The provider imports no container parser or codec. The URL stops here; what crosses into the engine is a decoder over the bytes and a description of the track.

func NewNetworkProvider added in v1.1.0

func NewNetworkProvider(client *http.Client) *NetworkProvider

NewNetworkProvider returns a provider that streams audio over HTTP. A nil client selects http.DefaultClient, which has no timeout; a caller that wants one should pass its own, because a media transfer is legitimately long-lived and a fixed whole-request timeout would cut it off.

func (*NetworkProvider) Match added in v1.1.0

func (p *NetworkProvider) Match(ref string) bool

Match reports whether ref is an http or https URL. It is the cheap prefix check the session runs for every queued reference; it never opens the URL, so a wrong or dead link is not discovered until Open.

func (*NetworkProvider) Name added in v1.1.0

func (p *NetworkProvider) Name() string

Name identifies the provider. It is the label a UI shows and the key a log line carries.

func (*NetworkProvider) Open added in v1.1.0

func (p *NetworkProvider) Open(ctx context.Context, ref string) (Source, error)

Open resolves a URL into a Source. The URL is validated here, on the session's build worker, but no bytes are fetched: the first request happens when the streamer calls the Opener, so Open stays cheap and the decoder open is the one place a network failure surfaces.

The provider cannot know the stream shape until a decoder opens it, because the container is sniffed from the bytes. It therefore captures the shape from the first decoder it builds and reports it through Probe, so the duration is known without a second index walk.

type Source

type Source struct {
	Opener stream.Opener

	// Local marks the reference as a filesystem path. The session then keeps its
	// own metadata resolver, duration prober and decoder preference, and ignores
	// Meta and Probe. LocalAudio sets it. A provider that wraps a filesystem
	// source must set it too; the session never inspects the provider's identity,
	// so a wrapper that sets Local behaves exactly like LocalAudio itself.
	Local bool

	// Meta describes the track up front. It is carried because the session's
	// local resolver is useless for a remote ref: there is no file to read, and
	// meta.Default() would invent a title from the ref string. For a local path
	// the session still runs its own resolver, so a provider leaves this zero.
	// Meta.Stream is advisory: the session replaces it with the decoder's real
	// core.StreamInfo, which only the decoder can report truthfully.
	Meta meta.Meta

	// Probe optionally reports the stream shape without decoding. Nil means
	// "unknown": the session then falls back to its own prober, which only works
	// for a local path, and leaves the total unknown for a remote ref. It is
	// carried for the same reason as Meta: only the provider can reach the
	// source.
	Probe func(mode core.DurationMode) (core.StreamInfo, error)

	// Upgrade optionally offers a replacement decoder for the seamless-swap
	// path. When non-nil and the session has the experimental upgrade enabled,
	// the session calls it once, off the control loop, after the track starts.
	// It may block until the replacement is ready and must honour ctx. The
	// returned Opener must build a decoder in the same format as Opener's, or
	// the swap is refused and the original keeps playing. Nil means the source
	// has no upgrade and the track uses the ordinary path.
	Upgrade func(ctx context.Context) (stream.Opener, error)
}

Source is one resolved track. Opener is a factory, not a decoder, because the streamer calls it again on the reopen-and-discard fallback (Streamer.reopenAndDiscard), on a decoder swap (Streamer.SwapDecoder) and on the restore after a failed swap (Streamer.doSeek); a provider that cannot re-open cannot seek. Returning one decoder would make remote seek impossible, so the seam deliberately exposes the way to open again rather than the open result.

Opener must return a non-nil decoder or an error, never (nil, nil): the session calls Info on the result, so a nil decoder would panic the producer goroutine.

Jump to

Keyboard shortcuts

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