Documentation
¶
Index ¶
- Variables
- func MJPEGHandler(snapshotFn SnapshotFunc) http.Handler
- func MJPEGHandlerRGB24(snapshotFn RGB24SnapshotFunc, frameSize int) http.Handler
- type CameraStreamSet
- type CameraStreams
- type HLSManager
- func (m *HLSManager) Close()
- func (m *HLSManager) Done() <-chan struct{}
- func (m *HLSManager) InitSegment(rtspURL string) ([]byte, string, bool)
- func (m *HLSManager) Playlist(rtspURL string) (string, bool)
- func (m *HLSManager) PlaylistWait(ctx context.Context, rtspURL string) (string, bool)
- func (m *HLSManager) Segment(rtspURL string, id uint64) ([]byte, bool)
- func (m *HLSManager) SetWarmURLs(desired []string)
- type MSEManager
- type RGB24SnapshotFunc
- type RTSPServer
- func (rs *RTSPServer) Close()
- func (rs *RTSPServer) OnConnClose(ctx *gortsplib.ServerHandlerOnConnCloseCtx)
- func (rs *RTSPServer) OnConnOpen(ctx *gortsplib.ServerHandlerOnConnOpenCtx)
- func (rs *RTSPServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error)
- func (rs *RTSPServer) OnPlay(_ *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error)
- func (rs *RTSPServer) OnSessionClose(_ *gortsplib.ServerHandlerOnSessionCloseCtx)
- func (rs *RTSPServer) OnSessionOpen(_ *gortsplib.ServerHandlerOnSessionOpenCtx)
- func (rs *RTSPServer) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error)
- func (rs *RTSPServer) Start() error
- type SnapshotFunc
- type StreamManager
- type TalkbackCapabilities
- type TalkbackManager
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 (rs *RTSPServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error)
func (*RTSPServer) OnPlay ¶
func (rs *RTSPServer) OnPlay(_ *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error)
func (*RTSPServer) OnSessionClose ¶
func (rs *RTSPServer) OnSessionClose(_ *gortsplib.ServerHandlerOnSessionCloseCtx)
func (*RTSPServer) OnSessionOpen ¶
func (rs *RTSPServer) OnSessionOpen(_ *gortsplib.ServerHandlerOnSessionOpenCtx)
func (*RTSPServer) OnSetup ¶
func (rs *RTSPServer) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error)
func (*RTSPServer) Start ¶
func (rs *RTSPServer) Start() error
Start starts the RTSP server and registers consumers on Hub sources.
type SnapshotFunc ¶
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 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)