fix: memory leaks with BufferFactory being held
This commit is contained in:
@@ -78,7 +78,8 @@ func NewConfig(confString string) (*Config, error) {
|
|||||||
"stun.l.google.com:19302",
|
"stun.l.google.com:19302",
|
||||||
"stun1.l.google.com:19302",
|
"stun1.l.google.com:19302",
|
||||||
},
|
},
|
||||||
MaxBitrate: 3 * 1024 * 1024, // 3 mbps
|
MaxBitrate: 3 * 1024 * 1024, // 3 mbps
|
||||||
|
PacketBufferSize: 500,
|
||||||
},
|
},
|
||||||
Audio: AudioConfig{
|
Audio: AudioConfig{
|
||||||
ActiveLevel: 40,
|
ActiveLevel: 40,
|
||||||
|
|||||||
+5
-4
@@ -6,7 +6,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/go-logr/zapr"
|
|
||||||
"github.com/pion/ice/v2"
|
"github.com/pion/ice/v2"
|
||||||
"github.com/pion/ion-sfu/pkg/buffer"
|
"github.com/pion/ion-sfu/pkg/buffer"
|
||||||
"github.com/pion/logging"
|
"github.com/pion/logging"
|
||||||
@@ -64,8 +63,6 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
|
|||||||
if rtcConf.PacketBufferSize == 0 {
|
if rtcConf.PacketBufferSize == 0 {
|
||||||
rtcConf.PacketBufferSize = 500
|
rtcConf.PacketBufferSize = 500
|
||||||
}
|
}
|
||||||
bufferFactory := buffer.NewBufferFactory(rtcConf.PacketBufferSize, zapr.NewLogger(logger.GetLogger()))
|
|
||||||
s.BufferFactory = bufferFactory.GetOrNew
|
|
||||||
|
|
||||||
networkTypes := make([]webrtc.NetworkType, 0, 4)
|
networkTypes := make([]webrtc.NetworkType, 0, 4)
|
||||||
if !rtcConf.ForceTCP {
|
if !rtcConf.ForceTCP {
|
||||||
@@ -135,7 +132,6 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
|
|||||||
return &WebRTCConfig{
|
return &WebRTCConfig{
|
||||||
Configuration: c,
|
Configuration: c,
|
||||||
SettingEngine: s,
|
SettingEngine: s,
|
||||||
BufferFactory: bufferFactory,
|
|
||||||
Receiver: ReceiverConfig{
|
Receiver: ReceiverConfig{
|
||||||
packetBufferSize: rtcConf.PacketBufferSize,
|
packetBufferSize: rtcConf.PacketBufferSize,
|
||||||
maxBitrate: rtcConf.MaxBitrate,
|
maxBitrate: rtcConf.MaxBitrate,
|
||||||
@@ -146,6 +142,11 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *WebRTCConfig) SetBufferFactory(factory *buffer.Factory) {
|
||||||
|
c.BufferFactory = factory
|
||||||
|
c.SettingEngine.BufferFactory = factory.GetOrNew
|
||||||
|
}
|
||||||
|
|
||||||
func checkUDPReadBuffer() (int, error) {
|
func checkUDPReadBuffer() (int, error) {
|
||||||
conn, err := net.ListenUDP("udp4", nil)
|
conn, err := net.ListenUDP("udp4", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-logr/zapr"
|
||||||
"github.com/livekit/protocol/utils"
|
"github.com/livekit/protocol/utils"
|
||||||
|
"github.com/pion/ion-sfu/pkg/buffer"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/logger"
|
"github.com/livekit/livekit-server/pkg/logger"
|
||||||
@@ -27,6 +29,7 @@ type Room struct {
|
|||||||
// map of identity -> Participant
|
// map of identity -> Participant
|
||||||
participants map[string]types.Participant
|
participants map[string]types.Participant
|
||||||
participantOpts map[string]*ParticipantOptions
|
participantOpts map[string]*ParticipantOptions
|
||||||
|
bufferFactory *buffer.Factory
|
||||||
|
|
||||||
// time the first participant joined the room
|
// time the first participant joined the room
|
||||||
joinedAt atomic.Value
|
joinedAt atomic.Value
|
||||||
@@ -57,6 +60,7 @@ func NewRoom(room *livekit.Room, config WebRTCConfig, iceServers []*livekit.ICES
|
|||||||
statsReporter: NewRoomStatsReporter(room.Name),
|
statsReporter: NewRoomStatsReporter(room.Name),
|
||||||
participants: make(map[string]types.Participant),
|
participants: make(map[string]types.Participant),
|
||||||
participantOpts: make(map[string]*ParticipantOptions),
|
participantOpts: make(map[string]*ParticipantOptions),
|
||||||
|
bufferFactory: buffer.NewBufferFactory(config.Receiver.packetBufferSize, zapr.NewLogger(logger.GetLogger())),
|
||||||
}
|
}
|
||||||
if r.Room.EmptyTimeout == 0 {
|
if r.Room.EmptyTimeout == 0 {
|
||||||
r.Room.EmptyTimeout = DefaultEmptyTimeout
|
r.Room.EmptyTimeout = DefaultEmptyTimeout
|
||||||
@@ -110,6 +114,10 @@ func (r *Room) GetStatsReporter() *RoomStatsReporter {
|
|||||||
return r.statsReporter
|
return r.statsReporter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Room) GetBufferFactor() *buffer.Factory {
|
||||||
|
return r.bufferFactory
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Room) FirstJoinedAt() int64 {
|
func (r *Room) FirstJoinedAt() int64 {
|
||||||
j := r.joinedAt.Load()
|
j := r.joinedAt.Load()
|
||||||
if t, ok := j.(int64); ok {
|
if t, ok := j.(int64); ok {
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ func (r *RoomManager) StartSession(roomName string, pi routing.ParticipantInit,
|
|||||||
|
|
||||||
pv := types.ProtocolVersion(pi.ProtocolVersion)
|
pv := types.ProtocolVersion(pi.ProtocolVersion)
|
||||||
rtcConf := *r.rtcConfig
|
rtcConf := *r.rtcConfig
|
||||||
|
rtcConf.SetBufferFactory(room.GetBufferFactor())
|
||||||
if pi.UsePlanB {
|
if pi.UsePlanB {
|
||||||
rtcConf.Configuration.SDPSemantics = webrtc.SDPSemanticsPlanB
|
rtcConf.Configuration.SDPSemantics = webrtc.SDPSemanticsPlanB
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user