Defer RTCP channel close till published tracks are closed (#286)

* Defer RTCP channel close till published tracks are closed

* Check for Close called before closing RTCP channel
This commit is contained in:
Raja Subramanian
2021-12-27 14:17:06 +05:30
committed by GitHub
parent ee99a323d2
commit a47153e50c
3 changed files with 14 additions and 4 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ func (r *Room) GetActiveSpeakers() []*livekit.SpeakerInfo {
return speakers
}
func (r *Room) GetBufferFactor() *buffer.Factory {
func (r *Room) GetBufferFactory() *buffer.Factory {
return r.bufferFactory
}
+12 -2
View File
@@ -30,6 +30,8 @@ type UptrackManager struct {
rtcpCh chan []rtcp.Packet
pliThrottle *pliThrottle
closed bool
// hold reference for MediaTrack
twcc *twcc.Responder
@@ -70,13 +72,16 @@ func (u *UptrackManager) Close() {
u.lock.Lock()
defer u.lock.Unlock()
u.closed = true
// remove all subscribers
for _, t := range u.publishedTracks {
// skip updates
t.RemoveAllSubscribers()
}
close(u.rtcpCh)
if len(u.publishedTracks) == 0 {
close(u.rtcpCh)
}
}
func (u *UptrackManager) ToProto() []*livekit.TrackInfo {
@@ -432,6 +437,11 @@ func (u *UptrackManager) handleTrackPublished(track types.PublishedTrack) {
delete(u.publishedTracks, trackSid)
delete(u.pendingSubscriptions, trackSid)
// not modifying subscription permissions, will get reset on next update from participant
// as rtcpCh handles RTCP for all published tracks, close only after all published tracks are closed
if u.closed && len(u.publishedTracks) == 0 {
close(u.rtcpCh)
}
u.lock.Unlock()
// only send this when client is in a ready state
if u.onTrackUpdated != nil {
+1 -1
View File
@@ -225,7 +225,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
pv := types.ProtocolVersion(pi.Client.Protocol)
rtcConf := *r.rtcConfig
rtcConf.SetBufferFactory(room.GetBufferFactor())
rtcConf.SetBufferFactory(room.GetBufferFactory())
sid := utils.NewGuid(utils.ParticipantPrefix)
pLogger := rtc.LoggerWithParticipant(room.Logger, pi.Identity, sid)
participant, err = rtc.NewParticipant(rtc.ParticipantParams{