blob: f94adc28f6e002f887c63e268fa3d1c272e6f94b [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
philipel3fa49382019-08-20 15:59:57 +0200153 << " not close to any stardard RTP frequency.";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200154 return absl::nullopt;
ivocaac9d6f2016-09-22 07:01:47 -0700155}
156
Danil Chapovalov431abd92018-06-18 12:54:17 +0200157absl::optional<double> NetworkDelayDiff_AbsSendTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100158 const LoggedRtpPacketIncoming& old_packet,
159 const LoggedRtpPacketIncoming& new_packet) {
160 if (old_packet.rtp.header.extension.hasAbsoluteSendTime &&
161 new_packet.rtp.header.extension.hasAbsoluteSendTime) {
terelius53dc23c2017-03-13 05:24:05 -0700162 int64_t send_time_diff = WrappingDifference(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100163 new_packet.rtp.header.extension.absoluteSendTime,
164 old_packet.rtp.header.extension.absoluteSendTime, 1ul << 24);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200165 int64_t recv_time_diff =
166 new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700167 double delay_change_us =
168 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100169 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700170 } else {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200171 return absl::nullopt;
terelius6addf492016-08-23 17:34:07 -0700172 }
173}
174
Danil Chapovalov431abd92018-06-18 12:54:17 +0200175absl::optional<double> NetworkDelayDiff_CaptureTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100176 const LoggedRtpPacketIncoming& old_packet,
177 const LoggedRtpPacketIncoming& new_packet,
178 const double sample_rate) {
179 int64_t send_time_diff =
180 WrappingDifference(new_packet.rtp.header.timestamp,
181 old_packet.rtp.header.timestamp, 1ull << 32);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200182 int64_t recv_time_diff = new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700183
terelius53dc23c2017-03-13 05:24:05 -0700184 double delay_change =
185 static_cast<double>(recv_time_diff) / 1000 -
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100186 static_cast<double>(send_time_diff) / sample_rate * 1000;
terelius53dc23c2017-03-13 05:24:05 -0700187 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100188 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100189 RTC_LOG(LS_WARNING) << "Old capture time "
190 << old_packet.rtp.header.timestamp << ", received time "
191 << old_packet.log_time_us();
192 RTC_LOG(LS_WARNING) << "New capture time "
193 << new_packet.rtp.header.timestamp << ", received time "
194 << new_packet.log_time_us();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100195 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800196 << static_cast<double>(recv_time_diff) /
197 kNumMicrosecsPerSec
198 << "s";
Mirko Bonadei675513b2017-11-09 11:09:25 +0100199 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100200 << static_cast<double>(send_time_diff) / sample_rate
Mirko Bonadei675513b2017-11-09 11:09:25 +0100201 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700202 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100203 return delay_change;
terelius53dc23c2017-03-13 05:24:05 -0700204}
205
terelius6addf492016-08-23 17:34:07 -0700206
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100207template <typename T>
208TimeSeries CreateRtcpTypeTimeSeries(const std::vector<T>& rtcp_list,
209 AnalyzerConfig config,
210 std::string rtcp_name,
211 int category_id) {
212 TimeSeries time_series(rtcp_name, LineStyle::kNone, PointStyle::kHighlight);
213 for (const auto& rtcp : rtcp_list) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000214 float x = config.GetCallTimeSec(rtcp.timestamp);
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100215 float y = category_id;
216 time_series.points.emplace_back(x, y);
217 }
218 return time_series;
219}
220
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800221const char kUnknownEnumValue[] = "unknown";
222
223const char kIceCandidateTypeLocal[] = "local";
224const char kIceCandidateTypeStun[] = "stun";
225const char kIceCandidateTypePrflx[] = "prflx";
226const char kIceCandidateTypeRelay[] = "relay";
227
228const char kProtocolUdp[] = "udp";
229const char kProtocolTcp[] = "tcp";
230const char kProtocolSsltcp[] = "ssltcp";
231const char kProtocolTls[] = "tls";
232
233const char kAddressFamilyIpv4[] = "ipv4";
234const char kAddressFamilyIpv6[] = "ipv6";
235
236const char kNetworkTypeEthernet[] = "ethernet";
237const char kNetworkTypeLoopback[] = "loopback";
238const char kNetworkTypeWifi[] = "wifi";
239const char kNetworkTypeVpn[] = "vpn";
240const char kNetworkTypeCellular[] = "cellular";
241
242std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) {
243 switch (type) {
244 case webrtc::IceCandidateType::kLocal:
245 return kIceCandidateTypeLocal;
246 case webrtc::IceCandidateType::kStun:
247 return kIceCandidateTypeStun;
248 case webrtc::IceCandidateType::kPrflx:
249 return kIceCandidateTypePrflx;
250 case webrtc::IceCandidateType::kRelay:
251 return kIceCandidateTypeRelay;
252 default:
253 return kUnknownEnumValue;
254 }
255}
256
257std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) {
258 switch (protocol) {
259 case webrtc::IceCandidatePairProtocol::kUdp:
260 return kProtocolUdp;
261 case webrtc::IceCandidatePairProtocol::kTcp:
262 return kProtocolTcp;
263 case webrtc::IceCandidatePairProtocol::kSsltcp:
264 return kProtocolSsltcp;
265 case webrtc::IceCandidatePairProtocol::kTls:
266 return kProtocolTls;
267 default:
268 return kUnknownEnumValue;
269 }
270}
271
272std::string GetAddressFamilyAsString(
273 webrtc::IceCandidatePairAddressFamily family) {
274 switch (family) {
275 case webrtc::IceCandidatePairAddressFamily::kIpv4:
276 return kAddressFamilyIpv4;
277 case webrtc::IceCandidatePairAddressFamily::kIpv6:
278 return kAddressFamilyIpv6;
279 default:
280 return kUnknownEnumValue;
281 }
282}
283
284std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) {
285 switch (type) {
286 case webrtc::IceCandidateNetworkType::kEthernet:
287 return kNetworkTypeEthernet;
288 case webrtc::IceCandidateNetworkType::kLoopback:
289 return kNetworkTypeLoopback;
290 case webrtc::IceCandidateNetworkType::kWifi:
291 return kNetworkTypeWifi;
292 case webrtc::IceCandidateNetworkType::kVpn:
293 return kNetworkTypeVpn;
294 case webrtc::IceCandidateNetworkType::kCellular:
295 return kNetworkTypeCellular;
296 default:
297 return kUnknownEnumValue;
298 }
299}
300
301std::string GetCandidatePairLogDescriptionAsString(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200302 const LoggedIceCandidatePairConfig& config) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800303 // Example: stun:wifi->relay(tcp):cellular@udp:ipv4
304 // represents a pair of a local server-reflexive candidate on a WiFi network
305 // and a remote relay candidate using TCP as the relay protocol on a cell
306 // network, when the candidate pair communicates over UDP using IPv4.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200307 rtc::StringBuilder ss;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800308 std::string local_candidate_type =
309 GetIceCandidateTypeAsString(config.local_candidate_type);
310 std::string remote_candidate_type =
311 GetIceCandidateTypeAsString(config.remote_candidate_type);
312 if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) {
313 local_candidate_type +=
314 "(" + GetProtocolAsString(config.local_relay_protocol) + ")";
315 }
316 ss << local_candidate_type << ":"
317 << GetNetworkTypeAsString(config.local_network_type) << ":"
318 << GetAddressFamilyAsString(config.local_address_family) << "->"
319 << remote_candidate_type << ":"
320 << GetAddressFamilyAsString(config.remote_address_family) << "@"
321 << GetProtocolAsString(config.candidate_pair_protocol);
Jonas Olsson84df1c72018-09-14 16:59:32 +0200322 return ss.Release();
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800323}
324
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200325std::string GetDirectionAsString(PacketDirection direction) {
326 if (direction == kIncomingPacket) {
327 return "Incoming";
328 } else {
329 return "Outgoing";
330 }
331}
332
333std::string GetDirectionAsShortString(PacketDirection direction) {
334 if (direction == kIncomingPacket) {
335 return "In";
336 } else {
337 return "Out";
338 }
339}
340
terelius54ce6802016-07-13 06:44:41 -0700341} // namespace
342
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100343EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200344 bool normalize_time)
Bjorn Terelius068fc352019-02-13 22:38:25 +0100345 : parsed_log_(log) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000346 config_.window_duration_ = TimeDelta::Millis(250);
347 config_.step_ = TimeDelta::Millis(10);
348 if (!log.start_log_events().empty()) {
349 config_.rtc_to_utc_offset_ = log.start_log_events()[0].utc_time() -
350 log.start_log_events()[0].log_time();
351 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100352 config_.normalize_time_ = normalize_time;
353 config_.begin_time_ = parsed_log_.first_timestamp();
354 config_.end_time_ = parsed_log_.last_timestamp();
355 if (config_.end_time_ < config_.begin_time_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200356 RTC_LOG(LS_WARNING) << "No useful events in the log.";
Björn Tereliuscb241582022-02-25 08:22:38 +0000357 config_.begin_time_ = config_.end_time_ = Timestamp::Zero();
Björn Tereliusff612732018-04-25 14:23:01 +0000358 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200359
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200360 RTC_LOG(LS_INFO) << "Log is "
Björn Tereliuscb241582022-02-25 08:22:38 +0000361 << (parsed_log_.last_timestamp().ms() -
362 parsed_log_.first_timestamp().ms()) /
363 1000
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200364 << " seconds long.";
Bjorn Terelius48b82792020-05-19 10:57:24 +0200365}
366
367EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
368 const AnalyzerConfig& config)
369 : parsed_log_(log), config_(config) {
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200370 RTC_LOG(LS_INFO) << "Log is "
Björn Tereliuscb241582022-02-25 08:22:38 +0000371 << (parsed_log_.last_timestamp().ms() -
372 parsed_log_.first_timestamp().ms()) /
373 1000
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200374 << " seconds long.";
terelius54ce6802016-07-13 06:44:41 -0700375}
376
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200377class BitrateObserver : public RemoteBitrateObserver {
Stefan Holmer13181032016-07-29 14:48:54 +0200378 public:
379 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
380
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200381 void Update(NetworkControlUpdate update) {
382 if (update.target_rate) {
383 last_bitrate_bps_ = update.target_rate->target_rate.bps();
384 bitrate_updated_ = true;
385 }
Stefan Holmer13181032016-07-29 14:48:54 +0200386 }
387
388 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
389 uint32_t bitrate) override {}
390
391 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
392 bool GetAndResetBitrateUpdated() {
393 bool bitrate_updated = bitrate_updated_;
394 bitrate_updated_ = false;
395 return bitrate_updated;
396 }
397
398 private:
399 uint32_t last_bitrate_bps_;
400 bool bitrate_updated_;
401};
402
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200403void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction,
terelius54ce6802016-07-13 06:44:41 -0700404 Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200405 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
406 // Filter on SSRC.
407 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700408 continue;
terelius54ce6802016-07-13 06:44:41 -0700409 }
terelius54ce6802016-07-13 06:44:41 -0700410
Bjorn Terelius48b82792020-05-19 10:57:24 +0200411 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200412 LineStyle::kBar);
413 auto GetPacketSize = [](const LoggedRtpPacket& packet) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200414 return absl::optional<float>(packet.total_length);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200415 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200416 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000417 return this->config_.GetCallTimeSec(packet.timestamp);
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200418 };
419 ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize,
420 stream.packet_view, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700421 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700422 }
423
Bjorn Terelius068fc352019-02-13 22:38:25 +0100424 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
425 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700426 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
427 kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200428 plot->SetTitle(GetDirectionAsString(direction) + " RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700429}
430
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100431void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction,
432 Plot* plot) {
433 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
434 parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1));
435 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
436 parsed_log_.receiver_reports(direction), config_, "RR", 2));
437 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
438 parsed_log_.sender_reports(direction), config_, "SR", 3));
439 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
440 parsed_log_.extended_reports(direction), config_, "XR", 4));
441 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction),
442 config_, "NACK", 5));
443 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction),
444 config_, "REMB", 6));
445 plot->AppendTimeSeries(
446 CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7));
447 plot->AppendTimeSeries(
448 CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8));
Björn Terelius4ef56382021-02-03 14:12:24 +0100449 plot->AppendTimeSeries(
450 CreateRtcpTypeTimeSeries(parsed_log_.byes(direction), config_, "BYE", 9));
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100451 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
452 "Time (s)", kLeftMargin, kRightMargin);
453 plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin);
454 plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets");
Bjorn Tereliusf640b872019-07-24 15:46:39 +0200455 plot->SetYAxisTickLabels({{1, "TWCC"},
456 {2, "RR"},
457 {3, "SR"},
458 {4, "XR"},
459 {5, "NACK"},
460 {6, "REMB"},
461 {7, "FIR"},
Björn Terelius4ef56382021-02-03 14:12:24 +0100462 {8, "PLI"},
463 {9, "BYE"}});
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100464}
465
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200466template <typename IterableType>
philipelccd74892016-09-05 02:46:25 -0700467void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
philipelccd74892016-09-05 02:46:25 -0700468 Plot* plot,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200469 const IterableType& packets,
470 const std::string& label) {
471 TimeSeries time_series(label, LineStyle::kStep);
472 for (size_t i = 0; i < packets.size(); i++) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000473 float x = config_.GetCallTimeSec(packets[i].log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200474 time_series.points.emplace_back(x, i + 1);
philipelccd74892016-09-05 02:46:25 -0700475 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200476 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700477}
478
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200479void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction,
480 Plot* plot) {
481 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
482 if (!MatchingSsrc(stream.ssrc, desired_ssrc_))
483 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200484 std::string label = std::string("RTP ") +
485 GetStreamName(parsed_log_, direction, stream.ssrc);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200486 CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label);
487 }
488 std::string label =
489 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")";
490 if (direction == kIncomingPacket) {
491 CreateAccumulatedPacketsTimeSeries(
492 plot, parsed_log_.incoming_rtcp_packets(), label);
493 } else {
494 CreateAccumulatedPacketsTimeSeries(
495 plot, parsed_log_.outgoing_rtcp_packets(), label);
496 }
philipelccd74892016-09-05 02:46:25 -0700497
Bjorn Terelius068fc352019-02-13 22:38:25 +0100498 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
499 "Time (s)", kLeftMargin, kRightMargin);
philipelccd74892016-09-05 02:46:25 -0700500 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200501 plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) +
502 " RTP/RTCP packets");
philipelccd74892016-09-05 02:46:25 -0700503}
504
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200505void EventLogAnalyzer::CreatePacketRateGraph(PacketDirection direction,
506 Plot* plot) {
507 auto CountPackets = [](auto packet) { return 1.0; };
508 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
509 // Filter on SSRC.
510 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
511 continue;
512 }
513 TimeSeries time_series(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200514 std::string("RTP ") +
515 GetStreamName(parsed_log_, direction, stream.ssrc),
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200516 LineStyle::kLine);
517 MovingAverage<LoggedRtpPacket, double>(CountPackets, stream.packet_view,
518 config_, &time_series);
519 plot->AppendTimeSeries(std::move(time_series));
520 }
521 TimeSeries time_series(
522 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")",
523 LineStyle::kLine);
524 if (direction == kIncomingPacket) {
525 MovingAverage<LoggedRtcpPacketIncoming, double>(
526 CountPackets, parsed_log_.incoming_rtcp_packets(), config_,
527 &time_series);
528 } else {
529 MovingAverage<LoggedRtcpPacketOutgoing, double>(
530 CountPackets, parsed_log_.outgoing_rtcp_packets(), config_,
531 &time_series);
532 }
533 plot->AppendTimeSeries(std::move(time_series));
534
535 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
536 "Time (s)", kLeftMargin, kRightMargin);
537 plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin,
538 kTopMargin);
539 plot->SetTitle("Rate of " + GetDirectionAsString(direction) +
540 " RTP/RTCP packets");
541}
542
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200543void EventLogAnalyzer::CreateTotalPacketRateGraph(PacketDirection direction,
544 Plot* plot) {
545 // Contains a log timestamp to enable counting logged events of different
546 // types using MovingAverage().
547 class LogTime {
548 public:
Björn Tereliuscb241582022-02-25 08:22:38 +0000549 explicit LogTime(Timestamp log_time) : log_time_(log_time) {}
550 Timestamp log_time() const { return log_time_; }
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200551
552 private:
Björn Tereliuscb241582022-02-25 08:22:38 +0000553 Timestamp log_time_;
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200554 };
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200555 std::vector<LogTime> packet_times;
556 auto handle_rtp = [&](const LoggedRtpPacket& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000557 packet_times.emplace_back(packet.log_time());
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200558 };
559 RtcEventProcessor process;
560 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
561 process.AddEvents(stream.packet_view, handle_rtp);
562 }
563 if (direction == kIncomingPacket) {
564 auto handle_incoming_rtcp = [&](const LoggedRtcpPacketIncoming& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000565 packet_times.emplace_back(packet.log_time());
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200566 };
567 process.AddEvents(parsed_log_.incoming_rtcp_packets(),
568 handle_incoming_rtcp);
569 } else {
570 auto handle_outgoing_rtcp = [&](const LoggedRtcpPacketOutgoing& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000571 packet_times.emplace_back(packet.log_time());
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200572 };
573 process.AddEvents(parsed_log_.outgoing_rtcp_packets(),
574 handle_outgoing_rtcp);
575 }
576 process.ProcessEventsInOrder();
577 TimeSeries time_series(std::string("Total ") + "(" +
578 GetDirectionAsShortString(direction) + ") packets",
579 LineStyle::kLine);
580 MovingAverage<LogTime, uint64_t>([](auto packet) { return 1; }, packet_times,
581 config_, &time_series);
582 plot->AppendTimeSeries(std::move(time_series));
583
584 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
585 "Time (s)", kLeftMargin, kRightMargin);
586 plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin,
587 kTopMargin);
588 plot->SetTitle("Rate of all " + GetDirectionAsString(direction) +
589 " RTP/RTCP packets");
590}
591
terelius54ce6802016-07-13 06:44:41 -0700592// For each SSRC, plot the time between the consecutive playouts.
593void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200594 for (const auto& playout_stream : parsed_log_.audio_playout_events()) {
595 uint32_t ssrc = playout_stream.first;
596 if (!MatchingSsrc(ssrc, desired_ssrc_))
597 continue;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200598 absl::optional<int64_t> last_playout_ms;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200599 TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar);
Minyue Li27e2b7d2018-05-07 15:20:24 +0200600 for (const auto& playout_event : playout_stream.second) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000601 float x = config_.GetCallTimeSec(playout_event.log_time());
Minyue Li27e2b7d2018-05-07 15:20:24 +0200602 int64_t playout_time_ms = playout_event.log_time_ms();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200603 // If there were no previous playouts, place the point on the x-axis.
Minyue Li27e2b7d2018-05-07 15:20:24 +0200604 float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200605 time_series.points.push_back(TimeSeriesPoint(x, y));
Minyue Li27e2b7d2018-05-07 15:20:24 +0200606 last_playout_ms.emplace(playout_time_ms);
terelius54ce6802016-07-13 06:44:41 -0700607 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200608 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700609 }
610
Bjorn Terelius068fc352019-02-13 22:38:25 +0100611 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
612 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700613 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
614 kTopMargin);
615 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700616}
617
ivocaac9d6f2016-09-22 07:01:47 -0700618// For audio SSRCs, plot the audio level.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200619void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction,
620 Plot* plot) {
621 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
Bjorn Terelius48b82792020-05-19 10:57:24 +0200622 if (!IsAudioSsrc(parsed_log_, direction, stream.ssrc))
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200623 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200624 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200625 LineStyle::kLine);
626 for (auto& packet : stream.packet_view) {
ivocaac9d6f2016-09-22 07:01:47 -0700627 if (packet.header.extension.hasAudioLevel) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000628 float x = config_.GetCallTimeSec(packet.log_time());
ivocaac9d6f2016-09-22 07:01:47 -0700629 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
630 // Here we convert it to dBov.
631 float y = static_cast<float>(-packet.header.extension.audioLevel);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200632 time_series.points.emplace_back(TimeSeriesPoint(x, y));
ivocaac9d6f2016-09-22 07:01:47 -0700633 }
634 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200635 plot->AppendTimeSeries(std::move(time_series));
ivocaac9d6f2016-09-22 07:01:47 -0700636 }
637
Bjorn Terelius068fc352019-02-13 22:38:25 +0100638 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
639 "Time (s)", kLeftMargin, kRightMargin);
Yves Gerey665174f2018-06-19 15:03:05 +0200640 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200641 plot->SetTitle(GetDirectionAsString(direction) + " audio level");
ivocaac9d6f2016-09-22 07:01:47 -0700642}
643
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100644// For each SSRC, plot the sequence number difference between consecutive
645// incoming packets.
terelius54ce6802016-07-13 06:44:41 -0700646void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200647 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
648 // Filter on SSRC.
649 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700650 continue;
terelius54ce6802016-07-13 06:44:41 -0700651 }
terelius54ce6802016-07-13 06:44:41 -0700652
Bjorn Terelius48b82792020-05-19 10:57:24 +0200653 TimeSeries time_series(
654 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc),
655 LineStyle::kBar);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200656 auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet,
657 const LoggedRtpPacketIncoming& new_packet) {
658 int64_t diff =
659 WrappingDifference(new_packet.rtp.header.sequenceNumber,
660 old_packet.rtp.header.sequenceNumber, 1ul << 16);
661 return diff;
662 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200663 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000664 return this->config_.GetCallTimeSec(packet.log_time());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200665 };
666 ProcessPairs<LoggedRtpPacketIncoming, float>(
667 ToCallTime, GetSequenceNumberDiff, stream.incoming_packets,
668 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700669 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700670 }
671
Bjorn Terelius068fc352019-02-13 22:38:25 +0100672 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
673 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700674 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
675 kTopMargin);
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100676 plot->SetTitle("Incoming sequence number delta");
terelius54ce6802016-07-13 06:44:41 -0700677}
678
Stefan Holmer99f8e082016-09-09 13:37:50 +0200679void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200680 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
681 const std::vector<LoggedRtpPacketIncoming>& packets =
682 stream.incoming_packets;
683 // Filter on SSRC.
Mirko Bonadei1f173152019-07-25 15:28:14 +0200684 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.empty()) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200685 continue;
686 }
687
Bjorn Terelius48b82792020-05-19 10:57:24 +0200688 TimeSeries time_series(
689 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc),
690 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200691 // TODO(terelius): Should the window and step size be read from the class
692 // instead?
Björn Tereliuscb241582022-02-25 08:22:38 +0000693 const TimeDelta kWindow = TimeDelta::Millis(1000);
694 const TimeDelta kStep = TimeDelta::Millis(1000);
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100695 SeqNumUnwrapper<uint16_t> unwrapper_;
696 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800697 size_t window_index_begin = 0;
698 size_t window_index_end = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200699 uint64_t highest_seq_number =
700 unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
701 uint64_t highest_prior_seq_number =
702 prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
terelius4c9b4af2017-01-30 08:44:51 -0800703
Björn Tereliuscb241582022-02-25 08:22:38 +0000704 for (Timestamp t = config_.begin_time_; t < config_.end_time_ + kStep;
Bjorn Terelius068fc352019-02-13 22:38:25 +0100705 t += kStep) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200706 while (window_index_end < packets.size() &&
Björn Tereliuscb241582022-02-25 08:22:38 +0000707 packets[window_index_end].rtp.log_time() < t) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200708 uint64_t sequence_number = unwrapper_.Unwrap(
709 packets[window_index_end].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800710 highest_seq_number = std::max(highest_seq_number, sequence_number);
711 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200712 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200713 while (window_index_begin < packets.size() &&
Björn Tereliuscb241582022-02-25 08:22:38 +0000714 packets[window_index_begin].rtp.log_time() < t - kWindow) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200715 uint64_t sequence_number = prior_unwrapper_.Unwrap(
716 packets[window_index_begin].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800717 highest_prior_seq_number =
718 std::max(highest_prior_seq_number, sequence_number);
719 ++window_index_begin;
720 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100721 float x = config_.GetCallTimeSec(t);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200722 uint64_t expected_packets = highest_seq_number - highest_prior_seq_number;
terelius4c9b4af2017-01-30 08:44:51 -0800723 if (expected_packets > 0) {
724 int64_t received_packets = window_index_end - window_index_begin;
725 int64_t lost_packets = expected_packets - received_packets;
726 float y = static_cast<float>(lost_packets) / expected_packets * 100;
727 time_series.points.emplace_back(x, y);
728 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200729 }
philipel35ba9bd2017-04-19 05:58:51 -0700730 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200731 }
732
Bjorn Terelius068fc352019-02-13 22:38:25 +0100733 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
734 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100735 plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin);
736 plot->SetTitle("Incoming packet loss (derived from incoming packets)");
Stefan Holmer99f8e082016-09-09 13:37:50 +0200737}
738
terelius2ee076d2017-08-15 02:04:02 -0700739void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100740 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200741 // Filter on SSRC.
742 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
Bjorn Terelius48b82792020-05-19 10:57:24 +0200743 IsRtxSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700744 continue;
745 }
terelius54ce6802016-07-13 06:44:41 -0700746
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100747 const std::vector<LoggedRtpPacketIncoming>& packets =
748 stream.incoming_packets;
749 if (packets.size() < 100) {
750 RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with "
751 << packets.size() << " packets in the stream.";
752 continue;
753 }
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200754 int64_t segment_end_us = parsed_log_.first_log_segment().stop_time_us();
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100755 absl::optional<uint32_t> estimated_frequency =
Bjorn Terelius48b82792020-05-19 10:57:24 +0200756 EstimateRtpClockFrequency(packets, segment_end_us);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100757 if (!estimated_frequency)
758 continue;
759 const double frequency_hz = *estimated_frequency;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200760 if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc) &&
761 frequency_hz != 90000) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100762 RTC_LOG(LS_WARNING)
763 << "Video stream should use a 90 kHz clock but appears to use "
764 << frequency_hz / 1000 << ". Discarding.";
765 continue;
766 }
767
768 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000769 return this->config_.GetCallTimeSec(packet.log_time());
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100770 };
771 auto ToNetworkDelay = [frequency_hz](
772 const LoggedRtpPacketIncoming& old_packet,
773 const LoggedRtpPacketIncoming& new_packet) {
774 return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz);
775 };
776
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200777 TimeSeries capture_time_data(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200778 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) +
779 " capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200780 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100781 AccumulatePairs<LoggedRtpPacketIncoming, double>(
782 ToCallTime, ToNetworkDelay, packets, &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700783 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700784
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200785 TimeSeries send_time_data(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200786 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) +
787 " abs-send-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200788 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100789 AccumulatePairs<LoggedRtpPacketIncoming, double>(
790 ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data);
791 plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700792 }
793
Bjorn Terelius068fc352019-02-13 22:38:25 +0100794 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
795 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +0100796 plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin);
797 plot->SetTitle("Incoming network delay (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700798}
799
tereliusf736d232016-08-04 10:00:11 -0700800// Plot the fraction of packets lost (as perceived by the loss-based BWE).
801void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100802 TimeSeries time_series("Fraction lost", LineStyle::kLine,
803 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200804 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000805 float x = config_.GetCallTimeSec(bwe_update.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200806 float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700807 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700808 }
tereliusf736d232016-08-04 10:00:11 -0700809
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200810 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +0100811 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
812 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100813 plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin);
814 plot->SetTitle("Outgoing packet loss (as reported by BWE)");
tereliusf736d232016-08-04 10:00:11 -0700815}
816
terelius54ce6802016-07-13 06:44:41 -0700817// Plot the total bandwidth used by all RTP streams.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200818void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) {
819 // TODO(terelius): This could be provided by the parser.
Björn Tereliuscb241582022-02-25 08:22:38 +0000820 std::multimap<Timestamp, size_t> packets_in_order;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200821 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
822 for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets)
823 packets_in_order.insert(
Björn Tereliuscb241582022-02-25 08:22:38 +0000824 std::make_pair(packet.rtp.log_time(), packet.rtp.total_length));
terelius54ce6802016-07-13 06:44:41 -0700825 }
826
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200827 auto window_begin = packets_in_order.begin();
828 auto window_end = packets_in_order.begin();
terelius54ce6802016-07-13 06:44:41 -0700829 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700830
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800831 if (!packets_in_order.empty()) {
832 // Calculate a moving average of the bitrate and store in a TimeSeries.
833 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
Björn Tereliuscb241582022-02-25 08:22:38 +0000834 for (Timestamp time = config_.begin_time_;
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800835 time < config_.end_time_ + config_.step_; time += config_.step_) {
836 while (window_end != packets_in_order.end() && window_end->first < time) {
837 bytes_in_window += window_end->second;
838 ++window_end;
839 }
840 while (window_begin != packets_in_order.end() &&
841 window_begin->first < time - config_.window_duration_) {
842 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
843 bytes_in_window -= window_begin->second;
844 ++window_begin;
845 }
846 float window_duration_in_seconds =
Björn Tereliuscb241582022-02-25 08:22:38 +0000847 static_cast<float>(config_.window_duration_.us()) /
848 kNumMicrosecsPerSec;
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800849 float x = config_.GetCallTimeSec(time);
850 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
851 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700852 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800853 plot->AppendTimeSeries(std::move(bitrate_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200854 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200855
856 // Overlay the outgoing REMB over incoming bitrate.
857 TimeSeries remb_series("Remb", LineStyle::kStep);
858 for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000859 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200860 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
861 remb_series.points.emplace_back(x, y);
862 }
863 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
864
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800865 if (!parsed_log_.generic_packets_received().empty()) {
866 TimeSeries time_series("Incoming generic bitrate", LineStyle::kLine);
867 auto GetPacketSizeKilobits = [](const LoggedGenericPacketReceived& packet) {
868 return packet.packet_length * 8.0 / 1000.0;
869 };
870 MovingAverage<LoggedGenericPacketReceived, double>(
871 GetPacketSizeKilobits, parsed_log_.generic_packets_received(), config_,
872 &time_series);
873 plot->AppendTimeSeries(std::move(time_series));
874 }
875
Bjorn Terelius068fc352019-02-13 22:38:25 +0100876 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
877 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200878 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
879 plot->SetTitle("Incoming RTP bitrate");
880}
881
882// Plot the total bandwidth used by all RTP streams.
883void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
884 bool show_detector_state,
885 bool show_alr_state) {
886 // TODO(terelius): This could be provided by the parser.
Björn Tereliuscb241582022-02-25 08:22:38 +0000887 std::multimap<Timestamp, size_t> packets_in_order;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200888 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
889 for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets)
890 packets_in_order.insert(
Björn Tereliuscb241582022-02-25 08:22:38 +0000891 std::make_pair(packet.rtp.log_time(), packet.rtp.total_length));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200892 }
893
894 auto window_begin = packets_in_order.begin();
895 auto window_end = packets_in_order.begin();
896 size_t bytes_in_window = 0;
897
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800898 if (!packets_in_order.empty()) {
899 // Calculate a moving average of the bitrate and store in a TimeSeries.
900 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
Björn Tereliuscb241582022-02-25 08:22:38 +0000901 for (Timestamp time = config_.begin_time_;
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800902 time < config_.end_time_ + config_.step_; time += config_.step_) {
903 while (window_end != packets_in_order.end() && window_end->first < time) {
904 bytes_in_window += window_end->second;
905 ++window_end;
906 }
907 while (window_begin != packets_in_order.end() &&
908 window_begin->first < time - config_.window_duration_) {
909 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
910 bytes_in_window -= window_begin->second;
911 ++window_begin;
912 }
913 float window_duration_in_seconds =
Björn Tereliuscb241582022-02-25 08:22:38 +0000914 static_cast<float>(config_.window_duration_.us()) /
915 kNumMicrosecsPerSec;
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800916 float x = config_.GetCallTimeSec(time);
917 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
918 bitrate_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200919 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800920 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700921 }
922
terelius8058e582016-07-25 01:32:41 -0700923 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200924 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
925 for (auto& loss_update : parsed_log_.bwe_loss_updates()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000926 float x = config_.GetCallTimeSec(loss_update.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200927 float y = static_cast<float>(loss_update.bitrate_bps) / 1000;
928 loss_series.points.emplace_back(x, y);
929 }
philipel10fc0e62017-04-11 01:50:23 -0700930
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200931 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
932 IntervalSeries overusing_series("Overusing", "#ff8e82",
933 IntervalSeries::kHorizontal);
934 IntervalSeries underusing_series("Underusing", "#5092fc",
935 IntervalSeries::kHorizontal);
936 IntervalSeries normal_series("Normal", "#c4ffc4",
937 IntervalSeries::kHorizontal);
938 IntervalSeries* last_series = &normal_series;
Björn Tereliuscb241582022-02-25 08:22:38 +0000939 float last_detector_switch = 0.0;
philipel23c7f252017-07-14 06:30:03 -0700940
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200941 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
philipel23c7f252017-07-14 06:30:03 -0700942
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200943 for (auto& delay_update : parsed_log_.bwe_delay_updates()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000944 float x = config_.GetCallTimeSec(delay_update.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200945 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -0700946
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200947 if (last_detector_state != delay_update.detector_state) {
948 last_series->intervals.emplace_back(last_detector_switch, x);
949 last_detector_state = delay_update.detector_state;
950 last_detector_switch = x;
philipel23c7f252017-07-14 06:30:03 -0700951
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200952 switch (delay_update.detector_state) {
953 case BandwidthUsage::kBwNormal:
954 last_series = &normal_series;
955 break;
956 case BandwidthUsage::kBwUnderusing:
957 last_series = &underusing_series;
958 break;
959 case BandwidthUsage::kBwOverusing:
960 last_series = &overusing_series;
961 break;
962 case BandwidthUsage::kLast:
Artem Titovd3251962021-11-15 16:57:07 +0100963 RTC_DCHECK_NOTREACHED();
philipele127e7a2017-03-29 16:28:53 +0200964 }
965 }
philipel23c7f252017-07-14 06:30:03 -0700966
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200967 delay_series.points.emplace_back(x, y);
968 }
Bjorn Terelius9e336ec2018-04-24 16:28:35 +0200969
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200970 RTC_CHECK(last_series);
Björn Tereliuscb241582022-02-25 08:22:38 +0000971 last_series->intervals.emplace_back(last_detector_switch,
972 config_.CallEndTimeSec());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200973
974 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
975 PointStyle::kHighlight);
976 for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000977 float x = config_.GetCallTimeSec(cluster.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200978 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
979 created_series.points.emplace_back(x, y);
980 }
981
982 TimeSeries result_series("Probing results.", LineStyle::kNone,
983 PointStyle::kHighlight);
Bjorn Terelius7a0bb002018-05-29 14:45:53 +0200984 for (auto& result : parsed_log_.bwe_probe_success_events()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000985 float x = config_.GetCallTimeSec(result.log_time());
Bjorn Terelius7a0bb002018-05-29 14:45:53 +0200986 float y = static_cast<float>(result.bitrate_bps) / 1000;
987 result_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200988 }
989
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -0800990 TimeSeries probe_failures_series("Probe failed", LineStyle::kNone,
991 PointStyle::kHighlight);
992 for (auto& failure : parsed_log_.bwe_probe_failure_events()) {
Björn Tereliuscb241582022-02-25 08:22:38 +0000993 float x = config_.GetCallTimeSec(failure.log_time());
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -0800994 probe_failures_series.points.emplace_back(x, 0);
995 }
996
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200997 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
998 bool previously_in_alr = false;
Björn Tereliuscb241582022-02-25 08:22:38 +0000999 Timestamp alr_start = Timestamp::Zero();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001000 for (auto& alr : parsed_log_.alr_state_events()) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001001 float y = config_.GetCallTimeSec(alr.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001002 if (!previously_in_alr && alr.in_alr) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001003 alr_start = alr.log_time();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001004 previously_in_alr = true;
1005 } else if (previously_in_alr && !alr.in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001006 float x = config_.GetCallTimeSec(alr_start);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001007 alr_state.intervals.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001008 previously_in_alr = false;
Björn Tereliusff612732018-04-25 14:23:01 +00001009 }
Björn Tereliusff612732018-04-25 14:23:01 +00001010 }
1011
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001012 if (previously_in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001013 float x = config_.GetCallTimeSec(alr_start);
1014 float y = config_.GetCallTimeSec(config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001015 alr_state.intervals.emplace_back(x, y);
1016 }
1017
1018 if (show_detector_state) {
1019 plot->AppendIntervalSeries(std::move(overusing_series));
1020 plot->AppendIntervalSeries(std::move(underusing_series));
1021 plot->AppendIntervalSeries(std::move(normal_series));
1022 }
1023
1024 if (show_alr_state) {
1025 plot->AppendIntervalSeries(std::move(alr_state));
1026 }
1027 plot->AppendTimeSeries(std::move(loss_series));
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001028 plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001029 plot->AppendTimeSeries(std::move(delay_series));
1030 plot->AppendTimeSeries(std::move(created_series));
1031 plot->AppendTimeSeries(std::move(result_series));
1032
1033 // Overlay the incoming REMB over the outgoing bitrate.
Björn Tereliusff612732018-04-25 14:23:01 +00001034 TimeSeries remb_series("Remb", LineStyle::kStep);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001035 for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001036 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001037 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
terelius2c8e8a32017-06-02 01:29:48 -07001038 remb_series.points.emplace_back(x, y);
1039 }
1040 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1041
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001042 if (!parsed_log_.generic_packets_sent().empty()) {
1043 {
1044 TimeSeries time_series("Outgoing generic total bitrate",
1045 LineStyle::kLine);
1046 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1047 return packet.packet_length() * 8.0 / 1000.0;
1048 };
1049 MovingAverage<LoggedGenericPacketSent, double>(
1050 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1051 &time_series);
1052 plot->AppendTimeSeries(std::move(time_series));
1053 }
1054
1055 {
1056 TimeSeries time_series("Outgoing generic payload bitrate",
1057 LineStyle::kLine);
1058 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1059 return packet.payload_length * 8.0 / 1000.0;
1060 };
1061 MovingAverage<LoggedGenericPacketSent, double>(
1062 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1063 &time_series);
1064 plot->AppendTimeSeries(std::move(time_series));
1065 }
1066 }
1067
Bjorn Terelius068fc352019-02-13 22:38:25 +01001068 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1069 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001070 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001071 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001072}
1073
1074// For each SSRC, plot the bandwidth used by that stream.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001075void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction,
1076 Plot* plot) {
1077 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1078 // Filter on SSRC.
1079 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -07001080 continue;
terelius54ce6802016-07-13 06:44:41 -07001081 }
1082
Bjorn Terelius48b82792020-05-19 10:57:24 +02001083 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001084 LineStyle::kLine);
1085 auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) {
1086 return packet.total_length * 8.0 / 1000.0;
1087 };
terelius53dc23c2017-03-13 05:24:05 -07001088 MovingAverage<LoggedRtpPacket, double>(
Bjorn Terelius068fc352019-02-13 22:38:25 +01001089 GetPacketSizeKilobits, stream.packet_view, config_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001090 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001091 }
1092
Bjorn Terelius068fc352019-02-13 22:38:25 +01001093 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1094 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001095 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001096 plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001097}
1098
Bjorn Terelius9775a582019-02-15 17:29:58 +01001099// Plot the bitrate allocation for each temporal and spatial layer.
1100// Computed from RTCP XR target bitrate block, so the graph is only populated if
1101// those are sent.
1102void EventLogAnalyzer::CreateBitrateAllocationGraph(PacketDirection direction,
1103 Plot* plot) {
1104 std::map<LayerDescription, TimeSeries> time_series;
1105 const auto& xr_list = parsed_log_.extended_reports(direction);
1106 for (const auto& rtcp : xr_list) {
1107 const absl::optional<rtcp::TargetBitrate>& target_bitrate =
1108 rtcp.xr.target_bitrate();
1109 if (!target_bitrate.has_value())
1110 continue;
1111 for (const auto& bitrate_item : target_bitrate->GetTargetBitrates()) {
1112 LayerDescription layer(rtcp.xr.sender_ssrc(), bitrate_item.spatial_layer,
1113 bitrate_item.temporal_layer);
1114 auto time_series_it = time_series.find(layer);
1115 if (time_series_it == time_series.end()) {
1116 std::string layer_name = GetLayerName(layer);
1117 bool inserted;
1118 std::tie(time_series_it, inserted) = time_series.insert(
1119 std::make_pair(layer, TimeSeries(layer_name, LineStyle::kStep)));
1120 RTC_DCHECK(inserted);
1121 }
Björn Tereliuscb241582022-02-25 08:22:38 +00001122 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Terelius9775a582019-02-15 17:29:58 +01001123 float y = bitrate_item.target_bitrate_kbps;
1124 time_series_it->second.points.emplace_back(x, y);
1125 }
1126 }
1127 for (auto& layer : time_series) {
1128 plot->AppendTimeSeries(std::move(layer.second));
1129 }
1130 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1131 "Time (s)", kLeftMargin, kRightMargin);
1132 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1133 if (direction == kIncomingPacket)
1134 plot->SetTitle("Target bitrate per incoming layer");
1135 else
1136 plot->SetTitle("Target bitrate per outgoing layer");
1137}
1138
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001139void EventLogAnalyzer::CreateGoogCcSimulationGraph(Plot* plot) {
1140 TimeSeries target_rates("Simulated target rate", LineStyle::kStep,
1141 PointStyle::kHighlight);
1142 TimeSeries delay_based("Logged delay-based estimate", LineStyle::kStep,
1143 PointStyle::kHighlight);
1144 TimeSeries loss_based("Logged loss-based estimate", LineStyle::kStep,
1145 PointStyle::kHighlight);
1146 TimeSeries probe_results("Logged probe success", LineStyle::kNone,
1147 PointStyle::kHighlight);
1148
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001149 LogBasedNetworkControllerSimulation simulation(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001150 std::make_unique<GoogCcNetworkControllerFactory>(),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001151 [&](const NetworkControlUpdate& update, Timestamp at_time) {
1152 if (update.target_rate) {
1153 target_rates.points.emplace_back(
Björn Tereliuscb241582022-02-25 08:22:38 +00001154 config_.GetCallTimeSec(at_time),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001155 update.target_rate->target_rate.kbps<float>());
1156 }
1157 });
1158
1159 simulation.ProcessEventsInLog(parsed_log_);
1160 for (const auto& logged : parsed_log_.bwe_delay_updates())
Björn Tereliuscb241582022-02-25 08:22:38 +00001161 delay_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time()),
1162 logged.bitrate_bps / 1000);
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001163 for (const auto& logged : parsed_log_.bwe_probe_success_events())
Björn Tereliuscb241582022-02-25 08:22:38 +00001164 probe_results.points.emplace_back(config_.GetCallTimeSec(logged.log_time()),
1165 logged.bitrate_bps / 1000);
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001166 for (const auto& logged : parsed_log_.bwe_loss_updates())
Björn Tereliuscb241582022-02-25 08:22:38 +00001167 loss_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time()),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001168 logged.bitrate_bps / 1000);
1169
1170 plot->AppendTimeSeries(std::move(delay_based));
1171 plot->AppendTimeSeries(std::move(loss_based));
1172 plot->AppendTimeSeries(std::move(probe_results));
1173 plot->AppendTimeSeries(std::move(target_rates));
1174
1175 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1176 "Time (s)", kLeftMargin, kRightMargin);
1177 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1178 plot->SetTitle("Simulated BWE behavior");
1179}
1180
Bjorn Terelius28db2662017-10-04 14:22:43 +02001181void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001182 using RtpPacketType = LoggedRtpPacketOutgoing;
1183 using TransportFeedbackType = LoggedRtcpPacketTransportFeedback;
Stefan Holmer13181032016-07-29 14:48:54 +02001184
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001185 // TODO(terelius): This could be provided by the parser.
1186 std::multimap<int64_t, const RtpPacketType*> outgoing_rtp;
1187 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1188 for (const RtpPacketType& rtp_packet : stream.outgoing_packets)
1189 outgoing_rtp.insert(
1190 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Stefan Holmer13181032016-07-29 14:48:54 +02001191 }
1192
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001193 const std::vector<TransportFeedbackType>& incoming_rtcp =
1194 parsed_log_.transport_feedbacks(kIncomingPacket);
Stefan Holmer13181032016-07-29 14:48:54 +02001195
1196 SimulatedClock clock(0);
1197 BitrateObserver observer;
Danil Chapovalov83bbe912019-08-07 12:24:53 +02001198 RtcEventLogNull null_event_log;
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001199 TransportFeedbackAdapter transport_feedback;
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001200 auto factory = GoogCcNetworkControllerFactory();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001201 TimeDelta process_interval = factory.GetProcessInterval();
Stefan Holmer13181032016-07-29 14:48:54 +02001202 // TODO(holmer): Log the call config and use that here instead.
1203 static const uint32_t kDefaultStartBitrateBps = 300000;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001204 NetworkControllerConfig cc_config;
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001205 cc_config.constraints.at_time = Timestamp::Micros(clock.TimeInMicroseconds());
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +01001206 cc_config.constraints.starting_rate =
1207 DataRate::BitsPerSec(kDefaultStartBitrateBps);
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001208 cc_config.event_log = &null_event_log;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001209 auto goog_cc = factory.Create(cc_config);
Stefan Holmer13181032016-07-29 14:48:54 +02001210
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001211 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1212 PointStyle::kHighlight);
Björn Tereliusae1892d2020-06-17 11:55:55 +02001213 TimeSeries acked_time_series("Raw acked bitrate", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001214 PointStyle::kHighlight);
Björn Tereliusae1892d2020-06-17 11:55:55 +02001215 TimeSeries robust_time_series("Robust throughput estimate", LineStyle::kLine,
1216 PointStyle::kHighlight);
1217 TimeSeries acked_estimate_time_series("Ackednowledged bitrate estimate",
1218 LineStyle::kLine,
1219 PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001220
1221 auto rtp_iterator = outgoing_rtp.begin();
1222 auto rtcp_iterator = incoming_rtcp.begin();
1223
1224 auto NextRtpTime = [&]() {
1225 if (rtp_iterator != outgoing_rtp.end())
1226 return static_cast<int64_t>(rtp_iterator->first);
1227 return std::numeric_limits<int64_t>::max();
1228 };
1229
1230 auto NextRtcpTime = [&]() {
1231 if (rtcp_iterator != incoming_rtcp.end())
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001232 return static_cast<int64_t>(rtcp_iterator->log_time_us());
Stefan Holmer13181032016-07-29 14:48:54 +02001233 return std::numeric_limits<int64_t>::max();
1234 };
Bjorn Tereliusa728c912018-12-06 12:26:30 +01001235 int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()});
Stefan Holmer13181032016-07-29 14:48:54 +02001236
1237 auto NextProcessTime = [&]() {
1238 if (rtcp_iterator != incoming_rtcp.end() ||
1239 rtp_iterator != outgoing_rtp.end()) {
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001240 return next_process_time_us_;
Stefan Holmer13181032016-07-29 14:48:54 +02001241 }
1242 return std::numeric_limits<int64_t>::max();
1243 };
1244
Björn Tereliuseb9af842022-05-05 15:54:49 +02001245 RateStatistics raw_acked_bitrate(750, 8000);
Björn Tereliusae1892d2020-06-17 11:55:55 +02001246 test::ExplicitKeyValueConfig throughput_config(
1247 "WebRTC-Bwe-RobustThroughputEstimatorSettings/"
Björn Tereliuseb9af842022-05-05 15:54:49 +02001248 "enabled:true,required_packets:10,"
1249 "window_packets:25,window_duration:1000ms,unacked_weight:1.0/");
Björn Tereliusae1892d2020-06-17 11:55:55 +02001250 std::unique_ptr<AcknowledgedBitrateEstimatorInterface>
1251 robust_throughput_estimator(
1252 AcknowledgedBitrateEstimatorInterface::Create(&throughput_config));
1253 FieldTrialBasedConfig field_trial_config;
Björn Terelius251b0dc2019-11-11 21:00:18 +01001254 std::unique_ptr<AcknowledgedBitrateEstimatorInterface>
1255 acknowledged_bitrate_estimator(
Björn Tereliusae1892d2020-06-17 11:55:55 +02001256 AcknowledgedBitrateEstimatorInterface::Create(&field_trial_config));
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001257 int64_t time_us =
1258 std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
Stefan Holmer492ee282016-10-27 17:19:20 +02001259 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001260 while (time_us != std::numeric_limits<int64_t>::max()) {
1261 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001262 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1263 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1264 const RtpPacketType& rtp_packet = *rtp_iterator->second;
1265 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
Erik Språng30a276b2019-04-23 12:00:11 +02001266 RtpPacketSendInfo packet_info;
Erik Språng6a0a5592021-06-15 19:04:24 +02001267 packet_info.media_ssrc = rtp_packet.rtp.header.ssrc;
Bjorn Tereliusf2e9cab2019-05-27 16:44:09 +02001268 packet_info.transport_sequence_number =
Erik Språng30a276b2019-04-23 12:00:11 +02001269 rtp_packet.rtp.header.extension.transportSequenceNumber;
1270 packet_info.rtp_sequence_number = rtp_packet.rtp.header.sequenceNumber;
Erik Språng30a276b2019-04-23 12:00:11 +02001271 packet_info.length = rtp_packet.rtp.total_length;
Björn Tereliusae1892d2020-06-17 11:55:55 +02001272 if (IsRtxSsrc(parsed_log_, PacketDirection::kOutgoingPacket,
1273 rtp_packet.rtp.header.ssrc)) {
1274 // Don't set the optional media type as we don't know if it is
1275 // a retransmission, FEC or padding.
1276 } else if (IsVideoSsrc(parsed_log_, PacketDirection::kOutgoingPacket,
1277 rtp_packet.rtp.header.ssrc)) {
1278 packet_info.packet_type = RtpPacketMediaType::kVideo;
1279 } else if (IsAudioSsrc(parsed_log_, PacketDirection::kOutgoingPacket,
1280 rtp_packet.rtp.header.ssrc)) {
1281 packet_info.packet_type = RtpPacketMediaType::kAudio;
1282 }
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001283 transport_feedback.AddPacket(
Erik Språng30a276b2019-04-23 12:00:11 +02001284 packet_info,
1285 0u, // Per packet overhead bytes.
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001286 Timestamp::Micros(rtp_packet.rtp.log_time_us()));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001287 }
Björn Tereliusae1892d2020-06-17 11:55:55 +02001288 rtc::SentPacket sent_packet;
1289 sent_packet.send_time_ms = rtp_packet.rtp.log_time_ms();
1290 sent_packet.info.included_in_allocation = true;
1291 sent_packet.info.packet_size_bytes = rtp_packet.rtp.total_length;
1292 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
1293 sent_packet.packet_id =
1294 rtp_packet.rtp.header.extension.transportSequenceNumber;
1295 sent_packet.info.included_in_feedback = true;
1296 }
1297 auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet);
1298 if (sent_msg)
1299 observer.Update(goog_cc->OnSentPacket(*sent_msg));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001300 ++rtp_iterator;
1301 }
Stefan Holmer13181032016-07-29 14:48:54 +02001302 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001303 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001304
1305 auto feedback_msg = transport_feedback.ProcessTransportFeedback(
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001306 rtcp_iterator->transport_feedback,
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001307 Timestamp::Millis(clock.TimeInMilliseconds()));
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001308 if (feedback_msg) {
1309 observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg));
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001310 std::vector<PacketResult> feedback =
1311 feedback_msg->SortedByReceiveTime();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001312 if (!feedback.empty()) {
Björn Terelius251b0dc2019-11-11 21:00:18 +01001313 acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
1314 feedback);
Björn Tereliusae1892d2020-06-17 11:55:55 +02001315 robust_throughput_estimator->IncomingPacketFeedbackVector(feedback);
1316 for (const PacketResult& packet : feedback) {
Björn Tereliuseb9af842022-05-05 15:54:49 +02001317 raw_acked_bitrate.Update(packet.sent_packet.size.bytes(),
1318 packet.receive_time.ms());
Björn Tereliusae1892d2020-06-17 11:55:55 +02001319 }
Björn Tereliuseb9af842022-05-05 15:54:49 +02001320 absl::optional<uint32_t> raw_bitrate_bps =
1321 raw_acked_bitrate.Rate(feedback.back().receive_time.ms());
1322 float x = config_.GetCallTimeSec(clock.CurrentTime());
1323 if (raw_bitrate_bps) {
1324 float y = raw_bitrate_bps.value() / 1000;
1325 acked_time_series.points.emplace_back(x, y);
1326 }
1327 absl::optional<DataRate> robust_estimate =
1328 robust_throughput_estimator->bitrate();
1329 if (robust_estimate) {
1330 float y = robust_estimate.value().kbps();
1331 robust_time_series.points.emplace_back(x, y);
1332 }
1333 absl::optional<DataRate> acked_estimate =
1334 acknowledged_bitrate_estimator->bitrate();
1335 if (acked_estimate) {
1336 float y = acked_estimate.value().kbps();
1337 acked_estimate_time_series.points.emplace_back(x, y);
1338 }
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001339 }
Stefan Holmer13181032016-07-29 14:48:54 +02001340 }
1341 ++rtcp_iterator;
1342 }
stefanc3de0332016-08-02 07:22:17 -07001343 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1344 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001345 ProcessInterval msg;
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001346 msg.at_time = Timestamp::Micros(clock.TimeInMicroseconds());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001347 observer.Update(goog_cc->OnProcessInterval(msg));
1348 next_process_time_us_ += process_interval.us();
stefanc3de0332016-08-02 07:22:17 -07001349 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001350 if (observer.GetAndResetBitrateUpdated() ||
1351 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001352 uint32_t y = observer.last_bitrate_bps() / 1000;
Björn Tereliuscb241582022-02-25 08:22:38 +00001353 float x = config_.GetCallTimeSec(clock.CurrentTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001354 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001355 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001356 }
1357 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1358 }
1359 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001360 plot->AppendTimeSeries(std::move(time_series));
Björn Tereliusae1892d2020-06-17 11:55:55 +02001361 plot->AppendTimeSeries(std::move(robust_time_series));
philipel35ba9bd2017-04-19 05:58:51 -07001362 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001363 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001364
Bjorn Terelius068fc352019-02-13 22:38:25 +01001365 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1366 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001367 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001368 plot->SetTitle("Simulated send-side BWE behavior");
1369}
1370
1371void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001372 using RtpPacketType = LoggedRtpPacketIncoming;
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001373 class RembInterceptor {
Bjorn Terelius28db2662017-10-04 14:22:43 +02001374 public:
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001375 void SendRemb(uint32_t bitrate_bps, std::vector<uint32_t> ssrcs) {
Bjorn Terelius28db2662017-10-04 14:22:43 +02001376 last_bitrate_bps_ = bitrate_bps;
1377 bitrate_updated_ = true;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001378 }
1379 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1380 bool GetAndResetBitrateUpdated() {
1381 bool bitrate_updated = bitrate_updated_;
1382 bitrate_updated_ = false;
1383 return bitrate_updated;
1384 }
1385
1386 private:
Bjorn Terelius571e1302020-06-09 10:29:09 +02001387 // We don't know the start bitrate, but assume that it is the default 300
1388 // kbps.
1389 uint32_t last_bitrate_bps_ = 300000;
1390 bool bitrate_updated_ = false;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001391 };
1392
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001393 std::multimap<int64_t, const RtpPacketType*> incoming_rtp;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001394
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001395 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Terelius48b82792020-05-19 10:57:24 +02001396 if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001397 for (const auto& rtp_packet : stream.incoming_packets)
1398 incoming_rtp.insert(
1399 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Bjorn Terelius28db2662017-10-04 14:22:43 +02001400 }
1401 }
1402
1403 SimulatedClock clock(0);
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001404 RembInterceptor remb_interceptor;
1405 ReceiveSideCongestionController rscc(
1406 &clock, [](auto...) {},
1407 absl::bind_front(&RembInterceptor::SendRemb, &remb_interceptor), nullptr);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001408 // TODO(holmer): Log the call config and use that here instead.
1409 // static const uint32_t kDefaultStartBitrateBps = 300000;
1410 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1411
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001412 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1413 PointStyle::kHighlight);
1414 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001415
1416 RateStatistics acked_bitrate(250, 8000);
1417 int64_t last_update_us = 0;
1418 for (const auto& kv : incoming_rtp) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001419 const RtpPacketType& packet = *kv.second;
1420 int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000;
1421 size_t payload = packet.rtp.total_length; /*Should subtract header?*/
1422 clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() -
Bjorn Terelius28db2662017-10-04 14:22:43 +02001423 clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001424 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001425 acked_bitrate.Update(payload, arrival_time_ms);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001426 absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001427 if (bitrate_bps) {
1428 uint32_t y = *bitrate_bps / 1000;
Björn Tereliuscb241582022-02-25 08:22:38 +00001429 float x = config_.GetCallTimeSec(clock.CurrentTime());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001430 acked_time_series.points.emplace_back(x, y);
1431 }
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001432 if (remb_interceptor.GetAndResetBitrateUpdated() ||
Bjorn Terelius28db2662017-10-04 14:22:43 +02001433 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
Per Kjellanderfe2063e2021-05-12 09:02:43 +02001434 uint32_t y = remb_interceptor.last_bitrate_bps() / 1000;
Björn Tereliuscb241582022-02-25 08:22:38 +00001435 float x = config_.GetCallTimeSec(clock.CurrentTime());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001436 time_series.points.emplace_back(x, y);
1437 last_update_us = clock.TimeInMicroseconds();
1438 }
1439 }
1440 // Add the data set to the plot.
1441 plot->AppendTimeSeries(std::move(time_series));
1442 plot->AppendTimeSeries(std::move(acked_time_series));
1443
Bjorn Terelius068fc352019-02-13 22:38:25 +01001444 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1445 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001446 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1447 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001448}
1449
tereliuse34c19c2016-08-15 08:47:14 -07001450void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001451 TimeSeries time_series("Network delay", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001452 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001453 int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max();
1454 int64_t min_rtt_ms = std::numeric_limits<int64_t>::max();
stefanc3de0332016-08-02 07:22:17 -07001455
Björn Tereliusc69c1bb2019-10-11 15:06:58 +02001456 std::vector<MatchedSendArrivalTimes> matched_rtp_rtcp =
1457 GetNetworkTrace(parsed_log_);
1458 absl::c_stable_sort(matched_rtp_rtcp, [](const MatchedSendArrivalTimes& a,
1459 const MatchedSendArrivalTimes& b) {
philipel3574d052019-11-18 14:38:13 +01001460 return a.feedback_arrival_time_ms < b.feedback_arrival_time_ms ||
1461 (a.feedback_arrival_time_ms == b.feedback_arrival_time_ms &&
1462 a.arrival_time_ms < b.arrival_time_ms);
Björn Tereliusc69c1bb2019-10-11 15:06:58 +02001463 });
1464 for (const auto& packet : matched_rtp_rtcp) {
Sebastian Jansson74f96ec2019-10-29 12:57:54 +01001465 if (packet.arrival_time_ms == MatchedSendArrivalTimes::kNotReceived)
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001466 continue;
Björn Tereliuscb241582022-02-25 08:22:38 +00001467 float x = config_.GetCallTimeSecFromMs(packet.feedback_arrival_time_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001468 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001469 int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms;
1470 min_rtt_ms = std::min(rtt_ms, min_rtt_ms);
1471 min_send_receive_diff_ms = std::min(y, min_send_receive_diff_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001472 time_series.points.emplace_back(x, y);
stefanc3de0332016-08-02 07:22:17 -07001473 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001474
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001475 // We assume that the base network delay (w/o queues) is equal to half
1476 // the minimum RTT. Therefore rescale the delays by subtracting the minimum
Mirko Bonadei604e75c2019-07-25 11:55:47 +02001477 // observed 1-ways delay and add half the minimum RTT.
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001478 const int64_t estimated_clock_offset_ms =
1479 min_send_receive_diff_ms - min_rtt_ms / 2;
stefanc3de0332016-08-02 07:22:17 -07001480 for (TimeSeriesPoint& point : time_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001481 point.y -= estimated_clock_offset_ms;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001482
stefanc3de0332016-08-02 07:22:17 -07001483 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001484 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001485
Bjorn Terelius068fc352019-02-13 22:38:25 +01001486 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1487 "Time (s)", kLeftMargin, kRightMargin);
stefanc3de0332016-08-02 07:22:17 -07001488 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +01001489 plot->SetTitle("Outgoing network delay (based on per-packet feedback)");
stefanc3de0332016-08-02 07:22:17 -07001490}
stefan08383272016-12-20 08:51:52 -08001491
Bjorn Terelius0295a962017-10-25 17:42:41 +02001492void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001493 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1494 const std::vector<LoggedRtpPacketOutgoing>& packets =
1495 stream.outgoing_packets;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001496
Bjorn Terelius48b82792020-05-19 10:57:24 +02001497 if (IsRtxSsrc(parsed_log_, kOutgoingPacket, stream.ssrc)) {
Konrad Hofbauerbfb735b2019-04-16 11:12:11 +02001498 continue;
1499 }
1500
Bjorn Terelius0295a962017-10-25 17:42:41 +02001501 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001502 RTC_LOG(LS_WARNING)
1503 << "Can't estimate a the RTP clock frequency or the "
1504 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001505 continue;
1506 }
Björn Terelius0d1b28c2020-05-27 20:25:06 +02001507 int64_t segment_end_us = parsed_log_.first_log_segment().stop_time_us();
Danil Chapovalov431abd92018-06-18 12:54:17 +02001508 absl::optional<uint32_t> estimated_frequency =
Bjorn Terelius48b82792020-05-19 10:57:24 +02001509 EstimateRtpClockFrequency(packets, segment_end_us);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001510 if (!estimated_frequency)
1511 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +02001512 if (IsVideoSsrc(parsed_log_, kOutgoingPacket, stream.ssrc) &&
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001513 *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001514 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001515 << "Video stream should use a 90 kHz clock but appears to use "
1516 << *estimated_frequency / 1000 << ". Discarding.";
1517 continue;
1518 }
1519
1520 TimeSeries pacer_delay_series(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001521 GetStreamName(parsed_log_, kOutgoingPacket, stream.ssrc) + "(" +
Bjorn Terelius0295a962017-10-25 17:42:41 +02001522 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001523 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001524 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1525 uint64_t first_capture_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001526 timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp);
1527 uint64_t first_send_timestamp = packets.front().rtp.log_time_us();
1528 for (const auto& packet : packets) {
Bjorn Terelius0295a962017-10-25 17:42:41 +02001529 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001530 packet.rtp.header.timestamp)) -
Bjorn Terelius0295a962017-10-25 17:42:41 +02001531 first_capture_timestamp) /
1532 *estimated_frequency * 1000;
1533 double send_time_ms =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001534 static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) /
1535 1000;
Björn Tereliuscb241582022-02-25 08:22:38 +00001536 float x = config_.GetCallTimeSec(packet.rtp.log_time());
Bjorn Terelius0295a962017-10-25 17:42:41 +02001537 float y = send_time_ms - capture_time_ms;
1538 pacer_delay_series.points.emplace_back(x, y);
1539 }
1540 plot->AppendTimeSeries(std::move(pacer_delay_series));
1541 }
1542
Bjorn Terelius068fc352019-02-13 22:38:25 +01001543 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1544 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001545 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1546 plot->SetTitle(
1547 "Delay from capture to send time. (First packet normalized to 0.)");
1548}
1549
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001550void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction,
1551 Plot* plot) {
1552 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1553 TimeSeries rtp_timestamps(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001554 GetStreamName(parsed_log_, direction, stream.ssrc) + " capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001555 LineStyle::kLine, PointStyle::kHighlight);
1556 for (const auto& packet : stream.packet_view) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001557 float x = config_.GetCallTimeSec(packet.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001558 float y = packet.header.timestamp;
1559 rtp_timestamps.points.emplace_back(x, y);
stefane372d3c2017-02-02 08:04:18 -08001560 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001561 plot->AppendTimeSeries(std::move(rtp_timestamps));
Björn Tereliusff612732018-04-25 14:23:01 +00001562
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001563 TimeSeries rtcp_timestamps(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001564 GetStreamName(parsed_log_, direction, stream.ssrc) +
1565 " rtcp capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001566 LineStyle::kLine, PointStyle::kHighlight);
1567 // TODO(terelius): Why only sender reports?
1568 const auto& sender_reports = parsed_log_.sender_reports(direction);
1569 for (const auto& rtcp : sender_reports) {
1570 if (rtcp.sr.sender_ssrc() != stream.ssrc)
1571 continue;
Björn Tereliuscb241582022-02-25 08:22:38 +00001572 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001573 float y = rtcp.sr.rtp_timestamp();
1574 rtcp_timestamps.points.emplace_back(x, y);
Björn Tereliusff612732018-04-25 14:23:01 +00001575 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001576 plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps));
stefane372d3c2017-02-02 08:04:18 -08001577 }
1578
Bjorn Terelius068fc352019-02-13 22:38:25 +01001579 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1580 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001581 plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin);
1582 plot->SetTitle(GetDirectionAsString(direction) + " timestamps");
stefane372d3c2017-02-02 08:04:18 -08001583}
michaelt6e5b2192017-02-22 07:33:27 -08001584
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001585void EventLogAnalyzer::CreateSenderAndReceiverReportPlot(
1586 PacketDirection direction,
1587 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
1588 std::string title,
1589 std::string yaxis_label,
1590 Plot* plot) {
1591 std::map<uint32_t, TimeSeries> sr_reports_by_ssrc;
1592 const auto& sender_reports = parsed_log_.sender_reports(direction);
1593 for (const auto& rtcp : sender_reports) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001594 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001595 uint32_t ssrc = rtcp.sr.sender_ssrc();
1596 for (const auto& block : rtcp.sr.report_blocks()) {
1597 float y = fy(block);
1598 auto sr_report_it = sr_reports_by_ssrc.find(ssrc);
1599 bool inserted;
1600 if (sr_report_it == sr_reports_by_ssrc.end()) {
1601 std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001602 ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) +
1603 " Sender Reports",
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001604 LineStyle::kLine, PointStyle::kHighlight));
1605 }
1606 sr_report_it->second.points.emplace_back(x, y);
1607 }
1608 }
1609 for (auto& kv : sr_reports_by_ssrc) {
1610 plot->AppendTimeSeries(std::move(kv.second));
1611 }
1612
1613 std::map<uint32_t, TimeSeries> rr_reports_by_ssrc;
1614 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
1615 for (const auto& rtcp : receiver_reports) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001616 float x = config_.GetCallTimeSec(rtcp.log_time());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001617 uint32_t ssrc = rtcp.rr.sender_ssrc();
1618 for (const auto& block : rtcp.rr.report_blocks()) {
1619 float y = fy(block);
1620 auto rr_report_it = rr_reports_by_ssrc.find(ssrc);
1621 bool inserted;
1622 if (rr_report_it == rr_reports_by_ssrc.end()) {
1623 std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001624 ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) +
1625 " Receiver Reports",
1626 LineStyle::kLine, PointStyle::kHighlight));
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001627 }
1628 rr_report_it->second.points.emplace_back(x, y);
1629 }
1630 }
1631 for (auto& kv : rr_reports_by_ssrc) {
1632 plot->AppendTimeSeries(std::move(kv.second));
1633 }
1634
Bjorn Terelius068fc352019-02-13 22:38:25 +01001635 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1636 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001637 plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin);
1638 plot->SetTitle(title);
1639}
1640
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001641void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
1642 std::map<uint32_t, TimeSeries> configs_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001643 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001644 if (configs_by_cp_id.find(config.candidate_pair_id) ==
1645 configs_by_cp_id.end()) {
1646 const std::string candidate_pair_desc =
1647 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08001648 configs_by_cp_id[config.candidate_pair_id] =
1649 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
1650 candidate_pair_desc,
1651 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001652 candidate_pair_desc_by_id_[config.candidate_pair_id] =
1653 candidate_pair_desc;
1654 }
Björn Tereliuscb241582022-02-25 08:22:38 +00001655 float x = config_.GetCallTimeSec(config.log_time());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001656 float y = static_cast<float>(config.type);
1657 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
1658 }
1659
1660 // TODO(qingsi): There can be a large number of candidate pairs generated by
1661 // certain calls and the frontend cannot render the chart in this case due to
1662 // the failure of generating a palette with the same number of colors.
1663 for (auto& kv : configs_by_cp_id) {
1664 plot->AppendTimeSeries(std::move(kv.second));
1665 }
1666
Bjorn Terelius068fc352019-02-13 22:38:25 +01001667 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1668 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001669 plot->SetSuggestedYAxis(0, 3, "Config Type", kBottomMargin, kTopMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001670 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001671 plot->SetYAxisTickLabels(
1672 {{static_cast<float>(IceCandidatePairConfigType::kAdded), "ADDED"},
1673 {static_cast<float>(IceCandidatePairConfigType::kUpdated), "UPDATED"},
1674 {static_cast<float>(IceCandidatePairConfigType::kDestroyed),
1675 "DESTROYED"},
1676 {static_cast<float>(IceCandidatePairConfigType::kSelected),
1677 "SELECTED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001678}
1679
1680std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
1681 uint32_t candidate_pair_id) {
1682 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
1683 candidate_pair_desc_by_id_.end()) {
1684 return candidate_pair_desc_by_id_[candidate_pair_id];
1685 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001686 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001687 // TODO(qingsi): Add the handling of the "Updated" config event after the
1688 // visualization of property change for candidate pairs is introduced.
1689 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
1690 candidate_pair_desc_by_id_.end()) {
1691 const std::string candidate_pair_desc =
1692 GetCandidatePairLogDescriptionAsString(config);
1693 candidate_pair_desc_by_id_[config.candidate_pair_id] =
1694 candidate_pair_desc;
1695 }
1696 }
1697 return candidate_pair_desc_by_id_[candidate_pair_id];
1698}
1699
1700void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001701 constexpr int kEventTypeOffset =
1702 static_cast<int>(IceCandidatePairConfigType::kNumValues);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001703 std::map<uint32_t, TimeSeries> checks_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001704 for (const auto& event : parsed_log_.ice_candidate_pair_events()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001705 if (checks_by_cp_id.find(event.candidate_pair_id) ==
1706 checks_by_cp_id.end()) {
1707 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08001708 "[" + std::to_string(event.candidate_pair_id) + "]" +
1709 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001710 LineStyle::kNone, PointStyle::kHighlight);
1711 }
Björn Tereliuscb241582022-02-25 08:22:38 +00001712 float x = config_.GetCallTimeSec(event.log_time());
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001713 float y = static_cast<float>(event.type) + kEventTypeOffset;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001714 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
1715 }
1716
1717 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
1718 for (auto& kv : checks_by_cp_id) {
1719 plot->AppendTimeSeries(std::move(kv.second));
1720 }
1721
Bjorn Terelius068fc352019-02-13 22:38:25 +01001722 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1723 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001724 plot->SetSuggestedYAxis(0, 4, "Connectivity State", kBottomMargin,
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001725 kTopMargin);
1726 plot->SetTitle("[IceEventLog] ICE connectivity checks");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001727
1728 plot->SetYAxisTickLabels(
1729 {{static_cast<float>(IceCandidatePairEventType::kCheckSent) +
1730 kEventTypeOffset,
1731 "CHECK SENT"},
1732 {static_cast<float>(IceCandidatePairEventType::kCheckReceived) +
1733 kEventTypeOffset,
1734 "CHECK RECEIVED"},
1735 {static_cast<float>(IceCandidatePairEventType::kCheckResponseSent) +
1736 kEventTypeOffset,
1737 "RESPONSE SENT"},
1738 {static_cast<float>(IceCandidatePairEventType::kCheckResponseReceived) +
1739 kEventTypeOffset,
1740 "RESPONSE RECEIVED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001741}
1742
Zach Stein10a58012018-12-07 12:26:28 -08001743void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) {
1744 TimeSeries states("DTLS Transport State", LineStyle::kNone,
1745 PointStyle::kHighlight);
1746 for (const auto& event : parsed_log_.dtls_transport_states()) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001747 float x = config_.GetCallTimeSec(event.log_time());
Zach Stein10a58012018-12-07 12:26:28 -08001748 float y = static_cast<float>(event.dtls_transport_state);
1749 states.points.emplace_back(x, y);
1750 }
1751 plot->AppendTimeSeries(std::move(states));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001752 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1753 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08001754 plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues),
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001755 "Transport State", kBottomMargin, kTopMargin);
Zach Stein10a58012018-12-07 12:26:28 -08001756 plot->SetTitle("DTLS Transport State");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02001757 plot->SetYAxisTickLabels(
1758 {{static_cast<float>(DtlsTransportState::kNew), "NEW"},
1759 {static_cast<float>(DtlsTransportState::kConnecting), "CONNECTING"},
1760 {static_cast<float>(DtlsTransportState::kConnected), "CONNECTED"},
1761 {static_cast<float>(DtlsTransportState::kClosed), "CLOSED"},
1762 {static_cast<float>(DtlsTransportState::kFailed), "FAILED"}});
Zach Stein10a58012018-12-07 12:26:28 -08001763}
1764
1765void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) {
1766 TimeSeries writable("DTLS Writable", LineStyle::kNone,
1767 PointStyle::kHighlight);
1768 for (const auto& event : parsed_log_.dtls_writable_states()) {
Björn Tereliuscb241582022-02-25 08:22:38 +00001769 float x = config_.GetCallTimeSec(event.log_time());
Zach Stein10a58012018-12-07 12:26:28 -08001770 float y = static_cast<float>(event.writable);
1771 writable.points.emplace_back(x, y);
1772 }
1773 plot->AppendTimeSeries(std::move(writable));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001774 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1775 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08001776 plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin);
1777 plot->SetTitle("DTLS Writable State");
1778}
1779
terelius54ce6802016-07-13 06:44:41 -07001780} // namespace webrtc