1 /* 2 * Copyright (c) 2017 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_ICE_CANDIDATE_PAIR_CONFIG_H_ 12 #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_ICE_CANDIDATE_PAIR_CONFIG_H_ 13 14 #include <stdint.h> 15 16 #include <memory> 17 #include <string> 18 #include <vector> 19 20 #include "absl/strings/string_view.h" 21 #include "api/rtc_event_log/rtc_event.h" 22 #include "api/units/timestamp.h" 23 #include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h" 24 25 namespace webrtc { 26 27 enum class IceCandidatePairConfigType { 28 kAdded, 29 kUpdated, 30 kDestroyed, 31 kSelected, 32 kNumValues, 33 }; 34 35 // TODO(qingsi): Change the names of candidate types to "host", "srflx", "prflx" 36 // and "relay" after the naming is spec-compliant in the signaling part 37 enum class IceCandidateType { 38 kUnknown, 39 kLocal, 40 kStun, 41 kPrflx, 42 kRelay, 43 kNumValues, 44 }; 45 46 enum class IceCandidatePairProtocol { 47 kUnknown, 48 kUdp, 49 kTcp, 50 kSsltcp, 51 kTls, 52 kNumValues, 53 }; 54 55 enum class IceCandidatePairAddressFamily { 56 kUnknown, 57 kIpv4, 58 kIpv6, 59 kNumValues, 60 }; 61 62 enum class IceCandidateNetworkType { 63 kUnknown, 64 kEthernet, 65 kLoopback, 66 kWifi, 67 kVpn, 68 kCellular, 69 kNumValues, 70 }; 71 72 struct LoggedIceCandidatePairConfig { log_time_usLoggedIceCandidatePairConfig73 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedIceCandidatePairConfig74 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedIceCandidatePairConfig75 Timestamp log_time() const { return timestamp; } 76 77 Timestamp timestamp = Timestamp::MinusInfinity(); 78 IceCandidatePairConfigType type; 79 uint32_t candidate_pair_id; 80 IceCandidateType local_candidate_type; 81 IceCandidatePairProtocol local_relay_protocol; 82 IceCandidateNetworkType local_network_type; 83 IceCandidatePairAddressFamily local_address_family; 84 IceCandidateType remote_candidate_type; 85 IceCandidatePairAddressFamily remote_address_family; 86 IceCandidatePairProtocol candidate_pair_protocol; 87 }; 88 89 class IceCandidatePairDescription { 90 public: 91 IceCandidatePairDescription(); 92 explicit IceCandidatePairDescription( 93 const IceCandidatePairDescription& other); 94 95 ~IceCandidatePairDescription(); 96 97 IceCandidateType local_candidate_type; 98 IceCandidatePairProtocol local_relay_protocol; 99 IceCandidateNetworkType local_network_type; 100 IceCandidatePairAddressFamily local_address_family; 101 IceCandidateType remote_candidate_type; 102 IceCandidatePairAddressFamily remote_address_family; 103 IceCandidatePairProtocol candidate_pair_protocol; 104 }; 105 106 class RtcEventIceCandidatePairConfig final : public RtcEvent { 107 public: 108 static constexpr Type kType = Type::IceCandidatePairConfig; 109 110 RtcEventIceCandidatePairConfig( 111 IceCandidatePairConfigType type, 112 uint32_t candidate_pair_id, 113 const IceCandidatePairDescription& candidate_pair_desc); 114 115 ~RtcEventIceCandidatePairConfig() override; 116 GetType()117 Type GetType() const override { return kType; } 118 // N.B. An ICE config event is not considered an RtcEventLog config event. IsConfigEvent()119 bool IsConfigEvent() const override { return false; } 120 121 std::unique_ptr<RtcEventIceCandidatePairConfig> Copy() const; 122 type()123 IceCandidatePairConfigType type() const { return type_; } candidate_pair_id()124 uint32_t candidate_pair_id() const { return candidate_pair_id_; } candidate_pair_desc()125 const IceCandidatePairDescription& candidate_pair_desc() const { 126 return candidate_pair_desc_; 127 } 128 Encode(rtc::ArrayView<const RtcEvent * > batch)129 static std::string Encode(rtc::ArrayView<const RtcEvent*> batch) { 130 // TODO(terelius): Implement 131 return ""; 132 } 133 Parse(absl::string_view encoded_bytes,bool batched,std::vector<LoggedIceCandidatePairConfig> & output)134 static RtcEventLogParseStatus Parse( 135 absl::string_view encoded_bytes, 136 bool batched, 137 std::vector<LoggedIceCandidatePairConfig>& output) { 138 // TODO(terelius): Implement 139 return RtcEventLogParseStatus::Error("Not Implemented", __FILE__, __LINE__); 140 } 141 142 private: 143 RtcEventIceCandidatePairConfig(const RtcEventIceCandidatePairConfig& other); 144 145 const IceCandidatePairConfigType type_; 146 const uint32_t candidate_pair_id_; 147 const IceCandidatePairDescription candidate_pair_desc_; 148 }; 149 150 } // namespace webrtc 151 152 #endif // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_ICE_CANDIDATE_PAIR_CONFIG_H_ 153