blob: 2853e86ad0e9d79aecd2a330f204cea17fbfcf44 [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
stefanc3de0332016-08-02 07:22:17 -070050 void CreateNetworkDelayFeebackGraph(Plot* plot);
51
terelius54ce6802016-07-13 06:44:41 -070052 private:
terelius88e64e52016-07-19 01:51:06 -070053 class StreamId {
54 public:
Stefan Holmer13181032016-07-29 14:48:54 +020055 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
56 : ssrc_(ssrc), direction_(direction) {}
terelius88e64e52016-07-19 01:51:06 -070057 bool operator<(const StreamId& other) const;
58 bool operator==(const StreamId& other) const;
59 uint32_t GetSsrc() const { return ssrc_; }
60 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -070061
62 private:
63 uint32_t ssrc_;
64 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -070065 };
66
67 struct LoggedRtpPacket {
Stefan Holmer13181032016-07-29 14:48:54 +020068 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
69 : timestamp(timestamp), header(header), total_length(total_length) {}
terelius88e64e52016-07-19 01:51:06 -070070 uint64_t timestamp;
71 RTPHeader header;
Stefan Holmer13181032016-07-29 14:48:54 +020072 size_t total_length;
73 };
74
75 struct LoggedRtcpPacket {
76 LoggedRtcpPacket(uint64_t timestamp,
77 RTCPPacketType rtcp_type,
78 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
79 : timestamp(timestamp),
80 type(rtcp_type),
81 packet(std::move(rtcp_packet)) {}
82 uint64_t timestamp;
83 RTCPPacketType type;
84 std::unique_ptr<rtcp::RtcpPacket> packet;
terelius88e64e52016-07-19 01:51:06 -070085 };
86
terelius8058e582016-07-25 01:32:41 -070087 struct BwePacketLossEvent {
88 uint64_t timestamp;
89 int32_t new_bitrate;
90 uint8_t fraction_loss;
91 int32_t expected_packets;
92 };
93
terelius54ce6802016-07-13 06:44:41 -070094 const ParsedRtcEventLog& parsed_log_;
95
96 // A list of SSRCs we are interested in analysing.
97 // If left empty, all SSRCs will be considered relevant.
98 std::vector<uint32_t> desired_ssrc_;
99
terelius88e64e52016-07-19 01:51:06 -0700100 // Maps a stream identifier consisting of ssrc, direction and MediaType
101 // to the parsed RTP headers in that stream. Header extensions are parsed
102 // if the stream has been configured.
103 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
104
Stefan Holmer13181032016-07-29 14:48:54 +0200105 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
106
terelius8058e582016-07-25 01:32:41 -0700107 // A list of all updates from the send-side loss-based bandwidth estimator.
108 std::vector<BwePacketLossEvent> bwe_loss_updates_;
109
terelius54ce6802016-07-13 06:44:41 -0700110 // Window and step size used for calculating moving averages, e.g. bitrate.
111 // The generated data points will be |step_| microseconds apart.
112 // Only events occuring at most |window_duration_| microseconds before the
113 // current data point will be part of the average.
114 uint64_t window_duration_;
115 uint64_t step_;
116
117 // First and last events of the log.
118 uint64_t begin_time_;
119 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700120
121 // Duration (in seconds) of log file.
122 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700123};
124
125} // namespace plotting
126} // namespace webrtc
127
128#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_