mediaweb

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MediaSessionWebrtc

type MediaSessionWebrtc struct {
	Laddr  string
	Raddr  string
	Codecs []media.Codec
	Mode   string

	Config MediaSessionWebrtcConfig
	// contains filtered or unexported fields
}

MediaSessionWebrtc is the direct ICE + DTLS-SRTP media stack. It intentionally does not embed MediaSession: legacy RTP uses two known UDP destinations, whereas WebRTC must send every DTLS/SRTP/SRTCP packet through the candidate pair selected and consent-checked by ICE.

Signalling lifecycle:

  • Init gathers local candidates (non-trickle ICE).
  • LocalSDP(false) creates an offer, or RemoteSDP(..., false) consumes one.
  • RemoteSDP starts ICE as controlling for a local offer and controlled for a local answer. It returns before connectivity checks finish.
  • Finalize waits for ICE, performs DTLS, verifies the SDP fingerprint and derives the SRTP keys. RTP must not be used before Finalize succeeds.

func (*MediaSessionWebrtc) Close

func (m *MediaSessionWebrtc) Close() error

func (*MediaSessionWebrtc) Codec

func (m *MediaSessionWebrtc) Codec() media.Codec

func (*MediaSessionWebrtc) CommonCodecs

func (m *MediaSessionWebrtc) CommonCodecs() []media.Codec

func (*MediaSessionWebrtc) Finalize

func (m *MediaSessionWebrtc) Finalize(ctx context.Context) error

Finalize completes ICE first and DTLS second. This order is the central WebRTC layering rule: ICE selects and maintains the network path; DTLS and all encrypted media then travel only over that path.

func (*MediaSessionWebrtc) Init

Init creates the ICE agent and waits for candidate gathering to finish. SIP offer/answer has no standard trickle-ICE exchange, so the SDP returned later contains a complete candidate set and a=end-of-candidates.

func (*MediaSessionWebrtc) LocalSDP

func (m *MediaSessionWebrtc) LocalSDP(_ context.Context, answered bool) ([]byte, error)

LocalSDP returns a complete, non-trickle WebRTC SDP. answered controls the DTLS setup attribute: an offer is actpass; an answer uses the role selected while parsing the remote offer.

func (*MediaSessionWebrtc) ReadRTCP

func (m *MediaSessionWebrtc) ReadRTCP(buf []byte, pkts []rtcp.Packet) (int, error)

func (*MediaSessionWebrtc) ReadRTP

func (m *MediaSessionWebrtc) ReadRTP(buf []byte, pkt *rtp.Packet) (int, error)

func (*MediaSessionWebrtc) ReadRTPRaw

func (m *MediaSessionWebrtc) ReadRTPRaw(buf []byte) (int, error)

func (*MediaSessionWebrtc) RemoteSDP

func (m *MediaSessionWebrtc) RemoteSDP(_ context.Context, body []byte, offered bool) error

RemoteSDP parses an answer when offered is true, otherwise it parses an offer. Starting ICE here is non-blocking so a SIP answer can be sent before the browser is required to complete connectivity checks.

func (*MediaSessionWebrtc) StartRTP

func (m *MediaSessionWebrtc) StartRTP(rw int8) error

func (*MediaSessionWebrtc) StopRTP

func (m *MediaSessionWebrtc) StopRTP(rw int8, duration time.Duration) error

func (*MediaSessionWebrtc) WriteRTCP

func (m *MediaSessionWebrtc) WriteRTCP(pkt rtcp.Packet) error

func (*MediaSessionWebrtc) WriteRTP

func (m *MediaSessionWebrtc) WriteRTP(pkt *rtp.Packet) error

type MediaSessionWebrtcConfig

type MediaSessionWebrtcConfig struct {
	ICEURLs         []string
	NetworkTypes    []ice.NetworkType
	PortMin         uint16
	PortMax         uint16
	IncludeLoopback bool
	InterfaceFilter func(interfaceName string) bool
	DTLS            media.DTLSConfig
}

MediaSessionWebrtcConfig contains transport settings which do not belong to the codec-level media API. ICEURLs accepts STUN and TURN URLs understood by Pion (for example stun:stun.example.org:3478).

type RTPReadStats

type RTPReadStats = media.RTPReadStats

RTPReadStats is shared with the core media package so existing statistics hooks can consume WebRTC and UDP RTP sessions uniformly.

type RTPSessionWebrtc

type RTPSessionWebrtc struct {
	// Keep pointers at the top to reduce GC scanning work.
	Sess *MediaSessionWebrtc

	// RTCPReportInterval controls sender/receiver report frequency. Set it
	// before Monitor or MonitorBackground. Zero uses five seconds.
	RTCPReportInterval time.Duration
	// contains filtered or unexported fields
}

RTPSessionWebrtc adds RTP statistics and RTCP reporting to a negotiated MediaSessionWebrtc transport. It is separate from MediaSessionWebrtc so the ICE/DTLS/SRTP lifecycle does not own application-facing packet wrappers.

Unlike the legacy RTPSession this type has no symmetric-RTP address learning, RTP source lock or separate RTCP destination. ICE authenticates the selected path, while WebRTC sends both RTP and RTCP over that one path (rtcp-mux).

func NewRTPSessionWebrtc

func NewRTPSessionWebrtc(sess *MediaSessionWebrtc) *RTPSessionWebrtc

func (*RTPSessionWebrtc) Close

func (s *RTPSessionWebrtc) Close() error

Close requests RTCP monitoring to stop without waiting for the goroutines.

func (*RTPSessionWebrtc) Monitor

func (s *RTPSessionWebrtc) Monitor() error

Monitor reads incoming SRTCP and periodically writes encrypted RTCP reports. It blocks until Close, a read failure or a write failure.

func (*RTPSessionWebrtc) MonitorBackground

func (s *RTPSessionWebrtc) MonitorBackground() error

MonitorBackground starts the RTCP reader and report writer in the background. Call MonitorClose before closing MediaSessionWebrtc when deterministic cleanup is required.

func (*RTPSessionWebrtc) MonitorClose

func (s *RTPSessionWebrtc) MonitorClose() error

MonitorClose stops RTCP monitoring and waits for both monitor goroutines. The ICE and media transports remain open.

func (*RTPSessionWebrtc) OnReadRTCP

func (s *RTPSessionWebrtc) OnReadRTCP(f func(pkt rtcp.Packet, rtpStats RTPReadStats))

func (*RTPSessionWebrtc) OnWriteRTCP

func (s *RTPSessionWebrtc) OnWriteRTCP(f func(pkt rtcp.Packet, rtpStats RTPWriteStats))

func (*RTPSessionWebrtc) ReadRTCP

func (s *RTPSessionWebrtc) ReadRTCP(buf []byte, pkts []rtcp.Packet) (int, error)

func (*RTPSessionWebrtc) ReadRTP

func (s *RTPSessionWebrtc) ReadRTP(buf []byte, pkt *rtp.Packet) (int, error)

ReadRTP decrypts through MediaSessionWebrtc and updates the receiver report counters. The generic RTPPacketReader can use RTPSessionWebrtc directly.

func (*RTPSessionWebrtc) ReadRTPRaw

func (s *RTPSessionWebrtc) ReadRTPRaw(buf []byte) (int, error)

func (*RTPSessionWebrtc) ReadStats

func (s *RTPSessionWebrtc) ReadStats() RTPReadStats

func (*RTPSessionWebrtc) WriteRTCP

func (s *RTPSessionWebrtc) WriteRTCP(pkt rtcp.Packet) error

func (*RTPSessionWebrtc) WriteRTP

func (s *RTPSessionWebrtc) WriteRTP(pkt *rtp.Packet) error

WriteRTP encrypts through MediaSessionWebrtc and updates sender-report counters only after the packet has been written successfully.

func (*RTPSessionWebrtc) WriteStats

func (s *RTPSessionWebrtc) WriteStats() RTPWriteStats

type RTPWriteStats

type RTPWriteStats = media.RTPWriteStats

RTPWriteStats is shared with the core media package so existing statistics hooks can consume WebRTC and UDP RTP sessions uniformly.

Jump to

Keyboard shortcuts

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