blob: 60642022fb0956105c1532a5bca89686a1f0d086 [file] [log] [blame]
terelius54ce6802016-07-13 06:44:41 -07001/*
2 * Copyright (c) 2016 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_
12#define RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_
terelius54ce6802016-07-13 06:44:41 -070013
terelius88e64e52016-07-19 01:51:06 -070014#include <map>
Stefan Holmer13181032016-07-29 14:48:54 +020015#include <memory>
terelius0740a202016-08-08 10:21:04 -070016#include <set>
philipelccd74892016-09-05 02:46:25 -070017#include <string>
Stefan Holmer13181032016-07-29 14:48:54 +020018#include <utility>
philipelccd74892016-09-05 02:46:25 -070019#include <vector>
terelius54ce6802016-07-13 06:44:41 -070020
Sebastian Janssonb290a6d2019-01-03 14:46:23 +010021#include "logging/rtc_event_log/rtc_event_log_parser.h"
Minyue Lic6ff7572018-05-04 09:46:44 +020022#include "modules/audio_coding/neteq/tools/neteq_stats_getter.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020023#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_tools/event_log_visualizer/plot_base.h"
Bjorn Terelius2eb31882017-11-30 15:15:25 +010025#include "rtc_tools/event_log_visualizer/triage_notifications.h"
terelius54ce6802016-07-13 06:44:41 -070026
27namespace webrtc {
michaelt6e5b2192017-02-22 07:33:27 -080028
Bjorn Terelius068fc352019-02-13 22:38:25 +010029class AnalyzerConfig {
30 public:
31 float GetCallTimeSec(int64_t timestamp_us) const {
32 int64_t offset = normalize_time_ ? begin_time_ : 0;
33 return static_cast<float>(timestamp_us - offset) / 1000000;
34 }
35
36 float CallBeginTimeSec() const { return GetCallTimeSec(begin_time_); }
37
38 float CallEndTimeSec() const { return GetCallTimeSec(end_time_); }
39
40 // Window and step size used for calculating moving averages, e.g. bitrate.
41 // The generated data points will be |step_| microseconds apart.
42 // Only events occuring at most |window_duration_| microseconds before the
43 // current data point will be part of the average.
44 int64_t window_duration_;
45 int64_t step_;
46
47 // First and last events of the log.
48 int64_t begin_time_;
49 int64_t end_time_;
50 bool normalize_time_;
51};
52
terelius54ce6802016-07-13 06:44:41 -070053class EventLogAnalyzer {
54 public:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020055 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLogNew for the
56 // duration of its lifetime. The ParsedRtcEventLogNew must not be destroyed or
terelius54ce6802016-07-13 06:44:41 -070057 // modified while the EventLogAnalyzer is being used.
Sebastian Janssonb290a6d2019-01-03 14:46:23 +010058 EventLogAnalyzer(const ParsedRtcEventLog& log, bool normalize_time);
terelius54ce6802016-07-13 06:44:41 -070059
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020060 void CreatePacketGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070061
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020062 void CreateAccumulatedPacketsGraph(PacketDirection direction, Plot* plot);
philipelccd74892016-09-05 02:46:25 -070063
terelius54ce6802016-07-13 06:44:41 -070064 void CreatePlayoutGraph(Plot* plot);
65
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020066 void CreateAudioLevelGraph(PacketDirection direction, Plot* plot);
ivocaac9d6f2016-09-22 07:01:47 -070067
terelius54ce6802016-07-13 06:44:41 -070068 void CreateSequenceNumberGraph(Plot* plot);
69
Stefan Holmer99f8e082016-09-09 13:37:50 +020070 void CreateIncomingPacketLossGraph(Plot* plot);
71
terelius2ee076d2017-08-15 02:04:02 -070072 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070073
tereliusf736d232016-08-04 10:00:11 -070074 void CreateFractionLossGraph(Plot* plot);
75
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020076 void CreateTotalIncomingBitrateGraph(Plot* plot);
77 void CreateTotalOutgoingBitrateGraph(Plot* plot,
78 bool show_detector_state = false,
79 bool show_alr_state = false);
terelius54ce6802016-07-13 06:44:41 -070080
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020081 void CreateStreamBitrateGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070082
Bjorn Terelius28db2662017-10-04 14:22:43 +020083 void CreateSendSideBweSimulationGraph(Plot* plot);
84 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020085
tereliuse34c19c2016-08-15 08:47:14 -070086 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +020087 void CreatePacerDelayGraph(Plot* plot);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020088
89 void CreateTimestampGraph(PacketDirection direction, Plot* plot);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +020090 void CreateSenderAndReceiverReportPlot(
91 PacketDirection direction,
92 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
93 std::string title,
94 std::string yaxis_label,
95 Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070096
michaelt6e5b2192017-02-22 07:33:27 -080097 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
98 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -070099 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800100 void CreateAudioEncoderEnableFecGraph(Plot* plot);
101 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
102 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
Minyue Lic6ff7572018-05-04 09:46:44 +0200103
104 using NetEqStatsGetterMap =
105 std::map<uint32_t, std::unique_ptr<test::NetEqStatsGetter>>;
106 NetEqStatsGetterMap SimulateNetEq(const std::string& replacement_file_name,
107 int file_sample_rate_hz) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200108
Minyue Li01d2a672018-06-21 21:17:19 +0200109 void CreateAudioJitterBufferGraph(uint32_t ssrc,
110 const test::NetEqStatsGetter* stats_getter,
111 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200112 void CreateNetEqNetworkStatsGraph(
Minyue Li27e2b7d2018-05-07 15:20:24 +0200113 const NetEqStatsGetterMap& neteq_stats_getters,
114 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
115 const std::string& plot_name,
116 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200117 void CreateNetEqLifetimeStatsGraph(
118 const NetEqStatsGetterMap& neteq_stats_getters,
119 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
120 const std::string& plot_name,
121 Plot* plot) const;
michaelt6e5b2192017-02-22 07:33:27 -0800122
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800123 void CreateIceCandidatePairConfigGraph(Plot* plot);
124 void CreateIceConnectivityCheckGraph(Plot* plot);
125
Zach Stein10a58012018-12-07 12:26:28 -0800126 void CreateDtlsTransportStateGraph(Plot* plot);
127 void CreateDtlsWritableStateGraph(Plot* plot);
128
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100129 void CreateTriageNotifications();
130 void PrintNotifications(FILE* file);
131
terelius54ce6802016-07-13 06:44:41 -0700132 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200133 bool IsRtxSsrc(PacketDirection direction, uint32_t ssrc) const {
134 if (direction == kIncomingPacket) {
135 return parsed_log_.incoming_rtx_ssrcs().find(ssrc) !=
136 parsed_log_.incoming_rtx_ssrcs().end();
137 } else {
138 return parsed_log_.outgoing_rtx_ssrcs().find(ssrc) !=
139 parsed_log_.outgoing_rtx_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700140 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200141 }
142
143 bool IsVideoSsrc(PacketDirection direction, uint32_t ssrc) const {
144 if (direction == kIncomingPacket) {
145 return parsed_log_.incoming_video_ssrcs().find(ssrc) !=
146 parsed_log_.incoming_video_ssrcs().end();
147 } else {
148 return parsed_log_.outgoing_video_ssrcs().find(ssrc) !=
149 parsed_log_.outgoing_video_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700150 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200151 }
terelius88e64e52016-07-19 01:51:06 -0700152
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200153 bool IsAudioSsrc(PacketDirection direction, uint32_t ssrc) const {
154 if (direction == kIncomingPacket) {
155 return parsed_log_.incoming_audio_ssrcs().find(ssrc) !=
156 parsed_log_.incoming_audio_ssrcs().end();
157 } else {
158 return parsed_log_.outgoing_audio_ssrcs().find(ssrc) !=
159 parsed_log_.outgoing_audio_ssrcs().end();
160 }
161 }
terelius88e64e52016-07-19 01:51:06 -0700162
Minyue Lic9ac93f2018-06-26 13:01:32 +0200163 template <typename NetEqStatsType>
164 void CreateNetEqStatsGraphInternal(
165 const NetEqStatsGetterMap& neteq_stats,
166 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
167 const test::NetEqStatsGetter*)> data_extractor,
168 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
169 const std::string& plot_name,
170 Plot* plot) const;
171
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200172 template <typename IterableType>
173 void CreateAccumulatedPacketsTimeSeries(Plot* plot,
174 const IterableType& packets,
175 const std::string& label);
philipelccd74892016-09-05 02:46:25 -0700176
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200177 void CreateStreamGapAlerts(PacketDirection direction);
178 void CreateTransmissionGapAlerts(PacketDirection direction);
terelius0740a202016-08-08 10:21:04 -0700179
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200180 std::string GetStreamName(PacketDirection direction, uint32_t ssrc) const {
181 char buffer[200];
182 rtc::SimpleStringBuilder name(buffer);
183 if (IsAudioSsrc(direction, ssrc)) {
184 name << "Audio ";
185 } else if (IsVideoSsrc(direction, ssrc)) {
186 name << "Video ";
187 } else {
188 name << "Unknown ";
189 }
190 if (IsRtxSsrc(direction, ssrc)) {
191 name << "RTX ";
192 }
193 if (direction == kIncomingPacket)
194 name << "(In) ";
195 else
196 name << "(Out) ";
197 name << "SSRC " << ssrc;
198 return name.str();
199 }
terelius0740a202016-08-08 10:21:04 -0700200
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200201 void Alert_RtpLogTimeGap(PacketDirection direction,
202 float time_seconds,
203 int64_t duration) {
204 if (direction == kIncomingPacket) {
205 incoming_rtp_recv_time_gaps_.emplace_back(time_seconds, duration);
206 } else {
207 outgoing_rtp_send_time_gaps_.emplace_back(time_seconds, duration);
208 }
209 }
210
211 void Alert_RtcpLogTimeGap(PacketDirection direction,
212 float time_seconds,
213 int64_t duration) {
214 if (direction == kIncomingPacket) {
215 incoming_rtcp_recv_time_gaps_.emplace_back(time_seconds, duration);
216 } else {
217 outgoing_rtcp_send_time_gaps_.emplace_back(time_seconds, duration);
218 }
219 }
220
221 void Alert_SeqNumJump(PacketDirection direction,
222 float time_seconds,
223 uint32_t ssrc) {
224 if (direction == kIncomingPacket) {
225 incoming_seq_num_jumps_.emplace_back(time_seconds, ssrc);
226 } else {
227 outgoing_seq_num_jumps_.emplace_back(time_seconds, ssrc);
228 }
229 }
230
231 void Alert_CaptureTimeJump(PacketDirection direction,
232 float time_seconds,
233 uint32_t ssrc) {
234 if (direction == kIncomingPacket) {
235 incoming_capture_time_jumps_.emplace_back(time_seconds, ssrc);
236 } else {
237 outgoing_capture_time_jumps_.emplace_back(time_seconds, ssrc);
238 }
239 }
240
241 void Alert_OutgoingHighLoss(double avg_loss_fraction) {
242 outgoing_high_loss_alerts_.emplace_back(avg_loss_fraction);
243 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100244
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800245 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
246
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100247 const ParsedRtcEventLog& parsed_log_;
terelius54ce6802016-07-13 06:44:41 -0700248
249 // A list of SSRCs we are interested in analysing.
250 // If left empty, all SSRCs will be considered relevant.
251 std::vector<uint32_t> desired_ssrc_;
252
henrik.lundin3c938fc2017-06-14 06:09:58 -0700253 // Stores the timestamps for all log segments, in the form of associated start
254 // and end events.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200255 std::vector<std::pair<int64_t, int64_t>> log_segments_;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700256
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200257 std::vector<IncomingRtpReceiveTimeGap> incoming_rtp_recv_time_gaps_;
258 std::vector<IncomingRtcpReceiveTimeGap> incoming_rtcp_recv_time_gaps_;
259 std::vector<OutgoingRtpSendTimeGap> outgoing_rtp_send_time_gaps_;
260 std::vector<OutgoingRtcpSendTimeGap> outgoing_rtcp_send_time_gaps_;
261 std::vector<IncomingSeqNumJump> incoming_seq_num_jumps_;
262 std::vector<IncomingCaptureTimeJump> incoming_capture_time_jumps_;
263 std::vector<OutgoingSeqNoJump> outgoing_seq_num_jumps_;
264 std::vector<OutgoingCaptureTimeJump> outgoing_capture_time_jumps_;
265 std::vector<OutgoingHighLoss> outgoing_high_loss_alerts_;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800266
267 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
268
Bjorn Terelius068fc352019-02-13 22:38:25 +0100269 AnalyzerConfig config_;
terelius54ce6802016-07-13 06:44:41 -0700270};
271
terelius54ce6802016-07-13 06:44:41 -0700272} // namespace webrtc
273
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200274#endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_