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