1 /* 2 * Copyright (c) 2021 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_BEGIN_LOG_H_ 12 #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_BEGIN_LOG_H_ 13 14 #include <string> 15 #include <vector> 16 17 #include "absl/strings/string_view.h" 18 #include "api/array_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.h" 22 #include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h" 23 #include "logging/rtc_event_log/events/rtc_event_field_extraction.h" 24 25 namespace webrtc { 26 27 struct LoggedStartEvent { 28 LoggedStartEvent() = default; 29 LoggedStartEventLoggedStartEvent30 explicit LoggedStartEvent(Timestamp timestamp) 31 : LoggedStartEvent(timestamp, timestamp) {} 32 LoggedStartEventLoggedStartEvent33 LoggedStartEvent(Timestamp timestamp, Timestamp utc_start_time) 34 : timestamp(timestamp), utc_start_time(utc_start_time) {} 35 log_time_usLoggedStartEvent36 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedStartEvent37 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedStartEvent38 Timestamp log_time() const { return timestamp; } 39 utc_timeLoggedStartEvent40 Timestamp utc_time() const { return utc_start_time; } 41 42 Timestamp timestamp = Timestamp::PlusInfinity(); 43 Timestamp utc_start_time = Timestamp::PlusInfinity(); 44 }; 45 46 class RtcEventBeginLog final : public RtcEvent { 47 public: 48 static constexpr Type kType = Type::BeginV3Log; 49 50 RtcEventBeginLog(Timestamp timestamp, Timestamp utc_start_time); 51 ~RtcEventBeginLog() override; 52 GetType()53 Type GetType() const override { return kType; } IsConfigEvent()54 bool IsConfigEvent() const override { return false; } 55 56 static std::string Encode(rtc::ArrayView<const RtcEvent*> batch); 57 58 static RtcEventLogParseStatus Parse(absl::string_view encoded_bytes, 59 bool batched, 60 std::vector<LoggedStartEvent>& output); 61 62 private: 63 RtcEventBeginLog(const RtcEventBeginLog& other); 64 65 int64_t utc_start_time_ms_; 66 67 static constexpr EventParameters event_params_{"BeginLog", 68 RtcEventBeginLog::kType}; 69 static constexpr FieldParameters utc_start_time_params_{ 70 "utc_start_time_ms", /*id=*/1, FieldType::kVarInt, /*width=*/64}; 71 }; 72 73 } // namespace webrtc 74 #endif // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_BEGIN_LOG_H_ 75