flow

package
v0.1.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 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 flow holds the branch buffer and flow-control vocabulary used to describe how a goav branch queues, drops, or backpressures messages. It keeps the goav root grammar clean while letting callers reach for buffer policies as flow.Blocking, flow.DropOldest, and friends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchBuffer

type BranchBuffer struct {
	Mode     BranchBufferMode
	Capacity int
	MaxBytes int64
	MaxDelay time.Duration
}

BranchBuffer describes how a branch queues, drops, or backpressures messages. Build one with Blocking, DropOldest, DropNewest, Latest, or Unbounded, then tune it with BranchBufferOption values. A queued message holds references to its payload, so every branch reads the bytes its producer published; none is copied per branch.

func Blocking

func Blocking(capacity int, options ...BranchBufferOption) BranchBuffer

Blocking applies backpressure to the producer when the branch queue is full.

func DropNewest

func DropNewest(capacity int, options ...BranchBufferOption) BranchBuffer

DropNewest refuses the incoming message and keeps the queue when full.

func DropOldest

func DropOldest(capacity int, options ...BranchBufferOption) BranchBuffer

DropOldest sheds the queued head to admit a newer message when full.

func Latest

func Latest(options ...BranchBufferOption) BranchBuffer

Latest keeps only the most recent message (capacity one, drop oldest).

func Unbounded

func Unbounded(options ...BranchBufferOption) BranchBuffer

Unbounded queues without a capacity limit.

func (BranchBuffer) PipelinePolicy

func (b BranchBuffer) PipelinePolicy() pipeline.BufferPolicy

PipelinePolicy lowers a BranchBuffer to the pipeline.BufferPolicy the runtime installs on the branch queue.

func (BranchBuffer) String

func (b BranchBuffer) String() string

String renders the buffer declaration (mode plus capacity) for plans and diagnostics.

type BranchBufferMode

type BranchBufferMode string

BranchBufferMode names the queueing discipline a branch buffer applies.

const (
	// BufferBlocking preserves every message: a full queue paces the producer.
	BufferBlocking BranchBufferMode = "blocking"
	// BufferDropOldest sheds the oldest queued message to admit the new one.
	BufferDropOldest BranchBufferMode = "drop_oldest"
	// BufferDropNewest sheds the incoming message when the queue is full.
	BufferDropNewest BranchBufferMode = "drop_newest"
	// BufferLatest keeps only the most recent message.
	BufferLatest BranchBufferMode = "latest"
	// BufferUnbounded queues without limit; memory is the only bound.
	BufferUnbounded BranchBufferMode = "unbounded"
)

type BranchBufferOption

type BranchBufferOption func(*BranchBuffer)

BranchBufferOption tunes a BranchBuffer produced by one of the constructors.

func BufferMaxBytes

func BufferMaxBytes(maxBytes int64) BranchBufferOption

BufferMaxBytes caps the total bytes a branch buffer may hold.

func BufferMaxDelay

func BufferMaxDelay(maxDelay time.Duration) BranchBufferOption

BufferMaxDelay caps how stale a queued message may be before it is shed.

type DropReason

type DropReason = pipeline.DropPolicy

DropReason keys GraphStats.DropReasons / NodeStats.DropReasons: why the runtime shed a message. Use the DropReason* constants to read those maps without importing the pipeline package.

const (
	// DropReasonOldest: a DropOldest branch dropped the queued head to admit a newer message.
	DropReasonOldest DropReason = pipeline.DropOldest
	// DropReasonNewest: a DropNewest branch refused the incoming message and kept the queue.
	DropReasonNewest DropReason = pipeline.DropNewest
	// DropReasonStale: a message older than the branch BufferMaxDelay was shed.
	DropReasonStale DropReason = pipeline.DropStale
	// DropReasonOverflow: a message that would exceed the branch BufferMaxBytes budget was shed.
	DropReasonOverflow DropReason = pipeline.DropOverflow
	// DropReasonUntilSync: messages dropped until the next keyframe/sync point.
	DropReasonUntilSync DropReason = pipeline.DropUntilSync
	// DropReasonNonKeyVideo: a non-keyframe video message was dropped.
	DropReasonNonKeyVideo DropReason = pipeline.DropNonKeyVideo
)

type PlayoutPolicy

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

PlayoutPolicy names one deliver-when-due schedule at the sink boundary: a playout gate holds each packet or frame until its media time is due on the task timeline, so real-time destinations render on time. Reuse the returned value across audio/video chains or branches when those branches should align on one shared anchor.

func Playout

func Playout(name string) PlayoutPolicy

Playout creates a deliver-when-due policy. The first admitted message anchors its PTS to the current task-timeline reading; every later message with PTS p is due at that anchor plus (p - first PTS) plus the offset. The default holds messages until due and delivers late ones immediately; use WithDropLate for preview-style branches that should shed overdue media.

func (PlayoutPolicy) Admit

func (p PlayoutPolicy) Admit(ctx context.Context, clock av.Clock, pts time.Duration) (time.Duration, bool, error)

Admit blocks on clock until the message with media time pts is due, and reports whether it should be dropped instead. Branches sharing this policy value share the anchor, so their deliveries interleave by PTS on the one clock. The returned lateness is how far past due the message already was when it reached the gate — positive for messages delivered late (hold-late) or shed (drop-late), non-positive for on-time media — the measurement QoS reports carry.

func (PlayoutPolicy) DropLate

func (p PlayoutPolicy) DropLate() bool

DropLate reports whether overdue messages are shed instead of delivered late.

func (PlayoutPolicy) Name

func (p PlayoutPolicy) Name() string

Name returns the stable name used for diagnostics and stage naming.

func (PlayoutPolicy) Normalize

func (p PlayoutPolicy) Normalize() PlayoutPolicy

Normalize fills the default name and scheduler used by a zero PlayoutPolicy.

func (PlayoutPolicy) ObserveEvent

func (p PlayoutPolicy) ObserveEvent(event *av.Event)

ObserveEvent resets the shared anchor after a discontinuity so post-seek media re-anchors on its first message instead of paying the seek gap as a playout delay.

func (PlayoutPolicy) Offset

func (p PlayoutPolicy) Offset() time.Duration

Offset returns the latency offset added to every due time.

func (PlayoutPolicy) Tolerance

func (p PlayoutPolicy) Tolerance() time.Duration

Tolerance returns the overdue budget before a drop-late gate sheds.

func (PlayoutPolicy) WithDropLate

func (p PlayoutPolicy) WithDropLate(tolerance time.Duration) PlayoutPolicy

WithDropLate returns a copy of the policy that sheds messages already overdue by more than tolerance instead of delivering them late. Early messages still wait until due.

func (PlayoutPolicy) WithOffset

func (p PlayoutPolicy) WithOffset(offset time.Duration) PlayoutPolicy

WithOffset returns a copy of the policy whose messages are due offset later than their anchored media time — the latency budget downstream rendering gets. Non-positive offsets leave the policy unchanged.

type SyncPolicy

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

SyncPolicy names one shared media timeline. Reuse the returned value across audio/video branches when those branches should align with each other.

func Sync

func Sync(name string) SyncPolicy

Sync creates a shared media timeline policy. The default holds early media until slower streams catch up; call WithDropLate for preview-style branches that should shed stale media instead.

func (SyncPolicy) Admit

func (p SyncPolicy) Admit(ctx context.Context, stream av.StreamID, pts time.Duration) (time.Duration, bool, error)

Admit updates the shared timeline and reports whether the message should be dropped before it reaches the branch. The returned lateness is how far the message trailed the policy's shared timeline in media time when it was dropped — the measurement QoS reports carry — and zero for admitted media (hold-late gates hold early media, never late media).

func (SyncPolicy) DropLate

func (p SyncPolicy) DropLate() bool

DropLate reports whether stale messages should be shed instead of holding.

func (SyncPolicy) Name

func (p SyncPolicy) Name() string

Name returns the stable name used for diagnostics and stage naming.

func (SyncPolicy) Normalize

func (p SyncPolicy) Normalize() SyncPolicy

Normalize fills the default name and scheduler used by a zero SyncPolicy.

func (SyncPolicy) ObserveEvent

func (p SyncPolicy) ObserveEvent(event *av.Event)

ObserveEvent updates the shared timeline after stream resets or removals.

func (SyncPolicy) Tolerance

func (p SyncPolicy) Tolerance() time.Duration

Tolerance returns the allowed media-time skew before the gate holds or drops.

func (SyncPolicy) WithDropLate

func (p SyncPolicy) WithDropLate() SyncPolicy

WithDropLate makes a sync gate drop messages that arrive behind the shared timeline by more than the tolerance.

func (SyncPolicy) WithTolerance

func (p SyncPolicy) WithTolerance(tolerance time.Duration) SyncPolicy

WithTolerance sets the allowed media-time skew before a sync gate holds or drops a message.

Jump to

Keyboard shortcuts

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