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