diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder.h b/logging/rtc_event_log/encoder/rtc_event_log_encoder.h index 8f509ce896..beb711c9dd 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder.h +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder.h @@ -25,8 +25,6 @@ class RtcEventLogEncoder { virtual std::string EncodeLogStart(int64_t timestamp_us) = 0; virtual std::string EncodeLogEnd(int64_t timestamp_us) = 0; - virtual std::string Encode(const RtcEvent& event) = 0; - virtual std::string EncodeBatch( std::deque>::const_iterator begin, std::deque>::const_iterator end) = 0; diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc index c05f7717c8..1f02bccbaf 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc @@ -105,7 +105,6 @@ rtclog::VideoReceiveConfig_RtcpMode ConvertRtcpMode(RtcpMode rtcp_mode) { } } // namespace - std::string RtcEventLogEncoderLegacy::EncodeLogStart(int64_t timestamp_us) { rtclog::Event rtclog_event; rtclog_event.set_timestamp_us(timestamp_us); diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h b/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h index a8173135ae..63102c502a 100644 --- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h +++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h @@ -50,8 +50,6 @@ class RtcEventLogEncoderLegacy final : public RtcEventLogEncoder { public: ~RtcEventLogEncoderLegacy() override = default; - std::string Encode(const RtcEvent& event) override; - std::string EncodeLogStart(int64_t timestamp_us) override; std::string EncodeLogEnd(int64_t timestamp_us) override; @@ -60,6 +58,7 @@ class RtcEventLogEncoderLegacy final : public RtcEventLogEncoder { std::deque>::const_iterator end) override; private: + std::string Encode(const RtcEvent& event); // Encoding entry-point for the various RtcEvent subclasses. std::string EncodeAlrState(const RtcEventAlrState& event); std::string EncodeAudioNetworkAdaptation( 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 00dad29d0f..a8e6e8d83c 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 @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -117,6 +118,7 @@ class RtcEventLogEncoderTest : public testing::TestWithParam { int RandomBitrate() { return RandomInt(); } + std::deque> history_; // TODO(eladalon): Once we have more than once possible encoder, parameterize // encoder selection. std::unique_ptr encoder_; @@ -126,12 +128,16 @@ class RtcEventLogEncoderTest : public testing::TestWithParam { void RtcEventLogEncoderTest::TestRtcEventAudioNetworkAdaptation( std::unique_ptr runtime_config) { + // This function is called repeatedly. Clear state between calls. + history_.clear(); auto original_runtime_config = *runtime_config; auto event = rtc::MakeUnique( std::move(runtime_config)); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT); @@ -220,8 +226,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioPlayout) { const uint32_t ssrc = RandomSsrc(); auto event = rtc::MakeUnique(ssrc); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT); @@ -248,8 +256,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioReceiveStreamConfig) { auto event = rtc::MakeUnique( std::move(stream_config)); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT); @@ -271,8 +281,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventAudioSendStreamConfig) { auto event = rtc::MakeUnique(std::move(stream_config)); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT); @@ -289,8 +301,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateDelayBased) { auto event = rtc::MakeUnique(bitrate_bps, detector_state); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE); @@ -311,8 +325,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateLossBased) { auto event = rtc::MakeUnique( bitrate_bps, fraction_loss, total_packets); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE); @@ -358,8 +374,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventProbeClusterCreated) { auto event = rtc::MakeUnique( id, bitrate_bps, min_probes, min_bytes); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT); @@ -380,8 +398,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultFailure) { auto event = rtc::MakeUnique(id, failure_reason); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT); @@ -401,8 +421,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultSuccess) { auto event = rtc::MakeUnique(id, bitrate_bps); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT); @@ -428,8 +450,10 @@ void RtcEventLogEncoderTest::TestRtcEventRtcpPacket(PacketDirection direction) { event = rtc::MakeUnique(rtcp_packet); } const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::RTCP_EVENT); @@ -480,8 +504,10 @@ void RtcEventLogEncoderTest::TestRtcEventRtpPacket(PacketDirection direction) { probe_cluster_id); } const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::RTP_EVENT); @@ -528,8 +554,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventVideoReceiveStreamConfig) { auto event = rtc::MakeUnique( std::move(stream_config)); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT); @@ -552,8 +580,10 @@ TEST_P(RtcEventLogEncoderTest, RtcEventVideoSendStreamConfig) { auto event = rtc::MakeUnique(std::move(stream_config)); const int64_t timestamp_us = event->timestamp_us_; + history_.push_back(std::move(event)); - ASSERT_TRUE(parsed_log_.ParseString(encoder_->Encode(*event))); + std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end()); + ASSERT_TRUE(parsed_log_.ParseString(encoded)); ASSERT_EQ(parsed_log_.GetNumberOfEvents(), 1u); ASSERT_EQ(parsed_log_.GetEventType(0), ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT);