feat(libwebrtc): implement the webrtc::AudioFrame constructor, mute state and data accessors #14116

Merged
alvaroelpob merged 9 commits from upstream-pr/14116 into main 2026-11-02 19:46:09 +00:00
alvaroelpob commented 2026-10-31 19:31:22 +00:00 (Migrated from github.com)

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


What

Implements the webrtc::AudioFrame default constructor, Mute(), muted(), data() and mutable_data(), and webrtc::AudioFrameOperations::Mute(AudioFrame*) in libwebrtc, which threw and were declared without parameters. Titles construct AudioFrame through the exported constructor, so it is needed before any other AudioFrame export can be used.

The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. These functions in api/audio/audio_frame.cc and audio/utility/audio_frame_operations.cc are the same at M127 branch-heads/6533 and M134 branch-heads/6998. The members of audio_frame.h are the same at both, except that absolute_capture_timestamp_ms_ changes from absl::optional<int64_t> to std::optional<int64_t>. The abseil both revisions pin sets ABSL_OPTION_USE_STD_OPTIONAL 2, so in a C++17 or later build absl::optional is std::optional and the layout is the same.

The functions are adapted from those two files and live in src/AudioFrame.cpp and src/AudioFrameOperations.cpp. Each starts with its source file's WebRTC copyright notice and the BSD licence text from WebRTC's LICENSE. The debt entry says they are adapted from them.

WebRtcAudioFrame is the 15456-byte layout of audio_frame.h, checked by static_asserts on every member. It has the 7680-sample data_ at 72, muted_ at 15432, channel_layout_ at 15436, and libc++'s std::optional<int64_t> (value, then the engaged flag) at 15440.

  • The constructor stores the member defaults of audio_frame.h:

    • timestamp 0, elapsed and NTP times -1, no samples, rate or channels;
    • kUndefined (4) and kVadUnknown (2);
    • profile timestamp 0, empty packet_infos_;
    • muted, CHANNEL_LAYOUT_NONE, and no absolute capture timestamp.

    As upstream, it leaves the samples uninitialized.

  • Mute() sets muted_; muted() returns it.

  • data() returns a shared zeroed buffer of 7680 samples while muted, and data_ otherwise.

  • mutable_data() clears all 7680 samples and the muted flag if the frame is muted, then returns data_.

  • AudioFrameOperations::Mute(frame) is Mute(frame, true, true) upstream, which mutes the frame. Its only other effect is an RTC_DCHECK_GE that the frame holds at most 7680 samples. Whether the console build has RTC_DCHECKs is not known, so more than 7680 samples throws through NotImplemented_nid_no_patch without muting.

Upstream dereferences a null frame, so each function throws for one. The inventory drops from 400 to 394.

Tested

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

  • New guest_webrtc_audio_frame test, on frames filled with 0x5A:
    • The constructor stores every default above and leaves the samples untouched.
    • A muted frame's data() is a separate all-zero buffer. mutable_data() zeroes all 7680 samples, unmutes and returns data_; on an unmuted frame it keeps the samples.
    • Mute() keeps the samples, data() then reads zeros, and the next mutable_data() clears them.
    • AudioFrameOperations::Mute mutes 480 × 2 and 960 × 8 samples and a frame with 0 channels, without changing the samples or sizes. 961 × 8 samples throws the not-implemented error and leaves the frame unmuted.
    • A null frame throws std::invalid_argument in each function.
  • Full ctest -j16 on head 3f2625b69b: 3035/3035 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, cbaba7e8ed): 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 (371
    31 on this head, 5a828570a0). 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5100836808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14116). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-31T19:31:22Z. --- ### What Implements the `webrtc::AudioFrame` default constructor, `Mute()`, `muted()`, `data()` and `mutable_data()`, and `webrtc::AudioFrameOperations::Mute(AudioFrame*)` in libwebrtc, which threw and were declared without parameters. Titles construct `AudioFrame` through the exported constructor, so it is needed before any other `AudioFrame` export can be used. The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. These functions in `api/audio/audio_frame.cc` and `audio/utility/audio_frame_operations.cc` are the same at [M127 branch-heads/6533](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/api/audio/audio_frame.cc) and [M134 branch-heads/6998](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/audio/audio_frame.cc). The members of `audio_frame.h` are the same at both, except that `absolute_capture_timestamp_ms_` changes from `absl::optional<int64_t>` to `std::optional<int64_t>`. 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 `absl::optional` is `std::optional` and the layout is the same. The functions are adapted from those two files and live in `src/AudioFrame.cpp` and `src/AudioFrameOperations.cpp`. Each starts with its source file's WebRTC copyright notice and the BSD licence text from WebRTC's `LICENSE`. The debt entry says they are adapted from them. `WebRtcAudioFrame` is the 15456-byte layout of `audio_frame.h`, checked by `static_assert`s on every member. It has the 7680-sample `data_` at 72, `muted_` at 15432, `channel_layout_` at 15436, and libc++'s `std::optional<int64_t>` (value, then the engaged flag) at 15440. - The constructor stores the member defaults of `audio_frame.h`: - timestamp 0, elapsed and NTP times -1, no samples, rate or channels; - `kUndefined` (4) and `kVadUnknown` (2); - profile timestamp 0, empty `packet_infos_`; - muted, `CHANNEL_LAYOUT_NONE`, and no absolute capture timestamp. As upstream, it leaves the samples uninitialized. - `Mute()` sets `muted_`; `muted()` returns it. - `data()` returns a shared zeroed buffer of 7680 samples while muted, and `data_` otherwise. - `mutable_data()` clears all 7680 samples and the muted flag if the frame is muted, then returns `data_`. - `AudioFrameOperations::Mute(frame)` is `Mute(frame, true, true)` upstream, which mutes the frame. Its only other effect is an `RTC_DCHECK_GE` that the frame holds at most 7680 samples. Whether the console build has `RTC_DCHECK`s is not known, so more than 7680 samples throws through `NotImplemented_nid_no_patch` without muting. Upstream dereferences a null frame, so each function throws for one. The inventory drops from 400 to 394. ### 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_frame` test, on frames filled with 0x5A: - The constructor stores every default above and leaves the samples untouched. - A muted frame's `data()` is a separate all-zero buffer. `mutable_data()` zeroes all 7680 samples, unmutes and returns `data_`; on an unmuted frame it keeps the samples. - `Mute()` keeps the samples, `data()` then reads zeros, and the next `mutable_data()` clears them. - `AudioFrameOperations::Mute` mutes 480 × 2 and 960 × 8 samples and a frame with 0 channels, without changing the samples or sizes. 961 × 8 samples throws the not-implemented error and leaves the frame unmuted. - A null frame throws `std::invalid_argument` in each function. - Full `ctest -j16` on head 3f2625b69b: 3035/3035 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, cbaba7e8ed): 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 (371 31 on this head, 5a828570a0). 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
slopgobblercobbler commented 2026-10-31 20:00:52 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Verified the implementation and guest test coverage for webrtc::AudioFrame:

  • Struct ABI: 15456-byte layout matches upstream WebRTC M127-M134 and libc++ optional packing. The offset static assertions (data at 72, muted at 15432, channelLayout at 15436, absoluteCaptureTimestampMs at 15440) guarantee field alignment with guest code.
  • Data accessors and mute state:
    • AudioFrame::data() correctly returns a pointer to ZeroedData when muted is set, avoiding data corruption and unneeded zeroing loops on read.
    • AudioFrame::mutable_data() lazily zero-initializes data and unsets muted only when called on a muted frame, matching upstream WebRTC semantics.
    • AudioFrame::Mute() sets muted to true without modifying existing buffer contents.
  • Bounds and validation:
    • AudioFrameOperations::Mute() guards against channel buffer overflow using samplesPerChannel > WebRtcAudioFrameMaxDataSizeSamples / numChannels while correctly handling numChannels == 0. Out-of-bounds frames throw NotImplemented_nid_no_patch without altering frame state.
    • Null pointer guards consistently throw std::invalid_argument.
  • Guest tests:
    • tests/AudioFrame.cpp validates constructor defaults, lazy zeroing in mutable_data, unmuted data persistence across Mute(), boundary edge cases (8 channels x 960/961 samples), and null arguments.
  • Technical debt documentation:
    • Debt entry in docs/dev/debt/libwebrtc.md is under 1,000 characters and leads with what is unmeasured. Conventions check passes cleanly with 0 findings.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5724702532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14116#pullrequestreview-5724702532). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-31T20:00:52Z. **Review:** COMMENTED --- Verified the implementation and guest test coverage for `webrtc::AudioFrame`: - Struct ABI: 15456-byte layout matches upstream WebRTC M127-M134 and libc++ optional packing. The offset static assertions (`data` at 72, `muted` at 15432, `channelLayout` at 15436, `absoluteCaptureTimestampMs` at 15440) guarantee field alignment with guest code. - Data accessors and mute state: - `AudioFrame::data()` correctly returns a pointer to `ZeroedData` when `muted` is set, avoiding data corruption and unneeded zeroing loops on read. - `AudioFrame::mutable_data()` lazily zero-initializes `data` and unsets `muted` only when called on a muted frame, matching upstream WebRTC semantics. - `AudioFrame::Mute()` sets `muted` to true without modifying existing buffer contents. - Bounds and validation: - `AudioFrameOperations::Mute()` guards against channel buffer overflow using `samplesPerChannel > WebRtcAudioFrameMaxDataSizeSamples / numChannels` while correctly handling `numChannels == 0`. Out-of-bounds frames throw `NotImplemented_nid_no_patch` without altering frame state. - Null pointer guards consistently throw `std::invalid_argument`. - Guest tests: - `tests/AudioFrame.cpp` validates constructor defaults, lazy zeroing in `mutable_data`, unmuted data persistence across `Mute()`, boundary edge cases (8 channels x 960/961 samples), and null arguments. - Technical debt documentation: - Debt entry in `docs/dev/debt/libwebrtc.md` is under 1,000 characters and leads with what is unmeasured. Conventions check passes cleanly with 0 findings.
CnRJay commented 2026-11-01 19:49:23 +00:00 (Migrated from github.com)

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

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:5729922110 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14116#pullrequestreview-5729922110). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:49:23Z. **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!14116
No description provided.