blob: 7ed65a76e0145441c6e219abb14d32a1ed46ba00 [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
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020021#include "logging/rtc_event_log/rtc_event_log_parser_new.h"
22#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_tools/event_log_visualizer/plot_base.h"
Bjorn Terelius2eb31882017-11-30 15:15:25 +010024#include "rtc_tools/event_log_visualizer/triage_notifications.h"
terelius54ce6802016-07-13 06:44:41 -070025
26namespace webrtc {
michaelt6e5b2192017-02-22 07:33:27 -080027
terelius54ce6802016-07-13 06:44:41 -070028class EventLogAnalyzer {
29 public:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020030 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLogNew for the
31 // duration of its lifetime. The ParsedRtcEventLogNew must not be destroyed or
terelius54ce6802016-07-13 06:44:41 -070032 // modified while the EventLogAnalyzer is being used.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020033 explicit EventLogAnalyzer(const ParsedRtcEventLogNew& log);
terelius54ce6802016-07-13 06:44:41 -070034
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020035 void CreatePacketGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070036
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020037 void CreateAccumulatedPacketsGraph(PacketDirection direction, Plot* plot);
philipelccd74892016-09-05 02:46:25 -070038
terelius54ce6802016-07-13 06:44:41 -070039 void CreatePlayoutGraph(Plot* plot);
40
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020041 void CreateAudioLevelGraph(PacketDirection direction, Plot* plot);
ivocaac9d6f2016-09-22 07:01:47 -070042
terelius54ce6802016-07-13 06:44:41 -070043 void CreateSequenceNumberGraph(Plot* plot);
44
Stefan Holmer99f8e082016-09-09 13:37:50 +020045 void CreateIncomingPacketLossGraph(Plot* plot);
46
terelius2ee076d2017-08-15 02:04:02 -070047 void CreateIncomingDelayDeltaGraph(Plot* plot);
48 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070049
tereliusf736d232016-08-04 10:00:11 -070050 void CreateFractionLossGraph(Plot* plot);
51
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020052 void CreateTotalIncomingBitrateGraph(Plot* plot);
53 void CreateTotalOutgoingBitrateGraph(Plot* plot,
54 bool show_detector_state = false,
55 bool show_alr_state = false);
terelius54ce6802016-07-13 06:44:41 -070056
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020057 void CreateStreamBitrateGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070058
Bjorn Terelius28db2662017-10-04 14:22:43 +020059 void CreateSendSideBweSimulationGraph(Plot* plot);
60 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020061
tereliuse34c19c2016-08-15 08:47:14 -070062 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +020063 void CreatePacerDelayGraph(Plot* plot);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020064
65 void CreateTimestampGraph(PacketDirection direction, Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070066
michaelt6e5b2192017-02-22 07:33:27 -080067 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
68 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -070069 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -080070 void CreateAudioEncoderEnableFecGraph(Plot* plot);
71 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
72 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
henrik.lundin3c938fc2017-06-14 06:09:58 -070073 void CreateAudioJitterBufferGraph(const std::string& replacement_file_name,
74 int file_sample_rate_hz,
75 Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -080076
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080077 void CreateIceCandidatePairConfigGraph(Plot* plot);
78 void CreateIceConnectivityCheckGraph(Plot* plot);
79
Bjorn Terelius2eb31882017-11-30 15:15:25 +010080 void CreateTriageNotifications();
81 void PrintNotifications(FILE* file);
82
terelius54ce6802016-07-13 06:44:41 -070083 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020084 bool IsRtxSsrc(PacketDirection direction, uint32_t ssrc) const {
85 if (direction == kIncomingPacket) {
86 return parsed_log_.incoming_rtx_ssrcs().find(ssrc) !=
87 parsed_log_.incoming_rtx_ssrcs().end();
88 } else {
89 return parsed_log_.outgoing_rtx_ssrcs().find(ssrc) !=
90 parsed_log_.outgoing_rtx_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -070091 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020092 }
93
94 bool IsVideoSsrc(PacketDirection direction, uint32_t ssrc) const {
95 if (direction == kIncomingPacket) {
96 return parsed_log_.incoming_video_ssrcs().find(ssrc) !=
97 parsed_log_.incoming_video_ssrcs().end();
98 } else {
99 return parsed_log_.outgoing_video_ssrcs().find(ssrc) !=
100 parsed_log_.outgoing_video_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700101 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200102 }
terelius88e64e52016-07-19 01:51:06 -0700103
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200104 bool IsAudioSsrc(PacketDirection direction, uint32_t ssrc) const {
105 if (direction == kIncomingPacket) {
106 return parsed_log_.incoming_audio_ssrcs().find(ssrc) !=
107 parsed_log_.incoming_audio_ssrcs().end();
108 } else {
109 return parsed_log_.outgoing_audio_ssrcs().find(ssrc) !=
110 parsed_log_.outgoing_audio_ssrcs().end();
111 }
112 }
terelius88e64e52016-07-19 01:51:06 -0700113
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200114 template <typename IterableType>
115 void CreateAccumulatedPacketsTimeSeries(Plot* plot,
116 const IterableType& packets,
117 const std::string& label);
philipelccd74892016-09-05 02:46:25 -0700118
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200119 void CreateStreamGapAlerts(PacketDirection direction);
120 void CreateTransmissionGapAlerts(PacketDirection direction);
terelius0740a202016-08-08 10:21:04 -0700121
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200122 std::string GetStreamName(PacketDirection direction, uint32_t ssrc) const {
123 char buffer[200];
124 rtc::SimpleStringBuilder name(buffer);
125 if (IsAudioSsrc(direction, ssrc)) {
126 name << "Audio ";
127 } else if (IsVideoSsrc(direction, ssrc)) {
128 name << "Video ";
129 } else {
130 name << "Unknown ";
131 }
132 if (IsRtxSsrc(direction, ssrc)) {
133 name << "RTX ";
134 }
135 if (direction == kIncomingPacket)
136 name << "(In) ";
137 else
138 name << "(Out) ";
139 name << "SSRC " << ssrc;
140 return name.str();
141 }
terelius0740a202016-08-08 10:21:04 -0700142
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100143 float ToCallTime(int64_t timestamp) const;
144
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200145 void Alert_RtpLogTimeGap(PacketDirection direction,
146 float time_seconds,
147 int64_t duration) {
148 if (direction == kIncomingPacket) {
149 incoming_rtp_recv_time_gaps_.emplace_back(time_seconds, duration);
150 } else {
151 outgoing_rtp_send_time_gaps_.emplace_back(time_seconds, duration);
152 }
153 }
154
155 void Alert_RtcpLogTimeGap(PacketDirection direction,
156 float time_seconds,
157 int64_t duration) {
158 if (direction == kIncomingPacket) {
159 incoming_rtcp_recv_time_gaps_.emplace_back(time_seconds, duration);
160 } else {
161 outgoing_rtcp_send_time_gaps_.emplace_back(time_seconds, duration);
162 }
163 }
164
165 void Alert_SeqNumJump(PacketDirection direction,
166 float time_seconds,
167 uint32_t ssrc) {
168 if (direction == kIncomingPacket) {
169 incoming_seq_num_jumps_.emplace_back(time_seconds, ssrc);
170 } else {
171 outgoing_seq_num_jumps_.emplace_back(time_seconds, ssrc);
172 }
173 }
174
175 void Alert_CaptureTimeJump(PacketDirection direction,
176 float time_seconds,
177 uint32_t ssrc) {
178 if (direction == kIncomingPacket) {
179 incoming_capture_time_jumps_.emplace_back(time_seconds, ssrc);
180 } else {
181 outgoing_capture_time_jumps_.emplace_back(time_seconds, ssrc);
182 }
183 }
184
185 void Alert_OutgoingHighLoss(double avg_loss_fraction) {
186 outgoing_high_loss_alerts_.emplace_back(avg_loss_fraction);
187 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100188
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800189 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
190
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200191 const ParsedRtcEventLogNew& parsed_log_;
terelius54ce6802016-07-13 06:44:41 -0700192
193 // A list of SSRCs we are interested in analysing.
194 // If left empty, all SSRCs will be considered relevant.
195 std::vector<uint32_t> desired_ssrc_;
196
henrik.lundin3c938fc2017-06-14 06:09:58 -0700197 // Stores the timestamps for all log segments, in the form of associated start
198 // and end events.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200199 std::vector<std::pair<int64_t, int64_t>> log_segments_;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700200
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200201 std::vector<IncomingRtpReceiveTimeGap> incoming_rtp_recv_time_gaps_;
202 std::vector<IncomingRtcpReceiveTimeGap> incoming_rtcp_recv_time_gaps_;
203 std::vector<OutgoingRtpSendTimeGap> outgoing_rtp_send_time_gaps_;
204 std::vector<OutgoingRtcpSendTimeGap> outgoing_rtcp_send_time_gaps_;
205 std::vector<IncomingSeqNumJump> incoming_seq_num_jumps_;
206 std::vector<IncomingCaptureTimeJump> incoming_capture_time_jumps_;
207 std::vector<OutgoingSeqNoJump> outgoing_seq_num_jumps_;
208 std::vector<OutgoingCaptureTimeJump> outgoing_capture_time_jumps_;
209 std::vector<OutgoingHighLoss> outgoing_high_loss_alerts_;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800210
211 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
212
terelius54ce6802016-07-13 06:44:41 -0700213 // Window and step size used for calculating moving averages, e.g. bitrate.
214 // The generated data points will be |step_| microseconds apart.
215 // Only events occuring at most |window_duration_| microseconds before the
216 // current data point will be part of the average.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200217 int64_t window_duration_;
218 int64_t step_;
terelius54ce6802016-07-13 06:44:41 -0700219
220 // First and last events of the log.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200221 int64_t begin_time_;
222 int64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700223
224 // Duration (in seconds) of log file.
225 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700226};
227
terelius54ce6802016-07-13 06:44:41 -0700228} // namespace webrtc
229
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200230#endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_