feat(libwebrtc): implement the legacy VideoEncoder::InitEncode overload #17725

Merged
AlexWhitehouse merged 1 commit from upstream-pr/17725 into main 2026-11-12 04:54:49 +00:00
AlexWhitehouse commented 2026-11-09 13:04:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-09T13:04:47Z.


What

The legacy libwebrtc overload int webrtc::VideoEncoder::InitEncode(const VideoCodec*, int number_of_cores, size_t max_payload_size) (_ZN6webrtc12VideoEncoder10InitEncodeEPKNS_10VideoCodecEim, NID gra0DGtALJU) threw not implemented. This PR implements it from video_encoder.cc at M134 (8d78f5de). The forwarding is the same at M127 (e0b28a6a). The new VideoEncoderInitEncode.cpp starts with that file's notice.

As upstream does, the overload builds Settings(Capabilities(/*loss_notification=*/false), number_of_cores, max_payload_size), with no encoder thread limit. It then calls the encoder's own InitEncode(const VideoCodec*, const Settings&) and returns its result. The core count and payload size are passed through unchanged.

  • ABI: these were checked by compiling the real video_encoder.h at both milestones with GCC's class-layout dump and static_asserts. M127's pinned Abseil maps absl::optional to std::optional, so the layout is the same at both revisions.
    • The Settings overload is vtable slot 4 from the address point: after the two destructor entries, SetFecControllerOverride and the legacy overload itself.
    • Settings is 24 bytes: capabilities.loss_notification at 0, number_of_cores at 4, max_payload_size at 8, and optional<int> encoder_thread_limit at 16 (its engaged flag at 20).
  • Calling the guest: the Settings object is built in host memory with that layout, and the guest virtual is called through its System V ABI (APS5_VABI). A null encoder, vtable or slot throws.
  • Debt: the libwebrtc unknown-export count drops from 279 to 278, and a debt entry records that the console ABI is unverified. The existing VideoEncoder.cpp (SetFecControllerOverride) isn't touched.

Tested

  • New test: guest_webrtc_video_encoder_init_encode uses a synthetic guest vtable whose slot-4 callback records the receiver, the codec pointer and every Settings field, and returns a distinctive value. It covers:
    • core counts including 0 and negative values, which upstream passes through;
    • payload sizes above 2^32;
    • loss notification false and the thread limit disengaged;
    • the return value passed back;
    • the null throws.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release):
    • on main, it fails with _ZN6webrtc12VideoEncoder10InitEncodeEPKNS_10VideoCodecEim_nid_postfix not implemented;
    • with this PR, it passes, as do guest_webrtc_video_encoder and public_headers.
  • Windows 11: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): all 44 libwebrtc tests pass at 7b5eebd254, the new one included, with no compiler warnings in the changed files.
  • Mutation check: setting loss notification to true 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.

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:5224324273 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17725). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-09T13:04:47Z. --- ### What The legacy libwebrtc overload `int webrtc::VideoEncoder::InitEncode(const VideoCodec*, int number_of_cores, size_t max_payload_size)` (`_ZN6webrtc12VideoEncoder10InitEncodeEPKNS_10VideoCodecEim`, NID `gra0DGtALJU`) threw `not implemented`. This PR implements it from [`video_encoder.cc`](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/video_codecs/video_encoder.cc) at M134 (8d78f5de). The forwarding is the same at M127 (e0b28a6a). The new `VideoEncoderInitEncode.cpp` starts with that file's notice. As upstream does, the overload builds `Settings(Capabilities(/*loss_notification=*/false), number_of_cores, max_payload_size)`, with no encoder thread limit. It then calls the encoder's own `InitEncode(const VideoCodec*, const Settings&)` and returns its result. The core count and payload size are passed through unchanged. - **ABI:** these were checked by compiling the real `video_encoder.h` at both milestones with GCC's class-layout dump and `static_assert`s. M127's pinned Abseil maps `absl::optional` to `std::optional`, so the layout is the same at both revisions. - The `Settings` overload is vtable slot 4 from the address point: after the two destructor entries, `SetFecControllerOverride` and the legacy overload itself. - `Settings` is 24 bytes: `capabilities.loss_notification` at 0, `number_of_cores` at 4, `max_payload_size` at 8, and `optional<int> encoder_thread_limit` at 16 (its engaged flag at 20). - **Calling the guest:** the `Settings` object is built in host memory with that layout, and the guest virtual is called through its System V ABI (`APS5_VABI`). A null encoder, vtable or slot throws. - **Debt:** the libwebrtc unknown-export count drops from 279 to 278, and a debt entry records that the console ABI is unverified. The existing `VideoEncoder.cpp` (`SetFecControllerOverride`) isn't touched. ### Tested - **New test:** `guest_webrtc_video_encoder_init_encode` uses a synthetic guest vtable whose slot-4 callback records the receiver, the codec pointer and every `Settings` field, and returns a distinctive value. It covers: - core counts including 0 and negative values, which upstream passes through; - payload sizes above 2^32; - loss notification false and the thread limit disengaged; - the return value passed back; - the null throws. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release): - on `main`, it fails with `_ZN6webrtc12VideoEncoder10InitEncodeEPKNS_10VideoCodecEim_nid_postfix not implemented`; - with this PR, it passes, as do `guest_webrtc_video_encoder` and `public_headers`. - **Windows 11:** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): all 44 libwebrtc tests pass at 7b5eebd254, the new one included, with no compiler warnings in the changed files. - **Mutation check:** setting loss notification to true 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. - These share the count line, inventory lines, or include and CMake insertion points: #15609; my #16381, #16485, #16850, #16870 and #16893; and #17269, #17273, #17313, #17353, #17497, #17705 and #17707. Whichever merges second recounts. - #14212 (debt formatting) and #15189 (`ColorSpace`) couldn't be compared automatically. Neither touches `InitEncode`. ### 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)
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!17725
No description provided.