• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 : uint32_t {
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     FrameDecoded,
57     BeginV3Log = 0x2501580,
58     EndV3Log = 0x2501581
59   };
60 
61   RtcEvent();
62   virtual ~RtcEvent() = default;
63 
64   virtual Type GetType() const = 0;
65 
66   virtual bool IsConfigEvent() const = 0;
67 
68   // Events are grouped by Type before being encoded.
69   // Optionally, `GetGroupKey` can be overloaded to group the
70   // events by a secondary key (in addition to the event type.)
71   // This can, in some cases, improve compression efficiency
72   // e.g. by grouping events by SSRC.
GetGroupKey()73   virtual uint32_t GetGroupKey() const { return 0; }
74 
timestamp_ms()75   int64_t timestamp_ms() const { return timestamp_us_ / 1000; }
timestamp_us()76   int64_t timestamp_us() const { return timestamp_us_; }
77 
78  protected:
RtcEvent(int64_t timestamp_us)79   explicit RtcEvent(int64_t timestamp_us) : timestamp_us_(timestamp_us) {}
80 
81   const int64_t timestamp_us_;
82 };
83 
84 }  // namespace webrtc
85 
86 #endif  // API_RTC_EVENT_LOG_RTC_EVENT_H_
87