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