feat(libwebrtc): implement RTCP REMB parsing #18798

Merged
AlexWhitehouse merged 4 commits from upstream-pr/18798 into main 2026-11-17 11:18:15 +00:00
AlexWhitehouse commented 2026-11-12 10:32:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-12T10:32:04Z.


What

libwebrtc webrtc::rtcp::Remb::Parse(const CommonHeader&) (_ZN6webrtc4rtcp4Remb5ParseERKNS0_12CommonHeaderE, NID QyR2ngto5ow) threw not implemented. This PR ports it from M134 (8d78f5de) remb.cc, with ParseCommonFeedback from psfb.cc. The new src/RtcpRemb.cpp starts with both files' notices. remb.cc and remb.h are byte-identical at M127 (e0b28a6a).

  • Layout: a GCC 15 class-layout dump of the real M134 remb.h, psfb.h and rtcp_packet.h gives a 48-byte object: the vtable pointer, sender and media SSRCs at 8 and 12, the 64-bit bitrate at 16, and the SSRC vector (begin/end/capacity) at 24.

  • Vector storage: the SSRC list is allocated and freed through guest operator new/operator delete (_Znwm_nid_postfix/_ZdlPv_nid_postfix), as CopyOnWriteBuffer does, so a guest destructor can free it.

  • Parse: follows upstream's release behaviour and write order:

    • a payload under 16 bytes, a missing REMB identifier, or a size that doesn't match the SSRC count returns false without changing the object;
    • the sender and media SSRCs are written first, then the bitrate (6-bit exponent, 18-bit mantissa);
    • if mantissa << exponent loses bits or is negative as a signed 64-bit value, it returns false, keeping the SSRCs and bitrate already written but leaving the vector untouched, as upstream does;
    • otherwise the vector is cleared and refilled, reallocating to exactly the SSRC count only when its capacity is too small, as clear() and reserve() do upstream. If that allocation fails, the vector is left empty with its old storage.

    RTC_DCHECKs and logging don't run in release builds, so they don't throw. A null object, header or payload that would be read throws.

  • Debt: the stub is removed, the libwebrtc unknown-export count drops from 188 to 187 (main's pending count minus one, set in the existing feat-libwebrtc-rnn-vad.md fragment that already changes that line), and a debt fragment (docs/dev/debt/changes/feat-libwebrtc-rtcp-remb-parse.md) adds an entry recording the layout and that the console's ABI is unverified.

Tested

  • New test: guest_webrtc_rtcp_remb (core/libs/prx/libwebrtc/tests/RtcpRemb.cpp) covers:
    • valid packets with zero, one and several SSRCs;
    • short payloads, a wrong identifier and mismatched lengths, each leaving the object unchanged;
    • bitrate overflow;
    • reuse of one object across parses, with the vector's contents replaced;
    • allocation failure, and every guest allocation freed.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release):
    • on main, the test fails with _ZN6webrtc4rtcp4Remb5ParseERKNS0_12CommonHeaderE_nid_postfix not implemented;
    • with this PR, guest_webrtc_rtcp_remb, guest_webrtc_rtcp_common_header, guest_webrtc_rtcp_pli and patched_libraries pass.
  • Windows 11 (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): all 54 guest_webrtc tests and patched_libraries pass at c8dcfe5501, with no compiler warnings in the changed files and no loader errors for the guest new/delete imports. The branch was then rebased onto current main: #17698 (rtcp::App) had added its source, include and test at the same insertion points, so both are kept, and the count was recounted. guest_webrtc_rtcp_remb and patched_libraries pass again on Linux.
  • Mutation check: swapping the sender and media SSRCs fails the test.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.
  • python3 tools/pr_overlap.py: no open PR implements this export.
    • #18507 shares registration and count lines.
    • It couldn't compare #14212, #17009, #17273, #17353, #18498 and #18503 automatically. I checked their diffs by hand: none implements Remb.
    • My #18796 (TransportFeedback), Nack and VideoSinkWants PRs share the count line. Whichever merges second recounts.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5275759986 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18798). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-12T10:32:04Z. --- ### What libwebrtc `webrtc::rtcp::Remb::Parse(const CommonHeader&)` (`_ZN6webrtc4rtcp4Remb5ParseERKNS0_12CommonHeaderE`, NID `QyR2ngto5ow`) threw `not implemented`. This PR ports it from M134 (8d78f5de) [`remb.cc`](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/modules/rtp_rtcp/source/rtcp_packet/remb.cc), with `ParseCommonFeedback` from [`psfb.cc`](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/modules/rtp_rtcp/source/rtcp_packet/psfb.cc). The new `src/RtcpRemb.cpp` starts with both files' notices. `remb.cc` and `remb.h` are byte-identical at M127 (e0b28a6a). - **Layout:** a GCC 15 class-layout dump of the real M134 `remb.h`, `psfb.h` and `rtcp_packet.h` gives a 48-byte object: the vtable pointer, sender and media SSRCs at 8 and 12, the 64-bit bitrate at 16, and the SSRC vector (begin/end/capacity) at 24. - **Vector storage:** the SSRC list is allocated and freed through guest `operator new`/`operator delete` (`_Znwm_nid_postfix`/`_ZdlPv_nid_postfix`), as `CopyOnWriteBuffer` does, so a guest destructor can free it. - **Parse:** follows upstream's release behaviour and write order: - a payload under 16 bytes, a missing `REMB` identifier, or a size that doesn't match the SSRC count returns false without changing the object; - the sender and media SSRCs are written first, then the bitrate (6-bit exponent, 18-bit mantissa); - if `mantissa << exponent` loses bits or is negative as a signed 64-bit value, it returns false, keeping the SSRCs and bitrate already written but leaving the vector untouched, as upstream does; - otherwise the vector is cleared and refilled, reallocating to exactly the SSRC count only when its capacity is too small, as `clear()` and `reserve()` do upstream. If that allocation fails, the vector is left empty with its old storage. `RTC_DCHECK`s and logging don't run in release builds, so they don't throw. A null object, header or payload that would be read throws. - **Debt:** the stub is removed, the libwebrtc unknown-export count drops from 188 to 187 (main's pending count minus one, set in the existing `feat-libwebrtc-rnn-vad.md` fragment that already changes that line), and a debt fragment (`docs/dev/debt/changes/feat-libwebrtc-rtcp-remb-parse.md`) adds an entry recording the layout and that the console's ABI is unverified. ### Tested - **New test:** `guest_webrtc_rtcp_remb` (`core/libs/prx/libwebrtc/tests/RtcpRemb.cpp`) covers: - valid packets with zero, one and several SSRCs; - short payloads, a wrong identifier and mismatched lengths, each leaving the object unchanged; - bitrate overflow; - reuse of one object across parses, with the vector's contents replaced; - allocation failure, and every guest allocation freed. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release): - on `main`, the test fails with `_ZN6webrtc4rtcp4Remb5ParseERKNS0_12CommonHeaderE_nid_postfix not implemented`; - with this PR, `guest_webrtc_rtcp_remb`, `guest_webrtc_rtcp_common_header`, `guest_webrtc_rtcp_pli` and `patched_libraries` pass. - **Windows 11** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): all 54 `guest_webrtc` tests and `patched_libraries` pass at c8dcfe5501, with no compiler warnings in the changed files and no loader errors for the guest `new`/`delete` imports. The branch was then rebased onto current `main`: #17698 (`rtcp::App`) had added its source, include and test at the same insertion points, so both are kept, and the count was recounted. `guest_webrtc_rtcp_remb` and `patched_libraries` pass again on Linux. - **Mutation check:** swapping the sender and media SSRCs fails the test. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - **`python3 tools/pr_overlap.py`:** no open PR implements this export. - #18507 shares registration and count lines. - It couldn't compare #14212, #17009, #17273, #17353, #18498 and #18503 automatically. I checked their diffs by hand: none implements `Remb`. - My #18796 (`TransportFeedback`), Nack and `VideoSinkWants` PRs share the count line. Whichever merges second recounts. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-12 12:00:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T12:00:17Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 8e80091923:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_webrtc_rtcp_remb_tests built cleanly.
  • CTest (guest_webrtc_rtcp_remb):
    1/1 Test #4748: guest_webrtc_rtcp_remb ...........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libwebrtc/Export.cpp, core/libs/prx/libwebrtc/include/Api.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libwebrtc/src/RtcpRemb.cpp: Verified null-pointer checks on remb, packet, and packet->payload, along with payloadSize bounds checking (payloadSize < 16 and payloadSize != 16 + count * 4) preventing buffer underflow or out-of-bounds reads.
    • core/libs/prx/libwebrtc/src/RtcpRemb.cpp: Verified big-endian unpacking for sender SSRC, media SSRC, REMB magic identifier (0x52454d42), 6-bit exponent, and 18-bit mantissa according to draft-alvestrand-rmcat-remb and RFC 4585.
    • core/libs/prx/libwebrtc/src/RtcpRemb.cpp: Verified bitrate arithmetic and overflow handling (mantissa << exponent with negative signed check and right-shift round-trip verification) ensuring well-defined C++20 shift semantics across all exponent ranges (0 to 63).
    • core/libs/prx/libwebrtc/src/RtcpRemb.cpp: Verified guest heap allocation and deallocation through _Znwm_nid_postfix and _ZdlPv_nid_postfix, confirming vector storage reuse when count <= capacity and exception-safe state preservation on bad_alloc.
    • core/libs/prx/libwebrtc/include/RtcpRemb.hpp: Verified struct WebRtcRtcpRemb member offsets and 48-byte size static_asserts across LP64 and LLP64 platforms.
    • docs/dev/debt/libwebrtc.md & AGENTS.md: Verified libwebrtc debt file update (unknown export count decremented from 249 to 248), technical debt entry additions, and zero comments rule compliance.
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5874094767 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18798#pullrequestreview-5874094767). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T12:00:17Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `8e80091923`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_webrtc_rtcp_remb_tests` built cleanly. - **CTest** (`guest_webrtc_rtcp_remb`): ``` 1/1 Test #4748: guest_webrtc_rtcp_remb ........... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libwebrtc/Export.cpp`, `core/libs/prx/libwebrtc/include/Api.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libwebrtc/src/RtcpRemb.cpp: Verified null-pointer checks on remb, packet, and packet->payload, along with payloadSize bounds checking (payloadSize < 16 and payloadSize != 16 + count * 4) preventing buffer underflow or out-of-bounds reads. - core/libs/prx/libwebrtc/src/RtcpRemb.cpp: Verified big-endian unpacking for sender SSRC, media SSRC, REMB magic identifier (0x52454d42), 6-bit exponent, and 18-bit mantissa according to draft-alvestrand-rmcat-remb and RFC 4585. - core/libs/prx/libwebrtc/src/RtcpRemb.cpp: Verified bitrate arithmetic and overflow handling (mantissa << exponent with negative signed check and right-shift round-trip verification) ensuring well-defined C++20 shift semantics across all exponent ranges (0 to 63). - core/libs/prx/libwebrtc/src/RtcpRemb.cpp: Verified guest heap allocation and deallocation through _Znwm_nid_postfix and _ZdlPv_nid_postfix, confirming vector storage reuse when count <= capacity and exception-safe state preservation on bad_alloc. - core/libs/prx/libwebrtc/include/RtcpRemb.hpp: Verified struct WebRtcRtcpRemb member offsets and 48-byte size static_asserts across LP64 and LLP64 platforms. - docs/dev/debt/libwebrtc.md & AGENTS.md: Verified libwebrtc debt file update (unknown export count decremented from 249 to 248), technical debt entry additions, and zero comments rule compliance. - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Looks Good To Me
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!18798
No description provided.