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