feat(libwebrtc): implement the WebRtcOpus encoder functions #13736
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13736"
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 2Swagger on 2026-10-31T03:23:08Z.
Stacked on #13692 (which includes #13687 and #13689): this diff includes their commits until they merge. This PR's own change is commit 9b9f9bca7.
What
Implements the 16
WebRtcOpus_*encoder exports of libwebrtc, which threw and were declared without parameters:EncoderCreate,EncoderFree,Encode,SetBitRate,SetPacketLossRate,SetMaxPlaybackRate,EnableFec/DisableFec,EnableDtx/DisableDtx,EnableCbr/DisableCbr,SetComplexity,GetBandwidth,SetBandwidthandSetForceChannels.They are adapted from WebRTC's
opus_interface.ccand encode through the libopus the repo already builds (3rdparty/opus, linked likelibSceOpusCeltEnc). #13687 places the module between M127 (branch-heads/6533) and M134 (branch-heads/6998); I compared both ends:opus_interface.hare identical at both revisions;include/Api.hppnow carries them, with the opaqueWebRtcOpusEncInstfrominclude/Opus.hpp.EncoderCreateandEncodediffer only in M127'sWebRTC-Audio-OpusAvoidNoisePumpingDuringDtxfield trial, which rewrites high-energy refresh DTX packets. Field trials are off unlesswebrtc::field_trial::InitFieldTrialsFromStringturns them on, and that export still throws here, so both ends behave the same.OPUS_APPLICATION_VOIP/AUDIOand returns -1 for anything else or for a libopus error;Encodereturns -1 for a libopus error, returns the first packet of 2 bytes or less and then 0 while the encoder stays in DTX, as upstream does; the setters forward toopus_encoder_ctl(SET_BITRATE,SET_PACKET_LOSS_PERC,SET_MAX_BANDWIDTHfrom the Hz thresholds,SET_INBAND_FEC,SET_DTX,SET_VBR,SET_COMPLEXITY,SET_BANDWIDTH,SET_FORCE_CHANNELS) and return its result; every function returns -1 for a null encoder, as upstream does.WEBRTC_OPUS_SUPPORT_120MS_PTIME, which is unknown for this module (over 120 ms returns -1 in both builds); and, as a host-side check, a null encoder or buffer inEncode, which upstream reads.src/Opus.cppstarts with the WebRTC copyright notice ofopus_interface.ccand the full BSDLICENSEtext, both verbatim from 8d78f5de6c (identical at e0b28a6a81), in the same format as #13689'ssrc/ExpFilter.cppand #13692'ssrc/RtcpCommonHeader.cpp. Opus.cpp adapts about 100 lines of WebRTC's opus_interface.cc wrapper (with its notice and BSD licence verbatim), the same way #13088 adapted LibreSSL's stack.c; libopus itself is the existing 3rdparty/opus submodule. The debt file records the source, the field-trial reasoning, the 60/120 ms gap and the libopus difference, and the inventory drops from 408 to 392.Tested
guest_webrtc_opus, through the bundled libopus:opus_decode, and after the codec delay the output correlates above 0.9 with the input at a gain between 0.7 and 1.3.SetForceChannels(1)makes a stereo encoder emit mono packets and0brings stereo back, while 3 returns -1; with DTX on, silence returns one packet of 2 bytes or less, then 0 while silent, and noise brings packets back;SetMaxPlaybackRate(8000)gives narrowband andSetBandwidthwideband, asGetBandwidthreports; FEC with 20 % expected loss adds LBRR data, and afterDisableFecit is gone.OPUS_BAD_ARG;Encodereturns -1 above 120 ms, for an invalid frame size and for a zero-length buffer, and encodes a 60 ms frame. Under 0.2 s.SetForceChannelsignoring its argument, the 8 kHz cap mapped to wideband) fails the test. With the previous throwing stubs the test does not build, since they had no parameters.42087bf11, merged ontomain014c19ab19. Windows 11 (WinLibs GCC 15.2.0, Release):guest_webrtc_opus, the chain'sguest_webrtc_fast_int_to_buffer,guest_webrtc_exp_filterandguest_webrtc_rtcp_common_header, andpublic_headerswith its compile batches pass, 69 of 69. Linux (Ubuntu 24.04 under WSL2, GCC 13.3.0, Release): the same set, 69 of 69.guest_webrtc_opuspassed 20 consecutive runs on both platforms (ctest --repeat until-fail:20).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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T03:46:24Z.
Review: APPROVED
Reviewed — looks good
I reviewed head
9b9f9bca74e3d8fcddee4cd7e0361ac485665299; the encoder implementation, declared stack, and reported cross-platform tests show no blocking issue.What I ran
Reviewed head
9b9f9bca74e3d8fcddee4cd7e0361ac485665299against PR base6475267b456de6a0a23b230aa751f0b917d12688; the stack preview also checked currentmainde824c2919ca65086c6324a1e0388866a7327eeaand merged cleanly. No local build or C++ test was run. Environment: Linux x86_64, GCC 12.2.0, Python 3.11.2.Results
main.WebRtcOpus_*declarations have one matching definition; no findings for those symbols. The audit reports unrelated explicit-NID alias warnings elsewhere in libwebrtc.add_test; this is a heuristic false positive.libwebrtc.prx; its log did not showguest_webrtc_opusexecuting.guest_webrtc_opusreportedly passed 20 consecutive runs on both. The author also reports four deliberate test mutations failed as expected.Unedited outputs from focused checks
Findings
Blocking: None found.
Non-blocking: Frames over 60 ms and up to 120 ms intentionally throw because the module's
WEBRTC_OPUS_SUPPORT_120MS_PTIMEsetting is unknown; this limitation is documented in the PR's debt entry. The implementation uses the repository's bundled libopus 1.6.1, so byte-for-byte output parity with WebRTC's pinned libopus is not claimed.Sources
Not verified
I did not independently compile or execute tests. Linux CI was skipped; the Linux and Windows focused runs and negative controls above are author-reported. No console or title behavior was tested.