blob: 59f64efb781f15d46f0ed3772a28ee2e8a18adf0 [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
Mirko Bonadei575998c2019-07-25 13:57:41 +020011#include "rtc_tools/rtc_event_log_visualizer/analyzer.h"
terelius54ce6802016-07-13 06:44:41 -070012
13#include <algorithm>
Oleh Prypin6581f212017-11-16 00:17:05 +010014#include <cmath>
terelius54ce6802016-07-13 06:44:41 -070015#include <limits>
16#include <map>
Mirko Bonadei317a1f02019-09-17 17:06:18 +020017#include <memory>
terelius54ce6802016-07-13 06:44:41 -070018#include <string>
19#include <utility>
20
Björn Tereliusc69c1bb2019-10-11 15:06:58 +020021#include "absl/algorithm/container.h"
Per Kjellanderfe2063e2021-05-12 09:02:43 +020022#include "absl/functional/bind_front.h"
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +010023#include "absl/strings/string_view.h"
Artem Titov741daaf2019-03-21 14:37:36 +010024#include "api/function_view.h"
Niels Möller0d863f72020-11-24 17:50:31 +010025#include "api/network_state_predictor.h"
Sebastian Jansson95edb032019-01-17 16:24:12 +010026#include "api/transport/field_trial_based_config.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020027#include "api/transport/goog_cc_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "call/audio_receive_stream.h"
29#include "call/audio_send_stream.h"
30#include "call/call.h"
31#include "call/video_receive_stream.h"
32#include "call/video_send_stream.h"
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +020033#include "logging/rtc_event_log/rtc_event_processor.h"
Elad Alon99a81b62017-09-21 10:25:29 +020034#include "logging/rtc_event_log/rtc_stream_config.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020035#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h"
Sebastian Jansson172fd852018-05-24 14:17:06 +020036#include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h"
37#include "modules/congestion_controller/goog_cc/bitrate_estimator.h"
Sebastian Jansson04b18cb2018-07-02 09:25:25 +020038#include "modules/congestion_controller/goog_cc/delay_based_bwe.h"
Bjorn Terelius28db2662017-10-04 14:22:43 +020039#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020040#include "modules/congestion_controller/rtp/transport_feedback_adapter.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020041#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020042#include "modules/rtp_rtcp/source/rtcp_packet.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020043#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
44#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
45#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
46#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
47#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
48#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
Tomas Gunnarssonf25761d2020-06-03 22:55:33 +020049#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020050#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020051#include "rtc_base/logging.h"
Bjorn Terelius0295a962017-10-25 17:42:41 +020052#include "rtc_base/numerics/sequence_number_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020053#include "rtc_base/rate_statistics.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020054#include "rtc_base/strings/string_builder.h"
Mirko Bonadei575998c2019-07-25 13:57:41 +020055#include "rtc_tools/rtc_event_log_visualizer/log_simulation.h"
Björn Tereliusae1892d2020-06-17 11:55:55 +020056#include "test/explicit_key_value_config.h"
Bjorn Terelius6984ad22017-10-24 12:19:45 +020057
tereliusdc35dcd2016-08-01 12:03:27 -070058namespace webrtc {
tereliusdc35dcd2016-08-01 12:03:27 -070059
terelius54ce6802016-07-13 06:44:41 -070060namespace {
61
62std::string SsrcToString(uint32_t ssrc) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020063 rtc::StringBuilder ss;
terelius54ce6802016-07-13 06:44:41 -070064 ss << "SSRC " << ssrc;
Jonas Olsson84df1c72018-09-14 16:59:32 +020065 return ss.Release();
terelius54ce6802016-07-13 06:44:41 -070066}
67
68// Checks whether an SSRC is contained in the list of desired SSRCs.
69// Note that an empty SSRC list matches every SSRC.
70bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
Mirko Bonadei1f173152019-07-25 15:28:14 +020071 if (desired_ssrc.empty())
terelius54ce6802016-07-13 06:44:41 -070072 return true;
73 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
74 desired_ssrc.end();
75}
76
77double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
78 // The timestamp is a fixed point representation with 6 bits for seconds
79 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080080 // time in seconds and then multiply by kNumMicrosecsPerSec to convert to
81 // microseconds.
terelius54ce6802016-07-13 06:44:41 -070082 static constexpr double kTimestampToMicroSec =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080083 static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070084 return abs_send_time * kTimestampToMicroSec;
85}
86
Artem Titov54500ad2021-07-26 15:51:27 +020087// Computes the difference `later` - `earlier` where `later` and `earlier`
88// are counters that wrap at `modulus`. The difference is chosen to have the
89// least absolute value. For example if `modulus` is 8, then the difference will
90// be chosen in the range [-3, 4]. If `modulus` is 9, then the difference will
terelius54ce6802016-07-13 06:44:41 -070091// be in [-4, 4].
92int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
93 RTC_DCHECK_LE(1, modulus);
94 RTC_DCHECK_LT(later, modulus);
95 RTC_DCHECK_LT(earlier, modulus);
96 int64_t difference =
97 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
98 int64_t max_difference = modulus / 2;
99 int64_t min_difference = max_difference - modulus + 1;
100 if (difference > max_difference) {
101 difference -= modulus;
102 }
103 if (difference < min_difference) {
104 difference += modulus;
105 }
terelius6addf492016-08-23 17:34:07 -0700106 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100107 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
108 << " expected to be in the range ("
109 << min_difference / 2 << "," << max_difference / 2
110 << ") but is " << difference
111 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700112 }
terelius54ce6802016-07-13 06:44:41 -0700113 return difference;
114}
115
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200116// This is much more reliable for outgoing streams than for incoming streams.
117template <typename RtpPacketContainer>
Danil Chapovalov431abd92018-06-18 12:54:17 +0200118absl::optional<uint32_t> EstimateRtpClockFrequency(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200119 const RtpPacketContainer& packets,
120 int64_t end_time_us) {
121 RTC_CHECK(packets.size() >= 2);
122 SeqNumUnwrapper<uint32_t> unwrapper;
Philip Eliasson1f850a62019-03-19 12:15:00 +0000123 int64_t first_rtp_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200124 unwrapper.Unwrap(packets[0].rtp.header.timestamp);
125 int64_t first_log_timestamp = packets[0].log_time_us();
Philip Eliasson1f850a62019-03-19 12:15:00 +0000126 int64_t last_rtp_timestamp = first_rtp_timestamp;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200127 int64_t last_log_timestamp = first_log_timestamp;
128 for (size_t i = 1; i < packets.size(); i++) {
129 if (packets[i].log_time_us() > end_time_us)
130 break;
131 last_rtp_timestamp = unwrapper.Unwrap(packets[i].rtp.header.timestamp);
132 last_log_timestamp = packets[i].log_time_us();
133 }
134 if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) {
135 RTC_LOG(LS_WARNING)
136 << "Failed to estimate RTP clock frequency: Stream too short. ("
137 << packets.size() << " packets, "
138 << last_log_timestamp - first_log_timestamp << " us)";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200139 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200140 }
141 double duration =
142 static_cast<double>(last_log_timestamp - first_log_timestamp) /
143 kNumMicrosecsPerSec;
144 double estimated_frequency =
145 (last_rtp_timestamp - first_rtp_timestamp) / duration;
146 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
philipel3fa49382019-08-20 15:59:57 +0200147 if (std::fabs(estimated_frequency - f) < 0.15 * f) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200148 return f;
149 }
150 }
151 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
152 << estimated_frequency
Philipp Hanckebc07d402022-05-27 18:46:23 +0200153 << " not close to any standard RTP frequency."
154 << " Last timestamp " << last_rtp_timestamp
155 << " first timestamp " << first_rtp_timestamp;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200156 return absl::nullopt;
ivocaac9d6f2016-09-22 07:01:47 -0700157}
158
Danil Chapovalov431abd92018-06-18 12:54:17 +0200159absl::optional<double> NetworkDelayDiff_AbsSendTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100160 const LoggedRtpPacketIncoming& old_packet,
161 const LoggedRtpPacketIncoming& new_packet) {
162 if (old_packet.rtp.header.extension.hasAbsoluteSendTime &&
163 new_packet.rtp.header.extension.hasAbsoluteSendTime) {
terelius53dc23c2017-03-13 05:24:05 -0700164 int64_t send_time_diff = WrappingDifference(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100165 new_packet.rtp.header.extension.absoluteSendTime,
166 old_packet.rtp.header.extension.absoluteSendTime, 1ul << 24);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200167 int64_t recv_time_diff =
168 new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700169 double delay_change_us =
170 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100171 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700172 } else {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200173 return absl::nullopt;
terelius6addf492016-08-23 17:34:07 -0700174 }
175}
176
Danil Chapovalov431abd92018-06-18 12:54:17 +0200177absl::optional<double> NetworkDelayDiff_CaptureTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100178 const LoggedRtpPacketIncoming& old_packet,
179 const LoggedRtpPacketIncoming& new_packet,
180 const double sample_rate) {
181 int64_t send_time_diff =
182 WrappingDifference(new_packet.rtp.header.timestamp,
183 old_packet.rtp.header.timestamp, 1ull << 32);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200184 int64_t recv_time_diff = new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700185
terelius53dc23c2017-03-13 05:24:05 -0700186 double delay_change =
187 static_cast<double>(recv_time_diff) / 1000 -
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100188 static_cast<double>(send_time_diff) / sample_rate * 1000;
terelius53dc23c2017-03-13 05:24:05 -0700189 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100190 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100191 RTC_LOG(LS_WARNING) << "Old capture time "
192 << old_packet.rtp.header.timestamp << ", received time "
193 << old_packet.log_time_us();
194 RTC_LOG(LS_WARNING) << "New capture time "
195 << new_packet.rtp.header.timestamp << ", received time "
196 << new_packet.log_time_us();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100197 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800198 << static_cast<double>(recv_time_diff) /
199 kNumMicrosecsPerSec
200 << "s";
Mirko Bonadei675513b2017-11-09 11:09:25 +0100201 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100202 << static_cast<double>(send_time_diff) / sample_rate
Mirko Bonadei675513b2017-11-09 11:09:25 +0100203 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700204 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100205 return delay_change;
terelius53dc23c2017-03-13 05:24:05 -0700206}
207
terelius6addf492016-08-23 17:34:07 -0700208
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100209template <typename T>
210TimeSeries CreateRtcpTypeTimeSeries(const std::vector<T>& rtcp_list,
211 AnalyzerConfig config,
212 std::string rtcp_name,
213 int category_id) {
214 TimeSeries time_series(rtcp_name, LineStyle::kNone, PointStyle::kHighlight);
215 for (const auto& rtcp : rtcp_list) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000216 float x = config.GetCallTimeSec(rtcp.timestamp);
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100217 float y = category_id;
218 time_series.points.emplace_back(x, y);
219 }
220 return time_series;
221}
222
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800223const char kUnknownEnumValue[] = "unknown";
224
225const char kIceCandidateTypeLocal[] = "local";
226const char kIceCandidateTypeStun[] = "stun";
227const char kIceCandidateTypePrflx[] = "prflx";
228const char kIceCandidateTypeRelay[] = "relay";
229
230const char kProtocolUdp[] = "udp";
231const char kProtocolTcp[] = "tcp";
232const char kProtocolSsltcp[] = "ssltcp";
233const char kProtocolTls[] = "tls";
234
235const char kAddressFamilyIpv4[] = "ipv4";
236const char kAddressFamilyIpv6[] = "ipv6";
237
238const char kNetworkTypeEthernet[] = "ethernet";
239const char kNetworkTypeLoopback[] = "loopback";
240const char kNetworkTypeWifi[] = "wifi";
241const char kNetworkTypeVpn[] = "vpn";
242const char kNetworkTypeCellular[] = "cellular";
243
244std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) {
245 switch (type) {
246 case webrtc::IceCandidateType::kLocal:
247 return kIceCandidateTypeLocal;
248 case webrtc::IceCandidateType::kStun:
249 return kIceCandidateTypeStun;
250 case webrtc::IceCandidateType::kPrflx:
251 return kIceCandidateTypePrflx;
252 case webrtc::IceCandidateType::kRelay:
253 return kIceCandidateTypeRelay;
254 default:
255 return kUnknownEnumValue;
256 }
257}
258
259std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) {
260 switch (protocol) {
261 case webrtc::IceCandidatePairProtocol::kUdp:
262 return kProtocolUdp;
263 case webrtc::IceCandidatePairProtocol::kTcp:
264 return kProtocolTcp;
265 case webrtc::IceCandidatePairProtocol::kSsltcp:
266 return kProtocolSsltcp;
267 case webrtc::IceCandidatePairProtocol::kTls:
268 return kProtocolTls;
269 default:
270 return kUnknownEnumValue;
271 }
272}
273
274std::string GetAddressFamilyAsString(
275 webrtc::IceCandidatePairAddressFamily family) {
276 switch (family) {
277 case webrtc::IceCandidatePairAddressFamily::kIpv4:
278 return kAddressFamilyIpv4;
279 case webrtc::IceCandidatePairAddressFamily::kIpv6:
280 return kAddressFamilyIpv6;
281 default:
282 return kUnknownEnumValue;
283 }
284}
285
286std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) {
287 switch (type) {
288 case webrtc::IceCandidateNetworkType::kEthernet:
289 return kNetworkTypeEthernet;
290 case webrtc::IceCandidateNetworkType::kLoopback:
291 return kNetworkTypeLoopback;
292 case webrtc::IceCandidateNetworkType::kWifi:
293 return kNetworkTypeWifi;
294 case webrtc::IceCandidateNetworkType::kVpn:
295 return kNetworkTypeVpn;
296 case webrtc::IceCandidateNetworkType::kCellular:
297 return kNetworkTypeCellular;
298 default:
299 return kUnknownEnumValue;
300 }
301}
302
303std::string GetCandidatePairLogDescriptionAsString(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200304 const LoggedIceCandidatePairConfig& config) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800305 // Example: stun:wifi->relay(tcp):cellular@udp:ipv4
306 // represents a pair of a local server-reflexive candidate on a WiFi network
307 // and a remote relay candidate using TCP as the relay protocol on a cell
308 // network, when the candidate pair communicates over UDP using IPv4.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200309 rtc::StringBuilder ss;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800310 std::string local_candidate_type =
311 GetIceCandidateTypeAsString(config.local_candidate_type);
312 std::string remote_candidate_type =
313 GetIceCandidateTypeAsString(config.remote_candidate_type);
314 if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) {
315 local_candidate_type +=
316 "(" + GetProtocolAsString(config.local_relay_protocol) + ")";
317 }
318 ss << local_candidate_type << ":"
319 << GetNetworkTypeAsString(config.local_network_type) << ":"
320 << GetAddressFamilyAsString(config.local_address_family) << "->"
321 << remote_candidate_type << ":"
322 << GetAddressFamilyAsString(config.remote_address_family) << "@"
323 << GetProtocolAsString(config.candidate_pair_protocol);
Jonas Olsson84df1c72018-09-14 16:59:32 +0200324 return ss.Release();
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800325}
326
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200327std::string GetDirectionAsString(PacketDirection direction) {
328 if (direction == kIncomingPacket) {
329 return "Incoming";
330 } else {
331 return "Outgoing";
332 }
333}
334
335std::string GetDirectionAsShortString(PacketDirection direction) {
336 if (direction == kIncomingPacket) {
337 return "In";
338 } else {
339 return "Out";
340 }
341}
342
terelius54ce6802016-07-13 06:44:41 -0700343} // namespace
344
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100345EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200346 bool normalize_time)
Bjorn Terelius068fc352019-02-13 22:38:25 +0100347 : parsed_log_(log) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000348 config_.window_duration_ = TimeDelta::Millis(250);
349 config_.step_ = TimeDelta::Millis(10);
350 if (!log.start_log_events().empty()) {
351 config_.rtc_to_utc_offset_ = log.start_log_events()[0].utc_time() -
352 log.start_log_events()[0].log_time();
353 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100354 config_.normalize_time_ = normalize_time;
355 config_.begin_time_ = parsed_log_.first_timestamp();
356 config_.end_time_ = parsed_log_.last_timestamp();
357 if (config_.end_time_ < config_.begin_time_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200358 RTC_LOG(LS_WARNING) << "No useful events in the log.";
Björn Tereliuscb241582022-02-25 08:22:38 +0000359 config_.begin_time_ = config_.end_time_ = Timestamp::Zero();
Björn Tereliusff612732018-04-25 14:23:01 +0000360 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200361
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200362 RTC_LOG(LS_INFO) << "Log is "
Björn Tereliuscb241582022-02-25 08:22:38 +0000363 << (parsed_log_.last_timestamp().ms() -
364 parsed_log_.first_timestamp().ms()) /
365 1000
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200366 << " seconds long.";
Bjorn Terelius48b82792020-05-19 10:57:24 +0200367}
368
369EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
370 const AnalyzerConfig& config)
371 : parsed_log_(log), config_(config) {
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200372 RTC_LOG(LS_INFO) << "Log is "
Björn Tereliuscb241582022-02-25 08:22:38 +0000373 << (parsed_log_.last_timestamp().ms() -
374 parsed_log_.first_timestamp().ms()) /
375 1000
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200376 << " seconds long.";
terelius54ce6802016-07-13 06:44:41 -0700377}
378
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200379class BitrateObserver : public RemoteBitrateObserver {
Stefan Holmer13181032016-07-29 14:48:54 +0200380 public:
381 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
382
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200383 void Update(NetworkControlUpdate update) {
384 if (update.target_rate) {
385 last_bitrate_bps_ = update.target_rate->target_rate.bps();
386 bitrate_updated_ = true;
387 }
Stefan Holmer13181032016-07-29 14:48:54 +0200388 }
389
390 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
391 uint32_t bitrate) override {}
392
393 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
394 bool GetAndResetBitrateUpdated() {
395 bool bitrate_updated = bitrate_updated_;
396 bitrate_updated_ = false;
397 return bitrate_updated;
398 }
399
400 private:
401 uint32_t last_bitrate_bps_;
402 bool bitrate_updated_;
403};
404
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200405void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction,
terelius54ce6802016-07-13 06:44:41 -0700406 Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200407 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
408 // Filter on SSRC.
409 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700410 continue;
terelius54ce6802016-07-13 06:44:41 -0700411 }
terelius54ce6802016-07-13 06:44:41 -0700412
Bjorn Terelius48b82792020-05-19 10:57:24 +0200413 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200414 LineStyle::kBar);
415 auto GetPacketSize = [](const LoggedRtpPacket& packet) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200416 return absl::optional<float>(packet.total_length);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200417 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200418 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000419 return this->config_.GetCallTimeSec(packet.timestamp);
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200420 };
421 ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize,
422 stream.packet_view, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700423 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700424 }
425
Bjorn Terelius068fc352019-02-13 22:38:25 +0100426 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
427 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700428 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
429 kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200430 plot->SetTitle(GetDirectionAsString(direction) + " RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700431}
432
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100433void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction,
434 Plot* plot) {
435 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
436 parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1));
437 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
438 parsed_log_.receiver_reports(direction), config_, "RR", 2));
439 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
440 parsed_log_.sender_reports(direction), config_, "SR", 3));
441 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
442 parsed_log_.extended_reports(direction), config_, "XR", 4));
443 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction),
444 config_, "NACK", 5));
445 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction),
446 config_, "REMB", 6));
447 plot->AppendTimeSeries(
448 CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7));
449 plot->AppendTimeSeries(
450 CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8));
Björn Terelius4ef56382021-02-03 14:12:24 +0100451 plot->AppendTimeSeries(
452 CreateRtcpTypeTimeSeries(parsed_log_.byes(direction), config_, "BYE", 9));
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100453 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
454 "Time (s)", kLeftMargin, kRightMargin);
455 plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin);
456 plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets");
Bjorn Tereliusf640b872019-07-24 15:46:39 +0200457 plot->SetYAxisTickLabels({{1, "TWCC"},
458 {2, "RR"},
459 {3, "SR"},
460 {4, "XR"},
461 {5, "NACK"},
462 {6, "REMB"},
463 {7, "FIR"},
Björn Terelius4ef56382021-02-03 14:12:24 +0100464 {8, "PLI"},
465 {9, "BYE"}});
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100466}
467
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200468template <typename IterableType>
philipelccd74892016-09-05 02:46:25 -0700469void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
philipelccd74892016-09-05 02:46:25 -0700470 Plot* plot,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200471 const IterableType& packets,
472 const std::string& label) {
473 TimeSeries time_series(label, LineStyle::kStep);
474 for (size_t i = 0; i < packets.size(); i++) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000475 float x = config_.GetCallTimeSec(packets[i].log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200476 time_series.points.emplace_back(x, i + 1);
philipelccd74892016-09-05 02:46:25 -0700477 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200478 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700479}
480
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200481void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction,
482 Plot* plot) {
483 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
484 if (!MatchingSsrc(stream.ssrc, desired_ssrc_))
485 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200486 std::string label = std::string("RTP ") +
487 GetStreamName(parsed_log_, direction, stream.ssrc);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200488 CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label);
489 }
490 std::string label =
491 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")";
492 if (direction == kIncomingPacket) {
493 CreateAccumulatedPacketsTimeSeries(
494 plot, parsed_log_.incoming_rtcp_packets(), label);
495 } else {
496 CreateAccumulatedPacketsTimeSeries(
497 plot, parsed_log_.outgoing_rtcp_packets(), label);
498 }
philipelccd74892016-09-05 02:46:25 -0700499
Bjorn Terelius068fc352019-02-13 22:38:25 +0100500 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
501 "Time (s)", kLeftMargin, kRightMargin);
philipelccd74892016-09-05 02:46:25 -0700502 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200503 plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) +
504 " RTP/RTCP packets");
philipelccd74892016-09-05 02:46:25 -0700505}
506
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200507void EventLogAnalyzer::CreatePacketRateGraph(PacketDirection direction,
508 Plot* plot) {
509 auto CountPackets = [](auto packet) { return 1.0; };
510 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
511 // Filter on SSRC.
512 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
513 continue;
514 }
515 TimeSeries time_series(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200516 std::string("RTP ") +
517 GetStreamName(parsed_log_, direction, stream.ssrc),
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200518 LineStyle::kLine);
519 MovingAverage<LoggedRtpPacket, double>(CountPackets, stream.packet_view,
520 config_, &time_series);
521 plot->AppendTimeSeries(std::move(time_series));
522 }
523 TimeSeries time_series(
524 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")",
525 LineStyle::kLine);
526 if (direction == kIncomingPacket) {
527 MovingAverage<LoggedRtcpPacketIncoming, double>(
528 CountPackets, parsed_log_.incoming_rtcp_packets(), config_,
529 &time_series);
530 } else {
531 MovingAverage<LoggedRtcpPacketOutgoing, double>(
532 CountPackets, parsed_log_.outgoing_rtcp_packets(), config_,
533 &time_series);
534 }
535 plot->AppendTimeSeries(std::move(time_series));
536
537 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
538 "Time (s)", kLeftMargin, kRightMargin);
539 plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin,
540 kTopMargin);
541 plot->SetTitle("Rate of " + GetDirectionAsString(direction) +
542 " RTP/RTCP packets");
543}
544
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200545void EventLogAnalyzer::CreateTotalPacketRateGraph(PacketDirection direction,
546 Plot* plot) {
547 // Contains a log timestamp to enable counting logged events of different
548 // types using MovingAverage().
549 class LogTime {
550 public:
Björn Tereliuscb241582022-02-25 08:22:38 +0000551 explicit LogTime(Timestamp log_time) : log_time_(log_time) {}
552 Timestamp log_time() const { return log_time_; }
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200553
554 private:
Björn Tereliuscb241582022-02-25 08:22:38 +0000555 Timestamp log_time_;
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200556 };
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200557 std::vector<LogTime> packet_times;
558 auto handle_rtp = [&](const LoggedRtpPacket& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000559 packet_times.emplace_back(packet.log_time());
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200560 };
561 RtcEventProcessor process;
562 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
563 process.AddEvents(stream.packet_view, handle_rtp);
564 }
565 if (direction == kIncomingPacket) {
566 auto handle_incoming_rtcp = [&](const LoggedRtcpPacketIncoming& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000567 packet_times.emplace_back(packet.log_time());
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200568 };
569 process.AddEvents(parsed_log_.incoming_rtcp_packets(),
570 handle_incoming_rtcp);
571 } else {
572 auto handle_outgoing_rtcp = [&](const LoggedRtcpPacketOutgoing& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000573 packet_times.emplace_back(packet.log_time());
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200574 };
575 process.AddEvents(parsed_log_.outgoing_rtcp_packets(),
576 handle_outgoing_rtcp);
577 }
578 process.ProcessEventsInOrder();
579 TimeSeries time_series(std::string("Total ") + "(" +
580 GetDirectionAsShortString(direction) + ") packets",
581 LineStyle::kLine);
582 MovingAverage<LogTime, uint64_t>([](auto packet) { return 1; }, packet_times,
583 config_, &time_series);
584 plot->AppendTimeSeries(std::move(time_series));
585
586 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
587 "Time (s)", kLeftMargin, kRightMargin);
588 plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin,
589 kTopMargin);
590 plot->SetTitle("Rate of all " + GetDirectionAsString(direction) +
591 " RTP/RTCP packets");
592}
593
terelius54ce6802016-07-13 06:44:41 -0700594// For each SSRC, plot the time between the consecutive playouts.
595void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200596 for (const auto& playout_stream : parsed_log_.audio_playout_events()) {
597 uint32_t ssrc = playout_stream.first;
598 if (!MatchingSsrc(ssrc, desired_ssrc_))
599 continue;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200600 absl::optional<int64_t> last_playout_ms;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200601 TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar);
Minyue Li27e2b7d2018-05-07 15:20:24 +0200602 for (const auto& playout_event : playout_stream.second) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000603 float x = config_.GetCallTimeSec(playout_event.log_time());
Minyue Li27e2b7d2018-05-07 15:20:24 +0200604 int64_t playout_time_ms = playout_event.log_time_ms();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200605 // If there were no previous playouts, place the point on the x-axis.
Minyue Li27e2b7d2018-05-07 15:20:24 +0200606 float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200607 time_series.points.push_back(TimeSeriesPoint(x, y));
Minyue Li27e2b7d2018-05-07 15:20:24 +0200608 last_playout_ms.emplace(playout_time_ms);
terelius54ce6802016-07-13 06:44:41 -0700609 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200610 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700611 }
612
Bjorn Terelius068fc352019-02-13 22:38:25 +0100613 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
614 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700615 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
616 kTopMargin);
617 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700618}
619
ivocaac9d6f2016-09-22 07:01:47 -0700620// For audio SSRCs, plot the audio level.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200621void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction,
622 Plot* plot) {
623 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
Bjorn Terelius48b82792020-05-19 10:57:24 +0200624 if (!IsAudioSsrc(parsed_log_, direction, stream.ssrc))
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200625 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200626 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200627 LineStyle::kLine);
628 for (auto& packet : stream.packet_view) {
ivocaac9d6f2016-09-22 07:01:47 -0700629 if (packet.header.extension.hasAudioLevel) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000630 float x = config_.GetCallTimeSec(packet.log_time());
ivocaac9d6f2016-09-22 07:01:47 -0700631 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
632 // Here we convert it to dBov.
633 float y = static_cast<float>(-packet.header.extension.audioLevel);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200634 time_series.points.emplace_back(TimeSeriesPoint(x, y));
ivocaac9d6f2016-09-22 07:01:47 -0700635 }
636 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200637 plot->AppendTimeSeries(std::move(time_series));
ivocaac9d6f2016-09-22 07:01:47 -0700638 }
639
Bjorn Terelius068fc352019-02-13 22:38:25 +0100640 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
641 "Time (s)", kLeftMargin, kRightMargin);
Yves Gerey665174f2018-06-19 15:03:05 +0200642 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200643 plot->SetTitle(GetDirectionAsString(direction) + " audio level");
ivocaac9d6f2016-09-22 07:01:47 -0700644}
645
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100646// For each SSRC, plot the sequence number difference between consecutive
647// incoming packets.
terelius54ce6802016-07-13 06:44:41 -0700648void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200649 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
650 // Filter on SSRC.
651 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700652 continue;
terelius54ce6802016-07-13 06:44:41 -0700653 }
terelius54ce6802016-07-13 06:44:41 -0700654
Bjorn Terelius48b82792020-05-19 10:57:24 +0200655 TimeSeries time_series(
656 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc),
657 LineStyle::kBar);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200658 auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet,
659 const LoggedRtpPacketIncoming& new_packet) {
660 int64_t diff =
661 WrappingDifference(new_packet.rtp.header.sequenceNumber,
662 old_packet.rtp.header.sequenceNumber, 1ul << 16);
663 return diff;
664 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200665 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000666 return this->config_.GetCallTimeSec(packet.log_time());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200667 };
668 ProcessPairs<LoggedRtpPacketIncoming, float>(
669 ToCallTime, GetSequenceNumberDiff, stream.incoming_packets,
670 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700671 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700672 }
673
Bjorn Terelius068fc352019-02-13 22:38:25 +0100674 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
675 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700676 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
677 kTopMargin);
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100678 plot->SetTitle("Incoming sequence number delta");
terelius54ce6802016-07-13 06:44:41 -0700679}
680
Stefan Holmer99f8e082016-09-09 13:37:50 +0200681void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200682 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
683 const std::vector<LoggedRtpPacketIncoming>& packets =
684 stream.incoming_packets;
685 // Filter on SSRC.
Mirko Bonadei1f173152019-07-25 15:28:14 +0200686 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.empty()) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200687 continue;
688 }
689
Bjorn Terelius48b82792020-05-19 10:57:24 +0200690 TimeSeries time_series(
691 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc),
692 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200693 // TODO(terelius): Should the window and step size be read from the class
694 // instead?
Björn Tereliuscb241582022-02-25 08:22:38 +0000695 const TimeDelta kWindow = TimeDelta::Millis(1000);
696 const TimeDelta kStep = TimeDelta::Millis(1000);
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100697 SeqNumUnwrapper<uint16_t> unwrapper_;
698 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800699 size_t window_index_begin = 0;
700 size_t window_index_end = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200701 uint64_t highest_seq_number =
702 unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
703 uint64_t highest_prior_seq_number =
704 prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
terelius4c9b4af2017-01-30 08:44:51 -0800705
Björn Tereliuscb241582022-02-25 08:22:38 +0000706 for (Timestamp t = config_.begin_time_; t < config_.end_time_ + kStep;
Bjorn Terelius068fc352019-02-13 22:38:25 +0100707 t += kStep) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200708 while (window_index_end < packets.size() &&
Björn Tereliuscb241582022-02-25 08:22:38 +0000709 packets[window_index_end].rtp.log_time() < t) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200710 uint64_t sequence_number = unwrapper_.Unwrap(
711 packets[window_index_end].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800712 highest_seq_number = std::max(highest_seq_number, sequence_number);
713 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200714 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200715 while (window_index_begin < packets.size() &&
Björn Tereliuscb241582022-02-25 08:22:38 +0000716 packets[window_index_begin].rtp.log_time() < t - kWindow) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200717 uint64_t sequence_number = prior_unwrapper_.Unwrap(
718 packets[window_index_begin].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800719 highest_prior_seq_number =
720 std::max(highest_prior_seq_number, sequence_number);
721 ++window_index_begin;
722 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100723 float x = config_.GetCallTimeSec(t);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200724 uint64_t expected_packets = highest_seq_number - highest_prior_seq_number;
terelius4c9b4af2017-01-30 08:44:51 -0800725 if (expected_packets > 0) {
726 int64_t received_packets = window_index_end - window_index_begin;
727 int64_t lost_packets = expected_packets - received_packets;
728 float y = static_cast<float>(lost_packets) / expected_packets * 100;
729 time_series.points.emplace_back(x, y);
730 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200731 }
philipel35ba9bd2017-04-19 05:58:51 -0700732 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200733 }
734
Bjorn Terelius068fc352019-02-13 22:38:25 +0100735 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
736 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100737 plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin);
738 plot->SetTitle("Incoming packet loss (derived from incoming packets)");
Stefan Holmer99f8e082016-09-09 13:37:50 +0200739}
740
terelius2ee076d2017-08-15 02:04:02 -0700741void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100742 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200743 // Filter on SSRC.
744 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
Bjorn Terelius48b82792020-05-19 10:57:24 +0200745 IsRtxSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700746 continue;
747 }
terelius54ce6802016-07-13 06:44:41 -0700748
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100749 const std::vector<LoggedRtpPacketIncoming>& packets =
750 stream.incoming_packets;
751 if (packets.size() < 100) {
752 RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with "
753 << packets.size() << " packets in the stream.";
754 continue;
755 }
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200756 int64_t segment_end_us = parsed_log_.first_log_segment().stop_time_us();
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100757 absl::optional<uint32_t> estimated_frequency =
Bjorn Terelius48b82792020-05-19 10:57:24 +0200758 EstimateRtpClockFrequency(packets, segment_end_us);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100759 if (!estimated_frequency)
760 continue;
761 const double frequency_hz = *estimated_frequency;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200762 if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc) &&
763 frequency_hz != 90000) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100764 RTC_LOG(LS_WARNING)
765 << "Video stream should use a 90 kHz clock but appears to use "
766 << frequency_hz / 1000 << ". Discarding.";
767 continue;
768 }
769
770 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000771 return this->config_.GetCallTimeSec(packet.log_time());
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100772 };
773 auto ToNetworkDelay = [frequency_hz](
774 const LoggedRtpPacketIncoming& old_packet,
775 const LoggedRtpPacketIncoming& new_packet) {
776 return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz);
777 };
778
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200779 TimeSeries capture_time_data(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200780 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) +
781 " capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200782 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100783 AccumulatePairs<LoggedRtpPacketIncoming, double>(
784 ToCallTime, ToNetworkDelay, packets, &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700785 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700786
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200787 TimeSeries send_time_data(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200788 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) +
789 " abs-send-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200790 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100791 AccumulatePairs<LoggedRtpPacketIncoming, double>(
792 ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data);
793 plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700794 }
795
Bjorn Terelius068fc352019-02-13 22:38:25 +0100796 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
797 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +0100798 plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin);
799 plot->SetTitle("Incoming network delay (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700800}
801
tereliusf736d232016-08-04 10:00:11 -0700802// Plot the fraction of packets lost (as perceived by the loss-based BWE).
803void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100804 TimeSeries time_series("Fraction lost", LineStyle::kLine,
805 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200806 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000807 float x = config_.GetCallTimeSec(bwe_update.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200808 float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700809 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700810 }
tereliusf736d232016-08-04 10:00:11 -0700811
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200812 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +0100813 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
814 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100815 plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin);
816 plot->SetTitle("Outgoing packet loss (as reported by BWE)");
tereliusf736d232016-08-04 10:00:11 -0700817}
818
terelius54ce6802016-07-13 06:44:41 -0700819// Plot the total bandwidth used by all RTP streams.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200820void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) {
821 // TODO(terelius): This could be provided by the parser.
Björn Tereliuscb241582022-02-25 08:22:38 +0000822 std::multimap<Timestamp, size_t> packets_in_order;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200823 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
824 for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets)
825 packets_in_order.insert(
Björn Tereliuscb241582022-02-25 08:22:38 +0000826 std::make_pair(packet.rtp.log_time(), packet.rtp.total_length));
terelius54ce6802016-07-13 06:44:41 -0700827 }
828
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200829 auto window_begin = packets_in_order.begin();
830 auto window_end = packets_in_order.begin();
terelius54ce6802016-07-13 06:44:41 -0700831 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700832
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800833 if (!packets_in_order.empty()) {
834 // Calculate a moving average of the bitrate and store in a TimeSeries.
835 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
Björn Tereliuscb241582022-02-25 08:22:38 +0000836 for (Timestamp time = config_.begin_time_;
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800837 time < config_.end_time_ + config_.step_; time += config_.step_) {
838 while (window_end != packets_in_order.end() && window_end->first < time) {
839 bytes_in_window += window_end->second;
840 ++window_end;
841 }
842 while (window_begin != packets_in_order.end() &&
843 window_begin->first < time - config_.window_duration_) {
844 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
845 bytes_in_window -= window_begin->second;
846 ++window_begin;
847 }
848 float window_duration_in_seconds =
Björn Tereliuscb241582022-02-25 08:22:38 +0000849 static_cast<float>(config_.window_duration_.us()) /
850 kNumMicrosecsPerSec;
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800851 float x = config_.GetCallTimeSec(time);
852 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
853 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700854 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800855 plot->AppendTimeSeries(std::move(bitrate_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200856 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200857
858 // Overlay the outgoing REMB over incoming bitrate.
859 TimeSeries remb_series("Remb", LineStyle::kStep);
860 for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000861 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200862 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
863 remb_series.points.emplace_back(x, y);
864 }
865 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
866
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800867 if (!parsed_log_.generic_packets_received().empty()) {
868 TimeSeries time_series("Incoming generic bitrate", LineStyle::kLine);
869 auto GetPacketSizeKilobits = [](const LoggedGenericPacketReceived& packet) {
870 return packet.packet_length * 8.0 / 1000.0;
871 };
872 MovingAverage<LoggedGenericPacketReceived, double>(
873 GetPacketSizeKilobits, parsed_log_.generic_packets_received(), config_,
874 &time_series);
875 plot->AppendTimeSeries(std::move(time_series));
876 }
877
Bjorn Terelius068fc352019-02-13 22:38:25 +0100878 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
879 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200880 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
881 plot->SetTitle("Incoming RTP bitrate");
882}
883
884// Plot the total bandwidth used by all RTP streams.
885void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
886 bool show_detector_state,
887 bool show_alr_state) {
888 // TODO(terelius): This could be provided by the parser.
Björn Tereliuscb241582022-02-25 08:22:38 +0000889 std::multimap<Timestamp, size_t> packets_in_order;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200890 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
891 for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets)
892 packets_in_order.insert(
Björn Tereliuscb241582022-02-25 08:22:38 +0000893 std::make_pair(packet.rtp.log_time(), packet.rtp.total_length));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200894 }
895
896 auto window_begin = packets_in_order.begin();
897 auto window_end = packets_in_order.begin();
898 size_t bytes_in_window = 0;
899
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800900 if (!packets_in_order.empty()) {
901 // Calculate a moving average of the bitrate and store in a TimeSeries.
902 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
Björn Tereliuscb241582022-02-25 08:22:38 +0000903 for (Timestamp time = config_.begin_time_;
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800904 time < config_.end_time_ + config_.step_; time += config_.step_) {
905 while (window_end != packets_in_order.end() && window_end->first < time) {
906 bytes_in_window += window_end->second;
907 ++window_end;
908 }
909 while (window_begin != packets_in_order.end() &&
910 window_begin->first < time - config_.window_duration_) {
911 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
912 bytes_in_window -= window_begin->second;
913 ++window_begin;
914 }
915 float window_duration_in_seconds =
Björn Tereliuscb241582022-02-25 08:22:38 +0000916 static_cast<float>(config_.window_duration_.us()) /
917 kNumMicrosecsPerSec;
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800918 float x = config_.GetCallTimeSec(time);
919 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
920 bitrate_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200921 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800922 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700923 }
924
terelius8058e582016-07-25 01:32:41 -0700925 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200926 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
927 for (auto& loss_update : parsed_log_.bwe_loss_updates()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000928 float x = config_.GetCallTimeSec(loss_update.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200929 float y = static_cast<float>(loss_update.bitrate_bps) / 1000;
930 loss_series.points.emplace_back(x, y);
931 }
philipel10fc0e62017-04-11 01:50:23 -0700932
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200933 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
934 IntervalSeries overusing_series("Overusing", "#ff8e82",
935 IntervalSeries::kHorizontal);
936 IntervalSeries underusing_series("Underusing", "#5092fc",
937 IntervalSeries::kHorizontal);
938 IntervalSeries normal_series("Normal", "#c4ffc4",
939 IntervalSeries::kHorizontal);
940 IntervalSeries* last_series = &normal_series;
Björn Tereliuscb241582022-02-25 08:22:38 +0000941 float last_detector_switch = 0.0;
philipel23c7f252017-07-14 06:30:03 -0700942
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200943 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
philipel23c7f252017-07-14 06:30:03 -0700944
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200945 for (auto& delay_update : parsed_log_.bwe_delay_updates()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000946 float x = config_.GetCallTimeSec(delay_update.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200947 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -0700948
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200949 if (last_detector_state != delay_update.detector_state) {
950 last_series->intervals.emplace_back(last_detector_switch, x);
951 last_detector_state = delay_update.detector_state;
952 last_detector_switch = x;
philipel23c7f252017-07-14 06:30:03 -0700953
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200954 switch (delay_update.detector_state) {
955 case BandwidthUsage::kBwNormal:
956 last_series = &normal_series;
957 break;
958 case BandwidthUsage::kBwUnderusing:
959 last_series = &underusing_series;
960 break;
961 case BandwidthUsage::kBwOverusing:
962 last_series = &overusing_series;
963 break;
964 case BandwidthUsage::kLast:
Artem Titovd3251962021-11-15 16:57:07 +0100965 RTC_DCHECK_NOTREACHED();
philipele127e7a2017-03-29 16:28:53 +0200966 }
967 }
philipel23c7f252017-07-14 06:30:03 -0700968
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200969 delay_series.points.emplace_back(x, y);
970 }
Bjorn Terelius9e336ec2018-04-24 16:28:35 +0200971
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200972 RTC_CHECK(last_series);
Björn Tereliuscb241582022-02-25 08:22:38 +0000973 last_series->intervals.emplace_back(last_detector_switch,
974 config_.CallEndTimeSec());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200975
976 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
977 PointStyle::kHighlight);
978 for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000979 float x = config_.GetCallTimeSec(cluster.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200980 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
981 created_series.points.emplace_back(x, y);
982 }
983
984 TimeSeries result_series("Probing results.", LineStyle::kNone,
985 PointStyle::kHighlight);
Bjorn Terelius7a0bb002018-05-29 14:45:53 +0200986 for (auto& result : parsed_log_.bwe_probe_success_events()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000987 float x = config_.GetCallTimeSec(result.log_time());
Bjorn Terelius7a0bb002018-05-29 14:45:53 +0200988 float y = static_cast<float>(result.bitrate_bps) / 1000;
989 result_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200990 }
991
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -0800992 TimeSeries probe_failures_series("Probe failed", LineStyle::kNone,
993 PointStyle::kHighlight);
994 for (auto& failure : parsed_log_.bwe_probe_failure_events()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000995 float x = config_.GetCallTimeSec(failure.log_time());
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -0800996 probe_failures_series.points.emplace_back(x, 0);
997 }
998
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200999 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
1000 bool previously_in_alr = false;
Björn Tereliuscb241582022-02-25 08:22:38 +00001001 Timestamp alr_start = Timestamp::Zero();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001002 for (auto& alr : parsed_log_.alr_state_events()) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001003 float y = config_.GetCallTimeSec(alr.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001004 if (!previously_in_alr && alr.in_alr) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001005 alr_start = alr.log_time();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001006 previously_in_alr = true;
1007 } else if (previously_in_alr && !alr.in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001008 float x = config_.GetCallTimeSec(alr_start);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001009 alr_state.intervals.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001010 previously_in_alr = false;
Björn Tereliusff612732018-04-25 14:23:01 +00001011 }
Björn Tereliusff612732018-04-25 14:23:01 +00001012 }
1013
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001014 if (previously_in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001015 float x = config_.GetCallTimeSec(alr_start);
1016 float y = config_.GetCallTimeSec(config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001017 alr_state.intervals.emplace_back(x, y);
1018 }
1019
1020 if (show_detector_state) {
1021 plot->AppendIntervalSeries(std::move(overusing_series));
1022 plot->AppendIntervalSeries(std::move(underusing_series));
1023 plot->AppendIntervalSeries(std::move(normal_series));
1024 }
1025
1026 if (show_alr_state) {
1027 plot->AppendIntervalSeries(std::move(alr_state));
1028 }
1029 plot->AppendTimeSeries(std::move(loss_series));
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001030 plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001031 plot->AppendTimeSeries(std::move(delay_series));
1032 plot->AppendTimeSeries(std::move(created_series));
1033 plot->AppendTimeSeries(std::move(result_series));
1034
1035 // Overlay the incoming REMB over the outgoing bitrate.
Björn Tereliusff612732018-04-25 14:23:01 +00001036 TimeSeries remb_series("Remb", LineStyle::kStep);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001037 for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001038 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001039 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
terelius2c8e8a32017-06-02 01:29:48 -07001040 remb_series.points.emplace_back(x, y);
1041 }
1042 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1043
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001044 if (!parsed_log_.generic_packets_sent().empty()) {
1045 {
1046 TimeSeries time_series("Outgoing generic total bitrate",
1047 LineStyle::kLine);
1048 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1049 return packet.packet_length() * 8.0 / 1000.0;
1050 };
1051 MovingAverage<LoggedGenericPacketSent, double>(
1052 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1053 &time_series);
1054 plot->AppendTimeSeries(std::move(time_series));
1055 }
1056
1057 {
1058 TimeSeries time_series("Outgoing generic payload bitrate",
1059 LineStyle::kLine);
1060 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1061 return packet.payload_length * 8.0 / 1000.0;
1062 };
1063 MovingAverage<LoggedGenericPacketSent, double>(
1064 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1065 &time_series);
1066 plot->AppendTimeSeries(std::move(time_series));
1067 }
1068 }
1069
Bjorn Terelius068fc352019-02-13 22:38:25 +01001070 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1071 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001072 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001073 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001074}
1075
1076// For each SSRC, plot the bandwidth used by that stream.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001077void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction,
1078 Plot* plot) {
1079 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1080 // Filter on SSRC.
1081 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -07001082 continue;
terelius54ce6802016-07-13 06:44:41 -07001083 }
1084
Bjorn Terelius48b82792020-05-19 10:57:24 +02001085 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001086 LineStyle::kLine);
1087 auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) {
1088 return packet.total_length * 8.0 / 1000.0;
1089 };
terelius53dc23c2017-03-13 05:24:05 -07001090 MovingAverage<LoggedRtpPacket, double>(
Bjorn Terelius068fc352019-02-13 22:38:25 +01001091 GetPacketSizeKilobits, stream.packet_view, config_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001092 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001093 }
1094
Bjorn Terelius068fc352019-02-13 22:38:25 +01001095 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1096 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001097 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001098 plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001099}
1100
Bjorn Terelius9775a582019-02-15 17:29:58 +01001101// Plot the bitrate allocation for each temporal and spatial layer.
1102// Computed from RTCP XR target bitrate block, so the graph is only populated if
1103// those are sent.
1104void EventLogAnalyzer::CreateBitrateAllocationGraph(PacketDirection direction,
1105 Plot* plot) {
1106 std::map<LayerDescription, TimeSeries> time_series;
1107 const auto& xr_list = parsed_log_.extended_reports(direction);
1108 for (const auto& rtcp : xr_list) {
1109 const absl::optional<rtcp::TargetBitrate>& target_bitrate =
1110 rtcp.xr.target_bitrate();
1111 if (!target_bitrate.has_value())
1112 continue;
1113 for (const auto& bitrate_item : target_bitrate->GetTargetBitrates()) {
1114 LayerDescription layer(rtcp.xr.sender_ssrc(), bitrate_item.spatial_layer,
1115 bitrate_item.temporal_layer);
1116 auto time_series_it = time_series.find(layer);
1117 if (time_series_it == time_series.end()) {
1118 std::string layer_name = GetLayerName(layer);
1119 bool inserted;
1120 std::tie(time_series_it, inserted) = time_series.insert(
1121 std::make_pair(layer, TimeSeries(layer_name, LineStyle::kStep)));
1122 RTC_DCHECK(inserted);
1123 }
Björn Tereliuscb241582022-02-25 08:22:38 +00001124 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Terelius9775a582019-02-15 17:29:58 +01001125 float y = bitrate_item.target_bitrate_kbps;
1126 time_series_it->second.points.emplace_back(x, y);
1127 }
1128 }
1129 for (auto& layer : time_series) {
1130 plot->AppendTimeSeries(std::move(layer.second));
1131 }
1132 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1133 "Time (s)", kLeftMargin, kRightMargin);
1134 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1135 if (direction == kIncomingPacket)
1136 plot->SetTitle("Target bitrate per incoming layer");
1137 else
1138 plot->SetTitle("Target bitrate per outgoing layer");
1139}
1140
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001141void EventLogAnalyzer::CreateGoogCcSimulationGraph(Plot* plot) {
1142 TimeSeries target_rates("Simulated target rate", LineStyle::kStep,
1143 PointStyle::kHighlight);
1144 TimeSeries delay_based("Logged delay-based estimate", LineStyle::kStep,
1145 PointStyle::kHighlight);
1146 TimeSeries loss_based("Logged loss-based estimate", LineStyle::kStep,
1147 PointStyle::kHighlight);
1148 TimeSeries probe_results("Logged probe success", LineStyle::kNone,
1149 PointStyle::kHighlight);
1150
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001151 LogBasedNetworkControllerSimulation simulation(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001152 std::make_unique<GoogCcNetworkControllerFactory>(),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001153 [&](const NetworkControlUpdate& update, Timestamp at_time) {
1154 if (update.target_rate) {
1155 target_rates.points.emplace_back(
Björn Tereliuscb241582022-02-25 08:22:38 +00001156 config_.GetCallTimeSec(at_time),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001157 update.target_rate->target_rate.kbps<float>());
1158 }
1159 });
1160
1161 simulation.ProcessEventsInLog(parsed_log_);
1162 for (const auto& logged : parsed_log_.bwe_delay_updates())
Björn Tereliuscb241582022-02-25 08:22:38 +00001163 delay_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time()),
1164 logged.bitrate_bps / 1000);
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001165 for (const auto& logged : parsed_log_.bwe_probe_success_events())
Björn Tereliuscb241582022-02-25 08:22:38 +00001166 probe_results.points.emplace_back(config_.GetCallTimeSec(logged.log_time()),
1167 logged.bitrate_bps / 1000);
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001168 for (const auto& logged : parsed_log_.bwe_loss_updates())
Björn Tereliuscb241582022-02-25 08:22:38 +00001169 loss_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time()),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001170 logged.bitrate_bps / 1000);
1171
1172 plot->AppendTimeSeries(std::move(delay_based));
1173 plot->AppendTimeSeries(std::move(loss_based));
1174 plot->AppendTimeSeries(std::move(probe_results));
1175 plot->AppendTimeSeries(std::move(target_rates));
1176
1177 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1178 "Time (s)", kLeftMargin, kRightMargin);
1179 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1180 plot->SetTitle("Simulated BWE behavior");
1181}
1182
Bjorn Terelius28db2662017-10-04 14:22:43 +02001183void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001184 using RtpPacketType = LoggedRtpPacketOutgoing;
1185 using TransportFeedbackType = LoggedRtcpPacketTransportFeedback;
Stefan Holmer13181032016-07-29 14:48:54 +02001186
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001187 // TODO(terelius): This could be provided by the parser.
1188 std::multimap<int64_t, const RtpPacketType*> outgoing_rtp;
1189 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1190 for (const RtpPacketType& rtp_packet : stream.outgoing_packets)
1191 outgoing_rtp.insert(
1192 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Stefan Holmer13181032016-07-29 14:48:54 +02001193 }
1194
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001195 const std::vector<TransportFeedbackType>& incoming_rtcp =
1196 parsed_log_.transport_feedbacks(kIncomingPacket);
Stefan Holmer13181032016-07-29 14:48:54 +02001197
1198 SimulatedClock clock(0);
1199 BitrateObserver observer;
Danil Chapovalov83bbe912019-08-07 12:24:53 +02001200 RtcEventLogNull null_event_log;
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001201 TransportFeedbackAdapter transport_feedback;
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001202 auto factory = GoogCcNetworkControllerFactory();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001203 TimeDelta process_interval = factory.GetProcessInterval();
Stefan Holmer13181032016-07-29 14:48:54 +02001204 // TODO(holmer): Log the call config and use that here instead.
1205 static const uint32_t kDefaultStartBitrateBps = 300000;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001206 NetworkControllerConfig cc_config;
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001207 cc_config.constraints.at_time = Timestamp::Micros(clock.TimeInMicroseconds());
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +01001208 cc_config.constraints.starting_rate =
1209 DataRate::BitsPerSec(kDefaultStartBitrateBps);
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001210 cc_config.event_log = &null_event_log;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001211 auto goog_cc = factory.Create(cc_config);
Stefan Holmer13181032016-07-29 14:48:54 +02001212
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001213 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1214 PointStyle::kHighlight);
Björn Tereliusae1892d2020-06-17 11:55:55 +02001215 TimeSeries acked_time_series("Raw acked bitrate", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001216 PointStyle::kHighlight);
Björn Tereliusae1892d2020-06-17 11:55:55 +02001217 TimeSeries robust_time_series("Robust throughput estimate", LineStyle::kLine,
1218 PointStyle::kHighlight);
1219 TimeSeries acked_estimate_time_series("Ackednowledged bitrate estimate",
1220 LineStyle::kLine,
1221 PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001222
1223 auto rtp_iterator = outgoing_rtp.begin();
1224 auto rtcp_iterator = incoming_rtcp.begin();
1225
1226 auto NextRtpTime = [&]() {
1227 if (rtp_iterator != outgoing_rtp.end())
1228 return static_cast<int64_t>(rtp_iterator->first);
1229 return std::numeric_limits<int64_t>::max();
1230 };
1231
1232 auto NextRtcpTime = [&]() {
1233 if (rtcp_iterator != incoming_rtcp.end())
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001234 return static_cast<int64_t>(rtcp_iterator->log_time_us());
Stefan Holmer13181032016-07-29 14:48:54 +02001235 return std::numeric_limits<int64_t>::max();
1236 };
Bjorn Tereliusa728c912018-12-06 12:26:30 +01001237 int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()});
Stefan Holmer13181032016-07-29 14:48:54 +02001238
1239 auto NextProcessTime = [&]() {
1240 if (rtcp_iterator != incoming_rtcp.end() ||
1241 rtp_iterator != outgoing_rtp.end()) {
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001242 return next_process_time_us_;
Stefan Holmer13181032016-07-29 14:48:54 +02001243 }
1244 return std::numeric_limits<int64_t>::max();
1245 };
1246
Björn Tereliuseb9af842022-05-05 15:54:49 +02001247 RateStatistics raw_acked_bitrate(750, 8000);
Björn Tereliusae1892d2020-06-17 11:55:55 +02001248 test::ExplicitKeyValueConfig throughput_config(
1249 "WebRTC-Bwe-RobustThroughputEstimatorSettings/"
Björn Tereliuseb9af842022-05-05 15:54:49 +02001250 "enabled:true,required_packets:10,"
1251 "window_packets:25,window_duration:1000ms,unacked_weight:1.0/");
Björn Tereliusae1892d2020-06-17 11:55:55 +02001252 std::unique_ptr<AcknowledgedBitrateEstimatorInterface>
1253 robust_throughput_estimator(
1254 AcknowledgedBitrateEstimatorInterface::Create(&throughput_config));
1255 FieldTrialBasedConfig field_trial_config;
Björn Terelius251b0dc2019-11-11 21:00:18 +01001256 std::unique_ptr<AcknowledgedBitrateEstimatorInterface>
1257 acknowledged_bitrate_estimator(
Björn Tereliusae1892d2020-06-17 11:55:55 +02001258 AcknowledgedBitrateEstimatorInterface::Create(&field_trial_config));
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001259 int64_t time_us =
1260 std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
Stefan Holmer492ee282016-10-27 17:19:20 +02001261 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001262 while (time_us != std::numeric_limits<int64_t>::max()) {
1263 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001264 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1265 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1266 const RtpPacketType& rtp_packet = *rtp_iterator->second;
1267 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
Erik Språng30a276b2019-04-23 12:00:11 +02001268 RtpPacketSendInfo packet_info;
Erik Språng6a0a5592021-06-15 19:04:24 +02001269 packet_info.media_ssrc = rtp_packet.rtp.header.ssrc;
Bjorn Tereliusf2e9cab2019-05-27 16:44:09 +02001270 packet_info.transport_sequence_number =
Erik Språng30a276b2019-04-23 12:00:11 +02001271 rtp_packet.rtp.header.extension.transportSequenceNumber;
1272 packet_info.rtp_sequence_number = rtp_packet.rtp.header.sequenceNumber;
Erik Språng30a276b2019-04-23 12:00:11 +02001273 packet_info.length = rtp_packet.rtp.total_length;
Björn Tereliusae1892d2020-06-17 11:55:55 +02001274 if (IsRtxSsrc(parsed_log_, PacketDirection::kOutgoingPacket,
1275 rtp_packet.rtp.header.ssrc)) {
1276 // Don't set the optional media type as we don't know if it is
1277 // a retransmission, FEC or padding.
1278 } else if (IsVideoSsrc(parsed_log_, PacketDirection::kOutgoingPacket,
1279 rtp_packet.rtp.header.ssrc)) {
1280 packet_info.packet_type = RtpPacketMediaType::kVideo;
1281 } else if (IsAudioSsrc(parsed_log_, PacketDirection::kOutgoingPacket,
1282 rtp_packet.rtp.header.ssrc)) {
1283 packet_info.packet_type = RtpPacketMediaType::kAudio;
1284 }
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001285 transport_feedback.AddPacket(
Erik Språng30a276b2019-04-23 12:00:11 +02001286 packet_info,
1287 0u, // Per packet overhead bytes.
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001288 Timestamp::Micros(rtp_packet.rtp.log_time_us()));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001289 }
Björn Tereliusae1892d2020-06-17 11:55:55 +02001290 rtc::SentPacket sent_packet;
1291 sent_packet.send_time_ms = rtp_packet.rtp.log_time_ms();
1292 sent_packet.info.included_in_allocation = true;
1293 sent_packet.info.packet_size_bytes = rtp_packet.rtp.total_length;
1294 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
1295 sent_packet.packet_id =
1296 rtp_packet.rtp.header.extension.transportSequenceNumber;
1297 sent_packet.info.included_in_feedback = true;
1298 }
1299 auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet);
1300 if (sent_msg)
1301 observer.Update(goog_cc->OnSentPacket(*sent_msg));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001302 ++rtp_iterator;
1303 }
Stefan Holmer13181032016-07-29 14:48:54 +02001304 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001305 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001306
1307 auto feedback_msg = transport_feedback.ProcessTransportFeedback(
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001308 rtcp_iterator->transport_feedback,
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001309 Timestamp::Millis(clock.TimeInMilliseconds()));
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001310 if (feedback_msg) {
1311 observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg));
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001312 std::vector<PacketResult> feedback =
1313 feedback_msg->SortedByReceiveTime();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001314 if (!feedback.empty()) {
Björn Terelius251b0dc2019-11-11 21:00:18 +01001315 acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
1316 feedback);
Björn Tereliusae1892d2020-06-17 11:55:55 +02001317 robust_throughput_estimator->IncomingPacketFeedbackVector(feedback);
1318 for (const PacketResult& packet : feedback) {
Björn Tereliuseb9af842022-05-05 15:54:49 +02001319 raw_acked_bitrate.Update(packet.sent_packet.size.bytes(),
1320 packet.receive_time.ms());
Björn Tereliusae1892d2020-06-17 11:55:55 +02001321 }
Björn Tereliuseb9af842022-05-05 15:54:49 +02001322 absl::optional<uint32_t> raw_bitrate_bps =
1323 raw_acked_bitrate.Rate(feedback.back().receive_time.ms());
1324 float x = config_.GetCallTimeSec(clock.CurrentTime());
1325 if (raw_bitrate_bps) {
1326 float y = raw_bitrate_bps.value() / 1000;
1327 acked_time_series.points.emplace_back(x, y);
1328 }
1329 absl::optional<DataRate> robust_estimate =
1330 robust_throughput_estimator->bitrate();
1331 if (robust_estimate) {
1332 float y = robust_estimate.value().kbps();
1333 robust_time_series.points.emplace_back(x, y);
1334 }
1335 absl::optional<DataRate> acked_estimate =
1336 acknowledged_bitrate_estimator->bitrate();
1337 if (acked_estimate) {
1338 float y = acked_estimate.value().kbps();
1339 acked_estimate_time_series.points.emplace_back(x, y);
1340 }
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001341 }
Stefan Holmer13181032016-07-29 14:48:54 +02001342 }
1343 ++rtcp_iterator;
1344 }
stefanc3de0332016-08-02 07:22:17 -07001345 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1346 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001347 ProcessInterval msg;
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001348 msg.at_time = Timestamp::Micros(clock.TimeInMicroseconds());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001349 observer.Update(goog_cc->OnProcessInterval(msg));
1350 next_process_time_us_ += process_interval.us();
stefanc3de0332016-08-02 07:22:17 -07001351 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001352 if (observer.GetAndResetBitrateUpdated() ||
1353 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001354 uint32_t y = observer.last_bitrate_bps() / 1000;
Björn Tereliuscb241582022-02-25 08:22:38 +00001355 float x = config_.GetCallTimeSec(clock.CurrentTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001356 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001357 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001358 }
1359 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1360 }
1361 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001362 plot->AppendTimeSeries(std::move(time_series));
Björn Tereliusae1892d2020-06-17 11:55:55 +02001363 plot->AppendTimeSeries(std::move(robust_time_series));
philipel35ba9bd2017-04-19 05:58:51 -07001364 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001365 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001366
Bjorn Terelius068fc352019-02-13 22:38:25 +01001367 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1368 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001369 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001370 plot->SetTitle("Simulated send-side BWE behavior");
1371}
1372
1373void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001374 using RtpPacketType = LoggedRtpPacketIncoming;
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001375 class RembInterceptor {
Bjorn Terelius28db2662017-10-04 14:22:43 +02001376 public:
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001377 void SendRemb(uint32_t bitrate_bps, std::vector<uint32_t> ssrcs) {
Bjorn Terelius28db2662017-10-04 14:22:43 +02001378 last_bitrate_bps_ = bitrate_bps;
1379 bitrate_updated_ = true;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001380 }
1381 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1382 bool GetAndResetBitrateUpdated() {
1383 bool bitrate_updated = bitrate_updated_;
1384 bitrate_updated_ = false;
1385 return bitrate_updated;
1386 }
1387
1388 private:
Bjorn Terelius571e1302020-06-09 10:29:09 +02001389 // We don't know the start bitrate, but assume that it is the default 300
1390 // kbps.
1391 uint32_t last_bitrate_bps_ = 300000;
1392 bool bitrate_updated_ = false;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001393 };
1394
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001395 std::multimap<int64_t, const RtpPacketType*> incoming_rtp;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001396
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001397 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Terelius48b82792020-05-19 10:57:24 +02001398 if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001399 for (const auto& rtp_packet : stream.incoming_packets)
1400 incoming_rtp.insert(
1401 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Bjorn Terelius28db2662017-10-04 14:22:43 +02001402 }
1403 }
1404
1405 SimulatedClock clock(0);
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001406 RembInterceptor remb_interceptor;
1407 ReceiveSideCongestionController rscc(
1408 &clock, [](auto...) {},
1409 absl::bind_front(&RembInterceptor::SendRemb, &remb_interceptor), nullptr);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001410 // TODO(holmer): Log the call config and use that here instead.
1411 // static const uint32_t kDefaultStartBitrateBps = 300000;
1412 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1413
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001414 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1415 PointStyle::kHighlight);
1416 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001417
1418 RateStatistics acked_bitrate(250, 8000);
1419 int64_t last_update_us = 0;
1420 for (const auto& kv : incoming_rtp) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001421 const RtpPacketType& packet = *kv.second;
1422 int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000;
1423 size_t payload = packet.rtp.total_length; /*Should subtract header?*/
1424 clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() -
Bjorn Terelius28db2662017-10-04 14:22:43 +02001425 clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001426 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001427 acked_bitrate.Update(payload, arrival_time_ms);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001428 absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001429 if (bitrate_bps) {
1430 uint32_t y = *bitrate_bps / 1000;
Björn Tereliuscb241582022-02-25 08:22:38 +00001431 float x = config_.GetCallTimeSec(clock.CurrentTime());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001432 acked_time_series.points.emplace_back(x, y);
1433 }
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001434 if (remb_interceptor.GetAndResetBitrateUpdated() ||
Bjorn Terelius28db2662017-10-04 14:22:43 +02001435 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001436 uint32_t y = remb_interceptor.last_bitrate_bps() / 1000;
Björn Tereliuscb241582022-02-25 08:22:38 +00001437 float x = config_.GetCallTimeSec(clock.CurrentTime());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001438 time_series.points.emplace_back(x, y);
1439 last_update_us = clock.TimeInMicroseconds();
1440 }
1441 }
1442 // Add the data set to the plot.
1443 plot->AppendTimeSeries(std::move(time_series));
1444 plot->AppendTimeSeries(std::move(acked_time_series));
1445
Bjorn Terelius068fc352019-02-13 22:38:25 +01001446 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1447 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001448 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1449 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001450}
1451
tereliuse34c19c2016-08-15 08:47:14 -07001452void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001453 TimeSeries time_series("Network delay", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001454 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001455 int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max();
1456 int64_t min_rtt_ms = std::numeric_limits<int64_t>::max();
stefanc3de0332016-08-02 07:22:17 -07001457
Björn Tereliusc69c1bb2019-10-11 15:06:58 +02001458 std::vector<MatchedSendArrivalTimes> matched_rtp_rtcp =
1459 GetNetworkTrace(parsed_log_);
1460 absl::c_stable_sort(matched_rtp_rtcp, [](const MatchedSendArrivalTimes& a,
1461 const MatchedSendArrivalTimes& b) {
philipel3574d052019-11-18 14:38:13 +01001462 return a.feedback_arrival_time_ms < b.feedback_arrival_time_ms ||
1463 (a.feedback_arrival_time_ms == b.feedback_arrival_time_ms &&
1464 a.arrival_time_ms < b.arrival_time_ms);
Björn Tereliusc69c1bb2019-10-11 15:06:58 +02001465 });
1466 for (const auto& packet : matched_rtp_rtcp) {
Sebastian Jansson74f96ec2019-10-29 12:57:54 +01001467 if (packet.arrival_time_ms == MatchedSendArrivalTimes::kNotReceived)
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001468 continue;
Björn Tereliuscb241582022-02-25 08:22:38 +00001469 float x = config_.GetCallTimeSecFromMs(packet.feedback_arrival_time_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001470 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001471 int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms;
1472 min_rtt_ms = std::min(rtt_ms, min_rtt_ms);
1473 min_send_receive_diff_ms = std::min(y, min_send_receive_diff_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001474 time_series.points.emplace_back(x, y);
stefanc3de0332016-08-02 07:22:17 -07001475 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001476
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001477 // We assume that the base network delay (w/o queues) is equal to half
1478 // the minimum RTT. Therefore rescale the delays by subtracting the minimum
Mirko Bonadei604e75c2019-07-25 11:55:47 +02001479 // observed 1-ways delay and add half the minimum RTT.
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001480 const int64_t estimated_clock_offset_ms =
1481 min_send_receive_diff_ms - min_rtt_ms / 2;
stefanc3de0332016-08-02 07:22:17 -07001482 for (TimeSeriesPoint& point : time_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001483 point.y -= estimated_clock_offset_ms;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001484
stefanc3de0332016-08-02 07:22:17 -07001485 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001486 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001487
Bjorn Terelius068fc352019-02-13 22:38:25 +01001488 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1489 "Time (s)", kLeftMargin, kRightMargin);
stefanc3de0332016-08-02 07:22:17 -07001490 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +01001491 plot->SetTitle("Outgoing network delay (based on per-packet feedback)");
stefanc3de0332016-08-02 07:22:17 -07001492}
stefan08383272016-12-20 08:51:52 -08001493
Bjorn Terelius0295a962017-10-25 17:42:41 +02001494void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001495 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1496 const std::vector<LoggedRtpPacketOutgoing>& packets =
1497 stream.outgoing_packets;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001498
Bjorn Terelius48b82792020-05-19 10:57:24 +02001499 if (IsRtxSsrc(parsed_log_, kOutgoingPacket, stream.ssrc)) {
Konrad Hofbauerbfb735b2019-04-16 11:12:11 +02001500 continue;
1501 }
1502
Bjorn Terelius0295a962017-10-25 17:42:41 +02001503 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001504 RTC_LOG(LS_WARNING)
1505 << "Can't estimate a the RTP clock frequency or the "
1506 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001507 continue;
1508 }
Björn Terelius0d1b28c2020-05-27 20:25:06 +02001509 int64_t segment_end_us = parsed_log_.first_log_segment().stop_time_us();
Danil Chapovalov431abd92018-06-18 12:54:17 +02001510 absl::optional<uint32_t> estimated_frequency =
Bjorn Terelius48b82792020-05-19 10:57:24 +02001511 EstimateRtpClockFrequency(packets, segment_end_us);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001512 if (!estimated_frequency)
1513 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +02001514 if (IsVideoSsrc(parsed_log_, kOutgoingPacket, stream.ssrc) &&
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001515 *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001516 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001517 << "Video stream should use a 90 kHz clock but appears to use "
1518 << *estimated_frequency / 1000 << ". Discarding.";
1519 continue;
1520 }
1521
1522 TimeSeries pacer_delay_series(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001523 GetStreamName(parsed_log_, kOutgoingPacket, stream.ssrc) + "(" +
Bjorn Terelius0295a962017-10-25 17:42:41 +02001524 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001525 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001526 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1527 uint64_t first_capture_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001528 timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp);
1529 uint64_t first_send_timestamp = packets.front().rtp.log_time_us();
1530 for (const auto& packet : packets) {
Bjorn Terelius0295a962017-10-25 17:42:41 +02001531 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001532 packet.rtp.header.timestamp)) -
Bjorn Terelius0295a962017-10-25 17:42:41 +02001533 first_capture_timestamp) /
1534 *estimated_frequency * 1000;
1535 double send_time_ms =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001536 static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) /
1537 1000;
Björn Tereliuscb241582022-02-25 08:22:38 +00001538 float x = config_.GetCallTimeSec(packet.rtp.log_time());
Bjorn Terelius0295a962017-10-25 17:42:41 +02001539 float y = send_time_ms - capture_time_ms;
1540 pacer_delay_series.points.emplace_back(x, y);
1541 }
1542 plot->AppendTimeSeries(std::move(pacer_delay_series));
1543 }
1544
Bjorn Terelius068fc352019-02-13 22:38:25 +01001545 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1546 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001547 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1548 plot->SetTitle(
1549 "Delay from capture to send time. (First packet normalized to 0.)");
1550}
1551
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001552void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction,
1553 Plot* plot) {
1554 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1555 TimeSeries rtp_timestamps(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001556 GetStreamName(parsed_log_, direction, stream.ssrc) + " capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001557 LineStyle::kLine, PointStyle::kHighlight);
1558 for (const auto& packet : stream.packet_view) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001559 float x = config_.GetCallTimeSec(packet.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001560 float y = packet.header.timestamp;
1561 rtp_timestamps.points.emplace_back(x, y);
stefane372d3c2017-02-02 08:04:18 -08001562 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001563 plot->AppendTimeSeries(std::move(rtp_timestamps));
Björn Tereliusff612732018-04-25 14:23:01 +00001564
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001565 TimeSeries rtcp_timestamps(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001566 GetStreamName(parsed_log_, direction, stream.ssrc) +
1567 " rtcp capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001568 LineStyle::kLine, PointStyle::kHighlight);
1569 // TODO(terelius): Why only sender reports?
1570 const auto& sender_reports = parsed_log_.sender_reports(direction);
1571 for (const auto& rtcp : sender_reports) {
1572 if (rtcp.sr.sender_ssrc() != stream.ssrc)
1573 continue;
Björn Tereliuscb241582022-02-25 08:22:38 +00001574 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001575 float y = rtcp.sr.rtp_timestamp();
1576 rtcp_timestamps.points.emplace_back(x, y);
Björn Tereliusff612732018-04-25 14:23:01 +00001577 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001578 plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps));
stefane372d3c2017-02-02 08:04:18 -08001579 }
1580
Bjorn Terelius068fc352019-02-13 22:38:25 +01001581 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1582 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001583 plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin);
1584 plot->SetTitle(GetDirectionAsString(direction) + " timestamps");
stefane372d3c2017-02-02 08:04:18 -08001585}
michaelt6e5b2192017-02-22 07:33:27 -08001586
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001587void EventLogAnalyzer::CreateSenderAndReceiverReportPlot(
1588 PacketDirection direction,
1589 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
1590 std::string title,
1591 std::string yaxis_label,
1592 Plot* plot) {
1593 std::map<uint32_t, TimeSeries> sr_reports_by_ssrc;
1594 const auto& sender_reports = parsed_log_.sender_reports(direction);
1595 for (const auto& rtcp : sender_reports) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001596 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001597 uint32_t ssrc = rtcp.sr.sender_ssrc();
1598 for (const auto& block : rtcp.sr.report_blocks()) {
1599 float y = fy(block);
1600 auto sr_report_it = sr_reports_by_ssrc.find(ssrc);
1601 bool inserted;
1602 if (sr_report_it == sr_reports_by_ssrc.end()) {
1603 std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001604 ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) +
1605 " Sender Reports",
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001606 LineStyle::kLine, PointStyle::kHighlight));
1607 }
1608 sr_report_it->second.points.emplace_back(x, y);
1609 }
1610 }
1611 for (auto& kv : sr_reports_by_ssrc) {
1612 plot->AppendTimeSeries(std::move(kv.second));
1613 }
1614
1615 std::map<uint32_t, TimeSeries> rr_reports_by_ssrc;
1616 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
1617 for (const auto& rtcp : receiver_reports) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001618 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001619 uint32_t ssrc = rtcp.rr.sender_ssrc();
1620 for (const auto& block : rtcp.rr.report_blocks()) {
1621 float y = fy(block);
1622 auto rr_report_it = rr_reports_by_ssrc.find(ssrc);
1623 bool inserted;
1624 if (rr_report_it == rr_reports_by_ssrc.end()) {
1625 std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001626 ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) +
1627 " Receiver Reports",
1628 LineStyle::kLine, PointStyle::kHighlight));
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001629 }
1630 rr_report_it->second.points.emplace_back(x, y);
1631 }
1632 }
1633 for (auto& kv : rr_reports_by_ssrc) {
1634 plot->AppendTimeSeries(std::move(kv.second));
1635 }
1636
Bjorn Terelius068fc352019-02-13 22:38:25 +01001637 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1638 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001639 plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin);
1640 plot->SetTitle(title);
1641}
1642
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001643void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
1644 std::map<uint32_t, TimeSeries> configs_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001645 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001646 if (configs_by_cp_id.find(config.candidate_pair_id) ==
1647 configs_by_cp_id.end()) {
1648 const std::string candidate_pair_desc =
1649 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08001650 configs_by_cp_id[config.candidate_pair_id] =
1651 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
1652 candidate_pair_desc,
1653 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001654 candidate_pair_desc_by_id_[config.candidate_pair_id] =
1655 candidate_pair_desc;
1656 }
Björn Tereliuscb241582022-02-25 08:22:38 +00001657 float x = config_.GetCallTimeSec(config.log_time());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001658 float y = static_cast<float>(config.type);
1659 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
1660 }
1661
1662 // TODO(qingsi): There can be a large number of candidate pairs generated by
1663 // certain calls and the frontend cannot render the chart in this case due to
1664 // the failure of generating a palette with the same number of colors.
1665 for (auto& kv : configs_by_cp_id) {
1666 plot->AppendTimeSeries(std::move(kv.second));
1667 }
1668
Bjorn Terelius068fc352019-02-13 22:38:25 +01001669 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1670 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001671 plot->SetSuggestedYAxis(0, 3, "Config Type", kBottomMargin, kTopMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001672 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001673 plot->SetYAxisTickLabels(
1674 {{static_cast<float>(IceCandidatePairConfigType::kAdded), "ADDED"},
1675 {static_cast<float>(IceCandidatePairConfigType::kUpdated), "UPDATED"},
1676 {static_cast<float>(IceCandidatePairConfigType::kDestroyed),
1677 "DESTROYED"},
1678 {static_cast<float>(IceCandidatePairConfigType::kSelected),
1679 "SELECTED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001680}
1681
1682std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
1683 uint32_t candidate_pair_id) {
1684 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
1685 candidate_pair_desc_by_id_.end()) {
1686 return candidate_pair_desc_by_id_[candidate_pair_id];
1687 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001688 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001689 // TODO(qingsi): Add the handling of the "Updated" config event after the
1690 // visualization of property change for candidate pairs is introduced.
1691 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
1692 candidate_pair_desc_by_id_.end()) {
1693 const std::string candidate_pair_desc =
1694 GetCandidatePairLogDescriptionAsString(config);
1695 candidate_pair_desc_by_id_[config.candidate_pair_id] =
1696 candidate_pair_desc;
1697 }
1698 }
1699 return candidate_pair_desc_by_id_[candidate_pair_id];
1700}
1701
1702void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001703 constexpr int kEventTypeOffset =
1704 static_cast<int>(IceCandidatePairConfigType::kNumValues);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001705 std::map<uint32_t, TimeSeries> checks_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001706 for (const auto& event : parsed_log_.ice_candidate_pair_events()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001707 if (checks_by_cp_id.find(event.candidate_pair_id) ==
1708 checks_by_cp_id.end()) {
1709 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08001710 "[" + std::to_string(event.candidate_pair_id) + "]" +
1711 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001712 LineStyle::kNone, PointStyle::kHighlight);
1713 }
Björn Tereliuscb241582022-02-25 08:22:38 +00001714 float x = config_.GetCallTimeSec(event.log_time());
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001715 float y = static_cast<float>(event.type) + kEventTypeOffset;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001716 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
1717 }
1718
1719 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
1720 for (auto& kv : checks_by_cp_id) {
1721 plot->AppendTimeSeries(std::move(kv.second));
1722 }
1723
Bjorn Terelius068fc352019-02-13 22:38:25 +01001724 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1725 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001726 plot->SetSuggestedYAxis(0, 4, "Connectivity State", kBottomMargin,
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001727 kTopMargin);
1728 plot->SetTitle("[IceEventLog] ICE connectivity checks");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001729
1730 plot->SetYAxisTickLabels(
1731 {{static_cast<float>(IceCandidatePairEventType::kCheckSent) +
1732 kEventTypeOffset,
1733 "CHECK SENT"},
1734 {static_cast<float>(IceCandidatePairEventType::kCheckReceived) +
1735 kEventTypeOffset,
1736 "CHECK RECEIVED"},
1737 {static_cast<float>(IceCandidatePairEventType::kCheckResponseSent) +
1738 kEventTypeOffset,
1739 "RESPONSE SENT"},
1740 {static_cast<float>(IceCandidatePairEventType::kCheckResponseReceived) +
1741 kEventTypeOffset,
1742 "RESPONSE RECEIVED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001743}
1744
Zach Stein10a58012018-12-07 12:26:28 -08001745void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) {
1746 TimeSeries states("DTLS Transport State", LineStyle::kNone,
1747 PointStyle::kHighlight);
1748 for (const auto& event : parsed_log_.dtls_transport_states()) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001749 float x = config_.GetCallTimeSec(event.log_time());
Zach Stein10a58012018-12-07 12:26:28 -08001750 float y = static_cast<float>(event.dtls_transport_state);
1751 states.points.emplace_back(x, y);
1752 }
1753 plot->AppendTimeSeries(std::move(states));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001754 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1755 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08001756 plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues),
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001757 "Transport State", kBottomMargin, kTopMargin);
Zach Stein10a58012018-12-07 12:26:28 -08001758 plot->SetTitle("DTLS Transport State");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001759 plot->SetYAxisTickLabels(
1760 {{static_cast<float>(DtlsTransportState::kNew), "NEW"},
1761 {static_cast<float>(DtlsTransportState::kConnecting), "CONNECTING"},
1762 {static_cast<float>(DtlsTransportState::kConnected), "CONNECTED"},
1763 {static_cast<float>(DtlsTransportState::kClosed), "CLOSED"},
1764 {static_cast<float>(DtlsTransportState::kFailed), "FAILED"}});
Zach Stein10a58012018-12-07 12:26:28 -08001765}
1766
1767void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) {
1768 TimeSeries writable("DTLS Writable", LineStyle::kNone,
1769 PointStyle::kHighlight);
1770 for (const auto& event : parsed_log_.dtls_writable_states()) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001771 float x = config_.GetCallTimeSec(event.log_time());
Zach Stein10a58012018-12-07 12:26:28 -08001772 float y = static_cast<float>(event.writable);
1773 writable.points.emplace_back(x, y);
1774 }
1775 plot->AppendTimeSeries(std::move(writable));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001776 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1777 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08001778 plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin);
1779 plot->SetTitle("DTLS Writable State");
1780}
1781
terelius54ce6802016-07-13 06:44:41 -07001782} // namespace webrtc