blob: bb4db2b824825240c7738b224aff5acf15993fea [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
14#include <vector>
terelius88e64e52016-07-19 01:51:06 -070015#include <map>
Stefan Holmer13181032016-07-29 14:48:54 +020016#include <memory>
17#include <utility>
terelius54ce6802016-07-13 06:44:41 -070018
19#include "webrtc/call/rtc_event_log_parser.h"
Stefan Holmer13181032016-07-29 14:48:54 +020020#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
21#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
terelius54ce6802016-07-13 06:44:41 -070022#include "webrtc/tools/event_log_visualizer/plot_base.h"
23
24namespace webrtc {
25namespace plotting {
26
27class EventLogAnalyzer {
28 public:
29 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
30 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
31 // modified while the EventLogAnalyzer is being used.
32 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
33
34 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
35
36 void CreatePlayoutGraph(Plot* plot);
37
38 void CreateSequenceNumberGraph(Plot* plot);
39
40 void CreateDelayChangeGraph(Plot* plot);
41
42 void CreateAccumulatedDelayChangeGraph(Plot* plot);
43
44 void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot);
45
46 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
47
Stefan Holmer13181032016-07-29 14:48:54 +020048 void CreateBweGraph(Plot* plot);
49
terelius54ce6802016-07-13 06:44:41 -070050 private:
terelius88e64e52016-07-19 01:51:06 -070051 class StreamId {
52 public:
Stefan Holmer13181032016-07-29 14:48:54 +020053 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
54 : ssrc_(ssrc), direction_(direction) {}
terelius88e64e52016-07-19 01:51:06 -070055 bool operator<(const StreamId& other) const;
56 bool operator==(const StreamId& other) const;
57 uint32_t GetSsrc() const { return ssrc_; }
58 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -070059
60 private:
61 uint32_t ssrc_;
62 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -070063 };
64
65 struct LoggedRtpPacket {
Stefan Holmer13181032016-07-29 14:48:54 +020066 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
67 : timestamp(timestamp), header(header), total_length(total_length) {}
terelius88e64e52016-07-19 01:51:06 -070068 uint64_t timestamp;
69 RTPHeader header;
Stefan Holmer13181032016-07-29 14:48:54 +020070 size_t total_length;
71 };
72
73 struct LoggedRtcpPacket {
74 LoggedRtcpPacket(uint64_t timestamp,
75 RTCPPacketType rtcp_type,
76 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
77 : timestamp(timestamp),
78 type(rtcp_type),
79 packet(std::move(rtcp_packet)) {}
80 uint64_t timestamp;
81 RTCPPacketType type;
82 std::unique_ptr<rtcp::RtcpPacket> packet;
terelius88e64e52016-07-19 01:51:06 -070083 };
84
terelius8058e582016-07-25 01:32:41 -070085 struct BwePacketLossEvent {
86 uint64_t timestamp;
87 int32_t new_bitrate;
88 uint8_t fraction_loss;
89 int32_t expected_packets;
90 };
91
terelius54ce6802016-07-13 06:44:41 -070092 const ParsedRtcEventLog& parsed_log_;
93
94 // A list of SSRCs we are interested in analysing.
95 // If left empty, all SSRCs will be considered relevant.
96 std::vector<uint32_t> desired_ssrc_;
97
terelius88e64e52016-07-19 01:51:06 -070098 // Maps a stream identifier consisting of ssrc, direction and MediaType
99 // to the parsed RTP headers in that stream. Header extensions are parsed
100 // if the stream has been configured.
101 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
102
Stefan Holmer13181032016-07-29 14:48:54 +0200103 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
104
terelius8058e582016-07-25 01:32:41 -0700105 // A list of all updates from the send-side loss-based bandwidth estimator.
106 std::vector<BwePacketLossEvent> bwe_loss_updates_;
107
terelius54ce6802016-07-13 06:44:41 -0700108 // Window and step size used for calculating moving averages, e.g. bitrate.
109 // The generated data points will be |step_| microseconds apart.
110 // Only events occuring at most |window_duration_| microseconds before the
111 // current data point will be part of the average.
112 uint64_t window_duration_;
113 uint64_t step_;
114
115 // First and last events of the log.
116 uint64_t begin_time_;
117 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700118
119 // Duration (in seconds) of log file.
120 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700121};
122
123} // namespace plotting
124} // namespace webrtc
125
126#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_