blob: fafce66d735351de50baa3bb81361e30bf659fef [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "logging/rtc_event_log/rtc_event_log_parser.h"
22#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h"
23#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
24#include "modules/rtp_rtcp/source/rtcp_packet.h"
25#include "rtc_base/function_view.h"
26#include "rtc_tools/event_log_visualizer/plot_base.h"
Bjorn Terelius2eb31882017-11-30 15:15:25 +010027#include "rtc_tools/event_log_visualizer/triage_notifications.h"
terelius54ce6802016-07-13 06:44:41 -070028
29namespace webrtc {
30namespace plotting {
31
tereliusccbbf8d2016-08-10 07:34:28 -070032struct LoggedRtpPacket {
33 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
34 : timestamp(timestamp), header(header), total_length(total_length) {}
35 uint64_t timestamp;
terelius6addf492016-08-23 17:34:07 -070036 // TODO(terelius): This allocates space for 15 CSRCs even if none are used.
tereliusccbbf8d2016-08-10 07:34:28 -070037 RTPHeader header;
38 size_t total_length;
39};
40
41struct LoggedRtcpPacket {
42 LoggedRtcpPacket(uint64_t timestamp,
43 RTCPPacketType rtcp_type,
44 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
45 : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {}
46 uint64_t timestamp;
47 RTCPPacketType type;
48 std::unique_ptr<rtcp::RtcpPacket> packet;
49};
50
terelius424e6cf2017-02-20 05:14:41 -080051struct LossBasedBweUpdate {
tereliusccbbf8d2016-08-10 07:34:28 -070052 uint64_t timestamp;
53 int32_t new_bitrate;
54 uint8_t fraction_loss;
55 int32_t expected_packets;
56};
57
michaelt6e5b2192017-02-22 07:33:27 -080058struct AudioNetworkAdaptationEvent {
59 uint64_t timestamp;
michaeltcde46b72017-04-06 05:59:10 -070060 AudioEncoderRuntimeConfig config;
michaelt6e5b2192017-02-22 07:33:27 -080061};
62
terelius54ce6802016-07-13 06:44:41 -070063class EventLogAnalyzer {
64 public:
65 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
66 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
67 // modified while the EventLogAnalyzer is being used.
68 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
69
70 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
71
philipelccd74892016-09-05 02:46:25 -070072 void CreateAccumulatedPacketsGraph(PacketDirection desired_direction,
73 Plot* plot);
74
terelius54ce6802016-07-13 06:44:41 -070075 void CreatePlayoutGraph(Plot* plot);
76
ivocaac9d6f2016-09-22 07:01:47 -070077 void CreateAudioLevelGraph(Plot* plot);
78
terelius54ce6802016-07-13 06:44:41 -070079 void CreateSequenceNumberGraph(Plot* plot);
80
Stefan Holmer99f8e082016-09-09 13:37:50 +020081 void CreateIncomingPacketLossGraph(Plot* plot);
82
terelius2ee076d2017-08-15 02:04:02 -070083 void CreateIncomingDelayDeltaGraph(Plot* plot);
84 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070085
tereliusf736d232016-08-04 10:00:11 -070086 void CreateFractionLossGraph(Plot* plot);
87
philipel23c7f252017-07-14 06:30:03 -070088 void CreateTotalBitrateGraph(PacketDirection desired_direction,
89 Plot* plot,
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +010090 bool show_detector_state = false,
91 bool show_alr_state = false);
terelius54ce6802016-07-13 06:44:41 -070092
93 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
94
Bjorn Terelius28db2662017-10-04 14:22:43 +020095 void CreateSendSideBweSimulationGraph(Plot* plot);
96 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020097
tereliuse34c19c2016-08-15 08:47:14 -070098 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +020099 void CreatePacerDelayGraph(Plot* plot);
stefane372d3c2017-02-02 08:04:18 -0800100 void CreateTimestampGraph(Plot* plot);
stefanc3de0332016-08-02 07:22:17 -0700101
michaelt6e5b2192017-02-22 07:33:27 -0800102 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
103 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -0700104 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800105 void CreateAudioEncoderEnableFecGraph(Plot* plot);
106 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
107 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
henrik.lundin3c938fc2017-06-14 06:09:58 -0700108 void CreateAudioJitterBufferGraph(const std::string& replacement_file_name,
109 int file_sample_rate_hz,
110 Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800111
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800112 void CreateIceCandidatePairConfigGraph(Plot* plot);
113 void CreateIceConnectivityCheckGraph(Plot* plot);
114
stefan08383272016-12-20 08:51:52 -0800115 // Returns a vector of capture and arrival timestamps for the video frames
116 // of the stream with the most number of frames.
117 std::vector<std::pair<int64_t, int64_t>> GetFrameTimestamps() const;
118
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100119 void CreateTriageNotifications();
120 void PrintNotifications(FILE* file);
121
terelius54ce6802016-07-13 06:44:41 -0700122 private:
terelius88e64e52016-07-19 01:51:06 -0700123 class StreamId {
124 public:
Stefan Holmer13181032016-07-29 14:48:54 +0200125 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
126 : ssrc_(ssrc), direction_(direction) {}
terelius0740a202016-08-08 10:21:04 -0700127 bool operator<(const StreamId& other) const {
128 return std::tie(ssrc_, direction_) <
129 std::tie(other.ssrc_, other.direction_);
130 }
131 bool operator==(const StreamId& other) const {
132 return std::tie(ssrc_, direction_) ==
133 std::tie(other.ssrc_, other.direction_);
134 }
terelius88e64e52016-07-19 01:51:06 -0700135 uint32_t GetSsrc() const { return ssrc_; }
136 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -0700137
138 private:
139 uint32_t ssrc_;
140 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -0700141 };
142
philipelccd74892016-09-05 02:46:25 -0700143 template <typename T>
144 void CreateAccumulatedPacketsTimeSeries(
145 PacketDirection desired_direction,
146 Plot* plot,
147 const std::map<StreamId, std::vector<T>>& packets,
148 const std::string& label_prefix);
149
Stefan Holmer99f8e082016-09-09 13:37:50 +0200150 bool IsRtxSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700151
Stefan Holmer99f8e082016-09-09 13:37:50 +0200152 bool IsVideoSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700153
Stefan Holmer99f8e082016-09-09 13:37:50 +0200154 bool IsAudioSsrc(StreamId stream_id) const;
155
Bjorn Terelius0295a962017-10-25 17:42:41 +0200156 std::string GetStreamName(StreamId stream_id) const;
157
158 rtc::Optional<uint32_t> EstimateRtpClockFrequency(
159 const std::vector<LoggedRtpPacket>& packets) const;
terelius0740a202016-08-08 10:21:04 -0700160
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100161 float ToCallTime(int64_t timestamp) const;
162
163 void Notification(std::unique_ptr<TriageNotification> notification);
164
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800165 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
166
terelius54ce6802016-07-13 06:44:41 -0700167 const ParsedRtcEventLog& parsed_log_;
168
169 // A list of SSRCs we are interested in analysing.
170 // If left empty, all SSRCs will be considered relevant.
171 std::vector<uint32_t> desired_ssrc_;
172
terelius0740a202016-08-08 10:21:04 -0700173 // Tracks what each stream is configured for. Note that a single SSRC can be
174 // in several sets. For example, the SSRC used for sending video over RTX
175 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
176 // an SSRC is reconfigured to a different media type mid-call, it will also
177 // appear in multiple sets.
178 std::set<StreamId> rtx_ssrcs_;
179 std::set<StreamId> video_ssrcs_;
180 std::set<StreamId> audio_ssrcs_;
181
182 // Maps a stream identifier consisting of ssrc and direction to the parsed
183 // RTP headers in that stream. Header extensions are parsed if the stream
184 // has been configured.
terelius88e64e52016-07-19 01:51:06 -0700185 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
186
Stefan Holmer13181032016-07-29 14:48:54 +0200187 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
188
henrik.lundin3c938fc2017-06-14 06:09:58 -0700189 // Maps an SSRC to the timestamps of parsed audio playout events.
190 std::map<uint32_t, std::vector<uint64_t>> audio_playout_events_;
191
192 // Stores the timestamps for all log segments, in the form of associated start
193 // and end events.
194 std::vector<std::pair<uint64_t, uint64_t>> log_segments_;
195
terelius8058e582016-07-25 01:32:41 -0700196 // A list of all updates from the send-side loss-based bandwidth estimator.
terelius424e6cf2017-02-20 05:14:41 -0800197 std::vector<LossBasedBweUpdate> bwe_loss_updates_;
terelius8058e582016-07-25 01:32:41 -0700198
michaelt6e5b2192017-02-22 07:33:27 -0800199 std::vector<AudioNetworkAdaptationEvent> audio_network_adaptation_events_;
200
philipele127e7a2017-03-29 16:28:53 +0200201 std::vector<ParsedRtcEventLog::BweProbeClusterCreatedEvent>
202 bwe_probe_cluster_created_events_;
203
204 std::vector<ParsedRtcEventLog::BweProbeResultEvent> bwe_probe_result_events_;
205
philipel10fc0e62017-04-11 01:50:23 -0700206 std::vector<ParsedRtcEventLog::BweDelayBasedUpdate> bwe_delay_updates_;
207
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100208 std::vector<std::unique_ptr<TriageNotification>> notifications_;
209
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100210 std::vector<ParsedRtcEventLog::AlrStateEvent> alr_state_events_;
211
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800212 std::vector<ParsedRtcEventLog::IceCandidatePairConfig>
213 ice_candidate_pair_configs_;
214
215 std::vector<ParsedRtcEventLog::IceCandidatePairEvent>
216 ice_candidate_pair_events_;
217
218 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
219
terelius54ce6802016-07-13 06:44:41 -0700220 // Window and step size used for calculating moving averages, e.g. bitrate.
221 // The generated data points will be |step_| microseconds apart.
222 // Only events occuring at most |window_duration_| microseconds before the
223 // current data point will be part of the average.
224 uint64_t window_duration_;
225 uint64_t step_;
226
227 // First and last events of the log.
228 uint64_t begin_time_;
229 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700230
231 // Duration (in seconds) of log file.
232 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700233};
234
235} // namespace plotting
236} // namespace webrtc
237
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200238#endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_