blob: 15f1fa7ea47467f41eb94aaa55b08315d5bc893b [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"
terelius54ce6802016-07-13 06:44:41 -070027
28namespace webrtc {
29namespace plotting {
30
tereliusccbbf8d2016-08-10 07:34:28 -070031struct LoggedRtpPacket {
32 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
33 : timestamp(timestamp), header(header), total_length(total_length) {}
34 uint64_t timestamp;
terelius6addf492016-08-23 17:34:07 -070035 // TODO(terelius): This allocates space for 15 CSRCs even if none are used.
tereliusccbbf8d2016-08-10 07:34:28 -070036 RTPHeader header;
37 size_t total_length;
38};
39
40struct LoggedRtcpPacket {
41 LoggedRtcpPacket(uint64_t timestamp,
42 RTCPPacketType rtcp_type,
43 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
44 : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {}
45 uint64_t timestamp;
46 RTCPPacketType type;
47 std::unique_ptr<rtcp::RtcpPacket> packet;
48};
49
terelius424e6cf2017-02-20 05:14:41 -080050struct LossBasedBweUpdate {
tereliusccbbf8d2016-08-10 07:34:28 -070051 uint64_t timestamp;
52 int32_t new_bitrate;
53 uint8_t fraction_loss;
54 int32_t expected_packets;
55};
56
michaelt6e5b2192017-02-22 07:33:27 -080057struct AudioNetworkAdaptationEvent {
58 uint64_t timestamp;
michaeltcde46b72017-04-06 05:59:10 -070059 AudioEncoderRuntimeConfig config;
michaelt6e5b2192017-02-22 07:33:27 -080060};
61
terelius54ce6802016-07-13 06:44:41 -070062class EventLogAnalyzer {
63 public:
64 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
65 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
66 // modified while the EventLogAnalyzer is being used.
67 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
68
69 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
70
philipelccd74892016-09-05 02:46:25 -070071 void CreateAccumulatedPacketsGraph(PacketDirection desired_direction,
72 Plot* plot);
73
terelius54ce6802016-07-13 06:44:41 -070074 void CreatePlayoutGraph(Plot* plot);
75
ivocaac9d6f2016-09-22 07:01:47 -070076 void CreateAudioLevelGraph(Plot* plot);
77
terelius54ce6802016-07-13 06:44:41 -070078 void CreateSequenceNumberGraph(Plot* plot);
79
Stefan Holmer99f8e082016-09-09 13:37:50 +020080 void CreateIncomingPacketLossGraph(Plot* plot);
81
terelius2ee076d2017-08-15 02:04:02 -070082 void CreateIncomingDelayDeltaGraph(Plot* plot);
83 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070084
tereliusf736d232016-08-04 10:00:11 -070085 void CreateFractionLossGraph(Plot* plot);
86
philipel23c7f252017-07-14 06:30:03 -070087 void CreateTotalBitrateGraph(PacketDirection desired_direction,
88 Plot* plot,
89 bool show_detector_state = false);
terelius54ce6802016-07-13 06:44:41 -070090
91 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
92
Bjorn Terelius28db2662017-10-04 14:22:43 +020093 void CreateSendSideBweSimulationGraph(Plot* plot);
94 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020095
tereliuse34c19c2016-08-15 08:47:14 -070096 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +020097 void CreatePacerDelayGraph(Plot* plot);
stefane372d3c2017-02-02 08:04:18 -080098 void CreateTimestampGraph(Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070099
michaelt6e5b2192017-02-22 07:33:27 -0800100 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
101 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -0700102 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800103 void CreateAudioEncoderEnableFecGraph(Plot* plot);
104 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
105 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
henrik.lundin3c938fc2017-06-14 06:09:58 -0700106 void CreateAudioJitterBufferGraph(const std::string& replacement_file_name,
107 int file_sample_rate_hz,
108 Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800109
stefan08383272016-12-20 08:51:52 -0800110 // Returns a vector of capture and arrival timestamps for the video frames
111 // of the stream with the most number of frames.
112 std::vector<std::pair<int64_t, int64_t>> GetFrameTimestamps() const;
113
terelius54ce6802016-07-13 06:44:41 -0700114 private:
terelius88e64e52016-07-19 01:51:06 -0700115 class StreamId {
116 public:
Stefan Holmer13181032016-07-29 14:48:54 +0200117 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
118 : ssrc_(ssrc), direction_(direction) {}
terelius0740a202016-08-08 10:21:04 -0700119 bool operator<(const StreamId& other) const {
120 return std::tie(ssrc_, direction_) <
121 std::tie(other.ssrc_, other.direction_);
122 }
123 bool operator==(const StreamId& other) const {
124 return std::tie(ssrc_, direction_) ==
125 std::tie(other.ssrc_, other.direction_);
126 }
terelius88e64e52016-07-19 01:51:06 -0700127 uint32_t GetSsrc() const { return ssrc_; }
128 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -0700129
130 private:
131 uint32_t ssrc_;
132 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -0700133 };
134
philipelccd74892016-09-05 02:46:25 -0700135 template <typename T>
136 void CreateAccumulatedPacketsTimeSeries(
137 PacketDirection desired_direction,
138 Plot* plot,
139 const std::map<StreamId, std::vector<T>>& packets,
140 const std::string& label_prefix);
141
Stefan Holmer99f8e082016-09-09 13:37:50 +0200142 bool IsRtxSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700143
Stefan Holmer99f8e082016-09-09 13:37:50 +0200144 bool IsVideoSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700145
Stefan Holmer99f8e082016-09-09 13:37:50 +0200146 bool IsAudioSsrc(StreamId stream_id) const;
147
Bjorn Terelius0295a962017-10-25 17:42:41 +0200148 std::string GetStreamName(StreamId stream_id) const;
149
150 rtc::Optional<uint32_t> EstimateRtpClockFrequency(
151 const std::vector<LoggedRtpPacket>& packets) const;
terelius0740a202016-08-08 10:21:04 -0700152
terelius54ce6802016-07-13 06:44:41 -0700153 const ParsedRtcEventLog& parsed_log_;
154
155 // A list of SSRCs we are interested in analysing.
156 // If left empty, all SSRCs will be considered relevant.
157 std::vector<uint32_t> desired_ssrc_;
158
terelius0740a202016-08-08 10:21:04 -0700159 // Tracks what each stream is configured for. Note that a single SSRC can be
160 // in several sets. For example, the SSRC used for sending video over RTX
161 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
162 // an SSRC is reconfigured to a different media type mid-call, it will also
163 // appear in multiple sets.
164 std::set<StreamId> rtx_ssrcs_;
165 std::set<StreamId> video_ssrcs_;
166 std::set<StreamId> audio_ssrcs_;
167
168 // Maps a stream identifier consisting of ssrc and direction to the parsed
169 // RTP headers in that stream. Header extensions are parsed if the stream
170 // has been configured.
terelius88e64e52016-07-19 01:51:06 -0700171 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
172
Stefan Holmer13181032016-07-29 14:48:54 +0200173 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
174
henrik.lundin3c938fc2017-06-14 06:09:58 -0700175 // Maps an SSRC to the timestamps of parsed audio playout events.
176 std::map<uint32_t, std::vector<uint64_t>> audio_playout_events_;
177
178 // Stores the timestamps for all log segments, in the form of associated start
179 // and end events.
180 std::vector<std::pair<uint64_t, uint64_t>> log_segments_;
181
terelius8058e582016-07-25 01:32:41 -0700182 // A list of all updates from the send-side loss-based bandwidth estimator.
terelius424e6cf2017-02-20 05:14:41 -0800183 std::vector<LossBasedBweUpdate> bwe_loss_updates_;
terelius8058e582016-07-25 01:32:41 -0700184
michaelt6e5b2192017-02-22 07:33:27 -0800185 std::vector<AudioNetworkAdaptationEvent> audio_network_adaptation_events_;
186
philipele127e7a2017-03-29 16:28:53 +0200187 std::vector<ParsedRtcEventLog::BweProbeClusterCreatedEvent>
188 bwe_probe_cluster_created_events_;
189
190 std::vector<ParsedRtcEventLog::BweProbeResultEvent> bwe_probe_result_events_;
191
philipel10fc0e62017-04-11 01:50:23 -0700192 std::vector<ParsedRtcEventLog::BweDelayBasedUpdate> bwe_delay_updates_;
193
terelius54ce6802016-07-13 06:44:41 -0700194 // Window and step size used for calculating moving averages, e.g. bitrate.
195 // The generated data points will be |step_| microseconds apart.
196 // Only events occuring at most |window_duration_| microseconds before the
197 // current data point will be part of the average.
198 uint64_t window_duration_;
199 uint64_t step_;
200
201 // First and last events of the log.
202 uint64_t begin_time_;
203 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700204
205 // Duration (in seconds) of log file.
206 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700207};
208
209} // namespace plotting
210} // namespace webrtc
211
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200212#endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_