feat(libwebrtc): implement rtc::ExpFilter Reset and Apply #13689

Merged
alvaroelpob merged 6 commits from upstream-pr/13689 into main 2026-10-31 19:46:31 +00:00
alvaroelpob commented 2026-10-31 00:04:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-31T00:04:24Z.


What

Implements rtc::ExpFilter::Reset(float) and rtc::ExpFilter::Apply(float, float) in libwebrtc. Both threw and were declared without parameters.

The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. rtc_base/numerics/exp_filter.h and exp_filter.cc are the same at M127 branch-heads/6533 and M134 branch-heads/6998. From M135 the class moves to the webrtc namespace, which no longer matches the export names.

The two functions are adapted from exp_filter.cc and live in src/ExpFilter.cpp, which starts with that file's WebRTC copyright notice and the BSD licence text from WebRTC's LICENSE at the same revision. The debt entry says they are adapted from exp_filter.cc.

WebRtcExpFilter is the 12-byte layout from exp_filter.h (alpha_, filtered_, max_), checked with static_asserts. The two member functions take this as their first argument:

  • Reset stores alpha and sets the output to kValueUndefined (-1), leaving max_ alone.
  • Apply behaves like upstream. The first sample after an unset output becomes the output. An exponent of 1 uses alpha_ directly, and any other exponent uses pow(alpha_, exp). If max_ is set, the result is clamped to it.
  • As upstream, an output that lands on exactly -1 counts as unset, so the next sample restarts the filter.
  • Upstream dereferences the filter without checking it, so a null filter throws.

The debt file records the source and notes that the last bit of a result can differ if the console build fuses the multiply-adds. The inventory drops from 411 to 409.

Tested

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

  • New guest_webrtc_exp_filter test:
    • Reset sets alpha and the unset output and keeps max_.
    • With alpha 0.5, samples 4, 8 and 10 at exponents 1, 1 and 2 give 4, 6 and 9, and exponent 0.5 matches pow(alpha, 0.5).
    • An output of exactly -1 restarts the filter on the next sample.
    • A maximum of 5 clamps 9 to 5, then gives 3 and 4.
    • Null filters throw std::invalid_argument.
  • Full ctest -j16 on head 0155e95648: 3031/3031 pass. check_conventions.py --base upstream/main passes. pr_overlap.py reports no overlap with open pull requests.
  • 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5092666704 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13689). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-31T00:04:24Z. --- ### What Implements `rtc::ExpFilter::Reset(float)` and `rtc::ExpFilter::Apply(float, float)` in libwebrtc. Both threw and were declared without parameters. The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. `rtc_base/numerics/exp_filter.h` and `exp_filter.cc` are the same at [M127 branch-heads/6533](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/rtc_base/numerics/exp_filter.cc) and [M134 branch-heads/6998](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/numerics/exp_filter.cc). From M135 the class moves to the `webrtc` namespace, which no longer matches the export names. The two functions are adapted from `exp_filter.cc` and live in `src/ExpFilter.cpp`, which starts with that file's WebRTC copyright notice and the BSD licence text from WebRTC's `LICENSE` at the same revision. The debt entry says they are adapted from `exp_filter.cc`. `WebRtcExpFilter` is the 12-byte layout from `exp_filter.h` (`alpha_`, `filtered_`, `max_`), checked with `static_assert`s. The two member functions take `this` as their first argument: - `Reset` stores `alpha` and sets the output to `kValueUndefined` (-1), leaving `max_` alone. - `Apply` behaves like upstream. The first sample after an unset output becomes the output. An exponent of 1 uses `alpha_` directly, and any other exponent uses `pow(alpha_, exp)`. If `max_` is set, the result is clamped to it. - As upstream, an output that lands on exactly -1 counts as unset, so the next sample restarts the filter. - Upstream dereferences the filter without checking it, so a null filter throws. The debt file records the source and notes that the last bit of a result can differ if the console build fuses the multiply-adds. The inventory drops from 411 to 409. ### 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_exp_filter` test: - `Reset` sets alpha and the unset output and keeps `max_`. - With alpha 0.5, samples 4, 8 and 10 at exponents 1, 1 and 2 give 4, 6 and 9, and exponent 0.5 matches `pow(alpha, 0.5)`. - An output of exactly -1 restarts the filter on the next sample. - A maximum of 5 clamps 9 to 5, then gives 3 and 4. - Null filters throw `std::invalid_argument`. - Full `ctest -j16` on head 0155e95648: 3031/3031 pass. `check_conventions.py --base upstream/main` passes. `pr_overlap.py` reports no overlap with open pull requests. - 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-31 00:31:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T00:31:05Z.

Review: APPROVED


Reviewed — looks good

The ExpFilter implementation matches the pinned WebRTC logic for valid objects, and its declarations, test registration, and declared #13687 dependency are consistent.

What I ran

Reviewed head 8f63559455b61e103a370148dd46d2e469ae1fc8 against PR base f25279c0ca4cb068370df4baaa46de7b4f4741c7. The stack check previewed it cleanly against current main cbc30121bd6135d6ba8f50fe0377a642b0a5139e; the exact #13687 head is included. Environment: Debian Linux x86-64, Python 3.11.2; no local build or C++ test run.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13689
python3 tools/pr_abi_audit.py --base f25279c0ca4cb068370df4baaa46de7b4f4741c7 --head 8f63559455b61e103a370148dd46d2e469ae1fc8 --json
git diff --check f25279c0ca4cb068370df4baaa46de7b4f4741c7...8f63559455b61e103a370148dd46d2e469ae1fc8
git grep -n -E 'guest_webrtc_exp_filter|ExpFilter.cpp' 8f63559455b61e103a370148dd46d2e469ae1fc8 --
python3 tools/pr_stack_check.py 13689 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13689-8f63559455b6/stack
gh pr checks 13689 --repo boykopovar/AnyPS5

Results

Check Result
Diff and conventions Passed.
ABI audit passed_with_warnings; both changed ExpFilter exports have matching declarations and definitions, with no target-specific findings. Remaining warnings concern existing unknown exports.
Test registration and assertions guest_webrtc_exp_filter is registered. I inspected coverage for Reset, first-sample behavior, exponents 1/2/fractional, the -1 sentinel restart, max clamping, and the local null guard.
Current-main preview and dependency Clean; exact head of #13687 is included as declared.
Hosted CI Windows, conventions, intake, labels, library-portability, eligibility, and report passed. Linux and specialized jobs were skipped.
Focused tests Not run locally because they require a build. The author reports 3031/3031 CTest tests passed on this head; I did not reproduce the run.
Precheck helper availability The isolated checkout lacked the workspace-only ABI and test-quality scripts. I ran the ABI audit directly; I inspected the C++ test manually.
Unedited outputs
All conventions checks passed.
status: passed_with_warnings
_ZN3rtc9ExpFilter5ApplyEff_nid_postfix 6KIZ6hIOqDk ['core/libs/prx/libwebrtc/include/Api.hpp'] ['core/libs/prx/libwebrtc/Export.cpp']
_ZN3rtc9ExpFilter5ResetEf_nid_postfix A8OVQ4wC21Y ['core/libs/prx/libwebrtc/include/Api.hpp'] ['core/libs/prx/libwebrtc/Export.cpp']
target findings: []
8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:16:    add_test_executable(guest_webrtc_exp_filter_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/ExpFilter.cpp)
8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:17:    target_include_directories(guest_webrtc_exp_filter_tests PRIVATE ${LIBS_INCLUDE_DIR})
8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:18:    target_link_libraries(guest_webrtc_exp_filter_tests PRIVATE libwebrtc libc)
8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:19:    configure_windows_unwind(guest_webrtc_exp_filter_tests)
8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:20:    add_test(NAME guest_webrtc_exp_filter COMMAND guest_webrtc_exp_filter_tests)
# PR stack check — fresh

Target: https://github.com/boykopovar/AnyPS5/pull/13689
Target branch tip: `cbc30121bd6135d6ba8f50fe0377a642b0a5139e`
All heads unchanged: **True**
Dependency order: #13687 → #13689

## Individual merge previews

- PR #13687: **clean** against current base; head `314a8c5b492c364f6ce9d520e78dde41c2fa2a91`; changed paths: none reported
- PR #13689: **clean** against current base; head `8f63559455b61e103a370148dd46d2e469ae1fc8`; changed paths: none reported

## Dependency relationships

- #13687 → #13689: **head_included**
conventions	pass	21s	https://github.com/boykopovar/AnyPS5/actions/runs/41148336925/job/124378610529
labels	pass	9s	https://github.com/boykopovar/AnyPS5/actions/runs/41148336926/job/124378857366
windows	pass	6m41s	https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378664386
linux	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378666014
register-context	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378665552
relinker	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378666134
relinker-asan	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378665955
write-watch	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378665859
eligibility	pass	5s	https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124377924425
intake	pass	17s	https://github.com/boykopovar/AnyPS5/actions/runs/41148126266/job/124377924626
library-portability	pass	1m45s	https://github.com/boykopovar/AnyPS5/actions/runs/41148126383/job/124377923860
report	pass	1m0s	https://github.com/boykopovar/AnyPS5/actions/runs/41148126422/job/124377924261

Findings

Blocking

None found in the reviewed stack head.

Non-blocking

The PR says upstream dereferences a null filter “so a null filter throws.” The pinned source does not specify an exception for a null this pointer; that call is outside the valid-object contract. The new std::invalid_argument guard is reasonable defensive behavior, but should be described as local behavior rather than upstream behavior.

Sources

Not verified

No local build or test run, Linux hosted product build, macOS runtime, or console/title behavior was independently verified. CTest results are author-reported.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5720113344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13689#pullrequestreview-5720113344). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T00:31:05Z. **Review:** APPROVED --- # Reviewed — looks good The `ExpFilter` implementation matches the pinned WebRTC logic for valid objects, and its declarations, test registration, and declared #13687 dependency are consistent. ## What I ran Reviewed head `8f63559455b61e103a370148dd46d2e469ae1fc8` against PR base `f25279c0ca4cb068370df4baaa46de7b4f4741c7`. The stack check previewed it cleanly against current `main` `cbc30121bd6135d6ba8f50fe0377a642b0a5139e`; the exact #13687 head is included. Environment: Debian Linux x86-64, Python 3.11.2; no local build or C++ test run. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13689 python3 tools/pr_abi_audit.py --base f25279c0ca4cb068370df4baaa46de7b4f4741c7 --head 8f63559455b61e103a370148dd46d2e469ae1fc8 --json git diff --check f25279c0ca4cb068370df4baaa46de7b4f4741c7...8f63559455b61e103a370148dd46d2e469ae1fc8 git grep -n -E 'guest_webrtc_exp_filter|ExpFilter.cpp' 8f63559455b61e103a370148dd46d2e469ae1fc8 -- python3 tools/pr_stack_check.py 13689 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13689-8f63559455b6/stack gh pr checks 13689 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | |---|---| | Diff and conventions | Passed. | | ABI audit | `passed_with_warnings`; both changed ExpFilter exports have matching declarations and definitions, with no target-specific findings. Remaining warnings concern existing unknown exports. | | Test registration and assertions | `guest_webrtc_exp_filter` is registered. I inspected coverage for `Reset`, first-sample behavior, exponents 1/2/fractional, the `-1` sentinel restart, max clamping, and the local null guard. | | Current-main preview and dependency | Clean; exact head of #13687 is included as declared. | | Hosted CI | Windows, conventions, intake, labels, library-portability, eligibility, and report passed. Linux and specialized jobs were skipped. | | Focused tests | Not run locally because they require a build. The author reports 3031/3031 CTest tests passed on this head; I did not reproduce the run. | | Precheck helper availability | The isolated checkout lacked the workspace-only ABI and test-quality scripts. I ran the ABI audit directly; I inspected the C++ test manually. | <details> <summary>Unedited outputs</summary> ```text All conventions checks passed. ``` ```text status: passed_with_warnings _ZN3rtc9ExpFilter5ApplyEff_nid_postfix 6KIZ6hIOqDk ['core/libs/prx/libwebrtc/include/Api.hpp'] ['core/libs/prx/libwebrtc/Export.cpp'] _ZN3rtc9ExpFilter5ResetEf_nid_postfix A8OVQ4wC21Y ['core/libs/prx/libwebrtc/include/Api.hpp'] ['core/libs/prx/libwebrtc/Export.cpp'] target findings: [] ``` ```text 8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:16: add_test_executable(guest_webrtc_exp_filter_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/ExpFilter.cpp) 8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:17: target_include_directories(guest_webrtc_exp_filter_tests PRIVATE ${LIBS_INCLUDE_DIR}) 8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:18: target_link_libraries(guest_webrtc_exp_filter_tests PRIVATE libwebrtc libc) 8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:19: configure_windows_unwind(guest_webrtc_exp_filter_tests) 8f63559455b61e103a370148dd46d2e469ae1fc8:core/libs/prx/libwebrtc/CMakeLists.txt:20: add_test(NAME guest_webrtc_exp_filter COMMAND guest_webrtc_exp_filter_tests) ``` ```text # PR stack check — fresh Target: https://github.com/boykopovar/AnyPS5/pull/13689 Target branch tip: `cbc30121bd6135d6ba8f50fe0377a642b0a5139e` All heads unchanged: **True** Dependency order: #13687 → #13689 ## Individual merge previews - PR #13687: **clean** against current base; head `314a8c5b492c364f6ce9d520e78dde41c2fa2a91`; changed paths: none reported - PR #13689: **clean** against current base; head `8f63559455b61e103a370148dd46d2e469ae1fc8`; changed paths: none reported ## Dependency relationships - #13687 → #13689: **head_included** ``` ```text conventions pass 21s https://github.com/boykopovar/AnyPS5/actions/runs/41148336925/job/124378610529 labels pass 9s https://github.com/boykopovar/AnyPS5/actions/runs/41148336926/job/124378857366 windows pass 6m41s https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378664386 linux skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378666014 register-context skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378665552 relinker skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378666134 relinker-asan skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378665955 write-watch skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124378665859 eligibility pass 5s https://github.com/boykopovar/AnyPS5/actions/runs/41148126390/job/124377924425 intake pass 17s https://github.com/boykopovar/AnyPS5/actions/runs/41148126266/job/124377924626 library-portability pass 1m45s https://github.com/boykopovar/AnyPS5/actions/runs/41148126383/job/124377923860 report pass 1m0s https://github.com/boykopovar/AnyPS5/actions/runs/41148126422/job/124377924261 ``` </details> ## Findings ### Blocking None found in the reviewed stack head. ### Non-blocking The PR says upstream dereferences a null filter “so a null filter throws.” The pinned source does not specify an exception for a null `this` pointer; that call is outside the valid-object contract. The new `std::invalid_argument` guard is reasonable defensive behavior, but should be described as local behavior rather than upstream behavior. ## Sources - [Implementation and ABI layout at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/8f63559455b61e103a370148dd46d2e469ae1fc8/core/libs/prx/libwebrtc/Export.cpp#L1112-L1133) - [ExpFilter layout at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/8f63559455b61e103a370148dd46d2e469ae1fc8/core/libs/prx/libwebrtc/include/ExpFilter.hpp) - [Pinned WebRTC M134 ExpFilter implementation](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/numerics/exp_filter.cc) - [Pinned WebRTC M134 ExpFilter declaration](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/numerics/exp_filter.h) ## Not verified No local build or test run, Linux hosted product build, macOS runtime, or console/title behavior was independently verified. CTest results are author-reported.
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!13689
No description provided.