• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2016 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 "logging/rtc_event_log/rtc_event_log_unittest_helper.h"
12 
13 #include <string.h>  // memcmp
14 
15 #include <cmath>
16 #include <cstdint>
17 #include <limits>
18 #include <memory>
19 #include <numeric>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "absl/strings/string_view.h"
25 #include "absl/types/optional.h"
26 #include "api/array_view.h"
27 #include "api/network_state_predictor.h"
28 #include "api/rtp_headers.h"
29 #include "api/rtp_parameters.h"
30 #include "api/units/time_delta.h"
31 #include "api/units/timestamp.h"
32 #include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor_config.h"
33 #include "modules/rtp_rtcp/include/rtp_cvo.h"
34 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
35 #include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
36 #include "modules/rtp_rtcp/source/rtcp_packet/rrtr.h"
37 #include "modules/rtp_rtcp/source/rtcp_packet/target_bitrate.h"
38 #include "modules/rtp_rtcp/source/rtp_header_extensions.h"
39 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
40 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
41 #include "rtc_base/buffer.h"
42 #include "rtc_base/checks.h"
43 #include "rtc_base/time_utils.h"
44 #include "system_wrappers/include/ntp_time.h"
45 #include "test/gtest.h"
46 
47 namespace webrtc {
48 
49 namespace test {
50 
51 namespace {
52 
53 struct ExtensionPair {
54   RTPExtensionType type;
55   const char* name;
56 };
57 
58 constexpr int kMaxCsrcs = 3;
59 
60 // Maximum serialized size of a header extension, including 1 byte ID.
61 constexpr int kMaxExtensionSizeBytes = 4;
62 constexpr int kMaxNumExtensions = 5;
63 
64 constexpr ExtensionPair kExtensions[kMaxNumExtensions] = {
65     {RTPExtensionType::kRtpExtensionTransmissionTimeOffset,
66      RtpExtension::kTimestampOffsetUri},
67     {RTPExtensionType::kRtpExtensionAbsoluteSendTime,
68      RtpExtension::kAbsSendTimeUri},
69     {RTPExtensionType::kRtpExtensionTransportSequenceNumber,
70      RtpExtension::kTransportSequenceNumberUri},
71     {RTPExtensionType::kRtpExtensionAudioLevel, RtpExtension::kAudioLevelUri},
72     {RTPExtensionType::kRtpExtensionVideoRotation,
73      RtpExtension::kVideoRotationUri}};
74 
75 template <typename T>
ShuffleInPlace(Random * prng,rtc::ArrayView<T> array)76 void ShuffleInPlace(Random* prng, rtc::ArrayView<T> array) {
77   RTC_DCHECK_LE(array.size(), std::numeric_limits<uint32_t>::max());
78   for (uint32_t i = 0; i + 1 < array.size(); i++) {
79     uint32_t other = prng->Rand(i, static_cast<uint32_t>(array.size() - 1));
80     std::swap(array[i], array[other]);
81   }
82 }
83 
GetExtensionId(const std::vector<RtpExtension> & extensions,absl::string_view uri)84 absl::optional<int> GetExtensionId(const std::vector<RtpExtension>& extensions,
85                                    absl::string_view uri) {
86   for (const auto& extension : extensions) {
87     if (extension.uri == uri)
88       return extension.id;
89   }
90   return absl::nullopt;
91 }
92 
93 }  // namespace
94 
NewAlrState()95 std::unique_ptr<RtcEventAlrState> EventGenerator::NewAlrState() {
96   return std::make_unique<RtcEventAlrState>(prng_.Rand<bool>());
97 }
98 
NewAudioPlayout(uint32_t ssrc)99 std::unique_ptr<RtcEventAudioPlayout> EventGenerator::NewAudioPlayout(
100     uint32_t ssrc) {
101   return std::make_unique<RtcEventAudioPlayout>(ssrc);
102 }
103 
104 std::unique_ptr<RtcEventAudioNetworkAdaptation>
NewAudioNetworkAdaptation()105 EventGenerator::NewAudioNetworkAdaptation() {
106   std::unique_ptr<AudioEncoderRuntimeConfig> config =
107       std::make_unique<AudioEncoderRuntimeConfig>();
108 
109   config->bitrate_bps = prng_.Rand(0, 3000000);
110   config->enable_fec = prng_.Rand<bool>();
111   config->enable_dtx = prng_.Rand<bool>();
112   config->frame_length_ms = prng_.Rand(10, 120);
113   config->num_channels = prng_.Rand(1, 2);
114   config->uplink_packet_loss_fraction = prng_.Rand<float>();
115 
116   return std::make_unique<RtcEventAudioNetworkAdaptation>(std::move(config));
117 }
118 
119 std::unique_ptr<RtcEventBweUpdateDelayBased>
NewBweUpdateDelayBased()120 EventGenerator::NewBweUpdateDelayBased() {
121   constexpr int32_t kMaxBweBps = 20000000;
122   int32_t bitrate_bps = prng_.Rand(0, kMaxBweBps);
123   BandwidthUsage state = static_cast<BandwidthUsage>(
124       prng_.Rand(static_cast<uint32_t>(BandwidthUsage::kLast) - 1));
125   return std::make_unique<RtcEventBweUpdateDelayBased>(bitrate_bps, state);
126 }
127 
128 std::unique_ptr<RtcEventBweUpdateLossBased>
NewBweUpdateLossBased()129 EventGenerator::NewBweUpdateLossBased() {
130   constexpr int32_t kMaxBweBps = 20000000;
131   constexpr int32_t kMaxPackets = 1000;
132   int32_t bitrate_bps = prng_.Rand(0, kMaxBweBps);
133   uint8_t fraction_lost = prng_.Rand<uint8_t>();
134   int32_t total_packets = prng_.Rand(1, kMaxPackets);
135 
136   return std::make_unique<RtcEventBweUpdateLossBased>(
137       bitrate_bps, fraction_lost, total_packets);
138 }
139 
140 std::unique_ptr<RtcEventDtlsTransportState>
NewDtlsTransportState()141 EventGenerator::NewDtlsTransportState() {
142   DtlsTransportState state = static_cast<DtlsTransportState>(
143       prng_.Rand(static_cast<uint32_t>(DtlsTransportState::kNumValues) - 1));
144 
145   return std::make_unique<RtcEventDtlsTransportState>(state);
146 }
147 
148 std::unique_ptr<RtcEventDtlsWritableState>
NewDtlsWritableState()149 EventGenerator::NewDtlsWritableState() {
150   bool writable = prng_.Rand<bool>();
151   return std::make_unique<RtcEventDtlsWritableState>(writable);
152 }
153 
NewFrameDecodedEvent(uint32_t ssrc)154 std::unique_ptr<RtcEventFrameDecoded> EventGenerator::NewFrameDecodedEvent(
155     uint32_t ssrc) {
156   constexpr int kMinRenderDelayMs = 1;
157   constexpr int kMaxRenderDelayMs = 2000000;
158   constexpr int kMaxWidth = 15360;
159   constexpr int kMaxHeight = 8640;
160   constexpr int kMinWidth = 16;
161   constexpr int kMinHeight = 16;
162   constexpr int kNumCodecTypes = 5;
163 
164   constexpr VideoCodecType kCodecList[kNumCodecTypes] = {
165       kVideoCodecGeneric, kVideoCodecVP8, kVideoCodecVP9, kVideoCodecAV1,
166       kVideoCodecH264};
167   const int64_t render_time_ms =
168       rtc::TimeMillis() + prng_.Rand(kMinRenderDelayMs, kMaxRenderDelayMs);
169   const int width = prng_.Rand(kMinWidth, kMaxWidth);
170   const int height = prng_.Rand(kMinHeight, kMaxHeight);
171   const VideoCodecType codec = kCodecList[prng_.Rand(0, kNumCodecTypes - 1)];
172   const uint8_t qp = prng_.Rand<uint8_t>();
173   return std::make_unique<RtcEventFrameDecoded>(render_time_ms, ssrc, width,
174                                                 height, codec, qp);
175 }
176 
177 std::unique_ptr<RtcEventProbeClusterCreated>
NewProbeClusterCreated()178 EventGenerator::NewProbeClusterCreated() {
179   constexpr int kMaxBweBps = 20000000;
180   constexpr int kMaxNumProbes = 10000;
181   int id = prng_.Rand(1, kMaxNumProbes);
182   int bitrate_bps = prng_.Rand(0, kMaxBweBps);
183   int min_probes = prng_.Rand(5, 50);
184   int min_bytes = prng_.Rand(500, 50000);
185 
186   return std::make_unique<RtcEventProbeClusterCreated>(id, bitrate_bps,
187                                                        min_probes, min_bytes);
188 }
189 
190 std::unique_ptr<RtcEventProbeResultFailure>
NewProbeResultFailure()191 EventGenerator::NewProbeResultFailure() {
192   constexpr int kMaxNumProbes = 10000;
193   int id = prng_.Rand(1, kMaxNumProbes);
194   ProbeFailureReason reason = static_cast<ProbeFailureReason>(
195       prng_.Rand(static_cast<uint32_t>(ProbeFailureReason::kLast) - 1));
196 
197   return std::make_unique<RtcEventProbeResultFailure>(id, reason);
198 }
199 
200 std::unique_ptr<RtcEventProbeResultSuccess>
NewProbeResultSuccess()201 EventGenerator::NewProbeResultSuccess() {
202   constexpr int kMaxBweBps = 20000000;
203   constexpr int kMaxNumProbes = 10000;
204   int id = prng_.Rand(1, kMaxNumProbes);
205   int bitrate_bps = prng_.Rand(0, kMaxBweBps);
206 
207   return std::make_unique<RtcEventProbeResultSuccess>(id, bitrate_bps);
208 }
209 
210 std::unique_ptr<RtcEventIceCandidatePairConfig>
NewIceCandidatePairConfig()211 EventGenerator::NewIceCandidatePairConfig() {
212   IceCandidateType local_candidate_type = static_cast<IceCandidateType>(
213       prng_.Rand(static_cast<uint32_t>(IceCandidateType::kNumValues) - 1));
214   IceCandidateNetworkType local_network_type =
215       static_cast<IceCandidateNetworkType>(prng_.Rand(
216           static_cast<uint32_t>(IceCandidateNetworkType::kNumValues) - 1));
217   IceCandidatePairAddressFamily local_address_family =
218       static_cast<IceCandidatePairAddressFamily>(prng_.Rand(
219           static_cast<uint32_t>(IceCandidatePairAddressFamily::kNumValues) -
220           1));
221   IceCandidateType remote_candidate_type = static_cast<IceCandidateType>(
222       prng_.Rand(static_cast<uint32_t>(IceCandidateType::kNumValues) - 1));
223   IceCandidatePairAddressFamily remote_address_family =
224       static_cast<IceCandidatePairAddressFamily>(prng_.Rand(
225           static_cast<uint32_t>(IceCandidatePairAddressFamily::kNumValues) -
226           1));
227   IceCandidatePairProtocol protocol_type =
228       static_cast<IceCandidatePairProtocol>(prng_.Rand(
229           static_cast<uint32_t>(IceCandidatePairProtocol::kNumValues) - 1));
230 
231   IceCandidatePairDescription desc;
232   desc.local_candidate_type = local_candidate_type;
233   desc.local_relay_protocol = protocol_type;
234   desc.local_network_type = local_network_type;
235   desc.local_address_family = local_address_family;
236   desc.remote_candidate_type = remote_candidate_type;
237   desc.remote_address_family = remote_address_family;
238   desc.candidate_pair_protocol = protocol_type;
239 
240   IceCandidatePairConfigType type =
241       static_cast<IceCandidatePairConfigType>(prng_.Rand(
242           static_cast<uint32_t>(IceCandidatePairConfigType::kNumValues) - 1));
243   uint32_t pair_id = prng_.Rand<uint32_t>();
244   return std::make_unique<RtcEventIceCandidatePairConfig>(type, pair_id, desc);
245 }
246 
247 std::unique_ptr<RtcEventIceCandidatePair>
NewIceCandidatePair()248 EventGenerator::NewIceCandidatePair() {
249   IceCandidatePairEventType type =
250       static_cast<IceCandidatePairEventType>(prng_.Rand(
251           static_cast<uint32_t>(IceCandidatePairEventType::kNumValues) - 1));
252   uint32_t pair_id = prng_.Rand<uint32_t>();
253   uint32_t transaction_id = prng_.Rand<uint32_t>();
254 
255   return std::make_unique<RtcEventIceCandidatePair>(type, pair_id,
256                                                     transaction_id);
257 }
258 
NewReportBlock()259 rtcp::ReportBlock EventGenerator::NewReportBlock() {
260   rtcp::ReportBlock report_block;
261   report_block.SetMediaSsrc(prng_.Rand<uint32_t>());
262   report_block.SetFractionLost(prng_.Rand<uint8_t>());
263   // cumulative_lost is a 3-byte signed value.
264   RTC_DCHECK(report_block.SetCumulativeLost(
265       prng_.Rand(-(1 << 23) + 1, (1 << 23) - 1)));
266   report_block.SetExtHighestSeqNum(prng_.Rand<uint32_t>());
267   report_block.SetJitter(prng_.Rand<uint32_t>());
268   report_block.SetLastSr(prng_.Rand<uint32_t>());
269   report_block.SetDelayLastSr(prng_.Rand<uint32_t>());
270   return report_block;
271 }
272 
NewSenderReport()273 rtcp::SenderReport EventGenerator::NewSenderReport() {
274   rtcp::SenderReport sender_report;
275   sender_report.SetSenderSsrc(prng_.Rand<uint32_t>());
276   sender_report.SetNtp(NtpTime(prng_.Rand<uint32_t>(), prng_.Rand<uint32_t>()));
277   sender_report.SetRtpTimestamp(prng_.Rand<uint32_t>());
278   sender_report.SetPacketCount(prng_.Rand<uint32_t>());
279   sender_report.SetOctetCount(prng_.Rand<uint32_t>());
280   sender_report.AddReportBlock(NewReportBlock());
281   return sender_report;
282 }
283 
NewReceiverReport()284 rtcp::ReceiverReport EventGenerator::NewReceiverReport() {
285   rtcp::ReceiverReport receiver_report;
286   receiver_report.SetSenderSsrc(prng_.Rand<uint32_t>());
287   receiver_report.AddReportBlock(NewReportBlock());
288   return receiver_report;
289 }
290 
NewExtendedReports()291 rtcp::ExtendedReports EventGenerator::NewExtendedReports() {
292   rtcp::ExtendedReports extended_report;
293   extended_report.SetSenderSsrc(prng_.Rand<uint32_t>());
294 
295   rtcp::Rrtr rrtr;
296   rrtr.SetNtp(NtpTime(prng_.Rand<uint32_t>(), prng_.Rand<uint32_t>()));
297   extended_report.SetRrtr(rrtr);
298 
299   rtcp::ReceiveTimeInfo time_info(
300       prng_.Rand<uint32_t>(), prng_.Rand<uint32_t>(), prng_.Rand<uint32_t>());
301   extended_report.AddDlrrItem(time_info);
302 
303   rtcp::TargetBitrate target_bitrate;
304   target_bitrate.AddTargetBitrate(/*spatial layer*/ prng_.Rand(0, 3),
305                                   /*temporal layer*/ prng_.Rand(0, 3),
306                                   /*bitrate kbps*/ prng_.Rand(0, 50000));
307   target_bitrate.AddTargetBitrate(/*spatial layer*/ prng_.Rand(4, 7),
308                                   /*temporal layer*/ prng_.Rand(4, 7),
309                                   /*bitrate kbps*/ prng_.Rand(0, 50000));
310   extended_report.SetTargetBitrate(target_bitrate);
311   return extended_report;
312 }
313 
NewNack()314 rtcp::Nack EventGenerator::NewNack() {
315   rtcp::Nack nack;
316   uint16_t base_seq_no = prng_.Rand<uint16_t>();
317   std::vector<uint16_t> nack_list;
318   nack_list.push_back(base_seq_no);
319   for (uint16_t i = 1u; i < 10u; i++) {
320     if (prng_.Rand<bool>())
321       nack_list.push_back(base_seq_no + i);
322   }
323   nack.SetPacketIds(nack_list);
324   return nack;
325 }
326 
NewFir()327 rtcp::Fir EventGenerator::NewFir() {
328   rtcp::Fir fir;
329   fir.SetSenderSsrc(prng_.Rand<uint32_t>());
330   fir.AddRequestTo(/*ssrc*/ prng_.Rand<uint32_t>(),
331                    /*seq num*/ prng_.Rand<uint8_t>());
332   fir.AddRequestTo(/*ssrc*/ prng_.Rand<uint32_t>(),
333                    /*seq num*/ prng_.Rand<uint8_t>());
334   return fir;
335 }
336 
NewPli()337 rtcp::Pli EventGenerator::NewPli() {
338   rtcp::Pli pli;
339   pli.SetSenderSsrc(prng_.Rand<uint32_t>());
340   pli.SetMediaSsrc(prng_.Rand<uint32_t>());
341   return pli;
342 }
343 
NewBye()344 rtcp::Bye EventGenerator::NewBye() {
345   rtcp::Bye bye;
346   bye.SetSenderSsrc(prng_.Rand<uint32_t>());
347   std::vector<uint32_t> csrcs{prng_.Rand<uint32_t>(), prng_.Rand<uint32_t>()};
348   bye.SetCsrcs(csrcs);
349   if (prng_.Rand(0, 2)) {
350     bye.SetReason("foo");
351   } else {
352     bye.SetReason("bar");
353   }
354   return bye;
355 }
356 
NewTransportFeedback()357 rtcp::TransportFeedback EventGenerator::NewTransportFeedback() {
358   rtcp::TransportFeedback transport_feedback;
359   uint16_t base_seq_no = prng_.Rand<uint16_t>();
360   Timestamp base_time = Timestamp::Micros(prng_.Rand<uint32_t>());
361   transport_feedback.SetBase(base_seq_no, base_time);
362   transport_feedback.AddReceivedPacket(base_seq_no, base_time);
363   Timestamp time = base_time;
364   for (uint16_t i = 1u; i < 10u; i++) {
365     time += TimeDelta::Micros(prng_.Rand(0, 100'000));
366     if (prng_.Rand<bool>()) {
367       transport_feedback.AddReceivedPacket(base_seq_no + i, time);
368     }
369   }
370   return transport_feedback;
371 }
372 
NewRemb()373 rtcp::Remb EventGenerator::NewRemb() {
374   rtcp::Remb remb;
375   // The remb bitrate is transported as a 16-bit mantissa and an 8-bit exponent.
376   uint64_t bitrate_bps = prng_.Rand(0, (1 << 16) - 1) << prng_.Rand(7);
377   std::vector<uint32_t> ssrcs{prng_.Rand<uint32_t>(), prng_.Rand<uint32_t>()};
378   remb.SetSsrcs(ssrcs);
379   remb.SetBitrateBps(bitrate_bps);
380   return remb;
381 }
382 
NewLossNotification()383 rtcp::LossNotification EventGenerator::NewLossNotification() {
384   rtcp::LossNotification loss_notification;
385   const uint16_t last_decoded = prng_.Rand<uint16_t>();
386   const uint16_t last_received =
387       last_decoded + (prng_.Rand<uint16_t>() & 0x7fff);
388   const bool decodability_flag = prng_.Rand<bool>();
389   EXPECT_TRUE(
390       loss_notification.Set(last_decoded, last_received, decodability_flag));
391   return loss_notification;
392 }
393 
NewRouteChange()394 std::unique_ptr<RtcEventRouteChange> EventGenerator::NewRouteChange() {
395   return std::make_unique<RtcEventRouteChange>(prng_.Rand<bool>(),
396                                                prng_.Rand(0, 128));
397 }
398 
NewRemoteEstimate()399 std::unique_ptr<RtcEventRemoteEstimate> EventGenerator::NewRemoteEstimate() {
400   return std::make_unique<RtcEventRemoteEstimate>(
401       DataRate::KilobitsPerSec(prng_.Rand(0, 100000)),
402       DataRate::KilobitsPerSec(prng_.Rand(0, 100000)));
403 }
404 
405 std::unique_ptr<RtcEventRtcpPacketIncoming>
NewRtcpPacketIncoming()406 EventGenerator::NewRtcpPacketIncoming() {
407   enum class SupportedRtcpTypes {
408     kSenderReport = 0,
409     kReceiverReport,
410     kExtendedReports,
411     kFir,
412     kPli,
413     kNack,
414     kRemb,
415     kBye,
416     kTransportFeedback,
417     kNumValues
418   };
419   SupportedRtcpTypes type = static_cast<SupportedRtcpTypes>(
420       prng_.Rand(0, static_cast<int>(SupportedRtcpTypes::kNumValues) - 1));
421   switch (type) {
422     case SupportedRtcpTypes::kSenderReport: {
423       rtcp::SenderReport sender_report = NewSenderReport();
424       rtc::Buffer buffer = sender_report.Build();
425       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
426     }
427     case SupportedRtcpTypes::kReceiverReport: {
428       rtcp::ReceiverReport receiver_report = NewReceiverReport();
429       rtc::Buffer buffer = receiver_report.Build();
430       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
431     }
432     case SupportedRtcpTypes::kExtendedReports: {
433       rtcp::ExtendedReports extended_report = NewExtendedReports();
434       rtc::Buffer buffer = extended_report.Build();
435       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
436     }
437     case SupportedRtcpTypes::kFir: {
438       rtcp::Fir fir = NewFir();
439       rtc::Buffer buffer = fir.Build();
440       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
441     }
442     case SupportedRtcpTypes::kPli: {
443       rtcp::Pli pli = NewPli();
444       rtc::Buffer buffer = pli.Build();
445       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
446     }
447     case SupportedRtcpTypes::kNack: {
448       rtcp::Nack nack = NewNack();
449       rtc::Buffer buffer = nack.Build();
450       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
451     }
452     case SupportedRtcpTypes::kRemb: {
453       rtcp::Remb remb = NewRemb();
454       rtc::Buffer buffer = remb.Build();
455       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
456     }
457     case SupportedRtcpTypes::kBye: {
458       rtcp::Bye bye = NewBye();
459       rtc::Buffer buffer = bye.Build();
460       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
461     }
462     case SupportedRtcpTypes::kTransportFeedback: {
463       rtcp::TransportFeedback transport_feedback = NewTransportFeedback();
464       rtc::Buffer buffer = transport_feedback.Build();
465       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
466     }
467     default:
468       RTC_DCHECK_NOTREACHED();
469       rtc::Buffer buffer;
470       return std::make_unique<RtcEventRtcpPacketIncoming>(buffer);
471   }
472 }
473 
474 std::unique_ptr<RtcEventRtcpPacketOutgoing>
NewRtcpPacketOutgoing()475 EventGenerator::NewRtcpPacketOutgoing() {
476   enum class SupportedRtcpTypes {
477     kSenderReport = 0,
478     kReceiverReport,
479     kExtendedReports,
480     kFir,
481     kPli,
482     kNack,
483     kRemb,
484     kBye,
485     kTransportFeedback,
486     kNumValues
487   };
488   SupportedRtcpTypes type = static_cast<SupportedRtcpTypes>(
489       prng_.Rand(0, static_cast<int>(SupportedRtcpTypes::kNumValues) - 1));
490   switch (type) {
491     case SupportedRtcpTypes::kSenderReport: {
492       rtcp::SenderReport sender_report = NewSenderReport();
493       rtc::Buffer buffer = sender_report.Build();
494       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
495     }
496     case SupportedRtcpTypes::kReceiverReport: {
497       rtcp::ReceiverReport receiver_report = NewReceiverReport();
498       rtc::Buffer buffer = receiver_report.Build();
499       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
500     }
501     case SupportedRtcpTypes::kExtendedReports: {
502       rtcp::ExtendedReports extended_report = NewExtendedReports();
503       rtc::Buffer buffer = extended_report.Build();
504       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
505     }
506     case SupportedRtcpTypes::kFir: {
507       rtcp::Fir fir = NewFir();
508       rtc::Buffer buffer = fir.Build();
509       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
510     }
511     case SupportedRtcpTypes::kPli: {
512       rtcp::Pli pli = NewPli();
513       rtc::Buffer buffer = pli.Build();
514       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
515     }
516     case SupportedRtcpTypes::kNack: {
517       rtcp::Nack nack = NewNack();
518       rtc::Buffer buffer = nack.Build();
519       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
520     }
521     case SupportedRtcpTypes::kRemb: {
522       rtcp::Remb remb = NewRemb();
523       rtc::Buffer buffer = remb.Build();
524       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
525     }
526     case SupportedRtcpTypes::kBye: {
527       rtcp::Bye bye = NewBye();
528       rtc::Buffer buffer = bye.Build();
529       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
530     }
531     case SupportedRtcpTypes::kTransportFeedback: {
532       rtcp::TransportFeedback transport_feedback = NewTransportFeedback();
533       rtc::Buffer buffer = transport_feedback.Build();
534       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
535     }
536     default:
537       RTC_DCHECK_NOTREACHED();
538       rtc::Buffer buffer;
539       return std::make_unique<RtcEventRtcpPacketOutgoing>(buffer);
540   }
541 }
542 
543 std::unique_ptr<RtcEventGenericPacketSent>
NewGenericPacketSent()544 EventGenerator::NewGenericPacketSent() {
545   return std::make_unique<RtcEventGenericPacketSent>(
546       sent_packet_number_++, prng_.Rand(40, 50), prng_.Rand(0, 150),
547       prng_.Rand(0, 1000));
548 }
549 std::unique_ptr<RtcEventGenericPacketReceived>
NewGenericPacketReceived()550 EventGenerator::NewGenericPacketReceived() {
551   return std::make_unique<RtcEventGenericPacketReceived>(
552       received_packet_number_++, prng_.Rand(40, 250));
553 }
554 std::unique_ptr<RtcEventGenericAckReceived>
NewGenericAckReceived()555 EventGenerator::NewGenericAckReceived() {
556   absl::optional<int64_t> receive_timestamp = absl::nullopt;
557   if (prng_.Rand(0, 2) > 0) {
558     receive_timestamp = prng_.Rand(0, 100000);
559   }
560   AckedPacket packet = {prng_.Rand(40, 250), receive_timestamp};
561   return std::move(RtcEventGenericAckReceived::CreateLogs(
562       received_packet_number_++, std::vector<AckedPacket>{packet})[0]);
563 }
564 
RandomizeRtpPacket(size_t payload_size,size_t padding_size,uint32_t ssrc,const RtpHeaderExtensionMap & extension_map,RtpPacket * rtp_packet,bool all_configured_exts)565 void EventGenerator::RandomizeRtpPacket(
566     size_t payload_size,
567     size_t padding_size,
568     uint32_t ssrc,
569     const RtpHeaderExtensionMap& extension_map,
570     RtpPacket* rtp_packet,
571     bool all_configured_exts) {
572   constexpr int kMaxPayloadType = 127;
573   rtp_packet->SetPayloadType(prng_.Rand(kMaxPayloadType));
574   rtp_packet->SetMarker(prng_.Rand<bool>());
575   rtp_packet->SetSequenceNumber(prng_.Rand<uint16_t>());
576   rtp_packet->SetSsrc(ssrc);
577   rtp_packet->SetTimestamp(prng_.Rand<uint32_t>());
578 
579   uint32_t csrcs_count = prng_.Rand(0, kMaxCsrcs);
580   std::vector<uint32_t> csrcs;
581   for (size_t i = 0; i < csrcs_count; i++) {
582     csrcs.push_back(prng_.Rand<uint32_t>());
583   }
584   rtp_packet->SetCsrcs(csrcs);
585 
586   if (extension_map.IsRegistered(TransmissionOffset::kId) &&
587       (all_configured_exts || prng_.Rand<bool>())) {
588     rtp_packet->SetExtension<TransmissionOffset>(prng_.Rand(0x00ffffff));
589   }
590 
591   if (extension_map.IsRegistered(AudioLevel::kId) &&
592       (all_configured_exts || prng_.Rand<bool>())) {
593     rtp_packet->SetExtension<AudioLevel>(prng_.Rand<bool>(), prng_.Rand(127));
594   }
595 
596   if (extension_map.IsRegistered(AbsoluteSendTime::kId) &&
597       (all_configured_exts || prng_.Rand<bool>())) {
598     rtp_packet->SetExtension<AbsoluteSendTime>(prng_.Rand(0x00ffffff));
599   }
600 
601   if (extension_map.IsRegistered(VideoOrientation::kId) &&
602       (all_configured_exts || prng_.Rand<bool>())) {
603     rtp_packet->SetExtension<VideoOrientation>(prng_.Rand(3));
604   }
605 
606   if (extension_map.IsRegistered(TransportSequenceNumber::kId) &&
607       (all_configured_exts || prng_.Rand<bool>())) {
608     rtp_packet->SetExtension<TransportSequenceNumber>(prng_.Rand<uint16_t>());
609   }
610 
611   RTC_CHECK_LE(rtp_packet->headers_size() + payload_size, IP_PACKET_SIZE);
612 
613   uint8_t* payload = rtp_packet->AllocatePayload(payload_size);
614   RTC_DCHECK(payload != nullptr);
615   for (size_t i = 0; i < payload_size; i++) {
616     payload[i] = prng_.Rand<uint8_t>();
617   }
618   RTC_CHECK(rtp_packet->SetPadding(padding_size));
619 }
620 
NewRtpPacketIncoming(uint32_t ssrc,const RtpHeaderExtensionMap & extension_map,bool all_configured_exts)621 std::unique_ptr<RtcEventRtpPacketIncoming> EventGenerator::NewRtpPacketIncoming(
622     uint32_t ssrc,
623     const RtpHeaderExtensionMap& extension_map,
624     bool all_configured_exts) {
625   constexpr size_t kMaxPaddingLength = 224;
626   const bool padding = prng_.Rand(0, 9) == 0;  // Let padding be 10% probable.
627   const size_t padding_size = !padding ? 0u : prng_.Rand(0u, kMaxPaddingLength);
628 
629   // 12 bytes RTP header, 4 bytes for 0xBEDE + alignment, 4 bytes per CSRC.
630   constexpr size_t kMaxHeaderSize =
631       16 + 4 * kMaxCsrcs + kMaxExtensionSizeBytes * kMaxNumExtensions;
632 
633   // In principle, a packet can contain both padding and other payload.
634   // Currently, RTC eventlog encoder-parser can only maintain padding length if
635   // packet is full padding.
636   // TODO(webrtc:9730): Remove the deterministic logic for padding_size > 0.
637   size_t payload_size =
638       padding_size > 0 ? 0
639                        : prng_.Rand(0u, static_cast<uint32_t>(IP_PACKET_SIZE -
640                                                               1 - padding_size -
641                                                               kMaxHeaderSize));
642 
643   RtpPacketReceived rtp_packet(&extension_map);
644   RandomizeRtpPacket(payload_size, padding_size, ssrc, extension_map,
645                      &rtp_packet, all_configured_exts);
646 
647   return std::make_unique<RtcEventRtpPacketIncoming>(rtp_packet);
648 }
649 
NewRtpPacketOutgoing(uint32_t ssrc,const RtpHeaderExtensionMap & extension_map,bool all_configured_exts)650 std::unique_ptr<RtcEventRtpPacketOutgoing> EventGenerator::NewRtpPacketOutgoing(
651     uint32_t ssrc,
652     const RtpHeaderExtensionMap& extension_map,
653     bool all_configured_exts) {
654   constexpr size_t kMaxPaddingLength = 224;
655   const bool padding = prng_.Rand(0, 9) == 0;  // Let padding be 10% probable.
656   const size_t padding_size = !padding ? 0u : prng_.Rand(0u, kMaxPaddingLength);
657 
658   // 12 bytes RTP header, 4 bytes for 0xBEDE + alignment, 4 bytes per CSRC.
659   constexpr size_t kMaxHeaderSize =
660       16 + 4 * kMaxCsrcs + kMaxExtensionSizeBytes * kMaxNumExtensions;
661 
662   // In principle,a packet can contain both padding and other payload.
663   // Currently, RTC eventlog encoder-parser can only maintain padding length if
664   // packet is full padding.
665   // TODO(webrtc:9730): Remove the deterministic logic for padding_size > 0.
666   size_t payload_size =
667       padding_size > 0 ? 0
668                        : prng_.Rand(0u, static_cast<uint32_t>(IP_PACKET_SIZE -
669                                                               1 - padding_size -
670                                                               kMaxHeaderSize));
671 
672   RtpPacketToSend rtp_packet(&extension_map,
673                              kMaxHeaderSize + payload_size + padding_size);
674   RandomizeRtpPacket(payload_size, padding_size, ssrc, extension_map,
675                      &rtp_packet, all_configured_exts);
676 
677   int probe_cluster_id = prng_.Rand(0, 100000);
678   return std::make_unique<RtcEventRtpPacketOutgoing>(rtp_packet,
679                                                      probe_cluster_id);
680 }
681 
NewRtpHeaderExtensionMap(bool configure_all)682 RtpHeaderExtensionMap EventGenerator::NewRtpHeaderExtensionMap(
683     bool configure_all) {
684   RtpHeaderExtensionMap extension_map;
685   std::vector<int> id(RtpExtension::kOneByteHeaderExtensionMaxId -
686                       RtpExtension::kMinId + 1);
687   std::iota(id.begin(), id.end(), RtpExtension::kMinId);
688   ShuffleInPlace(&prng_, rtc::ArrayView<int>(id));
689 
690   if (configure_all || prng_.Rand<bool>()) {
691     extension_map.Register<AudioLevel>(id[0]);
692   }
693   if (configure_all || prng_.Rand<bool>()) {
694     extension_map.Register<TransmissionOffset>(id[1]);
695   }
696   if (configure_all || prng_.Rand<bool>()) {
697     extension_map.Register<AbsoluteSendTime>(id[2]);
698   }
699   if (configure_all || prng_.Rand<bool>()) {
700     extension_map.Register<VideoOrientation>(id[3]);
701   }
702   if (configure_all || prng_.Rand<bool>()) {
703     extension_map.Register<TransportSequenceNumber>(id[4]);
704   }
705 
706   return extension_map;
707 }
708 
709 std::unique_ptr<RtcEventAudioReceiveStreamConfig>
NewAudioReceiveStreamConfig(uint32_t ssrc,const RtpHeaderExtensionMap & extensions)710 EventGenerator::NewAudioReceiveStreamConfig(
711     uint32_t ssrc,
712     const RtpHeaderExtensionMap& extensions) {
713   auto config = std::make_unique<rtclog::StreamConfig>();
714   // Add SSRCs for the stream.
715   config->remote_ssrc = ssrc;
716   config->local_ssrc = prng_.Rand<uint32_t>();
717   // Add header extensions.
718   for (size_t i = 0; i < kMaxNumExtensions; i++) {
719     uint8_t id = extensions.GetId(kExtensions[i].type);
720     if (id != RtpHeaderExtensionMap::kInvalidId) {
721       config->rtp_extensions.emplace_back(kExtensions[i].name, id);
722     }
723   }
724 
725   return std::make_unique<RtcEventAudioReceiveStreamConfig>(std::move(config));
726 }
727 
728 std::unique_ptr<RtcEventAudioSendStreamConfig>
NewAudioSendStreamConfig(uint32_t ssrc,const RtpHeaderExtensionMap & extensions)729 EventGenerator::NewAudioSendStreamConfig(
730     uint32_t ssrc,
731     const RtpHeaderExtensionMap& extensions) {
732   auto config = std::make_unique<rtclog::StreamConfig>();
733   // Add SSRC to the stream.
734   config->local_ssrc = ssrc;
735   // Add header extensions.
736   for (size_t i = 0; i < kMaxNumExtensions; i++) {
737     uint8_t id = extensions.GetId(kExtensions[i].type);
738     if (id != RtpHeaderExtensionMap::kInvalidId) {
739       config->rtp_extensions.emplace_back(kExtensions[i].name, id);
740     }
741   }
742   return std::make_unique<RtcEventAudioSendStreamConfig>(std::move(config));
743 }
744 
745 std::unique_ptr<RtcEventVideoReceiveStreamConfig>
NewVideoReceiveStreamConfig(uint32_t ssrc,const RtpHeaderExtensionMap & extensions)746 EventGenerator::NewVideoReceiveStreamConfig(
747     uint32_t ssrc,
748     const RtpHeaderExtensionMap& extensions) {
749   auto config = std::make_unique<rtclog::StreamConfig>();
750 
751   // Add SSRCs for the stream.
752   config->remote_ssrc = ssrc;
753   config->local_ssrc = prng_.Rand<uint32_t>();
754   // Add extensions and settings for RTCP.
755   config->rtcp_mode =
756       prng_.Rand<bool>() ? RtcpMode::kCompound : RtcpMode::kReducedSize;
757   config->remb = prng_.Rand<bool>();
758   config->rtx_ssrc = prng_.Rand<uint32_t>();
759   config->codecs.emplace_back(prng_.Rand<bool>() ? "VP8" : "H264",
760                               prng_.Rand(127), prng_.Rand(127));
761   // Add header extensions.
762   for (size_t i = 0; i < kMaxNumExtensions; i++) {
763     uint8_t id = extensions.GetId(kExtensions[i].type);
764     if (id != RtpHeaderExtensionMap::kInvalidId) {
765       config->rtp_extensions.emplace_back(kExtensions[i].name, id);
766     }
767   }
768   return std::make_unique<RtcEventVideoReceiveStreamConfig>(std::move(config));
769 }
770 
771 std::unique_ptr<RtcEventVideoSendStreamConfig>
NewVideoSendStreamConfig(uint32_t ssrc,const RtpHeaderExtensionMap & extensions)772 EventGenerator::NewVideoSendStreamConfig(
773     uint32_t ssrc,
774     const RtpHeaderExtensionMap& extensions) {
775   auto config = std::make_unique<rtclog::StreamConfig>();
776 
777   config->codecs.emplace_back(prng_.Rand<bool>() ? "VP8" : "H264",
778                               prng_.Rand(127), prng_.Rand(127));
779   config->local_ssrc = ssrc;
780   config->rtx_ssrc = prng_.Rand<uint32_t>();
781   // Add header extensions.
782   for (size_t i = 0; i < kMaxNumExtensions; i++) {
783     uint8_t id = extensions.GetId(kExtensions[i].type);
784     if (id != RtpHeaderExtensionMap::kInvalidId) {
785       config->rtp_extensions.emplace_back(kExtensions[i].name, id);
786     }
787   }
788   return std::make_unique<RtcEventVideoSendStreamConfig>(std::move(config));
789 }
790 
VerifyLoggedAlrStateEvent(const RtcEventAlrState & original_event,const LoggedAlrStateEvent & logged_event) const791 void EventVerifier::VerifyLoggedAlrStateEvent(
792     const RtcEventAlrState& original_event,
793     const LoggedAlrStateEvent& logged_event) const {
794   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
795   EXPECT_EQ(original_event.in_alr(), logged_event.in_alr);
796 }
797 
VerifyLoggedAudioPlayoutEvent(const RtcEventAudioPlayout & original_event,const LoggedAudioPlayoutEvent & logged_event) const798 void EventVerifier::VerifyLoggedAudioPlayoutEvent(
799     const RtcEventAudioPlayout& original_event,
800     const LoggedAudioPlayoutEvent& logged_event) const {
801   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
802   EXPECT_EQ(original_event.ssrc(), logged_event.ssrc);
803 }
804 
VerifyLoggedAudioNetworkAdaptationEvent(const RtcEventAudioNetworkAdaptation & original_event,const LoggedAudioNetworkAdaptationEvent & logged_event) const805 void EventVerifier::VerifyLoggedAudioNetworkAdaptationEvent(
806     const RtcEventAudioNetworkAdaptation& original_event,
807     const LoggedAudioNetworkAdaptationEvent& logged_event) const {
808   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
809 
810   EXPECT_EQ(original_event.config().bitrate_bps,
811             logged_event.config.bitrate_bps);
812   EXPECT_EQ(original_event.config().enable_dtx, logged_event.config.enable_dtx);
813   EXPECT_EQ(original_event.config().enable_fec, logged_event.config.enable_fec);
814   EXPECT_EQ(original_event.config().frame_length_ms,
815             logged_event.config.frame_length_ms);
816   EXPECT_EQ(original_event.config().num_channels,
817             logged_event.config.num_channels);
818 
819   // uplink_packet_loss_fraction
820   ASSERT_EQ(original_event.config().uplink_packet_loss_fraction.has_value(),
821             logged_event.config.uplink_packet_loss_fraction.has_value());
822   if (original_event.config().uplink_packet_loss_fraction.has_value()) {
823     const float original =
824         original_event.config().uplink_packet_loss_fraction.value();
825     const float logged =
826         logged_event.config.uplink_packet_loss_fraction.value();
827     const float uplink_packet_loss_fraction_delta = std::abs(original - logged);
828     EXPECT_LE(uplink_packet_loss_fraction_delta, 0.0001f);
829   }
830 }
831 
VerifyLoggedBweDelayBasedUpdate(const RtcEventBweUpdateDelayBased & original_event,const LoggedBweDelayBasedUpdate & logged_event) const832 void EventVerifier::VerifyLoggedBweDelayBasedUpdate(
833     const RtcEventBweUpdateDelayBased& original_event,
834     const LoggedBweDelayBasedUpdate& logged_event) const {
835   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
836   EXPECT_EQ(original_event.bitrate_bps(), logged_event.bitrate_bps);
837   EXPECT_EQ(original_event.detector_state(), logged_event.detector_state);
838 }
839 
VerifyLoggedBweLossBasedUpdate(const RtcEventBweUpdateLossBased & original_event,const LoggedBweLossBasedUpdate & logged_event) const840 void EventVerifier::VerifyLoggedBweLossBasedUpdate(
841     const RtcEventBweUpdateLossBased& original_event,
842     const LoggedBweLossBasedUpdate& logged_event) const {
843   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
844   EXPECT_EQ(original_event.bitrate_bps(), logged_event.bitrate_bps);
845   EXPECT_EQ(original_event.fraction_loss(), logged_event.fraction_lost);
846   EXPECT_EQ(original_event.total_packets(), logged_event.expected_packets);
847 }
848 
VerifyLoggedBweProbeClusterCreatedEvent(const RtcEventProbeClusterCreated & original_event,const LoggedBweProbeClusterCreatedEvent & logged_event) const849 void EventVerifier::VerifyLoggedBweProbeClusterCreatedEvent(
850     const RtcEventProbeClusterCreated& original_event,
851     const LoggedBweProbeClusterCreatedEvent& logged_event) const {
852   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
853   EXPECT_EQ(original_event.id(), logged_event.id);
854   EXPECT_EQ(original_event.bitrate_bps(), logged_event.bitrate_bps);
855   EXPECT_EQ(original_event.min_probes(), logged_event.min_packets);
856   EXPECT_EQ(original_event.min_bytes(), logged_event.min_bytes);
857 }
858 
VerifyLoggedBweProbeFailureEvent(const RtcEventProbeResultFailure & original_event,const LoggedBweProbeFailureEvent & logged_event) const859 void EventVerifier::VerifyLoggedBweProbeFailureEvent(
860     const RtcEventProbeResultFailure& original_event,
861     const LoggedBweProbeFailureEvent& logged_event) const {
862   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
863   EXPECT_EQ(original_event.id(), logged_event.id);
864   EXPECT_EQ(original_event.failure_reason(), logged_event.failure_reason);
865 }
866 
VerifyLoggedBweProbeSuccessEvent(const RtcEventProbeResultSuccess & original_event,const LoggedBweProbeSuccessEvent & logged_event) const867 void EventVerifier::VerifyLoggedBweProbeSuccessEvent(
868     const RtcEventProbeResultSuccess& original_event,
869     const LoggedBweProbeSuccessEvent& logged_event) const {
870   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
871   EXPECT_EQ(original_event.id(), logged_event.id);
872   EXPECT_EQ(original_event.bitrate_bps(), logged_event.bitrate_bps);
873 }
874 
VerifyLoggedDtlsTransportState(const RtcEventDtlsTransportState & original_event,const LoggedDtlsTransportState & logged_event) const875 void EventVerifier::VerifyLoggedDtlsTransportState(
876     const RtcEventDtlsTransportState& original_event,
877     const LoggedDtlsTransportState& logged_event) const {
878   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
879   EXPECT_EQ(original_event.dtls_transport_state(),
880             logged_event.dtls_transport_state);
881 }
882 
VerifyLoggedDtlsWritableState(const RtcEventDtlsWritableState & original_event,const LoggedDtlsWritableState & logged_event) const883 void EventVerifier::VerifyLoggedDtlsWritableState(
884     const RtcEventDtlsWritableState& original_event,
885     const LoggedDtlsWritableState& logged_event) const {
886   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
887   EXPECT_EQ(original_event.writable(), logged_event.writable);
888 }
889 
VerifyLoggedFrameDecoded(const RtcEventFrameDecoded & original_event,const LoggedFrameDecoded & logged_event) const890 void EventVerifier::VerifyLoggedFrameDecoded(
891     const RtcEventFrameDecoded& original_event,
892     const LoggedFrameDecoded& logged_event) const {
893   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
894   EXPECT_EQ(original_event.ssrc(), logged_event.ssrc);
895   EXPECT_EQ(original_event.render_time_ms(), logged_event.render_time_ms);
896   EXPECT_EQ(original_event.width(), logged_event.width);
897   EXPECT_EQ(original_event.height(), logged_event.height);
898   EXPECT_EQ(original_event.codec(), logged_event.codec);
899   EXPECT_EQ(original_event.qp(), logged_event.qp);
900 }
901 
VerifyLoggedIceCandidatePairConfig(const RtcEventIceCandidatePairConfig & original_event,const LoggedIceCandidatePairConfig & logged_event) const902 void EventVerifier::VerifyLoggedIceCandidatePairConfig(
903     const RtcEventIceCandidatePairConfig& original_event,
904     const LoggedIceCandidatePairConfig& logged_event) const {
905   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
906 
907   EXPECT_EQ(original_event.type(), logged_event.type);
908   EXPECT_EQ(original_event.candidate_pair_id(), logged_event.candidate_pair_id);
909   EXPECT_EQ(original_event.candidate_pair_desc().local_candidate_type,
910             logged_event.local_candidate_type);
911   EXPECT_EQ(original_event.candidate_pair_desc().local_relay_protocol,
912             logged_event.local_relay_protocol);
913   EXPECT_EQ(original_event.candidate_pair_desc().local_network_type,
914             logged_event.local_network_type);
915   EXPECT_EQ(original_event.candidate_pair_desc().local_address_family,
916             logged_event.local_address_family);
917   EXPECT_EQ(original_event.candidate_pair_desc().remote_candidate_type,
918             logged_event.remote_candidate_type);
919   EXPECT_EQ(original_event.candidate_pair_desc().remote_address_family,
920             logged_event.remote_address_family);
921   EXPECT_EQ(original_event.candidate_pair_desc().candidate_pair_protocol,
922             logged_event.candidate_pair_protocol);
923 }
924 
VerifyLoggedIceCandidatePairEvent(const RtcEventIceCandidatePair & original_event,const LoggedIceCandidatePairEvent & logged_event) const925 void EventVerifier::VerifyLoggedIceCandidatePairEvent(
926     const RtcEventIceCandidatePair& original_event,
927     const LoggedIceCandidatePairEvent& logged_event) const {
928   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
929 
930   EXPECT_EQ(original_event.type(), logged_event.type);
931   EXPECT_EQ(original_event.candidate_pair_id(), logged_event.candidate_pair_id);
932   if (encoding_type_ == RtcEventLog::EncodingType::NewFormat) {
933     EXPECT_EQ(original_event.transaction_id(), logged_event.transaction_id);
934   }
935 }
936 
937 template <typename Event>
VerifyLoggedRtpHeader(const Event & original_header,const RTPHeader & logged_header)938 void VerifyLoggedRtpHeader(const Event& original_header,
939                            const RTPHeader& logged_header) {
940   // Standard RTP header.
941   EXPECT_EQ(original_header.Marker(), logged_header.markerBit);
942   EXPECT_EQ(original_header.PayloadType(), logged_header.payloadType);
943   EXPECT_EQ(original_header.SequenceNumber(), logged_header.sequenceNumber);
944   EXPECT_EQ(original_header.Timestamp(), logged_header.timestamp);
945   EXPECT_EQ(original_header.Ssrc(), logged_header.ssrc);
946 
947   EXPECT_EQ(original_header.header_length(), logged_header.headerLength);
948 
949   // TransmissionOffset header extension.
950   ASSERT_EQ(original_header.template HasExtension<TransmissionOffset>(),
951             logged_header.extension.hasTransmissionTimeOffset);
952   if (logged_header.extension.hasTransmissionTimeOffset) {
953     int32_t offset;
954     ASSERT_TRUE(
955         original_header.template GetExtension<TransmissionOffset>(&offset));
956     EXPECT_EQ(offset, logged_header.extension.transmissionTimeOffset);
957   }
958 
959   // AbsoluteSendTime header extension.
960   ASSERT_EQ(original_header.template HasExtension<AbsoluteSendTime>(),
961             logged_header.extension.hasAbsoluteSendTime);
962   if (logged_header.extension.hasAbsoluteSendTime) {
963     uint32_t sendtime;
964     ASSERT_TRUE(
965         original_header.template GetExtension<AbsoluteSendTime>(&sendtime));
966     EXPECT_EQ(sendtime, logged_header.extension.absoluteSendTime);
967   }
968 
969   // TransportSequenceNumber header extension.
970   ASSERT_EQ(original_header.template HasExtension<TransportSequenceNumber>(),
971             logged_header.extension.hasTransportSequenceNumber);
972   if (logged_header.extension.hasTransportSequenceNumber) {
973     uint16_t seqnum;
974     ASSERT_TRUE(original_header.template GetExtension<TransportSequenceNumber>(
975         &seqnum));
976     EXPECT_EQ(seqnum, logged_header.extension.transportSequenceNumber);
977   }
978 
979   // AudioLevel header extension.
980   ASSERT_EQ(original_header.template HasExtension<AudioLevel>(),
981             logged_header.extension.hasAudioLevel);
982   if (logged_header.extension.hasAudioLevel) {
983     bool voice_activity;
984     uint8_t audio_level;
985     ASSERT_TRUE(original_header.template GetExtension<AudioLevel>(
986         &voice_activity, &audio_level));
987     EXPECT_EQ(voice_activity, logged_header.extension.voiceActivity);
988     EXPECT_EQ(audio_level, logged_header.extension.audioLevel);
989   }
990 
991   // VideoOrientation header extension.
992   ASSERT_EQ(original_header.template HasExtension<VideoOrientation>(),
993             logged_header.extension.hasVideoRotation);
994   if (logged_header.extension.hasVideoRotation) {
995     uint8_t rotation;
996     ASSERT_TRUE(
997         original_header.template GetExtension<VideoOrientation>(&rotation));
998     EXPECT_EQ(ConvertCVOByteToVideoRotation(rotation),
999               logged_header.extension.videoRotation);
1000   }
1001 }
1002 
VerifyLoggedRouteChangeEvent(const RtcEventRouteChange & original_event,const LoggedRouteChangeEvent & logged_event) const1003 void EventVerifier::VerifyLoggedRouteChangeEvent(
1004     const RtcEventRouteChange& original_event,
1005     const LoggedRouteChangeEvent& logged_event) const {
1006   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1007   EXPECT_EQ(original_event.connected(), logged_event.connected);
1008   EXPECT_EQ(original_event.overhead(), logged_event.overhead);
1009 }
1010 
VerifyLoggedRemoteEstimateEvent(const RtcEventRemoteEstimate & original_event,const LoggedRemoteEstimateEvent & logged_event) const1011 void EventVerifier::VerifyLoggedRemoteEstimateEvent(
1012     const RtcEventRemoteEstimate& original_event,
1013     const LoggedRemoteEstimateEvent& logged_event) const {
1014   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1015   EXPECT_EQ(original_event.link_capacity_lower_,
1016             logged_event.link_capacity_lower);
1017   EXPECT_EQ(original_event.link_capacity_upper_,
1018             logged_event.link_capacity_upper);
1019 }
1020 
VerifyLoggedRtpPacketIncoming(const RtcEventRtpPacketIncoming & original_event,const LoggedRtpPacketIncoming & logged_event) const1021 void EventVerifier::VerifyLoggedRtpPacketIncoming(
1022     const RtcEventRtpPacketIncoming& original_event,
1023     const LoggedRtpPacketIncoming& logged_event) const {
1024   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1025 
1026   EXPECT_EQ(original_event.header_length(), logged_event.rtp.header_length);
1027 
1028   EXPECT_EQ(original_event.packet_length(), logged_event.rtp.total_length);
1029 
1030   // Currently, RTC eventlog encoder-parser can only maintain padding length
1031   // if packet is full padding.
1032   EXPECT_EQ(original_event.padding_length(),
1033             logged_event.rtp.header.paddingLength);
1034 
1035   VerifyLoggedRtpHeader(original_event, logged_event.rtp.header);
1036 }
1037 
VerifyLoggedRtpPacketOutgoing(const RtcEventRtpPacketOutgoing & original_event,const LoggedRtpPacketOutgoing & logged_event) const1038 void EventVerifier::VerifyLoggedRtpPacketOutgoing(
1039     const RtcEventRtpPacketOutgoing& original_event,
1040     const LoggedRtpPacketOutgoing& logged_event) const {
1041   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1042 
1043   EXPECT_EQ(original_event.header_length(), logged_event.rtp.header_length);
1044 
1045   EXPECT_EQ(original_event.packet_length(), logged_event.rtp.total_length);
1046 
1047   // Currently, RTC eventlog encoder-parser can only maintain padding length
1048   // if packet is full padding.
1049   EXPECT_EQ(original_event.padding_length(),
1050             logged_event.rtp.header.paddingLength);
1051 
1052   // TODO(terelius): Probe cluster ID isn't parsed, used or tested. Unless
1053   // someone has a strong reason to keep it, it'll be removed.
1054 
1055   VerifyLoggedRtpHeader(original_event, logged_event.rtp.header);
1056 }
1057 
VerifyLoggedGenericPacketSent(const RtcEventGenericPacketSent & original_event,const LoggedGenericPacketSent & logged_event) const1058 void EventVerifier::VerifyLoggedGenericPacketSent(
1059     const RtcEventGenericPacketSent& original_event,
1060     const LoggedGenericPacketSent& logged_event) const {
1061   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1062   EXPECT_EQ(original_event.packet_number(), logged_event.packet_number);
1063   EXPECT_EQ(original_event.overhead_length(), logged_event.overhead_length);
1064   EXPECT_EQ(original_event.payload_length(), logged_event.payload_length);
1065   EXPECT_EQ(original_event.padding_length(), logged_event.padding_length);
1066 }
1067 
VerifyLoggedGenericPacketReceived(const RtcEventGenericPacketReceived & original_event,const LoggedGenericPacketReceived & logged_event) const1068 void EventVerifier::VerifyLoggedGenericPacketReceived(
1069     const RtcEventGenericPacketReceived& original_event,
1070     const LoggedGenericPacketReceived& logged_event) const {
1071   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1072   EXPECT_EQ(original_event.packet_number(), logged_event.packet_number);
1073   EXPECT_EQ(static_cast<int>(original_event.packet_length()),
1074             logged_event.packet_length);
1075 }
1076 
VerifyLoggedGenericAckReceived(const RtcEventGenericAckReceived & original_event,const LoggedGenericAckReceived & logged_event) const1077 void EventVerifier::VerifyLoggedGenericAckReceived(
1078     const RtcEventGenericAckReceived& original_event,
1079     const LoggedGenericAckReceived& logged_event) const {
1080   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1081   EXPECT_EQ(original_event.packet_number(), logged_event.packet_number);
1082   EXPECT_EQ(original_event.acked_packet_number(),
1083             logged_event.acked_packet_number);
1084   EXPECT_EQ(original_event.receive_acked_packet_time_ms(),
1085             logged_event.receive_acked_packet_time_ms);
1086 }
1087 
VerifyLoggedRtcpPacketIncoming(const RtcEventRtcpPacketIncoming & original_event,const LoggedRtcpPacketIncoming & logged_event) const1088 void EventVerifier::VerifyLoggedRtcpPacketIncoming(
1089     const RtcEventRtcpPacketIncoming& original_event,
1090     const LoggedRtcpPacketIncoming& logged_event) const {
1091   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1092 
1093   ASSERT_EQ(original_event.packet().size(), logged_event.rtcp.raw_data.size());
1094   EXPECT_EQ(
1095       memcmp(original_event.packet().data(), logged_event.rtcp.raw_data.data(),
1096              original_event.packet().size()),
1097       0);
1098 }
1099 
VerifyLoggedRtcpPacketOutgoing(const RtcEventRtcpPacketOutgoing & original_event,const LoggedRtcpPacketOutgoing & logged_event) const1100 void EventVerifier::VerifyLoggedRtcpPacketOutgoing(
1101     const RtcEventRtcpPacketOutgoing& original_event,
1102     const LoggedRtcpPacketOutgoing& logged_event) const {
1103   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1104 
1105   ASSERT_EQ(original_event.packet().size(), logged_event.rtcp.raw_data.size());
1106   EXPECT_EQ(
1107       memcmp(original_event.packet().data(), logged_event.rtcp.raw_data.data(),
1108              original_event.packet().size()),
1109       0);
1110 }
1111 
VerifyReportBlock(const rtcp::ReportBlock & original_report_block,const rtcp::ReportBlock & logged_report_block)1112 void EventVerifier::VerifyReportBlock(
1113     const rtcp::ReportBlock& original_report_block,
1114     const rtcp::ReportBlock& logged_report_block) {
1115   EXPECT_EQ(original_report_block.source_ssrc(),
1116             logged_report_block.source_ssrc());
1117   EXPECT_EQ(original_report_block.fraction_lost(),
1118             logged_report_block.fraction_lost());
1119   EXPECT_EQ(original_report_block.cumulative_lost_signed(),
1120             logged_report_block.cumulative_lost_signed());
1121   EXPECT_EQ(original_report_block.extended_high_seq_num(),
1122             logged_report_block.extended_high_seq_num());
1123   EXPECT_EQ(original_report_block.jitter(), logged_report_block.jitter());
1124   EXPECT_EQ(original_report_block.last_sr(), logged_report_block.last_sr());
1125   EXPECT_EQ(original_report_block.delay_since_last_sr(),
1126             logged_report_block.delay_since_last_sr());
1127 }
1128 
VerifyLoggedSenderReport(int64_t log_time_ms,const rtcp::SenderReport & original_sr,const LoggedRtcpPacketSenderReport & logged_sr)1129 void EventVerifier::VerifyLoggedSenderReport(
1130     int64_t log_time_ms,
1131     const rtcp::SenderReport& original_sr,
1132     const LoggedRtcpPacketSenderReport& logged_sr) {
1133   EXPECT_EQ(log_time_ms, logged_sr.log_time_ms());
1134   EXPECT_EQ(original_sr.sender_ssrc(), logged_sr.sr.sender_ssrc());
1135   EXPECT_EQ(original_sr.ntp(), logged_sr.sr.ntp());
1136   EXPECT_EQ(original_sr.rtp_timestamp(), logged_sr.sr.rtp_timestamp());
1137   EXPECT_EQ(original_sr.sender_packet_count(),
1138             logged_sr.sr.sender_packet_count());
1139   EXPECT_EQ(original_sr.sender_octet_count(),
1140             logged_sr.sr.sender_octet_count());
1141   ASSERT_EQ(original_sr.report_blocks().size(),
1142             logged_sr.sr.report_blocks().size());
1143   for (size_t i = 0; i < original_sr.report_blocks().size(); i++) {
1144     VerifyReportBlock(original_sr.report_blocks()[i],
1145                       logged_sr.sr.report_blocks()[i]);
1146   }
1147 }
1148 
VerifyLoggedReceiverReport(int64_t log_time_ms,const rtcp::ReceiverReport & original_rr,const LoggedRtcpPacketReceiverReport & logged_rr)1149 void EventVerifier::VerifyLoggedReceiverReport(
1150     int64_t log_time_ms,
1151     const rtcp::ReceiverReport& original_rr,
1152     const LoggedRtcpPacketReceiverReport& logged_rr) {
1153   EXPECT_EQ(log_time_ms, logged_rr.log_time_ms());
1154   EXPECT_EQ(original_rr.sender_ssrc(), logged_rr.rr.sender_ssrc());
1155   ASSERT_EQ(original_rr.report_blocks().size(),
1156             logged_rr.rr.report_blocks().size());
1157   for (size_t i = 0; i < original_rr.report_blocks().size(); i++) {
1158     VerifyReportBlock(original_rr.report_blocks()[i],
1159                       logged_rr.rr.report_blocks()[i]);
1160   }
1161 }
1162 
VerifyLoggedExtendedReports(int64_t log_time_ms,const rtcp::ExtendedReports & original_xr,const LoggedRtcpPacketExtendedReports & logged_xr)1163 void EventVerifier::VerifyLoggedExtendedReports(
1164     int64_t log_time_ms,
1165     const rtcp::ExtendedReports& original_xr,
1166     const LoggedRtcpPacketExtendedReports& logged_xr) {
1167   EXPECT_EQ(log_time_ms, logged_xr.log_time_ms());
1168   EXPECT_EQ(original_xr.sender_ssrc(), logged_xr.xr.sender_ssrc());
1169 
1170   EXPECT_EQ(original_xr.rrtr().has_value(), logged_xr.xr.rrtr().has_value());
1171   if (original_xr.rrtr().has_value() && logged_xr.xr.rrtr().has_value()) {
1172     EXPECT_EQ(original_xr.rrtr()->ntp(), logged_xr.xr.rrtr()->ntp());
1173   }
1174 
1175   const auto& original_subblocks = original_xr.dlrr().sub_blocks();
1176   const auto& logged_subblocks = logged_xr.xr.dlrr().sub_blocks();
1177   ASSERT_EQ(original_subblocks.size(), logged_subblocks.size());
1178   for (size_t i = 0; i < original_subblocks.size(); i++) {
1179     EXPECT_EQ(original_subblocks[i].ssrc, logged_subblocks[i].ssrc);
1180     EXPECT_EQ(original_subblocks[i].last_rr, logged_subblocks[i].last_rr);
1181     EXPECT_EQ(original_subblocks[i].delay_since_last_rr,
1182               logged_subblocks[i].delay_since_last_rr);
1183   }
1184 
1185   EXPECT_EQ(original_xr.target_bitrate().has_value(),
1186             logged_xr.xr.target_bitrate().has_value());
1187   if (original_xr.target_bitrate().has_value() &&
1188       logged_xr.xr.target_bitrate().has_value()) {
1189     const auto& original_bitrates =
1190         original_xr.target_bitrate()->GetTargetBitrates();
1191     const auto& logged_bitrates =
1192         logged_xr.xr.target_bitrate()->GetTargetBitrates();
1193     ASSERT_EQ(original_bitrates.size(), logged_bitrates.size());
1194     for (size_t i = 0; i < original_bitrates.size(); i++) {
1195       EXPECT_EQ(original_bitrates[i].spatial_layer,
1196                 logged_bitrates[i].spatial_layer);
1197       EXPECT_EQ(original_bitrates[i].temporal_layer,
1198                 logged_bitrates[i].temporal_layer);
1199       EXPECT_EQ(original_bitrates[i].target_bitrate_kbps,
1200                 logged_bitrates[i].target_bitrate_kbps);
1201     }
1202   }
1203 }
1204 
VerifyLoggedFir(int64_t log_time_ms,const rtcp::Fir & original_fir,const LoggedRtcpPacketFir & logged_fir)1205 void EventVerifier::VerifyLoggedFir(int64_t log_time_ms,
1206                                     const rtcp::Fir& original_fir,
1207                                     const LoggedRtcpPacketFir& logged_fir) {
1208   EXPECT_EQ(log_time_ms, logged_fir.log_time_ms());
1209   EXPECT_EQ(original_fir.sender_ssrc(), logged_fir.fir.sender_ssrc());
1210   const auto& original_requests = original_fir.requests();
1211   const auto& logged_requests = logged_fir.fir.requests();
1212   ASSERT_EQ(original_requests.size(), logged_requests.size());
1213   for (size_t i = 0; i < original_requests.size(); i++) {
1214     EXPECT_EQ(original_requests[i].ssrc, logged_requests[i].ssrc);
1215     EXPECT_EQ(original_requests[i].seq_nr, logged_requests[i].seq_nr);
1216   }
1217 }
1218 
VerifyLoggedPli(int64_t log_time_ms,const rtcp::Pli & original_pli,const LoggedRtcpPacketPli & logged_pli)1219 void EventVerifier::VerifyLoggedPli(int64_t log_time_ms,
1220                                     const rtcp::Pli& original_pli,
1221                                     const LoggedRtcpPacketPli& logged_pli) {
1222   EXPECT_EQ(log_time_ms, logged_pli.log_time_ms());
1223   EXPECT_EQ(original_pli.sender_ssrc(), logged_pli.pli.sender_ssrc());
1224   EXPECT_EQ(original_pli.media_ssrc(), logged_pli.pli.media_ssrc());
1225 }
1226 
VerifyLoggedBye(int64_t log_time_ms,const rtcp::Bye & original_bye,const LoggedRtcpPacketBye & logged_bye)1227 void EventVerifier::VerifyLoggedBye(int64_t log_time_ms,
1228                                     const rtcp::Bye& original_bye,
1229                                     const LoggedRtcpPacketBye& logged_bye) {
1230   EXPECT_EQ(log_time_ms, logged_bye.log_time_ms());
1231   EXPECT_EQ(original_bye.sender_ssrc(), logged_bye.bye.sender_ssrc());
1232   EXPECT_EQ(original_bye.csrcs(), logged_bye.bye.csrcs());
1233   EXPECT_EQ(original_bye.reason(), logged_bye.bye.reason());
1234 }
1235 
VerifyLoggedNack(int64_t log_time_ms,const rtcp::Nack & original_nack,const LoggedRtcpPacketNack & logged_nack)1236 void EventVerifier::VerifyLoggedNack(int64_t log_time_ms,
1237                                      const rtcp::Nack& original_nack,
1238                                      const LoggedRtcpPacketNack& logged_nack) {
1239   EXPECT_EQ(log_time_ms, logged_nack.log_time_ms());
1240   EXPECT_EQ(original_nack.packet_ids(), logged_nack.nack.packet_ids());
1241 }
1242 
VerifyLoggedTransportFeedback(int64_t log_time_ms,const rtcp::TransportFeedback & original_transport_feedback,const LoggedRtcpPacketTransportFeedback & logged_transport_feedback)1243 void EventVerifier::VerifyLoggedTransportFeedback(
1244     int64_t log_time_ms,
1245     const rtcp::TransportFeedback& original_transport_feedback,
1246     const LoggedRtcpPacketTransportFeedback& logged_transport_feedback) {
1247   EXPECT_EQ(log_time_ms, logged_transport_feedback.log_time_ms());
1248   ASSERT_EQ(
1249       original_transport_feedback.GetReceivedPackets().size(),
1250       logged_transport_feedback.transport_feedback.GetReceivedPackets().size());
1251   for (size_t i = 0;
1252        i < original_transport_feedback.GetReceivedPackets().size(); i++) {
1253     EXPECT_EQ(
1254         original_transport_feedback.GetReceivedPackets()[i].sequence_number(),
1255         logged_transport_feedback.transport_feedback.GetReceivedPackets()[i]
1256             .sequence_number());
1257     EXPECT_EQ(
1258         original_transport_feedback.GetReceivedPackets()[i].delta(),
1259         logged_transport_feedback.transport_feedback.GetReceivedPackets()[i]
1260             .delta());
1261   }
1262 }
1263 
VerifyLoggedRemb(int64_t log_time_ms,const rtcp::Remb & original_remb,const LoggedRtcpPacketRemb & logged_remb)1264 void EventVerifier::VerifyLoggedRemb(int64_t log_time_ms,
1265                                      const rtcp::Remb& original_remb,
1266                                      const LoggedRtcpPacketRemb& logged_remb) {
1267   EXPECT_EQ(log_time_ms, logged_remb.log_time_ms());
1268   EXPECT_EQ(original_remb.ssrcs(), logged_remb.remb.ssrcs());
1269   EXPECT_EQ(original_remb.bitrate_bps(), logged_remb.remb.bitrate_bps());
1270 }
1271 
VerifyLoggedLossNotification(int64_t log_time_ms,const rtcp::LossNotification & original_loss_notification,const LoggedRtcpPacketLossNotification & logged_loss_notification)1272 void EventVerifier::VerifyLoggedLossNotification(
1273     int64_t log_time_ms,
1274     const rtcp::LossNotification& original_loss_notification,
1275     const LoggedRtcpPacketLossNotification& logged_loss_notification) {
1276   EXPECT_EQ(log_time_ms, logged_loss_notification.log_time_ms());
1277   EXPECT_EQ(original_loss_notification.last_decoded(),
1278             logged_loss_notification.loss_notification.last_decoded());
1279   EXPECT_EQ(original_loss_notification.last_received(),
1280             logged_loss_notification.loss_notification.last_received());
1281   EXPECT_EQ(original_loss_notification.decodability_flag(),
1282             logged_loss_notification.loss_notification.decodability_flag());
1283 }
1284 
VerifyLoggedStartEvent(int64_t start_time_us,int64_t utc_start_time_us,const LoggedStartEvent & logged_event) const1285 void EventVerifier::VerifyLoggedStartEvent(
1286     int64_t start_time_us,
1287     int64_t utc_start_time_us,
1288     const LoggedStartEvent& logged_event) const {
1289   EXPECT_EQ(start_time_us / 1000, logged_event.log_time_ms());
1290   if (encoding_type_ == RtcEventLog::EncodingType::NewFormat) {
1291     EXPECT_EQ(utc_start_time_us / 1000, logged_event.utc_start_time.ms());
1292   }
1293 }
1294 
VerifyLoggedStopEvent(int64_t stop_time_us,const LoggedStopEvent & logged_event) const1295 void EventVerifier::VerifyLoggedStopEvent(
1296     int64_t stop_time_us,
1297     const LoggedStopEvent& logged_event) const {
1298   EXPECT_EQ(stop_time_us / 1000, logged_event.log_time_ms());
1299 }
1300 
VerifyLoggedStreamConfig(const rtclog::StreamConfig & original_config,const rtclog::StreamConfig & logged_config)1301 void VerifyLoggedStreamConfig(const rtclog::StreamConfig& original_config,
1302                               const rtclog::StreamConfig& logged_config) {
1303   EXPECT_EQ(original_config.local_ssrc, logged_config.local_ssrc);
1304   EXPECT_EQ(original_config.remote_ssrc, logged_config.remote_ssrc);
1305   EXPECT_EQ(original_config.rtx_ssrc, logged_config.rtx_ssrc);
1306 
1307   EXPECT_EQ(original_config.rtp_extensions.size(),
1308             logged_config.rtp_extensions.size());
1309   size_t recognized_extensions = 0;
1310   for (size_t i = 0; i < kMaxNumExtensions; i++) {
1311     auto original_id =
1312         GetExtensionId(original_config.rtp_extensions, kExtensions[i].name);
1313     auto logged_id =
1314         GetExtensionId(logged_config.rtp_extensions, kExtensions[i].name);
1315     EXPECT_EQ(original_id, logged_id)
1316         << "IDs for " << kExtensions[i].name << " don't match. Original ID "
1317         << original_id.value_or(-1) << ". Parsed ID " << logged_id.value_or(-1)
1318         << ".";
1319     if (original_id) {
1320       recognized_extensions++;
1321     }
1322   }
1323   EXPECT_EQ(recognized_extensions, original_config.rtp_extensions.size());
1324 }
1325 
VerifyLoggedAudioRecvConfig(const RtcEventAudioReceiveStreamConfig & original_event,const LoggedAudioRecvConfig & logged_event) const1326 void EventVerifier::VerifyLoggedAudioRecvConfig(
1327     const RtcEventAudioReceiveStreamConfig& original_event,
1328     const LoggedAudioRecvConfig& logged_event) const {
1329   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1330   VerifyLoggedStreamConfig(original_event.config(), logged_event.config);
1331 }
1332 
VerifyLoggedAudioSendConfig(const RtcEventAudioSendStreamConfig & original_event,const LoggedAudioSendConfig & logged_event) const1333 void EventVerifier::VerifyLoggedAudioSendConfig(
1334     const RtcEventAudioSendStreamConfig& original_event,
1335     const LoggedAudioSendConfig& logged_event) const {
1336   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1337   VerifyLoggedStreamConfig(original_event.config(), logged_event.config);
1338 }
1339 
VerifyLoggedVideoRecvConfig(const RtcEventVideoReceiveStreamConfig & original_event,const LoggedVideoRecvConfig & logged_event) const1340 void EventVerifier::VerifyLoggedVideoRecvConfig(
1341     const RtcEventVideoReceiveStreamConfig& original_event,
1342     const LoggedVideoRecvConfig& logged_event) const {
1343   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1344   VerifyLoggedStreamConfig(original_event.config(), logged_event.config);
1345 }
1346 
VerifyLoggedVideoSendConfig(const RtcEventVideoSendStreamConfig & original_event,const LoggedVideoSendConfig & logged_event) const1347 void EventVerifier::VerifyLoggedVideoSendConfig(
1348     const RtcEventVideoSendStreamConfig& original_event,
1349     const LoggedVideoSendConfig& logged_event) const {
1350   EXPECT_EQ(original_event.timestamp_ms(), logged_event.log_time_ms());
1351   VerifyLoggedStreamConfig(original_event.config(), logged_event.config);
1352 }
1353 
1354 }  // namespace test
1355 }  // namespace webrtc
1356