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