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