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