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