media

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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EffectiveBitsPerSample

func EffectiveBitsPerSample(format SampleFormat, bitsPerSample int) int

func IsCodecParameters

func IsCodecParameters[T any](p CodecParameters) bool

func Plane

func Plane[T SampleType](f *AudioFrame, planeIndex int) []T

Types

type AudioAttributes

type AudioAttributes struct {
	SampleRate    int
	Format        SampleFormat
	BitsPerSample int
	ChannelLayout ChannelLayout
}

func (AudioAttributes) ChannelCount

func (a AudioAttributes) ChannelCount() int

func (AudioAttributes) EffectiveBitsPerSample

func (a AudioAttributes) EffectiveBitsPerSample() int

type AudioFrame

type AudioFrame struct {
	ResourceBase

	Format SampleFormat
	// BitsPerSample is the significant sample width carried by this frame.
	// It may differ from the container's nominal format width (for example,
	// FLAC 12-bit samples are carried in an S16 frame).
	BitsPerSample int
	Layout        ChannelLayout
	SampleRate    int
	Samples       int
	// contains filtered or unexported fields
}

func NewAudioFrame

func NewAudioFrame(format SampleFormat, layout ChannelLayout, sampleRate, samples int, opts ...AudioFrameOption) *AudioFrame

func (*AudioFrame) Planes

func (f *AudioFrame) Planes() [][]byte

func (*AudioFrame) Pts

func (f *AudioFrame) Pts() Pts

type AudioFrameOption

type AudioFrameOption func(*AudioFrame)

func WithAudioBitsPerSample

func WithAudioBitsPerSample(bitsPerSample int) AudioFrameOption

func WithAudioPts

func WithAudioPts(pts Pts) AudioFrameOption

type ChannelCategory

type ChannelCategory uint8
const (
	OrderUnspecified ChannelCategory = iota
	OrderNative
	OrderCustom
	OrderAmbisonic
)

type ChannelLayout

type ChannelLayout struct {
	// contains filtered or unexported fields
}
var (
	LayoutMono1        ChannelLayout = NewNativeLayout(FrontCenter)
	LayoutDualMono2    ChannelLayout = NewCustomLayout(FrontCenter, FrontCenter)
	LayoutStereo2_0    ChannelLayout = NewNativeLayout(FrontLeft | FrontRight)
	LayoutStereo2_1    ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | LowFrequency)
	LayoutStereo3_0    ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter)
	LayoutStereo3_1    ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency)
	LayoutSurround3_0  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | BackCenter)
	LayoutQuad4_0      ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | BackLeft | BackRight)
	LayoutSideQuad4_0  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | SideLeft | SideRight)
	LayoutSurround4_0  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | BackCenter)
	LayoutSurround4_1  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackCenter)
	LayoutFront5_0     ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | BackLeft | BackRight)
	LayoutFront5_1     ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | BackLeft | BackRight | LowFrequency)
	LayoutSide5_0      ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | SideLeft | SideRight | FrontCenter)
	LayoutSide5_1      ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | SideLeft | SideRight | FrontCenter | LowFrequency)
	LayoutAtmos5_1_4   ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | TopFrontLeft | TopFrontRight | TopBackLeft | TopBackRight)
	LayoutHexagonal6_0 ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | BackLeft | BackRight | BackCenter)
	LayoutHexagonal6_1 ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | BackCenter)
	LayoutFront6_0     ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | FrontLeftOfCenter | FrontRightOfCenter | BackCenter)
	LayoutSide6_0      ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | SideLeft | SideRight | FrontCenter | BackCenter)
	LayoutSide6_1      ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | SideLeft | SideRight | FrontCenter | LowFrequency | BackCenter)
	LayoutWide7_1      ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | FrontLeftOfCenter | FrontRightOfCenter)
	LayoutSide7_0      ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | SideLeft | SideRight | FrontCenter | BackLeft | BackRight)
	LayoutSide7_1      ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | SideLeft | SideRight | FrontCenter | BackLeft | BackRight | LowFrequency)
	LayoutSurround7_1  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | SideLeft | SideRight)
	LayoutAtmos7_1_4   ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | SideLeft | SideRight | TopFrontLeft | TopFrontRight | TopBackLeft | TopBackRight)
	LayoutOctagonal8_0 ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | BackLeft | BackRight | BackCenter | SideLeft | SideRight)
	LayoutSurround9_0  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | BackLeft | BackRight | SideLeft | SideRight | FrontLeftOfCenter | FrontRightOfCenter)
	LayoutSurround9_1  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | SideLeft | SideRight | FrontLeftOfCenter | FrontRightOfCenter)
	LayoutSurround11_0 ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | BackLeft | BackRight | SideLeft | SideRight | FrontLeftOfCenter | FrontRightOfCenter | BackCenter | TopCenter)
	LayoutSurround11_1 ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | SideLeft | SideRight | FrontLeftOfCenter | FrontRightOfCenter | BackCenter | TopCenter)
	LayoutAtmos11_1_4  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | SideLeft | SideRight | FrontLeftOfCenter | FrontRightOfCenter | BackCenter | TopCenter | TopFrontLeft | TopFrontRight | TopBackLeft | TopBackRight)
	LayoutAtmos11_1_6  ChannelLayout = NewNativeLayout(FrontLeft | FrontRight | FrontCenter | LowFrequency | BackLeft | BackRight | SideLeft | SideRight | FrontLeftOfCenter | FrontRightOfCenter | BackCenter | TopCenter | TopFrontLeft | TopFrontCenter | TopFrontRight | TopBackLeft | TopBackCenter | TopBackRight)
)

func NewAmbisonicLayout

func NewAmbisonicLayout(order uint8) ChannelLayout

func NewCustomLayout

func NewCustomLayout(layout ...ChannelPosition) ChannelLayout

func NewNativeLayout

func NewNativeLayout(mask ChannelPosition) ChannelLayout

func NewUnspecified

func NewUnspecified(channels int) ChannelLayout

func ParseChannelLayout

func ParseChannelLayout(value string) (ChannelLayout, error)

func (ChannelLayout) AmbisonicOrder

func (l ChannelLayout) AmbisonicOrder() uint8

func (ChannelLayout) ChannelCount

func (l ChannelLayout) ChannelCount() int

func (ChannelLayout) Contains

func (l ChannelLayout) Contains(c ChannelPosition) bool

func (ChannelLayout) CustomChannels

func (l ChannelLayout) CustomChannels() []ChannelPosition

func (ChannelLayout) Enumerate

func (l ChannelLayout) Enumerate() []ChannelPosition

func (ChannelLayout) Index

func (l ChannelLayout) Index(c ChannelPosition) int

func (ChannelLayout) IsAmbisonic

func (l ChannelLayout) IsAmbisonic() bool

func (ChannelLayout) IsSpatial

func (l ChannelLayout) IsSpatial() bool

func (ChannelLayout) IsUnspecified

func (l ChannelLayout) IsUnspecified() bool

func (ChannelLayout) Mask

func (l ChannelLayout) Mask() ChannelPosition

func (ChannelLayout) Order

func (l ChannelLayout) Order() ChannelCategory

func (ChannelLayout) String

func (l ChannelLayout) String() string

func (*ChannelLayout) UnmarshalText

func (l *ChannelLayout) UnmarshalText(value []byte) error

func (ChannelLayout) Validate

func (l ChannelLayout) Validate() error

type ChannelPosition

type ChannelPosition uint64
const (
	FrontLeft ChannelPosition = 1 << iota
	FrontRight
	FrontCenter
	LowFrequency
	BackLeft
	BackRight
	FrontLeftOfCenter
	FrontRightOfCenter
	BackCenter
	SideLeft
	SideRight
	TopCenter
	TopFrontLeft
	TopFrontCenter
	TopFrontRight
	TopBackLeft
	TopBackCenter
	TopBackRight
)

type CodecID

type CodecID string
const (
	CodecLPCM     CodecID = "lpcm"
	CodecMPEG     CodecID = "mpeg"
	CodecPCMU     CodecID = "pcmu"
	CodecPCMA     CodecID = "pcma"
	CodecMP3      CodecID = "mp3"
	CodecMSADPCM  CodecID = "adpcm_ms"
	CodecIMAADPCM CodecID = "adpcm_ima"
	CodecGSM      CodecID = "gsm"
	CodecFLAC     CodecID = "flac"
)

type CodecParameters

type CodecParameters struct {
	Schema reflect.Type
	Data   []byte
}

CodecParameters is an opaque codec configuration payload.

Consumers must only interpret Data when they recognize Schema. The type is deliberately generic so codec and container plugins can evolve without adding codec-specific fields to core media types.

func NewCodecParameters

func NewCodecParameters[T any](data []byte) CodecParameters

func (CodecParameters) Clone

func (p CodecParameters) Clone() CodecParameters

Clone returns an independent copy of the parameter payload.

type Dts

type Dts int64

type Error

type Error struct {
	PTS         Pts
	Stage       PiplineStage
	StreamIndex int
	Err         error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorAction

type ErrorAction int
const (
	ActionStop ErrorAction = iota
	ActionIgnore
)

type ErrorHandler

type ErrorHandler interface {
	Handle(err *Error) ErrorAction
}

type Frame

type Frame interface {
	Retainer
	Pts() Pts
}

type MediaAttributes

type MediaAttributes struct {
	Codec           CodecID
	CodecParameters CodecParameters

	Video VideoAttributes
	Audio AudioAttributes
}

type MediaType

type MediaType string
const (
	MediaUnknown    MediaType = ""
	MediaVideo      MediaType = "video"
	MediaAudio      MediaType = "audio"
	MediaSubtitle   MediaType = "subtitle"
	MediaData       MediaType = "data"
	MediaAttachment MediaType = "attachment"
)

type Packet

type Packet struct {
	ResourceBase

	MediaType       MediaType
	StreamIndex     int
	Kind            PacketKind
	CodecParameters []CodecParameters

	PTS      Pts
	DTS      Dts
	Timebase time.Rational
	// contains filtered or unexported fields
}

func NewPacket

func NewPacket(size int, opts ...PacketOption) *Packet

func NewPacketEvent

func NewPacketEvent(kind PacketKind, streamIndex int, parameters []CodecParameters) *Packet

func NewPacketFromData

func NewPacketFromData(data []byte, opts ...PacketOption) *Packet

NewPacketFromData transfers ownership of data to the returned packet. The caller must not modify or retain data after this call.

func (*Packet) Data

func (p *Packet) Data() []byte

type PacketKind

type PacketKind uint8
const (
	PacketKindData PacketKind = iota
	PacketKindStreamEnd
)

type PacketOption

type PacketOption func(*Packet)

func WithDts

func WithDts(dts Dts) PacketOption

func WithPts

func WithPts(pts Pts) PacketOption

func WithStreamIndex

func WithStreamIndex(idx int) PacketOption

type PiplineStage

type PiplineStage string
const (
	StageDemuxer PiplineStage = "demuxer"
	StageDecoder PiplineStage = "decoder"
	StageFilter  PiplineStage = "filter"
	StageEncoder PiplineStage = "encoder"
	StageMuxer   PiplineStage = "muxer"
)

type Profile

type Profile struct {
	Type MediaType

	MediaAttributes
}

func (Profile) Signature

func (p Profile) Signature() string

type Pts

type Pts int64

type ResourceBase

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

func (*ResourceBase) Init

func (r *ResourceBase) Init(free func())

func (*ResourceBase) Release

func (r *ResourceBase) Release()

func (*ResourceBase) Retain

func (r *ResourceBase) Retain()

type Retainer

type Retainer interface {
	Retain()
	Release()
}

type SampleFormat

type SampleFormat string
const (
	SampleFormatUnknown SampleFormat = ""

	// Interleaved
	SampleFormatU8  SampleFormat = "u8"  // Unsigned 8-bit
	SampleFormatS8  SampleFormat = "s8"  // Signed 8-bit
	SampleFormatS16 SampleFormat = "s16" // Signed 16-bit
	SampleFormatS24 SampleFormat = "s24" // Signed 24-bit
	SampleFormatS32 SampleFormat = "s32" // Signed 32-bit
	SampleFormatF32 SampleFormat = "f32" // Float 32-bit
	SampleFormatF64 SampleFormat = "f64" // Double 64-bit

	// Planar
	SampleFormatU8P  SampleFormat = "u8p"  // Unsigned 8-bit
	SampleFormatS8P  SampleFormat = "s8p"  // Signed 8-bit
	SampleFormatS16P SampleFormat = "s16p" // Signed 16-bit
	SampleFormatS24P SampleFormat = "s24p" // Signed 24-bit
	SampleFormatS32P SampleFormat = "s32p" // Signed 32-bit
	SampleFormatF32P SampleFormat = "f32p" // Float 32-bit (recommended)
	SampleFormatF64P SampleFormat = "f64p" // Double 64-bit
)

func (SampleFormat) BitsPerSample

func (f SampleFormat) BitsPerSample() int

BitsPerSample returns the storage width of one sample in bits (e.g. 24 for SampleFormatS24), regardless of packed/planar layout.

func (SampleFormat) BytesPerSample

func (f SampleFormat) BytesPerSample() int

func (SampleFormat) IsFloat

func (f SampleFormat) IsFloat() bool

func (SampleFormat) IsInteger

func (f SampleFormat) IsInteger() bool

func (SampleFormat) IsPacked

func (f SampleFormat) IsPacked() bool

func (SampleFormat) IsPlanar

func (f SampleFormat) IsPlanar() bool

func (SampleFormat) Packed

func (f SampleFormat) Packed() SampleFormat

func (SampleFormat) Planar

func (f SampleFormat) Planar() SampleFormat

type SampleType

type SampleType interface {
	~uint8 | ~int16 | ~int32 | ~float32 | ~float64
}

type StreamInfo

type StreamInfo struct {
	Index int
	Type  MediaType

	Metadata metadata.Bundle

	IsDefault bool
	Duration  time.Duration

	MediaAttributes
}

func CloneStreams

func CloneStreams(streams []StreamInfo) []StreamInfo

CloneStreams returns an independent copy of streams, deep-cloning each element.

func (StreamInfo) Clone

func (s StreamInfo) Clone() StreamInfo

Clone returns an independent copy that shares no state with s.

type StreamSet

type StreamSet map[string]StreamInfo

StreamSet holds one StreamInfo per named port, for nodes whose ports can carry different stream shapes (e.g. a mixer's independent input/output ports).

func (StreamSet) Clone

func (s StreamSet) Clone() StreamSet

Clone returns an independent copy that shares no state with s.

type VideoAttributes

type VideoAttributes struct {
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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