Add reconnect reason and signal rtt calculation (#1381)

* Add connect reason and signal rtt calculate

* Update protocol

* solve comment
This commit is contained in:
cnderrauber
2023-02-06 11:12:25 +08:00
committed by GitHub
parent d67cdb6141
commit 8b6dab780c
16 changed files with 221 additions and 118 deletions
+20 -16
View File
@@ -70,7 +70,7 @@ type TransportManager struct {
mediaLossProxy *MediaLossProxy
udpLossUnstableCount uint32
tcpRTT, udpRTT uint32
signalingRTT, udpRTT uint32
onPublisherInitialConnected func()
onSubscriberInitialConnected func()
@@ -439,11 +439,15 @@ func (t *TransportManager) NegotiateSubscriber(force bool) {
t.subscriber.Negotiate(force)
}
func (t *TransportManager) ICERestart(iceConfig *livekit.ICEConfig) {
func (t *TransportManager) ICERestart(iceConfig *livekit.ICEConfig, resetShortConnection bool) {
if iceConfig != nil {
t.SetICEConfig(iceConfig)
}
if resetShortConnection {
t.publisher.ResetShortConnOnICERestart()
t.subscriber.ResetShortConnOnICERestart()
}
t.subscriber.ICERestart()
}
@@ -662,11 +666,11 @@ func (t *TransportManager) onMediaLossUpdate(loss uint8) {
if loss >= uint8(255*udpLossFracUnstable/100) {
t.udpLossUnstableCount |= 1
if bits.OnesCount32(t.udpLossUnstableCount) >= udpLossUnstableCountThreshold {
if t.udpRTT > 0 && t.tcpRTT < uint32(float32(t.udpRTT)*1.3) && t.tcpRTT < tcpGoodRTT {
if t.udpRTT > 0 && t.signalingRTT < uint32(float32(t.udpRTT)*1.3) && t.signalingRTT < tcpGoodRTT && time.Since(t.lastSignalAt) < iceFailedTimeout {
t.udpLossUnstableCount = 0
t.lock.Unlock()
t.params.Logger.Infow("udp connection unstable, switch to tcp")
t.params.Logger.Infow("udp connection unstable, switch to tcp", "signalingRTT", t.signalingRTT)
t.handleConnectionFailed(true)
if t.onAnyTransportFailed != nil {
t.onAnyTransportFailed()
@@ -678,19 +682,19 @@ func (t *TransportManager) onMediaLossUpdate(loss uint8) {
t.lock.Unlock()
}
func (t *TransportManager) UpdateRTT(rtt uint32, isUDP bool) {
if isUDP {
if t.udpRTT == 0 {
t.udpRTT = rtt
} else {
t.udpRTT = uint32(int(t.udpRTT) + (int(rtt)-int(t.udpRTT))/2)
}
} else {
t.tcpRTT = rtt
func (t *TransportManager) UpdateSignalingRTT(rtt uint32) {
t.signalingRTT = rtt
// TODO: considering using tcp rtt to calculate ice connection cost, if ice connection can't be established
// within 5 * tcp rtt(at least 5s), means udp traffic might be block/dropped, switch to tcp.
// Currently, most cases reported is that ice connected but subsequent connection, so left the thinking for now.
// TODO: considering using tcp rtt to calculate ice connection cost, if ice connection can't be established
// within 5 * tcp rtt(at least 5s), means udp traffic might be block/dropped, switch to tcp.
// Currently, most cases reported is that ice connected but subsequent connection, so left the thinking for now.
}
func (t *TransportManager) UpdateMediaRTT(rtt uint32) {
if t.udpRTT == 0 {
t.udpRTT = rtt
} else {
t.udpRTT = uint32(int(t.udpRTT) + (int(rtt)-int(t.udpRTT))/2)
}
}