feat(libwebrtc): implement the webrtc::ColorSpace copy constructor and assignment #15189

Merged
alvaroelpob merged 6 commits from upstream-pr/15189 into main 2026-11-10 03:16:02 +00:00
alvaroelpob commented 2026-11-02 20:25:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-11-02T20:25:55Z.


What

Implements webrtc::ColorSpace::ColorSpace(const ColorSpace&) and ColorSpace::operator=(const ColorSpace&) 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. Both are = default in color_space.cc (M127, M134). color_space.h differs between M127 and M134 only in spelling hdr_metadata_ as absl::optional or std::optional, and hdr_metadata.h is identical. The file src/ColorSpace.cpp starts with color_space.cc's WebRTC notice and the BSD licence.

WebRtcColorSpace is the 68-byte layout:

  • three uint8_t IDs (primaries, transfer, matrix);
  • the int range and the two chroma sitings at 4, 8 and 12;
  • the 48-byte HdrMetadata (four chromaticities, two luminances, two int light levels) at 16, with the optional's engaged flag at 64.

Every member is trivially copyable, so both copy the whole object, and the assignment returns this. A null object or source, which upstream dereferences, throws. It removes 2 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_color_space test: copying an HDR10 color space (BT.2020, PQ, full range, chroma sitings, mastering metadata and light levels) and an SDR one without metadata into storage filled with 0xA5; assignment returns this, clears the metadata from an empty source and survives self-assignment; null arguments throw std::invalid_argument and leave the object untouched.
  • Full ctest -j16 on head 64670e7028: 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 274830625a, 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. Both copies now move 65 bytes (offsetof(WebRtcColorSpace, hasHdrMetadata) + 1) as the 13.42 module does, and the new TestTailPaddingUntouched checks bytes 65 to 67 keep 0xA5 after the copy constructor and operator=. Full build and ctest -j16: 3800/3800 pass (a first run under load failed guest_sce_net, guest_poll, guest_select_wait and guest_memory, which pass alone and on main). 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:5126906694 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15189). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-11-02T20:25:55Z. --- ### What Implements `webrtc::ColorSpace::ColorSpace(const ColorSpace&)` and `ColorSpace::operator=(const ColorSpace&)` 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. Both are `= default` in `color_space.cc` ([M127](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/api/video/color_space.cc), [M134](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/video/color_space.cc)). `color_space.h` differs between M127 and M134 only in spelling `hdr_metadata_` as `absl::optional` or `std::optional`, and `hdr_metadata.h` is identical. The file `src/ColorSpace.cpp` starts with `color_space.cc`'s WebRTC notice and the BSD licence. `WebRtcColorSpace` is the 68-byte layout: - three `uint8_t` IDs (primaries, transfer, matrix); - the `int` range and the two chroma sitings at 4, 8 and 12; - the 48-byte `HdrMetadata` (four chromaticities, two luminances, two `int` light levels) at 16, with the optional's engaged flag at 64. Every member is trivially copyable, so both copy the whole object, and the assignment returns `this`. A null object or source, which upstream dereferences, throws. It removes 2 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_color_space` test: copying an HDR10 color space (BT.2020, PQ, full range, chroma sitings, mastering metadata and light levels) and an SDR one without metadata into storage filled with 0xA5; assignment returns `this`, clears the metadata from an empty source and survives self-assignment; null arguments throw `std::invalid_argument` and leave the object untouched. - Full `ctest -j16` on head 64670e7028: 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 274830625a, 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`. Both copies now move 65 bytes (`offsetof(WebRtcColorSpace, hasHdrMetadata) + 1`) as the 13.42 module does, and the new `TestTailPaddingUntouched` checks bytes 65 to 67 keep 0xA5 after the copy constructor and `operator=`. Full build and `ctest -j16`: 3800/3800 pass (a first run under load failed `guest_sce_net`, `guest_poll`, `guest_select_wait` and `guest_memory`, which pass alone and on `main`). `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-02 21:12:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T21:12:13Z.

Review: APPROVED


Matches firmware 13.42's system/common/lib/libwebrtc.sprx (sha256 d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314) in layout and result, disassembly only. The copy constructor (wTCRZOkkrnM, 0x1516f0) and operator= (tY7zuWm3mFU, 0x151730, which also returns this in rax) are the same copy:

1516f0: movzbl 0x40(%rsi),%eax ; mov %al,0x40(%rdi)     has_hdr_metadata byte at 64
1516f7: vmovups (%rsi),%ymm0 ; vmovups 0x20(%rsi),%ymm1
151700: vmovups %ymm1,0x20(%rdi) ; vmovups %ymm0,(%rdi)  bytes 0..63

That's this PR's 68-byte WebRtcColorSpace with hasHdrMetadata at 64.

Non-blocking: the module copies 65 bytes (0x00-0x40), while memmove(..., sizeof(WebRtcColorSpace)) copies 68 and so also writes the destination's three tail-padding bytes. That would only show if a guest object reused that tail padding (e.g. a derived class under the Itanium ABI), but copying offsetof(WebRtcColorSpace, hasHdrMetadata) + 1 bytes would match the module exactly.

Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto main: guest_webrtc_color_space passes, nothing skipped. With main's Export.cpp and Api.hpp, the new source doesn't compile against the old parameterless declarations.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5743416695 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15189#pullrequestreview-5743416695). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T21:12:13Z. **Review:** APPROVED --- Matches firmware 13.42's `system/common/lib/libwebrtc.sprx` (sha256 `d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314`) in layout and result, disassembly only. The copy constructor (`wTCRZOkkrnM`, `0x1516f0`) and `operator=` (`tY7zuWm3mFU`, `0x151730`, which also returns `this` in `rax`) are the same copy: ``` 1516f0: movzbl 0x40(%rsi),%eax ; mov %al,0x40(%rdi) has_hdr_metadata byte at 64 1516f7: vmovups (%rsi),%ymm0 ; vmovups 0x20(%rsi),%ymm1 151700: vmovups %ymm1,0x20(%rdi) ; vmovups %ymm0,(%rdi) bytes 0..63 ``` That's this PR's 68-byte `WebRtcColorSpace` with `hasHdrMetadata` at 64. Non-blocking: the module copies 65 bytes (`0x00`-`0x40`), while `memmove(..., sizeof(WebRtcColorSpace))` copies 68 and so also writes the destination's three tail-padding bytes. That would only show if a guest object reused that tail padding (e.g. a derived class under the Itanium ABI), but copying `offsetof(WebRtcColorSpace, hasHdrMetadata) + 1` bytes would match the module exactly. Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto `main`: `guest_webrtc_color_space` passes, nothing skipped. With `main`'s `Export.cpp` and `Api.hpp`, the new source doesn't compile against the old parameterless declarations.
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!15189
No description provided.