feat(libwebrtc): implement rtc::TimeMillis and rtc::TimeMicros #13764

Merged
jacknieland merged 4 commits from upstream-pr/13764 into main 2026-11-01 00:25:02 +00:00
jacknieland commented 2026-10-31 04:59:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jacknieland on 2026-10-31T04:59:20Z.


What

Implements rtc::TimeMillis() and rtc::TimeMicros() in libwebrtc. Both threw, and were declared without a return type.

The module's WebRTC revision is between M127 and M134, as #13687 records in the debt file. TimeNanos, TimeMillis and TimeMicros in rtc_base/time_utils.cc, and the POSIX SystemTimeNanos in rtc_base/system_time.cc, are the same at M127 branch-heads/6533 and M134 branch-heads/6998.

  • Both return int64_t. They read the guest CLOCK_MONOTONIC (4) through libkernel's clock_gettime, convert it to nanoseconds, and divide by 1,000,000 or 1,000, as upstream does.
  • Upstream reads g_clock first, but only rtc::SetClockForTesting sets it, and the module doesn't export that function, so that path is left out.
  • If clock_gettime fails, the call throws.
  • The debt entry records that it's unknown whether Sony builds the module with WEBRTC_EXCLUDE_SYSTEM_TIME and its own clock. The pending count drops from 411 to 409.

Tested

Windows 11 Pro (26200), WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r7), Release, BUILD_TESTING=ON, Ninja, on head 8901150f8a (this branch, on #13687).

  • New guest_webrtc_time test:
    • For 100 rounds, each value lies between two guest CLOCK_MONOTONIC readings taken before and after it, in the same unit.
    • Neither function decreases across 10,000 calls.
    • After a 20 ms sleep, the values advance by at least 19 ms and 19,000 µs.
  • ctest -R guest_webrtc --repeat until-fail:5: guest_webrtc_time and #13687's guest_webrtc_fast_int_to_buffer pass all 5 runs. ctest -R public_headers: 65/65 pass.
  • Negative control: with both bodies put back to NotImplemented_nid_no_patch(__func__), guest_webrtc_time fails with _ZN3rtc10TimeMillisEv_nid_postfix not implemented.
  • check_conventions.py --base origin/main passes. An overlap scan of every open pull request's diff found no other PR that changes these two exports.
  • Not tested: Linux, a title. Only the targets above were built, not the full test suite.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #13736
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5094711426 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13764). Originally posted by [jacknieland](https://github.com/jacknieland) on 2026-10-31T04:59:20Z. --- ### What Implements `rtc::TimeMillis()` and `rtc::TimeMicros()` in libwebrtc. Both threw, and were declared without a return type. The module's WebRTC revision is between M127 and M134, as #13687 records in the debt file. `TimeNanos`, `TimeMillis` and `TimeMicros` in `rtc_base/time_utils.cc`, and the POSIX `SystemTimeNanos` in `rtc_base/system_time.cc`, are the same at [M127 branch-heads/6533](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/rtc_base/time_utils.cc) and [M134 branch-heads/6998](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/time_utils.cc). - Both return `int64_t`. They read the guest `CLOCK_MONOTONIC` (4) through libkernel's `clock_gettime`, convert it to nanoseconds, and divide by 1,000,000 or 1,000, as upstream does. - Upstream reads `g_clock` first, but only `rtc::SetClockForTesting` sets it, and the module doesn't export that function, so that path is left out. - If `clock_gettime` fails, the call throws. - The debt entry records that it's unknown whether Sony builds the module with `WEBRTC_EXCLUDE_SYSTEM_TIME` and its own clock. The pending count drops from 411 to 409. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro (26200), WinLibs GCC 15.2.0 (`x86_64-ucrt-posix-seh`, r7), Release, `BUILD_TESTING=ON`, Ninja, on head `8901150f8a` (this branch, on #13687). - New `guest_webrtc_time` test: - For 100 rounds, each value lies between two guest `CLOCK_MONOTONIC` readings taken before and after it, in the same unit. - Neither function decreases across 10,000 calls. - After a 20 ms sleep, the values advance by at least 19 ms and 19,000 µs. - `ctest -R guest_webrtc --repeat until-fail:5`: `guest_webrtc_time` and #13687's `guest_webrtc_fast_int_to_buffer` pass all 5 runs. `ctest -R public_headers`: 65/65 pass. - Negative control: with both bodies put back to `NotImplemented_nid_no_patch(__func__)`, `guest_webrtc_time` fails with `_ZN3rtc10TimeMillisEv_nid_postfix not implemented`. - `check_conventions.py --base origin/main` passes. An overlap scan of every open pull request's diff found no other PR that changes these two exports. - Not tested: Linux, a title. Only the targets above were built, not the full test suite. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #13736 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-31 06:23:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-31T06:23:55Z.

Review: COMMENTED


Linux run of head 8901150f8a, merged (--no-commit) onto main 6a691f69ee. Ubuntu 26.04 (kernel 7.0), GCC 15.2.0, CMake 4.2.3, Ninja, Release, BUILD_TESTING=ON, i7-8700. The description lists Linux as not tested, so this is that run.

  • guest_webrtc_time and guest_webrtc_fast_int_to_buffer: pass 3/3.
  • Full build ok. Related subset webrtc: 2/2.
  • public_headers: 65/65.
  • Red: throwing at the top of rtc::TimeMillis and rtc::TimeMicros (a stand-in for the main stubs) makes guest_webrtc_time abort 3/3.
  • The head includes #13687's commit, as the description says.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5721622724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13764#pullrequestreview-5721622724). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-31T06:23:55Z. **Review:** COMMENTED --- Linux run of head `8901150f8a`, merged (`--no-commit`) onto `main` `6a691f69ee`. Ubuntu 26.04 (kernel 7.0), GCC 15.2.0, CMake 4.2.3, Ninja, Release, `BUILD_TESTING=ON`, i7-8700. The description lists Linux as not tested, so this is that run. - `guest_webrtc_time` and `guest_webrtc_fast_int_to_buffer`: pass 3/3. - Full build ok. Related subset `webrtc`: 2/2. - `public_headers`: 65/65. - Red: throwing at the top of `rtc::TimeMillis` and `rtc::TimeMicros` (a stand-in for the `main` stubs) makes `guest_webrtc_time` abort 3/3. - The head includes #13687's commit, as the description says. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13764
No description provided.