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