feat(libwebrtc): implement AudioDecoderOpusImpl constructor and destructor #21347
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21347"
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 Zyylon on 2026-11-16T05:26:26Z.
What
Implement the M134 three-argument
webrtc::AudioDecoderOpusImplconstructor and destructor (_ZN6webrtc20AudioDecoderOpusImplC1ERKNS_15FieldTrialsViewEmi,_ZN6webrtc20AudioDecoderOpusImplD1Ev) inlibwebrtc:WebRtcAudioDecoderOpusImpllayout header (AudioDecoderOpusImpl.hpp) and updateApi.hppandExport.cpp.AudioDecoderOpusImpl.cpp(with verbatim WebRTC notices pinned to8d78f5de6c27b2c793039989ea381f1428fb0100), querying"WebRTC-Audio-OpusGeneratePlc"via guestFieldTrialsView::Lookup(slot 2), backing decoding/duration/FEC/PLC operations with3rdparty/opus, populating all 15AudioDecodervtable slots, boundingDecodeInternal/DecodeRedundantInternal/OpusFrame::Decodeto the validated expected duration and caller-provided sample capacity, and safely validating guest pointers/buffers withGuestPtr,GuestBytes, andGuestWritable_nid_no_patch.guest_webrtc_audio_decoder_opus_testscovering field trials (inline SSO & heap strings), lifecycle, packet duration/FEC estimation, stereo & mono-in-stereo decoding, DTX,Reset,GeneratePlc,ParsePayload/OpusFrame, undersized output/duration bounds, and invalid/guarded guest pointers.Tested
Windows 11 (
x86_64,gcc16.2.0,build/):libwebrtcandguest_webrtc_audio_decoder_opus_testsctest --test-dir build -R "^guest_webrtc_audio_decoder_opus$" --repeat until-fail:5 -V(5/5 passed)ctest --test-dir build -R "^(guest_webrtc_audio_decoder(_decode)?|guest_webrtc_opus)$" -V(3/3 passed)tools/guest_pointer_audit.py --json libwebrtcreports 0 findings inAudioDecoderOpusImpl.cpptools/debt_fold.py --check,tools/check_test_registration.py, andtools/check_conventions.py --base origin/mainChecklist
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 PrivacyOnion on 2026-11-16T05:28:53Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
abee73af88:tools/check_conventions.pypassed;git diff --checkclean.guest_webrtc_audio_decoder_opus_testsbuilt cleanly.guest_webrtc_audio_decoder_opus):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T05:35:00Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent decoded samples from being copied beyond the caller-provided output capacity.
What I ran
abee73af887c1c518b622537060fbf75e8e19135; no commands or tests were run in this review.included: true:core/libs/prx/libwebrtc/CMakeLists.txt,core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/include/AudioDecoderOpusImpl.hpp,core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp,core/libs/prx/libwebrtc/tests/AudioDecoderOpusImpl.cpp, anddocs/dev/debt/changes/feat-libwebrtc-audio-decoder-opus.md.Results
Findings
Blocking
core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp:591: The decoder vtable's internalDecodecallback receives no output capacity, and this implementation writes the decoded frame size returned by Opus directly todecoded. The baseAudioDecoder::Decodechecks the packet duration againstmaxDecodedBytesbefore invoking the callback, but the changed callback also needs to ensure its actual output fits: malformed or mismatched packet duration can make Opus return more samples than the advertised duration. As written, the callback can overwrite the caller's output buffer. Carry the validated capacity into a safe decode path or otherwise bound the output copy to the caller's provided storage.Non-blocking
None.
Not verified
To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T06:45:36Z.
Review: COMMENTED
Reviewed — no blocking findings
The review folder and repository reader are not accessible through the available tools, so the change could not be inspected and a review verdict is not justified.
What I ran
Not run. No reader command or file-reading tool is available in this session.
Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
The description, commits, diff, manifest, changed files, and relevant repository context were not read. No tests were run.
To get this to a good state
Provide access to the review folder and reader so the change can be reviewed.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T11:57:50Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make
GeneratePlcappend the requested per-channel PCM as interleaved samples for stereo decoders.What I ran
Reviewed head
9445e63d94b2cfa3cacc57dfde231b6094f22a3fusing the pinnedrepo_read.pyreader tools. No build or tests were run. Read all changed files:core/libs/prx/libwebrtc/CMakeLists.txt,core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/include/AudioDecoderOpusImpl.hpp,core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp,core/libs/prx/libwebrtc/tests/AudioDecoderOpusImpl.cpp, anddocs/dev/debt/changes/feat-libwebrtc-audio-decoder-opus.md. No changed files were excluded byfiles.json.Results
Findings
Blocking
core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp:561uses Opus's per-channel return count as the number of interleaved samples to append. For a stereo decoder,OpusDecodewritesret * 2samples, but this code advances the buffer by onlyret; it therefore appends only half of the generated PCM and reports an undersized buffer. Scale the append count byhost.channels(and use that count for buffer sizing and copying). The stereo test currently asserts the incorrect count atcore/libs/prx/libwebrtc/tests/AudioDecoderOpusImpl.cpp:265.Non-blocking
None.
Sources
GeneratePlcparameter is namedrequestedSamplesPerChannelincore/libs/prx/libwebrtc/include/Api.hpp:312;DecodeInternalImplalso scales the returned per-channel count by the channel count before reporting decoded samples (core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp:511).Not verified
To get this to a good state
GeneratePlc, and update the stereo assertion to cover that count. Rerun the decoder test and the reported related checks on the new head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T12:32:54Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix the stereo decode sample count and make
ParsePayloadpreserve ownership on allocation failures.What I ran
Reviewed head
718923d16abd8b3668b927e0a920da1f386f7651against basemainfrom the prepared diff and pinned reader. No commands or tests were run; the Windows build and test results in the PR description are author-reported.Results
Findings
Blocking
core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp:511: Opus returns samples per channel, but this multiplies the return by channel count while leaving theAudioDecoder::Decodecontract and the call toOpusFrame::Decodemeasured in samples per channel. For a 960-sample stereo frame this returns 1920, causingOpusFrame::Decodeto reject a valid result when given a 960-sample output capacity; the existing test instead passes 1920. Keep the callback return in samples per channel and apply channel scaling only to buffer sizing/copying as required by the ABI.core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp:461: After creating the FEC frame, later failures while creating the primary frame or allocating/writing the result vector leave the FEC frame and its payload unowned. In the primary-frame allocation failure case, the original payload also remains owned by neither the input buffer (which has not yet been cleared) nor an output frame if creation partially succeeds. Add cleanup for all constructed frames and ensure input ownership transfers only after result construction succeeds.Non-blocking
None.
Not verified
core/libs/prx/libwebrtc/CMakeLists.txt,core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/include/AudioDecoderOpusImpl.hpp,core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp,core/libs/prx/libwebrtc/tests/AudioDecoderOpusImpl.cpp, anddocs/dev/debt/changes/feat-libwebrtc-audio-decoder-opus.md.To get this to a good state
Fix both blocking findings, then rerun the reported Windows build and decoder tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T12:52:04Z.
Review: COMMENTED
Reviewed — no blocking findings
The source review found no verified blocking defect at head
19154ac5cd56ef9df08978eba0e7aafb9869f20d; no build or test command was run in this review.What I ran
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libwebrtc/CMakeLists.txt,core/libs/prx/libwebrtc/Export.cppdiff,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/include/AudioDecoderOpusImpl.hpp,core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp,core/libs/prx/libwebrtc/tests/AudioDecoderOpusImpl.cpp, anddocs/dev/debt/changes/feat-libwebrtc-audio-decoder-opus.md.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T15:00:02Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent the decoder from writing past the caller-provided output capacity.
What I ran
Reviewed head
3be171fed4288967d1eb54c8581bfe1d0f1de731usingrepo_read.pyto inspect the prepared diff and targeted source ranges. No build or tests were run by me; the test results in the description are author-reported.Results
Findings
Blocking
core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp:508:DecodeInternalImplderives the writable range from the packet’s expected duration, but its ABI receives no output capacity. This check therefore assumes the caller allocated at least that many samples. A caller with a smaller buffer can pass the check and then be overrun byGuestBytes(decoded).CopyOutat line 522. Ensure the capacity is supplied and checked before decoding/copying, or otherwise make the API’s output size contract enforceable.Non-blocking
None.
Not verified
To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T06:26:03Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: fix the
ParsePayloadfailure cleanup so it releases the primary frame’s payload allocation.What I ran
Reviewed head
28158e021441fa5a036f1e2b8fe06abd74eeb942. No build or tests were run here. The reported Windows 11 test and audit results are author supplied.Results
Findings
Blocking
ParsePayloadexception handler,primaryFrameis freed withoperator deletewithout calling its destructor. Its destructor frees the payload allocation it owns, so a failure after frame creation leaks that payload. The allocation-failure test exercises later allocation failures but checks only that allocations are empty after freeing the original payload, which can hide a leaked copy in the FEC path. Run the primary frame destructor before freeing the frame object (or otherwise release its owned payload) in the catch path. (core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp:478)Non-blocking
None.
Not verified
Files read:
core/libs/prx/libwebrtc/CMakeLists.txt,core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/include/AudioDecoderOpusImpl.hpp,core/libs/prx/libwebrtc/src/AudioDecoderOpusImpl.cpp,core/libs/prx/libwebrtc/tests/AudioDecoderOpusImpl.cpp,docs/dev/debt/changes/feat-libwebrtc-audio-decoder-opus.md, pluscore/libs/prx/libwebrtc/include/AudioDecoder.hpp,core/libs/prx/libwebrtc/src/AudioDecoder.cpp,core/libs/prx/libwebrtc/src/AudioDecoderDecode.cpp, andcore/libs/prx/libwebrtc/src/Opus.cppfor context. All seven changed files listed in the manifest were read; no changed file was excluded.To get this to a good state
Call
OpusFrameD1_nid_no_patch(primaryFrame)before freeingprimaryFramein the failure cleanup, then rerun the allocation-failure tests and verify that both owned payloads are released.