feat(libwebrtc): implement the webrtc::AudioEncoder default methods and ANAStats #14120

Merged
alvaroelpob merged 12 commits from upstream-pr/14120 into main 2026-11-02 19:46:16 +00:00
alvaroelpob commented 2026-10-31 19:39:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-31T19:39:27Z.


What

Implements the webrtc::ANAStats default constructor and these webrtc::AudioEncoder default methods in libwebrtc, which threw and were declared without parameters:

  • GetANAStats()
  • GetDtx()
  • SetTargetBitrate(int)
  • DisableAudioNetworkAdaptor()
  • OnReceivedRtt(int)
  • OnReceivedOverhead(size_t)
  • SetReceiverFrameLengthRange(int, int)

AudioEncoder is an abstract base class. An encoder a title derives from it gets these base implementations in its vtable unless it overrides them, so any call through the vtable reaches these exports.

The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. These methods in api/audio_codecs/audio_encoder.cc are the same at M127 branch-heads/6533 and M134 branch-heads/6998, except that M134 comments out the unused parameter names. ANAStats in audio_encoder.h has the same seven members at both; only absl::optional changes to std::optional. The abseil both revisions pin sets ABSL_OPTION_USE_STD_OPTIONAL 2, so in a C++17 or later build the two are the same type.

The functions are adapted from audio_encoder.cc and live in src/AudioEncoder.cpp, which starts with that file's WebRTC copyright notice and the BSD licence text from WebRTC's LICENSE. The debt entry says it is adapted from audio_encoder.cc.

WebRtcAnaStats is the 56-byte struct of six std::optional<uint32_t> and one std::optional<float>, each with the libc++ layout: the value, then the engaged flag at offset 4. static_asserts check it.

  • The constructor leaves every optional empty, as libc++'s default constructor does: it clears the engaged flag and value-initializes its char null state.
  • ANAStats has a user-declared copy constructor and destructor, so GetANAStats returns it through the caller's result pointer (and returns that pointer). It fills that result with an empty ANAStats.
  • GetDtx returns false. SetTargetBitrate, DisableAudioNetworkAdaptor, OnReceivedRtt, OnReceivedOverhead and SetReceiverFrameLengthRange do nothing.

Upstream never reads the encoder in these methods, so it can be anything. Upstream writes through a null ANAStats or result, so those throw.

The base methods that call other virtual methods (OnReceivedTargetAudioBitrate, OnReceivedUplinkAllocation, Encode) need the vtable layout and are left throwing. So is OnReceivedUplinkRecoverablePacketLossFraction, which is RTC_DCHECK_NOTREACHED. The inventory drops from 394 to 386.

Tested

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

  • New guest_webrtc_audio_encoder test:
    • On ANAStats filled with 0x5A, the constructor and GetANAStats clear each engaged flag and the first value byte and leave the other bytes untouched. GetANAStats returns the result pointer.
    • On an encoder filled with 0xC3, GetDtx returns false before and after the other defaults run, and no encoder byte changes.
    • A null ANAStats or result throws std::invalid_argument.
  • Full ctest -j16 on head 96b7dcf16d: 3036/3036 pass. check_conventions.py --base upstream/main passes. pr_overlap.py reports the open pull requests listed in Depends on.
  • Rebased onto main 1bc97b9527 after #13736 merged; the only conflicts were the include, CMake source and debt count lines. Full ctest -j16 on the top of the stack, #14148 head 0884de5716 (which contains this head, 8b8fa8824d): 3087/3087 pass. check_conventions.py --base upstream/main passes.
  • Rebased onto main dc9dc7eaae after #13764 and #13816 merged. The conflicts were the debt count line and, in the AudioDeviceGeneric commit, the Export.cpp stubs next to the removed VAD stubs; that commit keeps main's side and removes only its own seven stubs. The count is now set from the stubs left in Export.cpp plus the 60 bound by NID (363
    31 on this head, 61d9e7d218). Full ctest -j16 on the top of the stack, #14148 head 44e052f6dd: 3113/3113 pass. check_conventions.py --base upstream/main passes.
  • Not tested: Windows, a title.

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: #14087, #14095, #14116
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5100901478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14120). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-31T19:39:27Z. --- ### What Implements the `webrtc::ANAStats` default constructor and these `webrtc::AudioEncoder` default methods in libwebrtc, which threw and were declared without parameters: - `GetANAStats()` - `GetDtx()` - `SetTargetBitrate(int)` - `DisableAudioNetworkAdaptor()` - `OnReceivedRtt(int)` - `OnReceivedOverhead(size_t)` - `SetReceiverFrameLengthRange(int, int)` `AudioEncoder` is an abstract base class. An encoder a title derives from it gets these base implementations in its vtable unless it overrides them, so any call through the vtable reaches these exports. The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. These methods in `api/audio_codecs/audio_encoder.cc` are the same at [M127 branch-heads/6533](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/api/audio_codecs/audio_encoder.cc) and [M134 branch-heads/6998](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/audio_codecs/audio_encoder.cc), except that M134 comments out the unused parameter names. `ANAStats` in `audio_encoder.h` has the same seven members at both; only `absl::optional` changes to `std::optional`. The abseil both revisions pin sets [`ABSL_OPTION_USE_STD_OPTIONAL 2`](https://chromium.googlesource.com/chromium/src/third_party/+/d212a71416ad7c6ceca04d6d27dfdd84fd00c04c/abseil-cpp/absl/base/options.h#124), so in a C++17 or later build the two are the same type. The functions are adapted from `audio_encoder.cc` and live in `src/AudioEncoder.cpp`, which starts with that file's WebRTC copyright notice and the BSD licence text from WebRTC's `LICENSE`. The debt entry says it is adapted from `audio_encoder.cc`. `WebRtcAnaStats` is the 56-byte struct of six `std::optional<uint32_t>` and one `std::optional<float>`, each with the libc++ layout: the value, then the engaged flag at offset 4. `static_assert`s check it. - The constructor leaves every optional empty, as libc++'s default constructor does: it clears the engaged flag and value-initializes its `char` null state. - `ANAStats` has a user-declared copy constructor and destructor, so `GetANAStats` returns it through the caller's result pointer (and returns that pointer). It fills that result with an empty `ANAStats`. - `GetDtx` returns false. `SetTargetBitrate`, `DisableAudioNetworkAdaptor`, `OnReceivedRtt`, `OnReceivedOverhead` and `SetReceiverFrameLengthRange` do nothing. Upstream never reads the encoder in these methods, so it can be anything. Upstream writes through a null `ANAStats` or result, so those throw. The base methods that call other virtual methods (`OnReceivedTargetAudioBitrate`, `OnReceivedUplinkAllocation`, `Encode`) need the vtable layout and are left throwing. So is `OnReceivedUplinkRecoverablePacketLossFraction`, which is `RTC_DCHECK_NOTREACHED`. The inventory drops from 394 to 386. ### 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_audio_encoder` test: - On `ANAStats` filled with 0x5A, the constructor and `GetANAStats` clear each engaged flag and the first value byte and leave the other bytes untouched. `GetANAStats` returns the result pointer. - On an encoder filled with 0xC3, `GetDtx` returns false before and after the other defaults run, and no encoder byte changes. - A null `ANAStats` or result throws `std::invalid_argument`. - Full `ctest -j16` on head 96b7dcf16d: 3036/3036 pass. `check_conventions.py --base upstream/main` passes. `pr_overlap.py` reports the open pull requests listed in Depends on. - Rebased onto main 1bc97b9527 after #13736 merged; the only conflicts were the include, CMake source and debt count lines. Full `ctest -j16` on the top of the stack, #14148 head 0884de5716 (which contains this head, 8b8fa8824d): 3087/3087 pass. `check_conventions.py --base upstream/main` passes. - Rebased onto main dc9dc7eaae after #13764 and #13816 merged. The conflicts were the debt count line and, in the AudioDeviceGeneric commit, the `Export.cpp` stubs next to the removed VAD stubs; that commit keeps `main`'s side and removes only its own seven stubs. The count is now set from the stubs left in `Export.cpp` plus the 60 bound by NID (363 31 on this head, 61d9e7d218). Full `ctest -j16` on the top of the stack, #14148 head 44e052f6dd: 3113/3113 pass. `check_conventions.py --base upstream/main` passes. - Not tested: Windows, a title. ### 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: #14087, #14095, #14116 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
slopgobblercobbler commented 2026-10-31 20:01:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-31T20:01:01Z.

Review: COMMENTED


Verified the implementation and guest test coverage for webrtc::AudioEncoder defaults and ANAStats:

  • Struct ABI and layout:
    • WebRtcAnaStats (56 bytes) accurately mirrors upstream WebRTC's seven std::optional fields under libc++ representation (4-byte storage union + 1-byte engaged flag + 3 bytes padding per optional).
    • Static assertions verify sizeof(WebRtcAnaStats) == 56 and the offset of uplinkPacketLossFraction at 48.
  • Method ABI and return semantics:
    • GetANAStats conforms to the Itanium C++ ABI sret convention (result struct pointer passed in first register, returning pointer to caller-allocated memory).
    • GetDtx returns false by default as expected.
    • No-op defaults (SetTargetBitrate, DisableAudioNetworkAdaptor, OnReceivedRtt, OnReceivedOverhead, SetReceiverFrameLengthRange) leave the encoder instance untouched.
    • Methods requiring derived vtable dispatch (Encode, OnReceivedUplinkAllocation, OnReceivedTargetAudioBitrate) remain throwing via NotImplemented_nid_no_patch.
  • Validation and guest tests:
    • Null checks on ANAStats constructor and GetANAStats result throw std::invalid_argument.
    • tests/AudioEncoder.cpp validates field clearance across prefilled memory, tests all no-op default methods, and checks that encoder storage remains unmodified.
  • Conventions and debt:
    • Zero inline comments, debt entry under 1,000 characters leading with what is unmeasured. Conventions check passes cleanly with 0 findings.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5724703439 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14120#pullrequestreview-5724703439). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-31T20:01:01Z. **Review:** COMMENTED --- Verified the implementation and guest test coverage for `webrtc::AudioEncoder` defaults and `ANAStats`: - Struct ABI and layout: - `WebRtcAnaStats` (56 bytes) accurately mirrors upstream WebRTC's seven `std::optional` fields under libc++ representation (4-byte storage union + 1-byte engaged flag + 3 bytes padding per optional). - Static assertions verify `sizeof(WebRtcAnaStats) == 56` and the offset of `uplinkPacketLossFraction` at 48. - Method ABI and return semantics: - `GetANAStats` conforms to the Itanium C++ ABI sret convention (result struct pointer passed in first register, returning pointer to caller-allocated memory). - `GetDtx` returns false by default as expected. - No-op defaults (`SetTargetBitrate`, `DisableAudioNetworkAdaptor`, `OnReceivedRtt`, `OnReceivedOverhead`, `SetReceiverFrameLengthRange`) leave the encoder instance untouched. - Methods requiring derived vtable dispatch (`Encode`, `OnReceivedUplinkAllocation`, `OnReceivedTargetAudioBitrate`) remain throwing via `NotImplemented_nid_no_patch`. - Validation and guest tests: - Null checks on `ANAStats` constructor and `GetANAStats` result throw `std::invalid_argument`. - `tests/AudioEncoder.cpp` validates field clearance across prefilled memory, tests all no-op default methods, and checks that encoder storage remains unmodified. - Conventions and debt: - Zero inline comments, debt entry under 1,000 characters leading with what is unmeasured. Conventions check passes cleanly with 0 findings.
CnRJay commented 2026-11-01 19:49:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:24Z.

Review: COMMENTED


Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (Unblocks: none is allowed), and it contained no code review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729922148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14120#pullrequestreview-5729922148). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:49:24Z. **Review:** COMMENTED --- Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (`Unblocks: none` is allowed), and it contained no code review.
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!14120
No description provided.