feat(libwebrtc): implement the webrtc::AudioEncoder default methods and ANAStats #14120
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14120"
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:39:27Z.
What
Implements the
webrtc::ANAStatsdefault constructor and thesewebrtc::AudioEncoderdefault methods in libwebrtc, which threw and were declared without parameters:GetANAStats()GetDtx()SetTargetBitrate(int)DisableAudioNetworkAdaptor()OnReceivedRtt(int)OnReceivedOverhead(size_t)SetReceiverFrameLengthRange(int, int)AudioEncoderis 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.ccare the same at M127 branch-heads/6533 and M134 branch-heads/6998, except that M134 comments out the unused parameter names.ANAStatsinaudio_encoder.hhas the same seven members at both; onlyabsl::optionalchanges tostd::optional. The abseil both revisions pin setsABSL_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.ccand live insrc/AudioEncoder.cpp, which starts with that file's WebRTC copyright notice and the BSD licence text from WebRTC'sLICENSE. The debt entry says it is adapted fromaudio_encoder.cc.WebRtcAnaStatsis the 56-byte struct of sixstd::optional<uint32_t>and onestd::optional<float>, each with the libc++ layout: the value, then the engaged flag at offset 4.static_asserts check it.charnull state.ANAStatshas a user-declared copy constructor and destructor, soGetANAStatsreturns it through the caller's result pointer (and returns that pointer). It fills that result with an emptyANAStats.GetDtxreturns false.SetTargetBitrate,DisableAudioNetworkAdaptor,OnReceivedRtt,OnReceivedOverheadandSetReceiverFrameLengthRangedo nothing.Upstream never reads the encoder in these methods, so it can be anything. Upstream writes through a null
ANAStatsor result, so those throw.The base methods that call other virtual methods (
OnReceivedTargetAudioBitrate,OnReceivedUplinkAllocation,Encode) need the vtable layout and are left throwing. So isOnReceivedUplinkRecoverablePacketLossFraction, which isRTC_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.guest_webrtc_audio_encodertest:ANAStatsfilled with 0x5A, the constructor andGetANAStatsclear each engaged flag and the first value byte and leave the other bytes untouched.GetANAStatsreturns the result pointer.GetDtxreturns false before and after the other defaults run, and no encoder byte changes.ANAStatsor result throwsstd::invalid_argument.ctest -j16on head 96b7dcf16d: 3036/3036 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, 8b8fa8824d): 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 (36331 on this head,
61d9e7d218). 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:01:01Z.
Review: COMMENTED
Verified the implementation and guest test coverage for
webrtc::AudioEncoderdefaults andANAStats:WebRtcAnaStats(56 bytes) accurately mirrors upstream WebRTC's sevenstd::optionalfields under libc++ representation (4-byte storage union + 1-byte engaged flag + 3 bytes padding per optional).sizeof(WebRtcAnaStats) == 56and the offset ofuplinkPacketLossFractionat 48.GetANAStatsconforms to the Itanium C++ ABI sret convention (result struct pointer passed in first register, returning pointer to caller-allocated memory).GetDtxreturns false by default as expected.SetTargetBitrate,DisableAudioNetworkAdaptor,OnReceivedRtt,OnReceivedOverhead,SetReceiverFrameLengthRange) leave the encoder instance untouched.Encode,OnReceivedUplinkAllocation,OnReceivedTargetAudioBitrate) remain throwing viaNotImplemented_nid_no_patch.ANAStatsconstructor andGetANAStatsresult throwstd::invalid_argument.tests/AudioEncoder.cppvalidates field clearance across prefilled memory, tests all no-op default methods, and checks that encoder storage remains unmodified.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: noneis allowed), and it contained no code review.