blob: 572884cc609d0ea3dea0c11c116e88277bee77aa [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"
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
terelius54ce6802016-07-13 06:44:41 -070029class EventLogAnalyzer {
30 public:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020031 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLogNew for the
32 // duration of its lifetime. The ParsedRtcEventLogNew must not be destroyed or
terelius54ce6802016-07-13 06:44:41 -070033 // modified while the EventLogAnalyzer is being used.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020034 explicit EventLogAnalyzer(const ParsedRtcEventLogNew& log);
terelius54ce6802016-07-13 06:44:41 -070035
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020036 void CreatePacketGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070037
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020038 void CreateAccumulatedPacketsGraph(PacketDirection direction, Plot* plot);
philipelccd74892016-09-05 02:46:25 -070039
terelius54ce6802016-07-13 06:44:41 -070040 void CreatePlayoutGraph(Plot* plot);
41
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020042 void CreateAudioLevelGraph(PacketDirection direction, Plot* plot);
ivocaac9d6f2016-09-22 07:01:47 -070043
terelius54ce6802016-07-13 06:44:41 -070044 void CreateSequenceNumberGraph(Plot* plot);
45
Stefan Holmer99f8e082016-09-09 13:37:50 +020046 void CreateIncomingPacketLossGraph(Plot* plot);
47
terelius2ee076d2017-08-15 02:04:02 -070048 void CreateIncomingDelayDeltaGraph(Plot* plot);
49 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070050
tereliusf736d232016-08-04 10:00:11 -070051 void CreateFractionLossGraph(Plot* plot);
52
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020053 void CreateTotalIncomingBitrateGraph(Plot* plot);
54 void CreateTotalOutgoingBitrateGraph(Plot* plot,
55 bool show_detector_state = false,
56 bool show_alr_state = false);
terelius54ce6802016-07-13 06:44:41 -070057
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020058 void CreateStreamBitrateGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070059
Bjorn Terelius28db2662017-10-04 14:22:43 +020060 void CreateSendSideBweSimulationGraph(Plot* plot);
61 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020062
tereliuse34c19c2016-08-15 08:47:14 -070063 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +020064 void CreatePacerDelayGraph(Plot* plot);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020065
66 void CreateTimestampGraph(PacketDirection direction, Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070067
michaelt6e5b2192017-02-22 07:33:27 -080068 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
69 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -070070 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -080071 void CreateAudioEncoderEnableFecGraph(Plot* plot);
72 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
73 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
Minyue Lic6ff7572018-05-04 09:46:44 +020074
75 using NetEqStatsGetterMap =
76 std::map<uint32_t, std::unique_ptr<test::NetEqStatsGetter>>;
77 NetEqStatsGetterMap SimulateNetEq(const std::string& replacement_file_name,
78 int file_sample_rate_hz) const;
79 void CreateAudioJitterBufferGraph(
80 const NetEqStatsGetterMap& neteq_stats_getters,
81 Plot* plot) const;
michaelt6e5b2192017-02-22 07:33:27 -080082
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080083 void CreateIceCandidatePairConfigGraph(Plot* plot);
84 void CreateIceConnectivityCheckGraph(Plot* plot);
85
Bjorn Terelius2eb31882017-11-30 15:15:25 +010086 void CreateTriageNotifications();
87 void PrintNotifications(FILE* file);
88
terelius54ce6802016-07-13 06:44:41 -070089 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020090 bool IsRtxSsrc(PacketDirection direction, uint32_t ssrc) const {
91 if (direction == kIncomingPacket) {
92 return parsed_log_.incoming_rtx_ssrcs().find(ssrc) !=
93 parsed_log_.incoming_rtx_ssrcs().end();
94 } else {
95 return parsed_log_.outgoing_rtx_ssrcs().find(ssrc) !=
96 parsed_log_.outgoing_rtx_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -070097 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020098 }
99
100 bool IsVideoSsrc(PacketDirection direction, uint32_t ssrc) const {
101 if (direction == kIncomingPacket) {
102 return parsed_log_.incoming_video_ssrcs().find(ssrc) !=
103 parsed_log_.incoming_video_ssrcs().end();
104 } else {
105 return parsed_log_.outgoing_video_ssrcs().find(ssrc) !=
106 parsed_log_.outgoing_video_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700107 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200108 }
terelius88e64e52016-07-19 01:51:06 -0700109
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200110 bool IsAudioSsrc(PacketDirection direction, uint32_t ssrc) const {
111 if (direction == kIncomingPacket) {
112 return parsed_log_.incoming_audio_ssrcs().find(ssrc) !=
113 parsed_log_.incoming_audio_ssrcs().end();
114 } else {
115 return parsed_log_.outgoing_audio_ssrcs().find(ssrc) !=
116 parsed_log_.outgoing_audio_ssrcs().end();
117 }
118 }
terelius88e64e52016-07-19 01:51:06 -0700119
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200120 template <typename IterableType>
121 void CreateAccumulatedPacketsTimeSeries(Plot* plot,
122 const IterableType& packets,
123 const std::string& label);
philipelccd74892016-09-05 02:46:25 -0700124
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200125 void CreateStreamGapAlerts(PacketDirection direction);
126 void CreateTransmissionGapAlerts(PacketDirection direction);
terelius0740a202016-08-08 10:21:04 -0700127
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200128 std::string GetStreamName(PacketDirection direction, uint32_t ssrc) const {
129 char buffer[200];
130 rtc::SimpleStringBuilder name(buffer);
131 if (IsAudioSsrc(direction, ssrc)) {
132 name << "Audio ";
133 } else if (IsVideoSsrc(direction, ssrc)) {
134 name << "Video ";
135 } else {
136 name << "Unknown ";
137 }
138 if (IsRtxSsrc(direction, ssrc)) {
139 name << "RTX ";
140 }
141 if (direction == kIncomingPacket)
142 name << "(In) ";
143 else
144 name << "(Out) ";
145 name << "SSRC " << ssrc;
146 return name.str();
147 }
terelius0740a202016-08-08 10:21:04 -0700148
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100149 float ToCallTime(int64_t timestamp) const;
150
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200151 void Alert_RtpLogTimeGap(PacketDirection direction,
152 float time_seconds,
153 int64_t duration) {
154 if (direction == kIncomingPacket) {
155 incoming_rtp_recv_time_gaps_.emplace_back(time_seconds, duration);
156 } else {
157 outgoing_rtp_send_time_gaps_.emplace_back(time_seconds, duration);
158 }
159 }
160
161 void Alert_RtcpLogTimeGap(PacketDirection direction,
162 float time_seconds,
163 int64_t duration) {
164 if (direction == kIncomingPacket) {
165 incoming_rtcp_recv_time_gaps_.emplace_back(time_seconds, duration);
166 } else {
167 outgoing_rtcp_send_time_gaps_.emplace_back(time_seconds, duration);
168 }
169 }
170
171 void Alert_SeqNumJump(PacketDirection direction,
172 float time_seconds,
173 uint32_t ssrc) {
174 if (direction == kIncomingPacket) {
175 incoming_seq_num_jumps_.emplace_back(time_seconds, ssrc);
176 } else {
177 outgoing_seq_num_jumps_.emplace_back(time_seconds, ssrc);
178 }
179 }
180
181 void Alert_CaptureTimeJump(PacketDirection direction,
182 float time_seconds,
183 uint32_t ssrc) {
184 if (direction == kIncomingPacket) {
185 incoming_capture_time_jumps_.emplace_back(time_seconds, ssrc);
186 } else {
187 outgoing_capture_time_jumps_.emplace_back(time_seconds, ssrc);
188 }
189 }
190
191 void Alert_OutgoingHighLoss(double avg_loss_fraction) {
192 outgoing_high_loss_alerts_.emplace_back(avg_loss_fraction);
193 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100194
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800195 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
196
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200197 const ParsedRtcEventLogNew& parsed_log_;
terelius54ce6802016-07-13 06:44:41 -0700198
199 // A list of SSRCs we are interested in analysing.
200 // If left empty, all SSRCs will be considered relevant.
201 std::vector<uint32_t> desired_ssrc_;
202
henrik.lundin3c938fc2017-06-14 06:09:58 -0700203 // Stores the timestamps for all log segments, in the form of associated start
204 // and end events.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200205 std::vector<std::pair<int64_t, int64_t>> log_segments_;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700206
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200207 std::vector<IncomingRtpReceiveTimeGap> incoming_rtp_recv_time_gaps_;
208 std::vector<IncomingRtcpReceiveTimeGap> incoming_rtcp_recv_time_gaps_;
209 std::vector<OutgoingRtpSendTimeGap> outgoing_rtp_send_time_gaps_;
210 std::vector<OutgoingRtcpSendTimeGap> outgoing_rtcp_send_time_gaps_;
211 std::vector<IncomingSeqNumJump> incoming_seq_num_jumps_;
212 std::vector<IncomingCaptureTimeJump> incoming_capture_time_jumps_;
213 std::vector<OutgoingSeqNoJump> outgoing_seq_num_jumps_;
214 std::vector<OutgoingCaptureTimeJump> outgoing_capture_time_jumps_;
215 std::vector<OutgoingHighLoss> outgoing_high_loss_alerts_;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800216
217 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
218
terelius54ce6802016-07-13 06:44:41 -0700219 // Window and step size used for calculating moving averages, e.g. bitrate.
220 // The generated data points will be |step_| microseconds apart.
221 // Only events occuring at most |window_duration_| microseconds before the
222 // current data point will be part of the average.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200223 int64_t window_duration_;
224 int64_t step_;
terelius54ce6802016-07-13 06:44:41 -0700225
226 // First and last events of the log.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200227 int64_t begin_time_;
228 int64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700229
230 // Duration (in seconds) of log file.
231 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700232};
233
terelius54ce6802016-07-13 06:44:41 -0700234} // namespace webrtc
235
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200236#endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_