Publish rtc event log api and default factory for it in api/
Bug: webrtc:10206 Change-Id: I34194ddb6fd2b0a3d7c553fadc9ddc1ea9740da0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/137500 Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28023}
This commit is contained in:
committed by
Commit Bot
parent
23aff9b737
commit
b32f2c7f57
@ -31,7 +31,6 @@ rtc_source_set("rtc_event_log_api") {
|
||||
sources = [
|
||||
"rtc_event_log/encoder/rtc_event_log_encoder.h",
|
||||
"rtc_event_log/events/rtc_event.h",
|
||||
"rtc_event_log/rtc_event_log.cc",
|
||||
"rtc_event_log/rtc_event_log.h",
|
||||
"rtc_event_log/rtc_event_log_factory_interface.h",
|
||||
]
|
||||
@ -39,6 +38,7 @@ rtc_source_set("rtc_event_log_api") {
|
||||
deps = [
|
||||
"../api:libjingle_logging_api",
|
||||
"../api:scoped_refptr",
|
||||
"../api/rtc_event_log",
|
||||
"../api/task_queue",
|
||||
"../rtc_base:rtc_base_approved",
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
@ -129,7 +129,9 @@ rtc_source_set("rtc_event_generic_packet_events") {
|
||||
]
|
||||
deps = [
|
||||
":rtc_event_log_api",
|
||||
"../rtc_base:timeutils",
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
|
||||
@ -239,37 +241,46 @@ rtc_source_set("rtc_event_log_impl_output") {
|
||||
]
|
||||
}
|
||||
|
||||
if (rtc_enable_protobuf) {
|
||||
rtc_source_set("rtc_event_log_impl") {
|
||||
visibility = [ "../api/rtc_event_log:rtc_event_log_factory" ]
|
||||
sources = [
|
||||
"rtc_event_log/rtc_event_log_impl.cc",
|
||||
"rtc_event_log/rtc_event_log_impl.h",
|
||||
]
|
||||
deps = [
|
||||
":ice_log",
|
||||
":rtc_event_log_api",
|
||||
":rtc_event_log_impl_encoder",
|
||||
"../api:libjingle_logging_api",
|
||||
"../api/rtc_event_log",
|
||||
"../api/task_queue",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:rtc_base_approved",
|
||||
"../rtc_base:rtc_task_queue",
|
||||
"../rtc_base:safe_minmax",
|
||||
"../rtc_base/synchronization:sequence_checker",
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
rtc_static_library("rtc_event_log_impl_base") {
|
||||
# TODO(terelius): Should this really be visible? Currently used to instantiate
|
||||
# the default event log factory.
|
||||
# TODO(bugs.webrtc.org/10206): Remove this target when all users switch to
|
||||
# using target api/rtc_event_log:rtc_event_log_factory directly.
|
||||
visibility = [ "*" ]
|
||||
sources = [
|
||||
"rtc_event_log/rtc_event_log_factory.cc",
|
||||
"rtc_event_log/rtc_event_log_factory.h",
|
||||
"rtc_event_log/rtc_event_log_impl.cc",
|
||||
]
|
||||
|
||||
defines = []
|
||||
|
||||
deps = [
|
||||
":ice_log",
|
||||
":rtc_event_log_api",
|
||||
"../api:libjingle_logging_api",
|
||||
"../api/task_queue",
|
||||
"../api/rtc_event_log",
|
||||
"../api/rtc_event_log:rtc_event_log_factory",
|
||||
"../api/task_queue:global_task_queue_factory",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:rtc_base_approved",
|
||||
"../rtc_base:rtc_task_queue",
|
||||
"../rtc_base:safe_minmax",
|
||||
"../rtc_base/synchronization:sequence_checker",
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
|
||||
if (rtc_enable_protobuf) {
|
||||
defines += [ "ENABLE_RTC_EVENT_LOG" ]
|
||||
deps += [ ":rtc_event_log_impl_encoder" ]
|
||||
}
|
||||
}
|
||||
|
||||
rtc_source_set("fake_rtc_event_log") {
|
||||
|
||||
@ -11,67 +11,9 @@
|
||||
#ifndef LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_H_
|
||||
#define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_H_
|
||||
|
||||
#include <memory>
|
||||
// TODO(bugs.webrtc.org/10206): For backwards compatibility; Delete as soon as
|
||||
// dependencies are updated.
|
||||
|
||||
#include "rtc_base/time_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// This class allows us to store unencoded RTC events. Subclasses of this class
|
||||
// store the actual information. This allows us to keep all unencoded events,
|
||||
// even when their type and associated information differ, in the same buffer.
|
||||
// Additionally, it prevents dependency leaking - a module that only logs
|
||||
// events of type RtcEvent_A doesn't need to know about anything associated
|
||||
// with events of type RtcEvent_B.
|
||||
class RtcEvent {
|
||||
public:
|
||||
// Subclasses of this class have to associate themselves with a unique value
|
||||
// of Type. This leaks the information of existing subclasses into the
|
||||
// superclass, but the *actual* information - rtclog::StreamConfig, etc. -
|
||||
// is kept separate.
|
||||
enum class Type {
|
||||
AlrStateEvent,
|
||||
RouteChangeEvent,
|
||||
AudioNetworkAdaptation,
|
||||
AudioPlayout,
|
||||
AudioReceiveStreamConfig,
|
||||
AudioSendStreamConfig,
|
||||
BweUpdateDelayBased,
|
||||
BweUpdateLossBased,
|
||||
DtlsTransportState,
|
||||
DtlsWritableState,
|
||||
IceCandidatePairConfig,
|
||||
IceCandidatePairEvent,
|
||||
ProbeClusterCreated,
|
||||
ProbeResultFailure,
|
||||
ProbeResultSuccess,
|
||||
RtcpPacketIncoming,
|
||||
RtcpPacketOutgoing,
|
||||
RtpPacketIncoming,
|
||||
RtpPacketOutgoing,
|
||||
VideoReceiveStreamConfig,
|
||||
VideoSendStreamConfig,
|
||||
GenericPacketSent,
|
||||
GenericPacketReceived,
|
||||
GenericAckReceived
|
||||
};
|
||||
|
||||
RtcEvent() : timestamp_us_(rtc::TimeMicros()) {}
|
||||
virtual ~RtcEvent() = default;
|
||||
|
||||
virtual Type GetType() const = 0;
|
||||
|
||||
virtual bool IsConfigEvent() const = 0;
|
||||
|
||||
int64_t timestamp_ms() const { return timestamp_us_ / 1000; }
|
||||
int64_t timestamp_us() const { return timestamp_us_; }
|
||||
|
||||
protected:
|
||||
explicit RtcEvent(int64_t timestamp_us) : timestamp_us_(timestamp_us) {}
|
||||
|
||||
const int64_t timestamp_us_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
#include "api/rtc_event_log/rtc_event.h"
|
||||
|
||||
#endif // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_H_
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
struct AckedPacket {
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "logging/rtc_event_log/rtc_event_log.h"
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() {
|
||||
return absl::make_unique<RtcEventLogNullImpl>();
|
||||
}
|
||||
|
||||
bool RtcEventLogNullImpl::StartLogging(
|
||||
std::unique_ptr<RtcEventLogOutput> output,
|
||||
int64_t output_period_ms) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -11,59 +11,13 @@
|
||||
#ifndef LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
|
||||
#define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
// TODO(bugs.webrtc.org/10206): For backwards compatibility; Delete as soon as
|
||||
// dependencies are updated.
|
||||
|
||||
#include "api/rtc_event_log_output.h"
|
||||
#include "api/task_queue/task_queue_factory.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event.h"
|
||||
#include "api/rtc_event_log/rtc_event_log.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// TODO(terelius): Move this to the parser.
|
||||
enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
|
||||
|
||||
class RtcEventLog {
|
||||
public:
|
||||
enum : size_t { kUnlimitedOutput = 0 };
|
||||
enum : int64_t { kImmediateOutput = 0 };
|
||||
|
||||
// TODO(eladalon): Get rid of the legacy encoding and this enum once all
|
||||
// clients have migrated to the new format.
|
||||
enum class EncodingType { Legacy, NewFormat };
|
||||
|
||||
virtual ~RtcEventLog() {}
|
||||
|
||||
// Factory method to create an RtcEventLog object.
|
||||
static std::unique_ptr<RtcEventLog> Create(
|
||||
EncodingType encoding_type,
|
||||
TaskQueueFactory* task_queue_factory);
|
||||
|
||||
// Create an RtcEventLog object that does nothing.
|
||||
static std::unique_ptr<RtcEventLog> CreateNull();
|
||||
|
||||
// Starts logging to a given output. The output might be limited in size,
|
||||
// and may close itself once it has reached the maximum size.
|
||||
virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
|
||||
int64_t output_period_ms) = 0;
|
||||
|
||||
// Stops logging to file and waits until the file has been closed, after
|
||||
// which it would be permissible to read and/or modify it.
|
||||
virtual void StopLogging() = 0;
|
||||
|
||||
// Log an RTC event (the type of event is determined by the subclass).
|
||||
virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
|
||||
};
|
||||
|
||||
// No-op implementation is used if flag is not set, or in tests.
|
||||
class RtcEventLogNullImpl : public RtcEventLog {
|
||||
public:
|
||||
bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
|
||||
int64_t output_period_ms) override;
|
||||
void StopLogging() override {}
|
||||
void Log(std::unique_ptr<RtcEvent> event) override {}
|
||||
};
|
||||
|
||||
using RtcEventLogNullImpl = ::webrtc::RtcEventLogNull;
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
|
||||
|
||||
@ -10,25 +10,11 @@
|
||||
|
||||
#include "logging/rtc_event_log/rtc_event_log_factory.h"
|
||||
|
||||
#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, task_queue_factory_);
|
||||
}
|
||||
|
||||
std::unique_ptr<RtcEventLogFactoryInterface> CreateRtcEventLogFactory() {
|
||||
return absl::make_unique<RtcEventLogFactory>(&GlobalTaskQueueFactory());
|
||||
}
|
||||
|
||||
@ -13,24 +13,11 @@
|
||||
|
||||
#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"
|
||||
#include "api/rtc_event_log/rtc_event_log_factory.h"
|
||||
#include "api/rtc_event_log/rtc_event_log_factory_interface.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
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
|
||||
|
||||
@ -11,23 +11,8 @@
|
||||
#ifndef LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_INTERFACE_H_
|
||||
#define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_INTERFACE_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "logging/rtc_event_log/rtc_event_log.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// This interface exists to allow webrtc to be optionally built without
|
||||
// RtcEventLog support. A PeerConnectionFactory is constructed with an
|
||||
// RtcEventLogFactoryInterface, which may or may not be null.
|
||||
class RtcEventLogFactoryInterface {
|
||||
public:
|
||||
virtual ~RtcEventLogFactoryInterface() {}
|
||||
|
||||
virtual std::unique_ptr<RtcEventLog> CreateRtcEventLog(
|
||||
RtcEventLog::EncodingType encoding_type) = 0;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
// TODO(bugs.webrtc.org/10206): For backwards compatibility; Delete as soon as
|
||||
// dependencies are updated.
|
||||
#include "api/rtc_event_log/rtc_event_log_factory_interface.h"
|
||||
|
||||
#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_INTERFACE_H_
|
||||
|
||||
@ -8,18 +8,15 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "logging/rtc_event_log/rtc_event_log.h"
|
||||
#include "logging/rtc_event_log/rtc_event_log_impl.h"
|
||||
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/rtc_event_log_output.h"
|
||||
#include "api/task_queue/queued_task.h"
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h"
|
||||
@ -30,15 +27,9 @@
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/numerics/safe_conversions.h"
|
||||
#include "rtc_base/numerics/safe_minmax.h"
|
||||
#include "rtc_base/synchronization/sequence_checker.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
#ifdef ENABLE_RTC_EVENT_LOG
|
||||
|
||||
namespace {
|
||||
constexpr size_t kMaxEventsInHistory = 10000;
|
||||
// The config-history is supposed to be unbounded, but needs to have some bound
|
||||
@ -81,77 +72,20 @@ std::unique_ptr<RtcEventLogEncoder> CreateEncoder(
|
||||
return std::unique_ptr<RtcEventLogEncoder>(nullptr);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
class RtcEventLogImpl final : public RtcEventLog {
|
||||
public:
|
||||
RtcEventLogImpl(std::unique_ptr<RtcEventLogEncoder> event_encoder,
|
||||
std::unique_ptr<rtc::TaskQueue> task_queue);
|
||||
|
||||
~RtcEventLogImpl() override;
|
||||
|
||||
// TODO(eladalon): We should change these name to reflect that what we're
|
||||
// actually starting/stopping is the output of the log, not the log itself.
|
||||
bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
|
||||
int64_t output_period_ms) override;
|
||||
void StopLogging() override;
|
||||
|
||||
void Log(std::unique_ptr<RtcEvent> event) override;
|
||||
|
||||
private:
|
||||
void LogToMemory(std::unique_ptr<RtcEvent> event) RTC_RUN_ON(task_queue_);
|
||||
void LogEventsFromMemoryToOutput() RTC_RUN_ON(task_queue_);
|
||||
|
||||
void StopOutput() RTC_RUN_ON(task_queue_);
|
||||
|
||||
void WriteConfigsAndHistoryToOutput(const std::string& encoded_configs,
|
||||
const std::string& encoded_history)
|
||||
RTC_RUN_ON(task_queue_);
|
||||
void WriteToOutput(const std::string& output_string) RTC_RUN_ON(task_queue_);
|
||||
|
||||
void StopLoggingInternal() RTC_RUN_ON(task_queue_);
|
||||
|
||||
void ScheduleOutput() RTC_RUN_ON(task_queue_);
|
||||
|
||||
// History containing all past configuration events.
|
||||
std::deque<std::unique_ptr<RtcEvent>> config_history_
|
||||
RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
// History containing the most recent (non-configuration) events (~10s).
|
||||
std::deque<std::unique_ptr<RtcEvent>> history_ RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
size_t max_size_bytes_ RTC_GUARDED_BY(*task_queue_);
|
||||
size_t written_bytes_ RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
std::unique_ptr<RtcEventLogEncoder> event_encoder_
|
||||
RTC_GUARDED_BY(*task_queue_);
|
||||
std::unique_ptr<RtcEventLogOutput> event_output_ RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
size_t num_config_events_written_ RTC_GUARDED_BY(*task_queue_);
|
||||
absl::optional<int64_t> output_period_ms_ RTC_GUARDED_BY(*task_queue_);
|
||||
int64_t last_output_ms_ RTC_GUARDED_BY(*task_queue_);
|
||||
bool output_scheduled_ RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
// Since we are posting tasks bound to |this|, it is critical that the event
|
||||
// log and it's members outlive the |task_queue_|. Keep the "task_queue_|
|
||||
// last to ensure it destructs first, or else tasks living on the queue might
|
||||
// access other members after they've been torn down.
|
||||
std::unique_ptr<rtc::TaskQueue> task_queue_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl);
|
||||
};
|
||||
|
||||
RtcEventLogImpl::RtcEventLogImpl(
|
||||
std::unique_ptr<RtcEventLogEncoder> event_encoder,
|
||||
std::unique_ptr<rtc::TaskQueue> task_queue)
|
||||
RtcEventLogImpl::RtcEventLogImpl(RtcEventLog::EncodingType encoding_type,
|
||||
TaskQueueFactory* task_queue_factory)
|
||||
: max_size_bytes_(std::numeric_limits<decltype(max_size_bytes_)>::max()),
|
||||
written_bytes_(0),
|
||||
event_encoder_(std::move(event_encoder)),
|
||||
event_encoder_(CreateEncoder(encoding_type)),
|
||||
num_config_events_written_(0),
|
||||
last_output_ms_(rtc::TimeMillis()),
|
||||
output_scheduled_(false),
|
||||
task_queue_(std::move(task_queue)) {
|
||||
RTC_DCHECK(task_queue_);
|
||||
}
|
||||
task_queue_(
|
||||
absl::make_unique<rtc::TaskQueue>(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.
|
||||
@ -361,22 +295,4 @@ void RtcEventLogImpl::WriteToOutput(const std::string& output_string) {
|
||||
written_bytes_ += output_string.size();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // ENABLE_RTC_EVENT_LOG
|
||||
|
||||
// RtcEventLog member functions.
|
||||
std::unique_ptr<RtcEventLog> RtcEventLog::Create(
|
||||
RtcEventLog::EncodingType encoding_type,
|
||||
TaskQueueFactory* task_queue_factory) {
|
||||
#ifdef ENABLE_RTC_EVENT_LOG
|
||||
return absl::make_unique<RtcEventLogImpl>(
|
||||
CreateEncoder(encoding_type),
|
||||
absl::make_unique<rtc::TaskQueue>(task_queue_factory->CreateTaskQueue(
|
||||
"rtc_event_log", TaskQueueFactory::Priority::NORMAL)));
|
||||
#else
|
||||
return CreateNull();
|
||||
#endif // ENABLE_RTC_EVENT_LOG
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
92
logging/rtc_event_log/rtc_event_log_impl.h
Normal file
92
logging/rtc_event_log/rtc_event_log_impl.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_IMPL_H_
|
||||
#define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_IMPL_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/rtc_event_log/rtc_event.h"
|
||||
#include "api/rtc_event_log/rtc_event_log.h"
|
||||
#include "api/rtc_event_log_output.h"
|
||||
#include "api/task_queue/task_queue_factory.h"
|
||||
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder.h"
|
||||
#include "rtc_base/synchronization/sequence_checker.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class RtcEventLogImpl final : public RtcEventLog {
|
||||
public:
|
||||
RtcEventLogImpl(EncodingType encoding_type,
|
||||
TaskQueueFactory* task_queue_factory);
|
||||
RtcEventLogImpl(const RtcEventLogImpl&) = delete;
|
||||
RtcEventLogImpl& operator=(const RtcEventLogImpl&) = delete;
|
||||
|
||||
~RtcEventLogImpl() override;
|
||||
|
||||
// TODO(eladalon): We should change these name to reflect that what we're
|
||||
// actually starting/stopping is the output of the log, not the log itself.
|
||||
bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
|
||||
int64_t output_period_ms) override;
|
||||
void StopLogging() override;
|
||||
|
||||
void Log(std::unique_ptr<RtcEvent> event) override;
|
||||
|
||||
private:
|
||||
void LogToMemory(std::unique_ptr<RtcEvent> event) RTC_RUN_ON(task_queue_);
|
||||
void LogEventsFromMemoryToOutput() RTC_RUN_ON(task_queue_);
|
||||
|
||||
void StopOutput() RTC_RUN_ON(task_queue_);
|
||||
|
||||
void WriteConfigsAndHistoryToOutput(const std::string& encoded_configs,
|
||||
const std::string& encoded_history)
|
||||
RTC_RUN_ON(task_queue_);
|
||||
void WriteToOutput(const std::string& output_string) RTC_RUN_ON(task_queue_);
|
||||
|
||||
void StopLoggingInternal() RTC_RUN_ON(task_queue_);
|
||||
|
||||
void ScheduleOutput() RTC_RUN_ON(task_queue_);
|
||||
|
||||
// History containing all past configuration events.
|
||||
std::deque<std::unique_ptr<RtcEvent>> config_history_
|
||||
RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
// History containing the most recent (non-configuration) events (~10s).
|
||||
std::deque<std::unique_ptr<RtcEvent>> history_ RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
size_t max_size_bytes_ RTC_GUARDED_BY(*task_queue_);
|
||||
size_t written_bytes_ RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
std::unique_ptr<RtcEventLogEncoder> event_encoder_
|
||||
RTC_GUARDED_BY(*task_queue_);
|
||||
std::unique_ptr<RtcEventLogOutput> event_output_ RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
size_t num_config_events_written_ RTC_GUARDED_BY(*task_queue_);
|
||||
absl::optional<int64_t> output_period_ms_ RTC_GUARDED_BY(*task_queue_);
|
||||
int64_t last_output_ms_ RTC_GUARDED_BY(*task_queue_);
|
||||
bool output_scheduled_ RTC_GUARDED_BY(*task_queue_);
|
||||
|
||||
// Since we are posting tasks bound to |this|, it is critical that the event
|
||||
// log and its members outlive |task_queue_|. Keep the |task_queue_|
|
||||
// last to ensure it destructs first, or else tasks living on the queue might
|
||||
// access other members after they've been torn down.
|
||||
std::unique_ptr<rtc::TaskQueue> task_queue_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_IMPL_H_
|
||||
@ -39,6 +39,8 @@ RTC_POP_IGNORING_WUNDEF()
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
|
||||
|
||||
template <typename T>
|
||||
class PacketView;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user