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