terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 575998c | 2019-07-25 13:57:41 +0200 | [diff] [blame] | 11 | #include "rtc_tools/rtc_event_log_visualizer/analyzer.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
Oleh Prypin | 6581f21 | 2017-11-16 00:17:05 +0100 | [diff] [blame] | 14 | #include <cmath> |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 15 | #include <limits> |
| 16 | #include <map> |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 17 | #include <memory> |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 18 | #include <string> |
| 19 | #include <utility> |
| 20 | |
Björn Terelius | c69c1bb | 2019-10-11 15:06:58 +0200 | [diff] [blame] | 21 | #include "absl/algorithm/container.h" |
Bjorn Terelius | 6c4b1b7 | 2019-01-11 13:01:29 +0100 | [diff] [blame] | 22 | #include "absl/strings/string_view.h" |
Artem Titov | 741daaf | 2019-03-21 14:37:36 +0100 | [diff] [blame] | 23 | #include "api/function_view.h" |
Niels Möller | 0d863f7 | 2020-11-24 17:50:31 +0100 | [diff] [blame] | 24 | #include "api/network_state_predictor.h" |
Sebastian Jansson | 95edb03 | 2019-01-17 16:24:12 +0100 | [diff] [blame] | 25 | #include "api/transport/field_trial_based_config.h" |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 26 | #include "api/transport/goog_cc_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "call/audio_receive_stream.h" |
| 28 | #include "call/audio_send_stream.h" |
| 29 | #include "call/call.h" |
| 30 | #include "call/video_receive_stream.h" |
| 31 | #include "call/video_send_stream.h" |
Kristoffer Erlandsson | a2ce423 | 2020-04-01 14:33:30 +0200 | [diff] [blame] | 32 | #include "logging/rtc_event_log/rtc_event_processor.h" |
Elad Alon | 99a81b6 | 2017-09-21 10:25:29 +0200 | [diff] [blame] | 33 | #include "logging/rtc_event_log/rtc_stream_config.h" |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 34 | #include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h" |
Sebastian Jansson | 172fd85 | 2018-05-24 14:17:06 +0200 | [diff] [blame] | 35 | #include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h" |
| 36 | #include "modules/congestion_controller/goog_cc/bitrate_estimator.h" |
Sebastian Jansson | 04b18cb | 2018-07-02 09:25:25 +0200 | [diff] [blame] | 37 | #include "modules/congestion_controller/goog_cc/delay_based_bwe.h" |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 38 | #include "modules/congestion_controller/include/receive_side_congestion_controller.h" |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 39 | #include "modules/congestion_controller/rtp/transport_feedback_adapter.h" |
Erik Språng | e794243 | 2019-06-12 13:30:02 +0200 | [diff] [blame] | 40 | #include "modules/pacing/paced_sender.h" |
Niels Möller | fd6c091 | 2017-10-31 10:19:10 +0100 | [diff] [blame] | 41 | #include "modules/pacing/packet_router.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 42 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 43 | #include "modules/rtp_rtcp/source/rtcp_packet.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 44 | #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 45 | #include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 46 | #include "modules/rtp_rtcp/source/rtcp_packet/remb.h" |
| 47 | #include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
| 48 | #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 49 | #include "modules/rtp_rtcp/source/rtp_header_extensions.h" |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 50 | #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 51 | #include "modules/rtp_rtcp/source/rtp_utility.h" |
| 52 | #include "rtc_base/checks.h" |
| 53 | #include "rtc_base/format_macros.h" |
| 54 | #include "rtc_base/logging.h" |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 55 | #include "rtc_base/numerics/sequence_number_util.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 56 | #include "rtc_base/rate_statistics.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 57 | #include "rtc_base/strings/string_builder.h" |
Mirko Bonadei | 575998c | 2019-07-25 13:57:41 +0200 | [diff] [blame] | 58 | #include "rtc_tools/rtc_event_log_visualizer/log_simulation.h" |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 59 | #include "test/explicit_key_value_config.h" |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 60 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 61 | namespace webrtc { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 62 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 63 | namespace { |
| 64 | |
| 65 | std::string SsrcToString(uint32_t ssrc) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 66 | rtc::StringBuilder ss; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 67 | ss << "SSRC " << ssrc; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 68 | return ss.Release(); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | // Checks whether an SSRC is contained in the list of desired SSRCs. |
| 72 | // Note that an empty SSRC list matches every SSRC. |
| 73 | bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) { |
Mirko Bonadei | 1f17315 | 2019-07-25 15:28:14 +0200 | [diff] [blame] | 74 | if (desired_ssrc.empty()) |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 75 | return true; |
| 76 | return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) != |
| 77 | desired_ssrc.end(); |
| 78 | } |
| 79 | |
| 80 | double AbsSendTimeToMicroseconds(int64_t abs_send_time) { |
| 81 | // The timestamp is a fixed point representation with 6 bits for seconds |
| 82 | // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 83 | // time in seconds and then multiply by kNumMicrosecsPerSec to convert to |
| 84 | // microseconds. |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 85 | static constexpr double kTimestampToMicroSec = |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 86 | static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 87 | return abs_send_time * kTimestampToMicroSec; |
| 88 | } |
| 89 | |
| 90 | // Computes the difference |later| - |earlier| where |later| and |earlier| |
| 91 | // are counters that wrap at |modulus|. The difference is chosen to have the |
| 92 | // least absolute value. For example if |modulus| is 8, then the difference will |
| 93 | // be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will |
| 94 | // be in [-4, 4]. |
| 95 | int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) { |
| 96 | RTC_DCHECK_LE(1, modulus); |
| 97 | RTC_DCHECK_LT(later, modulus); |
| 98 | RTC_DCHECK_LT(earlier, modulus); |
| 99 | int64_t difference = |
| 100 | static_cast<int64_t>(later) - static_cast<int64_t>(earlier); |
| 101 | int64_t max_difference = modulus / 2; |
| 102 | int64_t min_difference = max_difference - modulus + 1; |
| 103 | if (difference > max_difference) { |
| 104 | difference -= modulus; |
| 105 | } |
| 106 | if (difference < min_difference) { |
| 107 | difference += modulus; |
| 108 | } |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 109 | if (difference > max_difference / 2 || difference < min_difference / 2) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 110 | RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier |
| 111 | << " expected to be in the range (" |
| 112 | << min_difference / 2 << "," << max_difference / 2 |
| 113 | << ") but is " << difference |
| 114 | << ". Correct unwrapping is uncertain."; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 115 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 116 | return difference; |
| 117 | } |
| 118 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 119 | // This is much more reliable for outgoing streams than for incoming streams. |
| 120 | template <typename RtpPacketContainer> |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 121 | absl::optional<uint32_t> EstimateRtpClockFrequency( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 122 | const RtpPacketContainer& packets, |
| 123 | int64_t end_time_us) { |
| 124 | RTC_CHECK(packets.size() >= 2); |
| 125 | SeqNumUnwrapper<uint32_t> unwrapper; |
Philip Eliasson | 1f850a6 | 2019-03-19 12:15:00 +0000 | [diff] [blame] | 126 | int64_t first_rtp_timestamp = |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 127 | unwrapper.Unwrap(packets[0].rtp.header.timestamp); |
| 128 | int64_t first_log_timestamp = packets[0].log_time_us(); |
Philip Eliasson | 1f850a6 | 2019-03-19 12:15:00 +0000 | [diff] [blame] | 129 | int64_t last_rtp_timestamp = first_rtp_timestamp; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 130 | int64_t last_log_timestamp = first_log_timestamp; |
| 131 | for (size_t i = 1; i < packets.size(); i++) { |
| 132 | if (packets[i].log_time_us() > end_time_us) |
| 133 | break; |
| 134 | last_rtp_timestamp = unwrapper.Unwrap(packets[i].rtp.header.timestamp); |
| 135 | last_log_timestamp = packets[i].log_time_us(); |
| 136 | } |
| 137 | if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) { |
| 138 | RTC_LOG(LS_WARNING) |
| 139 | << "Failed to estimate RTP clock frequency: Stream too short. (" |
| 140 | << packets.size() << " packets, " |
| 141 | << last_log_timestamp - first_log_timestamp << " us)"; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 142 | return absl::nullopt; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 143 | } |
| 144 | double duration = |
| 145 | static_cast<double>(last_log_timestamp - first_log_timestamp) / |
| 146 | kNumMicrosecsPerSec; |
| 147 | double estimated_frequency = |
| 148 | (last_rtp_timestamp - first_rtp_timestamp) / duration; |
| 149 | for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) { |
philipel | 3fa4938 | 2019-08-20 15:59:57 +0200 | [diff] [blame] | 150 | if (std::fabs(estimated_frequency - f) < 0.15 * f) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 151 | return f; |
| 152 | } |
| 153 | } |
| 154 | RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate " |
| 155 | << estimated_frequency |
philipel | 3fa4938 | 2019-08-20 15:59:57 +0200 | [diff] [blame] | 156 | << " not close to any stardard RTP frequency."; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 157 | return absl::nullopt; |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 160 | absl::optional<double> NetworkDelayDiff_AbsSendTime( |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 161 | const LoggedRtpPacketIncoming& old_packet, |
| 162 | const LoggedRtpPacketIncoming& new_packet) { |
| 163 | if (old_packet.rtp.header.extension.hasAbsoluteSendTime && |
| 164 | new_packet.rtp.header.extension.hasAbsoluteSendTime) { |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 165 | int64_t send_time_diff = WrappingDifference( |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 166 | new_packet.rtp.header.extension.absoluteSendTime, |
| 167 | old_packet.rtp.header.extension.absoluteSendTime, 1ul << 24); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 168 | int64_t recv_time_diff = |
| 169 | new_packet.log_time_us() - old_packet.log_time_us(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 170 | double delay_change_us = |
| 171 | recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff); |
Oskar Sundbom | 3928dbc | 2017-11-16 10:53:09 +0100 | [diff] [blame] | 172 | return delay_change_us / 1000; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 173 | } else { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 174 | return absl::nullopt; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 178 | absl::optional<double> NetworkDelayDiff_CaptureTime( |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 179 | const LoggedRtpPacketIncoming& old_packet, |
| 180 | const LoggedRtpPacketIncoming& new_packet, |
| 181 | const double sample_rate) { |
| 182 | int64_t send_time_diff = |
| 183 | WrappingDifference(new_packet.rtp.header.timestamp, |
| 184 | old_packet.rtp.header.timestamp, 1ull << 32); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 185 | int64_t recv_time_diff = new_packet.log_time_us() - old_packet.log_time_us(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 186 | |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 187 | double delay_change = |
| 188 | static_cast<double>(recv_time_diff) / 1000 - |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 189 | static_cast<double>(send_time_diff) / sample_rate * 1000; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 190 | if (delay_change < -10000 || 10000 < delay_change) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 191 | RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?"; |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 192 | RTC_LOG(LS_WARNING) << "Old capture time " |
| 193 | << old_packet.rtp.header.timestamp << ", received time " |
| 194 | << old_packet.log_time_us(); |
| 195 | RTC_LOG(LS_WARNING) << "New capture time " |
| 196 | << new_packet.rtp.header.timestamp << ", received time " |
| 197 | << new_packet.log_time_us(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 198 | RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = " |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 199 | << static_cast<double>(recv_time_diff) / |
| 200 | kNumMicrosecsPerSec |
| 201 | << "s"; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 202 | RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = " |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 203 | << static_cast<double>(send_time_diff) / sample_rate |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 204 | << "s"; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 205 | } |
Oskar Sundbom | 3928dbc | 2017-11-16 10:53:09 +0100 | [diff] [blame] | 206 | return delay_change; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 207 | } |
| 208 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 209 | |
Bjorn Terelius | 7c974e6 | 2019-02-15 17:20:12 +0100 | [diff] [blame] | 210 | template <typename T> |
| 211 | TimeSeries CreateRtcpTypeTimeSeries(const std::vector<T>& rtcp_list, |
| 212 | AnalyzerConfig config, |
| 213 | std::string rtcp_name, |
| 214 | int category_id) { |
| 215 | TimeSeries time_series(rtcp_name, LineStyle::kNone, PointStyle::kHighlight); |
| 216 | for (const auto& rtcp : rtcp_list) { |
| 217 | float x = config.GetCallTimeSec(rtcp.log_time_us()); |
| 218 | float y = category_id; |
| 219 | time_series.points.emplace_back(x, y); |
| 220 | } |
| 221 | return time_series; |
| 222 | } |
| 223 | |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 224 | const char kUnknownEnumValue[] = "unknown"; |
| 225 | |
| 226 | const char kIceCandidateTypeLocal[] = "local"; |
| 227 | const char kIceCandidateTypeStun[] = "stun"; |
| 228 | const char kIceCandidateTypePrflx[] = "prflx"; |
| 229 | const char kIceCandidateTypeRelay[] = "relay"; |
| 230 | |
| 231 | const char kProtocolUdp[] = "udp"; |
| 232 | const char kProtocolTcp[] = "tcp"; |
| 233 | const char kProtocolSsltcp[] = "ssltcp"; |
| 234 | const char kProtocolTls[] = "tls"; |
| 235 | |
| 236 | const char kAddressFamilyIpv4[] = "ipv4"; |
| 237 | const char kAddressFamilyIpv6[] = "ipv6"; |
| 238 | |
| 239 | const char kNetworkTypeEthernet[] = "ethernet"; |
| 240 | const char kNetworkTypeLoopback[] = "loopback"; |
| 241 | const char kNetworkTypeWifi[] = "wifi"; |
| 242 | const char kNetworkTypeVpn[] = "vpn"; |
| 243 | const char kNetworkTypeCellular[] = "cellular"; |
| 244 | |
| 245 | std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) { |
| 246 | switch (type) { |
| 247 | case webrtc::IceCandidateType::kLocal: |
| 248 | return kIceCandidateTypeLocal; |
| 249 | case webrtc::IceCandidateType::kStun: |
| 250 | return kIceCandidateTypeStun; |
| 251 | case webrtc::IceCandidateType::kPrflx: |
| 252 | return kIceCandidateTypePrflx; |
| 253 | case webrtc::IceCandidateType::kRelay: |
| 254 | return kIceCandidateTypeRelay; |
| 255 | default: |
| 256 | return kUnknownEnumValue; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) { |
| 261 | switch (protocol) { |
| 262 | case webrtc::IceCandidatePairProtocol::kUdp: |
| 263 | return kProtocolUdp; |
| 264 | case webrtc::IceCandidatePairProtocol::kTcp: |
| 265 | return kProtocolTcp; |
| 266 | case webrtc::IceCandidatePairProtocol::kSsltcp: |
| 267 | return kProtocolSsltcp; |
| 268 | case webrtc::IceCandidatePairProtocol::kTls: |
| 269 | return kProtocolTls; |
| 270 | default: |
| 271 | return kUnknownEnumValue; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | std::string GetAddressFamilyAsString( |
| 276 | webrtc::IceCandidatePairAddressFamily family) { |
| 277 | switch (family) { |
| 278 | case webrtc::IceCandidatePairAddressFamily::kIpv4: |
| 279 | return kAddressFamilyIpv4; |
| 280 | case webrtc::IceCandidatePairAddressFamily::kIpv6: |
| 281 | return kAddressFamilyIpv6; |
| 282 | default: |
| 283 | return kUnknownEnumValue; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) { |
| 288 | switch (type) { |
| 289 | case webrtc::IceCandidateNetworkType::kEthernet: |
| 290 | return kNetworkTypeEthernet; |
| 291 | case webrtc::IceCandidateNetworkType::kLoopback: |
| 292 | return kNetworkTypeLoopback; |
| 293 | case webrtc::IceCandidateNetworkType::kWifi: |
| 294 | return kNetworkTypeWifi; |
| 295 | case webrtc::IceCandidateNetworkType::kVpn: |
| 296 | return kNetworkTypeVpn; |
| 297 | case webrtc::IceCandidateNetworkType::kCellular: |
| 298 | return kNetworkTypeCellular; |
| 299 | default: |
| 300 | return kUnknownEnumValue; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | std::string GetCandidatePairLogDescriptionAsString( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 305 | const LoggedIceCandidatePairConfig& config) { |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 306 | // Example: stun:wifi->relay(tcp):cellular@udp:ipv4 |
| 307 | // represents a pair of a local server-reflexive candidate on a WiFi network |
| 308 | // and a remote relay candidate using TCP as the relay protocol on a cell |
| 309 | // network, when the candidate pair communicates over UDP using IPv4. |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 310 | rtc::StringBuilder ss; |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 311 | std::string local_candidate_type = |
| 312 | GetIceCandidateTypeAsString(config.local_candidate_type); |
| 313 | std::string remote_candidate_type = |
| 314 | GetIceCandidateTypeAsString(config.remote_candidate_type); |
| 315 | if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) { |
| 316 | local_candidate_type += |
| 317 | "(" + GetProtocolAsString(config.local_relay_protocol) + ")"; |
| 318 | } |
| 319 | ss << local_candidate_type << ":" |
| 320 | << GetNetworkTypeAsString(config.local_network_type) << ":" |
| 321 | << GetAddressFamilyAsString(config.local_address_family) << "->" |
| 322 | << remote_candidate_type << ":" |
| 323 | << GetAddressFamilyAsString(config.remote_address_family) << "@" |
| 324 | << GetProtocolAsString(config.candidate_pair_protocol); |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 325 | return ss.Release(); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 328 | std::string GetDirectionAsString(PacketDirection direction) { |
| 329 | if (direction == kIncomingPacket) { |
| 330 | return "Incoming"; |
| 331 | } else { |
| 332 | return "Outgoing"; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | std::string GetDirectionAsShortString(PacketDirection direction) { |
| 337 | if (direction == kIncomingPacket) { |
| 338 | return "In"; |
| 339 | } else { |
| 340 | return "Out"; |
| 341 | } |
| 342 | } |
| 343 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 344 | } // namespace |
| 345 | |
Sebastian Jansson | b290a6d | 2019-01-03 14:46:23 +0100 | [diff] [blame] | 346 | EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log, |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 347 | bool normalize_time) |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 348 | : parsed_log_(log) { |
| 349 | config_.window_duration_ = 250000; |
| 350 | config_.step_ = 10000; |
| 351 | config_.normalize_time_ = normalize_time; |
| 352 | config_.begin_time_ = parsed_log_.first_timestamp(); |
| 353 | config_.end_time_ = parsed_log_.last_timestamp(); |
| 354 | if (config_.end_time_ < config_.begin_time_) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 355 | RTC_LOG(LS_WARNING) << "No useful events in the log."; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 356 | config_.begin_time_ = config_.end_time_ = 0; |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 357 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 358 | |
Björn Terelius | 0d1b28c | 2020-05-27 20:25:06 +0200 | [diff] [blame] | 359 | RTC_LOG(LS_INFO) << "Log is " |
| 360 | << (parsed_log_.last_timestamp() - |
| 361 | parsed_log_.first_timestamp()) / |
| 362 | 1000000 |
| 363 | << " seconds long."; |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log, |
| 367 | const AnalyzerConfig& config) |
| 368 | : parsed_log_(log), config_(config) { |
Björn Terelius | 0d1b28c | 2020-05-27 20:25:06 +0200 | [diff] [blame] | 369 | RTC_LOG(LS_INFO) << "Log is " |
| 370 | << (parsed_log_.last_timestamp() - |
| 371 | parsed_log_.first_timestamp()) / |
| 372 | 1000000 |
| 373 | << " seconds long."; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 376 | class BitrateObserver : public RemoteBitrateObserver { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 377 | public: |
| 378 | BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {} |
| 379 | |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 380 | void Update(NetworkControlUpdate update) { |
| 381 | if (update.target_rate) { |
| 382 | last_bitrate_bps_ = update.target_rate->target_rate.bps(); |
| 383 | bitrate_updated_ = true; |
| 384 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 388 | uint32_t bitrate) override {} |
| 389 | |
| 390 | uint32_t last_bitrate_bps() const { return last_bitrate_bps_; } |
| 391 | bool GetAndResetBitrateUpdated() { |
| 392 | bool bitrate_updated = bitrate_updated_; |
| 393 | bitrate_updated_ = false; |
| 394 | return bitrate_updated; |
| 395 | } |
| 396 | |
| 397 | private: |
| 398 | uint32_t last_bitrate_bps_; |
| 399 | bool bitrate_updated_; |
| 400 | }; |
| 401 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 402 | void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction, |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 403 | Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 404 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 405 | // Filter on SSRC. |
| 406 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 407 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 408 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 409 | |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 410 | TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc), |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 411 | LineStyle::kBar); |
| 412 | auto GetPacketSize = [](const LoggedRtpPacket& packet) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 413 | return absl::optional<float>(packet.total_length); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 414 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 415 | auto ToCallTime = [this](const LoggedRtpPacket& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 416 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 417 | }; |
| 418 | ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize, |
| 419 | stream.packet_view, &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 420 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 423 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 424 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 425 | plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin, |
| 426 | kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 427 | plot->SetTitle(GetDirectionAsString(direction) + " RTP packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Bjorn Terelius | 7c974e6 | 2019-02-15 17:20:12 +0100 | [diff] [blame] | 430 | void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction, |
| 431 | Plot* plot) { |
| 432 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries( |
| 433 | parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1)); |
| 434 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries( |
| 435 | parsed_log_.receiver_reports(direction), config_, "RR", 2)); |
| 436 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries( |
| 437 | parsed_log_.sender_reports(direction), config_, "SR", 3)); |
| 438 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries( |
| 439 | parsed_log_.extended_reports(direction), config_, "XR", 4)); |
| 440 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction), |
| 441 | config_, "NACK", 5)); |
| 442 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction), |
| 443 | config_, "REMB", 6)); |
| 444 | plot->AppendTimeSeries( |
| 445 | CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7)); |
| 446 | plot->AppendTimeSeries( |
| 447 | CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8)); |
Björn Terelius | 4ef5638 | 2021-02-03 14:12:24 +0100 | [diff] [blame^] | 448 | plot->AppendTimeSeries( |
| 449 | CreateRtcpTypeTimeSeries(parsed_log_.byes(direction), config_, "BYE", 9)); |
Bjorn Terelius | 7c974e6 | 2019-02-15 17:20:12 +0100 | [diff] [blame] | 450 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 451 | "Time (s)", kLeftMargin, kRightMargin); |
| 452 | plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin); |
| 453 | plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets"); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 454 | plot->SetYAxisTickLabels({{1, "TWCC"}, |
| 455 | {2, "RR"}, |
| 456 | {3, "SR"}, |
| 457 | {4, "XR"}, |
| 458 | {5, "NACK"}, |
| 459 | {6, "REMB"}, |
| 460 | {7, "FIR"}, |
Björn Terelius | 4ef5638 | 2021-02-03 14:12:24 +0100 | [diff] [blame^] | 461 | {8, "PLI"}, |
| 462 | {9, "BYE"}}); |
Bjorn Terelius | 7c974e6 | 2019-02-15 17:20:12 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 465 | template <typename IterableType> |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 466 | void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries( |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 467 | Plot* plot, |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 468 | const IterableType& packets, |
| 469 | const std::string& label) { |
| 470 | TimeSeries time_series(label, LineStyle::kStep); |
| 471 | for (size_t i = 0; i < packets.size(); i++) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 472 | float x = config_.GetCallTimeSec(packets[i].log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 473 | time_series.points.emplace_back(x, i + 1); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 474 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 475 | plot->AppendTimeSeries(std::move(time_series)); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 478 | void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction, |
| 479 | Plot* plot) { |
| 480 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 481 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) |
| 482 | continue; |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 483 | std::string label = std::string("RTP ") + |
| 484 | GetStreamName(parsed_log_, direction, stream.ssrc); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 485 | CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label); |
| 486 | } |
| 487 | std::string label = |
| 488 | std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")"; |
| 489 | if (direction == kIncomingPacket) { |
| 490 | CreateAccumulatedPacketsTimeSeries( |
| 491 | plot, parsed_log_.incoming_rtcp_packets(), label); |
| 492 | } else { |
| 493 | CreateAccumulatedPacketsTimeSeries( |
| 494 | plot, parsed_log_.outgoing_rtcp_packets(), label); |
| 495 | } |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 496 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 497 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 498 | "Time (s)", kLeftMargin, kRightMargin); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 499 | plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 500 | plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) + |
| 501 | " RTP/RTCP packets"); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Kristoffer Erlandsson | 283c106 | 2020-03-30 13:01:37 +0200 | [diff] [blame] | 504 | void EventLogAnalyzer::CreatePacketRateGraph(PacketDirection direction, |
| 505 | Plot* plot) { |
| 506 | auto CountPackets = [](auto packet) { return 1.0; }; |
| 507 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 508 | // Filter on SSRC. |
| 509 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) { |
| 510 | continue; |
| 511 | } |
| 512 | TimeSeries time_series( |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 513 | std::string("RTP ") + |
| 514 | GetStreamName(parsed_log_, direction, stream.ssrc), |
Kristoffer Erlandsson | 283c106 | 2020-03-30 13:01:37 +0200 | [diff] [blame] | 515 | LineStyle::kLine); |
| 516 | MovingAverage<LoggedRtpPacket, double>(CountPackets, stream.packet_view, |
| 517 | config_, &time_series); |
| 518 | plot->AppendTimeSeries(std::move(time_series)); |
| 519 | } |
| 520 | TimeSeries time_series( |
| 521 | std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")", |
| 522 | LineStyle::kLine); |
| 523 | if (direction == kIncomingPacket) { |
| 524 | MovingAverage<LoggedRtcpPacketIncoming, double>( |
| 525 | CountPackets, parsed_log_.incoming_rtcp_packets(), config_, |
| 526 | &time_series); |
| 527 | } else { |
| 528 | MovingAverage<LoggedRtcpPacketOutgoing, double>( |
| 529 | CountPackets, parsed_log_.outgoing_rtcp_packets(), config_, |
| 530 | &time_series); |
| 531 | } |
| 532 | plot->AppendTimeSeries(std::move(time_series)); |
| 533 | |
| 534 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 535 | "Time (s)", kLeftMargin, kRightMargin); |
| 536 | plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin, |
| 537 | kTopMargin); |
| 538 | plot->SetTitle("Rate of " + GetDirectionAsString(direction) + |
| 539 | " RTP/RTCP packets"); |
| 540 | } |
| 541 | |
Kristoffer Erlandsson | a2ce423 | 2020-04-01 14:33:30 +0200 | [diff] [blame] | 542 | void EventLogAnalyzer::CreateTotalPacketRateGraph(PacketDirection direction, |
| 543 | Plot* plot) { |
| 544 | // Contains a log timestamp to enable counting logged events of different |
| 545 | // types using MovingAverage(). |
| 546 | class LogTime { |
| 547 | public: |
| 548 | explicit LogTime(int64_t log_time_us) : log_time_us_(log_time_us) {} |
| 549 | |
| 550 | int64_t log_time_us() const { return log_time_us_; } |
| 551 | |
| 552 | private: |
| 553 | int64_t log_time_us_; |
| 554 | }; |
| 555 | |
| 556 | std::vector<LogTime> packet_times; |
| 557 | auto handle_rtp = [&](const LoggedRtpPacket& packet) { |
| 558 | packet_times.emplace_back(packet.log_time_us()); |
| 559 | }; |
| 560 | RtcEventProcessor process; |
| 561 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 562 | process.AddEvents(stream.packet_view, handle_rtp); |
| 563 | } |
| 564 | if (direction == kIncomingPacket) { |
| 565 | auto handle_incoming_rtcp = [&](const LoggedRtcpPacketIncoming& packet) { |
| 566 | packet_times.emplace_back(packet.log_time_us()); |
| 567 | }; |
| 568 | process.AddEvents(parsed_log_.incoming_rtcp_packets(), |
| 569 | handle_incoming_rtcp); |
| 570 | } else { |
| 571 | auto handle_outgoing_rtcp = [&](const LoggedRtcpPacketOutgoing& packet) { |
| 572 | packet_times.emplace_back(packet.log_time_us()); |
| 573 | }; |
| 574 | process.AddEvents(parsed_log_.outgoing_rtcp_packets(), |
| 575 | handle_outgoing_rtcp); |
| 576 | } |
| 577 | process.ProcessEventsInOrder(); |
| 578 | TimeSeries time_series(std::string("Total ") + "(" + |
| 579 | GetDirectionAsShortString(direction) + ") packets", |
| 580 | LineStyle::kLine); |
| 581 | MovingAverage<LogTime, uint64_t>([](auto packet) { return 1; }, packet_times, |
| 582 | config_, &time_series); |
| 583 | plot->AppendTimeSeries(std::move(time_series)); |
| 584 | |
| 585 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 586 | "Time (s)", kLeftMargin, kRightMargin); |
| 587 | plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin, |
| 588 | kTopMargin); |
| 589 | plot->SetTitle("Rate of all " + GetDirectionAsString(direction) + |
| 590 | " RTP/RTCP packets"); |
| 591 | } |
| 592 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 593 | // For each SSRC, plot the time between the consecutive playouts. |
| 594 | void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 595 | for (const auto& playout_stream : parsed_log_.audio_playout_events()) { |
| 596 | uint32_t ssrc = playout_stream.first; |
| 597 | if (!MatchingSsrc(ssrc, desired_ssrc_)) |
| 598 | continue; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 599 | absl::optional<int64_t> last_playout_ms; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 600 | TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 601 | for (const auto& playout_event : playout_stream.second) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 602 | float x = config_.GetCallTimeSec(playout_event.log_time_us()); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 603 | int64_t playout_time_ms = playout_event.log_time_ms(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 604 | // If there were no previous playouts, place the point on the x-axis. |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 605 | float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 606 | time_series.points.push_back(TimeSeriesPoint(x, y)); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 607 | last_playout_ms.emplace(playout_time_ms); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 608 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 609 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 612 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 613 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 614 | plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin, |
| 615 | kTopMargin); |
| 616 | plot->SetTitle("Audio playout"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 617 | } |
| 618 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 619 | // For audio SSRCs, plot the audio level. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 620 | void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction, |
| 621 | Plot* plot) { |
| 622 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 623 | if (!IsAudioSsrc(parsed_log_, direction, stream.ssrc)) |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 624 | continue; |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 625 | TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc), |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 626 | LineStyle::kLine); |
| 627 | for (auto& packet : stream.packet_view) { |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 628 | if (packet.header.extension.hasAudioLevel) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 629 | float x = config_.GetCallTimeSec(packet.log_time_us()); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 630 | // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10) |
| 631 | // Here we convert it to dBov. |
| 632 | float y = static_cast<float>(-packet.header.extension.audioLevel); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 633 | time_series.points.emplace_back(TimeSeriesPoint(x, y)); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 636 | plot->AppendTimeSeries(std::move(time_series)); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 639 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 640 | "Time (s)", kLeftMargin, kRightMargin); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 641 | plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 642 | plot->SetTitle(GetDirectionAsString(direction) + " audio level"); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Konrad Hofbauer | ca3c801 | 2019-02-15 20:52:19 +0100 | [diff] [blame] | 645 | // For each SSRC, plot the sequence number difference between consecutive |
| 646 | // incoming packets. |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 647 | void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 648 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
| 649 | // Filter on SSRC. |
| 650 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 651 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 652 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 653 | |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 654 | TimeSeries time_series( |
| 655 | GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc), |
| 656 | LineStyle::kBar); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 657 | auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet, |
| 658 | const LoggedRtpPacketIncoming& new_packet) { |
| 659 | int64_t diff = |
| 660 | WrappingDifference(new_packet.rtp.header.sequenceNumber, |
| 661 | old_packet.rtp.header.sequenceNumber, 1ul << 16); |
| 662 | return diff; |
| 663 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 664 | auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 665 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 666 | }; |
| 667 | ProcessPairs<LoggedRtpPacketIncoming, float>( |
| 668 | ToCallTime, GetSequenceNumberDiff, stream.incoming_packets, |
| 669 | &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 670 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 673 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 674 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 675 | plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin, |
| 676 | kTopMargin); |
Konrad Hofbauer | ca3c801 | 2019-02-15 20:52:19 +0100 | [diff] [blame] | 677 | plot->SetTitle("Incoming sequence number delta"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 680 | void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 681 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
| 682 | const std::vector<LoggedRtpPacketIncoming>& packets = |
| 683 | stream.incoming_packets; |
| 684 | // Filter on SSRC. |
Mirko Bonadei | 1f17315 | 2019-07-25 15:28:14 +0200 | [diff] [blame] | 685 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.empty()) { |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 686 | continue; |
| 687 | } |
| 688 | |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 689 | TimeSeries time_series( |
| 690 | GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc), |
| 691 | LineStyle::kLine, PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 692 | // TODO(terelius): Should the window and step size be read from the class |
| 693 | // instead? |
| 694 | const int64_t kWindowUs = 1000000; |
| 695 | const int64_t kStep = 1000000; |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 696 | SeqNumUnwrapper<uint16_t> unwrapper_; |
| 697 | SeqNumUnwrapper<uint16_t> prior_unwrapper_; |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 698 | size_t window_index_begin = 0; |
| 699 | size_t window_index_end = 0; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 700 | uint64_t highest_seq_number = |
| 701 | unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1; |
| 702 | uint64_t highest_prior_seq_number = |
| 703 | prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1; |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 704 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 705 | for (int64_t t = config_.begin_time_; t < config_.end_time_ + kStep; |
| 706 | t += kStep) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 707 | while (window_index_end < packets.size() && |
| 708 | packets[window_index_end].rtp.log_time_us() < t) { |
| 709 | uint64_t sequence_number = unwrapper_.Unwrap( |
| 710 | packets[window_index_end].rtp.header.sequenceNumber); |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 711 | highest_seq_number = std::max(highest_seq_number, sequence_number); |
| 712 | ++window_index_end; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 713 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 714 | while (window_index_begin < packets.size() && |
| 715 | packets[window_index_begin].rtp.log_time_us() < t - kWindowUs) { |
| 716 | uint64_t sequence_number = prior_unwrapper_.Unwrap( |
| 717 | packets[window_index_begin].rtp.header.sequenceNumber); |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 718 | highest_prior_seq_number = |
| 719 | std::max(highest_prior_seq_number, sequence_number); |
| 720 | ++window_index_begin; |
| 721 | } |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 722 | float x = config_.GetCallTimeSec(t); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 723 | uint64_t expected_packets = highest_seq_number - highest_prior_seq_number; |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 724 | if (expected_packets > 0) { |
| 725 | int64_t received_packets = window_index_end - window_index_begin; |
| 726 | int64_t lost_packets = expected_packets - received_packets; |
| 727 | float y = static_cast<float>(lost_packets) / expected_packets * 100; |
| 728 | time_series.points.emplace_back(x, y); |
| 729 | } |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 730 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 731 | plot->AppendTimeSeries(std::move(time_series)); |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 732 | } |
| 733 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 734 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 735 | "Time (s)", kLeftMargin, kRightMargin); |
Konrad Hofbauer | d036c65 | 2019-02-14 16:17:28 +0100 | [diff] [blame] | 736 | plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin); |
| 737 | plot->SetTitle("Incoming packet loss (derived from incoming packets)"); |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 738 | } |
| 739 | |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 740 | void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) { |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 741 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 742 | // Filter on SSRC. |
| 743 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 744 | IsRtxSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 745 | continue; |
| 746 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 747 | |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 748 | const std::vector<LoggedRtpPacketIncoming>& packets = |
| 749 | stream.incoming_packets; |
| 750 | if (packets.size() < 100) { |
| 751 | RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with " |
| 752 | << packets.size() << " packets in the stream."; |
| 753 | continue; |
| 754 | } |
Björn Terelius | 0d1b28c | 2020-05-27 20:25:06 +0200 | [diff] [blame] | 755 | int64_t segment_end_us = parsed_log_.first_log_segment().stop_time_us(); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 756 | absl::optional<uint32_t> estimated_frequency = |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 757 | EstimateRtpClockFrequency(packets, segment_end_us); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 758 | if (!estimated_frequency) |
| 759 | continue; |
| 760 | const double frequency_hz = *estimated_frequency; |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 761 | if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc) && |
| 762 | frequency_hz != 90000) { |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 763 | RTC_LOG(LS_WARNING) |
| 764 | << "Video stream should use a 90 kHz clock but appears to use " |
| 765 | << frequency_hz / 1000 << ". Discarding."; |
| 766 | continue; |
| 767 | } |
| 768 | |
| 769 | auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 770 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 771 | }; |
| 772 | auto ToNetworkDelay = [frequency_hz]( |
| 773 | const LoggedRtpPacketIncoming& old_packet, |
| 774 | const LoggedRtpPacketIncoming& new_packet) { |
| 775 | return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz); |
| 776 | }; |
| 777 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 778 | TimeSeries capture_time_data( |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 779 | GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) + |
| 780 | " capture-time", |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 781 | LineStyle::kLine); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 782 | AccumulatePairs<LoggedRtpPacketIncoming, double>( |
| 783 | ToCallTime, ToNetworkDelay, packets, &capture_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 784 | plot->AppendTimeSeries(std::move(capture_time_data)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 785 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 786 | TimeSeries send_time_data( |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 787 | GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) + |
| 788 | " abs-send-time", |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 789 | LineStyle::kLine); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 790 | AccumulatePairs<LoggedRtpPacketIncoming, double>( |
| 791 | ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data); |
| 792 | plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 795 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 796 | "Time (s)", kLeftMargin, kRightMargin); |
Konrad Hofbauer | 5be3bbd | 2019-01-21 12:31:07 +0100 | [diff] [blame] | 797 | plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin); |
| 798 | plot->SetTitle("Incoming network delay (relative to first packet)"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 799 | } |
| 800 | |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 801 | // Plot the fraction of packets lost (as perceived by the loss-based BWE). |
| 802 | void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) { |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 803 | TimeSeries time_series("Fraction lost", LineStyle::kLine, |
| 804 | PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 805 | for (auto& bwe_update : parsed_log_.bwe_loss_updates()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 806 | float x = config_.GetCallTimeSec(bwe_update.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 807 | float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 808 | time_series.points.emplace_back(x, y); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 809 | } |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 810 | |
Bjorn Terelius | 19f5be3 | 2017-10-18 12:39:49 +0200 | [diff] [blame] | 811 | plot->AppendTimeSeries(std::move(time_series)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 812 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 813 | "Time (s)", kLeftMargin, kRightMargin); |
Konrad Hofbauer | d036c65 | 2019-02-14 16:17:28 +0100 | [diff] [blame] | 814 | plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin); |
| 815 | plot->SetTitle("Outgoing packet loss (as reported by BWE)"); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 816 | } |
| 817 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 818 | // Plot the total bandwidth used by all RTP streams. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 819 | void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) { |
| 820 | // TODO(terelius): This could be provided by the parser. |
| 821 | std::multimap<int64_t, size_t> packets_in_order; |
| 822 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
| 823 | for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets) |
| 824 | packets_in_order.insert( |
| 825 | std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 828 | auto window_begin = packets_in_order.begin(); |
| 829 | auto window_end = packets_in_order.begin(); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 830 | size_t bytes_in_window = 0; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 831 | |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 832 | if (!packets_in_order.empty()) { |
| 833 | // Calculate a moving average of the bitrate and store in a TimeSeries. |
| 834 | TimeSeries bitrate_series("Bitrate", LineStyle::kLine); |
| 835 | for (int64_t time = config_.begin_time_; |
| 836 | time < config_.end_time_ + config_.step_; time += config_.step_) { |
| 837 | while (window_end != packets_in_order.end() && window_end->first < time) { |
| 838 | bytes_in_window += window_end->second; |
| 839 | ++window_end; |
| 840 | } |
| 841 | while (window_begin != packets_in_order.end() && |
| 842 | window_begin->first < time - config_.window_duration_) { |
| 843 | RTC_DCHECK_LE(window_begin->second, bytes_in_window); |
| 844 | bytes_in_window -= window_begin->second; |
| 845 | ++window_begin; |
| 846 | } |
| 847 | float window_duration_in_seconds = |
| 848 | static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec; |
| 849 | 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); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 852 | } |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 853 | plot->AppendTimeSeries(std::move(bitrate_series)); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 854 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 855 | |
| 856 | // Overlay the outgoing REMB over incoming bitrate. |
| 857 | TimeSeries remb_series("Remb", LineStyle::kStep); |
| 858 | for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 859 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 860 | 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) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 865 | 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 Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 876 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 877 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 878 | 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. |
| 883 | void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot, |
| 884 | bool show_detector_state, |
| 885 | bool show_alr_state) { |
| 886 | // TODO(terelius): This could be provided by the parser. |
| 887 | std::multimap<int64_t, size_t> packets_in_order; |
| 888 | for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) { |
| 889 | for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets) |
| 890 | packets_in_order.insert( |
| 891 | std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length)); |
| 892 | } |
| 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) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 898 | 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); |
| 901 | for (int64_t time = config_.begin_time_; |
| 902 | 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 = |
| 914 | static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec; |
| 915 | float x = config_.GetCallTimeSec(time); |
| 916 | float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; |
| 917 | bitrate_series.points.emplace_back(x, y); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 918 | } |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 919 | plot->AppendTimeSeries(std::move(bitrate_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 920 | } |
| 921 | |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 922 | // Overlay the send-side bandwidth estimate over the outgoing bitrate. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 923 | TimeSeries loss_series("Loss-based estimate", LineStyle::kStep); |
| 924 | for (auto& loss_update : parsed_log_.bwe_loss_updates()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 925 | float x = config_.GetCallTimeSec(loss_update.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 926 | float y = static_cast<float>(loss_update.bitrate_bps) / 1000; |
| 927 | loss_series.points.emplace_back(x, y); |
| 928 | } |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 929 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 930 | TimeSeries delay_series("Delay-based estimate", LineStyle::kStep); |
| 931 | IntervalSeries overusing_series("Overusing", "#ff8e82", |
| 932 | IntervalSeries::kHorizontal); |
| 933 | IntervalSeries underusing_series("Underusing", "#5092fc", |
| 934 | IntervalSeries::kHorizontal); |
| 935 | IntervalSeries normal_series("Normal", "#c4ffc4", |
| 936 | IntervalSeries::kHorizontal); |
| 937 | IntervalSeries* last_series = &normal_series; |
| 938 | double last_detector_switch = 0.0; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 939 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 940 | BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 941 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 942 | for (auto& delay_update : parsed_log_.bwe_delay_updates()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 943 | float x = config_.GetCallTimeSec(delay_update.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 944 | float y = static_cast<float>(delay_update.bitrate_bps) / 1000; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 945 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 946 | if (last_detector_state != delay_update.detector_state) { |
| 947 | last_series->intervals.emplace_back(last_detector_switch, x); |
| 948 | last_detector_state = delay_update.detector_state; |
| 949 | last_detector_switch = x; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 950 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 951 | switch (delay_update.detector_state) { |
| 952 | case BandwidthUsage::kBwNormal: |
| 953 | last_series = &normal_series; |
| 954 | break; |
| 955 | case BandwidthUsage::kBwUnderusing: |
| 956 | last_series = &underusing_series; |
| 957 | break; |
| 958 | case BandwidthUsage::kBwOverusing: |
| 959 | last_series = &overusing_series; |
| 960 | break; |
| 961 | case BandwidthUsage::kLast: |
| 962 | RTC_NOTREACHED(); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 963 | } |
| 964 | } |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 965 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 966 | delay_series.points.emplace_back(x, y); |
| 967 | } |
Bjorn Terelius | 9e336ec | 2018-04-24 16:28:35 +0200 | [diff] [blame] | 968 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 969 | RTC_CHECK(last_series); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 970 | last_series->intervals.emplace_back(last_detector_switch, config_.end_time_); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 971 | |
| 972 | TimeSeries created_series("Probe cluster created.", LineStyle::kNone, |
| 973 | PointStyle::kHighlight); |
| 974 | for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 975 | float x = config_.GetCallTimeSec(cluster.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 976 | float y = static_cast<float>(cluster.bitrate_bps) / 1000; |
| 977 | created_series.points.emplace_back(x, y); |
| 978 | } |
| 979 | |
| 980 | TimeSeries result_series("Probing results.", LineStyle::kNone, |
| 981 | PointStyle::kHighlight); |
Bjorn Terelius | 7a0bb00 | 2018-05-29 14:45:53 +0200 | [diff] [blame] | 982 | for (auto& result : parsed_log_.bwe_probe_success_events()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 983 | float x = config_.GetCallTimeSec(result.log_time_us()); |
Bjorn Terelius | 7a0bb00 | 2018-05-29 14:45:53 +0200 | [diff] [blame] | 984 | float y = static_cast<float>(result.bitrate_bps) / 1000; |
| 985 | result_series.points.emplace_back(x, y); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 986 | } |
| 987 | |
Piotr (Peter) Slatala | f996c84 | 2019-01-04 06:54:22 -0800 | [diff] [blame] | 988 | TimeSeries probe_failures_series("Probe failed", LineStyle::kNone, |
| 989 | PointStyle::kHighlight); |
| 990 | for (auto& failure : parsed_log_.bwe_probe_failure_events()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 991 | float x = config_.GetCallTimeSec(failure.log_time_us()); |
Piotr (Peter) Slatala | f996c84 | 2019-01-04 06:54:22 -0800 | [diff] [blame] | 992 | probe_failures_series.points.emplace_back(x, 0); |
| 993 | } |
| 994 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 995 | IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal); |
| 996 | bool previously_in_alr = false; |
| 997 | int64_t alr_start = 0; |
| 998 | for (auto& alr : parsed_log_.alr_state_events()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 999 | float y = config_.GetCallTimeSec(alr.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1000 | if (!previously_in_alr && alr.in_alr) { |
| 1001 | alr_start = alr.log_time_us(); |
| 1002 | previously_in_alr = true; |
| 1003 | } else if (previously_in_alr && !alr.in_alr) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1004 | float x = config_.GetCallTimeSec(alr_start); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1005 | alr_state.intervals.emplace_back(x, y); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1006 | previously_in_alr = false; |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1007 | } |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1010 | if (previously_in_alr) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1011 | float x = config_.GetCallTimeSec(alr_start); |
| 1012 | float y = config_.GetCallTimeSec(config_.end_time_); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1013 | alr_state.intervals.emplace_back(x, y); |
| 1014 | } |
| 1015 | |
| 1016 | if (show_detector_state) { |
| 1017 | plot->AppendIntervalSeries(std::move(overusing_series)); |
| 1018 | plot->AppendIntervalSeries(std::move(underusing_series)); |
| 1019 | plot->AppendIntervalSeries(std::move(normal_series)); |
| 1020 | } |
| 1021 | |
| 1022 | if (show_alr_state) { |
| 1023 | plot->AppendIntervalSeries(std::move(alr_state)); |
| 1024 | } |
| 1025 | plot->AppendTimeSeries(std::move(loss_series)); |
Piotr (Peter) Slatala | f996c84 | 2019-01-04 06:54:22 -0800 | [diff] [blame] | 1026 | plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series)); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1027 | plot->AppendTimeSeries(std::move(delay_series)); |
| 1028 | plot->AppendTimeSeries(std::move(created_series)); |
| 1029 | plot->AppendTimeSeries(std::move(result_series)); |
| 1030 | |
| 1031 | // Overlay the incoming REMB over the outgoing bitrate. |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1032 | TimeSeries remb_series("Remb", LineStyle::kStep); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1033 | for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1034 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1035 | float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000; |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 1036 | remb_series.points.emplace_back(x, y); |
| 1037 | } |
| 1038 | plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series)); |
| 1039 | |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 1040 | if (!parsed_log_.generic_packets_sent().empty()) { |
| 1041 | { |
| 1042 | TimeSeries time_series("Outgoing generic total bitrate", |
| 1043 | LineStyle::kLine); |
| 1044 | auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) { |
| 1045 | return packet.packet_length() * 8.0 / 1000.0; |
| 1046 | }; |
| 1047 | MovingAverage<LoggedGenericPacketSent, double>( |
| 1048 | GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_, |
| 1049 | &time_series); |
| 1050 | plot->AppendTimeSeries(std::move(time_series)); |
| 1051 | } |
| 1052 | |
| 1053 | { |
| 1054 | TimeSeries time_series("Outgoing generic payload bitrate", |
| 1055 | LineStyle::kLine); |
| 1056 | auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) { |
| 1057 | return packet.payload_length * 8.0 / 1000.0; |
| 1058 | }; |
| 1059 | MovingAverage<LoggedGenericPacketSent, double>( |
| 1060 | GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_, |
| 1061 | &time_series); |
| 1062 | plot->AppendTimeSeries(std::move(time_series)); |
| 1063 | } |
| 1064 | } |
| 1065 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1066 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1067 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1068 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1069 | plot->SetTitle("Outgoing RTP bitrate"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | // For each SSRC, plot the bandwidth used by that stream. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1073 | void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction, |
| 1074 | Plot* plot) { |
| 1075 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 1076 | // Filter on SSRC. |
| 1077 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 1078 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1081 | TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc), |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1082 | LineStyle::kLine); |
| 1083 | auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) { |
| 1084 | return packet.total_length * 8.0 / 1000.0; |
| 1085 | }; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1086 | MovingAverage<LoggedRtpPacket, double>( |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1087 | GetPacketSizeKilobits, stream.packet_view, config_, &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1088 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1091 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1092 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1093 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1094 | plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
Bjorn Terelius | 9775a58 | 2019-02-15 17:29:58 +0100 | [diff] [blame] | 1097 | // Plot the bitrate allocation for each temporal and spatial layer. |
| 1098 | // Computed from RTCP XR target bitrate block, so the graph is only populated if |
| 1099 | // those are sent. |
| 1100 | void EventLogAnalyzer::CreateBitrateAllocationGraph(PacketDirection direction, |
| 1101 | Plot* plot) { |
| 1102 | std::map<LayerDescription, TimeSeries> time_series; |
| 1103 | const auto& xr_list = parsed_log_.extended_reports(direction); |
| 1104 | for (const auto& rtcp : xr_list) { |
| 1105 | const absl::optional<rtcp::TargetBitrate>& target_bitrate = |
| 1106 | rtcp.xr.target_bitrate(); |
| 1107 | if (!target_bitrate.has_value()) |
| 1108 | continue; |
| 1109 | for (const auto& bitrate_item : target_bitrate->GetTargetBitrates()) { |
| 1110 | LayerDescription layer(rtcp.xr.sender_ssrc(), bitrate_item.spatial_layer, |
| 1111 | bitrate_item.temporal_layer); |
| 1112 | auto time_series_it = time_series.find(layer); |
| 1113 | if (time_series_it == time_series.end()) { |
| 1114 | std::string layer_name = GetLayerName(layer); |
| 1115 | bool inserted; |
| 1116 | std::tie(time_series_it, inserted) = time_series.insert( |
| 1117 | std::make_pair(layer, TimeSeries(layer_name, LineStyle::kStep))); |
| 1118 | RTC_DCHECK(inserted); |
| 1119 | } |
| 1120 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
| 1121 | float y = bitrate_item.target_bitrate_kbps; |
| 1122 | time_series_it->second.points.emplace_back(x, y); |
| 1123 | } |
| 1124 | } |
| 1125 | for (auto& layer : time_series) { |
| 1126 | plot->AppendTimeSeries(std::move(layer.second)); |
| 1127 | } |
| 1128 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1129 | "Time (s)", kLeftMargin, kRightMargin); |
| 1130 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 1131 | if (direction == kIncomingPacket) |
| 1132 | plot->SetTitle("Target bitrate per incoming layer"); |
| 1133 | else |
| 1134 | plot->SetTitle("Target bitrate per outgoing layer"); |
| 1135 | } |
| 1136 | |
Sebastian Jansson | 1175ae0 | 2019-03-13 08:56:58 +0100 | [diff] [blame] | 1137 | void EventLogAnalyzer::CreateGoogCcSimulationGraph(Plot* plot) { |
| 1138 | TimeSeries target_rates("Simulated target rate", LineStyle::kStep, |
| 1139 | PointStyle::kHighlight); |
| 1140 | TimeSeries delay_based("Logged delay-based estimate", LineStyle::kStep, |
| 1141 | PointStyle::kHighlight); |
| 1142 | TimeSeries loss_based("Logged loss-based estimate", LineStyle::kStep, |
| 1143 | PointStyle::kHighlight); |
| 1144 | TimeSeries probe_results("Logged probe success", LineStyle::kNone, |
| 1145 | PointStyle::kHighlight); |
| 1146 | |
Sebastian Jansson | 1175ae0 | 2019-03-13 08:56:58 +0100 | [diff] [blame] | 1147 | LogBasedNetworkControllerSimulation simulation( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1148 | std::make_unique<GoogCcNetworkControllerFactory>(), |
Sebastian Jansson | 1175ae0 | 2019-03-13 08:56:58 +0100 | [diff] [blame] | 1149 | [&](const NetworkControlUpdate& update, Timestamp at_time) { |
| 1150 | if (update.target_rate) { |
| 1151 | target_rates.points.emplace_back( |
| 1152 | config_.GetCallTimeSec(at_time.us()), |
| 1153 | update.target_rate->target_rate.kbps<float>()); |
| 1154 | } |
| 1155 | }); |
| 1156 | |
| 1157 | simulation.ProcessEventsInLog(parsed_log_); |
| 1158 | for (const auto& logged : parsed_log_.bwe_delay_updates()) |
| 1159 | delay_based.points.emplace_back( |
| 1160 | config_.GetCallTimeSec(logged.log_time_us()), |
| 1161 | logged.bitrate_bps / 1000); |
| 1162 | for (const auto& logged : parsed_log_.bwe_probe_success_events()) |
| 1163 | probe_results.points.emplace_back( |
| 1164 | config_.GetCallTimeSec(logged.log_time_us()), |
| 1165 | logged.bitrate_bps / 1000); |
| 1166 | for (const auto& logged : parsed_log_.bwe_loss_updates()) |
| 1167 | loss_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time_us()), |
| 1168 | 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 Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1181 | void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1182 | using RtpPacketType = LoggedRtpPacketOutgoing; |
| 1183 | using TransportFeedbackType = LoggedRtcpPacketTransportFeedback; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1184 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1185 | // 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 Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1191 | } |
| 1192 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1193 | const std::vector<TransportFeedbackType>& incoming_rtcp = |
| 1194 | parsed_log_.transport_feedbacks(kIncomingPacket); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1195 | |
| 1196 | SimulatedClock clock(0); |
| 1197 | BitrateObserver observer; |
Danil Chapovalov | 83bbe91 | 2019-08-07 12:24:53 +0200 | [diff] [blame] | 1198 | RtcEventLogNull null_event_log; |
nisse | 0245da0 | 2016-11-30 03:35:20 -0800 | [diff] [blame] | 1199 | PacketRouter packet_router; |
Stefan Holmer | 5c8942a | 2017-08-22 16:16:44 +0200 | [diff] [blame] | 1200 | PacedSender pacer(&clock, &packet_router, &null_event_log); |
Sebastian Jansson | 05acd2b | 2019-01-21 13:07:47 +0100 | [diff] [blame] | 1201 | TransportFeedbackAdapter transport_feedback; |
Sebastian Jansson | 2db5fc0 | 2019-04-30 14:17:45 +0200 | [diff] [blame] | 1202 | auto factory = GoogCcNetworkControllerFactory(); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1203 | TimeDelta process_interval = factory.GetProcessInterval(); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1204 | // TODO(holmer): Log the call config and use that here instead. |
| 1205 | static const uint32_t kDefaultStartBitrateBps = 300000; |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1206 | NetworkControllerConfig cc_config; |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1207 | cc_config.constraints.at_time = Timestamp::Micros(clock.TimeInMicroseconds()); |
Danil Chapovalov | cad3e0e | 2020-02-17 18:46:07 +0100 | [diff] [blame] | 1208 | cc_config.constraints.starting_rate = |
| 1209 | DataRate::BitsPerSec(kDefaultStartBitrateBps); |
Sebastian Jansson | 2db5fc0 | 2019-04-30 14:17:45 +0200 | [diff] [blame] | 1210 | cc_config.event_log = &null_event_log; |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1211 | auto goog_cc = factory.Create(cc_config); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1212 | |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1213 | TimeSeries time_series("Delay-based estimate", LineStyle::kStep, |
| 1214 | PointStyle::kHighlight); |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1215 | TimeSeries acked_time_series("Raw acked bitrate", LineStyle::kLine, |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1216 | PointStyle::kHighlight); |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1217 | TimeSeries robust_time_series("Robust throughput estimate", LineStyle::kLine, |
| 1218 | PointStyle::kHighlight); |
| 1219 | TimeSeries acked_estimate_time_series("Ackednowledged bitrate estimate", |
| 1220 | LineStyle::kLine, |
| 1221 | PointStyle::kHighlight); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1222 | |
| 1223 | auto rtp_iterator = outgoing_rtp.begin(); |
| 1224 | auto rtcp_iterator = incoming_rtcp.begin(); |
| 1225 | |
| 1226 | auto NextRtpTime = [&]() { |
| 1227 | if (rtp_iterator != outgoing_rtp.end()) |
| 1228 | return static_cast<int64_t>(rtp_iterator->first); |
| 1229 | return std::numeric_limits<int64_t>::max(); |
| 1230 | }; |
| 1231 | |
| 1232 | auto NextRtcpTime = [&]() { |
| 1233 | if (rtcp_iterator != incoming_rtcp.end()) |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1234 | return static_cast<int64_t>(rtcp_iterator->log_time_us()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1235 | return std::numeric_limits<int64_t>::max(); |
| 1236 | }; |
Bjorn Terelius | a728c91 | 2018-12-06 12:26:30 +0100 | [diff] [blame] | 1237 | int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()}); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1238 | |
| 1239 | auto NextProcessTime = [&]() { |
| 1240 | if (rtcp_iterator != incoming_rtcp.end() || |
| 1241 | rtp_iterator != outgoing_rtp.end()) { |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1242 | return next_process_time_us_; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1243 | } |
| 1244 | return std::numeric_limits<int64_t>::max(); |
| 1245 | }; |
| 1246 | |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1247 | RateStatistics acked_bitrate(750, 8000); |
| 1248 | test::ExplicitKeyValueConfig throughput_config( |
| 1249 | "WebRTC-Bwe-RobustThroughputEstimatorSettings/" |
| 1250 | "enabled:true,reduce_bias:true,assume_shared_link:false,initial_packets:" |
| 1251 | "10,min_packets:25,window_duration:750ms,unacked_weight:0.5/"); |
| 1252 | std::unique_ptr<AcknowledgedBitrateEstimatorInterface> |
| 1253 | robust_throughput_estimator( |
| 1254 | AcknowledgedBitrateEstimatorInterface::Create(&throughput_config)); |
| 1255 | FieldTrialBasedConfig field_trial_config; |
Björn Terelius | 251b0dc | 2019-11-11 21:00:18 +0100 | [diff] [blame] | 1256 | std::unique_ptr<AcknowledgedBitrateEstimatorInterface> |
| 1257 | acknowledged_bitrate_estimator( |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1258 | AcknowledgedBitrateEstimatorInterface::Create(&field_trial_config)); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1259 | int64_t time_us = |
| 1260 | std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()}); |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1261 | int64_t last_update_us = 0; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1262 | while (time_us != std::numeric_limits<int64_t>::max()) { |
| 1263 | clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds()); |
Bjorn Terelius | c60a777 | 2018-12-05 21:15:30 +0100 | [diff] [blame] | 1264 | if (clock.TimeInMicroseconds() >= NextRtpTime()) { |
| 1265 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime()); |
| 1266 | const RtpPacketType& rtp_packet = *rtp_iterator->second; |
| 1267 | if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) { |
Erik Språng | 30a276b | 2019-04-23 12:00:11 +0200 | [diff] [blame] | 1268 | RtpPacketSendInfo packet_info; |
| 1269 | packet_info.ssrc = rtp_packet.rtp.header.ssrc; |
Bjorn Terelius | f2e9cab | 2019-05-27 16:44:09 +0200 | [diff] [blame] | 1270 | packet_info.transport_sequence_number = |
Erik Språng | 30a276b | 2019-04-23 12:00:11 +0200 | [diff] [blame] | 1271 | rtp_packet.rtp.header.extension.transportSequenceNumber; |
| 1272 | packet_info.rtp_sequence_number = rtp_packet.rtp.header.sequenceNumber; |
Erik Språng | 30a276b | 2019-04-23 12:00:11 +0200 | [diff] [blame] | 1273 | packet_info.length = rtp_packet.rtp.total_length; |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1274 | if (IsRtxSsrc(parsed_log_, PacketDirection::kOutgoingPacket, |
| 1275 | rtp_packet.rtp.header.ssrc)) { |
| 1276 | // Don't set the optional media type as we don't know if it is |
| 1277 | // a retransmission, FEC or padding. |
| 1278 | } else if (IsVideoSsrc(parsed_log_, PacketDirection::kOutgoingPacket, |
| 1279 | rtp_packet.rtp.header.ssrc)) { |
| 1280 | packet_info.packet_type = RtpPacketMediaType::kVideo; |
| 1281 | } else if (IsAudioSsrc(parsed_log_, PacketDirection::kOutgoingPacket, |
| 1282 | rtp_packet.rtp.header.ssrc)) { |
| 1283 | packet_info.packet_type = RtpPacketMediaType::kAudio; |
| 1284 | } |
Bjorn Terelius | c60a777 | 2018-12-05 21:15:30 +0100 | [diff] [blame] | 1285 | transport_feedback.AddPacket( |
Erik Språng | 30a276b | 2019-04-23 12:00:11 +0200 | [diff] [blame] | 1286 | packet_info, |
| 1287 | 0u, // Per packet overhead bytes. |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1288 | Timestamp::Micros(rtp_packet.rtp.log_time_us())); |
Bjorn Terelius | c60a777 | 2018-12-05 21:15:30 +0100 | [diff] [blame] | 1289 | } |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1290 | rtc::SentPacket sent_packet; |
| 1291 | sent_packet.send_time_ms = rtp_packet.rtp.log_time_ms(); |
| 1292 | sent_packet.info.included_in_allocation = true; |
| 1293 | sent_packet.info.packet_size_bytes = rtp_packet.rtp.total_length; |
| 1294 | if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) { |
| 1295 | sent_packet.packet_id = |
| 1296 | rtp_packet.rtp.header.extension.transportSequenceNumber; |
| 1297 | sent_packet.info.included_in_feedback = true; |
| 1298 | } |
| 1299 | auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet); |
| 1300 | if (sent_msg) |
| 1301 | observer.Update(goog_cc->OnSentPacket(*sent_msg)); |
Bjorn Terelius | c60a777 | 2018-12-05 21:15:30 +0100 | [diff] [blame] | 1302 | ++rtp_iterator; |
| 1303 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1304 | if (clock.TimeInMicroseconds() >= NextRtcpTime()) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1305 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime()); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1306 | |
| 1307 | auto feedback_msg = transport_feedback.ProcessTransportFeedback( |
Sebastian Jansson | 05acd2b | 2019-01-21 13:07:47 +0100 | [diff] [blame] | 1308 | rtcp_iterator->transport_feedback, |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1309 | Timestamp::Millis(clock.TimeInMilliseconds())); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1310 | absl::optional<uint32_t> bitrate_bps; |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1311 | if (feedback_msg) { |
| 1312 | observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg)); |
Sebastian Jansson | 88290ae | 2019-06-20 12:26:31 +0200 | [diff] [blame] | 1313 | std::vector<PacketResult> feedback = |
| 1314 | feedback_msg->SortedByReceiveTime(); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1315 | if (!feedback.empty()) { |
Björn Terelius | 251b0dc | 2019-11-11 21:00:18 +0100 | [diff] [blame] | 1316 | acknowledged_bitrate_estimator->IncomingPacketFeedbackVector( |
| 1317 | feedback); |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1318 | robust_throughput_estimator->IncomingPacketFeedbackVector(feedback); |
| 1319 | for (const PacketResult& packet : feedback) { |
Sebastian Jansson | 88290ae | 2019-06-20 12:26:31 +0200 | [diff] [blame] | 1320 | acked_bitrate.Update(packet.sent_packet.size.bytes(), |
| 1321 | packet.receive_time.ms()); |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1322 | } |
Sebastian Jansson | 88290ae | 2019-06-20 12:26:31 +0200 | [diff] [blame] | 1323 | bitrate_bps = acked_bitrate.Rate(feedback.back().receive_time.ms()); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1324 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1325 | } |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1326 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1327 | float x = config_.GetCallTimeSec(clock.TimeInMicroseconds()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1328 | float y = bitrate_bps.value_or(0) / 1000; |
| 1329 | acked_time_series.points.emplace_back(x, y); |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1330 | y = robust_throughput_estimator->bitrate() |
| 1331 | .value_or(DataRate::Zero()) |
| 1332 | .kbps(); |
| 1333 | robust_time_series.points.emplace_back(x, y); |
Björn Terelius | 251b0dc | 2019-11-11 21:00:18 +0100 | [diff] [blame] | 1334 | y = acknowledged_bitrate_estimator->bitrate() |
Sebastian Jansson | 88290ae | 2019-06-20 12:26:31 +0200 | [diff] [blame] | 1335 | .value_or(DataRate::Zero()) |
| 1336 | .kbps(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1337 | acked_estimate_time_series.points.emplace_back(x, y); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1338 | ++rtcp_iterator; |
| 1339 | } |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1340 | if (clock.TimeInMicroseconds() >= NextProcessTime()) { |
| 1341 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime()); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1342 | ProcessInterval msg; |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1343 | msg.at_time = Timestamp::Micros(clock.TimeInMicroseconds()); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1344 | observer.Update(goog_cc->OnProcessInterval(msg)); |
| 1345 | next_process_time_us_ += process_interval.us(); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1346 | } |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1347 | if (observer.GetAndResetBitrateUpdated() || |
| 1348 | time_us - last_update_us >= 1e6) { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1349 | uint32_t y = observer.last_bitrate_bps() / 1000; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1350 | float x = config_.GetCallTimeSec(clock.TimeInMicroseconds()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1351 | time_series.points.emplace_back(x, y); |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1352 | last_update_us = time_us; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1353 | } |
| 1354 | time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()}); |
| 1355 | } |
| 1356 | // Add the data set to the plot. |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1357 | plot->AppendTimeSeries(std::move(time_series)); |
Björn Terelius | ae1892d | 2020-06-17 11:55:55 +0200 | [diff] [blame] | 1358 | plot->AppendTimeSeries(std::move(robust_time_series)); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1359 | plot->AppendTimeSeries(std::move(acked_time_series)); |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 1360 | plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series)); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1361 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1362 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1363 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1364 | plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1365 | plot->SetTitle("Simulated send-side BWE behavior"); |
| 1366 | } |
| 1367 | |
| 1368 | void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1369 | using RtpPacketType = LoggedRtpPacketIncoming; |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1370 | class RembInterceptingPacketRouter : public PacketRouter { |
| 1371 | public: |
| 1372 | void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 1373 | uint32_t bitrate_bps) override { |
| 1374 | last_bitrate_bps_ = bitrate_bps; |
| 1375 | bitrate_updated_ = true; |
| 1376 | PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps); |
| 1377 | } |
| 1378 | uint32_t last_bitrate_bps() const { return last_bitrate_bps_; } |
| 1379 | bool GetAndResetBitrateUpdated() { |
| 1380 | bool bitrate_updated = bitrate_updated_; |
| 1381 | bitrate_updated_ = false; |
| 1382 | return bitrate_updated; |
| 1383 | } |
| 1384 | |
| 1385 | private: |
Bjorn Terelius | 571e130 | 2020-06-09 10:29:09 +0200 | [diff] [blame] | 1386 | // We don't know the start bitrate, but assume that it is the default 300 |
| 1387 | // kbps. |
| 1388 | uint32_t last_bitrate_bps_ = 300000; |
| 1389 | bool bitrate_updated_ = false; |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1390 | }; |
| 1391 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1392 | std::multimap<int64_t, const RtpPacketType*> incoming_rtp; |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1393 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1394 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1395 | if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1396 | for (const auto& rtp_packet : stream.incoming_packets) |
| 1397 | incoming_rtp.insert( |
| 1398 | std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet)); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | SimulatedClock clock(0); |
| 1403 | RembInterceptingPacketRouter packet_router; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1404 | // TODO(terelius): The PacketRouter is used as the RemoteBitrateObserver. |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1405 | // Is this intentional? |
| 1406 | ReceiveSideCongestionController rscc(&clock, &packet_router); |
| 1407 | // TODO(holmer): Log the call config and use that here instead. |
| 1408 | // static const uint32_t kDefaultStartBitrateBps = 300000; |
| 1409 | // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1); |
| 1410 | |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1411 | TimeSeries time_series("Receive side estimate", LineStyle::kLine, |
| 1412 | PointStyle::kHighlight); |
| 1413 | TimeSeries acked_time_series("Received bitrate", LineStyle::kLine); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1414 | |
| 1415 | RateStatistics acked_bitrate(250, 8000); |
| 1416 | int64_t last_update_us = 0; |
| 1417 | for (const auto& kv : incoming_rtp) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1418 | const RtpPacketType& packet = *kv.second; |
| 1419 | int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000; |
| 1420 | size_t payload = packet.rtp.total_length; /*Should subtract header?*/ |
| 1421 | clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() - |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1422 | clock.TimeInMicroseconds()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1423 | rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1424 | acked_bitrate.Update(payload, arrival_time_ms); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1425 | absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1426 | if (bitrate_bps) { |
| 1427 | uint32_t y = *bitrate_bps / 1000; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1428 | float x = config_.GetCallTimeSec(clock.TimeInMicroseconds()); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1429 | acked_time_series.points.emplace_back(x, y); |
| 1430 | } |
| 1431 | if (packet_router.GetAndResetBitrateUpdated() || |
| 1432 | clock.TimeInMicroseconds() - last_update_us >= 1e6) { |
| 1433 | uint32_t y = packet_router.last_bitrate_bps() / 1000; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1434 | float x = config_.GetCallTimeSec(clock.TimeInMicroseconds()); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1435 | time_series.points.emplace_back(x, y); |
| 1436 | last_update_us = clock.TimeInMicroseconds(); |
| 1437 | } |
| 1438 | } |
| 1439 | // Add the data set to the plot. |
| 1440 | plot->AppendTimeSeries(std::move(time_series)); |
| 1441 | plot->AppendTimeSeries(std::move(acked_time_series)); |
| 1442 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1443 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1444 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1445 | plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 1446 | plot->SetTitle("Simulated receive-side BWE behavior"); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1447 | } |
| 1448 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 1449 | void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) { |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1450 | TimeSeries time_series("Network delay", LineStyle::kLine, |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1451 | PointStyle::kHighlight); |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1452 | int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max(); |
| 1453 | int64_t min_rtt_ms = std::numeric_limits<int64_t>::max(); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1454 | |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1455 | int64_t prev_y = 0; |
Björn Terelius | c69c1bb | 2019-10-11 15:06:58 +0200 | [diff] [blame] | 1456 | 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) { |
philipel | 3574d05 | 2019-11-18 14:38:13 +0100 | [diff] [blame] | 1460 | 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 Terelius | c69c1bb | 2019-10-11 15:06:58 +0200 | [diff] [blame] | 1463 | }); |
| 1464 | for (const auto& packet : matched_rtp_rtcp) { |
Sebastian Jansson | 74f96ec | 2019-10-29 12:57:54 +0100 | [diff] [blame] | 1465 | if (packet.arrival_time_ms == MatchedSendArrivalTimes::kNotReceived) |
Christoffer Rodbro | 89f64d3 | 2018-09-27 14:29:35 +0200 | [diff] [blame] | 1466 | continue; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1467 | float x = config_.GetCallTimeSec(1000 * packet.feedback_arrival_time_ms); |
Christoffer Rodbro | 89f64d3 | 2018-09-27 14:29:35 +0200 | [diff] [blame] | 1468 | int64_t y = packet.arrival_time_ms - packet.send_time_ms; |
| 1469 | prev_y = y; |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1470 | int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms; |
| 1471 | min_rtt_ms = std::min(rtt_ms, min_rtt_ms); |
| 1472 | min_send_receive_diff_ms = std::min(y, min_send_receive_diff_ms); |
Christoffer Rodbro | 89f64d3 | 2018-09-27 14:29:35 +0200 | [diff] [blame] | 1473 | time_series.points.emplace_back(x, y); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1474 | } |
Christoffer Rodbro | 89f64d3 | 2018-09-27 14:29:35 +0200 | [diff] [blame] | 1475 | |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1476 | // We assume that the base network delay (w/o queues) is equal to half |
| 1477 | // the minimum RTT. Therefore rescale the delays by subtracting the minimum |
Mirko Bonadei | 604e75c | 2019-07-25 11:55:47 +0200 | [diff] [blame] | 1478 | // observed 1-ways delay and add half the minimum RTT. |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1479 | const int64_t estimated_clock_offset_ms = |
| 1480 | min_send_receive_diff_ms - min_rtt_ms / 2; |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1481 | for (TimeSeriesPoint& point : time_series.points) |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1482 | point.y -= estimated_clock_offset_ms; |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1483 | |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1484 | // Add the data set to the plot. |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1485 | plot->AppendTimeSeriesIfNotEmpty(std::move(time_series)); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1486 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1487 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1488 | "Time (s)", kLeftMargin, kRightMargin); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1489 | plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin); |
Konrad Hofbauer | 5be3bbd | 2019-01-21 12:31:07 +0100 | [diff] [blame] | 1490 | plot->SetTitle("Outgoing network delay (based on per-packet feedback)"); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1491 | } |
stefan | 0838327 | 2016-12-20 08:51:52 -0800 | [diff] [blame] | 1492 | |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1493 | void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1494 | for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) { |
| 1495 | const std::vector<LoggedRtpPacketOutgoing>& packets = |
| 1496 | stream.outgoing_packets; |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1497 | |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1498 | if (IsRtxSsrc(parsed_log_, kOutgoingPacket, stream.ssrc)) { |
Konrad Hofbauer | bfb735b | 2019-04-16 11:12:11 +0200 | [diff] [blame] | 1499 | continue; |
| 1500 | } |
| 1501 | |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1502 | if (packets.size() < 2) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1503 | RTC_LOG(LS_WARNING) |
| 1504 | << "Can't estimate a the RTP clock frequency or the " |
| 1505 | "pacer delay with less than 2 packets in the stream"; |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1506 | continue; |
| 1507 | } |
Björn Terelius | 0d1b28c | 2020-05-27 20:25:06 +0200 | [diff] [blame] | 1508 | int64_t segment_end_us = parsed_log_.first_log_segment().stop_time_us(); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1509 | absl::optional<uint32_t> estimated_frequency = |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1510 | EstimateRtpClockFrequency(packets, segment_end_us); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1511 | if (!estimated_frequency) |
| 1512 | continue; |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1513 | if (IsVideoSsrc(parsed_log_, kOutgoingPacket, stream.ssrc) && |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1514 | *estimated_frequency != 90000) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1515 | RTC_LOG(LS_WARNING) |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1516 | << "Video stream should use a 90 kHz clock but appears to use " |
| 1517 | << *estimated_frequency / 1000 << ". Discarding."; |
| 1518 | continue; |
| 1519 | } |
| 1520 | |
| 1521 | TimeSeries pacer_delay_series( |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1522 | GetStreamName(parsed_log_, kOutgoingPacket, stream.ssrc) + "(" + |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1523 | std::to_string(*estimated_frequency / 1000) + " kHz)", |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1524 | LineStyle::kLine, PointStyle::kHighlight); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1525 | SeqNumUnwrapper<uint32_t> timestamp_unwrapper; |
| 1526 | uint64_t first_capture_timestamp = |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1527 | timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp); |
| 1528 | uint64_t first_send_timestamp = packets.front().rtp.log_time_us(); |
| 1529 | for (const auto& packet : packets) { |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1530 | double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1531 | packet.rtp.header.timestamp)) - |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1532 | first_capture_timestamp) / |
| 1533 | *estimated_frequency * 1000; |
| 1534 | double send_time_ms = |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1535 | static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) / |
| 1536 | 1000; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1537 | float x = config_.GetCallTimeSec(packet.rtp.log_time_us()); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1538 | float y = send_time_ms - capture_time_ms; |
| 1539 | pacer_delay_series.points.emplace_back(x, y); |
| 1540 | } |
| 1541 | plot->AppendTimeSeries(std::move(pacer_delay_series)); |
| 1542 | } |
| 1543 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1544 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1545 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1546 | plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin); |
| 1547 | plot->SetTitle( |
| 1548 | "Delay from capture to send time. (First packet normalized to 0.)"); |
| 1549 | } |
| 1550 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1551 | void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction, |
| 1552 | Plot* plot) { |
| 1553 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 1554 | TimeSeries rtp_timestamps( |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1555 | GetStreamName(parsed_log_, direction, stream.ssrc) + " capture-time", |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1556 | LineStyle::kLine, PointStyle::kHighlight); |
| 1557 | for (const auto& packet : stream.packet_view) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1558 | float x = config_.GetCallTimeSec(packet.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1559 | float y = packet.header.timestamp; |
| 1560 | rtp_timestamps.points.emplace_back(x, y); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1561 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1562 | plot->AppendTimeSeries(std::move(rtp_timestamps)); |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1563 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1564 | TimeSeries rtcp_timestamps( |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1565 | GetStreamName(parsed_log_, direction, stream.ssrc) + |
| 1566 | " rtcp capture-time", |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1567 | LineStyle::kLine, PointStyle::kHighlight); |
| 1568 | // TODO(terelius): Why only sender reports? |
| 1569 | const auto& sender_reports = parsed_log_.sender_reports(direction); |
| 1570 | for (const auto& rtcp : sender_reports) { |
| 1571 | if (rtcp.sr.sender_ssrc() != stream.ssrc) |
| 1572 | continue; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1573 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1574 | float y = rtcp.sr.rtp_timestamp(); |
| 1575 | rtcp_timestamps.points.emplace_back(x, y); |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1576 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1577 | plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps)); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1578 | } |
| 1579 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1580 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1581 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1582 | plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin); |
| 1583 | plot->SetTitle(GetDirectionAsString(direction) + " timestamps"); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1584 | } |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1585 | |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1586 | void EventLogAnalyzer::CreateSenderAndReceiverReportPlot( |
| 1587 | PacketDirection direction, |
| 1588 | rtc::FunctionView<float(const rtcp::ReportBlock&)> fy, |
| 1589 | std::string title, |
| 1590 | std::string yaxis_label, |
| 1591 | Plot* plot) { |
| 1592 | std::map<uint32_t, TimeSeries> sr_reports_by_ssrc; |
| 1593 | const auto& sender_reports = parsed_log_.sender_reports(direction); |
| 1594 | for (const auto& rtcp : sender_reports) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1595 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1596 | uint32_t ssrc = rtcp.sr.sender_ssrc(); |
| 1597 | for (const auto& block : rtcp.sr.report_blocks()) { |
| 1598 | float y = fy(block); |
| 1599 | auto sr_report_it = sr_reports_by_ssrc.find(ssrc); |
| 1600 | bool inserted; |
| 1601 | if (sr_report_it == sr_reports_by_ssrc.end()) { |
| 1602 | std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace( |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1603 | ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) + |
| 1604 | " Sender Reports", |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1605 | LineStyle::kLine, PointStyle::kHighlight)); |
| 1606 | } |
| 1607 | sr_report_it->second.points.emplace_back(x, y); |
| 1608 | } |
| 1609 | } |
| 1610 | for (auto& kv : sr_reports_by_ssrc) { |
| 1611 | plot->AppendTimeSeries(std::move(kv.second)); |
| 1612 | } |
| 1613 | |
| 1614 | std::map<uint32_t, TimeSeries> rr_reports_by_ssrc; |
| 1615 | const auto& receiver_reports = parsed_log_.receiver_reports(direction); |
| 1616 | for (const auto& rtcp : receiver_reports) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1617 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1618 | uint32_t ssrc = rtcp.rr.sender_ssrc(); |
| 1619 | for (const auto& block : rtcp.rr.report_blocks()) { |
| 1620 | float y = fy(block); |
| 1621 | auto rr_report_it = rr_reports_by_ssrc.find(ssrc); |
| 1622 | bool inserted; |
| 1623 | if (rr_report_it == rr_reports_by_ssrc.end()) { |
| 1624 | std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace( |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1625 | ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) + |
| 1626 | " Receiver Reports", |
| 1627 | LineStyle::kLine, PointStyle::kHighlight)); |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1628 | } |
| 1629 | rr_report_it->second.points.emplace_back(x, y); |
| 1630 | } |
| 1631 | } |
| 1632 | for (auto& kv : rr_reports_by_ssrc) { |
| 1633 | plot->AppendTimeSeries(std::move(kv.second)); |
| 1634 | } |
| 1635 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1636 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1637 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1638 | plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin); |
| 1639 | plot->SetTitle(title); |
| 1640 | } |
| 1641 | |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1642 | void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) { |
| 1643 | std::map<uint32_t, TimeSeries> configs_by_cp_id; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1644 | for (const auto& config : parsed_log_.ice_candidate_pair_configs()) { |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1645 | if (configs_by_cp_id.find(config.candidate_pair_id) == |
| 1646 | configs_by_cp_id.end()) { |
| 1647 | const std::string candidate_pair_desc = |
| 1648 | GetCandidatePairLogDescriptionAsString(config); |
Qingsi Wang | 93a8439 | 2018-01-30 17:13:09 -0800 | [diff] [blame] | 1649 | configs_by_cp_id[config.candidate_pair_id] = |
| 1650 | TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" + |
| 1651 | candidate_pair_desc, |
| 1652 | LineStyle::kNone, PointStyle::kHighlight); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1653 | candidate_pair_desc_by_id_[config.candidate_pair_id] = |
| 1654 | candidate_pair_desc; |
| 1655 | } |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1656 | float x = config_.GetCallTimeSec(config.log_time_us()); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1657 | float y = static_cast<float>(config.type); |
| 1658 | configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y); |
| 1659 | } |
| 1660 | |
| 1661 | // TODO(qingsi): There can be a large number of candidate pairs generated by |
| 1662 | // certain calls and the frontend cannot render the chart in this case due to |
| 1663 | // the failure of generating a palette with the same number of colors. |
| 1664 | for (auto& kv : configs_by_cp_id) { |
| 1665 | plot->AppendTimeSeries(std::move(kv.second)); |
| 1666 | } |
| 1667 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1668 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1669 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 1670 | plot->SetSuggestedYAxis(0, 3, "Config Type", kBottomMargin, kTopMargin); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1671 | plot->SetTitle("[IceEventLog] ICE candidate pair configs"); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 1672 | plot->SetYAxisTickLabels( |
| 1673 | {{static_cast<float>(IceCandidatePairConfigType::kAdded), "ADDED"}, |
| 1674 | {static_cast<float>(IceCandidatePairConfigType::kUpdated), "UPDATED"}, |
| 1675 | {static_cast<float>(IceCandidatePairConfigType::kDestroyed), |
| 1676 | "DESTROYED"}, |
| 1677 | {static_cast<float>(IceCandidatePairConfigType::kSelected), |
| 1678 | "SELECTED"}}); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId( |
| 1682 | uint32_t candidate_pair_id) { |
| 1683 | if (candidate_pair_desc_by_id_.find(candidate_pair_id) != |
| 1684 | candidate_pair_desc_by_id_.end()) { |
| 1685 | return candidate_pair_desc_by_id_[candidate_pair_id]; |
| 1686 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1687 | for (const auto& config : parsed_log_.ice_candidate_pair_configs()) { |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1688 | // TODO(qingsi): Add the handling of the "Updated" config event after the |
| 1689 | // visualization of property change for candidate pairs is introduced. |
| 1690 | if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) == |
| 1691 | candidate_pair_desc_by_id_.end()) { |
| 1692 | const std::string candidate_pair_desc = |
| 1693 | GetCandidatePairLogDescriptionAsString(config); |
| 1694 | candidate_pair_desc_by_id_[config.candidate_pair_id] = |
| 1695 | candidate_pair_desc; |
| 1696 | } |
| 1697 | } |
| 1698 | return candidate_pair_desc_by_id_[candidate_pair_id]; |
| 1699 | } |
| 1700 | |
| 1701 | void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) { |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 1702 | constexpr int kEventTypeOffset = |
| 1703 | static_cast<int>(IceCandidatePairConfigType::kNumValues); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1704 | std::map<uint32_t, TimeSeries> checks_by_cp_id; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1705 | for (const auto& event : parsed_log_.ice_candidate_pair_events()) { |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1706 | if (checks_by_cp_id.find(event.candidate_pair_id) == |
| 1707 | checks_by_cp_id.end()) { |
| 1708 | checks_by_cp_id[event.candidate_pair_id] = TimeSeries( |
Qingsi Wang | 93a8439 | 2018-01-30 17:13:09 -0800 | [diff] [blame] | 1709 | "[" + std::to_string(event.candidate_pair_id) + "]" + |
| 1710 | GetCandidatePairLogDescriptionFromId(event.candidate_pair_id), |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1711 | LineStyle::kNone, PointStyle::kHighlight); |
| 1712 | } |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1713 | float x = config_.GetCallTimeSec(event.log_time_us()); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 1714 | float y = static_cast<float>(event.type) + kEventTypeOffset; |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1715 | checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y); |
| 1716 | } |
| 1717 | |
| 1718 | // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph. |
| 1719 | for (auto& kv : checks_by_cp_id) { |
| 1720 | plot->AppendTimeSeries(std::move(kv.second)); |
| 1721 | } |
| 1722 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1723 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1724 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 1725 | plot->SetSuggestedYAxis(0, 4, "Connectivity State", kBottomMargin, |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1726 | kTopMargin); |
| 1727 | plot->SetTitle("[IceEventLog] ICE connectivity checks"); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 1728 | |
| 1729 | plot->SetYAxisTickLabels( |
| 1730 | {{static_cast<float>(IceCandidatePairEventType::kCheckSent) + |
| 1731 | kEventTypeOffset, |
| 1732 | "CHECK SENT"}, |
| 1733 | {static_cast<float>(IceCandidatePairEventType::kCheckReceived) + |
| 1734 | kEventTypeOffset, |
| 1735 | "CHECK RECEIVED"}, |
| 1736 | {static_cast<float>(IceCandidatePairEventType::kCheckResponseSent) + |
| 1737 | kEventTypeOffset, |
| 1738 | "RESPONSE SENT"}, |
| 1739 | {static_cast<float>(IceCandidatePairEventType::kCheckResponseReceived) + |
| 1740 | kEventTypeOffset, |
| 1741 | "RESPONSE RECEIVED"}}); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 1742 | } |
| 1743 | |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 1744 | void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) { |
| 1745 | TimeSeries states("DTLS Transport State", LineStyle::kNone, |
| 1746 | PointStyle::kHighlight); |
| 1747 | for (const auto& event : parsed_log_.dtls_transport_states()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1748 | float x = config_.GetCallTimeSec(event.log_time_us()); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 1749 | float y = static_cast<float>(event.dtls_transport_state); |
| 1750 | states.points.emplace_back(x, y); |
| 1751 | } |
| 1752 | plot->AppendTimeSeries(std::move(states)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1753 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1754 | "Time (s)", kLeftMargin, kRightMargin); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 1755 | plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues), |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 1756 | "Transport State", kBottomMargin, kTopMargin); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 1757 | plot->SetTitle("DTLS Transport State"); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 1758 | plot->SetYAxisTickLabels( |
| 1759 | {{static_cast<float>(DtlsTransportState::kNew), "NEW"}, |
| 1760 | {static_cast<float>(DtlsTransportState::kConnecting), "CONNECTING"}, |
| 1761 | {static_cast<float>(DtlsTransportState::kConnected), "CONNECTED"}, |
| 1762 | {static_cast<float>(DtlsTransportState::kClosed), "CLOSED"}, |
| 1763 | {static_cast<float>(DtlsTransportState::kFailed), "FAILED"}}); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) { |
| 1767 | TimeSeries writable("DTLS Writable", LineStyle::kNone, |
| 1768 | PointStyle::kHighlight); |
| 1769 | for (const auto& event : parsed_log_.dtls_writable_states()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1770 | float x = config_.GetCallTimeSec(event.log_time_us()); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 1771 | float y = static_cast<float>(event.writable); |
| 1772 | writable.points.emplace_back(x, y); |
| 1773 | } |
| 1774 | plot->AppendTimeSeries(std::move(writable)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1775 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1776 | "Time (s)", kLeftMargin, kRightMargin); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 1777 | plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin); |
| 1778 | plot->SetTitle("DTLS Writable State"); |
| 1779 | } |
| 1780 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1781 | } // namespace webrtc |