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