Skip to content

Commit a82b843

Browse files
committed
Use an improved RTT calculation
Previously each ack was assigned an RTT estimation using the time between packet departure and ack arrival. That method is inaccurate as multiple acks are aggregated in a single feedback packet. Instead, use the min round trip time between packet departure and ack in a feedback packet and subtracting the pending time between packet arrival and feedback departure.
1 parent 1caabbb commit a82b843

15 files changed

+61
-229
lines changed

internal/cc/acknowledgment.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type Acknowledgment struct {
1515
Size int
1616
Departure time.Time
1717
Arrival time.Time
18-
RTT time.Duration
1918
ECN rtcp.ECN
2019
}
2120

@@ -25,6 +24,5 @@ func (a Acknowledgment) String() string {
2524
s += fmt.Sprintf("\tSIZE:\t%v\n", a.Size)
2625
s += fmt.Sprintf("\tDEPARTURE:\t%v\n", int64(float64(a.Departure.UnixNano())/1e+6))
2726
s += fmt.Sprintf("\tARRIVAL:\t%v\n", int64(float64(a.Arrival.UnixNano())/1e+6))
28-
s += fmt.Sprintf("\tRTT:\t%v\n", a.RTT)
2927
return s
3028
}

internal/cc/feedback_adapter.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func (f *FeedbackAdapter) onSentRFC8888(ts time.Time, header *rtp.Header, size i
4343
Size: size,
4444
Departure: ts,
4545
Arrival: time.Time{},
46-
RTT: 0,
4746
ECN: 0,
4847
})
4948
return nil
@@ -65,7 +64,6 @@ func (f *FeedbackAdapter) onSentTWCC(ts time.Time, extID uint8, header *rtp.Head
6564
Size: header.MarshalSize() + size,
6665
Departure: ts,
6766
Arrival: time.Time{},
68-
RTT: 0,
6967
ECN: 0,
7068
})
7169
return nil
@@ -83,7 +81,7 @@ func (f *FeedbackAdapter) OnSent(ts time.Time, header *rtp.Header, size int, att
8381
return f.onSentRFC8888(ts, header, size)
8482
}
8583

86-
func (f *FeedbackAdapter) unpackRunLengthChunk(ts time.Time, start uint16, refTime time.Time, chunk *rtcp.RunLengthChunk, deltas []*rtcp.RecvDelta) (consumedDeltas int, nextRef time.Time, acks []Acknowledgment, err error) {
84+
func (f *FeedbackAdapter) unpackRunLengthChunk(start uint16, refTime time.Time, chunk *rtcp.RunLengthChunk, deltas []*rtcp.RecvDelta) (consumedDeltas int, nextRef time.Time, acks []Acknowledgment, err error) {
8785
result := make([]Acknowledgment, chunk.RunLength)
8886
deltaIndex := 0
8987

@@ -101,7 +99,6 @@ func (f *FeedbackAdapter) unpackRunLengthChunk(ts time.Time, start uint16, refTi
10199
}
102100
refTime = refTime.Add(time.Duration(deltas[deltaIndex].Delta) * time.Microsecond)
103101
ack.Arrival = refTime
104-
ack.RTT = ts.Sub(ack.Departure)
105102
deltaIndex++
106103
}
107104
result[resultIndex] = ack
@@ -111,7 +108,7 @@ func (f *FeedbackAdapter) unpackRunLengthChunk(ts time.Time, start uint16, refTi
111108
return deltaIndex, refTime, result, nil
112109
}
113110

114-
func (f *FeedbackAdapter) unpackStatusVectorChunk(ts time.Time, start uint16, refTime time.Time, chunk *rtcp.StatusVectorChunk, deltas []*rtcp.RecvDelta) (consumedDeltas int, nextRef time.Time, acks []Acknowledgment, err error) {
111+
func (f *FeedbackAdapter) unpackStatusVectorChunk(start uint16, refTime time.Time, chunk *rtcp.StatusVectorChunk, deltas []*rtcp.RecvDelta) (consumedDeltas int, nextRef time.Time, acks []Acknowledgment, err error) {
115112
result := make([]Acknowledgment, len(chunk.SymbolList))
116113
deltaIndex := 0
117114
resultIndex := 0
@@ -127,7 +124,6 @@ func (f *FeedbackAdapter) unpackStatusVectorChunk(ts time.Time, start uint16, re
127124
}
128125
refTime = refTime.Add(time.Duration(deltas[deltaIndex].Delta) * time.Microsecond)
129126
ack.Arrival = refTime
130-
ack.RTT = ts.Sub(ack.Departure)
131127
deltaIndex++
132128
}
133129
result[resultIndex] = ack
@@ -152,7 +148,7 @@ func (f *FeedbackAdapter) OnTransportCCFeedback(ts time.Time, feedback *rtcp.Tra
152148
for _, chunk := range feedback.PacketChunks {
153149
switch chunk := chunk.(type) {
154150
case *rtcp.RunLengthChunk:
155-
n, nextRefTime, acks, err := f.unpackRunLengthChunk(ts, index, refTime, chunk, recvDeltas)
151+
n, nextRefTime, acks, err := f.unpackRunLengthChunk(index, refTime, chunk, recvDeltas)
156152
if err != nil {
157153
return nil, err
158154
}
@@ -161,7 +157,7 @@ func (f *FeedbackAdapter) OnTransportCCFeedback(ts time.Time, feedback *rtcp.Tra
161157
recvDeltas = recvDeltas[n:]
162158
index = uint16(int(index) + len(acks))
163159
case *rtcp.StatusVectorChunk:
164-
n, nextRefTime, acks, err := f.unpackStatusVectorChunk(ts, index, refTime, chunk, recvDeltas)
160+
n, nextRefTime, acks, err := f.unpackStatusVectorChunk(index, refTime, chunk, recvDeltas)
165161
if err != nil {
166162
return nil, err
167163
}
@@ -196,7 +192,6 @@ func (f *FeedbackAdapter) OnRFC8888Feedback(ts time.Time, feedback *rtcp.CCFeedb
196192
if mb.Received {
197193
delta := time.Duration((float64(mb.ArrivalTimeOffset) / 1024.0) * float64(time.Second))
198194
ack.Arrival = referenceTime.Add(-delta)
199-
ack.RTT = ts.Sub(ack.Departure)
200195
ack.ECN = mb.ECN
201196
}
202197
result = append(result, ack)

0 commit comments

Comments
 (0)