blob: ce2179f5fb60030c35b8e9f493fb9e133a65d9d3 [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
28class EventLogAnalyzer {
29 public:
30 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
31 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
32 // modified while the EventLogAnalyzer is being used.
33 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
34
35 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
36
37 void CreatePlayoutGraph(Plot* plot);
38
39 void CreateSequenceNumberGraph(Plot* plot);
40
41 void CreateDelayChangeGraph(Plot* plot);
42
43 void CreateAccumulatedDelayChangeGraph(Plot* plot);
44
tereliusf736d232016-08-04 10:00:11 -070045 void CreateFractionLossGraph(Plot* plot);
46
terelius54ce6802016-07-13 06:44:41 -070047 void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot);
48
49 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
50
Stefan Holmer13181032016-07-29 14:48:54 +020051 void CreateBweGraph(Plot* plot);
52
stefanc3de0332016-08-02 07:22:17 -070053 void CreateNetworkDelayFeebackGraph(Plot* plot);
54
terelius54ce6802016-07-13 06:44:41 -070055 private:
terelius88e64e52016-07-19 01:51:06 -070056 class StreamId {
57 public:
Stefan Holmer13181032016-07-29 14:48:54 +020058 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
59 : ssrc_(ssrc), direction_(direction) {}
terelius0740a202016-08-08 10:21:04 -070060 bool operator<(const StreamId& other) const {
61 return std::tie(ssrc_, direction_) <
62 std::tie(other.ssrc_, other.direction_);
63 }
64 bool operator==(const StreamId& other) const {
65 return std::tie(ssrc_, direction_) ==
66 std::tie(other.ssrc_, other.direction_);
67 }
terelius88e64e52016-07-19 01:51:06 -070068 uint32_t GetSsrc() const { return ssrc_; }
69 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -070070
71 private:
72 uint32_t ssrc_;
73 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -070074 };
75
76 struct LoggedRtpPacket {
Stefan Holmer13181032016-07-29 14:48:54 +020077 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
78 : timestamp(timestamp), header(header), total_length(total_length) {}
terelius88e64e52016-07-19 01:51:06 -070079 uint64_t timestamp;
80 RTPHeader header;
Stefan Holmer13181032016-07-29 14:48:54 +020081 size_t total_length;
82 };
83
84 struct LoggedRtcpPacket {
85 LoggedRtcpPacket(uint64_t timestamp,
86 RTCPPacketType rtcp_type,
87 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
88 : timestamp(timestamp),
89 type(rtcp_type),
90 packet(std::move(rtcp_packet)) {}
91 uint64_t timestamp;
92 RTCPPacketType type;
93 std::unique_ptr<rtcp::RtcpPacket> packet;
terelius88e64e52016-07-19 01:51:06 -070094 };
95
terelius8058e582016-07-25 01:32:41 -070096 struct BwePacketLossEvent {
97 uint64_t timestamp;
98 int32_t new_bitrate;
99 uint8_t fraction_loss;
100 int32_t expected_packets;
101 };
102
terelius0740a202016-08-08 10:21:04 -0700103 bool IsRtxSsrc(StreamId stream_id);
104
105 bool IsVideoSsrc(StreamId stream_id);
106
107 bool IsAudioSsrc(StreamId stream_id);
108
terelius54ce6802016-07-13 06:44:41 -0700109 const ParsedRtcEventLog& parsed_log_;
110
111 // A list of SSRCs we are interested in analysing.
112 // If left empty, all SSRCs will be considered relevant.
113 std::vector<uint32_t> desired_ssrc_;
114
terelius0740a202016-08-08 10:21:04 -0700115 // Tracks what each stream is configured for. Note that a single SSRC can be
116 // in several sets. For example, the SSRC used for sending video over RTX
117 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
118 // an SSRC is reconfigured to a different media type mid-call, it will also
119 // appear in multiple sets.
120 std::set<StreamId> rtx_ssrcs_;
121 std::set<StreamId> video_ssrcs_;
122 std::set<StreamId> audio_ssrcs_;
123
124 // Maps a stream identifier consisting of ssrc and direction to the parsed
125 // RTP headers in that stream. Header extensions are parsed if the stream
126 // has been configured.
terelius88e64e52016-07-19 01:51:06 -0700127 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
128
Stefan Holmer13181032016-07-29 14:48:54 +0200129 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
130
terelius8058e582016-07-25 01:32:41 -0700131 // A list of all updates from the send-side loss-based bandwidth estimator.
132 std::vector<BwePacketLossEvent> bwe_loss_updates_;
133
terelius54ce6802016-07-13 06:44:41 -0700134 // Window and step size used for calculating moving averages, e.g. bitrate.
135 // The generated data points will be |step_| microseconds apart.
136 // Only events occuring at most |window_duration_| microseconds before the
137 // current data point will be part of the average.
138 uint64_t window_duration_;
139 uint64_t step_;
140
141 // First and last events of the log.
142 uint64_t begin_time_;
143 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700144
145 // Duration (in seconds) of log file.
146 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700147};
148
149} // namespace plotting
150} // namespace webrtc
151
152#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_