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" |
Sebastian Jansson | 95edb03 | 2019-01-17 16:24:12 +0100 | [diff] [blame] | 24 | #include "api/transport/field_trial_based_config.h" |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 25 | #include "api/transport/goog_cc_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "call/audio_receive_stream.h" |
| 27 | #include "call/audio_send_stream.h" |
| 28 | #include "call/call.h" |
| 29 | #include "call/video_receive_stream.h" |
| 30 | #include "call/video_send_stream.h" |
Elad Alon | 99a81b6 | 2017-09-21 10:25:29 +0200 | [diff] [blame] | 31 | #include "logging/rtc_event_log/rtc_stream_config.h" |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 32 | #include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "modules/audio_coding/neteq/tools/audio_sink.h" |
| 34 | #include "modules/audio_coding/neteq/tools/fake_decode_from_file.h" |
| 35 | #include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h" |
| 36 | #include "modules/audio_coding/neteq/tools/neteq_replacement_input.h" |
| 37 | #include "modules/audio_coding/neteq/tools/neteq_test.h" |
| 38 | #include "modules/audio_coding/neteq/tools/resample_input_audio_file.h" |
Sebastian Jansson | 172fd85 | 2018-05-24 14:17:06 +0200 | [diff] [blame] | 39 | #include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h" |
| 40 | #include "modules/congestion_controller/goog_cc/bitrate_estimator.h" |
Sebastian Jansson | 04b18cb | 2018-07-02 09:25:25 +0200 | [diff] [blame] | 41 | #include "modules/congestion_controller/goog_cc/delay_based_bwe.h" |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 42 | #include "modules/congestion_controller/include/receive_side_congestion_controller.h" |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 43 | #include "modules/congestion_controller/rtp/transport_feedback_adapter.h" |
Erik Språng | e794243 | 2019-06-12 13:30:02 +0200 | [diff] [blame] | 44 | #include "modules/pacing/paced_sender.h" |
Niels Möller | fd6c091 | 2017-10-31 10:19:10 +0100 | [diff] [blame] | 45 | #include "modules/pacing/packet_router.h" |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 46 | #include "modules/remote_bitrate_estimator/include/bwe_defines.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 47 | #include "modules/rtp_rtcp/include/rtp_rtcp.h" |
| 48 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 49 | #include "modules/rtp_rtcp/source/rtcp_packet.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 50 | #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 51 | #include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 52 | #include "modules/rtp_rtcp/source/rtcp_packet/remb.h" |
| 53 | #include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
| 54 | #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 55 | #include "modules/rtp_rtcp/source/rtp_header_extensions.h" |
| 56 | #include "modules/rtp_rtcp/source/rtp_utility.h" |
| 57 | #include "rtc_base/checks.h" |
| 58 | #include "rtc_base/format_macros.h" |
| 59 | #include "rtc_base/logging.h" |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 60 | #include "rtc_base/numerics/sequence_number_util.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 61 | #include "rtc_base/rate_statistics.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 62 | #include "rtc_base/strings/string_builder.h" |
Mirko Bonadei | 575998c | 2019-07-25 13:57:41 +0200 | [diff] [blame] | 63 | #include "rtc_tools/rtc_event_log_visualizer/log_simulation.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 64 | |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 65 | #ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE |
| 66 | #define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0 |
| 67 | #endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE |
| 68 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 69 | namespace webrtc { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 70 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 71 | namespace { |
| 72 | |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 73 | const int kNumMicrosecsPerSec = 1000000; |
| 74 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 75 | std::string SsrcToString(uint32_t ssrc) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 76 | rtc::StringBuilder ss; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 77 | ss << "SSRC " << ssrc; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 78 | return ss.Release(); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // Checks whether an SSRC is contained in the list of desired SSRCs. |
| 82 | // Note that an empty SSRC list matches every SSRC. |
| 83 | bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) { |
Mirko Bonadei | 1f17315 | 2019-07-25 15:28:14 +0200 | [diff] [blame] | 84 | if (desired_ssrc.empty()) |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 85 | return true; |
| 86 | return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) != |
| 87 | desired_ssrc.end(); |
| 88 | } |
| 89 | |
| 90 | double AbsSendTimeToMicroseconds(int64_t abs_send_time) { |
| 91 | // The timestamp is a fixed point representation with 6 bits for seconds |
| 92 | // 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] | 93 | // time in seconds and then multiply by kNumMicrosecsPerSec to convert to |
| 94 | // microseconds. |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 95 | static constexpr double kTimestampToMicroSec = |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 96 | static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 97 | return abs_send_time * kTimestampToMicroSec; |
| 98 | } |
| 99 | |
| 100 | // Computes the difference |later| - |earlier| where |later| and |earlier| |
| 101 | // are counters that wrap at |modulus|. The difference is chosen to have the |
| 102 | // least absolute value. For example if |modulus| is 8, then the difference will |
| 103 | // be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will |
| 104 | // be in [-4, 4]. |
| 105 | int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) { |
| 106 | RTC_DCHECK_LE(1, modulus); |
| 107 | RTC_DCHECK_LT(later, modulus); |
| 108 | RTC_DCHECK_LT(earlier, modulus); |
| 109 | int64_t difference = |
| 110 | static_cast<int64_t>(later) - static_cast<int64_t>(earlier); |
| 111 | int64_t max_difference = modulus / 2; |
| 112 | int64_t min_difference = max_difference - modulus + 1; |
| 113 | if (difference > max_difference) { |
| 114 | difference -= modulus; |
| 115 | } |
| 116 | if (difference < min_difference) { |
| 117 | difference += modulus; |
| 118 | } |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 119 | if (difference > max_difference / 2 || difference < min_difference / 2) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 120 | RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier |
| 121 | << " expected to be in the range (" |
| 122 | << min_difference / 2 << "," << max_difference / 2 |
| 123 | << ") but is " << difference |
| 124 | << ". Correct unwrapping is uncertain."; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 125 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 126 | return difference; |
| 127 | } |
| 128 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 129 | // This is much more reliable for outgoing streams than for incoming streams. |
| 130 | template <typename RtpPacketContainer> |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 131 | absl::optional<uint32_t> EstimateRtpClockFrequency( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 132 | const RtpPacketContainer& packets, |
| 133 | int64_t end_time_us) { |
| 134 | RTC_CHECK(packets.size() >= 2); |
| 135 | SeqNumUnwrapper<uint32_t> unwrapper; |
Philip Eliasson | 1f850a6 | 2019-03-19 12:15:00 +0000 | [diff] [blame] | 136 | int64_t first_rtp_timestamp = |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 137 | unwrapper.Unwrap(packets[0].rtp.header.timestamp); |
| 138 | int64_t first_log_timestamp = packets[0].log_time_us(); |
Philip Eliasson | 1f850a6 | 2019-03-19 12:15:00 +0000 | [diff] [blame] | 139 | int64_t last_rtp_timestamp = first_rtp_timestamp; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 140 | int64_t last_log_timestamp = first_log_timestamp; |
| 141 | for (size_t i = 1; i < packets.size(); i++) { |
| 142 | if (packets[i].log_time_us() > end_time_us) |
| 143 | break; |
| 144 | last_rtp_timestamp = unwrapper.Unwrap(packets[i].rtp.header.timestamp); |
| 145 | last_log_timestamp = packets[i].log_time_us(); |
| 146 | } |
| 147 | if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) { |
| 148 | RTC_LOG(LS_WARNING) |
| 149 | << "Failed to estimate RTP clock frequency: Stream too short. (" |
| 150 | << packets.size() << " packets, " |
| 151 | << last_log_timestamp - first_log_timestamp << " us)"; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 152 | return absl::nullopt; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 153 | } |
| 154 | double duration = |
| 155 | static_cast<double>(last_log_timestamp - first_log_timestamp) / |
| 156 | kNumMicrosecsPerSec; |
| 157 | double estimated_frequency = |
| 158 | (last_rtp_timestamp - first_rtp_timestamp) / duration; |
| 159 | for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) { |
philipel | 3fa4938 | 2019-08-20 15:59:57 +0200 | [diff] [blame] | 160 | if (std::fabs(estimated_frequency - f) < 0.15 * f) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 161 | return f; |
| 162 | } |
| 163 | } |
| 164 | RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate " |
| 165 | << estimated_frequency |
philipel | 3fa4938 | 2019-08-20 15:59:57 +0200 | [diff] [blame] | 166 | << " not close to any stardard RTP frequency."; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 167 | return absl::nullopt; |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 168 | } |
| 169 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 170 | constexpr float kLeftMargin = 0.01f; |
| 171 | constexpr float kRightMargin = 0.02f; |
| 172 | constexpr float kBottomMargin = 0.02f; |
| 173 | constexpr float kTopMargin = 0.05f; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 174 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 175 | absl::optional<double> NetworkDelayDiff_AbsSendTime( |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 176 | const LoggedRtpPacketIncoming& old_packet, |
| 177 | const LoggedRtpPacketIncoming& new_packet) { |
| 178 | if (old_packet.rtp.header.extension.hasAbsoluteSendTime && |
| 179 | new_packet.rtp.header.extension.hasAbsoluteSendTime) { |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 180 | int64_t send_time_diff = WrappingDifference( |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 181 | new_packet.rtp.header.extension.absoluteSendTime, |
| 182 | old_packet.rtp.header.extension.absoluteSendTime, 1ul << 24); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 183 | int64_t recv_time_diff = |
| 184 | new_packet.log_time_us() - old_packet.log_time_us(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 185 | double delay_change_us = |
| 186 | recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff); |
Oskar Sundbom | 3928dbc | 2017-11-16 10:53:09 +0100 | [diff] [blame] | 187 | return delay_change_us / 1000; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 188 | } else { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 189 | return absl::nullopt; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 193 | absl::optional<double> NetworkDelayDiff_CaptureTime( |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 194 | const LoggedRtpPacketIncoming& old_packet, |
| 195 | const LoggedRtpPacketIncoming& new_packet, |
| 196 | const double sample_rate) { |
| 197 | int64_t send_time_diff = |
| 198 | WrappingDifference(new_packet.rtp.header.timestamp, |
| 199 | old_packet.rtp.header.timestamp, 1ull << 32); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 200 | 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] | 201 | |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 202 | double delay_change = |
| 203 | static_cast<double>(recv_time_diff) / 1000 - |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 204 | static_cast<double>(send_time_diff) / sample_rate * 1000; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 205 | if (delay_change < -10000 || 10000 < delay_change) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 206 | RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?"; |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 207 | RTC_LOG(LS_WARNING) << "Old capture time " |
| 208 | << old_packet.rtp.header.timestamp << ", received time " |
| 209 | << old_packet.log_time_us(); |
| 210 | RTC_LOG(LS_WARNING) << "New capture time " |
| 211 | << new_packet.rtp.header.timestamp << ", received time " |
| 212 | << new_packet.log_time_us(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 213 | RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = " |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 214 | << static_cast<double>(recv_time_diff) / |
| 215 | kNumMicrosecsPerSec |
| 216 | << "s"; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 217 | RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = " |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 218 | << static_cast<double>(send_time_diff) / sample_rate |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 219 | << "s"; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 220 | } |
Oskar Sundbom | 3928dbc | 2017-11-16 10:53:09 +0100 | [diff] [blame] | 221 | return delay_change; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 224 | // For each element in data_view, use |f()| to extract a y-coordinate and |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 225 | // store the result in a TimeSeries. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 226 | template <typename DataType, typename IterableType> |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 227 | void ProcessPoints(rtc::FunctionView<float(const DataType&)> fx, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 228 | rtc::FunctionView<absl::optional<float>(const DataType&)> fy, |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 229 | const IterableType& data_view, |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 230 | TimeSeries* result) { |
| 231 | for (size_t i = 0; i < data_view.size(); i++) { |
| 232 | const DataType& elem = data_view[i]; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 233 | float x = fx(elem); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 234 | absl::optional<float> y = fy(elem); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 235 | if (y) |
| 236 | result->points.emplace_back(x, *y); |
| 237 | } |
| 238 | } |
| 239 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 240 | // For each pair of adjacent elements in |data|, use |f()| to extract a |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 241 | // y-coordinate and store the result in a TimeSeries. Note that the x-coordinate |
| 242 | // will be the time of the second element in the pair. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 243 | template <typename DataType, typename ResultType, typename IterableType> |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 244 | void ProcessPairs( |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 245 | rtc::FunctionView<float(const DataType&)> fx, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 246 | rtc::FunctionView<absl::optional<ResultType>(const DataType&, |
| 247 | const DataType&)> fy, |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 248 | const IterableType& data, |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 249 | TimeSeries* result) { |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 250 | for (size_t i = 1; i < data.size(); i++) { |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 251 | float x = fx(data[i]); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 252 | absl::optional<ResultType> y = fy(data[i - 1], data[i]); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 253 | if (y) |
| 254 | result->points.emplace_back(x, static_cast<float>(*y)); |
| 255 | } |
| 256 | } |
| 257 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 258 | // For each pair of adjacent elements in |data|, use |f()| to extract a |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 259 | // y-coordinate and store the result in a TimeSeries. Note that the x-coordinate |
| 260 | // will be the time of the second element in the pair. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 261 | template <typename DataType, typename ResultType, typename IterableType> |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 262 | void AccumulatePairs( |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 263 | rtc::FunctionView<float(const DataType&)> fx, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 264 | rtc::FunctionView<absl::optional<ResultType>(const DataType&, |
| 265 | const DataType&)> fy, |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 266 | const IterableType& data, |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 267 | TimeSeries* result) { |
| 268 | ResultType sum = 0; |
| 269 | for (size_t i = 1; i < data.size(); i++) { |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 270 | float x = fx(data[i]); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 271 | absl::optional<ResultType> y = fy(data[i - 1], data[i]); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 272 | if (y) { |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 273 | sum += *y; |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 274 | result->points.emplace_back(x, static_cast<float>(sum)); |
| 275 | } |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 279 | // Calculates a moving average of |data| and stores the result in a TimeSeries. |
| 280 | // A data point is generated every |step| microseconds from |begin_time| |
| 281 | // to |end_time|. The value of each data point is the average of the data |
Mirko Bonadei | 604e75c | 2019-07-25 11:55:47 +0200 | [diff] [blame] | 282 | // during the preceding |window_duration_us| microseconds. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 283 | template <typename DataType, typename ResultType, typename IterableType> |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 284 | void MovingAverage( |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 285 | rtc::FunctionView<absl::optional<ResultType>(const DataType&)> fy, |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 286 | const IterableType& data_view, |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 287 | AnalyzerConfig config, |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 288 | TimeSeries* result) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 289 | size_t window_index_begin = 0; |
| 290 | size_t window_index_end = 0; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 291 | ResultType sum_in_window = 0; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 292 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 293 | for (int64_t t = config.begin_time_; t < config.end_time_ + config.step_; |
| 294 | t += config.step_) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 295 | while (window_index_end < data_view.size() && |
| 296 | data_view[window_index_end].log_time_us() < t) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 297 | absl::optional<ResultType> value = fy(data_view[window_index_end]); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 298 | if (value) |
| 299 | sum_in_window += *value; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 300 | ++window_index_end; |
| 301 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 302 | while (window_index_begin < data_view.size() && |
| 303 | data_view[window_index_begin].log_time_us() < |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 304 | t - config.window_duration_) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 305 | absl::optional<ResultType> value = fy(data_view[window_index_begin]); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 306 | if (value) |
| 307 | sum_in_window -= *value; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 308 | ++window_index_begin; |
| 309 | } |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 310 | float window_duration_s = |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 311 | static_cast<float>(config.window_duration_) / kNumMicrosecsPerSec; |
| 312 | float x = config.GetCallTimeSec(t); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 313 | float y = sum_in_window / window_duration_s; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 314 | result->points.emplace_back(x, y); |
| 315 | } |
| 316 | } |
| 317 | |
Bjorn Terelius | 7c974e6 | 2019-02-15 17:20:12 +0100 | [diff] [blame] | 318 | template <typename T> |
| 319 | TimeSeries CreateRtcpTypeTimeSeries(const std::vector<T>& rtcp_list, |
| 320 | AnalyzerConfig config, |
| 321 | std::string rtcp_name, |
| 322 | int category_id) { |
| 323 | TimeSeries time_series(rtcp_name, LineStyle::kNone, PointStyle::kHighlight); |
| 324 | for (const auto& rtcp : rtcp_list) { |
| 325 | float x = config.GetCallTimeSec(rtcp.log_time_us()); |
| 326 | float y = category_id; |
| 327 | time_series.points.emplace_back(x, y); |
| 328 | } |
| 329 | return time_series; |
| 330 | } |
| 331 | |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 332 | const char kUnknownEnumValue[] = "unknown"; |
| 333 | |
| 334 | const char kIceCandidateTypeLocal[] = "local"; |
| 335 | const char kIceCandidateTypeStun[] = "stun"; |
| 336 | const char kIceCandidateTypePrflx[] = "prflx"; |
| 337 | const char kIceCandidateTypeRelay[] = "relay"; |
| 338 | |
| 339 | const char kProtocolUdp[] = "udp"; |
| 340 | const char kProtocolTcp[] = "tcp"; |
| 341 | const char kProtocolSsltcp[] = "ssltcp"; |
| 342 | const char kProtocolTls[] = "tls"; |
| 343 | |
| 344 | const char kAddressFamilyIpv4[] = "ipv4"; |
| 345 | const char kAddressFamilyIpv6[] = "ipv6"; |
| 346 | |
| 347 | const char kNetworkTypeEthernet[] = "ethernet"; |
| 348 | const char kNetworkTypeLoopback[] = "loopback"; |
| 349 | const char kNetworkTypeWifi[] = "wifi"; |
| 350 | const char kNetworkTypeVpn[] = "vpn"; |
| 351 | const char kNetworkTypeCellular[] = "cellular"; |
| 352 | |
| 353 | std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) { |
| 354 | switch (type) { |
| 355 | case webrtc::IceCandidateType::kLocal: |
| 356 | return kIceCandidateTypeLocal; |
| 357 | case webrtc::IceCandidateType::kStun: |
| 358 | return kIceCandidateTypeStun; |
| 359 | case webrtc::IceCandidateType::kPrflx: |
| 360 | return kIceCandidateTypePrflx; |
| 361 | case webrtc::IceCandidateType::kRelay: |
| 362 | return kIceCandidateTypeRelay; |
| 363 | default: |
| 364 | return kUnknownEnumValue; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) { |
| 369 | switch (protocol) { |
| 370 | case webrtc::IceCandidatePairProtocol::kUdp: |
| 371 | return kProtocolUdp; |
| 372 | case webrtc::IceCandidatePairProtocol::kTcp: |
| 373 | return kProtocolTcp; |
| 374 | case webrtc::IceCandidatePairProtocol::kSsltcp: |
| 375 | return kProtocolSsltcp; |
| 376 | case webrtc::IceCandidatePairProtocol::kTls: |
| 377 | return kProtocolTls; |
| 378 | default: |
| 379 | return kUnknownEnumValue; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | std::string GetAddressFamilyAsString( |
| 384 | webrtc::IceCandidatePairAddressFamily family) { |
| 385 | switch (family) { |
| 386 | case webrtc::IceCandidatePairAddressFamily::kIpv4: |
| 387 | return kAddressFamilyIpv4; |
| 388 | case webrtc::IceCandidatePairAddressFamily::kIpv6: |
| 389 | return kAddressFamilyIpv6; |
| 390 | default: |
| 391 | return kUnknownEnumValue; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) { |
| 396 | switch (type) { |
| 397 | case webrtc::IceCandidateNetworkType::kEthernet: |
| 398 | return kNetworkTypeEthernet; |
| 399 | case webrtc::IceCandidateNetworkType::kLoopback: |
| 400 | return kNetworkTypeLoopback; |
| 401 | case webrtc::IceCandidateNetworkType::kWifi: |
| 402 | return kNetworkTypeWifi; |
| 403 | case webrtc::IceCandidateNetworkType::kVpn: |
| 404 | return kNetworkTypeVpn; |
| 405 | case webrtc::IceCandidateNetworkType::kCellular: |
| 406 | return kNetworkTypeCellular; |
| 407 | default: |
| 408 | return kUnknownEnumValue; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | std::string GetCandidatePairLogDescriptionAsString( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 413 | const LoggedIceCandidatePairConfig& config) { |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 414 | // Example: stun:wifi->relay(tcp):cellular@udp:ipv4 |
| 415 | // represents a pair of a local server-reflexive candidate on a WiFi network |
| 416 | // and a remote relay candidate using TCP as the relay protocol on a cell |
| 417 | // network, when the candidate pair communicates over UDP using IPv4. |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 418 | rtc::StringBuilder ss; |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 419 | std::string local_candidate_type = |
| 420 | GetIceCandidateTypeAsString(config.local_candidate_type); |
| 421 | std::string remote_candidate_type = |
| 422 | GetIceCandidateTypeAsString(config.remote_candidate_type); |
| 423 | if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) { |
| 424 | local_candidate_type += |
| 425 | "(" + GetProtocolAsString(config.local_relay_protocol) + ")"; |
| 426 | } |
| 427 | ss << local_candidate_type << ":" |
| 428 | << GetNetworkTypeAsString(config.local_network_type) << ":" |
| 429 | << GetAddressFamilyAsString(config.local_address_family) << "->" |
| 430 | << remote_candidate_type << ":" |
| 431 | << GetAddressFamilyAsString(config.remote_address_family) << "@" |
| 432 | << GetProtocolAsString(config.candidate_pair_protocol); |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 433 | return ss.Release(); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 436 | std::string GetDirectionAsString(PacketDirection direction) { |
| 437 | if (direction == kIncomingPacket) { |
| 438 | return "Incoming"; |
| 439 | } else { |
| 440 | return "Outgoing"; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | std::string GetDirectionAsShortString(PacketDirection direction) { |
| 445 | if (direction == kIncomingPacket) { |
| 446 | return "In"; |
| 447 | } else { |
| 448 | return "Out"; |
| 449 | } |
| 450 | } |
| 451 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 452 | } // namespace |
| 453 | |
Sebastian Jansson | b290a6d | 2019-01-03 14:46:23 +0100 | [diff] [blame] | 454 | EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log, |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 455 | bool normalize_time) |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 456 | : parsed_log_(log) { |
| 457 | config_.window_duration_ = 250000; |
| 458 | config_.step_ = 10000; |
| 459 | config_.normalize_time_ = normalize_time; |
| 460 | config_.begin_time_ = parsed_log_.first_timestamp(); |
| 461 | config_.end_time_ = parsed_log_.last_timestamp(); |
| 462 | if (config_.end_time_ < config_.begin_time_) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 463 | RTC_LOG(LS_WARNING) << "No useful events in the log."; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 464 | config_.begin_time_ = config_.end_time_ = 0; |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 465 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 466 | |
| 467 | const auto& log_start_events = parsed_log_.start_log_events(); |
| 468 | const auto& log_end_events = parsed_log_.stop_log_events(); |
| 469 | auto start_iter = log_start_events.begin(); |
| 470 | auto end_iter = log_end_events.begin(); |
| 471 | while (start_iter != log_start_events.end()) { |
| 472 | int64_t start = start_iter->log_time_us(); |
| 473 | ++start_iter; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 474 | absl::optional<int64_t> next_start; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 475 | if (start_iter != log_start_events.end()) |
| 476 | next_start.emplace(start_iter->log_time_us()); |
| 477 | if (end_iter != log_end_events.end() && |
| 478 | end_iter->log_time_us() <= |
| 479 | next_start.value_or(std::numeric_limits<int64_t>::max())) { |
| 480 | int64_t end = end_iter->log_time_us(); |
| 481 | RTC_DCHECK_LE(start, end); |
| 482 | log_segments_.push_back(std::make_pair(start, end)); |
| 483 | ++end_iter; |
| 484 | } else { |
| 485 | // we're missing an end event. Assume that it occurred just before the |
| 486 | // next start. |
| 487 | log_segments_.push_back( |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 488 | std::make_pair(start, next_start.value_or(config_.end_time_))); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 489 | } |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 490 | } |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 491 | RTC_LOG(LS_INFO) << "Found " << log_segments_.size() |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 492 | << " (LOG_START, LOG_END) segments in log."; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 495 | class BitrateObserver : public RemoteBitrateObserver { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 496 | public: |
| 497 | BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {} |
| 498 | |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 499 | void Update(NetworkControlUpdate update) { |
| 500 | if (update.target_rate) { |
| 501 | last_bitrate_bps_ = update.target_rate->target_rate.bps(); |
| 502 | bitrate_updated_ = true; |
| 503 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 507 | uint32_t bitrate) override {} |
| 508 | |
| 509 | uint32_t last_bitrate_bps() const { return last_bitrate_bps_; } |
| 510 | bool GetAndResetBitrateUpdated() { |
| 511 | bool bitrate_updated = bitrate_updated_; |
| 512 | bitrate_updated_ = false; |
| 513 | return bitrate_updated; |
| 514 | } |
| 515 | |
| 516 | private: |
| 517 | uint32_t last_bitrate_bps_; |
| 518 | bool bitrate_updated_; |
| 519 | }; |
| 520 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 521 | void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction, |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 522 | Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 523 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 524 | // Filter on SSRC. |
| 525 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 526 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 527 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 528 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 529 | TimeSeries time_series(GetStreamName(direction, stream.ssrc), |
| 530 | LineStyle::kBar); |
| 531 | auto GetPacketSize = [](const LoggedRtpPacket& packet) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 532 | return absl::optional<float>(packet.total_length); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 533 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 534 | auto ToCallTime = [this](const LoggedRtpPacket& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 535 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 536 | }; |
| 537 | ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize, |
| 538 | stream.packet_view, &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 539 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 542 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 543 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 544 | plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin, |
| 545 | kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 546 | plot->SetTitle(GetDirectionAsString(direction) + " RTP packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Bjorn Terelius | 7c974e6 | 2019-02-15 17:20:12 +0100 | [diff] [blame] | 549 | void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction, |
| 550 | Plot* plot) { |
| 551 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries( |
| 552 | parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1)); |
| 553 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries( |
| 554 | parsed_log_.receiver_reports(direction), config_, "RR", 2)); |
| 555 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries( |
| 556 | parsed_log_.sender_reports(direction), config_, "SR", 3)); |
| 557 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries( |
| 558 | parsed_log_.extended_reports(direction), config_, "XR", 4)); |
| 559 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction), |
| 560 | config_, "NACK", 5)); |
| 561 | plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction), |
| 562 | config_, "REMB", 6)); |
| 563 | plot->AppendTimeSeries( |
| 564 | CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7)); |
| 565 | plot->AppendTimeSeries( |
| 566 | CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8)); |
| 567 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 568 | "Time (s)", kLeftMargin, kRightMargin); |
| 569 | plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin); |
| 570 | plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets"); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 571 | plot->SetYAxisTickLabels({{1, "TWCC"}, |
| 572 | {2, "RR"}, |
| 573 | {3, "SR"}, |
| 574 | {4, "XR"}, |
| 575 | {5, "NACK"}, |
| 576 | {6, "REMB"}, |
| 577 | {7, "FIR"}, |
| 578 | {8, "PLI"}}); |
Bjorn Terelius | 7c974e6 | 2019-02-15 17:20:12 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 581 | template <typename IterableType> |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 582 | void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries( |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 583 | Plot* plot, |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 584 | const IterableType& packets, |
| 585 | const std::string& label) { |
| 586 | TimeSeries time_series(label, LineStyle::kStep); |
| 587 | for (size_t i = 0; i < packets.size(); i++) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 588 | float x = config_.GetCallTimeSec(packets[i].log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 589 | time_series.points.emplace_back(x, i + 1); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 590 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 591 | plot->AppendTimeSeries(std::move(time_series)); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 594 | void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction, |
| 595 | Plot* plot) { |
| 596 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 597 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) |
| 598 | continue; |
| 599 | std::string label = |
| 600 | std::string("RTP ") + GetStreamName(direction, stream.ssrc); |
| 601 | CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label); |
| 602 | } |
| 603 | std::string label = |
| 604 | std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")"; |
| 605 | if (direction == kIncomingPacket) { |
| 606 | CreateAccumulatedPacketsTimeSeries( |
| 607 | plot, parsed_log_.incoming_rtcp_packets(), label); |
| 608 | } else { |
| 609 | CreateAccumulatedPacketsTimeSeries( |
| 610 | plot, parsed_log_.outgoing_rtcp_packets(), label); |
| 611 | } |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 612 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 613 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 614 | "Time (s)", kLeftMargin, kRightMargin); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 615 | plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 616 | plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) + |
| 617 | " RTP/RTCP packets"); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Kristoffer Erlandsson | 283c106 | 2020-03-30 13:01:37 +0200 | [diff] [blame] | 620 | void EventLogAnalyzer::CreatePacketRateGraph(PacketDirection direction, |
| 621 | Plot* plot) { |
| 622 | auto CountPackets = [](auto packet) { return 1.0; }; |
| 623 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 624 | // Filter on SSRC. |
| 625 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) { |
| 626 | continue; |
| 627 | } |
| 628 | TimeSeries time_series( |
| 629 | std::string("RTP ") + GetStreamName(direction, stream.ssrc), |
| 630 | LineStyle::kLine); |
| 631 | MovingAverage<LoggedRtpPacket, double>(CountPackets, stream.packet_view, |
| 632 | config_, &time_series); |
| 633 | plot->AppendTimeSeries(std::move(time_series)); |
| 634 | } |
| 635 | TimeSeries time_series( |
| 636 | std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")", |
| 637 | LineStyle::kLine); |
| 638 | if (direction == kIncomingPacket) { |
| 639 | MovingAverage<LoggedRtcpPacketIncoming, double>( |
| 640 | CountPackets, parsed_log_.incoming_rtcp_packets(), config_, |
| 641 | &time_series); |
| 642 | } else { |
| 643 | MovingAverage<LoggedRtcpPacketOutgoing, double>( |
| 644 | CountPackets, parsed_log_.outgoing_rtcp_packets(), config_, |
| 645 | &time_series); |
| 646 | } |
| 647 | plot->AppendTimeSeries(std::move(time_series)); |
| 648 | |
| 649 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 650 | "Time (s)", kLeftMargin, kRightMargin); |
| 651 | plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin, |
| 652 | kTopMargin); |
| 653 | plot->SetTitle("Rate of " + GetDirectionAsString(direction) + |
| 654 | " RTP/RTCP packets"); |
| 655 | } |
| 656 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 657 | // For each SSRC, plot the time between the consecutive playouts. |
| 658 | void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 659 | for (const auto& playout_stream : parsed_log_.audio_playout_events()) { |
| 660 | uint32_t ssrc = playout_stream.first; |
| 661 | if (!MatchingSsrc(ssrc, desired_ssrc_)) |
| 662 | continue; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 663 | absl::optional<int64_t> last_playout_ms; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 664 | TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 665 | for (const auto& playout_event : playout_stream.second) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 666 | float x = config_.GetCallTimeSec(playout_event.log_time_us()); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 667 | int64_t playout_time_ms = playout_event.log_time_ms(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 668 | // 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] | 669 | 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] | 670 | time_series.points.push_back(TimeSeriesPoint(x, y)); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 671 | last_playout_ms.emplace(playout_time_ms); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 672 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 673 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 676 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 677 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 678 | plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin, |
| 679 | kTopMargin); |
| 680 | plot->SetTitle("Audio playout"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 681 | } |
| 682 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 683 | // For audio SSRCs, plot the audio level. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 684 | void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction, |
| 685 | Plot* plot) { |
| 686 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 687 | if (!IsAudioSsrc(direction, stream.ssrc)) |
| 688 | continue; |
| 689 | TimeSeries time_series(GetStreamName(direction, stream.ssrc), |
| 690 | LineStyle::kLine); |
| 691 | for (auto& packet : stream.packet_view) { |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 692 | if (packet.header.extension.hasAudioLevel) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 693 | float x = config_.GetCallTimeSec(packet.log_time_us()); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 694 | // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10) |
| 695 | // Here we convert it to dBov. |
| 696 | float y = static_cast<float>(-packet.header.extension.audioLevel); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 697 | time_series.points.emplace_back(TimeSeriesPoint(x, y)); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 700 | plot->AppendTimeSeries(std::move(time_series)); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 703 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 704 | "Time (s)", kLeftMargin, kRightMargin); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 705 | plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 706 | plot->SetTitle(GetDirectionAsString(direction) + " audio level"); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Konrad Hofbauer | ca3c801 | 2019-02-15 20:52:19 +0100 | [diff] [blame] | 709 | // For each SSRC, plot the sequence number difference between consecutive |
| 710 | // incoming packets. |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 711 | void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 712 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
| 713 | // Filter on SSRC. |
| 714 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 715 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 716 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 717 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 718 | TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc), |
| 719 | LineStyle::kBar); |
| 720 | auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet, |
| 721 | const LoggedRtpPacketIncoming& new_packet) { |
| 722 | int64_t diff = |
| 723 | WrappingDifference(new_packet.rtp.header.sequenceNumber, |
| 724 | old_packet.rtp.header.sequenceNumber, 1ul << 16); |
| 725 | return diff; |
| 726 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 727 | auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 728 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 729 | }; |
| 730 | ProcessPairs<LoggedRtpPacketIncoming, float>( |
| 731 | ToCallTime, GetSequenceNumberDiff, stream.incoming_packets, |
| 732 | &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 733 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 736 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 737 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 738 | plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin, |
| 739 | kTopMargin); |
Konrad Hofbauer | ca3c801 | 2019-02-15 20:52:19 +0100 | [diff] [blame] | 740 | plot->SetTitle("Incoming sequence number delta"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 743 | void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 744 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
| 745 | const std::vector<LoggedRtpPacketIncoming>& packets = |
| 746 | stream.incoming_packets; |
| 747 | // Filter on SSRC. |
Mirko Bonadei | 1f17315 | 2019-07-25 15:28:14 +0200 | [diff] [blame] | 748 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.empty()) { |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 749 | continue; |
| 750 | } |
| 751 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 752 | TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc), |
| 753 | LineStyle::kLine, PointStyle::kHighlight); |
| 754 | // TODO(terelius): Should the window and step size be read from the class |
| 755 | // instead? |
| 756 | const int64_t kWindowUs = 1000000; |
| 757 | const int64_t kStep = 1000000; |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 758 | SeqNumUnwrapper<uint16_t> unwrapper_; |
| 759 | SeqNumUnwrapper<uint16_t> prior_unwrapper_; |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 760 | size_t window_index_begin = 0; |
| 761 | size_t window_index_end = 0; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 762 | uint64_t highest_seq_number = |
| 763 | unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1; |
| 764 | uint64_t highest_prior_seq_number = |
| 765 | prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1; |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 766 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 767 | for (int64_t t = config_.begin_time_; t < config_.end_time_ + kStep; |
| 768 | t += kStep) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 769 | while (window_index_end < packets.size() && |
| 770 | packets[window_index_end].rtp.log_time_us() < t) { |
| 771 | uint64_t sequence_number = unwrapper_.Unwrap( |
| 772 | packets[window_index_end].rtp.header.sequenceNumber); |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 773 | highest_seq_number = std::max(highest_seq_number, sequence_number); |
| 774 | ++window_index_end; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 775 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 776 | while (window_index_begin < packets.size() && |
| 777 | packets[window_index_begin].rtp.log_time_us() < t - kWindowUs) { |
| 778 | uint64_t sequence_number = prior_unwrapper_.Unwrap( |
| 779 | packets[window_index_begin].rtp.header.sequenceNumber); |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 780 | highest_prior_seq_number = |
| 781 | std::max(highest_prior_seq_number, sequence_number); |
| 782 | ++window_index_begin; |
| 783 | } |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 784 | float x = config_.GetCallTimeSec(t); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 785 | uint64_t expected_packets = highest_seq_number - highest_prior_seq_number; |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 786 | if (expected_packets > 0) { |
| 787 | int64_t received_packets = window_index_end - window_index_begin; |
| 788 | int64_t lost_packets = expected_packets - received_packets; |
| 789 | float y = static_cast<float>(lost_packets) / expected_packets * 100; |
| 790 | time_series.points.emplace_back(x, y); |
| 791 | } |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 792 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 793 | plot->AppendTimeSeries(std::move(time_series)); |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 794 | } |
| 795 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 796 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 797 | "Time (s)", kLeftMargin, kRightMargin); |
Konrad Hofbauer | d036c65 | 2019-02-14 16:17:28 +0100 | [diff] [blame] | 798 | plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin); |
| 799 | plot->SetTitle("Incoming packet loss (derived from incoming packets)"); |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 800 | } |
| 801 | |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 802 | void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) { |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 803 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 804 | // Filter on SSRC. |
| 805 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 806 | IsRtxSsrc(kIncomingPacket, stream.ssrc)) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 807 | continue; |
| 808 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 809 | |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 810 | const std::vector<LoggedRtpPacketIncoming>& packets = |
| 811 | stream.incoming_packets; |
| 812 | if (packets.size() < 100) { |
| 813 | RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with " |
| 814 | << packets.size() << " packets in the stream."; |
| 815 | continue; |
| 816 | } |
| 817 | int64_t end_time_us = log_segments_.empty() |
| 818 | ? std::numeric_limits<int64_t>::max() |
| 819 | : log_segments_.front().second; |
| 820 | absl::optional<uint32_t> estimated_frequency = |
| 821 | EstimateRtpClockFrequency(packets, end_time_us); |
| 822 | if (!estimated_frequency) |
| 823 | continue; |
| 824 | const double frequency_hz = *estimated_frequency; |
| 825 | if (IsVideoSsrc(kIncomingPacket, stream.ssrc) && frequency_hz != 90000) { |
| 826 | RTC_LOG(LS_WARNING) |
| 827 | << "Video stream should use a 90 kHz clock but appears to use " |
| 828 | << frequency_hz / 1000 << ". Discarding."; |
| 829 | continue; |
| 830 | } |
| 831 | |
| 832 | auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 833 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 834 | }; |
| 835 | auto ToNetworkDelay = [frequency_hz]( |
| 836 | const LoggedRtpPacketIncoming& old_packet, |
| 837 | const LoggedRtpPacketIncoming& new_packet) { |
| 838 | return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz); |
| 839 | }; |
| 840 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 841 | TimeSeries capture_time_data( |
| 842 | GetStreamName(kIncomingPacket, stream.ssrc) + " capture-time", |
| 843 | LineStyle::kLine); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 844 | AccumulatePairs<LoggedRtpPacketIncoming, double>( |
| 845 | ToCallTime, ToNetworkDelay, packets, &capture_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 846 | plot->AppendTimeSeries(std::move(capture_time_data)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 847 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 848 | TimeSeries send_time_data( |
| 849 | GetStreamName(kIncomingPacket, stream.ssrc) + " abs-send-time", |
| 850 | LineStyle::kLine); |
Bjorn Terelius | 6c373cc | 2018-11-01 14:31:10 +0100 | [diff] [blame] | 851 | AccumulatePairs<LoggedRtpPacketIncoming, double>( |
| 852 | ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data); |
| 853 | plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 854 | } |
| 855 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 856 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 857 | "Time (s)", kLeftMargin, kRightMargin); |
Konrad Hofbauer | 5be3bbd | 2019-01-21 12:31:07 +0100 | [diff] [blame] | 858 | plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin); |
| 859 | plot->SetTitle("Incoming network delay (relative to first packet)"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 860 | } |
| 861 | |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 862 | // Plot the fraction of packets lost (as perceived by the loss-based BWE). |
| 863 | void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) { |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 864 | TimeSeries time_series("Fraction lost", LineStyle::kLine, |
| 865 | PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 866 | for (auto& bwe_update : parsed_log_.bwe_loss_updates()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 867 | float x = config_.GetCallTimeSec(bwe_update.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 868 | float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 869 | time_series.points.emplace_back(x, y); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 870 | } |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 871 | |
Bjorn Terelius | 19f5be3 | 2017-10-18 12:39:49 +0200 | [diff] [blame] | 872 | plot->AppendTimeSeries(std::move(time_series)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 873 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 874 | "Time (s)", kLeftMargin, kRightMargin); |
Konrad Hofbauer | d036c65 | 2019-02-14 16:17:28 +0100 | [diff] [blame] | 875 | plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin); |
| 876 | plot->SetTitle("Outgoing packet loss (as reported by BWE)"); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 877 | } |
| 878 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 879 | // Plot the total bandwidth used by all RTP streams. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 880 | void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) { |
| 881 | // TODO(terelius): This could be provided by the parser. |
| 882 | std::multimap<int64_t, size_t> packets_in_order; |
| 883 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
| 884 | for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets) |
| 885 | packets_in_order.insert( |
| 886 | std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 889 | auto window_begin = packets_in_order.begin(); |
| 890 | auto window_end = packets_in_order.begin(); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 891 | size_t bytes_in_window = 0; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 892 | |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 893 | if (!packets_in_order.empty()) { |
| 894 | // Calculate a moving average of the bitrate and store in a TimeSeries. |
| 895 | TimeSeries bitrate_series("Bitrate", LineStyle::kLine); |
| 896 | for (int64_t time = config_.begin_time_; |
| 897 | time < config_.end_time_ + config_.step_; time += config_.step_) { |
| 898 | while (window_end != packets_in_order.end() && window_end->first < time) { |
| 899 | bytes_in_window += window_end->second; |
| 900 | ++window_end; |
| 901 | } |
| 902 | while (window_begin != packets_in_order.end() && |
| 903 | window_begin->first < time - config_.window_duration_) { |
| 904 | RTC_DCHECK_LE(window_begin->second, bytes_in_window); |
| 905 | bytes_in_window -= window_begin->second; |
| 906 | ++window_begin; |
| 907 | } |
| 908 | float window_duration_in_seconds = |
| 909 | static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec; |
| 910 | float x = config_.GetCallTimeSec(time); |
| 911 | float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; |
| 912 | bitrate_series.points.emplace_back(x, y); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 913 | } |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 914 | plot->AppendTimeSeries(std::move(bitrate_series)); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 915 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 916 | |
| 917 | // Overlay the outgoing REMB over incoming bitrate. |
| 918 | TimeSeries remb_series("Remb", LineStyle::kStep); |
| 919 | for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 920 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 921 | float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000; |
| 922 | remb_series.points.emplace_back(x, y); |
| 923 | } |
| 924 | plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series)); |
| 925 | |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 926 | if (!parsed_log_.generic_packets_received().empty()) { |
| 927 | TimeSeries time_series("Incoming generic bitrate", LineStyle::kLine); |
| 928 | auto GetPacketSizeKilobits = [](const LoggedGenericPacketReceived& packet) { |
| 929 | return packet.packet_length * 8.0 / 1000.0; |
| 930 | }; |
| 931 | MovingAverage<LoggedGenericPacketReceived, double>( |
| 932 | GetPacketSizeKilobits, parsed_log_.generic_packets_received(), config_, |
| 933 | &time_series); |
| 934 | plot->AppendTimeSeries(std::move(time_series)); |
| 935 | } |
| 936 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 937 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 938 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 939 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 940 | plot->SetTitle("Incoming RTP bitrate"); |
| 941 | } |
| 942 | |
| 943 | // Plot the total bandwidth used by all RTP streams. |
| 944 | void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot, |
| 945 | bool show_detector_state, |
| 946 | bool show_alr_state) { |
| 947 | // TODO(terelius): This could be provided by the parser. |
| 948 | std::multimap<int64_t, size_t> packets_in_order; |
| 949 | for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) { |
| 950 | for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets) |
| 951 | packets_in_order.insert( |
| 952 | std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length)); |
| 953 | } |
| 954 | |
| 955 | auto window_begin = packets_in_order.begin(); |
| 956 | auto window_end = packets_in_order.begin(); |
| 957 | size_t bytes_in_window = 0; |
| 958 | |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 959 | if (!packets_in_order.empty()) { |
| 960 | // Calculate a moving average of the bitrate and store in a TimeSeries. |
| 961 | TimeSeries bitrate_series("Bitrate", LineStyle::kLine); |
| 962 | for (int64_t time = config_.begin_time_; |
| 963 | time < config_.end_time_ + config_.step_; time += config_.step_) { |
| 964 | while (window_end != packets_in_order.end() && window_end->first < time) { |
| 965 | bytes_in_window += window_end->second; |
| 966 | ++window_end; |
| 967 | } |
| 968 | while (window_begin != packets_in_order.end() && |
| 969 | window_begin->first < time - config_.window_duration_) { |
| 970 | RTC_DCHECK_LE(window_begin->second, bytes_in_window); |
| 971 | bytes_in_window -= window_begin->second; |
| 972 | ++window_begin; |
| 973 | } |
| 974 | float window_duration_in_seconds = |
| 975 | static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec; |
| 976 | float x = config_.GetCallTimeSec(time); |
| 977 | float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; |
| 978 | bitrate_series.points.emplace_back(x, y); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 979 | } |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 980 | plot->AppendTimeSeries(std::move(bitrate_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 981 | } |
| 982 | |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 983 | // Overlay the send-side bandwidth estimate over the outgoing bitrate. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 984 | TimeSeries loss_series("Loss-based estimate", LineStyle::kStep); |
| 985 | for (auto& loss_update : parsed_log_.bwe_loss_updates()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 986 | float x = config_.GetCallTimeSec(loss_update.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 987 | float y = static_cast<float>(loss_update.bitrate_bps) / 1000; |
| 988 | loss_series.points.emplace_back(x, y); |
| 989 | } |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 990 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 991 | TimeSeries delay_series("Delay-based estimate", LineStyle::kStep); |
| 992 | IntervalSeries overusing_series("Overusing", "#ff8e82", |
| 993 | IntervalSeries::kHorizontal); |
| 994 | IntervalSeries underusing_series("Underusing", "#5092fc", |
| 995 | IntervalSeries::kHorizontal); |
| 996 | IntervalSeries normal_series("Normal", "#c4ffc4", |
| 997 | IntervalSeries::kHorizontal); |
| 998 | IntervalSeries* last_series = &normal_series; |
| 999 | double last_detector_switch = 0.0; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 1000 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1001 | BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 1002 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1003 | for (auto& delay_update : parsed_log_.bwe_delay_updates()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1004 | float x = config_.GetCallTimeSec(delay_update.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1005 | float y = static_cast<float>(delay_update.bitrate_bps) / 1000; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 1006 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1007 | if (last_detector_state != delay_update.detector_state) { |
| 1008 | last_series->intervals.emplace_back(last_detector_switch, x); |
| 1009 | last_detector_state = delay_update.detector_state; |
| 1010 | last_detector_switch = x; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 1011 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1012 | switch (delay_update.detector_state) { |
| 1013 | case BandwidthUsage::kBwNormal: |
| 1014 | last_series = &normal_series; |
| 1015 | break; |
| 1016 | case BandwidthUsage::kBwUnderusing: |
| 1017 | last_series = &underusing_series; |
| 1018 | break; |
| 1019 | case BandwidthUsage::kBwOverusing: |
| 1020 | last_series = &overusing_series; |
| 1021 | break; |
| 1022 | case BandwidthUsage::kLast: |
| 1023 | RTC_NOTREACHED(); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 1024 | } |
| 1025 | } |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 1026 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1027 | delay_series.points.emplace_back(x, y); |
| 1028 | } |
Bjorn Terelius | 9e336ec | 2018-04-24 16:28:35 +0200 | [diff] [blame] | 1029 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1030 | RTC_CHECK(last_series); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1031 | last_series->intervals.emplace_back(last_detector_switch, config_.end_time_); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1032 | |
| 1033 | TimeSeries created_series("Probe cluster created.", LineStyle::kNone, |
| 1034 | PointStyle::kHighlight); |
| 1035 | for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1036 | float x = config_.GetCallTimeSec(cluster.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1037 | float y = static_cast<float>(cluster.bitrate_bps) / 1000; |
| 1038 | created_series.points.emplace_back(x, y); |
| 1039 | } |
| 1040 | |
| 1041 | TimeSeries result_series("Probing results.", LineStyle::kNone, |
| 1042 | PointStyle::kHighlight); |
Bjorn Terelius | 7a0bb00 | 2018-05-29 14:45:53 +0200 | [diff] [blame] | 1043 | for (auto& result : parsed_log_.bwe_probe_success_events()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1044 | float x = config_.GetCallTimeSec(result.log_time_us()); |
Bjorn Terelius | 7a0bb00 | 2018-05-29 14:45:53 +0200 | [diff] [blame] | 1045 | float y = static_cast<float>(result.bitrate_bps) / 1000; |
| 1046 | result_series.points.emplace_back(x, y); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1047 | } |
| 1048 | |
Piotr (Peter) Slatala | f996c84 | 2019-01-04 06:54:22 -0800 | [diff] [blame] | 1049 | TimeSeries probe_failures_series("Probe failed", LineStyle::kNone, |
| 1050 | PointStyle::kHighlight); |
| 1051 | for (auto& failure : parsed_log_.bwe_probe_failure_events()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1052 | float x = config_.GetCallTimeSec(failure.log_time_us()); |
Piotr (Peter) Slatala | f996c84 | 2019-01-04 06:54:22 -0800 | [diff] [blame] | 1053 | probe_failures_series.points.emplace_back(x, 0); |
| 1054 | } |
| 1055 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1056 | IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal); |
| 1057 | bool previously_in_alr = false; |
| 1058 | int64_t alr_start = 0; |
| 1059 | for (auto& alr : parsed_log_.alr_state_events()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1060 | float y = config_.GetCallTimeSec(alr.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1061 | if (!previously_in_alr && alr.in_alr) { |
| 1062 | alr_start = alr.log_time_us(); |
| 1063 | previously_in_alr = true; |
| 1064 | } else if (previously_in_alr && !alr.in_alr) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1065 | float x = config_.GetCallTimeSec(alr_start); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1066 | alr_state.intervals.emplace_back(x, y); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1067 | previously_in_alr = false; |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1068 | } |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1071 | if (previously_in_alr) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1072 | float x = config_.GetCallTimeSec(alr_start); |
| 1073 | float y = config_.GetCallTimeSec(config_.end_time_); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1074 | alr_state.intervals.emplace_back(x, y); |
| 1075 | } |
| 1076 | |
| 1077 | if (show_detector_state) { |
| 1078 | plot->AppendIntervalSeries(std::move(overusing_series)); |
| 1079 | plot->AppendIntervalSeries(std::move(underusing_series)); |
| 1080 | plot->AppendIntervalSeries(std::move(normal_series)); |
| 1081 | } |
| 1082 | |
| 1083 | if (show_alr_state) { |
| 1084 | plot->AppendIntervalSeries(std::move(alr_state)); |
| 1085 | } |
| 1086 | plot->AppendTimeSeries(std::move(loss_series)); |
Piotr (Peter) Slatala | f996c84 | 2019-01-04 06:54:22 -0800 | [diff] [blame] | 1087 | plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series)); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1088 | plot->AppendTimeSeries(std::move(delay_series)); |
| 1089 | plot->AppendTimeSeries(std::move(created_series)); |
| 1090 | plot->AppendTimeSeries(std::move(result_series)); |
| 1091 | |
| 1092 | // Overlay the incoming REMB over the outgoing bitrate. |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1093 | TimeSeries remb_series("Remb", LineStyle::kStep); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1094 | for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1095 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1096 | float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000; |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 1097 | remb_series.points.emplace_back(x, y); |
| 1098 | } |
| 1099 | plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series)); |
| 1100 | |
Piotr (Peter) Slatala | cf8405e | 2019-02-14 13:44:57 -0800 | [diff] [blame] | 1101 | if (!parsed_log_.generic_packets_sent().empty()) { |
| 1102 | { |
| 1103 | TimeSeries time_series("Outgoing generic total bitrate", |
| 1104 | LineStyle::kLine); |
| 1105 | auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) { |
| 1106 | return packet.packet_length() * 8.0 / 1000.0; |
| 1107 | }; |
| 1108 | MovingAverage<LoggedGenericPacketSent, double>( |
| 1109 | GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_, |
| 1110 | &time_series); |
| 1111 | plot->AppendTimeSeries(std::move(time_series)); |
| 1112 | } |
| 1113 | |
| 1114 | { |
| 1115 | TimeSeries time_series("Outgoing generic payload bitrate", |
| 1116 | LineStyle::kLine); |
| 1117 | auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) { |
| 1118 | return packet.payload_length * 8.0 / 1000.0; |
| 1119 | }; |
| 1120 | MovingAverage<LoggedGenericPacketSent, double>( |
| 1121 | GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_, |
| 1122 | &time_series); |
| 1123 | plot->AppendTimeSeries(std::move(time_series)); |
| 1124 | } |
| 1125 | } |
| 1126 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1127 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1128 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1129 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1130 | plot->SetTitle("Outgoing RTP bitrate"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | // For each SSRC, plot the bandwidth used by that stream. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1134 | void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction, |
| 1135 | Plot* plot) { |
| 1136 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 1137 | // Filter on SSRC. |
| 1138 | if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 1139 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1142 | TimeSeries time_series(GetStreamName(direction, stream.ssrc), |
| 1143 | LineStyle::kLine); |
| 1144 | auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) { |
| 1145 | return packet.total_length * 8.0 / 1000.0; |
| 1146 | }; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1147 | MovingAverage<LoggedRtpPacket, double>( |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1148 | GetPacketSizeKilobits, stream.packet_view, config_, &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1149 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1152 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1153 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1154 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1155 | plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Bjorn Terelius | 9775a58 | 2019-02-15 17:29:58 +0100 | [diff] [blame] | 1158 | // Plot the bitrate allocation for each temporal and spatial layer. |
| 1159 | // Computed from RTCP XR target bitrate block, so the graph is only populated if |
| 1160 | // those are sent. |
| 1161 | void EventLogAnalyzer::CreateBitrateAllocationGraph(PacketDirection direction, |
| 1162 | Plot* plot) { |
| 1163 | std::map<LayerDescription, TimeSeries> time_series; |
| 1164 | const auto& xr_list = parsed_log_.extended_reports(direction); |
| 1165 | for (const auto& rtcp : xr_list) { |
| 1166 | const absl::optional<rtcp::TargetBitrate>& target_bitrate = |
| 1167 | rtcp.xr.target_bitrate(); |
| 1168 | if (!target_bitrate.has_value()) |
| 1169 | continue; |
| 1170 | for (const auto& bitrate_item : target_bitrate->GetTargetBitrates()) { |
| 1171 | LayerDescription layer(rtcp.xr.sender_ssrc(), bitrate_item.spatial_layer, |
| 1172 | bitrate_item.temporal_layer); |
| 1173 | auto time_series_it = time_series.find(layer); |
| 1174 | if (time_series_it == time_series.end()) { |
| 1175 | std::string layer_name = GetLayerName(layer); |
| 1176 | bool inserted; |
| 1177 | std::tie(time_series_it, inserted) = time_series.insert( |
| 1178 | std::make_pair(layer, TimeSeries(layer_name, LineStyle::kStep))); |
| 1179 | RTC_DCHECK(inserted); |
| 1180 | } |
| 1181 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
| 1182 | float y = bitrate_item.target_bitrate_kbps; |
| 1183 | time_series_it->second.points.emplace_back(x, y); |
| 1184 | } |
| 1185 | } |
| 1186 | for (auto& layer : time_series) { |
| 1187 | plot->AppendTimeSeries(std::move(layer.second)); |
| 1188 | } |
| 1189 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1190 | "Time (s)", kLeftMargin, kRightMargin); |
| 1191 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 1192 | if (direction == kIncomingPacket) |
| 1193 | plot->SetTitle("Target bitrate per incoming layer"); |
| 1194 | else |
| 1195 | plot->SetTitle("Target bitrate per outgoing layer"); |
| 1196 | } |
| 1197 | |
Sebastian Jansson | 1175ae0 | 2019-03-13 08:56:58 +0100 | [diff] [blame] | 1198 | void EventLogAnalyzer::CreateGoogCcSimulationGraph(Plot* plot) { |
| 1199 | TimeSeries target_rates("Simulated target rate", LineStyle::kStep, |
| 1200 | PointStyle::kHighlight); |
| 1201 | TimeSeries delay_based("Logged delay-based estimate", LineStyle::kStep, |
| 1202 | PointStyle::kHighlight); |
| 1203 | TimeSeries loss_based("Logged loss-based estimate", LineStyle::kStep, |
| 1204 | PointStyle::kHighlight); |
| 1205 | TimeSeries probe_results("Logged probe success", LineStyle::kNone, |
| 1206 | PointStyle::kHighlight); |
| 1207 | |
Sebastian Jansson | 1175ae0 | 2019-03-13 08:56:58 +0100 | [diff] [blame] | 1208 | LogBasedNetworkControllerSimulation simulation( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1209 | std::make_unique<GoogCcNetworkControllerFactory>(), |
Sebastian Jansson | 1175ae0 | 2019-03-13 08:56:58 +0100 | [diff] [blame] | 1210 | [&](const NetworkControlUpdate& update, Timestamp at_time) { |
| 1211 | if (update.target_rate) { |
| 1212 | target_rates.points.emplace_back( |
| 1213 | config_.GetCallTimeSec(at_time.us()), |
| 1214 | update.target_rate->target_rate.kbps<float>()); |
| 1215 | } |
| 1216 | }); |
| 1217 | |
| 1218 | simulation.ProcessEventsInLog(parsed_log_); |
| 1219 | for (const auto& logged : parsed_log_.bwe_delay_updates()) |
| 1220 | delay_based.points.emplace_back( |
| 1221 | config_.GetCallTimeSec(logged.log_time_us()), |
| 1222 | logged.bitrate_bps / 1000); |
| 1223 | for (const auto& logged : parsed_log_.bwe_probe_success_events()) |
| 1224 | probe_results.points.emplace_back( |
| 1225 | config_.GetCallTimeSec(logged.log_time_us()), |
| 1226 | logged.bitrate_bps / 1000); |
| 1227 | for (const auto& logged : parsed_log_.bwe_loss_updates()) |
| 1228 | loss_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time_us()), |
| 1229 | logged.bitrate_bps / 1000); |
| 1230 | |
| 1231 | plot->AppendTimeSeries(std::move(delay_based)); |
| 1232 | plot->AppendTimeSeries(std::move(loss_based)); |
| 1233 | plot->AppendTimeSeries(std::move(probe_results)); |
| 1234 | plot->AppendTimeSeries(std::move(target_rates)); |
| 1235 | |
| 1236 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1237 | "Time (s)", kLeftMargin, kRightMargin); |
| 1238 | plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 1239 | plot->SetTitle("Simulated BWE behavior"); |
| 1240 | } |
| 1241 | |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1242 | void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1243 | using RtpPacketType = LoggedRtpPacketOutgoing; |
| 1244 | using TransportFeedbackType = LoggedRtcpPacketTransportFeedback; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1245 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1246 | // TODO(terelius): This could be provided by the parser. |
| 1247 | std::multimap<int64_t, const RtpPacketType*> outgoing_rtp; |
| 1248 | for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) { |
| 1249 | for (const RtpPacketType& rtp_packet : stream.outgoing_packets) |
| 1250 | outgoing_rtp.insert( |
| 1251 | std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet)); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1252 | } |
| 1253 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1254 | const std::vector<TransportFeedbackType>& incoming_rtcp = |
| 1255 | parsed_log_.transport_feedbacks(kIncomingPacket); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1256 | |
| 1257 | SimulatedClock clock(0); |
| 1258 | BitrateObserver observer; |
Danil Chapovalov | 83bbe91 | 2019-08-07 12:24:53 +0200 | [diff] [blame] | 1259 | RtcEventLogNull null_event_log; |
nisse | 0245da0 | 2016-11-30 03:35:20 -0800 | [diff] [blame] | 1260 | PacketRouter packet_router; |
Stefan Holmer | 5c8942a | 2017-08-22 16:16:44 +0200 | [diff] [blame] | 1261 | PacedSender pacer(&clock, &packet_router, &null_event_log); |
Sebastian Jansson | 05acd2b | 2019-01-21 13:07:47 +0100 | [diff] [blame] | 1262 | TransportFeedbackAdapter transport_feedback; |
Sebastian Jansson | 2db5fc0 | 2019-04-30 14:17:45 +0200 | [diff] [blame] | 1263 | auto factory = GoogCcNetworkControllerFactory(); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1264 | TimeDelta process_interval = factory.GetProcessInterval(); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1265 | // TODO(holmer): Log the call config and use that here instead. |
| 1266 | static const uint32_t kDefaultStartBitrateBps = 300000; |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1267 | NetworkControllerConfig cc_config; |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1268 | cc_config.constraints.at_time = Timestamp::Micros(clock.TimeInMicroseconds()); |
Danil Chapovalov | cad3e0e | 2020-02-17 18:46:07 +0100 | [diff] [blame] | 1269 | cc_config.constraints.starting_rate = |
| 1270 | DataRate::BitsPerSec(kDefaultStartBitrateBps); |
Sebastian Jansson | 2db5fc0 | 2019-04-30 14:17:45 +0200 | [diff] [blame] | 1271 | cc_config.event_log = &null_event_log; |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1272 | auto goog_cc = factory.Create(cc_config); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1273 | |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1274 | TimeSeries time_series("Delay-based estimate", LineStyle::kStep, |
| 1275 | PointStyle::kHighlight); |
| 1276 | TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine, |
| 1277 | PointStyle::kHighlight); |
| 1278 | TimeSeries acked_estimate_time_series( |
| 1279 | "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1280 | |
| 1281 | auto rtp_iterator = outgoing_rtp.begin(); |
| 1282 | auto rtcp_iterator = incoming_rtcp.begin(); |
| 1283 | |
| 1284 | auto NextRtpTime = [&]() { |
| 1285 | if (rtp_iterator != outgoing_rtp.end()) |
| 1286 | return static_cast<int64_t>(rtp_iterator->first); |
| 1287 | return std::numeric_limits<int64_t>::max(); |
| 1288 | }; |
| 1289 | |
| 1290 | auto NextRtcpTime = [&]() { |
| 1291 | if (rtcp_iterator != incoming_rtcp.end()) |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1292 | return static_cast<int64_t>(rtcp_iterator->log_time_us()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1293 | return std::numeric_limits<int64_t>::max(); |
| 1294 | }; |
Bjorn Terelius | a728c91 | 2018-12-06 12:26:30 +0100 | [diff] [blame] | 1295 | int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()}); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1296 | |
| 1297 | auto NextProcessTime = [&]() { |
| 1298 | if (rtcp_iterator != incoming_rtcp.end() || |
| 1299 | rtp_iterator != outgoing_rtp.end()) { |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1300 | return next_process_time_us_; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1301 | } |
| 1302 | return std::numeric_limits<int64_t>::max(); |
| 1303 | }; |
| 1304 | |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1305 | RateStatistics acked_bitrate(250, 8000); |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 1306 | #if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE) |
Sebastian Jansson | 95edb03 | 2019-01-17 16:24:12 +0100 | [diff] [blame] | 1307 | FieldTrialBasedConfig field_trial_config_; |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 1308 | // The event_log_visualizer should normally not be compiled with |
| 1309 | // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work. |
Björn Terelius | 251b0dc | 2019-11-11 21:00:18 +0100 | [diff] [blame] | 1310 | // However, compiling with BWE_TEST_LOGGING, running with --plot=sendside_bwe |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 1311 | // and piping the output to plot_dynamics.py can be used as a hack to get the |
| 1312 | // internal state of various BWE components. In this case, it is important |
| 1313 | // we don't instantiate the AcknowledgedBitrateEstimator both here and in |
Sebastian Jansson | 4ad51d8 | 2019-06-11 11:24:40 +0200 | [diff] [blame] | 1314 | // GoogCcNetworkController since that would lead to duplicate outputs. |
Björn Terelius | 251b0dc | 2019-11-11 21:00:18 +0100 | [diff] [blame] | 1315 | std::unique_ptr<AcknowledgedBitrateEstimatorInterface> |
| 1316 | acknowledged_bitrate_estimator( |
| 1317 | AcknowledgedBitrateEstimatorInterface::Create(&field_trial_config_)); |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 1318 | #endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE) |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1319 | int64_t time_us = |
| 1320 | std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()}); |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1321 | int64_t last_update_us = 0; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1322 | while (time_us != std::numeric_limits<int64_t>::max()) { |
| 1323 | clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds()); |
Bjorn Terelius | c60a777 | 2018-12-05 21:15:30 +0100 | [diff] [blame] | 1324 | if (clock.TimeInMicroseconds() >= NextRtpTime()) { |
| 1325 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime()); |
| 1326 | const RtpPacketType& rtp_packet = *rtp_iterator->second; |
| 1327 | if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) { |
| 1328 | RTC_DCHECK(rtp_packet.rtp.header.extension.hasTransportSequenceNumber); |
Erik Språng | 30a276b | 2019-04-23 12:00:11 +0200 | [diff] [blame] | 1329 | RtpPacketSendInfo packet_info; |
| 1330 | packet_info.ssrc = rtp_packet.rtp.header.ssrc; |
Bjorn Terelius | f2e9cab | 2019-05-27 16:44:09 +0200 | [diff] [blame] | 1331 | packet_info.transport_sequence_number = |
Erik Språng | 30a276b | 2019-04-23 12:00:11 +0200 | [diff] [blame] | 1332 | rtp_packet.rtp.header.extension.transportSequenceNumber; |
| 1333 | packet_info.rtp_sequence_number = rtp_packet.rtp.header.sequenceNumber; |
Erik Språng | 30a276b | 2019-04-23 12:00:11 +0200 | [diff] [blame] | 1334 | packet_info.length = rtp_packet.rtp.total_length; |
Bjorn Terelius | c60a777 | 2018-12-05 21:15:30 +0100 | [diff] [blame] | 1335 | transport_feedback.AddPacket( |
Erik Språng | 30a276b | 2019-04-23 12:00:11 +0200 | [diff] [blame] | 1336 | packet_info, |
| 1337 | 0u, // Per packet overhead bytes. |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1338 | Timestamp::Micros(rtp_packet.rtp.log_time_us())); |
Bjorn Terelius | c60a777 | 2018-12-05 21:15:30 +0100 | [diff] [blame] | 1339 | rtc::SentPacket sent_packet( |
| 1340 | rtp_packet.rtp.header.extension.transportSequenceNumber, |
| 1341 | rtp_packet.rtp.log_time_us() / 1000); |
| 1342 | auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet); |
| 1343 | if (sent_msg) |
| 1344 | observer.Update(goog_cc->OnSentPacket(*sent_msg)); |
| 1345 | } |
| 1346 | ++rtp_iterator; |
| 1347 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1348 | if (clock.TimeInMicroseconds() >= NextRtcpTime()) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1349 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime()); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1350 | |
| 1351 | auto feedback_msg = transport_feedback.ProcessTransportFeedback( |
Sebastian Jansson | 05acd2b | 2019-01-21 13:07:47 +0100 | [diff] [blame] | 1352 | rtcp_iterator->transport_feedback, |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1353 | Timestamp::Millis(clock.TimeInMilliseconds())); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1354 | absl::optional<uint32_t> bitrate_bps; |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1355 | if (feedback_msg) { |
| 1356 | observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg)); |
Sebastian Jansson | 88290ae | 2019-06-20 12:26:31 +0200 | [diff] [blame] | 1357 | std::vector<PacketResult> feedback = |
| 1358 | feedback_msg->SortedByReceiveTime(); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1359 | if (!feedback.empty()) { |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 1360 | #if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE) |
Björn Terelius | 251b0dc | 2019-11-11 21:00:18 +0100 | [diff] [blame] | 1361 | acknowledged_bitrate_estimator->IncomingPacketFeedbackVector( |
| 1362 | feedback); |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 1363 | #endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE) |
Sebastian Jansson | 88290ae | 2019-06-20 12:26:31 +0200 | [diff] [blame] | 1364 | for (const PacketResult& packet : feedback) |
| 1365 | acked_bitrate.Update(packet.sent_packet.size.bytes(), |
| 1366 | packet.receive_time.ms()); |
| 1367 | bitrate_bps = acked_bitrate.Rate(feedback.back().receive_time.ms()); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1368 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1369 | } |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1370 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1371 | float x = config_.GetCallTimeSec(clock.TimeInMicroseconds()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1372 | float y = bitrate_bps.value_or(0) / 1000; |
| 1373 | acked_time_series.points.emplace_back(x, y); |
| 1374 | #if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE) |
Björn Terelius | 251b0dc | 2019-11-11 21:00:18 +0100 | [diff] [blame] | 1375 | y = acknowledged_bitrate_estimator->bitrate() |
Sebastian Jansson | 88290ae | 2019-06-20 12:26:31 +0200 | [diff] [blame] | 1376 | .value_or(DataRate::Zero()) |
| 1377 | .kbps(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1378 | acked_estimate_time_series.points.emplace_back(x, y); |
| 1379 | #endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE) |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1380 | ++rtcp_iterator; |
| 1381 | } |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1382 | if (clock.TimeInMicroseconds() >= NextProcessTime()) { |
| 1383 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime()); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1384 | ProcessInterval msg; |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1385 | msg.at_time = Timestamp::Micros(clock.TimeInMicroseconds()); |
Sebastian Jansson | 5c94f55 | 2018-10-15 18:46:51 +0200 | [diff] [blame] | 1386 | observer.Update(goog_cc->OnProcessInterval(msg)); |
| 1387 | next_process_time_us_ += process_interval.us(); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1388 | } |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1389 | if (observer.GetAndResetBitrateUpdated() || |
| 1390 | time_us - last_update_us >= 1e6) { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1391 | uint32_t y = observer.last_bitrate_bps() / 1000; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1392 | float x = config_.GetCallTimeSec(clock.TimeInMicroseconds()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1393 | time_series.points.emplace_back(x, y); |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1394 | last_update_us = time_us; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1395 | } |
| 1396 | time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()}); |
| 1397 | } |
| 1398 | // Add the data set to the plot. |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1399 | plot->AppendTimeSeries(std::move(time_series)); |
| 1400 | plot->AppendTimeSeries(std::move(acked_time_series)); |
Bjorn Terelius | 6984ad2 | 2017-10-24 12:19:45 +0200 | [diff] [blame] | 1401 | plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series)); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1402 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1403 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1404 | "Time (s)", kLeftMargin, kRightMargin); |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1405 | plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1406 | plot->SetTitle("Simulated send-side BWE behavior"); |
| 1407 | } |
| 1408 | |
| 1409 | void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1410 | using RtpPacketType = LoggedRtpPacketIncoming; |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1411 | class RembInterceptingPacketRouter : public PacketRouter { |
| 1412 | public: |
| 1413 | void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 1414 | uint32_t bitrate_bps) override { |
| 1415 | last_bitrate_bps_ = bitrate_bps; |
| 1416 | bitrate_updated_ = true; |
| 1417 | PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps); |
| 1418 | } |
| 1419 | uint32_t last_bitrate_bps() const { return last_bitrate_bps_; } |
| 1420 | bool GetAndResetBitrateUpdated() { |
| 1421 | bool bitrate_updated = bitrate_updated_; |
| 1422 | bitrate_updated_ = false; |
| 1423 | return bitrate_updated; |
| 1424 | } |
| 1425 | |
| 1426 | private: |
| 1427 | uint32_t last_bitrate_bps_; |
| 1428 | bool bitrate_updated_; |
| 1429 | }; |
| 1430 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1431 | std::multimap<int64_t, const RtpPacketType*> incoming_rtp; |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1432 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1433 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
| 1434 | if (IsVideoSsrc(kIncomingPacket, stream.ssrc)) { |
| 1435 | for (const auto& rtp_packet : stream.incoming_packets) |
| 1436 | incoming_rtp.insert( |
| 1437 | std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet)); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | SimulatedClock clock(0); |
| 1442 | RembInterceptingPacketRouter packet_router; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1443 | // TODO(terelius): The PacketRouter is used as the RemoteBitrateObserver. |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1444 | // Is this intentional? |
| 1445 | ReceiveSideCongestionController rscc(&clock, &packet_router); |
| 1446 | // TODO(holmer): Log the call config and use that here instead. |
| 1447 | // static const uint32_t kDefaultStartBitrateBps = 300000; |
| 1448 | // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1); |
| 1449 | |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1450 | TimeSeries time_series("Receive side estimate", LineStyle::kLine, |
| 1451 | PointStyle::kHighlight); |
| 1452 | TimeSeries acked_time_series("Received bitrate", LineStyle::kLine); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1453 | |
| 1454 | RateStatistics acked_bitrate(250, 8000); |
| 1455 | int64_t last_update_us = 0; |
| 1456 | for (const auto& kv : incoming_rtp) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1457 | const RtpPacketType& packet = *kv.second; |
| 1458 | int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000; |
| 1459 | size_t payload = packet.rtp.total_length; /*Should subtract header?*/ |
| 1460 | clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() - |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1461 | clock.TimeInMicroseconds()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1462 | rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1463 | acked_bitrate.Update(payload, arrival_time_ms); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1464 | absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1465 | if (bitrate_bps) { |
| 1466 | uint32_t y = *bitrate_bps / 1000; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1467 | float x = config_.GetCallTimeSec(clock.TimeInMicroseconds()); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1468 | acked_time_series.points.emplace_back(x, y); |
| 1469 | } |
| 1470 | if (packet_router.GetAndResetBitrateUpdated() || |
| 1471 | clock.TimeInMicroseconds() - last_update_us >= 1e6) { |
| 1472 | uint32_t y = packet_router.last_bitrate_bps() / 1000; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1473 | float x = config_.GetCallTimeSec(clock.TimeInMicroseconds()); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1474 | time_series.points.emplace_back(x, y); |
| 1475 | last_update_us = clock.TimeInMicroseconds(); |
| 1476 | } |
| 1477 | } |
| 1478 | // Add the data set to the plot. |
| 1479 | plot->AppendTimeSeries(std::move(time_series)); |
| 1480 | plot->AppendTimeSeries(std::move(acked_time_series)); |
| 1481 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1482 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1483 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 1484 | plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 1485 | plot->SetTitle("Simulated receive-side BWE behavior"); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1486 | } |
| 1487 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 1488 | void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) { |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1489 | TimeSeries time_series("Network delay", LineStyle::kLine, |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1490 | PointStyle::kHighlight); |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1491 | int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max(); |
| 1492 | int64_t min_rtt_ms = std::numeric_limits<int64_t>::max(); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1493 | |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1494 | int64_t prev_y = 0; |
Björn Terelius | c69c1bb | 2019-10-11 15:06:58 +0200 | [diff] [blame] | 1495 | std::vector<MatchedSendArrivalTimes> matched_rtp_rtcp = |
| 1496 | GetNetworkTrace(parsed_log_); |
| 1497 | absl::c_stable_sort(matched_rtp_rtcp, [](const MatchedSendArrivalTimes& a, |
| 1498 | const MatchedSendArrivalTimes& b) { |
philipel | 3574d05 | 2019-11-18 14:38:13 +0100 | [diff] [blame] | 1499 | return a.feedback_arrival_time_ms < b.feedback_arrival_time_ms || |
| 1500 | (a.feedback_arrival_time_ms == b.feedback_arrival_time_ms && |
| 1501 | a.arrival_time_ms < b.arrival_time_ms); |
Björn Terelius | c69c1bb | 2019-10-11 15:06:58 +0200 | [diff] [blame] | 1502 | }); |
| 1503 | for (const auto& packet : matched_rtp_rtcp) { |
Sebastian Jansson | 74f96ec | 2019-10-29 12:57:54 +0100 | [diff] [blame] | 1504 | if (packet.arrival_time_ms == MatchedSendArrivalTimes::kNotReceived) |
Christoffer Rodbro | 89f64d3 | 2018-09-27 14:29:35 +0200 | [diff] [blame] | 1505 | continue; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1506 | float x = config_.GetCallTimeSec(1000 * packet.feedback_arrival_time_ms); |
Christoffer Rodbro | 89f64d3 | 2018-09-27 14:29:35 +0200 | [diff] [blame] | 1507 | int64_t y = packet.arrival_time_ms - packet.send_time_ms; |
| 1508 | prev_y = y; |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1509 | int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms; |
| 1510 | min_rtt_ms = std::min(rtt_ms, min_rtt_ms); |
| 1511 | 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] | 1512 | time_series.points.emplace_back(x, y); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1513 | } |
Christoffer Rodbro | 89f64d3 | 2018-09-27 14:29:35 +0200 | [diff] [blame] | 1514 | |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1515 | // We assume that the base network delay (w/o queues) is equal to half |
| 1516 | // the minimum RTT. Therefore rescale the delays by subtracting the minimum |
Mirko Bonadei | 604e75c | 2019-07-25 11:55:47 +0200 | [diff] [blame] | 1517 | // observed 1-ways delay and add half the minimum RTT. |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1518 | const int64_t estimated_clock_offset_ms = |
| 1519 | min_send_receive_diff_ms - min_rtt_ms / 2; |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1520 | for (TimeSeriesPoint& point : time_series.points) |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1521 | point.y -= estimated_clock_offset_ms; |
Bjorn Terelius | 57ba7e1 | 2018-10-25 15:31:35 +0200 | [diff] [blame] | 1522 | |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1523 | // Add the data set to the plot. |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1524 | plot->AppendTimeSeriesIfNotEmpty(std::move(time_series)); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1525 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1526 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1527 | "Time (s)", kLeftMargin, kRightMargin); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1528 | plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin); |
Konrad Hofbauer | 5be3bbd | 2019-01-21 12:31:07 +0100 | [diff] [blame] | 1529 | plot->SetTitle("Outgoing network delay (based on per-packet feedback)"); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1530 | } |
stefan | 0838327 | 2016-12-20 08:51:52 -0800 | [diff] [blame] | 1531 | |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1532 | void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1533 | for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) { |
| 1534 | const std::vector<LoggedRtpPacketOutgoing>& packets = |
| 1535 | stream.outgoing_packets; |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1536 | |
Konrad Hofbauer | bfb735b | 2019-04-16 11:12:11 +0200 | [diff] [blame] | 1537 | if (IsRtxSsrc(kOutgoingPacket, stream.ssrc)) { |
| 1538 | continue; |
| 1539 | } |
| 1540 | |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1541 | if (packets.size() < 2) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1542 | RTC_LOG(LS_WARNING) |
| 1543 | << "Can't estimate a the RTP clock frequency or the " |
| 1544 | "pacer delay with less than 2 packets in the stream"; |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1545 | continue; |
| 1546 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1547 | int64_t end_time_us = log_segments_.empty() |
| 1548 | ? std::numeric_limits<int64_t>::max() |
| 1549 | : log_segments_.front().second; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1550 | absl::optional<uint32_t> estimated_frequency = |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1551 | EstimateRtpClockFrequency(packets, end_time_us); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1552 | if (!estimated_frequency) |
| 1553 | continue; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1554 | if (IsVideoSsrc(kOutgoingPacket, stream.ssrc) && |
| 1555 | *estimated_frequency != 90000) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1556 | RTC_LOG(LS_WARNING) |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1557 | << "Video stream should use a 90 kHz clock but appears to use " |
| 1558 | << *estimated_frequency / 1000 << ". Discarding."; |
| 1559 | continue; |
| 1560 | } |
| 1561 | |
| 1562 | TimeSeries pacer_delay_series( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1563 | GetStreamName(kOutgoingPacket, stream.ssrc) + "(" + |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1564 | std::to_string(*estimated_frequency / 1000) + " kHz)", |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1565 | LineStyle::kLine, PointStyle::kHighlight); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1566 | SeqNumUnwrapper<uint32_t> timestamp_unwrapper; |
| 1567 | uint64_t first_capture_timestamp = |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1568 | timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp); |
| 1569 | uint64_t first_send_timestamp = packets.front().rtp.log_time_us(); |
| 1570 | for (const auto& packet : packets) { |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1571 | double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1572 | packet.rtp.header.timestamp)) - |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1573 | first_capture_timestamp) / |
| 1574 | *estimated_frequency * 1000; |
| 1575 | double send_time_ms = |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1576 | static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) / |
| 1577 | 1000; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1578 | float x = config_.GetCallTimeSec(packet.rtp.log_time_us()); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1579 | float y = send_time_ms - capture_time_ms; |
| 1580 | pacer_delay_series.points.emplace_back(x, y); |
| 1581 | } |
| 1582 | plot->AppendTimeSeries(std::move(pacer_delay_series)); |
| 1583 | } |
| 1584 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1585 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1586 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 1587 | plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin); |
| 1588 | plot->SetTitle( |
| 1589 | "Delay from capture to send time. (First packet normalized to 0.)"); |
| 1590 | } |
| 1591 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1592 | void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction, |
| 1593 | Plot* plot) { |
| 1594 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 1595 | TimeSeries rtp_timestamps( |
| 1596 | GetStreamName(direction, stream.ssrc) + " capture-time", |
| 1597 | LineStyle::kLine, PointStyle::kHighlight); |
| 1598 | for (const auto& packet : stream.packet_view) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1599 | float x = config_.GetCallTimeSec(packet.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1600 | float y = packet.header.timestamp; |
| 1601 | rtp_timestamps.points.emplace_back(x, y); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1602 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1603 | plot->AppendTimeSeries(std::move(rtp_timestamps)); |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1604 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1605 | TimeSeries rtcp_timestamps( |
| 1606 | GetStreamName(direction, stream.ssrc) + " rtcp capture-time", |
| 1607 | LineStyle::kLine, PointStyle::kHighlight); |
| 1608 | // TODO(terelius): Why only sender reports? |
| 1609 | const auto& sender_reports = parsed_log_.sender_reports(direction); |
| 1610 | for (const auto& rtcp : sender_reports) { |
| 1611 | if (rtcp.sr.sender_ssrc() != stream.ssrc) |
| 1612 | continue; |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1613 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1614 | float y = rtcp.sr.rtp_timestamp(); |
| 1615 | rtcp_timestamps.points.emplace_back(x, y); |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 1616 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1617 | plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps)); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1618 | } |
| 1619 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1620 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1621 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1622 | plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin); |
| 1623 | plot->SetTitle(GetDirectionAsString(direction) + " timestamps"); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1624 | } |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1625 | |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1626 | void EventLogAnalyzer::CreateSenderAndReceiverReportPlot( |
| 1627 | PacketDirection direction, |
| 1628 | rtc::FunctionView<float(const rtcp::ReportBlock&)> fy, |
| 1629 | std::string title, |
| 1630 | std::string yaxis_label, |
| 1631 | Plot* plot) { |
| 1632 | std::map<uint32_t, TimeSeries> sr_reports_by_ssrc; |
| 1633 | const auto& sender_reports = parsed_log_.sender_reports(direction); |
| 1634 | for (const auto& rtcp : sender_reports) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1635 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1636 | uint32_t ssrc = rtcp.sr.sender_ssrc(); |
| 1637 | for (const auto& block : rtcp.sr.report_blocks()) { |
| 1638 | float y = fy(block); |
| 1639 | auto sr_report_it = sr_reports_by_ssrc.find(ssrc); |
| 1640 | bool inserted; |
| 1641 | if (sr_report_it == sr_reports_by_ssrc.end()) { |
| 1642 | std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace( |
| 1643 | ssrc, TimeSeries(GetStreamName(direction, ssrc) + " Sender Reports", |
| 1644 | LineStyle::kLine, PointStyle::kHighlight)); |
| 1645 | } |
| 1646 | sr_report_it->second.points.emplace_back(x, y); |
| 1647 | } |
| 1648 | } |
| 1649 | for (auto& kv : sr_reports_by_ssrc) { |
| 1650 | plot->AppendTimeSeries(std::move(kv.second)); |
| 1651 | } |
| 1652 | |
| 1653 | std::map<uint32_t, TimeSeries> rr_reports_by_ssrc; |
| 1654 | const auto& receiver_reports = parsed_log_.receiver_reports(direction); |
| 1655 | for (const auto& rtcp : receiver_reports) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1656 | float x = config_.GetCallTimeSec(rtcp.log_time_us()); |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1657 | uint32_t ssrc = rtcp.rr.sender_ssrc(); |
| 1658 | for (const auto& block : rtcp.rr.report_blocks()) { |
| 1659 | float y = fy(block); |
| 1660 | auto rr_report_it = rr_reports_by_ssrc.find(ssrc); |
| 1661 | bool inserted; |
| 1662 | if (rr_report_it == rr_reports_by_ssrc.end()) { |
| 1663 | std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace( |
| 1664 | ssrc, |
| 1665 | TimeSeries(GetStreamName(direction, ssrc) + " Receiver Reports", |
| 1666 | LineStyle::kLine, PointStyle::kHighlight)); |
| 1667 | } |
| 1668 | rr_report_it->second.points.emplace_back(x, y); |
| 1669 | } |
| 1670 | } |
| 1671 | for (auto& kv : rr_reports_by_ssrc) { |
| 1672 | plot->AppendTimeSeries(std::move(kv.second)); |
| 1673 | } |
| 1674 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1675 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1676 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | b1222c2 | 2018-07-24 13:45:31 +0200 | [diff] [blame] | 1677 | plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin); |
| 1678 | plot->SetTitle(title); |
| 1679 | } |
| 1680 | |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1681 | void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) { |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1682 | TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine, |
| 1683 | PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1684 | auto GetAnaBitrateBps = [](const LoggedAudioNetworkAdaptationEvent& ana_event) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1685 | -> absl::optional<float> { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1686 | if (ana_event.config.bitrate_bps) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1687 | return absl::optional<float>( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1688 | static_cast<float>(*ana_event.config.bitrate_bps)); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1689 | return absl::nullopt; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1690 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1691 | auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1692 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1693 | }; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1694 | ProcessPoints<LoggedAudioNetworkAdaptationEvent>( |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1695 | ToCallTime, GetAnaBitrateBps, |
| 1696 | parsed_log_.audio_network_adaptation_events(), &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1697 | plot->AppendTimeSeries(std::move(time_series)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1698 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1699 | "Time (s)", kLeftMargin, kRightMargin); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1700 | plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin); |
| 1701 | plot->SetTitle("Reported audio encoder target bitrate"); |
| 1702 | } |
| 1703 | |
| 1704 | void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) { |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1705 | TimeSeries time_series("Audio encoder frame length", LineStyle::kLine, |
| 1706 | PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1707 | auto GetAnaFrameLengthMs = |
| 1708 | [](const LoggedAudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1709 | if (ana_event.config.frame_length_ms) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1710 | return absl::optional<float>( |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1711 | static_cast<float>(*ana_event.config.frame_length_ms)); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1712 | return absl::optional<float>(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1713 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1714 | auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1715 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1716 | }; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1717 | ProcessPoints<LoggedAudioNetworkAdaptationEvent>( |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1718 | ToCallTime, GetAnaFrameLengthMs, |
| 1719 | parsed_log_.audio_network_adaptation_events(), &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1720 | plot->AppendTimeSeries(std::move(time_series)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1721 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1722 | "Time (s)", kLeftMargin, kRightMargin); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1723 | plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin); |
| 1724 | plot->SetTitle("Reported audio encoder frame length"); |
| 1725 | } |
| 1726 | |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 1727 | void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1728 | TimeSeries time_series("Audio encoder uplink packet loss fraction", |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1729 | LineStyle::kLine, PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1730 | auto GetAnaPacketLoss = |
| 1731 | [](const LoggedAudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1732 | if (ana_event.config.uplink_packet_loss_fraction) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1733 | return absl::optional<float>(static_cast<float>( |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1734 | *ana_event.config.uplink_packet_loss_fraction)); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1735 | return absl::optional<float>(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1736 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1737 | auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1738 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1739 | }; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1740 | ProcessPoints<LoggedAudioNetworkAdaptationEvent>( |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1741 | ToCallTime, GetAnaPacketLoss, |
| 1742 | parsed_log_.audio_network_adaptation_events(), &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1743 | plot->AppendTimeSeries(std::move(time_series)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1744 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1745 | "Time (s)", kLeftMargin, kRightMargin); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1746 | plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin, |
| 1747 | kTopMargin); |
| 1748 | plot->SetTitle("Reported audio encoder lost packets"); |
| 1749 | } |
| 1750 | |
| 1751 | void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) { |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1752 | TimeSeries time_series("Audio encoder FEC", LineStyle::kLine, |
| 1753 | PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1754 | auto GetAnaFecEnabled = |
| 1755 | [](const LoggedAudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1756 | if (ana_event.config.enable_fec) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1757 | return absl::optional<float>( |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1758 | static_cast<float>(*ana_event.config.enable_fec)); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1759 | return absl::optional<float>(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1760 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1761 | auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1762 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1763 | }; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1764 | ProcessPoints<LoggedAudioNetworkAdaptationEvent>( |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1765 | ToCallTime, GetAnaFecEnabled, |
| 1766 | parsed_log_.audio_network_adaptation_events(), &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1767 | plot->AppendTimeSeries(std::move(time_series)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1768 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1769 | "Time (s)", kLeftMargin, kRightMargin); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1770 | plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin); |
| 1771 | plot->SetTitle("Reported audio encoder FEC"); |
| 1772 | } |
| 1773 | |
| 1774 | void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) { |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1775 | TimeSeries time_series("Audio encoder DTX", LineStyle::kLine, |
| 1776 | PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1777 | auto GetAnaDtxEnabled = |
| 1778 | [](const LoggedAudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1779 | if (ana_event.config.enable_dtx) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1780 | return absl::optional<float>( |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1781 | static_cast<float>(*ana_event.config.enable_dtx)); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1782 | return absl::optional<float>(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1783 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1784 | auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1785 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1786 | }; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1787 | ProcessPoints<LoggedAudioNetworkAdaptationEvent>( |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1788 | ToCallTime, GetAnaDtxEnabled, |
| 1789 | parsed_log_.audio_network_adaptation_events(), &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1790 | plot->AppendTimeSeries(std::move(time_series)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1791 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1792 | "Time (s)", kLeftMargin, kRightMargin); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1793 | plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin); |
| 1794 | plot->SetTitle("Reported audio encoder DTX"); |
| 1795 | } |
| 1796 | |
| 1797 | void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) { |
Bjorn Terelius | b577d5e | 2017-11-10 16:21:34 +0100 | [diff] [blame] | 1798 | TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine, |
| 1799 | PointStyle::kHighlight); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1800 | auto GetAnaNumChannels = |
| 1801 | [](const LoggedAudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1802 | if (ana_event.config.num_channels) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1803 | return absl::optional<float>( |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1804 | static_cast<float>(*ana_event.config.num_channels)); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1805 | return absl::optional<float>(); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1806 | }; |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1807 | auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1808 | return this->config_.GetCallTimeSec(packet.log_time_us()); |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1809 | }; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1810 | ProcessPoints<LoggedAudioNetworkAdaptationEvent>( |
Stefan Holmer | 1d4a227 | 2018-05-24 13:48:09 +0200 | [diff] [blame] | 1811 | ToCallTime, GetAnaNumChannels, |
| 1812 | parsed_log_.audio_network_adaptation_events(), &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1813 | plot->AppendTimeSeries(std::move(time_series)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 1814 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 1815 | "Time (s)", kLeftMargin, kRightMargin); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1816 | plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))", |
| 1817 | kBottomMargin, kTopMargin); |
| 1818 | plot->SetTitle("Reported audio encoder number of channels"); |
| 1819 | } |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1820 | |
| 1821 | class NetEqStreamInput : public test::NetEqInput { |
| 1822 | public: |
| 1823 | // Does not take any ownership, and all pointers must refer to valid objects |
| 1824 | // that outlive the one constructed. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1825 | NetEqStreamInput(const std::vector<LoggedRtpPacketIncoming>* packet_stream, |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1826 | const std::vector<LoggedAudioPlayoutEvent>* output_events, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1827 | absl::optional<int64_t> end_time_ms) |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1828 | : packet_stream_(*packet_stream), |
| 1829 | packet_stream_it_(packet_stream_.begin()), |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1830 | output_events_it_(output_events->begin()), |
| 1831 | output_events_end_(output_events->end()), |
| 1832 | end_time_ms_(end_time_ms) { |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1833 | RTC_DCHECK(packet_stream); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1834 | RTC_DCHECK(output_events); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1837 | absl::optional<int64_t> NextPacketTime() const override { |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1838 | if (packet_stream_it_ == packet_stream_.end()) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1839 | return absl::nullopt; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1840 | } |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1841 | if (end_time_ms_ && packet_stream_it_->rtp.log_time_ms() > *end_time_ms_) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1842 | return absl::nullopt; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1843 | } |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1844 | return packet_stream_it_->rtp.log_time_ms(); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1847 | absl::optional<int64_t> NextOutputEventTime() const override { |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1848 | if (output_events_it_ == output_events_end_) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1849 | return absl::nullopt; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1850 | } |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1851 | if (end_time_ms_ && output_events_it_->log_time_ms() > *end_time_ms_) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1852 | return absl::nullopt; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1853 | } |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1854 | return output_events_it_->log_time_ms(); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | std::unique_ptr<PacketData> PopPacket() override { |
| 1858 | if (packet_stream_it_ == packet_stream_.end()) { |
| 1859 | return std::unique_ptr<PacketData>(); |
| 1860 | } |
| 1861 | std::unique_ptr<PacketData> packet_data(new PacketData()); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1862 | packet_data->header = packet_stream_it_->rtp.header; |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1863 | packet_data->time_ms = packet_stream_it_->rtp.log_time_ms(); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1864 | |
| 1865 | // This is a header-only "dummy" packet. Set the payload to all zeros, with |
| 1866 | // length according to the virtual length. |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1867 | packet_data->payload.SetSize(packet_stream_it_->rtp.total_length - |
| 1868 | packet_stream_it_->rtp.header_length); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1869 | std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0); |
| 1870 | |
| 1871 | ++packet_stream_it_; |
| 1872 | return packet_data; |
| 1873 | } |
| 1874 | |
| 1875 | void AdvanceOutputEvent() override { |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1876 | if (output_events_it_ != output_events_end_) { |
| 1877 | ++output_events_it_; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | bool ended() const override { return !NextEventTime(); } |
| 1882 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1883 | absl::optional<RTPHeader> NextHeader() const override { |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1884 | if (packet_stream_it_ == packet_stream_.end()) { |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1885 | return absl::nullopt; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1886 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1887 | return packet_stream_it_->rtp.header; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | private: |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1891 | const std::vector<LoggedRtpPacketIncoming>& packet_stream_; |
| 1892 | std::vector<LoggedRtpPacketIncoming>::const_iterator packet_stream_it_; |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1893 | std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_it_; |
| 1894 | const std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_end_; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1895 | const absl::optional<int64_t> end_time_ms_; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1896 | }; |
| 1897 | |
| 1898 | namespace { |
Bjorn Terelius | 6c4b1b7 | 2019-01-11 13:01:29 +0100 | [diff] [blame] | 1899 | |
| 1900 | // Factory to create a "replacement decoder" that produces the decoded audio |
| 1901 | // by reading from a file rather than from the encoded payloads. |
| 1902 | class ReplacementAudioDecoderFactory : public AudioDecoderFactory { |
| 1903 | public: |
| 1904 | ReplacementAudioDecoderFactory(const absl::string_view replacement_file_name, |
| 1905 | int file_sample_rate_hz) |
| 1906 | : replacement_file_name_(replacement_file_name), |
| 1907 | file_sample_rate_hz_(file_sample_rate_hz) {} |
| 1908 | |
| 1909 | std::vector<AudioCodecSpec> GetSupportedDecoders() override { |
| 1910 | RTC_NOTREACHED(); |
| 1911 | return {}; |
| 1912 | } |
| 1913 | |
| 1914 | bool IsSupportedDecoder(const SdpAudioFormat& format) override { |
| 1915 | return true; |
| 1916 | } |
| 1917 | |
| 1918 | std::unique_ptr<AudioDecoder> MakeAudioDecoder( |
| 1919 | const SdpAudioFormat& format, |
| 1920 | absl::optional<AudioCodecPairId> codec_pair_id) override { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1921 | auto replacement_file = std::make_unique<test::ResampleInputAudioFile>( |
Bjorn Terelius | 6c4b1b7 | 2019-01-11 13:01:29 +0100 | [diff] [blame] | 1922 | replacement_file_name_, file_sample_rate_hz_); |
| 1923 | replacement_file->set_output_rate_hz(48000); |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1924 | return std::make_unique<test::FakeDecodeFromFile>( |
Bjorn Terelius | 6c4b1b7 | 2019-01-11 13:01:29 +0100 | [diff] [blame] | 1925 | std::move(replacement_file), 48000, false); |
| 1926 | } |
| 1927 | |
| 1928 | private: |
| 1929 | const std::string replacement_file_name_; |
| 1930 | const int file_sample_rate_hz_; |
| 1931 | }; |
| 1932 | |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1933 | // Creates a NetEq test object and all necessary input and output helpers. Runs |
| 1934 | // the test and returns the NetEqDelayAnalyzer object that was used to |
| 1935 | // instrument the test. |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 1936 | std::unique_ptr<test::NetEqStatsGetter> CreateNetEqTestAndRun( |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1937 | const std::vector<LoggedRtpPacketIncoming>* packet_stream, |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1938 | const std::vector<LoggedAudioPlayoutEvent>* output_events, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 1939 | absl::optional<int64_t> end_time_ms, |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1940 | const std::string& replacement_file_name, |
| 1941 | int file_sample_rate_hz) { |
| 1942 | std::unique_ptr<test::NetEqInput> input( |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1943 | new NetEqStreamInput(packet_stream, output_events, end_time_ms)); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1944 | |
| 1945 | constexpr int kReplacementPt = 127; |
| 1946 | std::set<uint8_t> cn_types; |
| 1947 | std::set<uint8_t> forbidden_types; |
| 1948 | input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt, |
| 1949 | cn_types, forbidden_types)); |
| 1950 | |
| 1951 | NetEq::Config config; |
| 1952 | config.max_packets_in_buffer = 200; |
| 1953 | config.enable_fast_accelerate = true; |
| 1954 | |
| 1955 | std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink()); |
| 1956 | |
Niels Möller | 3f651d8 | 2018-12-19 15:06:17 +0100 | [diff] [blame] | 1957 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory = |
Bjorn Terelius | 6c4b1b7 | 2019-01-11 13:01:29 +0100 | [diff] [blame] | 1958 | new rtc::RefCountedObject<ReplacementAudioDecoderFactory>( |
| 1959 | replacement_file_name, file_sample_rate_hz); |
Niels Möller | 3f651d8 | 2018-12-19 15:06:17 +0100 | [diff] [blame] | 1960 | |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 1961 | test::NetEqTest::DecoderMap codecs = { |
| 1962 | {kReplacementPt, SdpAudioFormat("l16", 48000, 1)}}; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1963 | |
| 1964 | std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb( |
| 1965 | new test::NetEqDelayAnalyzer); |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 1966 | std::unique_ptr<test::NetEqStatsGetter> neteq_stats_getter( |
| 1967 | new test::NetEqStatsGetter(std::move(delay_cb))); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1968 | test::DefaultNetEqTestErrorCallback error_cb; |
| 1969 | test::NetEqTest::Callbacks callbacks; |
| 1970 | callbacks.error_callback = &error_cb; |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 1971 | callbacks.post_insert_packet = neteq_stats_getter->delay_analyzer(); |
| 1972 | callbacks.get_audio_callback = neteq_stats_getter.get(); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1973 | |
Ivo Creusen | cee751a | 2020-01-16 17:17:09 +0100 | [diff] [blame] | 1974 | test::NetEqTest test(config, decoder_factory, codecs, /*text_log=*/nullptr, |
| 1975 | /*factory=*/nullptr, std::move(input), std::move(output), |
| 1976 | callbacks); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1977 | test.Run(); |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 1978 | return neteq_stats_getter; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1979 | } |
| 1980 | } // namespace |
| 1981 | |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 1982 | EventLogAnalyzer::NetEqStatsGetterMap EventLogAnalyzer::SimulateNetEq( |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1983 | const std::string& replacement_file_name, |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 1984 | int file_sample_rate_hz) const { |
| 1985 | NetEqStatsGetterMap neteq_stats; |
| 1986 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1987 | for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) { |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1988 | const uint32_t ssrc = stream.ssrc; |
| 1989 | if (!IsAudioSsrc(kIncomingPacket, ssrc)) |
| 1990 | continue; |
| 1991 | const std::vector<LoggedRtpPacketIncoming>* audio_packets = |
| 1992 | &stream.incoming_packets; |
| 1993 | if (audio_packets == nullptr) { |
| 1994 | // No incoming audio stream found. |
| 1995 | continue; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 1996 | } |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1997 | |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 1998 | RTC_DCHECK(neteq_stats.find(ssrc) == neteq_stats.end()); |
| 1999 | |
| 2000 | std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>::const_iterator |
| 2001 | output_events_it = parsed_log_.audio_playout_events().find(ssrc); |
| 2002 | if (output_events_it == parsed_log_.audio_playout_events().end()) { |
| 2003 | // Could not find output events with SSRC matching the input audio stream. |
| 2004 | // Using the first available stream of output events. |
| 2005 | output_events_it = parsed_log_.audio_playout_events().cbegin(); |
| 2006 | } |
| 2007 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 2008 | absl::optional<int64_t> end_time_ms = |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2009 | log_segments_.empty() |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 2010 | ? absl::nullopt |
| 2011 | : absl::optional<int64_t>(log_segments_.front().second / 1000); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2012 | |
| 2013 | neteq_stats[ssrc] = CreateNetEqTestAndRun( |
| 2014 | audio_packets, &output_events_it->second, end_time_ms, |
| 2015 | replacement_file_name, file_sample_rate_hz); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 2018 | return neteq_stats; |
| 2019 | } |
| 2020 | |
Minyue Li | c97933f | 2018-08-10 12:51:15 +0200 | [diff] [blame] | 2021 | // Given a NetEqStatsGetter and the SSRC that the NetEqStatsGetter was created |
| 2022 | // for, this method generates a plot for the jitter buffer delay profile. |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 2023 | void EventLogAnalyzer::CreateAudioJitterBufferGraph( |
Minyue Li | 01d2a67 | 2018-06-21 21:17:19 +0200 | [diff] [blame] | 2024 | uint32_t ssrc, |
| 2025 | const test::NetEqStatsGetter* stats_getter, |
Minyue Li | c6ff757 | 2018-05-04 09:46:44 +0200 | [diff] [blame] | 2026 | Plot* plot) const { |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2027 | test::NetEqDelayAnalyzer::Delays arrival_delay_ms; |
| 2028 | test::NetEqDelayAnalyzer::Delays corrected_arrival_delay_ms; |
| 2029 | test::NetEqDelayAnalyzer::Delays playout_delay_ms; |
| 2030 | test::NetEqDelayAnalyzer::Delays target_delay_ms; |
| 2031 | |
Minyue Li | 01d2a67 | 2018-06-21 21:17:19 +0200 | [diff] [blame] | 2032 | stats_getter->delay_analyzer()->CreateGraphs( |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2033 | &arrival_delay_ms, &corrected_arrival_delay_ms, &playout_delay_ms, |
| 2034 | &target_delay_ms); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 2035 | |
Minyue Li | c97933f | 2018-08-10 12:51:15 +0200 | [diff] [blame] | 2036 | TimeSeries time_series_packet_arrival("packet arrival delay", |
| 2037 | LineStyle::kLine); |
| 2038 | TimeSeries time_series_relative_packet_arrival( |
| 2039 | "Relative packet arrival delay", LineStyle::kLine); |
| 2040 | TimeSeries time_series_play_time("Playout delay", LineStyle::kLine); |
| 2041 | TimeSeries time_series_target_time("Target delay", LineStyle::kLine, |
| 2042 | PointStyle::kHighlight); |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2043 | |
| 2044 | for (const auto& data : arrival_delay_ms) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2045 | const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us. |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2046 | const float y = data.second; |
Minyue Li | c97933f | 2018-08-10 12:51:15 +0200 | [diff] [blame] | 2047 | time_series_packet_arrival.points.emplace_back(TimeSeriesPoint(x, y)); |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2048 | } |
| 2049 | for (const auto& data : corrected_arrival_delay_ms) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2050 | const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us. |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2051 | const float y = data.second; |
Minyue Li | c97933f | 2018-08-10 12:51:15 +0200 | [diff] [blame] | 2052 | time_series_relative_packet_arrival.points.emplace_back( |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2053 | TimeSeriesPoint(x, y)); |
| 2054 | } |
| 2055 | for (const auto& data : playout_delay_ms) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2056 | const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us. |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2057 | const float y = data.second; |
Minyue Li | c97933f | 2018-08-10 12:51:15 +0200 | [diff] [blame] | 2058 | time_series_play_time.points.emplace_back(TimeSeriesPoint(x, y)); |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2059 | } |
| 2060 | for (const auto& data : target_delay_ms) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2061 | const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us. |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2062 | const float y = data.second; |
Minyue Li | c97933f | 2018-08-10 12:51:15 +0200 | [diff] [blame] | 2063 | time_series_target_time.points.emplace_back(TimeSeriesPoint(x, y)); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
Minyue Li | c97933f | 2018-08-10 12:51:15 +0200 | [diff] [blame] | 2066 | plot->AppendTimeSeries(std::move(time_series_packet_arrival)); |
| 2067 | plot->AppendTimeSeries(std::move(time_series_relative_packet_arrival)); |
| 2068 | plot->AppendTimeSeries(std::move(time_series_play_time)); |
| 2069 | plot->AppendTimeSeries(std::move(time_series_target_time)); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 2070 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2071 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 2072 | "Time (s)", kLeftMargin, kRightMargin); |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2073 | plot->SetSuggestedYAxis(0, 1, "Relative delay (ms)", kBottomMargin, |
| 2074 | kTopMargin); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2075 | plot->SetTitle("NetEq timing for " + GetStreamName(kIncomingPacket, ssrc)); |
| 2076 | } |
| 2077 | |
Minyue Li | c9ac93f | 2018-06-26 13:01:32 +0200 | [diff] [blame] | 2078 | template <typename NetEqStatsType> |
| 2079 | void EventLogAnalyzer::CreateNetEqStatsGraphInternal( |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2080 | const NetEqStatsGetterMap& neteq_stats, |
Minyue Li | c9ac93f | 2018-06-26 13:01:32 +0200 | [diff] [blame] | 2081 | rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*( |
| 2082 | const test::NetEqStatsGetter*)> data_extractor, |
| 2083 | rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor, |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2084 | const std::string& plot_name, |
| 2085 | Plot* plot) const { |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2086 | std::map<uint32_t, TimeSeries> time_series; |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2087 | |
| 2088 | for (const auto& st : neteq_stats) { |
| 2089 | const uint32_t ssrc = st.first; |
Minyue Li | c9ac93f | 2018-06-26 13:01:32 +0200 | [diff] [blame] | 2090 | const std::vector<std::pair<int64_t, NetEqStatsType>>* data_vector = |
| 2091 | data_extractor(st.second.get()); |
| 2092 | for (const auto& data : *data_vector) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2093 | const float time = |
| 2094 | config_.GetCallTimeSec(data.first * 1000); // ms to us. |
Minyue Li | c9ac93f | 2018-06-26 13:01:32 +0200 | [diff] [blame] | 2095 | const float value = stats_extractor(data.second); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2096 | time_series[ssrc].points.emplace_back(TimeSeriesPoint(time, value)); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | for (auto& series : time_series) { |
| 2101 | series.second.label = GetStreamName(kIncomingPacket, series.first); |
| 2102 | series.second.line_style = LineStyle::kLine; |
| 2103 | plot->AppendTimeSeries(std::move(series.second)); |
| 2104 | } |
| 2105 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2106 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 2107 | "Time (s)", kLeftMargin, kRightMargin); |
Minyue Li | 45fc6df | 2018-06-21 11:47:14 +0200 | [diff] [blame] | 2108 | plot->SetSuggestedYAxis(0, 1, plot_name, kBottomMargin, kTopMargin); |
Minyue Li | 27e2b7d | 2018-05-07 15:20:24 +0200 | [diff] [blame] | 2109 | plot->SetTitle(plot_name); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 2110 | } |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2111 | |
Minyue Li | c9ac93f | 2018-06-26 13:01:32 +0200 | [diff] [blame] | 2112 | void EventLogAnalyzer::CreateNetEqNetworkStatsGraph( |
| 2113 | const NetEqStatsGetterMap& neteq_stats, |
| 2114 | rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor, |
| 2115 | const std::string& plot_name, |
| 2116 | Plot* plot) const { |
| 2117 | CreateNetEqStatsGraphInternal<NetEqNetworkStatistics>( |
| 2118 | neteq_stats, |
| 2119 | [](const test::NetEqStatsGetter* stats_getter) { |
| 2120 | return stats_getter->stats(); |
| 2121 | }, |
| 2122 | stats_extractor, plot_name, plot); |
| 2123 | } |
| 2124 | |
| 2125 | void EventLogAnalyzer::CreateNetEqLifetimeStatsGraph( |
| 2126 | const NetEqStatsGetterMap& neteq_stats, |
| 2127 | rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor, |
| 2128 | const std::string& plot_name, |
| 2129 | Plot* plot) const { |
| 2130 | CreateNetEqStatsGraphInternal<NetEqLifetimeStatistics>( |
| 2131 | neteq_stats, |
| 2132 | [](const test::NetEqStatsGetter* stats_getter) { |
| 2133 | return stats_getter->lifetime_stats(); |
| 2134 | }, |
| 2135 | stats_extractor, plot_name, plot); |
| 2136 | } |
| 2137 | |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2138 | void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) { |
| 2139 | std::map<uint32_t, TimeSeries> configs_by_cp_id; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2140 | for (const auto& config : parsed_log_.ice_candidate_pair_configs()) { |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2141 | if (configs_by_cp_id.find(config.candidate_pair_id) == |
| 2142 | configs_by_cp_id.end()) { |
| 2143 | const std::string candidate_pair_desc = |
| 2144 | GetCandidatePairLogDescriptionAsString(config); |
Qingsi Wang | 93a8439 | 2018-01-30 17:13:09 -0800 | [diff] [blame] | 2145 | configs_by_cp_id[config.candidate_pair_id] = |
| 2146 | TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" + |
| 2147 | candidate_pair_desc, |
| 2148 | LineStyle::kNone, PointStyle::kHighlight); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2149 | candidate_pair_desc_by_id_[config.candidate_pair_id] = |
| 2150 | candidate_pair_desc; |
| 2151 | } |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2152 | float x = config_.GetCallTimeSec(config.log_time_us()); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2153 | float y = static_cast<float>(config.type); |
| 2154 | configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y); |
| 2155 | } |
| 2156 | |
| 2157 | // TODO(qingsi): There can be a large number of candidate pairs generated by |
| 2158 | // certain calls and the frontend cannot render the chart in this case due to |
| 2159 | // the failure of generating a palette with the same number of colors. |
| 2160 | for (auto& kv : configs_by_cp_id) { |
| 2161 | plot->AppendTimeSeries(std::move(kv.second)); |
| 2162 | } |
| 2163 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2164 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 2165 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 2166 | plot->SetSuggestedYAxis(0, 3, "Config Type", kBottomMargin, kTopMargin); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2167 | plot->SetTitle("[IceEventLog] ICE candidate pair configs"); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 2168 | plot->SetYAxisTickLabels( |
| 2169 | {{static_cast<float>(IceCandidatePairConfigType::kAdded), "ADDED"}, |
| 2170 | {static_cast<float>(IceCandidatePairConfigType::kUpdated), "UPDATED"}, |
| 2171 | {static_cast<float>(IceCandidatePairConfigType::kDestroyed), |
| 2172 | "DESTROYED"}, |
| 2173 | {static_cast<float>(IceCandidatePairConfigType::kSelected), |
| 2174 | "SELECTED"}}); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId( |
| 2178 | uint32_t candidate_pair_id) { |
| 2179 | if (candidate_pair_desc_by_id_.find(candidate_pair_id) != |
| 2180 | candidate_pair_desc_by_id_.end()) { |
| 2181 | return candidate_pair_desc_by_id_[candidate_pair_id]; |
| 2182 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2183 | for (const auto& config : parsed_log_.ice_candidate_pair_configs()) { |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2184 | // TODO(qingsi): Add the handling of the "Updated" config event after the |
| 2185 | // visualization of property change for candidate pairs is introduced. |
| 2186 | if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) == |
| 2187 | candidate_pair_desc_by_id_.end()) { |
| 2188 | const std::string candidate_pair_desc = |
| 2189 | GetCandidatePairLogDescriptionAsString(config); |
| 2190 | candidate_pair_desc_by_id_[config.candidate_pair_id] = |
| 2191 | candidate_pair_desc; |
| 2192 | } |
| 2193 | } |
| 2194 | return candidate_pair_desc_by_id_[candidate_pair_id]; |
| 2195 | } |
| 2196 | |
| 2197 | void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) { |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 2198 | constexpr int kEventTypeOffset = |
| 2199 | static_cast<int>(IceCandidatePairConfigType::kNumValues); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2200 | std::map<uint32_t, TimeSeries> checks_by_cp_id; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2201 | for (const auto& event : parsed_log_.ice_candidate_pair_events()) { |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2202 | if (checks_by_cp_id.find(event.candidate_pair_id) == |
| 2203 | checks_by_cp_id.end()) { |
| 2204 | checks_by_cp_id[event.candidate_pair_id] = TimeSeries( |
Qingsi Wang | 93a8439 | 2018-01-30 17:13:09 -0800 | [diff] [blame] | 2205 | "[" + std::to_string(event.candidate_pair_id) + "]" + |
| 2206 | GetCandidatePairLogDescriptionFromId(event.candidate_pair_id), |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2207 | LineStyle::kNone, PointStyle::kHighlight); |
| 2208 | } |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2209 | float x = config_.GetCallTimeSec(event.log_time_us()); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 2210 | float y = static_cast<float>(event.type) + kEventTypeOffset; |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2211 | checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y); |
| 2212 | } |
| 2213 | |
| 2214 | // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph. |
| 2215 | for (auto& kv : checks_by_cp_id) { |
| 2216 | plot->AppendTimeSeries(std::move(kv.second)); |
| 2217 | } |
| 2218 | |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2219 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 2220 | "Time (s)", kLeftMargin, kRightMargin); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 2221 | plot->SetSuggestedYAxis(0, 4, "Connectivity State", kBottomMargin, |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2222 | kTopMargin); |
| 2223 | plot->SetTitle("[IceEventLog] ICE connectivity checks"); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 2224 | |
| 2225 | plot->SetYAxisTickLabels( |
| 2226 | {{static_cast<float>(IceCandidatePairEventType::kCheckSent) + |
| 2227 | kEventTypeOffset, |
| 2228 | "CHECK SENT"}, |
| 2229 | {static_cast<float>(IceCandidatePairEventType::kCheckReceived) + |
| 2230 | kEventTypeOffset, |
| 2231 | "CHECK RECEIVED"}, |
| 2232 | {static_cast<float>(IceCandidatePairEventType::kCheckResponseSent) + |
| 2233 | kEventTypeOffset, |
| 2234 | "RESPONSE SENT"}, |
| 2235 | {static_cast<float>(IceCandidatePairEventType::kCheckResponseReceived) + |
| 2236 | kEventTypeOffset, |
| 2237 | "RESPONSE RECEIVED"}}); |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 2238 | } |
| 2239 | |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 2240 | void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) { |
| 2241 | TimeSeries states("DTLS Transport State", LineStyle::kNone, |
| 2242 | PointStyle::kHighlight); |
| 2243 | for (const auto& event : parsed_log_.dtls_transport_states()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2244 | float x = config_.GetCallTimeSec(event.log_time_us()); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 2245 | float y = static_cast<float>(event.dtls_transport_state); |
| 2246 | states.points.emplace_back(x, y); |
| 2247 | } |
| 2248 | plot->AppendTimeSeries(std::move(states)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2249 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 2250 | "Time (s)", kLeftMargin, kRightMargin); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 2251 | plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues), |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 2252 | "Transport State", kBottomMargin, kTopMargin); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 2253 | plot->SetTitle("DTLS Transport State"); |
Bjorn Terelius | f640b87 | 2019-07-24 15:46:39 +0200 | [diff] [blame] | 2254 | plot->SetYAxisTickLabels( |
| 2255 | {{static_cast<float>(DtlsTransportState::kNew), "NEW"}, |
| 2256 | {static_cast<float>(DtlsTransportState::kConnecting), "CONNECTING"}, |
| 2257 | {static_cast<float>(DtlsTransportState::kConnected), "CONNECTED"}, |
| 2258 | {static_cast<float>(DtlsTransportState::kClosed), "CLOSED"}, |
| 2259 | {static_cast<float>(DtlsTransportState::kFailed), "FAILED"}}); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) { |
| 2263 | TimeSeries writable("DTLS Writable", LineStyle::kNone, |
| 2264 | PointStyle::kHighlight); |
| 2265 | for (const auto& event : parsed_log_.dtls_writable_states()) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2266 | float x = config_.GetCallTimeSec(event.log_time_us()); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 2267 | float y = static_cast<float>(event.writable); |
| 2268 | writable.points.emplace_back(x, y); |
| 2269 | } |
| 2270 | plot->AppendTimeSeries(std::move(writable)); |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2271 | plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(), |
| 2272 | "Time (s)", kLeftMargin, kRightMargin); |
Zach Stein | 10a5801 | 2018-12-07 12:26:28 -0800 | [diff] [blame] | 2273 | plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin); |
| 2274 | plot->SetTitle("DTLS Writable State"); |
| 2275 | } |
| 2276 | |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2277 | void EventLogAnalyzer::PrintNotifications(FILE* file) { |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2278 | fprintf(file, "========== TRIAGE NOTIFICATIONS ==========\n"); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2279 | for (const auto& alert : incoming_rtp_recv_time_gaps_) { |
| 2280 | fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str()); |
| 2281 | } |
| 2282 | for (const auto& alert : incoming_rtcp_recv_time_gaps_) { |
| 2283 | fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str()); |
| 2284 | } |
| 2285 | for (const auto& alert : outgoing_rtp_send_time_gaps_) { |
| 2286 | fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str()); |
| 2287 | } |
| 2288 | for (const auto& alert : outgoing_rtcp_send_time_gaps_) { |
| 2289 | fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str()); |
| 2290 | } |
| 2291 | for (const auto& alert : incoming_seq_num_jumps_) { |
| 2292 | fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str()); |
| 2293 | } |
| 2294 | for (const auto& alert : incoming_capture_time_jumps_) { |
| 2295 | fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str()); |
| 2296 | } |
| 2297 | for (const auto& alert : outgoing_seq_num_jumps_) { |
| 2298 | fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str()); |
| 2299 | } |
| 2300 | for (const auto& alert : outgoing_capture_time_jumps_) { |
| 2301 | fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str()); |
| 2302 | } |
| 2303 | for (const auto& alert : outgoing_high_loss_alerts_) { |
| 2304 | fprintf(file, " : %s\n", alert.ToString().c_str()); |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2305 | } |
| 2306 | fprintf(file, "========== END TRIAGE NOTIFICATIONS ==========\n"); |
| 2307 | } |
| 2308 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2309 | void EventLogAnalyzer::CreateStreamGapAlerts(PacketDirection direction) { |
| 2310 | // With 100 packets/s (~800kbps), false positives would require 10 s without |
| 2311 | // data. |
| 2312 | constexpr int64_t kMaxSeqNumJump = 1000; |
| 2313 | // With a 90 kHz clock, false positives would require 10 s without data. |
| 2314 | constexpr int64_t kMaxCaptureTimeJump = 900000; |
| 2315 | |
| 2316 | int64_t end_time_us = log_segments_.empty() |
| 2317 | ? std::numeric_limits<int64_t>::max() |
| 2318 | : log_segments_.front().second; |
| 2319 | |
| 2320 | SeqNumUnwrapper<uint16_t> seq_num_unwrapper; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 2321 | absl::optional<int64_t> last_seq_num; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2322 | SeqNumUnwrapper<uint32_t> capture_time_unwrapper; |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 2323 | absl::optional<int64_t> last_capture_time; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2324 | // Check for gaps in sequence numbers and capture timestamps. |
| 2325 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 2326 | for (const auto& packet : stream.packet_view) { |
| 2327 | if (packet.log_time_us() > end_time_us) { |
| 2328 | // Only process the first (LOG_START, LOG_END) segment. |
| 2329 | break; |
| 2330 | } |
| 2331 | |
| 2332 | int64_t seq_num = seq_num_unwrapper.Unwrap(packet.header.sequenceNumber); |
| 2333 | if (last_seq_num.has_value() && |
| 2334 | std::abs(seq_num - last_seq_num.value()) > kMaxSeqNumJump) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2335 | Alert_SeqNumJump(direction, |
| 2336 | config_.GetCallTimeSec(packet.log_time_us()), |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2337 | packet.header.ssrc); |
| 2338 | } |
| 2339 | last_seq_num.emplace(seq_num); |
| 2340 | |
| 2341 | int64_t capture_time = |
| 2342 | capture_time_unwrapper.Unwrap(packet.header.timestamp); |
| 2343 | if (last_capture_time.has_value() && |
| 2344 | std::abs(capture_time - last_capture_time.value()) > |
| 2345 | kMaxCaptureTimeJump) { |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2346 | Alert_CaptureTimeJump(direction, |
| 2347 | config_.GetCallTimeSec(packet.log_time_us()), |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2348 | packet.header.ssrc); |
| 2349 | } |
| 2350 | last_capture_time.emplace(capture_time); |
| 2351 | } |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | void EventLogAnalyzer::CreateTransmissionGapAlerts(PacketDirection direction) { |
| 2356 | constexpr int64_t kMaxRtpTransmissionGap = 500000; |
| 2357 | constexpr int64_t kMaxRtcpTransmissionGap = 2000000; |
| 2358 | int64_t end_time_us = log_segments_.empty() |
| 2359 | ? std::numeric_limits<int64_t>::max() |
| 2360 | : log_segments_.front().second; |
| 2361 | |
| 2362 | // TODO(terelius): The parser could provide a list of all packets, ordered |
| 2363 | // by time, for each direction. |
| 2364 | std::multimap<int64_t, const LoggedRtpPacket*> rtp_in_direction; |
| 2365 | for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) { |
| 2366 | for (const LoggedRtpPacket& rtp_packet : stream.packet_view) |
| 2367 | rtp_in_direction.emplace(rtp_packet.log_time_us(), &rtp_packet); |
| 2368 | } |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 2369 | absl::optional<int64_t> last_rtp_time; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2370 | for (const auto& kv : rtp_in_direction) { |
| 2371 | int64_t timestamp = kv.first; |
| 2372 | if (timestamp > end_time_us) { |
| 2373 | // Only process the first (LOG_START, LOG_END) segment. |
| 2374 | break; |
| 2375 | } |
| 2376 | int64_t duration = timestamp - last_rtp_time.value_or(0); |
| 2377 | if (last_rtp_time.has_value() && duration > kMaxRtpTransmissionGap) { |
| 2378 | // No packet sent/received for more than 500 ms. |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2379 | Alert_RtpLogTimeGap(direction, config_.GetCallTimeSec(timestamp), |
| 2380 | duration / 1000); |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2381 | } |
| 2382 | last_rtp_time.emplace(timestamp); |
| 2383 | } |
| 2384 | |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 2385 | absl::optional<int64_t> last_rtcp_time; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2386 | if (direction == kIncomingPacket) { |
| 2387 | for (const auto& rtcp : parsed_log_.incoming_rtcp_packets()) { |
| 2388 | if (rtcp.log_time_us() > end_time_us) { |
| 2389 | // Only process the first (LOG_START, LOG_END) segment. |
| 2390 | break; |
| 2391 | } |
| 2392 | int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0); |
| 2393 | if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) { |
| 2394 | // No feedback sent/received for more than 2000 ms. |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2395 | Alert_RtcpLogTimeGap(direction, |
| 2396 | config_.GetCallTimeSec(rtcp.log_time_us()), |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2397 | duration / 1000); |
| 2398 | } |
| 2399 | last_rtcp_time.emplace(rtcp.log_time_us()); |
| 2400 | } |
| 2401 | } else { |
| 2402 | for (const auto& rtcp : parsed_log_.outgoing_rtcp_packets()) { |
| 2403 | if (rtcp.log_time_us() > end_time_us) { |
| 2404 | // Only process the first (LOG_START, LOG_END) segment. |
| 2405 | break; |
| 2406 | } |
| 2407 | int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0); |
| 2408 | if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) { |
| 2409 | // No feedback sent/received for more than 2000 ms. |
Bjorn Terelius | 068fc35 | 2019-02-13 22:38:25 +0100 | [diff] [blame] | 2410 | Alert_RtcpLogTimeGap(direction, |
| 2411 | config_.GetCallTimeSec(rtcp.log_time_us()), |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2412 | duration / 1000); |
| 2413 | } |
| 2414 | last_rtcp_time.emplace(rtcp.log_time_us()); |
| 2415 | } |
| 2416 | } |
| 2417 | } |
| 2418 | |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2419 | // TODO(terelius): Notifications could possibly be generated by the same code |
| 2420 | // that produces the graphs. There is some code duplication that could be |
| 2421 | // avoided, but that might be solved anyway when we move functionality from the |
| 2422 | // analyzer to the parser. |
| 2423 | void EventLogAnalyzer::CreateTriageNotifications() { |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2424 | CreateStreamGapAlerts(kIncomingPacket); |
| 2425 | CreateStreamGapAlerts(kOutgoingPacket); |
| 2426 | CreateTransmissionGapAlerts(kIncomingPacket); |
| 2427 | CreateTransmissionGapAlerts(kOutgoingPacket); |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2428 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2429 | int64_t end_time_us = log_segments_.empty() |
| 2430 | ? std::numeric_limits<int64_t>::max() |
| 2431 | : log_segments_.front().second; |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2432 | |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2433 | constexpr double kMaxLossFraction = 0.05; |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2434 | // Loss feedback |
| 2435 | int64_t total_lost_packets = 0; |
| 2436 | int64_t total_expected_packets = 0; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2437 | for (auto& bwe_update : parsed_log_.bwe_loss_updates()) { |
| 2438 | if (bwe_update.log_time_us() > end_time_us) { |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2439 | // Only process the first (LOG_START, LOG_END) segment. |
| 2440 | break; |
| 2441 | } |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2442 | int64_t lost_packets = static_cast<double>(bwe_update.fraction_lost) / 255 * |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2443 | bwe_update.expected_packets; |
| 2444 | total_lost_packets += lost_packets; |
| 2445 | total_expected_packets += bwe_update.expected_packets; |
| 2446 | } |
| 2447 | double avg_outgoing_loss = |
| 2448 | static_cast<double>(total_lost_packets) / total_expected_packets; |
Bjorn Terelius | c4ca1d3 | 2018-04-27 14:33:34 +0200 | [diff] [blame] | 2449 | if (avg_outgoing_loss > kMaxLossFraction) { |
| 2450 | Alert_OutgoingHighLoss(avg_outgoing_loss); |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 2454 | } // namespace webrtc |