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