From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- .../logging/rtc_event_log/rtc_event_log_impl.cc | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc') diff --git a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc index f2b3f22d6a..419afd330a 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc @@ -17,6 +17,8 @@ #include #include "absl/strings/string_view.h" +#include "api/environment/environment.h" +#include "api/field_trials_view.h" #include "api/task_queue/task_queue_base.h" #include "api/units/time_delta.h" #include "logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h" @@ -29,24 +31,23 @@ #include "rtc_base/time_utils.h" namespace webrtc { +namespace { -std::unique_ptr RtcEventLogImpl::CreateEncoder( - RtcEventLog::EncodingType type) { - switch (type) { - case RtcEventLog::EncodingType::Legacy: - RTC_DLOG(LS_INFO) << "Creating legacy encoder for RTC event log."; - return std::make_unique(); - case RtcEventLog::EncodingType::NewFormat: - RTC_DLOG(LS_INFO) << "Creating new format encoder for RTC event log."; - return std::make_unique(); - default: - RTC_LOG(LS_ERROR) << "Unknown RtcEventLog encoder type (" << int(type) - << ")"; - RTC_DCHECK_NOTREACHED(); - return std::unique_ptr(nullptr); +std::unique_ptr CreateEncoder(const Environment& env) { + if (env.field_trials().IsDisabled("WebRTC-RtcEventLogNewFormat")) { + RTC_DLOG(LS_INFO) << "Creating legacy encoder for RTC event log."; + return std::make_unique(); + } else { + RTC_DLOG(LS_INFO) << "Creating new format encoder for RTC event log."; + return std::make_unique(); } } +} // namespace + +RtcEventLogImpl::RtcEventLogImpl(const Environment& env) + : RtcEventLogImpl(CreateEncoder(env), &env.task_queue_factory()) {} + RtcEventLogImpl::RtcEventLogImpl(std::unique_ptr encoder, TaskQueueFactory* task_queue_factory, size_t max_events_in_history, @@ -55,10 +56,9 @@ RtcEventLogImpl::RtcEventLogImpl(std::unique_ptr encoder, max_config_events_in_history_(max_config_events_in_history), event_encoder_(std::move(encoder)), last_output_ms_(rtc::TimeMillis()), - task_queue_( - std::make_unique(task_queue_factory->CreateTaskQueue( - "rtc_event_log", - TaskQueueFactory::Priority::NORMAL))) {} + task_queue_(task_queue_factory->CreateTaskQueue( + "rtc_event_log", + TaskQueueFactory::Priority::NORMAL)) {} RtcEventLogImpl::~RtcEventLogImpl() { // If we're logging to the output, this will stop that. Blocking function. @@ -71,10 +71,12 @@ RtcEventLogImpl::~RtcEventLogImpl() { StopLogging(); } - // We want to block on any executing task by invoking ~TaskQueue() before + // Since we are posting tasks bound to `this`, it is critical that the event + // log and its members outlive `task_queue_`. Destruct `task_queue_` first + // to ensure tasks living on the queue can access other members. + // We want to block on any executing task by deleting TaskQueue before // we set unique_ptr's internal pointer to null. - rtc::TaskQueue* tq = task_queue_.get(); - delete tq; + task_queue_.get_deleter()(task_queue_.get()); task_queue_.release(); } -- cgit v1.2.3