stream

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: AGPL-3.0 Imports: 8 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

Overview

Package stream joins one camera to one hub: dial, depacketise, mux, publish, on repeat until the context is cancelled or something fails.

Index

Constants

View Source
const DefaultMediaTimeout = 30 * time.Second

DefaultMediaTimeout bounds how long Run tolerates zero decoded video frames before giving up on the connection and returning an error, so the supervisor tears it down and reconnects.

This exists because internal/baichuan's idle-read timeout does not catch the failure that actually happened in production on 2026-09-08: a camera holding a stale session from a client that died without sending stream-stop still answers a new login, hands out a valid nonce, and keeps the connection responsive at the byte level (it acks other protocol traffic), while never sending a single media frame. Bytes kept arriving, so the idle timeout's read deadline kept getting pushed out, and two streams sat reporting connected:true, 0 fps, restarts:0 for over 25 seconds with no reconnection attempt before this was caught by hand. Byte liveness and media liveness are different facts about a connection, and only media liveness is what this package's job depends on.

30 seconds is chosen from the fleet measurements taken the same day, against the whole running fleet, not a lab bench: every healthy stream observed ran between 9.9 and 25.1 fps with last_frame_age_seconds consistently under 0.1, including a 4K main stream whose keyframes span several messages and a substream under load. None of that comes anywhere close to even a single second of genuine gap between decoded frames. 30s is a full order of magnitude above the worst observed gap, not a value tuned close to it, so it will not fire on a camera stuttering under load, a keyframe taking longer to reassemble, or ordinary network jitter. It is also double DefaultIdleTimeout: a fully silent camera (no bytes at all, not even keepalive traffic) is always caught by the idle-read timeout first, since that fires at 15s: this timeout exists specifically to catch the case the idle timeout structurally cannot, a connection with traffic but no media, so it does not need to race it and can afford to be patient. The production incident this responds to ran for minutes before anyone noticed; catching it in 30s instead is a large improvement without risking a reconnect storm on a healthy fleet.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, cfg Config, h *hub.Hub) (err error)

Run dials cfg's camera, starts its video stream, and publishes muxed MPEG-TS to h until ctx is cancelled or an error occurs. It never retries: retry and backoff belong to the supervisor that runs many of these, since a runner that retries internally would hold the camera's one connection for that stream and block its own replacement from ever connecting.

Run returns promptly on an already cancelled context without dialling, so a supervisor can cancel a Config before Run has had a chance to start it.

Types

type Config

type Config struct {
	Name     string
	Address  string
	Username string
	Password string
	Stream   string // "main", "sub" or "extern"

	// Sink, when non-nil, receives every decoded frame before muxing. Nil
	// is the default and the only state the HTTP output has ever run in.
	Sink FrameSink

	// MediaTimeout overrides DefaultMediaTimeout. Zero means the default.
	//
	// This is a Config field, not a TOML setting: unlike a per-camera value
	// such as a stream name or credentials, the right timeout here is a
	// property of the protocol's own frame cadence (see
	// DefaultMediaTimeout's derivation from fleet-wide fps measurements),
	// the same reasoning that kept baichuan.Options.IdleTimeout out of the
	// TOML config. Exposing it to operators would invite "fixing" a camera
	// that is actually failing by loosening the timeout that exists to
	// catch exactly that, which defeats the point of the watchdog. It stays
	// a Go field so tests can shorten it without a live camera or a config
	// file.
	MediaTimeout time.Duration
}

type FrameSink

type FrameSink interface {
	Frame(baichuan.Frame)
}

Config names one camera stream to run. FrameSink receives every frame a stream decodes, before it is muxed.

It exists so an output that needs frames rather than TS bytes, such as RTSP, can have them without the hub carrying frames and without demuxing TS back into them. Implementations must not block: this runs on the camera goroutine, and anything slow here stalls the read loop that the media watchdog is watching.

Jump to

Keyboard shortcuts

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