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_PACKET_RECEIVED_H_ 12 #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_GENERIC_PACKET_RECEIVED_H_ 13 14 #include <memory> 15 #include <string> 16 #include <vector> 17 18 #include "absl/strings/string_view.h" 19 #include "api/rtc_event_log/rtc_event.h" 20 #include "api/units/timestamp.h" 21 #include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h" 22 23 namespace webrtc { 24 25 struct LoggedGenericPacketReceived { 26 LoggedGenericPacketReceived() = default; LoggedGenericPacketReceivedLoggedGenericPacketReceived27 LoggedGenericPacketReceived(Timestamp timestamp, 28 int64_t packet_number, 29 int packet_length) 30 : timestamp(timestamp), 31 packet_number(packet_number), 32 packet_length(packet_length) {} 33 log_time_usLoggedGenericPacketReceived34 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedGenericPacketReceived35 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedGenericPacketReceived36 Timestamp log_time() const { return timestamp; } 37 38 Timestamp timestamp = Timestamp::MinusInfinity(); 39 int64_t packet_number; 40 int packet_length; 41 }; 42 43 class RtcEventGenericPacketReceived final : public RtcEvent { 44 public: 45 static constexpr Type kType = Type::GenericPacketReceived; 46 47 RtcEventGenericPacketReceived(int64_t packet_number, size_t packet_length); 48 ~RtcEventGenericPacketReceived() override; 49 50 std::unique_ptr<RtcEventGenericPacketReceived> Copy() const; 51 GetType()52 Type GetType() const override { return kType; } IsConfigEvent()53 bool IsConfigEvent() const override { return false; } 54 55 // An identifier of the packet. packet_number()56 int64_t packet_number() const { return packet_number_; } 57 58 // Total packet length, including all packetization overheads, but not 59 // including ICE/TURN/IP overheads. packet_length()60 size_t packet_length() const { return packet_length_; } 61 Encode(rtc::ArrayView<const RtcEvent * > batch)62 static std::string Encode(rtc::ArrayView<const RtcEvent*> batch) { 63 // TODO(terelius): Implement 64 return ""; 65 } 66 Parse(absl::string_view encoded_bytes,bool batched,std::vector<LoggedGenericPacketReceived> & output)67 static RtcEventLogParseStatus Parse( 68 absl::string_view encoded_bytes, 69 bool batched, 70 std::vector<LoggedGenericPacketReceived>& output) { 71 // TODO(terelius): Implement 72 return RtcEventLogParseStatus::Error("Not Implemented", __FILE__, __LINE__); 73 } 74 75 private: 76 RtcEventGenericPacketReceived(const RtcEventGenericPacketReceived& packet); 77 78 const int64_t packet_number_; 79 const size_t packet_length_; 80 }; 81 82 } // namespace webrtc 83 84 #endif // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_GENERIC_PACKET_RECEIVED_H_ 85