filter

package
v0.2.2 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: 8 Imported by: ? modules, 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 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

View Source
const (
	FactoryResize   = "resize"
	FactoryResample = "resample"
)

The well-known filter factory names recipes resolve transforms through.

Variables

View Source
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  []string
	SampleFormats []string
	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 ResampleConfig

type ResampleConfig struct {
	SampleRate    int
	Channels      int
	ChannelLayout string
	SampleFormat  string
}

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 string
	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

type Result struct {
	Frames []av.Frame
	Events []av.Event
}

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.

func (*Result) Reset

func (r *Result) Reset()

Reset clears the result for reuse, keeping allocated capacity.

type SimpleRegistry

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

SimpleRegistry 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 NewRegistry

func NewRegistry() *SimpleRegistry

NewRegistry returns an empty filter registry.

func (*SimpleRegistry) Descriptor

func (r *SimpleRegistry) Descriptor(name string) (Descriptor, error)

Descriptor returns the capability descriptor registered under name, or ErrNotFound.

func (*SimpleRegistry) Descriptors

func (r *SimpleRegistry) Descriptors() []Descriptor

Descriptors lists every registered filter descriptor sorted by name, so capability-driven selection (the shape solver) is deterministic.

func (*SimpleRegistry) Factory

func (r *SimpleRegistry) Factory(name string) (Factory, error)

Factory returns the factory registered under name, or ErrNotFound.

func (*SimpleRegistry) RegisterFactory

func (r *SimpleRegistry) RegisterFactory(desc Descriptor, factory Factory)

RegisterFactory records a filter factory under its descriptor's name; last registration wins.

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) Close

func (s *Stage) Close() error

Close closes the wrapped filter once.

func (*Stage) DescribeNode

func (s *Stage) DescribeNode() pipeline.NodeSpec

DescribeNode reports the stage's spec entry for Describe.

func (*Stage) Handle

func (s *Stage) Handle(ctx context.Context, msg *pipeline.Message, emitter pipeline.Emitter) error

Handle filters one frame message (events pass to the filter first), emitting converted frames downstream.

func (*Stage) Name

func (s *Stage) Name() string

Name returns the stage's node name.

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.

Jump to

Keyboard shortcuts

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