blob: a8fedb83415a96755f0373e24c37ed777183b9dc [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
Björn Tereliusff612732018-04-25 14:23:01 +000021#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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#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 {
Björn Tereliusff612732018-04-25 14:23:01 +000030namespace plotting {
31
32struct LoggedRtpPacket {
33 LoggedRtpPacket(uint64_t timestamp,
34 RTPHeader header,
35 size_t header_length,
36 size_t total_length)
37 : timestamp(timestamp),
38 header(header),
39 header_length(header_length),
40 total_length(total_length) {}
41 uint64_t timestamp;
42 // TODO(terelius): This allocates space for 15 CSRCs even if none are used.
43 RTPHeader header;
44 size_t header_length;
45 size_t total_length;
46};
47
48struct LoggedRtcpPacket {
49 LoggedRtcpPacket(uint64_t timestamp,
50 RTCPPacketType rtcp_type,
51 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
52 : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {}
53 uint64_t timestamp;
54 RTCPPacketType type;
55 std::unique_ptr<rtcp::RtcpPacket> packet;
56};
57
58struct LossBasedBweUpdate {
59 uint64_t timestamp;
60 int32_t new_bitrate;
61 uint8_t fraction_loss;
62 int32_t expected_packets;
63};
64
65struct AudioNetworkAdaptationEvent {
66 uint64_t timestamp;
67 AudioEncoderRuntimeConfig config;
68};
michaelt6e5b2192017-02-22 07:33:27 -080069
terelius54ce6802016-07-13 06:44:41 -070070class EventLogAnalyzer {
71 public:
72 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
73 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
74 // modified while the EventLogAnalyzer is being used.
75 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
76
Björn Tereliusff612732018-04-25 14:23:01 +000077 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070078
Björn Tereliusff612732018-04-25 14:23:01 +000079 void CreateAccumulatedPacketsGraph(PacketDirection desired_direction,
80 Plot* plot);
philipelccd74892016-09-05 02:46:25 -070081
terelius54ce6802016-07-13 06:44:41 -070082 void CreatePlayoutGraph(Plot* plot);
83
Björn Tereliusff612732018-04-25 14:23:01 +000084 void CreateAudioLevelGraph(Plot* plot);
ivocaac9d6f2016-09-22 07:01:47 -070085
terelius54ce6802016-07-13 06:44:41 -070086 void CreateSequenceNumberGraph(Plot* plot);
87
Stefan Holmer99f8e082016-09-09 13:37:50 +020088 void CreateIncomingPacketLossGraph(Plot* plot);
89
terelius2ee076d2017-08-15 02:04:02 -070090 void CreateIncomingDelayDeltaGraph(Plot* plot);
91 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070092
tereliusf736d232016-08-04 10:00:11 -070093 void CreateFractionLossGraph(Plot* plot);
94
Björn Tereliusff612732018-04-25 14:23:01 +000095 void CreateTotalBitrateGraph(PacketDirection desired_direction,
96 Plot* plot,
97 bool show_detector_state = false,
98 bool show_alr_state = false);
terelius54ce6802016-07-13 06:44:41 -070099
Björn Tereliusff612732018-04-25 14:23:01 +0000100 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -0700101
Bjorn Terelius28db2662017-10-04 14:22:43 +0200102 void CreateSendSideBweSimulationGraph(Plot* plot);
103 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +0200104
tereliuse34c19c2016-08-15 08:47:14 -0700105 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +0200106 void CreatePacerDelayGraph(Plot* plot);
Björn Tereliusff612732018-04-25 14:23:01 +0000107 void CreateTimestampGraph(Plot* plot);
stefanc3de0332016-08-02 07:22:17 -0700108
michaelt6e5b2192017-02-22 07:33:27 -0800109 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
110 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -0700111 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800112 void CreateAudioEncoderEnableFecGraph(Plot* plot);
113 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
114 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
henrik.lundin3c938fc2017-06-14 06:09:58 -0700115 void CreateAudioJitterBufferGraph(const std::string& replacement_file_name,
116 int file_sample_rate_hz,
117 Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800118
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800119 void CreateIceCandidatePairConfigGraph(Plot* plot);
120 void CreateIceConnectivityCheckGraph(Plot* plot);
121
Björn Tereliusff612732018-04-25 14:23:01 +0000122 // Returns a vector of capture and arrival timestamps for the video frames
123 // of the stream with the most number of frames.
124 std::vector<std::pair<int64_t, int64_t>> GetFrameTimestamps() const;
125
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100126 void CreateTriageNotifications();
127 void PrintNotifications(FILE* file);
128
terelius54ce6802016-07-13 06:44:41 -0700129 private:
Björn Tereliusff612732018-04-25 14:23:01 +0000130 class StreamId {
131 public:
132 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
133 : ssrc_(ssrc), direction_(direction) {}
134 bool operator<(const StreamId& other) const {
135 return std::tie(ssrc_, direction_) <
136 std::tie(other.ssrc_, other.direction_);
terelius0740a202016-08-08 10:21:04 -0700137 }
Björn Tereliusff612732018-04-25 14:23:01 +0000138 bool operator==(const StreamId& other) const {
139 return std::tie(ssrc_, direction_) ==
140 std::tie(other.ssrc_, other.direction_);
terelius0740a202016-08-08 10:21:04 -0700141 }
Björn Tereliusff612732018-04-25 14:23:01 +0000142 uint32_t GetSsrc() const { return ssrc_; }
143 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -0700144
Björn Tereliusff612732018-04-25 14:23:01 +0000145 private:
146 uint32_t ssrc_;
147 webrtc::PacketDirection direction_;
148 };
terelius88e64e52016-07-19 01:51:06 -0700149
Björn Tereliusff612732018-04-25 14:23:01 +0000150 template <typename T>
151 void CreateAccumulatedPacketsTimeSeries(
152 PacketDirection desired_direction,
153 Plot* plot,
154 const std::map<StreamId, std::vector<T>>& packets,
155 const std::string& label_prefix);
philipelccd74892016-09-05 02:46:25 -0700156
Björn Tereliusff612732018-04-25 14:23:01 +0000157 bool IsRtxSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700158
Björn Tereliusff612732018-04-25 14:23:01 +0000159 bool IsVideoSsrc(StreamId stream_id) const;
160
161 bool IsAudioSsrc(StreamId stream_id) const;
162
163 std::string GetStreamName(StreamId stream_id) const;
164
165 rtc::Optional<uint32_t> EstimateRtpClockFrequency(
166 const std::vector<LoggedRtpPacket>& packets) const;
terelius0740a202016-08-08 10:21:04 -0700167
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100168 float ToCallTime(int64_t timestamp) const;
169
Björn Tereliusff612732018-04-25 14:23:01 +0000170 void Notification(std::unique_ptr<TriageNotification> notification);
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100171
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800172 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
173
terelius54ce6802016-07-13 06:44:41 -0700174 const ParsedRtcEventLog& parsed_log_;
175
176 // A list of SSRCs we are interested in analysing.
177 // If left empty, all SSRCs will be considered relevant.
178 std::vector<uint32_t> desired_ssrc_;
179
Björn Tereliusff612732018-04-25 14:23:01 +0000180 // Tracks what each stream is configured for. Note that a single SSRC can be
181 // in several sets. For example, the SSRC used for sending video over RTX
182 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
183 // an SSRC is reconfigured to a different media type mid-call, it will also
184 // appear in multiple sets.
185 std::set<StreamId> rtx_ssrcs_;
186 std::set<StreamId> video_ssrcs_;
187 std::set<StreamId> audio_ssrcs_;
188
189 // Maps a stream identifier consisting of ssrc and direction to the parsed
190 // RTP headers in that stream. Header extensions are parsed if the stream
191 // has been configured.
192 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
193
194 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
195
196 // Maps an SSRC to the timestamps of parsed audio playout events.
197 std::map<uint32_t, std::vector<uint64_t>> audio_playout_events_;
198
henrik.lundin3c938fc2017-06-14 06:09:58 -0700199 // Stores the timestamps for all log segments, in the form of associated start
200 // and end events.
Björn Tereliusff612732018-04-25 14:23:01 +0000201 std::vector<std::pair<uint64_t, uint64_t>> log_segments_;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700202
Björn Tereliusff612732018-04-25 14:23:01 +0000203 // A list of all updates from the send-side loss-based bandwidth estimator.
204 std::vector<LossBasedBweUpdate> bwe_loss_updates_;
205
206 std::vector<AudioNetworkAdaptationEvent> audio_network_adaptation_events_;
207
208 std::vector<ParsedRtcEventLog::BweProbeClusterCreatedEvent>
209 bwe_probe_cluster_created_events_;
210
211 std::vector<ParsedRtcEventLog::BweProbeResultEvent> bwe_probe_result_events_;
212
213 std::vector<ParsedRtcEventLog::BweDelayBasedUpdate> bwe_delay_updates_;
214
215 std::vector<std::unique_ptr<TriageNotification>> notifications_;
216
217 std::vector<ParsedRtcEventLog::AlrStateEvent> alr_state_events_;
218
219 std::vector<ParsedRtcEventLog::IceCandidatePairConfig>
220 ice_candidate_pair_configs_;
221
222 std::vector<ParsedRtcEventLog::IceCandidatePairEvent>
223 ice_candidate_pair_events_;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800224
225 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
226
terelius54ce6802016-07-13 06:44:41 -0700227 // Window and step size used for calculating moving averages, e.g. bitrate.
228 // The generated data points will be |step_| microseconds apart.
229 // Only events occuring at most |window_duration_| microseconds before the
230 // current data point will be part of the average.
Björn Tereliusff612732018-04-25 14:23:01 +0000231 uint64_t window_duration_;
232 uint64_t step_;
terelius54ce6802016-07-13 06:44:41 -0700233
234 // First and last events of the log.
Björn Tereliusff612732018-04-25 14:23:01 +0000235 uint64_t begin_time_;
236 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700237
238 // Duration (in seconds) of log file.
239 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700240};
241
Björn Tereliusff612732018-04-25 14:23:01 +0000242} // namespace plotting
terelius54ce6802016-07-13 06:44:41 -0700243} // namespace webrtc
244
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200245#endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_