Documentation
¶
Index ¶
- Variables
- type Manager
- func (m *Manager) CanHandle(codec model.Format) bool
- func (m *Manager) CreateWHEPSession(streamKey string, offerSDP []byte) (answerSDP []byte, sessionID string, err error)
- func (m *Manager) DeleteWHEPSession(sessionID string) error
- func (m *Manager) PeerCount(camID string) int
- func (m *Manager) RegisterStream(key string, hub *streamhub.StreamHub, sps []byte)
- func (m *Manager) RegisteredHub(key string) *streamhub.StreamHub
- func (m *Manager) SetAudioInfo(camID string, codec string, muLaw bool, sampleRate, channels int) error
- func (m *Manager) SetOnSessionEnd(cb func(streamKey string))
- func (m *Manager) StopAll()
- func (m *Manager) UnregisterStream(key string)
- func (m *Manager) WriteAudio(camID string, pts int64, data []byte)
- func (m *Manager) WriteH264(key string, pts int64, au [][]byte)
- type ManagerOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMaxPeersReached is returned when the maximum number of concurrent // WebRTC peers is reached for a camera. ErrMaxPeersReached = errors.New("maximum WebRTC peers reached for camera") // ErrSessionNotFound is returned when the requested WHEP session does not exist. ErrSessionNotFound = errors.New("WebRTC session not found") // ErrUnsupportedCodec is returned when the codec is not supported for WebRTC. ErrUnsupportedCodec = errors.New("unsupported codec for WebRTC (H.264 only)") )
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages WebRTC WHEP sessions for camera streaming. H.264 video with optional G.711 (PCMU/PCMA) or Opus audio — the WebRTC mandatory codecs, passed through with zero transcoding. AAC cameras stay video-only (AAC is not a WebRTC codec; those keep the separate audio WS).
func NewManager ¶
func NewManager(opts ...ManagerOption) *Manager
NewManager creates a new WebRTC Manager with H.264 video-only support.
func (*Manager) CanHandle ¶
CanHandle returns true if the codec format is supported for WebRTC streaming. Only H.264 is supported (no H.265, no MJPEG).
func (*Manager) CreateWHEPSession ¶
func (m *Manager) CreateWHEPSession(streamKey string, offerSDP []byte) (answerSDP []byte, sessionID string, err error)
CreateWHEPSession creates a new WHEP session for the given stream. streamKey is normally the camera ID (main stream); the api handler passes the sub-stream key (camID+streamhub.SubStreamKeySuffix) for quality=sub sessions — main and sub sessions live in independent peer buckets. It processes the SDP offer, creates a PeerConnection with H.264 video only, and returns the SDP answer and session ID.
func (*Manager) DeleteWHEPSession ¶
DeleteWHEPSession removes a WHEP session and cleans up all associated resources. Returns ErrSessionNotFound if the session does not exist.
func (*Manager) PeerCount ¶ added in v0.12.0
PeerCount returns the number of active WHEP peers for the given camera (public — used by the /api/streams flow view, #469).
func (*Manager) RegisterStream ¶ added in v0.4.0
RegisterStream subscribes to a StreamHub for live frames. key is normally the camera ID (main stream) but may carry the sub-stream suffix (camID+streamhub.SubStreamKeySuffix) when the api handler serves quality=sub — main and sub entries then coexist as independent buckets. If hub is nil, this is a no-op. Safe to call multiple times for the same key. sps (optional, the stream's codec params) selects the H.264 profile variant offered for this stream's track — see NewManager's codec list.
func (*Manager) RegisteredHub ¶ added in v0.12.0
RegisteredHub returns the StreamHub a stream key is currently subscribed to, or nil when the key has no registration. Callers use it to detect a stale hub (recycled sub-stream puller) before unregistering (#513).
func (*Manager) SetAudioInfo ¶ added in v0.11.0
func (m *Manager) SetAudioInfo(camID string, codec string, muLaw bool, sampleRate, channels int) error
SetAudioInfo configures the audio track offered for a camera's WHEP sessions (#372). Must be called after RegisterStream. codec is the recorder's audio codec ("g711", "opus", ...); muLaw selects PCMU vs PCMA for G.711. AAC is not a WebRTC codec — it returns without configuring (those cameras keep the separate audio-WS path).
func (*Manager) SetOnSessionEnd ¶ added in v0.12.0
SetOnSessionEnd registers the per-session teardown hook fired from DeleteWHEPSession (#513). Set once at wiring time, before traffic arrives.
func (*Manager) StopAll ¶
func (m *Manager) StopAll()
StopAll closes all active WHEP sessions and releases resources.
func (*Manager) UnregisterStream ¶ added in v0.4.0
UnregisterStream unsubscribes from the StreamHub registered under key.
func (*Manager) WriteAudio ¶ added in v0.11.0
WriteAudio queues an audio frame for async writing to all WHEP peers of the given camera. Non-blocking — frames are dropped if a peer's audio buffer is full (audio glitches are preferable to stalling the pipeline).
func (*Manager) WriteH264 ¶
WriteH264 queues an H.264 access unit for async writing to all WHEP peers registered under the stream key (main camera ID or a sub-stream key — the hub subscription closures pass whichever key they registered under). This is non-blocking — frames are dropped if a peer's buffer is full to protect the recording pipeline.
type ManagerOption ¶
type ManagerOption func(*Manager)
ManagerOption configures a Manager.
func WithICEServers ¶ added in v0.10.0
func WithICEServers(servers []webrtc.ICEServer) ManagerOption
WithICEServers sets STUN/TURN servers used when creating PeerConnections. This enables cross-network (WAN/4G/remote WiFi) WHEP access. Leave empty for LAN-only deployments (preserves the legacy behavior).
func WithIdleTimeout ¶
func WithIdleTimeout(d time.Duration) ManagerOption
WithIdleTimeout sets the idle timeout for WHEP sessions.
func WithMaxPeers ¶
func WithMaxPeers(n int) ManagerOption
WithMaxPeers sets the maximum number of concurrent WHEP peers per camera.
func WithMetrics ¶ added in v0.6.0
func WithMetrics(m *metrics.Metrics) ManagerOption
WithMetrics sets the Prometheus metrics collector.