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