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