Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TWCC: Fix small receive delta rounding #207

Merged
merged 1 commit into from
Sep 28, 2023

Conversation

kcaffrey
Copy link
Contributor

Prior to this change, a sequence of small receive deltas could get erroneously encoded as a series of 0s.

If the actual receive deltas were {200μs, 200μs, ..., 200μs}, what was appearing in the TWCC feedback packet (after marshaling) was {0, 0, ..., 0}. (Note: the added test, without the code fixes, would fail by returning deltas of {200, 200, ..., 200}, but marshalling the feedback packet would truncate all of those to 0).

To fix this, receive deltas are rounded to the closest "delta tick" period (250μs) as opposed to truncating. Additionally, lastTimestampUS is moved forward by the rounded delta instead of set to the timestamp of the last packet. This lets rounding errors accumulate so that a series of packets will have the correct sum of receive deltas (within the margin of error of a delta tick).

@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

All modified lines are covered by tests ✅

Files Coverage Δ
pkg/twcc/twcc.go 95.08% <100.00%> (+0.19%) ⬆️

... and 2 files with indirect coverage changes

📢 Thoughts on this report? Let us know!.

@davidzhao davidzhao requested a review from boks1971 September 27, 2023 23:39
Copy link
Contributor

@boks1971 boks1971 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

pkg/twcc/twcc_test.go Show resolved Hide resolved
pkg/twcc/twcc.go Outdated Show resolved Hide resolved
@kcaffrey
Copy link
Contributor Author

@boks1971 Thanks for the review, I made those changes.

Prior to this change, a sequence of small receive deltas could get
erroneously encoded as a series of 0s.

If the actual receive deltas were {200μs, 200μs, ..., 200μs}, what
was appearing in the TWCC feedback packet (after marshaling) was
{0, 0, ..., 0}. (Note: the added test, without the code fixes, would
fail by returning deltas of {200, 200, ..., 200}, but marshalling the
feedback packet would truncate all of those to 0).

To fix this, receive deltas are rounded to the closest "delta tick"
period (250μs) as opposed to truncating. Additionally,
`lastTimestampUS` is moved forward by the rounded delta instead of set
to the timestamp of the last packet. This lets rounding errors
accumulate so that a series of packets will have the correct sum of
receive deltas (within the margin of error of a delta tick).
@kcaffrey kcaffrey force-pushed the fix-twcc-small-deltas branch from b67f05e to 4c1a9d4 Compare September 28, 2023 22:22
@adriancable adriancable merged commit 306e11d into pion:master Sep 28, 2023
15 checks passed
@kcaffrey kcaffrey deleted the fix-twcc-small-deltas branch September 29, 2023 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants