commit 3acb7331d88d7175804253ded277f30cdd7f1db1
parent 1189a78a4a215fac054efd4d13a9a53ed6b1c920
Author: Dan Baker <dbaker@mozilla.com>
Date: Mon, 1 Dec 2025 17:37:39 -0700
Bug 2000941 - Vendor libwebrtc from 79edd6e8ed
Upstream commit: https://webrtc.googlesource.com/src/+/79edd6e8ed5be3bfd79bc92644eed423a4c6f9d8
Use injected clock in video_codec_tester
Bug: webrtc:42223992
Change-Id: I99eb12d4d395c84a6ff342c14e3d565d6c4c4daa
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/407822
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45587}
Diffstat:
6 files changed, 38 insertions(+), 32 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-12-02T00:34:47.337550+00:00.
+libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T00:37:25.765320+00:00.
# base of lastest vendoring
-d7b5845e5e
+79edd6e8ed
diff --git a/third_party/libwebrtc/moz-patch-stack/s0027.patch b/third_party/libwebrtc/moz-patch-stack/s0027.patch
@@ -1199,7 +1199,7 @@ index c1181618e9..4a772795ed 100644
deps += [
"..:logging",
diff --git a/test/BUILD.gn b/test/BUILD.gn
-index 7651da3c90..5d39040dd8 100644
+index 0c7ce99ac0..1873e67f52 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -279,6 +279,7 @@ rtc_library("audio_test_common") {
diff --git a/third_party/libwebrtc/moz-patch-stack/s0099.patch b/third_party/libwebrtc/moz-patch-stack/s0099.patch
@@ -86,7 +86,7 @@ index ef363d15a6..90389a59fc 100644
if (!build_with_mozilla) {
diff --git a/test/BUILD.gn b/test/BUILD.gn
-index 5d39040dd8..9981ae4d80 100644
+index 1873e67f52..b24e6d2957 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -491,6 +491,12 @@ rtc_source_set("test_support") {
diff --git a/third_party/libwebrtc/moz-patch-stack/s0102.patch b/third_party/libwebrtc/moz-patch-stack/s0102.patch
@@ -756,7 +756,7 @@ index 2823625062..fdd5474c33 100644
import("../webrtc.gni")
diff --git a/test/BUILD.gn b/test/BUILD.gn
-index 9981ae4d80..9abf24e919 100644
+index b24e6d2957..329313d232 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -6,10 +6,10 @@
diff --git a/third_party/libwebrtc/test/BUILD.gn b/third_party/libwebrtc/test/BUILD.gn
@@ -1508,6 +1508,7 @@ rtc_library("video_codec_tester") {
"../rtc_base:timeutils",
"../rtc_base/synchronization:mutex",
"../rtc_base/system:file_wrapper",
+ "../system_wrappers",
"../video/config:encoder_config",
"../video/config:streams_config",
"//third_party/abseil-cpp/absl/functional:any_invocable",
diff --git a/third_party/libwebrtc/test/video_codec_tester.cc b/third_party/libwebrtc/test/video_codec_tester.cc
@@ -83,7 +83,7 @@
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/thread.h"
#include "rtc_base/thread_annotations.h"
-#include "rtc_base/time_utils.h"
+#include "system_wrappers/include/clock.h"
#include "test/testsupport/frame_reader.h"
#include "test/testsupport/video_frame_writer.h"
#include "third_party/libyuv/include/libyuv/compare.h"
@@ -207,11 +207,11 @@ class VideoSource {
// class is not thread safe.
class Pacer {
public:
- explicit Pacer(PacingSettings settings)
- : settings_(settings), delay_(TimeDelta::Zero()) {}
+ Pacer(Clock* clock, PacingSettings settings)
+ : clock_(clock), settings_(settings), delay_(TimeDelta::Zero()) {}
Timestamp Schedule(Timestamp timestamp) {
- Timestamp now = Timestamp::Micros(TimeMicros());
+ Timestamp now = clock_->CurrentTime();
if (settings_.mode == PacingMode::kNoPacing) {
return now;
}
@@ -238,6 +238,7 @@ class Pacer {
return 1 / settings_.constant_rate;
}
+ Clock* const clock_;
PacingSettings settings_;
std::optional<Timestamp> prev_timestamp_;
std::optional<Timestamp> prev_scheduled_;
@@ -255,7 +256,7 @@ class LimitedTaskQueue {
// until the queue size is reduced by executing previous tasks.
static constexpr int kMaxTaskQueueSize = 3;
- LimitedTaskQueue() : queue_size_(0) {}
+ explicit LimitedTaskQueue(Clock* clock) : clock_(clock), queue_size_(0) {}
void PostScheduledTask(absl::AnyInvocable<void() &&> task,
Timestamp scheduled) {
@@ -270,7 +271,7 @@ class LimitedTaskQueue {
++queue_size_;
task_queue_.PostTask([this, task = std::move(task), scheduled]() mutable {
- Timestamp now = Timestamp::Millis(TimeMillis());
+ Timestamp now = clock_->CurrentTime();
int64_t wait_ms = (scheduled - now).ms();
if (wait_ms > 0) {
RTC_CHECK_LT(wait_ms, 10000) << "Too high wait_ms " << wait_ms;
@@ -283,7 +284,7 @@ class LimitedTaskQueue {
}
void PostTask(absl::AnyInvocable<void() &&> task) {
- Timestamp now = Timestamp::Millis(TimeMillis());
+ Timestamp now = clock_->CurrentTime();
PostScheduledTask(std::move(task), now);
}
@@ -297,6 +298,7 @@ class LimitedTaskQueue {
}
private:
+ Clock* const clock_;
TaskQueueForTest task_queue_;
std::atomic_int queue_size_;
Event task_executed_;
@@ -410,18 +412,21 @@ class LeakyBucket {
class VideoCodecAnalyzer : public VideoCodecTester::VideoCodecStats {
public:
+ explicit VideoCodecAnalyzer(Clock* clock)
+ : clock_(clock), task_queue_(clock) {}
+
void StartEncode(const VideoFrame& video_frame,
const EncodingSettings& encoding_settings) {
- int64_t encode_start_us = TimeMicros();
+ Timestamp encode_start = clock_->CurrentTime();
task_queue_.PostTask([this, timestamp_rtp = video_frame.rtp_timestamp(),
- encoding_settings, encode_start_us]() {
+ encoding_settings, encode_start]() {
RTC_CHECK(frames_.find(timestamp_rtp) == frames_.end())
<< "Duplicate frame. Frame with timestamp " << timestamp_rtp
<< " was seen before";
Frame frame;
frame.timestamp_rtp = timestamp_rtp;
- frame.encode_start = Timestamp::Micros(encode_start_us),
+ frame.encode_start = encode_start,
frames_.emplace(timestamp_rtp,
std::map<int, Frame>{{/*spatial_idx=*/0, frame}});
encoding_settings_.emplace(timestamp_rtp, encoding_settings);
@@ -429,7 +434,7 @@ class VideoCodecAnalyzer : public VideoCodecTester::VideoCodecStats {
}
void FinishEncode(const EncodedImage& encoded_frame) {
- int64_t encode_finished_us = TimeMicros();
+ Timestamp encode_finished = clock_->CurrentTime();
task_queue_.PostTask(
[this, timestamp_rtp = encoded_frame.RtpTimestamp(),
spatial_idx = encoded_frame.SpatialIndex().value_or(
@@ -439,7 +444,7 @@ class VideoCodecAnalyzer : public VideoCodecTester::VideoCodecStats {
height = encoded_frame._encodedHeight,
frame_type = encoded_frame._frameType,
frame_size_bytes = encoded_frame.size(), qp = encoded_frame.qp_,
- encode_finished_us]() {
+ encode_finished]() {
if (spatial_idx > 0) {
RTC_CHECK(frames_.find(timestamp_rtp) != frames_.end())
<< "Spatial layer 0 frame with timestamp " << timestamp_rtp
@@ -457,14 +462,13 @@ class VideoCodecAnalyzer : public VideoCodecTester::VideoCodecStats {
frame.frame_size = DataSize::Bytes(frame_size_bytes);
frame.qp = qp;
frame.keyframe = frame_type == VideoFrameType::kVideoFrameKey;
- frame.encode_time =
- Timestamp::Micros(encode_finished_us) - frame.encode_start;
+ frame.encode_time = encode_finished - frame.encode_start;
frame.encoded = true;
});
}
void StartDecode(const EncodedImage& encoded_frame) {
- int64_t decode_start_us = TimeMicros();
+ Timestamp decode_start = clock_->CurrentTime();
task_queue_.PostTask(
[this, timestamp_rtp = encoded_frame.RtpTimestamp(),
spatial_idx = encoded_frame.SpatialIndex().value_or(
@@ -473,7 +477,7 @@ class VideoCodecAnalyzer : public VideoCodecTester::VideoCodecStats {
width = encoded_frame._encodedWidth,
height = encoded_frame._encodedHeight,
frame_type = encoded_frame._frameType, qp = encoded_frame.qp_,
- frame_size_bytes = encoded_frame.size(), decode_start_us]() {
+ frame_size_bytes = encoded_frame.size(), decode_start]() {
bool decode_only = frames_.find(timestamp_rtp) == frames_.end();
if (decode_only || frames_.at(timestamp_rtp).find(spatial_idx) ==
frames_.at(timestamp_rtp).end()) {
@@ -494,21 +498,19 @@ class VideoCodecAnalyzer : public VideoCodecTester::VideoCodecStats {
}
Frame& frame = frames_.at(timestamp_rtp).at(spatial_idx);
- frame.decode_start = Timestamp::Micros(decode_start_us);
+ frame.decode_start = decode_start;
});
}
void FinishDecode(const VideoFrame& decoded_frame,
int spatial_idx,
std::optional<VideoFrame> ref_frame = std::nullopt) {
- int64_t decode_finished_us = TimeMicros();
+ Timestamp decode_finished = clock_->CurrentTime();
task_queue_.PostTask([this, timestamp_rtp = decoded_frame.rtp_timestamp(),
spatial_idx, width = decoded_frame.width(),
- height = decoded_frame.height(),
- decode_finished_us]() {
+ height = decoded_frame.height(), decode_finished]() {
Frame& frame = frames_.at(timestamp_rtp).at(spatial_idx);
- frame.decode_time =
- Timestamp::Micros(decode_finished_us) - frame.decode_start;
+ frame.decode_time = decode_finished - frame.decode_start;
if (!frame.encoded) {
frame.width = width;
frame.height = height;
@@ -851,6 +853,7 @@ class VideoCodecAnalyzer : public VideoCodecTester::VideoCodecStats {
return SamplesStatsCounter::StatsSample{.value = value, .time = time};
}
+ Clock* const clock_;
LimitedTaskQueue task_queue_;
// RTP timestamp -> spatial layer -> Frame
std::map<uint32_t, std::map<int, Frame>> frames_;
@@ -866,7 +869,8 @@ class Decoder : public DecodedImageCallback {
: env_(env),
decoder_factory_(decoder_factory),
analyzer_(analyzer),
- pacer_(decoder_settings.pacing_settings) {
+ pacer_(&env.clock(), decoder_settings.pacing_settings),
+ task_queue_(&env.clock()) {
RTC_CHECK(analyzer_) << "Analyzer must be provided";
if (decoder_settings.decoder_input_base_path) {
@@ -991,7 +995,8 @@ class Encoder : public EncodedImageCallback {
: env_(env),
encoder_factory_(encoder_factory),
analyzer_(analyzer),
- pacer_(encoder_settings.pacing_settings) {
+ pacer_(&env.clock(), encoder_settings.pacing_settings),
+ task_queue_(&env.clock()) {
RTC_CHECK(analyzer_) << "Analyzer must be provided";
if (encoder_settings.encoder_input_base_path) {
@@ -1671,7 +1676,7 @@ VideoCodecTester::RunDecodeTest(const Environment& env,
const DecoderSettings& decoder_settings,
const SdpVideoFormat& sdp_video_format) {
std::unique_ptr<VideoCodecAnalyzer> analyzer =
- std::make_unique<VideoCodecAnalyzer>();
+ std::make_unique<VideoCodecAnalyzer>(&env.clock());
Decoder decoder(env, decoder_factory, decoder_settings, analyzer.get());
decoder.Initialize(sdp_video_format);
@@ -1693,7 +1698,7 @@ VideoCodecTester::RunEncodeTest(
const std::map<uint32_t, EncodingSettings>& encoding_settings) {
VideoSource video_source(env, source_settings);
std::unique_ptr<VideoCodecAnalyzer> analyzer =
- std::make_unique<VideoCodecAnalyzer>();
+ std::make_unique<VideoCodecAnalyzer>(&env.clock());
Encoder encoder(env, encoder_factory, encoder_settings, analyzer.get());
encoder.Initialize(encoding_settings.begin()->second);
@@ -1722,7 +1727,7 @@ VideoCodecTester::RunEncodeDecodeTest(
const std::map<uint32_t, EncodingSettings>& encoding_settings) {
VideoSource video_source(env, source_settings);
std::unique_ptr<VideoCodecAnalyzer> analyzer =
- std::make_unique<VideoCodecAnalyzer>();
+ std::make_unique<VideoCodecAnalyzer>(&env.clock());
const EncodingSettings& first_frame_settings =
encoding_settings.begin()->second;
Encoder encoder(env, encoder_factory, encoder_settings, analyzer.get());