rtc

package
v1.10.6 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: Apache-2.0 Imports: 37 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultEmptyTimeout       = 5 * 60 // 5m
	DefaultRoomDepartureGrace = 20
	AudioLevelQuantization    = 8 // ideally power of 2 to minimize float decimal
)

Variables

View Source
var (
	ErrRoomClosed              = errors.New("room has already closed")
	ErrPermissionDenied        = errors.New("no permissions to access the room")
	ErrMaxParticipantsExceeded = errors.New("room has exceeded its max participants")
	ErrAlreadyJoined           = errors.New("a participant with the same identity is already in the room")
	ErrUnexpectedOffer         = errors.New("expected answer SDP, received offer")
	ErrDataChannelUnavailable  = errors.New("data channel is not available")
	ErrCannotSubscribe         = errors.New("participant does not have permission to subscribe")
)

Functions

func ConvertAudioLevel added in v0.9.14

func ConvertAudioLevel(level uint8) float32

convert decibel back to linear

func FromProtoSessionDescription

func FromProtoSessionDescription(sd *livekit.SessionDescription) webrtc.SessionDescription

func FromProtoTrickle

func FromProtoTrickle(trickle *livekit.TrickleRequest) (webrtc.ICECandidateInit, error)

func IsEOF

func IsEOF(err error) bool

func PackDataTrackLabel

func PackDataTrackLabel(participantId, trackId string, label string) string

func PackStreamID

func PackStreamID(participantId, trackId string) string

func Recover

func Recover()

func RecoverSilent

func RecoverSilent()

func ToProtoParticipants

func ToProtoParticipants(participants []types.Participant) []*livekit.ParticipantInfo

func ToProtoSessionDescription

func ToProtoSessionDescription(sd webrtc.SessionDescription) *livekit.SessionDescription

func ToProtoTrackKind

func ToProtoTrackKind(kind webrtc.RTPCodecType) livekit.TrackType

func ToProtoTrickle

func ToProtoTrickle(candidateInit webrtc.ICECandidateInit) *livekit.TrickleRequest

func UnpackDataTrackLabel

func UnpackDataTrackLabel(packed string) (peerId string, trackId string, label string)

func UnpackStreamID

func UnpackStreamID(packed string) (participantId string, trackId string)

Types

type AudioLevel

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

keeps track of audio level for a participant

func NewAudioLevel

func NewAudioLevel(activeLevel uint8, minPercentile uint8) *AudioLevel

func (*AudioLevel) GetLevel

func (l *AudioLevel) GetLevel() (uint8, bool)

returns current audio level, 0 (loudest) to 127 (silent)

func (*AudioLevel) Observe

func (l *AudioLevel) Observe(level uint8)

Observes a new frame, must be called from the same thread

type MediaTrack

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

MediaTrack represents a WebRTC track that needs to be forwarded Implements the PublishedTrack interface

func NewMediaTrack

func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTrack

func (*MediaTrack) AddReceiver

func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote, twcc *twcc.Responder)

AddReceiver adds a new RTP receiver to the track

func (*MediaTrack) AddSubscriber

func (t *MediaTrack) AddSubscriber(sub types.Participant) error

AddSubscriber subscribes sub to current mediaTrack

func (*MediaTrack) DebugInfo added in v0.10.6

func (t *MediaTrack) DebugInfo() map[string]interface{}

func (*MediaTrack) ID

func (t *MediaTrack) ID() string

func (*MediaTrack) IsMuted

func (t *MediaTrack) IsMuted() bool

func (*MediaTrack) IsSubscriber added in v0.9.2

func (t *MediaTrack) IsSubscriber(subId string) bool

func (*MediaTrack) Kind

func (t *MediaTrack) Kind() livekit.TrackType

func (*MediaTrack) Name

func (t *MediaTrack) Name() string

func (*MediaTrack) OnClose

func (t *MediaTrack) OnClose(f func())

func (*MediaTrack) RemoveAllSubscribers

func (t *MediaTrack) RemoveAllSubscribers()

func (*MediaTrack) RemoveSubscriber

func (t *MediaTrack) RemoveSubscriber(participantId string)

RemoveSubscriber removes participant from subscription stop all forwarders to the client

func (*MediaTrack) SetMuted

func (t *MediaTrack) SetMuted(muted bool)

func (*MediaTrack) Start

func (t *MediaTrack) Start()

func (*MediaTrack) ToProto added in v0.9.13

func (t *MediaTrack) ToProto() *livekit.TrackInfo

type MediaTrackParams

type MediaTrackParams struct {
	TrackID        string
	ParticipantID  string
	RTCPChan       chan []rtcp.Packet
	BufferFactory  *buffer.Factory
	ReceiverConfig ReceiverConfig
	AudioConfig    config.AudioConfig
	Stats          *RoomStatsReporter
	Width          uint32
	Height         uint32
}

type PCTransport

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

PCTransport is a wrapper around PeerConnection, with some helper methods

func NewPCTransport

func NewPCTransport(params TransportParams) (*PCTransport, error)

func (*PCTransport) AddICECandidate

func (t *PCTransport) AddICECandidate(candidate webrtc.ICECandidateInit) error

func (*PCTransport) Close

func (t *PCTransport) Close()

func (*PCTransport) CreateAndSendOffer

func (t *PCTransport) CreateAndSendOffer(options *webrtc.OfferOptions) error

func (*PCTransport) Negotiate

func (t *PCTransport) Negotiate()

func (*PCTransport) OnOffer

func (t *PCTransport) OnOffer(f func(sd webrtc.SessionDescription))

OnOffer is called when the PeerConnection starts negotiation and prepares an offer

func (*PCTransport) PeerConnection

func (t *PCTransport) PeerConnection() *webrtc.PeerConnection

func (*PCTransport) SetRemoteDescription

func (t *PCTransport) SetRemoteDescription(sd webrtc.SessionDescription) error

type PacketStats

type PacketStats struct {
	PacketBytes uint64 `json:"packetBytes"`
	PacketTotal uint64 `json:"packetTotal"`
	NackTotal   uint64 `json:"nackTotal"`
	PLITotal    uint64 `json:"pliTotal"`
	FIRTotal    uint64 `json:"firTotal"`
	// contains filtered or unexported fields
}

func (PacketStats) Copy added in v0.9.7

func (s PacketStats) Copy() *PacketStats

func (*PacketStats) HandleRTCP

func (s *PacketStats) HandleRTCP(pkts []rtcp.Packet)

func (*PacketStats) IncrementBytes

func (s *PacketStats) IncrementBytes(bytes uint64)

func (*PacketStats) IncrementFIR

func (s *PacketStats) IncrementFIR(count uint64)

func (*PacketStats) IncrementNack

func (s *PacketStats) IncrementNack(count uint64)

func (*PacketStats) IncrementPLI

func (s *PacketStats) IncrementPLI(count uint64)

func (*PacketStats) IncrementPackets

func (s *PacketStats) IncrementPackets(count uint64)

type ParticipantImpl

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

func NewParticipant

func NewParticipant(params ParticipantParams) (*ParticipantImpl, error)

func (*ParticipantImpl) AddICECandidate

func (p *ParticipantImpl) AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) error

AddICECandidate adds candidates for remote peer

func (*ParticipantImpl) AddSubscribedTrack

func (p *ParticipantImpl) AddSubscribedTrack(pubId string, subTrack types.SubscribedTrack)

AddSubscribedTrack adds a track to the participant's subscribed list

func (*ParticipantImpl) AddSubscriber

func (p *ParticipantImpl) AddSubscriber(op types.Participant) (int, error)

AddSubscriber subscribes op to all publishedTracks

func (*ParticipantImpl) AddTrack

func (p *ParticipantImpl) AddTrack(req *livekit.AddTrackRequest)

AddTrack is called when client intends to publish track. records track details and lets client know it's ok to proceed

func (*ParticipantImpl) CanPublish

func (p *ParticipantImpl) CanPublish() bool

func (*ParticipantImpl) CanSubscribe

func (p *ParticipantImpl) CanSubscribe() bool

func (*ParticipantImpl) Close

func (p *ParticipantImpl) Close() error

func (*ParticipantImpl) ConnectedAt

func (p *ParticipantImpl) ConnectedAt() time.Time

func (*ParticipantImpl) DebugInfo added in v0.10.6

func (p *ParticipantImpl) DebugInfo() map[string]interface{}

func (*ParticipantImpl) GetAudioLevel

func (p *ParticipantImpl) GetAudioLevel() (level uint8, active bool)

func (*ParticipantImpl) GetPublishedTracks

func (p *ParticipantImpl) GetPublishedTracks() []types.PublishedTrack

func (*ParticipantImpl) GetResponseSink

func (p *ParticipantImpl) GetResponseSink() routing.MessageSink

func (*ParticipantImpl) GetSubscribedTracks

func (p *ParticipantImpl) GetSubscribedTracks() []types.SubscribedTrack

func (*ParticipantImpl) HandleAnswer

func (p *ParticipantImpl) HandleAnswer(sdp webrtc.SessionDescription) error

HandleAnswer handles a client answer response, with subscriber PC, server initiates the offer and client answers

func (*ParticipantImpl) HandleOffer

func (p *ParticipantImpl) HandleOffer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error)

HandleOffer an offer from remote participant, used when clients make the initial connection

func (*ParticipantImpl) ICERestart

func (p *ParticipantImpl) ICERestart() error

ICERestart restarts subscriber ICE connections

func (*ParticipantImpl) ID

func (p *ParticipantImpl) ID() string

func (*ParticipantImpl) Identity

func (p *ParticipantImpl) Identity() string

func (*ParticipantImpl) IsReady

func (p *ParticipantImpl) IsReady() bool

func (*ParticipantImpl) Negotiate

func (p *ParticipantImpl) Negotiate()

func (*ParticipantImpl) OnClose

func (p *ParticipantImpl) OnClose(callback func(types.Participant))

func (*ParticipantImpl) OnDataPacket

func (p *ParticipantImpl) OnDataPacket(callback func(types.Participant, *livekit.DataPacket))

func (*ParticipantImpl) OnMetadataUpdate

func (p *ParticipantImpl) OnMetadataUpdate(callback func(types.Participant))

func (*ParticipantImpl) OnStateChange

func (p *ParticipantImpl) OnStateChange(callback func(p types.Participant, oldState livekit.ParticipantInfo_State))

func (*ParticipantImpl) OnTrackPublished

func (p *ParticipantImpl) OnTrackPublished(callback func(types.Participant, types.PublishedTrack))

func (*ParticipantImpl) OnTrackUpdated

func (p *ParticipantImpl) OnTrackUpdated(callback func(types.Participant, types.PublishedTrack))

func (*ParticipantImpl) ProtocolVersion

func (p *ParticipantImpl) ProtocolVersion() types.ProtocolVersion

func (*ParticipantImpl) RTCPChan

func (p *ParticipantImpl) RTCPChan() chan []rtcp.Packet

func (*ParticipantImpl) RemoveSubscribedTrack

func (p *ParticipantImpl) RemoveSubscribedTrack(pubId string, subTrack types.SubscribedTrack)

RemoveSubscribedTrack removes a track to the participant's subscribed list

func (*ParticipantImpl) RemoveSubscriber

func (p *ParticipantImpl) RemoveSubscriber(participantId string)

func (*ParticipantImpl) SendActiveSpeakers

func (p *ParticipantImpl) SendActiveSpeakers(speakers []*livekit.SpeakerInfo) error

func (*ParticipantImpl) SendDataPacket

func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket) error

func (*ParticipantImpl) SendJoinResponse

func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticipants []types.Participant, iceServers []*livekit.ICEServer) error

func (*ParticipantImpl) SendParticipantUpdate

func (p *ParticipantImpl) SendParticipantUpdate(participants []*livekit.ParticipantInfo) error

func (*ParticipantImpl) SetMetadata

func (p *ParticipantImpl) SetMetadata(metadata string)

SetMetadata attaches metadata to the participant

func (*ParticipantImpl) SetPermission

func (p *ParticipantImpl) SetPermission(permission *livekit.ParticipantPermission)

func (*ParticipantImpl) SetResponseSink

func (p *ParticipantImpl) SetResponseSink(sink routing.MessageSink)

func (*ParticipantImpl) SetTrackMuted

func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool)

func (*ParticipantImpl) Start

func (p *ParticipantImpl) Start()

func (*ParticipantImpl) State

func (*ParticipantImpl) SubscriberMediaEngine

func (p *ParticipantImpl) SubscriberMediaEngine() *webrtc.MediaEngine

func (*ParticipantImpl) SubscriberPC

func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection

func (*ParticipantImpl) ToProto

func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo

func (*ParticipantImpl) UpdateAfterActive added in v0.9.13

func (p *ParticipantImpl) UpdateAfterActive() bool

type ParticipantOptions added in v0.9.4

type ParticipantOptions struct {
	AutoSubscribe bool
}

type ParticipantParams

type ParticipantParams struct {
	Identity        string
	Config          *WebRTCConfig
	Sink            routing.MessageSink
	AudioConfig     config.AudioConfig
	ProtocolVersion types.ProtocolVersion
	Stats           *RoomStatsReporter
	ThrottleConfig  config.PLIThrottleConfig
	EnabledCodecs   []*livekit.Codec
}

type ReceiverConfig

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

type Room

type Room struct {
	Room *livekit.Room
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(room *livekit.Room, config WebRTCConfig, iceServers []*livekit.ICEServer, audioConfig *config.AudioConfig) *Room

func (*Room) Close

func (r *Room) Close()

func (*Room) CloseIfEmpty

func (r *Room) CloseIfEmpty()

CloseIfEmpty closes the room if all participants had left, or it's still empty past timeout

func (*Room) DebugInfo added in v0.10.6

func (r *Room) DebugInfo() map[string]interface{}

func (*Room) FirstJoinedAt

func (r *Room) FirstJoinedAt() int64

func (*Room) GetActiveSpeakers

func (r *Room) GetActiveSpeakers() []*livekit.SpeakerInfo

func (*Room) GetBufferFactor added in v0.9.11

func (r *Room) GetBufferFactor() *buffer.Factory

func (*Room) GetIncomingStats

func (r *Room) GetIncomingStats() PacketStats

func (*Room) GetOutgoingStats

func (r *Room) GetOutgoingStats() PacketStats

func (*Room) GetParticipant

func (r *Room) GetParticipant(identity string) types.Participant

func (*Room) GetParticipants

func (r *Room) GetParticipants() []types.Participant

func (*Room) GetStatsReporter

func (r *Room) GetStatsReporter() *RoomStatsReporter

func (*Room) Join

func (r *Room) Join(participant types.Participant, opts *ParticipantOptions) error

func (*Room) LastLeftAt

func (r *Room) LastLeftAt() int64

func (*Room) OnClose

func (r *Room) OnClose(f func())

func (*Room) OnParticipantChanged

func (r *Room) OnParticipantChanged(f func(participant types.Participant))

func (*Room) RemoveParticipant

func (r *Room) RemoveParticipant(identity string)

func (*Room) UpdateSubscriptions

func (r *Room) UpdateSubscriptions(participant types.Participant, trackIds []string, subscribe bool) error

type RoomStatsReporter

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

RoomStatsReporter is created for each room

func NewRoomStatsReporter

func NewRoomStatsReporter(roomName string) *RoomStatsReporter

func (*RoomStatsReporter) AddParticipant

func (r *RoomStatsReporter) AddParticipant()

func (*RoomStatsReporter) AddPublishedTrack

func (r *RoomStatsReporter) AddPublishedTrack(kind string)

func (*RoomStatsReporter) AddSubscribedTrack

func (r *RoomStatsReporter) AddSubscribedTrack(kind string)

func (*RoomStatsReporter) RoomEnded

func (r *RoomStatsReporter) RoomEnded()

func (*RoomStatsReporter) RoomStarted

func (r *RoomStatsReporter) RoomStarted()

func (*RoomStatsReporter) SubParticipant

func (r *RoomStatsReporter) SubParticipant()

func (*RoomStatsReporter) SubPublishedTrack

func (r *RoomStatsReporter) SubPublishedTrack(kind string)

func (*RoomStatsReporter) SubSubscribedTrack

func (r *RoomStatsReporter) SubSubscribedTrack(kind string)

type StatsBufferWrapper

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

StatsBufferWrapper wraps a buffer factory so we could get information on incoming packets

func (*StatsBufferWrapper) CreateBuffer

func (w *StatsBufferWrapper) CreateBuffer(packetType packetio.BufferPacketType, ssrc uint32) io.ReadWriteCloser

type StatsInterceptor

type StatsInterceptor struct {
	interceptor.NoOp
	// contains filtered or unexported fields
}

StatsInterceptor is created for each participant to keep of track of outgoing stats it adheres to Pion interceptor interface

func NewStatsInterceptor

func NewStatsInterceptor(reporter *RoomStatsReporter) *StatsInterceptor

func (*StatsInterceptor) BindLocalStream

BindLocalStream lets you modify any outgoing RTP packets. It is called once for per LocalStream. The returned method will be called once per rtp packet.

func (*StatsInterceptor) BindRTCPWriter

func (s *StatsInterceptor) BindRTCPWriter(writer interceptor.RTCPWriter) interceptor.RTCPWriter

BindRTCPWriter lets you modify any outgoing RTCP packets. It is called once per PeerConnection. The returned method will be called once per packet batch.

type SubscribedTrack

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

func NewSubscribedTrack

func NewSubscribedTrack(dt *sfu.DownTrack) *SubscribedTrack

func (*SubscribedTrack) DownTrack

func (t *SubscribedTrack) DownTrack() *sfu.DownTrack

func (*SubscribedTrack) ID

func (t *SubscribedTrack) ID() string

func (*SubscribedTrack) IsMuted

func (t *SubscribedTrack) IsMuted() bool

has subscriber indicated it wants to mute this track

func (*SubscribedTrack) SetPublisherMuted

func (t *SubscribedTrack) SetPublisherMuted(muted bool)

func (*SubscribedTrack) UpdateSubscriberSettings added in v0.9.14

func (t *SubscribedTrack) UpdateSubscriberSettings(enabled bool, quality livekit.VideoQuality)

type TransportParams

type TransportParams struct {
	Target        livekit.SignalTarget
	Config        *WebRTCConfig
	Stats         *RoomStatsReporter
	EnabledCodecs []*livekit.Codec
}

type WebRTCConfig

type WebRTCConfig struct {
	Configuration  webrtc.Configuration
	SettingEngine  webrtc.SettingEngine
	Receiver       ReceiverConfig
	BufferFactory  *buffer.Factory
	UDPMux         ice.UDPMux
	UDPMuxConn     *net.UDPConn
	TCPMuxListener *net.TCPListener
}

func NewWebRTCConfig

func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, error)

func (*WebRTCConfig) SetBufferFactory added in v0.9.11

func (c *WebRTCConfig) SetBufferFactory(factory *buffer.Factory)

type WrappedReceiver

type WrappedReceiver struct {
	sfu.Receiver
	// contains filtered or unexported fields
}

func NewWrappedReceiver

func NewWrappedReceiver(receiver sfu.Receiver, trackId string, streamId string) WrappedReceiver

func (WrappedReceiver) StreamID

func (r WrappedReceiver) StreamID() string

func (WrappedReceiver) TrackID

func (r WrappedReceiver) TrackID() string

Directories

Path Synopsis
typesfakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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