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_ENCODER_RTC_EVENT_LOG_ENCODER_NEW_FORMAT_H_
12 #define LOGGING_RTC_EVENT_LOG_ENCODER_RTC_EVENT_LOG_ENCODER_NEW_FORMAT_H_
13 
14 #include <deque>
15 #include <map>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 #include "api/array_view.h"
21 #include "logging/rtc_event_log/encoder/rtc_event_log_encoder.h"
22 
23 namespace webrtc {
24 
25 namespace rtclog2 {
26 class EventStream;  // Auto-generated from protobuf.
27 }  // namespace rtclog2
28 
29 class RtcEventAlrState;
30 class RtcEventRouteChange;
31 class RtcEventRemoteEstimate;
32 class RtcEventAudioNetworkAdaptation;
33 class RtcEventAudioPlayout;
34 class RtcEventAudioReceiveStreamConfig;
35 class RtcEventAudioSendStreamConfig;
36 class RtcEventBweUpdateDelayBased;
37 class RtcEventBweUpdateLossBased;
38 class RtcEventDtlsTransportState;
39 class RtcEventDtlsWritableState;
40 class RtcEventLoggingStarted;
41 class RtcEventLoggingStopped;
42 class RtcEventProbeClusterCreated;
43 class RtcEventProbeResultFailure;
44 class RtcEventProbeResultSuccess;
45 class RtcEventRtcpPacketIncoming;
46 class RtcEventRtcpPacketOutgoing;
47 class RtcEventRtpPacketIncoming;
48 class RtcEventRtpPacketOutgoing;
49 class RtcEventVideoReceiveStreamConfig;
50 class RtcEventVideoSendStreamConfig;
51 class RtcEventIceCandidatePairConfig;
52 class RtcEventIceCandidatePair;
53 class RtpPacket;
54 class RtcEventFrameDecoded;
55 class RtcEventGenericAckReceived;
56 class RtcEventGenericPacketReceived;
57 class RtcEventGenericPacketSent;
58 
59 class RtcEventLogEncoderNewFormat final : public RtcEventLogEncoder {
60  public:
61   ~RtcEventLogEncoderNewFormat() override = default;
62 
63   std::string EncodeBatch(
64       std::deque<std::unique_ptr<RtcEvent>>::const_iterator begin,
65       std::deque<std::unique_ptr<RtcEvent>>::const_iterator end) override;
66 
67   std::string EncodeLogStart(int64_t timestamp_us,
68                              int64_t utc_time_us) override;
69   std::string EncodeLogEnd(int64_t timestamp_us) override;
70 
71  private:
72   // Encoding entry-point for the various RtcEvent subclasses.
73   void EncodeAlrState(rtc::ArrayView<const RtcEventAlrState*> batch,
74                       rtclog2::EventStream* event_stream);
75   void EncodeAudioNetworkAdaptation(
76       rtc::ArrayView<const RtcEventAudioNetworkAdaptation*> batch,
77       rtclog2::EventStream* event_stream);
78   void EncodeAudioPlayout(rtc::ArrayView<const RtcEventAudioPlayout*> batch,
79                           rtclog2::EventStream* event_stream);
80   void EncodeAudioRecvStreamConfig(
81       rtc::ArrayView<const RtcEventAudioReceiveStreamConfig*> batch,
82       rtclog2::EventStream* event_stream);
83   void EncodeAudioSendStreamConfig(
84       rtc::ArrayView<const RtcEventAudioSendStreamConfig*> batch,
85       rtclog2::EventStream* event_stream);
86   void EncodeBweUpdateDelayBased(
87       rtc::ArrayView<const RtcEventBweUpdateDelayBased*> batch,
88       rtclog2::EventStream* event_stream);
89   void EncodeBweUpdateLossBased(
90       rtc::ArrayView<const RtcEventBweUpdateLossBased*> batch,
91       rtclog2::EventStream* event_stream);
92   void EncodeDtlsTransportState(
93       rtc::ArrayView<const RtcEventDtlsTransportState*> batch,
94       rtclog2::EventStream* event_stream);
95   void EncodeDtlsWritableState(
96       rtc::ArrayView<const RtcEventDtlsWritableState*> batch,
97       rtclog2::EventStream* event_stream);
98   void EncodeFramesDecoded(
99       rtc::ArrayView<const RtcEventFrameDecoded* const> batch,
100       rtclog2::EventStream* event_stream);
101   void EncodeGenericAcksReceived(
102       rtc::ArrayView<const RtcEventGenericAckReceived*> batch,
103       rtclog2::EventStream* event_stream);
104   void EncodeGenericPacketsReceived(
105       rtc::ArrayView<const RtcEventGenericPacketReceived*> batch,
106       rtclog2::EventStream* event_stream);
107   void EncodeGenericPacketsSent(
108       rtc::ArrayView<const RtcEventGenericPacketSent*> batch,
109       rtclog2::EventStream* event_stream);
110   void EncodeIceCandidatePairConfig(
111       rtc::ArrayView<const RtcEventIceCandidatePairConfig*> batch,
112       rtclog2::EventStream* event_stream);
113   void EncodeIceCandidatePairEvent(
114       rtc::ArrayView<const RtcEventIceCandidatePair*> batch,
115       rtclog2::EventStream* event_stream);
116   void EncodeLoggingStarted(rtc::ArrayView<const RtcEventLoggingStarted*> batch,
117                             rtclog2::EventStream* event_stream);
118   void EncodeLoggingStopped(rtc::ArrayView<const RtcEventLoggingStopped*> batch,
119                             rtclog2::EventStream* event_stream);
120   void EncodeProbeClusterCreated(
121       rtc::ArrayView<const RtcEventProbeClusterCreated*> batch,
122       rtclog2::EventStream* event_stream);
123   void EncodeProbeResultFailure(
124       rtc::ArrayView<const RtcEventProbeResultFailure*> batch,
125       rtclog2::EventStream* event_stream);
126   void EncodeProbeResultSuccess(
127       rtc::ArrayView<const RtcEventProbeResultSuccess*> batch,
128       rtclog2::EventStream* event_stream);
129   void EncodeRouteChange(rtc::ArrayView<const RtcEventRouteChange*> batch,
130                          rtclog2::EventStream* event_stream);
131   void EncodeRemoteEstimate(rtc::ArrayView<const RtcEventRemoteEstimate*> batch,
132                             rtclog2::EventStream* event_stream);
133   void EncodeRtcpPacketIncoming(
134       rtc::ArrayView<const RtcEventRtcpPacketIncoming*> batch,
135       rtclog2::EventStream* event_stream);
136   void EncodeRtcpPacketOutgoing(
137       rtc::ArrayView<const RtcEventRtcpPacketOutgoing*> batch,
138       rtclog2::EventStream* event_stream);
139   void EncodeRtpPacketIncoming(
140       const std::map<uint32_t, std::vector<const RtcEventRtpPacketIncoming*>>&
141           batch,
142       rtclog2::EventStream* event_stream);
143   void EncodeRtpPacketOutgoing(
144       const std::map<uint32_t, std::vector<const RtcEventRtpPacketOutgoing*>>&
145           batch,
146       rtclog2::EventStream* event_stream);
147   void EncodeVideoRecvStreamConfig(
148       rtc::ArrayView<const RtcEventVideoReceiveStreamConfig*> batch,
149       rtclog2::EventStream* event_stream);
150   void EncodeVideoSendStreamConfig(
151       rtc::ArrayView<const RtcEventVideoSendStreamConfig*> batch,
152       rtclog2::EventStream* event_stream);
153 };
154 
155 }  // namespace webrtc
156 
157 #endif  // LOGGING_RTC_EVENT_LOG_ENCODER_RTC_EVENT_LOG_ENCODER_NEW_FORMAT_H_
158