blob: 4a1a2d60194c83b2fbf15305124501cb7af3cd69 [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>
terelius0740a202016-08-08 10:21:04 -070017#include <set>
Stefan Holmer13181032016-07-29 14:48:54 +020018#include <utility>
terelius54ce6802016-07-13 06:44:41 -070019
20#include "webrtc/call/rtc_event_log_parser.h"
Stefan Holmer13181032016-07-29 14:48:54 +020021#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
terelius54ce6802016-07-13 06:44:41 -070023#include "webrtc/tools/event_log_visualizer/plot_base.h"
24
25namespace webrtc {
26namespace plotting {
27
tereliusccbbf8d2016-08-10 07:34:28 -070028struct LoggedRtpPacket {
29 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
30 : timestamp(timestamp), header(header), total_length(total_length) {}
31 uint64_t timestamp;
32 RTPHeader header;
33 size_t total_length;
34};
35
36struct LoggedRtcpPacket {
37 LoggedRtcpPacket(uint64_t timestamp,
38 RTCPPacketType rtcp_type,
39 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
40 : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {}
41 uint64_t timestamp;
42 RTCPPacketType type;
43 std::unique_ptr<rtcp::RtcpPacket> packet;
44};
45
46struct BwePacketLossEvent {
47 uint64_t timestamp;
48 int32_t new_bitrate;
49 uint8_t fraction_loss;
50 int32_t expected_packets;
51};
52
terelius54ce6802016-07-13 06:44:41 -070053class EventLogAnalyzer {
54 public:
55 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
56 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
57 // modified while the EventLogAnalyzer is being used.
58 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
59
60 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
61
62 void CreatePlayoutGraph(Plot* plot);
63
64 void CreateSequenceNumberGraph(Plot* plot);
65
66 void CreateDelayChangeGraph(Plot* plot);
67
68 void CreateAccumulatedDelayChangeGraph(Plot* plot);
69
tereliusf736d232016-08-04 10:00:11 -070070 void CreateFractionLossGraph(Plot* plot);
71
terelius54ce6802016-07-13 06:44:41 -070072 void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot);
73
74 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
75
Stefan Holmer13181032016-07-29 14:48:54 +020076 void CreateBweGraph(Plot* plot);
77
stefanc3de0332016-08-02 07:22:17 -070078 void CreateNetworkDelayFeebackGraph(Plot* plot);
79
terelius54ce6802016-07-13 06:44:41 -070080 private:
terelius88e64e52016-07-19 01:51:06 -070081 class StreamId {
82 public:
Stefan Holmer13181032016-07-29 14:48:54 +020083 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
84 : ssrc_(ssrc), direction_(direction) {}
terelius0740a202016-08-08 10:21:04 -070085 bool operator<(const StreamId& other) const {
86 return std::tie(ssrc_, direction_) <
87 std::tie(other.ssrc_, other.direction_);
88 }
89 bool operator==(const StreamId& other) const {
90 return std::tie(ssrc_, direction_) ==
91 std::tie(other.ssrc_, other.direction_);
92 }
terelius88e64e52016-07-19 01:51:06 -070093 uint32_t GetSsrc() const { return ssrc_; }
94 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -070095
96 private:
97 uint32_t ssrc_;
98 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -070099 };
100
terelius0740a202016-08-08 10:21:04 -0700101 bool IsRtxSsrc(StreamId stream_id);
102
103 bool IsVideoSsrc(StreamId stream_id);
104
105 bool IsAudioSsrc(StreamId stream_id);
106
terelius54ce6802016-07-13 06:44:41 -0700107 const ParsedRtcEventLog& parsed_log_;
108
109 // A list of SSRCs we are interested in analysing.
110 // If left empty, all SSRCs will be considered relevant.
111 std::vector<uint32_t> desired_ssrc_;
112
terelius0740a202016-08-08 10:21:04 -0700113 // Tracks what each stream is configured for. Note that a single SSRC can be
114 // in several sets. For example, the SSRC used for sending video over RTX
115 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
116 // an SSRC is reconfigured to a different media type mid-call, it will also
117 // appear in multiple sets.
118 std::set<StreamId> rtx_ssrcs_;
119 std::set<StreamId> video_ssrcs_;
120 std::set<StreamId> audio_ssrcs_;
121
122 // Maps a stream identifier consisting of ssrc and direction to the parsed
123 // RTP headers in that stream. Header extensions are parsed if the stream
124 // has been configured.
terelius88e64e52016-07-19 01:51:06 -0700125 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
126
Stefan Holmer13181032016-07-29 14:48:54 +0200127 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
128
terelius8058e582016-07-25 01:32:41 -0700129 // A list of all updates from the send-side loss-based bandwidth estimator.
130 std::vector<BwePacketLossEvent> bwe_loss_updates_;
131
terelius54ce6802016-07-13 06:44:41 -0700132 // Window and step size used for calculating moving averages, e.g. bitrate.
133 // The generated data points will be |step_| microseconds apart.
134 // Only events occuring at most |window_duration_| microseconds before the
135 // current data point will be part of the average.
136 uint64_t window_duration_;
137 uint64_t step_;
138
139 // First and last events of the log.
140 uint64_t begin_time_;
141 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700142
143 // Duration (in seconds) of log file.
144 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700145};
146
147} // namespace plotting
148} // namespace webrtc
149
150#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_