blob: 4b8c27c9517d0cbcc0401d48ab118cc23d90128a [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.
Stefan Holmer1d4a2272018-05-24 13:48:09 +020034 EventLogAnalyzer(const ParsedRtcEventLogNew& log, bool normalize_time);
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);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +020067 void CreateSenderAndReceiverReportPlot(
68 PacketDirection direction,
69 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
70 std::string title,
71 std::string yaxis_label,
72 Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070073
michaelt6e5b2192017-02-22 07:33:27 -080074 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
75 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -070076 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -080077 void CreateAudioEncoderEnableFecGraph(Plot* plot);
78 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
79 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
Minyue Lic6ff7572018-05-04 09:46:44 +020080
81 using NetEqStatsGetterMap =
82 std::map<uint32_t, std::unique_ptr<test::NetEqStatsGetter>>;
83 NetEqStatsGetterMap SimulateNetEq(const std::string& replacement_file_name,
84 int file_sample_rate_hz) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +020085
Minyue Li01d2a672018-06-21 21:17:19 +020086 void CreateAudioJitterBufferGraph(uint32_t ssrc,
87 const test::NetEqStatsGetter* stats_getter,
88 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +020089 void CreateNetEqNetworkStatsGraph(
Minyue Li27e2b7d2018-05-07 15:20:24 +020090 const NetEqStatsGetterMap& neteq_stats_getters,
91 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
92 const std::string& plot_name,
93 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +020094 void CreateNetEqLifetimeStatsGraph(
95 const NetEqStatsGetterMap& neteq_stats_getters,
96 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
97 const std::string& plot_name,
98 Plot* plot) const;
michaelt6e5b2192017-02-22 07:33:27 -080099
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800100 void CreateIceCandidatePairConfigGraph(Plot* plot);
101 void CreateIceConnectivityCheckGraph(Plot* plot);
102
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100103 void CreateTriageNotifications();
104 void PrintNotifications(FILE* file);
105
terelius54ce6802016-07-13 06:44:41 -0700106 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200107 bool IsRtxSsrc(PacketDirection direction, uint32_t ssrc) const {
108 if (direction == kIncomingPacket) {
109 return parsed_log_.incoming_rtx_ssrcs().find(ssrc) !=
110 parsed_log_.incoming_rtx_ssrcs().end();
111 } else {
112 return parsed_log_.outgoing_rtx_ssrcs().find(ssrc) !=
113 parsed_log_.outgoing_rtx_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700114 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200115 }
116
117 bool IsVideoSsrc(PacketDirection direction, uint32_t ssrc) const {
118 if (direction == kIncomingPacket) {
119 return parsed_log_.incoming_video_ssrcs().find(ssrc) !=
120 parsed_log_.incoming_video_ssrcs().end();
121 } else {
122 return parsed_log_.outgoing_video_ssrcs().find(ssrc) !=
123 parsed_log_.outgoing_video_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700124 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200125 }
terelius88e64e52016-07-19 01:51:06 -0700126
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200127 bool IsAudioSsrc(PacketDirection direction, uint32_t ssrc) const {
128 if (direction == kIncomingPacket) {
129 return parsed_log_.incoming_audio_ssrcs().find(ssrc) !=
130 parsed_log_.incoming_audio_ssrcs().end();
131 } else {
132 return parsed_log_.outgoing_audio_ssrcs().find(ssrc) !=
133 parsed_log_.outgoing_audio_ssrcs().end();
134 }
135 }
terelius88e64e52016-07-19 01:51:06 -0700136
Minyue Lic9ac93f2018-06-26 13:01:32 +0200137 template <typename NetEqStatsType>
138 void CreateNetEqStatsGraphInternal(
139 const NetEqStatsGetterMap& neteq_stats,
140 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
141 const test::NetEqStatsGetter*)> data_extractor,
142 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
143 const std::string& plot_name,
144 Plot* plot) const;
145
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200146 template <typename IterableType>
147 void CreateAccumulatedPacketsTimeSeries(Plot* plot,
148 const IterableType& packets,
149 const std::string& label);
philipelccd74892016-09-05 02:46:25 -0700150
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200151 void CreateStreamGapAlerts(PacketDirection direction);
152 void CreateTransmissionGapAlerts(PacketDirection direction);
terelius0740a202016-08-08 10:21:04 -0700153
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200154 std::string GetStreamName(PacketDirection direction, uint32_t ssrc) const {
155 char buffer[200];
156 rtc::SimpleStringBuilder name(buffer);
157 if (IsAudioSsrc(direction, ssrc)) {
158 name << "Audio ";
159 } else if (IsVideoSsrc(direction, ssrc)) {
160 name << "Video ";
161 } else {
162 name << "Unknown ";
163 }
164 if (IsRtxSsrc(direction, ssrc)) {
165 name << "RTX ";
166 }
167 if (direction == kIncomingPacket)
168 name << "(In) ";
169 else
170 name << "(Out) ";
171 name << "SSRC " << ssrc;
172 return name.str();
173 }
terelius0740a202016-08-08 10:21:04 -0700174
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200175 int64_t ToCallTimeUs(int64_t timestamp) const;
176 float ToCallTimeSec(int64_t timestamp) const;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100177
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200178 void Alert_RtpLogTimeGap(PacketDirection direction,
179 float time_seconds,
180 int64_t duration) {
181 if (direction == kIncomingPacket) {
182 incoming_rtp_recv_time_gaps_.emplace_back(time_seconds, duration);
183 } else {
184 outgoing_rtp_send_time_gaps_.emplace_back(time_seconds, duration);
185 }
186 }
187
188 void Alert_RtcpLogTimeGap(PacketDirection direction,
189 float time_seconds,
190 int64_t duration) {
191 if (direction == kIncomingPacket) {
192 incoming_rtcp_recv_time_gaps_.emplace_back(time_seconds, duration);
193 } else {
194 outgoing_rtcp_send_time_gaps_.emplace_back(time_seconds, duration);
195 }
196 }
197
198 void Alert_SeqNumJump(PacketDirection direction,
199 float time_seconds,
200 uint32_t ssrc) {
201 if (direction == kIncomingPacket) {
202 incoming_seq_num_jumps_.emplace_back(time_seconds, ssrc);
203 } else {
204 outgoing_seq_num_jumps_.emplace_back(time_seconds, ssrc);
205 }
206 }
207
208 void Alert_CaptureTimeJump(PacketDirection direction,
209 float time_seconds,
210 uint32_t ssrc) {
211 if (direction == kIncomingPacket) {
212 incoming_capture_time_jumps_.emplace_back(time_seconds, ssrc);
213 } else {
214 outgoing_capture_time_jumps_.emplace_back(time_seconds, ssrc);
215 }
216 }
217
218 void Alert_OutgoingHighLoss(double avg_loss_fraction) {
219 outgoing_high_loss_alerts_.emplace_back(avg_loss_fraction);
220 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100221
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800222 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
223
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200224 const ParsedRtcEventLogNew& parsed_log_;
terelius54ce6802016-07-13 06:44:41 -0700225
226 // A list of SSRCs we are interested in analysing.
227 // If left empty, all SSRCs will be considered relevant.
228 std::vector<uint32_t> desired_ssrc_;
229
henrik.lundin3c938fc2017-06-14 06:09:58 -0700230 // Stores the timestamps for all log segments, in the form of associated start
231 // and end events.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200232 std::vector<std::pair<int64_t, int64_t>> log_segments_;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700233
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200234 std::vector<IncomingRtpReceiveTimeGap> incoming_rtp_recv_time_gaps_;
235 std::vector<IncomingRtcpReceiveTimeGap> incoming_rtcp_recv_time_gaps_;
236 std::vector<OutgoingRtpSendTimeGap> outgoing_rtp_send_time_gaps_;
237 std::vector<OutgoingRtcpSendTimeGap> outgoing_rtcp_send_time_gaps_;
238 std::vector<IncomingSeqNumJump> incoming_seq_num_jumps_;
239 std::vector<IncomingCaptureTimeJump> incoming_capture_time_jumps_;
240 std::vector<OutgoingSeqNoJump> outgoing_seq_num_jumps_;
241 std::vector<OutgoingCaptureTimeJump> outgoing_capture_time_jumps_;
242 std::vector<OutgoingHighLoss> outgoing_high_loss_alerts_;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800243
244 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
245
terelius54ce6802016-07-13 06:44:41 -0700246 // Window and step size used for calculating moving averages, e.g. bitrate.
247 // The generated data points will be |step_| microseconds apart.
248 // Only events occuring at most |window_duration_| microseconds before the
249 // current data point will be part of the average.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200250 int64_t window_duration_;
251 int64_t step_;
terelius54ce6802016-07-13 06:44:41 -0700252
253 // First and last events of the log.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200254 int64_t begin_time_;
255 int64_t end_time_;
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200256 const bool normalize_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700257
258 // Duration (in seconds) of log file.
259 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700260};
261
terelius54ce6802016-07-13 06:44:41 -0700262} // namespace webrtc
263
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200264#endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_