Help us shape the future of Go! Take the 2026 Go Developer Survey

ivf

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSuperframe

func BuildSuperframe(subFrames [][]byte) []byte

BuildSuperframe constructs a VP9 superframe from the given sub-frame data. The superframe format is:

[frame_0][frame_1]...[frame_N][marker][size_0]...[size_N][marker]

Marker byte: bits[7:5]=110, bits[4:2]=frames_minus_1, bits[1:0]=mag_minus_1

func LoadCameraPaths

func LoadCameraPaths(dir string) ([]string, error)

LoadCameraPaths returns the sorted absolute paths of all regular files in dir.

func LoopIntoTrack

func LoopIntoTrack(
	l *log.Logger,
	track *webrtc.TrackLocalStaticSample,
	src FrameSource,
)

LoopIntoTrack continuously reads frames from src and writes them into track, pacing by IVF timestamps. It uses wall-clock-relative timing to prevent accumulated drift across frames. It runs forever; call from a goroutine.

func LoopIntoTrackUntil

func LoopIntoTrackUntil(
	ctx context.Context,
	l *log.Logger,
	track *webrtc.TrackLocalStaticSample,
	src FrameSource,
)

func ProbeSVCLayers

func ProbeSVCLayers(path string) (int, error)

ProbeSVCLayers reads the first frame of an IVF file and returns the number of spatial layers (sub-frames in the VP9 superframe). Returns 1 if the file does not contain superframes.

func RepackageSVCIVF

func RepackageSVCIVF(srcPath, dstPath string, numSpatialLayers int) error

RepackageSVCIVF reads a single-layer IVF file and writes a new IVF where each frame is a VP9 superframe containing numSpatialLayers copies of the source frame. This produces valid superframe structure that the send loop can parse into per-layer sub-frames.

The output IVF uses the same timebase and dimensions as the input.

func RepackageSVCIVFMulti

func RepackageSVCIVFMulti(srcPaths []string, dstPath string) error

RepackageSVCIVFMulti reads one IVF per spatial layer (S0, S1, ..., S_N) and writes an output IVF where each frame is a VP9 superframe combining one frame from each layer. srcPaths[0] is the lowest spatial layer (S0) and srcPaths[len-1] is the highest. All source IVFs must have the same number of frames; the output header uses the dimensions of the highest layer.

Unlike RepackageSVCIVF (which duplicates a single frame), this function produces genuinely different-sized sub-frames per layer, matching what a real VP9 SVC encoder produces. The total output bitrate is the sum of all per-layer IVF bitrates.

func SVCLoopIntoTrack

func SVCLoopIntoTrack(
	l *log.Logger,
	track *webrtc.TrackLocalStaticRTP,
	src FrameSource,
	cfg SVCConfig,
	targetBitrate func() int,
)

SVCLoopIntoTrack continuously reads frames from src, demuxes SVC superframes, and writes RTP packets with proper SVC layer indices into track. It runs forever; call from a goroutine.

targetBitrate optionally returns the current bandwidth estimate in bps. When non-nil, higher layers are dropped when bandwidth is constrained.

func SVCLoopIntoTrackUntil

func SVCLoopIntoTrackUntil(
	ctx context.Context,
	l *log.Logger,
	track *webrtc.TrackLocalStaticRTP,
	src FrameSource,
	cfg SVCConfig,
	targetBitrate func() int,
)

func TemporalLayerID

func TemporalLayerID(frameIdx, numTemporalLayers int) uint8

TemporalLayerID returns the temporal layer ID for a given frame index using standard dyadic temporal layering.

1 TL: all TID=0
2 TL: [0, 1] repeating
3 TL: [0, 2, 1, 2] repeating

Types

type Cameras

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

Cameras holds loaded camera data for sending. It encapsulates the disk-vs-memory decision so plugins don't need to handle it.

func NewCameras

func NewCameras(dir string, inMemory bool) (*Cameras, error)

NewCameras loads IVF files from dir. If inMemory is true, all frames are pre-parsed into memory; otherwise only file paths are resolved.

func (*Cameras) NewSource

func (c *Cameras) NewSource() FrameSource

NewSource returns a new FrameSource for a sender goroutine. Each call returns an independent source with its own position, so multiple senders can share the same Cameras safely.

func (*Cameras) Paths

func (c *Cameras) Paths() []string

Paths returns the IVF file paths. Returns nil for in-memory cameras.

type Frame

type Frame struct {
	Data     []byte
	Duration time.Duration
}

Frame holds a single pre-parsed IVF frame ready for sending.

type FrameSource

type FrameSource interface {
	NextFrame() (data []byte, dur time.Duration, err error)
}

FrameSource provides frames for the send loop. Each call to NextFrame returns the next frame's data and duration. Implementations cycle through their content indefinitely.

func NewDiskSource

func NewDiskSource(paths []string) FrameSource

NewDiskSource returns a FrameSource that reads IVF files from disk. The paths slice is shared read-only; each source maintains its own file handle and position.

func NewMemSource

func NewMemSource(cams *PreloadedCameras) FrameSource

NewMemSource returns a FrameSource backed by preloaded camera data. The PreloadedCameras data is shared read-only; each source maintains its own position.

type PreloadedCameras

type PreloadedCameras struct {
	Files [][]Frame // one slice of frames per IVF file
}

PreloadedCameras holds all IVF files pre-loaded into memory as parsed frames.

func LoadCameras

func LoadCameras(dir string) (*PreloadedCameras, error)

LoadCameras reads all IVF files from dir into memory, pre-parsing frames and computing inter-frame durations. The returned PreloadedCameras can be shared across multiple sender goroutines since the frame data is read-only.

type SVCConfig

type SVCConfig struct {
	NumSpatialLayers  int
	NumTemporalLayers int
	Widths            []uint16 // resolution per spatial layer
	Heights           []uint16 // resolution per spatial layer
	TargetBitrateBps  int      // encoding bitrate for the full layer set (used for layer selection)
}

SVCConfig describes the SVC layer structure for the send loop.

func ProbeAndBuildSVCConfig

func ProbeAndBuildSVCConfig(paths []string, targetBitrateBps int) SVCConfig

ProbeAndBuildSVCConfig is a convenience wrapper for ResolveSVC with mode="auto". Deprecated: use ResolveSVC for full control.

type SVCResult

type SVCResult struct {
	Enabled bool
	Config  SVCConfig
}

SVCResult holds the resolved SVC mode and config for a sender.

func ResolveSVC

func ResolveSVC(cameraPaths []string, mode string, overrideSL, overrideTL, targetBitrateBps int) SVCResult

ResolveSVC determines whether to use SVC mode and builds the SVCConfig.

  • mode "auto": probe the first IVF file. SVC content -> enabled, else disabled.
  • mode "on": force SVC. overrideSL/overrideTL override auto-detection (0 = auto).
  • mode "off": force simple (non-SVC) path.

Jump to

Keyboard shortcuts

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