blob: 74c0ff08759357f2ca0638128a3fbd041fd86a5c [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
71 void CreateDelayChangeGraph(Plot* plot);
72
73 void CreateAccumulatedDelayChangeGraph(Plot* plot);
74
tereliusf736d232016-08-04 10:00:11 -070075 void CreateFractionLossGraph(Plot* plot);
76
terelius54ce6802016-07-13 06:44:41 -070077 void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot);
78
79 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
80
tereliuse34c19c2016-08-15 08:47:14 -070081 void CreateBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020082
tereliuse34c19c2016-08-15 08:47:14 -070083 void CreateNetworkDelayFeedbackGraph(Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070084
terelius54ce6802016-07-13 06:44:41 -070085 private:
terelius88e64e52016-07-19 01:51:06 -070086 class StreamId {
87 public:
Stefan Holmer13181032016-07-29 14:48:54 +020088 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
89 : ssrc_(ssrc), direction_(direction) {}
terelius0740a202016-08-08 10:21:04 -070090 bool operator<(const StreamId& other) const {
91 return std::tie(ssrc_, direction_) <
92 std::tie(other.ssrc_, other.direction_);
93 }
94 bool operator==(const StreamId& other) const {
95 return std::tie(ssrc_, direction_) ==
96 std::tie(other.ssrc_, other.direction_);
97 }
terelius88e64e52016-07-19 01:51:06 -070098 uint32_t GetSsrc() const { return ssrc_; }
99 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -0700100
101 private:
102 uint32_t ssrc_;
103 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -0700104 };
105
philipelccd74892016-09-05 02:46:25 -0700106 template <typename T>
107 void CreateAccumulatedPacketsTimeSeries(
108 PacketDirection desired_direction,
109 Plot* plot,
110 const std::map<StreamId, std::vector<T>>& packets,
111 const std::string& label_prefix);
112
terelius0740a202016-08-08 10:21:04 -0700113 bool IsRtxSsrc(StreamId stream_id);
114
115 bool IsVideoSsrc(StreamId stream_id);
116
117 bool IsAudioSsrc(StreamId stream_id);
118
terelius54ce6802016-07-13 06:44:41 -0700119 const ParsedRtcEventLog& parsed_log_;
120
121 // A list of SSRCs we are interested in analysing.
122 // If left empty, all SSRCs will be considered relevant.
123 std::vector<uint32_t> desired_ssrc_;
124
terelius0740a202016-08-08 10:21:04 -0700125 // Tracks what each stream is configured for. Note that a single SSRC can be
126 // in several sets. For example, the SSRC used for sending video over RTX
127 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
128 // an SSRC is reconfigured to a different media type mid-call, it will also
129 // appear in multiple sets.
130 std::set<StreamId> rtx_ssrcs_;
131 std::set<StreamId> video_ssrcs_;
132 std::set<StreamId> audio_ssrcs_;
133
134 // Maps a stream identifier consisting of ssrc and direction to the parsed
135 // RTP headers in that stream. Header extensions are parsed if the stream
136 // has been configured.
terelius88e64e52016-07-19 01:51:06 -0700137 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
138
Stefan Holmer13181032016-07-29 14:48:54 +0200139 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
140
terelius8058e582016-07-25 01:32:41 -0700141 // A list of all updates from the send-side loss-based bandwidth estimator.
142 std::vector<BwePacketLossEvent> bwe_loss_updates_;
143
terelius54ce6802016-07-13 06:44:41 -0700144 // Window and step size used for calculating moving averages, e.g. bitrate.
145 // The generated data points will be |step_| microseconds apart.
146 // Only events occuring at most |window_duration_| microseconds before the
147 // current data point will be part of the average.
148 uint64_t window_duration_;
149 uint64_t step_;
150
151 // First and last events of the log.
152 uint64_t begin_time_;
153 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700154
155 // Duration (in seconds) of log file.
156 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700157};
158
159} // namespace plotting
160} // namespace webrtc
161
162#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_