Add option to enable skip tcp ice if tcp rtt is high (#1484)

* Add option to switch tcp ice only if tcp works well

* solve comment

* rename and remove config change
This commit is contained in:
cnderrauber
2023-03-01 16:45:39 +08:00
committed by GitHub
parent a35eecd03d
commit 4277699600
2 changed files with 16 additions and 3 deletions
+2
View File
@@ -73,6 +73,7 @@ type ParticipantParams struct {
Migration bool
AdaptiveStream bool
AllowTCPFallback bool
TCPFallbackRTTThreshold int
TURNSEnabled bool
GetParticipantInfo func(pID livekit.ParticipantID) *livekit.ParticipantInfo
ReconnectOnPublicationError bool
@@ -981,6 +982,7 @@ func (p *ParticipantImpl) setupTransportManager() error {
ClientInfo: p.params.ClientInfo,
Migration: p.params.Migration,
AllowTCPFallback: p.params.AllowTCPFallback,
TCPFallbackRTTThreshold: p.params.TCPFallbackRTTThreshold,
TURNSEnabled: p.params.TURNSEnabled,
Logger: p.params.Logger,
})
+14 -3
View File
@@ -30,7 +30,6 @@ const (
udpLossFracUnstable = 25
// if in last 32 times RR, the unstable report count over this threshold, the connection is unstable
udpLossUnstableCountThreshold = 20
tcpGoodRTT = 80
)
type TransportManagerParams struct {
@@ -47,6 +46,7 @@ type TransportManagerParams struct {
ClientInfo ClientInfo
Migration bool
AllowTCPFallback bool
TCPFallbackRTTThreshold int
TURNSEnabled bool
Logger logger.Logger
}
@@ -554,7 +554,7 @@ func (t *TransportManager) handleConnectionFailed(isShortLived bool) {
// As both transports are switched to the same type on any failure, checking just subscriber should be fine.
//
getNext := func(ic *livekit.ICEConfig) livekit.ICECandidateType {
if ic.PreferenceSubscriber == livekit.ICECandidateType_ICT_NONE && t.params.ClientInfo.SupportsICETCP() {
if ic.PreferenceSubscriber == livekit.ICECandidateType_ICT_NONE && t.params.ClientInfo.SupportsICETCP() && t.canUseICETCP() {
return livekit.ICECandidateType_ICT_TCP
} else if ic.PreferenceSubscriber != livekit.ICECandidateType_ICT_TLS && t.params.TURNSEnabled {
return livekit.ICECandidateType_ICT_TLS
@@ -675,12 +675,15 @@ func (t *TransportManager) OnReceiverReport(dt *sfu.DownTrack, report *rtcp.Rece
}
func (t *TransportManager) onMediaLossUpdate(loss uint8) {
if t.params.TCPFallbackRTTThreshold == 0 {
return
}
t.lock.Lock()
t.udpLossUnstableCount <<= 1
if loss >= uint8(255*udpLossFracUnstable/100) {
t.udpLossUnstableCount |= 1
if bits.OnesCount32(t.udpLossUnstableCount) >= udpLossUnstableCountThreshold {
if t.udpRTT > 0 && t.signalingRTT < uint32(float32(t.udpRTT)*1.3) && t.signalingRTT < tcpGoodRTT && time.Since(t.lastSignalAt) < iceFailedTimeout {
if t.udpRTT > 0 && t.signalingRTT < uint32(float32(t.udpRTT)*1.3) && int(t.signalingRTT) < t.params.TCPFallbackRTTThreshold && time.Since(t.lastSignalAt) < iceFailedTimeout {
t.udpLossUnstableCount = 0
t.lock.Unlock()
@@ -697,7 +700,9 @@ func (t *TransportManager) onMediaLossUpdate(loss uint8) {
}
func (t *TransportManager) UpdateSignalingRTT(rtt uint32) {
t.lock.Lock()
t.signalingRTT = rtt
t.lock.Unlock()
t.publisher.SetSignalingRTT(rtt)
t.subscriber.SetSignalingRTT(rtt)
@@ -707,11 +712,13 @@ func (t *TransportManager) UpdateSignalingRTT(rtt uint32) {
}
func (t *TransportManager) UpdateMediaRTT(rtt uint32) {
t.lock.Lock()
if t.udpRTT == 0 {
t.udpRTT = rtt
} else {
t.udpRTT = uint32(int(t.udpRTT) + (int(rtt)-int(t.udpRTT))/2)
}
t.lock.Unlock()
}
func (t *TransportManager) UpdateLastSeenSignal() {
@@ -725,3 +732,7 @@ func (t *TransportManager) SinceLastSignal() time.Duration {
defer t.lock.RUnlock()
return time.Since(t.lastSignalAt)
}
func (t *TransportManager) canUseICETCP() bool {
return t.params.TCPFallbackRTTThreshold == 0 || int(t.signalingRTT) < t.params.TCPFallbackRTTThreshold
}