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 | |
kjellander | a69d973 | 2016-08-31 07:33:05 -0700 | [diff] [blame] | 20 | #include "webrtc/api/call/audio_receive_stream.h" |
| 21 | #include "webrtc/api/call/audio_send_stream.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 22 | #include "webrtc/base/checks.h" |
stefan | 6a850c3 | 2016-07-29 10:28:08 -0700 | [diff] [blame] | 23 | #include "webrtc/base/logging.h" |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 24 | #include "webrtc/base/rate_statistics.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 25 | #include "webrtc/call.h" |
| 26 | #include "webrtc/common_types.h" |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 27 | #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 28 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 29 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 30 | #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 31 | #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| 32 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 33 | #include "webrtc/video_receive_stream.h" |
| 34 | #include "webrtc/video_send_stream.h" |
| 35 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 36 | namespace webrtc { |
| 37 | namespace plotting { |
| 38 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 39 | namespace { |
| 40 | |
| 41 | std::string SsrcToString(uint32_t ssrc) { |
| 42 | std::stringstream ss; |
| 43 | ss << "SSRC " << ssrc; |
| 44 | return ss.str(); |
| 45 | } |
| 46 | |
| 47 | // Checks whether an SSRC is contained in the list of desired SSRCs. |
| 48 | // Note that an empty SSRC list matches every SSRC. |
| 49 | bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) { |
| 50 | if (desired_ssrc.size() == 0) |
| 51 | return true; |
| 52 | return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) != |
| 53 | desired_ssrc.end(); |
| 54 | } |
| 55 | |
| 56 | double AbsSendTimeToMicroseconds(int64_t abs_send_time) { |
| 57 | // The timestamp is a fixed point representation with 6 bits for seconds |
| 58 | // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the |
| 59 | // time in seconds and then multiply by 1000000 to convert to microseconds. |
| 60 | static constexpr double kTimestampToMicroSec = |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 61 | 1000000.0 / static_cast<double>(1ul << 18); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 62 | return abs_send_time * kTimestampToMicroSec; |
| 63 | } |
| 64 | |
| 65 | // Computes the difference |later| - |earlier| where |later| and |earlier| |
| 66 | // are counters that wrap at |modulus|. The difference is chosen to have the |
| 67 | // least absolute value. For example if |modulus| is 8, then the difference will |
| 68 | // be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will |
| 69 | // be in [-4, 4]. |
| 70 | int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) { |
| 71 | RTC_DCHECK_LE(1, modulus); |
| 72 | RTC_DCHECK_LT(later, modulus); |
| 73 | RTC_DCHECK_LT(earlier, modulus); |
| 74 | int64_t difference = |
| 75 | static_cast<int64_t>(later) - static_cast<int64_t>(earlier); |
| 76 | int64_t max_difference = modulus / 2; |
| 77 | int64_t min_difference = max_difference - modulus + 1; |
| 78 | if (difference > max_difference) { |
| 79 | difference -= modulus; |
| 80 | } |
| 81 | if (difference < min_difference) { |
| 82 | difference += modulus; |
| 83 | } |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 84 | if (difference > max_difference / 2 || difference < min_difference / 2) { |
| 85 | LOG(LS_WARNING) << "Difference between" << later << " and " << earlier |
| 86 | << " expected to be in the range (" << min_difference / 2 |
| 87 | << "," << max_difference / 2 << ") but is " << difference |
| 88 | << ". Correct unwrapping is uncertain."; |
| 89 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 90 | return difference; |
| 91 | } |
| 92 | |
stefan | 6a850c3 | 2016-07-29 10:28:08 -0700 | [diff] [blame] | 93 | void RegisterHeaderExtensions( |
| 94 | const std::vector<webrtc::RtpExtension>& extensions, |
| 95 | webrtc::RtpHeaderExtensionMap* extension_map) { |
| 96 | extension_map->Erase(); |
| 97 | for (const webrtc::RtpExtension& extension : extensions) { |
| 98 | extension_map->Register(webrtc::StringToRtpExtensionType(extension.uri), |
| 99 | extension.id); |
| 100 | } |
| 101 | } |
| 102 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 103 | constexpr float kLeftMargin = 0.01f; |
| 104 | constexpr float kRightMargin = 0.02f; |
| 105 | constexpr float kBottomMargin = 0.02f; |
| 106 | constexpr float kTopMargin = 0.05f; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 107 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 108 | class PacketSizeBytes { |
| 109 | public: |
| 110 | using DataType = LoggedRtpPacket; |
| 111 | using ResultType = size_t; |
| 112 | size_t operator()(const LoggedRtpPacket& packet) { |
| 113 | return packet.total_length; |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | class SequenceNumberDiff { |
| 118 | public: |
| 119 | using DataType = LoggedRtpPacket; |
| 120 | using ResultType = int64_t; |
| 121 | int64_t operator()(const LoggedRtpPacket& old_packet, |
| 122 | const LoggedRtpPacket& new_packet) { |
| 123 | return WrappingDifference(new_packet.header.sequenceNumber, |
| 124 | old_packet.header.sequenceNumber, 1ul << 16); |
| 125 | } |
| 126 | }; |
| 127 | |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 128 | class NetworkDelayDiff { |
| 129 | public: |
| 130 | class AbsSendTime { |
| 131 | public: |
| 132 | using DataType = LoggedRtpPacket; |
| 133 | using ResultType = double; |
| 134 | double operator()(const LoggedRtpPacket& old_packet, |
| 135 | const LoggedRtpPacket& new_packet) { |
| 136 | if (old_packet.header.extension.hasAbsoluteSendTime && |
| 137 | new_packet.header.extension.hasAbsoluteSendTime) { |
| 138 | int64_t send_time_diff = WrappingDifference( |
| 139 | new_packet.header.extension.absoluteSendTime, |
| 140 | old_packet.header.extension.absoluteSendTime, 1ul << 24); |
| 141 | int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
| 142 | return static_cast<double>(recv_time_diff - |
| 143 | AbsSendTimeToMicroseconds(send_time_diff)) / |
| 144 | 1000; |
| 145 | } else { |
| 146 | return 0; |
| 147 | } |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | class CaptureTime { |
| 152 | public: |
| 153 | using DataType = LoggedRtpPacket; |
| 154 | using ResultType = double; |
| 155 | double operator()(const LoggedRtpPacket& old_packet, |
| 156 | const LoggedRtpPacket& new_packet) { |
| 157 | int64_t send_time_diff = WrappingDifference( |
| 158 | new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32); |
| 159 | int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
| 160 | |
| 161 | const double kVideoSampleRate = 90000; |
| 162 | // TODO(terelius): We treat all streams as video for now, even though |
| 163 | // audio might be sampled at e.g. 16kHz, because it is really difficult to |
| 164 | // figure out the true sampling rate of a stream. The effect is that the |
| 165 | // delay will be scaled incorrectly for non-video streams. |
| 166 | |
| 167 | double delay_change = |
| 168 | static_cast<double>(recv_time_diff) / 1000 - |
| 169 | static_cast<double>(send_time_diff) / kVideoSampleRate * 1000; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 170 | if (delay_change < -10000 || 10000 < delay_change) { |
| 171 | LOG(LS_WARNING) << "Very large delay change. Timestamps correct?"; |
| 172 | LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp |
| 173 | << ", received time " << old_packet.timestamp; |
| 174 | LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp |
| 175 | << ", received time " << new_packet.timestamp; |
| 176 | LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = " |
| 177 | << static_cast<double>(recv_time_diff) / 1000000 << "s"; |
| 178 | LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = " |
| 179 | << static_cast<double>(send_time_diff) / |
| 180 | kVideoSampleRate |
| 181 | << "s"; |
| 182 | } |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 183 | return delay_change; |
| 184 | } |
| 185 | }; |
| 186 | }; |
| 187 | |
| 188 | template <typename Extractor> |
| 189 | class Accumulated { |
| 190 | public: |
| 191 | using DataType = typename Extractor::DataType; |
| 192 | using ResultType = typename Extractor::ResultType; |
| 193 | ResultType operator()(const DataType& old_packet, |
| 194 | const DataType& new_packet) { |
| 195 | sum += extract(old_packet, new_packet); |
| 196 | return sum; |
| 197 | } |
| 198 | |
| 199 | private: |
| 200 | Extractor extract; |
| 201 | ResultType sum = 0; |
| 202 | }; |
| 203 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 204 | // For each element in data, use |Extractor| to extract a y-coordinate and |
| 205 | // store the result in a TimeSeries. |
| 206 | template <typename Extractor> |
| 207 | void Pointwise(const std::vector<typename Extractor::DataType>& data, |
| 208 | uint64_t begin_time, |
| 209 | TimeSeries* result) { |
| 210 | Extractor extract; |
| 211 | for (size_t i = 0; i < data.size(); i++) { |
| 212 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
| 213 | float y = extract(data[i]); |
| 214 | result->points.emplace_back(x, y); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | // For each pair of adjacent elements in |data|, use |Extractor| to extract a |
| 219 | // y-coordinate and store the result in a TimeSeries. Note that the x-coordinate |
| 220 | // will be the time of the second element in the pair. |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 221 | template <typename Extractor> |
| 222 | void Pairwise(const std::vector<typename Extractor::DataType>& data, |
| 223 | uint64_t begin_time, |
| 224 | TimeSeries* result) { |
| 225 | Extractor extract; |
| 226 | for (size_t i = 1; i < data.size(); i++) { |
| 227 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
| 228 | float y = extract(data[i - 1], data[i]); |
| 229 | result->points.emplace_back(x, y); |
| 230 | } |
| 231 | } |
| 232 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 233 | // Calculates a moving average of |data| and stores the result in a TimeSeries. |
| 234 | // A data point is generated every |step| microseconds from |begin_time| |
| 235 | // to |end_time|. The value of each data point is the average of the data |
| 236 | // during the preceeding |window_duration_us| microseconds. |
| 237 | template <typename Extractor> |
| 238 | void MovingAverage(const std::vector<typename Extractor::DataType>& data, |
| 239 | uint64_t begin_time, |
| 240 | uint64_t end_time, |
| 241 | uint64_t window_duration_us, |
| 242 | uint64_t step, |
| 243 | float y_scaling, |
| 244 | webrtc::plotting::TimeSeries* result) { |
| 245 | size_t window_index_begin = 0; |
| 246 | size_t window_index_end = 0; |
| 247 | typename Extractor::ResultType sum_in_window = 0; |
| 248 | Extractor extract; |
| 249 | |
| 250 | for (uint64_t t = begin_time; t < end_time + step; t += step) { |
| 251 | while (window_index_end < data.size() && |
| 252 | data[window_index_end].timestamp < t) { |
| 253 | sum_in_window += extract(data[window_index_end]); |
| 254 | ++window_index_end; |
| 255 | } |
| 256 | while (window_index_begin < data.size() && |
| 257 | data[window_index_begin].timestamp < t - window_duration_us) { |
| 258 | sum_in_window -= extract(data[window_index_begin]); |
| 259 | ++window_index_begin; |
| 260 | } |
| 261 | float window_duration_s = static_cast<float>(window_duration_us) / 1000000; |
| 262 | float x = static_cast<float>(t - begin_time) / 1000000; |
| 263 | float y = sum_in_window / window_duration_s * y_scaling; |
| 264 | result->points.emplace_back(x, y); |
| 265 | } |
| 266 | } |
| 267 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 268 | } // namespace |
| 269 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 270 | EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log) |
| 271 | : parsed_log_(log), window_duration_(250000), step_(10000) { |
| 272 | uint64_t first_timestamp = std::numeric_limits<uint64_t>::max(); |
| 273 | uint64_t last_timestamp = std::numeric_limits<uint64_t>::min(); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 274 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 275 | // Maps a stream identifier consisting of ssrc and direction |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 276 | // to the header extensions used by that stream, |
| 277 | std::map<StreamId, RtpHeaderExtensionMap> extension_maps; |
| 278 | |
| 279 | PacketDirection direction; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 280 | uint8_t header[IP_PACKET_SIZE]; |
| 281 | size_t header_length; |
| 282 | size_t total_length; |
| 283 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 284 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 285 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 286 | if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT && |
| 287 | event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT && |
| 288 | event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT && |
terelius | 88c1d2b | 2016-08-01 05:20:33 -0700 | [diff] [blame] | 289 | event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT && |
| 290 | event_type != ParsedRtcEventLog::LOG_START && |
| 291 | event_type != ParsedRtcEventLog::LOG_END) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 292 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 293 | first_timestamp = std::min(first_timestamp, timestamp); |
| 294 | last_timestamp = std::max(last_timestamp, timestamp); |
| 295 | } |
| 296 | |
| 297 | switch (parsed_log_.GetEventType(i)) { |
| 298 | case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: { |
| 299 | VideoReceiveStream::Config config(nullptr); |
| 300 | parsed_log_.GetVideoReceiveConfig(i, &config); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 301 | StreamId stream(config.rtp.remote_ssrc, kIncomingPacket); |
stefan | 6a850c3 | 2016-07-29 10:28:08 -0700 | [diff] [blame] | 302 | RegisterHeaderExtensions(config.rtp.extensions, |
| 303 | &extension_maps[stream]); |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 304 | video_ssrcs_.insert(stream); |
stefan | 6a850c3 | 2016-07-29 10:28:08 -0700 | [diff] [blame] | 305 | for (auto kv : config.rtp.rtx) { |
| 306 | StreamId rtx_stream(kv.second.ssrc, kIncomingPacket); |
| 307 | RegisterHeaderExtensions(config.rtp.extensions, |
| 308 | &extension_maps[rtx_stream]); |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 309 | video_ssrcs_.insert(rtx_stream); |
| 310 | rtx_ssrcs_.insert(rtx_stream); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 311 | } |
| 312 | break; |
| 313 | } |
| 314 | case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: { |
| 315 | VideoSendStream::Config config(nullptr); |
| 316 | parsed_log_.GetVideoSendConfig(i, &config); |
| 317 | for (auto ssrc : config.rtp.ssrcs) { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 318 | StreamId stream(ssrc, kOutgoingPacket); |
stefan | 6a850c3 | 2016-07-29 10:28:08 -0700 | [diff] [blame] | 319 | RegisterHeaderExtensions(config.rtp.extensions, |
| 320 | &extension_maps[stream]); |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 321 | video_ssrcs_.insert(stream); |
stefan | 6a850c3 | 2016-07-29 10:28:08 -0700 | [diff] [blame] | 322 | } |
| 323 | for (auto ssrc : config.rtp.rtx.ssrcs) { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 324 | StreamId rtx_stream(ssrc, kOutgoingPacket); |
stefan | 6a850c3 | 2016-07-29 10:28:08 -0700 | [diff] [blame] | 325 | RegisterHeaderExtensions(config.rtp.extensions, |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 326 | &extension_maps[rtx_stream]); |
| 327 | video_ssrcs_.insert(rtx_stream); |
| 328 | rtx_ssrcs_.insert(rtx_stream); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 329 | } |
| 330 | break; |
| 331 | } |
| 332 | case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: { |
| 333 | AudioReceiveStream::Config config; |
| 334 | // TODO(terelius): Parse the audio configs once we have them. |
| 335 | break; |
| 336 | } |
| 337 | case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: { |
| 338 | AudioSendStream::Config config(nullptr); |
| 339 | // TODO(terelius): Parse the audio configs once we have them. |
| 340 | break; |
| 341 | } |
| 342 | case ParsedRtcEventLog::RTP_EVENT: { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 343 | MediaType media_type; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 344 | parsed_log_.GetRtpHeader(i, &direction, &media_type, header, |
| 345 | &header_length, &total_length); |
| 346 | // Parse header to get SSRC. |
| 347 | RtpUtility::RtpHeaderParser rtp_parser(header, header_length); |
| 348 | RTPHeader parsed_header; |
| 349 | rtp_parser.Parse(&parsed_header); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 350 | StreamId stream(parsed_header.ssrc, direction); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 351 | // Look up the extension_map and parse it again to get the extensions. |
| 352 | if (extension_maps.count(stream) == 1) { |
| 353 | RtpHeaderExtensionMap* extension_map = &extension_maps[stream]; |
| 354 | rtp_parser.Parse(&parsed_header, extension_map); |
| 355 | } |
| 356 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 357 | rtp_packets_[stream].push_back( |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 358 | LoggedRtpPacket(timestamp, parsed_header, total_length)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | case ParsedRtcEventLog::RTCP_EVENT: { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 362 | uint8_t packet[IP_PACKET_SIZE]; |
| 363 | MediaType media_type; |
| 364 | parsed_log_.GetRtcpPacket(i, &direction, &media_type, packet, |
| 365 | &total_length); |
| 366 | |
| 367 | RtpUtility::RtpHeaderParser rtp_parser(packet, total_length); |
| 368 | RTPHeader parsed_header; |
| 369 | RTC_CHECK(rtp_parser.ParseRtcp(&parsed_header)); |
| 370 | uint32_t ssrc = parsed_header.ssrc; |
| 371 | |
| 372 | RTCPUtility::RTCPParserV2 rtcp_parser(packet, total_length, true); |
| 373 | RTC_CHECK(rtcp_parser.IsValid()); |
| 374 | |
| 375 | RTCPUtility::RTCPPacketTypes packet_type = rtcp_parser.Begin(); |
| 376 | while (packet_type != RTCPUtility::RTCPPacketTypes::kInvalid) { |
| 377 | switch (packet_type) { |
| 378 | case RTCPUtility::RTCPPacketTypes::kTransportFeedback: { |
| 379 | // Currently feedback is logged twice, both for audio and video. |
| 380 | // Only act on one of them. |
| 381 | if (media_type == MediaType::VIDEO) { |
| 382 | std::unique_ptr<rtcp::RtcpPacket> rtcp_packet( |
| 383 | rtcp_parser.ReleaseRtcpPacket()); |
| 384 | StreamId stream(ssrc, direction); |
| 385 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 386 | rtcp_packets_[stream].push_back(LoggedRtcpPacket( |
| 387 | timestamp, kRtcpTransportFeedback, std::move(rtcp_packet))); |
| 388 | } |
| 389 | break; |
| 390 | } |
| 391 | default: |
| 392 | break; |
| 393 | } |
| 394 | rtcp_parser.Iterate(); |
| 395 | packet_type = rtcp_parser.PacketType(); |
| 396 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 397 | break; |
| 398 | } |
| 399 | case ParsedRtcEventLog::LOG_START: { |
| 400 | break; |
| 401 | } |
| 402 | case ParsedRtcEventLog::LOG_END: { |
| 403 | break; |
| 404 | } |
| 405 | case ParsedRtcEventLog::BWE_PACKET_LOSS_EVENT: { |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 406 | BwePacketLossEvent bwe_update; |
| 407 | bwe_update.timestamp = parsed_log_.GetTimestamp(i); |
| 408 | parsed_log_.GetBwePacketLossEvent(i, &bwe_update.new_bitrate, |
| 409 | &bwe_update.fraction_loss, |
| 410 | &bwe_update.expected_packets); |
| 411 | bwe_loss_updates_.push_back(bwe_update); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 412 | break; |
| 413 | } |
| 414 | case ParsedRtcEventLog::BWE_PACKET_DELAY_EVENT: { |
| 415 | break; |
| 416 | } |
| 417 | case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: { |
| 418 | break; |
| 419 | } |
| 420 | case ParsedRtcEventLog::UNKNOWN_EVENT: { |
| 421 | break; |
| 422 | } |
| 423 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 424 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 425 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 426 | if (last_timestamp < first_timestamp) { |
| 427 | // No useful events in the log. |
| 428 | first_timestamp = last_timestamp = 0; |
| 429 | } |
| 430 | begin_time_ = first_timestamp; |
| 431 | end_time_ = last_timestamp; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 432 | call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 435 | class BitrateObserver : public CongestionController::Observer, |
| 436 | public RemoteBitrateObserver { |
| 437 | public: |
| 438 | BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {} |
| 439 | |
| 440 | void OnNetworkChanged(uint32_t bitrate_bps, |
| 441 | uint8_t fraction_loss, |
| 442 | int64_t rtt_ms) override { |
| 443 | last_bitrate_bps_ = bitrate_bps; |
| 444 | bitrate_updated_ = true; |
| 445 | } |
| 446 | |
| 447 | void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 448 | uint32_t bitrate) override {} |
| 449 | |
| 450 | uint32_t last_bitrate_bps() const { return last_bitrate_bps_; } |
| 451 | bool GetAndResetBitrateUpdated() { |
| 452 | bool bitrate_updated = bitrate_updated_; |
| 453 | bitrate_updated_ = false; |
| 454 | return bitrate_updated; |
| 455 | } |
| 456 | |
| 457 | private: |
| 458 | uint32_t last_bitrate_bps_; |
| 459 | bool bitrate_updated_; |
| 460 | }; |
| 461 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 462 | bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 463 | return rtx_ssrcs_.count(stream_id) == 1; |
| 464 | } |
| 465 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 466 | bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 467 | return video_ssrcs_.count(stream_id) == 1; |
| 468 | } |
| 469 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 470 | bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 471 | return audio_ssrcs_.count(stream_id) == 1; |
| 472 | } |
| 473 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 474 | std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const { |
| 475 | std::stringstream name; |
| 476 | if (IsAudioSsrc(stream_id)) { |
| 477 | name << "Audio "; |
| 478 | } else if (IsVideoSsrc(stream_id)) { |
| 479 | name << "Video "; |
| 480 | } else { |
| 481 | name << "Unknown "; |
| 482 | } |
| 483 | if (IsRtxSsrc(stream_id)) |
| 484 | name << "RTX "; |
| 485 | name << SsrcToString(stream_id.GetSsrc()); |
| 486 | return name.str(); |
| 487 | } |
| 488 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 489 | void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction, |
| 490 | Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 491 | for (auto& kv : rtp_packets_) { |
| 492 | StreamId stream_id = kv.first; |
| 493 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 494 | // Filter on direction and SSRC. |
| 495 | if (stream_id.GetDirection() != desired_direction || |
| 496 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 497 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 498 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 499 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 500 | TimeSeries time_series; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 501 | time_series.label = GetStreamName(stream_id); |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 502 | time_series.style = BAR_GRAPH; |
| 503 | Pointwise<PacketSizeBytes>(packet_stream, begin_time_, &time_series); |
| 504 | plot->series_list_.push_back(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 505 | } |
| 506 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 507 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 508 | plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin, |
| 509 | kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 510 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 511 | plot->SetTitle("Incoming RTP packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 512 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 513 | plot->SetTitle("Outgoing RTP packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 517 | template <typename T> |
| 518 | void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries( |
| 519 | PacketDirection desired_direction, |
| 520 | Plot* plot, |
| 521 | const std::map<StreamId, std::vector<T>>& packets, |
| 522 | const std::string& label_prefix) { |
| 523 | for (auto& kv : packets) { |
| 524 | StreamId stream_id = kv.first; |
| 525 | const std::vector<T>& packet_stream = kv.second; |
| 526 | // Filter on direction and SSRC. |
| 527 | if (stream_id.GetDirection() != desired_direction || |
| 528 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 529 | continue; |
| 530 | } |
| 531 | |
| 532 | TimeSeries time_series; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 533 | time_series.label = label_prefix + " " + GetStreamName(stream_id); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 534 | time_series.style = LINE_GRAPH; |
| 535 | |
| 536 | for (size_t i = 0; i < packet_stream.size(); i++) { |
| 537 | float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) / |
| 538 | 1000000; |
| 539 | time_series.points.emplace_back(x, i); |
| 540 | time_series.points.emplace_back(x, i + 1); |
| 541 | } |
| 542 | |
| 543 | plot->series_list_.push_back(std::move(time_series)); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | void EventLogAnalyzer::CreateAccumulatedPacketsGraph( |
| 548 | PacketDirection desired_direction, |
| 549 | Plot* plot) { |
| 550 | CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_, |
| 551 | "RTP"); |
| 552 | CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_, |
| 553 | "RTCP"); |
| 554 | |
| 555 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 556 | plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin); |
| 557 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
| 558 | plot->SetTitle("Accumulated Incoming RTP/RTCP packets"); |
| 559 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
| 560 | plot->SetTitle("Accumulated Outgoing RTP/RTCP packets"); |
| 561 | } |
| 562 | } |
| 563 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 564 | // For each SSRC, plot the time between the consecutive playouts. |
| 565 | void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) { |
| 566 | std::map<uint32_t, TimeSeries> time_series; |
| 567 | std::map<uint32_t, uint64_t> last_playout; |
| 568 | |
| 569 | uint32_t ssrc; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 570 | |
| 571 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 572 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
| 573 | if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) { |
| 574 | parsed_log_.GetAudioPlayout(i, &ssrc); |
| 575 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 576 | if (MatchingSsrc(ssrc, desired_ssrc_)) { |
| 577 | float x = static_cast<float>(timestamp - begin_time_) / 1000000; |
| 578 | float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000; |
| 579 | if (time_series[ssrc].points.size() == 0) { |
| 580 | // There were no previusly logged playout for this SSRC. |
| 581 | // Generate a point, but place it on the x-axis. |
| 582 | y = 0; |
| 583 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 584 | time_series[ssrc].points.push_back(TimeSeriesPoint(x, y)); |
| 585 | last_playout[ssrc] = timestamp; |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | // Set labels and put in graph. |
| 591 | for (auto& kv : time_series) { |
| 592 | kv.second.label = SsrcToString(kv.first); |
| 593 | kv.second.style = BAR_GRAPH; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 594 | plot->series_list_.push_back(std::move(kv.second)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 595 | } |
| 596 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 597 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 598 | plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin, |
| 599 | kTopMargin); |
| 600 | plot->SetTitle("Audio playout"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | // For each SSRC, plot the time between the consecutive playouts. |
| 604 | void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 605 | for (auto& kv : rtp_packets_) { |
| 606 | StreamId stream_id = kv.first; |
| 607 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 608 | // Filter on direction and SSRC. |
| 609 | if (stream_id.GetDirection() != kIncomingPacket || |
| 610 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 611 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 612 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 613 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 614 | TimeSeries time_series; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 615 | time_series.label = GetStreamName(stream_id); |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 616 | time_series.style = BAR_GRAPH; |
| 617 | Pairwise<SequenceNumberDiff>(packet_stream, begin_time_, &time_series); |
| 618 | plot->series_list_.push_back(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 619 | } |
| 620 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 621 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 622 | plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin, |
| 623 | kTopMargin); |
| 624 | plot->SetTitle("Sequence number"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 627 | void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) { |
| 628 | for (auto& kv : rtp_packets_) { |
| 629 | StreamId stream_id = kv.first; |
| 630 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 631 | // Filter on direction and SSRC. |
| 632 | if (stream_id.GetDirection() != kIncomingPacket || |
| 633 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 634 | continue; |
| 635 | } |
| 636 | |
| 637 | TimeSeries time_series; |
| 638 | time_series.label = GetStreamName(stream_id); |
| 639 | time_series.style = LINE_DOT_GRAPH; |
| 640 | const uint64_t kWindowUs = 1000000; |
| 641 | const LoggedRtpPacket* first_in_window = &packet_stream.front(); |
| 642 | const LoggedRtpPacket* last_in_window = &packet_stream.front(); |
| 643 | int packets_in_window = 0; |
| 644 | for (const LoggedRtpPacket& packet : packet_stream) { |
| 645 | if (packet.timestamp > first_in_window->timestamp + kWindowUs) { |
| 646 | uint16_t expected_num_packets = last_in_window->header.sequenceNumber - |
| 647 | first_in_window->header.sequenceNumber + 1; |
| 648 | float fraction_lost = (expected_num_packets - packets_in_window) / |
| 649 | static_cast<float>(expected_num_packets); |
| 650 | float y = fraction_lost * 100; |
| 651 | float x = |
| 652 | static_cast<float>(last_in_window->timestamp - begin_time_) / |
| 653 | 1000000; |
| 654 | time_series.points.emplace_back(x, y); |
| 655 | first_in_window = &packet; |
| 656 | last_in_window = &packet; |
| 657 | packets_in_window = 1; |
| 658 | continue; |
| 659 | } |
| 660 | ++packets_in_window; |
| 661 | last_in_window = &packet; |
| 662 | } |
| 663 | plot->series_list_.push_back(std::move(time_series)); |
| 664 | } |
| 665 | |
| 666 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 667 | plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin, |
| 668 | kTopMargin); |
| 669 | plot->SetTitle("Estimated incoming loss rate"); |
| 670 | } |
| 671 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 672 | void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 673 | for (auto& kv : rtp_packets_) { |
| 674 | StreamId stream_id = kv.first; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 675 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 676 | // Filter on direction and SSRC. |
| 677 | if (stream_id.GetDirection() != kIncomingPacket || |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 678 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) || |
| 679 | IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) || |
| 680 | IsRtxSsrc(stream_id)) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 681 | continue; |
| 682 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 683 | |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 684 | TimeSeries capture_time_data; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 685 | capture_time_data.label = GetStreamName(stream_id) + " capture-time"; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 686 | capture_time_data.style = BAR_GRAPH; |
| 687 | Pairwise<NetworkDelayDiff::CaptureTime>(packet_stream, begin_time_, |
| 688 | &capture_time_data); |
| 689 | plot->series_list_.push_back(std::move(capture_time_data)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 690 | |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 691 | TimeSeries send_time_data; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 692 | send_time_data.label = GetStreamName(stream_id) + " abs-send-time"; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 693 | send_time_data.style = BAR_GRAPH; |
| 694 | Pairwise<NetworkDelayDiff::AbsSendTime>(packet_stream, begin_time_, |
| 695 | &send_time_data); |
| 696 | plot->series_list_.push_back(std::move(send_time_data)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 697 | } |
| 698 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 699 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 700 | plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin, |
| 701 | kTopMargin); |
| 702 | plot->SetTitle("Network latency change between consecutive packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 706 | for (auto& kv : rtp_packets_) { |
| 707 | StreamId stream_id = kv.first; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 708 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 709 | // Filter on direction and SSRC. |
| 710 | if (stream_id.GetDirection() != kIncomingPacket || |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 711 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) || |
| 712 | IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) || |
| 713 | IsRtxSsrc(stream_id)) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 714 | continue; |
| 715 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 716 | |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 717 | TimeSeries capture_time_data; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 718 | capture_time_data.label = GetStreamName(stream_id) + " capture-time"; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 719 | capture_time_data.style = LINE_GRAPH; |
| 720 | Pairwise<Accumulated<NetworkDelayDiff::CaptureTime>>( |
| 721 | packet_stream, begin_time_, &capture_time_data); |
| 722 | plot->series_list_.push_back(std::move(capture_time_data)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 723 | |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 724 | TimeSeries send_time_data; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 725 | send_time_data.label = GetStreamName(stream_id) + " abs-send-time"; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 726 | send_time_data.style = LINE_GRAPH; |
| 727 | Pairwise<Accumulated<NetworkDelayDiff::AbsSendTime>>( |
| 728 | packet_stream, begin_time_, &send_time_data); |
| 729 | plot->series_list_.push_back(std::move(send_time_data)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 730 | } |
| 731 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 732 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 733 | plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin, |
| 734 | kTopMargin); |
| 735 | plot->SetTitle("Accumulated network latency change"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 736 | } |
| 737 | |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 738 | // Plot the fraction of packets lost (as perceived by the loss-based BWE). |
| 739 | void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) { |
| 740 | plot->series_list_.push_back(TimeSeries()); |
| 741 | for (auto& bwe_update : bwe_loss_updates_) { |
| 742 | float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000; |
| 743 | float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100; |
| 744 | plot->series_list_.back().points.emplace_back(x, y); |
| 745 | } |
| 746 | plot->series_list_.back().label = "Fraction lost"; |
| 747 | plot->series_list_.back().style = LINE_DOT_GRAPH; |
| 748 | |
| 749 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 750 | plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin, |
| 751 | kTopMargin); |
| 752 | plot->SetTitle("Reported packet loss"); |
| 753 | } |
| 754 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 755 | // Plot the total bandwidth used by all RTP streams. |
| 756 | void EventLogAnalyzer::CreateTotalBitrateGraph( |
| 757 | PacketDirection desired_direction, |
| 758 | Plot* plot) { |
| 759 | struct TimestampSize { |
| 760 | TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {} |
| 761 | uint64_t timestamp; |
| 762 | size_t size; |
| 763 | }; |
| 764 | std::vector<TimestampSize> packets; |
| 765 | |
| 766 | PacketDirection direction; |
| 767 | size_t total_length; |
| 768 | |
| 769 | // Extract timestamps and sizes for the relevant packets. |
| 770 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 771 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
| 772 | if (event_type == ParsedRtcEventLog::RTP_EVENT) { |
| 773 | parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, nullptr, |
| 774 | &total_length); |
| 775 | if (direction == desired_direction) { |
| 776 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 777 | packets.push_back(TimestampSize(timestamp, total_length)); |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | size_t window_index_begin = 0; |
| 783 | size_t window_index_end = 0; |
| 784 | size_t bytes_in_window = 0; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 785 | |
| 786 | // Calculate a moving average of the bitrate and store in a TimeSeries. |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 787 | plot->series_list_.push_back(TimeSeries()); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 788 | for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) { |
| 789 | while (window_index_end < packets.size() && |
| 790 | packets[window_index_end].timestamp < time) { |
| 791 | bytes_in_window += packets[window_index_end].size; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 792 | ++window_index_end; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 793 | } |
| 794 | while (window_index_begin < packets.size() && |
| 795 | packets[window_index_begin].timestamp < time - window_duration_) { |
| 796 | RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window); |
| 797 | bytes_in_window -= packets[window_index_begin].size; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 798 | ++window_index_begin; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 799 | } |
| 800 | float window_duration_in_seconds = |
| 801 | static_cast<float>(window_duration_) / 1000000; |
| 802 | float x = static_cast<float>(time - begin_time_) / 1000000; |
| 803 | float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 804 | plot->series_list_.back().points.push_back(TimeSeriesPoint(x, y)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | // Set labels. |
| 808 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 809 | plot->series_list_.back().label = "Incoming bitrate"; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 810 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 811 | plot->series_list_.back().label = "Outgoing bitrate"; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 812 | } |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 813 | plot->series_list_.back().style = LINE_GRAPH; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 814 | |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 815 | // Overlay the send-side bandwidth estimate over the outgoing bitrate. |
| 816 | if (desired_direction == kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 817 | plot->series_list_.push_back(TimeSeries()); |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 818 | for (auto& bwe_update : bwe_loss_updates_) { |
| 819 | float x = |
| 820 | static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000; |
| 821 | float y = static_cast<float>(bwe_update.new_bitrate) / 1000; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 822 | plot->series_list_.back().points.emplace_back(x, y); |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 823 | } |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 824 | plot->series_list_.back().label = "Loss-based estimate"; |
| 825 | plot->series_list_.back().style = LINE_GRAPH; |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 826 | } |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 827 | plot->series_list_.back().style = LINE_GRAPH; |
| 828 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 829 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 830 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 831 | plot->SetTitle("Incoming RTP bitrate"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 832 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 833 | plot->SetTitle("Outgoing RTP bitrate"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | |
| 837 | // For each SSRC, plot the bandwidth used by that stream. |
| 838 | void EventLogAnalyzer::CreateStreamBitrateGraph( |
| 839 | PacketDirection desired_direction, |
| 840 | Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 841 | for (auto& kv : rtp_packets_) { |
| 842 | StreamId stream_id = kv.first; |
| 843 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 844 | // Filter on direction and SSRC. |
| 845 | if (stream_id.GetDirection() != desired_direction || |
| 846 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 847 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 848 | } |
| 849 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 850 | TimeSeries time_series; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 851 | time_series.label = GetStreamName(stream_id); |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 852 | time_series.style = LINE_GRAPH; |
| 853 | double bytes_to_kilobits = 8.0 / 1000; |
| 854 | MovingAverage<PacketSizeBytes>(packet_stream, begin_time_, end_time_, |
| 855 | window_duration_, step_, bytes_to_kilobits, |
| 856 | &time_series); |
| 857 | plot->series_list_.push_back(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 858 | } |
| 859 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 860 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 861 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 862 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 863 | plot->SetTitle("Incoming bitrate per stream"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 864 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 865 | plot->SetTitle("Outgoing bitrate per stream"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 869 | void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 870 | std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp; |
| 871 | std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp; |
| 872 | |
| 873 | for (const auto& kv : rtp_packets_) { |
| 874 | if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) { |
| 875 | for (const LoggedRtpPacket& rtp_packet : kv.second) |
| 876 | outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet)); |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | for (const auto& kv : rtcp_packets_) { |
| 881 | if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) { |
| 882 | for (const LoggedRtcpPacket& rtcp_packet : kv.second) |
| 883 | incoming_rtcp.insert( |
| 884 | std::make_pair(rtcp_packet.timestamp, &rtcp_packet)); |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | SimulatedClock clock(0); |
| 889 | BitrateObserver observer; |
| 890 | RtcEventLogNullImpl null_event_log; |
| 891 | CongestionController cc(&clock, &observer, &observer, &null_event_log); |
| 892 | // TODO(holmer): Log the call config and use that here instead. |
| 893 | static const uint32_t kDefaultStartBitrateBps = 300000; |
| 894 | cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1); |
| 895 | |
| 896 | TimeSeries time_series; |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 897 | time_series.label = "Delay-based estimate"; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 898 | time_series.style = LINE_DOT_GRAPH; |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 899 | TimeSeries acked_time_series; |
| 900 | acked_time_series.label = "Acked bitrate"; |
| 901 | acked_time_series.style = LINE_DOT_GRAPH; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 902 | |
| 903 | auto rtp_iterator = outgoing_rtp.begin(); |
| 904 | auto rtcp_iterator = incoming_rtcp.begin(); |
| 905 | |
| 906 | auto NextRtpTime = [&]() { |
| 907 | if (rtp_iterator != outgoing_rtp.end()) |
| 908 | return static_cast<int64_t>(rtp_iterator->first); |
| 909 | return std::numeric_limits<int64_t>::max(); |
| 910 | }; |
| 911 | |
| 912 | auto NextRtcpTime = [&]() { |
| 913 | if (rtcp_iterator != incoming_rtcp.end()) |
| 914 | return static_cast<int64_t>(rtcp_iterator->first); |
| 915 | return std::numeric_limits<int64_t>::max(); |
| 916 | }; |
| 917 | |
| 918 | auto NextProcessTime = [&]() { |
| 919 | if (rtcp_iterator != incoming_rtcp.end() || |
| 920 | rtp_iterator != outgoing_rtp.end()) { |
| 921 | return clock.TimeInMicroseconds() + |
| 922 | std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0); |
| 923 | } |
| 924 | return std::numeric_limits<int64_t>::max(); |
| 925 | }; |
| 926 | |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 927 | RateStatistics acked_bitrate(1000, 8000); |
| 928 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 929 | int64_t time_us = std::min(NextRtpTime(), NextRtcpTime()); |
| 930 | while (time_us != std::numeric_limits<int64_t>::max()) { |
| 931 | clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds()); |
| 932 | if (clock.TimeInMicroseconds() >= NextRtcpTime()) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 933 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 934 | const LoggedRtcpPacket& rtcp = *rtcp_iterator->second; |
| 935 | if (rtcp.type == kRtcpTransportFeedback) { |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 936 | TransportFeedbackObserver* observer = cc.GetTransportFeedbackObserver(); |
| 937 | observer->OnTransportFeedback(*static_cast<rtcp::TransportFeedback*>( |
| 938 | rtcp.packet.get())); |
| 939 | std::vector<PacketInfo> feedback = |
| 940 | observer->GetTransportFeedbackVector(); |
| 941 | rtc::Optional<uint32_t> bitrate_bps; |
| 942 | if (!feedback.empty()) { |
| 943 | for (const PacketInfo& packet : feedback) |
| 944 | acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms); |
| 945 | bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms); |
| 946 | } |
| 947 | uint32_t y = 0; |
| 948 | if (bitrate_bps) |
| 949 | y = *bitrate_bps / 1000; |
| 950 | float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 951 | 1000000; |
| 952 | acked_time_series.points.emplace_back(x, y); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 953 | } |
| 954 | ++rtcp_iterator; |
| 955 | } |
| 956 | if (clock.TimeInMicroseconds() >= NextRtpTime()) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 957 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 958 | const LoggedRtpPacket& rtp = *rtp_iterator->second; |
| 959 | if (rtp.header.extension.hasTransportSequenceNumber) { |
| 960 | RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber); |
| 961 | cc.GetTransportFeedbackObserver()->AddPacket( |
stefan | a93d5ac | 2016-08-17 02:14:32 -0700 | [diff] [blame] | 962 | rtp.header.extension.transportSequenceNumber, rtp.total_length, |
| 963 | PacketInfo::kNotAProbe); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 964 | rtc::SentPacket sent_packet( |
| 965 | rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000); |
| 966 | cc.OnSentPacket(sent_packet); |
| 967 | } |
| 968 | ++rtp_iterator; |
| 969 | } |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 970 | if (clock.TimeInMicroseconds() >= NextProcessTime()) { |
| 971 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 972 | cc.Process(); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 973 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 974 | if (observer.GetAndResetBitrateUpdated()) { |
| 975 | uint32_t y = observer.last_bitrate_bps() / 1000; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 976 | float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 977 | 1000000; |
| 978 | time_series.points.emplace_back(x, y); |
| 979 | } |
| 980 | time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()}); |
| 981 | } |
| 982 | // Add the data set to the plot. |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 983 | plot->series_list_.push_back(std::move(time_series)); |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 984 | plot->series_list_.push_back(std::move(acked_time_series)); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 985 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 986 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 987 | plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 988 | plot->SetTitle("Simulated BWE behavior"); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 989 | } |
| 990 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 991 | void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 992 | std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp; |
| 993 | std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp; |
| 994 | |
| 995 | for (const auto& kv : rtp_packets_) { |
| 996 | if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) { |
| 997 | for (const LoggedRtpPacket& rtp_packet : kv.second) |
| 998 | outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet)); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | for (const auto& kv : rtcp_packets_) { |
| 1003 | if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) { |
| 1004 | for (const LoggedRtcpPacket& rtcp_packet : kv.second) |
| 1005 | incoming_rtcp.insert( |
| 1006 | std::make_pair(rtcp_packet.timestamp, &rtcp_packet)); |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | SimulatedClock clock(0); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame^] | 1011 | TransportFeedbackAdapter feedback_adapter(&clock); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1012 | |
| 1013 | TimeSeries time_series; |
| 1014 | time_series.label = "Network Delay Change"; |
| 1015 | time_series.style = LINE_DOT_GRAPH; |
| 1016 | int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max(); |
| 1017 | |
| 1018 | auto rtp_iterator = outgoing_rtp.begin(); |
| 1019 | auto rtcp_iterator = incoming_rtcp.begin(); |
| 1020 | |
| 1021 | auto NextRtpTime = [&]() { |
| 1022 | if (rtp_iterator != outgoing_rtp.end()) |
| 1023 | return static_cast<int64_t>(rtp_iterator->first); |
| 1024 | return std::numeric_limits<int64_t>::max(); |
| 1025 | }; |
| 1026 | |
| 1027 | auto NextRtcpTime = [&]() { |
| 1028 | if (rtcp_iterator != incoming_rtcp.end()) |
| 1029 | return static_cast<int64_t>(rtcp_iterator->first); |
| 1030 | return std::numeric_limits<int64_t>::max(); |
| 1031 | }; |
| 1032 | |
| 1033 | int64_t time_us = std::min(NextRtpTime(), NextRtcpTime()); |
| 1034 | while (time_us != std::numeric_limits<int64_t>::max()) { |
| 1035 | clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds()); |
| 1036 | if (clock.TimeInMicroseconds() >= NextRtcpTime()) { |
| 1037 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime()); |
| 1038 | const LoggedRtcpPacket& rtcp = *rtcp_iterator->second; |
| 1039 | if (rtcp.type == kRtcpTransportFeedback) { |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1040 | feedback_adapter.OnTransportFeedback( |
| 1041 | *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get())); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1042 | std::vector<PacketInfo> feedback = |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1043 | feedback_adapter.GetTransportFeedbackVector(); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1044 | for (const PacketInfo& packet : feedback) { |
| 1045 | int64_t y = packet.arrival_time_ms - packet.send_time_ms; |
| 1046 | float x = |
| 1047 | static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 1048 | 1000000; |
| 1049 | estimated_base_delay_ms = std::min(y, estimated_base_delay_ms); |
| 1050 | time_series.points.emplace_back(x, y); |
| 1051 | } |
| 1052 | } |
| 1053 | ++rtcp_iterator; |
| 1054 | } |
| 1055 | if (clock.TimeInMicroseconds() >= NextRtpTime()) { |
| 1056 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime()); |
| 1057 | const LoggedRtpPacket& rtp = *rtp_iterator->second; |
| 1058 | if (rtp.header.extension.hasTransportSequenceNumber) { |
| 1059 | RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber); |
| 1060 | feedback_adapter.AddPacket(rtp.header.extension.transportSequenceNumber, |
| 1061 | rtp.total_length, 0); |
| 1062 | feedback_adapter.OnSentPacket( |
| 1063 | rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000); |
| 1064 | } |
| 1065 | ++rtp_iterator; |
| 1066 | } |
| 1067 | time_us = std::min(NextRtpTime(), NextRtcpTime()); |
| 1068 | } |
| 1069 | // We assume that the base network delay (w/o queues) is the min delay |
| 1070 | // observed during the call. |
| 1071 | for (TimeSeriesPoint& point : time_series.points) |
| 1072 | point.y -= estimated_base_delay_ms; |
| 1073 | // Add the data set to the plot. |
| 1074 | plot->series_list_.push_back(std::move(time_series)); |
| 1075 | |
| 1076 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1077 | plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin); |
| 1078 | plot->SetTitle("Network Delay Change."); |
| 1079 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1080 | } // namespace plotting |
| 1081 | } // namespace webrtc |