tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e6787fd56d89a5aaedcd16b1688e3af3ed959c27
parent 8f0aa2f6e52ac8180cc6ae7b4f82d9b2a86a90ac
Author: Dan Baker <dbaker@mozilla.com>
Date:   Mon, 27 Oct 2025 14:48:49 -0600

Bug 1995393 - Vendor libwebrtc from 98db746a35

Upstream commit: https://webrtc.googlesource.com/src/+/98db746a3574f174141a810e0fc3b6603bba2e93
    Remove use of TimeMillis in EncoderOvershootDetectorTest

    The EncoderOvershootDetector already takes the time as input, so no need
    to change any injection.

    Bug: webrtc:42223992
    Change-Id: Ie8a6e1fe5c1816aed35672883a43e4e957a68f58
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/406762
    Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
    Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
    Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
    Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#45471}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/video/encoder_overshoot_detector_unittest.cc | 86+++++++++++++++++++++++++++++++++++++++++++------------------------------------
2 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-27T20:46:12.462085+00:00. +libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-27T20:48:36.482443+00:00. # base of lastest vendoring -0e582e5b50 +98db746a35 diff --git a/third_party/libwebrtc/video/encoder_overshoot_detector_unittest.cc b/third_party/libwebrtc/video/encoder_overshoot_detector_unittest.cc @@ -18,9 +18,9 @@ #include "api/units/data_size.h" #include "api/units/frequency.h" #include "api/units/time_delta.h" +#include "api/units/timestamp.h" #include "api/video/video_codec_type.h" -#include "rtc_base/fake_clock.h" -#include "rtc_base/time_utils.h" +#include "system_wrappers/include/clock.h" #include "system_wrappers/include/metrics.h" #include "test/gtest.h" @@ -60,7 +60,7 @@ class EncoderOvershootDetectorTest : public TestWithParam<TestParams> { static constexpr int kDefaultBitrateBps = 300000; static constexpr double kDefaultFrameRateFps = 15; EncoderOvershootDetectorTest() - : detector_(kWindowSizeMs, + : detector_(kWindowSize.ms(), GetParam().codec_type, GetParam().is_screenshare), target_bitrate_(DataRate::BitsPerSec(kDefaultBitrateBps)), @@ -71,42 +71,42 @@ class EncoderOvershootDetectorTest : public TestWithParam<TestParams> { void RunConstantUtilizationTest(double actual_utilization_factor, double expected_utilization_factor, double allowed_error, - int64_t test_duration_ms) { + TimeDelta test_duration) { const int frame_size_bytes = static_cast<int>(actual_utilization_factor * (target_bitrate_.bps() / target_framerate_fps_) / 8); detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, - TimeMillis()); + clock_.TimeInMilliseconds()); - if (TimeMillis() == 0) { + if (clock_.TimeInMilliseconds() == 0) { // Encode a first frame which by definition has no overuse factor. - detector_.OnEncodedFrame(frame_size_bytes, TimeMillis()); + detector_.OnEncodedFrame(frame_size_bytes, clock_.TimeInMilliseconds()); clock_.AdvanceTime(TimeDelta::Seconds(1) / target_framerate_fps_); } - int64_t runtime_us = 0; - while (runtime_us < test_duration_ms * 1000) { - detector_.OnEncodedFrame(frame_size_bytes, TimeMillis()); - runtime_us += kNumMicrosecsPerSec / target_framerate_fps_; + TimeDelta runtime = TimeDelta::Zero(); + while (runtime < test_duration) { + detector_.OnEncodedFrame(frame_size_bytes, clock_.TimeInMilliseconds()); + runtime += TimeDelta::Seconds(1) / target_framerate_fps_; clock_.AdvanceTime(TimeDelta::Seconds(1) / target_framerate_fps_); } // At constant utilization, both network and media utilization should be // close to expected. const std::optional<double> network_utilization_factor = - detector_.GetNetworkRateUtilizationFactor(TimeMillis()); + detector_.GetNetworkRateUtilizationFactor(clock_.TimeInMilliseconds()); EXPECT_NEAR(network_utilization_factor.value_or(-1), expected_utilization_factor, allowed_error); const std::optional<double> media_utilization_factor = - detector_.GetMediaRateUtilizationFactor(TimeMillis()); + detector_.GetMediaRateUtilizationFactor(clock_.TimeInMilliseconds()); EXPECT_NEAR(media_utilization_factor.value_or(-1), expected_utilization_factor, allowed_error); } - static constexpr int64_t kWindowSizeMs = 3000; + static constexpr TimeDelta kWindowSize = TimeDelta::Millis(3000); EncoderOvershootDetector detector_; - ScopedFakeClock clock_; + SimulatedClock clock_{Timestamp::Millis(12345)}; DataRate target_bitrate_; double target_framerate_fps_; }; @@ -114,63 +114,67 @@ class EncoderOvershootDetectorTest : public TestWithParam<TestParams> { TEST_P(EncoderOvershootDetectorTest, NoUtilizationIfNoRate) { const int frame_size_bytes = 1000; const int64_t time_interval_ms = 33; - detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, TimeMillis()); + detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, + clock_.TimeInMilliseconds()); // No data points, can't determine overshoot rate. EXPECT_FALSE( - detector_.GetNetworkRateUtilizationFactor(TimeMillis()).has_value()); + detector_.GetNetworkRateUtilizationFactor(clock_.TimeInMilliseconds()) + .has_value()); - detector_.OnEncodedFrame(frame_size_bytes, TimeMillis()); + detector_.OnEncodedFrame(frame_size_bytes, clock_.TimeInMilliseconds()); clock_.AdvanceTime(TimeDelta::Millis(time_interval_ms)); EXPECT_TRUE( - detector_.GetNetworkRateUtilizationFactor(TimeMillis()).has_value()); + detector_.GetNetworkRateUtilizationFactor(clock_.TimeInMilliseconds()) + .has_value()); } TEST_P(EncoderOvershootDetectorTest, OptimalSize) { // Optimally behaved encoder. // Allow some error margin due to rounding errors, eg due to frame // interval not being an integer. - RunConstantUtilizationTest(1.0, 1.0, 0.01, kWindowSizeMs); + RunConstantUtilizationTest(1.0, 1.0, 0.01, kWindowSize); } TEST_P(EncoderOvershootDetectorTest, Undershoot) { // Undershoot, reported utilization factor should be capped to 1.0 so // that we don't incorrectly boost encoder bitrate during movement. - RunConstantUtilizationTest(0.5, 1.0, 0.00, kWindowSizeMs); + RunConstantUtilizationTest(0.5, 1.0, 0.00, kWindowSize); } TEST_P(EncoderOvershootDetectorTest, Overshoot) { // Overshoot by 20%. // Allow some error margin due to rounding errors. - RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs); + RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize); } TEST_P(EncoderOvershootDetectorTest, ConstantOvershootVaryingRates) { // Overshoot by 20%, but vary framerate and bitrate. // Allow some error margin due to rounding errors. - RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs); + RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize); target_framerate_fps_ /= 2; - RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs / 2); + RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize / 2); target_bitrate_ = DataRate::BitsPerSec(target_bitrate_.bps() / 2); - RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs / 2); + RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize / 2); } TEST_P(EncoderOvershootDetectorTest, ConstantRateVaryingOvershoot) { // Overshoot by 10%, keep framerate and bitrate constant. // Allow some error margin due to rounding errors. - RunConstantUtilizationTest(1.1, 1.1, 0.01, kWindowSizeMs); + RunConstantUtilizationTest(1.1, 1.1, 0.01, kWindowSize); // Change overshoot to 20%, run for half window and expect overshoot // to be 15%. - RunConstantUtilizationTest(1.2, 1.15, 0.01, kWindowSizeMs / 2); + RunConstantUtilizationTest(1.2, 1.15, 0.01, kWindowSize / 2); // Keep running at 20% overshoot, after window is full that should now // be the reported overshoot. - RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs / 2); + RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize / 2); } TEST_P(EncoderOvershootDetectorTest, PartialOvershoot) { const int ideal_frame_size_bytes = (target_bitrate_.bps() / target_framerate_fps_) / 8; - detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, TimeMillis()); + detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, + clock_.TimeInMilliseconds()); // Test scenario with average bitrate matching the target bitrate, but // with some utilization factor penalty as the frames can't be paced out @@ -182,32 +186,34 @@ TEST_P(EncoderOvershootDetectorTest, PartialOvershoot) { // 4) 20% undershoot, no penalty. // On average then utilization penalty is thus 5%. - int64_t runtime_us = 0; + TimeDelta runtime = TimeDelta::Zero(); int i = 0; - while (runtime_us < kWindowSizeMs * kNumMicrosecsPerMillisec) { - runtime_us += kNumMicrosecsPerSec / target_framerate_fps_; + while (runtime < kWindowSize) { + runtime += TimeDelta::Seconds(1) / target_framerate_fps_; clock_.AdvanceTime(TimeDelta::Seconds(1) / target_framerate_fps_); int frame_size_bytes = (i++ % 4 < 2) ? (ideal_frame_size_bytes * 120) / 100 : (ideal_frame_size_bytes * 80) / 100; - detector_.OnEncodedFrame(frame_size_bytes, TimeMillis()); + detector_.OnEncodedFrame(frame_size_bytes, clock_.TimeInMilliseconds()); } // Expect 5% overshoot for network rate, see above. const std::optional<double> network_utilization_factor = - detector_.GetNetworkRateUtilizationFactor(TimeMillis()); + detector_.GetNetworkRateUtilizationFactor(clock_.TimeInMilliseconds()); EXPECT_NEAR(network_utilization_factor.value_or(-1), 1.05, 0.01); // Expect media rate to be on average correct. const std::optional<double> media_utilization_factor = - detector_.GetMediaRateUtilizationFactor(TimeMillis()); + detector_.GetMediaRateUtilizationFactor(clock_.TimeInMilliseconds()); EXPECT_NEAR(media_utilization_factor.value_or(-1), 1.00, 0.01); } TEST_P(EncoderOvershootDetectorTest, RecordsZeroErrorMetricWithNoOvershoot) { DataSize ideal_frame_size = target_bitrate_ / Frequency::Hertz(target_framerate_fps_); - detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, TimeMillis()); - detector_.OnEncodedFrame(ideal_frame_size.bytes(), TimeMillis()); + detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, + clock_.TimeInMilliseconds()); + detector_.OnEncodedFrame(ideal_frame_size.bytes(), + clock_.TimeInMilliseconds()); detector_.Reset(); const VideoCodecType codec = GetParam().codec_type; @@ -238,8 +244,10 @@ TEST_P(EncoderOvershootDetectorTest, target_bitrate_ / Frequency::Hertz(target_framerate_fps_); // Use target frame size with 50% overshoot. DataSize target_frame_size = ideal_frame_size * 3 / 2; - detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, TimeMillis()); - detector_.OnEncodedFrame(target_frame_size.bytes(), TimeMillis()); + detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, + clock_.TimeInMilliseconds()); + detector_.OnEncodedFrame(target_frame_size.bytes(), + clock_.TimeInMilliseconds()); detector_.Reset(); const VideoCodecType codec = GetParam().codec_type;