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