shape

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 6 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 shape holds the media-format descriptor vocabulary used across goav to describe the shape of a stream at a point in a pipeline: its domain, media kind, codec, geometry, and audio layout. It keeps the goav root grammar clean while letting callers reach for descriptors as shape.Spec, shape.Set, and the shape.Frame/Packet/Event constructors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contract

type Contract interface {
	InputShapes() Set
	OutputShapes(Spec) Set
}

Contract describes a stage that maps an input Spec to a Set of output Specs and advertises the Set of inputs it accepts.

type MediaDomain

type MediaDomain string

MediaDomain names which representation a Spec describes: packets, frames, or out-of-band events.

const (
	DomainPacket MediaDomain = "packet"
	DomainFrame  MediaDomain = "frame"
	DomainEvent  MediaDomain = "event"
)

The media domains: encoded packets, decoded frames, or event-only flow.

type Option

type Option func(*Spec)

Option mutates a Spec under construction.

func Audio

func Audio(sampleRate int, channels int, sampleFormat string) Option

Audio states the audio layout facts: sample rate, channel count, and sample format. Zero or empty fields stay unconstrained — Audio(0, 0, "f32") pins only the sample format, which is how a Prefer steers an otherwise open solver choice.

func Codec

func Codec(codec av.CodecID) Option

Codec pins the codec id (av.CodecOpus, ...); unset matches any codec.

func Domain

func Domain(domain MediaDomain) Option

Domain pins which representation the Spec describes: packets, frames, or events. The Frame/Packet/Event constructors set it for you.

func Format

func Format(format av.FormatID) Option

Format pins the container or transport framing format (av.FormatRTP, ...); unset matches any format.

func Media

func Media(media av.MediaType) Option

Media pins the media kind (audio, video); unset matches any kind.

func Realtime

func Realtime(realtime bool) Option

Realtime marks the Spec as a realtime stream.

func Stream

func Stream(stream av.StreamID) Option

Stream pins the Spec to one stream id; unset matches any stream.

func Video

func Video(width int, height int, pixelFormat string) Option

Video states the video layout facts: geometry and pixel format. Zero or empty fields stay unconstrained — Video(0, 0, "i420") pins only the pixel format, which is how a Prefer steers an otherwise open solver choice.

type Policy

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

Policy is the shape solver's conversion vocabulary: which classes of automatic conversion a chain allows the planner to insert when an operation pins format facts the current media does not satisfy. The zero Policy allows nothing — every needed conversion is refused with the exact allowance to add. Build policies with AllowResample, AllowResize, and AllowConvert and combine them with Union (or by passing several to .Auto(...)).

func AllowConvert

func AllowConvert() Policy

AllowConvert permits inserting pixel-format and sample-format conversions.

func AllowCustom

func AllowCustom(name string) Policy

AllowCustom permits an application-registered solver delta by name. Custom names are matched against per-runtime delta contributors registered with runconfig; empty names allow nothing.

func AllowResample

func AllowResample() Policy

AllowResample permits inserting audio sample-rate and channel conversions.

func AllowResize

func AllowResize() Policy

AllowResize permits inserting video width and height conversions.

func Conversions

func Conversions(actual Spec, expected Spec) Policy

Conversions reports the conversion classes required to make actual satisfy the populated format facts of expected: resample for sample-rate or channel deltas, resize for width or height deltas, convert for pixel-format or sample-format deltas. Facts the expected Spec leaves empty never require a conversion; facts it pins follow Accepts semantics (an unknown actual fact does not satisfy a pinned expectation).

func (Policy) AllowsConvert

func (p Policy) AllowsConvert() bool

AllowsConvert reports whether pixel/sample format conversions are allowed.

func (Policy) AllowsResample

func (p Policy) AllowsResample() bool

AllowsResample reports whether sample-rate/channel conversions are allowed.

func (Policy) AllowsResize

func (p Policy) AllowsResize() bool

AllowsResize reports whether width/height conversions are allowed.

func (Policy) Constructors

func (p Policy) Constructors() []string

Constructors lists the shape package constructor calls that build this policy — the exact fix a refusal error should suggest.

func (Policy) Covers

func (p Policy) Covers(needed Policy) bool

Covers reports whether the policy allows every conversion class in needed.

func (Policy) Empty

func (p Policy) Empty() bool

Empty reports whether the policy allows nothing.

func (Policy) Missing

func (p Policy) Missing(needed Policy) Policy

Missing returns the conversion classes in needed that the policy does not allow.

func (Policy) String

func (p Policy) String() string

String renders the allowed classes, or "none" for the zero policy.

func (Policy) Union

func (p Policy) Union(other Policy) Policy

Union combines two policies; the result allows everything either allows.

type Set

type Set []Spec

Set is a collection of acceptable Specs. An empty Set accepts any Spec.

func (Set) Accepts

func (s Set) Accepts(actual Spec) bool

Accepts reports whether the actual Spec satisfies any member of the Set. An empty Set accepts anything.

func (Set) Clone

func (s Set) Clone() Set

Clone returns a copy of the Set.

type Spec

type Spec struct {
	Domain       MediaDomain  `json:"domain,omitempty"`
	MediaKind    av.MediaType `json:"mediaKind,omitempty"`
	StreamID     av.StreamID  `json:"streamID,omitempty"`
	Codec        av.CodecID   `json:"codec,omitempty"`
	Format       av.FormatID  `json:"format,omitempty"`
	Width        int          `json:"width,omitempty"`
	Height       int          `json:"height,omitempty"`
	PixelFormat  string       `json:"pixelFormat,omitempty"`
	SampleRate   int          `json:"sampleRate,omitempty"`
	Channels     int          `json:"channels,omitempty"`
	SampleFormat string       `json:"sampleFormat,omitempty"`
	Realtime     bool         `json:"realtime,omitempty"`
}

Spec is the core media-format descriptor: the shape of a stream at a point in a pipeline. A zero Spec matches anything; populated fields constrain the match.

func Event

func Event(options ...Option) Spec

Event builds an event-domain Spec.

func Frame

func Frame(media av.MediaType, options ...Option) Spec

Frame builds a frame-domain Spec for the given media.

func FromCodecParameters

func FromCodecParameters(parameters av.CodecParameters) Spec

FromCodecParameters derives a Spec from decoded codec parameters.

func FromStream

func FromStream(stream av.Stream, domain MediaDomain) Spec

FromStream derives a Spec from a demuxed stream in the given domain.

func Merge

func Merge(base Spec, next Spec) Spec

Merge overlays the non-empty fields of next onto base and returns the result.

func New

func New(options ...Option) Spec

New builds a Spec from options.

func Packet

func Packet(media av.MediaType, codec av.CodecID, options ...Option) Spec

Packet builds a packet-domain Spec for the given media and codec.

func (Spec) CompatibleWith

func (s Spec) CompatibleWith(expected Spec) bool

CompatibleWith reports whether the receiver satisfies the non-empty fields of expected.

func (Spec) String

func (s Spec) String() string

String renders the Spec as a compact key=value description, or "any" when the Spec is empty.

Jump to

Keyboard shortcuts

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