1 /*
2 * Copyright 2019 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 #ifndef LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_PARSER_H_
11 #define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_PARSER_H_
12
13 #include <iterator>
14 #include <limits>
15 #include <map>
16 #include <set>
17 #include <string>
18 #include <vector>
19
20 #include "absl/base/attributes.h"
21 #include "absl/strings/string_view.h"
22 #include "api/rtc_event_log/rtc_event_log.h"
23 #include "call/video_receive_stream.h"
24 #include "call/video_send_stream.h"
25 #include "logging/rtc_event_log/events/logged_rtp_rtcp.h"
26 #include "logging/rtc_event_log/events/rtc_event_alr_state.h"
27 #include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
28 #include "logging/rtc_event_log/events/rtc_event_audio_playout.h"
29 #include "logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h"
30 #include "logging/rtc_event_log/events/rtc_event_audio_send_stream_config.h"
31 #include "logging/rtc_event_log/events/rtc_event_begin_log.h"
32 #include "logging/rtc_event_log/events/rtc_event_bwe_update_delay_based.h"
33 #include "logging/rtc_event_log/events/rtc_event_bwe_update_loss_based.h"
34 #include "logging/rtc_event_log/events/rtc_event_dtls_transport_state.h"
35 #include "logging/rtc_event_log/events/rtc_event_dtls_writable_state.h"
36 #include "logging/rtc_event_log/events/rtc_event_end_log.h"
37 #include "logging/rtc_event_log/events/rtc_event_frame_decoded.h"
38 #include "logging/rtc_event_log/events/rtc_event_generic_ack_received.h"
39 #include "logging/rtc_event_log/events/rtc_event_generic_packet_received.h"
40 #include "logging/rtc_event_log/events/rtc_event_generic_packet_sent.h"
41 #include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair.h"
42 #include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h"
43 #include "logging/rtc_event_log/events/rtc_event_probe_cluster_created.h"
44 #include "logging/rtc_event_log/events/rtc_event_probe_result_failure.h"
45 #include "logging/rtc_event_log/events/rtc_event_probe_result_success.h"
46 #include "logging/rtc_event_log/events/rtc_event_remote_estimate.h"
47 #include "logging/rtc_event_log/events/rtc_event_route_change.h"
48 #include "logging/rtc_event_log/events/rtc_event_rtcp_packet_incoming.h"
49 #include "logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h"
50 #include "logging/rtc_event_log/events/rtc_event_rtp_packet_incoming.h"
51 #include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h"
52 #include "logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h"
53 #include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h"
54 #include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
55 #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
56 #include "rtc_base/ignore_wundef.h"
57
58 // Files generated at build-time by the protobuf compiler.
59 RTC_PUSH_IGNORING_WUNDEF()
60 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
61 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h"
62 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log2.pb.h"
63 #else
64 #include "logging/rtc_event_log/rtc_event_log.pb.h"
65 #include "logging/rtc_event_log/rtc_event_log2.pb.h"
66 #endif
RTC_POP_IGNORING_WUNDEF()67 RTC_POP_IGNORING_WUNDEF()
68
69 namespace webrtc {
70
71 enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
72
73 enum class LoggedMediaType : uint8_t { kUnknown, kAudio, kVideo };
74
75 struct LoggedPacketInfo {
76 LoggedPacketInfo(const LoggedRtpPacket& rtp,
77 LoggedMediaType media_type,
78 bool rtx,
79 Timestamp capture_time);
80 LoggedPacketInfo(const LoggedPacketInfo&);
81 ~LoggedPacketInfo();
82 int64_t log_time_ms() const { return log_packet_time.ms(); }
83 int64_t log_time_us() const { return log_packet_time.us(); }
84 uint32_t ssrc;
85 uint16_t stream_seq_no;
86 uint16_t size;
87 uint16_t payload_size;
88 uint16_t padding_size;
89 uint16_t overhead = 0;
90 uint8_t payload_type;
91 LoggedMediaType media_type = LoggedMediaType::kUnknown;
92 bool rtx = false;
93 bool marker_bit = false;
94 bool has_transport_seq_no = false;
95 bool last_in_feedback = false;
96 uint16_t transport_seq_no = 0;
97 // The RTP header timestamp unwrapped and converted from tick count to seconds
98 // based timestamp.
99 Timestamp capture_time;
100 // The time the packet was logged. This is the receive time for incoming
101 // packets and send time for outgoing.
102 Timestamp log_packet_time;
103 // Send time as reported by abs-send-time extension, For outgoing packets this
104 // corresponds to log_packet_time, but might be measured using another clock.
105 Timestamp reported_send_time;
106 // The receive time that was reported in feedback. For incoming packets this
107 // corresponds to log_packet_time, but might be measured using another clock.
108 // PlusInfinity indicates that the packet was lost.
109 Timestamp reported_recv_time = Timestamp::MinusInfinity();
110 // The time feedback message was logged. This is the feedback send time for
111 // incoming packets and feedback receive time for outgoing.
112 // PlusInfinity indicates that feedback was expected but not received.
113 Timestamp log_feedback_time = Timestamp::MinusInfinity();
114 // The delay betweeen receiving an RTP packet and sending feedback for
115 // incoming packets. For outgoing packets we don't know the feedback send
116 // time, and this is instead calculated as the difference in reported receive
117 // time between this packet and the last packet in the same feedback message.
118 TimeDelta feedback_hold_duration = TimeDelta::MinusInfinity();
119 };
120
121 struct InferredRouteChangeEvent {
122 int64_t log_time_ms() const { return log_time.ms(); }
123 int64_t log_time_us() const { return log_time.us(); }
124 uint32_t route_id;
125 Timestamp log_time = Timestamp::MinusInfinity();
126 uint16_t send_overhead;
127 uint16_t return_overhead;
128 };
129
130 enum class LoggedIceEventType {
131 kAdded,
132 kUpdated,
133 kDestroyed,
134 kSelected,
135 kCheckSent,
136 kCheckReceived,
137 kCheckResponseSent,
138 kCheckResponseReceived,
139 };
140
141 struct LoggedIceEvent {
142 uint32_t candidate_pair_id;
143 Timestamp log_time;
144 LoggedIceEventType event_type;
145 };
146
147 // This class is used to process lists of LoggedRtpPacketIncoming
148 // and LoggedRtpPacketOutgoing without duplicating the code.
149 // TODO(terelius): Remove this class. Instead use e.g. a vector of pointers
150 // to LoggedRtpPacket or templatize the surrounding code.
151 template <typename T>
152 class DereferencingVector {
153 public:
154 template <bool IsConst>
155 class DereferencingIterator {
156 public:
157 // Standard iterator traits.
158 using difference_type = std::ptrdiff_t;
159 using value_type = T;
160 using pointer = typename std::conditional_t<IsConst, const T*, T*>;
161 using reference = typename std::conditional_t<IsConst, const T&, T&>;
162 using iterator_category = std::bidirectional_iterator_tag;
163
164 using representation =
165 typename std::conditional_t<IsConst, const T* const*, T**>;
166
167 explicit DereferencingIterator(representation ptr) : ptr_(ptr) {}
168
169 DereferencingIterator(const DereferencingIterator& other)
170 : ptr_(other.ptr_) {}
171 DereferencingIterator(const DereferencingIterator&& other)
172 : ptr_(other.ptr_) {}
173 ~DereferencingIterator() = default;
174
175 DereferencingIterator& operator=(const DereferencingIterator& other) {
176 ptr_ = other.ptr_;
177 return *this;
178 }
179 DereferencingIterator& operator=(const DereferencingIterator&& other) {
180 ptr_ = other.ptr_;
181 return *this;
182 }
183
184 bool operator==(const DereferencingIterator& other) const {
185 return ptr_ == other.ptr_;
186 }
187 bool operator!=(const DereferencingIterator& other) const {
188 return ptr_ != other.ptr_;
189 }
190
191 DereferencingIterator& operator++() {
192 ++ptr_;
193 return *this;
194 }
195 DereferencingIterator& operator--() {
196 --ptr_;
197 return *this;
198 }
199 DereferencingIterator operator++(int) {
200 DereferencingIterator iter_copy(ptr_);
201 ++ptr_;
202 return iter_copy;
203 }
204 DereferencingIterator operator--(int) {
205 DereferencingIterator iter_copy(ptr_);
206 --ptr_;
207 return iter_copy;
208 }
209
210 template <bool _IsConst = IsConst>
211 std::enable_if_t<!_IsConst, reference> operator*() {
212 return **ptr_;
213 }
214
215 template <bool _IsConst = IsConst>
216 std::enable_if_t<_IsConst, reference> operator*() const {
217 return **ptr_;
218 }
219
220 template <bool _IsConst = IsConst>
221 std::enable_if_t<!_IsConst, pointer> operator->() {
222 return *ptr_;
223 }
224
225 template <bool _IsConst = IsConst>
226 std::enable_if_t<_IsConst, pointer> operator->() const {
227 return *ptr_;
228 }
229
230 private:
231 representation ptr_;
232 };
233
234 using value_type = T;
235 using reference = value_type&;
236 using const_reference = const value_type&;
237
238 using iterator = DereferencingIterator<false>;
239 using const_iterator = DereferencingIterator<true>;
240 using reverse_iterator = std::reverse_iterator<iterator>;
241 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
242
243 iterator begin() { return iterator(elems_.data()); }
244 iterator end() { return iterator(elems_.data() + elems_.size()); }
245
246 const_iterator begin() const { return const_iterator(elems_.data()); }
247 const_iterator end() const {
248 return const_iterator(elems_.data() + elems_.size());
249 }
250
251 reverse_iterator rbegin() { return reverse_iterator(end()); }
252 reverse_iterator rend() { return reverse_iterator(begin()); }
253
254 const_reverse_iterator rbegin() const {
255 return const_reverse_iterator(end());
256 }
257 const_reverse_iterator rend() const {
258 return const_reverse_iterator(begin());
259 }
260
261 size_t size() const { return elems_.size(); }
262
263 bool empty() const { return elems_.empty(); }
264
265 T& operator[](size_t i) {
266 RTC_DCHECK_LT(i, elems_.size());
267 return *elems_[i];
268 }
269
270 const T& operator[](size_t i) const {
271 RTC_DCHECK_LT(i, elems_.size());
272 return *elems_[i];
273 }
274
275 void push_back(T* elem) {
276 RTC_DCHECK(elem != nullptr);
277 elems_.push_back(elem);
278 }
279
280 private:
281 std::vector<T*> elems_;
282 };
283
284 // Conversion functions for version 2 of the wire format.
285 BandwidthUsage GetRuntimeDetectorState(
286 rtclog2::DelayBasedBweUpdates::DetectorState detector_state);
287
288 ProbeFailureReason GetRuntimeProbeFailureReason(
289 rtclog2::BweProbeResultFailure::FailureReason failure);
290
291 DtlsTransportState GetRuntimeDtlsTransportState(
292 rtclog2::DtlsTransportStateEvent::DtlsTransportState state);
293
294 IceCandidatePairConfigType GetRuntimeIceCandidatePairConfigType(
295 rtclog2::IceCandidatePairConfig::IceCandidatePairConfigType type);
296
297 IceCandidateType GetRuntimeIceCandidateType(
298 rtclog2::IceCandidatePairConfig::IceCandidateType type);
299
300 IceCandidatePairProtocol GetRuntimeIceCandidatePairProtocol(
301 rtclog2::IceCandidatePairConfig::Protocol protocol);
302
303 IceCandidatePairAddressFamily GetRuntimeIceCandidatePairAddressFamily(
304 rtclog2::IceCandidatePairConfig::AddressFamily address_family);
305
306 IceCandidateNetworkType GetRuntimeIceCandidateNetworkType(
307 rtclog2::IceCandidatePairConfig::NetworkType network_type);
308
309 IceCandidatePairEventType GetRuntimeIceCandidatePairEventType(
310 rtclog2::IceCandidatePairEvent::IceCandidatePairEventType type);
311
312 std::vector<RtpExtension> GetRuntimeRtpHeaderExtensionConfig(
313 const rtclog2::RtpHeaderExtensionConfig& proto_header_extensions);
314 // End of conversion functions.
315
316 class ParsedRtcEventLog {
317 public:
318 enum class MediaType { ANY, AUDIO, VIDEO, DATA };
319 enum class UnconfiguredHeaderExtensions {
320 kDontParse,
321 kAttemptWebrtcDefaultConfig
322 };
323
324 using ParseStatus = RtcEventLogParseStatus;
325
326 template <typename T>
327 using ParseStatusOr = RtcEventLogParseStatusOr<T>;
328
329 struct LoggedRtpStreamIncoming {
330 LoggedRtpStreamIncoming();
331 LoggedRtpStreamIncoming(const LoggedRtpStreamIncoming&);
332 ~LoggedRtpStreamIncoming();
333 uint32_t ssrc;
334 std::vector<LoggedRtpPacketIncoming> incoming_packets;
335 };
336
337 struct LoggedRtpStreamOutgoing {
338 LoggedRtpStreamOutgoing();
339 LoggedRtpStreamOutgoing(const LoggedRtpStreamOutgoing&);
340 ~LoggedRtpStreamOutgoing();
341 uint32_t ssrc;
342 std::vector<LoggedRtpPacketOutgoing> outgoing_packets;
343 };
344
345 struct LoggedRtpStreamView {
346 LoggedRtpStreamView(uint32_t ssrc,
347 const std::vector<LoggedRtpPacketIncoming>& packets);
348 LoggedRtpStreamView(uint32_t ssrc,
349 const std::vector<LoggedRtpPacketOutgoing>& packets);
350 LoggedRtpStreamView(const LoggedRtpStreamView&);
351 uint32_t ssrc;
352 DereferencingVector<const LoggedRtpPacket> packet_view;
353 };
354
355 class LogSegment {
356 public:
357 LogSegment(int64_t start_time_us, int64_t stop_time_us)
358 : start_time_us_(start_time_us), stop_time_us_(stop_time_us) {}
359 int64_t start_time_ms() const { return start_time_us_ / 1000; }
360 int64_t start_time_us() const { return start_time_us_; }
361 int64_t stop_time_ms() const { return stop_time_us_ / 1000; }
362 int64_t stop_time_us() const { return stop_time_us_; }
363
364 private:
365 int64_t start_time_us_;
366 int64_t stop_time_us_;
367 };
368
369 static webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap();
370
371 explicit ParsedRtcEventLog(
372 UnconfiguredHeaderExtensions parse_unconfigured_header_extensions =
373 UnconfiguredHeaderExtensions::kDontParse,
374 bool allow_incomplete_log = false);
375
376 ~ParsedRtcEventLog();
377
378 // Clears previously parsed events and resets the ParsedRtcEventLogNew to an
379 // empty state.
380 void Clear();
381
382 // Reads an RtcEventLog file and returns success if parsing was successful.
383 ParseStatus ParseFile(absl::string_view file_name);
384
385 // Reads an RtcEventLog from a string and returns success if successful.
386 ParseStatus ParseString(absl::string_view s);
387
388 // Reads an RtcEventLog from an string and returns success if successful.
389 ParseStatus ParseStream(absl::string_view s);
390
391 MediaType GetMediaType(uint32_t ssrc, PacketDirection direction) const;
392
393 // Configured SSRCs.
394 const std::set<uint32_t>& incoming_rtx_ssrcs() const {
395 return incoming_rtx_ssrcs_;
396 }
397
398 const std::set<uint32_t>& incoming_video_ssrcs() const {
399 return incoming_video_ssrcs_;
400 }
401
402 const std::set<uint32_t>& incoming_audio_ssrcs() const {
403 return incoming_audio_ssrcs_;
404 }
405
406 const std::set<uint32_t>& outgoing_rtx_ssrcs() const {
407 return outgoing_rtx_ssrcs_;
408 }
409
410 const std::set<uint32_t>& outgoing_video_ssrcs() const {
411 return outgoing_video_ssrcs_;
412 }
413
414 const std::set<uint32_t>& outgoing_audio_ssrcs() const {
415 return outgoing_audio_ssrcs_;
416 }
417
418 // Stream configurations.
419 const std::vector<LoggedAudioRecvConfig>& audio_recv_configs() const {
420 return audio_recv_configs_;
421 }
422
423 const std::vector<LoggedAudioSendConfig>& audio_send_configs() const {
424 return audio_send_configs_;
425 }
426
427 const std::vector<LoggedVideoRecvConfig>& video_recv_configs() const {
428 return video_recv_configs_;
429 }
430
431 const std::vector<LoggedVideoSendConfig>& video_send_configs() const {
432 return video_send_configs_;
433 }
434
435 // Beginning and end of log segments.
436 const std::vector<LoggedStartEvent>& start_log_events() const {
437 return start_log_events_;
438 }
439
440 const std::vector<LoggedStopEvent>& stop_log_events() const {
441 return stop_log_events_;
442 }
443
444 const std::vector<LoggedAlrStateEvent>& alr_state_events() const {
445 return alr_state_events_;
446 }
447
448 // Audio
449 const std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>&
450 audio_playout_events() const {
451 return audio_playout_events_;
452 }
453
454 const std::vector<LoggedAudioNetworkAdaptationEvent>&
455 audio_network_adaptation_events() const {
456 return audio_network_adaptation_events_;
457 }
458
459 // Bandwidth estimation
460 const std::vector<LoggedBweProbeClusterCreatedEvent>&
461 bwe_probe_cluster_created_events() const {
462 return bwe_probe_cluster_created_events_;
463 }
464
465 const std::vector<LoggedBweProbeFailureEvent>& bwe_probe_failure_events()
466 const {
467 return bwe_probe_failure_events_;
468 }
469
470 const std::vector<LoggedBweProbeSuccessEvent>& bwe_probe_success_events()
471 const {
472 return bwe_probe_success_events_;
473 }
474
475 const std::vector<LoggedBweDelayBasedUpdate>& bwe_delay_updates() const {
476 return bwe_delay_updates_;
477 }
478
479 const std::vector<LoggedBweLossBasedUpdate>& bwe_loss_updates() const {
480 return bwe_loss_updates_;
481 }
482
483 // DTLS
484 const std::vector<LoggedDtlsTransportState>& dtls_transport_states() const {
485 return dtls_transport_states_;
486 }
487
488 const std::vector<LoggedDtlsWritableState>& dtls_writable_states() const {
489 return dtls_writable_states_;
490 }
491
492 // ICE events
493 const std::vector<LoggedIceCandidatePairConfig>& ice_candidate_pair_configs()
494 const {
495 return ice_candidate_pair_configs_;
496 }
497
498 const std::vector<LoggedIceCandidatePairEvent>& ice_candidate_pair_events()
499 const {
500 return ice_candidate_pair_events_;
501 }
502
503 const std::vector<LoggedRouteChangeEvent>& route_change_events() const {
504 return route_change_events_;
505 }
506
507 const std::vector<LoggedRemoteEstimateEvent>& remote_estimate_events() const {
508 return remote_estimate_events_;
509 }
510
511 // RTP
512 const std::vector<LoggedRtpStreamIncoming>& incoming_rtp_packets_by_ssrc()
513 const {
514 return incoming_rtp_packets_by_ssrc_;
515 }
516
517 const std::vector<LoggedRtpStreamOutgoing>& outgoing_rtp_packets_by_ssrc()
518 const {
519 return outgoing_rtp_packets_by_ssrc_;
520 }
521
522 const std::vector<LoggedRtpStreamView>& rtp_packets_by_ssrc(
523 PacketDirection direction) const {
524 if (direction == kIncomingPacket)
525 return incoming_rtp_packet_views_by_ssrc_;
526 else
527 return outgoing_rtp_packet_views_by_ssrc_;
528 }
529
530 // RTCP
531 const std::vector<LoggedRtcpPacketIncoming>& incoming_rtcp_packets() const {
532 return incoming_rtcp_packets_;
533 }
534
535 const std::vector<LoggedRtcpPacketOutgoing>& outgoing_rtcp_packets() const {
536 return outgoing_rtcp_packets_;
537 }
538
539 const std::vector<LoggedRtcpPacketReceiverReport>& receiver_reports(
540 PacketDirection direction) const {
541 if (direction == kIncomingPacket) {
542 return incoming_rr_;
543 } else {
544 return outgoing_rr_;
545 }
546 }
547
548 const std::vector<LoggedRtcpPacketSenderReport>& sender_reports(
549 PacketDirection direction) const {
550 if (direction == kIncomingPacket) {
551 return incoming_sr_;
552 } else {
553 return outgoing_sr_;
554 }
555 }
556
557 const std::vector<LoggedRtcpPacketExtendedReports>& extended_reports(
558 PacketDirection direction) const {
559 if (direction == kIncomingPacket) {
560 return incoming_xr_;
561 } else {
562 return outgoing_xr_;
563 }
564 }
565
566 const std::vector<LoggedRtcpPacketNack>& nacks(
567 PacketDirection direction) const {
568 if (direction == kIncomingPacket) {
569 return incoming_nack_;
570 } else {
571 return outgoing_nack_;
572 }
573 }
574
575 const std::vector<LoggedRtcpPacketRemb>& rembs(
576 PacketDirection direction) const {
577 if (direction == kIncomingPacket) {
578 return incoming_remb_;
579 } else {
580 return outgoing_remb_;
581 }
582 }
583
584 const std::vector<LoggedRtcpPacketFir>& firs(
585 PacketDirection direction) const {
586 if (direction == kIncomingPacket) {
587 return incoming_fir_;
588 } else {
589 return outgoing_fir_;
590 }
591 }
592
593 const std::vector<LoggedRtcpPacketPli>& plis(
594 PacketDirection direction) const {
595 if (direction == kIncomingPacket) {
596 return incoming_pli_;
597 } else {
598 return outgoing_pli_;
599 }
600 }
601
602 const std::vector<LoggedRtcpPacketBye>& byes(
603 PacketDirection direction) const {
604 if (direction == kIncomingPacket) {
605 return incoming_bye_;
606 } else {
607 return outgoing_bye_;
608 }
609 }
610
611 const std::vector<LoggedRtcpPacketTransportFeedback>& transport_feedbacks(
612 PacketDirection direction) const {
613 if (direction == kIncomingPacket) {
614 return incoming_transport_feedback_;
615 } else {
616 return outgoing_transport_feedback_;
617 }
618 }
619
620 const std::vector<LoggedRtcpPacketLossNotification>& loss_notifications(
621 PacketDirection direction) {
622 if (direction == kIncomingPacket) {
623 return incoming_loss_notification_;
624 } else {
625 return outgoing_loss_notification_;
626 }
627 }
628
629 const std::vector<LoggedGenericPacketReceived>& generic_packets_received()
630 const {
631 return generic_packets_received_;
632 }
633 const std::vector<LoggedGenericPacketSent>& generic_packets_sent() const {
634 return generic_packets_sent_;
635 }
636
637 const std::vector<LoggedGenericAckReceived>& generic_acks_received() const {
638 return generic_acks_received_;
639 }
640
641 // Media
642 const std::map<uint32_t, std::vector<LoggedFrameDecoded>>& decoded_frames()
643 const {
644 return decoded_frames_;
645 }
646
647 Timestamp first_timestamp() const { return first_timestamp_; }
648 Timestamp last_timestamp() const { return last_timestamp_; }
649
650 const LogSegment& first_log_segment() const { return first_log_segment_; }
651
652 std::vector<LoggedPacketInfo> GetPacketInfos(PacketDirection direction) const;
653 std::vector<LoggedPacketInfo> GetIncomingPacketInfos() const {
654 return GetPacketInfos(kIncomingPacket);
655 }
656 std::vector<LoggedPacketInfo> GetOutgoingPacketInfos() const {
657 return GetPacketInfos(kOutgoingPacket);
658 }
659 std::vector<LoggedIceCandidatePairConfig> GetIceCandidates() const;
660 std::vector<LoggedIceEvent> GetIceEvents() const;
661
662 std::vector<InferredRouteChangeEvent> GetRouteChanges() const;
663
664 private:
665 ABSL_MUST_USE_RESULT ParseStatus ParseStreamInternal(absl::string_view s);
666 ABSL_MUST_USE_RESULT ParseStatus ParseStreamInternalV3(absl::string_view s);
667
668 ABSL_MUST_USE_RESULT ParseStatus
669 StoreParsedLegacyEvent(const rtclog::Event& event);
670
671 template <typename T>
672 void StoreFirstAndLastTimestamp(const std::vector<T>& v);
673
674 // Returns: a pointer to a header extensions map acquired from parsing
675 // corresponding Audio/Video Sender/Receiver config events.
676 // Warning: if the same SSRC is reused by both video and audio streams during
677 // call, extensions maps may be incorrect (the last one would be returned).
678 const RtpHeaderExtensionMap* GetRtpHeaderExtensionMap(bool incoming,
679 uint32_t ssrc);
680
681 // Reads packet, direction and packet length from the RTCP event at `index`,
682 // and stores the values in the corresponding output parameters.
683 // Each output parameter can be set to nullptr if that value isn't needed.
684 // NB: The packet must have space for at least IP_PACKET_SIZE bytes.
685 ParseStatus GetRtcpPacket(const rtclog::Event& event,
686 PacketDirection* incoming,
687 std::vector<uint8_t>* packet) const;
688
689 ParseStatusOr<rtclog::StreamConfig> GetVideoReceiveConfig(
690 const rtclog::Event& event) const;
691 ParseStatusOr<rtclog::StreamConfig> GetVideoSendConfig(
692 const rtclog::Event& event) const;
693 ParseStatusOr<rtclog::StreamConfig> GetAudioReceiveConfig(
694 const rtclog::Event& event) const;
695 ParseStatusOr<rtclog::StreamConfig> GetAudioSendConfig(
696 const rtclog::Event& event) const;
697
698 ParsedRtcEventLog::ParseStatusOr<LoggedAudioPlayoutEvent> GetAudioPlayout(
699 const rtclog::Event& event) const;
700
701 ParsedRtcEventLog::ParseStatusOr<LoggedBweLossBasedUpdate>
702 GetLossBasedBweUpdate(const rtclog::Event& event) const;
703
704 ParsedRtcEventLog::ParseStatusOr<LoggedBweDelayBasedUpdate>
705 GetDelayBasedBweUpdate(const rtclog::Event& event) const;
706
707 ParsedRtcEventLog::ParseStatusOr<LoggedAudioNetworkAdaptationEvent>
708 GetAudioNetworkAdaptation(const rtclog::Event& event) const;
709
710 ParsedRtcEventLog::ParseStatusOr<LoggedBweProbeClusterCreatedEvent>
711 GetBweProbeClusterCreated(const rtclog::Event& event) const;
712
713 ParsedRtcEventLog::ParseStatusOr<LoggedBweProbeFailureEvent>
714 GetBweProbeFailure(const rtclog::Event& event) const;
715
716 ParsedRtcEventLog::ParseStatusOr<LoggedBweProbeSuccessEvent>
717 GetBweProbeSuccess(const rtclog::Event& event) const;
718
719 ParsedRtcEventLog::ParseStatusOr<LoggedAlrStateEvent> GetAlrState(
720 const rtclog::Event& event) const;
721
722 ParsedRtcEventLog::ParseStatusOr<LoggedIceCandidatePairConfig>
723 GetIceCandidatePairConfig(const rtclog::Event& event) const;
724
725 ParsedRtcEventLog::ParseStatusOr<LoggedIceCandidatePairEvent>
726 GetIceCandidatePairEvent(const rtclog::Event& event) const;
727
728 ParsedRtcEventLog::ParseStatusOr<LoggedRemoteEstimateEvent>
729 GetRemoteEstimateEvent(const rtclog::Event& event) const;
730
731 // Parsing functions for new format.
732 ParseStatus StoreAlrStateEvent(const rtclog2::AlrState& proto);
733 ParseStatus StoreAudioNetworkAdaptationEvent(
734 const rtclog2::AudioNetworkAdaptations& proto);
735 ParseStatus StoreAudioPlayoutEvent(const rtclog2::AudioPlayoutEvents& proto);
736 ParseStatus StoreAudioRecvConfig(const rtclog2::AudioRecvStreamConfig& proto);
737 ParseStatus StoreAudioSendConfig(const rtclog2::AudioSendStreamConfig& proto);
738 ParseStatus StoreBweDelayBasedUpdate(
739 const rtclog2::DelayBasedBweUpdates& proto);
740 ParseStatus StoreBweLossBasedUpdate(
741 const rtclog2::LossBasedBweUpdates& proto);
742 ParseStatus StoreBweProbeClusterCreated(
743 const rtclog2::BweProbeCluster& proto);
744 ParseStatus StoreBweProbeFailureEvent(
745 const rtclog2::BweProbeResultFailure& proto);
746 ParseStatus StoreBweProbeSuccessEvent(
747 const rtclog2::BweProbeResultSuccess& proto);
748 ParseStatus StoreDtlsTransportState(
749 const rtclog2::DtlsTransportStateEvent& proto);
750 ParseStatus StoreDtlsWritableState(const rtclog2::DtlsWritableState& proto);
751 ParsedRtcEventLog::ParseStatus StoreFrameDecodedEvents(
752 const rtclog2::FrameDecodedEvents& proto);
753 ParseStatus StoreGenericAckReceivedEvent(
754 const rtclog2::GenericAckReceived& proto);
755 ParseStatus StoreGenericPacketReceivedEvent(
756 const rtclog2::GenericPacketReceived& proto);
757 ParseStatus StoreGenericPacketSentEvent(
758 const rtclog2::GenericPacketSent& proto);
759 ParseStatus StoreIceCandidateEvent(
760 const rtclog2::IceCandidatePairEvent& proto);
761 ParseStatus StoreIceCandidatePairConfig(
762 const rtclog2::IceCandidatePairConfig& proto);
763 ParseStatus StoreIncomingRtcpPackets(
764 const rtclog2::IncomingRtcpPackets& proto);
765 ParseStatus StoreIncomingRtpPackets(const rtclog2::IncomingRtpPackets& proto);
766 ParseStatus StoreOutgoingRtcpPackets(
767 const rtclog2::OutgoingRtcpPackets& proto);
768 ParseStatus StoreOutgoingRtpPackets(const rtclog2::OutgoingRtpPackets& proto);
769 ParseStatus StoreParsedNewFormatEvent(const rtclog2::EventStream& event);
770 ParseStatus StoreRouteChangeEvent(const rtclog2::RouteChange& proto);
771 ParseStatus StoreRemoteEstimateEvent(const rtclog2::RemoteEstimates& proto);
772 ParseStatus StoreStartEvent(const rtclog2::BeginLogEvent& proto);
773 ParseStatus StoreStopEvent(const rtclog2::EndLogEvent& proto);
774 ParseStatus StoreVideoRecvConfig(const rtclog2::VideoRecvStreamConfig& proto);
775 ParseStatus StoreVideoSendConfig(const rtclog2::VideoSendStreamConfig& proto);
776 // End of new parsing functions.
777
778 struct Stream {
779 Stream(uint32_t ssrc,
780 MediaType media_type,
781 PacketDirection direction,
782 webrtc::RtpHeaderExtensionMap map)
783 : ssrc(ssrc),
784 media_type(media_type),
785 direction(direction),
786 rtp_extensions_map(map) {}
787 uint32_t ssrc;
788 MediaType media_type;
789 PacketDirection direction;
790 webrtc::RtpHeaderExtensionMap rtp_extensions_map;
791 };
792
793 const UnconfiguredHeaderExtensions parse_unconfigured_header_extensions_;
794 const bool allow_incomplete_logs_;
795
796 // Make a default extension map for streams without configuration information.
797 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
798 // this can be removed. Tracking bug: webrtc:6399
799 RtpHeaderExtensionMap default_extension_map_;
800
801 // Tracks what each stream is configured for. Note that a single SSRC can be
802 // in several sets. For example, the SSRC used for sending video over RTX
803 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
804 // an SSRC is reconfigured to a different media type mid-call, it will also
805 // appear in multiple sets.
806 std::set<uint32_t> incoming_rtx_ssrcs_;
807 std::set<uint32_t> incoming_video_ssrcs_;
808 std::set<uint32_t> incoming_audio_ssrcs_;
809 std::set<uint32_t> outgoing_rtx_ssrcs_;
810 std::set<uint32_t> outgoing_video_ssrcs_;
811 std::set<uint32_t> outgoing_audio_ssrcs_;
812
813 // Maps an SSRC to the parsed RTP headers in that stream. Header extensions
814 // are parsed if the stream has been configured. This is only used for
815 // grouping the events by SSRC during parsing; the events are moved to
816 // incoming_rtp_packets_by_ssrc_ once the parsing is done.
817 std::map<uint32_t, std::vector<LoggedRtpPacketIncoming>>
818 incoming_rtp_packets_map_;
819 std::map<uint32_t, std::vector<LoggedRtpPacketOutgoing>>
820 outgoing_rtp_packets_map_;
821
822 // RTP headers.
823 std::vector<LoggedRtpStreamIncoming> incoming_rtp_packets_by_ssrc_;
824 std::vector<LoggedRtpStreamOutgoing> outgoing_rtp_packets_by_ssrc_;
825 std::vector<LoggedRtpStreamView> incoming_rtp_packet_views_by_ssrc_;
826 std::vector<LoggedRtpStreamView> outgoing_rtp_packet_views_by_ssrc_;
827
828 // Raw RTCP packets.
829 std::vector<LoggedRtcpPacketIncoming> incoming_rtcp_packets_;
830 std::vector<LoggedRtcpPacketOutgoing> outgoing_rtcp_packets_;
831
832 // Parsed RTCP messages. Currently not separated based on SSRC.
833 std::vector<LoggedRtcpPacketReceiverReport> incoming_rr_;
834 std::vector<LoggedRtcpPacketReceiverReport> outgoing_rr_;
835 std::vector<LoggedRtcpPacketSenderReport> incoming_sr_;
836 std::vector<LoggedRtcpPacketSenderReport> outgoing_sr_;
837 std::vector<LoggedRtcpPacketExtendedReports> incoming_xr_;
838 std::vector<LoggedRtcpPacketExtendedReports> outgoing_xr_;
839 std::vector<LoggedRtcpPacketNack> incoming_nack_;
840 std::vector<LoggedRtcpPacketNack> outgoing_nack_;
841 std::vector<LoggedRtcpPacketRemb> incoming_remb_;
842 std::vector<LoggedRtcpPacketRemb> outgoing_remb_;
843 std::vector<LoggedRtcpPacketFir> incoming_fir_;
844 std::vector<LoggedRtcpPacketFir> outgoing_fir_;
845 std::vector<LoggedRtcpPacketPli> incoming_pli_;
846 std::vector<LoggedRtcpPacketPli> outgoing_pli_;
847 std::vector<LoggedRtcpPacketBye> incoming_bye_;
848 std::vector<LoggedRtcpPacketBye> outgoing_bye_;
849 std::vector<LoggedRtcpPacketTransportFeedback> incoming_transport_feedback_;
850 std::vector<LoggedRtcpPacketTransportFeedback> outgoing_transport_feedback_;
851 std::vector<LoggedRtcpPacketLossNotification> incoming_loss_notification_;
852 std::vector<LoggedRtcpPacketLossNotification> outgoing_loss_notification_;
853
854 std::vector<LoggedStartEvent> start_log_events_;
855 std::vector<LoggedStopEvent> stop_log_events_;
856
857 std::vector<LoggedAlrStateEvent> alr_state_events_;
858
859 std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>
860 audio_playout_events_;
861
862 std::vector<LoggedAudioNetworkAdaptationEvent>
863 audio_network_adaptation_events_;
864
865 std::vector<LoggedBweProbeClusterCreatedEvent>
866 bwe_probe_cluster_created_events_;
867
868 std::vector<LoggedBweProbeFailureEvent> bwe_probe_failure_events_;
869 std::vector<LoggedBweProbeSuccessEvent> bwe_probe_success_events_;
870
871 std::vector<LoggedBweDelayBasedUpdate> bwe_delay_updates_;
872 std::vector<LoggedBweLossBasedUpdate> bwe_loss_updates_;
873
874 std::vector<LoggedDtlsTransportState> dtls_transport_states_;
875 std::vector<LoggedDtlsWritableState> dtls_writable_states_;
876
877 std::map<uint32_t, std::vector<LoggedFrameDecoded>> decoded_frames_;
878
879 std::vector<LoggedIceCandidatePairConfig> ice_candidate_pair_configs_;
880 std::vector<LoggedIceCandidatePairEvent> ice_candidate_pair_events_;
881
882 std::vector<LoggedAudioRecvConfig> audio_recv_configs_;
883 std::vector<LoggedAudioSendConfig> audio_send_configs_;
884 std::vector<LoggedVideoRecvConfig> video_recv_configs_;
885 std::vector<LoggedVideoSendConfig> video_send_configs_;
886
887 std::vector<LoggedGenericPacketReceived> generic_packets_received_;
888 std::vector<LoggedGenericPacketSent> generic_packets_sent_;
889 std::vector<LoggedGenericAckReceived> generic_acks_received_;
890
891 std::vector<LoggedRouteChangeEvent> route_change_events_;
892 std::vector<LoggedRemoteEstimateEvent> remote_estimate_events_;
893
894 std::vector<uint8_t> last_incoming_rtcp_packet_;
895
896 Timestamp first_timestamp_ = Timestamp::PlusInfinity();
897 Timestamp last_timestamp_ = Timestamp::MinusInfinity();
898
899 LogSegment first_log_segment_ =
900 LogSegment(0, std::numeric_limits<int64_t>::max());
901
902 // The extension maps are mutable to allow us to insert the default
903 // configuration when parsing an RTP header for an unconfigured stream.
904 // TODO(terelius): This is only used for the legacy format. Remove once we've
905 // fully transitioned to the new format.
906 mutable std::map<uint32_t, webrtc::RtpHeaderExtensionMap>
907 incoming_rtp_extensions_maps_;
908 mutable std::map<uint32_t, webrtc::RtpHeaderExtensionMap>
909 outgoing_rtp_extensions_maps_;
910 };
911
912 struct MatchedSendArrivalTimes {
913 static constexpr int64_t kNotReceived = -1;
914
915 MatchedSendArrivalTimes(int64_t fb, int64_t tx, int64_t rx, int64_t ps)
916 : feedback_arrival_time_ms(fb),
917 send_time_ms(tx),
918 arrival_time_ms(rx),
919 payload_size(ps) {}
920
921 int64_t feedback_arrival_time_ms;
922 int64_t send_time_ms;
923 int64_t arrival_time_ms; // kNotReceived for lost packets.
924 int64_t payload_size;
925 };
926 const std::vector<MatchedSendArrivalTimes> GetNetworkTrace(
927 const ParsedRtcEventLog& parsed_log);
928
929 } // namespace webrtc
930
931 #endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_PARSER_H_
932