Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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" | |
| 23 #include "webrtc/call.h" | |
| 24 #include "webrtc/common_types.h" | |
| 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | |
| 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | |
| 27 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | |
| 28 #include "webrtc/video_receive_stream.h" | |
| 29 #include "webrtc/video_send_stream.h" | |
| 30 | |
| 31 namespace { | |
| 32 | |
| 33 std::string HeaderToString(const webrtc::RTPHeader& parsed_header) { | |
| 34 std::stringstream ss; | |
| 35 ss << "Marker=" << parsed_header.markerBit | |
| 36 << ", PType=" << parsed_header.payloadType | |
| 37 << ", SeqNum=" << parsed_header.sequenceNumber | |
| 38 << ", CaptureTime=" << parsed_header.timestamp | |
| 39 << ", SSRC=" << parsed_header.ssrc; | |
| 40 return ss.str(); | |
| 41 } | |
| 42 | |
| 43 std::string SsrcToString(uint32_t ssrc) { | |
| 44 std::stringstream ss; | |
| 45 ss << "SSRC " << ssrc; | |
| 46 return ss.str(); | |
| 47 } | |
| 48 | |
| 49 // Checks whether an SSRC is contained in the list of desired SSRCs. | |
| 50 // Note that an empty SSRC list matches every SSRC. | |
| 51 bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) { | |
| 52 if (desired_ssrc.size() == 0) | |
| 53 return true; | |
| 54 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) != | |
| 55 desired_ssrc.end(); | |
| 56 } | |
| 57 | |
| 58 double AbsSendTimeToMicroseconds(int64_t abs_send_time) { | |
| 59 // The timestamp is a fixed point representation with 6 bits for seconds | |
| 60 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the | |
| 61 // time in seconds and then multiply by 1000000 to convert to microseconds. | |
| 62 static constexpr double kTimestampToMicroSec = | |
| 63 1000000.0 / static_cast<double>(1 << 18); | |
| 64 return abs_send_time * kTimestampToMicroSec; | |
| 65 } | |
| 66 | |
| 67 // Computes the difference |later| - |earlier| where |later| and |earlier| | |
| 68 // are counters that wrap at |modulus|. The difference is chosen to have the | |
| 69 // least absolute value. For example if |modulus| is 8, then the difference will | |
| 70 // be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will | |
| 71 // be in [-4, 4]. | |
| 72 int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) { | |
| 73 RTC_DCHECK_LE(1, modulus); | |
| 74 RTC_DCHECK_LT(later, modulus); | |
| 75 RTC_DCHECK_LT(earlier, modulus); | |
| 76 int64_t difference = | |
| 77 static_cast<int64_t>(later) - static_cast<int64_t>(earlier); | |
| 78 int64_t max_difference = modulus / 2; | |
| 79 int64_t min_difference = max_difference - modulus + 1; | |
| 80 if (difference > max_difference) { | |
| 81 difference -= modulus; | |
| 82 } | |
| 83 if (difference < min_difference) { | |
| 84 difference += modulus; | |
| 85 } | |
| 86 return difference; | |
| 87 } | |
| 88 | |
| 89 class StreamId { | |
| 90 public: | |
| 91 StreamId(uint32_t ssrc, | |
| 92 webrtc::PacketDirection direction, | |
| 93 webrtc::MediaType media_type) | |
| 94 : ssrc_(ssrc), direction_(direction), media_type_(media_type) {} | |
| 95 bool operator<(const StreamId& other) const { | |
|
stefan-webrtc
2016/07/05 08:58:12
empty line above
terelius
2016/07/06 15:15:12
Done.
| |
| 96 if (ssrc_ < other.ssrc_) { | |
| 97 return true; | |
| 98 } | |
| 99 if (ssrc_ == other.ssrc_) { | |
| 100 if (media_type_ < other.media_type_) { | |
| 101 return true; | |
| 102 } | |
| 103 if (media_type_ == other.media_type_) { | |
| 104 if (direction_ < other.direction_) { | |
| 105 return true; | |
| 106 } | |
| 107 } | |
| 108 } | |
| 109 return false; | |
| 110 } | |
| 111 bool operator==(const StreamId& other) const { | |
|
stefan-webrtc
2016/07/05 08:58:11
empty line
terelius
2016/07/06 15:15:12
Done.
| |
| 112 return ssrc_ == other.ssrc_ && direction_ == other.direction_ && | |
| 113 media_type_ == other.media_type_; | |
| 114 } | |
| 115 uint32_t GetSsrc() const { return ssrc_; } | |
|
stefan-webrtc
2016/07/05 08:58:12
and here
terelius
2016/07/06 15:15:12
Done.
| |
| 116 | |
| 117 private: | |
| 118 uint32_t ssrc_; | |
| 119 webrtc::PacketDirection direction_; | |
| 120 webrtc::MediaType media_type_; | |
| 121 }; | |
| 122 | |
| 123 const double kXMargin = 1.02; | |
| 124 const double kYMargin = 1.1; | |
| 125 const double kDefaultXMin = -1; | |
| 126 const double kDefaultYMin = -1; | |
| 127 | |
| 128 } // namespace | |
| 129 | |
| 130 namespace webrtc { | |
| 131 namespace plotting { | |
| 132 | |
| 133 EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log, | |
| 134 bool extra_info) | |
| 135 : parsed_log_(log), | |
| 136 extra_point_info_(extra_info), | |
| 137 window_duration_(250000), | |
| 138 step_(10000) { | |
| 139 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max(); | |
| 140 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min(); | |
| 141 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { | |
| 142 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); | |
| 143 if (event_type == ParsedRtcEventLog::EventType::VIDEO_RECEIVER_CONFIG_EVENT) | |
| 144 continue; | |
| 145 if (event_type == ParsedRtcEventLog::EventType::VIDEO_SENDER_CONFIG_EVENT) | |
| 146 continue; | |
| 147 if (event_type == ParsedRtcEventLog::EventType::AUDIO_RECEIVER_CONFIG_EVENT) | |
| 148 continue; | |
| 149 if (event_type == ParsedRtcEventLog::EventType::AUDIO_SENDER_CONFIG_EVENT) | |
| 150 continue; | |
| 151 uint64_t timestamp = parsed_log_.GetTimestamp(i); | |
| 152 first_timestamp = std::min(first_timestamp, timestamp); | |
| 153 last_timestamp = std::max(last_timestamp, timestamp); | |
| 154 } | |
| 155 if (last_timestamp < first_timestamp) { | |
| 156 // No useful events in the log. | |
| 157 first_timestamp = last_timestamp = 0; | |
| 158 } | |
| 159 begin_time_ = first_timestamp; | |
| 160 end_time_ = last_timestamp; | |
| 161 } | |
| 162 | |
| 163 void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction, | |
| 164 Plot* plot) { | |
| 165 std::map<uint32_t, TimeSeries> time_series; | |
| 166 | |
| 167 PacketDirection direction; | |
| 168 MediaType media_type; | |
| 169 uint8_t header[IP_PACKET_SIZE]; | |
| 170 size_t header_length, total_length; | |
| 171 float max_y = 0; | |
| 172 | |
| 173 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { | |
| 174 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); | |
| 175 if (event_type == ParsedRtcEventLog::RTP_EVENT) { | |
| 176 parsed_log_.GetRtpHeader(i, &direction, &media_type, header, | |
| 177 &header_length, &total_length); | |
| 178 if (direction == desired_direction) { | |
| 179 // Parse header to get SSRC. | |
| 180 RtpUtility::RtpHeaderParser rtp_parser(header, header_length); | |
| 181 RTPHeader parsed_header; | |
| 182 rtp_parser.Parse(&parsed_header); | |
| 183 // Filter on SSRC. | |
| 184 if (MatchingSsrc(parsed_header.ssrc, desired_ssrc_)) { | |
| 185 uint64_t timestamp = parsed_log_.GetTimestamp(i); | |
| 186 float x = static_cast<float>(timestamp - begin_time_) / 1000000; | |
| 187 float y = total_length; | |
| 188 max_y = std::max(max_y, y); | |
| 189 std::string message; | |
| 190 if (extra_point_info_) { | |
| 191 message = HeaderToString(parsed_header); | |
| 192 } | |
| 193 time_series[parsed_header.ssrc].points.push_back( | |
| 194 TimeSeriesPoint(x, y, message)); | |
| 195 } | |
| 196 } | |
| 197 } | |
| 198 } | |
| 199 | |
| 200 // Set labels and put in graph. | |
| 201 for (auto& kv : time_series) { | |
| 202 kv.second.label = SsrcToString(kv.first); | |
| 203 kv.second.style = BAR_GRAPH; | |
| 204 plot->series.push_back(std::move(kv.second)); | |
| 205 } | |
| 206 | |
| 207 plot->xaxis_min = kDefaultXMin; | |
| 208 plot->xaxis_max = (end_time_ - begin_time_) / 1000000 * kXMargin; | |
| 209 plot->xaxis_label = "Time (s)"; | |
| 210 plot->yaxis_min = kDefaultYMin; | |
| 211 plot->yaxis_max = max_y * kYMargin; | |
| 212 plot->yaxis_label = "Packet size (bytes)"; | |
| 213 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { | |
| 214 plot->title = "Incoming RTP packets"; | |
| 215 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { | |
| 216 plot->title = "Outgoing RTP packets"; | |
| 217 } | |
| 218 } | |
| 219 | |
| 220 // For each SSRC, plot the time between the consecutive playouts. | |
| 221 void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) { | |
| 222 std::map<uint32_t, TimeSeries> time_series; | |
| 223 std::map<uint32_t, uint64_t> last_playout; | |
| 224 | |
| 225 uint32_t ssrc; | |
| 226 float max_y = 0; | |
| 227 | |
| 228 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { | |
| 229 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); | |
| 230 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) { | |
| 231 parsed_log_.GetAudioPlayout(i, &ssrc); | |
| 232 uint64_t timestamp = parsed_log_.GetTimestamp(i); | |
| 233 if (MatchingSsrc(ssrc, desired_ssrc_)) { | |
| 234 float x = static_cast<float>(timestamp - begin_time_) / 1000000; | |
| 235 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000; | |
| 236 if (time_series[ssrc].points.size() == 0) { | |
| 237 // There were no previusly logged playout for this SSRC. | |
| 238 // Generate a point, but place it on the x-axis. | |
| 239 y = 0; | |
| 240 } | |
| 241 max_y = std::max(max_y, y); | |
| 242 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y, "")); | |
| 243 last_playout[ssrc] = timestamp; | |
| 244 } | |
| 245 } | |
| 246 } | |
| 247 | |
| 248 // Set labels and put in graph. | |
| 249 for (auto& kv : time_series) { | |
| 250 kv.second.label = SsrcToString(kv.first); | |
| 251 kv.second.style = BAR_GRAPH; | |
| 252 plot->series.push_back(std::move(kv.second)); | |
| 253 } | |
| 254 | |
| 255 plot->xaxis_min = kDefaultXMin; | |
| 256 plot->xaxis_max = (end_time_ - begin_time_) / 1000000 * kXMargin; | |
| 257 plot->xaxis_label = "Time (s)"; | |
| 258 plot->yaxis_min = kDefaultYMin; | |
| 259 plot->yaxis_max = max_y * kYMargin; | |
| 260 plot->yaxis_label = "Time since last playout (ms)"; | |
| 261 plot->title = "Audio playout"; | |
| 262 } | |
| 263 | |
| 264 // For each SSRC, plot the time between the consecutive playouts. | |
| 265 void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) { | |
| 266 std::map<uint32_t, TimeSeries> time_series; | |
| 267 std::map<uint32_t, uint16_t> last_seqno; | |
| 268 | |
| 269 PacketDirection direction; | |
| 270 MediaType media_type; | |
| 271 uint8_t header[IP_PACKET_SIZE]; | |
| 272 size_t header_length, total_length; | |
| 273 | |
| 274 int max_y = 1; | |
| 275 int min_y = 0; | |
| 276 | |
| 277 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { | |
| 278 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); | |
| 279 if (event_type == ParsedRtcEventLog::RTP_EVENT) { | |
| 280 parsed_log_.GetRtpHeader(i, &direction, &media_type, header, | |
| 281 &header_length, &total_length); | |
| 282 uint64_t timestamp = parsed_log_.GetTimestamp(i); | |
| 283 if (direction == PacketDirection::kIncomingPacket) { | |
| 284 // Parse header to get SSRC. | |
| 285 RtpUtility::RtpHeaderParser rtp_parser(header, header_length); | |
| 286 RTPHeader parsed_header; | |
| 287 rtp_parser.Parse(&parsed_header); | |
| 288 // Filter on SSRC. | |
| 289 if (MatchingSsrc(parsed_header.ssrc, desired_ssrc_)) { | |
| 290 float x = static_cast<float>(timestamp - begin_time_) / 1000000; | |
| 291 int y = WrappingDifference(parsed_header.sequenceNumber, | |
| 292 last_seqno[parsed_header.ssrc], 1ul << 16); | |
| 293 if (time_series[parsed_header.ssrc].points.size() == 0) { | |
| 294 // There were no previusly logged playout for this SSRC. | |
| 295 // Generate a point, but place it on the x-axis. | |
| 296 y = 0; | |
| 297 } | |
| 298 max_y = std::max(max_y, y); | |
| 299 min_y = std::min(min_y, y); | |
| 300 time_series[parsed_header.ssrc].points.push_back( | |
| 301 TimeSeriesPoint(x, y, "")); | |
| 302 last_seqno[parsed_header.ssrc] = parsed_header.sequenceNumber; | |
| 303 } | |
| 304 } | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 // Set labels and put in graph. | |
| 309 for (auto& kv : time_series) { | |
| 310 kv.second.label = SsrcToString(kv.first); | |
| 311 kv.second.style = BAR_GRAPH; | |
| 312 plot->series.push_back(std::move(kv.second)); | |
| 313 } | |
| 314 | |
| 315 plot->xaxis_min = kDefaultXMin; | |
| 316 plot->xaxis_max = (end_time_ - begin_time_) / 1000000 * kXMargin; | |
| 317 plot->xaxis_label = "Time (s)"; | |
| 318 plot->yaxis_min = min_y - (kYMargin - 1) / 2 * (max_y - min_y); | |
| 319 plot->yaxis_max = max_y + (kYMargin - 1) / 2 * (max_y - min_y); | |
| 320 plot->yaxis_label = "Difference since last packet"; | |
| 321 plot->title = "Sequence number"; | |
| 322 } | |
| 323 | |
| 324 void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) { | |
| 325 // Maps a stream identifier consisting of ssrc, direction and MediaType | |
| 326 // to the header extensions used by that stream, | |
| 327 std::map<StreamId, RtpHeaderExtensionMap> extension_maps; | |
| 328 | |
| 329 struct SendReceiveTime { | |
| 330 SendReceiveTime() = default; | |
| 331 SendReceiveTime(uint32_t send_time, uint64_t recv_time) | |
| 332 : absolute_send_time(send_time), receive_timestamp(recv_time) {} | |
| 333 uint32_t absolute_send_time; // 24-bit value in units of 2^-18 seconds. | |
| 334 uint64_t receive_timestamp; // In microseconds. | |
| 335 }; | |
| 336 std::map<StreamId, SendReceiveTime> last_packet; | |
| 337 std::map<StreamId, TimeSeries> time_series; | |
| 338 | |
| 339 PacketDirection direction; | |
| 340 MediaType media_type; | |
| 341 uint8_t header[IP_PACKET_SIZE]; | |
| 342 size_t header_length, total_length; | |
| 343 | |
| 344 double max_y = 10; | |
| 345 double min_y = 0; | |
| 346 | |
| 347 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { | |
| 348 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); | |
| 349 if (event_type == ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT) { | |
| 350 VideoReceiveStream::Config config(nullptr); | |
| 351 parsed_log_.GetVideoReceiveConfig(i, &config); | |
| 352 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket, | |
| 353 MediaType::VIDEO); | |
| 354 extension_maps[stream].Erase(); | |
| 355 for (size_t j = 0; j < config.rtp.extensions.size(); ++j) { | |
| 356 const std::string& extension = config.rtp.extensions[j].uri; | |
| 357 int id = config.rtp.extensions[j].id; | |
| 358 extension_maps[stream].Register(StringToRtpExtensionType(extension), | |
| 359 id); | |
| 360 } | |
| 361 } else if (event_type == ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT) { | |
| 362 VideoSendStream::Config config(nullptr); | |
| 363 parsed_log_.GetVideoSendConfig(i, &config); | |
| 364 for (auto ssrc : config.rtp.ssrcs) { | |
| 365 StreamId stream(ssrc, kIncomingPacket, MediaType::VIDEO); | |
| 366 extension_maps[stream].Erase(); | |
| 367 for (size_t j = 0; j < config.rtp.extensions.size(); ++j) { | |
| 368 const std::string& extension = config.rtp.extensions[j].uri; | |
| 369 int id = config.rtp.extensions[j].id; | |
| 370 extension_maps[stream].Register(StringToRtpExtensionType(extension), | |
| 371 id); | |
| 372 } | |
| 373 } | |
| 374 } else if (event_type == ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT) { | |
| 375 AudioReceiveStream::Config config; | |
| 376 // TODO(terelius): Parse the audio configs once we have them | |
| 377 } else if (event_type == ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT) { | |
| 378 AudioSendStream::Config config(nullptr); | |
| 379 // TODO(terelius): Parse the audio configs once we have them | |
| 380 } else if (event_type == ParsedRtcEventLog::RTP_EVENT) { | |
| 381 parsed_log_.GetRtpHeader(i, &direction, &media_type, header, | |
| 382 &header_length, &total_length); | |
| 383 if (direction == kIncomingPacket) { | |
| 384 // Parse header to get SSRC. | |
| 385 RtpUtility::RtpHeaderParser rtp_parser(header, header_length); | |
| 386 RTPHeader parsed_header; | |
| 387 rtp_parser.Parse(&parsed_header); | |
| 388 // Filter on SSRC. | |
| 389 if (MatchingSsrc(parsed_header.ssrc, desired_ssrc_)) { | |
| 390 StreamId stream(parsed_header.ssrc, direction, media_type); | |
| 391 // Look up the extension_map and parse it again to get the extensions. | |
| 392 if (extension_maps.count(stream) == 1) { | |
| 393 RtpHeaderExtensionMap* extension_map = &extension_maps[stream]; | |
| 394 rtp_parser.Parse(&parsed_header, extension_map); | |
| 395 if (parsed_header.extension.hasAbsoluteSendTime) { | |
| 396 uint64_t timestamp = parsed_log_.GetTimestamp(i); | |
| 397 int64_t send_time_diff = WrappingDifference( | |
| 398 parsed_header.extension.absoluteSendTime, | |
| 399 last_packet[stream].absolute_send_time, 1ul << 24); | |
| 400 int64_t recv_time_diff = | |
| 401 timestamp - last_packet[stream].receive_timestamp; | |
| 402 | |
| 403 float x = static_cast<float>(timestamp - begin_time_) / 1000000; | |
| 404 double y = static_cast<double>( | |
| 405 recv_time_diff - | |
| 406 AbsSendTimeToMicroseconds(send_time_diff)) / | |
| 407 1000; | |
| 408 if (time_series[stream].points.size() == 0) { | |
| 409 // There were no previusly logged playout for this SSRC. | |
| 410 // Generate a point, but place it on the x-axis. | |
| 411 y = 0; | |
| 412 } | |
| 413 max_y = std::max(max_y, y); | |
| 414 min_y = std::min(min_y, y); | |
| 415 time_series[stream].points.push_back(TimeSeriesPoint(x, y, "")); | |
| 416 last_packet[stream] = SendReceiveTime( | |
| 417 parsed_header.extension.absoluteSendTime, timestamp); | |
| 418 } | |
| 419 } | |
| 420 } | |
| 421 } | |
| 422 } | |
| 423 } | |
| 424 | |
| 425 // Set labels and put in graph. | |
| 426 for (auto& kv : time_series) { | |
| 427 kv.second.label = SsrcToString(kv.first.GetSsrc()); | |
| 428 kv.second.style = BAR_GRAPH; | |
| 429 plot->series.push_back(std::move(kv.second)); | |
| 430 } | |
| 431 | |
| 432 plot->xaxis_min = kDefaultXMin; | |
| 433 plot->xaxis_max = (end_time_ - begin_time_) / 1000000 * kXMargin; | |
| 434 plot->xaxis_label = "Time (s)"; | |
| 435 plot->yaxis_min = min_y - (kYMargin - 1) / 2 * (max_y - min_y); | |
| 436 plot->yaxis_max = max_y + (kYMargin - 1) / 2 * (max_y - min_y); | |
| 437 plot->yaxis_label = "Latency change (ms)"; | |
| 438 plot->title = "Network latency change between consecutive packets"; | |
| 439 } | |
| 440 | |
| 441 void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) { | |
| 442 // TODO(terelius): Refactor | |
| 443 | |
| 444 // Maps a stream identifier consisting of ssrc, direction and MediaType | |
| 445 // to the header extensions used by that stream. | |
| 446 std::map<StreamId, RtpHeaderExtensionMap> extension_maps; | |
| 447 | |
| 448 struct SendReceiveTime { | |
| 449 SendReceiveTime() = default; | |
| 450 SendReceiveTime(uint32_t send_time, uint64_t recv_time, double accumulated) | |
| 451 : absolute_send_time(send_time), | |
| 452 receive_timestamp(recv_time), | |
| 453 accumulated_delay(accumulated) {} | |
| 454 uint32_t absolute_send_time; // 24-bit value in units of 2^-18 seconds. | |
| 455 uint64_t receive_timestamp; // In microseconds. | |
| 456 double accumulated_delay; // In milliseconds. | |
| 457 }; | |
| 458 std::map<StreamId, SendReceiveTime> last_packet; | |
| 459 std::map<StreamId, TimeSeries> time_series; | |
| 460 | |
| 461 PacketDirection direction; | |
| 462 MediaType media_type; | |
| 463 uint8_t header[IP_PACKET_SIZE]; | |
| 464 size_t header_length, total_length; | |
| 465 | |
| 466 double max_y = 10; | |
| 467 double min_y = 0; | |
| 468 | |
| 469 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { | |
| 470 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); | |
| 471 if (event_type == ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT) { | |
| 472 VideoReceiveStream::Config config(nullptr); | |
| 473 parsed_log_.GetVideoReceiveConfig(i, &config); | |
| 474 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket, | |
| 475 MediaType::VIDEO); | |
| 476 extension_maps[stream].Erase(); | |
| 477 for (size_t j = 0; j < config.rtp.extensions.size(); ++j) { | |
| 478 const std::string& extension = config.rtp.extensions[j].uri; | |
| 479 int id = config.rtp.extensions[j].id; | |
| 480 extension_maps[stream].Register(StringToRtpExtensionType(extension), | |
| 481 id); | |
| 482 } | |
| 483 } else if (event_type == ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT) { | |
| 484 VideoSendStream::Config config(nullptr); | |
| 485 parsed_log_.GetVideoSendConfig(i, &config); | |
| 486 for (auto ssrc : config.rtp.ssrcs) { | |
| 487 StreamId stream(ssrc, kIncomingPacket, MediaType::VIDEO); | |
| 488 extension_maps[stream].Erase(); | |
| 489 for (size_t j = 0; j < config.rtp.extensions.size(); ++j) { | |
| 490 const std::string& extension = config.rtp.extensions[j].uri; | |
| 491 int id = config.rtp.extensions[j].id; | |
| 492 extension_maps[stream].Register(StringToRtpExtensionType(extension), | |
| 493 id); | |
| 494 } | |
| 495 } | |
| 496 } else if (event_type == ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT) { | |
| 497 AudioReceiveStream::Config config; | |
| 498 // TODO(terelius): Parse the audio configs once we have them | |
| 499 } else if (event_type == ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT) { | |
| 500 AudioSendStream::Config config(nullptr); | |
| 501 // TODO(terelius): Parse the audio configs once we have them | |
| 502 } else if (event_type == ParsedRtcEventLog::RTP_EVENT) { | |
| 503 parsed_log_.GetRtpHeader(i, &direction, &media_type, header, | |
| 504 &header_length, &total_length); | |
| 505 if (direction == kIncomingPacket) { | |
| 506 // Parse header to get SSRC. | |
| 507 RtpUtility::RtpHeaderParser rtp_parser(header, header_length); | |
| 508 RTPHeader parsed_header; | |
| 509 rtp_parser.Parse(&parsed_header); | |
| 510 // Filter on SSRC. | |
| 511 if (MatchingSsrc(parsed_header.ssrc, desired_ssrc_)) { | |
| 512 StreamId stream(parsed_header.ssrc, direction, media_type); | |
| 513 // Look up the extension_map and parse it again to get the extensions. | |
| 514 if (extension_maps.count(stream) == 1) { | |
| 515 RtpHeaderExtensionMap* extension_map = &extension_maps[stream]; | |
| 516 rtp_parser.Parse(&parsed_header, extension_map); | |
| 517 if (parsed_header.extension.hasAbsoluteSendTime) { | |
| 518 uint64_t timestamp = parsed_log_.GetTimestamp(i); | |
| 519 int64_t send_time_diff = WrappingDifference( | |
| 520 parsed_header.extension.absoluteSendTime, | |
| 521 last_packet[stream].absolute_send_time, 1ul << 24); | |
| 522 int64_t recv_time_diff = | |
| 523 timestamp - last_packet[stream].receive_timestamp; | |
| 524 | |
| 525 float x = static_cast<float>(timestamp - begin_time_) / 1000000; | |
| 526 double y = last_packet[stream].accumulated_delay + | |
| 527 static_cast<double>( | |
| 528 recv_time_diff - | |
| 529 AbsSendTimeToMicroseconds(send_time_diff)) / | |
| 530 1000; | |
| 531 if (time_series[stream].points.size() == 0) { | |
| 532 // There were no previusly logged playout for this SSRC. | |
| 533 // Generate a point, but place it on the x-axis. | |
| 534 y = 0; | |
| 535 } | |
| 536 max_y = std::max(max_y, y); | |
| 537 min_y = std::min(min_y, y); | |
| 538 time_series[stream].points.push_back(TimeSeriesPoint(x, y, "")); | |
| 539 last_packet[stream] = SendReceiveTime( | |
| 540 parsed_header.extension.absoluteSendTime, timestamp, y); | |
| 541 } | |
| 542 } | |
| 543 } | |
| 544 } | |
| 545 } | |
| 546 } | |
| 547 | |
| 548 // Set labels and put in graph. | |
| 549 for (auto& kv : time_series) { | |
| 550 kv.second.label = SsrcToString(kv.first.GetSsrc()); | |
| 551 kv.second.style = LINE_GRAPH; | |
| 552 plot->series.push_back(std::move(kv.second)); | |
| 553 } | |
| 554 | |
| 555 plot->xaxis_min = kDefaultXMin; | |
| 556 plot->xaxis_max = (end_time_ - begin_time_) / 1000000 * kXMargin; | |
| 557 plot->xaxis_label = "Time (s)"; | |
| 558 plot->yaxis_min = min_y - (kYMargin - 1) / 2 * (max_y - min_y); | |
| 559 plot->yaxis_max = max_y + (kYMargin - 1) / 2 * (max_y - min_y); | |
| 560 plot->yaxis_label = "Latency change (ms)"; | |
| 561 plot->title = "Accumulated network latency change"; | |
| 562 } | |
| 563 | |
| 564 // Plot the total bandwidth used by all RTP streams. | |
| 565 void EventLogAnalyzer::CreateTotalBitrateGraph( | |
| 566 PacketDirection desired_direction, | |
| 567 Plot* plot) { | |
| 568 struct TimestampSize { | |
| 569 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {} | |
| 570 uint64_t timestamp; | |
| 571 size_t size; | |
| 572 }; | |
| 573 std::vector<TimestampSize> packets; | |
| 574 | |
| 575 PacketDirection direction; | |
| 576 size_t total_length; | |
| 577 | |
| 578 // Extract timestamps and sizes for the relevant packets. | |
| 579 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { | |
| 580 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); | |
| 581 if (event_type == ParsedRtcEventLog::RTP_EVENT) { | |
| 582 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, nullptr, | |
| 583 &total_length); | |
| 584 if (direction == desired_direction) { | |
| 585 uint64_t timestamp = parsed_log_.GetTimestamp(i); | |
| 586 packets.push_back(TimestampSize(timestamp, total_length)); | |
| 587 } | |
| 588 } | |
| 589 } | |
| 590 | |
| 591 size_t window_index_begin = 0; | |
| 592 size_t window_index_end = 0; | |
| 593 size_t bytes_in_window = 0; | |
| 594 float max_y = 0; | |
| 595 | |
| 596 // Calculate a moving average of the bitrate and store in a TimeSeries. | |
| 597 plot->series.push_back(TimeSeries()); | |
| 598 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) { | |
| 599 while (window_index_end < packets.size() && | |
| 600 packets[window_index_end].timestamp < time) { | |
| 601 bytes_in_window += packets[window_index_end].size; | |
| 602 window_index_end++; | |
| 603 } | |
| 604 while (window_index_begin < packets.size() && | |
| 605 packets[window_index_begin].timestamp < time - window_duration_) { | |
| 606 bytes_in_window -= packets[window_index_begin].size; | |
| 607 window_index_begin++; | |
| 608 } | |
| 609 RTC_DCHECK_LE(0ul, bytes_in_window); | |
| 610 float window_duration_in_seconds = | |
| 611 static_cast<float>(window_duration_) / 1000000; | |
| 612 float x = static_cast<float>(time - begin_time_) / 1000000; | |
| 613 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; | |
| 614 max_y = std::max(max_y, y); | |
| 615 plot->series.back().points.push_back(TimeSeriesPoint(x, y)); | |
| 616 } | |
| 617 | |
| 618 // Set labels. | |
| 619 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { | |
| 620 plot->series.back().label = "Incoming bitrate"; | |
| 621 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { | |
| 622 plot->series.back().label = "Outgoing bitrate"; | |
| 623 } | |
| 624 plot->series.back().style = LINE_GRAPH; | |
| 625 | |
| 626 plot->xaxis_min = kDefaultXMin; | |
| 627 plot->xaxis_max = (end_time_ - begin_time_) / 1000000 * kXMargin; | |
| 628 plot->xaxis_label = "Time (s)"; | |
| 629 plot->yaxis_min = kDefaultYMin; | |
| 630 plot->yaxis_max = max_y * kYMargin; | |
| 631 plot->yaxis_label = "Bitrate (kbps)"; | |
| 632 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { | |
| 633 plot->title = "Incoming RTP bitrate"; | |
| 634 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { | |
| 635 plot->title = "Outgoing RTP bitrate"; | |
| 636 } | |
| 637 } | |
| 638 | |
| 639 // For each SSRC, plot the bandwitch used by that stream. | |
| 640 void EventLogAnalyzer::CreateStreamBitrateGraph( | |
| 641 PacketDirection desired_direction, | |
| 642 Plot* plot) { | |
| 643 struct TimestampSize { | |
| 644 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {} | |
| 645 uint64_t timestamp; | |
| 646 size_t size; | |
| 647 }; | |
| 648 std::map<uint32_t, std::vector<TimestampSize> > packets; | |
| 649 | |
| 650 PacketDirection direction; | |
| 651 MediaType media_type; | |
| 652 uint8_t header[IP_PACKET_SIZE]; | |
| 653 size_t header_length, total_length; | |
| 654 | |
| 655 // Extract timestamps and sizes for the relevant packets. | |
| 656 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { | |
| 657 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); | |
| 658 if (event_type == ParsedRtcEventLog::RTP_EVENT) { | |
| 659 parsed_log_.GetRtpHeader(i, &direction, &media_type, header, | |
| 660 &header_length, &total_length); | |
| 661 if (direction == desired_direction) { | |
| 662 // Parse header to get SSRC. | |
| 663 RtpUtility::RtpHeaderParser rtp_parser(header, header_length); | |
| 664 RTPHeader parsed_header; | |
| 665 rtp_parser.Parse(&parsed_header); | |
| 666 // Filter on SSRC. | |
| 667 if (MatchingSsrc(parsed_header.ssrc, desired_ssrc_)) { | |
| 668 uint64_t timestamp = parsed_log_.GetTimestamp(i); | |
| 669 packets[parsed_header.ssrc].push_back( | |
| 670 TimestampSize(timestamp, total_length)); | |
| 671 } | |
| 672 } | |
| 673 } | |
| 674 } | |
| 675 | |
| 676 float max_y = 0; | |
| 677 | |
| 678 for (auto& kv : packets) { | |
| 679 size_t window_index_begin = 0; | |
| 680 size_t window_index_end = 0; | |
| 681 size_t bytes_in_window = 0; | |
| 682 | |
| 683 // Calculate a moving average of the bitrate and store in a TimeSeries. | |
| 684 plot->series.push_back(TimeSeries()); | |
| 685 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) { | |
| 686 while (window_index_end < kv.second.size() && | |
| 687 kv.second[window_index_end].timestamp < time) { | |
| 688 bytes_in_window += kv.second[window_index_end].size; | |
| 689 window_index_end++; | |
| 690 } | |
| 691 while (window_index_begin < kv.second.size() && | |
| 692 kv.second[window_index_begin].timestamp < | |
| 693 time - window_duration_) { | |
| 694 bytes_in_window -= kv.second[window_index_begin].size; | |
| 695 window_index_begin++; | |
| 696 } | |
| 697 RTC_DCHECK_LE(0ul, bytes_in_window); | |
| 698 float window_duration_in_seconds = | |
| 699 static_cast<float>(window_duration_) / 1000000; | |
| 700 float x = static_cast<float>(time - begin_time_) / 1000000; | |
| 701 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; | |
| 702 max_y = std::max(max_y, y); | |
| 703 plot->series.back().points.push_back(TimeSeriesPoint(x, y)); | |
| 704 } | |
| 705 | |
| 706 // Set labels. | |
| 707 plot->series.back().label = SsrcToString(kv.first); | |
| 708 plot->series.back().style = LINE_GRAPH; | |
| 709 } | |
| 710 | |
| 711 plot->xaxis_min = kDefaultXMin; | |
| 712 plot->xaxis_max = (end_time_ - begin_time_) / 1000000 * kXMargin; | |
| 713 plot->xaxis_label = "Time (s)"; | |
| 714 plot->yaxis_min = kDefaultYMin; | |
| 715 plot->yaxis_max = max_y * kYMargin; | |
| 716 plot->yaxis_label = "Bitrate (kbps)"; | |
| 717 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { | |
| 718 plot->title = "Incoming bitrate per stream"; | |
| 719 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { | |
| 720 plot->title = "Outgoing bitrate per stream"; | |
| 721 } | |
| 722 } | |
| 723 | |
| 724 } // namespace plotting | |
| 725 } // namespace webrtc | |
| OLD | NEW |