encoder

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedFormats = []FormatSupport{
	{Format: media.SampleFormatS8, MinBits: 4, MaxBits: 8},
	{Format: media.SampleFormatS16, MinBits: 4, MaxBits: 16},
	{Format: media.SampleFormatS24, MinBits: 17, MaxBits: 24},
	{Format: media.SampleFormatS32, MinBits: 17, MaxBits: 32},
}

Functions

func EncodeFrame

func EncodeFrame(samples [][]int64, sampleRate, bitsPerSample int, frameNumber uint64, options config.EncoderConfig) ([]byte, error)

func EncodeResidual

func EncodeResidual(w *bits.Writer, residual []int64, coding riceCoding) error

func EncodeSubframeCandidate

func EncodeSubframeCandidate(w *bits.Writer, samples []int64, bitsPerSample int, best subframeCandidate) error

Types

type Encoder

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

func NewEncoder

func NewEncoder(stream media.StreamInfo, cfg config.EncoderConfig, workers *registry.WorkerPool) *Encoder

NewEncoder builds an encoder. workers may be nil, in which case blocks are encoded synchronously; otherwise it must be a pool this encoder is allowed to submit work to for its entire lifetime (the caller retains ownership and is responsible for closing it once every stage sharing it has finished).

func (*Encoder) Close

func (e *Encoder) Close() error

Close stops accepting further work without emitting a final packet or MD5 summary. It exists so the pipeline wrapper (pkg/engine) can guarantee in-flight state is released on error/cancellation exits, which never reach Flush's io.EOF-only call site. It does not close the pool: that is shared with other stages and owned by whoever constructed this encoder. Safe whether or not Flush ran first, and safe to call more than once.

func (*Encoder) Flush

func (e *Encoder) Flush() error

func (*Encoder) MD5

func (e *Encoder) MD5() [16]byte

func (*Encoder) OutputReady

func (e *Encoder) OutputReady() <-chan struct{}

func (*Encoder) Prepare

func (e *Encoder) Prepare(resources registry.ResourceGrant) error

func (*Encoder) ReceivePacket

func (e *Encoder) ReceivePacket() (*media.Packet, error)

ReceivePacket drains pendingQueue in submission order. Entries produced by the parallel path may still be in flight (entry.ready == false), in which case waitForEntry blocks on that specific entry until a worker finishes it.

It deliberately never returns ErrEAGAIN just because the head isn't ready yet: callers may wire this encoder into a pipeline with fan-out (e.g. a tee feeding both this encoder and a comparison against its own output), where upstream progress depends on the encoder actually producing a packet rather than the caller pulling more input first. Any policy that withholds a dispatched-but-pending packet in favor of "let more work queue up" can deadlock such a graph — see the regression that motivated this comment. This does mean input chunked smaller than BlockSize (one job dispatched per full block) gets pipelined roughly one job deep rather than the configured parallelism; blocks dispatched together (e.g. a decoder frame larger than BlockSize) still encode in parallel within a single emitFullBlocks call.

func (*Encoder) SendFrame

func (e *Encoder) SendFrame(frame *media.Frame) error

type FormatSupport

type FormatSupport struct {
	Format           media.SampleFormat
	MinBits, MaxBits int
}

FormatSupport describes one FLAC-supported input container: MinBits is one more than the next-smaller container's MaxBits (so 12-bit audio must be declared S16, never S24), and MaxBits is the container's own full width. register.go's capability declaration is derived from SupportedFormats so the two can never drift apart.

Jump to

Keyboard shortcuts

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