Repository navigation
util: Carry a whole second in os_nstime_to_timespec - #1508
Conversation
|
Coordinator: not queueing this one myself. It changes the expectation of the existing C test |
|
Confirming: the test change is deliberate. |
The characterization tests for os_nstime_to_timespec (obs-rust#262 slice 6) pinned an odd case as "characterized, not endorsed": above the base, a result that lands on a whole second comes back as tv_nsec == 1000000000 with tv_sec one short, because the carry tests nsecs > 1000000000 where >= was meant. That is not a valid struct timespec (tv_nsec must be below 1000000000). This deliberately changes those characterization tests to expect the normalized result, {sec, 0}, since the next commit fixes the carry: - test_whole_second_above_the_base (and its Tier 1 mirror whole_second_above_the_base) expect {sec, 0} and {sec + 7, 0}, and pin one nanosecond below ({sec - 1, 999999999}) and above ({sec, 1}). - check() no longer special-cases a whole second above the base, and test_around_the_base no longer accepts either form. - The Tier 1 fixed-base cases (carry_and_borrow_with_a_fixed_base, negative_wall_seconds) expect the carried second, and the fixed base also pins one nanosecond below the edge. On master, test_platform_time fails test_whole_second_above_the_base (8 of 9 pass) against libobs and libobs-with-rust in both lanes, and the obs-util platform_time tests fail 3 of 21. Refs obs-rust#1505
Above the base, os_nstime_to_timespec adds the base's tv_nsec and the
offset's nanoseconds, which sum to anything from 0 to 1999999998, and
carried only when the sum was greater than 1000000000. A sum of exactly
1000000000 was returned as tv_nsec == 1000000000 with tv_sec one short,
which is not a valid struct timespec. That happens for every timestamp
whose wall time is a whole second, unless the base's own wall time was one.
Carry with >= in the C (libobs/util/platform-time.c.h) and in the Rust
core (obs-util::platform_time), so the result is always normalized, as it
already was below the base.
The only caller in the tree is shared/bpm (Broadcast Performance Metrics
on Enhanced Broadcasting multitrack video). It prints tv_sec with %T and
tv_nsec / 1000000 with .%03ld, so a frame at ...:33.000 was sent as
...:32.1000Z, 900 ms early. A plugin passing the result to
pthread_cond_timedwait or nanosleep would get EINVAL.
Upstream OBS has the same code in libobs/util/platform.c (no upstream
issue). The Tier 3 parity test compares the Rust core with the same C
file, so the C and the Rust change together and need no exclusion; the
whole_second_edge case now expects {101, 0} from both and checks one
nanosecond either side. rust/README.md no longer lists the carry as kept.
Fixes obs-rust#1505
303d764 to
1361e61
Compare
|
Coordinator, approved on the maintainer's instruction: this fixes a real off-by-one (a whole-second result comes back as |
Fixes #1505
What and why
os_nstime_to_timespecnow returns a normalizedstruct timespecfor every timestamp. Before, a timestamp above the base whose wall time landed on a whole second came back astv_nsec == 1000000000withtv_secone short, which is not a valid timespec.tv_nsecplusoffset % 1000000000, which can be anything from 0 to 1999999998. The carry wasif (nsecs > nsecs_per_sec), so a sum of exactly 1000000000 was not carried. It is>=now, in the C (libobs/util/platform-time.c.h) and in the Rust core (obs-util::platform_time, ported in util: Port os_nstime_to_timespec to obs-util #1507). Below the base the result was already normalized.shared/bpm(Broadcast Performance Metrics, sent with Enhanced Broadcasting multitrack video).render_metrics_time()printstv_secwith%Tandtv_nsec / 1000000with.%03ld, so a frame at…:33.000was sent as…:32.1000Z, which reads as 900 ms early. A plugin passing the result topthread_cond_timedwaitornanosleepwould getEINVAL.libobs/util/platform.c. Nobody has reported it there, so there is no upstream issue.{sec, 0}:test_whole_second_above_the_baseand its Tier 1 mirror,check()(no whole-second special case above the base),test_around_the_base(no longer accepts either form), and the Tier 1 fixed-base cases. Each also pins one nanosecond below and above the edge.whole_second_edgenow expects{101, 0}from both. The rust/README.md row no longer says the port keeps the C carry.Headless (private Xvfb, private D-Bus, fresh HOME):
test_platform_timewith the RED tests, libobs and libobs-with-rust, both lanestest_whole_second_above_the_basefails (tv_secone short), 8/9 passplatform_timetests with the RED testswhole_second_above_the_base,carry_and_borrow_with_a_fixed_base,negative_wall_seconds)test_platform_time, libobs and libobs-with-rust, both lanesplatform_timetests (Tiers 1 and 3)RED → GREEN
test: Expect a normalized timespec on a whole second above the base. On master,ctest -R test_platformfails 1 of 5 (test_platform_time:test_whole_second_above_the_base) in the C lane (ENABLE_RUST_LIBOBS=OFF) and the libobs-with-rust lane (ON), each against bothlibobsandlibobs-with-rust.cargo test -p obs-util --lib platform_time: 18 passed, 3 failed.ctest -R test_platform5/5 in both lanes, against both libraries, none skipped; exported symbols of the two libraries identical (1766).cargo test -p obs-util: 637/637.cargo clippy --workspace --all-targets -- -D warnings: clean.uv run ci/local_gate.py --lane lint: ok.tv_nsecstay below 1000000000, which is whatrender_metrics_time()assumes.Checklist
masterdocs/features.mdis added (Fixed upstream bugs, Encoding, streaming and recording)-W..., ratchets): built with scripting ON (a flag change under cmake/ or build-aux/ runs the full builds) and cross-checked with clang and MSVC (not applicable: no flag change)