blob: dc56c5fd16debe647b72ff9c42da290f2dcd9693 [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
tereliusf736d232016-08-04 10:00:11 -070044 void CreateFractionLossGraph(Plot* plot);
45
terelius54ce6802016-07-13 06:44:41 -070046 void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot);
47
48 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
49
Stefan Holmer13181032016-07-29 14:48:54 +020050 void CreateBweGraph(Plot* plot);
51
stefanc3de0332016-08-02 07:22:17 -070052 void CreateNetworkDelayFeebackGraph(Plot* plot);
53
terelius54ce6802016-07-13 06:44:41 -070054 private:
terelius88e64e52016-07-19 01:51:06 -070055 class StreamId {
56 public:
Stefan Holmer13181032016-07-29 14:48:54 +020057 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
58 : ssrc_(ssrc), direction_(direction) {}
terelius88e64e52016-07-19 01:51:06 -070059 bool operator<(const StreamId& other) const;
60 bool operator==(const StreamId& other) const;
61 uint32_t GetSsrc() const { return ssrc_; }
62 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -070063
64 private:
65 uint32_t ssrc_;
66 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -070067 };
68
69 struct LoggedRtpPacket {
Stefan Holmer13181032016-07-29 14:48:54 +020070 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
71 : timestamp(timestamp), header(header), total_length(total_length) {}
terelius88e64e52016-07-19 01:51:06 -070072 uint64_t timestamp;
73 RTPHeader header;
Stefan Holmer13181032016-07-29 14:48:54 +020074 size_t total_length;
75 };
76
77 struct LoggedRtcpPacket {
78 LoggedRtcpPacket(uint64_t timestamp,
79 RTCPPacketType rtcp_type,
80 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
81 : timestamp(timestamp),
82 type(rtcp_type),
83 packet(std::move(rtcp_packet)) {}
84 uint64_t timestamp;
85 RTCPPacketType type;
86 std::unique_ptr<rtcp::RtcpPacket> packet;
terelius88e64e52016-07-19 01:51:06 -070087 };
88
terelius8058e582016-07-25 01:32:41 -070089 struct BwePacketLossEvent {
90 uint64_t timestamp;
91 int32_t new_bitrate;
92 uint8_t fraction_loss;
93 int32_t expected_packets;
94 };
95
terelius54ce6802016-07-13 06:44:41 -070096 const ParsedRtcEventLog& parsed_log_;
97
98 // A list of SSRCs we are interested in analysing.
99 // If left empty, all SSRCs will be considered relevant.
100 std::vector<uint32_t> desired_ssrc_;
101
terelius88e64e52016-07-19 01:51:06 -0700102 // Maps a stream identifier consisting of ssrc, direction and MediaType
103 // to the parsed RTP headers in that stream. Header extensions are parsed
104 // if the stream has been configured.
105 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
106
Stefan Holmer13181032016-07-29 14:48:54 +0200107 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
108
terelius8058e582016-07-25 01:32:41 -0700109 // A list of all updates from the send-side loss-based bandwidth estimator.
110 std::vector<BwePacketLossEvent> bwe_loss_updates_;
111
terelius54ce6802016-07-13 06:44:41 -0700112 // Window and step size used for calculating moving averages, e.g. bitrate.
113 // The generated data points will be |step_| microseconds apart.
114 // Only events occuring at most |window_duration_| microseconds before the
115 // current data point will be part of the average.
116 uint64_t window_duration_;
117 uint64_t step_;
118
119 // First and last events of the log.
120 uint64_t begin_time_;
121 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700122
123 // Duration (in seconds) of log file.
124 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700125};
126
127} // namespace plotting
128} // namespace webrtc
129
130#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_