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 API_RTC_EVENT_LOG_RTC_EVENT_H_
12 #define API_RTC_EVENT_LOG_RTC_EVENT_H_
13 
14 #include <cstdint>
15 
16 namespace webrtc {
17 
18 // This class allows us to store unencoded RTC events. Subclasses of this class
19 // store the actual information. This allows us to keep all unencoded events,
20 // even when their type and associated information differ, in the same buffer.
21 // Additionally, it prevents dependency leaking - a module that only logs
22 // events of type RtcEvent_A doesn't need to know about anything associated
23 // with events of type RtcEvent_B.
24 class RtcEvent {
25  public:
26   // Subclasses of this class have to associate themselves with a unique value
27   // of Type. This leaks the information of existing subclasses into the
28   // superclass, but the *actual* information - rtclog::StreamConfig, etc. -
29   // is kept separate.
30   enum class Type {
31     AlrStateEvent,
32     RouteChangeEvent,
33     RemoteEstimateEvent,
34     AudioNetworkAdaptation,
35     AudioPlayout,
36     AudioReceiveStreamConfig,
37     AudioSendStreamConfig,
38     BweUpdateDelayBased,
39     BweUpdateLossBased,
40     DtlsTransportState,
41     DtlsWritableState,
42     IceCandidatePairConfig,
43     IceCandidatePairEvent,
44     ProbeClusterCreated,
45     ProbeResultFailure,
46     ProbeResultSuccess,
47     RtcpPacketIncoming,
48     RtcpPacketOutgoing,
49     RtpPacketIncoming,
50     RtpPacketOutgoing,
51     VideoReceiveStreamConfig,
52     VideoSendStreamConfig,
53     GenericPacketSent,
54     GenericPacketReceived,
55     GenericAckReceived
56   };
57 
58   RtcEvent();
59   virtual ~RtcEvent() = default;
60 
61   virtual Type GetType() const = 0;
62 
63   virtual bool IsConfigEvent() const = 0;
64 
timestamp_ms()65   int64_t timestamp_ms() const { return timestamp_us_ / 1000; }
timestamp_us()66   int64_t timestamp_us() const { return timestamp_us_; }
67 
68  protected:
RtcEvent(int64_t timestamp_us)69   explicit RtcEvent(int64_t timestamp_us) : timestamp_us_(timestamp_us) {}
70 
71   const int64_t timestamp_us_;
72 };
73 
74 }  // namespace webrtc
75 
76 #endif  // API_RTC_EVENT_LOG_RTC_EVENT_H_
77