Documentation
¶
Overview ¶
Package webrtc provides high-throughput WebRTC WHEP (WebRTC-HTTP Egress Protocol) streaming, pre-warmed DTLS certificate handling, UDP port multiplexing, and zero-allocation sendmmsg batching.
Index ¶
- type BatchingUDPMuxConn
- func (c *BatchingUDPMuxConn) Close() error
- func (c *BatchingUDPMuxConn) LocalAddr() net.Addr
- func (c *BatchingUDPMuxConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (c *BatchingUDPMuxConn) ReadFromAddrPort(b []byte) (int, netip.AddrPort, error)
- func (c *BatchingUDPMuxConn) SetDeadline(t time.Time) error
- func (c *BatchingUDPMuxConn) SetReadDeadline(t time.Time) error
- func (c *BatchingUDPMuxConn) SetWriteDeadline(t time.Time) error
- func (c *BatchingUDPMuxConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- func (c *BatchingUDPMuxConn) WriteToAddrPort(b []byte, addr netip.AddrPort) (int, error)
- type Engine
- type WHEPHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchingUDPMuxConn ¶
type BatchingUDPMuxConn struct {
// contains filtered or unexported fields
}
BatchingUDPMuxConn wraps a *net.UDPConn and implements both net.PacketConn and Pion ICE AddrPortReaderWriter for zero-allocation, adaptive sendmmsg packet batching.
func NewBatchingUDPMuxConn ¶
func NewBatchingUDPMuxConn(udpConn *net.UDPConn) *BatchingUDPMuxConn
NewBatchingUDPMuxConn wraps the provided UDPConn with platform-specific packet batching.
func (*BatchingUDPMuxConn) Close ¶
func (c *BatchingUDPMuxConn) Close() error
Close flushes all pending batches and closes the underlying UDP connection.
func (*BatchingUDPMuxConn) LocalAddr ¶
func (c *BatchingUDPMuxConn) LocalAddr() net.Addr
LocalAddr returns the local network address of the UDP listener.
func (*BatchingUDPMuxConn) ReadFrom ¶
ReadFrom reads an incoming packet from the underlying UDP connection.
func (*BatchingUDPMuxConn) ReadFromAddrPort ¶
ReadFromAddrPort implements ice.AddrPortReaderWriter for zero-allocation packet reading.
func (*BatchingUDPMuxConn) SetDeadline ¶
func (c *BatchingUDPMuxConn) SetDeadline(t time.Time) error
SetDeadline sets the read and write deadlines on the UDP socket.
func (*BatchingUDPMuxConn) SetReadDeadline ¶
func (c *BatchingUDPMuxConn) SetReadDeadline(t time.Time) error
SetReadDeadline sets the read deadline on the UDP socket.
func (*BatchingUDPMuxConn) SetWriteDeadline ¶
func (c *BatchingUDPMuxConn) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets the write deadline on the UDP socket.
func (*BatchingUDPMuxConn) WriteToAddrPort ¶
WriteToAddrPort implements ice.AddrPortReaderWriter for zero-allocation adaptive packet batching.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine encapsulates reusable Pion WebRTC instances, pre-generated DTLS certificates, and single-port UDP ICE multiplexing.
Concurrency & Performance:
- Pre-generates DTLS ECDSA P-256 certificates on startup, eliminating ~15-30ms CPU crypto spikes per client.
- Shares a single UDP listener port across thousands of concurrent WebRTC sessions via ICEUDPMux.
- Adapts packet egress with kernel-level batching (sendmmsg on Linux).
func NewEngine ¶
NewEngine initializes and configures a global WebRTC Engine with optimal media codecs and network socket buffers.
func (*Engine) Close ¶
Close gracefully closes the UDP listener socket and frees multiplexing resources.
func (*Engine) NewPeerConnection ¶
func (e *Engine) NewPeerConnection(baseConfig webrtc.Configuration) (*webrtc.PeerConnection, error)
NewPeerConnection allocates and configures a new WebRTC PeerConnection injecting the pre-generated DTLS certificate.
type WHEPHandler ¶
type WHEPHandler struct {
// contains filtered or unexported fields
}
WHEPHandler handles client WebRTC sessions following the WHEP (WebRTC-HTTP Egress Protocol) specification. It delivers ultra-low-latency (<500ms) H.264 video frames and synchronized AI inference DataChannel metadata.
func NewWHEPHandler ¶
func NewWHEPHandler(streamID string, rb *buffer.RingBuffer, mb *stream.MetadataBroadcaster, cfg *config.Config, engine ...*Engine) *WHEPHandler
NewWHEPHandler constructs a new WHEPHandler for the given camera stream and frame buffer.
func (*WHEPHandler) HandleOffer ¶
HandleOffer processes an incoming SDP Offer string from a WHEP client, configures ICE and DTLS, establishes a PeerConnection, sets up H.264 video and metadata DataChannels, and returns the SDP Answer string.