sfu

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SimpleRouter = iota + 1
	SimulcastRouter
	SVCRouter
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer contains all packets

func NewBuffer

func NewBuffer(ssrc uint32, pt uint8, o BufferOptions) *Buffer

NewBuffer constructs a new Buffer

func (*Buffer) GetLostRateBandwidth

func (b *Buffer) GetLostRateBandwidth(cycle uint64) (float64, uint64)

GetLostRateBandwidth calc lostRate and bandwidth by cycle

func (*Buffer) GetNackPair

func (b *Buffer) GetNackPair(buffer [65536]*rtp.Packet, begin, end uint16) (rtcp.NackPair, int)

GetNackPair calc nackpair

func (*Buffer) GetPacket

func (b *Buffer) GetPacket(sn uint16) *rtp.Packet

GetPacket get packet by sequence number

func (*Buffer) GetPayloadType

func (b *Buffer) GetPayloadType() uint8

GetPayloadType get payloadtype

func (*Buffer) GetRTCPChan

func (b *Buffer) GetRTCPChan() chan rtcp.Packet

GetRTCPChan return rtcp channel

func (*Buffer) GetSSRC

func (b *Buffer) GetSSRC() uint32

GetSSRC get ssrc

func (*Buffer) Push

func (b *Buffer) Push(p *rtp.Packet)

Push adds a RTP Packet, out of order, new packet may be arrived later

func (*Buffer) Stop

func (b *Buffer) Stop()

Stop buffer

type BufferOptions

type BufferOptions struct {
	BufferTime int
}

BufferOptions provides configuration options for the buffer

type Config

type Config struct {
	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 Receiver

type Receiver interface {
	Track() *webrtc.Track
	AddSender(sender Sender)
	DeleteSender(pid string)
	GetPacket(sn uint16) *rtp.Packet
	ReadRTCP() chan rtcp.Packet
	WriteRTCP(rtcp.Packet) error
	OnCloseHandler(fn func())
	SpatialLayer() uint8
	Close()
	// contains filtered or unexported methods
}

Receiver defines a interface for a track receivers

func NewWebRTCReceiver added in v1.0.16

func NewWebRTCReceiver(ctx context.Context, track *webrtc.Track, config RouterConfig) Receiver

NewWebRTCReceiver creates a new webrtc track receivers

type Router

type Router interface {
	ID() string
	AddReceiver(recv Receiver)
	GetReceiver(layer uint8) Receiver
	AddSender(p *WebRTCTransport) error
	SwitchSpatialLayer(currentLayer, targetLayer uint8, sub Sender) bool
}

Router defines a track rtp/rtcp router

type RouterConfig added in v1.0.15

type RouterConfig struct {
	REMBFeedback bool                      `mapstructure:"subrembfeedback"`
	MaxBandwidth uint64                    `mapstructure:"maxbandwidth"`
	MaxNackTime  int64                     `mapstructure:"maxnacktime"`
	Video        WebRTCVideoReceiverConfig `mapstructure:"video"`
	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 webrtc.MediaEngine) (*WebRTCTransport, error)

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

func (*SFU) Stop added in v1.0.8

func (s *SFU) Stop()

Stop the sfu

type Sender

type Sender interface {
	ID() string
	WriteRTP(*rtp.Packet)
	CurrentSpatialLayer() uint8
	OnCloseHandler(fn func())
	Close()

	// Simulcast/SVC events
	SwitchSpatialLayer(layer uint8)
	SwitchTemporalLayer(layer uint8)
	// contains filtered or unexported methods
}

Sender defines a interface for a track receivers

func NewWebRTCSender

func NewWebRTCSender(ctx context.Context, id string, router Router, sender *webrtc.RTPSender) Sender

NewWebRTCSender creates a new track sender instance

func NewWebRTCSimulcastSender added in v1.0.18

func NewWebRTCSimulcastSender(ctx context.Context, id string, router Router, sender *webrtc.RTPSender, layer uint8) Sender

NewWebRTCSimulcastSender creates a new track sender instance

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

func (r *Session) AddRouter(router Router)

AddRouter adds a router to transports

func (*Session) AddTransport

func (r *Session) AddTransport(transport Transport)

AddTransport adds a transport to the session

func (*Session) OnClose

func (r *Session) OnClose(f func())

OnClose called when session is closed

func (*Session) RemoveTransport

func (r *Session) RemoveTransport(tid string)

RemoveTransport removes a transport for the session

func (*Session) Transports

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

Transports returns transports in this session

type SimulcastConfig added in v1.0.18

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

type Transport

type Transport interface {
	ID() string
	GetRouter(string) Router
	Routers() map[string]Router
	// contains filtered or unexported methods
}

Transport represents a transport that media can be sent over

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"`
	NAT1To1IPs   []string          `mapstructure:"nat1to1"`
}

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) Close added in v1.0.16

func (w *WebRTCReceiver) Close()

Close gracefully close the track

func (*WebRTCReceiver) DeleteSender added in v1.0.18

func (w *WebRTCReceiver) DeleteSender(pid string)

DeleteSender removes a Sender from a Receiver

func (*WebRTCReceiver) GetPacket added in v1.0.16

func (w *WebRTCReceiver) GetPacket(sn uint16) *rtp.Packet

GetPacket get a buffered packet if we have one

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) ReadRTCP added in v1.0.16

func (w *WebRTCReceiver) ReadRTCP() chan rtcp.Packet

ReadRTCP read rtcp packets

func (*WebRTCReceiver) SpatialLayer added in v1.0.18

func (w *WebRTCReceiver) SpatialLayer() uint8

func (*WebRTCReceiver) Track added in v1.0.16

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

Track returns receivers track

func (*WebRTCReceiver) WriteRTCP added in v1.0.16

func (w *WebRTCReceiver) WriteRTCP(pkt rtcp.Packet) error

WriteRTCP write rtcp packet

type WebRTCSender

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

WebRTCSender represents a Sender which writes RTP to a webrtc track

func (*WebRTCSender) Close

func (s *WebRTCSender) Close()

Close track

func (*WebRTCSender) CurrentSpatialLayer added in v1.0.18

func (s *WebRTCSender) CurrentSpatialLayer() uint8

func (*WebRTCSender) ID added in v1.0.18

func (s *WebRTCSender) ID() string

func (*WebRTCSender) OnCloseHandler added in v1.0.16

func (s *WebRTCSender) OnCloseHandler(fn func())

OnCloseHandler method to be called on remote tracked removed

func (*WebRTCSender) SwitchSpatialLayer added in v1.0.18

func (s *WebRTCSender) SwitchSpatialLayer(layer uint8)

func (*WebRTCSender) SwitchTemporalLayer added in v1.0.18

func (s *WebRTCSender) SwitchTemporalLayer(layer uint8)

func (*WebRTCSender) WriteRTP

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

WriteRTP to the track

type WebRTCSimulcastSender added in v1.0.18

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

WebRTCSimulcastSender represents a Sender which writes RTP to a webrtc track

func (*WebRTCSimulcastSender) Close added in v1.0.18

func (s *WebRTCSimulcastSender) Close()

Close track

func (*WebRTCSimulcastSender) CurrentSpatialLayer added in v1.0.18

func (s *WebRTCSimulcastSender) CurrentSpatialLayer() uint8

func (*WebRTCSimulcastSender) ID added in v1.0.18

func (s *WebRTCSimulcastSender) ID() string

func (*WebRTCSimulcastSender) OnCloseHandler added in v1.0.18

func (s *WebRTCSimulcastSender) OnCloseHandler(fn func())

OnCloseHandler method to be called on remote tracked removed

func (*WebRTCSimulcastSender) SwitchSpatialLayer added in v1.0.18

func (s *WebRTCSimulcastSender) SwitchSpatialLayer(targetLayer uint8)

func (*WebRTCSimulcastSender) SwitchTemporalLayer added in v1.0.18

func (s *WebRTCSimulcastSender) SwitchTemporalLayer(layer uint8)

func (*WebRTCSimulcastSender) WriteRTP added in v1.0.18

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

WriteRTP to the track

type WebRTCTransport

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

WebRTCTransport represents a sfu peer connection

func NewWebRTCTransport

func NewWebRTCTransport(ctx context.Context, session *Session, me webrtc.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) AddTransceiverFromKind added in v1.0.5

func (p *WebRTCTransport) AddTransceiverFromKind(kind webrtc.RTPCodecType, init ...webrtc.RtpTransceiverInit) (*webrtc.RTPTransceiver, error)

AddTransceiverFromKind adds RtpTransceiver on WebRTC Transport

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(trackID string) Router

GetRouter returns router with ssrc

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

func (p *WebRTCTransport) OnConnectionStateChange(f func(webrtc.PeerConnectionState))

OnConnectionStateChange handler

func (*WebRTCTransport) OnDataChannel added in v1.0.4

func (p *WebRTCTransport) OnDataChannel(f func(*webrtc.DataChannel))

OnDataChannel handler

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

func (p *WebRTCTransport) Routers() map[string]Router

Routers returns routers for this peer

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

type WebRTCTransportConfig added in v1.0.3

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

WebRTCTransportConfig represents configuration options

type WebRTCVideoReceiverConfig

type WebRTCVideoReceiverConfig struct {
	REMBCycle       int `mapstructure:"rembcycle"`
	TCCCycle        int `mapstructure:"tcccycle"`
	MaxBufferTime   int `mapstructure:"maxbuffertime"`
	ReceiveRTPCycle int `mapstructure:"rtpcycle"`
}

WebRTCVideoReceiverConfig .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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