| Index: webrtc/logging/rtc_event_log/rtc_event_log.cc
|
| diff --git a/webrtc/logging/rtc_event_log/rtc_event_log.cc b/webrtc/logging/rtc_event_log/rtc_event_log.cc
|
| index 3c2b00a5c3ae33bb8158946f9f66560c9f805073..518fc305d9cbfed0fb60370309032b1dad3d9461 100644
|
| --- a/webrtc/logging/rtc_event_log/rtc_event_log.cc
|
| +++ b/webrtc/logging/rtc_event_log/rtc_event_log.cc
|
| @@ -18,7 +18,27 @@
|
| #include <utility>
|
| #include <vector>
|
|
|
| +#include "webrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h"
|
| +// TODO(eladalon): Remove events/* when the deprecated functions are removed.
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_audio_playout.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_audio_send_stream_config.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_bwe_update_delay_based.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_bwe_update_loss_based.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_logging_started.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_logging_stopped.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_probe_cluster_created.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_probe_result_failure.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_probe_result_success.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_rtcp_packet_incoming.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_rtp_packet_incoming.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h"
|
| +#include "webrtc/logging/rtc_event_log/events/rtc_event_video_send_stream_config.h"
|
| #include "webrtc/logging/rtc_event_log/rtc_stream_config.h"
|
| +// TODO(eladalon): Remove these when deprecated functions are removed.
|
| #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h"
|
| #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
|
| #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
| @@ -38,7 +58,6 @@
|
| #include "webrtc/rtc_base/checks.h"
|
| #include "webrtc/rtc_base/constructormagic.h"
|
| #include "webrtc/rtc_base/event.h"
|
| -#include "webrtc/rtc_base/ignore_wundef.h"
|
| #include "webrtc/rtc_base/logging.h"
|
| #include "webrtc/rtc_base/protobuf_utils.h"
|
| #include "webrtc/rtc_base/ptr_util.h"
|
| @@ -46,20 +65,10 @@
|
| #include "webrtc/rtc_base/task_queue.h"
|
| #include "webrtc/rtc_base/thread_annotations.h"
|
| #include "webrtc/rtc_base/timeutils.h"
|
| +// TODO(eladalon): Remove this when output is modularized away.
|
| #include "webrtc/system_wrappers/include/file_wrapper.h"
|
| #include "webrtc/typedefs.h"
|
|
|
| -#ifdef ENABLE_RTC_EVENT_LOG
|
| -// *.pb.h files are generated at build-time by the protobuf compiler.
|
| -RTC_PUSH_IGNORING_WUNDEF()
|
| -#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
|
| -#include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h"
|
| -#else
|
| -#include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h"
|
| -#endif
|
| -RTC_POP_IGNORING_WUNDEF()
|
| -#endif
|
| -
|
| namespace webrtc {
|
|
|
| #ifdef ENABLE_RTC_EVENT_LOG
|
| @@ -67,14 +76,6 @@ namespace webrtc {
|
| namespace {
|
| const int kEventsInHistory = 10000;
|
|
|
| -bool IsConfigEvent(const rtclog::Event& event) {
|
| - rtclog::Event_EventType event_type = event.type();
|
| - return event_type == rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT ||
|
| - event_type == rtclog::Event::VIDEO_SENDER_CONFIG_EVENT ||
|
| - event_type == rtclog::Event::AUDIO_RECEIVER_CONFIG_EVENT ||
|
| - event_type == rtclog::Event::AUDIO_SENDER_CONFIG_EVENT;
|
| -}
|
| -
|
| // Observe a limit on the number of concurrent logs, so as not to run into
|
| // OS-imposed limits on open files and/or threads/task-queues.
|
| // TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|.
|
| @@ -99,11 +100,21 @@ class ResourceOwningTask final : public rtc::QueuedTask {
|
| std::unique_ptr<T> resource_;
|
| std::function<void(std::unique_ptr<T>)> handler_;
|
| };
|
| +
|
| +std::unique_ptr<RtcEventLogEncoder> CreateEncoder(EncodingType type) {
|
| + switch (type) {
|
| + case EncodingType::Legacy:
|
| + return rtc::MakeUnique<RtcEventLogEncoderLegacy>();
|
| + default:
|
| + LOG(LS_ERROR) << "Unknown RtcEventLog encoder type (" << int(type) << ")";
|
| + RTC_NOTREACHED();
|
| + }
|
| +}
|
| } // namespace
|
|
|
| class RtcEventLogImpl final : public RtcEventLog {
|
| public:
|
| - RtcEventLogImpl();
|
| + explicit RtcEventLogImpl(std::unique_ptr<RtcEventLogEncoder> event_encoder);
|
| ~RtcEventLogImpl() override;
|
|
|
| bool StartLogging(const std::string& file_name,
|
| @@ -111,6 +122,7 @@ class RtcEventLogImpl final : public RtcEventLog {
|
| bool StartLogging(rtc::PlatformFile platform_file,
|
| int64_t max_size_bytes) override;
|
| void StopLogging() override;
|
| + void Log(std::unique_ptr<RtcEvent> event) override;
|
| void LogVideoReceiveStreamConfig(const rtclog::StreamConfig& config) override;
|
| void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override;
|
| void LogAudioReceiveStreamConfig(const rtclog::StreamConfig& config) override;
|
| @@ -156,21 +168,17 @@ class RtcEventLogImpl final : public RtcEventLog {
|
| void StartLoggingInternal(std::unique_ptr<FileWrapper> file,
|
| int64_t max_size_bytes);
|
|
|
| - void StoreEvent(std::unique_ptr<rtclog::Event> event);
|
| - void LogProbeResult(int id,
|
| - rtclog::BweProbeResult::ResultType result,
|
| - int bitrate_bps);
|
| -
|
| // Appends an event to the output protobuf string, returning true on success.
|
| // Fails and returns false in case the limit on output size prevents the
|
| // event from being added; in this case, the output string is left unchanged.
|
| - bool AppendEventToString(rtclog::Event* event,
|
| + // The event is encoded before being appended.
|
| + bool AppendEventToString(const RtcEvent& event,
|
| ProtoString* output_string) RTC_WARN_UNUSED_RESULT;
|
|
|
| - void LogToMemory(std::unique_ptr<rtclog::Event> event);
|
| + void LogToMemory(std::unique_ptr<RtcEvent> event);
|
|
|
| void StartLogFile();
|
| - void LogToFile(std::unique_ptr<rtclog::Event> event);
|
| + void LogToFile(std::unique_ptr<RtcEvent> event);
|
| void StopLogFile(int64_t stop_time);
|
|
|
| // Make sure that the event log is "managed" - created/destroyed, as well
|
| @@ -178,18 +186,19 @@ class RtcEventLogImpl final : public RtcEventLog {
|
| rtc::SequencedTaskChecker owner_sequence_checker_;
|
|
|
| // History containing all past configuration events.
|
| - std::vector<std::unique_ptr<rtclog::Event>> config_history_
|
| + std::vector<std::unique_ptr<RtcEvent>> config_history_
|
| RTC_ACCESS_ON(task_queue_);
|
|
|
| // History containing the most recent (non-configuration) events (~10s).
|
| - std::deque<std::unique_ptr<rtclog::Event>> history_
|
| - RTC_ACCESS_ON(task_queue_);
|
| + std::deque<std::unique_ptr<RtcEvent>> history_ RTC_ACCESS_ON(task_queue_);
|
|
|
| std::unique_ptr<FileWrapper> file_ RTC_ACCESS_ON(task_queue_);
|
|
|
| size_t max_size_bytes_ RTC_ACCESS_ON(task_queue_);
|
| size_t written_bytes_ RTC_ACCESS_ON(task_queue_);
|
|
|
| + std::unique_ptr<RtcEventLogEncoder> event_encoder_ RTC_ACCESS_ON(task_queue_);
|
| +
|
| // Keep this last to ensure it destructs first, or else tasks living on the
|
| // queue might access other members after they've been torn down.
|
| rtc::TaskQueue task_queue_;
|
| @@ -197,59 +206,12 @@ class RtcEventLogImpl final : public RtcEventLog {
|
| RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl);
|
| };
|
|
|
| -namespace {
|
| -// The functions in this namespace convert enums from the runtime format
|
| -// that the rest of the WebRtc project can use, to the corresponding
|
| -// serialized enum which is defined by the protobuf.
|
| -
|
| -rtclog::VideoReceiveConfig_RtcpMode ConvertRtcpMode(RtcpMode rtcp_mode) {
|
| - switch (rtcp_mode) {
|
| - case RtcpMode::kCompound:
|
| - return rtclog::VideoReceiveConfig::RTCP_COMPOUND;
|
| - case RtcpMode::kReducedSize:
|
| - return rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE;
|
| - case RtcpMode::kOff:
|
| - RTC_NOTREACHED();
|
| - return rtclog::VideoReceiveConfig::RTCP_COMPOUND;
|
| - }
|
| - RTC_NOTREACHED();
|
| - return rtclog::VideoReceiveConfig::RTCP_COMPOUND;
|
| -}
|
| -
|
| -rtclog::DelayBasedBweUpdate::DetectorState ConvertDetectorState(
|
| - BandwidthUsage state) {
|
| - switch (state) {
|
| - case BandwidthUsage::kBwNormal:
|
| - return rtclog::DelayBasedBweUpdate::BWE_NORMAL;
|
| - case BandwidthUsage::kBwUnderusing:
|
| - return rtclog::DelayBasedBweUpdate::BWE_UNDERUSING;
|
| - case BandwidthUsage::kBwOverusing:
|
| - return rtclog::DelayBasedBweUpdate::BWE_OVERUSING;
|
| - }
|
| - RTC_NOTREACHED();
|
| - return rtclog::DelayBasedBweUpdate::BWE_NORMAL;
|
| -}
|
| -
|
| -rtclog::BweProbeResult::ResultType ConvertProbeResultType(
|
| - ProbeFailureReason failure_reason) {
|
| - switch (failure_reason) {
|
| - case kInvalidSendReceiveInterval:
|
| - return rtclog::BweProbeResult::INVALID_SEND_RECEIVE_INTERVAL;
|
| - case kInvalidSendReceiveRatio:
|
| - return rtclog::BweProbeResult::INVALID_SEND_RECEIVE_RATIO;
|
| - case kTimeout:
|
| - return rtclog::BweProbeResult::TIMEOUT;
|
| - }
|
| - RTC_NOTREACHED();
|
| - return rtclog::BweProbeResult::SUCCESS;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -RtcEventLogImpl::RtcEventLogImpl()
|
| +RtcEventLogImpl::RtcEventLogImpl(
|
| + std::unique_ptr<RtcEventLogEncoder> event_encoder)
|
| : file_(FileWrapper::Create()),
|
| max_size_bytes_(std::numeric_limits<decltype(max_size_bytes_)>::max()),
|
| written_bytes_(0),
|
| + event_encoder_(std::move(event_encoder)),
|
| task_queue_("rtc_event_log") {}
|
|
|
| RtcEventLogImpl::~RtcEventLogImpl() {
|
| @@ -324,129 +286,53 @@ void RtcEventLogImpl::StopLogging() {
|
| LOG(LS_INFO) << "WebRTC event log successfully stopped.";
|
| }
|
|
|
| -void RtcEventLogImpl::LogVideoReceiveStreamConfig(
|
| - const rtclog::StreamConfig& config) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT);
|
| -
|
| - rtclog::VideoReceiveConfig* receiver_config =
|
| - event->mutable_video_receiver_config();
|
| - receiver_config->set_remote_ssrc(config.remote_ssrc);
|
| - receiver_config->set_local_ssrc(config.local_ssrc);
|
| -
|
| - // TODO(perkj): Add field for rsid.
|
| - receiver_config->set_rtcp_mode(ConvertRtcpMode(config.rtcp_mode));
|
| - receiver_config->set_remb(config.remb);
|
| -
|
| - for (const auto& e : config.rtp_extensions) {
|
| - rtclog::RtpHeaderExtension* extension =
|
| - receiver_config->add_header_extensions();
|
| - extension->set_name(e.uri);
|
| - extension->set_id(e.id);
|
| - }
|
| +void RtcEventLogImpl::Log(std::unique_ptr<RtcEvent> event) {
|
| + RTC_DCHECK(event);
|
|
|
| - for (const auto& d : config.codecs) {
|
| - rtclog::DecoderConfig* decoder = receiver_config->add_decoders();
|
| - decoder->set_name(d.payload_name);
|
| - decoder->set_payload_type(d.payload_type);
|
| - if (d.rtx_payload_type != 0) {
|
| - rtclog::RtxMap* rtx = receiver_config->add_rtx_map();
|
| - rtx->set_payload_type(d.payload_type);
|
| - rtx->mutable_config()->set_rtx_ssrc(config.rtx_ssrc);
|
| - rtx->mutable_config()->set_rtx_payload_type(d.rtx_payload_type);
|
| + auto event_handler = [this](std::unique_ptr<RtcEvent> unencoded_event) {
|
| + RTC_DCHECK_RUN_ON(&task_queue_);
|
| + if (file_->is_open()) {
|
| + LogToFile(std::move(unencoded_event));
|
| + } else {
|
| + LogToMemory(std::move(unencoded_event));
|
| }
|
| - }
|
| - StoreEvent(std::move(event));
|
| + };
|
| +
|
| + task_queue_.PostTask(rtc::MakeUnique<ResourceOwningTask<RtcEvent>>(
|
| + std::move(event), event_handler));
|
| }
|
|
|
| -void RtcEventLogImpl::LogVideoSendStreamConfig(
|
| +void RtcEventLogImpl::LogVideoReceiveStreamConfig(
|
| const rtclog::StreamConfig& config) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::VIDEO_SENDER_CONFIG_EVENT);
|
| -
|
| - rtclog::VideoSendConfig* sender_config = event->mutable_video_sender_config();
|
| -
|
| - // TODO(perkj): rtclog::VideoSendConfig should only contain one SSRC.
|
| - sender_config->add_ssrcs(config.local_ssrc);
|
| - if (config.rtx_ssrc != 0) {
|
| - sender_config->add_rtx_ssrcs(config.rtx_ssrc);
|
| - }
|
| -
|
| - for (const auto& e : config.rtp_extensions) {
|
| - rtclog::RtpHeaderExtension* extension =
|
| - sender_config->add_header_extensions();
|
| - extension->set_name(e.uri);
|
| - extension->set_id(e.id);
|
| - }
|
| -
|
| - // TODO(perkj): rtclog::VideoSendConfig should contain many possible codec
|
| - // configurations.
|
| - for (const auto& codec : config.codecs) {
|
| - sender_config->set_rtx_payload_type(codec.rtx_payload_type);
|
| - rtclog::EncoderConfig* encoder = sender_config->mutable_encoder();
|
| - encoder->set_name(codec.payload_name);
|
| - encoder->set_payload_type(codec.payload_type);
|
| -
|
| - if (config.codecs.size() > 1) {
|
| - LOG(WARNING) << "LogVideoSendStreamConfig currently only supports one "
|
| - << "codec. Logging codec :" << codec.payload_name;
|
| - break;
|
| - }
|
| - }
|
| + Log(rtc::MakeUnique<RtcEventVideoReceiveStreamConfig>(
|
| + rtc::MakeUnique<rtclog::StreamConfig>(config)));
|
| +}
|
|
|
| - StoreEvent(std::move(event));
|
| +void RtcEventLogImpl::LogVideoSendStreamConfig(
|
| + const rtclog::StreamConfig& config) {
|
| + Log(rtc::MakeUnique<RtcEventVideoSendStreamConfig>(
|
| + rtc::MakeUnique<rtclog::StreamConfig>(config)));
|
| }
|
|
|
| void RtcEventLogImpl::LogAudioReceiveStreamConfig(
|
| const rtclog::StreamConfig& config) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::AUDIO_RECEIVER_CONFIG_EVENT);
|
| -
|
| - rtclog::AudioReceiveConfig* receiver_config =
|
| - event->mutable_audio_receiver_config();
|
| - receiver_config->set_remote_ssrc(config.remote_ssrc);
|
| - receiver_config->set_local_ssrc(config.local_ssrc);
|
| -
|
| - for (const auto& e : config.rtp_extensions) {
|
| - rtclog::RtpHeaderExtension* extension =
|
| - receiver_config->add_header_extensions();
|
| - extension->set_name(e.uri);
|
| - extension->set_id(e.id);
|
| - }
|
| - StoreEvent(std::move(event));
|
| + Log(rtc::MakeUnique<RtcEventAudioReceiveStreamConfig>(
|
| + rtc::MakeUnique<rtclog::StreamConfig>(config)));
|
| }
|
|
|
| void RtcEventLogImpl::LogAudioSendStreamConfig(
|
| const rtclog::StreamConfig& config) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::AUDIO_SENDER_CONFIG_EVENT);
|
| -
|
| - rtclog::AudioSendConfig* sender_config = event->mutable_audio_sender_config();
|
| -
|
| - sender_config->set_ssrc(config.local_ssrc);
|
| -
|
| - for (const auto& e : config.rtp_extensions) {
|
| - rtclog::RtpHeaderExtension* extension =
|
| - sender_config->add_header_extensions();
|
| - extension->set_name(e.uri);
|
| - extension->set_id(e.id);
|
| - }
|
| -
|
| - StoreEvent(std::move(event));
|
| + Log(rtc::MakeUnique<RtcEventAudioSendStreamConfig>(
|
| + rtc::MakeUnique<rtclog::StreamConfig>(config)));
|
| }
|
|
|
| void RtcEventLogImpl::LogIncomingRtpHeader(const RtpPacketReceived& packet) {
|
| - LogRtpHeader(kIncomingPacket, packet.data(), packet.size(),
|
| - PacedPacketInfo::kNotAProbe);
|
| + Log(rtc::MakeUnique<RtcEventRtpPacketIncoming>(packet));
|
| }
|
|
|
| void RtcEventLogImpl::LogOutgoingRtpHeader(const RtpPacketToSend& packet,
|
| int probe_cluster_id) {
|
| - LogRtpHeader(kOutgoingPacket, packet.data(), packet.size(), probe_cluster_id);
|
| + Log(rtc::MakeUnique<RtcEventRtpPacketOutgoing>(packet, probe_cluster_id));
|
| }
|
|
|
| void RtcEventLogImpl::LogRtpHeader(PacketDirection direction,
|
| @@ -459,187 +345,79 @@ void RtcEventLogImpl::LogRtpHeader(PacketDirection direction,
|
| const uint8_t* header,
|
| size_t packet_length,
|
| int probe_cluster_id) {
|
| - // Read header length (in bytes) from packet data.
|
| - if (packet_length < 12u) {
|
| - return; // Don't read outside the packet.
|
| - }
|
| - const bool x = (header[0] & 0x10) != 0;
|
| - const uint8_t cc = header[0] & 0x0f;
|
| - size_t header_length = 12u + cc * 4u;
|
| -
|
| - if (x) {
|
| - if (packet_length < 12u + cc * 4u + 4u) {
|
| - return; // Don't read outside the packet.
|
| - }
|
| - size_t x_len = ByteReader<uint16_t>::ReadBigEndian(header + 14 + cc * 4);
|
| - header_length += (x_len + 1) * 4;
|
| + // TODO(eladalon): This is highly inefficient. We're only doing this for
|
| + // the deprecated interface. We should remove this soon.
|
| + if (direction == PacketDirection::kIncomingPacket) {
|
| + RtpPacketReceived packet;
|
| + packet.Parse(header, packet_length);
|
| + Log(rtc::MakeUnique<RtcEventRtpPacketIncoming>(packet));
|
| + } else {
|
| + RTC_CHECK_EQ(direction, PacketDirection::kOutgoingPacket);
|
| + RtpPacketToSend packet(nullptr);
|
| + packet.Parse(header, packet_length);
|
| + Log(rtc::MakeUnique<RtcEventRtpPacketOutgoing>(packet, probe_cluster_id));
|
| }
|
| -
|
| - std::unique_ptr<rtclog::Event> rtp_event(new rtclog::Event());
|
| - rtp_event->set_timestamp_us(rtc::TimeMicros());
|
| - rtp_event->set_type(rtclog::Event::RTP_EVENT);
|
| - rtp_event->mutable_rtp_packet()->set_incoming(direction == kIncomingPacket);
|
| - rtp_event->mutable_rtp_packet()->set_packet_length(packet_length);
|
| - rtp_event->mutable_rtp_packet()->set_header(header, header_length);
|
| - if (probe_cluster_id != PacedPacketInfo::kNotAProbe)
|
| - rtp_event->mutable_rtp_packet()->set_probe_cluster_id(probe_cluster_id);
|
| - StoreEvent(std::move(rtp_event));
|
| }
|
|
|
| void RtcEventLogImpl::LogIncomingRtcpPacket(
|
| rtc::ArrayView<const uint8_t> packet) {
|
| - LogRtcpPacket(kIncomingPacket, packet.data(), packet.size());
|
| + Log(rtc::MakeUnique<RtcEventRtcpPacketIncoming>(packet));
|
| }
|
|
|
| void RtcEventLogImpl::LogOutgoingRtcpPacket(
|
| rtc::ArrayView<const uint8_t> packet) {
|
| - LogRtcpPacket(kOutgoingPacket, packet.data(), packet.size());
|
| + Log(rtc::MakeUnique<RtcEventRtcpPacketOutgoing>(packet));
|
| }
|
|
|
| void RtcEventLogImpl::LogRtcpPacket(PacketDirection direction,
|
| const uint8_t* packet,
|
| size_t length) {
|
| - std::unique_ptr<rtclog::Event> rtcp_event(new rtclog::Event());
|
| - rtcp_event->set_timestamp_us(rtc::TimeMicros());
|
| - rtcp_event->set_type(rtclog::Event::RTCP_EVENT);
|
| - rtcp_event->mutable_rtcp_packet()->set_incoming(direction == kIncomingPacket);
|
| -
|
| - rtcp::CommonHeader header;
|
| - const uint8_t* block_begin = packet;
|
| - const uint8_t* packet_end = packet + length;
|
| - RTC_DCHECK(length <= IP_PACKET_SIZE);
|
| - uint8_t buffer[IP_PACKET_SIZE];
|
| - uint32_t buffer_length = 0;
|
| - while (block_begin < packet_end) {
|
| - if (!header.Parse(block_begin, packet_end - block_begin)) {
|
| - break; // Incorrect message header.
|
| - }
|
| - const uint8_t* next_block = header.NextPacket();
|
| - uint32_t block_size = next_block - block_begin;
|
| - switch (header.type()) {
|
| - case rtcp::SenderReport::kPacketType:
|
| - case rtcp::ReceiverReport::kPacketType:
|
| - case rtcp::Bye::kPacketType:
|
| - case rtcp::ExtendedJitterReport::kPacketType:
|
| - case rtcp::Rtpfb::kPacketType:
|
| - case rtcp::Psfb::kPacketType:
|
| - case rtcp::ExtendedReports::kPacketType:
|
| - // We log sender reports, receiver reports, bye messages
|
| - // inter-arrival jitter, third-party loss reports, payload-specific
|
| - // feedback and extended reports.
|
| - memcpy(buffer + buffer_length, block_begin, block_size);
|
| - buffer_length += block_size;
|
| - break;
|
| - case rtcp::Sdes::kPacketType:
|
| - case rtcp::App::kPacketType:
|
| - default:
|
| - // We don't log sender descriptions, application defined messages
|
| - // or message blocks of unknown type.
|
| - break;
|
| - }
|
| -
|
| - block_begin += block_size;
|
| + if (direction == PacketDirection::kIncomingPacket) {
|
| + LogIncomingRtcpPacket(rtc::ArrayView<const uint8_t>(packet, length));
|
| + } else {
|
| + RTC_CHECK_EQ(direction, PacketDirection::kOutgoingPacket);
|
| + LogOutgoingRtcpPacket(rtc::ArrayView<const uint8_t>(packet, length));
|
| }
|
| - rtcp_event->mutable_rtcp_packet()->set_packet_data(buffer, buffer_length);
|
| - StoreEvent(std::move(rtcp_event));
|
| }
|
|
|
| void RtcEventLogImpl::LogAudioPlayout(uint32_t ssrc) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::AUDIO_PLAYOUT_EVENT);
|
| - auto playout_event = event->mutable_audio_playout_event();
|
| - playout_event->set_local_ssrc(ssrc);
|
| - StoreEvent(std::move(event));
|
| + Log(rtc::MakeUnique<RtcEventAudioPlayout>(ssrc));
|
| }
|
|
|
| void RtcEventLogImpl::LogLossBasedBweUpdate(int32_t bitrate_bps,
|
| uint8_t fraction_loss,
|
| int32_t total_packets) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::LOSS_BASED_BWE_UPDATE);
|
| - auto bwe_event = event->mutable_loss_based_bwe_update();
|
| - bwe_event->set_bitrate_bps(bitrate_bps);
|
| - bwe_event->set_fraction_loss(fraction_loss);
|
| - bwe_event->set_total_packets(total_packets);
|
| - StoreEvent(std::move(event));
|
| + Log(rtc::MakeUnique<RtcEventBweUpdateLossBased>(bitrate_bps, fraction_loss,
|
| + total_packets));
|
| }
|
|
|
| void RtcEventLogImpl::LogDelayBasedBweUpdate(int32_t bitrate_bps,
|
| BandwidthUsage detector_state) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::DELAY_BASED_BWE_UPDATE);
|
| - auto bwe_event = event->mutable_delay_based_bwe_update();
|
| - bwe_event->set_bitrate_bps(bitrate_bps);
|
| - bwe_event->set_detector_state(ConvertDetectorState(detector_state));
|
| - StoreEvent(std::move(event));
|
| + Log(rtc::MakeUnique<RtcEventBweUpdateDelayBased>(bitrate_bps,
|
| + detector_state));
|
| }
|
|
|
| void RtcEventLogImpl::LogAudioNetworkAdaptation(
|
| const AudioEncoderRuntimeConfig& config) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::AUDIO_NETWORK_ADAPTATION_EVENT);
|
| - auto audio_network_adaptation = event->mutable_audio_network_adaptation();
|
| - if (config.bitrate_bps)
|
| - audio_network_adaptation->set_bitrate_bps(*config.bitrate_bps);
|
| - if (config.frame_length_ms)
|
| - audio_network_adaptation->set_frame_length_ms(*config.frame_length_ms);
|
| - if (config.uplink_packet_loss_fraction) {
|
| - audio_network_adaptation->set_uplink_packet_loss_fraction(
|
| - *config.uplink_packet_loss_fraction);
|
| - }
|
| - if (config.enable_fec)
|
| - audio_network_adaptation->set_enable_fec(*config.enable_fec);
|
| - if (config.enable_dtx)
|
| - audio_network_adaptation->set_enable_dtx(*config.enable_dtx);
|
| - if (config.num_channels)
|
| - audio_network_adaptation->set_num_channels(*config.num_channels);
|
| - StoreEvent(std::move(event));
|
| + Log(rtc::MakeUnique<RtcEventAudioNetworkAdaptation>(
|
| + rtc::MakeUnique<AudioEncoderRuntimeConfig>(config)));
|
| }
|
|
|
| void RtcEventLogImpl::LogProbeClusterCreated(int id,
|
| int bitrate_bps,
|
| int min_probes,
|
| int min_bytes) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::BWE_PROBE_CLUSTER_CREATED_EVENT);
|
| -
|
| - auto probe_cluster = event->mutable_probe_cluster();
|
| - probe_cluster->set_id(id);
|
| - probe_cluster->set_bitrate_bps(bitrate_bps);
|
| - probe_cluster->set_min_packets(min_probes);
|
| - probe_cluster->set_min_bytes(min_bytes);
|
| - StoreEvent(std::move(event));
|
| + Log(rtc::MakeUnique<RtcEventProbeClusterCreated>(id, bitrate_bps, min_probes,
|
| + min_bytes));
|
| }
|
|
|
| void RtcEventLogImpl::LogProbeResultSuccess(int id, int bitrate_bps) {
|
| - LogProbeResult(id, rtclog::BweProbeResult::SUCCESS, bitrate_bps);
|
| + Log(rtc::MakeUnique<RtcEventProbeResultSuccess>(id, bitrate_bps));
|
| }
|
|
|
| void RtcEventLogImpl::LogProbeResultFailure(int id,
|
| ProbeFailureReason failure_reason) {
|
| - rtclog::BweProbeResult::ResultType result =
|
| - ConvertProbeResultType(failure_reason);
|
| - LogProbeResult(id, result, -1);
|
| -}
|
| -
|
| -void RtcEventLogImpl::LogProbeResult(int id,
|
| - rtclog::BweProbeResult::ResultType result,
|
| - int bitrate_bps) {
|
| - std::unique_ptr<rtclog::Event> event(new rtclog::Event());
|
| - event->set_timestamp_us(rtc::TimeMicros());
|
| - event->set_type(rtclog::Event::BWE_PROBE_RESULT_EVENT);
|
| -
|
| - auto probe_result = event->mutable_probe_result();
|
| - probe_result->set_id(id);
|
| - probe_result->set_result(result);
|
| - if (result == rtclog::BweProbeResult::SUCCESS)
|
| - probe_result->set_bitrate_bps(bitrate_bps);
|
| - StoreEvent(std::move(event));
|
| + Log(rtc::MakeUnique<RtcEventProbeResultFailure>(id, failure_reason));
|
| }
|
|
|
| void RtcEventLogImpl::StartLoggingInternal(std::unique_ptr<FileWrapper> file,
|
| @@ -665,61 +443,30 @@ void RtcEventLogImpl::StartLoggingInternal(std::unique_ptr<FileWrapper> file,
|
| std::move(file), file_handler));
|
| }
|
|
|
| -void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event> event) {
|
| - RTC_DCHECK(event);
|
| -
|
| - auto event_handler = [this](std::unique_ptr<rtclog::Event> rtclog_event) {
|
| - RTC_DCHECK_RUN_ON(&task_queue_);
|
| - if (file_->is_open()) {
|
| - LogToFile(std::move(rtclog_event));
|
| - } else {
|
| - LogToMemory(std::move(rtclog_event));
|
| - }
|
| - };
|
| -
|
| - task_queue_.PostTask(rtc::MakeUnique<ResourceOwningTask<rtclog::Event>>(
|
| - std::move(event), event_handler));
|
| -}
|
| -
|
| -bool RtcEventLogImpl::AppendEventToString(rtclog::Event* event,
|
| +bool RtcEventLogImpl::AppendEventToString(const RtcEvent& event,
|
| ProtoString* output_string) {
|
| RTC_DCHECK_RUN_ON(&task_queue_);
|
|
|
| - // Even though we're only serializing a single event during this call, what
|
| - // we intend to get is a list of events, with a tag and length preceding
|
| - // each actual event. To produce that, we serialize a list of a single event.
|
| - // If we later serialize additional events, the resulting ProtoString will
|
| - // be a proper concatenation of all those events.
|
| -
|
| - rtclog::EventStream event_stream;
|
| - event_stream.add_stream();
|
| -
|
| - // As a tweak, we swap the new event into the event-stream, write that to
|
| - // file, then swap back. This saves on some copying.
|
| - rtclog::Event* output_event = event_stream.mutable_stream(0);
|
| - output_event->Swap(event);
|
| + std::string encoded_event = event_encoder_->Encode(event);
|
|
|
| bool appended;
|
| size_t potential_new_size =
|
| - written_bytes_ + output_string->size() + event_stream.ByteSize();
|
| + written_bytes_ + output_string->size() + encoded_event.length();
|
| if (potential_new_size <= max_size_bytes_) {
|
| - event_stream.AppendToString(output_string);
|
| + *output_string += encoded_event;
|
| appended = true;
|
| } else {
|
| appended = false;
|
| }
|
|
|
| - // When the function returns, the original Event will be unchanged.
|
| - output_event->Swap(event);
|
| -
|
| return appended;
|
| }
|
|
|
| -void RtcEventLogImpl::LogToMemory(std::unique_ptr<rtclog::Event> event) {
|
| +void RtcEventLogImpl::LogToMemory(std::unique_ptr<RtcEvent> event) {
|
| RTC_DCHECK_RUN_ON(&task_queue_);
|
| RTC_DCHECK(!file_->is_open());
|
|
|
| - if (IsConfigEvent(*event.get())) {
|
| + if (event->IsConfigEvent()) {
|
| config_history_.push_back(std::move(event));
|
| } else {
|
| history_.push_back(std::move(event));
|
| @@ -739,10 +486,7 @@ void RtcEventLogImpl::StartLogFile() {
|
| // The timestamp used will correspond to when logging has started. The log
|
| // may contain events earlier than the LOG_START event. (In general, the
|
| // timestamps in the log are not monotonic.)
|
| - rtclog::Event start_event;
|
| - start_event.set_timestamp_us(rtc::TimeMicros());
|
| - start_event.set_type(rtclog::Event::LOG_START);
|
| - bool appended = AppendEventToString(&start_event, &output_string);
|
| + bool appended = AppendEventToString(RtcEventLoggingStarted(), &output_string);
|
|
|
| // Serialize the config information for all old streams, including streams
|
| // which were already logged to previous files.
|
| @@ -750,12 +494,12 @@ void RtcEventLogImpl::StartLogFile() {
|
| if (!appended) {
|
| break;
|
| }
|
| - appended = AppendEventToString(event.get(), &output_string);
|
| + appended = AppendEventToString(*event, &output_string);
|
| }
|
|
|
| // Serialize the events in the event queue.
|
| while (appended && !history_.empty()) {
|
| - appended = AppendEventToString(history_.front().get(), &output_string);
|
| + appended = AppendEventToString(*history_.front(), &output_string);
|
| if (appended) {
|
| // Known issue - if writing to the file fails, these events will have
|
| // been lost. If we try to open a new file, these events will be missing
|
| @@ -779,15 +523,15 @@ void RtcEventLogImpl::StartLogFile() {
|
| }
|
| }
|
|
|
| -void RtcEventLogImpl::LogToFile(std::unique_ptr<rtclog::Event> event) {
|
| +void RtcEventLogImpl::LogToFile(std::unique_ptr<RtcEvent> event) {
|
| RTC_DCHECK_RUN_ON(&task_queue_);
|
| RTC_DCHECK(file_->is_open());
|
|
|
| ProtoString output_string;
|
|
|
| - bool appended = AppendEventToString(event.get(), &output_string);
|
| + bool appended = AppendEventToString(*event, &output_string);
|
|
|
| - if (IsConfigEvent(*event.get())) {
|
| + if (event->IsConfigEvent()) {
|
| config_history_.push_back(std::move(event));
|
| }
|
|
|
| @@ -814,10 +558,7 @@ void RtcEventLogImpl::StopLogFile(int64_t stop_time) {
|
|
|
| ProtoString output_string;
|
|
|
| - rtclog::Event end_event;
|
| - end_event.set_timestamp_us(stop_time);
|
| - end_event.set_type(rtclog::Event::LOG_END);
|
| - bool appended = AppendEventToString(&end_event, &output_string);
|
| + bool appended = AppendEventToString(RtcEventLoggingStopped(), &output_string);
|
|
|
| if (appended) {
|
| if (!file_->Write(output_string.data(), output_string.size())) {
|
| @@ -838,9 +579,9 @@ void RtcEventLogImpl::StopLogFile(int64_t stop_time) {
|
| #endif // ENABLE_RTC_EVENT_LOG
|
|
|
| // RtcEventLog member functions.
|
| -std::unique_ptr<RtcEventLog> RtcEventLog::Create() {
|
| +std::unique_ptr<RtcEventLog> RtcEventLog::Create(EncodingType encoding_type) {
|
| #ifdef ENABLE_RTC_EVENT_LOG
|
| - // TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|.
|
| + // TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|.
|
| constexpr int kMaxLogCount = 5;
|
| int count = 1 + std::atomic_fetch_add(&rtc_event_log_count, 1);
|
| if (count > kMaxLogCount) {
|
| @@ -849,7 +590,8 @@ std::unique_ptr<RtcEventLog> RtcEventLog::Create() {
|
| std::atomic_fetch_sub(&rtc_event_log_count, 1);
|
| return CreateNull();
|
| }
|
| - return rtc::MakeUnique<RtcEventLogImpl>();
|
| + auto encoder = CreateEncoder(encoding_type);
|
| + return rtc::MakeUnique<RtcEventLogImpl>(std::move(encoder));
|
| #else
|
| return CreateNull();
|
| #endif // ENABLE_RTC_EVENT_LOG
|
|
|