blob: 1acf756133a8c130cd895e12772daee9e5c5aff6 [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
11#ifndef WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_
12#define WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_
13
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
michaelt6e5b2192017-02-22 07:33:27 -080021#include "webrtc/base/function_view.h"
skvladcc91d282016-10-03 18:31:22 -070022#include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h"
Stefan Holmer13181032016-07-29 14:48:54 +020023#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
24#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
terelius54ce6802016-07-13 06:44:41 -070025#include "webrtc/tools/event_log_visualizer/plot_base.h"
26
27namespace webrtc {
28namespace plotting {
29
tereliusccbbf8d2016-08-10 07:34:28 -070030struct LoggedRtpPacket {
31 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
32 : timestamp(timestamp), header(header), total_length(total_length) {}
33 uint64_t timestamp;
terelius6addf492016-08-23 17:34:07 -070034 // TODO(terelius): This allocates space for 15 CSRCs even if none are used.
tereliusccbbf8d2016-08-10 07:34:28 -070035 RTPHeader header;
36 size_t total_length;
37};
38
39struct LoggedRtcpPacket {
40 LoggedRtcpPacket(uint64_t timestamp,
41 RTCPPacketType rtcp_type,
42 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
43 : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {}
44 uint64_t timestamp;
45 RTCPPacketType type;
46 std::unique_ptr<rtcp::RtcpPacket> packet;
47};
48
terelius424e6cf2017-02-20 05:14:41 -080049struct LossBasedBweUpdate {
tereliusccbbf8d2016-08-10 07:34:28 -070050 uint64_t timestamp;
51 int32_t new_bitrate;
52 uint8_t fraction_loss;
53 int32_t expected_packets;
54};
55
michaelt6e5b2192017-02-22 07:33:27 -080056struct AudioNetworkAdaptationEvent {
57 uint64_t timestamp;
58 AudioNetworkAdaptor::EncoderRuntimeConfig config;
59};
60
terelius54ce6802016-07-13 06:44:41 -070061class EventLogAnalyzer {
62 public:
63 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
64 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
65 // modified while the EventLogAnalyzer is being used.
66 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
67
68 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
69
philipelccd74892016-09-05 02:46:25 -070070 void CreateAccumulatedPacketsGraph(PacketDirection desired_direction,
71 Plot* plot);
72
terelius54ce6802016-07-13 06:44:41 -070073 void CreatePlayoutGraph(Plot* plot);
74
ivocaac9d6f2016-09-22 07:01:47 -070075 void CreateAudioLevelGraph(Plot* plot);
76
terelius54ce6802016-07-13 06:44:41 -070077 void CreateSequenceNumberGraph(Plot* plot);
78
Stefan Holmer99f8e082016-09-09 13:37:50 +020079 void CreateIncomingPacketLossGraph(Plot* plot);
80
terelius54ce6802016-07-13 06:44:41 -070081 void CreateDelayChangeGraph(Plot* plot);
82
83 void CreateAccumulatedDelayChangeGraph(Plot* plot);
84
tereliusf736d232016-08-04 10:00:11 -070085 void CreateFractionLossGraph(Plot* plot);
86
terelius54ce6802016-07-13 06:44:41 -070087 void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot);
88
89 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
90
tereliuse34c19c2016-08-15 08:47:14 -070091 void CreateBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020092
tereliuse34c19c2016-08-15 08:47:14 -070093 void CreateNetworkDelayFeedbackGraph(Plot* plot);
stefane372d3c2017-02-02 08:04:18 -080094 void CreateTimestampGraph(Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070095
michaelt6e5b2192017-02-22 07:33:27 -080096 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
97 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
98 void CreateAudioEncoderUplinkPacketLossFractionGraph(Plot* plot);
99 void CreateAudioEncoderEnableFecGraph(Plot* plot);
100 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
101 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
102
stefan08383272016-12-20 08:51:52 -0800103 // Returns a vector of capture and arrival timestamps for the video frames
104 // of the stream with the most number of frames.
105 std::vector<std::pair<int64_t, int64_t>> GetFrameTimestamps() const;
106
terelius54ce6802016-07-13 06:44:41 -0700107 private:
terelius88e64e52016-07-19 01:51:06 -0700108 class StreamId {
109 public:
Stefan Holmer13181032016-07-29 14:48:54 +0200110 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
111 : ssrc_(ssrc), direction_(direction) {}
terelius0740a202016-08-08 10:21:04 -0700112 bool operator<(const StreamId& other) const {
113 return std::tie(ssrc_, direction_) <
114 std::tie(other.ssrc_, other.direction_);
115 }
116 bool operator==(const StreamId& other) const {
117 return std::tie(ssrc_, direction_) ==
118 std::tie(other.ssrc_, other.direction_);
119 }
terelius88e64e52016-07-19 01:51:06 -0700120 uint32_t GetSsrc() const { return ssrc_; }
121 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -0700122
123 private:
124 uint32_t ssrc_;
125 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -0700126 };
127
philipelccd74892016-09-05 02:46:25 -0700128 template <typename T>
129 void CreateAccumulatedPacketsTimeSeries(
130 PacketDirection desired_direction,
131 Plot* plot,
132 const std::map<StreamId, std::vector<T>>& packets,
133 const std::string& label_prefix);
134
Stefan Holmer99f8e082016-09-09 13:37:50 +0200135 bool IsRtxSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700136
Stefan Holmer99f8e082016-09-09 13:37:50 +0200137 bool IsVideoSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700138
Stefan Holmer99f8e082016-09-09 13:37:50 +0200139 bool IsAudioSsrc(StreamId stream_id) const;
140
141 std::string GetStreamName(StreamId) const;
terelius0740a202016-08-08 10:21:04 -0700142
terelius54ce6802016-07-13 06:44:41 -0700143 const ParsedRtcEventLog& parsed_log_;
144
145 // A list of SSRCs we are interested in analysing.
146 // If left empty, all SSRCs will be considered relevant.
147 std::vector<uint32_t> desired_ssrc_;
148
terelius0740a202016-08-08 10:21:04 -0700149 // Tracks what each stream is configured for. Note that a single SSRC can be
150 // in several sets. For example, the SSRC used for sending video over RTX
151 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
152 // an SSRC is reconfigured to a different media type mid-call, it will also
153 // appear in multiple sets.
154 std::set<StreamId> rtx_ssrcs_;
155 std::set<StreamId> video_ssrcs_;
156 std::set<StreamId> audio_ssrcs_;
157
158 // Maps a stream identifier consisting of ssrc and direction to the parsed
159 // RTP headers in that stream. Header extensions are parsed if the stream
160 // has been configured.
terelius88e64e52016-07-19 01:51:06 -0700161 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
162
Stefan Holmer13181032016-07-29 14:48:54 +0200163 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
164
terelius8058e582016-07-25 01:32:41 -0700165 // A list of all updates from the send-side loss-based bandwidth estimator.
terelius424e6cf2017-02-20 05:14:41 -0800166 std::vector<LossBasedBweUpdate> bwe_loss_updates_;
terelius8058e582016-07-25 01:32:41 -0700167
michaelt6e5b2192017-02-22 07:33:27 -0800168 std::vector<AudioNetworkAdaptationEvent> audio_network_adaptation_events_;
169
philipele127e7a2017-03-29 16:28:53 +0200170 std::vector<ParsedRtcEventLog::BweProbeClusterCreatedEvent>
171 bwe_probe_cluster_created_events_;
172
173 std::vector<ParsedRtcEventLog::BweProbeResultEvent> bwe_probe_result_events_;
174
terelius54ce6802016-07-13 06:44:41 -0700175 // Window and step size used for calculating moving averages, e.g. bitrate.
176 // The generated data points will be |step_| microseconds apart.
177 // Only events occuring at most |window_duration_| microseconds before the
178 // current data point will be part of the average.
179 uint64_t window_duration_;
180 uint64_t step_;
181
182 // First and last events of the log.
183 uint64_t begin_time_;
184 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700185
186 // Duration (in seconds) of log file.
187 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700188};
189
190} // namespace plotting
191} // namespace webrtc
192
193#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_