1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <deque>
12 #include <limits>
13 #include <memory>
14 #include <string>
15 #include <tuple>
16
17 #include "logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h"
18 #include "logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h"
19 #include "logging/rtc_event_log/events/rtc_event_alr_state.h"
20 #include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
21 #include "logging/rtc_event_log/events/rtc_event_audio_playout.h"
22 #include "logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h"
23 #include "logging/rtc_event_log/events/rtc_event_audio_send_stream_config.h"
24 #include "logging/rtc_event_log/events/rtc_event_bwe_update_delay_based.h"
25 #include "logging/rtc_event_log/events/rtc_event_bwe_update_loss_based.h"
26 #include "logging/rtc_event_log/events/rtc_event_probe_cluster_created.h"
27 #include "logging/rtc_event_log/events/rtc_event_probe_result_failure.h"
28 #include "logging/rtc_event_log/events/rtc_event_probe_result_success.h"
29 #include "logging/rtc_event_log/events/rtc_event_rtcp_packet_incoming.h"
30 #include "logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h"
31 #include "logging/rtc_event_log/events/rtc_event_rtp_packet_incoming.h"
32 #include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h"
33 #include "logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h"
34 #include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h"
35 #include "logging/rtc_event_log/rtc_event_log_parser.h"
36 #include "logging/rtc_event_log/rtc_event_log_unittest_helper.h"
37 #include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor_config.h"
38 #include "modules/remote_bitrate_estimator/include/bwe_defines.h"
39 #include "modules/rtp_rtcp/source/rtp_header_extensions.h"
40 #include "rtc_base/fake_clock.h"
41 #include "rtc_base/random.h"
42 #include "test/gtest.h"
43
44 namespace webrtc {
45 class RtcEventLogEncoderTest
46 : public ::testing::TestWithParam<std::tuple<int, bool, size_t, bool>> {
47 protected:
RtcEventLogEncoderTest()48 RtcEventLogEncoderTest()
49 : seed_(std::get<0>(GetParam())),
50 prng_(seed_),
51 new_encoding_(std::get<1>(GetParam())),
52 event_count_(std::get<2>(GetParam())),
53 force_repeated_fields_(std::get<3>(GetParam())),
54 gen_(seed_ * 880001UL),
55 verifier_(new_encoding_ ? RtcEventLog::EncodingType::NewFormat
56 : RtcEventLog::EncodingType::Legacy) {
57 if (new_encoding_)
58 encoder_ = std::make_unique<RtcEventLogEncoderNewFormat>();
59 else
60 encoder_ = std::make_unique<RtcEventLogEncoderLegacy>();
61 }
62 ~RtcEventLogEncoderTest() override = default;
63
64 // ANA events have some optional fields, so we want to make sure that we get
65 // correct behavior both when all of the values are there, as well as when
66 // only some.
67 void TestRtcEventAudioNetworkAdaptation(
68 const std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>>&);
69
70 template <typename EventType>
71 std::unique_ptr<EventType> NewRtpPacket(
72 uint32_t ssrc,
73 const RtpHeaderExtensionMap& extension_map);
74
75 template <typename ParsedType>
76 const std::vector<ParsedType>* GetRtpPacketsBySsrc(
77 const ParsedRtcEventLog* parsed_log,
78 uint32_t ssrc);
79
80 template <typename EventType, typename ParsedType>
81 void TestRtpPackets();
82
83 std::deque<std::unique_ptr<RtcEvent>> history_;
84 std::unique_ptr<RtcEventLogEncoder> encoder_;
85 ParsedRtcEventLog parsed_log_;
86 const uint64_t seed_;
87 Random prng_;
88 const bool new_encoding_;
89 const size_t event_count_;
90 const bool force_repeated_fields_;
91 test::EventGenerator gen_;
92 test::EventVerifier verifier_;
93 };
94
TestRtcEventAudioNetworkAdaptation(const std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>> & events)95 void RtcEventLogEncoderTest::TestRtcEventAudioNetworkAdaptation(
96 const std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>>&
97 events) {
98 ASSERT_TRUE(history_.empty()) << "Function should be called once per test.";
99
100 for (auto& event : events) {
101 history_.push_back(event->Copy());
102 }
103
104 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
105 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
106 const auto& ana_configs = parsed_log_.audio_network_adaptation_events();
107
108 ASSERT_EQ(ana_configs.size(), events.size());
109 for (size_t i = 0; i < events.size(); ++i) {
110 verifier_.VerifyLoggedAudioNetworkAdaptationEvent(*events[i],
111 ana_configs[i]);
112 }
113 }
114
115 template <>
NewRtpPacket(uint32_t ssrc,const RtpHeaderExtensionMap & extension_map)116 std::unique_ptr<RtcEventRtpPacketIncoming> RtcEventLogEncoderTest::NewRtpPacket(
117 uint32_t ssrc,
118 const RtpHeaderExtensionMap& extension_map) {
119 return gen_.NewRtpPacketIncoming(ssrc, extension_map, false);
120 }
121
122 template <>
NewRtpPacket(uint32_t ssrc,const RtpHeaderExtensionMap & extension_map)123 std::unique_ptr<RtcEventRtpPacketOutgoing> RtcEventLogEncoderTest::NewRtpPacket(
124 uint32_t ssrc,
125 const RtpHeaderExtensionMap& extension_map) {
126 return gen_.NewRtpPacketOutgoing(ssrc, extension_map, false);
127 }
128
129 template <>
130 const std::vector<LoggedRtpPacketIncoming>*
GetRtpPacketsBySsrc(const ParsedRtcEventLog * parsed_log,uint32_t ssrc)131 RtcEventLogEncoderTest::GetRtpPacketsBySsrc(const ParsedRtcEventLog* parsed_log,
132 uint32_t ssrc) {
133 const auto& incoming_streams = parsed_log->incoming_rtp_packets_by_ssrc();
134 for (const auto& stream : incoming_streams) {
135 if (stream.ssrc == ssrc) {
136 return &stream.incoming_packets;
137 }
138 }
139 return nullptr;
140 }
141
142 template <>
143 const std::vector<LoggedRtpPacketOutgoing>*
GetRtpPacketsBySsrc(const ParsedRtcEventLog * parsed_log,uint32_t ssrc)144 RtcEventLogEncoderTest::GetRtpPacketsBySsrc(const ParsedRtcEventLog* parsed_log,
145 uint32_t ssrc) {
146 const auto& outgoing_streams = parsed_log->outgoing_rtp_packets_by_ssrc();
147 for (const auto& stream : outgoing_streams) {
148 if (stream.ssrc == ssrc) {
149 return &stream.outgoing_packets;
150 }
151 }
152 return nullptr;
153 }
154
155 template <typename EventType, typename ParsedType>
TestRtpPackets()156 void RtcEventLogEncoderTest::TestRtpPackets() {
157 // SSRCs will be randomly assigned out of this small pool, significant only
158 // in that it also covers such edge cases as SSRC = 0 and SSRC = 0xffffffff.
159 // The pool is intentionally small, so as to produce collisions.
160 const std::vector<uint32_t> kSsrcPool = {0x00000000, 0x12345678, 0xabcdef01,
161 0xffffffff, 0x20171024, 0x19840730,
162 0x19831230};
163
164 // TODO(terelius): Test extensions for legacy encoding, too.
165 RtpHeaderExtensionMap extension_map;
166 if (new_encoding_) {
167 extension_map = gen_.NewRtpHeaderExtensionMap(true);
168 }
169
170 // Simulate |event_count_| RTP packets, with SSRCs assigned randomly
171 // out of the small pool above.
172 std::map<uint32_t, std::vector<std::unique_ptr<EventType>>> events_by_ssrc;
173 for (size_t i = 0; i < event_count_; ++i) {
174 const uint32_t ssrc = kSsrcPool[prng_.Rand(kSsrcPool.size() - 1)];
175 std::unique_ptr<EventType> event =
176 (events_by_ssrc[ssrc].empty() || !force_repeated_fields_)
177 ? NewRtpPacket<EventType>(ssrc, extension_map)
178 : events_by_ssrc[ssrc][0]->Copy();
179 history_.push_back(event->Copy());
180 events_by_ssrc[ssrc].emplace_back(std::move(event));
181 }
182
183 // Encode and parse.
184 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
185 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
186
187 // For each SSRC, make sure the RTP packets associated with it to have been
188 // correctly encoded and parsed.
189 for (auto it = events_by_ssrc.begin(); it != events_by_ssrc.end(); ++it) {
190 const uint32_t ssrc = it->first;
191 const auto& original_packets = it->second;
192 const std::vector<ParsedType>* parsed_rtp_packets =
193 GetRtpPacketsBySsrc<ParsedType>(&parsed_log_, ssrc);
194 ASSERT_NE(parsed_rtp_packets, nullptr);
195 ASSERT_EQ(original_packets.size(), parsed_rtp_packets->size());
196 for (size_t i = 0; i < original_packets.size(); ++i) {
197 verifier_.VerifyLoggedRtpPacket<EventType, ParsedType>(
198 *original_packets[i], (*parsed_rtp_packets)[i]);
199 }
200 }
201 }
202
TEST_P(RtcEventLogEncoderTest,RtcEventAlrState)203 TEST_P(RtcEventLogEncoderTest, RtcEventAlrState) {
204 std::vector<std::unique_ptr<RtcEventAlrState>> events(event_count_);
205 for (size_t i = 0; i < event_count_; ++i) {
206 events[i] = (i == 0 || !force_repeated_fields_) ? gen_.NewAlrState()
207 : events[0]->Copy();
208 history_.push_back(events[i]->Copy());
209 }
210
211 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
212 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
213 const auto& alr_state_events = parsed_log_.alr_state_events();
214
215 ASSERT_EQ(alr_state_events.size(), event_count_);
216 for (size_t i = 0; i < event_count_; ++i) {
217 verifier_.VerifyLoggedAlrStateEvent(*events[i], alr_state_events[i]);
218 }
219 }
220
TEST_P(RtcEventLogEncoderTest,RtcEventRouteChange)221 TEST_P(RtcEventLogEncoderTest, RtcEventRouteChange) {
222 if (!new_encoding_) {
223 return;
224 }
225 std::vector<std::unique_ptr<RtcEventRouteChange>> events(event_count_);
226 for (size_t i = 0; i < event_count_; ++i) {
227 events[i] = (i == 0 || !force_repeated_fields_) ? gen_.NewRouteChange()
228 : events[0]->Copy();
229 history_.push_back(events[i]->Copy());
230 }
231
232 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
233 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
234 const auto& route_change_events = parsed_log_.route_change_events();
235
236 ASSERT_EQ(route_change_events.size(), event_count_);
237 for (size_t i = 0; i < event_count_; ++i) {
238 verifier_.VerifyLoggedRouteChangeEvent(*events[i], route_change_events[i]);
239 }
240 }
241
TEST_P(RtcEventLogEncoderTest,RtcEventRemoteEstimate)242 TEST_P(RtcEventLogEncoderTest, RtcEventRemoteEstimate) {
243 if (!new_encoding_) {
244 return;
245 }
246 std::vector<std::unique_ptr<RtcEventRemoteEstimate>> events(event_count_);
247 for (size_t i = 0; i < event_count_; ++i) {
248 events[i] = (i == 0 || !force_repeated_fields_)
249 ? gen_.NewRemoteEstimate()
250 : std::make_unique<RtcEventRemoteEstimate>(*events[0]);
251 history_.push_back(std::make_unique<RtcEventRemoteEstimate>(*events[i]));
252 }
253
254 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
255 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
256 const auto& parsed_events = parsed_log_.remote_estimate_events();
257
258 ASSERT_EQ(parsed_events.size(), event_count_);
259 for (size_t i = 0; i < event_count_; ++i) {
260 verifier_.VerifyLoggedRemoteEstimateEvent(*events[i], parsed_events[i]);
261 }
262 }
263
TEST_P(RtcEventLogEncoderTest,RtcEventAudioNetworkAdaptationBitrate)264 TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationBitrate) {
265 std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>> events(
266 event_count_);
267 for (size_t i = 0; i < event_count_; ++i) {
268 if (i == 0 || !force_repeated_fields_) {
269 auto runtime_config = std::make_unique<AudioEncoderRuntimeConfig>();
270 const int bitrate_bps = rtc::checked_cast<int>(
271 prng_.Rand(0, std::numeric_limits<int32_t>::max()));
272 runtime_config->bitrate_bps = bitrate_bps;
273 events[i] = std::make_unique<RtcEventAudioNetworkAdaptation>(
274 std::move(runtime_config));
275 } else {
276 events[i] = events[0]->Copy();
277 }
278 }
279 TestRtcEventAudioNetworkAdaptation(events);
280 }
281
TEST_P(RtcEventLogEncoderTest,RtcEventAudioNetworkAdaptationFrameLength)282 TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationFrameLength) {
283 std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>> events(
284 event_count_);
285 for (size_t i = 0; i < event_count_; ++i) {
286 if (i == 0 || !force_repeated_fields_) {
287 auto runtime_config = std::make_unique<AudioEncoderRuntimeConfig>();
288 const int frame_length_ms = prng_.Rand(1, 1000);
289 runtime_config->frame_length_ms = frame_length_ms;
290 events[i] = std::make_unique<RtcEventAudioNetworkAdaptation>(
291 std::move(runtime_config));
292 } else {
293 events[i] = events[0]->Copy();
294 }
295 }
296 TestRtcEventAudioNetworkAdaptation(events);
297 }
298
TEST_P(RtcEventLogEncoderTest,RtcEventAudioNetworkAdaptationPacketLoss)299 TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationPacketLoss) {
300 std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>> events(
301 event_count_);
302 for (size_t i = 0; i < event_count_; ++i) {
303 if (i == 0 || !force_repeated_fields_) {
304 // To simplify the test, we just check powers of two.
305 const float plr = std::pow(0.5f, prng_.Rand(1, 8));
306 auto runtime_config = std::make_unique<AudioEncoderRuntimeConfig>();
307 runtime_config->uplink_packet_loss_fraction = plr;
308 events[i] = std::make_unique<RtcEventAudioNetworkAdaptation>(
309 std::move(runtime_config));
310 } else {
311 events[i] = events[0]->Copy();
312 }
313 }
314 TestRtcEventAudioNetworkAdaptation(events);
315 }
316
TEST_P(RtcEventLogEncoderTest,RtcEventAudioNetworkAdaptationFec)317 TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationFec) {
318 std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>> events(
319 event_count_);
320 for (size_t i = 0; i < event_count_; ++i) {
321 if (i == 0 || !force_repeated_fields_) {
322 auto runtime_config = std::make_unique<AudioEncoderRuntimeConfig>();
323 runtime_config->enable_fec = prng_.Rand<bool>();
324 events[i] = std::make_unique<RtcEventAudioNetworkAdaptation>(
325 std::move(runtime_config));
326 } else {
327 events[i] = events[0]->Copy();
328 }
329 }
330 TestRtcEventAudioNetworkAdaptation(events);
331 }
332
TEST_P(RtcEventLogEncoderTest,RtcEventAudioNetworkAdaptationDtx)333 TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationDtx) {
334 std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>> events(
335 event_count_);
336 for (size_t i = 0; i < event_count_; ++i) {
337 if (i == 0 || !force_repeated_fields_) {
338 auto runtime_config = std::make_unique<AudioEncoderRuntimeConfig>();
339 runtime_config->enable_dtx = prng_.Rand<bool>();
340 events[i] = std::make_unique<RtcEventAudioNetworkAdaptation>(
341 std::move(runtime_config));
342 } else {
343 events[i] = events[0]->Copy();
344 }
345 }
346 TestRtcEventAudioNetworkAdaptation(events);
347 }
348
TEST_P(RtcEventLogEncoderTest,RtcEventAudioNetworkAdaptationChannels)349 TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationChannels) {
350 std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>> events(
351 event_count_);
352 for (size_t i = 0; i < event_count_; ++i) {
353 if (i == 0 || !force_repeated_fields_) {
354 auto runtime_config = std::make_unique<AudioEncoderRuntimeConfig>();
355 runtime_config->num_channels = prng_.Rand(1, 2);
356 events[i] = std::make_unique<RtcEventAudioNetworkAdaptation>(
357 std::move(runtime_config));
358 } else {
359 events[i] = events[0]->Copy();
360 }
361 }
362 TestRtcEventAudioNetworkAdaptation(events);
363 }
364
TEST_P(RtcEventLogEncoderTest,RtcEventAudioNetworkAdaptationAll)365 TEST_P(RtcEventLogEncoderTest, RtcEventAudioNetworkAdaptationAll) {
366 std::vector<std::unique_ptr<RtcEventAudioNetworkAdaptation>> events(
367 event_count_);
368 for (size_t i = 0; i < event_count_; ++i) {
369 if (i == 0 || !force_repeated_fields_) {
370 auto runtime_config = std::make_unique<AudioEncoderRuntimeConfig>();
371 runtime_config->bitrate_bps = rtc::checked_cast<int>(
372 prng_.Rand(0, std::numeric_limits<int32_t>::max()));
373 runtime_config->frame_length_ms = prng_.Rand(1, 1000);
374 runtime_config->uplink_packet_loss_fraction =
375 std::pow(0.5f, prng_.Rand(1, 8));
376 runtime_config->enable_fec = prng_.Rand<bool>();
377 runtime_config->enable_dtx = prng_.Rand<bool>();
378 runtime_config->num_channels = prng_.Rand(1, 2);
379 events[i] = std::make_unique<RtcEventAudioNetworkAdaptation>(
380 std::move(runtime_config));
381 } else {
382 events[i] = events[0]->Copy();
383 }
384 }
385 TestRtcEventAudioNetworkAdaptation(events);
386 }
387
TEST_P(RtcEventLogEncoderTest,RtcEventAudioPlayout)388 TEST_P(RtcEventLogEncoderTest, RtcEventAudioPlayout) {
389 // SSRCs will be randomly assigned out of this small pool, significant only
390 // in that it also covers such edge cases as SSRC = 0 and SSRC = 0xffffffff.
391 // The pool is intentionally small, so as to produce collisions.
392 const std::vector<uint32_t> kSsrcPool = {0x00000000, 0x12345678, 0xabcdef01,
393 0xffffffff, 0x20171024, 0x19840730,
394 0x19831230};
395
396 std::map<uint32_t, std::vector<std::unique_ptr<RtcEventAudioPlayout>>>
397 original_events_by_ssrc;
398 for (size_t i = 0; i < event_count_; ++i) {
399 const uint32_t ssrc = kSsrcPool[prng_.Rand(kSsrcPool.size() - 1)];
400 std::unique_ptr<RtcEventAudioPlayout> event =
401 (original_events_by_ssrc[ssrc].empty() || !force_repeated_fields_)
402 ? gen_.NewAudioPlayout(ssrc)
403 : original_events_by_ssrc[ssrc][0]->Copy();
404 history_.push_back(event->Copy());
405 original_events_by_ssrc[ssrc].push_back(std::move(event));
406 }
407
408 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
409 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
410
411 const auto& parsed_playout_events_by_ssrc =
412 parsed_log_.audio_playout_events();
413
414 // Same number of distinct SSRCs.
415 ASSERT_EQ(parsed_playout_events_by_ssrc.size(),
416 original_events_by_ssrc.size());
417
418 for (auto& original_event_it : original_events_by_ssrc) {
419 const uint32_t ssrc = original_event_it.first;
420 const auto& original_playout_events = original_event_it.second;
421
422 const auto& parsed_event_it = parsed_playout_events_by_ssrc.find(ssrc);
423 ASSERT_TRUE(parsed_event_it != parsed_playout_events_by_ssrc.end());
424 const auto& parsed_playout_events = parsed_event_it->second;
425
426 // Same number playout events for the SSRC under examination.
427 ASSERT_EQ(original_playout_events.size(), parsed_playout_events.size());
428
429 for (size_t i = 0; i < original_playout_events.size(); ++i) {
430 verifier_.VerifyLoggedAudioPlayoutEvent(*original_playout_events[i],
431 parsed_playout_events[i]);
432 }
433 }
434 }
435
436 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventAudioReceiveStreamConfig)437 TEST_P(RtcEventLogEncoderTest, RtcEventAudioReceiveStreamConfig) {
438 uint32_t ssrc = prng_.Rand<uint32_t>();
439 RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap();
440 std::unique_ptr<RtcEventAudioReceiveStreamConfig> event =
441 gen_.NewAudioReceiveStreamConfig(ssrc, extensions);
442 history_.push_back(event->Copy());
443
444 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
445 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
446 const auto& audio_recv_configs = parsed_log_.audio_recv_configs();
447
448 ASSERT_EQ(audio_recv_configs.size(), 1u);
449 verifier_.VerifyLoggedAudioRecvConfig(*event, audio_recv_configs[0]);
450 }
451
452 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventAudioSendStreamConfig)453 TEST_P(RtcEventLogEncoderTest, RtcEventAudioSendStreamConfig) {
454 uint32_t ssrc = prng_.Rand<uint32_t>();
455 RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap();
456 std::unique_ptr<RtcEventAudioSendStreamConfig> event =
457 gen_.NewAudioSendStreamConfig(ssrc, extensions);
458 history_.push_back(event->Copy());
459
460 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
461 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
462 const auto& audio_send_configs = parsed_log_.audio_send_configs();
463
464 ASSERT_EQ(audio_send_configs.size(), 1u);
465 verifier_.VerifyLoggedAudioSendConfig(*event, audio_send_configs[0]);
466 }
467
TEST_P(RtcEventLogEncoderTest,RtcEventBweUpdateDelayBased)468 TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateDelayBased) {
469 std::vector<std::unique_ptr<RtcEventBweUpdateDelayBased>> events(
470 event_count_);
471 for (size_t i = 0; i < event_count_; ++i) {
472 events[i] = (i == 0 || !force_repeated_fields_)
473 ? gen_.NewBweUpdateDelayBased()
474 : events[0]->Copy();
475 history_.push_back(events[i]->Copy());
476 }
477
478 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
479 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
480
481 const auto& bwe_delay_updates = parsed_log_.bwe_delay_updates();
482 ASSERT_EQ(bwe_delay_updates.size(), event_count_);
483
484 for (size_t i = 0; i < event_count_; ++i) {
485 verifier_.VerifyLoggedBweDelayBasedUpdate(*events[i], bwe_delay_updates[i]);
486 }
487 }
488
TEST_P(RtcEventLogEncoderTest,RtcEventBweUpdateLossBased)489 TEST_P(RtcEventLogEncoderTest, RtcEventBweUpdateLossBased) {
490 std::vector<std::unique_ptr<RtcEventBweUpdateLossBased>> events(event_count_);
491 for (size_t i = 0; i < event_count_; ++i) {
492 events[i] = (i == 0 || !force_repeated_fields_)
493 ? gen_.NewBweUpdateLossBased()
494 : events[0]->Copy();
495 history_.push_back(events[i]->Copy());
496 }
497
498 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
499 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
500
501 const auto& bwe_loss_updates = parsed_log_.bwe_loss_updates();
502 ASSERT_EQ(bwe_loss_updates.size(), event_count_);
503
504 for (size_t i = 0; i < event_count_; ++i) {
505 verifier_.VerifyLoggedBweLossBasedUpdate(*events[i], bwe_loss_updates[i]);
506 }
507 }
508
TEST_P(RtcEventLogEncoderTest,RtcEventGenericPacketReceived)509 TEST_P(RtcEventLogEncoderTest, RtcEventGenericPacketReceived) {
510 if (!new_encoding_) {
511 return;
512 }
513 std::vector<std::unique_ptr<RtcEventGenericPacketReceived>> events(
514 event_count_);
515 for (size_t i = 0; i < event_count_; ++i) {
516 events[i] = (i == 0 || !force_repeated_fields_)
517 ? gen_.NewGenericPacketReceived()
518 : events[0]->Copy();
519 history_.push_back(events[i]->Copy());
520 }
521
522 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
523 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
524
525 const auto& packets_received = parsed_log_.generic_packets_received();
526 ASSERT_EQ(packets_received.size(), event_count_);
527
528 for (size_t i = 0; i < event_count_; ++i) {
529 verifier_.VerifyLoggedGenericPacketReceived(*events[i],
530 packets_received[i]);
531 }
532 }
533
TEST_P(RtcEventLogEncoderTest,RtcEventGenericPacketSent)534 TEST_P(RtcEventLogEncoderTest, RtcEventGenericPacketSent) {
535 if (!new_encoding_) {
536 return;
537 }
538 std::vector<std::unique_ptr<RtcEventGenericPacketSent>> events(event_count_);
539 for (size_t i = 0; i < event_count_; ++i) {
540 events[i] = (i == 0 || !force_repeated_fields_)
541 ? gen_.NewGenericPacketSent()
542 : events[0]->Copy();
543 history_.push_back(events[i]->Copy());
544 }
545
546 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
547 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
548
549 const auto& packets_sent = parsed_log_.generic_packets_sent();
550 ASSERT_EQ(packets_sent.size(), event_count_);
551
552 for (size_t i = 0; i < event_count_; ++i) {
553 verifier_.VerifyLoggedGenericPacketSent(*events[i], packets_sent[i]);
554 }
555 }
556
TEST_P(RtcEventLogEncoderTest,RtcEventGenericAcksReceived)557 TEST_P(RtcEventLogEncoderTest, RtcEventGenericAcksReceived) {
558 if (!new_encoding_) {
559 return;
560 }
561 std::vector<std::unique_ptr<RtcEventGenericAckReceived>> events(event_count_);
562 for (size_t i = 0; i < event_count_; ++i) {
563 events[i] = (i == 0 || !force_repeated_fields_)
564 ? gen_.NewGenericAckReceived()
565 : events[0]->Copy();
566 history_.push_back(events[i]->Copy());
567 }
568
569 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
570 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
571
572 const auto& decoded_events = parsed_log_.generic_acks_received();
573 ASSERT_EQ(decoded_events.size(), event_count_);
574
575 for (size_t i = 0; i < event_count_; ++i) {
576 verifier_.VerifyLoggedGenericAckReceived(*events[i], decoded_events[i]);
577 }
578 }
579
TEST_P(RtcEventLogEncoderTest,RtcEventDtlsTransportState)580 TEST_P(RtcEventLogEncoderTest, RtcEventDtlsTransportState) {
581 std::vector<std::unique_ptr<RtcEventDtlsTransportState>> events(event_count_);
582 for (size_t i = 0; i < event_count_; ++i) {
583 events[i] = (i == 0 || !force_repeated_fields_)
584 ? gen_.NewDtlsTransportState()
585 : events[0]->Copy();
586 history_.push_back(events[i]->Copy());
587 }
588
589 const std::string encoded =
590 encoder_->EncodeBatch(history_.begin(), history_.end());
591 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
592
593 const auto& dtls_transport_states = parsed_log_.dtls_transport_states();
594 if (!new_encoding_) {
595 ASSERT_EQ(dtls_transport_states.size(), 0u);
596 return;
597 }
598
599 ASSERT_EQ(dtls_transport_states.size(), event_count_);
600 for (size_t i = 0; i < event_count_; ++i) {
601 verifier_.VerifyLoggedDtlsTransportState(*events[i],
602 dtls_transport_states[i]);
603 }
604 }
605
TEST_P(RtcEventLogEncoderTest,RtcEventDtlsWritableState)606 TEST_P(RtcEventLogEncoderTest, RtcEventDtlsWritableState) {
607 std::vector<std::unique_ptr<RtcEventDtlsWritableState>> events(event_count_);
608 for (size_t i = 0; i < event_count_; ++i) {
609 events[i] = (i == 0 || !force_repeated_fields_)
610 ? gen_.NewDtlsWritableState()
611 : events[0]->Copy();
612 history_.push_back(events[i]->Copy());
613 }
614
615 const std::string encoded =
616 encoder_->EncodeBatch(history_.begin(), history_.end());
617 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
618
619 const auto& dtls_writable_states = parsed_log_.dtls_writable_states();
620 if (!new_encoding_) {
621 ASSERT_EQ(dtls_writable_states.size(), 0u);
622 return;
623 }
624
625 ASSERT_EQ(dtls_writable_states.size(), event_count_);
626
627 for (size_t i = 0; i < event_count_; ++i) {
628 verifier_.VerifyLoggedDtlsWritableState(*events[i],
629 dtls_writable_states[i]);
630 }
631 }
632
633 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventIceCandidatePairConfig)634 TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePairConfig) {
635 std::unique_ptr<RtcEventIceCandidatePairConfig> event =
636 gen_.NewIceCandidatePairConfig();
637 history_.push_back(event->Copy());
638
639 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
640 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
641 const auto& ice_candidate_pair_configs =
642 parsed_log_.ice_candidate_pair_configs();
643
644 ASSERT_EQ(ice_candidate_pair_configs.size(), 1u);
645 verifier_.VerifyLoggedIceCandidatePairConfig(*event,
646 ice_candidate_pair_configs[0]);
647 }
648
649 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventIceCandidatePair)650 TEST_P(RtcEventLogEncoderTest, RtcEventIceCandidatePair) {
651 std::unique_ptr<RtcEventIceCandidatePair> event = gen_.NewIceCandidatePair();
652 history_.push_back(event->Copy());
653
654 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
655 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
656 const auto& ice_candidate_pair_events =
657 parsed_log_.ice_candidate_pair_events();
658
659 ASSERT_EQ(ice_candidate_pair_events.size(), 1u);
660 verifier_.VerifyLoggedIceCandidatePairEvent(*event,
661 ice_candidate_pair_events[0]);
662 }
663
TEST_P(RtcEventLogEncoderTest,RtcEventLoggingStarted)664 TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStarted) {
665 const int64_t timestamp_us = rtc::TimeMicros();
666 const int64_t utc_time_us = rtc::TimeUTCMicros();
667
668 std::string encoded = encoder_->EncodeLogStart(timestamp_us, utc_time_us);
669 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
670 const auto& start_log_events = parsed_log_.start_log_events();
671
672 ASSERT_EQ(start_log_events.size(), 1u);
673 verifier_.VerifyLoggedStartEvent(timestamp_us, utc_time_us,
674 start_log_events[0]);
675 }
676
TEST_P(RtcEventLogEncoderTest,RtcEventLoggingStopped)677 TEST_P(RtcEventLogEncoderTest, RtcEventLoggingStopped) {
678 const int64_t start_timestamp_us = rtc::TimeMicros();
679 const int64_t start_utc_time_us = rtc::TimeUTCMicros();
680 std::string encoded =
681 encoder_->EncodeLogStart(start_timestamp_us, start_utc_time_us);
682
683 const int64_t stop_timestamp_us = rtc::TimeMicros();
684 encoded += encoder_->EncodeLogEnd(stop_timestamp_us);
685 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
686 const auto& stop_log_events = parsed_log_.stop_log_events();
687
688 ASSERT_EQ(stop_log_events.size(), 1u);
689 verifier_.VerifyLoggedStopEvent(stop_timestamp_us, stop_log_events[0]);
690 }
691
692 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventProbeClusterCreated)693 TEST_P(RtcEventLogEncoderTest, RtcEventProbeClusterCreated) {
694 std::unique_ptr<RtcEventProbeClusterCreated> event =
695 gen_.NewProbeClusterCreated();
696 history_.push_back(event->Copy());
697
698 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
699 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
700 const auto& bwe_probe_cluster_created_events =
701 parsed_log_.bwe_probe_cluster_created_events();
702
703 ASSERT_EQ(bwe_probe_cluster_created_events.size(), 1u);
704 verifier_.VerifyLoggedBweProbeClusterCreatedEvent(
705 *event, bwe_probe_cluster_created_events[0]);
706 }
707
708 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventProbeResultFailure)709 TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultFailure) {
710 std::unique_ptr<RtcEventProbeResultFailure> event =
711 gen_.NewProbeResultFailure();
712 history_.push_back(event->Copy());
713
714 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
715 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
716 const auto& bwe_probe_failure_events = parsed_log_.bwe_probe_failure_events();
717
718 ASSERT_EQ(bwe_probe_failure_events.size(), 1u);
719 verifier_.VerifyLoggedBweProbeFailureEvent(*event,
720 bwe_probe_failure_events[0]);
721 }
722
723 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventProbeResultSuccess)724 TEST_P(RtcEventLogEncoderTest, RtcEventProbeResultSuccess) {
725 std::unique_ptr<RtcEventProbeResultSuccess> event =
726 gen_.NewProbeResultSuccess();
727 history_.push_back(event->Copy());
728
729 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
730 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
731 const auto& bwe_probe_success_events = parsed_log_.bwe_probe_success_events();
732
733 ASSERT_EQ(bwe_probe_success_events.size(), 1u);
734 verifier_.VerifyLoggedBweProbeSuccessEvent(*event,
735 bwe_probe_success_events[0]);
736 }
737
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpPacketIncoming)738 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketIncoming) {
739 if (force_repeated_fields_) {
740 // RTCP packets maybe delivered twice (once for audio and once for video).
741 // As a work around, we're removing duplicates in the parser.
742 return;
743 }
744
745 std::vector<std::unique_ptr<RtcEventRtcpPacketIncoming>> events(event_count_);
746 for (size_t i = 0; i < event_count_; ++i) {
747 events[i] = (i == 0 || !force_repeated_fields_)
748 ? gen_.NewRtcpPacketIncoming()
749 : events[0]->Copy();
750 history_.push_back(events[i]->Copy());
751 }
752
753 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
754 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
755
756 const auto& incoming_rtcp_packets = parsed_log_.incoming_rtcp_packets();
757 ASSERT_EQ(incoming_rtcp_packets.size(), event_count_);
758
759 for (size_t i = 0; i < event_count_; ++i) {
760 verifier_.VerifyLoggedRtcpPacketIncoming(*events[i],
761 incoming_rtcp_packets[i]);
762 }
763 }
764
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpPacketOutgoing)765 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPacketOutgoing) {
766 std::vector<std::unique_ptr<RtcEventRtcpPacketOutgoing>> events(event_count_);
767 for (size_t i = 0; i < event_count_; ++i) {
768 events[i] = (i == 0 || !force_repeated_fields_)
769 ? gen_.NewRtcpPacketOutgoing()
770 : events[0]->Copy();
771 history_.push_back(events[i]->Copy());
772 }
773
774 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
775 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
776
777 const auto& outgoing_rtcp_packets = parsed_log_.outgoing_rtcp_packets();
778 ASSERT_EQ(outgoing_rtcp_packets.size(), event_count_);
779
780 for (size_t i = 0; i < event_count_; ++i) {
781 verifier_.VerifyLoggedRtcpPacketOutgoing(*events[i],
782 outgoing_rtcp_packets[i]);
783 }
784 }
785
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpReceiverReport)786 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpReceiverReport) {
787 if (force_repeated_fields_) {
788 return;
789 }
790
791 rtc::ScopedFakeClock fake_clock;
792 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
793
794 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
795 std::vector<rtcp::ReceiverReport> events(event_count_);
796 std::vector<int64_t> timestamps_us(event_count_);
797 for (size_t i = 0; i < event_count_; ++i) {
798 timestamps_us[i] = rtc::TimeMicros();
799 events[i] = gen_.NewReceiverReport();
800 rtc::Buffer buffer = events[i].Build();
801 if (direction == kIncomingPacket) {
802 history_.push_back(
803 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
804 } else {
805 history_.push_back(
806 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
807 }
808 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
809 }
810
811 std::string encoded =
812 encoder_->EncodeBatch(history_.begin(), history_.end());
813 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
814
815 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
816 ASSERT_EQ(receiver_reports.size(), event_count_);
817
818 for (size_t i = 0; i < event_count_; ++i) {
819 verifier_.VerifyLoggedReceiverReport(timestamps_us[i], events[i],
820 receiver_reports[i]);
821 }
822 }
823 }
824
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpSenderReport)825 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpSenderReport) {
826 if (force_repeated_fields_) {
827 return;
828 }
829
830 rtc::ScopedFakeClock fake_clock;
831 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
832
833 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
834 std::vector<rtcp::SenderReport> events(event_count_);
835 std::vector<int64_t> timestamps_us(event_count_);
836 for (size_t i = 0; i < event_count_; ++i) {
837 timestamps_us[i] = rtc::TimeMicros();
838 events[i] = gen_.NewSenderReport();
839 rtc::Buffer buffer = events[i].Build();
840 if (direction == kIncomingPacket) {
841 history_.push_back(
842 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
843 } else {
844 history_.push_back(
845 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
846 }
847 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
848 }
849
850 std::string encoded =
851 encoder_->EncodeBatch(history_.begin(), history_.end());
852 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
853
854 const auto& sender_reports = parsed_log_.sender_reports(direction);
855 ASSERT_EQ(sender_reports.size(), event_count_);
856
857 for (size_t i = 0; i < event_count_; ++i) {
858 verifier_.VerifyLoggedSenderReport(timestamps_us[i], events[i],
859 sender_reports[i]);
860 }
861 }
862 }
863
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpExtendedReports)864 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpExtendedReports) {
865 if (force_repeated_fields_) {
866 return;
867 }
868
869 rtc::ScopedFakeClock fake_clock;
870 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
871
872 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
873 std::vector<rtcp::ExtendedReports> events(event_count_);
874 std::vector<int64_t> timestamps_us(event_count_);
875 for (size_t i = 0; i < event_count_; ++i) {
876 timestamps_us[i] = rtc::TimeMicros();
877 events[i] = gen_.NewExtendedReports();
878 rtc::Buffer buffer = events[i].Build();
879 if (direction == kIncomingPacket) {
880 history_.push_back(
881 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
882 } else {
883 history_.push_back(
884 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
885 }
886 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
887 }
888
889 std::string encoded =
890 encoder_->EncodeBatch(history_.begin(), history_.end());
891 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
892
893 const auto& extended_reports = parsed_log_.extended_reports(direction);
894 ASSERT_EQ(extended_reports.size(), event_count_);
895
896 for (size_t i = 0; i < event_count_; ++i) {
897 verifier_.VerifyLoggedExtendedReports(timestamps_us[i], events[i],
898 extended_reports[i]);
899 }
900 }
901 }
902
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpFir)903 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpFir) {
904 if (force_repeated_fields_) {
905 return;
906 }
907
908 rtc::ScopedFakeClock fake_clock;
909 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
910
911 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
912 std::vector<rtcp::Fir> events(event_count_);
913 std::vector<int64_t> timestamps_us(event_count_);
914 for (size_t i = 0; i < event_count_; ++i) {
915 timestamps_us[i] = rtc::TimeMicros();
916 events[i] = gen_.NewFir();
917 rtc::Buffer buffer = events[i].Build();
918 if (direction == kIncomingPacket) {
919 history_.push_back(
920 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
921 } else {
922 history_.push_back(
923 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
924 }
925 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
926 }
927
928 std::string encoded =
929 encoder_->EncodeBatch(history_.begin(), history_.end());
930 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
931
932 const auto& firs = parsed_log_.firs(direction);
933 ASSERT_EQ(firs.size(), event_count_);
934
935 for (size_t i = 0; i < event_count_; ++i) {
936 verifier_.VerifyLoggedFir(timestamps_us[i], events[i], firs[i]);
937 }
938 }
939 }
940
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpPli)941 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpPli) {
942 if (force_repeated_fields_) {
943 return;
944 }
945
946 rtc::ScopedFakeClock fake_clock;
947 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
948
949 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
950 std::vector<rtcp::Pli> events(event_count_);
951 std::vector<int64_t> timestamps_us(event_count_);
952 for (size_t i = 0; i < event_count_; ++i) {
953 timestamps_us[i] = rtc::TimeMicros();
954 events[i] = gen_.NewPli();
955 rtc::Buffer buffer = events[i].Build();
956 if (direction == kIncomingPacket) {
957 history_.push_back(
958 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
959 } else {
960 history_.push_back(
961 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
962 }
963 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
964 }
965
966 std::string encoded =
967 encoder_->EncodeBatch(history_.begin(), history_.end());
968 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
969
970 const auto& plis = parsed_log_.plis(direction);
971 ASSERT_EQ(plis.size(), event_count_);
972
973 for (size_t i = 0; i < event_count_; ++i) {
974 verifier_.VerifyLoggedPli(timestamps_us[i], events[i], plis[i]);
975 }
976 }
977 }
978
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpNack)979 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpNack) {
980 if (force_repeated_fields_) {
981 return;
982 }
983
984 rtc::ScopedFakeClock fake_clock;
985 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
986
987 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
988 std::vector<rtcp::Nack> events(event_count_);
989 std::vector<int64_t> timestamps_us(event_count_);
990 for (size_t i = 0; i < event_count_; ++i) {
991 timestamps_us[i] = rtc::TimeMicros();
992 events[i] = gen_.NewNack();
993 rtc::Buffer buffer = events[i].Build();
994 if (direction == kIncomingPacket) {
995 history_.push_back(
996 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
997 } else {
998 history_.push_back(
999 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
1000 }
1001 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
1002 }
1003
1004 std::string encoded =
1005 encoder_->EncodeBatch(history_.begin(), history_.end());
1006 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
1007
1008 const auto& nacks = parsed_log_.nacks(direction);
1009 ASSERT_EQ(nacks.size(), event_count_);
1010
1011 for (size_t i = 0; i < event_count_; ++i) {
1012 verifier_.VerifyLoggedNack(timestamps_us[i], events[i], nacks[i]);
1013 }
1014 }
1015 }
1016
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpRemb)1017 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpRemb) {
1018 if (force_repeated_fields_) {
1019 return;
1020 }
1021
1022 rtc::ScopedFakeClock fake_clock;
1023 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
1024
1025 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
1026 std::vector<rtcp::Remb> events(event_count_);
1027 std::vector<int64_t> timestamps_us(event_count_);
1028 for (size_t i = 0; i < event_count_; ++i) {
1029 timestamps_us[i] = rtc::TimeMicros();
1030 events[i] = gen_.NewRemb();
1031 rtc::Buffer buffer = events[i].Build();
1032 if (direction == kIncomingPacket) {
1033 history_.push_back(
1034 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
1035 } else {
1036 history_.push_back(
1037 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
1038 }
1039 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
1040 }
1041
1042 std::string encoded =
1043 encoder_->EncodeBatch(history_.begin(), history_.end());
1044 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
1045
1046 const auto& rembs = parsed_log_.rembs(direction);
1047 ASSERT_EQ(rembs.size(), event_count_);
1048
1049 for (size_t i = 0; i < event_count_; ++i) {
1050 verifier_.VerifyLoggedRemb(timestamps_us[i], events[i], rembs[i]);
1051 }
1052 }
1053 }
1054
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpTransportFeedback)1055 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpTransportFeedback) {
1056 if (force_repeated_fields_) {
1057 return;
1058 }
1059
1060 rtc::ScopedFakeClock fake_clock;
1061 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
1062
1063 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
1064 std::vector<rtcp::TransportFeedback> events;
1065 events.reserve(event_count_);
1066 std::vector<int64_t> timestamps_us(event_count_);
1067 for (size_t i = 0; i < event_count_; ++i) {
1068 timestamps_us[i] = rtc::TimeMicros();
1069 events.emplace_back(gen_.NewTransportFeedback());
1070 rtc::Buffer buffer = events[i].Build();
1071 if (direction == kIncomingPacket) {
1072 history_.push_back(
1073 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
1074 } else {
1075 history_.push_back(
1076 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
1077 }
1078 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
1079 }
1080
1081 std::string encoded =
1082 encoder_->EncodeBatch(history_.begin(), history_.end());
1083 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
1084
1085 const auto& transport_feedbacks =
1086 parsed_log_.transport_feedbacks(direction);
1087 ASSERT_EQ(transport_feedbacks.size(), event_count_);
1088
1089 for (size_t i = 0; i < event_count_; ++i) {
1090 verifier_.VerifyLoggedTransportFeedback(timestamps_us[i], events[i],
1091 transport_feedbacks[i]);
1092 }
1093 }
1094 }
1095
TEST_P(RtcEventLogEncoderTest,RtcEventRtcpLossNotification)1096 TEST_P(RtcEventLogEncoderTest, RtcEventRtcpLossNotification) {
1097 if (force_repeated_fields_) {
1098 return;
1099 }
1100
1101 rtc::ScopedFakeClock fake_clock;
1102 fake_clock.SetTime(Timestamp::Millis(prng_.Rand<uint32_t>()));
1103
1104 for (auto direction : {kIncomingPacket, kOutgoingPacket}) {
1105 std::vector<rtcp::LossNotification> events;
1106 events.reserve(event_count_);
1107 std::vector<int64_t> timestamps_us(event_count_);
1108 for (size_t i = 0; i < event_count_; ++i) {
1109 timestamps_us[i] = rtc::TimeMicros();
1110 events.emplace_back(gen_.NewLossNotification());
1111 rtc::Buffer buffer = events[i].Build();
1112 if (direction == kIncomingPacket) {
1113 history_.push_back(
1114 std::make_unique<RtcEventRtcpPacketIncoming>(buffer));
1115 } else {
1116 history_.push_back(
1117 std::make_unique<RtcEventRtcpPacketOutgoing>(buffer));
1118 }
1119 fake_clock.AdvanceTime(TimeDelta::Millis(prng_.Rand(0, 1000)));
1120 }
1121
1122 std::string encoded =
1123 encoder_->EncodeBatch(history_.begin(), history_.end());
1124 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
1125
1126 const auto& loss_notifications = parsed_log_.loss_notifications(direction);
1127 ASSERT_EQ(loss_notifications.size(), event_count_);
1128
1129 for (size_t i = 0; i < event_count_; ++i) {
1130 verifier_.VerifyLoggedLossNotification(timestamps_us[i], events[i],
1131 loss_notifications[i]);
1132 }
1133 }
1134 }
1135
TEST_P(RtcEventLogEncoderTest,RtcEventRtpPacketIncoming)1136 TEST_P(RtcEventLogEncoderTest, RtcEventRtpPacketIncoming) {
1137 TestRtpPackets<RtcEventRtpPacketIncoming, LoggedRtpPacketIncoming>();
1138 }
1139
TEST_P(RtcEventLogEncoderTest,RtcEventRtpPacketOutgoing)1140 TEST_P(RtcEventLogEncoderTest, RtcEventRtpPacketOutgoing) {
1141 TestRtpPackets<RtcEventRtpPacketOutgoing, LoggedRtpPacketOutgoing>();
1142 }
1143
1144 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventVideoReceiveStreamConfig)1145 TEST_P(RtcEventLogEncoderTest, RtcEventVideoReceiveStreamConfig) {
1146 uint32_t ssrc = prng_.Rand<uint32_t>();
1147 RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap();
1148 std::unique_ptr<RtcEventVideoReceiveStreamConfig> event =
1149 gen_.NewVideoReceiveStreamConfig(ssrc, extensions);
1150 history_.push_back(event->Copy());
1151
1152 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
1153 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
1154 const auto& video_recv_configs = parsed_log_.video_recv_configs();
1155
1156 ASSERT_EQ(video_recv_configs.size(), 1u);
1157 verifier_.VerifyLoggedVideoRecvConfig(*event, video_recv_configs[0]);
1158 }
1159
1160 // TODO(eladalon/terelius): Test with multiple events in the batch.
TEST_P(RtcEventLogEncoderTest,RtcEventVideoSendStreamConfig)1161 TEST_P(RtcEventLogEncoderTest, RtcEventVideoSendStreamConfig) {
1162 uint32_t ssrc = prng_.Rand<uint32_t>();
1163 RtpHeaderExtensionMap extensions = gen_.NewRtpHeaderExtensionMap();
1164 std::unique_ptr<RtcEventVideoSendStreamConfig> event =
1165 gen_.NewVideoSendStreamConfig(ssrc, extensions);
1166 history_.push_back(event->Copy());
1167
1168 std::string encoded = encoder_->EncodeBatch(history_.begin(), history_.end());
1169 ASSERT_TRUE(parsed_log_.ParseString(encoded).ok());
1170 const auto& video_send_configs = parsed_log_.video_send_configs();
1171
1172 ASSERT_EQ(video_send_configs.size(), 1u);
1173 verifier_.VerifyLoggedVideoSendConfig(*event, video_send_configs[0]);
1174 }
1175
1176 INSTANTIATE_TEST_SUITE_P(
1177 RandomSeeds,
1178 RtcEventLogEncoderTest,
1179 ::testing::Combine(/* Random seed*: */ ::testing::Values(1, 2, 3, 4, 5),
1180 /* Encoding: */ ::testing::Bool(),
1181 /* Event count: */ ::testing::Values(1, 2, 10, 100),
1182 /* Repeated fields: */ ::testing::Bool()));
1183
1184 } // namespace webrtc
1185