webrtc

package
v2.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 22 Imported by: 0

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

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

func (c *BatchingUDPMuxConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)

ReadFrom reads an incoming packet from the underlying UDP connection.

func (*BatchingUDPMuxConn) ReadFromAddrPort

func (c *BatchingUDPMuxConn) ReadFromAddrPort(b []byte) (int, netip.AddrPort, error)

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) WriteTo

func (c *BatchingUDPMuxConn) WriteTo(p []byte, addr net.Addr) (n int, err error)

WriteTo writes a packet with destination net.Addr.

func (*BatchingUDPMuxConn) WriteToAddrPort

func (c *BatchingUDPMuxConn) WriteToAddrPort(b []byte, addr netip.AddrPort) (int, error)

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

func NewEngine(cfg *config.Config) (*Engine, error)

NewEngine initializes and configures a global WebRTC Engine with optimal media codecs and network socket buffers.

func (*Engine) Close

func (e *Engine) Close() error

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

func (h *WHEPHandler) HandleOffer(_ context.Context, offerSDP string) (string, error)

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.

Jump to

Keyboard shortcuts

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