Reland "Wire up proto-free event log format in encoder and parser."
This is a reland of 46333dbf6211ea197965c30fdbecbeb62bc81e5b Original change's description: > Wire up proto-free event log format in encoder and parser. > > Encode ALR state events as an example. The ALR state unit tests pass with the new format, but the tests are not enabled in this CL since the other event types aren't encoded yet. > > Bug: webrtc:11933 > Change-Id: I3ba22778b55f24e2e2bd7d95bb9b17de29ef899f > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/234520 > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35752} Bug: webrtc:11933 Change-Id: Ia8b23cfb134b61c9ef02aa21189ecbd239783c40 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/248141 Reviewed-by: Sebastian Jansson <srte@webrtc.org> Commit-Queue: Björn Terelius <terelius@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35762}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
e1cd3ad4f5
commit
01ef37c08e
@ -16,6 +16,7 @@
|
||||
|
||||
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h"
|
||||
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h"
|
||||
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_v3.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_alr_state.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_audio_playout.h"
|
||||
@ -62,8 +63,7 @@ class RtcEventLogEncoderTest
|
||||
encoder_ = std::make_unique<RtcEventLogEncoderNewFormat>();
|
||||
break;
|
||||
case RtcEventLog::EncodingType::ProtoFree:
|
||||
// TODO(terelius): Enable test once the format has been wired up.
|
||||
RTC_CHECK_NOTREACHED();
|
||||
encoder_ = std::make_unique<RtcEventLogEncoderV3>();
|
||||
break;
|
||||
}
|
||||
encoded_ =
|
||||
@ -1290,8 +1290,7 @@ class RtcEventLogEncoderSimpleTest
|
||||
encoder_ = std::make_unique<RtcEventLogEncoderNewFormat>();
|
||||
break;
|
||||
case RtcEventLog::EncodingType::ProtoFree:
|
||||
// TODO(terelius): Enable test once the format has been wired up.
|
||||
RTC_CHECK_NOTREACHED();
|
||||
encoder_ = std::make_unique<RtcEventLogEncoderV3>();
|
||||
break;
|
||||
}
|
||||
encoded_ =
|
||||
|
||||
117
logging/rtc_event_log/encoder/rtc_event_log_encoder_v3.cc
Normal file
117
logging/rtc_event_log/encoder/rtc_event_log_encoder_v3.cc
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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/encoder/rtc_event_log_encoder_v3.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_common.h"
|
||||
#include "logging/rtc_event_log/encoder/var_int.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_alr_state.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_audio_playout.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_audio_send_stream_config.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_begin_log.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_bwe_update_delay_based.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_bwe_update_loss_based.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_dtls_transport_state.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_dtls_writable_state.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_end_log.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_frame_decoded.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_generic_ack_received.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_generic_packet_received.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_generic_packet_sent.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_probe_cluster_created.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_probe_result_failure.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_probe_result_success.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_remote_estimate.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_route_change.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_rtcp_packet_incoming.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_rtp_packet_incoming.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
std::string RtcEventLogEncoderV3::EncodeLogStart(int64_t timestamp_us,
|
||||
int64_t utc_time_us) {
|
||||
std::unique_ptr<RtcEventBeginLog> begin_log =
|
||||
std::make_unique<RtcEventBeginLog>(Timestamp::Micros(timestamp_us),
|
||||
Timestamp::Micros(utc_time_us));
|
||||
std::vector<const RtcEvent*> batch;
|
||||
batch.push_back(begin_log.get());
|
||||
|
||||
std::string encoded_event = RtcEventBeginLog::Encode(batch);
|
||||
|
||||
return encoded_event;
|
||||
}
|
||||
|
||||
std::string RtcEventLogEncoderV3::EncodeLogEnd(int64_t timestamp_us) {
|
||||
std::unique_ptr<RtcEventEndLog> end_log =
|
||||
std::make_unique<RtcEventEndLog>(Timestamp::Micros(timestamp_us));
|
||||
std::vector<const RtcEvent*> batch;
|
||||
batch.push_back(end_log.get());
|
||||
|
||||
std::string encoded_event = RtcEventEndLog::Encode(batch);
|
||||
|
||||
return encoded_event;
|
||||
}
|
||||
|
||||
RtcEventLogEncoderV3::RtcEventLogEncoderV3() {
|
||||
encoders_[RtcEvent::Type::AlrStateEvent] = RtcEventAlrState::Encode;
|
||||
}
|
||||
|
||||
std::string RtcEventLogEncoderV3::EncodeBatch(
|
||||
std::deque<std::unique_ptr<RtcEvent>>::const_iterator begin,
|
||||
std::deque<std::unique_ptr<RtcEvent>>::const_iterator end) {
|
||||
struct EventGroupKey {
|
||||
// Events are grouped by event type. For compression efficiency,
|
||||
// events can optionally have a secondary key, in most cases the
|
||||
// SSRC.
|
||||
RtcEvent::Type type;
|
||||
uint32_t secondary_group_key;
|
||||
|
||||
bool operator<(EventGroupKey other) const {
|
||||
return type < other.type ||
|
||||
(type == other.type &&
|
||||
secondary_group_key < other.secondary_group_key);
|
||||
}
|
||||
};
|
||||
|
||||
std::map<EventGroupKey, std::vector<const RtcEvent*>> event_groups;
|
||||
|
||||
for (auto it = begin; it != end; ++it) {
|
||||
event_groups[{(*it)->GetType(), (*it)->GetGroupKey()}].push_back(it->get());
|
||||
}
|
||||
|
||||
std::string encoded_output;
|
||||
for (auto& kv : event_groups) {
|
||||
auto it = encoders_.find(kv.first.type);
|
||||
RTC_DCHECK(it != encoders_.end());
|
||||
if (it != encoders_.end()) {
|
||||
auto& encoder = it->second;
|
||||
// TODO(terelius): Use some "string builder" or preallocate?
|
||||
encoded_output += encoder(kv.second);
|
||||
}
|
||||
}
|
||||
|
||||
return encoded_output;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
46
logging/rtc_event_log/encoder/rtc_event_log_encoder_v3.h
Normal file
46
logging/rtc_event_log/encoder/rtc_event_log_encoder_v3.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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_ENCODER_RTC_EVENT_LOG_ENCODER_V3_H_
|
||||
#define LOGGING_RTC_EVENT_LOG_ENCODER_RTC_EVENT_LOG_ENCODER_V3_H_
|
||||
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_definition.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class RtcEventLogEncoderV3 final : public RtcEventLogEncoder {
|
||||
public:
|
||||
RtcEventLogEncoderV3();
|
||||
~RtcEventLogEncoderV3() override = default;
|
||||
|
||||
std::string EncodeBatch(
|
||||
std::deque<std::unique_ptr<RtcEvent>>::const_iterator begin,
|
||||
std::deque<std::unique_ptr<RtcEvent>>::const_iterator end) override;
|
||||
|
||||
std::string EncodeLogStart(int64_t timestamp_us,
|
||||
int64_t utc_time_us) override;
|
||||
std::string EncodeLogEnd(int64_t timestamp_us) override;
|
||||
|
||||
private:
|
||||
std::map<RtcEvent::Type,
|
||||
std::function<std::string(rtc::ArrayView<const RtcEvent*>)>>
|
||||
encoders_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // LOGGING_RTC_EVENT_LOG_ENCODER_RTC_EVENT_LOG_ENCODER_V3_H_
|
||||
Reference in New Issue
Block a user