dynacast: re-send subscribed qualities after every publisher answer (#4907)
* dynacast: re-send subscribed qualities after every publisher answer The SFU answers publisher offers without the simulcast pause markers (SetIgnoreRidPauseForRecv), so applying the answer re-enables in the browser the layers that dynacast had paused. Dynacast only notifies changes, so those layers stayed on until the subscribed quality of the track changed again. Send the publisher its committed subscribed qualities again 1 s after each answer, once the client has applied it: livekit-client handles the next signal message without waiting for the answer to be applied. Fixes https://github.com/livekit/livekit/issues/4906 * dynacast: resend once per burst of publisher answers, only for paused layers In SPC, every subscription change of a participant goes through a new publisher offer and answer, so answers come in bursts when a room is busy. Each answer scheduled its own resend of the subscribed qualities, sending the same update several times in a row. Thist change keeps one pending resend per participant instead. It fires 2 s after the last answer, and never later than 8 s after the first answer of the burst, so a steady stream of answers cannot postpone it forever. It also skips the resend for tracks whose committed qualities are all HIGH: with every layer enabled, an answer has nothing paused to re-enable. We can save those messages.
This commit is contained in:
+38
-1
@@ -74,6 +74,9 @@ const (
|
||||
sdBatchSize = 30
|
||||
rttUpdateInterval = 5 * time.Second
|
||||
|
||||
publisherAnswerDynacastResendDelay = 2 * time.Second
|
||||
publisherAnswerDynacastResendMaxDelay = 8 * time.Second
|
||||
|
||||
disconnectCleanupDuration = 5 * time.Second
|
||||
migrationWaitDuration = 3 * time.Second
|
||||
migrationWaitContinuousMsgDuration = 2 * time.Second
|
||||
@@ -277,6 +280,9 @@ type ParticipantImpl struct {
|
||||
// timer that's set when disconnect is detected on primary PC
|
||||
disconnectTimer *time.Timer
|
||||
migrationTimer *time.Timer
|
||||
// re-send of the subscribed qualities pending after publisher answers
|
||||
dynacastResendTimer *time.Timer
|
||||
dynacastResendDeadline time.Time
|
||||
|
||||
migratedInAt atomic.Pointer[time.Time]
|
||||
|
||||
@@ -1268,7 +1274,38 @@ func (p *ParticipantImpl) onPublisherAnswer(answer webrtc.SessionDescription, an
|
||||
"midToTrackID", midToTrackID,
|
||||
)
|
||||
|
||||
return p.sendSdpAnswer(answer, answerId, midToTrackID)
|
||||
if err := p.sendSdpAnswer(answer, answerId, midToTrackID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// The answer does not carry the pause state of the simulcast layers (SetIgnoreRidPauseForRecv),
|
||||
// so applying it re-enables in the publisher the layers paused by dynacast. Send the subscribed
|
||||
// qualities again with a delay to ensure the answer has been applied, once for a burst of answers:
|
||||
// the delay restarts with each answer, up to a maximum from the first one
|
||||
p.lock.Lock()
|
||||
if p.dynacastResendTimer == nil {
|
||||
p.dynacastResendDeadline = time.Now().Add(publisherAnswerDynacastResendMaxDelay)
|
||||
p.dynacastResendTimer = time.AfterFunc(publisherAnswerDynacastResendDelay, p.resendSubscribedQualities)
|
||||
} else {
|
||||
p.dynacastResendTimer.Reset(min(publisherAnswerDynacastResendDelay, time.Until(p.dynacastResendDeadline)))
|
||||
}
|
||||
p.lock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) resendSubscribedQualities() {
|
||||
p.lock.Lock()
|
||||
p.dynacastResendTimer = nil
|
||||
p.lock.Unlock()
|
||||
|
||||
if p.IsClosed() || p.IsDisconnected() {
|
||||
return
|
||||
}
|
||||
for _, track := range p.GetPublishedTracks() {
|
||||
if mt, ok := track.(*MediaTrack); ok {
|
||||
mt.ResendSubscribedQuality()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) GetAnswer() (webrtc.SessionDescription, uint32, error) {
|
||||
|
||||
Reference in New Issue
Block a user