blob: 988f2cb482151aaa87288cf27ef119c7e5f38527 [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
terelius88e64e52016-07-19 01:51:06 -070014#include <map>
Stefan Holmer13181032016-07-29 14:48:54 +020015#include <memory>
terelius0740a202016-08-08 10:21:04 -070016#include <set>
philipelccd74892016-09-05 02:46:25 -070017#include <string>
Stefan Holmer13181032016-07-29 14:48:54 +020018#include <utility>
philipelccd74892016-09-05 02:46:25 -070019#include <vector>
terelius54ce6802016-07-13 06:44:41 -070020
michaelt6e5b2192017-02-22 07:33:27 -080021#include "webrtc/base/function_view.h"
skvladcc91d282016-10-03 18:31:22 -070022#include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h"
michaeltcde46b72017-04-06 05:59:10 -070023#include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h"
Stefan Holmer13181032016-07-29 14:48:54 +020024#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
25#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
terelius54ce6802016-07-13 06:44:41 -070026#include "webrtc/tools/event_log_visualizer/plot_base.h"
27
28namespace webrtc {
29namespace plotting {
30
tereliusccbbf8d2016-08-10 07:34:28 -070031struct LoggedRtpPacket {
32 LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length)
33 : timestamp(timestamp), header(header), total_length(total_length) {}
34 uint64_t timestamp;
terelius6addf492016-08-23 17:34:07 -070035 // TODO(terelius): This allocates space for 15 CSRCs even if none are used.
tereliusccbbf8d2016-08-10 07:34:28 -070036 RTPHeader header;
37 size_t total_length;
38};
39
40struct LoggedRtcpPacket {
41 LoggedRtcpPacket(uint64_t timestamp,
42 RTCPPacketType rtcp_type,
43 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet)
44 : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {}
45 uint64_t timestamp;
46 RTCPPacketType type;
47 std::unique_ptr<rtcp::RtcpPacket> packet;
48};
49
terelius424e6cf2017-02-20 05:14:41 -080050struct LossBasedBweUpdate {
tereliusccbbf8d2016-08-10 07:34:28 -070051 uint64_t timestamp;
52 int32_t new_bitrate;
53 uint8_t fraction_loss;
54 int32_t expected_packets;
55};
56
michaelt6e5b2192017-02-22 07:33:27 -080057struct AudioNetworkAdaptationEvent {
58 uint64_t timestamp;
michaeltcde46b72017-04-06 05:59:10 -070059 AudioEncoderRuntimeConfig config;
michaelt6e5b2192017-02-22 07:33:27 -080060};
61
terelius54ce6802016-07-13 06:44:41 -070062class EventLogAnalyzer {
63 public:
64 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the
65 // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or
66 // modified while the EventLogAnalyzer is being used.
67 explicit EventLogAnalyzer(const ParsedRtcEventLog& log);
68
69 void CreatePacketGraph(PacketDirection desired_direction, Plot* plot);
70
philipelccd74892016-09-05 02:46:25 -070071 void CreateAccumulatedPacketsGraph(PacketDirection desired_direction,
72 Plot* plot);
73
terelius54ce6802016-07-13 06:44:41 -070074 void CreatePlayoutGraph(Plot* plot);
75
ivocaac9d6f2016-09-22 07:01:47 -070076 void CreateAudioLevelGraph(Plot* plot);
77
terelius54ce6802016-07-13 06:44:41 -070078 void CreateSequenceNumberGraph(Plot* plot);
79
Stefan Holmer99f8e082016-09-09 13:37:50 +020080 void CreateIncomingPacketLossGraph(Plot* plot);
81
terelius54ce6802016-07-13 06:44:41 -070082 void CreateDelayChangeGraph(Plot* plot);
83
84 void CreateAccumulatedDelayChangeGraph(Plot* plot);
85
tereliusf736d232016-08-04 10:00:11 -070086 void CreateFractionLossGraph(Plot* plot);
87
terelius54ce6802016-07-13 06:44:41 -070088 void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot);
89
90 void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot);
91
tereliuse34c19c2016-08-15 08:47:14 -070092 void CreateBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020093
tereliuse34c19c2016-08-15 08:47:14 -070094 void CreateNetworkDelayFeedbackGraph(Plot* plot);
stefane372d3c2017-02-02 08:04:18 -080095 void CreateTimestampGraph(Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070096
michaelt6e5b2192017-02-22 07:33:27 -080097 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
98 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
99 void CreateAudioEncoderUplinkPacketLossFractionGraph(Plot* plot);
100 void CreateAudioEncoderEnableFecGraph(Plot* plot);
101 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
102 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
103
stefan08383272016-12-20 08:51:52 -0800104 // Returns a vector of capture and arrival timestamps for the video frames
105 // of the stream with the most number of frames.
106 std::vector<std::pair<int64_t, int64_t>> GetFrameTimestamps() const;
107
terelius54ce6802016-07-13 06:44:41 -0700108 private:
terelius88e64e52016-07-19 01:51:06 -0700109 class StreamId {
110 public:
Stefan Holmer13181032016-07-29 14:48:54 +0200111 StreamId(uint32_t ssrc, webrtc::PacketDirection direction)
112 : ssrc_(ssrc), direction_(direction) {}
terelius0740a202016-08-08 10:21:04 -0700113 bool operator<(const StreamId& other) const {
114 return std::tie(ssrc_, direction_) <
115 std::tie(other.ssrc_, other.direction_);
116 }
117 bool operator==(const StreamId& other) const {
118 return std::tie(ssrc_, direction_) ==
119 std::tie(other.ssrc_, other.direction_);
120 }
terelius88e64e52016-07-19 01:51:06 -0700121 uint32_t GetSsrc() const { return ssrc_; }
122 webrtc::PacketDirection GetDirection() const { return direction_; }
terelius88e64e52016-07-19 01:51:06 -0700123
124 private:
125 uint32_t ssrc_;
126 webrtc::PacketDirection direction_;
terelius88e64e52016-07-19 01:51:06 -0700127 };
128
philipelccd74892016-09-05 02:46:25 -0700129 template <typename T>
130 void CreateAccumulatedPacketsTimeSeries(
131 PacketDirection desired_direction,
132 Plot* plot,
133 const std::map<StreamId, std::vector<T>>& packets,
134 const std::string& label_prefix);
135
Stefan Holmer99f8e082016-09-09 13:37:50 +0200136 bool IsRtxSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700137
Stefan Holmer99f8e082016-09-09 13:37:50 +0200138 bool IsVideoSsrc(StreamId stream_id) const;
terelius0740a202016-08-08 10:21:04 -0700139
Stefan Holmer99f8e082016-09-09 13:37:50 +0200140 bool IsAudioSsrc(StreamId stream_id) const;
141
142 std::string GetStreamName(StreamId) const;
terelius0740a202016-08-08 10:21:04 -0700143
terelius54ce6802016-07-13 06:44:41 -0700144 const ParsedRtcEventLog& parsed_log_;
145
146 // A list of SSRCs we are interested in analysing.
147 // If left empty, all SSRCs will be considered relevant.
148 std::vector<uint32_t> desired_ssrc_;
149
terelius0740a202016-08-08 10:21:04 -0700150 // Tracks what each stream is configured for. Note that a single SSRC can be
151 // in several sets. For example, the SSRC used for sending video over RTX
152 // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that
153 // an SSRC is reconfigured to a different media type mid-call, it will also
154 // appear in multiple sets.
155 std::set<StreamId> rtx_ssrcs_;
156 std::set<StreamId> video_ssrcs_;
157 std::set<StreamId> audio_ssrcs_;
158
159 // Maps a stream identifier consisting of ssrc and direction to the parsed
160 // RTP headers in that stream. Header extensions are parsed if the stream
161 // has been configured.
terelius88e64e52016-07-19 01:51:06 -0700162 std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_;
163
Stefan Holmer13181032016-07-29 14:48:54 +0200164 std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_;
165
terelius8058e582016-07-25 01:32:41 -0700166 // A list of all updates from the send-side loss-based bandwidth estimator.
terelius424e6cf2017-02-20 05:14:41 -0800167 std::vector<LossBasedBweUpdate> bwe_loss_updates_;
terelius8058e582016-07-25 01:32:41 -0700168
michaelt6e5b2192017-02-22 07:33:27 -0800169 std::vector<AudioNetworkAdaptationEvent> audio_network_adaptation_events_;
170
philipele127e7a2017-03-29 16:28:53 +0200171 std::vector<ParsedRtcEventLog::BweProbeClusterCreatedEvent>
172 bwe_probe_cluster_created_events_;
173
174 std::vector<ParsedRtcEventLog::BweProbeResultEvent> bwe_probe_result_events_;
175
philipel10fc0e62017-04-11 01:50:23 -0700176 std::vector<ParsedRtcEventLog::BweDelayBasedUpdate> bwe_delay_updates_;
177
terelius54ce6802016-07-13 06:44:41 -0700178 // Window and step size used for calculating moving averages, e.g. bitrate.
179 // The generated data points will be |step_| microseconds apart.
180 // Only events occuring at most |window_duration_| microseconds before the
181 // current data point will be part of the average.
182 uint64_t window_duration_;
183 uint64_t step_;
184
185 // First and last events of the log.
186 uint64_t begin_time_;
187 uint64_t end_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700188
189 // Duration (in seconds) of log file.
190 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700191};
192
193} // namespace plotting
194} // namespace webrtc
195
196#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_