updated to ion-sfu v1.9.1, removed package bufferFactory
This commit is contained in:
+18
-9
@@ -3,6 +3,7 @@ package rtc
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pion/ion-sfu/pkg/buffer"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
@@ -12,16 +13,16 @@ type WebRTCConfig struct {
|
||||
Configuration webrtc.Configuration
|
||||
SettingEngine webrtc.SettingEngine
|
||||
Receiver ReceiverConfig
|
||||
BufferFactory *buffer.Factory
|
||||
}
|
||||
|
||||
type ReceiverConfig struct {
|
||||
maxBitrate uint64
|
||||
maxBufferTime int
|
||||
packetBufferSize int
|
||||
maxBitrate uint64
|
||||
maxBufferTime int
|
||||
}
|
||||
|
||||
type ExternalIP string
|
||||
|
||||
func NewWebRTCConfig(conf *config.RTCConfig, externalIP ExternalIP) (*WebRTCConfig, error) {
|
||||
func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig, error) {
|
||||
c := webrtc.Configuration{
|
||||
SDPSemantics: webrtc.SDPSemanticsUnifiedPlan,
|
||||
}
|
||||
@@ -42,16 +43,24 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP ExternalIP) (*WebRTCConf
|
||||
URLs: iceUrls,
|
||||
},
|
||||
}
|
||||
if conf.UseExternalIP {
|
||||
s.SetNAT1To1IPs([]string{string(externalIP)}, webrtc.ICECandidateTypeHost)
|
||||
if conf.UseExternalIP && externalIP != "" {
|
||||
s.SetNAT1To1IPs([]string{externalIP}, webrtc.ICECandidateTypeHost)
|
||||
}
|
||||
|
||||
if conf.PacketBufferSize == 0 {
|
||||
conf.PacketBufferSize = 500
|
||||
}
|
||||
bufferFactory := buffer.NewBufferFactory(conf.PacketBufferSize)
|
||||
s.BufferFactory = bufferFactory.GetOrNew
|
||||
|
||||
return &WebRTCConfig{
|
||||
Configuration: c,
|
||||
SettingEngine: s,
|
||||
BufferFactory: bufferFactory,
|
||||
Receiver: ReceiverConfig{
|
||||
maxBitrate: conf.MaxBitrate,
|
||||
maxBufferTime: conf.MaxBufferTime,
|
||||
packetBufferSize: conf.PacketBufferSize,
|
||||
maxBitrate: conf.MaxBitrate,
|
||||
maxBufferTime: conf.MaxBufferTime,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/pion/ion-sfu/pkg/buffer"
|
||||
)
|
||||
|
||||
const (
|
||||
rtpPacketMaxSize = 1460
|
||||
)
|
||||
|
||||
// package level factories for buffers
|
||||
var (
|
||||
bufferFactory = buffer.NewBufferFactory()
|
||||
packetFactory = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return make([]byte, rtpPacketMaxSize)
|
||||
},
|
||||
}
|
||||
)
|
||||
+13
-13
@@ -33,14 +33,15 @@ type MediaTrack struct {
|
||||
participantId string
|
||||
muted utils.AtomicFlag
|
||||
|
||||
ssrc webrtc.SSRC
|
||||
name string
|
||||
streamID string
|
||||
kind livekit.TrackType
|
||||
codec webrtc.RTPCodecParameters
|
||||
receiverConf ReceiverConfig
|
||||
audioConf config.AudioConfig
|
||||
onClose func()
|
||||
ssrc webrtc.SSRC
|
||||
name string
|
||||
streamID string
|
||||
kind livekit.TrackType
|
||||
codec webrtc.RTPCodecParameters
|
||||
bufferFactory *buffer.Factory
|
||||
receiverConf ReceiverConfig
|
||||
audioConf config.AudioConfig
|
||||
onClose func()
|
||||
|
||||
// channel to send RTCP packets to the source
|
||||
rtcpCh chan []rtcp.Packet
|
||||
@@ -54,7 +55,7 @@ type MediaTrack struct {
|
||||
lastPLI time.Time
|
||||
}
|
||||
|
||||
func NewMediaTrack(trackId string, pId string, rtcpCh chan []rtcp.Packet, track *webrtc.TrackRemote, rc ReceiverConfig, ac config.AudioConfig) *MediaTrack {
|
||||
func NewMediaTrack(trackId string, pId string, rtcpCh chan []rtcp.Packet, track *webrtc.TrackRemote, bufferFactory *buffer.Factory, rc ReceiverConfig, ac config.AudioConfig) *MediaTrack {
|
||||
t := &MediaTrack{
|
||||
id: trackId,
|
||||
participantId: pId,
|
||||
@@ -62,6 +63,7 @@ func NewMediaTrack(trackId string, pId string, rtcpCh chan []rtcp.Packet, track
|
||||
streamID: track.StreamID(),
|
||||
kind: ToProtoTrackKind(track.Kind()),
|
||||
codec: track.Codec(),
|
||||
bufferFactory: bufferFactory,
|
||||
receiverConf: rc,
|
||||
audioConf: ac,
|
||||
rtcpCh: rtcpCh,
|
||||
@@ -136,11 +138,10 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
||||
Channels: codec.Channels,
|
||||
SDPFmtpLine: codec.SDPFmtpLine,
|
||||
RTCPFeedback: feedbackTypes,
|
||||
}, t.receiver, sub.ID())
|
||||
}, t.receiver, t.bufferFactory, sub.ID(), t.receiverConf.packetBufferSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
downTrack.SetBufferFactory(bufferFactory)
|
||||
subTrack := NewSubscribedTrack(downTrack)
|
||||
|
||||
transceiver, err := sub.SubscriberPC().AddTransceiverFromTrack(downTrack, webrtc.RTPTransceiverInit{
|
||||
@@ -205,7 +206,7 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
||||
defer t.lock.Unlock()
|
||||
|
||||
//rid := track.RID()
|
||||
buff, rtcpReader := bufferFactory.GetBufferPair(uint32(track.SSRC()))
|
||||
buff, rtcpReader := t.bufferFactory.GetBufferPair(uint32(track.SSRC()))
|
||||
buff.OnFeedback(func(fb []rtcp.Packet) {
|
||||
// feedback for the source RTCP
|
||||
t.rtcpCh <- fb
|
||||
@@ -258,7 +259,6 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
||||
t.receiver.AddUpTrack(track, buff)
|
||||
|
||||
buff.Bind(receiver.GetParameters(), buffer.Options{
|
||||
BufferTime: t.receiverConf.maxBufferTime,
|
||||
MaxBitRate: t.receiverConf.maxBitrate,
|
||||
})
|
||||
}
|
||||
|
||||
+12
-11
@@ -29,19 +29,20 @@ const (
|
||||
)
|
||||
|
||||
type ParticipantImpl struct {
|
||||
id string
|
||||
publisher *PCTransport
|
||||
subscriber *PCTransport
|
||||
responseSink routing.MessageSink
|
||||
receiverConfig ReceiverConfig
|
||||
audioConfig config.AudioConfig
|
||||
isClosed utils.AtomicFlag
|
||||
identity string
|
||||
id string
|
||||
publisher *PCTransport
|
||||
subscriber *PCTransport
|
||||
responseSink routing.MessageSink
|
||||
audioConfig config.AudioConfig
|
||||
isClosed utils.AtomicFlag
|
||||
conf *WebRTCConfig
|
||||
identity string
|
||||
// JSON encoded metadata to pass to clients
|
||||
metadata string
|
||||
state atomic.Value // livekit.ParticipantInfo_State
|
||||
rtcpCh chan []rtcp.Packet
|
||||
|
||||
// hold reference for MediaTrack
|
||||
twcc *twcc.Responder
|
||||
|
||||
// tracks the current participant is subscribed to, map of otherParticipantId => []DownTrack
|
||||
@@ -61,15 +62,15 @@ type ParticipantImpl struct {
|
||||
onClose func(types.Participant)
|
||||
}
|
||||
|
||||
func NewParticipant(identity string, conf *WebRTCConfig, rs routing.MessageSink, rc ReceiverConfig, ac config.AudioConfig) (*ParticipantImpl, error) {
|
||||
func NewParticipant(identity string, conf *WebRTCConfig, rs routing.MessageSink, ac config.AudioConfig) (*ParticipantImpl, error) {
|
||||
// TODO: check to ensure params are valid, id and identity can't be empty
|
||||
|
||||
p := &ParticipantImpl{
|
||||
id: utils.NewGuid(utils.ParticipantPrefix),
|
||||
identity: identity,
|
||||
responseSink: rs,
|
||||
receiverConfig: rc,
|
||||
audioConfig: ac,
|
||||
conf: conf,
|
||||
rtcpCh: make(chan []rtcp.Packet, 50),
|
||||
subscribedTracks: make(map[string][]types.SubscribedTrack),
|
||||
lock: sync.RWMutex{},
|
||||
@@ -593,7 +594,7 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
|
||||
if trk, ok := ptrack.(*MediaTrack); ok {
|
||||
mt = trk
|
||||
} else {
|
||||
mt = NewMediaTrack(ti.Sid, p.id, p.rtcpCh, track, p.receiverConfig, p.audioConfig)
|
||||
mt = NewMediaTrack(ti.Sid, p.id, p.rtcpCh, track, p.conf.BufferFactory, p.conf.Receiver, p.audioConfig)
|
||||
mt.name = ti.Name
|
||||
newTrack = true
|
||||
}
|
||||
|
||||
@@ -120,11 +120,12 @@ func TestDisconnectTiming(t *testing.T) {
|
||||
}
|
||||
|
||||
func newParticipantForTest(identity string) *ParticipantImpl {
|
||||
conf, _ := config.NewConfig("")
|
||||
rtcConf, _ := NewWebRTCConfig(&conf.RTC, "")
|
||||
p, _ := NewParticipant(
|
||||
identity,
|
||||
&WebRTCConfig{},
|
||||
rtcConf,
|
||||
&routingfakes.FakeMessageSink{},
|
||||
ReceiverConfig{},
|
||||
config.AudioConfig{})
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ func newPeerConnection(target livekit.SignalTarget, conf *WebRTCConfig) (*webrtc
|
||||
}
|
||||
se := conf.SettingEngine
|
||||
se.DisableMediaEngineCopy(true)
|
||||
se.BufferFactory = bufferFactory.GetOrNew
|
||||
|
||||
api := webrtc.NewAPI(webrtc.WithMediaEngine(me), webrtc.WithSettingEngine(se))
|
||||
pc, err := api.NewPeerConnection(conf.Configuration)
|
||||
|
||||
@@ -5,11 +5,9 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/google/wire"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/proto/livekit"
|
||||
@@ -19,15 +17,6 @@ const (
|
||||
trackIdSeparator = "|"
|
||||
)
|
||||
|
||||
var RTCSet = wire.NewSet(
|
||||
NewWebRTCConfig,
|
||||
RTCConfigFromConfig,
|
||||
)
|
||||
|
||||
func RTCConfigFromConfig(conf *config.Config) *config.RTCConfig {
|
||||
return &conf.RTC
|
||||
}
|
||||
|
||||
func UnpackTrackId(packed string) (peerId string, trackId string) {
|
||||
parts := strings.Split(packed, trackIdSeparator)
|
||||
if len(parts) > 1 {
|
||||
|
||||
Reference in New Issue
Block a user