feat(libwebrtc): implement webrtc::AudioFrame::UpdateFrame and data_view #15196

Merged
alvaroelpob merged 5 commits from upstream-pr/15196 into main 2026-11-07 03:27:40 +00:00
alvaroelpob commented 2026-11-02 20:26:18 +00:00 (Migrated from github.com)

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


What

Implements webrtc::AudioFrame::UpdateFrame(uint32_t, const int16_t*, size_t, int, SpeechType, VADActivity, size_t) and AudioFrame::data_view() const in libwebrtc, which threw and were declared without parameters. Both use the WebRtcAudioFrame layout and zeroed buffer already on main.

The module's WebRTC revision lies between M127 and M134, as recorded in the debt file. Both functions in audio_frame.cc (M127, M134), and GuessChannelLayout in channel_layout.cc (M127, M134), are the same at both. They are added to src/AudioFrame.cpp, which already carries audio_frame.cc's notice and licence.

UpdateFrame:

  • Stores the timestamp, samples per channel, rate, speech type, VAD activity and channel count.
  • Guesses the channel layout: mono, stereo, surround, quad, 5.0, 5.1, 6.1 and 7.1 for 1 to 8 channels, otherwise unsupported.
  • Copies the samples and unmutes the frame, or mutes it for null data.
  • Throws, as upstream's RTC_CHECKs do, before setting any field when the frame has more than kMaxConcurrentChannels (8) channels, and after setting the fields when it has more than 7680 samples.

data_view returns the 32-byte InterleavedView<const int16_t> of audio_view.h: channels, samples per channel, then an ArrayView whose pointer is the zeroed buffer when muted, the frame's data otherwise, and null when the size is 0.

CopyFrom stays unimplemented: it copies packet_infos_, a reference to a guest object. A null frame 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.

  • Extended guest_webrtc_audio_frame test:
    • UpdateFrame with 480 stereo samples sets every field, copies exactly 960 samples and leaves the profiling fields; null data mutes the frame and keeps the samples.
    • 0 to 8 channels give the expected layouts.
    • 960 × 8 samples are accepted; 9 channels and 961 × 8 samples throw, as does a null frame.
    • data_view returns the data, the zeroed buffer when muted, and a null pointer when either count is 0.
  • Full ctest -j16 on head 86116773cd: 3595/3595 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 881e69af04, 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. Full build and ctest -j16: 3795/3799 pass; guest_sce_net, guest_poll, guest_select_wait and guest_memory failed under that load, pass when run alone, and main 4f41f4c375 passes all 3799 with -j16 on the same machine. 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:5126911373 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15196). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-11-02T20:26:18Z. --- ### What Implements `webrtc::AudioFrame::UpdateFrame(uint32_t, const int16_t*, size_t, int, SpeechType, VADActivity, size_t)` and `AudioFrame::data_view() const` in libwebrtc, which threw and were declared without parameters. Both use the `WebRtcAudioFrame` layout and zeroed buffer already on `main`. The module's WebRTC revision lies between M127 and M134, as recorded in the debt file. Both functions in `audio_frame.cc` ([M127](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/api/audio/audio_frame.cc), [M134](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/audio/audio_frame.cc)), and `GuessChannelLayout` in `channel_layout.cc` ([M127](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/api/audio/channel_layout.cc), [M134](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/audio/channel_layout.cc)), are the same at both. They are added to `src/AudioFrame.cpp`, which already carries `audio_frame.cc`'s notice and licence. `UpdateFrame`: - Stores the timestamp, samples per channel, rate, speech type, VAD activity and channel count. - Guesses the channel layout: mono, stereo, surround, quad, 5.0, 5.1, 6.1 and 7.1 for 1 to 8 channels, otherwise unsupported. - Copies the samples and unmutes the frame, or mutes it for null data. - Throws, as upstream's `RTC_CHECK`s do, before setting any field when the frame has more than `kMaxConcurrentChannels` (8) channels, and after setting the fields when it has more than 7680 samples. `data_view` returns the 32-byte `InterleavedView<const int16_t>` of `audio_view.h`: channels, samples per channel, then an `ArrayView` whose pointer is the zeroed buffer when muted, the frame's data otherwise, and null when the size is 0. `CopyFrom` stays unimplemented: it copies `packet_infos_`, a reference to a guest object. A null frame 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`. - Extended `guest_webrtc_audio_frame` test: - `UpdateFrame` with 480 stereo samples sets every field, copies exactly 960 samples and leaves the profiling fields; null data mutes the frame and keeps the samples. - 0 to 8 channels give the expected layouts. - 960 × 8 samples are accepted; 9 channels and 961 × 8 samples throw, as does a null frame. - `data_view` returns the data, the zeroed buffer when muted, and a null pointer when either count is 0. - Full `ctest -j16` on head 86116773cd: 3595/3595 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 881e69af04, 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`. Full build and `ctest -j16`: 3795/3799 pass; `guest_sce_net`, `guest_poll`, `guest_select_wait` and `guest_memory` failed under that load, pass when run alone, and `main` 4f41f4c375 passes all 3799 with `-j16` on the same machine. `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
XairRrR commented 2026-11-03 19:12:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T19:12:50Z.

Review: APPROVED


Reviewed — approved

webrtc::AudioFrame::UpdateFrame and data_view follow upstream audio_frame.cc and channel_layout.cc and fit the existing WebRtcAudioFrame layout. The extended test passes, and it fails against main's production files and against two behaviour mutations.

What I ran

Head 881e69af0446d93ca4cb1ab744cbbe4f4085c830, main 1e658521a0a599872612bb91949311e2956b5283, merged tree 3bd1c5cd0de5999702d74c9eacfb249aef4642ae.

git diff --check 1e658521a0a599872612bb91949311e2956b5283...881e69af0446d93ca4cb1ab744cbbe4f4085c830
python3 tools/check_conventions.py --base 1e658521a0a599872612bb91949311e2956b5283
ctest --test-dir build --output-on-failure -R '^guest_webrtc_audio_frame$'
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R 'public_headers|^guest_webrtc_audio_frame$'
# negative control and mutations (see below)
ninja -C build -j32 -l32 guest_webrtc_audio_frame_tests
ctest --test-dir build -R '^guest_webrtc_audio_frame$'

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Build (script, Release, GCC 14.2.0) ok
Script's selected tests (808) 806 passed, 1 expected skip, 1 known failure from main (unwrap_self_..._inherits_the_destination_directory_group); no new failures, no timeouts
guest_webrtc_audio_frame passed (0.01 s)
public_headers tests and guest_webrtc_audio_frame (66 tests) 66/66 passed
Debt counter Export.cpp has 289 NotImplemented_nid_no_patch(__func__) stubs on the merged tree and 291 on main. Adding the 60 NID-bound exports gives 349 (was 351), which matches the debt file
Vulkan validation not applicable (no AGC, shader or VideoOut change)

Negative control

  • I restored Export.cpp, include/Api.hpp, include/AudioFrame.hpp and src/AudioFrame.cpp from main. The test executable then does not compile: too many arguments to function ... UpdateFrame...(), and WebRtcChannelLayoutStereo was not declared.
  • On the merged tree, I removed the size == 0 ? nullptr : branch in data_view. The test aborts.
  • On the merged tree, I swapped the 7-channel and 8-channel layouts (6.1 and 7.1) in GuessChannelLayout. The test aborts.

After restoring the merged files and rebuilding, the test passes and git status --porcelain is empty.

Findings

I compared the code with upstream:

  • UpdateFrame: checks num_channels before storing anything, stores the fields, guesses the layout, checks the length against the buffer after storing the fields, then copies or mutes. This is the upstream order.
  • Layout enum values: match ChannelLayout (UNSUPPORTED 1, MONO 2, STEREO 3, SURROUND 5, QUAD 8, 5_0 9, 5_1 10, 7_1 14, 6_1 23).
  • data_view: reproduces InterleavedView{num_channels_, samples_per_channel_, ArrayView{data, size}}, including ArrayView's null pointer for size 0.
  • ABI: the 32-byte trivially copyable return goes through a hidden pointer with this in the second register, which the host prototype reproduces. UpdateFrame keeps its 8 arguments in SysV order: numChannels and vadActivity go on the stack.

Blocking

None.

Non-blocking

  1. Debt entry wording on when the channel check throws. docs/dev/debt/libwebrtc.md:24 says that more than 8 channels "or 7680 samples ... throw after the same fields are set". That is true for the sample-count check. The channel-count check at core/libs/prx/libwebrtc/src/AudioFrame.cpp:130-131 throws before any field is written, as upstream's first RTC_CHECK_LE does, and the test checks that numChannels stays 8. Suggested wording: "more than kMaxConcurrentChannels (8) channels throw before any field is set; more than 7680 samples throw after the fields are set."
  2. Description count is out of date. The description says the inventory drops from 352 to 350. After the rebase it drops from 351 to 349, and the debt file already says 349. Only the PR text needs updating.

Not verified

  • Behaviour on the console: the debt entry records this.
  • The Windows (MinGW) build and ABI: I only built and tested on Linux.
  • Any title using these exports.
  • The full test suite: per policy, only the selected tests ran.

I did not repeat the PR's own full ctest -j16 claims.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5758073630 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15196#pullrequestreview-5758073630). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T19:12:50Z. **Review:** APPROVED --- # Reviewed — approved `webrtc::AudioFrame::UpdateFrame` and `data_view` follow upstream `audio_frame.cc` and `channel_layout.cc` and fit the existing `WebRtcAudioFrame` layout. The extended test passes, and it fails against `main`'s production files and against two behaviour mutations. ## What I ran Head `881e69af0446d93ca4cb1ab744cbbe4f4085c830`, `main` `1e658521a0a599872612bb91949311e2956b5283`, merged tree `3bd1c5cd0de5999702d74c9eacfb249aef4642ae`. ``` git diff --check 1e658521a0a599872612bb91949311e2956b5283...881e69af0446d93ca4cb1ab744cbbe4f4085c830 python3 tools/check_conventions.py --base 1e658521a0a599872612bb91949311e2956b5283 ctest --test-dir build --output-on-failure -R '^guest_webrtc_audio_frame$' ctest --test-dir build -j8 --test-load 32 --output-on-failure -R 'public_headers|^guest_webrtc_audio_frame$' # negative control and mutations (see below) ninja -C build -j32 -l32 guest_webrtc_audio_frame_tests ctest --test-dir build -R '^guest_webrtc_audio_frame$' ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Build (script, Release, GCC 14.2.0) | ok | | Script's selected tests (808) | 806 passed, 1 expected skip, 1 known failure from `main` (`unwrap_self_..._inherits_the_destination_directory_group`); no new failures, no timeouts | | `guest_webrtc_audio_frame` | passed (0.01 s) | | `public_headers` tests and `guest_webrtc_audio_frame` (66 tests) | 66/66 passed | | Debt counter | `Export.cpp` has 289 `NotImplemented_nid_no_patch(__func__)` stubs on the merged tree and 291 on `main`. Adding the 60 NID-bound exports gives 349 (was 351), which matches the debt file | | Vulkan validation | not applicable (no AGC, shader or VideoOut change) | ## Negative control - I restored `Export.cpp`, `include/Api.hpp`, `include/AudioFrame.hpp` and `src/AudioFrame.cpp` from `main`. The test executable then does not compile: `too many arguments to function ... UpdateFrame...()`, and `WebRtcChannelLayoutStereo` was not declared. - On the merged tree, I removed the `size == 0 ? nullptr :` branch in `data_view`. The test aborts. - On the merged tree, I swapped the 7-channel and 8-channel layouts (6.1 and 7.1) in `GuessChannelLayout`. The test aborts. After restoring the merged files and rebuilding, the test passes and `git status --porcelain` is empty. ## Findings I compared the code with upstream: - **`UpdateFrame`:** checks `num_channels` before storing anything, stores the fields, guesses the layout, checks the length against the buffer after storing the fields, then copies or mutes. This is the upstream order. - **Layout enum values:** match `ChannelLayout` (UNSUPPORTED 1, MONO 2, STEREO 3, SURROUND 5, QUAD 8, 5_0 9, 5_1 10, 7_1 14, 6_1 23). - **`data_view`:** reproduces `InterleavedView{num_channels_, samples_per_channel_, ArrayView{data, size}}`, including `ArrayView`'s null pointer for size 0. - **ABI:** the 32-byte trivially copyable return goes through a hidden pointer with `this` in the second register, which the host prototype reproduces. `UpdateFrame` keeps its 8 arguments in SysV order: `numChannels` and `vadActivity` go on the stack. ### Blocking None. ### Non-blocking 1. **Debt entry wording on when the channel check throws.** `docs/dev/debt/libwebrtc.md:24` says that more than 8 channels "or 7680 samples ... throw after the same fields are set". That is true for the sample-count check. The channel-count check at `core/libs/prx/libwebrtc/src/AudioFrame.cpp:130-131` throws before any field is written, as upstream's first `RTC_CHECK_LE` does, and the test checks that `numChannels` stays 8. Suggested wording: "more than `kMaxConcurrentChannels` (8) channels throw before any field is set; more than 7680 samples throw after the fields are set." 2. **Description count is out of date.** The description says the inventory drops from 352 to 350. After the rebase it drops from 351 to 349, and the debt file already says 349. Only the PR text needs updating. ## Not verified - Behaviour on the console: the debt entry records this. - The Windows (MinGW) build and ABI: I only built and tested on Linux. - Any title using these exports. - The full test suite: per policy, only the selected tests ran. I did not repeat the PR's own full `ctest -j16` claims. <!-- anyps5-bots job=2494 head=881e69af0446d93ca4cb1ab744cbbe4f4085c830 -->
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!15196
No description provided.