diff options
Diffstat (limited to 'third_party/libwebrtc/logging')
13 files changed, 267 insertions, 159 deletions
diff --git a/third_party/libwebrtc/logging/BUILD.gn b/third_party/libwebrtc/logging/BUILD.gn index 91890553a3..117d5c4a3c 100644 --- a/third_party/libwebrtc/logging/BUILD.gn +++ b/third_party/libwebrtc/logging/BUILD.gn @@ -353,6 +353,7 @@ rtc_library("rtc_event_log_impl_encoder") { deps = [ ":rtc_event_number_encodings", + "../api:field_trials_view", "../api:rtp_headers", "../api:rtp_parameters", "../api/transport:network_control", @@ -362,7 +363,6 @@ rtc_library("rtc_event_log_impl_encoder") { "../rtc_base:checks", "../rtc_base:logging", "../rtc_base:safe_conversions", - "../system_wrappers:field_trial", ] absl_deps = [ "//third_party/abseil-cpp/absl/memory", @@ -609,6 +609,7 @@ if (rtc_enable_protobuf) { ":rtc_event_video", ":rtc_stream_config", "../api:array_view", + "../api:field_trials_view", "../api:network_state_predictor_api", "../api:rtc_event_log_output_file", "../api:rtp_headers", @@ -630,9 +631,7 @@ if (rtc_enable_protobuf) { "../rtc_base:rtc_base_tests_utils", "../rtc_base:timeutils", "../system_wrappers", - "../system_wrappers:field_trial", "../test:explicit_key_value_config", - "../test:field_trial", "../test:fileutils", "../test:test_support", "../test/logging:log_writer", @@ -689,6 +688,7 @@ rtc_library("ice_log") { deps = [ ":rtc_event_field", + "../api:candidate", "../api:dtls_transport_interface", "../api:libjingle_logging_api", "../api/rtc_event_log", diff --git a/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc b/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc index 2c1444af07..83c5441138 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc @@ -131,21 +131,15 @@ ConvertIceCandidatePairConfigType(IceCandidatePairConfigType type) { rtclog::IceCandidatePairConfig::IceCandidateType ConvertIceCandidateType( IceCandidateType type) { switch (type) { - case IceCandidateType::kUnknown: - return rtclog::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE; - case IceCandidateType::kLocal: + case IceCandidateType::kHost: return rtclog::IceCandidatePairConfig::LOCAL; - case IceCandidateType::kStun: + case IceCandidateType::kSrflx: return rtclog::IceCandidatePairConfig::STUN; case IceCandidateType::kPrflx: return rtclog::IceCandidatePairConfig::PRFLX; case IceCandidateType::kRelay: return rtclog::IceCandidatePairConfig::RELAY; - case IceCandidateType::kNumValues: - RTC_DCHECK_NOTREACHED(); } - RTC_DCHECK_NOTREACHED(); - return rtclog::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE; } rtclog::IceCandidatePairConfig::Protocol ConvertIceCandidatePairProtocol( @@ -202,6 +196,7 @@ rtclog::IceCandidatePairConfig::NetworkType ConvertIceCandidateNetworkType( return rtclog::IceCandidatePairConfig::CELLULAR; case IceCandidateNetworkType::kNumValues: RTC_DCHECK_NOTREACHED(); + break; } RTC_DCHECK_NOTREACHED(); return rtclog::IceCandidatePairConfig::UNKNOWN_NETWORK_TYPE; diff --git a/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc b/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc index 01bd89718d..7018f71e1b 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc @@ -10,8 +10,11 @@ #include "logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h" +#include <type_traits> + #include "absl/types/optional.h" #include "api/array_view.h" +#include "api/field_trials_view.h" #include "api/network_state_predictor.h" #include "logging/rtc_event_log/dependency_descriptor_encoder_decoder.h" #include "logging/rtc_event_log/encoder/blob_encoding.h" @@ -62,7 +65,6 @@ #include "modules/rtp_rtcp/source/rtp_packet.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" -#include "system_wrappers/include/field_trial.h" // *.pb.h files are generated at build-time by the protobuf compiler. #ifdef WEBRTC_ANDROID_PLATFORM_BUILD @@ -198,18 +200,14 @@ ConvertToProtoFormat(IceCandidatePairConfigType type) { rtclog2::IceCandidatePairConfig::IceCandidateType ConvertToProtoFormat( IceCandidateType type) { switch (type) { - case IceCandidateType::kUnknown: - return rtclog2::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE; - case IceCandidateType::kLocal: + case IceCandidateType::kHost: return rtclog2::IceCandidatePairConfig::LOCAL; - case IceCandidateType::kStun: + case IceCandidateType::kSrflx: return rtclog2::IceCandidatePairConfig::STUN; case IceCandidateType::kPrflx: return rtclog2::IceCandidatePairConfig::PRFLX; case IceCandidateType::kRelay: return rtclog2::IceCandidatePairConfig::RELAY; - case IceCandidateType::kNumValues: - RTC_DCHECK_NOTREACHED(); } RTC_DCHECK_NOTREACHED(); return rtclog2::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE; @@ -385,10 +383,12 @@ void EncodeRtcpPacket(rtc::ArrayView<const EventType*> batch, } proto_batch->set_raw_packet_blobs(EncodeBlobs(scrubed_packets)); } +} // namespace -template <typename EventType, typename ProtoType> -void EncodeRtpPacket(const std::vector<const EventType*>& batch, - ProtoType* proto_batch) { +template <typename Batch, typename ProtoType> +void RtcEventLogEncoderNewFormat::EncodeRtpPacket(const Batch& batch, + ProtoType* proto_batch) { + using EventType = std::remove_pointer_t<typename Batch::value_type>; if (batch.empty()) { return; } @@ -463,8 +463,7 @@ void EncodeRtpPacket(const std::vector<const EventType*>& batch, { // TODO(webrtc:14975) Remove this kill switch after DD in RTC event log has // been rolled out. - if (!webrtc::field_trial::IsDisabled( - "WebRTC-RtcEventLogEncodeDependencyDescriptor")) { + if (encode_dependency_descriptor_) { std::vector<rtc::ArrayView<const uint8_t>> raw_dds(batch.size()); bool has_dd = false; for (size_t i = 0; i < batch.size(); ++i) { @@ -678,15 +677,13 @@ void EncodeRtpPacket(const std::vector<const EventType*>& batch, proto_batch->set_voice_activity_deltas(encoded_deltas); } } -} // namespace -RtcEventLogEncoderNewFormat::RtcEventLogEncoderNewFormat() { - encode_neteq_set_minimum_delay_kill_switch_ = false; - if (webrtc::field_trial::IsEnabled( - "WebRTC-RtcEventLogEncodeNetEqSetMinimumDelayKillSwitch")) { - encode_neteq_set_minimum_delay_kill_switch_ = true; - } -} +RtcEventLogEncoderNewFormat::RtcEventLogEncoderNewFormat( + const FieldTrialsView& field_trials) + : encode_neteq_set_minimum_delay_kill_switch_(field_trials.IsEnabled( + "WebRTC-RtcEventLogEncodeNetEqSetMinimumDelayKillSwitch")), + encode_dependency_descriptor_(!field_trials.IsDisabled( + "WebRTC-RtcEventLogEncodeDependencyDescriptor")) {} std::string RtcEventLogEncoderNewFormat::EncodeLogStart(int64_t timestamp_us, int64_t utc_time_us) { diff --git a/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h b/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h index 6747f41f07..6a657090dd 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h +++ b/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h @@ -18,6 +18,7 @@ #include <vector> #include "api/array_view.h" +#include "api/field_trials_view.h" #include "logging/rtc_event_log/encoder/rtc_event_log_encoder.h" namespace webrtc { @@ -59,7 +60,7 @@ class RtcEventGenericPacketSent; class RtcEventLogEncoderNewFormat final : public RtcEventLogEncoder { public: - RtcEventLogEncoderNewFormat(); + explicit RtcEventLogEncoderNewFormat(const FieldTrialsView& field_trials); ~RtcEventLogEncoderNewFormat() override = default; std::string EncodeBatch( @@ -71,8 +72,6 @@ class RtcEventLogEncoderNewFormat final : public RtcEventLogEncoder { std::string EncodeLogEnd(int64_t timestamp_us) override; private: - bool encode_neteq_set_minimum_delay_kill_switch_ = false; - // Encoding entry-point for the various RtcEvent subclasses. void EncodeAlrState(rtc::ArrayView<const RtcEventAlrState*> batch, rtclog2::EventStream* event_stream); @@ -157,6 +156,11 @@ class RtcEventLogEncoderNewFormat final : public RtcEventLogEncoder { void EncodeVideoSendStreamConfig( rtc::ArrayView<const RtcEventVideoSendStreamConfig*> batch, rtclog2::EventStream* event_stream); + template <typename Batch, typename ProtoType> + void EncodeRtpPacket(const Batch& batch, ProtoType* proto_batch); + + const bool encode_neteq_set_minimum_delay_kill_switch_; + const bool encode_dependency_descriptor_; }; } // namespace webrtc diff --git a/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc b/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc index 612f85bf61..72611db8ce 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc @@ -14,6 +14,7 @@ #include <string> #include <tuple> +#include "api/field_trials_view.h" #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" @@ -40,10 +41,13 @@ #include "modules/rtp_rtcp/source/rtp_header_extensions.h" #include "rtc_base/fake_clock.h" #include "rtc_base/random.h" -#include "test/field_trial.h" +#include "test/explicit_key_value_config.h" #include "test/gtest.h" namespace webrtc { + +using test::ExplicitKeyValueConfig; + class RtcEventLogEncoderTest : public ::testing::TestWithParam< std::tuple<int, RtcEventLog::EncodingType, size_t, bool>> { @@ -55,22 +59,26 @@ class RtcEventLogEncoderTest event_count_(std::get<2>(GetParam())), force_repeated_fields_(std::get<3>(GetParam())), gen_(seed_ * 880001UL), - verifier_(encoding_type_) { + verifier_(encoding_type_) {} + ~RtcEventLogEncoderTest() override = default; + + std::unique_ptr<RtcEventLogEncoder> CreateEncoder( + const FieldTrialsView& field_trials = ExplicitKeyValueConfig("")) { + std::unique_ptr<RtcEventLogEncoder> encoder; switch (encoding_type_) { case RtcEventLog::EncodingType::Legacy: - encoder_ = std::make_unique<RtcEventLogEncoderLegacy>(); + encoder = std::make_unique<RtcEventLogEncoderLegacy>(); break; case RtcEventLog::EncodingType::NewFormat: - encoder_ = std::make_unique<RtcEventLogEncoderNewFormat>(); + encoder = std::make_unique<RtcEventLogEncoderNewFormat>(field_trials); break; case RtcEventLog::EncodingType::ProtoFree: - encoder_ = std::make_unique<RtcEventLogEncoderV3>(); + encoder = std::make_unique<RtcEventLogEncoderV3>(); break; } - encoded_ = - encoder_->EncodeLogStart(rtc::TimeMillis(), rtc::TimeUTCMillis()); + encoded_ = encoder->EncodeLogStart(rtc::TimeMillis(), rtc::TimeUTCMillis()); + return encoder; } - ~RtcEventLogEncoderTest() override = default; // ANA events have some optional fields, so we want to make sure that we get // correct behavior both when all of the values are there, as well as when @@ -89,10 +97,9 @@ class RtcEventLogEncoderTest uint32_t ssrc); template <typename EventType, typename ParsedType> - void TestRtpPackets(); + void TestRtpPackets(RtcEventLogEncoder& encoder); std::deque<std::unique_ptr<RtcEvent>> history_; - std::unique_ptr<RtcEventLogEncoder> encoder_; ParsedRtcEventLog parsed_log_; const uint64_t seed_; Random prng_; @@ -108,12 +115,13 @@ void RtcEventLogEncoderTest::TestRtcEventAudioNetworkAdaptation( const std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>>& events) { ASSERT_TRUE(history_.empty()) << "Function should be called once per test."; + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); for (auto& event : events) { history_.push_back(event->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& ana_configs = parsed_log_.audio_network_adaptation_events(); @@ -165,7 +173,7 @@ RtcEventLogEncoderTest::GetRtpPacketsBySsrc(const ParsedRtcEventLog* parsed_log, } template <typename EventType, typename ParsedType> -void RtcEventLogEncoderTest::TestRtpPackets() { +void RtcEventLogEncoderTest::TestRtpPackets(RtcEventLogEncoder& encoder) { // SSRCs will be randomly assigned out of this small pool, significant only // in that it also covers such edge cases as SSRC = 0 and SSRC = 0xffffffff. // The pool is intentionally small, so as to produce collisions. @@ -193,7 +201,7 @@ void RtcEventLogEncoderTest::TestRtpPackets() { } // Encode and parse. - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder.EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); // For each SSRC, make sure the RTP packets associated with it to have been @@ -213,6 +221,7 @@ void RtcEventLogEncoderTest::TestRtpPackets() { } TEST_P(RtcEventLogEncoderTest, RtcEventAlrState) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventAlrState>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) ? gen_.NewAlrState() @@ -220,7 +229,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAlrState) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& alr_state_events = parsed_log_.alr_state_events(); @@ -234,6 +243,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRouteChange) { if (encoding_type_ == RtcEventLog::EncodingType::Legacy) { return; } + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventRouteChange>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) ? gen_.NewRouteChange() @@ -241,7 +251,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRouteChange) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& route_change_events = parsed_log_.route_change_events(); @@ -252,6 +262,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRouteChange) { } TEST_P(RtcEventLogEncoderTest, RtcEventRemoteEstimate) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventRemoteEstimate>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -260,7 +271,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRemoteEstimate) { history_.push_back(std::make_unique<RtcEventRemoteEstimate>(*events[i])); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& parsed_events = parsed_log_.remote_estimate_events(); @@ -395,6 +406,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationAll) { } TEST_P(RtcEventLogEncoderTest, RtcEventAudioPlayout) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); // SSRCs will be randomly assigned out of this small pool, significant only // in that it also covers such edge cases as SSRC = 0 and SSRC = 0xffffffff. // The pool is intentionally small, so as to produce collisions. @@ -414,7 +426,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioPlayout) { original_events_by_ssrc[ssrc].push_back(std::move(event)); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& parsed_playout_events_by_ssrc = @@ -443,6 +455,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioPlayout) { } TEST_P(RtcEventLogEncoderTest, RtcEventNetEqSetMinimumDelayDecoded) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); // SSRCs will be randomly assigned out of this small pool, significant only // in that it also covers such edge cases as SSRC = 0 and SSRC = 0xffffffff. // The pool is intentionally small, so as to produce collisions. @@ -461,7 +474,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventNetEqSetMinimumDelayDecoded) { original_events_by_ssrc[ssrc].push_back(std::move(event)); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& parsed_neteq_set_minimum_delay_events_by_ssrc = @@ -502,13 +515,14 @@ TEST_P(RtcEventLogEncoderTest, RtcEventNetEqSetMinimumDelayDecoded) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventAudioReceiveStreamConfig) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); uint32_t ssrc = prng_.Rand<uint32_t>(); RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap(); std::unique_ptr<RtcEventAudioReceiveStreamConfig> event = gen_.NewAudioReceiveStreamConfig(ssrc, extensions); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& audio_recv_configs = parsed_log_.audio_recv_configs(); @@ -518,13 +532,14 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioReceiveStreamConfig) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventAudioSendStreamConfig) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); uint32_t ssrc = prng_.Rand<uint32_t>(); RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap(); std::unique_ptr<RtcEventAudioSendStreamConfig> event = gen_.NewAudioSendStreamConfig(ssrc, extensions); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& audio_send_configs = parsed_log_.audio_send_configs(); @@ -533,6 +548,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioSendStreamConfig) { } TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateDelayBased) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventBweUpdateDelayBased>> events( event_count_); for (size_t i = 0; i < event_count_; ++i) { @@ -542,7 +558,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateDelayBased) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& bwe_delay_updates = parsed_log_.bwe_delay_updates(); @@ -554,6 +570,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateDelayBased) { } TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateLossBased) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventBweUpdateLossBased>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -562,7 +579,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateLossBased) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& bwe_loss_updates = parsed_log_.bwe_loss_updates(); @@ -577,6 +594,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericPacketReceived) { if (encoding_type_ == RtcEventLog::EncodingType::Legacy) { return; } + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventGenericPacketReceived>> events( event_count_); for (size_t i = 0; i < event_count_; ++i) { @@ -586,7 +604,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericPacketReceived) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& packets_received = parsed_log_.generic_packets_received(); @@ -602,6 +620,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericPacketSent) { if (encoding_type_ == RtcEventLog::EncodingType::Legacy) { return; } + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventGenericPacketSent>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -610,7 +629,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericPacketSent) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& packets_sent = parsed_log_.generic_packets_sent(); @@ -625,6 +644,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericAcksReceived) { if (encoding_type_ == RtcEventLog::EncodingType::Legacy) { return; } + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventGenericAckReceived>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -633,7 +653,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericAcksReceived) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& decoded_events = parsed_log_.generic_acks_received(); @@ -645,6 +665,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericAcksReceived) { } TEST_P(RtcEventLogEncoderTest, RtcEventDtlsTransportState) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventDtlsTransportState>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -653,7 +674,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventDtlsTransportState) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& dtls_transport_states = parsed_log_.dtls_transport_states(); @@ -670,6 +691,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventDtlsTransportState) { } TEST_P(RtcEventLogEncoderTest, RtcEventDtlsWritableState) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventDtlsWritableState>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -678,7 +700,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventDtlsWritableState) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& dtls_writable_states = parsed_log_.dtls_writable_states(); @@ -696,6 +718,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventDtlsWritableState) { } TEST_P(RtcEventLogEncoderTest, RtcEventFrameDecoded) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); // SSRCs will be randomly assigned out of this small pool, significant only // in that it also covers such edge cases as SSRC = 0 and SSRC = 0xffffffff. // The pool is intentionally small, so as to produce collisions. @@ -715,7 +738,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventFrameDecoded) { original_events_by_ssrc[ssrc].push_back(std::move(event)); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); auto status = parsed_log_.ParseString(encoded_); if (!status.ok()) RTC_LOG(LS_ERROR) << status.message(); @@ -751,11 +774,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventFrameDecoded) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePairConfig) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::unique_ptr<RtcEventIceCandidatePairConfig> event = gen_.NewIceCandidatePairConfig(); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& ice_candidate_pair_configs = parsed_log_.ice_candidate_pair_configs(); @@ -767,10 +791,11 @@ TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePairConfig) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePair) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::unique_ptr<RtcEventIceCandidatePair> event = gen_.NewIceCandidatePair(); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& ice_candidate_pair_events = parsed_log_.ice_candidate_pair_events(); @@ -781,11 +806,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePair) { } TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStarted) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); const int64_t timestamp_ms = prng_.Rand(1'000'000'000); const int64_t utc_time_ms = prng_.Rand(1'000'000'000); // Overwrite the previously encoded LogStart event. - encoded_ = encoder_->EncodeLogStart(timestamp_ms * 1000, utc_time_ms * 1000); + encoded_ = encoder->EncodeLogStart(timestamp_ms * 1000, utc_time_ms * 1000); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& start_log_events = parsed_log_.start_log_events(); @@ -795,16 +821,17 @@ TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStarted) { } TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStopped) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); const int64_t start_timestamp_ms = prng_.Rand(1'000'000'000); const int64_t start_utc_time_ms = prng_.Rand(1'000'000'000); // Overwrite the previously encoded LogStart event. - encoded_ = encoder_->EncodeLogStart(start_timestamp_ms * 1000, - start_utc_time_ms * 1000); + encoded_ = encoder->EncodeLogStart(start_timestamp_ms * 1000, + start_utc_time_ms * 1000); const int64_t stop_timestamp_ms = prng_.Rand(start_timestamp_ms, 2'000'000'000); - encoded_ += encoder_->EncodeLogEnd(stop_timestamp_ms * 1000); + encoded_ += encoder->EncodeLogEnd(stop_timestamp_ms * 1000); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& stop_log_events = parsed_log_.stop_log_events(); @@ -814,11 +841,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStopped) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventProbeClusterCreated) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::unique_ptr<RtcEventProbeClusterCreated> event = gen_.NewProbeClusterCreated(); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& bwe_probe_cluster_created_events = parsed_log_.bwe_probe_cluster_created_events(); @@ -830,11 +858,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventProbeClusterCreated) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultFailure) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::unique_ptr<RtcEventProbeResultFailure> event = gen_.NewProbeResultFailure(); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& bwe_probe_failure_events = parsed_log_.bwe_probe_failure_events(); @@ -845,11 +874,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultFailure) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultSuccess) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::unique_ptr<RtcEventProbeResultSuccess> event = gen_.NewProbeResultSuccess(); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& bwe_probe_success_events = parsed_log_.bwe_probe_success_events(); @@ -864,6 +894,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketIncoming) { // As a work around, we're removing duplicates in the parser. return; } + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventRtcpPacketIncoming>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { @@ -873,7 +904,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketIncoming) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& incoming_rtcp_packets = parsed_log_.incoming_rtcp_packets(); @@ -886,6 +917,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketIncoming) { } TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketOutgoing) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); std::vector<std::unique_ptr<RtcEventRtcpPacketOutgoing>> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -894,7 +926,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketOutgoing) { history_.push_back(events[i]->Copy()); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& outgoing_rtcp_packets = parsed_log_.outgoing_rtcp_packets(); @@ -914,6 +946,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpReceiverReport) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::ReceiverReport> events(event_count_); std::vector<int64_t> timestamps_ms(event_count_); @@ -931,7 +965,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpReceiverReport) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& receiver_reports = parsed_log_.receiver_reports(direction); @@ -952,6 +986,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpSenderReport) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::SenderReport> events(event_count_); std::vector<int64_t> timestamps_ms(event_count_); @@ -969,7 +1005,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpSenderReport) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& sender_reports = parsed_log_.sender_reports(direction); @@ -990,6 +1026,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpExtendedReports) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::ExtendedReports> events(event_count_); std::vector<int64_t> timestamps_ms(event_count_); @@ -1007,7 +1045,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpExtendedReports) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& extended_reports = parsed_log_.extended_reports(direction); @@ -1028,6 +1066,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpFir) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::Fir> events(event_count_); std::vector<int64_t> timestamps_ms(event_count_); @@ -1045,7 +1085,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpFir) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& firs = parsed_log_.firs(direction); @@ -1065,6 +1105,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPli) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::Pli> events(event_count_); std::vector<int64_t> timestamps_ms(event_count_); @@ -1082,7 +1124,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPli) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& plis = parsed_log_.plis(direction); @@ -1102,6 +1144,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpBye) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::Bye> events(event_count_); std::vector<int64_t> timestamps_ms(event_count_); @@ -1119,7 +1163,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpBye) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& byes = parsed_log_.byes(direction); @@ -1139,6 +1183,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpNack) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::Nack> events(event_count_); std::vector<int64_t> timestamps_ms(event_count_); @@ -1156,7 +1202,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpNack) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& nacks = parsed_log_.nacks(direction); @@ -1176,6 +1222,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpRemb) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::Remb> events(event_count_); std::vector<int64_t> timestamps_ms(event_count_); @@ -1193,7 +1241,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpRemb) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& rembs = parsed_log_.rembs(direction); @@ -1213,6 +1261,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpTransportFeedback) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::TransportFeedback> events; events.reserve(event_count_); @@ -1231,7 +1281,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpTransportFeedback) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& transport_feedbacks = @@ -1253,6 +1303,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>())); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector<rtcp::LossNotification> events; events.reserve(event_count_); @@ -1271,7 +1323,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) { fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000))); } - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& loss_notifications = parsed_log_.loss_notifications(direction); @@ -1285,36 +1337,43 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) { } TEST_P(RtcEventLogEncoderTest, RtcEventRtpPacketIncoming) { - TestRtpPackets<RtcEventRtpPacketIncoming, LoggedRtpPacketIncoming>(); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + TestRtpPackets<RtcEventRtpPacketIncoming, LoggedRtpPacketIncoming>(*encoder); } TEST_P(RtcEventLogEncoderTest, RtcEventRtpPacketOutgoing) { - TestRtpPackets<RtcEventRtpPacketOutgoing, LoggedRtpPacketOutgoing>(); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); + TestRtpPackets<RtcEventRtpPacketOutgoing, LoggedRtpPacketOutgoing>(*encoder); } TEST_P(RtcEventLogEncoderTest, RtcEventRtpPacketIncomingNoDependencyDescriptor) { - test::ScopedFieldTrials no_dd( + ExplicitKeyValueConfig no_dd( "WebRTC-RtcEventLogEncodeDependencyDescriptor/Disabled/"); - TestRtpPackets<RtcEventRtpPacketIncoming, LoggedRtpPacketIncoming>(); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(no_dd); + verifier_.ExpectDependencyDescriptorExtensionIsSet(false); + TestRtpPackets<RtcEventRtpPacketIncoming, LoggedRtpPacketIncoming>(*encoder); } TEST_P(RtcEventLogEncoderTest, RtcEventRtpPacketOutgoingNoDependencyDescriptor) { - test::ScopedFieldTrials no_dd( + ExplicitKeyValueConfig no_dd( "WebRTC-RtcEventLogEncodeDependencyDescriptor/Disabled/"); - TestRtpPackets<RtcEventRtpPacketOutgoing, LoggedRtpPacketOutgoing>(); + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(no_dd); + verifier_.ExpectDependencyDescriptorExtensionIsSet(false); + TestRtpPackets<RtcEventRtpPacketOutgoing, LoggedRtpPacketOutgoing>(*encoder); } // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventVideoReceiveStreamConfig) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); uint32_t ssrc = prng_.Rand<uint32_t>(); RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap(); std::unique_ptr<RtcEventVideoReceiveStreamConfig> event = gen_.NewVideoReceiveStreamConfig(ssrc, extensions); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& video_recv_configs = parsed_log_.video_recv_configs(); @@ -1324,13 +1383,14 @@ TEST_P(RtcEventLogEncoderTest, RtcEventVideoReceiveStreamConfig) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventVideoSendStreamConfig) { + std::unique_ptr<RtcEventLogEncoder> encoder = CreateEncoder(); uint32_t ssrc = prng_.Rand<uint32_t>(); RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap(); std::unique_ptr<RtcEventVideoSendStreamConfig> event = gen_.NewVideoSendStreamConfig(ssrc, extensions); history_.push_back(event->Copy()); - encoded_ += encoder_->EncodeBatch(history_.begin(), history_.end()); + encoded_ += encoder->EncodeBatch(history_.begin(), history_.end()); ASSERT_TRUE(parsed_log_.ParseString(encoded_).ok()); const auto& video_send_configs = parsed_log_.video_send_configs(); @@ -1357,7 +1417,8 @@ class RtcEventLogEncoderSimpleTest encoder_ = std::make_unique<RtcEventLogEncoderLegacy>(); break; case RtcEventLog::EncodingType::NewFormat: - encoder_ = std::make_unique<RtcEventLogEncoderNewFormat>(); + encoder_ = std::make_unique<RtcEventLogEncoderNewFormat>( + ExplicitKeyValueConfig("")); break; case RtcEventLog::EncodingType::ProtoFree: encoder_ = std::make_unique<RtcEventLogEncoderV3>(); diff --git a/third_party/libwebrtc/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.cc b/third_party/libwebrtc/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.cc index eb458c4640..59d76e7a03 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.cc @@ -14,12 +14,14 @@ namespace webrtc { -IceCandidatePairDescription::IceCandidatePairDescription() { - local_candidate_type = IceCandidateType::kUnknown; +IceCandidatePairDescription::IceCandidatePairDescription( + IceCandidateType local_candidate_type, + IceCandidateType remote_candidate_type) + : local_candidate_type(local_candidate_type), + remote_candidate_type(remote_candidate_type) { local_relay_protocol = IceCandidatePairProtocol::kUnknown; local_network_type = IceCandidateNetworkType::kUnknown; local_address_family = IceCandidatePairAddressFamily::kUnknown; - remote_candidate_type = IceCandidateType::kUnknown; remote_address_family = IceCandidatePairAddressFamily::kUnknown; candidate_pair_protocol = IceCandidatePairProtocol::kUnknown; } diff --git a/third_party/libwebrtc/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h b/third_party/libwebrtc/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h index e72d999cff..8198659cb2 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h +++ b/third_party/libwebrtc/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h @@ -18,6 +18,7 @@ #include <vector> #include "absl/strings/string_view.h" +#include "api/candidate.h" #include "api/rtc_event_log/rtc_event.h" #include "api/units/timestamp.h" #include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h" @@ -32,17 +33,6 @@ enum class IceCandidatePairConfigType { kNumValues, }; -// TODO(qingsi): Change the names of candidate types to "host", "srflx", "prflx" -// and "relay" after the naming is spec-compliant in the signaling part -enum class IceCandidateType { - kUnknown, - kLocal, - kStun, - kPrflx, - kRelay, - kNumValues, -}; - enum class IceCandidatePairProtocol { kUnknown, kUdp, @@ -88,7 +78,8 @@ struct LoggedIceCandidatePairConfig { class IceCandidatePairDescription { public: - IceCandidatePairDescription(); + IceCandidatePairDescription(IceCandidateType local_candidate_type, + IceCandidateType remote_candidate_type); explicit IceCandidatePairDescription( const IceCandidatePairDescription& other); diff --git a/third_party/libwebrtc/logging/rtc_event_log/ice_logger.cc b/third_party/libwebrtc/logging/rtc_event_log/ice_logger.cc index 390deda953..daa7057439 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/ice_logger.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/ice_logger.cc @@ -26,7 +26,8 @@ void IceEventLog::LogCandidatePairConfig( if (event_log_ == nullptr) { return; } - candidate_pair_desc_by_id_[candidate_pair_id] = candidate_pair_desc; + + candidate_pair_desc_by_id_.emplace(candidate_pair_id, candidate_pair_desc); event_log_->Log(std::make_unique<RtcEventIceCandidatePairConfig>( type, candidate_pair_id, candidate_pair_desc)); } diff --git a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc index 419afd330a..5cafe8a711 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_impl.cc @@ -39,7 +39,7 @@ std::unique_ptr<RtcEventLogEncoder> CreateEncoder(const Environment& env) { return std::make_unique<RtcEventLogEncoderLegacy>(); } else { RTC_DLOG(LS_INFO) << "Creating new format encoder for RTC event log."; - return std::make_unique<RtcEventLogEncoderNewFormat>(); + return std::make_unique<RtcEventLogEncoderNewFormat>(env.field_trials()); } } diff --git a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_parser.cc b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_parser.cc index 37bb70a69b..d6469e1033 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_parser.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_parser.cc @@ -163,22 +163,29 @@ IceCandidatePairConfigType GetRuntimeIceCandidatePairConfigType( return IceCandidatePairConfigType::kAdded; } -IceCandidateType GetRuntimeIceCandidateType( - rtclog::IceCandidatePairConfig::IceCandidateType type) { - switch (type) { +// Converts a log type (proto based) to a matching `IceCandidateType` value +// and checks for validity of the log type (since the enums aren't a perfect +// match). +bool GetRuntimeIceCandidateType( + rtclog::IceCandidatePairConfig::IceCandidateType log_type, + IceCandidateType& parsed_type) { + switch (log_type) { case rtclog::IceCandidatePairConfig::LOCAL: - return IceCandidateType::kLocal; + parsed_type = IceCandidateType::kHost; + break; case rtclog::IceCandidatePairConfig::STUN: - return IceCandidateType::kStun; + parsed_type = IceCandidateType::kSrflx; + break; case rtclog::IceCandidatePairConfig::PRFLX: - return IceCandidateType::kPrflx; + parsed_type = IceCandidateType::kPrflx; + break; case rtclog::IceCandidatePairConfig::RELAY: - return IceCandidateType::kRelay; - case rtclog::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE: - return IceCandidateType::kUnknown; + parsed_type = IceCandidateType::kRelay; + break; + default: + return false; } - RTC_DCHECK_NOTREACHED(); - return IceCandidateType::kUnknown; + return true; } IceCandidatePairProtocol GetRuntimeIceCandidatePairProtocol( @@ -806,18 +813,39 @@ IceCandidateType GetRuntimeIceCandidateType( rtclog2::IceCandidatePairConfig::IceCandidateType type) { switch (type) { case rtclog2::IceCandidatePairConfig::LOCAL: - return IceCandidateType::kLocal; + return IceCandidateType::kHost; case rtclog2::IceCandidatePairConfig::STUN: - return IceCandidateType::kStun; + return IceCandidateType::kSrflx; case rtclog2::IceCandidatePairConfig::PRFLX: return IceCandidateType::kPrflx; case rtclog2::IceCandidatePairConfig::RELAY: return IceCandidateType::kRelay; - case rtclog2::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE: - return IceCandidateType::kUnknown; + default: + RTC_DCHECK_NOTREACHED(); + return IceCandidateType::kHost; } - RTC_DCHECK_NOTREACHED(); - return IceCandidateType::kUnknown; +} + +bool GetRuntimeIceCandidateType( + rtclog2::IceCandidatePairConfig::IceCandidateType log_type, + IceCandidateType& parsed_type) { + switch (log_type) { + case rtclog2::IceCandidatePairConfig::LOCAL: + parsed_type = IceCandidateType::kHost; + break; + case rtclog2::IceCandidatePairConfig::STUN: + parsed_type = IceCandidateType::kSrflx; + break; + case rtclog2::IceCandidatePairConfig::PRFLX: + parsed_type = IceCandidateType::kPrflx; + break; + case rtclog2::IceCandidatePairConfig::RELAY: + parsed_type = IceCandidateType::kRelay; + break; + default: + return false; + } + return true; } IceCandidatePairProtocol GetRuntimeIceCandidatePairProtocol( @@ -2142,8 +2170,8 @@ ParsedRtcEventLog::GetIceCandidatePairConfig( RTC_PARSE_CHECK_OR_RETURN(config.has_candidate_pair_id()); res.candidate_pair_id = config.candidate_pair_id(); RTC_PARSE_CHECK_OR_RETURN(config.has_local_candidate_type()); - res.local_candidate_type = - GetRuntimeIceCandidateType(config.local_candidate_type()); + RTC_PARSE_CHECK_OR_RETURN(GetRuntimeIceCandidateType( + config.local_candidate_type(), res.local_candidate_type)); RTC_PARSE_CHECK_OR_RETURN(config.has_local_relay_protocol()); res.local_relay_protocol = GetRuntimeIceCandidatePairProtocol(config.local_relay_protocol()); @@ -2154,8 +2182,8 @@ ParsedRtcEventLog::GetIceCandidatePairConfig( res.local_address_family = GetRuntimeIceCandidatePairAddressFamily(config.local_address_family()); RTC_PARSE_CHECK_OR_RETURN(config.has_remote_candidate_type()); - res.remote_candidate_type = - GetRuntimeIceCandidateType(config.remote_candidate_type()); + RTC_PARSE_CHECK_OR_RETURN(GetRuntimeIceCandidateType( + config.remote_candidate_type(), res.remote_candidate_type)); RTC_PARSE_CHECK_OR_RETURN(config.has_remote_address_family()); res.remote_address_family = GetRuntimeIceCandidatePairAddressFamily(config.remote_address_family()); @@ -2242,13 +2270,13 @@ std::vector<InferredRouteChangeEvent> ParsedRtcEventLog::GetRouteChanges() if (candidate.remote_address_family == IceCandidatePairAddressFamily::kIpv6) route.send_overhead += kIpv6Overhead - kIpv4Overhead; - if (candidate.remote_candidate_type != IceCandidateType::kLocal) + if (candidate.remote_candidate_type != IceCandidateType::kHost) route.send_overhead += kStunOverhead; route.return_overhead = kUdpOverhead + kSrtpOverhead + kIpv4Overhead; if (candidate.remote_address_family == IceCandidatePairAddressFamily::kIpv6) route.return_overhead += kIpv6Overhead - kIpv4Overhead; - if (candidate.remote_candidate_type != IceCandidateType::kLocal) + if (candidate.remote_candidate_type != IceCandidateType::kHost) route.return_overhead += kStunOverhead; route_changes.push_back(route); } @@ -3498,8 +3526,8 @@ ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::StoreIceCandidatePairConfig( RTC_PARSE_CHECK_OR_RETURN(proto.has_candidate_pair_id()); ice_config.candidate_pair_id = proto.candidate_pair_id(); RTC_PARSE_CHECK_OR_RETURN(proto.has_local_candidate_type()); - ice_config.local_candidate_type = - GetRuntimeIceCandidateType(proto.local_candidate_type()); + RTC_PARSE_CHECK_OR_RETURN(GetRuntimeIceCandidateType( + proto.local_candidate_type(), ice_config.local_candidate_type)); RTC_PARSE_CHECK_OR_RETURN(proto.has_local_relay_protocol()); ice_config.local_relay_protocol = GetRuntimeIceCandidatePairProtocol(proto.local_relay_protocol()); @@ -3510,8 +3538,8 @@ ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::StoreIceCandidatePairConfig( ice_config.local_address_family = GetRuntimeIceCandidatePairAddressFamily(proto.local_address_family()); RTC_PARSE_CHECK_OR_RETURN(proto.has_remote_candidate_type()); - ice_config.remote_candidate_type = - GetRuntimeIceCandidateType(proto.remote_candidate_type()); + RTC_PARSE_CHECK_OR_RETURN(GetRuntimeIceCandidateType( + proto.remote_candidate_type(), ice_config.remote_candidate_type)); RTC_PARSE_CHECK_OR_RETURN(proto.has_remote_address_family()); ice_config.remote_address_family = GetRuntimeIceCandidatePairAddressFamily(proto.remote_address_family()); diff --git a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_parser.h b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_parser.h index def9f0ab35..c24e5e8186 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_parser.h +++ b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_parser.h @@ -71,12 +71,15 @@ enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; enum class LoggedMediaType : uint8_t { kUnknown, kAudio, kVideo }; struct LoggedPacketInfo { + static LoggedPacketInfo CreateEmptyForTesting() { return LoggedPacketInfo(); } + LoggedPacketInfo(const LoggedRtpPacket& rtp, LoggedMediaType media_type, bool rtx, Timestamp capture_time); LoggedPacketInfo(const LoggedPacketInfo&); ~LoggedPacketInfo(); + int64_t log_time_ms() const { return log_packet_time.ms(); } int64_t log_time_us() const { return log_packet_time.us(); } uint32_t ssrc; @@ -114,6 +117,12 @@ struct LoggedPacketInfo { // time, and this is instead calculated as the difference in reported receive // time between this packet and the last packet in the same feedback message. TimeDelta feedback_hold_duration = TimeDelta::MinusInfinity(); + + private: + LoggedPacketInfo() + : capture_time(Timestamp::MinusInfinity()), + log_packet_time(Timestamp::MinusInfinity()), + reported_send_time(Timestamp::MinusInfinity()) {} }; struct InferredRouteChangeEvent { diff --git a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.cc b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.cc index aece4b5753..bd83586456 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.cc +++ b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.cc @@ -42,8 +42,8 @@ #include "rtc_base/buffer.h" #include "rtc_base/checks.h" #include "rtc_base/time_utils.h" -#include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/ntp_time.h" +#include "test/gmock.h" #include "test/gtest.h" namespace webrtc { @@ -52,6 +52,9 @@ namespace test { namespace { +using ::testing::ElementsAreArray; +using ::testing::IsEmpty; + struct ExtensionPair { RTPExtensionType type; const char* name; @@ -217,10 +220,27 @@ EventGenerator::NewProbeResultSuccess() { return std::make_unique<RtcEventProbeResultSuccess>(id, bitrate_bps); } +constexpr uint32_t CandidateTypeCount() { + // This switch statement only exists to catch changes to the IceCandidateType + // enumeration. If you get an error here, please update the switch statement + // and the return value. + IceCandidateType type = IceCandidateType::kHost; + switch (type) { + case IceCandidateType::kHost: + case IceCandidateType::kSrflx: + case IceCandidateType::kPrflx: + case IceCandidateType::kRelay: + break; + } + return 4u; +} + std::unique_ptr<RtcEventIceCandidatePairConfig> EventGenerator::NewIceCandidatePairConfig() { - IceCandidateType local_candidate_type = static_cast<IceCandidateType>( - prng_.Rand(static_cast<uint32_t>(IceCandidateType::kNumValues) - 1)); + static_assert(static_cast<int>(IceCandidateType::kHost) == 0, + "Expect kLocal to be the first enum value, equal to 0"); + IceCandidateType local_candidate_type = + static_cast<IceCandidateType>(prng_.Rand(CandidateTypeCount() - 1)); IceCandidateNetworkType local_network_type = static_cast<IceCandidateNetworkType>(prng_.Rand( static_cast<uint32_t>(IceCandidateNetworkType::kNumValues) - 1)); @@ -228,8 +248,8 @@ EventGenerator::NewIceCandidatePairConfig() { static_cast<IceCandidatePairAddressFamily>(prng_.Rand( static_cast<uint32_t>(IceCandidatePairAddressFamily::kNumValues) - 1)); - IceCandidateType remote_candidate_type = static_cast<IceCandidateType>( - prng_.Rand(static_cast<uint32_t>(IceCandidateType::kNumValues) - 1)); + IceCandidateType remote_candidate_type = + static_cast<IceCandidateType>(prng_.Rand(CandidateTypeCount() - 1)); IceCandidatePairAddressFamily remote_address_family = static_cast<IceCandidatePairAddressFamily>(prng_.Rand( static_cast<uint32_t>(IceCandidatePairAddressFamily::kNumValues) - @@ -238,12 +258,10 @@ EventGenerator::NewIceCandidatePairConfig() { static_cast<IceCandidatePairProtocol>(prng_.Rand( static_cast<uint32_t>(IceCandidatePairProtocol::kNumValues) - 1)); - IceCandidatePairDescription desc; - desc.local_candidate_type = local_candidate_type; + IceCandidatePairDescription desc(local_candidate_type, remote_candidate_type); desc.local_relay_protocol = protocol_type; desc.local_network_type = local_network_type; desc.local_address_family = local_address_family; - desc.remote_candidate_type = remote_candidate_type; desc.remote_address_family = remote_address_family; desc.candidate_pair_protocol = protocol_type; @@ -1032,23 +1050,15 @@ void VerifyLoggedRtpHeader(const Event& original_header, } template <typename Event> -void VerifyLoggedDependencyDescriptor(const Event& packet, - const std::vector<uint8_t>& logged_dd) { - if (webrtc::field_trial::IsDisabled( - "WebRTC-RtcEventLogEncodeDependencyDescriptor")) { - EXPECT_TRUE(logged_dd.empty()); - } else { +void EventVerifier::VerifyLoggedDependencyDescriptor( + const Event& packet, + const std::vector<uint8_t>& logged_dd) const { + if (expect_dependency_descriptor_rtp_header_extension_is_set_) { rtc::ArrayView<const uint8_t> original = packet.template GetRawExtension<RtpDependencyDescriptorExtension>(); - EXPECT_EQ(logged_dd.size(), original.size()); - bool dd_is_same = true; - for (size_t i = 0; i < logged_dd.size(); ++i) { - dd_is_same = logged_dd[i] == original[i]; - if (!dd_is_same) { - break; - } - } - EXPECT_TRUE(dd_is_same); + EXPECT_THAT(logged_dd, ElementsAreArray(original)); + } else { + EXPECT_THAT(logged_dd, IsEmpty()); } } diff --git a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.h b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.h index 950a622f8b..e0fd3b741b 100644 --- a/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.h +++ b/third_party/libwebrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.h @@ -160,6 +160,10 @@ class EventVerifier { explicit EventVerifier(RtcEventLog::EncodingType encoding_type) : encoding_type_(encoding_type) {} + void ExpectDependencyDescriptorExtensionIsSet(bool value) { + expect_dependency_descriptor_rtp_header_extension_is_set_ = value; + } + void VerifyLoggedAlrStateEvent(const RtcEventAlrState& original_event, const LoggedAlrStateEvent& logged_event) const; @@ -331,7 +335,13 @@ class EventVerifier { void VerifyReportBlock(const rtcp::ReportBlock& original_report_block, const rtcp::ReportBlock& logged_report_block); + template <typename Event> + void VerifyLoggedDependencyDescriptor( + const Event& packet, + const std::vector<uint8_t>& logged_dd) const; + RtcEventLog::EncodingType encoding_type_; + bool expect_dependency_descriptor_rtp_header_extension_is_set_ = true; }; } // namespace test |