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