Documentation
¶
Overview ¶
Package filter defines the frame transform contracts: filters that resize, resample, or convert decoded frames through caller-owned result buffers, the capability descriptors the planner and shape solver select adapters by, and the per-runtime registry external filters plug into.
Index ¶
Constants ¶
const ( FactoryResize = "resize" FactoryResample = "resample" )
The well-known filter factory names recipes resolve transforms through.
Variables ¶
var ( // ErrNotFound reports a filter name with no registered factory. ErrNotFound = errors.New("filter: not found") // ErrNilFilter reports a nil filter where one is required. ErrNilFilter = errors.New("filter: nil filter") // ErrResultFull reports a result slice at capacity. ErrResultFull = errors.New("filter: result capacity full") // ErrUnsupportedFormat reports a pixel or sample format the filter cannot // consume or produce. ErrUnsupportedFormat = errors.New("filter: unsupported format") // ErrOutputBufferTooSmall reports caller-owned output planes without the // capacity the conversion needs. ErrOutputBufferTooSmall = errors.New("filter: output buffer too small") )
Filter sentinels, matched with errors.Is.
Functions ¶
func Fill ¶
func Fill(config *ResizeConfig)
Fill is the .Resize option for crop-to-cover scaling; see Fit.
func Fit ¶
func Fit(config *ResizeConfig)
Fit and Fill are .Resize options that pick the scaling mode; exact (stretch to the target) is the default:
.Resize(1280, 720, filter.Fit) // keep the aspect ratio inside 1280x720 .Resize(1280, 720, filter.Fill) // keep the aspect ratio, crop to cover it
Types ¶
type Config ¶
type Config struct {
Stream av.Stream
Realtime bool
Video *ResizeConfig
Audio *ResampleConfig
Opaque map[string]any
}
Config is everything a filter needs at open: the input stream, pacing, and exactly one of the Video or Audio conversion targets.
type Descriptor ¶
type Descriptor struct {
Name string
Input av.MediaType
Output av.MediaType
PixelFormats []av.PixelFormat
SampleFormats []av.SampleFormat
ResizeModes []ResizeMode
Realtime bool
Stateless bool
Metadata av.Metadata
}
Descriptor declares a filter's identity and capabilities — media kinds, formats, resize modes, realtime/stateless flags — so transform validation and the shape solver can select adapters before anything opens.
type Factory ¶
type Factory interface {
NewFilter(context.Context, Config) (FrameFilter, error)
}
Factory opens filters for a registered descriptor; registries hold factories so nothing opens during planning.
type FrameFilter ¶
type FrameFilter interface {
Descriptor() Descriptor
Open(context.Context, Config) error
FilterInto(context.Context, *av.Frame, *Result) error
FlushInto(context.Context, *Result) error
HandleEvent(context.Context, *av.Event) error
Close() error
}
FrameFilter is one frame transform (resize, resample, format convert): FilterInto converts frames into caller-owned results, FlushInto drains any buffered tail, HandleEvent reacts to in-band events.
type Registry ¶ added in v0.3.0
type Registry struct {
// contains filtered or unexported fields
}
Registry is the per-runtime filter registry: factories and capability descriptors keyed by filter name. Registration is last-wins; it is populated at runtime construction and read-only afterwards.
func (*Registry) Descriptor ¶ added in v0.3.0
func (r *Registry) Descriptor(name string) (Descriptor, error)
Descriptor returns the capability descriptor registered under name, or ErrNotFound.
func (*Registry) Descriptors ¶ added in v0.3.0
func (r *Registry) Descriptors() []Descriptor
Descriptors lists every registered filter descriptor sorted by name, so capability-driven selection (the shape solver) is deterministic.
func (*Registry) Factory ¶ added in v0.3.0
Factory returns the factory registered under name, or ErrNotFound.
func (*Registry) RegisterFactory ¶ added in v0.3.0
func (r *Registry) RegisterFactory(desc Descriptor, factory Factory)
RegisterFactory records a filter factory under its descriptor's name; last registration wins.
type ResampleConfig ¶
type ResampleConfig struct {
SampleRate int
Channels int
ChannelLayout string
SampleFormat av.SampleFormat
}
ResampleConfig is an audio conversion target: output rate, channels, and optional layout and sample format.
type ResizeConfig ¶
type ResizeConfig struct {
Width int
Height int
PixelFormat av.PixelFormat
Mode ResizeMode
}
ResizeConfig is a video conversion target: output geometry, optional pixel format, and the scaling mode.
type ResizeMode ¶
type ResizeMode string
ResizeMode says how a resize maps input geometry onto the target.
const ( ResizeExact ResizeMode = "exact" ResizeFit ResizeMode = "fit" ResizeFill ResizeMode = "fill" ResizePassthrough ResizeMode = "passthrough" )
The resize modes: exact stretches to the target, fit letterboxes inside it, fill crops to cover it, passthrough forwards unchanged.
type Result ¶
Result is the caller-owned output buffer FilterInto/FlushInto append to, keeping filtering allocation-free. Plane lifetimes follow codec.DecodeResult's: scratch is copied once when published, av.NewBuffer planes pass their reference to the stage, and a filter that forwards an input plane retains it first.
type Stage ¶
type Stage struct {
// contains filtered or unexported fields
}
Stage adapts a FrameFilter into a pipeline.Stage: frames are converted through caller-owned results, events reach the filter before continuing downstream.
func NewStage ¶
func NewStage(config StageConfig) (*Stage, error)
NewStage wraps an opened filter as a stage; the filter is required.
func (*Stage) DescribeNode ¶
DescribeNode reports the stage's spec entry for Describe.
type StageConfig ¶
type StageConfig struct {
Name string
// Detail is optional graph-rendering context for humans.
Detail string
// Filter receives frames and events and writes transformed frames into Result.
Filter FrameFilter
// Result is caller-owned scratch. Its slice capacities define how many
// frames and events can be emitted per input message.
Result Result
}
StageConfig configures a Stage: the opened filter and the caller-owned result scratch bounding per-message output.