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