1 /* 2 * Copyright (c) 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 11 #ifndef LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_GENERIC_ACK_RECEIVED_H_ 12 #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_GENERIC_ACK_RECEIVED_H_ 13 14 #include <memory> 15 #include <string> 16 #include <vector> 17 18 #include "absl/strings/string_view.h" 19 #include "absl/types/optional.h" 20 #include "api/rtc_event_log/rtc_event.h" 21 #include "api/units/timestamp.h" 22 #include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h" 23 24 namespace webrtc { 25 26 struct LoggedGenericAckReceived { 27 LoggedGenericAckReceived() = default; LoggedGenericAckReceivedLoggedGenericAckReceived28 LoggedGenericAckReceived(Timestamp timestamp, 29 int64_t packet_number, 30 int64_t acked_packet_number, 31 absl::optional<int64_t> receive_acked_packet_time_ms) 32 : timestamp(timestamp), 33 packet_number(packet_number), 34 acked_packet_number(acked_packet_number), 35 receive_acked_packet_time_ms(receive_acked_packet_time_ms) {} 36 log_time_usLoggedGenericAckReceived37 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedGenericAckReceived38 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedGenericAckReceived39 Timestamp log_time() const { return timestamp; } 40 41 Timestamp timestamp = Timestamp::MinusInfinity(); 42 int64_t packet_number; 43 int64_t acked_packet_number; 44 absl::optional<int64_t> receive_acked_packet_time_ms; 45 }; 46 47 struct AckedPacket { 48 // The packet number that was acked. 49 int64_t packet_number; 50 51 // The time where the packet was received. Not every ACK will 52 // include the receive timestamp. 53 absl::optional<int64_t> receive_acked_packet_time_ms; 54 }; 55 56 class RtcEventGenericAckReceived final : public RtcEvent { 57 public: 58 static constexpr Type kType = Type::GenericAckReceived; 59 60 // For a collection of acked packets, it creates a vector of logs to log with 61 // the same timestamp. 62 static std::vector<std::unique_ptr<RtcEventGenericAckReceived>> CreateLogs( 63 int64_t packet_number, 64 const std::vector<AckedPacket>& acked_packets); 65 66 ~RtcEventGenericAckReceived() override; 67 68 std::unique_ptr<RtcEventGenericAckReceived> Copy() const; 69 GetType()70 Type GetType() const override { return kType; } IsConfigEvent()71 bool IsConfigEvent() const override { return false; } 72 73 // An identifier of the packet which contained an ack. packet_number()74 int64_t packet_number() const { return packet_number_; } 75 76 // An identifier of the acked packet. acked_packet_number()77 int64_t acked_packet_number() const { return acked_packet_number_; } 78 79 // Timestamp when the `acked_packet_number` was received by the remote side. receive_acked_packet_time_ms()80 absl::optional<int64_t> receive_acked_packet_time_ms() const { 81 return receive_acked_packet_time_ms_; 82 } 83 Encode(rtc::ArrayView<const RtcEvent * > batch)84 static std::string Encode(rtc::ArrayView<const RtcEvent*> batch) { 85 // TODO(terelius): Implement 86 return ""; 87 } 88 Parse(absl::string_view encoded_bytes,bool batched,std::vector<LoggedGenericAckReceived> & output)89 static RtcEventLogParseStatus Parse( 90 absl::string_view encoded_bytes, 91 bool batched, 92 std::vector<LoggedGenericAckReceived>& output) { 93 // TODO(terelius): Implement 94 return RtcEventLogParseStatus::Error("Not Implemented", __FILE__, __LINE__); 95 } 96 97 private: 98 RtcEventGenericAckReceived(const RtcEventGenericAckReceived& packet); 99 100 // When the ack is received, `packet_number` identifies the packet which 101 // contained an ack for `acked_packet_number`, and contains the 102 // `receive_acked_packet_time_ms` on which the `acked_packet_number` was 103 // received on the remote side. The `receive_acked_packet_time_ms` may be 104 // null. 105 RtcEventGenericAckReceived( 106 int64_t timestamp_us, 107 int64_t packet_number, 108 int64_t acked_packet_number, 109 absl::optional<int64_t> receive_acked_packet_time_ms); 110 111 const int64_t packet_number_; 112 const int64_t acked_packet_number_; 113 const absl::optional<int64_t> receive_acked_packet_time_ms_; 114 }; 115 116 } // namespace webrtc 117 118 #endif // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_GENERIC_ACK_RECEIVED_H_ 119