media

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsProxyableStream added in v0.0.23

func IsProxyableStream(p pb.MediaStreamProtocol) bool

func IsVideoStream added in v0.0.23

func IsVideoStream(p pb.MediaStreamProtocol) bool

IsVideoStream returns true for streams that can be bridged to WebRTC.

func ResolveStreamIndex added in v0.0.23

func ResolveStreamIndex(r *http.Request, streams []*pb.MediaStream, prefer func(pb.MediaStreamProtocol) bool) (int, error)

ResolveStreamIndex returns the camera stream index to use. If ?stream=N is set, it validates and returns N. Otherwise it finds the first stream where prefer() returns true, falling back to stream 0.

Types

type Bridge

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

Bridge manages a single video source and fans out RTP packets to multiple consumers (WebRTC peers, RTSP server streams, etc.) via a shared track.

func (*Bridge) AddPeer

func (b *Bridge) AddPeer(offerSDP string) (string, error)

AddPeer creates a new WebRTC PeerConnection, adds the shared video track, performs SDP negotiation, and returns the SDP answer.

func (*Bridge) Codec

func (b *Bridge) Codec() string

Codec returns the codec MIME type (e.g., "video/H264").

func (*Bridge) OffRTP

func (b *Bridge) OffRTP(key string)

OffRTP removes an RTP tap.

func (*Bridge) OnRTP

func (b *Bridge) OnRTP(key string, cb func(*rtp.Packet))

OnRTP registers a callback that receives every RTP packet written to this bridge. Returns a key that can be passed to OffRTP to unregister.

func (*Bridge) PPS

func (b *Bridge) PPS() []byte

PPS returns the last seen H264 PPS NALU (may be nil).

func (*Bridge) SPS

func (b *Bridge) SPS() []byte

SPS returns the last seen H264 SPS NALU (may be nil).

type BridgeManager

type BridgeManager struct {
	OnEpoch func(key string, epoch time.Time)

	// DialContext, if set, is used by RTSP bridges to connect to the source.
	// This allows routing RTSP through a tunnel or custom transport.
	DialContext func(ctx context.Context, network, address string) (net.Conn, error)
	// contains filtered or unexported fields
}

BridgeManager is the registry of active bridges keyed by "entityId/cameraIndex".

func NewBridgeManager

func NewBridgeManager() *BridgeManager

func (*BridgeManager) GetOrCreate

func (bm *BridgeManager) GetOrCreate(key, sourceURL string) (*Bridge, error)

GetOrCreate returns an existing bridge or creates a new one. If the source URL changed the old bridge is torn down first. Supports rtsp://, rtsps://, and v4l2:// source URLs.

func (*BridgeManager) InvalidateEntity added in v1.0.0

func (bm *BridgeManager) InvalidateEntity(entityID string)

InvalidateEntity closes all bridges for the given entity ID. This forces browsers to reconnect and pick up new stream URLs.

func (*BridgeManager) SetupWebRTCMux

func (bm *BridgeManager) SetupWebRTCMux(conn net.PacketConn, tcpListener net.Listener)

SetupWebRTCMux configures a shared SettingEngine that multiplexes all ICE traffic through the given listeners. UDP and TCP ICE candidates are both gathered so browsers can fall back to TCP when UDP is blocked. conn may be nil when the UDP port could not be bound; ICE then gathers TCP mux candidates (and per-connection UDP candidates where possible).

type GetStreamsFunc added in v0.0.23

type GetStreamsFunc func(entityID string) []*pb.MediaStream

GetStreamsFunc returns the camera streams for an entity, or nil if not found.

type Peer

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

Peer represents a single WHEP viewer connected to a Bridge.

type RTSPServer

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

RTSPServer relays camera streams from entities as an RTSP server. Clients connect to rtsp://host:port/media/rtsp/{entityId}/{cameraIndex}. Supports both RTSP sources (direct relay) and HTTP MJPEG sources (fetches MJPEG, packetizes as RTP/JPEG).

func NewRTSPServer

func NewRTSPServer(getStreams GetStreamsFunc, bridges *BridgeManager, checkAccess func(remoteAddr string) bool) *RTSPServer

NewRTSPServer creates an RTSP relay server. checkAccess is called per connection with the client's remote address to decide whether access is permitted (policy evaluation).

func (*RTSPServer) Close

func (rs *RTSPServer) Close()

Close shuts down the RTSP server.

func (*RTSPServer) OnConnOpen

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

OnConnOpen rejects connections the access policy denies for the client's remote address.

func (*RTSPServer) OnDescribe

OnDescribe handles DESCRIBE requests.

func (*RTSPServer) OnPlay

OnPlay handles PLAY requests.

func (*RTSPServer) OnSessionClose

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

OnSessionClose handles session disconnection (RTCP timeout, TCP close, TEARDOWN).

func (*RTSPServer) OnSetup

OnSetup handles SETUP requests.

func (*RTSPServer) Start

func (rs *RTSPServer) Start(ln net.Listener) error

Start starts the RTSP server using the provided listener. UDP RTP/RTCP need consecutive even/odd ports. We pick the nearest even port at or above the TCP port.

Jump to

Keyboard shortcuts

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