diff --git a/logging/BUILD.gn b/logging/BUILD.gn index 91890553a3..5b91a39357 100644 --- a/logging/BUILD.gn +++ b/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", @@ -617,6 +617,7 @@ if (rtc_enable_protobuf) { "../api/environment:environment_factory", "../api/rtc_event_log", "../api/rtc_event_log:rtc_event_log_factory", + "../api/transport:field_trial_based_config", "../api/units:time_delta", "../api/units:timestamp", "../call", diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc index 4c662fd266..ebda3bfeed 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc +++ b/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 + #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 @@ -381,10 +383,12 @@ void EncodeRtcpPacket(rtc::ArrayView batch, } proto_batch->set_raw_packet_blobs(EncodeBlobs(scrubed_packets)); } +} // namespace -template -void EncodeRtpPacket(const std::vector& batch, - ProtoType* proto_batch) { +template +void RtcEventLogEncoderNewFormat::EncodeRtpPacket(const Batch& batch, + ProtoType* proto_batch) { + using EventType = std::remove_pointer_t; if (batch.empty()) { return; } @@ -459,8 +463,7 @@ void EncodeRtpPacket(const std::vector& 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> raw_dds(batch.size()); bool has_dd = false; for (size_t i = 0; i < batch.size(); ++i) { @@ -674,15 +677,13 @@ void EncodeRtpPacket(const std::vector& 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/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h b/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h index 6747f41f07..6a657090dd 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h @@ -18,6 +18,7 @@ #include #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 batch, rtclog2::EventStream* event_stream); @@ -157,6 +156,11 @@ class RtcEventLogEncoderNewFormat final : public RtcEventLogEncoder { void EncodeVideoSendStreamConfig( rtc::ArrayView batch, rtclog2::EventStream* event_stream); + template + 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/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc index 612f85bf61..73ff67e8b9 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_unittest.cc @@ -14,6 +14,7 @@ #include #include +#include "api/transport/field_trial_based_config.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,14 @@ #include "modules/rtp_rtcp/source/rtp_header_extensions.h" #include "rtc_base/fake_clock.h" #include "rtc_base/random.h" +#include "test/explicit_key_value_config.h" #include "test/field_trial.h" #include "test/gtest.h" namespace webrtc { + +using test::ExplicitKeyValueConfig; + class RtcEventLogEncoderTest : public ::testing::TestWithParam< std::tuple> { @@ -55,22 +60,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 CreateEncoder() { + std::unique_ptr encoder; switch (encoding_type_) { case RtcEventLog::EncodingType::Legacy: - encoder_ = std::make_unique(); + encoder = std::make_unique(); break; case RtcEventLog::EncodingType::NewFormat: - encoder_ = std::make_unique(); + encoder = std::make_unique( + FieldTrialBasedConfig()); break; case RtcEventLog::EncodingType::ProtoFree: - encoder_ = std::make_unique(); + encoder = std::make_unique(); 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 @@ -92,7 +101,6 @@ class RtcEventLogEncoderTest void TestRtpPackets(); std::deque> history_; - std::unique_ptr encoder_; ParsedRtcEventLog parsed_log_; const uint64_t seed_; Random prng_; @@ -108,12 +116,13 @@ void RtcEventLogEncoderTest::TestRtcEventAudioNetworkAdaptation( const std::vector>& events) { ASSERT_TRUE(history_.empty()) << "Function should be called once per test."; + std::unique_ptr 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(); @@ -172,6 +181,7 @@ void RtcEventLogEncoderTest::TestRtpPackets() { const std::vector kSsrcPool = {0x00000000, 0x12345678, 0xabcdef01, 0xffffffff, 0x20171024, 0x19840730, 0x19831230}; + std::unique_ptr encoder = CreateEncoder(); // TODO(terelius): Test extensions for legacy encoding, too. RtpHeaderExtensionMap extension_map; @@ -193,7 +203,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 +223,7 @@ void RtcEventLogEncoderTest::TestRtpPackets() { } TEST_P(RtcEventLogEncoderTest, RtcEventAlrState) { + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) ? gen_.NewAlrState() @@ -220,7 +231,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 +245,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRouteChange) { if (encoding_type_ == RtcEventLog::EncodingType::Legacy) { return; } + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) ? gen_.NewRouteChange() @@ -241,7 +253,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 +264,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRouteChange) { } TEST_P(RtcEventLogEncoderTest, RtcEventRemoteEstimate) { + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -260,7 +273,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRemoteEstimate) { history_.push_back(std::make_unique(*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 +408,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationAll) { } TEST_P(RtcEventLogEncoderTest, RtcEventAudioPlayout) { + std::unique_ptr 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 +428,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 +457,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioPlayout) { } TEST_P(RtcEventLogEncoderTest, RtcEventNetEqSetMinimumDelayDecoded) { + std::unique_ptr 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 +476,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 +517,14 @@ TEST_P(RtcEventLogEncoderTest, RtcEventNetEqSetMinimumDelayDecoded) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventAudioReceiveStreamConfig) { + std::unique_ptr encoder = CreateEncoder(); uint32_t ssrc = prng_.Rand(); RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap(); std::unique_ptr 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 +534,14 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioReceiveStreamConfig) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventAudioSendStreamConfig) { + std::unique_ptr encoder = CreateEncoder(); uint32_t ssrc = prng_.Rand(); RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap(); std::unique_ptr 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 +550,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioSendStreamConfig) { } TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateDelayBased) { + std::unique_ptr encoder = CreateEncoder(); std::vector> events( event_count_); for (size_t i = 0; i < event_count_; ++i) { @@ -542,7 +560,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 +572,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateDelayBased) { } TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateLossBased) { + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -562,7 +581,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 +596,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericPacketReceived) { if (encoding_type_ == RtcEventLog::EncodingType::Legacy) { return; } + std::unique_ptr encoder = CreateEncoder(); std::vector> events( event_count_); for (size_t i = 0; i < event_count_; ++i) { @@ -586,7 +606,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 +622,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericPacketSent) { if (encoding_type_ == RtcEventLog::EncodingType::Legacy) { return; } + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -610,7 +631,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 +646,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericAcksReceived) { if (encoding_type_ == RtcEventLog::EncodingType::Legacy) { return; } + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -633,7 +655,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 +667,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventGenericAcksReceived) { } TEST_P(RtcEventLogEncoderTest, RtcEventDtlsTransportState) { + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -653,7 +676,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 +693,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventDtlsTransportState) { } TEST_P(RtcEventLogEncoderTest, RtcEventDtlsWritableState) { + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -678,7 +702,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 +720,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventDtlsWritableState) { } TEST_P(RtcEventLogEncoderTest, RtcEventFrameDecoded) { + std::unique_ptr 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 +740,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 +776,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventFrameDecoded) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePairConfig) { + std::unique_ptr encoder = CreateEncoder(); std::unique_ptr 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 +793,11 @@ TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePairConfig) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePair) { + std::unique_ptr encoder = CreateEncoder(); std::unique_ptr 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 +808,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePair) { } TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStarted) { + std::unique_ptr 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 +823,17 @@ TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStarted) { } TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStopped) { + std::unique_ptr 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 +843,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStopped) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventProbeClusterCreated) { + std::unique_ptr encoder = CreateEncoder(); std::unique_ptr 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 +860,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventProbeClusterCreated) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultFailure) { + std::unique_ptr encoder = CreateEncoder(); std::unique_ptr 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 +876,12 @@ TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultFailure) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultSuccess) { + std::unique_ptr encoder = CreateEncoder(); std::unique_ptr 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 +896,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketIncoming) { // As a work around, we're removing duplicates in the parser. return; } + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { @@ -873,7 +906,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 +919,7 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketIncoming) { } TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketOutgoing) { + std::unique_ptr encoder = CreateEncoder(); std::vector> events(event_count_); for (size_t i = 0; i < event_count_; ++i) { events[i] = (i == 0 || !force_repeated_fields_) @@ -894,7 +928,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 +948,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpReceiverReport) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); std::vector timestamps_ms(event_count_); @@ -931,7 +967,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 +988,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpSenderReport) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); std::vector timestamps_ms(event_count_); @@ -969,7 +1007,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 +1028,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpExtendedReports) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); std::vector timestamps_ms(event_count_); @@ -1007,7 +1047,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 +1068,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpFir) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); std::vector timestamps_ms(event_count_); @@ -1045,7 +1087,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 +1107,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPli) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); std::vector timestamps_ms(event_count_); @@ -1082,7 +1126,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 +1146,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpBye) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); std::vector timestamps_ms(event_count_); @@ -1119,7 +1165,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 +1185,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpNack) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); std::vector timestamps_ms(event_count_); @@ -1156,7 +1204,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 +1224,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpRemb) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events(event_count_); std::vector timestamps_ms(event_count_); @@ -1193,7 +1243,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 +1263,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpTransportFeedback) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events; events.reserve(event_count_); @@ -1231,7 +1283,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 +1305,8 @@ TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) { rtc::ScopedFakeClock fake_clock; fake_clock.SetTime(Timestamp::Millis(prng_.Rand())); + std::unique_ptr encoder = CreateEncoder(); + for (auto direction : {kIncomingPacket, kOutgoingPacket}) { std::vector events; events.reserve(event_count_); @@ -1271,7 +1325,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); @@ -1308,13 +1362,14 @@ TEST_P(RtcEventLogEncoderTest, // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventVideoReceiveStreamConfig) { + std::unique_ptr encoder = CreateEncoder(); uint32_t ssrc = prng_.Rand(); RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap(); std::unique_ptr 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 +1379,14 @@ TEST_P(RtcEventLogEncoderTest, RtcEventVideoReceiveStreamConfig) { // TODO(eladalon/terelius): Test with multiple events in the batch. TEST_P(RtcEventLogEncoderTest, RtcEventVideoSendStreamConfig) { + std::unique_ptr encoder = CreateEncoder(); uint32_t ssrc = prng_.Rand(); RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap(); std::unique_ptr 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 +1413,8 @@ class RtcEventLogEncoderSimpleTest encoder_ = std::make_unique(); break; case RtcEventLog::EncodingType::NewFormat: - encoder_ = std::make_unique(); + encoder_ = std::make_unique( + ExplicitKeyValueConfig("")); break; case RtcEventLog::EncodingType::ProtoFree: encoder_ = std::make_unique(); diff --git a/logging/rtc_event_log/rtc_event_log_impl.cc b/logging/rtc_event_log/rtc_event_log_impl.cc index 419afd330a..5cafe8a711 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.cc +++ b/logging/rtc_event_log/rtc_event_log_impl.cc @@ -39,7 +39,7 @@ std::unique_ptr CreateEncoder(const Environment& env) { return std::make_unique(); } else { RTC_DLOG(LS_INFO) << "Creating new format encoder for RTC event log."; - return std::make_unique(); + return std::make_unique(env.field_trials()); } }