stream

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 42 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

This section is empty.

Variables

View Source
var (
	ErrTalkbackUnsupported = errors.New("camera has no supported ONVIF audio backchannel")
	ErrTalkbackBusy        = errors.New("another talkback session is active")
)

Functions

func MJPEGHandler

func MJPEGHandler(snapshotFn SnapshotFunc) http.Handler

MJPEGHandler returns an HTTP handler that serves a multipart MJPEG stream. This variant accepts a SnapshotFunc that returns *image.RGBA.

func MJPEGHandlerRGB24

func MJPEGHandlerRGB24(snapshotFn RGB24SnapshotFunc, frameSize int) http.Handler

MJPEGHandlerRGB24 returns an optimized MJPEG handler that avoids per-frame RGBA allocation by working directly with raw RGB24 data.

Types

type CameraStreamSet

type CameraStreamSet struct {
	Name    string        `json:"name"`
	Streams CameraStreams `json:"streams"`
}

CameraStreamSet pairs a camera name with its consumable stream URLs.

func CameraStreamCapabilities

func CameraStreamCapabilities(cams []config.CameraConfig, rtspCfg config.RTSPServerConfig, rtspHost string) []CameraStreamSet

CameraStreamCapabilities derives the consumable stream inventory for every enabled camera. The sub-stream rule mirrors NewRTSPServer exactly: a `_sub` path is published only when the camera has a distinct low-res URL (RecordURL set and different from URL). rtspHost is the host clients should dial for RTSP (the API request host, or a configured/placeholder host for the CLI); it is only used when rtspCfg.Enabled.

type CameraStreams

type CameraStreams struct {
	RTSPMain string `json:"rtsp_main,omitempty"`
	RTSPSub  string `json:"rtsp_sub,omitempty"`
	WebRTC   string `json:"webrtc,omitempty"`
	HLS      string `json:"hls,omitempty"`
	MJPEG    string `json:"mjpeg,omitempty"`
	MSE      string `json:"mse,omitempty"`
	Snapshot string `json:"snapshot,omitempty"`
}

CameraStreams is the protocol-by-protocol inventory of how one camera can be consumed. RTSP fields are absolute URLs (empty when the RTSP republish server is disabled, or RTSPSub when the camera has no distinct sub-stream). HTTP fields are always paths relative to the API base. JSON tags mirror the CameraStreamURLs schema so the CLI and HTTP API serialize identically.

type HLSManager

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

HLSManager owns one hlsConsumer per RTSP URL and reaps idle ones.

func NewHLSManager

func NewHLSManager(hub *rtsp.Hub) *HLSManager

NewHLSManager creates the manager and starts the idle-reaper janitor.

func (*HLSManager) Close

func (m *HLSManager) Close()

Close stops the janitor and detaches every consumer from its source.

func (*HLSManager) Done

func (m *HLSManager) Done() <-chan struct{}

Done is closed when the manager is closed, so external loops (the warm reconcile loop) stop at shutdown regardless of their own context.

func (*HLSManager) InitSegment

func (m *HLSManager) InitSegment(rtspURL string) ([]byte, string, bool)

InitSegment serves the fMP4 init segment.

func (*HLSManager) Playlist

func (m *HLSManager) Playlist(rtspURL string) (string, bool)

Playlist serves the live media playlist, lazily starting the consumer.

func (*HLSManager) PlaylistWait

func (m *HLSManager) PlaylistWait(ctx context.Context, rtspURL string) (string, bool)

PlaylistWait serves the live playlist, holding the request until the Apple-minimum live window is ready or ctx is done. Native HLS clients (AVPlayer) treat an HTTP 503 on the playlist as fatal, so callers must wait out the cold warmup window rather than 503 a client that would never retry.

func (*HLSManager) Segment

func (m *HLSManager) Segment(rtspURL string, id uint64) ([]byte, bool)

Segment serves one media segment by its sequence id.

func (*HLSManager) SetWarmURLs

func (m *HLSManager) SetWarmURLs(desired []string)

SetWarmURLs reconciles the kept-warm URL set to exactly desired: it warms newly-desired URLs, drops no-longer-desired ones (detaching their consumers), and refreshes any whose source was recreated by a stop/start. Keeping a consumer warm leaves its segment ring populated so the first viewer's playlist is served instantly. No-op without a hub or after Close.

type MSEManager

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

MSEManager manages per-camera MSE consumers.

func NewMSEManager

func NewMSEManager(hub *rtsp.Hub, allowedOrigins, trustedProxies []string) *MSEManager

NewMSEManager creates an MSE manager.

func (*MSEManager) ClientCounts

func (m *MSEManager) ClientCounts() map[string]int

ClientCounts returns the number of connected MSE clients per camera name. Consumers are keyed by RTSP URL, so a camera with distinct main and sub streams contributes from two consumers; counts are summed by camera name.

func (*MSEManager) Close

func (m *MSEManager) Close()

Close shuts down all MSE consumers and disconnects all clients.

func (*MSEManager) DroppedFrames

func (m *MSEManager) DroppedFrames() int64

DroppedFrames returns the cumulative count of MSE frames dropped to full client buffers across all cameras.

func (*MSEManager) HandleWebSocket

func (m *MSEManager) HandleWebSocket(w http.ResponseWriter, r *http.Request, cameraName, rtspURL string)

HandleWebSocket upgrades an HTTP request to a WebSocket and streams fMP4 to the client.

type RGB24SnapshotFunc

type RGB24SnapshotFunc func(dst []byte) (w, h int, ok bool)

RGB24SnapshotFunc copies the raw RGB24 frame into dst and returns dimensions. Returns false if no frame is available.

type RTSPServer

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

RTSPServer re-publishes camera streams via RTSP.

func NewRTSPServer

func NewRTSPServer(hub *rtsp.Hub, cfg config.RTSPServerConfig, authChecker *auth.Checker, cameras []config.CameraConfig) *RTSPServer

NewRTSPServer creates a new RTSP re-publishing server.

func (*RTSPServer) Close

func (rs *RTSPServer) Close()

Close shuts down the RTSP server and removes all consumers.

func (*RTSPServer) OnConnClose

func (rs *RTSPServer) OnConnClose(ctx *gortsplib.ServerHandlerOnConnCloseCtx)

func (*RTSPServer) OnConnOpen

func (rs *RTSPServer) OnConnOpen(ctx *gortsplib.ServerHandlerOnConnOpenCtx)

func (*RTSPServer) OnDescribe

func (*RTSPServer) OnPlay

func (*RTSPServer) OnSessionClose

func (rs *RTSPServer) OnSessionClose(_ *gortsplib.ServerHandlerOnSessionCloseCtx)

func (*RTSPServer) OnSessionOpen

func (rs *RTSPServer) OnSessionOpen(_ *gortsplib.ServerHandlerOnSessionOpenCtx)

func (*RTSPServer) OnSetup

func (*RTSPServer) Start

func (rs *RTSPServer) Start() error

Start starts the RTSP server and registers consumers on Hub sources.

type SnapshotFunc

type SnapshotFunc func() *image.RGBA

SnapshotFunc returns the latest snapshot for a camera.

type StreamManager

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

StreamManager manages per-camera WebRTC sessions with direct RTP forwarding.

func NewStreamManager

func NewStreamManager(hub *rtsp.Hub, iceServers []config.ICEServerConfig) *StreamManager

NewStreamManager creates a stream manager that uses an RTSP Hub for direct forwarding. iceServers configures the STUN/TURN servers offered to WebRTC peers; pass nil to offer none (the privacy-first default).

func (*StreamManager) ClientCounts

func (sm *StreamManager) ClientCounts() map[string]int

ClientCounts returns the number of connected WebRTC peers per camera name.

func (*StreamManager) Close

func (sm *StreamManager) Close()

Close shuts down all sessions and peer connections.

func (*StreamManager) HandleOffer

func (sm *StreamManager) HandleOffer(cameraName, rtspURL string, offer webrtc.SessionDescription) (*webrtc.SessionDescription, error)

HandleOffer processes a WebRTC SDP offer and returns an SDP answer.

type TalkbackCapabilities

type TalkbackCapabilities struct {
	Supported bool   `json:"supported"`
	Codec     string `json:"codec,omitempty"`
	Reason    string `json:"reason,omitempty"`
}

type TalkbackManager

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

TalkbackManager bridges a browser's microphone-only WebRTC peer to an ONVIF Profile T G.711 RTSP backchannel. Only one speaker can own a camera at a time, preventing overlapping household sessions from reaching the device.

func NewTalkbackManager

func NewTalkbackManager(iceServers []config.ICEServerConfig) *TalkbackManager

func (*TalkbackManager) Capabilities

func (m *TalkbackManager) Capabilities(ctx context.Context, rtspURL string) TalkbackCapabilities

func (*TalkbackManager) HandleOffer

func (m *TalkbackManager) HandleOffer(ctx context.Context, cameraName, rtspURL string, offer webrtc.SessionDescription) (*webrtc.SessionDescription, error)

Jump to

Keyboard shortcuts

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