Skip to content

Commit

Permalink
Use an improved RTT calculation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mengelbart committed Jul 20, 2022
1 parent 1caabbb commit a82b843
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 229 deletions.
2 changes: 0 additions & 2 deletions internal/cc/acknowledgment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Acknowledgment struct {
Size int
Departure time.Time
Arrival time.Time
RTT time.Duration
ECN rtcp.ECN
}

Expand All @@ -25,6 +24,5 @@ func (a Acknowledgment) String() string {
s += fmt.Sprintf("\tSIZE:\t%v\n", a.Size)
s += fmt.Sprintf("\tDEPARTURE:\t%v\n", int64(float64(a.Departure.UnixNano())/1e+6))
s += fmt.Sprintf("\tARRIVAL:\t%v\n", int64(float64(a.Arrival.UnixNano())/1e+6))
s += fmt.Sprintf("\tRTT:\t%v\n", a.RTT)
return s
}
13 changes: 4 additions & 9 deletions internal/cc/feedback_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (f *FeedbackAdapter) onSentRFC8888(ts time.Time, header *rtp.Header, size i
Size: size,
Departure: ts,
Arrival: time.Time{},
RTT: 0,
ECN: 0,
})
return nil
Expand All @@ -65,7 +64,6 @@ func (f *FeedbackAdapter) onSentTWCC(ts time.Time, extID uint8, header *rtp.Head
Size: header.MarshalSize() + size,
Departure: ts,
Arrival: time.Time{},
RTT: 0,
ECN: 0,
})
return nil
Expand All @@ -83,7 +81,7 @@ func (f *FeedbackAdapter) OnSent(ts time.Time, header *rtp.Header, size int, att
return f.onSentRFC8888(ts, header, size)
}

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) {
func (f *FeedbackAdapter) unpackRunLengthChunk(start uint16, refTime time.Time, chunk *rtcp.RunLengthChunk, deltas []*rtcp.RecvDelta) (consumedDeltas int, nextRef time.Time, acks []Acknowledgment, err error) {
result := make([]Acknowledgment, chunk.RunLength)
deltaIndex := 0

Expand All @@ -101,7 +99,6 @@ func (f *FeedbackAdapter) unpackRunLengthChunk(ts time.Time, start uint16, refTi
}
refTime = refTime.Add(time.Duration(deltas[deltaIndex].Delta) * time.Microsecond)
ack.Arrival = refTime
ack.RTT = ts.Sub(ack.Departure)
deltaIndex++
}
result[resultIndex] = ack
Expand All @@ -111,7 +108,7 @@ func (f *FeedbackAdapter) unpackRunLengthChunk(ts time.Time, start uint16, refTi
return deltaIndex, refTime, result, nil
}

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) {
func (f *FeedbackAdapter) unpackStatusVectorChunk(start uint16, refTime time.Time, chunk *rtcp.StatusVectorChunk, deltas []*rtcp.RecvDelta) (consumedDeltas int, nextRef time.Time, acks []Acknowledgment, err error) {
result := make([]Acknowledgment, len(chunk.SymbolList))
deltaIndex := 0
resultIndex := 0
Expand All @@ -127,7 +124,6 @@ func (f *FeedbackAdapter) unpackStatusVectorChunk(ts time.Time, start uint16, re
}
refTime = refTime.Add(time.Duration(deltas[deltaIndex].Delta) * time.Microsecond)
ack.Arrival = refTime
ack.RTT = ts.Sub(ack.Departure)
deltaIndex++
}
result[resultIndex] = ack
Expand All @@ -152,7 +148,7 @@ func (f *FeedbackAdapter) OnTransportCCFeedback(ts time.Time, feedback *rtcp.Tra
for _, chunk := range feedback.PacketChunks {
switch chunk := chunk.(type) {
case *rtcp.RunLengthChunk:
n, nextRefTime, acks, err := f.unpackRunLengthChunk(ts, index, refTime, chunk, recvDeltas)
n, nextRefTime, acks, err := f.unpackRunLengthChunk(index, refTime, chunk, recvDeltas)
if err != nil {
return nil, err
}
Expand All @@ -161,7 +157,7 @@ func (f *FeedbackAdapter) OnTransportCCFeedback(ts time.Time, feedback *rtcp.Tra
recvDeltas = recvDeltas[n:]
index = uint16(int(index) + len(acks))
case *rtcp.StatusVectorChunk:
n, nextRefTime, acks, err := f.unpackStatusVectorChunk(ts, index, refTime, chunk, recvDeltas)
n, nextRefTime, acks, err := f.unpackStatusVectorChunk(index, refTime, chunk, recvDeltas)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -196,7 +192,6 @@ func (f *FeedbackAdapter) OnRFC8888Feedback(ts time.Time, feedback *rtcp.CCFeedb
if mb.Received {
delta := time.Duration((float64(mb.ArrivalTimeOffset) / 1024.0) * float64(time.Second))
ack.Arrival = referenceTime.Add(-delta)
ack.RTT = ts.Sub(ack.Departure)
ack.ECN = mb.ECN
}
result = append(result, ack)
Expand Down
Loading

0 comments on commit a82b843

Please sign in to comment.