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:
@@ -73,6 +73,7 @@ type ParticipantParams struct {
|
|||||||
Migration bool
|
Migration bool
|
||||||
AdaptiveStream bool
|
AdaptiveStream bool
|
||||||
AllowTCPFallback bool
|
AllowTCPFallback bool
|
||||||
|
TCPFallbackRTTThreshold int
|
||||||
TURNSEnabled bool
|
TURNSEnabled bool
|
||||||
GetParticipantInfo func(pID livekit.ParticipantID) *livekit.ParticipantInfo
|
GetParticipantInfo func(pID livekit.ParticipantID) *livekit.ParticipantInfo
|
||||||
ReconnectOnPublicationError bool
|
ReconnectOnPublicationError bool
|
||||||
@@ -981,6 +982,7 @@ func (p *ParticipantImpl) setupTransportManager() error {
|
|||||||
ClientInfo: p.params.ClientInfo,
|
ClientInfo: p.params.ClientInfo,
|
||||||
Migration: p.params.Migration,
|
Migration: p.params.Migration,
|
||||||
AllowTCPFallback: p.params.AllowTCPFallback,
|
AllowTCPFallback: p.params.AllowTCPFallback,
|
||||||
|
TCPFallbackRTTThreshold: p.params.TCPFallbackRTTThreshold,
|
||||||
TURNSEnabled: p.params.TURNSEnabled,
|
TURNSEnabled: p.params.TURNSEnabled,
|
||||||
Logger: p.params.Logger,
|
Logger: p.params.Logger,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ const (
|
|||||||
udpLossFracUnstable = 25
|
udpLossFracUnstable = 25
|
||||||
// if in last 32 times RR, the unstable report count over this threshold, the connection is unstable
|
// if in last 32 times RR, the unstable report count over this threshold, the connection is unstable
|
||||||
udpLossUnstableCountThreshold = 20
|
udpLossUnstableCountThreshold = 20
|
||||||
tcpGoodRTT = 80
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransportManagerParams struct {
|
type TransportManagerParams struct {
|
||||||
@@ -47,6 +46,7 @@ type TransportManagerParams struct {
|
|||||||
ClientInfo ClientInfo
|
ClientInfo ClientInfo
|
||||||
Migration bool
|
Migration bool
|
||||||
AllowTCPFallback bool
|
AllowTCPFallback bool
|
||||||
|
TCPFallbackRTTThreshold int
|
||||||
TURNSEnabled bool
|
TURNSEnabled bool
|
||||||
Logger logger.Logger
|
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.
|
// 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 {
|
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
|
return livekit.ICECandidateType_ICT_TCP
|
||||||
} else if ic.PreferenceSubscriber != livekit.ICECandidateType_ICT_TLS && t.params.TURNSEnabled {
|
} else if ic.PreferenceSubscriber != livekit.ICECandidateType_ICT_TLS && t.params.TURNSEnabled {
|
||||||
return livekit.ICECandidateType_ICT_TLS
|
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) {
|
func (t *TransportManager) onMediaLossUpdate(loss uint8) {
|
||||||
|
if t.params.TCPFallbackRTTThreshold == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
t.udpLossUnstableCount <<= 1
|
t.udpLossUnstableCount <<= 1
|
||||||
if loss >= uint8(255*udpLossFracUnstable/100) {
|
if loss >= uint8(255*udpLossFracUnstable/100) {
|
||||||
t.udpLossUnstableCount |= 1
|
t.udpLossUnstableCount |= 1
|
||||||
if bits.OnesCount32(t.udpLossUnstableCount) >= udpLossUnstableCountThreshold {
|
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.udpLossUnstableCount = 0
|
||||||
t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
|
|
||||||
@@ -697,7 +700,9 @@ func (t *TransportManager) onMediaLossUpdate(loss uint8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TransportManager) UpdateSignalingRTT(rtt uint32) {
|
func (t *TransportManager) UpdateSignalingRTT(rtt uint32) {
|
||||||
|
t.lock.Lock()
|
||||||
t.signalingRTT = rtt
|
t.signalingRTT = rtt
|
||||||
|
t.lock.Unlock()
|
||||||
t.publisher.SetSignalingRTT(rtt)
|
t.publisher.SetSignalingRTT(rtt)
|
||||||
t.subscriber.SetSignalingRTT(rtt)
|
t.subscriber.SetSignalingRTT(rtt)
|
||||||
|
|
||||||
@@ -707,11 +712,13 @@ func (t *TransportManager) UpdateSignalingRTT(rtt uint32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TransportManager) UpdateMediaRTT(rtt uint32) {
|
func (t *TransportManager) UpdateMediaRTT(rtt uint32) {
|
||||||
|
t.lock.Lock()
|
||||||
if t.udpRTT == 0 {
|
if t.udpRTT == 0 {
|
||||||
t.udpRTT = rtt
|
t.udpRTT = rtt
|
||||||
} else {
|
} else {
|
||||||
t.udpRTT = uint32(int(t.udpRTT) + (int(rtt)-int(t.udpRTT))/2)
|
t.udpRTT = uint32(int(t.udpRTT) + (int(rtt)-int(t.udpRTT))/2)
|
||||||
}
|
}
|
||||||
|
t.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TransportManager) UpdateLastSeenSignal() {
|
func (t *TransportManager) UpdateLastSeenSignal() {
|
||||||
@@ -725,3 +732,7 @@ func (t *TransportManager) SinceLastSignal() time.Duration {
|
|||||||
defer t.lock.RUnlock()
|
defer t.lock.RUnlock()
|
||||||
return time.Since(t.lastSignalAt)
|
return time.Since(t.lastSignalAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TransportManager) canUseICETCP() bool {
|
||||||
|
return t.params.TCPFallbackRTTThreshold == 0 || int(t.signalingRTT) < t.params.TCPFallbackRTTThreshold
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user