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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "rtc_tools/event_log_visualizer/analyzer.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
| 14 | #include <limits> |
| 15 | #include <map> |
| 16 | #include <sstream> |
| 17 | #include <string> |
| 18 | #include <utility> |
| 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "call/audio_receive_stream.h" |
| 21 | #include "call/audio_send_stream.h" |
| 22 | #include "call/call.h" |
| 23 | #include "call/video_receive_stream.h" |
| 24 | #include "call/video_send_stream.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 25 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "modules/audio_coding/neteq/tools/audio_sink.h" |
| 27 | #include "modules/audio_coding/neteq/tools/fake_decode_from_file.h" |
| 28 | #include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h" |
| 29 | #include "modules/audio_coding/neteq/tools/neteq_replacement_input.h" |
| 30 | #include "modules/audio_coding/neteq/tools/neteq_test.h" |
| 31 | #include "modules/audio_coding/neteq/tools/resample_input_audio_file.h" |
| 32 | #include "modules/congestion_controller/include/send_side_congestion_controller.h" |
| 33 | #include "modules/include/module_common_types.h" |
| 34 | #include "modules/rtp_rtcp/include/rtp_rtcp.h" |
| 35 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 36 | #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 37 | #include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 38 | #include "modules/rtp_rtcp/source/rtcp_packet/remb.h" |
| 39 | #include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
| 40 | #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 41 | #include "modules/rtp_rtcp/source/rtp_header_extensions.h" |
| 42 | #include "modules/rtp_rtcp/source/rtp_utility.h" |
| 43 | #include "rtc_base/checks.h" |
| 44 | #include "rtc_base/format_macros.h" |
| 45 | #include "rtc_base/logging.h" |
| 46 | #include "rtc_base/ptr_util.h" |
| 47 | #include "rtc_base/rate_statistics.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 48 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 49 | namespace webrtc { |
| 50 | namespace plotting { |
| 51 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 52 | namespace { |
| 53 | |
elad.alon | ec304f9 | 2017-03-08 05:03:53 -0800 | [diff] [blame] | 54 | void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) { |
| 55 | auto pred = [](const PacketFeedback& packet_feedback) { |
| 56 | return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived; |
| 57 | }; |
| 58 | vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end()); |
| 59 | std::sort(vec->begin(), vec->end(), PacketFeedbackComparator()); |
| 60 | } |
| 61 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 62 | std::string SsrcToString(uint32_t ssrc) { |
| 63 | std::stringstream ss; |
| 64 | ss << "SSRC " << ssrc; |
| 65 | return ss.str(); |
| 66 | } |
| 67 | |
| 68 | // Checks whether an SSRC is contained in the list of desired SSRCs. |
| 69 | // Note that an empty SSRC list matches every SSRC. |
| 70 | bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) { |
| 71 | if (desired_ssrc.size() == 0) |
| 72 | return true; |
| 73 | return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) != |
| 74 | desired_ssrc.end(); |
| 75 | } |
| 76 | |
| 77 | double AbsSendTimeToMicroseconds(int64_t abs_send_time) { |
| 78 | // The timestamp is a fixed point representation with 6 bits for seconds |
| 79 | // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the |
| 80 | // time in seconds and then multiply by 1000000 to convert to microseconds. |
| 81 | static constexpr double kTimestampToMicroSec = |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 82 | 1000000.0 / static_cast<double>(1ul << 18); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 83 | return abs_send_time * kTimestampToMicroSec; |
| 84 | } |
| 85 | |
| 86 | // Computes the difference |later| - |earlier| where |later| and |earlier| |
| 87 | // are counters that wrap at |modulus|. The difference is chosen to have the |
| 88 | // least absolute value. For example if |modulus| is 8, then the difference will |
| 89 | // be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will |
| 90 | // be in [-4, 4]. |
| 91 | int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) { |
| 92 | RTC_DCHECK_LE(1, modulus); |
| 93 | RTC_DCHECK_LT(later, modulus); |
| 94 | RTC_DCHECK_LT(earlier, modulus); |
| 95 | int64_t difference = |
| 96 | static_cast<int64_t>(later) - static_cast<int64_t>(earlier); |
| 97 | int64_t max_difference = modulus / 2; |
| 98 | int64_t min_difference = max_difference - modulus + 1; |
| 99 | if (difference > max_difference) { |
| 100 | difference -= modulus; |
| 101 | } |
| 102 | if (difference < min_difference) { |
| 103 | difference += modulus; |
| 104 | } |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 105 | if (difference > max_difference / 2 || difference < min_difference / 2) { |
| 106 | LOG(LS_WARNING) << "Difference between" << later << " and " << earlier |
| 107 | << " expected to be in the range (" << min_difference / 2 |
| 108 | << "," << max_difference / 2 << ") but is " << difference |
| 109 | << ". Correct unwrapping is uncertain."; |
| 110 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 111 | return difference; |
| 112 | } |
| 113 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 114 | // Return default values for header extensions, to use on streams without stored |
| 115 | // mapping data. Currently this only applies to audio streams, since the mapping |
| 116 | // is not stored in the event log. |
| 117 | // TODO(ivoc): Remove this once this mapping is stored in the event log for |
| 118 | // audio streams. Tracking bug: webrtc:6399 |
| 119 | webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() { |
| 120 | webrtc::RtpHeaderExtensionMap default_map; |
danilchap | 4aecc58 | 2016-11-15 09:21:00 -0800 | [diff] [blame] | 121 | default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId); |
terelius | 007d562 | 2017-08-08 05:40:26 -0700 | [diff] [blame] | 122 | default_map.Register<TransmissionOffset>( |
| 123 | webrtc::RtpExtension::kTimestampOffsetDefaultId); |
danilchap | 4aecc58 | 2016-11-15 09:21:00 -0800 | [diff] [blame] | 124 | default_map.Register<AbsoluteSendTime>( |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 125 | webrtc::RtpExtension::kAbsSendTimeDefaultId); |
terelius | 007d562 | 2017-08-08 05:40:26 -0700 | [diff] [blame] | 126 | default_map.Register<VideoOrientation>( |
| 127 | webrtc::RtpExtension::kVideoRotationDefaultId); |
| 128 | default_map.Register<VideoContentTypeExtension>( |
| 129 | webrtc::RtpExtension::kVideoContentTypeDefaultId); |
| 130 | default_map.Register<VideoTimingExtension>( |
| 131 | webrtc::RtpExtension::kVideoTimingDefaultId); |
| 132 | default_map.Register<TransportSequenceNumber>( |
| 133 | webrtc::RtpExtension::kTransportSequenceNumberDefaultId); |
| 134 | default_map.Register<PlayoutDelayLimits>( |
| 135 | webrtc::RtpExtension::kPlayoutDelayDefaultId); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 136 | return default_map; |
| 137 | } |
| 138 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 139 | constexpr float kLeftMargin = 0.01f; |
| 140 | constexpr float kRightMargin = 0.02f; |
| 141 | constexpr float kBottomMargin = 0.02f; |
| 142 | constexpr float kTopMargin = 0.05f; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 143 | |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 144 | rtc::Optional<double> NetworkDelayDiff_AbsSendTime( |
| 145 | const LoggedRtpPacket& old_packet, |
| 146 | const LoggedRtpPacket& new_packet) { |
| 147 | if (old_packet.header.extension.hasAbsoluteSendTime && |
| 148 | new_packet.header.extension.hasAbsoluteSendTime) { |
| 149 | int64_t send_time_diff = WrappingDifference( |
| 150 | new_packet.header.extension.absoluteSendTime, |
| 151 | old_packet.header.extension.absoluteSendTime, 1ul << 24); |
| 152 | int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
| 153 | double delay_change_us = |
| 154 | recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff); |
| 155 | return rtc::Optional<double>(delay_change_us / 1000); |
| 156 | } else { |
| 157 | return rtc::Optional<double>(); |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 161 | rtc::Optional<double> NetworkDelayDiff_CaptureTime( |
| 162 | const LoggedRtpPacket& old_packet, |
| 163 | const LoggedRtpPacket& new_packet) { |
| 164 | int64_t send_time_diff = WrappingDifference( |
| 165 | new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32); |
| 166 | int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
| 167 | |
| 168 | const double kVideoSampleRate = 90000; |
| 169 | // TODO(terelius): We treat all streams as video for now, even though |
| 170 | // audio might be sampled at e.g. 16kHz, because it is really difficult to |
| 171 | // figure out the true sampling rate of a stream. The effect is that the |
| 172 | // delay will be scaled incorrectly for non-video streams. |
| 173 | |
| 174 | double delay_change = |
| 175 | static_cast<double>(recv_time_diff) / 1000 - |
| 176 | static_cast<double>(send_time_diff) / kVideoSampleRate * 1000; |
| 177 | if (delay_change < -10000 || 10000 < delay_change) { |
| 178 | LOG(LS_WARNING) << "Very large delay change. Timestamps correct?"; |
| 179 | LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp |
| 180 | << ", received time " << old_packet.timestamp; |
| 181 | LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp |
| 182 | << ", received time " << new_packet.timestamp; |
| 183 | LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = " |
| 184 | << static_cast<double>(recv_time_diff) / 1000000 << "s"; |
| 185 | LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = " |
| 186 | << static_cast<double>(send_time_diff) / kVideoSampleRate |
| 187 | << "s"; |
| 188 | } |
| 189 | return rtc::Optional<double>(delay_change); |
| 190 | } |
| 191 | |
| 192 | // For each element in data, use |get_y()| to extract a y-coordinate and |
| 193 | // store the result in a TimeSeries. |
| 194 | template <typename DataType> |
| 195 | void ProcessPoints( |
| 196 | rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y, |
| 197 | const std::vector<DataType>& data, |
| 198 | uint64_t begin_time, |
| 199 | TimeSeries* result) { |
| 200 | for (size_t i = 0; i < data.size(); i++) { |
| 201 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
| 202 | rtc::Optional<float> y = get_y(data[i]); |
| 203 | if (y) |
| 204 | result->points.emplace_back(x, *y); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // For each pair of adjacent elements in |data|, use |get_y| to extract a |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 209 | // y-coordinate and store the result in a TimeSeries. Note that the x-coordinate |
| 210 | // will be the time of the second element in the pair. |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 211 | template <typename DataType, typename ResultType> |
| 212 | void ProcessPairs( |
| 213 | rtc::FunctionView<rtc::Optional<ResultType>(const DataType&, |
| 214 | const DataType&)> get_y, |
| 215 | const std::vector<DataType>& data, |
| 216 | uint64_t begin_time, |
| 217 | TimeSeries* result) { |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 218 | for (size_t i = 1; i < data.size(); i++) { |
| 219 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 220 | rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]); |
| 221 | if (y) |
| 222 | result->points.emplace_back(x, static_cast<float>(*y)); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // For each element in data, use |extract()| to extract a y-coordinate and |
| 227 | // store the result in a TimeSeries. |
| 228 | template <typename DataType, typename ResultType> |
| 229 | void AccumulatePoints( |
| 230 | rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract, |
| 231 | const std::vector<DataType>& data, |
| 232 | uint64_t begin_time, |
| 233 | TimeSeries* result) { |
| 234 | ResultType sum = 0; |
| 235 | for (size_t i = 0; i < data.size(); i++) { |
| 236 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
| 237 | rtc::Optional<ResultType> y = extract(data[i]); |
| 238 | if (y) { |
| 239 | sum += *y; |
| 240 | result->points.emplace_back(x, static_cast<float>(sum)); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | // For each pair of adjacent elements in |data|, use |extract()| 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. |
| 248 | template <typename DataType, typename ResultType> |
| 249 | void AccumulatePairs( |
| 250 | rtc::FunctionView<rtc::Optional<ResultType>(const DataType&, |
| 251 | const DataType&)> extract, |
| 252 | const std::vector<DataType>& data, |
| 253 | uint64_t begin_time, |
| 254 | TimeSeries* result) { |
| 255 | ResultType sum = 0; |
| 256 | for (size_t i = 1; i < data.size(); i++) { |
| 257 | float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
| 258 | rtc::Optional<ResultType> y = extract(data[i - 1], data[i]); |
| 259 | if (y) |
| 260 | sum += *y; |
| 261 | result->points.emplace_back(x, static_cast<float>(sum)); |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 265 | // Calculates a moving average of |data| and stores the result in a TimeSeries. |
| 266 | // A data point is generated every |step| microseconds from |begin_time| |
| 267 | // to |end_time|. The value of each data point is the average of the data |
| 268 | // during the preceeding |window_duration_us| microseconds. |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 269 | template <typename DataType, typename ResultType> |
| 270 | void MovingAverage( |
| 271 | rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract, |
| 272 | const std::vector<DataType>& data, |
| 273 | uint64_t begin_time, |
| 274 | uint64_t end_time, |
| 275 | uint64_t window_duration_us, |
| 276 | uint64_t step, |
| 277 | webrtc::plotting::TimeSeries* result) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 278 | size_t window_index_begin = 0; |
| 279 | size_t window_index_end = 0; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 280 | ResultType sum_in_window = 0; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 281 | |
| 282 | for (uint64_t t = begin_time; t < end_time + step; t += step) { |
| 283 | while (window_index_end < data.size() && |
| 284 | data[window_index_end].timestamp < t) { |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 285 | rtc::Optional<ResultType> value = extract(data[window_index_end]); |
| 286 | if (value) |
| 287 | sum_in_window += *value; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 288 | ++window_index_end; |
| 289 | } |
| 290 | while (window_index_begin < data.size() && |
| 291 | data[window_index_begin].timestamp < t - window_duration_us) { |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 292 | rtc::Optional<ResultType> value = extract(data[window_index_begin]); |
| 293 | if (value) |
| 294 | sum_in_window -= *value; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 295 | ++window_index_begin; |
| 296 | } |
| 297 | float window_duration_s = static_cast<float>(window_duration_us) / 1000000; |
| 298 | float x = static_cast<float>(t - begin_time) / 1000000; |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 299 | float y = sum_in_window / window_duration_s; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 300 | result->points.emplace_back(x, y); |
| 301 | } |
| 302 | } |
| 303 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 304 | } // namespace |
| 305 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 306 | EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log) |
| 307 | : parsed_log_(log), window_duration_(250000), step_(10000) { |
| 308 | uint64_t first_timestamp = std::numeric_limits<uint64_t>::max(); |
| 309 | uint64_t last_timestamp = std::numeric_limits<uint64_t>::min(); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 310 | |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 311 | PacketDirection direction; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 312 | uint8_t header[IP_PACKET_SIZE]; |
| 313 | size_t header_length; |
| 314 | size_t total_length; |
| 315 | |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 316 | uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE]; |
| 317 | uint8_t last_incoming_rtcp_packet_length = 0; |
| 318 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 319 | // Make a default extension map for streams without configuration information. |
| 320 | // TODO(ivoc): Once configuration of audio streams is stored in the event log, |
| 321 | // this can be removed. Tracking bug: webrtc:6399 |
| 322 | RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap(); |
| 323 | |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 324 | rtc::Optional<uint64_t> last_log_start; |
| 325 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 326 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 327 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 328 | if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT && |
| 329 | event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT && |
| 330 | event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT && |
terelius | 88c1d2b | 2016-08-01 05:20:33 -0700 | [diff] [blame] | 331 | event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT && |
| 332 | event_type != ParsedRtcEventLog::LOG_START && |
| 333 | event_type != ParsedRtcEventLog::LOG_END) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 334 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 335 | first_timestamp = std::min(first_timestamp, timestamp); |
| 336 | last_timestamp = std::max(last_timestamp, timestamp); |
| 337 | } |
| 338 | |
| 339 | switch (parsed_log_.GetEventType(i)) { |
| 340 | case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: { |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 341 | rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i); |
perkj | 09e71da | 2017-05-22 03:26:49 -0700 | [diff] [blame] | 342 | StreamId stream(config.remote_ssrc, kIncomingPacket); |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 343 | video_ssrcs_.insert(stream); |
perkj | 09e71da | 2017-05-22 03:26:49 -0700 | [diff] [blame] | 344 | StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 345 | video_ssrcs_.insert(rtx_stream); |
| 346 | rtx_ssrcs_.insert(rtx_stream); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 347 | break; |
| 348 | } |
| 349 | case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: { |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 350 | std::vector<rtclog::StreamConfig> configs = |
| 351 | parsed_log_.GetVideoSendConfig(i); |
terelius | 405f90c | 2017-06-01 03:50:31 -0700 | [diff] [blame] | 352 | for (const auto& config : configs) { |
| 353 | StreamId stream(config.local_ssrc, kOutgoingPacket); |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 354 | video_ssrcs_.insert(stream); |
terelius | 405f90c | 2017-06-01 03:50:31 -0700 | [diff] [blame] | 355 | StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket); |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 356 | video_ssrcs_.insert(rtx_stream); |
| 357 | rtx_ssrcs_.insert(rtx_stream); |
| 358 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: { |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 362 | rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i); |
perkj | ac8f52d | 2017-05-22 09:36:28 -0700 | [diff] [blame] | 363 | StreamId stream(config.remote_ssrc, kIncomingPacket); |
ivoc | e0928d8 | 2016-10-10 05:12:51 -0700 | [diff] [blame] | 364 | audio_ssrcs_.insert(stream); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 365 | break; |
| 366 | } |
| 367 | case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: { |
terelius | 8fbc765 | 2017-05-31 02:03:16 -0700 | [diff] [blame] | 368 | rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i); |
perkj | f472699 | 2017-05-22 10:12:26 -0700 | [diff] [blame] | 369 | StreamId stream(config.local_ssrc, kOutgoingPacket); |
ivoc | e0928d8 | 2016-10-10 05:12:51 -0700 | [diff] [blame] | 370 | audio_ssrcs_.insert(stream); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 371 | break; |
| 372 | } |
| 373 | case ParsedRtcEventLog::RTP_EVENT: { |
ilnik | a8e781a | 2017-06-12 01:02:46 -0700 | [diff] [blame] | 374 | RtpHeaderExtensionMap* extension_map = parsed_log_.GetRtpHeader( |
| 375 | i, &direction, header, &header_length, &total_length); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 376 | RtpUtility::RtpHeaderParser rtp_parser(header, header_length); |
| 377 | RTPHeader parsed_header; |
ilnik | a8e781a | 2017-06-12 01:02:46 -0700 | [diff] [blame] | 378 | if (extension_map != nullptr) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 379 | rtp_parser.Parse(&parsed_header, extension_map); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 380 | } else { |
| 381 | // Use the default extension map. |
| 382 | // TODO(ivoc): Once configuration of audio streams is stored in the |
| 383 | // event log, this can be removed. |
| 384 | // Tracking bug: webrtc:6399 |
| 385 | rtp_parser.Parse(&parsed_header, &default_extension_map); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 386 | } |
| 387 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
ilnik | a8e781a | 2017-06-12 01:02:46 -0700 | [diff] [blame] | 388 | StreamId stream(parsed_header.ssrc, direction); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 389 | rtp_packets_[stream].push_back( |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 390 | LoggedRtpPacket(timestamp, parsed_header, total_length)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 391 | break; |
| 392 | } |
| 393 | case ParsedRtcEventLog::RTCP_EVENT: { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 394 | uint8_t packet[IP_PACKET_SIZE]; |
perkj | 77cd58e | 2017-05-30 03:52:10 -0700 | [diff] [blame] | 395 | parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length); |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 396 | // Currently incoming RTCP packets are logged twice, both for audio and |
| 397 | // video. Only act on one of them. Compare against the previous parsed |
| 398 | // incoming RTCP packet. |
| 399 | if (direction == webrtc::kIncomingPacket) { |
| 400 | RTC_CHECK_LE(total_length, IP_PACKET_SIZE); |
| 401 | if (total_length == last_incoming_rtcp_packet_length && |
| 402 | memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) { |
| 403 | continue; |
| 404 | } else { |
| 405 | memcpy(last_incoming_rtcp_packet, packet, total_length); |
| 406 | last_incoming_rtcp_packet_length = total_length; |
| 407 | } |
| 408 | } |
| 409 | rtcp::CommonHeader header; |
| 410 | const uint8_t* packet_end = packet + total_length; |
| 411 | for (const uint8_t* block = packet; block < packet_end; |
| 412 | block = header.NextPacket()) { |
| 413 | RTC_CHECK(header.Parse(block, packet_end - block)); |
| 414 | if (header.type() == rtcp::TransportFeedback::kPacketType && |
| 415 | header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) { |
| 416 | std::unique_ptr<rtcp::TransportFeedback> rtcp_packet( |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 417 | rtc::MakeUnique<rtcp::TransportFeedback>()); |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 418 | if (rtcp_packet->Parse(header)) { |
| 419 | uint32_t ssrc = rtcp_packet->sender_ssrc(); |
| 420 | StreamId stream(ssrc, direction); |
| 421 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 422 | rtcp_packets_[stream].push_back(LoggedRtcpPacket( |
| 423 | timestamp, kRtcpTransportFeedback, std::move(rtcp_packet))); |
| 424 | } |
| 425 | } else if (header.type() == rtcp::SenderReport::kPacketType) { |
| 426 | std::unique_ptr<rtcp::SenderReport> rtcp_packet( |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 427 | rtc::MakeUnique<rtcp::SenderReport>()); |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 428 | if (rtcp_packet->Parse(header)) { |
| 429 | uint32_t ssrc = rtcp_packet->sender_ssrc(); |
| 430 | StreamId stream(ssrc, direction); |
| 431 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 432 | rtcp_packets_[stream].push_back( |
| 433 | LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet))); |
| 434 | } |
| 435 | } else if (header.type() == rtcp::ReceiverReport::kPacketType) { |
| 436 | std::unique_ptr<rtcp::ReceiverReport> rtcp_packet( |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 437 | rtc::MakeUnique<rtcp::ReceiverReport>()); |
perkj | bbbad6d | 2017-05-19 06:30:28 -0700 | [diff] [blame] | 438 | if (rtcp_packet->Parse(header)) { |
| 439 | uint32_t ssrc = rtcp_packet->sender_ssrc(); |
| 440 | StreamId stream(ssrc, direction); |
| 441 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 442 | rtcp_packets_[stream].push_back( |
| 443 | LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet))); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 444 | } |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 445 | } else if (header.type() == rtcp::Remb::kPacketType && |
| 446 | header.fmt() == rtcp::Remb::kFeedbackMessageType) { |
| 447 | std::unique_ptr<rtcp::Remb> rtcp_packet( |
| 448 | rtc::MakeUnique<rtcp::Remb>()); |
| 449 | if (rtcp_packet->Parse(header)) { |
| 450 | uint32_t ssrc = rtcp_packet->sender_ssrc(); |
| 451 | StreamId stream(ssrc, direction); |
| 452 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 453 | rtcp_packets_[stream].push_back(LoggedRtcpPacket( |
| 454 | timestamp, kRtcpRemb, std::move(rtcp_packet))); |
| 455 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 456 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 457 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 458 | break; |
| 459 | } |
| 460 | case ParsedRtcEventLog::LOG_START: { |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 461 | if (last_log_start) { |
| 462 | // A LOG_END event was missing. Use last_timestamp. |
| 463 | RTC_DCHECK_GE(last_timestamp, *last_log_start); |
| 464 | log_segments_.push_back( |
| 465 | std::make_pair(*last_log_start, last_timestamp)); |
| 466 | } |
| 467 | last_log_start = rtc::Optional<uint64_t>(parsed_log_.GetTimestamp(i)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 468 | break; |
| 469 | } |
| 470 | case ParsedRtcEventLog::LOG_END: { |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 471 | RTC_DCHECK(last_log_start); |
| 472 | log_segments_.push_back( |
| 473 | std::make_pair(*last_log_start, parsed_log_.GetTimestamp(i))); |
| 474 | last_log_start.reset(); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 475 | break; |
| 476 | } |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 477 | case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: { |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 478 | uint32_t this_ssrc; |
| 479 | parsed_log_.GetAudioPlayout(i, &this_ssrc); |
| 480 | audio_playout_events_[this_ssrc].push_back(parsed_log_.GetTimestamp(i)); |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 481 | break; |
| 482 | } |
| 483 | case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: { |
| 484 | LossBasedBweUpdate bwe_update; |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 485 | bwe_update.timestamp = parsed_log_.GetTimestamp(i); |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 486 | parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate, |
| 487 | &bwe_update.fraction_loss, |
| 488 | &bwe_update.expected_packets); |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 489 | bwe_loss_updates_.push_back(bwe_update); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 490 | break; |
| 491 | } |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 492 | case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: { |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 493 | bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i)); |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 494 | break; |
| 495 | } |
minyue | 4b7c952 | 2017-01-24 04:54:59 -0800 | [diff] [blame] | 496 | case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 497 | AudioNetworkAdaptationEvent ana_event; |
| 498 | ana_event.timestamp = parsed_log_.GetTimestamp(i); |
| 499 | parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config); |
| 500 | audio_network_adaptation_events_.push_back(ana_event); |
minyue | 4b7c952 | 2017-01-24 04:54:59 -0800 | [diff] [blame] | 501 | break; |
| 502 | } |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 503 | case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: { |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 504 | bwe_probe_cluster_created_events_.push_back( |
| 505 | parsed_log_.GetBweProbeClusterCreated(i)); |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 506 | break; |
| 507 | } |
| 508 | case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: { |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 509 | bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i)); |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 510 | break; |
| 511 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 512 | case ParsedRtcEventLog::UNKNOWN_EVENT: { |
| 513 | break; |
| 514 | } |
| 515 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 516 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 517 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 518 | if (last_timestamp < first_timestamp) { |
| 519 | // No useful events in the log. |
| 520 | first_timestamp = last_timestamp = 0; |
| 521 | } |
| 522 | begin_time_ = first_timestamp; |
| 523 | end_time_ = last_timestamp; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 524 | call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 525 | if (last_log_start) { |
| 526 | // The log was missing the last LOG_END event. Fake it. |
| 527 | log_segments_.push_back(std::make_pair(*last_log_start, end_time_)); |
| 528 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Niels Möller | 245f17e | 2017-08-21 10:45:07 +0200 | [diff] [blame] | 531 | class BitrateObserver : public SendSideCongestionController::Observer, |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 532 | public RemoteBitrateObserver { |
| 533 | public: |
| 534 | BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {} |
| 535 | |
| 536 | void OnNetworkChanged(uint32_t bitrate_bps, |
| 537 | uint8_t fraction_loss, |
minyue | 78b4d56 | 2016-11-30 04:47:39 -0800 | [diff] [blame] | 538 | int64_t rtt_ms, |
| 539 | int64_t probing_interval_ms) override { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 540 | last_bitrate_bps_ = bitrate_bps; |
| 541 | bitrate_updated_ = true; |
| 542 | } |
| 543 | |
| 544 | void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 545 | uint32_t bitrate) override {} |
| 546 | |
| 547 | uint32_t last_bitrate_bps() const { return last_bitrate_bps_; } |
| 548 | bool GetAndResetBitrateUpdated() { |
| 549 | bool bitrate_updated = bitrate_updated_; |
| 550 | bitrate_updated_ = false; |
| 551 | return bitrate_updated; |
| 552 | } |
| 553 | |
| 554 | private: |
| 555 | uint32_t last_bitrate_bps_; |
| 556 | bool bitrate_updated_; |
| 557 | }; |
| 558 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 559 | bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 560 | return rtx_ssrcs_.count(stream_id) == 1; |
| 561 | } |
| 562 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 563 | bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 564 | return video_ssrcs_.count(stream_id) == 1; |
| 565 | } |
| 566 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 567 | bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const { |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 568 | return audio_ssrcs_.count(stream_id) == 1; |
| 569 | } |
| 570 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 571 | std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const { |
| 572 | std::stringstream name; |
| 573 | if (IsAudioSsrc(stream_id)) { |
| 574 | name << "Audio "; |
| 575 | } else if (IsVideoSsrc(stream_id)) { |
| 576 | name << "Video "; |
| 577 | } else { |
| 578 | name << "Unknown "; |
| 579 | } |
| 580 | if (IsRtxSsrc(stream_id)) |
| 581 | name << "RTX "; |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 582 | if (stream_id.GetDirection() == kIncomingPacket) { |
| 583 | name << "(In) "; |
| 584 | } else { |
| 585 | name << "(Out) "; |
| 586 | } |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 587 | name << SsrcToString(stream_id.GetSsrc()); |
| 588 | return name.str(); |
| 589 | } |
| 590 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 591 | void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction, |
| 592 | Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 593 | for (auto& kv : rtp_packets_) { |
| 594 | StreamId stream_id = kv.first; |
| 595 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 596 | // Filter on direction and SSRC. |
| 597 | if (stream_id.GetDirection() != desired_direction || |
| 598 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 599 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 600 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 601 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 602 | TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 603 | ProcessPoints<LoggedRtpPacket>( |
| 604 | [](const LoggedRtpPacket& packet) -> rtc::Optional<float> { |
| 605 | return rtc::Optional<float>(packet.total_length); |
| 606 | }, |
| 607 | packet_stream, begin_time_, &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 608 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 609 | } |
| 610 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 611 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 612 | plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin, |
| 613 | kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 614 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 615 | plot->SetTitle("Incoming RTP packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 616 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 617 | plot->SetTitle("Outgoing RTP packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 621 | template <typename T> |
| 622 | void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries( |
| 623 | PacketDirection desired_direction, |
| 624 | Plot* plot, |
| 625 | const std::map<StreamId, std::vector<T>>& packets, |
| 626 | const std::string& label_prefix) { |
| 627 | for (auto& kv : packets) { |
| 628 | StreamId stream_id = kv.first; |
| 629 | const std::vector<T>& packet_stream = kv.second; |
| 630 | // Filter on direction and SSRC. |
| 631 | if (stream_id.GetDirection() != desired_direction || |
| 632 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 633 | continue; |
| 634 | } |
| 635 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 636 | std::string label = label_prefix + " " + GetStreamName(stream_id); |
| 637 | TimeSeries time_series(label, LINE_STEP_GRAPH); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 638 | for (size_t i = 0; i < packet_stream.size(); i++) { |
| 639 | float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) / |
| 640 | 1000000; |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 641 | time_series.points.emplace_back(x, i + 1); |
| 642 | } |
| 643 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 644 | plot->AppendTimeSeries(std::move(time_series)); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
| 648 | void EventLogAnalyzer::CreateAccumulatedPacketsGraph( |
| 649 | PacketDirection desired_direction, |
| 650 | Plot* plot) { |
| 651 | CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_, |
| 652 | "RTP"); |
| 653 | CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_, |
| 654 | "RTCP"); |
| 655 | |
| 656 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 657 | plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin); |
| 658 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
| 659 | plot->SetTitle("Accumulated Incoming RTP/RTCP packets"); |
| 660 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
| 661 | plot->SetTitle("Accumulated Outgoing RTP/RTCP packets"); |
| 662 | } |
| 663 | } |
| 664 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 665 | // For each SSRC, plot the time between the consecutive playouts. |
| 666 | void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) { |
| 667 | std::map<uint32_t, TimeSeries> time_series; |
| 668 | std::map<uint32_t, uint64_t> last_playout; |
| 669 | |
| 670 | uint32_t ssrc; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 671 | |
| 672 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 673 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
| 674 | if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) { |
| 675 | parsed_log_.GetAudioPlayout(i, &ssrc); |
| 676 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 677 | if (MatchingSsrc(ssrc, desired_ssrc_)) { |
| 678 | float x = static_cast<float>(timestamp - begin_time_) / 1000000; |
| 679 | float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000; |
| 680 | if (time_series[ssrc].points.size() == 0) { |
| 681 | // There were no previusly logged playout for this SSRC. |
| 682 | // Generate a point, but place it on the x-axis. |
| 683 | y = 0; |
| 684 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 685 | time_series[ssrc].points.push_back(TimeSeriesPoint(x, y)); |
| 686 | last_playout[ssrc] = timestamp; |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | // Set labels and put in graph. |
| 692 | for (auto& kv : time_series) { |
| 693 | kv.second.label = SsrcToString(kv.first); |
| 694 | kv.second.style = BAR_GRAPH; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 695 | plot->AppendTimeSeries(std::move(kv.second)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 696 | } |
| 697 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 698 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 699 | plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin, |
| 700 | kTopMargin); |
| 701 | plot->SetTitle("Audio playout"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 702 | } |
| 703 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 704 | // For audio SSRCs, plot the audio level. |
| 705 | void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) { |
| 706 | std::map<StreamId, TimeSeries> time_series; |
| 707 | |
| 708 | for (auto& kv : rtp_packets_) { |
| 709 | StreamId stream_id = kv.first; |
| 710 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 711 | // TODO(ivoc): When audio send/receive configs are stored in the event |
| 712 | // log, a check should be added here to only process audio |
| 713 | // streams. Tracking bug: webrtc:6399 |
| 714 | for (auto& packet : packet_stream) { |
| 715 | if (packet.header.extension.hasAudioLevel) { |
| 716 | float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000; |
| 717 | // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10) |
| 718 | // Here we convert it to dBov. |
| 719 | float y = static_cast<float>(-packet.header.extension.audioLevel); |
| 720 | time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y)); |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | for (auto& series : time_series) { |
| 726 | series.second.label = GetStreamName(series.first); |
| 727 | series.second.style = LINE_GRAPH; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 728 | plot->AppendTimeSeries(std::move(series.second)); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
ivoc | bf67663 | 2016-11-24 08:30:34 -0800 | [diff] [blame] | 732 | plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 733 | kTopMargin); |
| 734 | plot->SetTitle("Audio level"); |
| 735 | } |
| 736 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 737 | // For each SSRC, plot the time between the consecutive playouts. |
| 738 | void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 739 | for (auto& kv : rtp_packets_) { |
| 740 | StreamId stream_id = kv.first; |
| 741 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 742 | // Filter on direction and SSRC. |
| 743 | if (stream_id.GetDirection() != kIncomingPacket || |
| 744 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 745 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 746 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 747 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 748 | TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 749 | ProcessPairs<LoggedRtpPacket, float>( |
| 750 | [](const LoggedRtpPacket& old_packet, |
| 751 | const LoggedRtpPacket& new_packet) { |
| 752 | int64_t diff = |
| 753 | WrappingDifference(new_packet.header.sequenceNumber, |
| 754 | old_packet.header.sequenceNumber, 1ul << 16); |
| 755 | return rtc::Optional<float>(diff); |
| 756 | }, |
| 757 | packet_stream, begin_time_, &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 758 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 759 | } |
| 760 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 761 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 762 | plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin, |
| 763 | kTopMargin); |
| 764 | plot->SetTitle("Sequence number"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 767 | void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) { |
| 768 | for (auto& kv : rtp_packets_) { |
| 769 | StreamId stream_id = kv.first; |
| 770 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 771 | // Filter on direction and SSRC. |
| 772 | if (stream_id.GetDirection() != kIncomingPacket || |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 773 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) || |
| 774 | packet_stream.size() == 0) { |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 775 | continue; |
| 776 | } |
| 777 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 778 | TimeSeries time_series(GetStreamName(stream_id), LINE_DOT_GRAPH); |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 779 | const uint64_t kWindowUs = 1000000; |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 780 | const uint64_t kStep = 1000000; |
| 781 | SequenceNumberUnwrapper unwrapper_; |
| 782 | SequenceNumberUnwrapper prior_unwrapper_; |
| 783 | size_t window_index_begin = 0; |
| 784 | size_t window_index_end = 0; |
| 785 | int64_t highest_seq_number = |
| 786 | unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1; |
| 787 | int64_t highest_prior_seq_number = |
| 788 | prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1; |
| 789 | |
| 790 | for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) { |
| 791 | while (window_index_end < packet_stream.size() && |
| 792 | packet_stream[window_index_end].timestamp < t) { |
| 793 | int64_t sequence_number = unwrapper_.Unwrap( |
| 794 | packet_stream[window_index_end].header.sequenceNumber); |
| 795 | highest_seq_number = std::max(highest_seq_number, sequence_number); |
| 796 | ++window_index_end; |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 797 | } |
terelius | 4c9b4af | 2017-01-30 08:44:51 -0800 | [diff] [blame] | 798 | while (window_index_begin < packet_stream.size() && |
| 799 | packet_stream[window_index_begin].timestamp < t - kWindowUs) { |
| 800 | int64_t sequence_number = prior_unwrapper_.Unwrap( |
| 801 | packet_stream[window_index_begin].header.sequenceNumber); |
| 802 | highest_prior_seq_number = |
| 803 | std::max(highest_prior_seq_number, sequence_number); |
| 804 | ++window_index_begin; |
| 805 | } |
| 806 | float x = static_cast<float>(t - begin_time_) / 1000000; |
| 807 | int64_t expected_packets = highest_seq_number - highest_prior_seq_number; |
| 808 | if (expected_packets > 0) { |
| 809 | int64_t received_packets = window_index_end - window_index_begin; |
| 810 | int64_t lost_packets = expected_packets - received_packets; |
| 811 | float y = static_cast<float>(lost_packets) / expected_packets * 100; |
| 812 | time_series.points.emplace_back(x, y); |
| 813 | } |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 814 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 815 | plot->AppendTimeSeries(std::move(time_series)); |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 819 | plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin, |
| 820 | kTopMargin); |
| 821 | plot->SetTitle("Estimated incoming loss rate"); |
| 822 | } |
| 823 | |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 824 | void EventLogAnalyzer::CreateIncomingDelayDeltaGraph(Plot* plot) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 825 | for (auto& kv : rtp_packets_) { |
| 826 | StreamId stream_id = kv.first; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 827 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 828 | // Filter on direction and SSRC. |
| 829 | if (stream_id.GetDirection() != kIncomingPacket || |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 830 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) || |
| 831 | IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) || |
| 832 | IsRtxSsrc(stream_id)) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 833 | continue; |
| 834 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 835 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 836 | TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time", |
| 837 | BAR_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 838 | ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime, |
| 839 | packet_stream, begin_time_, |
| 840 | &capture_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 841 | plot->AppendTimeSeries(std::move(capture_time_data)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 842 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 843 | TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time", |
| 844 | BAR_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 845 | ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime, |
| 846 | packet_stream, begin_time_, |
| 847 | &send_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 848 | plot->AppendTimeSeries(std::move(send_time_data)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 849 | } |
| 850 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 851 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 852 | plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin, |
| 853 | kTopMargin); |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 854 | plot->SetTitle("Network latency difference between consecutive packets"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 855 | } |
| 856 | |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 857 | void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 858 | for (auto& kv : rtp_packets_) { |
| 859 | StreamId stream_id = kv.first; |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 860 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 861 | // Filter on direction and SSRC. |
| 862 | if (stream_id.GetDirection() != kIncomingPacket || |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 863 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) || |
| 864 | IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) || |
| 865 | IsRtxSsrc(stream_id)) { |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 866 | continue; |
| 867 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 868 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 869 | TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time", |
| 870 | LINE_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 871 | AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime, |
| 872 | packet_stream, begin_time_, |
| 873 | &capture_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 874 | plot->AppendTimeSeries(std::move(capture_time_data)); |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 875 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 876 | TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time", |
| 877 | LINE_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 878 | AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime, |
| 879 | packet_stream, begin_time_, |
| 880 | &send_time_data); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 881 | plot->AppendTimeSeries(std::move(send_time_data)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 882 | } |
| 883 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 884 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 885 | plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin, |
| 886 | kTopMargin); |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 887 | plot->SetTitle("Network latency (relative to first packet)"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 888 | } |
| 889 | |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 890 | // Plot the fraction of packets lost (as perceived by the loss-based BWE). |
| 891 | void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 892 | TimeSeries time_series("Fraction lost", LINE_DOT_GRAPH); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 893 | for (auto& bwe_update : bwe_loss_updates_) { |
| 894 | float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000; |
| 895 | float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 896 | time_series.points.emplace_back(x, y); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 897 | } |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 898 | |
| 899 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 900 | plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin, |
| 901 | kTopMargin); |
| 902 | plot->SetTitle("Reported packet loss"); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 903 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 904 | } |
| 905 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 906 | // Plot the total bandwidth used by all RTP streams. |
| 907 | void EventLogAnalyzer::CreateTotalBitrateGraph( |
| 908 | PacketDirection desired_direction, |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 909 | Plot* plot, |
| 910 | bool show_detector_state) { |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 911 | struct TimestampSize { |
| 912 | TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {} |
| 913 | uint64_t timestamp; |
| 914 | size_t size; |
| 915 | }; |
| 916 | std::vector<TimestampSize> packets; |
| 917 | |
| 918 | PacketDirection direction; |
| 919 | size_t total_length; |
| 920 | |
| 921 | // Extract timestamps and sizes for the relevant packets. |
| 922 | for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) { |
| 923 | ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i); |
| 924 | if (event_type == ParsedRtcEventLog::RTP_EVENT) { |
perkj | 77cd58e | 2017-05-30 03:52:10 -0700 | [diff] [blame] | 925 | parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 926 | if (direction == desired_direction) { |
| 927 | uint64_t timestamp = parsed_log_.GetTimestamp(i); |
| 928 | packets.push_back(TimestampSize(timestamp, total_length)); |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | size_t window_index_begin = 0; |
| 934 | size_t window_index_end = 0; |
| 935 | size_t bytes_in_window = 0; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 936 | |
| 937 | // Calculate a moving average of the bitrate and store in a TimeSeries. |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 938 | TimeSeries bitrate_series("Bitrate", LINE_GRAPH); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 939 | for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) { |
| 940 | while (window_index_end < packets.size() && |
| 941 | packets[window_index_end].timestamp < time) { |
| 942 | bytes_in_window += packets[window_index_end].size; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 943 | ++window_index_end; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 944 | } |
| 945 | while (window_index_begin < packets.size() && |
| 946 | packets[window_index_begin].timestamp < time - window_duration_) { |
| 947 | RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window); |
| 948 | bytes_in_window -= packets[window_index_begin].size; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 949 | ++window_index_begin; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 950 | } |
| 951 | float window_duration_in_seconds = |
| 952 | static_cast<float>(window_duration_) / 1000000; |
| 953 | float x = static_cast<float>(time - begin_time_) / 1000000; |
| 954 | float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 955 | bitrate_series.points.emplace_back(x, y); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 956 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 957 | plot->AppendTimeSeries(std::move(bitrate_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 958 | |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 959 | // Overlay the send-side bandwidth estimate over the outgoing bitrate. |
| 960 | if (desired_direction == kOutgoingPacket) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 961 | TimeSeries loss_series("Loss-based estimate", LINE_STEP_GRAPH); |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 962 | for (auto& loss_update : bwe_loss_updates_) { |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 963 | float x = |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 964 | static_cast<float>(loss_update.timestamp - begin_time_) / 1000000; |
| 965 | float y = static_cast<float>(loss_update.new_bitrate) / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 966 | loss_series.points.emplace_back(x, y); |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 967 | } |
| 968 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 969 | TimeSeries delay_series("Delay-based estimate", LINE_STEP_GRAPH); |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 970 | IntervalSeries overusing_series("Overusing", "#ff8e82", |
| 971 | IntervalSeries::kHorizontal); |
| 972 | IntervalSeries underusing_series("Underusing", "#5092fc", |
| 973 | IntervalSeries::kHorizontal); |
| 974 | IntervalSeries normal_series("Normal", "#c4ffc4", |
| 975 | IntervalSeries::kHorizontal); |
| 976 | IntervalSeries* last_series = &normal_series; |
| 977 | double last_detector_switch = 0.0; |
| 978 | |
| 979 | BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal; |
| 980 | |
philipel | 10fc0e6 | 2017-04-11 01:50:23 -0700 | [diff] [blame] | 981 | for (auto& delay_update : bwe_delay_updates_) { |
| 982 | float x = |
| 983 | static_cast<float>(delay_update.timestamp - begin_time_) / 1000000; |
| 984 | float y = static_cast<float>(delay_update.bitrate_bps) / 1000; |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 985 | |
| 986 | if (last_detector_state != delay_update.detector_state) { |
| 987 | last_series->intervals.emplace_back(last_detector_switch, x); |
| 988 | last_detector_state = delay_update.detector_state; |
| 989 | last_detector_switch = x; |
| 990 | |
| 991 | switch (delay_update.detector_state) { |
| 992 | case BandwidthUsage::kBwNormal: |
| 993 | last_series = &normal_series; |
| 994 | break; |
| 995 | case BandwidthUsage::kBwUnderusing: |
| 996 | last_series = &underusing_series; |
| 997 | break; |
| 998 | case BandwidthUsage::kBwOverusing: |
| 999 | last_series = &overusing_series; |
| 1000 | break; |
| 1001 | } |
| 1002 | } |
| 1003 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1004 | delay_series.points.emplace_back(x, y); |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 1005 | } |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 1006 | |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 1007 | RTC_CHECK(last_series); |
| 1008 | last_series->intervals.emplace_back(last_detector_switch, end_time_); |
| 1009 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1010 | TimeSeries created_series("Probe cluster created.", DOT_GRAPH); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 1011 | for (auto& cluster : bwe_probe_cluster_created_events_) { |
| 1012 | float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000; |
| 1013 | float y = static_cast<float>(cluster.bitrate_bps) / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1014 | created_series.points.emplace_back(x, y); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 1015 | } |
| 1016 | |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1017 | TimeSeries result_series("Probing results.", DOT_GRAPH); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 1018 | for (auto& result : bwe_probe_result_events_) { |
| 1019 | if (result.bitrate_bps) { |
| 1020 | float x = static_cast<float>(result.timestamp - begin_time_) / 1000000; |
| 1021 | float y = static_cast<float>(*result.bitrate_bps) / 1000; |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1022 | result_series.points.emplace_back(x, y); |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 1023 | } |
| 1024 | } |
philipel | 23c7f25 | 2017-07-14 06:30:03 -0700 | [diff] [blame] | 1025 | |
| 1026 | if (show_detector_state) { |
| 1027 | plot->AppendIntervalSeries(std::move(overusing_series)); |
| 1028 | plot->AppendIntervalSeries(std::move(underusing_series)); |
| 1029 | plot->AppendIntervalSeries(std::move(normal_series)); |
| 1030 | } |
| 1031 | |
| 1032 | plot->AppendTimeSeries(std::move(bitrate_series)); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1033 | plot->AppendTimeSeries(std::move(loss_series)); |
| 1034 | plot->AppendTimeSeries(std::move(delay_series)); |
| 1035 | plot->AppendTimeSeries(std::move(created_series)); |
| 1036 | plot->AppendTimeSeries(std::move(result_series)); |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 1037 | } |
philipel | e127e7a | 2017-03-29 16:28:53 +0200 | [diff] [blame] | 1038 | |
terelius | 2c8e8a3 | 2017-06-02 01:29:48 -0700 | [diff] [blame] | 1039 | // Overlay the incoming REMB over the outgoing bitrate |
| 1040 | // and outgoing REMB over incoming bitrate. |
| 1041 | PacketDirection remb_direction = |
| 1042 | desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket; |
| 1043 | TimeSeries remb_series("Remb", LINE_STEP_GRAPH); |
| 1044 | std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets; |
| 1045 | for (const auto& kv : rtcp_packets_) { |
| 1046 | if (kv.first.GetDirection() == remb_direction) { |
| 1047 | for (const LoggedRtcpPacket& rtcp_packet : kv.second) { |
| 1048 | if (rtcp_packet.type == kRtcpRemb) { |
| 1049 | remb_packets.insert( |
| 1050 | std::make_pair(rtcp_packet.timestamp, &rtcp_packet)); |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | for (const auto& kv : remb_packets) { |
| 1057 | const LoggedRtcpPacket* const rtcp = kv.second; |
| 1058 | const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get()); |
| 1059 | float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000; |
| 1060 | float y = static_cast<float>(remb->bitrate_bps()) / 1000; |
| 1061 | remb_series.points.emplace_back(x, y); |
| 1062 | } |
| 1063 | plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series)); |
| 1064 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1065 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1066 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1067 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1068 | plot->SetTitle("Incoming RTP bitrate"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1069 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1070 | plot->SetTitle("Outgoing RTP bitrate"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | // For each SSRC, plot the bandwidth used by that stream. |
| 1075 | void EventLogAnalyzer::CreateStreamBitrateGraph( |
| 1076 | PacketDirection desired_direction, |
| 1077 | Plot* plot) { |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 1078 | for (auto& kv : rtp_packets_) { |
| 1079 | StreamId stream_id = kv.first; |
| 1080 | const std::vector<LoggedRtpPacket>& packet_stream = kv.second; |
| 1081 | // Filter on direction and SSRC. |
| 1082 | if (stream_id.GetDirection() != desired_direction || |
| 1083 | !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) { |
| 1084 | continue; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1087 | TimeSeries time_series(GetStreamName(stream_id), LINE_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1088 | MovingAverage<LoggedRtpPacket, double>( |
| 1089 | [](const LoggedRtpPacket& packet) { |
| 1090 | return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0); |
| 1091 | }, |
| 1092 | packet_stream, begin_time_, end_time_, window_duration_, step_, |
| 1093 | &time_series); |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1094 | plot->AppendTimeSeries(std::move(time_series)); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1097 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1098 | plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1099 | if (desired_direction == webrtc::PacketDirection::kIncomingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1100 | plot->SetTitle("Incoming bitrate per stream"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1101 | } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) { |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1102 | plot->SetTitle("Outgoing bitrate per stream"); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1103 | } |
| 1104 | } |
| 1105 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 1106 | void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) { |
stefan | ff42162 | 2017-04-20 03:24:01 -0700 | [diff] [blame] | 1107 | std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp; |
| 1108 | std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1109 | |
| 1110 | for (const auto& kv : rtp_packets_) { |
| 1111 | if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) { |
| 1112 | for (const LoggedRtpPacket& rtp_packet : kv.second) |
| 1113 | outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet)); |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | for (const auto& kv : rtcp_packets_) { |
| 1118 | if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) { |
| 1119 | for (const LoggedRtcpPacket& rtcp_packet : kv.second) |
| 1120 | incoming_rtcp.insert( |
| 1121 | std::make_pair(rtcp_packet.timestamp, &rtcp_packet)); |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | SimulatedClock clock(0); |
| 1126 | BitrateObserver observer; |
| 1127 | RtcEventLogNullImpl null_event_log; |
nisse | 0245da0 | 2016-11-30 03:35:20 -0800 | [diff] [blame] | 1128 | PacketRouter packet_router; |
Stefan Holmer | 5c8942a | 2017-08-22 16:16:44 +0200 | [diff] [blame] | 1129 | PacedSender pacer(&clock, &packet_router, &null_event_log); |
| 1130 | SendSideCongestionController cc(&clock, &observer, &null_event_log, &pacer); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1131 | // TODO(holmer): Log the call config and use that here instead. |
| 1132 | static const uint32_t kDefaultStartBitrateBps = 300000; |
| 1133 | cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1); |
| 1134 | |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1135 | TimeSeries time_series("Delay-based estimate", LINE_DOT_GRAPH); |
| 1136 | TimeSeries acked_time_series("Acked bitrate", LINE_DOT_GRAPH); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1137 | |
| 1138 | auto rtp_iterator = outgoing_rtp.begin(); |
| 1139 | auto rtcp_iterator = incoming_rtcp.begin(); |
| 1140 | |
| 1141 | auto NextRtpTime = [&]() { |
| 1142 | if (rtp_iterator != outgoing_rtp.end()) |
| 1143 | return static_cast<int64_t>(rtp_iterator->first); |
| 1144 | return std::numeric_limits<int64_t>::max(); |
| 1145 | }; |
| 1146 | |
| 1147 | auto NextRtcpTime = [&]() { |
| 1148 | if (rtcp_iterator != incoming_rtcp.end()) |
| 1149 | return static_cast<int64_t>(rtcp_iterator->first); |
| 1150 | return std::numeric_limits<int64_t>::max(); |
| 1151 | }; |
| 1152 | |
| 1153 | auto NextProcessTime = [&]() { |
| 1154 | if (rtcp_iterator != incoming_rtcp.end() || |
| 1155 | rtp_iterator != outgoing_rtp.end()) { |
| 1156 | return clock.TimeInMicroseconds() + |
| 1157 | std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0); |
| 1158 | } |
| 1159 | return std::numeric_limits<int64_t>::max(); |
| 1160 | }; |
| 1161 | |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1162 | RateStatistics acked_bitrate(250, 8000); |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1163 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1164 | int64_t time_us = std::min(NextRtpTime(), NextRtcpTime()); |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1165 | int64_t last_update_us = 0; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1166 | while (time_us != std::numeric_limits<int64_t>::max()) { |
| 1167 | clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds()); |
| 1168 | if (clock.TimeInMicroseconds() >= NextRtcpTime()) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1169 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1170 | const LoggedRtcpPacket& rtcp = *rtcp_iterator->second; |
| 1171 | if (rtcp.type == kRtcpTransportFeedback) { |
elad.alon | 5bbf43f | 2017-03-09 06:40:08 -0800 | [diff] [blame] | 1172 | cc.OnTransportFeedback( |
| 1173 | *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get())); |
| 1174 | std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector(); |
elad.alon | ec304f9 | 2017-03-08 05:03:53 -0800 | [diff] [blame] | 1175 | SortPacketFeedbackVector(&feedback); |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1176 | rtc::Optional<uint32_t> bitrate_bps; |
| 1177 | if (!feedback.empty()) { |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame] | 1178 | for (const PacketFeedback& packet : feedback) |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1179 | acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms); |
| 1180 | bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms); |
| 1181 | } |
| 1182 | uint32_t y = 0; |
| 1183 | if (bitrate_bps) |
| 1184 | y = *bitrate_bps / 1000; |
| 1185 | float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 1186 | 1000000; |
| 1187 | acked_time_series.points.emplace_back(x, y); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1188 | } |
| 1189 | ++rtcp_iterator; |
| 1190 | } |
| 1191 | if (clock.TimeInMicroseconds() >= NextRtpTime()) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1192 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1193 | const LoggedRtpPacket& rtp = *rtp_iterator->second; |
| 1194 | if (rtp.header.extension.hasTransportSequenceNumber) { |
| 1195 | RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber); |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 1196 | cc.AddPacket(rtp.header.ssrc, |
| 1197 | rtp.header.extension.transportSequenceNumber, |
elad.alon | 5bbf43f | 2017-03-09 06:40:08 -0800 | [diff] [blame] | 1198 | rtp.total_length, PacedPacketInfo()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1199 | rtc::SentPacket sent_packet( |
| 1200 | rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000); |
| 1201 | cc.OnSentPacket(sent_packet); |
| 1202 | } |
| 1203 | ++rtp_iterator; |
| 1204 | } |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1205 | if (clock.TimeInMicroseconds() >= NextProcessTime()) { |
| 1206 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime()); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1207 | cc.Process(); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1208 | } |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1209 | if (observer.GetAndResetBitrateUpdated() || |
| 1210 | time_us - last_update_us >= 1e6) { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1211 | uint32_t y = observer.last_bitrate_bps() / 1000; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1212 | float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 1213 | 1000000; |
| 1214 | time_series.points.emplace_back(x, y); |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 1215 | last_update_us = time_us; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1216 | } |
| 1217 | time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()}); |
| 1218 | } |
| 1219 | // Add the data set to the plot. |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1220 | plot->AppendTimeSeries(std::move(time_series)); |
| 1221 | plot->AppendTimeSeries(std::move(acked_time_series)); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1222 | |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 1223 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1224 | plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); |
| 1225 | plot->SetTitle("Simulated BWE behavior"); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 1226 | } |
| 1227 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 1228 | void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) { |
stefan | ff42162 | 2017-04-20 03:24:01 -0700 | [diff] [blame] | 1229 | std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp; |
| 1230 | std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp; |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1231 | |
| 1232 | for (const auto& kv : rtp_packets_) { |
| 1233 | if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) { |
| 1234 | for (const LoggedRtpPacket& rtp_packet : kv.second) |
| 1235 | outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet)); |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | for (const auto& kv : rtcp_packets_) { |
| 1240 | if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) { |
| 1241 | for (const LoggedRtcpPacket& rtcp_packet : kv.second) |
| 1242 | incoming_rtcp.insert( |
| 1243 | std::make_pair(rtcp_packet.timestamp, &rtcp_packet)); |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | SimulatedClock clock(0); |
elad.alon | 5bbf43f | 2017-03-09 06:40:08 -0800 | [diff] [blame] | 1248 | TransportFeedbackAdapter feedback_adapter(&clock); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1249 | |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1250 | TimeSeries late_feedback_series("Late feedback results.", DOT_GRAPH); |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1251 | TimeSeries time_series("Network Delay Change", LINE_DOT_GRAPH); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1252 | int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max(); |
| 1253 | |
| 1254 | auto rtp_iterator = outgoing_rtp.begin(); |
| 1255 | auto rtcp_iterator = incoming_rtcp.begin(); |
| 1256 | |
| 1257 | auto NextRtpTime = [&]() { |
| 1258 | if (rtp_iterator != outgoing_rtp.end()) |
| 1259 | return static_cast<int64_t>(rtp_iterator->first); |
| 1260 | return std::numeric_limits<int64_t>::max(); |
| 1261 | }; |
| 1262 | |
| 1263 | auto NextRtcpTime = [&]() { |
| 1264 | if (rtcp_iterator != incoming_rtcp.end()) |
| 1265 | return static_cast<int64_t>(rtcp_iterator->first); |
| 1266 | return std::numeric_limits<int64_t>::max(); |
| 1267 | }; |
| 1268 | |
| 1269 | int64_t time_us = std::min(NextRtpTime(), NextRtcpTime()); |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1270 | int64_t prev_y = 0; |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1271 | while (time_us != std::numeric_limits<int64_t>::max()) { |
| 1272 | clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds()); |
| 1273 | if (clock.TimeInMicroseconds() >= NextRtcpTime()) { |
| 1274 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime()); |
| 1275 | const LoggedRtcpPacket& rtcp = *rtcp_iterator->second; |
| 1276 | if (rtcp.type == kRtcpTransportFeedback) { |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 1277 | feedback_adapter.OnTransportFeedback( |
| 1278 | *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get())); |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame] | 1279 | std::vector<PacketFeedback> feedback = |
| 1280 | feedback_adapter.GetTransportFeedbackVector(); |
elad.alon | ec304f9 | 2017-03-08 05:03:53 -0800 | [diff] [blame] | 1281 | SortPacketFeedbackVector(&feedback); |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame] | 1282 | for (const PacketFeedback& packet : feedback) { |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1283 | float x = |
| 1284 | static_cast<float>(clock.TimeInMicroseconds() - begin_time_) / |
| 1285 | 1000000; |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1286 | if (packet.send_time_ms == -1) { |
| 1287 | late_feedback_series.points.emplace_back(x, prev_y); |
| 1288 | continue; |
| 1289 | } |
| 1290 | int64_t y = packet.arrival_time_ms - packet.send_time_ms; |
| 1291 | prev_y = y; |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1292 | estimated_base_delay_ms = std::min(y, estimated_base_delay_ms); |
| 1293 | time_series.points.emplace_back(x, y); |
| 1294 | } |
| 1295 | } |
| 1296 | ++rtcp_iterator; |
| 1297 | } |
| 1298 | if (clock.TimeInMicroseconds() >= NextRtpTime()) { |
| 1299 | RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime()); |
| 1300 | const LoggedRtpPacket& rtp = *rtp_iterator->second; |
| 1301 | if (rtp.header.extension.hasTransportSequenceNumber) { |
| 1302 | RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber); |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 1303 | feedback_adapter.AddPacket(rtp.header.ssrc, |
| 1304 | rtp.header.extension.transportSequenceNumber, |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 1305 | rtp.total_length, PacedPacketInfo()); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1306 | feedback_adapter.OnSentPacket( |
| 1307 | rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000); |
| 1308 | } |
| 1309 | ++rtp_iterator; |
| 1310 | } |
| 1311 | time_us = std::min(NextRtpTime(), NextRtcpTime()); |
| 1312 | } |
| 1313 | // We assume that the base network delay (w/o queues) is the min delay |
| 1314 | // observed during the call. |
| 1315 | for (TimeSeriesPoint& point : time_series.points) |
| 1316 | point.y -= estimated_base_delay_ms; |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1317 | for (TimeSeriesPoint& point : late_feedback_series.points) |
| 1318 | point.y -= estimated_base_delay_ms; |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1319 | // Add the data set to the plot. |
stefan | a0a8ed7 | 2017-09-06 02:06:32 -0700 | [diff] [blame] | 1320 | plot->AppendTimeSeriesIfNotEmpty(std::move(time_series)); |
| 1321 | plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series)); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 1322 | |
| 1323 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1324 | plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin); |
| 1325 | plot->SetTitle("Network Delay Change."); |
| 1326 | } |
stefan | 0838327 | 2016-12-20 08:51:52 -0800 | [diff] [blame] | 1327 | |
| 1328 | std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps() |
| 1329 | const { |
| 1330 | std::vector<std::pair<int64_t, int64_t>> timestamps; |
| 1331 | size_t largest_stream_size = 0; |
| 1332 | const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr; |
| 1333 | // Find the incoming video stream with the most number of packets that is |
| 1334 | // not rtx. |
| 1335 | for (const auto& kv : rtp_packets_) { |
| 1336 | if (kv.first.GetDirection() == kIncomingPacket && |
| 1337 | video_ssrcs_.find(kv.first) != video_ssrcs_.end() && |
| 1338 | rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() && |
| 1339 | kv.second.size() > largest_stream_size) { |
| 1340 | largest_stream_size = kv.second.size(); |
| 1341 | largest_video_stream = &kv.second; |
| 1342 | } |
| 1343 | } |
| 1344 | if (largest_video_stream == nullptr) { |
| 1345 | for (auto& packet : *largest_video_stream) { |
| 1346 | if (packet.header.markerBit) { |
| 1347 | int64_t capture_ms = packet.header.timestamp / 90.0; |
| 1348 | int64_t arrival_ms = packet.timestamp / 1000.0; |
| 1349 | timestamps.push_back(std::make_pair(capture_ms, arrival_ms)); |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | return timestamps; |
| 1354 | } |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1355 | |
| 1356 | void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) { |
| 1357 | for (const auto& kv : rtp_packets_) { |
| 1358 | const std::vector<LoggedRtpPacket>& rtp_packets = kv.second; |
| 1359 | StreamId stream_id = kv.first; |
| 1360 | |
| 1361 | { |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1362 | TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time", |
| 1363 | LINE_DOT_GRAPH); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1364 | for (LoggedRtpPacket packet : rtp_packets) { |
| 1365 | float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000; |
| 1366 | float y = packet.header.timestamp; |
| 1367 | timestamp_data.points.emplace_back(x, y); |
| 1368 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1369 | plot->AppendTimeSeries(std::move(timestamp_data)); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | { |
| 1373 | auto kv = rtcp_packets_.find(stream_id); |
| 1374 | if (kv != rtcp_packets_.end()) { |
| 1375 | const auto& packets = kv->second; |
terelius | 23c595a | 2017-03-15 01:59:12 -0700 | [diff] [blame] | 1376 | TimeSeries timestamp_data( |
| 1377 | GetStreamName(stream_id) + " rtcp capture-time", LINE_DOT_GRAPH); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1378 | for (const LoggedRtcpPacket& rtcp : packets) { |
| 1379 | if (rtcp.type != kRtcpSr) |
| 1380 | continue; |
| 1381 | rtcp::SenderReport* sr; |
| 1382 | sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get()); |
| 1383 | float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000; |
| 1384 | float y = sr->rtp_timestamp(); |
| 1385 | timestamp_data.points.emplace_back(x, y); |
| 1386 | } |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1387 | plot->AppendTimeSeries(std::move(timestamp_data)); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 1388 | } |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1393 | plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin); |
| 1394 | plot->SetTitle("Timestamps"); |
| 1395 | } |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1396 | |
| 1397 | void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1398 | TimeSeries time_series("Audio encoder target bitrate", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1399 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1400 | [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1401 | if (ana_event.config.bitrate_bps) |
| 1402 | return rtc::Optional<float>( |
| 1403 | static_cast<float>(*ana_event.config.bitrate_bps)); |
| 1404 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1405 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1406 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1407 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1408 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1409 | plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin); |
| 1410 | plot->SetTitle("Reported audio encoder target bitrate"); |
| 1411 | } |
| 1412 | |
| 1413 | void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1414 | TimeSeries time_series("Audio encoder frame length", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1415 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1416 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1417 | if (ana_event.config.frame_length_ms) |
| 1418 | return rtc::Optional<float>( |
| 1419 | static_cast<float>(*ana_event.config.frame_length_ms)); |
| 1420 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1421 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1422 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1423 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1424 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1425 | plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin); |
| 1426 | plot->SetTitle("Reported audio encoder frame length"); |
| 1427 | } |
| 1428 | |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 1429 | void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1430 | TimeSeries time_series("Audio encoder uplink packet loss fraction", |
| 1431 | LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1432 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1433 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1434 | if (ana_event.config.uplink_packet_loss_fraction) |
| 1435 | return rtc::Optional<float>(static_cast<float>( |
| 1436 | *ana_event.config.uplink_packet_loss_fraction)); |
| 1437 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1438 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1439 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1440 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1441 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1442 | plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin, |
| 1443 | kTopMargin); |
| 1444 | plot->SetTitle("Reported audio encoder lost packets"); |
| 1445 | } |
| 1446 | |
| 1447 | void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1448 | TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1449 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1450 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1451 | if (ana_event.config.enable_fec) |
| 1452 | return rtc::Optional<float>( |
| 1453 | static_cast<float>(*ana_event.config.enable_fec)); |
| 1454 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1455 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1456 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1457 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1458 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1459 | plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin); |
| 1460 | plot->SetTitle("Reported audio encoder FEC"); |
| 1461 | } |
| 1462 | |
| 1463 | void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1464 | TimeSeries time_series("Audio encoder DTX", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1465 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1466 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1467 | if (ana_event.config.enable_dtx) |
| 1468 | return rtc::Optional<float>( |
| 1469 | static_cast<float>(*ana_event.config.enable_dtx)); |
| 1470 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1471 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1472 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1473 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1474 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1475 | plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin); |
| 1476 | plot->SetTitle("Reported audio encoder DTX"); |
| 1477 | } |
| 1478 | |
| 1479 | void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) { |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1480 | TimeSeries time_series("Audio encoder number of channels", LINE_DOT_GRAPH); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1481 | ProcessPoints<AudioNetworkAdaptationEvent>( |
| 1482 | [](const AudioNetworkAdaptationEvent& ana_event) { |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1483 | if (ana_event.config.num_channels) |
| 1484 | return rtc::Optional<float>( |
| 1485 | static_cast<float>(*ana_event.config.num_channels)); |
| 1486 | return rtc::Optional<float>(); |
terelius | 53dc23c | 2017-03-13 05:24:05 -0700 | [diff] [blame] | 1487 | }, |
philipel | 35ba9bd | 2017-04-19 05:58:51 -0700 | [diff] [blame] | 1488 | audio_network_adaptation_events_, begin_time_, &time_series); |
| 1489 | plot->AppendTimeSeries(std::move(time_series)); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 1490 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1491 | plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))", |
| 1492 | kBottomMargin, kTopMargin); |
| 1493 | plot->SetTitle("Reported audio encoder number of channels"); |
| 1494 | } |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 1495 | |
| 1496 | class NetEqStreamInput : public test::NetEqInput { |
| 1497 | public: |
| 1498 | // Does not take any ownership, and all pointers must refer to valid objects |
| 1499 | // that outlive the one constructed. |
| 1500 | NetEqStreamInput(const std::vector<LoggedRtpPacket>* packet_stream, |
| 1501 | const std::vector<uint64_t>* output_events_us, |
| 1502 | rtc::Optional<uint64_t> end_time_us) |
| 1503 | : packet_stream_(*packet_stream), |
| 1504 | packet_stream_it_(packet_stream_.begin()), |
| 1505 | output_events_us_it_(output_events_us->begin()), |
| 1506 | output_events_us_end_(output_events_us->end()), |
| 1507 | end_time_us_(end_time_us) { |
| 1508 | RTC_DCHECK(packet_stream); |
| 1509 | RTC_DCHECK(output_events_us); |
| 1510 | } |
| 1511 | |
| 1512 | rtc::Optional<int64_t> NextPacketTime() const override { |
| 1513 | if (packet_stream_it_ == packet_stream_.end()) { |
| 1514 | return rtc::Optional<int64_t>(); |
| 1515 | } |
| 1516 | if (end_time_us_ && packet_stream_it_->timestamp > *end_time_us_) { |
| 1517 | return rtc::Optional<int64_t>(); |
| 1518 | } |
| 1519 | // Convert from us to ms. |
| 1520 | return rtc::Optional<int64_t>(packet_stream_it_->timestamp / 1000); |
| 1521 | } |
| 1522 | |
| 1523 | rtc::Optional<int64_t> NextOutputEventTime() const override { |
| 1524 | if (output_events_us_it_ == output_events_us_end_) { |
| 1525 | return rtc::Optional<int64_t>(); |
| 1526 | } |
| 1527 | if (end_time_us_ && *output_events_us_it_ > *end_time_us_) { |
| 1528 | return rtc::Optional<int64_t>(); |
| 1529 | } |
| 1530 | // Convert from us to ms. |
| 1531 | return rtc::Optional<int64_t>( |
| 1532 | rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000)); |
| 1533 | } |
| 1534 | |
| 1535 | std::unique_ptr<PacketData> PopPacket() override { |
| 1536 | if (packet_stream_it_ == packet_stream_.end()) { |
| 1537 | return std::unique_ptr<PacketData>(); |
| 1538 | } |
| 1539 | std::unique_ptr<PacketData> packet_data(new PacketData()); |
| 1540 | packet_data->header = packet_stream_it_->header; |
| 1541 | // Convert from us to ms. |
| 1542 | packet_data->time_ms = packet_stream_it_->timestamp / 1000.0; |
| 1543 | |
| 1544 | // This is a header-only "dummy" packet. Set the payload to all zeros, with |
| 1545 | // length according to the virtual length. |
| 1546 | packet_data->payload.SetSize(packet_stream_it_->total_length); |
| 1547 | std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0); |
| 1548 | |
| 1549 | ++packet_stream_it_; |
| 1550 | return packet_data; |
| 1551 | } |
| 1552 | |
| 1553 | void AdvanceOutputEvent() override { |
| 1554 | if (output_events_us_it_ != output_events_us_end_) { |
| 1555 | ++output_events_us_it_; |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | bool ended() const override { return !NextEventTime(); } |
| 1560 | |
| 1561 | rtc::Optional<RTPHeader> NextHeader() const override { |
| 1562 | if (packet_stream_it_ == packet_stream_.end()) { |
| 1563 | return rtc::Optional<RTPHeader>(); |
| 1564 | } |
| 1565 | return rtc::Optional<RTPHeader>(packet_stream_it_->header); |
| 1566 | } |
| 1567 | |
| 1568 | private: |
| 1569 | const std::vector<LoggedRtpPacket>& packet_stream_; |
| 1570 | std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_; |
| 1571 | std::vector<uint64_t>::const_iterator output_events_us_it_; |
| 1572 | const std::vector<uint64_t>::const_iterator output_events_us_end_; |
| 1573 | const rtc::Optional<uint64_t> end_time_us_; |
| 1574 | }; |
| 1575 | |
| 1576 | namespace { |
| 1577 | // Creates a NetEq test object and all necessary input and output helpers. Runs |
| 1578 | // the test and returns the NetEqDelayAnalyzer object that was used to |
| 1579 | // instrument the test. |
| 1580 | std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun( |
| 1581 | const std::vector<LoggedRtpPacket>* packet_stream, |
| 1582 | const std::vector<uint64_t>* output_events_us, |
| 1583 | rtc::Optional<uint64_t> end_time_us, |
| 1584 | const std::string& replacement_file_name, |
| 1585 | int file_sample_rate_hz) { |
| 1586 | std::unique_ptr<test::NetEqInput> input( |
| 1587 | new NetEqStreamInput(packet_stream, output_events_us, end_time_us)); |
| 1588 | |
| 1589 | constexpr int kReplacementPt = 127; |
| 1590 | std::set<uint8_t> cn_types; |
| 1591 | std::set<uint8_t> forbidden_types; |
| 1592 | input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt, |
| 1593 | cn_types, forbidden_types)); |
| 1594 | |
| 1595 | NetEq::Config config; |
| 1596 | config.max_packets_in_buffer = 200; |
| 1597 | config.enable_fast_accelerate = true; |
| 1598 | |
| 1599 | std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink()); |
| 1600 | |
| 1601 | test::NetEqTest::DecoderMap codecs; |
| 1602 | |
| 1603 | // Create a "replacement decoder" that produces the decoded audio by reading |
| 1604 | // from a file rather than from the encoded payloads. |
| 1605 | std::unique_ptr<test::ResampleInputAudioFile> replacement_file( |
| 1606 | new test::ResampleInputAudioFile(replacement_file_name, |
| 1607 | file_sample_rate_hz)); |
| 1608 | replacement_file->set_output_rate_hz(48000); |
| 1609 | std::unique_ptr<AudioDecoder> replacement_decoder( |
| 1610 | new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false)); |
| 1611 | test::NetEqTest::ExtDecoderMap ext_codecs; |
| 1612 | ext_codecs[kReplacementPt] = {replacement_decoder.get(), |
| 1613 | NetEqDecoder::kDecoderArbitrary, |
| 1614 | "replacement codec"}; |
| 1615 | |
| 1616 | std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb( |
| 1617 | new test::NetEqDelayAnalyzer); |
| 1618 | test::DefaultNetEqTestErrorCallback error_cb; |
| 1619 | test::NetEqTest::Callbacks callbacks; |
| 1620 | callbacks.error_callback = &error_cb; |
| 1621 | callbacks.post_insert_packet = delay_cb.get(); |
| 1622 | callbacks.get_audio_callback = delay_cb.get(); |
| 1623 | |
| 1624 | test::NetEqTest test(config, codecs, ext_codecs, std::move(input), |
| 1625 | std::move(output), callbacks); |
| 1626 | test.Run(); |
| 1627 | return delay_cb; |
| 1628 | } |
| 1629 | } // namespace |
| 1630 | |
| 1631 | // Plots the jitter buffer delay profile. This will plot only for the first |
| 1632 | // incoming audio SSRC. If the stream contains more than one incoming audio |
| 1633 | // SSRC, all but the first will be ignored. |
| 1634 | void EventLogAnalyzer::CreateAudioJitterBufferGraph( |
| 1635 | const std::string& replacement_file_name, |
| 1636 | int file_sample_rate_hz, |
| 1637 | Plot* plot) { |
| 1638 | const auto& incoming_audio_kv = std::find_if( |
| 1639 | rtp_packets_.begin(), rtp_packets_.end(), |
| 1640 | [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) { |
| 1641 | return kv.first.GetDirection() == kIncomingPacket && |
| 1642 | this->IsAudioSsrc(kv.first); |
| 1643 | }); |
| 1644 | if (incoming_audio_kv == rtp_packets_.end()) { |
| 1645 | // No incoming audio stream found. |
| 1646 | return; |
| 1647 | } |
| 1648 | |
| 1649 | const uint32_t ssrc = incoming_audio_kv->first.GetSsrc(); |
| 1650 | |
| 1651 | std::map<uint32_t, std::vector<uint64_t>>::const_iterator output_events_it = |
| 1652 | audio_playout_events_.find(ssrc); |
| 1653 | if (output_events_it == audio_playout_events_.end()) { |
| 1654 | // Could not find output events with SSRC matching the input audio stream. |
| 1655 | // Using the first available stream of output events. |
| 1656 | output_events_it = audio_playout_events_.cbegin(); |
| 1657 | } |
| 1658 | |
| 1659 | rtc::Optional<uint64_t> end_time_us = |
| 1660 | log_segments_.empty() |
| 1661 | ? rtc::Optional<uint64_t>() |
| 1662 | : rtc::Optional<uint64_t>(log_segments_.front().second); |
| 1663 | |
| 1664 | auto delay_cb = CreateNetEqTestAndRun( |
| 1665 | &incoming_audio_kv->second, &output_events_it->second, end_time_us, |
| 1666 | replacement_file_name, file_sample_rate_hz); |
| 1667 | |
| 1668 | std::vector<float> send_times_s; |
| 1669 | std::vector<float> arrival_delay_ms; |
| 1670 | std::vector<float> corrected_arrival_delay_ms; |
| 1671 | std::vector<rtc::Optional<float>> playout_delay_ms; |
| 1672 | std::vector<rtc::Optional<float>> target_delay_ms; |
| 1673 | delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms, |
| 1674 | &corrected_arrival_delay_ms, &playout_delay_ms, |
| 1675 | &target_delay_ms); |
| 1676 | RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size()); |
| 1677 | RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size()); |
| 1678 | RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size()); |
| 1679 | RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size()); |
| 1680 | |
| 1681 | std::map<StreamId, TimeSeries> time_series_packet_arrival; |
| 1682 | std::map<StreamId, TimeSeries> time_series_relative_packet_arrival; |
| 1683 | std::map<StreamId, TimeSeries> time_series_play_time; |
| 1684 | std::map<StreamId, TimeSeries> time_series_target_time; |
| 1685 | float min_y_axis = 0.f; |
| 1686 | float max_y_axis = 0.f; |
| 1687 | const StreamId stream_id = incoming_audio_kv->first; |
| 1688 | for (size_t i = 0; i < send_times_s.size(); ++i) { |
| 1689 | time_series_packet_arrival[stream_id].points.emplace_back( |
| 1690 | TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i])); |
| 1691 | time_series_relative_packet_arrival[stream_id].points.emplace_back( |
| 1692 | TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i])); |
| 1693 | min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]); |
| 1694 | max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]); |
| 1695 | if (playout_delay_ms[i]) { |
| 1696 | time_series_play_time[stream_id].points.emplace_back( |
| 1697 | TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i])); |
| 1698 | min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]); |
| 1699 | max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]); |
| 1700 | } |
| 1701 | if (target_delay_ms[i]) { |
| 1702 | time_series_target_time[stream_id].points.emplace_back( |
| 1703 | TimeSeriesPoint(send_times_s[i], *target_delay_ms[i])); |
| 1704 | min_y_axis = std::min(min_y_axis, *target_delay_ms[i]); |
| 1705 | max_y_axis = std::max(max_y_axis, *target_delay_ms[i]); |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | // This code is adapted for a single stream. The creation of the streams above |
| 1710 | // guarantee that no more than one steam is included. If multiple streams are |
| 1711 | // to be plotted, they should likely be given distinct labels below. |
| 1712 | RTC_DCHECK_EQ(time_series_relative_packet_arrival.size(), 1); |
| 1713 | for (auto& series : time_series_relative_packet_arrival) { |
| 1714 | series.second.label = "Relative packet arrival delay"; |
| 1715 | series.second.style = LINE_GRAPH; |
| 1716 | plot->AppendTimeSeries(std::move(series.second)); |
| 1717 | } |
| 1718 | RTC_DCHECK_EQ(time_series_play_time.size(), 1); |
| 1719 | for (auto& series : time_series_play_time) { |
| 1720 | series.second.label = "Playout delay"; |
| 1721 | series.second.style = LINE_GRAPH; |
| 1722 | plot->AppendTimeSeries(std::move(series.second)); |
| 1723 | } |
| 1724 | RTC_DCHECK_EQ(time_series_target_time.size(), 1); |
| 1725 | for (auto& series : time_series_target_time) { |
| 1726 | series.second.label = "Target delay"; |
| 1727 | series.second.style = LINE_DOT_GRAPH; |
| 1728 | plot->AppendTimeSeries(std::move(series.second)); |
| 1729 | } |
| 1730 | |
| 1731 | plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
| 1732 | plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin, |
| 1733 | kTopMargin); |
| 1734 | plot->SetTitle("NetEq timing"); |
| 1735 | } |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1736 | } // namespace plotting |
| 1737 | } // namespace webrtc |