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