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