Documentation
¶
Index ¶
- func BuildSuperframe(subFrames [][]byte) []byte
- func LoadCameraPaths(dir string) ([]string, error)
- func LoopIntoTrack(l *log.Logger, track *webrtc.TrackLocalStaticSample, src FrameSource)
- func LoopIntoTrackUntil(ctx context.Context, l *log.Logger, track *webrtc.TrackLocalStaticSample, ...)
- func ProbeSVCLayers(path string) (int, error)
- func RepackageSVCIVF(srcPath, dstPath string, numSpatialLayers int) error
- func RepackageSVCIVFMulti(srcPaths []string, dstPath string) error
- func SVCLoopIntoTrack(l *log.Logger, track *webrtc.TrackLocalStaticRTP, src FrameSource, ...)
- func SVCLoopIntoTrackUntil(ctx context.Context, l *log.Logger, track *webrtc.TrackLocalStaticRTP, ...)
- func TemporalLayerID(frameIdx, numTemporalLayers int) uint8
- type Cameras
- type Frame
- type FrameSource
- type PreloadedCameras
- type SVCConfig
- type SVCResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildSuperframe ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
type FrameSource ¶
type FrameSource interface {
NextFrame() (data []byte, dur time.Duration, err error)
Close() 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 ¶
ProbeAndBuildSVCConfig is a convenience wrapper for ResolveSVC with mode="auto". Deprecated: use ResolveSVC for full control.
type SVCResult ¶
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.