feat(libwebrtc): implement AudioDecoder::Decode and DecodeRedundant #16870

Merged
AlexWhitehouse merged 1 commit from upstream-pr/16870 into main 2026-11-11 16:08:08 +00:00
AlexWhitehouse commented 2026-11-07 19:28:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T19:28:00Z.


What

Two libwebrtc exports threw ..._nid_postfix not implemented:

  • webrtc::AudioDecoder::Decode (_ZN6webrtc12AudioDecoder6DecodeEPKhmimPsPNS0_10SpeechTypeE, NID NK438p2MZgA);
  • webrtc::AudioDecoder::DecodeRedundant (_ZN6webrtc12AudioDecoder15DecodeRedundantEPKhmimPsPNS0_10SpeechTypeE, NID ClTxsLU-OX4).

This PR implements them from audio_decoder.cc at M134 (8d78f5de), the revision the other libwebrtc ports cite. Both functions are the same at M127 (e0b28a6a). The new AudioDecoderDecode.cpp starts with that file's notice.

Each function calls the guest decoder's own virtual functions, as upstream does:

  1. It calls PacketDuration (PacketDurationRedundant for DecodeRedundant).
  2. If the duration is non-negative and duration * Channels() * sizeof(int16_t) > max_decoded_bytes, it returns -1. This uses upstream's int × size_t arithmetic, and Channels() is only called for a non-negative duration.
  3. Otherwise it returns DecodeInternal (DecodeRedundantInternal).

Other details:

  • Release behaviour: TRACE_EVENT0 and MsanCheckInitialized do nothing in release builds, so this PR doesn't reproduce them.
  • Virtual-function slots: the five virtuals are slots 8, 9, 12, 13 and 14 from the vtable's address point. They come from a GCC class-layout dump of audio_decoder.h at both milestones. Calls go through the guest's System V ABI (APS5_VABI) on every host.
  • Null pointers: a null decoder, vtable or slot throws, because upstream would call through null.

The libwebrtc unknown-export count drops from 300 to 298.

Tested

  • New tests: guest_webrtc_audio_decoder_decode and guest_webrtc_audio_decoder_decode_redundant (tests/AudioDecoderDecode.cpp). They use a fake guest vtable whose callbacks record their arguments and write recognisable samples and a speech type. They cover:
    • exact capacity and one byte short;
    • negative and zero durations;
    • one and several channels;
    • the arguments each callback receives;
    • that the decode callback's return value is passed back.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release):
    • on main, both fail with ..._nid_postfix not implemented;
    • with this PR, both pass, as does the existing guest_webrtc_audio_decoder (3/3).
  • Windows 11: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): all 37 libwebrtc tests pass at ed36d08d33, the two new ones included, with no compiler warnings in the changed files. The fake vtable's System V callbacks work under MinGW.
  • Mutation check: replacing the channel factor with 1 fails both tests.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.
  • python3 tools/pr_overlap.py --branch feat/libwebrtc-audio-decoder-decode: no open PR implements these exports.
    • #15609, my #16381 (RateTracker), my #16485 (CopyOnWriteBuffer) and my #16850 (SentPacket) share registration lines and the count line. Whichever merges second recounts.
    • #15271 changes the neighbouring ParseResult stubs and the existing AudioDecoder files, which this PR leaves alone.
    • The other libwebrtc PRs the tool couldn't compare (#14212, #15189, #15197, #15262-#15265, #15270, #15274-#15277) implement other exports.

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:5205106498 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16870). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-07T19:28:00Z. --- ### What Two libwebrtc exports threw `..._nid_postfix not implemented`: - `webrtc::AudioDecoder::Decode` (`_ZN6webrtc12AudioDecoder6DecodeEPKhmimPsPNS0_10SpeechTypeE`, NID `NK438p2MZgA`); - `webrtc::AudioDecoder::DecodeRedundant` (`_ZN6webrtc12AudioDecoder15DecodeRedundantEPKhmimPsPNS0_10SpeechTypeE`, NID `ClTxsLU-OX4`). This PR implements them from [`audio_decoder.cc`](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/audio_codecs/audio_decoder.cc) at M134 (8d78f5de), the revision the other libwebrtc ports cite. Both functions are the same at M127 (e0b28a6a). The new `AudioDecoderDecode.cpp` starts with that file's notice. Each function calls the guest decoder's own virtual functions, as upstream does: 1. It calls `PacketDuration` (`PacketDurationRedundant` for `DecodeRedundant`). 2. If the duration is non-negative and `duration * Channels() * sizeof(int16_t) > max_decoded_bytes`, it returns -1. This uses upstream's `int` × `size_t` arithmetic, and `Channels()` is only called for a non-negative duration. 3. Otherwise it returns `DecodeInternal` (`DecodeRedundantInternal`). Other details: - **Release behaviour:** `TRACE_EVENT0` and `MsanCheckInitialized` do nothing in release builds, so this PR doesn't reproduce them. - **Virtual-function slots:** the five virtuals are slots 8, 9, 12, 13 and 14 from the vtable's address point. They come from a GCC class-layout dump of `audio_decoder.h` at both milestones. Calls go through the guest's System V ABI (`APS5_VABI`) on every host. - **Null pointers:** a null decoder, vtable or slot throws, because upstream would call through null. The libwebrtc unknown-export count drops from 300 to 298. ### Tested - **New tests:** `guest_webrtc_audio_decoder_decode` and `guest_webrtc_audio_decoder_decode_redundant` (`tests/AudioDecoderDecode.cpp`). They use a fake guest vtable whose callbacks record their arguments and write recognisable samples and a speech type. They cover: - exact capacity and one byte short; - negative and zero durations; - one and several channels; - the arguments each callback receives; - that the decode callback's return value is passed back. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release): - on `main`, both fail with `..._nid_postfix not implemented`; - with this PR, both pass, as does the existing `guest_webrtc_audio_decoder` (3/3). - **Windows 11:** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): all 37 libwebrtc tests pass at ed36d08d33, the two new ones included, with no compiler warnings in the changed files. The fake vtable's System V callbacks work under MinGW. - **Mutation check:** replacing the channel factor with 1 fails both tests. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - **`python3 tools/pr_overlap.py --branch feat/libwebrtc-audio-decoder-decode`:** no open PR implements these exports. - #15609, my #16381 (RateTracker), my #16485 (CopyOnWriteBuffer) and my #16850 (SentPacket) share registration lines and the count line. Whichever merges second recounts. - #15271 changes the neighbouring `ParseResult` stubs and the existing `AudioDecoder` files, which this PR leaves alone. - The other libwebrtc PRs the tool couldn't compare (#14212, #15189, #15197, #15262-#15265, #15270, #15274-#15277) implement other exports. ### 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)
gabichuuuuu commented 2026-11-07 22:05:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T22:05:32Z.

Review: COMMENTED


Read ed36d08d33 against main.

Decode and DecodeRedundant match audio_decoder.cc at 8d78f5de: duration first, Channels() only for a non-negative duration, the same int/size_t capacity arithmetic, -1 on overflow and otherwise the *Internal result, with speech_type passed through untouched. Slots 8, 9, 12, 13 and 14 match the virtual order of audio_decoder.h at that revision. The tests would fail on main, including the one that leaves slot 12 null to prove Channels() is skipped for a negative duration.

Count line. main now lists 296 unknown exports, so docs/dev/debt/libwebrtc.md:5 should read 294 after the rebase, and the appended debt entry's context has moved too (main added a VideoFrame::Builder entry after FieldTrial); GitHub currently shows a conflict.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815214496 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16870#pullrequestreview-5815214496). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T22:05:32Z. **Review:** COMMENTED --- Read `ed36d08d33` against `main`. `Decode` and `DecodeRedundant` match `audio_decoder.cc` at `8d78f5de`: duration first, `Channels()` only for a non-negative duration, the same `int`/`size_t` capacity arithmetic, -1 on overflow and otherwise the `*Internal` result, with `speech_type` passed through untouched. Slots 8, 9, 12, 13 and 14 match the virtual order of `audio_decoder.h` at that revision. The tests would fail on `main`, including the one that leaves slot 12 null to prove `Channels()` is skipped for a negative duration. **Count line.** `main` now lists 296 unknown exports, so `docs/dev/debt/libwebrtc.md:5` should read 294 after the rebase, and the appended debt entry's context has moved too (`main` added a `VideoFrame::Builder` entry after `FieldTrial`); GitHub currently shows a conflict. Not run here; this is from reading the code. AI-assisted: yes.
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!16870
No description provided.