Update rtc tools to create Call using Environment
Bug: webrtc:15656
Change-Id: I2bf17e95f4c8b26dcb735eb5198d5347a97dee69
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/329082
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41261}
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index 1ab7a98..e5c0cdf 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -204,9 +204,8 @@
"../api:create_frame_generator",
"../api:rtp_parameters",
"../api:transport_api",
- "../api/rtc_event_log",
- "../api/task_queue:default_task_queue_factory",
- "../api/task_queue:task_queue",
+ "../api/environment",
+ "../api/environment:environment_factory",
"../api/video:builtin_video_bitrate_allocator_factory",
"../api/video_codecs:video_codecs_api",
"../call",
@@ -257,8 +256,8 @@
deps = [
"../api:field_trials",
"../api:rtp_parameters",
- "../api/rtc_event_log",
- "../api/task_queue:default_task_queue_factory",
+ "../api/environment",
+ "../api/environment:environment_factory",
"../api/test/video:function_video_factory",
"../api/transport:field_trial_based_config",
"../api/units:timestamp",
@@ -273,7 +272,6 @@
"../rtc_base:checks",
"../rtc_base:rtc_json",
"../rtc_base:stringutils",
- "../rtc_base:timeutils",
"../system_wrappers",
"../test:call_config_utils",
"../test:encoder_settings",
diff --git a/rtc_tools/rtp_generator/rtp_generator.cc b/rtc_tools/rtp_generator/rtp_generator.cc
index e50c125..0c6d3e3 100644
--- a/rtc_tools/rtp_generator/rtp_generator.cc
+++ b/rtc_tools/rtp_generator/rtp_generator.cc
@@ -14,7 +14,7 @@
#include <memory>
#include <utility>
-#include "api/task_queue/default_task_queue_factory.h"
+#include "api/environment/environment_factory.h"
#include "api/test/create_frame_generator.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
@@ -171,6 +171,7 @@
RtpGenerator::RtpGenerator(const RtpGeneratorOptions& options)
: options_(options),
+ env_(CreateEnvironment()),
video_encoder_factory_(
std::make_unique<webrtc::VideoEncoderFactoryTemplate<
webrtc::LibvpxVp8EncoderTemplateAdapter,
@@ -183,9 +184,7 @@
webrtc::Dav1dDecoderTemplateAdapter>>()),
video_bitrate_allocator_factory_(
CreateBuiltinVideoBitrateAllocatorFactory()),
- event_log_(std::make_unique<RtcEventLogNull>()),
- call_(Call::Create(CallConfig(event_log_.get()))),
- task_queue_(CreateDefaultTaskQueueFactory()) {
+ call_(Call::Create(CallConfig(env_))) {
constexpr int kMinBitrateBps = 30000; // 30 Kbps
constexpr int kMaxBitrateBps = 2500000; // 2.5 Mbps
@@ -246,11 +245,11 @@
// Setup the fake video stream for this.
std::unique_ptr<test::FrameGeneratorCapturer> frame_generator =
std::make_unique<test::FrameGeneratorCapturer>(
- Clock::GetRealTimeClock(),
+ &env_.clock(),
test::CreateSquareFrameGenerator(send_config.video_width,
send_config.video_height,
absl::nullopt, absl::nullopt),
- send_config.video_fps, *task_queue_);
+ send_config.video_fps, env_.task_queue_factory());
frame_generator->Init();
VideoSendStream* video_send_stream = call_->CreateVideoSendStream(
diff --git a/rtc_tools/rtp_generator/rtp_generator.h b/rtc_tools/rtp_generator/rtp_generator.h
index e9d2336..2f178d3 100644
--- a/rtc_tools/rtp_generator/rtp_generator.h
+++ b/rtc_tools/rtp_generator/rtp_generator.h
@@ -16,9 +16,8 @@
#include <vector>
#include "api/call/transport.h"
+#include "api/environment/environment.h"
#include "api/media_types.h"
-#include "api/rtc_event_log/rtc_event_log.h"
-#include "api/task_queue/task_queue_factory.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "api/video_codecs/video_decoder_factory.h"
#include "api/video_codecs/video_encoder_factory.h"
@@ -104,18 +103,17 @@
test::RtpPacket DataToRtpPacket(const uint8_t* packet, size_t packet_len);
const RtpGeneratorOptions options_;
+ const Environment env_;
std::unique_ptr<VideoEncoderFactory> video_encoder_factory_;
std::unique_ptr<VideoDecoderFactory> video_decoder_factory_;
std::unique_ptr<VideoBitrateAllocatorFactory>
video_bitrate_allocator_factory_;
- std::unique_ptr<RtcEventLog> event_log_;
std::unique_ptr<Call> call_;
std::unique_ptr<test::RtpFileWriter> rtp_dump_writer_;
std::vector<std::unique_ptr<test::FrameGeneratorCapturer>> frame_generators_;
std::vector<VideoSendStream*> video_send_streams_;
std::vector<uint32_t> durations_ms_;
uint32_t start_ms_ = 0;
- std::unique_ptr<TaskQueueFactory> task_queue_;
};
} // namespace webrtc
diff --git a/rtc_tools/video_replay.cc b/rtc_tools/video_replay.cc
index b19850e..52c8d68 100644
--- a/rtc_tools/video_replay.cc
+++ b/rtc_tools/video_replay.cc
@@ -16,10 +16,10 @@
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
+#include "api/environment/environment.h"
+#include "api/environment/environment_factory.h"
#include "api/field_trials.h"
#include "api/media_types.h"
-#include "api/rtc_event_log/rtc_event_log.h"
-#include "api/task_queue/default_task_queue_factory.h"
#include "api/test/video/function_video_decoder_factory.h"
#include "api/transport/field_trial_based_config.h"
#include "api/units/timestamp.h"
@@ -36,7 +36,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/string_to_number.h"
#include "rtc_base/strings/json.h"
-#include "rtc_base/time_utils.h"
#include "system_wrappers/include/clock.h"
#include "system_wrappers/include/sleep.h"
#include "test/call_config_utils.h"
@@ -478,26 +477,21 @@
bool simulated_time)
: replay_config_path_(replay_config_path),
rtp_dump_path_(rtp_dump_path),
- field_trials_(std::move(field_trials)),
+ time_sim_(simulated_time
+ ? std::make_unique<GlobalSimulatedTimeController>(
+ Timestamp::Millis(1 << 30))
+ : nullptr),
+ env_(CreateEnvironment(
+ std::move(field_trials),
+ time_sim_ ? time_sim_->GetTaskQueueFactory() : nullptr,
+ time_sim_ ? time_sim_->GetClock() : nullptr)),
rtp_reader_(CreateRtpReader(rtp_dump_path_)) {
- TaskQueueFactory* task_queue_factory;
- if (simulated_time) {
- time_sim_ = std::make_unique<GlobalSimulatedTimeController>(
- Timestamp::Millis(1 << 30));
- task_queue_factory = time_sim_->GetTaskQueueFactory();
- } else {
- task_queue_factory_ = CreateDefaultTaskQueueFactory(field_trials_.get()),
- task_queue_factory = task_queue_factory_.get();
- }
- worker_thread_ =
- std::make_unique<rtc::TaskQueue>(task_queue_factory->CreateTaskQueue(
+ worker_thread_ = std::make_unique<rtc::TaskQueue>(
+ env_.task_queue_factory().CreateTaskQueue(
"worker_thread", TaskQueueFactory::Priority::NORMAL));
rtc::Event event;
worker_thread_->PostTask([&]() {
- CallConfig call_config(&event_log_);
- call_config.trials = field_trials_.get();
- call_config.task_queue_factory = task_queue_factory;
- call_ = Call::Create(call_config);
+ call_ = Call::Create(CallConfig(env_));
// Creation of the streams must happen inside a task queue because it is
// resued as a worker thread.
@@ -655,10 +649,7 @@
}
}
- int64_t CurrentTimeMs() {
- return time_sim_ ? time_sim_->GetClock()->TimeInMilliseconds()
- : rtc::TimeMillis();
- }
+ int64_t CurrentTimeMs() { return env_.clock().CurrentTime().ms(); }
void SleepOrAdvanceTime(int64_t duration_ms) {
if (time_sim_) {
@@ -670,10 +661,8 @@
const std::string replay_config_path_;
const std::string rtp_dump_path_;
- RtcEventLogNull event_log_;
- std::unique_ptr<FieldTrialsView> field_trials_;
std::unique_ptr<GlobalSimulatedTimeController> time_sim_;
- std::unique_ptr<TaskQueueFactory> task_queue_factory_;
+ Environment env_;
std::unique_ptr<rtc::TaskQueue> worker_thread_;
std::unique_ptr<Call> call_;
std::unique_ptr<test::RtpFileReader> rtp_reader_;