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