stage

package
v0.3.0 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: 13 Imported by: 0 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

Index

Constants

View Source
const (
	CompositeBlackLuma     = 16
	CompositeNeutralChroma = 128
)

Limited-range I420 black: the canvas color wherever no arm paints.

Variables

This section is empty.

Functions

func FrameDurationNS

func FrameDurationNS(frame *av.Frame) int64

frameDurationNS reports the frame's span on the nanosecond clock: the declared Duration when usable, else the audio length derived from samples/rate, else 0 (exact-match tolerance). FrameDurationNS reports the frame's span on the nanosecond clock: the explicit Duration when valid, else the sample count over the sample rate for audio frames, else 0.

func MarkTimelinePaced

func MarkTimelinePaced(clock av.Clock)

markTimelinePaced records a paced consumer on clock when it is the task timeline — the one call every seam that hands out the clock (provider open, realtime demux, gate lowering) makes so task-wide rate and pause controls have a consumer to scale. Non-timeline clocks (unit-test fakes) are ignored.

func MixS16Into

func MixS16Into(dst []byte, inputs [][]byte, n int)

func MixS16KernelName

func MixS16KernelName() string

Types

type ArmRestamp

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

armRestampStage republishes an arm's stream under the arm's id — the runtime body of a tap arm and of an arm bound when its input opens. Join stages identify arms by stream id: a tap's own media keeps flowing down its declaring arm unchanged, and two files carry the same track ids, so the converged copy is re-stamped: a shallow per-message copy (payloads are shared exactly like every other fanout; downstream joins clone what they buffer). With in set, only that stream and stream-less events pass: a file's source carries all its streams.

func NewArmRestamp

func NewArmRestamp(name string, detail string, in av.StreamID, out av.StreamID) *ArmRestamp

func (*ArmRestamp) Close

func (s *ArmRestamp) Close() error

func (*ArmRestamp) DescribeNode

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

DescribeNode reports the same detail the join planner records on the planned restamp node, keeping Describe() ≡ Build().

func (*ArmRestamp) Handle

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

func (*ArmRestamp) Name

func (s *ArmRestamp) Name() string

type AudioMix

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

audioMixStage sums N synchronized audio inputs into one output stream — the runtime heart of a convergent Mix. Each input arm is identified by its frame StreamID. It is a normal pipeline.Stage: the buffered runner calls Handle serially per node, so the per-input queues need no locking (lock-free by design — the hot path takes no mutex).

func NewAudioMix

func NewAudioMix(name string, inputs []av.StreamID, out av.StreamID, mode compile.JoinSyncMode) *AudioMix

func NewAudioMixWithPrealloc

func NewAudioMixWithPrealloc(name string, inputs []av.StreamID, out av.StreamID, mode compile.JoinSyncMode, preallocDepth int) *AudioMix

func NewAudioMixWithPreallocAndPools

func NewAudioMixWithPreallocAndPools(name string, inputs []av.StreamID, out av.StreamID, mode compile.JoinSyncMode, preallocDepth int, pools *MediaPools) *AudioMix

func (*AudioMix) Admit

func (b *AudioMix) Admit(ctx context.Context, msg *pipeline.Message) error

Admit implements pipeline.Admitter.

func (*AudioMix) Admits

func (b *AudioMix) Admits(_ interleave.Token, arm int) bool

func (*AudioMix) Arm

func (b *AudioMix) Arm(_ interleave.Token, msg any) (int, bool)

Arm and Admits implement interleave.Gate.

func (*AudioMix) Close

func (b *AudioMix) Close() error

func (*AudioMix) DescribeNode

func (b *AudioMix) DescribeNode() pipeline.NodeSpec

DescribeNode reports the same detail the join planner records on the planned node, keeping Describe() ≡ Build() when ByPTS annotates the join.

func (*AudioMix) DroppedMessages

func (b *AudioMix) DroppedMessages() uint64

DroppedMessages implements pipeline.DropReporter.

func (*AudioMix) EnableAdmission

func (b *AudioMix) EnableAdmission()

func (*AudioMix) Handle

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

func (*AudioMix) Name

func (b *AudioMix) Name() string

type JoinSyncState

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

joinSyncState is the arm buffering and alignment state shared by the convergence stages (audioMixStage, videoCompositeStage). Every field is touched only inside the owning stage's serial Handle — lock-free by design, no mutex on the hot path — and alignment is pure PTS math: no wall clock, deterministic, unit-testable.

EOS semantics (both modes): an ended arm stops gating — its buffered frames still participate, then the remaining arms keep joining without it; the joined stream ends only when every arm has ended.

func NewJoinSyncStateWithPendingCap

func NewJoinSyncStateWithPendingCap(mode compile.JoinSyncMode, inputs []av.StreamID, pendingCap int) *JoinSyncState

func (*JoinSyncState) Buffer

func (s *JoinSyncState) Buffer(frame *av.Frame)

buffer queues one arm frame by StreamID lookup.

func (*JoinSyncState) MarkEOS

func (s *JoinSyncState) MarkEOS(id av.StreamID) bool

markEOS records an arm's end of stream and reports whether every arm ended for the first time. A stream-less EOS marks every declared arm ended; unknown stream IDs are ignored.

func (*JoinSyncState) PendingCount

func (s *JoinSyncState) PendingCount(id av.StreamID) int

pendingCount returns the number of buffered frames for id (used by tests).

type MediaPools

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

func NewMediaPools

func NewMediaPools() *MediaPools

func (*MediaPools) PlanePoolCounts

func (p *MediaPools) PlanePoolCounts() (audio, video int)

PlanePoolCounts returns the number of pooled audio and video plane slices.

func (*MediaPools) PutMetadata

func (p *MediaPools) PutMetadata(metadata av.Metadata)

func (*MediaPools) PutPlanes

func (p *MediaPools) PutPlanes(planes []av.Plane)

func (*MediaPools) TakeMetadata

func (p *MediaPools) TakeMetadata() av.Metadata

func (*MediaPools) TakePlanes

func (p *MediaPools) TakePlanes(count int) []av.Plane

type Selector

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

selectorStage forwards messages from exactly one of N inputs to a single output and drops the rest — the runtime heart of a one-of-N Select switch (active-speaker camera, simulcast layer switch, failover). Each input arm is identified by its frame/packet StreamID.

It is a normal pipeline.Stage: the buffered runner calls Handle serially per node, so the per-input EOS bookkeeping needs no locking (lock-free by design — the hot path takes no mutex). The active input lives in an atomic pointer so SetActive may be called concurrently with Handle without a mutex: the read on the forwarding hot path is a plain atomic load.

EOS is forwarded like the mixer: one output EOS is emitted only after every input has ended. Non-EOS events are forwarded only from the currently active input so the downstream sees a single coherent stream.

A switch is driven live through the control plane: an injected av.EventSelectActive event names the target input in Event.StreamID, calls SetActive, and is consumed (not forwarded). control.SelectActive builds that control.

func NewSelector

func NewSelector(name string, inputs []av.StreamID, out av.StreamID) *Selector

func (*Selector) ActiveID

func (s *Selector) ActiveID() av.StreamID

ActiveID returns the currently active input id (empty if none configured).

func (*Selector) Close

func (s *Selector) Close() error

func (*Selector) Handle

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

func (*Selector) Name

func (s *Selector) Name() string

func (*Selector) SetActive

func (s *Selector) SetActive(id av.StreamID) error

SetActive switches the forwarded input. It is safe to call concurrently with Handle: the new id is published with a single atomic store. An id that is not one of the configured inputs is rejected so a typo cannot silently mute the output.

type Timeline

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

timeline is the task-wide clock service: one shared av.Clock per task that maps the runtime clock onto media run time through an atomically readable rate and pause epoch. Paced consumers — the realtime demux pacer, clock-aware provider sources, and playout gates — read and sleep on the timeline, so one control.Rate re-anchors every consumer coherently instead of each source keeping a private rate.

Concurrency: Now is lock-free (one atomic epoch load, arithmetic only), per the data-plane rule. SetRate/Pause/Resume serialize on a cold-side mutex, re-anchor the epoch atomically, and rotate a broadcast channel so in-flight Sleeps recompute their remaining wall wait under the new epoch.

func NewTimeline

func NewTimeline(inner av.Clock) *Timeline

newTimeline anchors a timeline at zero on the inner clock's current reading, running at 1x. A nil inner clock falls back to av.MonotonicClock, matching the pacing default.

func (*Timeline) Inner

func (t *Timeline) Inner() av.Clock

Inner returns the underlying wall clock wrapped by this timeline.

func (*Timeline) MarkPaced

func (t *Timeline) MarkPaced()

markPaced records that a paced consumer (demux pacer, clock-aware source) waits on this timeline; the task refuses rate controls until one exists.

func (*Timeline) Now

func (t *Timeline) Now() time.Duration

Now reports the timeline reading: the integral of rate over unpaused inner time since construction. Lock-free — one epoch load plus arithmetic.

func (*Timeline) Paced

func (t *Timeline) Paced() bool

paced reports whether any paced consumer waits on the timeline.

func (*Timeline) Pause

func (t *Timeline) Pause()

Pause freezes the timeline at its current reading. Sleeps hold until Resume (or their context ends). Pausing a paused timeline is a no-op.

func (*Timeline) PausedNow

func (t *Timeline) PausedNow() bool

pausedNow reports whether the timeline is currently frozen at its reading.

func (*Timeline) Rate

func (t *Timeline) Rate() float64

Rate reports the current playback-rate multiplier.

func (*Timeline) Resume

func (t *Timeline) Resume()

Resume continues a paused timeline from the frozen reading at the current rate. Resuming a running timeline is a no-op.

func (*Timeline) SetRate

func (t *Timeline) SetRate(rate float64) error

SetRate re-anchors the timeline at the current reading with a new rate. In-flight Sleeps wake and recompute their remaining wall wait, so every paced consumer changes pace together, mid-sleep included.

func (*Timeline) Sleep

func (t *Timeline) Sleep(ctx context.Context, d time.Duration) error

Sleep blocks until d of timeline time has elapsed or ctx is done. d is a timeline duration: at rate 2 a 100ms sleep costs 50ms of inner time, and a rate or pause change mid-sleep re-derives the remaining wall wait instead of finishing on the stale conversion. While paused it holds for the next epoch change. All wall waits go through the inner clock's Sleep so fake clocks keep pacing deterministic.

type VideoComposite

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

videoCompositeStage overlays N synchronized video inputs into one output frame — the video dual of audioMixStage. Each input arm is identified by its frame StreamID. It is a normal pipeline.Stage: the buffered runner calls Handle serially per node, so the per-input queues need no locking (lock-free by design — the hot path takes no mutex).

func NewVideoComposite

func NewVideoComposite(name string, inputs []av.StreamID, out av.StreamID, layout []compile.CompositeLayout, mode compile.JoinSyncMode) *VideoComposite

func NewVideoCompositeWithPrealloc

func NewVideoCompositeWithPrealloc(name string, inputs []av.StreamID, out av.StreamID, layout []compile.CompositeLayout, mode compile.JoinSyncMode, preallocDepth int) *VideoComposite

func NewVideoCompositeWithPreallocAndPools

func NewVideoCompositeWithPreallocAndPools(name string, inputs []av.StreamID, out av.StreamID, layout []compile.CompositeLayout, mode compile.JoinSyncMode, preallocDepth int, pools *MediaPools) *VideoComposite

func (*VideoComposite) Admit

func (b *VideoComposite) Admit(ctx context.Context, msg *pipeline.Message) error

Admit implements pipeline.Admitter.

func (*VideoComposite) Admits

func (b *VideoComposite) Admits(_ interleave.Token, arm int) bool

func (*VideoComposite) Arm

func (b *VideoComposite) Arm(_ interleave.Token, msg any) (int, bool)

Arm and Admits implement interleave.Gate.

func (*VideoComposite) Close

func (b *VideoComposite) Close() error

func (*VideoComposite) DescribeNode

func (b *VideoComposite) DescribeNode() pipeline.NodeSpec

DescribeNode reports the same detail the join planner records on the planned node, keeping Describe() ≡ Build() when ByPTS annotates the join.

func (*VideoComposite) DroppedMessages

func (b *VideoComposite) DroppedMessages() uint64

DroppedMessages implements pipeline.DropReporter.

func (*VideoComposite) EnableAdmission

func (b *VideoComposite) EnableAdmission()

func (*VideoComposite) Handle

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

func (*VideoComposite) Name

func (b *VideoComposite) Name() string

Jump to

Keyboard shortcuts

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