blob: 402f75f904a422370bb73c3029ad8df5eefa7bdf [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
21#include "webrtc/call/rtc_event_log_parser.h"
Stefan Holmer13181032016-07-29 14:48:54 +020022#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
23#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
terelius54ce6802016-07-13 06:44:41 -070024#include "webrtc/tools/event_log_visualizer/plot_base.h"
25
26namespace webrtc {
27namespace plotting {
28
tereliusccbbf8d2016-08-10 07:34:28 -070029struct LoggedRtpPacket {
30 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
31 : timestamp(timestamp), header(header), total_length(total_length) {}
32 uint64_t timestamp;
terelius6addf492016-08-23 17:34:07 -070033 // TODO(terelius): This allocates space for 15 CSRCs even if none are used.
tereliusccbbf8d2016-08-10 07:34:28 -070034 RTPHeader header;
35 size_t total_length;
36};
37
38struct LoggedRtcpPacket {
39 LoggedRtcpPacket(uint64_t timestamp,
40 RTCPPacketType rtcp_type,
41 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
42 : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {}
43 uint64_t timestamp;
44 RTCPPacketType type;
45 std::unique_ptr<rtcp::RtcpPacket> packet;
46};
47
48struct BwePacketLossEvent {
49 uint64_t timestamp;
50 int32_t new_bitrate;
51 uint8_t fraction_loss;
52 int32_t expected_packets;
53};
54
terelius54ce6802016-07-13 06:44:41 -070055class EventLogAnalyzer {
56 public:
57 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
58 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
59 // modified while the EventLogAnalyzer is being used.
60 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
61
62 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
63
philipelccd74892016-09-05 02:46:25 -070064 void CreateAccumulatedPacketsGraph(PacketDirection desired_direction,
65 Plot* plot);
66
terelius54ce6802016-07-13 06:44:41 -070067 void CreatePlayoutGraph(Plot* plot);
68
69 void CreateSequenceNumberGraph(Plot* plot);
70
Stefan Holmer99f8e082016-09-09 13:37:50 +020071 void CreateIncomingPacketLossGraph(Plot* plot);
72
terelius54ce6802016-07-13 06:44:41 -070073 void CreateDelayChangeGraph(Plot* plot);
74
75 void CreateAccumulatedDelayChangeGraph(Plot* plot);
76
tereliusf736d232016-08-04 10:00:11 -070077 void CreateFractionLossGraph(Plot* plot);
78
terelius54ce6802016-07-13 06:44:41 -070079 void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot);
80
81 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
82
tereliuse34c19c2016-08-15 08:47:14 -070083 void CreateBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020084
tereliuse34c19c2016-08-15 08:47:14 -070085 void CreateNetworkDelayFeedbackGraph(Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070086
terelius54ce6802016-07-13 06:44:41 -070087 private:
terelius88e64e52016-07-19 01:51:06 -070088 class StreamId {
89 public:
Stefan Holmer13181032016-07-29 14:48:54 +020090 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
91 : ssrc_(ssrc), direction_(direction) {}
terelius0740a202016-08-08 10:21:04 -070092 bool operator<(const StreamId& other) const {
93 return std::tie(ssrc_, direction_) <
94 std::tie(other.ssrc_, other.direction_);
95 }
96 bool operator==(const StreamId& other) const {
97 return std::tie(ssrc_, direction_) ==
98 std::tie(other.ssrc_, other.direction_);
99 }
terelius88e64e52016-07-19 01:51:06 -0700100 uint32_t GetSsrc() const { return ssrc_; }
101 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -0700102
103 private:
104 uint32_t ssrc_;
105 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -0700106 };
107
philipelccd74892016-09-05 02:46:25 -0700108 template <typename T>
109 void CreateAccumulatedPacketsTimeSeries(
110 PacketDirection desired_direction,
111 Plot* plot,
112 const std::map<StreamId, std::vector<T>>& packets,
113 const std::string& label_prefix);
114
Stefan Holmer99f8e082016-09-09 13:37:50 +0200115 bool IsRtxSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700116
Stefan Holmer99f8e082016-09-09 13:37:50 +0200117 bool IsVideoSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700118
Stefan Holmer99f8e082016-09-09 13:37:50 +0200119 bool IsAudioSsrc(StreamId stream_id) const;
120
121 std::string GetStreamName(StreamId) const;
terelius0740a202016-08-08 10:21:04 -0700122
terelius54ce6802016-07-13 06:44:41 -0700123 const ParsedRtcEventLog& parsed_log_;
124
125 // A list of SSRCs we are interested in analysing.
126 // If left empty, all SSRCs will be considered relevant.
127 std::vector<uint32_t> desired_ssrc_;
128
terelius0740a202016-08-08 10:21:04 -0700129 // Tracks what each stream is configured for. Note that a single SSRC can be
130 // in several sets. For example, the SSRC used for sending video over RTX
131 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
132 // an SSRC is reconfigured to a different media type mid-call, it will also
133 // appear in multiple sets.
134 std::set<StreamId> rtx_ssrcs_;
135 std::set<StreamId> video_ssrcs_;
136 std::set<StreamId> audio_ssrcs_;
137
138 // Maps a stream identifier consisting of ssrc and direction to the parsed
139 // RTP headers in that stream. Header extensions are parsed if the stream
140 // has been configured.
terelius88e64e52016-07-19 01:51:06 -0700141 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
142
Stefan Holmer13181032016-07-29 14:48:54 +0200143 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
144
terelius8058e582016-07-25 01:32:41 -0700145 // A list of all updates from the send-side loss-based bandwidth estimator.
146 std::vector<BwePacketLossEvent> bwe_loss_updates_;
147
terelius54ce6802016-07-13 06:44:41 -0700148 // Window and step size used for calculating moving averages, e.g. bitrate.
149 // The generated data points will be |step_| microseconds apart.
150 // Only events occuring at most |window_duration_| microseconds before the
151 // current data point will be part of the average.
152 uint64_t window_duration_;
153 uint64_t step_;
154
155 // First and last events of the log.
156 uint64_t begin_time_;
157 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700158
159 // Duration (in seconds) of log file.
160 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700161};
162
163} // namespace plotting
164} // namespace webrtc
165
166#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_