xref: /aosp_15_r20/external/webrtc/logging/rtc_event_log/events/rtc_event_end_log.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_END_LOG_H_
12 #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_END_LOG_H_
13 
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "absl/strings/string_view.h"
19 #include "api/array_view.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.h"
23 #include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h"
24 #include "logging/rtc_event_log/events/rtc_event_field_extraction.h"
25 
26 namespace webrtc {
27 
28 struct LoggedStopEvent {
29   LoggedStopEvent() = default;
30 
LoggedStopEventLoggedStopEvent31   explicit LoggedStopEvent(Timestamp timestamp) : timestamp(timestamp) {}
32 
log_time_usLoggedStopEvent33   int64_t log_time_us() const { return timestamp.us(); }
log_time_msLoggedStopEvent34   int64_t log_time_ms() const { return timestamp.ms(); }
log_timeLoggedStopEvent35   Timestamp log_time() const { return timestamp; }
36 
37   Timestamp timestamp = Timestamp::PlusInfinity();
38 };
39 
40 class RtcEventEndLog final : public RtcEvent {
41  public:
42   static constexpr Type kType = Type::EndV3Log;
43 
44   explicit RtcEventEndLog(Timestamp timestamp);
45   ~RtcEventEndLog() override;
46 
GetType()47   Type GetType() const override { return kType; }
IsConfigEvent()48   bool IsConfigEvent() const override { return false; }
49 
50   static std::string Encode(rtc::ArrayView<const RtcEvent*> batch);
51 
52   static RtcEventLogParseStatus Parse(absl::string_view encoded_bytes,
53                                       bool batched,
54                                       std::vector<LoggedStopEvent>& output);
55 
56  private:
57   RtcEventEndLog(const RtcEventEndLog& other);
58 
59   static constexpr EventParameters event_params_{"EndLog",
60                                                  RtcEventEndLog::kType};
61 };
62 
63 }  // namespace webrtc
64 #endif  // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_END_LOG_H_
65