xref: /aosp_15_r20/external/webrtc/logging/rtc_event_log/events/rtc_event_alr_state.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_ALR_STATE_H_
12 #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_ALR_STATE_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_definition.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 LoggedAlrStateEvent {
29   LoggedAlrStateEvent() = default;
LoggedAlrStateEventLoggedAlrStateEvent30   LoggedAlrStateEvent(Timestamp timestamp, bool in_alr)
31       : timestamp(timestamp), in_alr(in_alr) {}
32 
log_time_usLoggedAlrStateEvent33   int64_t log_time_us() const { return timestamp.us(); }
log_time_msLoggedAlrStateEvent34   int64_t log_time_ms() const { return timestamp.ms(); }
log_timeLoggedAlrStateEvent35   Timestamp log_time() const { return timestamp; }
36 
37   Timestamp timestamp = Timestamp::MinusInfinity();
38   bool in_alr;
39 };
40 
41 class RtcEventAlrState final : public RtcEvent {
42  public:
43   static constexpr Type kType = Type::AlrStateEvent;
44 
45   explicit RtcEventAlrState(bool in_alr);
46   ~RtcEventAlrState() override;
47 
GetType()48   Type GetType() const override { return kType; }
IsConfigEvent()49   bool IsConfigEvent() const override { return false; }
50 
51   std::unique_ptr<RtcEventAlrState> Copy() const;
52 
in_alr()53   bool in_alr() const { return in_alr_; }
54 
Encode(rtc::ArrayView<const RtcEvent * > batch)55   static std::string Encode(rtc::ArrayView<const RtcEvent*> batch) {
56     return RtcEventAlrState::definition_.EncodeBatch(batch);
57   }
58 
59   static RtcEventLogParseStatus Parse(absl::string_view s,
60                                       bool batched,
61                                       std::vector<LoggedAlrStateEvent>& output);
62 
63  private:
64   RtcEventAlrState(const RtcEventAlrState& other);
65 
66   const bool in_alr_;
67 
68   static constexpr RtcEventDefinition<RtcEventAlrState,
69                                       LoggedAlrStateEvent,
70                                       bool>
71       definition_{{"AlrState", RtcEventAlrState::kType},
72                   {&RtcEventAlrState::in_alr_,
73                    &LoggedAlrStateEvent::in_alr,
74                    {"in_alr", /*id=*/1, FieldType::kFixed8, /*width=*/1}}};
75 };
76 
77 }  // namespace webrtc
78 #endif  // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_ALR_STATE_H_
79