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