Add RtcEventLogFactory factory with explicit TaskQueueFactory
remove RtcEventLog factory function that relies on GlobalTaskQueueFactory,
move that default behaviour up to RtcEventLogFactory level.
Bug: webrtc:10284
Change-Id: I512d8a13e6a2f320000dd08e6355c0a7e9de8561
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132542
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27573}
diff --git a/call/BUILD.gn b/call/BUILD.gn
index bcd3078..5dc9670 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -423,10 +423,13 @@
":video_stream_api",
"../api:simulated_network_api",
"../api/audio_codecs:builtin_audio_encoder_factory",
+ "../api/task_queue",
+ "../api/task_queue:default_task_queue_factory",
"../api/video:builtin_video_bitrate_allocator_factory",
"../api/video:video_bitrate_allocation",
"../api/video_codecs:video_codecs_api",
"../logging:rtc_event_log_api",
+ "../logging:rtc_event_log_impl_base",
"../logging:rtc_event_log_impl_output",
"../modules/audio_coding",
"../modules/audio_device",
diff --git a/call/rampup_tests.cc b/call/rampup_tests.cc
index 55d6a9b..85e8d95 100644
--- a/call/rampup_tests.cc
+++ b/call/rampup_tests.cc
@@ -10,9 +10,14 @@
#include "call/rampup_tests.h"
+#include <memory>
+
#include "absl/memory/memory.h"
+#include "api/task_queue/default_task_queue_factory.h"
+#include "api/task_queue/task_queue_factory.h"
#include "call/fake_network_pipe.h"
#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
+#include "logging/rtc_event_log/rtc_event_log_factory.h"
#include "rtc_base/checks.h"
#include "rtc_base/flags.h"
#include "rtc_base/logging.h"
@@ -575,11 +580,15 @@
class RampUpTest : public test::CallTest {
public:
- RampUpTest() {
+ RampUpTest()
+ : task_queue_factory_(CreateDefaultTaskQueueFactory()),
+ rtc_event_log_factory_(task_queue_factory_.get()) {
std::string dump_name(FLAG_ramp_dump_name);
if (!dump_name.empty()) {
- send_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy);
- recv_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy);
+ send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
+ RtcEventLog::EncodingType::Legacy);
+ recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
+ RtcEventLog::EncodingType::Legacy);
bool event_log_started =
send_event_log_->StartLogging(
absl::make_unique<RtcEventLogOutputFile>(
@@ -592,6 +601,10 @@
RTC_DCHECK(event_log_started);
}
}
+
+ private:
+ const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
+ RtcEventLogFactory rtc_event_log_factory_;
};
static const uint32_t kStartBitrateBps = 60000;
diff --git a/logging/BUILD.gn b/logging/BUILD.gn
index 81f24b5..e1d5289 100644
--- a/logging/BUILD.gn
+++ b/logging/BUILD.gn
@@ -385,6 +385,7 @@
"../api:array_view",
"../api:libjingle_peerconnection_api",
"../api:rtp_headers",
+ "../api/task_queue:default_task_queue_factory",
"../call",
"../call:call_interfaces",
"../modules/audio_coding:audio_network_adaptor",
diff --git a/logging/rtc_event_log/rtc_event_log.h b/logging/rtc_event_log/rtc_event_log.h
index edfeef9..08b5475 100644
--- a/logging/rtc_event_log/rtc_event_log.h
+++ b/logging/rtc_event_log/rtc_event_log.h
@@ -35,8 +35,6 @@
virtual ~RtcEventLog() {}
// Factory method to create an RtcEventLog object.
- static std::unique_ptr<RtcEventLog> Create(EncodingType encoding_type);
-
static std::unique_ptr<RtcEventLog> Create(
EncodingType encoding_type,
TaskQueueFactory* task_queue_factory);
diff --git a/logging/rtc_event_log/rtc_event_log_factory.cc b/logging/rtc_event_log/rtc_event_log_factory.cc
index a116973..b38b7bc 100644
--- a/logging/rtc_event_log/rtc_event_log_factory.cc
+++ b/logging/rtc_event_log/rtc_event_log_factory.cc
@@ -12,17 +12,25 @@
#include <utility>
+#include "absl/memory/memory.h"
+#include "api/task_queue/global_task_queue_factory.h"
#include "logging/rtc_event_log/rtc_event_log.h"
+#include "rtc_base/checks.h"
namespace webrtc {
+RtcEventLogFactory::RtcEventLogFactory(TaskQueueFactory* task_queue_factory)
+ : task_queue_factory_(task_queue_factory) {
+ RTC_DCHECK(task_queue_factory_);
+}
+
std::unique_ptr<RtcEventLog> RtcEventLogFactory::CreateRtcEventLog(
RtcEventLog::EncodingType encoding_type) {
- return RtcEventLog::Create(encoding_type);
+ return RtcEventLog::Create(encoding_type, task_queue_factory_);
}
std::unique_ptr<RtcEventLogFactoryInterface> CreateRtcEventLogFactory() {
- return std::unique_ptr<RtcEventLogFactoryInterface>(new RtcEventLogFactory());
+ return absl::make_unique<RtcEventLogFactory>(&GlobalTaskQueueFactory());
}
} // namespace webrtc
diff --git a/logging/rtc_event_log/rtc_event_log_factory.h b/logging/rtc_event_log/rtc_event_log_factory.h
index 1480551..01e3994 100644
--- a/logging/rtc_event_log/rtc_event_log_factory.h
+++ b/logging/rtc_event_log/rtc_event_log_factory.h
@@ -13,6 +13,7 @@
#include <memory>
+#include "api/task_queue/task_queue_factory.h"
#include "logging/rtc_event_log/rtc_event_log.h"
#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
@@ -20,12 +21,17 @@
class RtcEventLogFactory : public RtcEventLogFactoryInterface {
public:
+ explicit RtcEventLogFactory(TaskQueueFactory* task_queue_factory);
~RtcEventLogFactory() override {}
std::unique_ptr<RtcEventLog> CreateRtcEventLog(
RtcEventLog::EncodingType encoding_type) override;
+
+ private:
+ TaskQueueFactory* const task_queue_factory_;
};
+// TODO(bugs.webrtc.org/10284): Stop using the RtcEventLogFactory factory.
std::unique_ptr<RtcEventLogFactoryInterface> CreateRtcEventLogFactory();
} // namespace webrtc
diff --git a/logging/rtc_event_log/rtc_event_log_impl.cc b/logging/rtc_event_log/rtc_event_log_impl.cc
index f62f690..51fa74a 100644
--- a/logging/rtc_event_log/rtc_event_log_impl.cc
+++ b/logging/rtc_event_log/rtc_event_log_impl.cc
@@ -20,7 +20,6 @@
#include "absl/memory/memory.h"
#include "absl/types/optional.h"
#include "api/rtc_event_log_output.h"
-#include "api/task_queue/global_task_queue_factory.h"
#include "api/task_queue/queued_task.h"
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h"
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h"
@@ -371,10 +370,6 @@
#endif // ENABLE_RTC_EVENT_LOG
// RtcEventLog member functions.
-std::unique_ptr<RtcEventLog> RtcEventLog::Create(EncodingType encoding_type) {
- return RtcEventLog::Create(encoding_type, &GlobalTaskQueueFactory());
-}
-
std::unique_ptr<RtcEventLog> RtcEventLog::Create(
RtcEventLog::EncodingType encoding_type,
TaskQueueFactory* task_queue_factory) {
diff --git a/logging/rtc_event_log/rtc_event_log_unittest.cc b/logging/rtc_event_log/rtc_event_log_unittest.cc
index 05d519b..2c57220 100644
--- a/logging/rtc_event_log/rtc_event_log_unittest.cc
+++ b/logging/rtc_event_log/rtc_event_log_unittest.cc
@@ -18,6 +18,7 @@
#include <vector>
#include "absl/memory/memory.h"
+#include "api/task_queue/default_task_queue_factory.h"
#include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
#include "logging/rtc_event_log/events/rtc_event_audio_playout.h"
#include "logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h"
@@ -40,6 +41,7 @@
#include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h"
#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
#include "logging/rtc_event_log/rtc_event_log.h"
+#include "logging/rtc_event_log/rtc_event_log_factory.h"
#include "logging/rtc_event_log/rtc_event_log_parser.h"
#include "logging/rtc_event_log/rtc_event_log_unittest_helper.h"
#include "logging/rtc_event_log/rtc_stream_config.h"
@@ -305,8 +307,11 @@
// TODO(terelius): Allow test to run with either a real or a fake clock_.
// Maybe always use the ScopedFakeClock, but conditionally SleepMs()?
+ auto task_queue_factory = CreateDefaultTaskQueueFactory();
+ RtcEventLogFactory rtc_event_log_factory(task_queue_factory.get());
// The log file will be flushed to disk when the event_log goes out of scope.
- std::unique_ptr<RtcEventLog> event_log(RtcEventLog::Create(encoding_type_));
+ std::unique_ptr<RtcEventLog> event_log =
+ rtc_event_log_factory.CreateRtcEventLog(encoding_type_);
// We can't send or receive packets without configured streams.
RTC_CHECK_GE(count.video_recv_streams, 1);
@@ -822,9 +827,12 @@
absl::make_unique<rtc::ScopedFakeClock>();
fake_clock->SetTimeMicros(kStartTime);
+ auto task_queue_factory = CreateDefaultTaskQueueFactory();
+ RtcEventLogFactory rtc_event_log_factory(task_queue_factory.get());
// When log_dumper goes out of scope, it causes the log file to be flushed
// to disk.
- std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(encoding_type_));
+ std::unique_ptr<RtcEventLog> log_dumper =
+ rtc_event_log_factory.CreateRtcEventLog(encoding_type_);
for (size_t i = 0; i < kNumEvents; i++) {
// The purpose of the test is to verify that the log can handle
diff --git a/video/BUILD.gn b/video/BUILD.gn
index ddcbaab..fffd582 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -256,6 +256,7 @@
"../call:simulated_network",
"../common_video",
"../logging:rtc_event_log_api",
+ "../logging:rtc_event_log_impl_base",
"../logging:rtc_event_log_impl_output",
"../media:rtc_audio_video",
"../media:rtc_encoder_simulcast_proxy",
diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc
index 5aead68..5c1a903 100644
--- a/video/video_quality_test.cc
+++ b/video/video_quality_test.cc
@@ -325,6 +325,7 @@
std::unique_ptr<InjectionComponents> injection_components)
: clock_(Clock::GetRealTimeClock()),
task_queue_factory_(CreateDefaultTaskQueueFactory()),
+ rtc_event_log_factory_(task_queue_factory_.get()),
video_decoder_factory_([this](const SdpVideoFormat& format) {
return this->CreateVideoDecoder(format);
}),
@@ -1177,8 +1178,10 @@
}
if (!params.logging.rtc_event_log_name.empty()) {
- send_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy);
- recv_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy);
+ send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
+ RtcEventLog::EncodingType::Legacy);
+ recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
+ RtcEventLog::EncodingType::Legacy);
std::unique_ptr<RtcEventLogOutputFile> send_output(
absl::make_unique<RtcEventLogOutputFile>(
params.logging.rtc_event_log_name + "_send",
@@ -1397,8 +1400,10 @@
std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers;
if (!params.logging.rtc_event_log_name.empty()) {
- send_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy);
- recv_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy);
+ send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
+ RtcEventLog::EncodingType::Legacy);
+ recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
+ RtcEventLog::EncodingType::Legacy);
std::unique_ptr<RtcEventLogOutputFile> send_output(
absl::make_unique<RtcEventLogOutputFile>(
params.logging.rtc_event_log_name + "_send",
diff --git a/video/video_quality_test.h b/video/video_quality_test.h
index b0f9036..bd871b7 100644
--- a/video/video_quality_test.h
+++ b/video/video_quality_test.h
@@ -20,6 +20,7 @@
#include "api/test/video_quality_test_fixture.h"
#include "api/video/video_bitrate_allocator_factory.h"
#include "call/fake_network_pipe.h"
+#include "logging/rtc_event_log/rtc_event_log_factory.h"
#include "media/engine/internal_decoder_factory.h"
#include "media/engine/internal_encoder_factory.h"
#include "test/call_test.h"
@@ -102,6 +103,7 @@
thumbnail_capturers_;
Clock* const clock_;
const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
+ RtcEventLogFactory rtc_event_log_factory_;
test::FunctionVideoDecoderFactory video_decoder_factory_;
InternalDecoderFactory internal_decoder_factory_;