feat(libwebrtc): implement the webrtc::VideoFrame::Builder timestamp, RTP timestamp, NTP time and id setters #15274

Merged
alvaroelpob merged 6 commits from upstream-pr/15274 into main 2026-11-07 21:55:18 +00:00
alvaroelpob commented 2026-11-02 22:37:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-11-02T22:37:22Z.


What

Implements webrtc::VideoFrame::Builder::set_timestamp_ms(int64_t), set_timestamp_rtp(uint32_t), set_ntp_time_ms(int64_t) and set_id(uint16_t) in libwebrtc, which threw and were declared without parameters.

The module's WebRTC revision lies between M127 and M134, as recorded in the debt file. The four setters in video_frame.cc (M127, M134) are the same at both. The Builder members are too, apart from M134 renaming capture_time_identifier_ to presentation_timestamp_. src/VideoFrameBuilder.cpp starts with that file's WebRTC notice and the BSD licence.

WebRtcVideoFrameBuilder is the 192-byte layout, checked by compiling an equivalent struct with std::optional on the host:

  • id_ at 0, the buffer reference at 8, timestamp_us_ at 16;
  • two optional timestamps, then timestamp_rtp_ at 56, ntp_time_ms_ at 64 and the rotation at 72;
  • the optional ColorSpace (68 bytes) at 76, RenderParameters at 148, the optional UpdateRect at 160 and RtpPacketInfos at 184.

The layout assumes the guest std::optional stores its flag after the value. set_timestamp_ms stores milliseconds × 1000 in timestamp_us_; each setter returns the builder. A null builder throws. It removes 4 exports from the inventory.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON.

  • New guest_webrtc_video_frame_builder test: each setter returns the builder and changes only its own field in a builder filled with 0xA5, including negative milliseconds, UINT32_MAX RTP timestamps and INT64_MIN NTP times; a null builder throws.
  • Full ctest -j16 on head f08e8c83df: 3596/3596 pass. check_conventions.py --base upstream/main passes.
  • pr_overlap.py: no open pull request implements these functions. The shared lines are the pending-export count in docs/dev/debt/libwebrtc.md and the source, test and declaration lists in CMakeLists.txt and Api.hpp.
  • Not tested: Windows, a title.
  • Rebased on main 4f41f4c375, head 432413b6c2, to resolve the conflicts on the shared CMakeLists.txt, Export.cpp and debt-file lines; both sides are kept and the debt count is recomputed from Export.cpp. Full build and ctest -j16: 3796/3800 pass; guest_sce_net, guest_poll, guest_select_wait and guest_memory failed under that load, pass when run alone, and main 4f41f4c375 passes all 3799 with -j16 on the same machine. check_conventions.py --base upstream/main passes.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5128547927 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15274). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-11-02T22:37:22Z. --- ### What Implements `webrtc::VideoFrame::Builder::set_timestamp_ms(int64_t)`, `set_timestamp_rtp(uint32_t)`, `set_ntp_time_ms(int64_t)` and `set_id(uint16_t)` in libwebrtc, which threw and were declared without parameters. The module's WebRTC revision lies between M127 and M134, as recorded in the debt file. The four setters in `video_frame.cc` ([M127](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/api/video/video_frame.cc), [M134](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/video/video_frame.cc)) are the same at both. The `Builder` members are too, apart from M134 renaming `capture_time_identifier_` to `presentation_timestamp_`. `src/VideoFrameBuilder.cpp` starts with that file's WebRTC notice and the BSD licence. `WebRtcVideoFrameBuilder` is the 192-byte layout, checked by compiling an equivalent struct with `std::optional` on the host: - `id_` at 0, the buffer reference at 8, `timestamp_us_` at 16; - two optional timestamps, then `timestamp_rtp_` at 56, `ntp_time_ms_` at 64 and the rotation at 72; - the optional `ColorSpace` (68 bytes) at 76, `RenderParameters` at 148, the optional `UpdateRect` at 160 and `RtpPacketInfos` at 184. The layout assumes the guest `std::optional` stores its flag after the value. `set_timestamp_ms` stores milliseconds × 1000 in `timestamp_us_`; each setter returns the builder. A null builder throws. It removes 4 exports from the inventory. ### 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. --> Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with `BUILD_TESTING=ON`. - New `guest_webrtc_video_frame_builder` test: each setter returns the builder and changes only its own field in a builder filled with 0xA5, including negative milliseconds, `UINT32_MAX` RTP timestamps and `INT64_MIN` NTP times; a null builder throws. - Full `ctest -j16` on head f08e8c83df: 3596/3596 pass. `check_conventions.py --base upstream/main` passes. - `pr_overlap.py`: no open pull request implements these functions. The shared lines are the pending-export count in `docs/dev/debt/libwebrtc.md` and the source, test and declaration lists in `CMakeLists.txt` and `Api.hpp`. - Not tested: Windows, a title. - Rebased on `main` 4f41f4c375, head 432413b6c2, to resolve the conflicts on the shared `CMakeLists.txt`, `Export.cpp` and debt-file lines; both sides are kept and the debt count is recomputed from `Export.cpp`. Full build and `ctest -j16`: 3796/3800 pass; `guest_sce_net`, `guest_poll`, `guest_select_wait` and `guest_memory` failed under that load, pass when run alone, and `main` 4f41f4c375 passes all 3799 with `-j16` on the same machine. `check_conventions.py --base upstream/main` passes. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
BunnyFl commented 2026-11-04 01:07:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T01:07:26Z.

Review: APPROVED


@alvaroelpob thanks, the four setters match the firmware module.

Firmware 13.42. In system/common/lib/libwebrtc.sprx (sha256 d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314), read from disassembly to each ret, not run, not measured on a console:

set_timestamp_ms (X2d8ud4lr-k):
150490: imul   $0x3e8,%rsi,%rcx
150497: mov    %rdi,%rax
15049a: mov    %rcx,0x10(%rdi)
15049e: ret
set_timestamp_rtp (Yryh2HZBUew):
150520: mov    %rdi,%rax
150523: mov    %esi,0x38(%rdi)
150526: ret
set_ntp_time_ms (NKVPbnB0c+c):
150530: mov    %rdi,%rax
150533: mov    %rsi,0x40(%rdi)
150537: ret
set_id (0BYaZKAPP2M):
150610: mov    %rdi,%rax
150613: mov    %si,(%rdi)
150616: ret

So the offsets the PR uses (id at 0, timestampUs at 16, timestampRtp at 56, ntpTimeMs at 64), the store widths, the factor of 1000 and the returned builder all match. The 64-bit imul wraps, and so does your std::uint64_t multiply. The stores above touch only those four fields, so this doesn't confirm the rest of the 192-byte layout.

Optional, debt wording. The entry says "nothing is checked on the console". With the above, it could cite the module instead: "Firmware 13.42 stores directly with no null check (read from disassembly, not measured on a console), so the console faults on a null builder; AnyPS5 throws instead." The layout assumption for the remaining fields still stands.

What I ran: head 432413b6c2 merged onto main 1c8c0efc8c, Windows 11, WinLibs GCC, Release:

  • guest_webrtc_video_frame_builder and public_headers pass (2 of 2);
  • mutation (* 1000u changed to * 100u in set_timestamp_ms): guest_webrtc_video_frame_builder fails;
  • tools/check_conventions.py --base upstream/main on the head: all checks passed. Export.cpp has 347 throwing exports on the head (351 on main), matching the debt entry.

Approving.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5761772810 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15274#pullrequestreview-5761772810). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T01:07:26Z. **Review:** APPROVED --- @alvaroelpob thanks, the four setters match the firmware module. **Firmware 13.42.** In `system/common/lib/libwebrtc.sprx` (sha256 `d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314`), read from disassembly to each `ret`, not run, not measured on a console: ``` set_timestamp_ms (X2d8ud4lr-k): 150490: imul $0x3e8,%rsi,%rcx 150497: mov %rdi,%rax 15049a: mov %rcx,0x10(%rdi) 15049e: ret set_timestamp_rtp (Yryh2HZBUew): 150520: mov %rdi,%rax 150523: mov %esi,0x38(%rdi) 150526: ret set_ntp_time_ms (NKVPbnB0c+c): 150530: mov %rdi,%rax 150533: mov %rsi,0x40(%rdi) 150537: ret set_id (0BYaZKAPP2M): 150610: mov %rdi,%rax 150613: mov %si,(%rdi) 150616: ret ``` So the offsets the PR uses (`id` at 0, `timestampUs` at 16, `timestampRtp` at 56, `ntpTimeMs` at 64), the store widths, the factor of 1000 and the returned builder all match. The 64-bit `imul` wraps, and so does your `std::uint64_t` multiply. The stores above touch only those four fields, so this doesn't confirm the rest of the 192-byte layout. **Optional, debt wording.** The entry says "nothing is checked on the console". With the above, it could cite the module instead: "Firmware 13.42 stores directly with no null check (read from disassembly, not measured on a console), so the console faults on a null builder; AnyPS5 throws instead." The layout assumption for the remaining fields still stands. **What I ran:** head `432413b6c2` merged onto `main` `1c8c0efc8c`, Windows 11, WinLibs GCC, Release: - `guest_webrtc_video_frame_builder` and `public_headers` pass (2 of 2); - mutation (`* 1000u` changed to `* 100u` in `set_timestamp_ms`): `guest_webrtc_video_frame_builder` fails; - `tools/check_conventions.py --base upstream/main` on the head: all checks passed. `Export.cpp` has 347 throwing exports on the head (351 on `main`), matching the debt entry. Approving.
BunnyFl commented 2026-11-05 17:57:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-05T17:57:36Z.

Review: APPROVED


@alvaroelpob re-approving at 3b81e53ed8, after the rebase.

What changed since my approval at 432413b6c2 (git range-diff): the code and test commits differ only in a CMakeLists.txt context line from the rebase. The new commits only touch docs/dev/debt/libwebrtc.md:

  • the entry now cites the 13.42 reading the way I posted it: the same four fields, widths and factor, no null check, read from disassembly and not measured on a console;
  • the count is 343. core/libs/prx/libwebrtc/Export.cpp has 343 NotImplemented_nid_no_patch exports at this head and 347 on main fc23faa40a, whose entry also says 347.

What I ran: this head merged onto main fc23faa40a (merge a7ddcb591b, clean), Windows 11 Pro 10.0.26300, WinLibs GCC, Release:

  • guest_webrtc_video_frame_builder and public_headers pass (2 of 2);
  • mutation, * 1000u changed to * 100u in set_timestamp_ms (the pattern matched once): guest_webrtc_video_frame_builder fails with libwebrtc VideoFrame::Builder check failed at line 40.

Overlap (tools/pr_overlap.py --branch on this head): #15275 and #15276 share these exports and new files; both are yours and declare Depends on: #15274. The other rows are the shared CMakeLists.txt source list and the debt count line that every open libwebrtc PR edits, with no shared exports.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5789552711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15274#pullrequestreview-5789552711). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-05T17:57:36Z. **Review:** APPROVED --- @alvaroelpob re-approving at `3b81e53ed8`, after the rebase. **What changed since my approval at `432413b6c2`** (`git range-diff`): the code and test commits differ only in a `CMakeLists.txt` context line from the rebase. The new commits only touch `docs/dev/debt/libwebrtc.md`: - the entry now cites the 13.42 reading the way I posted it: the same four fields, widths and factor, no null check, read from disassembly and not measured on a console; - the count is 343. `core/libs/prx/libwebrtc/Export.cpp` has 343 `NotImplemented_nid_no_patch` exports at this head and 347 on `main` `fc23faa40a`, whose entry also says 347. **What I ran:** this head merged onto `main` `fc23faa40a` (merge `a7ddcb591b`, clean), Windows 11 Pro 10.0.26300, WinLibs GCC, Release: - `guest_webrtc_video_frame_builder` and `public_headers` pass (2 of 2); - mutation, `* 1000u` changed to `* 100u` in `set_timestamp_ms` (the pattern matched once): `guest_webrtc_video_frame_builder` fails with `libwebrtc VideoFrame::Builder check failed at line 40`. **Overlap** (`tools/pr_overlap.py --branch` on this head): #15275 and #15276 share these exports and new files; both are yours and declare `Depends on: #15274`. The other rows are the shared `CMakeLists.txt` source list and the debt count line that every open libwebrtc PR edits, with no shared exports. AI-assisted: yes (Claude Code)
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!15274
No description provided.