-
Notifications
You must be signed in to change notification settings - Fork 4
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
int32 milliseconds overflow when time difference is over 24 days #16
Comments
What would you prefer using for time handling in case of going 64 bit, milliseconds, microseconds, a structure like tm_t, a combination? Here are some particularities that I've noticed for each:
Here are some methods added to tm_t that would allow writing expressions likestruct tv_t {
int32_t sec;
int32_t usec;
int64_t toMillis() const { return int64_t(sec) * 1000 + usec / 1000; }
int64_t toMicros() const { return int64_t(sec) * 1000 * 1000 + usec; }
tv_t& setMillis(int64_t ms) {
sec = ms / 1000;
usec = (ms - int64_t(sec) * 1000) * 1000;
return *this;
}
tv_t& setMicros(int64_t us) {
sec = us / 1000 / 1000;
usec = us - int64_t(sec) * 1000 * 1000;
return *this;
}
tv_t operator +(tv_t other) const {
// from time.h timeradd(...)
tv_t out;
out.sec = sec + other.sec;
out.usec = usec + other.usec;
if(out.usec >= 1000*1000) {
out.sec++;
out.usec -= 1000*1000;
}
return out;
}
tv_t operator -(tv_t other) const {
// from time.h timersub(...)
tv_t out;
out.sec = sec - other.sec;
out.usec = usec - other.usec;
if(out.usec < 0) {
out.sec--;
out.usec += 1000*1000;
}
return out;
}
tv_t operator /(int div) {
tv_t out;
out.sec = sec / div;
out.usec = ((sec - out.sec * div) * 1000*1000 + usec) / div;
while(out.usec >= 1000*1000) {
out.sec++;
out.usec -= 1000*1000;
}
return out;
}
}; tm_t diff_to_server = (time_message.latency - (base_message.received - base_message.sent)) / 2; I would favor using microseconds given these observations. |
My preference is in the order you mentioned the options. I think humans can not distinguish any difference in microseconds, so I would not see any big advantage in going more detailed. |
I'm getting sync between different clients including snapdroid with this commit 8f6d62e, by using the timestamp from SnapAudioHeader. The Not submitting a PR yet since SnapTimeSync is no longer used except for storing the initial delay, and most of the sync code referencing it would drop. I found it easier to use microseconds for now, and trying to reduce some jitter observed on successive latency messages. |
With commit 8949733 it's syncing with snapdroid using a Edit: to be in sync, |
Hi, I wrote a draft of a SnapProcessor that buffers the encoded chunks paired with their respective timestamps. I've noticed that if they're applied to SnapOutput (via writeAudioInfo) unpaired, the buffer acts as a constant time delay line, instead of being elastic, and it doesn't compensate for network hiccups. The commits are d5ff509 and e2b213a. I'm getting synchronization with snapdroid with a |
Discussed in #15
Originally posted by mcbp223 March 18, 2024
It seems I had the snapserver turned on for a long time, and now the time difference between server and client overflows when calculated in milliseconds,
2^31 / 1000 / 3600 / 24 = 24.855 134 81
. This can be overcome by callingsettimeofday(...)
when appropriate.I'm experimenting with the following:
SnapTime::toMillis(timeval)
andSnapTime::timeDifferenceMs(...)
from uint32_t to int64_t.SnapProcessor::processMessageTime()
I call 'settimeofday()' instead of assert, the part after the trx assignment isThe log when set to show the time difference is:
There's also a detail that can easily be overlooked, the printf format for int64_t is
%lld
with double 'l`.The text was updated successfully, but these errors were encountered: