sfu

package
v1.1.5-fixbuffer7 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SimpleReceiver = iota + 1
	SimulcastReceiver
	SVCReceiver
)

Variables

View Source
var (
	// ErrTransportExists join is called after a peerconnection is established
	ErrTransportExists = errors.New("rtc transport already exists for this connection")
	// ErrNoTransportEstablished cannot signal before join
	ErrNoTransportEstablished = errors.New("no rtc transport exists for this Peer")
	// ErrOfferIgnored if offer received in unstable state
	ErrOfferIgnored = errors.New("offered ignored")
)

Functions

This section is empty.

Types

type Buffer

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

Buffer contains all packets

func NewBuffer

func NewBuffer(track *webrtc.Track, o BufferOptions) *Buffer

NewBuffer constructs a new Buffer

type BufferOptions

type BufferOptions struct {
	TWCCExt    int
	BufferTime int
	MaxBitRate uint64
}

BufferOptions provides configuration options for the buffer

type Candidates added in v1.0.40

type Candidates struct {
	IceLite    bool     `mapstructure:"icelite"`
	NAT1To1IPs []string `mapstructure:"nat1to1"`
}

type Config

type Config struct {
	SFU struct {
		Ballast int64 `mapstructure:"ballast"`
	} `mapstructure:"sfu"`
	WebRTC WebRTCConfig `mapstructure:"webrtc"`
	Log    log.Config   `mapstructure:"log"`
	Router RouterConfig `mapstructure:"router"`
}

Config for base SFU

type ICEServerConfig

type ICEServerConfig struct {
	URLs       []string `mapstructure:"urls"`
	Username   string   `mapstructure:"username"`
	Credential string   `mapstructure:"credential"`
}

ICEServerConfig defines parameters for ice servers

type MediaEngine

type MediaEngine struct {
	webrtc.MediaEngine
}

MediaEngine handles stream codecs

func (*MediaEngine) PopulateFromSDP

func (e *MediaEngine) PopulateFromSDP(sd webrtc.SessionDescription) error

PopulateFromSDP finds all codecs in sd and adds them to m, using the dynamic payload types and parameters from sd. PopulateFromSDP is intended for use when answering a request. The offerer sets the PayloadTypes for the connection. PopulateFromSDP allows an answerer to properly match the PayloadTypes from the offerer. A MediaEngine populated by PopulateFromSDP should be used only for a single session.

type Peer added in v1.0.23

type Peer struct {
	OnIceCandidate func(*webrtc.ICECandidateInit)
	OnOffer        func(*webrtc.SessionDescription)
	// contains filtered or unexported fields
}

Peer represents a single peer signal session

func NewPeer added in v1.0.23

func NewPeer(sfu *SFU) Peer

NewPeer creates a new Peer for signaling with the given SFU

func (*Peer) Answer added in v1.0.23

func (p *Peer) Answer(sdp webrtc.SessionDescription) (*webrtc.SessionDescription, error)

Answer an offer from remote

func (*Peer) Close added in v1.0.23

func (p *Peer) Close() error

Close shuts down the peer connection and sends true to the done channel

func (*Peer) Join added in v1.0.23

func (p *Peer) Join(sid string, sdp webrtc.SessionDescription) (*webrtc.SessionDescription, error)

Join initializes this peer for a given sessionID (takes an SDPOffer)

func (*Peer) SetRemoteDescription added in v1.0.23

func (p *Peer) SetRemoteDescription(sdp webrtc.SessionDescription) error

SetRemoteDescription when receiving an answer from remote

func (*Peer) Trickle added in v1.0.23

func (p *Peer) Trickle(candidate webrtc.ICECandidateInit) error

Trickle candidates available for this peer

type Receiver

type Receiver interface {
	Start()
	Track() *webrtc.Track
	AddSender(sender Sender)
	DeleteSender(pid string)
	SpatialLayer() uint8
	OnCloseHandler(fn func())
	OnTransportWideCC(fn func(sn uint16, timeNS int64, marker bool))
	SendRTCP(p []rtcp.Packet)
	SetRTCPCh(ch chan []rtcp.Packet)
	WriteBufferedPacket(sn []uint16, track *webrtc.Track, snOffset uint16, tsOffset, ssrc uint32) error
}

Receiver defines a interface for a track receivers

func NewWebRTCReceiver added in v1.0.16

func NewWebRTCReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Track, config BufferOptions) Receiver

NewWebRTCReceiver creates a new webrtc track receivers

type Router

type Router interface {
	ID() string
	Config() RouterConfig
	AddReceiver(track *webrtc.Track, receiver *webrtc.RTPReceiver) *receiverRouter
	AddSender(p *WebRTCTransport, rr *receiverRouter) error
	AddTWCCExt(id string, ext int)
	SendRTCP(pkts []rtcp.Packet)
	Stop()
}

Router defines a track rtp/rtcp router

type RouterConfig added in v1.0.15

type RouterConfig struct {
	MaxBandwidth  uint64          `mapstructure:"maxbandwidth"`
	MaxBufferTime int             `mapstructure:"maxbuffertime"`
	Simulcast     SimulcastConfig `mapstructure:"simulcast"`
}

RouterConfig defines router configurations

type SFU

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

SFU represents an sfu instance

func NewSFU

func NewSFU(c Config) *SFU

NewSFU creates a new sfu instance

func (*SFU) NewWebRTCTransport

func (s *SFU) NewWebRTCTransport(sid string, me MediaEngine) (*WebRTCTransport, error)

NewWebRTCTransport creates a new WebRTCTransport that is a member of a session

type Sender

type Sender interface {
	ID() string
	Start()
	Close()
	Kind() webrtc.RTPCodecType
	Type() SenderType
	Track() *webrtc.Track
	Transceiver() *webrtc.RTPTransceiver
	Mute(val bool)
	WriteRTP(*rtp.Packet)
	CurrentSpatialLayer() uint8
	OnCloseHandler(fn func())
	// Simulcast/SVC events
	SwitchSpatialLayer(layer uint8)
	SwitchTemporalLayer(layer uint8)
}

Sender defines a interface for a track receivers

func NewSimpleSender added in v1.0.23

func NewSimpleSender(id string, router *receiverRouter, transceiver *webrtc.RTPTransceiver) Sender

NewSimpleSender creates a new track sender instance

func NewSimulcastSender added in v1.0.23

func NewSimulcastSender(id string, router *receiverRouter, transceiver *webrtc.RTPTransceiver, layer uint8, conf SimulcastConfig) Sender

NewSimulcastSender creates a new track sender instance

type SenderType added in v1.0.26

type SenderType int

SenderType determines the type of a sender

const (
	SimpleSenderType SenderType = iota + 1
	SimulcastSenderType
	SVCSenderType
)

type Session

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

Session represents a set of transports. Transports inside a session are automatically subscribed to each other.

func NewSession

func NewSession(id string) *Session

NewSession creates a new session

func (*Session) AddTransport

func (s *Session) AddTransport(transport Transport)

AddTransport adds a transport to the session

func (*Session) OnClose

func (s *Session) OnClose(f func())

OnClose is called when the session is closed

func (*Session) Publish added in v1.0.41

func (s *Session) Publish(router Router, rr *receiverRouter)

Publish will add a Sender to all peers in current Session from given Receiver

func (*Session) RemoveTransport

func (s *Session) RemoveTransport(tid string)

RemoveTransport removes a transport from the session

func (*Session) Subscribe added in v1.0.41

func (s *Session) Subscribe(p *WebRTCTransport)

Subscribe will create a Sender for every other Receiver in the session

func (*Session) Transports

func (s *Session) Transports() map[string]Transport

Transports returns transports in this session

type SimpleSender added in v1.0.23

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

SimpleSender represents a Sender which writes RTP to a webrtc track

func (*SimpleSender) Close added in v1.0.23

func (s *SimpleSender) Close()

Close track

func (*SimpleSender) CurrentSpatialLayer added in v1.0.23

func (s *SimpleSender) CurrentSpatialLayer() uint8

func (*SimpleSender) ID added in v1.0.23

func (s *SimpleSender) ID() string

func (*SimpleSender) Kind added in v1.0.23

func (s *SimpleSender) Kind() webrtc.RTPCodecType

func (*SimpleSender) Mute added in v1.0.23

func (s *SimpleSender) Mute(val bool)

func (*SimpleSender) OnCloseHandler added in v1.0.23

func (s *SimpleSender) OnCloseHandler(fn func())

OnCloseHandler method to be called on remote tracked removed

func (*SimpleSender) Start added in v1.0.30

func (s *SimpleSender) Start()

func (*SimpleSender) SwitchSpatialLayer added in v1.0.23

func (s *SimpleSender) SwitchSpatialLayer(layer uint8)

func (*SimpleSender) SwitchTemporalLayer added in v1.0.23

func (s *SimpleSender) SwitchTemporalLayer(layer uint8)

func (*SimpleSender) Track added in v1.0.30

func (s *SimpleSender) Track() *webrtc.Track

func (*SimpleSender) Transceiver added in v1.0.41

func (s *SimpleSender) Transceiver() *webrtc.RTPTransceiver

func (*SimpleSender) Type added in v1.0.26

func (s *SimpleSender) Type() SenderType

func (*SimpleSender) WriteRTP added in v1.0.23

func (s *SimpleSender) WriteRTP(pkt *rtp.Packet)

WriteRTP to the track

type SimulcastConfig added in v1.0.18

type SimulcastConfig struct {
	BestQualityFirst    bool `mapstructure:"bestqualityfirst"`
	EnableTemporalLayer bool `mapstructure:"enabletemporallayer"`
}

type SimulcastSender added in v1.0.23

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

SimulcastSender represents a Sender which writes RTP to a webrtc track

func (*SimulcastSender) Close added in v1.0.23

func (s *SimulcastSender) Close()

Close track

func (*SimulcastSender) CurrentSpatialLayer added in v1.0.23

func (s *SimulcastSender) CurrentSpatialLayer() uint8

func (*SimulcastSender) ID added in v1.0.23

func (s *SimulcastSender) ID() string

func (*SimulcastSender) Kind added in v1.0.23

func (s *SimulcastSender) Kind() webrtc.RTPCodecType

func (*SimulcastSender) Mute added in v1.0.23

func (s *SimulcastSender) Mute(val bool)

func (*SimulcastSender) OnCloseHandler added in v1.0.23

func (s *SimulcastSender) OnCloseHandler(fn func())

OnCloseHandler method to be called on remote tracked removed

func (*SimulcastSender) Start added in v1.0.30

func (s *SimulcastSender) Start()

func (*SimulcastSender) SwitchSpatialLayer added in v1.0.23

func (s *SimulcastSender) SwitchSpatialLayer(targetLayer uint8)

func (*SimulcastSender) SwitchTemporalLayer added in v1.0.23

func (s *SimulcastSender) SwitchTemporalLayer(layer uint8)

func (*SimulcastSender) Track added in v1.0.30

func (s *SimulcastSender) Track() *webrtc.Track

func (*SimulcastSender) Transceiver added in v1.0.41

func (s *SimulcastSender) Transceiver() *webrtc.RTPTransceiver

func (*SimulcastSender) Type added in v1.0.26

func (s *SimulcastSender) Type() SenderType

func (*SimulcastSender) WriteRTP added in v1.0.23

func (s *SimulcastSender) WriteRTP(pkt *rtp.Packet)

WriteRTP to the track

type Transport

type Transport interface {
	ID() string
	GetRouter() Router
	AddSender(streamID string, sender Sender)
	GetSenders(streamID string) []Sender
}

Transport represents a transport that media can be sent over

type TransportWideCC added in v1.0.31

type TransportWideCC struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type VP8Helper added in v1.0.18

type VP8Helper struct {
	TemporalSupported bool
	// Optional Header
	PictureID uint16 /* 8 or 16 bits, picture ID */

	TL0PICIDX uint8 /* 8 bits temporal level zero index */

	// Optional Header If either of the T or K bits are set to 1,
	// the TID/Y/KEYIDX extension field MUST be present.
	TID uint8 /* 2 bits temporal layer idx*/
	// IsKeyFrame is a helper to detect if current packet is a keyframe
	IsKeyFrame bool
	// contains filtered or unexported fields
}

VP8Helper is a helper to get temporal data from VP8 packet header

VP8Helper Payload Descriptor
		0 1 2 3 4 5 6 7                      0 1 2 3 4 5 6 7
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
		|X|R|N|S|R| PID | (REQUIRED)        |X|R|N|S|R| PID | (REQUIRED)
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	X:  |I|L|T|K| RSV   | (OPTIONAL)   X:   |I|L|T|K| RSV   | (OPTIONAL)
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	I:  |M| PictureID   | (OPTIONAL)   I:   |M| PictureID   | (OPTIONAL)
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	L:  |   TL0PICIDX   | (OPTIONAL)        |   PictureID   |
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	T/K:|TID|Y| KEYIDX  | (OPTIONAL)   L:   |   TL0PICIDX   | (OPTIONAL)
		+-+-+-+-+-+-+-+-+                   +-+-+-+-+-+-+-+-+
	T/K:|TID|Y| KEYIDX  | (OPTIONAL)
		+-+-+-+-+-+-+-+-+

func (*VP8Helper) Unmarshal added in v1.0.18

func (p *VP8Helper) Unmarshal(payload []byte) error

Unmarshal parses the passed byte slice and stores the result in the VP8Helper this method is called upon

type WebRTCConfig

type WebRTCConfig struct {
	ICEPortRange []uint16          `mapstructure:"portrange"`
	ICEServers   []ICEServerConfig `mapstructure:"iceserver"`
	Candidates   Candidates        `mapstructure:"candidates"`
	SDPSemantics string            `mapstructure:"sdpsemantics"`
}

WebRTCConfig defines parameters for ice

type WebRTCReceiver added in v1.0.16

type WebRTCReceiver struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

WebRTCReceiver receives a video track

func (*WebRTCReceiver) AddSender added in v1.0.18

func (w *WebRTCReceiver) AddSender(sender Sender)

func (*WebRTCReceiver) DeleteSender added in v1.0.18

func (w *WebRTCReceiver) DeleteSender(pid string)

DeleteSender removes a Sender from a Receiver

func (*WebRTCReceiver) OnCloseHandler added in v1.0.16

func (w *WebRTCReceiver) OnCloseHandler(fn func())

OnCloseHandler method to be called on remote tracked removed

func (*WebRTCReceiver) OnTransportWideCC added in v1.0.31

func (w *WebRTCReceiver) OnTransportWideCC(fn func(sn uint16, timeNS int64, marker bool))

func (*WebRTCReceiver) SendRTCP added in v1.0.31

func (w *WebRTCReceiver) SendRTCP(p []rtcp.Packet)

func (*WebRTCReceiver) SetRTCPCh added in v1.0.31

func (w *WebRTCReceiver) SetRTCPCh(ch chan []rtcp.Packet)

func (*WebRTCReceiver) SpatialLayer added in v1.0.18

func (w *WebRTCReceiver) SpatialLayer() uint8

func (*WebRTCReceiver) Start added in v1.0.31

func (w *WebRTCReceiver) Start()

func (*WebRTCReceiver) Track added in v1.0.16

func (w *WebRTCReceiver) Track() *webrtc.Track

Track returns receivers track

func (*WebRTCReceiver) WriteBufferedPacket added in v1.0.23

func (w *WebRTCReceiver) WriteBufferedPacket(sn []uint16, track *webrtc.Track, snOffset uint16, tsOffset, ssrc uint32) error

WriteBufferedPacket writes buffered packet to track, return error if packet not found

type WebRTCTransport

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

WebRTCTransport represents a sfu peer connection

func NewWebRTCTransport

func NewWebRTCTransport(session *Session, me MediaEngine, cfg WebRTCTransportConfig) (*WebRTCTransport, error)

NewWebRTCTransport creates a new WebRTCTransport

func (*WebRTCTransport) AddICECandidate

func (p *WebRTCTransport) AddICECandidate(candidate webrtc.ICECandidateInit) error

AddICECandidate to peer connection

func (*WebRTCTransport) AddSender added in v1.0.23

func (p *WebRTCTransport) AddSender(streamID string, sender Sender)

func (*WebRTCTransport) Close

func (p *WebRTCTransport) Close() error

Close peer

func (*WebRTCTransport) CreateAnswer

func (p *WebRTCTransport) CreateAnswer() (webrtc.SessionDescription, error)

CreateAnswer generates the localDescription

func (*WebRTCTransport) CreateOffer

func (p *WebRTCTransport) CreateOffer() (webrtc.SessionDescription, error)

CreateOffer generates the localDescription

func (*WebRTCTransport) GetRouter

func (p *WebRTCTransport) GetRouter() Router

GetRouter returns router with mediaSSRC

func (*WebRTCTransport) GetSenders added in v1.0.23

func (p *WebRTCTransport) GetSenders(streamID string) []Sender

func (*WebRTCTransport) ID

func (p *WebRTCTransport) ID() string

ID of peer

func (*WebRTCTransport) LocalDescription added in v1.0.7

func (p *WebRTCTransport) LocalDescription() *webrtc.SessionDescription

LocalDescription returns the peer connection LocalDescription

func (*WebRTCTransport) OnICECandidate

func (p *WebRTCTransport) OnICECandidate(f func(c *webrtc.ICECandidate))

OnICECandidate handler

func (*WebRTCTransport) OnNegotiationNeeded

func (p *WebRTCTransport) OnNegotiationNeeded(f func())

OnNegotiationNeeded handler

func (*WebRTCTransport) OnTrack

func (p *WebRTCTransport) OnTrack(f func(*webrtc.Track, *webrtc.RTPReceiver))

OnTrack handler

func (*WebRTCTransport) SetLocalDescription

func (p *WebRTCTransport) SetLocalDescription(desc webrtc.SessionDescription) error

SetLocalDescription sets the SessionDescription of the remote peer

func (*WebRTCTransport) SetRemoteDescription

func (p *WebRTCTransport) SetRemoteDescription(desc webrtc.SessionDescription) error

SetRemoteDescription sets the SessionDescription of the remote peer

func (*WebRTCTransport) SignalingState added in v1.0.29

func (p *WebRTCTransport) SignalingState() webrtc.SignalingState

type WebRTCTransportConfig added in v1.0.3

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

WebRTCTransportConfig represents configuration options

Jump to

Keyboard shortcuts

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