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 | |
| 11 | #include "webrtc/tools/event_log_visualizer/analyzer.h" |
| 12 | |
| 13 | #include <algorithm> |
| 14 | #include <limits> |
| 15 | #include <map> |
| 16 | #include <sstream> |
| 17 | #include <string> |
| 18 | #include <utility> |
| 19 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 20 | #include "webrtc/base/checks.h" |
stefan | 6a850c3 | 2016-07-29 10:28:08 -0700 | [diff] [blame] | 21 | #include "webrtc/base/logging.h" |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 22 | #include "webrtc/base/ptr_util.h" |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 23 | #include "webrtc/base/rate_statistics.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 24 | #include "webrtc/call/audio_receive_stream.h" |
| 25 | #include "webrtc/call/audio_send_stream.h" |
| 26 | #include "webrtc/call/call.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 27 | #include "webrtc/common_types.h" |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 28 | #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 29 | #include "webrtc/modules/include/module_common_types.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 30 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 31 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
danilchap | bf369fe | 2016-10-07 07:39:54 -0700 | [diff] [blame] | 32 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 33 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 34 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h" |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 35 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 36 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 37 | #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
| 38 | #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 39 | #include "webrtc/video_receive_stream.h" |
| 40 | #include "webrtc/video_send_stream.h" |
| 41 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 42 | namespace webrtc { |
| 43 | namespace plotting { |
| 44 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 45 | namespace { |
| 46 | |
elad.alon | ec304f9 | 2017-03-08 05:03:53 -0800 | [diff] [blame] | 47 | void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) { |
| 48 | auto pred = [](const PacketFeedback& packet_feedback) { |
| 49 | return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived; |
| 50 | }; |
| 51 | vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end()); |
| 52 | std::sort(vec->begin(), vec->end(), PacketFeedbackComparator()); |
| 53 | } |
| 54 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 55 | std::string SsrcToString(uint32_t ssrc) { |
| 56 | std::stringstream ss; |
| 57 | ss << "SSRC " << ssrc; |
| 58 | return ss.str(); |
| 59 | } |
| 60 | |
| 61 | // Checks whether an SSRC is contained in the list of desired SSRCs. |
| 62 | // Note that an empty SSRC list matches every SSRC. |
| 63 | bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) { |
| 64 | if (desired_ssrc.size() == 0) |
| 65 | return true; |
| 66 | return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) != |
| 67 | desired_ssrc.end(); |
| 68 | } |
| 69 | |
| 70 | double AbsSendTimeToMicroseconds(int64_t abs_send_time) { |
| 71 | // The timestamp is a fixed point representation with 6 bits for seconds |
| 72 | // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the |
| 73 | // time in seconds and then multiply by 1000000 to convert to microseconds. |
| 74 | static constexpr double kTimestampToMicroSec = |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 75 | 1000000.0 / static_cast<double>(1ul << 18); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 76 | return abs_send_time * kTimestampToMicroSec; |
| 77 | } |
| 78 | |
| 79 | // Computes the difference |later| - |earlier| where |later| and |earlier| |
| 80 | // are counters that wrap at |modulus|. The difference is chosen to have the |
| 81 | // least absolute value. For example if |modulus| is 8, then the difference will |
| 82 | // be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will |
| 83 | // be in [-4, 4]. |
| 84 | int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) { |
| 85 | RTC_DCHECK_LE(1, modulus); |
| 86 | RTC_DCHECK_LT(later, modulus); |
| 87 | RTC_DCHECK_LT(earlier, modulus); |
| 88 | int64_t difference = |
| 89 | static_cast<int64_t>(later) - static_cast<int64_t>(earlier); |
| 90 | int64_t max_difference = modulus / 2; |
| 91 | int64_t min_difference = max_difference - modulus + 1; |
| 92 | if (difference > max_difference) { |
| 93 | difference -= modulus; |
| 94 | } |
| 95 | if (difference < min_difference) { |
| 96 | difference += modulus; |
| 97 | } |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 98 | if (difference > max_difference / 2 || difference < min_difference / 2) { |
| 99 | LOG(LS_WARNING) << "Difference between" << later << " and " << earlier |
| 100 | << " expected to be in the range (" << min_difference / 2 |
| 101 | << "," << max_difference / 2 << ") but is " << difference |
| 102 | << ". Correct unwrapping is uncertain."; |
| 103 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 104 | return difference; |
| 105 | } |
| 106 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 107 | // Return default values for header extensions, to use on streams without stored |
| 108 | // mapping data. Currently this only applies to audio streams, since the mapping |
| 109 | // is not stored in the event log. |
| 110 | // TODO(ivoc): Remove this once this mapping is stored in the event log for |
| 111 | // audio streams. Tracking bug: webrtc:6399 |
| 112 | webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() { |
| 113 | webrtc::RtpHeaderExtensionMap default_map; |
danilchap | 4aecc58 | 2016-11-15 09:21:00 -0800 | [diff] [blame] | 114 | default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId); |
| 115 | default_map.Register<AbsoluteSendTime>( |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 116 | webrtc::RtpExtension::kAbsSendTimeDefaultId); |
| 117 | return default_map; |
| 118 | } |
| 119 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 120 | constexpr float kLeftMargin = 0.01f; |
| 121 | constexpr float kRightMargin = 0.02f; |
| 122 | constexpr float kBottomMargin = 0.02f; |
| 123 | constexpr float kTopMargin = 0.05f; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 124 | |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 125 | rtc::Optional<double> NetworkDelayDiff_AbsSendTime( |
| 126 | const LoggedRtpPacket& old_packet, |
| 127 | const LoggedRtpPacket& new_packet) { |
| 128 | if (old_packet.header.extension.hasAbsoluteSendTime && |
| 129 | new_packet.header.extension.hasAbsoluteSendTime) { |
| 130 | int64_t send_time_diff = WrappingDifference( |
| 131 | new_packet.header.extension.absoluteSendTime, |
| 132 | old_packet.header.extension.absoluteSendTime, 1ul << 24); |
| 133 | int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
| 134 | double delay_change_us = |
| 135 | recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff); |
| 136 | return rtc::Optional<double>(delay_change_us / 1000); |
| 137 | } else { |
| 138 | return rtc::Optional<double>(); |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 142 | rtc::Optional<double> NetworkDelayDiff_CaptureTime( |
| 143 | const LoggedRtpPacket& old_packet, |
| 144 | const LoggedRtpPacket& new_packet) { |
| 145 | int64_t send_time_diff = WrappingDifference( |
| 146 | new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32); |
| 147 | int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
| 148 | |
| 149 | const double kVideoSampleRate = 90000; |
| 150 | // TODO(terelius): We treat all streams as video for now, even though |
| 151 | // audio might be sampled at e.g. 16kHz, because it is really difficult to |
| 152 | // figure out the true sampling rate of a stream. The effect is that the |
| 153 | // delay will be scaled incorrectly for non-video streams. |
| 154 | |
| 155 | double delay_change = |
| 156 | static_cast<double>(recv_time_diff) / 1000 - |
| 157 | static_cast<double>(send_time_diff) / kVideoSampleRate * 1000; |
| 158 | if (delay_change < -10000 || 10000 < delay_change) { |
| 159 | LOG(LS_WARNING) << "Very large delay change. Timestamps correct?"; |
| 160 | LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp |
| 161 | << ", received time " << old_packet.timestamp; |
| 162 | LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp |
| 163 | << ", received time " << new_packet.timestamp; |
| 164 | LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = " |
| 165 | << static_cast<double>(recv_time_diff) / 1000000 << "s"; |
| 166 | LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = " |
| 167 | << static_cast<double>(send_time_diff) / kVideoSampleRate |
| 168 | << "s"; |
| 169 | } |
| 170 | return rtc::Optional<double>(delay_change); |
| 171 | } |
| 172 | |
| 173 | // For each element in data, use |get_y()| to extract a y-coordinate and |
| 174 | // store the result in a TimeSeries. |
| 175 | template <typename DataType> |
| 176 | void ProcessPoints( |
| 177 | rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y, |
| 178 | const std::vector<DataType>& data, |
| 179 | uint64_t begin_time, |
| 180 | TimeSeries* result) { |
| 181 | for (size_t i = 0; i < data.size(); i++) { |
| 182 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
| 183 | rtc::Optional<float> y = get_y(data[i]); |
| 184 | if (y) |
| 185 | result->points.emplace_back(x, *y); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // 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] | 190 | // y-coordinate and store the result in a TimeSeries. Note that the x-coordinate |
| 191 | // will be the time of the second element in the pair. |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 192 | template <typename DataType, typename ResultType> |
| 193 | void ProcessPairs( |
| 194 | rtc::FunctionView<rtc::Optional<ResultType>(const DataType&, |
| 195 | const DataType&)> get_y, |
| 196 | const std::vector<DataType>& data, |
| 197 | uint64_t begin_time, |
| 198 | TimeSeries* result) { |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 199 | for (size_t i = 1; i < data.size(); i++) { |
| 200 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 201 | rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]); |
| 202 | if (y) |
| 203 | result->points.emplace_back(x, static_cast<float>(*y)); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // For each element in data, use |extract()| to extract a y-coordinate and |
| 208 | // store the result in a TimeSeries. |
| 209 | template <typename DataType, typename ResultType> |
| 210 | void AccumulatePoints( |
| 211 | rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract, |
| 212 | const std::vector<DataType>& data, |
| 213 | uint64_t begin_time, |
| 214 | TimeSeries* result) { |
| 215 | ResultType sum = 0; |
| 216 | for (size_t i = 0; i < data.size(); i++) { |
| 217 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
| 218 | rtc::Optional<ResultType> y = extract(data[i]); |
| 219 | if (y) { |
| 220 | sum += *y; |
| 221 | result->points.emplace_back(x, static_cast<float>(sum)); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // For each pair of adjacent elements in |data|, use |extract()| to extract a |
| 227 | // y-coordinate and store the result in a TimeSeries. Note that the x-coordinate |
| 228 | // will be the time of the second element in the pair. |
| 229 | template <typename DataType, typename ResultType> |
| 230 | void AccumulatePairs( |
| 231 | rtc::FunctionView<rtc::Optional<ResultType>(const DataType&, |
| 232 | const DataType&)> extract, |
| 233 | const std::vector<DataType>& data, |
| 234 | uint64_t begin_time, |
| 235 | TimeSeries* result) { |
| 236 | ResultType sum = 0; |
| 237 | for (size_t i = 1; i < data.size(); i++) { |
| 238 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
| 239 | rtc::Optional<ResultType> y = extract(data[i - 1], data[i]); |
| 240 | if (y) |
| 241 | sum += *y; |
| 242 | result->points.emplace_back(x, static_cast<float>(sum)); |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 246 | // Calculates a moving average of |data| and stores the result in a TimeSeries. |
| 247 | // A data point is generated every |step| microseconds from |begin_time| |
| 248 | // to |end_time|. The value of each data point is the average of the data |
| 249 | // during the preceeding |window_duration_us| microseconds. |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 250 | template <typename DataType, typename ResultType> |
| 251 | void MovingAverage( |
| 252 | rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract, |
| 253 | const std::vector<DataType>& data, |
| 254 | uint64_t begin_time, |
| 255 | uint64_t end_time, |
| 256 | uint64_t window_duration_us, |
| 257 | uint64_t step, |
| 258 | webrtc::plotting::TimeSeries* result) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 259 | size_t window_index_begin = 0; |
| 260 | size_t window_index_end = 0; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 261 | ResultType sum_in_window = 0; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 262 | |
| 263 | for (uint64_t t = begin_time; t < end_time + step; t += step) { |
| 264 | while (window_index_end < data.size() && |
| 265 | data[window_index_end].timestamp < t) { |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 266 | rtc::Optional<ResultType> value = extract(data[window_index_end]); |
| 267 | if (value) |
| 268 | sum_in_window += *value; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 269 | ++window_index_end; |
| 270 | } |
| 271 | while (window_index_begin < data.size() && |
| 272 | data[window_index_begin].timestamp < t - window_duration_us) { |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 273 | rtc::Optional<ResultType> value = extract(data[window_index_begin]); |
| 274 | if (value) |
| 275 | sum_in_window -= *value; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 276 | ++window_index_begin; |
| 277 | } |
| 278 | float window_duration_s = static_cast<float>(window_duration_us) / 1000000; |
| 279 | float x = static_cast<float>(t - begin_time) / 1000000; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 280 | float y = sum_in_window / window_duration_s; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 281 | result->points.emplace_back(x, y); |
| 282 | } |
| 283 | } |
| 284 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 285 | } // namespace |
| 286 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 287 | EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log) |
| 288 | : parsed_log_(log), window_duration_(250000), step_(10000) { |
| 289 | uint64_t first_timestamp = std::numeric_limits<uint64_t>::max(); |
| 290 | uint64_t last_timestamp = std::numeric_limits<uint64_t>::min(); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 291 | |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 292 | PacketDirection direction; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 293 | uint8_t header[IP_PACKET_SIZE]; |
| 294 | size_t header_length; |
| 295 | size_t total_length; |
| 296 | |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 297 | uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE]; |
| 298 | uint8_t last_incoming_rtcp_packet_length = 0; |
| 299 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 300 | // Make a default extension map for streams without configuration information. |
| 301 | // TODO(ivoc): Once configuration of audio streams is stored in the event log, |
| 302 | // this can be removed. Tracking bug: webrtc:6399 |
| 303 | RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap(); |
| 304 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 305 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 306 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 307 | if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT && |
| 308 | event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT && |
| 309 | event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT && |
terelius | 88c1d2b | 2016-08-01 05:20:33 -0700 | [diff] [blame] | 310 | event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT && |
| 311 | event_type != ParsedRtcEventLog::LOG_START && |
| 312 | event_type != ParsedRtcEventLog::LOG_END) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 313 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 314 | first_timestamp = std::min(first_timestamp, timestamp); |
| 315 | last_timestamp = std::max(last_timestamp, timestamp); |
| 316 | } |
| 317 | |
| 318 | switch (parsed_log_.GetEventType(i)) { |
| 319 | case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: { |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 320 | rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i); |
perkj | 09e71da | 2017-05-22 03:26:49 -0700 | [diff] [blame] | 321 | StreamId stream(config.remote_ssrc, kIncomingPacket); |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 322 | video_ssrcs_.insert(stream); |
perkj | 09e71da | 2017-05-22 03:26:49 -0700 | [diff] [blame] | 323 | StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 324 | video_ssrcs_.insert(rtx_stream); |
| 325 | rtx_ssrcs_.insert(rtx_stream); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 326 | break; |
| 327 | } |
| 328 | case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: { |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 329 | std::vector<rtclog::StreamConfig> configs = |
| 330 | parsed_log_.GetVideoSendConfig(i); |
terelius | 405f90c | 2017-06-01 03:50:31 -0700 | [diff] [blame] | 331 | for (const auto& config : configs) { |
| 332 | StreamId stream(config.local_ssrc, kOutgoingPacket); |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 333 | video_ssrcs_.insert(stream); |
terelius | 405f90c | 2017-06-01 03:50:31 -0700 | [diff] [blame] | 334 | StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket); |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 335 | video_ssrcs_.insert(rtx_stream); |
| 336 | rtx_ssrcs_.insert(rtx_stream); |
| 337 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 338 | break; |
| 339 | } |
| 340 | case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: { |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 341 | rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i); |
perkj | ac8f52d | 2017-05-22 09:36:28 -0700 | [diff] [blame] | 342 | StreamId stream(config.remote_ssrc, kIncomingPacket); |
ivoc | e0928d8 | 2016-10-10 05:12:51 -0700 | [diff] [blame] | 343 | audio_ssrcs_.insert(stream); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 344 | break; |
| 345 | } |
| 346 | case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: { |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 347 | rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i); |
perkj | f472699 | 2017-05-22 10:12:26 -0700 | [diff] [blame] | 348 | StreamId stream(config.local_ssrc, kOutgoingPacket); |
ivoc | e0928d8 | 2016-10-10 05:12:51 -0700 | [diff] [blame] | 349 | audio_ssrcs_.insert(stream); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 350 | break; |
| 351 | } |
| 352 | case ParsedRtcEventLog::RTP_EVENT: { |
ilnik | a8e781a | 2017-06-12 01:02:46 -0700 | [diff] [blame^] | 353 | RtpHeaderExtensionMap* extension_map = parsed_log_.GetRtpHeader( |
| 354 | i, &direction, header, &header_length, &total_length); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 355 | RtpUtility::RtpHeaderParser rtp_parser(header, header_length); |
| 356 | RTPHeader parsed_header; |
ilnik | a8e781a | 2017-06-12 01:02:46 -0700 | [diff] [blame^] | 357 | if (extension_map != nullptr) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 358 | rtp_parser.Parse(&parsed_header, extension_map); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 359 | } else { |
| 360 | // Use the default extension map. |
| 361 | // TODO(ivoc): Once configuration of audio streams is stored in the |
| 362 | // event log, this can be removed. |
| 363 | // Tracking bug: webrtc:6399 |
| 364 | rtp_parser.Parse(&parsed_header, &default_extension_map); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 365 | } |
| 366 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
ilnik | a8e781a | 2017-06-12 01:02:46 -0700 | [diff] [blame^] | 367 | StreamId stream(parsed_header.ssrc, direction); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 368 | rtp_packets_[stream].push_back( |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 369 | LoggedRtpPacket(timestamp, parsed_header, total_length)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 370 | break; |
| 371 | } |
| 372 | case ParsedRtcEventLog::RTCP_EVENT: { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 373 | uint8_t packet[IP_PACKET_SIZE]; |
perkj | 77cd58e | 2017-05-30 03:52:10 -0700 | [diff] [blame] | 374 | parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length); |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 375 | // Currently incoming RTCP packets are logged twice, both for audio and |
| 376 | // video. Only act on one of them. Compare against the previous parsed |
| 377 | // incoming RTCP packet. |
| 378 | if (direction == webrtc::kIncomingPacket) { |
| 379 | RTC_CHECK_LE(total_length, IP_PACKET_SIZE); |
| 380 | if (total_length == last_incoming_rtcp_packet_length && |
| 381 | memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) { |
| 382 | continue; |
| 383 | } else { |
| 384 | memcpy(last_incoming_rtcp_packet, packet, total_length); |
| 385 | last_incoming_rtcp_packet_length = total_length; |
| 386 | } |
| 387 | } |
| 388 | rtcp::CommonHeader header; |
| 389 | const uint8_t* packet_end = packet + total_length; |
| 390 | for (const uint8_t* block = packet; block < packet_end; |
| 391 | block = header.NextPacket()) { |
| 392 | RTC_CHECK(header.Parse(block, packet_end - block)); |
| 393 | if (header.type() == rtcp::TransportFeedback::kPacketType && |
| 394 | header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) { |
| 395 | std::unique_ptr<rtcp::TransportFeedback> rtcp_packet( |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 396 | rtc::MakeUnique<rtcp::TransportFeedback>()); |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 397 | if (rtcp_packet->Parse(header)) { |
| 398 | uint32_t ssrc = rtcp_packet->sender_ssrc(); |
| 399 | StreamId stream(ssrc, direction); |
| 400 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 401 | rtcp_packets_[stream].push_back(LoggedRtcpPacket( |
| 402 | timestamp, kRtcpTransportFeedback, std::move(rtcp_packet))); |
| 403 | } |
| 404 | } else if (header.type() == rtcp::SenderReport::kPacketType) { |
| 405 | std::unique_ptr<rtcp::SenderReport> rtcp_packet( |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 406 | rtc::MakeUnique<rtcp::SenderReport>()); |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 407 | if (rtcp_packet->Parse(header)) { |
| 408 | uint32_t ssrc = rtcp_packet->sender_ssrc(); |
| 409 | StreamId stream(ssrc, direction); |
| 410 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 411 | rtcp_packets_[stream].push_back( |
| 412 | LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet))); |
| 413 | } |
| 414 | } else if (header.type() == rtcp::ReceiverReport::kPacketType) { |
| 415 | std::unique_ptr<rtcp::ReceiverReport> rtcp_packet( |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 416 | rtc::MakeUnique<rtcp::ReceiverReport>()); |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 417 | if (rtcp_packet->Parse(header)) { |
| 418 | uint32_t ssrc = rtcp_packet->sender_ssrc(); |
| 419 | StreamId stream(ssrc, direction); |
| 420 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 421 | rtcp_packets_[stream].push_back( |
| 422 | LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet))); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 423 | } |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 424 | } else if (header.type() == rtcp::Remb::kPacketType && |
| 425 | header.fmt() == rtcp::Remb::kFeedbackMessageType) { |
| 426 | std::unique_ptr<rtcp::Remb> rtcp_packet( |
| 427 | rtc::MakeUnique<rtcp::Remb>()); |
| 428 | if (rtcp_packet->Parse(header)) { |
| 429 | uint32_t ssrc = rtcp_packet->sender_ssrc(); |
| 430 | StreamId stream(ssrc, direction); |
| 431 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 432 | rtcp_packets_[stream].push_back(LoggedRtcpPacket( |
| 433 | timestamp, kRtcpRemb, std::move(rtcp_packet))); |
| 434 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 435 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 436 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 437 | break; |
| 438 | } |
| 439 | case ParsedRtcEventLog::LOG_START: { |
| 440 | break; |
| 441 | } |
| 442 | case ParsedRtcEventLog::LOG_END: { |
| 443 | break; |
| 444 | } |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 445 | case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: { |
| 446 | break; |
| 447 | } |
| 448 | case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: { |
| 449 | LossBasedBweUpdate bwe_update; |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 450 | bwe_update.timestamp = parsed_log_.GetTimestamp(i); |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 451 | parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate, |
| 452 | &bwe_update.fraction_loss, |
| 453 | &bwe_update.expected_packets); |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 454 | bwe_loss_updates_.push_back(bwe_update); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 455 | break; |
| 456 | } |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 457 | case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: { |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 458 | bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i)); |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 459 | break; |
| 460 | } |
minyue | 4b7c952 | 2017-01-24 04:54:59 -0800 | [diff] [blame] | 461 | case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 462 | AudioNetworkAdaptationEvent ana_event; |
| 463 | ana_event.timestamp = parsed_log_.GetTimestamp(i); |
| 464 | parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config); |
| 465 | audio_network_adaptation_events_.push_back(ana_event); |
minyue | 4b7c952 | 2017-01-24 04:54:59 -0800 | [diff] [blame] | 466 | break; |
| 467 | } |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 468 | case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: { |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 469 | bwe_probe_cluster_created_events_.push_back( |
| 470 | parsed_log_.GetBweProbeClusterCreated(i)); |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 471 | break; |
| 472 | } |
| 473 | case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: { |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 474 | bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i)); |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 475 | break; |
| 476 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 477 | case ParsedRtcEventLog::UNKNOWN_EVENT: { |
| 478 | break; |
| 479 | } |
| 480 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 481 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 482 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 483 | if (last_timestamp < first_timestamp) { |
| 484 | // No useful events in the log. |
| 485 | first_timestamp = last_timestamp = 0; |
| 486 | } |
| 487 | begin_time_ = first_timestamp; |
| 488 | end_time_ = last_timestamp; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 489 | call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 492 | class BitrateObserver : public CongestionController::Observer, |
| 493 | public RemoteBitrateObserver { |
| 494 | public: |
| 495 | BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {} |
| 496 | |
minyue | 78b4d56 | 2016-11-30 04:47:39 -0800 | [diff] [blame] | 497 | // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See |
| 498 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796 |
| 499 | using CongestionController::Observer::OnNetworkChanged; |
| 500 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 501 | void OnNetworkChanged(uint32_t bitrate_bps, |
| 502 | uint8_t fraction_loss, |
minyue | 78b4d56 | 2016-11-30 04:47:39 -0800 | [diff] [blame] | 503 | int64_t rtt_ms, |
| 504 | int64_t probing_interval_ms) override { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 505 | last_bitrate_bps_ = bitrate_bps; |
| 506 | bitrate_updated_ = true; |
| 507 | } |
| 508 | |
| 509 | void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 510 | uint32_t bitrate) override {} |
| 511 | |
| 512 | uint32_t last_bitrate_bps() const { return last_bitrate_bps_; } |
| 513 | bool GetAndResetBitrateUpdated() { |
| 514 | bool bitrate_updated = bitrate_updated_; |
| 515 | bitrate_updated_ = false; |
| 516 | return bitrate_updated; |
| 517 | } |
| 518 | |
| 519 | private: |
| 520 | uint32_t last_bitrate_bps_; |
| 521 | bool bitrate_updated_; |
| 522 | }; |
| 523 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 524 | bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 525 | return rtx_ssrcs_.count(stream_id) == 1; |
| 526 | } |
| 527 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 528 | bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 529 | return video_ssrcs_.count(stream_id) == 1; |
| 530 | } |
| 531 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 532 | bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 533 | return audio_ssrcs_.count(stream_id) == 1; |
| 534 | } |
| 535 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 536 | std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const { |
| 537 | std::stringstream name; |
| 538 | if (IsAudioSsrc(stream_id)) { |
| 539 | name << "Audio "; |
| 540 | } else if (IsVideoSsrc(stream_id)) { |
| 541 | name << "Video "; |
| 542 | } else { |
| 543 | name << "Unknown "; |
| 544 | } |
| 545 | if (IsRtxSsrc(stream_id)) |
| 546 | name << "RTX "; |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 547 | if (stream_id.GetDirection() == kIncomingPacket) { |
| 548 | name << "(In) "; |
| 549 | } else { |
| 550 | name << "(Out) "; |
| 551 | } |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 552 | name << SsrcToString(stream_id.GetSsrc()); |
| 553 | return name.str(); |
| 554 | } |
| 555 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 556 | void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction, |
| 557 | Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 558 | for (auto& kv : rtp_packets_) { |
| 559 | StreamId stream_id = kv.first; |
| 560 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 561 | // Filter on direction and SSRC. |
| 562 | if (stream_id.GetDirection() != desired_direction || |
| 563 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 564 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 565 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 566 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 567 | TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 568 | ProcessPoints<LoggedRtpPacket>( |
| 569 | [](const LoggedRtpPacket& packet) -> rtc::Optional<float> { |
| 570 | return rtc::Optional<float>(packet.total_length); |
| 571 | }, |
| 572 | packet_stream, begin_time_, &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 573 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 574 | } |
| 575 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 576 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 577 | plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin, |
| 578 | kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 579 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 580 | plot->SetTitle("Incoming RTP packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 581 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 582 | plot->SetTitle("Outgoing RTP packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 586 | template <typename T> |
| 587 | void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries( |
| 588 | PacketDirection desired_direction, |
| 589 | Plot* plot, |
| 590 | const std::map<StreamId, std::vector<T>>& packets, |
| 591 | const std::string& label_prefix) { |
| 592 | for (auto& kv : packets) { |
| 593 | StreamId stream_id = kv.first; |
| 594 | const std::vector<T>& packet_stream = kv.second; |
| 595 | // Filter on direction and SSRC. |
| 596 | if (stream_id.GetDirection() != desired_direction || |
| 597 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 598 | continue; |
| 599 | } |
| 600 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 601 | std::string label = label_prefix + " " + GetStreamName(stream_id); |
| 602 | TimeSeries time_series(label, LINE_STEP_GRAPH); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 603 | for (size_t i = 0; i < packet_stream.size(); i++) { |
| 604 | float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) / |
| 605 | 1000000; |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 606 | time_series.points.emplace_back(x, i + 1); |
| 607 | } |
| 608 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 609 | plot->AppendTimeSeries(std::move(time_series)); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
| 613 | void EventLogAnalyzer::CreateAccumulatedPacketsGraph( |
| 614 | PacketDirection desired_direction, |
| 615 | Plot* plot) { |
| 616 | CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_, |
| 617 | "RTP"); |
| 618 | CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_, |
| 619 | "RTCP"); |
| 620 | |
| 621 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 622 | plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin); |
| 623 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
| 624 | plot->SetTitle("Accumulated Incoming RTP/RTCP packets"); |
| 625 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
| 626 | plot->SetTitle("Accumulated Outgoing RTP/RTCP packets"); |
| 627 | } |
| 628 | } |
| 629 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 630 | // For each SSRC, plot the time between the consecutive playouts. |
| 631 | void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) { |
| 632 | std::map<uint32_t, TimeSeries> time_series; |
| 633 | std::map<uint32_t, uint64_t> last_playout; |
| 634 | |
| 635 | uint32_t ssrc; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 636 | |
| 637 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 638 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
| 639 | if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) { |
| 640 | parsed_log_.GetAudioPlayout(i, &ssrc); |
| 641 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 642 | if (MatchingSsrc(ssrc, desired_ssrc_)) { |
| 643 | float x = static_cast<float>(timestamp - begin_time_) / 1000000; |
| 644 | float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000; |
| 645 | if (time_series[ssrc].points.size() == 0) { |
| 646 | // There were no previusly logged playout for this SSRC. |
| 647 | // Generate a point, but place it on the x-axis. |
| 648 | y = 0; |
| 649 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 650 | time_series[ssrc].points.push_back(TimeSeriesPoint(x, y)); |
| 651 | last_playout[ssrc] = timestamp; |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | // Set labels and put in graph. |
| 657 | for (auto& kv : time_series) { |
| 658 | kv.second.label = SsrcToString(kv.first); |
| 659 | kv.second.style = BAR_GRAPH; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 660 | plot->AppendTimeSeries(std::move(kv.second)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 661 | } |
| 662 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 663 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 664 | plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin, |
| 665 | kTopMargin); |
| 666 | plot->SetTitle("Audio playout"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 667 | } |
| 668 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 669 | // For audio SSRCs, plot the audio level. |
| 670 | void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) { |
| 671 | std::map<StreamId, TimeSeries> time_series; |
| 672 | |
| 673 | for (auto& kv : rtp_packets_) { |
| 674 | StreamId stream_id = kv.first; |
| 675 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 676 | // TODO(ivoc): When audio send/receive configs are stored in the event |
| 677 | // log, a check should be added here to only process audio |
| 678 | // streams. Tracking bug: webrtc:6399 |
| 679 | for (auto& packet : packet_stream) { |
| 680 | if (packet.header.extension.hasAudioLevel) { |
| 681 | float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000; |
| 682 | // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10) |
| 683 | // Here we convert it to dBov. |
| 684 | float y = static_cast<float>(-packet.header.extension.audioLevel); |
| 685 | time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y)); |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | for (auto& series : time_series) { |
| 691 | series.second.label = GetStreamName(series.first); |
| 692 | series.second.style = LINE_GRAPH; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 693 | plot->AppendTimeSeries(std::move(series.second)); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
ivoc | bf67663 | 2016-11-24 08:30:34 -0800 | [diff] [blame] | 697 | plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 698 | kTopMargin); |
| 699 | plot->SetTitle("Audio level"); |
| 700 | } |
| 701 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 702 | // For each SSRC, plot the time between the consecutive playouts. |
| 703 | void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 704 | for (auto& kv : rtp_packets_) { |
| 705 | StreamId stream_id = kv.first; |
| 706 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 707 | // Filter on direction and SSRC. |
| 708 | if (stream_id.GetDirection() != kIncomingPacket || |
| 709 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 710 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 711 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 712 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 713 | TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 714 | ProcessPairs<LoggedRtpPacket, float>( |
| 715 | [](const LoggedRtpPacket& old_packet, |
| 716 | const LoggedRtpPacket& new_packet) { |
| 717 | int64_t diff = |
| 718 | WrappingDifference(new_packet.header.sequenceNumber, |
| 719 | old_packet.header.sequenceNumber, 1ul << 16); |
| 720 | return rtc::Optional<float>(diff); |
| 721 | }, |
| 722 | packet_stream, begin_time_, &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 723 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 724 | } |
| 725 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 726 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 727 | plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin, |
| 728 | kTopMargin); |
| 729 | plot->SetTitle("Sequence number"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 732 | void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) { |
| 733 | for (auto& kv : rtp_packets_) { |
| 734 | StreamId stream_id = kv.first; |
| 735 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 736 | // Filter on direction and SSRC. |
| 737 | if (stream_id.GetDirection() != kIncomingPacket || |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 738 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) || |
| 739 | packet_stream.size() == 0) { |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 740 | continue; |
| 741 | } |
| 742 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 743 | TimeSeries time_series(GetStreamName(stream_id), LINE_DOT_GRAPH); |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 744 | const uint64_t kWindowUs = 1000000; |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 745 | const uint64_t kStep = 1000000; |
| 746 | SequenceNumberUnwrapper unwrapper_; |
| 747 | SequenceNumberUnwrapper prior_unwrapper_; |
| 748 | size_t window_index_begin = 0; |
| 749 | size_t window_index_end = 0; |
| 750 | int64_t highest_seq_number = |
| 751 | unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1; |
| 752 | int64_t highest_prior_seq_number = |
| 753 | prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1; |
| 754 | |
| 755 | for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) { |
| 756 | while (window_index_end < packet_stream.size() && |
| 757 | packet_stream[window_index_end].timestamp < t) { |
| 758 | int64_t sequence_number = unwrapper_.Unwrap( |
| 759 | packet_stream[window_index_end].header.sequenceNumber); |
| 760 | highest_seq_number = std::max(highest_seq_number, sequence_number); |
| 761 | ++window_index_end; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 762 | } |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 763 | while (window_index_begin < packet_stream.size() && |
| 764 | packet_stream[window_index_begin].timestamp < t - kWindowUs) { |
| 765 | int64_t sequence_number = prior_unwrapper_.Unwrap( |
| 766 | packet_stream[window_index_begin].header.sequenceNumber); |
| 767 | highest_prior_seq_number = |
| 768 | std::max(highest_prior_seq_number, sequence_number); |
| 769 | ++window_index_begin; |
| 770 | } |
| 771 | float x = static_cast<float>(t - begin_time_) / 1000000; |
| 772 | int64_t expected_packets = highest_seq_number - highest_prior_seq_number; |
| 773 | if (expected_packets > 0) { |
| 774 | int64_t received_packets = window_index_end - window_index_begin; |
| 775 | int64_t lost_packets = expected_packets - received_packets; |
| 776 | float y = static_cast<float>(lost_packets) / expected_packets * 100; |
| 777 | time_series.points.emplace_back(x, y); |
| 778 | } |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 779 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 780 | plot->AppendTimeSeries(std::move(time_series)); |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 784 | plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin, |
| 785 | kTopMargin); |
| 786 | plot->SetTitle("Estimated incoming loss rate"); |
| 787 | } |
| 788 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 789 | void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 790 | for (auto& kv : rtp_packets_) { |
| 791 | StreamId stream_id = kv.first; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 792 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 793 | // Filter on direction and SSRC. |
| 794 | if (stream_id.GetDirection() != kIncomingPacket || |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 795 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) || |
| 796 | IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) || |
| 797 | IsRtxSsrc(stream_id)) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 798 | continue; |
| 799 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 800 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 801 | TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time", |
| 802 | BAR_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 803 | ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime, |
| 804 | packet_stream, begin_time_, |
| 805 | &capture_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 806 | plot->AppendTimeSeries(std::move(capture_time_data)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 807 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 808 | TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time", |
| 809 | BAR_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 810 | ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime, |
| 811 | packet_stream, begin_time_, |
| 812 | &send_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 813 | plot->AppendTimeSeries(std::move(send_time_data)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 814 | } |
| 815 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 816 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 817 | plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin, |
| 818 | kTopMargin); |
| 819 | plot->SetTitle("Network latency change between consecutive packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 823 | for (auto& kv : rtp_packets_) { |
| 824 | StreamId stream_id = kv.first; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 825 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 826 | // Filter on direction and SSRC. |
| 827 | if (stream_id.GetDirection() != kIncomingPacket || |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 828 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) || |
| 829 | IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) || |
| 830 | IsRtxSsrc(stream_id)) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 831 | continue; |
| 832 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 833 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 834 | TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time", |
| 835 | LINE_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 836 | AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime, |
| 837 | packet_stream, begin_time_, |
| 838 | &capture_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 839 | plot->AppendTimeSeries(std::move(capture_time_data)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 840 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 841 | TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time", |
| 842 | LINE_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 843 | AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime, |
| 844 | packet_stream, begin_time_, |
| 845 | &send_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 846 | plot->AppendTimeSeries(std::move(send_time_data)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 847 | } |
| 848 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 849 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 850 | plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin, |
| 851 | kTopMargin); |
| 852 | plot->SetTitle("Accumulated network latency change"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 853 | } |
| 854 | |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 855 | // Plot the fraction of packets lost (as perceived by the loss-based BWE). |
| 856 | void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 857 | TimeSeries time_series("Fraction lost", LINE_DOT_GRAPH); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 858 | for (auto& bwe_update : bwe_loss_updates_) { |
| 859 | float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000; |
| 860 | float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 861 | time_series.points.emplace_back(x, y); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 862 | } |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 863 | |
| 864 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 865 | plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin, |
| 866 | kTopMargin); |
| 867 | plot->SetTitle("Reported packet loss"); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 868 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 869 | } |
| 870 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 871 | // Plot the total bandwidth used by all RTP streams. |
| 872 | void EventLogAnalyzer::CreateTotalBitrateGraph( |
| 873 | PacketDirection desired_direction, |
| 874 | Plot* plot) { |
| 875 | struct TimestampSize { |
| 876 | TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {} |
| 877 | uint64_t timestamp; |
| 878 | size_t size; |
| 879 | }; |
| 880 | std::vector<TimestampSize> packets; |
| 881 | |
| 882 | PacketDirection direction; |
| 883 | size_t total_length; |
| 884 | |
| 885 | // Extract timestamps and sizes for the relevant packets. |
| 886 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 887 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
| 888 | if (event_type == ParsedRtcEventLog::RTP_EVENT) { |
perkj | 77cd58e | 2017-05-30 03:52:10 -0700 | [diff] [blame] | 889 | parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 890 | if (direction == desired_direction) { |
| 891 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 892 | packets.push_back(TimestampSize(timestamp, total_length)); |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | size_t window_index_begin = 0; |
| 898 | size_t window_index_end = 0; |
| 899 | size_t bytes_in_window = 0; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 900 | |
| 901 | // Calculate a moving average of the bitrate and store in a TimeSeries. |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 902 | TimeSeries bitrate_series("Bitrate", LINE_GRAPH); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 903 | for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) { |
| 904 | while (window_index_end < packets.size() && |
| 905 | packets[window_index_end].timestamp < time) { |
| 906 | bytes_in_window += packets[window_index_end].size; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 907 | ++window_index_end; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 908 | } |
| 909 | while (window_index_begin < packets.size() && |
| 910 | packets[window_index_begin].timestamp < time - window_duration_) { |
| 911 | RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window); |
| 912 | bytes_in_window -= packets[window_index_begin].size; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 913 | ++window_index_begin; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 914 | } |
| 915 | float window_duration_in_seconds = |
| 916 | static_cast<float>(window_duration_) / 1000000; |
| 917 | float x = static_cast<float>(time - begin_time_) / 1000000; |
| 918 | float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 919 | bitrate_series.points.emplace_back(x, y); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 920 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 921 | plot->AppendTimeSeries(std::move(bitrate_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 922 | |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 923 | // Overlay the send-side bandwidth estimate over the outgoing bitrate. |
| 924 | if (desired_direction == kOutgoingPacket) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 925 | TimeSeries loss_series("Loss-based estimate", LINE_STEP_GRAPH); |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 926 | for (auto& loss_update : bwe_loss_updates_) { |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 927 | float x = |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 928 | static_cast<float>(loss_update.timestamp - begin_time_) / 1000000; |
| 929 | float y = static_cast<float>(loss_update.new_bitrate) / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 930 | loss_series.points.emplace_back(x, y); |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 931 | } |
| 932 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 933 | TimeSeries delay_series("Delay-based estimate", LINE_STEP_GRAPH); |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 934 | for (auto& delay_update : bwe_delay_updates_) { |
| 935 | float x = |
| 936 | static_cast<float>(delay_update.timestamp - begin_time_) / 1000000; |
| 937 | float y = static_cast<float>(delay_update.bitrate_bps) / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 938 | delay_series.points.emplace_back(x, y); |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 939 | } |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 940 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 941 | TimeSeries created_series("Probe cluster created.", DOT_GRAPH); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 942 | for (auto& cluster : bwe_probe_cluster_created_events_) { |
| 943 | float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000; |
| 944 | float y = static_cast<float>(cluster.bitrate_bps) / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 945 | created_series.points.emplace_back(x, y); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 946 | } |
| 947 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 948 | TimeSeries result_series("Probing results.", DOT_GRAPH); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 949 | for (auto& result : bwe_probe_result_events_) { |
| 950 | if (result.bitrate_bps) { |
| 951 | float x = static_cast<float>(result.timestamp - begin_time_) / 1000000; |
| 952 | float y = static_cast<float>(*result.bitrate_bps) / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 953 | result_series.points.emplace_back(x, y); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 954 | } |
| 955 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 956 | plot->AppendTimeSeries(std::move(loss_series)); |
| 957 | plot->AppendTimeSeries(std::move(delay_series)); |
| 958 | plot->AppendTimeSeries(std::move(created_series)); |
| 959 | plot->AppendTimeSeries(std::move(result_series)); |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 960 | } |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 961 | |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 962 | // Overlay the incoming REMB over the outgoing bitrate |
| 963 | // and outgoing REMB over incoming bitrate. |
| 964 | PacketDirection remb_direction = |
| 965 | desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket; |
| 966 | TimeSeries remb_series("Remb", LINE_STEP_GRAPH); |
| 967 | std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets; |
| 968 | for (const auto& kv : rtcp_packets_) { |
| 969 | if (kv.first.GetDirection() == remb_direction) { |
| 970 | for (const LoggedRtcpPacket& rtcp_packet : kv.second) { |
| 971 | if (rtcp_packet.type == kRtcpRemb) { |
| 972 | remb_packets.insert( |
| 973 | std::make_pair(rtcp_packet.timestamp, &rtcp_packet)); |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | for (const auto& kv : remb_packets) { |
| 980 | const LoggedRtcpPacket* const rtcp = kv.second; |
| 981 | const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get()); |
| 982 | float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000; |
| 983 | float y = static_cast<float>(remb->bitrate_bps()) / 1000; |
| 984 | remb_series.points.emplace_back(x, y); |
| 985 | } |
| 986 | plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series)); |
| 987 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 988 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 989 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 990 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 991 | plot->SetTitle("Incoming RTP bitrate"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 992 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 993 | plot->SetTitle("Outgoing RTP bitrate"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
| 997 | // For each SSRC, plot the bandwidth used by that stream. |
| 998 | void EventLogAnalyzer::CreateStreamBitrateGraph( |
| 999 | PacketDirection desired_direction, |
| 1000 | Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 1001 | for (auto& kv : rtp_packets_) { |
| 1002 | StreamId stream_id = kv.first; |
| 1003 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 1004 | // Filter on direction and SSRC. |
| 1005 | if (stream_id.GetDirection() != desired_direction || |
| 1006 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 1007 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1010 | TimeSeries time_series(GetStreamName(stream_id), LINE_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1011 | MovingAverage<LoggedRtpPacket, double>( |
| 1012 | [](const LoggedRtpPacket& packet) { |
| 1013 | return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0); |
| 1014 | }, |
| 1015 | packet_stream, begin_time_, end_time_, window_duration_, step_, |
| 1016 | &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1017 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1020 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1021 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1022 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1023 | plot->SetTitle("Incoming bitrate per stream"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1024 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1025 | plot->SetTitle("Outgoing bitrate per stream"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 1029 | void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) { |
stefan | ff42162 | 2017-04-20 03:24:01 -0700 | [diff] [blame] | 1030 | std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp; |
| 1031 | std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1032 | |
| 1033 | for (const auto& kv : rtp_packets_) { |
| 1034 | if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) { |
| 1035 | for (const LoggedRtpPacket& rtp_packet : kv.second) |
| 1036 | outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet)); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | for (const auto& kv : rtcp_packets_) { |
| 1041 | if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) { |
| 1042 | for (const LoggedRtcpPacket& rtcp_packet : kv.second) |
| 1043 | incoming_rtcp.insert( |
| 1044 | std::make_pair(rtcp_packet.timestamp, &rtcp_packet)); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | SimulatedClock clock(0); |
| 1049 | BitrateObserver observer; |
| 1050 | RtcEventLogNullImpl null_event_log; |
nisse | 0245da0 | 2016-11-30 03:35:20 -0800 | [diff] [blame] | 1051 | PacketRouter packet_router; |
| 1052 | CongestionController cc(&clock, &observer, &observer, &null_event_log, |
| 1053 | &packet_router); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1054 | // TODO(holmer): Log the call config and use that here instead. |
| 1055 | static const uint32_t kDefaultStartBitrateBps = 300000; |
| 1056 | cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1); |
| 1057 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1058 | TimeSeries time_series("Delay-based estimate", LINE_DOT_GRAPH); |
| 1059 | TimeSeries acked_time_series("Acked bitrate", LINE_DOT_GRAPH); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1060 | |
| 1061 | auto rtp_iterator = outgoing_rtp.begin(); |
| 1062 | auto rtcp_iterator = incoming_rtcp.begin(); |
| 1063 | |
| 1064 | auto NextRtpTime = [&]() { |
| 1065 | if (rtp_iterator != outgoing_rtp.end()) |
| 1066 | return static_cast<int64_t>(rtp_iterator->first); |
| 1067 | return std::numeric_limits<int64_t>::max(); |
| 1068 | }; |
| 1069 | |
| 1070 | auto NextRtcpTime = [&]() { |
| 1071 | if (rtcp_iterator != incoming_rtcp.end()) |
| 1072 | return static_cast<int64_t>(rtcp_iterator->first); |
| 1073 | return std::numeric_limits<int64_t>::max(); |
| 1074 | }; |
| 1075 | |
| 1076 | auto NextProcessTime = [&]() { |
| 1077 | if (rtcp_iterator != incoming_rtcp.end() || |
| 1078 | rtp_iterator != outgoing_rtp.end()) { |
| 1079 | return clock.TimeInMicroseconds() + |
| 1080 | std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0); |
| 1081 | } |
| 1082 | return std::numeric_limits<int64_t>::max(); |
| 1083 | }; |
| 1084 | |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1085 | RateStatistics acked_bitrate(250, 8000); |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1086 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1087 | int64_t time_us = std::min(NextRtpTime(), NextRtcpTime()); |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1088 | int64_t last_update_us = 0; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1089 | while (time_us != std::numeric_limits<int64_t>::max()) { |
| 1090 | clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds()); |
| 1091 | if (clock.TimeInMicroseconds() >= NextRtcpTime()) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1092 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1093 | const LoggedRtcpPacket& rtcp = *rtcp_iterator->second; |
| 1094 | if (rtcp.type == kRtcpTransportFeedback) { |
elad.alon | 5bbf43f | 2017-03-09 06:40:08 -0800 | [diff] [blame] | 1095 | cc.OnTransportFeedback( |
| 1096 | *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get())); |
| 1097 | std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector(); |
elad.alon | ec304f9 | 2017-03-08 05:03:53 -0800 | [diff] [blame] | 1098 | SortPacketFeedbackVector(&feedback); |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1099 | rtc::Optional<uint32_t> bitrate_bps; |
| 1100 | if (!feedback.empty()) { |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame] | 1101 | for (const PacketFeedback& packet : feedback) |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1102 | acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms); |
| 1103 | bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms); |
| 1104 | } |
| 1105 | uint32_t y = 0; |
| 1106 | if (bitrate_bps) |
| 1107 | y = *bitrate_bps / 1000; |
| 1108 | float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 1109 | 1000000; |
| 1110 | acked_time_series.points.emplace_back(x, y); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1111 | } |
| 1112 | ++rtcp_iterator; |
| 1113 | } |
| 1114 | if (clock.TimeInMicroseconds() >= NextRtpTime()) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1115 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1116 | const LoggedRtpPacket& rtp = *rtp_iterator->second; |
| 1117 | if (rtp.header.extension.hasTransportSequenceNumber) { |
| 1118 | RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber); |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 1119 | cc.AddPacket(rtp.header.ssrc, |
| 1120 | rtp.header.extension.transportSequenceNumber, |
elad.alon | 5bbf43f | 2017-03-09 06:40:08 -0800 | [diff] [blame] | 1121 | rtp.total_length, PacedPacketInfo()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1122 | rtc::SentPacket sent_packet( |
| 1123 | rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000); |
| 1124 | cc.OnSentPacket(sent_packet); |
| 1125 | } |
| 1126 | ++rtp_iterator; |
| 1127 | } |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1128 | if (clock.TimeInMicroseconds() >= NextProcessTime()) { |
| 1129 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1130 | cc.Process(); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1131 | } |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1132 | if (observer.GetAndResetBitrateUpdated() || |
| 1133 | time_us - last_update_us >= 1e6) { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1134 | uint32_t y = observer.last_bitrate_bps() / 1000; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1135 | float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 1136 | 1000000; |
| 1137 | time_series.points.emplace_back(x, y); |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1138 | last_update_us = time_us; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1139 | } |
| 1140 | time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()}); |
| 1141 | } |
| 1142 | // Add the data set to the plot. |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1143 | plot->AppendTimeSeries(std::move(time_series)); |
| 1144 | plot->AppendTimeSeries(std::move(acked_time_series)); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1145 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1146 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1147 | plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 1148 | plot->SetTitle("Simulated BWE behavior"); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1149 | } |
| 1150 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 1151 | void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) { |
stefan | ff42162 | 2017-04-20 03:24:01 -0700 | [diff] [blame] | 1152 | std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp; |
| 1153 | std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp; |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1154 | |
| 1155 | for (const auto& kv : rtp_packets_) { |
| 1156 | if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) { |
| 1157 | for (const LoggedRtpPacket& rtp_packet : kv.second) |
| 1158 | outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet)); |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | for (const auto& kv : rtcp_packets_) { |
| 1163 | if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) { |
| 1164 | for (const LoggedRtcpPacket& rtcp_packet : kv.second) |
| 1165 | incoming_rtcp.insert( |
| 1166 | std::make_pair(rtcp_packet.timestamp, &rtcp_packet)); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | SimulatedClock clock(0); |
elad.alon | 5bbf43f | 2017-03-09 06:40:08 -0800 | [diff] [blame] | 1171 | TransportFeedbackAdapter feedback_adapter(&clock); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1172 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1173 | TimeSeries time_series("Network Delay Change", LINE_DOT_GRAPH); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1174 | int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max(); |
| 1175 | |
| 1176 | auto rtp_iterator = outgoing_rtp.begin(); |
| 1177 | auto rtcp_iterator = incoming_rtcp.begin(); |
| 1178 | |
| 1179 | auto NextRtpTime = [&]() { |
| 1180 | if (rtp_iterator != outgoing_rtp.end()) |
| 1181 | return static_cast<int64_t>(rtp_iterator->first); |
| 1182 | return std::numeric_limits<int64_t>::max(); |
| 1183 | }; |
| 1184 | |
| 1185 | auto NextRtcpTime = [&]() { |
| 1186 | if (rtcp_iterator != incoming_rtcp.end()) |
| 1187 | return static_cast<int64_t>(rtcp_iterator->first); |
| 1188 | return std::numeric_limits<int64_t>::max(); |
| 1189 | }; |
| 1190 | |
| 1191 | int64_t time_us = std::min(NextRtpTime(), NextRtcpTime()); |
| 1192 | while (time_us != std::numeric_limits<int64_t>::max()) { |
| 1193 | clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds()); |
| 1194 | if (clock.TimeInMicroseconds() >= NextRtcpTime()) { |
| 1195 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime()); |
| 1196 | const LoggedRtcpPacket& rtcp = *rtcp_iterator->second; |
| 1197 | if (rtcp.type == kRtcpTransportFeedback) { |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1198 | feedback_adapter.OnTransportFeedback( |
| 1199 | *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get())); |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame] | 1200 | std::vector<PacketFeedback> feedback = |
| 1201 | feedback_adapter.GetTransportFeedbackVector(); |
elad.alon | ec304f9 | 2017-03-08 05:03:53 -0800 | [diff] [blame] | 1202 | SortPacketFeedbackVector(&feedback); |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame] | 1203 | for (const PacketFeedback& packet : feedback) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1204 | int64_t y = packet.arrival_time_ms - packet.send_time_ms; |
| 1205 | float x = |
| 1206 | static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 1207 | 1000000; |
| 1208 | estimated_base_delay_ms = std::min(y, estimated_base_delay_ms); |
| 1209 | time_series.points.emplace_back(x, y); |
| 1210 | } |
| 1211 | } |
| 1212 | ++rtcp_iterator; |
| 1213 | } |
| 1214 | if (clock.TimeInMicroseconds() >= NextRtpTime()) { |
| 1215 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime()); |
| 1216 | const LoggedRtpPacket& rtp = *rtp_iterator->second; |
| 1217 | if (rtp.header.extension.hasTransportSequenceNumber) { |
| 1218 | RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber); |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 1219 | feedback_adapter.AddPacket(rtp.header.ssrc, |
| 1220 | rtp.header.extension.transportSequenceNumber, |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 1221 | rtp.total_length, PacedPacketInfo()); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1222 | feedback_adapter.OnSentPacket( |
| 1223 | rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000); |
| 1224 | } |
| 1225 | ++rtp_iterator; |
| 1226 | } |
| 1227 | time_us = std::min(NextRtpTime(), NextRtcpTime()); |
| 1228 | } |
| 1229 | // We assume that the base network delay (w/o queues) is the min delay |
| 1230 | // observed during the call. |
| 1231 | for (TimeSeriesPoint& point : time_series.points) |
| 1232 | point.y -= estimated_base_delay_ms; |
| 1233 | // Add the data set to the plot. |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1234 | plot->AppendTimeSeries(std::move(time_series)); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1235 | |
| 1236 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1237 | plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin); |
| 1238 | plot->SetTitle("Network Delay Change."); |
| 1239 | } |
stefan | 0838327 | 2016-12-20 08:51:52 -0800 | [diff] [blame] | 1240 | |
| 1241 | std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps() |
| 1242 | const { |
| 1243 | std::vector<std::pair<int64_t, int64_t>> timestamps; |
| 1244 | size_t largest_stream_size = 0; |
| 1245 | const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr; |
| 1246 | // Find the incoming video stream with the most number of packets that is |
| 1247 | // not rtx. |
| 1248 | for (const auto& kv : rtp_packets_) { |
| 1249 | if (kv.first.GetDirection() == kIncomingPacket && |
| 1250 | video_ssrcs_.find(kv.first) != video_ssrcs_.end() && |
| 1251 | rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() && |
| 1252 | kv.second.size() > largest_stream_size) { |
| 1253 | largest_stream_size = kv.second.size(); |
| 1254 | largest_video_stream = &kv.second; |
| 1255 | } |
| 1256 | } |
| 1257 | if (largest_video_stream == nullptr) { |
| 1258 | for (auto& packet : *largest_video_stream) { |
| 1259 | if (packet.header.markerBit) { |
| 1260 | int64_t capture_ms = packet.header.timestamp / 90.0; |
| 1261 | int64_t arrival_ms = packet.timestamp / 1000.0; |
| 1262 | timestamps.push_back(std::make_pair(capture_ms, arrival_ms)); |
| 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | return timestamps; |
| 1267 | } |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1268 | |
| 1269 | void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) { |
| 1270 | for (const auto& kv : rtp_packets_) { |
| 1271 | const std::vector<LoggedRtpPacket>& rtp_packets = kv.second; |
| 1272 | StreamId stream_id = kv.first; |
| 1273 | |
| 1274 | { |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1275 | TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time", |
| 1276 | LINE_DOT_GRAPH); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1277 | for (LoggedRtpPacket packet : rtp_packets) { |
| 1278 | float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000; |
| 1279 | float y = packet.header.timestamp; |
| 1280 | timestamp_data.points.emplace_back(x, y); |
| 1281 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1282 | plot->AppendTimeSeries(std::move(timestamp_data)); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | { |
| 1286 | auto kv = rtcp_packets_.find(stream_id); |
| 1287 | if (kv != rtcp_packets_.end()) { |
| 1288 | const auto& packets = kv->second; |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1289 | TimeSeries timestamp_data( |
| 1290 | GetStreamName(stream_id) + " rtcp capture-time", LINE_DOT_GRAPH); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1291 | for (const LoggedRtcpPacket& rtcp : packets) { |
| 1292 | if (rtcp.type != kRtcpSr) |
| 1293 | continue; |
| 1294 | rtcp::SenderReport* sr; |
| 1295 | sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get()); |
| 1296 | float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000; |
| 1297 | float y = sr->rtp_timestamp(); |
| 1298 | timestamp_data.points.emplace_back(x, y); |
| 1299 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1300 | plot->AppendTimeSeries(std::move(timestamp_data)); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1306 | plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin); |
| 1307 | plot->SetTitle("Timestamps"); |
| 1308 | } |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1309 | |
| 1310 | void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1311 | TimeSeries time_series("Audio encoder target bitrate", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1312 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1313 | [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1314 | if (ana_event.config.bitrate_bps) |
| 1315 | return rtc::Optional<float>( |
| 1316 | static_cast<float>(*ana_event.config.bitrate_bps)); |
| 1317 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1318 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1319 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1320 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1321 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1322 | plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin); |
| 1323 | plot->SetTitle("Reported audio encoder target bitrate"); |
| 1324 | } |
| 1325 | |
| 1326 | void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1327 | TimeSeries time_series("Audio encoder frame length", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1328 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1329 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1330 | if (ana_event.config.frame_length_ms) |
| 1331 | return rtc::Optional<float>( |
| 1332 | static_cast<float>(*ana_event.config.frame_length_ms)); |
| 1333 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1334 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1335 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1336 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1337 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1338 | plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin); |
| 1339 | plot->SetTitle("Reported audio encoder frame length"); |
| 1340 | } |
| 1341 | |
| 1342 | void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph( |
| 1343 | Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1344 | TimeSeries time_series("Audio encoder uplink packet loss fraction", |
| 1345 | LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1346 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1347 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1348 | if (ana_event.config.uplink_packet_loss_fraction) |
| 1349 | return rtc::Optional<float>(static_cast<float>( |
| 1350 | *ana_event.config.uplink_packet_loss_fraction)); |
| 1351 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1352 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1353 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1354 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1355 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1356 | plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin, |
| 1357 | kTopMargin); |
| 1358 | plot->SetTitle("Reported audio encoder lost packets"); |
| 1359 | } |
| 1360 | |
| 1361 | void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1362 | TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1363 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1364 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1365 | if (ana_event.config.enable_fec) |
| 1366 | return rtc::Optional<float>( |
| 1367 | static_cast<float>(*ana_event.config.enable_fec)); |
| 1368 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1369 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1370 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1371 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1372 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1373 | plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin); |
| 1374 | plot->SetTitle("Reported audio encoder FEC"); |
| 1375 | } |
| 1376 | |
| 1377 | void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1378 | TimeSeries time_series("Audio encoder DTX", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1379 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1380 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1381 | if (ana_event.config.enable_dtx) |
| 1382 | return rtc::Optional<float>( |
| 1383 | static_cast<float>(*ana_event.config.enable_dtx)); |
| 1384 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1385 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1386 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1387 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1388 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1389 | plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin); |
| 1390 | plot->SetTitle("Reported audio encoder DTX"); |
| 1391 | } |
| 1392 | |
| 1393 | void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1394 | TimeSeries time_series("Audio encoder number of channels", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1395 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1396 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1397 | if (ana_event.config.num_channels) |
| 1398 | return rtc::Optional<float>( |
| 1399 | static_cast<float>(*ana_event.config.num_channels)); |
| 1400 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1401 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1402 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1403 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1404 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1405 | plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))", |
| 1406 | kBottomMargin, kTopMargin); |
| 1407 | plot->SetTitle("Reported audio encoder number of channels"); |
| 1408 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1409 | } // namespace plotting |
| 1410 | } // namespace webrtc |