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