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