xref: /aosp_15_r20/external/webrtc/logging/rtc_event_log/events/rtc_event_bwe_update_loss_based.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_BWE_UPDATE_LOSS_BASED_H_
12 #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_BWE_UPDATE_LOSS_BASED_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 struct LoggedBweLossBasedUpdate {
28   LoggedBweLossBasedUpdate() = default;
LoggedBweLossBasedUpdateLoggedBweLossBasedUpdate29   LoggedBweLossBasedUpdate(Timestamp timestamp,
30                            int32_t bitrate_bps,
31                            uint8_t fraction_lost,
32                            int32_t expected_packets)
33       : timestamp(timestamp),
34         bitrate_bps(bitrate_bps),
35         fraction_lost(fraction_lost),
36         expected_packets(expected_packets) {}
37 
log_time_usLoggedBweLossBasedUpdate38   int64_t log_time_us() const { return timestamp.us(); }
log_time_msLoggedBweLossBasedUpdate39   int64_t log_time_ms() const { return timestamp.ms(); }
log_timeLoggedBweLossBasedUpdate40   Timestamp log_time() const { return timestamp; }
41 
42   Timestamp timestamp = Timestamp::MinusInfinity();
43   int32_t bitrate_bps;
44   uint8_t fraction_lost;
45   int32_t expected_packets;
46 };
47 
48 class RtcEventBweUpdateLossBased final : public RtcEvent {
49  public:
50   static constexpr Type kType = Type::BweUpdateLossBased;
51 
52   RtcEventBweUpdateLossBased(int32_t bitrate_bps_,
53                              uint8_t fraction_loss_,
54                              int32_t total_packets_);
55   ~RtcEventBweUpdateLossBased() override;
56 
GetType()57   Type GetType() const override { return kType; }
IsConfigEvent()58   bool IsConfigEvent() const override { return false; }
59 
60   std::unique_ptr<RtcEventBweUpdateLossBased> Copy() const;
61 
bitrate_bps()62   int32_t bitrate_bps() const { return bitrate_bps_; }
fraction_loss()63   uint8_t fraction_loss() const { return fraction_loss_; }
total_packets()64   int32_t total_packets() const { return total_packets_; }
65 
Encode(rtc::ArrayView<const RtcEvent * > batch)66   static std::string Encode(rtc::ArrayView<const RtcEvent*> batch) {
67     // TODO(terelius): Implement
68     return "";
69   }
70 
Parse(absl::string_view encoded_bytes,bool batched,std::vector<LoggedBweLossBasedUpdate> & output)71   static RtcEventLogParseStatus Parse(
72       absl::string_view encoded_bytes,
73       bool batched,
74       std::vector<LoggedBweLossBasedUpdate>& output) {
75     // TODO(terelius): Implement
76     return RtcEventLogParseStatus::Error("Not Implemented", __FILE__, __LINE__);
77   }
78 
79  private:
80   RtcEventBweUpdateLossBased(const RtcEventBweUpdateLossBased& other);
81 
82   const int32_t bitrate_bps_;
83   const uint8_t fraction_loss_;
84   const int32_t total_packets_;
85 };
86 
87 }  // namespace webrtc
88 
89 #endif  // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_BWE_UPDATE_LOSS_BASED_H_
90