diff --git a/api/BUILD.gn b/api/BUILD.gn index 6700a9531a..dc83db9cce 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -151,6 +151,7 @@ rtc_static_library("libjingle_peerconnection_api") { ":scoped_refptr", "audio:audio_mixer_api", "audio_codecs:audio_codecs_api", + "rtc_event_log", "task_queue", "transport:bitrate_settings", "transport:network_control", @@ -167,7 +168,6 @@ rtc_static_library("libjingle_peerconnection_api") { # targets like pnacl. API should not depend on anything outside of this # file, really. All these should arguably go away in time. "..:webrtc_common", - "../logging:rtc_event_log_api", "../media:rtc_media_config", "../modules/audio_processing:audio_processing_statistics", "../rtc_base", @@ -361,10 +361,10 @@ rtc_source_set("rtc_event_log_output_file") { deps = [ ":libjingle_logging_api", - "../logging:rtc_event_log_api", "../rtc_base:checks", "../rtc_base:rtc_base_approved", "../rtc_base/system:file_wrapper", + "rtc_event_log", ] } diff --git a/api/DEPS b/api/DEPS index 9c174a1eb6..32440b1c91 100644 --- a/api/DEPS +++ b/api/DEPS @@ -117,7 +117,6 @@ specific_include_rules = { ], "peer_connection_interface\.h": [ - "+logging/rtc_event_log/rtc_event_log_factory_interface.h", "+media/base/media_config.h", "+media/base/media_engine.h", "+p2p/base/port_allocator.h", diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h index 7cb0e8f4fd..bdada31343 100644 --- a/api/peer_connection_interface.h +++ b/api/peer_connection_interface.h @@ -85,6 +85,7 @@ #include "api/media_transport_interface.h" #include "api/network_state_predictor.h" #include "api/rtc_error.h" +#include "api/rtc_event_log/rtc_event_log_factory_interface.h" #include "api/rtc_event_log_output.h" #include "api/rtp_receiver_interface.h" #include "api/rtp_sender_interface.h" @@ -96,7 +97,6 @@ #include "api/transport/bitrate_settings.h" #include "api/transport/network_control.h" #include "api/turn_customizer.h" -#include "logging/rtc_event_log/rtc_event_log_factory_interface.h" #include "media/base/media_config.h" // TODO(bugs.webrtc.org/7447): We plan to provide a way to let applications // inject a PacketSocketFactory and/or NetworkManager, and not expose diff --git a/api/rtc_event_log/BUILD.gn b/api/rtc_event_log/BUILD.gn new file mode 100644 index 0000000000..70074938b2 --- /dev/null +++ b/api/rtc_event_log/BUILD.gn @@ -0,0 +1,49 @@ +# 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. + +import("../../webrtc.gni") + +rtc_source_set("rtc_event_log") { + visibility = [ "*" ] + sources = [ + "rtc_event.cc", + "rtc_event.h", + "rtc_event_log.cc", + "rtc_event_log.h", + "rtc_event_log_factory_interface.h", + ] + + deps = [ + "..:libjingle_logging_api", + "../../rtc_base:checks", + "../../rtc_base:deprecation", + "../../rtc_base:timeutils", + "../task_queue", + "//third_party/abseil-cpp/absl/memory", + ] +} + +rtc_source_set("rtc_event_log_factory") { + visibility = [ "*" ] + sources = [ + "rtc_event_log_factory.cc", + "rtc_event_log_factory.h", + ] + + deps = [ + ":rtc_event_log", + "../../rtc_base:checks", + "../task_queue", + "//third_party/abseil-cpp/absl/memory", + ] + + if (rtc_enable_protobuf) { + defines = [ "ENABLE_RTC_EVENT_LOG" ] + deps += [ "../../logging:rtc_event_log_impl" ] + } +} diff --git a/api/rtc_event_log/rtc_event.cc b/api/rtc_event_log/rtc_event.cc new file mode 100644 index 0000000000..81e6a4e6da --- /dev/null +++ b/api/rtc_event_log/rtc_event.cc @@ -0,0 +1,19 @@ +/* + * 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. + */ + +#include "api/rtc_event_log/rtc_event.h" + +#include "rtc_base/time_utils.h" + +namespace webrtc { + +RtcEvent::RtcEvent() : timestamp_us_(rtc::TimeMicros()) {} + +} // namespace webrtc diff --git a/api/rtc_event_log/rtc_event.h b/api/rtc_event_log/rtc_event.h new file mode 100644 index 0000000000..1b7fa5593a --- /dev/null +++ b/api/rtc_event_log/rtc_event.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017 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 API_RTC_EVENT_LOG_RTC_EVENT_H_ +#define API_RTC_EVENT_LOG_RTC_EVENT_H_ + +#include + +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(); + 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 + +#endif // API_RTC_EVENT_LOG_RTC_EVENT_H_ diff --git a/logging/rtc_event_log/rtc_event_log.cc b/api/rtc_event_log/rtc_event_log.cc similarity index 60% rename from logging/rtc_event_log/rtc_event_log.cc rename to api/rtc_event_log/rtc_event_log.cc index b48fe9234f..56189c0ff7 100644 --- a/logging/rtc_event_log/rtc_event_log.cc +++ b/api/rtc_event_log/rtc_event_log.cc @@ -8,19 +8,13 @@ * 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" +#include "api/rtc_event_log/rtc_event_log.h" namespace webrtc { -std::unique_ptr RtcEventLog::CreateNull() { - return absl::make_unique(); -} - -bool RtcEventLogNullImpl::StartLogging( - std::unique_ptr output, - int64_t output_period_ms) { +bool RtcEventLogNull::StartLogging( + std::unique_ptr /*output*/, + int64_t /*output_period_ms*/) { return false; } diff --git a/api/rtc_event_log/rtc_event_log.h b/api/rtc_event_log/rtc_event_log.h new file mode 100644 index 0000000000..5839f4b2b0 --- /dev/null +++ b/api/rtc_event_log/rtc_event_log.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015 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 API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ +#define API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ + +#include +#include +#include + +#include "absl/memory/memory.h" +#include "api/rtc_event_log/rtc_event.h" +#include "api/rtc_event_log_output.h" +#include "api/task_queue/task_queue_factory.h" +#include "rtc_base/deprecation.h" + +namespace webrtc { + +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 }; + + // Factory method to create an RtcEventLog object. + // Create RtcEventLog with an RtcEventLogFactory instead. + RTC_DEPRECATED + static std::unique_ptr Create( + EncodingType encoding_type, + TaskQueueFactory* task_queue_factory); + + // Create an RtcEventLog object that does nothing. + RTC_DEPRECATED + static std::unique_ptr CreateNull(); + + virtual ~RtcEventLog() = default; + + // 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 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 event) = 0; +}; + +// No-op implementation is used if flag is not set, or in tests. +class RtcEventLogNull final : public RtcEventLog { + public: + bool StartLogging(std::unique_ptr output, + int64_t output_period_ms) override; + void StopLogging() override {} + void Log(std::unique_ptr event) override {} +}; + +inline std::unique_ptr RtcEventLog::CreateNull() { + return absl::make_unique(); +} + +} // namespace webrtc + +#endif // API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ diff --git a/api/rtc_event_log/rtc_event_log_factory.cc b/api/rtc_event_log/rtc_event_log_factory.cc new file mode 100644 index 0000000000..188de15068 --- /dev/null +++ b/api/rtc_event_log/rtc_event_log_factory.cc @@ -0,0 +1,44 @@ +/* + * Copyright 2017 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 "api/rtc_event_log/rtc_event_log_factory.h" + +#include + +#include "absl/memory/memory.h" +#include "rtc_base/checks.h" + +#ifdef ENABLE_RTC_EVENT_LOG +#include "logging/rtc_event_log/rtc_event_log_impl.h" +#endif + +namespace webrtc { + +RtcEventLogFactory::RtcEventLogFactory(TaskQueueFactory* task_queue_factory) + : task_queue_factory_(task_queue_factory) { + RTC_DCHECK(task_queue_factory_); +} + +std::unique_ptr RtcEventLogFactory::CreateRtcEventLog( + RtcEventLog::EncodingType encoding_type) { +#ifdef ENABLE_RTC_EVENT_LOG + return absl::make_unique(encoding_type, task_queue_factory_); +#else + return absl::make_unique(); +#endif +} + +std::unique_ptr RtcEventLog::Create( + RtcEventLog::EncodingType encoding_type, + TaskQueueFactory* task_queue_factory) { + return RtcEventLogFactory(task_queue_factory) + .CreateRtcEventLog(encoding_type); +} +} // namespace webrtc diff --git a/api/rtc_event_log/rtc_event_log_factory.h b/api/rtc_event_log/rtc_event_log_factory.h new file mode 100644 index 0000000000..0efb1e5bb2 --- /dev/null +++ b/api/rtc_event_log/rtc_event_log_factory.h @@ -0,0 +1,36 @@ +/* + * Copyright 2017 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 API_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_H_ +#define API_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_H_ + +#include + +#include "api/rtc_event_log/rtc_event_log.h" +#include "api/rtc_event_log/rtc_event_log_factory_interface.h" +#include "api/task_queue/task_queue_factory.h" + +namespace webrtc { + +class RtcEventLogFactory : public RtcEventLogFactoryInterface { + public: + explicit RtcEventLogFactory(TaskQueueFactory* task_queue_factory); + ~RtcEventLogFactory() override {} + + std::unique_ptr CreateRtcEventLog( + RtcEventLog::EncodingType encoding_type) override; + + private: + TaskQueueFactory* const task_queue_factory_; +}; + +} // namespace webrtc + +#endif // API_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_H_ diff --git a/api/rtc_event_log/rtc_event_log_factory_interface.h b/api/rtc_event_log/rtc_event_log_factory_interface.h new file mode 100644 index 0000000000..acc5bcb038 --- /dev/null +++ b/api/rtc_event_log/rtc_event_log_factory_interface.h @@ -0,0 +1,33 @@ +/* + * Copyright 2017 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 API_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_INTERFACE_H_ +#define API_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_INTERFACE_H_ + +#include + +#include "api/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() = default; + + virtual std::unique_ptr CreateRtcEventLog( + RtcEventLog::EncodingType encoding_type) = 0; +}; + +} // namespace webrtc + +#endif // API_RTC_EVENT_LOG_RTC_EVENT_LOG_FACTORY_INTERFACE_H_ diff --git a/api/rtc_event_log_output_file.cc b/api/rtc_event_log_output_file.cc index 3845071c8e..c300a54fce 100644 --- a/api/rtc_event_log_output_file.cc +++ b/api/rtc_event_log_output_file.cc @@ -11,8 +11,8 @@ #include #include +#include "api/rtc_event_log/rtc_event_log.h" #include "api/rtc_event_log_output_file.h" -#include "logging/rtc_event_log/rtc_event_log.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" diff --git a/audio/test/media_transport_test.cc b/audio/test/media_transport_test.cc index 4594c3e585..5b2c554663 100644 --- a/audio/test/media_transport_test.cc +++ b/audio/test/media_transport_test.cc @@ -75,7 +75,7 @@ TEST(AudioWithMediaTransport, DeliversAudio) { MediaTransportPair transport_pair(transport_thread.get()); NiceMock rtcp_send_transport; NiceMock send_transport; - std::unique_ptr null_event_log = RtcEventLog::CreateNull(); + RtcEventLogNull null_event_log; NiceMock bitrate_allocator; rtc::scoped_refptr audio_device = @@ -114,7 +114,7 @@ TEST(AudioWithMediaTransport, DeliversAudio) { Clock::GetRealTimeClock(), /*receiver_controller=*/nullptr, /*packet_router=*/nullptr, receive_process_thread.get(), receive_config, - audio_state, null_event_log.get()); + audio_state, &null_event_log); // TODO(nisse): Update AudioSendStream to not require send_transport when a // MediaTransport is provided. @@ -128,13 +128,13 @@ TEST(AudioWithMediaTransport, DeliversAudio) { std::unique_ptr task_queue_factory = CreateDefaultTaskQueueFactory(); RtpTransportControllerSend rtp_transport( - Clock::GetRealTimeClock(), null_event_log.get(), nullptr, nullptr, + Clock::GetRealTimeClock(), &null_event_log, nullptr, nullptr, BitrateConstraints(), ProcessThread::Create("Pacer"), task_queue_factory.get()); webrtc::internal::AudioSendStream send_stream( Clock::GetRealTimeClock(), send_config, audio_state, task_queue_factory.get(), send_process_thread.get(), &rtp_transport, - &bitrate_allocator, null_event_log.get(), + &bitrate_allocator, &null_event_log, /*rtcp_rtt_stats=*/nullptr, absl::optional()); audio_device->Init(); // Starts thread. diff --git a/logging/BUILD.gn b/logging/BUILD.gn index 13f3f34fd6..ca1d2c9eba 100644 --- a/logging/BUILD.gn +++ b/logging/BUILD.gn @@ -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") { diff --git a/logging/rtc_event_log/events/rtc_event.h b/logging/rtc_event_log/events/rtc_event.h index c288bf37b9..23a2624a20 100644 --- a/logging/rtc_event_log/events/rtc_event.h +++ b/logging/rtc_event_log/events/rtc_event.h @@ -11,67 +11,9 @@ #ifndef LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_H_ #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_H_ -#include +// 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_ diff --git a/logging/rtc_event_log/events/rtc_event_generic_ack_received.cc b/logging/rtc_event_log/events/rtc_event_generic_ack_received.cc index bfdf2786c4..0ffe62259f 100644 --- a/logging/rtc_event_log/events/rtc_event_generic_ack_received.cc +++ b/logging/rtc_event_log/events/rtc_event_generic_ack_received.cc @@ -13,6 +13,7 @@ #include #include "absl/memory/memory.h" +#include "rtc_base/time_utils.h" namespace webrtc { diff --git a/logging/rtc_event_log/events/rtc_event_generic_ack_received.h b/logging/rtc_event_log/events/rtc_event_generic_ack_received.h index 79bcd34d83..59d75dbb69 100644 --- a/logging/rtc_event_log/events/rtc_event_generic_ack_received.h +++ b/logging/rtc_event_log/events/rtc_event_generic_ack_received.h @@ -16,6 +16,8 @@ #include #include +#include "absl/types/optional.h" + namespace webrtc { struct AckedPacket { diff --git a/logging/rtc_event_log/rtc_event_log.h b/logging/rtc_event_log/rtc_event_log.h index 08b5475610..2a088f6432 100644 --- a/logging/rtc_event_log/rtc_event_log.h +++ b/logging/rtc_event_log/rtc_event_log.h @@ -11,59 +11,13 @@ #ifndef LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ #define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ -#include -#include +// 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 Create( - EncodingType encoding_type, - TaskQueueFactory* task_queue_factory); - - // Create an RtcEventLog object that does nothing. - static std::unique_ptr 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 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 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 output, - int64_t output_period_ms) override; - void StopLogging() override {} - void Log(std::unique_ptr event) override {} -}; - +using RtcEventLogNullImpl = ::webrtc::RtcEventLogNull; } // namespace webrtc #endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ diff --git a/logging/rtc_event_log/rtc_event_log_factory.cc b/logging/rtc_event_log/rtc_event_log_factory.cc index b38b7bc52b..ff6e4e549a 100644 --- a/logging/rtc_event_log/rtc_event_log_factory.cc +++ b/logging/rtc_event_log/rtc_event_log_factory.cc @@ -10,25 +10,11 @@ #include "logging/rtc_event_log/rtc_event_log_factory.h" -#include - #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 RtcEventLogFactory::CreateRtcEventLog( - RtcEventLog::EncodingType encoding_type) { - return RtcEventLog::Create(encoding_type, task_queue_factory_); -} - std::unique_ptr CreateRtcEventLogFactory() { return absl::make_unique(&GlobalTaskQueueFactory()); } diff --git a/logging/rtc_event_log/rtc_event_log_factory.h b/logging/rtc_event_log/rtc_event_log_factory.h index 01e3994099..63b1b609c3 100644 --- a/logging/rtc_event_log/rtc_event_log_factory.h +++ b/logging/rtc_event_log/rtc_event_log_factory.h @@ -13,24 +13,11 @@ #include -#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 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 CreateRtcEventLogFactory(); } // namespace webrtc diff --git a/logging/rtc_event_log/rtc_event_log_factory_interface.h b/logging/rtc_event_log/rtc_event_log_factory_interface.h index 48ea3e568b..47078dffec 100644 --- a/logging/rtc_event_log/rtc_event_log_factory_interface.h +++ b/logging/rtc_event_log/rtc_event_log_factory_interface.h @@ -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 - -#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 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_ diff --git a/logging/rtc_event_log/rtc_event_log_impl.cc b/logging/rtc_event_log/rtc_event_log_impl.cc index c8c7c626ee..38e2ee7afd 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.cc +++ b/logging/rtc_event_log/rtc_event_log_impl.cc @@ -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 #include #include -#include #include #include #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 CreateEncoder( return std::unique_ptr(nullptr); } } +} // namespace -class RtcEventLogImpl final : public RtcEventLog { - public: - RtcEventLogImpl(std::unique_ptr event_encoder, - std::unique_ptr 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 output, - int64_t output_period_ms) override; - void StopLogging() override; - - void Log(std::unique_ptr event) override; - - private: - void LogToMemory(std::unique_ptr 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> config_history_ - RTC_GUARDED_BY(*task_queue_); - - // History containing the most recent (non-configuration) events (~10s). - std::deque> 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 event_encoder_ - RTC_GUARDED_BY(*task_queue_); - std::unique_ptr event_output_ RTC_GUARDED_BY(*task_queue_); - - size_t num_config_events_written_ RTC_GUARDED_BY(*task_queue_); - absl::optional 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 task_queue_; - - RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl); -}; - -RtcEventLogImpl::RtcEventLogImpl( - std::unique_ptr event_encoder, - std::unique_ptr task_queue) +RtcEventLogImpl::RtcEventLogImpl(RtcEventLog::EncodingType encoding_type, + TaskQueueFactory* task_queue_factory) : max_size_bytes_(std::numeric_limits::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(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::Create( - RtcEventLog::EncodingType encoding_type, - TaskQueueFactory* task_queue_factory) { -#ifdef ENABLE_RTC_EVENT_LOG - return absl::make_unique( - CreateEncoder(encoding_type), - absl::make_unique(task_queue_factory->CreateTaskQueue( - "rtc_event_log", TaskQueueFactory::Priority::NORMAL))); -#else - return CreateNull(); -#endif // ENABLE_RTC_EVENT_LOG -} - } // namespace webrtc diff --git a/logging/rtc_event_log/rtc_event_log_impl.h b/logging/rtc_event_log/rtc_event_log_impl.h new file mode 100644 index 0000000000..e1ba830b52 --- /dev/null +++ b/logging/rtc_event_log/rtc_event_log_impl.h @@ -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 +#include +#include +#include +#include + +#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 output, + int64_t output_period_ms) override; + void StopLogging() override; + + void Log(std::unique_ptr event) override; + + private: + void LogToMemory(std::unique_ptr 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> config_history_ + RTC_GUARDED_BY(*task_queue_); + + // History containing the most recent (non-configuration) events (~10s). + std::deque> 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 event_encoder_ + RTC_GUARDED_BY(*task_queue_); + std::unique_ptr event_output_ RTC_GUARDED_BY(*task_queue_); + + size_t num_config_events_written_ RTC_GUARDED_BY(*task_queue_); + absl::optional 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 task_queue_; +}; + +} // namespace webrtc + +#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_IMPL_H_ diff --git a/logging/rtc_event_log/rtc_event_log_parser.h b/logging/rtc_event_log/rtc_event_log_parser.h index 763c0861bf..03ea4868f6 100644 --- a/logging/rtc_event_log/rtc_event_log_parser.h +++ b/logging/rtc_event_log/rtc_event_log_parser.h @@ -39,6 +39,8 @@ RTC_POP_IGNORING_WUNDEF() namespace webrtc { +enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; + template class PacketView; diff --git a/test/call_test.cc b/test/call_test.cc index ffb7305fe8..1dd4c80765 100644 --- a/test/call_test.cc +++ b/test/call_test.cc @@ -32,8 +32,8 @@ namespace test { CallTest::CallTest() : clock_(Clock::GetRealTimeClock()), task_queue_factory_(CreateDefaultTaskQueueFactory()), - send_event_log_(RtcEventLog::CreateNull()), - recv_event_log_(RtcEventLog::CreateNull()), + send_event_log_(absl::make_unique()), + recv_event_log_(absl::make_unique()), audio_send_config_(/*send_transport=*/nullptr, MediaTransportConfig()), audio_send_stream_(nullptr), frame_generator_capturer_(nullptr), diff --git a/test/scenario/BUILD.gn b/test/scenario/BUILD.gn index 16f841fb6a..31c0db08e8 100644 --- a/test/scenario/BUILD.gn +++ b/test/scenario/BUILD.gn @@ -87,6 +87,8 @@ if (rtc_include_tests) { "../../api:transport_api", "../../api/audio_codecs:builtin_audio_decoder_factory", "../../api/audio_codecs:builtin_audio_encoder_factory", + "../../api/rtc_event_log", + "../../api/rtc_event_log:rtc_event_log_factory", "../../api/test/video:function_video_factory", "../../api/transport:network_control", "../../api/units:data_rate", @@ -105,7 +107,6 @@ if (rtc_include_tests) { "../../call:video_stream_api", "../../common_video", "../../logging:rtc_event_log_api", - "../../logging:rtc_event_log_impl_base", "../../media:rtc_audio_video", "../../media:rtc_internal_video_codecs", "../../media:rtc_media_base", diff --git a/test/scenario/call_client.cc b/test/scenario/call_client.cc index bc93a490f0..a710ad1973 100644 --- a/test/scenario/call_client.cc +++ b/test/scenario/call_client.cc @@ -12,6 +12,8 @@ #include #include "absl/memory/memory.h" +#include "api/rtc_event_log/rtc_event_log.h" +#include "api/rtc_event_log/rtc_event_log_factory.h" #include "modules/audio_mixer/audio_mixer_impl.h" namespace webrtc { @@ -74,10 +76,10 @@ std::unique_ptr CreateEventLog( TaskQueueFactory* task_queue_factory, LogWriterFactoryInterface* log_writer_factory) { if (!log_writer_factory) { - return RtcEventLog::CreateNull(); + return absl::make_unique(); } - auto event_log = RtcEventLog::Create(RtcEventLog::EncodingType::NewFormat, - task_queue_factory); + auto event_log = RtcEventLogFactory(task_queue_factory) + .CreateRtcEventLog(RtcEventLog::EncodingType::NewFormat); bool success = event_log->StartLogging(log_writer_factory->Create(".rtc.dat"), kEventLogOutputIntervalMs); RTC_CHECK(success); diff --git a/test/scenario/simulated_time.cc b/test/scenario/simulated_time.cc index efee9583ef..fa3ab3907f 100644 --- a/test/scenario/simulated_time.cc +++ b/test/scenario/simulated_time.cc @@ -15,7 +15,9 @@ #include #include +#include "absl/memory/memory.h" #include "absl/types/optional.h" +#include "api/rtc_event_log/rtc_event_log_factory.h" #include "rtc_base/checks.h" #include "rtc_base/socket_address.h" @@ -39,10 +41,10 @@ std::unique_ptr CreateEventLog( TaskQueueFactory* task_queue_factory, LogWriterFactoryInterface* log_writer_factory) { if (!log_writer_factory) { - return RtcEventLog::CreateNull(); + return absl::make_unique(); } - auto event_log = RtcEventLog::Create(RtcEventLog::EncodingType::NewFormat, - task_queue_factory); + auto event_log = RtcEventLogFactory(task_queue_factory) + .CreateRtcEventLog(RtcEventLog::EncodingType::NewFormat); bool success = event_log->StartLogging(log_writer_factory->Create(".rtc.dat"), kEventLogOutputIntervalMs); RTC_CHECK(success); diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc index be29714c6c..5415f96401 100644 --- a/video/video_quality_test.cc +++ b/video/video_quality_test.cc @@ -1222,8 +1222,8 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { RtcEventLog::kImmediateOutput); RTC_DCHECK(event_log_started); } else { - send_event_log_ = RtcEventLog::CreateNull(); - recv_event_log_ = RtcEventLog::CreateNull(); + send_event_log_ = absl::make_unique(); + recv_event_log_ = absl::make_unique(); } task_queue_.SendTask([this, ¶ms, &send_transport, &recv_transport]() { @@ -1443,8 +1443,8 @@ void VideoQualityTest::RunWithRenderers(const Params& params) { /*output_period_ms=*/5000); RTC_DCHECK(event_log_started); } else { - send_event_log_ = RtcEventLog::CreateNull(); - recv_event_log_ = RtcEventLog::CreateNull(); + send_event_log_ = absl::make_unique(); + recv_event_log_ = absl::make_unique(); } task_queue_.SendTask([&]() {