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

Fix a bug in AbsCpatureTimeExtension #248

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Fix a bug in AbsCpatureTimeExtension #248

merged 1 commit into from
Mar 15, 2024

Conversation

enobufs
Copy link
Member

@enobufs enobufs commented Mar 9, 2024

Description

  • Small modifications to the following method to handle a negative captureClockOffset value correctly.
    • EstimatedCaptureClockOffsetDuration
    • NewAbsCaptureTimeExtensionWithCaptureClockOffset
  • Added a unit test to verify the fix

Reference issue

Fixes #247

Copy link

codecov bot commented Mar 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.50%. Comparing base (78da5a2) to head (af67ac0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #248      +/-   ##
==========================================
+ Coverage   87.41%   87.50%   +0.09%     
==========================================
  Files          21       21              
  Lines        2113     2129      +16     
==========================================
+ Hits         1847     1863      +16     
  Misses        230      230              
  Partials       36       36              
Flag Coverage Δ
go 87.50% <100.00%> (+0.09%) ⬆️
wasm 86.98% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

if offset < 0 {
offset = -offset
negative = true
}
duration := time.Duration(offset/(1<<32))*time.Second + time.Duration((offset&0xFFFFFFFF)*1e9/(1<<32))*time.Nanosecond
Copy link
Contributor

Choose a reason for hiding this comment

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

Would something like:

duration := time.Duration(offset/(1<<32))*time.Second + time.Duration((offset%(1<<32)))*1e9/(1<<32))*time.Nanosecond

work instead to be branchless?

Copy link
Member Author

@enobufs enobufs Mar 15, 2024

Choose a reason for hiding this comment

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

Thanks @kevmo314 for your comment.
To accurately handle negative durations in the NTP offset conversion, the 64-bit value must undergo a 2's complement operation (^(value) + 1), the example you showed wouldn't work. I think it is challenging to implement without conditional branching imo. (FYI: We found, based on a benchmark, the unary operation (val = -val) is faster (Go does it well apparently) than ^(val) + 1. )

If you had a better solution that works, please let me know!

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good thanks for trying!

Comment on lines 96 to 97
lsb := (ns / 1e9) & 0xFFFFFFFF
msb := (((ns % 1e9) * (1 << 32)) / 1e9) & 0xFFFFFFFF
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, could we replace & 0xFFFFFFFF with % (1 << 32) to fix the issue?

@kevmo314 kevmo314 merged commit 410c582 into master Mar 15, 2024
14 checks passed
@kevmo314 kevmo314 deleted the fix_abscapturetime branch March 15, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AbsCaptureTimeExtension does not encode/decode correctly when captureClockOffset is negative
2 participants