mirror of
https://github.com/livekit/livekit.git
synced 2026-08-28 20:08:16 +00:00
Add Close method for UpDataTrackManager and call it on participant (#4432)
* Add `Close` method for UpDataTrackManager and call it on participant close. * include out-of-order packets in total packets
This commit is contained in:
@@ -65,6 +65,7 @@ func (d *dataTrackStats) Update(packet *datatrack.Packet, arrivalTime int64) {
|
||||
return
|
||||
|
||||
case diff > (1 << 15): // out of order
|
||||
d.numPackets++
|
||||
d.numPacketsOutOfOrder++
|
||||
if d.numPacketsLost > 0 {
|
||||
d.numPacketsLost--
|
||||
|
||||
@@ -1427,6 +1427,7 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
|
||||
p.pendingTracksLock.Unlock()
|
||||
|
||||
p.UpTrackManager.Close(isExpectedToResume)
|
||||
p.UpDataTrackManager.Close()
|
||||
|
||||
p.rpcLock.Lock()
|
||||
clear(p.rpcPendingAcks)
|
||||
|
||||
@@ -34,6 +34,7 @@ type UpDataTrackManager struct {
|
||||
|
||||
lock sync.RWMutex
|
||||
dataTracks map[uint16]types.DataTrack
|
||||
closed bool
|
||||
|
||||
onDataTrackPublished func(types.Participant, types.DataTrack)
|
||||
onDataTrackUnpublished func(types.Participant, types.DataTrack)
|
||||
@@ -46,6 +47,24 @@ func NewUpDataTrackManager(params UpDataTrackManagerParams) *UpDataTrackManager
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UpDataTrackManager) Close() {
|
||||
u.lock.Lock()
|
||||
if u.closed {
|
||||
u.lock.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
u.closed = true
|
||||
|
||||
dataTracks := u.dataTracks
|
||||
u.dataTracks = make(map[uint16]types.DataTrack)
|
||||
u.lock.Unlock()
|
||||
|
||||
for _, t := range dataTracks {
|
||||
t.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UpDataTrackManager) AddPublishedDataTrack(dt types.DataTrack) {
|
||||
u.lock.Lock()
|
||||
u.dataTracks[dt.PubHandle()] = dt
|
||||
|
||||
Reference in New Issue
Block a user