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