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