feat(libwebrtc): implement rtc::RateTracker #16381
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16381"
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 AlexWhitehouse on 2026-11-06T13:57:55Z.
What
Implements libwebrtc
rtc::RateTracker's four exports, which threw throughNotImplemented_nid_no_patch:rtc::RateTracker::RateTracker(int64_t, size_t)(_ZN3rtc11RateTrackerC1Elm)o-7JqHJukNcrtc::RateTracker::~RateTracker()(_ZN3rtc11RateTrackerD1Ev)03MioCxwz-grtc::RateTracker::AddSamples(int64_t)(_ZN3rtc11RateTracker10AddSamplesEl)BMS8p-tBcTUrtc::RateTracker::ComputeRateForInterval(int64_t) const(_ZNK3rtc11RateTracker22ComputeRateForIntervalEl)HVudf31CXkcSource:
rtc_base/rate_tracker.ccandrate_tracker.hat M134. Both files are byte-identical at M127, the other end of the revision range in the debt file's "Source revision" entry.src/RateTracker.cppstarts withrate_tracker.cc's notice copied byte for byte, plus the WebRTC BSD licence, as the other libwebrtc ports do. The bodies follow upstream line for line:AddSamplesreadsTime()and callsEnsureInitialized, then advances and clears at mostbucket_count + 1buckets, realigns the bucket start after a full expiry, and adds to the current bucket and the total.ComputeRateForIntervalcaps the interval at the window, skips expired buckets, counts the oldest bucket in proportion (with upstream's rounding), and returns 0 during the first bucket after initialization.ABI, from the header:
bucket_milliseconds_,bucket_count_,sample_buckets_,total_sample_count_,current_bucket_,bucket_start_time_milliseconds_andinitialization_time_milliseconds_at offsets 8 to 56.include/RateTracker.hppchecks every offset with astatic_assert.sample_buckets_isnew int64_t[bucket_count + 1]upstream. It is allocated and freed through the guest'soperator new[]andoperator delete[](_Znam,_ZdaPv), as libc'sStdioExtras.cppcalls them, so guest code that owns or frees the object stays consistent. libwebrtc now links libc for them.Time()is a protected virtual that upstream calls through the vptr, so a guest subclass can override it. The constructor installs a vtable with the Itanium slot order of the header's virtuals:~RateTracker(complete and deleting), thenTime, which defaults to this module's existingrtc::TimeMillis.Timeis called through the object's vptr withAPS5_VABI.RateTrackervtable and typeinfo are not among the 31 libwebrtc data exports, so the table is local. Its typeinfo slot is null, so RTTI on these objects is unsupported, as in libSceNpCommon.RTC_CHECKs on a non-positive bucket length or a zero bucket count abort, so those throw here. So does a bucket count whose array size overflows.RTC_DCHECK_LE(0, sample_count)is debug-only and is left out, as in a release build.docs/dev/debt/libwebrtc.mdrecords these choices and that nothing is compared with the console. The inventory count drops from 339 to 335; all four exports had names, so the unnamed figure stays 60.Tested
guest_webrtc_rate_tracker(core/libs/prx/libwebrtc/tests/RateTracker.cpp). A test vtable whoseTimeslot returns a controlled clock drives the exports, so there are no sleeps.rate_tracker_unittest.cc: 30 and 60 FPS, basics (0 before a full bucket, 12340 after 1234 samples in 100 ms, partial-window and full-expiry values), a long period between samples, rolloff, the first second after an initial value, and counts above 2^32.Timereadsrtc::TimeMillis; and both destructors free the array (and the object) through the guest allocator. Invalid constructor parameters throw.main's library, 17 existing tests pass and the new test fails with_ZN3rtc11RateTrackerC1Elm_nid_postfix not implemented;public_headerspasses.libwebrtc RateTracker check failed at line 279.ctest -R webrtcpasses 18/18 at 533e376f51, with no warnings in the new files.mainthere: the header it uses doesn't exist onmain, andmaindeclares the stubs as(void).main's library.python3 tools/check_conventions.py --base origin/main: all conventions checks passed.python3 tools/pr_overlap.py --branch feat/libwebrtc-rate-tracker: no open PR implements these exports. #15154 listsRateTrackeramong the families it leaves unimplemented, and merges cleanly with this branch.Export.cpp/Api.hpp) and my #15766 merge cleanly in code. They conflict only on the inventory count line indocs/dev/debt/libwebrtc.md.mainand keep only those conflicts.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 ahmadmuj on 2026-11-06T15:32:13Z.
Review: COMMENTED
Checked head
533e376f517a7a54372bdaa2057cb5a77bf5bf42, PR based60ebec0c292807398de2130294cac8ae0c1b862, and main492ed5c5fe5d476257ab52fa8e09cf7c343c8200.The odd-width path matches WebRTC's pinned source. I checked this through the actual exact-head CMake
libwebrtcand guestlibc, with an isolatedRateTrackerOddWindow044.cppprobe.Setup: Ubuntu 24.04.2 under WSL2, x86-64 i7-13700K, GCC 13.3.0, Release. The probe uses the declared exports,
APS5_VABI, and a controlled Time slot.dladdrconfirms all tracker and allocator calls resolve to the built modules.With a 3 ms bucket, count 1, and one sample at time 0, interval 3 returns:
0.01000.0 / 3.00.0Adding seven samples at time 6 gives
7000.0 / 3.0at time 9. All assertions pass. The probe verifies binary64 andFE_TONEAREST, uses no fast-math, and compares exact divisions rather than decimal approximations.For a control, I changed only the production rounding term from
bucketMilliseconds >> 1to(bucketMilliseconds + 1) >> 1. The new probe fails at time 5: it gets1000.0 / 3.0instead of zero. The unchangedguest_webrtc_rate_trackerfixture still passes with that mutation. Its valid constructions use 100 ms buckets, where both terms equal 50.Object/allocation guards, initialized bucket state, one 16-byte allocation, one matching free, and direct D1 cleanup pass, including the failing control. Each run uses a fresh process. After restoring production bytes and rebuilding, both tests pass again. Source and artifact hashes match the original build. The mutant build also refreshes libc/libkernel's generated modified-state metadata.
Commands used, with
Wthe exact-head worktree,Bits build,Ethe probe directory, andL=$B/core/libs/libs/unpatched:Conventions pass. Each fixture/probe invocation finishes below 0.12 seconds. Builds and tests run without credential variables; builds hold the shared build lock. No full product build runs.
This adds coverage beyond removing the rounding term or repeating the even-width fixture. The current head passes; I found no defect in this boundary. Main's four exports remain throwing stubs by source inspection; no main runtime result is claimed. Console layout, dispatch, and behavior remain unverified. GPUs tested: n/a. AI-assisted: yes.