webrtc

package
v1.20.1-soundar.7 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 40 Imported by: 0

Documentation

Overview

Package webrtc contains WebRTC utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromStream

func FromStream(
	desc *description.Session,
	r *stream.Reader,
	pc *PeerConnection,
) error

FromStream maps a MediaMTX stream to a WebRTC connection

func ToStream

func ToStream(
	pc *PeerConnection,
	pathConf *conf.Path,
	subStream **stream.SubStream,
	log logger.Writer,
) ([]*description.Media, error)

ToStream maps a WebRTC connection to a MediaMTX stream.

func TracksAreValid

func TracksAreValid(medias []*sdp.MediaDescription) error

TracksAreValid checks whether tracks in the SDP are valid

Types

type InboundTrack

type InboundTrack struct {
	OnPacketRTP func(*rtp.Packet)
	// contains filtered or unexported fields
}

InboundTrack is an incoming track.

func (*InboundTrack) ClockRate

func (t *InboundTrack) ClockRate() int

ClockRate returns the clock rate. Needed by rtptime.GlobalDecoder

func (*InboundTrack) Codec

Codec returns the track codec.

func (*InboundTrack) PTSEqualsDTS

func (*InboundTrack) PTSEqualsDTS(*rtp.Packet) bool

PTSEqualsDTS returns whether PTS equals DTS. Needed by rtptime.GlobalDecoder

func (*InboundTrack) PacketNTP

func (t *InboundTrack) PacketNTP(pkt *rtp.Packet) (time.Time, bool)

PacketNTP returns the packet NTP.

type Net

type Net struct {
	UDPReadBufferSize int

	stdnet.Net
}

Net is stdnet.Net with the following changes: - Interfaces() is overridden to query the OS directly on every call without caching. - ListenUDP() is overridden to apply the configured read buffer size to the returned UDPConn.

func (*Net) InterfaceByIndex

func (n *Net) InterfaceByIndex(index int) (*transport.Interface, error)

InterfaceByIndex returns the interface specified by index.

func (*Net) InterfaceByName

func (n *Net) InterfaceByName(name string) (*transport.Interface, error)

InterfaceByName returns the interface specified by name.

func (*Net) Interfaces

func (n *Net) Interfaces() ([]*transport.Interface, error)

Interfaces returns the current list of network interfaces by querying the OS on every call, with no caching.

func (*Net) ListenUDP

func (n *Net) ListenUDP(network string, laddr *net.UDPAddr) (transport.UDPConn, error)

ListenUDP acts like ListenPacket for UDP networks and applies the configured read buffer size.

type OutboundDataChannel

type OutboundDataChannel struct {
	Label string
	// contains filtered or unexported fields
}

OutboundDataChannel is an outgoing data channel.

func (*OutboundDataChannel) Write

func (c *OutboundDataChannel) Write(data []byte)

Write writes data to the channel.

type OutboundTrack

type OutboundTrack struct {
	Caps webrtc.RTPCodecCapability
	// contains filtered or unexported fields
}

OutboundTrack is an outgoing track.

func (*OutboundTrack) WriteRTP

func (t *OutboundTrack) WriteRTP(pkt *rtp.Packet) error

WriteRTP writes a RTP packet.

func (*OutboundTrack) WriteRTPWithNTP

func (t *OutboundTrack) WriteRTPWithNTP(pkt *rtp.Packet, ntp time.Time) error

WriteRTPWithNTP writes a RTP packet.

type PeerConnection

type PeerConnection struct {
	Net                   transport.Net
	LocalRandomUDP        bool
	ICEUDPMux             ice.UDPMux
	ICETCPMux             *TCPMuxWrapper
	ICEServers            []webrtc.ICEServer
	IPsFromInterfaces     bool
	IPsFromInterfacesList []string
	AdditionalHosts       []string
	STUNGatherTimeout     time.Duration
	SupportsIPv6          bool
	Publish               bool
	OutboundTracks        []*OutboundTrack
	OutboundDataChannels  []*OutboundDataChannel
	Log                   logger.Writer
	// contains filtered or unexported fields
}

PeerConnection is a wrapper around webrtc.PeerConnection.

func (*PeerConnection) AddRemoteCandidate

func (co *PeerConnection) AddRemoteCandidate(candidate *webrtc.ICECandidateInit) error

AddRemoteCandidate adds a remote candidate.

func (*PeerConnection) Close

func (co *PeerConnection) Close()

Close closes the connection.

func (*PeerConnection) Connected

func (co *PeerConnection) Connected() <-chan struct{}

Connected returns when connected.

func (*PeerConnection) CreateFullAnswer

func (co *PeerConnection) CreateFullAnswer(
	offer *webrtc.SessionDescription,
	restarted bool,
) (*webrtc.SessionDescription, error)

CreateFullAnswer accepts an offer and creates a full answer.

func (*PeerConnection) CreateFullOffer

func (co *PeerConnection) CreateFullOffer() (*webrtc.SessionDescription, error)

CreateFullOffer creates a full offer.

func (*PeerConnection) CreatePartialOffer

func (co *PeerConnection) CreatePartialOffer(restart bool) (*webrtc.SessionDescription, error)

CreatePartialOffer creates a partial offer.

func (*PeerConnection) Failed

func (co *PeerConnection) Failed() <-chan struct{}

Failed returns when failed or closed.

func (*PeerConnection) GatherInboundTracks

func (co *PeerConnection) GatherInboundTracks(timeout time.Duration) error

GatherInboundTracks gathers incoming tracks.

func (*PeerConnection) GatheringDone

func (co *PeerConnection) GatheringDone() <-chan struct{}

GatheringDone returns when candidate gathering is complete.

func (*PeerConnection) InboundTracks

func (co *PeerConnection) InboundTracks() []*InboundTrack

InboundTracks returns incoming tracks.

func (*PeerConnection) LocalCandidate

func (co *PeerConnection) LocalCandidate() string

LocalCandidate returns the local candidate.

func (*PeerConnection) NewLocalCandidate

func (co *PeerConnection) NewLocalCandidate() <-chan *webrtc.ICECandidateInit

NewLocalCandidate returns when there's a new local candidate.

func (*PeerConnection) RemoteCandidate

func (co *PeerConnection) RemoteCandidate() string

RemoteCandidate returns the remote candidate.

func (*PeerConnection) RemoteDescription

func (co *PeerConnection) RemoteDescription() *webrtc.SessionDescription

RemoteDescription returns the current remote description.

func (*PeerConnection) SetAnswer

func (co *PeerConnection) SetAnswer(answer *webrtc.SessionDescription) error

SetAnswer sets the answer.

func (*PeerConnection) Start

func (co *PeerConnection) Start() error

Start starts the peer connection.

func (*PeerConnection) StartReading

func (co *PeerConnection) StartReading()

StartReading starts reading incoming tracks.

func (*PeerConnection) Stats

func (co *PeerConnection) Stats() *Stats

Stats returns statistics.

func (*PeerConnection) WaitUntilConnected

func (co *PeerConnection) WaitUntilConnected(timeout time.Duration) error

WaitUntilConnected waits until connection is established.

type Stats

type Stats struct {
	BytesReceived       uint64
	BytesSent           uint64
	RTPPacketsReceived  uint64
	RTPPacketsSent      uint64
	RTPPacketsLost      uint64
	RTPPacketsJitter    float64
	RTCPPacketsReceived uint64
	RTCPPacketsSent     uint64
}

Stats are WebRTC statistics.

type TCPMuxWrapper

type TCPMuxWrapper struct {
	Mux ice.TCPMux
	Ln  net.Listener
}

TCPMuxWrapper is a wrapper around ice.TCPMux.

Jump to

Keyboard shortcuts

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