feat(libwebrtc): implement the webrtc::AudioFrame constructor, mute state and data accessors #14116
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14116"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-31T19:31:22Z.
What
Implements the
webrtc::AudioFramedefault constructor,Mute(),muted(),data()andmutable_data(), andwebrtc::AudioFrameOperations::Mute(AudioFrame*)in libwebrtc, which threw and were declared without parameters. Titles constructAudioFramethrough the exported constructor, so it is needed before any otherAudioFrameexport 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.ccandaudio/utility/audio_frame_operations.ccare the same at M127 branch-heads/6533 and M134 branch-heads/6998. The members ofaudio_frame.hare the same at both, except thatabsolute_capture_timestamp_ms_changes fromabsl::optional<int64_t>tostd::optional<int64_t>. The abseil both revisions pin setsABSL_OPTION_USE_STD_OPTIONAL 2, so in a C++17 or later buildabsl::optionalisstd::optionaland the layout is the same.The functions are adapted from those two files and live in
src/AudioFrame.cppandsrc/AudioFrameOperations.cpp. Each starts with its source file's WebRTC copyright notice and the BSD licence text from WebRTC'sLICENSE. The debt entry says they are adapted from them.WebRtcAudioFrameis the 15456-byte layout ofaudio_frame.h, checked bystatic_asserts on every member. It has the 7680-sampledata_at 72,muted_at 15432,channel_layout_at 15436, and libc++'sstd::optional<int64_t>(value, then the engaged flag) at 15440.The constructor stores the member defaults of
audio_frame.h:kUndefined(4) andkVadUnknown(2);packet_infos_;CHANNEL_LAYOUT_NONE, and no absolute capture timestamp.As upstream, it leaves the samples uninitialized.
Mute()setsmuted_;muted()returns it.data()returns a shared zeroed buffer of 7680 samples while muted, anddata_otherwise.mutable_data()clears all 7680 samples and the muted flag if the frame is muted, then returnsdata_.AudioFrameOperations::Mute(frame)isMute(frame, true, true)upstream, which mutes the frame. Its only other effect is anRTC_DCHECK_GEthat the frame holds at most 7680 samples. Whether the console build hasRTC_DCHECKs is not known, so more than 7680 samples throws throughNotImplemented_nid_no_patchwithout 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.guest_webrtc_audio_frametest, on frames filled with 0x5A:data()is a separate all-zero buffer.mutable_data()zeroes all 7680 samples, unmutes and returnsdata_; on an unmuted frame it keeps the samples.Mute()keeps the samples,data()then reads zeros, and the nextmutable_data()clears them.AudioFrameOperations::Mutemutes 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.std::invalid_argumentin each function.ctest -j16on head 3f2625b69b: 3035/3035 pass.check_conventions.py --base upstream/mainpasses.pr_overlap.pyreports the open pull requests listed in Depends on.1bc97b9527after #13736 merged; the only conflicts were the include, CMake source and debt count lines. Fullctest -j16on the top of the stack, #14148 head 0884de5716 (which contains this head, cbaba7e8ed): 3087/3087 pass.check_conventions.py --base upstream/mainpasses.dc9dc7eaaeafter #13764 and #13816 merged. The conflicts were the debt count line and, in the AudioDeviceGeneric commit, theExport.cppstubs next to the removed VAD stubs; that commit keepsmain's side and removes only its own seven stubs. The count is now set from the stubs left inExport.cppplus the 60 bound by NID (37131 on this head,
5a828570a0). Fullctest -j16on the top of the stack, #14148 head44e052f6dd: 3113/3113 pass.check_conventions.py --base upstream/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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:dataat 72,mutedat 15432,channelLayoutat 15436,absoluteCaptureTimestampMsat 15440) guarantee field alignment with guest code.AudioFrame::data()correctly returns a pointer toZeroedDatawhenmutedis set, avoiding data corruption and unneeded zeroing loops on read.AudioFrame::mutable_data()lazily zero-initializesdataand unsetsmutedonly when called on a muted frame, matching upstream WebRTC semantics.AudioFrame::Mute()setsmutedto true without modifying existing buffer contents.AudioFrameOperations::Mute()guards against channel buffer overflow usingsamplesPerChannel > WebRtcAudioFrameMaxDataSizeSamples / numChannelswhile correctly handlingnumChannels == 0. Out-of-bounds frames throwNotImplemented_nid_no_patchwithout altering frame state.std::invalid_argument.tests/AudioFrame.cppvalidates constructor defaults, lazy zeroing inmutable_data, unmuted data persistence acrossMute(), boundary edge cases (8 channels x 960/961 samples), and null arguments.docs/dev/debt/libwebrtc.mdis under 1,000 characters and leads with what is unmeasured. Conventions check passes cleanly with 0 findings.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: noneis allowed), and it contained no code review.