blob: 4c82a216a4b69f74e477cdf3946c2ec4068025e0 [file] [log] [blame]
terelius54ce6802016-07-13 06:44:41 -07001/*
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 Bonadei575998c2019-07-25 13:57:41 +020011#include "rtc_tools/rtc_event_log_visualizer/analyzer.h"
terelius54ce6802016-07-13 06:44:41 -070012
13#include <algorithm>
Oleh Prypin6581f212017-11-16 00:17:05 +010014#include <cmath>
terelius54ce6802016-07-13 06:44:41 -070015#include <limits>
16#include <map>
terelius54ce6802016-07-13 06:44:41 -070017#include <string>
18#include <utility>
19
Karl Wiberg918f50c2018-07-05 11:40:33 +020020#include "absl/memory/memory.h"
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +010021#include "absl/strings/string_view.h"
Artem Titov741daaf2019-03-21 14:37:36 +010022#include "api/function_view.h"
Sebastian Jansson95edb032019-01-17 16:24:12 +010023#include "api/transport/field_trial_based_config.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020024#include "api/transport/goog_cc_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "call/audio_receive_stream.h"
26#include "call/audio_send_stream.h"
27#include "call/call.h"
28#include "call/video_receive_stream.h"
29#include "call/video_send_stream.h"
Elad Alon99a81b62017-09-21 10:25:29 +020030#include "logging/rtc_event_log/rtc_stream_config.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020031#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "modules/audio_coding/neteq/tools/audio_sink.h"
33#include "modules/audio_coding/neteq/tools/fake_decode_from_file.h"
34#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
35#include "modules/audio_coding/neteq/tools/neteq_replacement_input.h"
36#include "modules/audio_coding/neteq/tools/neteq_test.h"
37#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
Sebastian Jansson172fd852018-05-24 14:17:06 +020038#include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h"
39#include "modules/congestion_controller/goog_cc/bitrate_estimator.h"
Sebastian Jansson04b18cb2018-07-02 09:25:25 +020040#include "modules/congestion_controller/goog_cc/delay_based_bwe.h"
Bjorn Terelius28db2662017-10-04 14:22:43 +020041#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020042#include "modules/congestion_controller/rtp/transport_feedback_adapter.h"
Erik Språnge7942432019-06-12 13:30:02 +020043#include "modules/pacing/paced_sender.h"
Niels Möllerfd6c0912017-10-31 10:19:10 +010044#include "modules/pacing/packet_router.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020045#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "modules/rtp_rtcp/include/rtp_rtcp.h"
47#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020048#include "modules/rtp_rtcp/source/rtcp_packet.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020049#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
50#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
51#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
52#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
53#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
54#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
55#include "modules/rtp_rtcp/source/rtp_utility.h"
56#include "rtc_base/checks.h"
57#include "rtc_base/format_macros.h"
58#include "rtc_base/logging.h"
Bjorn Terelius0295a962017-10-25 17:42:41 +020059#include "rtc_base/numerics/sequence_number_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020060#include "rtc_base/rate_statistics.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020061#include "rtc_base/strings/string_builder.h"
Mirko Bonadei575998c2019-07-25 13:57:41 +020062#include "rtc_tools/rtc_event_log_visualizer/log_simulation.h"
terelius54ce6802016-07-13 06:44:41 -070063
Bjorn Terelius6984ad22017-10-24 12:19:45 +020064#ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
65#define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0
66#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
67
tereliusdc35dcd2016-08-01 12:03:27 -070068namespace webrtc {
tereliusdc35dcd2016-08-01 12:03:27 -070069
terelius54ce6802016-07-13 06:44:41 -070070namespace {
71
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080072const int kNumMicrosecsPerSec = 1000000;
73
terelius54ce6802016-07-13 06:44:41 -070074std::string SsrcToString(uint32_t ssrc) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020075 rtc::StringBuilder ss;
terelius54ce6802016-07-13 06:44:41 -070076 ss << "SSRC " << ssrc;
Jonas Olsson84df1c72018-09-14 16:59:32 +020077 return ss.Release();
terelius54ce6802016-07-13 06:44:41 -070078}
79
80// Checks whether an SSRC is contained in the list of desired SSRCs.
81// Note that an empty SSRC list matches every SSRC.
82bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
83 if (desired_ssrc.size() == 0)
84 return true;
85 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
86 desired_ssrc.end();
87}
88
89double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
90 // The timestamp is a fixed point representation with 6 bits for seconds
91 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080092 // time in seconds and then multiply by kNumMicrosecsPerSec to convert to
93 // microseconds.
terelius54ce6802016-07-13 06:44:41 -070094 static constexpr double kTimestampToMicroSec =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080095 static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070096 return abs_send_time * kTimestampToMicroSec;
97}
98
99// Computes the difference |later| - |earlier| where |later| and |earlier|
100// are counters that wrap at |modulus|. The difference is chosen to have the
101// least absolute value. For example if |modulus| is 8, then the difference will
102// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
103// be in [-4, 4].
104int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
105 RTC_DCHECK_LE(1, modulus);
106 RTC_DCHECK_LT(later, modulus);
107 RTC_DCHECK_LT(earlier, modulus);
108 int64_t difference =
109 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
110 int64_t max_difference = modulus / 2;
111 int64_t min_difference = max_difference - modulus + 1;
112 if (difference > max_difference) {
113 difference -= modulus;
114 }
115 if (difference < min_difference) {
116 difference += modulus;
117 }
terelius6addf492016-08-23 17:34:07 -0700118 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100119 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
120 << " expected to be in the range ("
121 << min_difference / 2 << "," << max_difference / 2
122 << ") but is " << difference
123 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700124 }
terelius54ce6802016-07-13 06:44:41 -0700125 return difference;
126}
127
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200128// This is much more reliable for outgoing streams than for incoming streams.
129template <typename RtpPacketContainer>
Danil Chapovalov431abd92018-06-18 12:54:17 +0200130absl::optional<uint32_t> EstimateRtpClockFrequency(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200131 const RtpPacketContainer& packets,
132 int64_t end_time_us) {
133 RTC_CHECK(packets.size() >= 2);
134 SeqNumUnwrapper<uint32_t> unwrapper;
Philip Eliasson1f850a62019-03-19 12:15:00 +0000135 int64_t first_rtp_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200136 unwrapper.Unwrap(packets[0].rtp.header.timestamp);
137 int64_t first_log_timestamp = packets[0].log_time_us();
Philip Eliasson1f850a62019-03-19 12:15:00 +0000138 int64_t last_rtp_timestamp = first_rtp_timestamp;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200139 int64_t last_log_timestamp = first_log_timestamp;
140 for (size_t i = 1; i < packets.size(); i++) {
141 if (packets[i].log_time_us() > end_time_us)
142 break;
143 last_rtp_timestamp = unwrapper.Unwrap(packets[i].rtp.header.timestamp);
144 last_log_timestamp = packets[i].log_time_us();
145 }
146 if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) {
147 RTC_LOG(LS_WARNING)
148 << "Failed to estimate RTP clock frequency: Stream too short. ("
149 << packets.size() << " packets, "
150 << last_log_timestamp - first_log_timestamp << " us)";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200151 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200152 }
153 double duration =
154 static_cast<double>(last_log_timestamp - first_log_timestamp) /
155 kNumMicrosecsPerSec;
156 double estimated_frequency =
157 (last_rtp_timestamp - first_rtp_timestamp) / duration;
158 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
159 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
160 return f;
161 }
162 }
163 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
164 << estimated_frequency
165 << "not close to any stardard RTP frequency.";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200166 return absl::nullopt;
ivocaac9d6f2016-09-22 07:01:47 -0700167}
168
tereliusdc35dcd2016-08-01 12:03:27 -0700169constexpr float kLeftMargin = 0.01f;
170constexpr float kRightMargin = 0.02f;
171constexpr float kBottomMargin = 0.02f;
172constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700173
Danil Chapovalov431abd92018-06-18 12:54:17 +0200174absl::optional<double> NetworkDelayDiff_AbsSendTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100175 const LoggedRtpPacketIncoming& old_packet,
176 const LoggedRtpPacketIncoming& new_packet) {
177 if (old_packet.rtp.header.extension.hasAbsoluteSendTime &&
178 new_packet.rtp.header.extension.hasAbsoluteSendTime) {
terelius53dc23c2017-03-13 05:24:05 -0700179 int64_t send_time_diff = WrappingDifference(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100180 new_packet.rtp.header.extension.absoluteSendTime,
181 old_packet.rtp.header.extension.absoluteSendTime, 1ul << 24);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200182 int64_t recv_time_diff =
183 new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700184 double delay_change_us =
185 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100186 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700187 } else {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200188 return absl::nullopt;
terelius6addf492016-08-23 17:34:07 -0700189 }
190}
191
Danil Chapovalov431abd92018-06-18 12:54:17 +0200192absl::optional<double> NetworkDelayDiff_CaptureTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100193 const LoggedRtpPacketIncoming& old_packet,
194 const LoggedRtpPacketIncoming& new_packet,
195 const double sample_rate) {
196 int64_t send_time_diff =
197 WrappingDifference(new_packet.rtp.header.timestamp,
198 old_packet.rtp.header.timestamp, 1ull << 32);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200199 int64_t recv_time_diff = new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700200
terelius53dc23c2017-03-13 05:24:05 -0700201 double delay_change =
202 static_cast<double>(recv_time_diff) / 1000 -
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100203 static_cast<double>(send_time_diff) / sample_rate * 1000;
terelius53dc23c2017-03-13 05:24:05 -0700204 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100205 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100206 RTC_LOG(LS_WARNING) << "Old capture time "
207 << old_packet.rtp.header.timestamp << ", received time "
208 << old_packet.log_time_us();
209 RTC_LOG(LS_WARNING) << "New capture time "
210 << new_packet.rtp.header.timestamp << ", received time "
211 << new_packet.log_time_us();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100212 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800213 << static_cast<double>(recv_time_diff) /
214 kNumMicrosecsPerSec
215 << "s";
Mirko Bonadei675513b2017-11-09 11:09:25 +0100216 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100217 << static_cast<double>(send_time_diff) / sample_rate
Mirko Bonadei675513b2017-11-09 11:09:25 +0100218 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700219 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100220 return delay_change;
terelius53dc23c2017-03-13 05:24:05 -0700221}
222
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200223// For each element in data_view, use |f()| to extract a y-coordinate and
terelius53dc23c2017-03-13 05:24:05 -0700224// store the result in a TimeSeries.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200225template <typename DataType, typename IterableType>
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200226void ProcessPoints(rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200227 rtc::FunctionView<absl::optional<float>(const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200228 const IterableType& data_view,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200229 TimeSeries* result) {
230 for (size_t i = 0; i < data_view.size(); i++) {
231 const DataType& elem = data_view[i];
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200232 float x = fx(elem);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200233 absl::optional<float> y = fy(elem);
terelius53dc23c2017-03-13 05:24:05 -0700234 if (y)
235 result->points.emplace_back(x, *y);
236 }
237}
238
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200239// For each pair of adjacent elements in |data|, use |f()| to extract a
terelius6addf492016-08-23 17:34:07 -0700240// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
241// will be the time of the second element in the pair.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200242template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700243void ProcessPairs(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200244 rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200245 rtc::FunctionView<absl::optional<ResultType>(const DataType&,
246 const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200247 const IterableType& data,
terelius53dc23c2017-03-13 05:24:05 -0700248 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700249 for (size_t i = 1; i < data.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200250 float x = fx(data[i]);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200251 absl::optional<ResultType> y = fy(data[i - 1], data[i]);
terelius53dc23c2017-03-13 05:24:05 -0700252 if (y)
253 result->points.emplace_back(x, static_cast<float>(*y));
254 }
255}
256
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200257// For each pair of adjacent elements in |data|, use |f()| to extract a
terelius53dc23c2017-03-13 05:24:05 -0700258// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
259// will be the time of the second element in the pair.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200260template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700261void AccumulatePairs(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200262 rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200263 rtc::FunctionView<absl::optional<ResultType>(const DataType&,
264 const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200265 const IterableType& data,
terelius53dc23c2017-03-13 05:24:05 -0700266 TimeSeries* result) {
267 ResultType sum = 0;
268 for (size_t i = 1; i < data.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200269 float x = fx(data[i]);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200270 absl::optional<ResultType> y = fy(data[i - 1], data[i]);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100271 if (y) {
terelius53dc23c2017-03-13 05:24:05 -0700272 sum += *y;
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100273 result->points.emplace_back(x, static_cast<float>(sum));
274 }
tereliusccbbf8d2016-08-10 07:34:28 -0700275 }
276}
277
terelius6addf492016-08-23 17:34:07 -0700278// Calculates a moving average of |data| and stores the result in a TimeSeries.
279// A data point is generated every |step| microseconds from |begin_time|
280// to |end_time|. The value of each data point is the average of the data
Mirko Bonadei604e75c2019-07-25 11:55:47 +0200281// during the preceding |window_duration_us| microseconds.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200282template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700283void MovingAverage(
Danil Chapovalov431abd92018-06-18 12:54:17 +0200284 rtc::FunctionView<absl::optional<ResultType>(const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200285 const IterableType& data_view,
Bjorn Terelius068fc352019-02-13 22:38:25 +0100286 AnalyzerConfig config,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200287 TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700288 size_t window_index_begin = 0;
289 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700290 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700291
Bjorn Terelius068fc352019-02-13 22:38:25 +0100292 for (int64_t t = config.begin_time_; t < config.end_time_ + config.step_;
293 t += config.step_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200294 while (window_index_end < data_view.size() &&
295 data_view[window_index_end].log_time_us() < t) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200296 absl::optional<ResultType> value = fy(data_view[window_index_end]);
terelius53dc23c2017-03-13 05:24:05 -0700297 if (value)
298 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700299 ++window_index_end;
300 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200301 while (window_index_begin < data_view.size() &&
302 data_view[window_index_begin].log_time_us() <
Bjorn Terelius068fc352019-02-13 22:38:25 +0100303 t - config.window_duration_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200304 absl::optional<ResultType> value = fy(data_view[window_index_begin]);
terelius53dc23c2017-03-13 05:24:05 -0700305 if (value)
306 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700307 ++window_index_begin;
308 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800309 float window_duration_s =
Bjorn Terelius068fc352019-02-13 22:38:25 +0100310 static_cast<float>(config.window_duration_) / kNumMicrosecsPerSec;
311 float x = config.GetCallTimeSec(t);
terelius53dc23c2017-03-13 05:24:05 -0700312 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700313 result->points.emplace_back(x, y);
314 }
315}
316
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100317template <typename T>
318TimeSeries CreateRtcpTypeTimeSeries(const std::vector<T>& rtcp_list,
319 AnalyzerConfig config,
320 std::string rtcp_name,
321 int category_id) {
322 TimeSeries time_series(rtcp_name, LineStyle::kNone, PointStyle::kHighlight);
323 for (const auto& rtcp : rtcp_list) {
324 float x = config.GetCallTimeSec(rtcp.log_time_us());
325 float y = category_id;
326 time_series.points.emplace_back(x, y);
327 }
328 return time_series;
329}
330
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800331const char kUnknownEnumValue[] = "unknown";
332
333const char kIceCandidateTypeLocal[] = "local";
334const char kIceCandidateTypeStun[] = "stun";
335const char kIceCandidateTypePrflx[] = "prflx";
336const char kIceCandidateTypeRelay[] = "relay";
337
338const char kProtocolUdp[] = "udp";
339const char kProtocolTcp[] = "tcp";
340const char kProtocolSsltcp[] = "ssltcp";
341const char kProtocolTls[] = "tls";
342
343const char kAddressFamilyIpv4[] = "ipv4";
344const char kAddressFamilyIpv6[] = "ipv6";
345
346const char kNetworkTypeEthernet[] = "ethernet";
347const char kNetworkTypeLoopback[] = "loopback";
348const char kNetworkTypeWifi[] = "wifi";
349const char kNetworkTypeVpn[] = "vpn";
350const char kNetworkTypeCellular[] = "cellular";
351
352std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) {
353 switch (type) {
354 case webrtc::IceCandidateType::kLocal:
355 return kIceCandidateTypeLocal;
356 case webrtc::IceCandidateType::kStun:
357 return kIceCandidateTypeStun;
358 case webrtc::IceCandidateType::kPrflx:
359 return kIceCandidateTypePrflx;
360 case webrtc::IceCandidateType::kRelay:
361 return kIceCandidateTypeRelay;
362 default:
363 return kUnknownEnumValue;
364 }
365}
366
367std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) {
368 switch (protocol) {
369 case webrtc::IceCandidatePairProtocol::kUdp:
370 return kProtocolUdp;
371 case webrtc::IceCandidatePairProtocol::kTcp:
372 return kProtocolTcp;
373 case webrtc::IceCandidatePairProtocol::kSsltcp:
374 return kProtocolSsltcp;
375 case webrtc::IceCandidatePairProtocol::kTls:
376 return kProtocolTls;
377 default:
378 return kUnknownEnumValue;
379 }
380}
381
382std::string GetAddressFamilyAsString(
383 webrtc::IceCandidatePairAddressFamily family) {
384 switch (family) {
385 case webrtc::IceCandidatePairAddressFamily::kIpv4:
386 return kAddressFamilyIpv4;
387 case webrtc::IceCandidatePairAddressFamily::kIpv6:
388 return kAddressFamilyIpv6;
389 default:
390 return kUnknownEnumValue;
391 }
392}
393
394std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) {
395 switch (type) {
396 case webrtc::IceCandidateNetworkType::kEthernet:
397 return kNetworkTypeEthernet;
398 case webrtc::IceCandidateNetworkType::kLoopback:
399 return kNetworkTypeLoopback;
400 case webrtc::IceCandidateNetworkType::kWifi:
401 return kNetworkTypeWifi;
402 case webrtc::IceCandidateNetworkType::kVpn:
403 return kNetworkTypeVpn;
404 case webrtc::IceCandidateNetworkType::kCellular:
405 return kNetworkTypeCellular;
406 default:
407 return kUnknownEnumValue;
408 }
409}
410
411std::string GetCandidatePairLogDescriptionAsString(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200412 const LoggedIceCandidatePairConfig& config) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800413 // Example: stun:wifi->relay(tcp):cellular@udp:ipv4
414 // represents a pair of a local server-reflexive candidate on a WiFi network
415 // and a remote relay candidate using TCP as the relay protocol on a cell
416 // network, when the candidate pair communicates over UDP using IPv4.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200417 rtc::StringBuilder ss;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800418 std::string local_candidate_type =
419 GetIceCandidateTypeAsString(config.local_candidate_type);
420 std::string remote_candidate_type =
421 GetIceCandidateTypeAsString(config.remote_candidate_type);
422 if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) {
423 local_candidate_type +=
424 "(" + GetProtocolAsString(config.local_relay_protocol) + ")";
425 }
426 ss << local_candidate_type << ":"
427 << GetNetworkTypeAsString(config.local_network_type) << ":"
428 << GetAddressFamilyAsString(config.local_address_family) << "->"
429 << remote_candidate_type << ":"
430 << GetAddressFamilyAsString(config.remote_address_family) << "@"
431 << GetProtocolAsString(config.candidate_pair_protocol);
Jonas Olsson84df1c72018-09-14 16:59:32 +0200432 return ss.Release();
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800433}
434
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200435std::string GetDirectionAsString(PacketDirection direction) {
436 if (direction == kIncomingPacket) {
437 return "Incoming";
438 } else {
439 return "Outgoing";
440 }
441}
442
443std::string GetDirectionAsShortString(PacketDirection direction) {
444 if (direction == kIncomingPacket) {
445 return "In";
446 } else {
447 return "Out";
448 }
449}
450
terelius54ce6802016-07-13 06:44:41 -0700451} // namespace
452
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100453EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200454 bool normalize_time)
Bjorn Terelius068fc352019-02-13 22:38:25 +0100455 : parsed_log_(log) {
456 config_.window_duration_ = 250000;
457 config_.step_ = 10000;
458 config_.normalize_time_ = normalize_time;
459 config_.begin_time_ = parsed_log_.first_timestamp();
460 config_.end_time_ = parsed_log_.last_timestamp();
461 if (config_.end_time_ < config_.begin_time_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200462 RTC_LOG(LS_WARNING) << "No useful events in the log.";
Bjorn Terelius068fc352019-02-13 22:38:25 +0100463 config_.begin_time_ = config_.end_time_ = 0;
Björn Tereliusff612732018-04-25 14:23:01 +0000464 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200465
466 const auto& log_start_events = parsed_log_.start_log_events();
467 const auto& log_end_events = parsed_log_.stop_log_events();
468 auto start_iter = log_start_events.begin();
469 auto end_iter = log_end_events.begin();
470 while (start_iter != log_start_events.end()) {
471 int64_t start = start_iter->log_time_us();
472 ++start_iter;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200473 absl::optional<int64_t> next_start;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200474 if (start_iter != log_start_events.end())
475 next_start.emplace(start_iter->log_time_us());
476 if (end_iter != log_end_events.end() &&
477 end_iter->log_time_us() <=
478 next_start.value_or(std::numeric_limits<int64_t>::max())) {
479 int64_t end = end_iter->log_time_us();
480 RTC_DCHECK_LE(start, end);
481 log_segments_.push_back(std::make_pair(start, end));
482 ++end_iter;
483 } else {
484 // we're missing an end event. Assume that it occurred just before the
485 // next start.
486 log_segments_.push_back(
Bjorn Terelius068fc352019-02-13 22:38:25 +0100487 std::make_pair(start, next_start.value_or(config_.end_time_)));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200488 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700489 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100490 RTC_LOG(LS_INFO) << "Found " << log_segments_.size()
Yves Gerey665174f2018-06-19 15:03:05 +0200491 << " (LOG_START, LOG_END) segments in log.";
terelius54ce6802016-07-13 06:44:41 -0700492}
493
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200494class BitrateObserver : public RemoteBitrateObserver {
Stefan Holmer13181032016-07-29 14:48:54 +0200495 public:
496 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
497
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200498 void Update(NetworkControlUpdate update) {
499 if (update.target_rate) {
500 last_bitrate_bps_ = update.target_rate->target_rate.bps();
501 bitrate_updated_ = true;
502 }
Stefan Holmer13181032016-07-29 14:48:54 +0200503 }
504
505 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
506 uint32_t bitrate) override {}
507
508 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
509 bool GetAndResetBitrateUpdated() {
510 bool bitrate_updated = bitrate_updated_;
511 bitrate_updated_ = false;
512 return bitrate_updated;
513 }
514
515 private:
516 uint32_t last_bitrate_bps_;
517 bool bitrate_updated_;
518};
519
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200520void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction,
terelius54ce6802016-07-13 06:44:41 -0700521 Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200522 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
523 // Filter on SSRC.
524 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700525 continue;
terelius54ce6802016-07-13 06:44:41 -0700526 }
terelius54ce6802016-07-13 06:44:41 -0700527
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200528 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
529 LineStyle::kBar);
530 auto GetPacketSize = [](const LoggedRtpPacket& packet) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200531 return absl::optional<float>(packet.total_length);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200532 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200533 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100534 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200535 };
536 ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize,
537 stream.packet_view, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700538 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700539 }
540
Bjorn Terelius068fc352019-02-13 22:38:25 +0100541 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
542 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700543 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
544 kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200545 plot->SetTitle(GetDirectionAsString(direction) + " RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700546}
547
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100548void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction,
549 Plot* plot) {
550 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
551 parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1));
552 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
553 parsed_log_.receiver_reports(direction), config_, "RR", 2));
554 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
555 parsed_log_.sender_reports(direction), config_, "SR", 3));
556 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
557 parsed_log_.extended_reports(direction), config_, "XR", 4));
558 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction),
559 config_, "NACK", 5));
560 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction),
561 config_, "REMB", 6));
562 plot->AppendTimeSeries(
563 CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7));
564 plot->AppendTimeSeries(
565 CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8));
566 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
567 "Time (s)", kLeftMargin, kRightMargin);
568 plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin);
569 plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets");
Bjorn Tereliusf640b872019-07-24 15:46:39 +0200570 plot->SetYAxisTickLabels({{1, "TWCC"},
571 {2, "RR"},
572 {3, "SR"},
573 {4, "XR"},
574 {5, "NACK"},
575 {6, "REMB"},
576 {7, "FIR"},
577 {8, "PLI"}});
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100578}
579
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200580template <typename IterableType>
philipelccd74892016-09-05 02:46:25 -0700581void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
philipelccd74892016-09-05 02:46:25 -0700582 Plot* plot,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200583 const IterableType& packets,
584 const std::string& label) {
585 TimeSeries time_series(label, LineStyle::kStep);
586 for (size_t i = 0; i < packets.size(); i++) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100587 float x = config_.GetCallTimeSec(packets[i].log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200588 time_series.points.emplace_back(x, i + 1);
philipelccd74892016-09-05 02:46:25 -0700589 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200590 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700591}
592
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200593void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction,
594 Plot* plot) {
595 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
596 if (!MatchingSsrc(stream.ssrc, desired_ssrc_))
597 continue;
598 std::string label =
599 std::string("RTP ") + GetStreamName(direction, stream.ssrc);
600 CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label);
601 }
602 std::string label =
603 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")";
604 if (direction == kIncomingPacket) {
605 CreateAccumulatedPacketsTimeSeries(
606 plot, parsed_log_.incoming_rtcp_packets(), label);
607 } else {
608 CreateAccumulatedPacketsTimeSeries(
609 plot, parsed_log_.outgoing_rtcp_packets(), label);
610 }
philipelccd74892016-09-05 02:46:25 -0700611
Bjorn Terelius068fc352019-02-13 22:38:25 +0100612 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
613 "Time (s)", kLeftMargin, kRightMargin);
philipelccd74892016-09-05 02:46:25 -0700614 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200615 plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) +
616 " RTP/RTCP packets");
philipelccd74892016-09-05 02:46:25 -0700617}
618
terelius54ce6802016-07-13 06:44:41 -0700619// For each SSRC, plot the time between the consecutive playouts.
620void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200621 for (const auto& playout_stream : parsed_log_.audio_playout_events()) {
622 uint32_t ssrc = playout_stream.first;
623 if (!MatchingSsrc(ssrc, desired_ssrc_))
624 continue;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200625 absl::optional<int64_t> last_playout_ms;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200626 TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar);
Minyue Li27e2b7d2018-05-07 15:20:24 +0200627 for (const auto& playout_event : playout_stream.second) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100628 float x = config_.GetCallTimeSec(playout_event.log_time_us());
Minyue Li27e2b7d2018-05-07 15:20:24 +0200629 int64_t playout_time_ms = playout_event.log_time_ms();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200630 // If there were no previous playouts, place the point on the x-axis.
Minyue Li27e2b7d2018-05-07 15:20:24 +0200631 float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200632 time_series.points.push_back(TimeSeriesPoint(x, y));
Minyue Li27e2b7d2018-05-07 15:20:24 +0200633 last_playout_ms.emplace(playout_time_ms);
terelius54ce6802016-07-13 06:44:41 -0700634 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200635 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700636 }
637
Bjorn Terelius068fc352019-02-13 22:38:25 +0100638 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
639 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700640 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
641 kTopMargin);
642 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700643}
644
ivocaac9d6f2016-09-22 07:01:47 -0700645// For audio SSRCs, plot the audio level.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200646void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction,
647 Plot* plot) {
648 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
649 if (!IsAudioSsrc(direction, stream.ssrc))
650 continue;
651 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
652 LineStyle::kLine);
653 for (auto& packet : stream.packet_view) {
ivocaac9d6f2016-09-22 07:01:47 -0700654 if (packet.header.extension.hasAudioLevel) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100655 float x = config_.GetCallTimeSec(packet.log_time_us());
ivocaac9d6f2016-09-22 07:01:47 -0700656 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
657 // Here we convert it to dBov.
658 float y = static_cast<float>(-packet.header.extension.audioLevel);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200659 time_series.points.emplace_back(TimeSeriesPoint(x, y));
ivocaac9d6f2016-09-22 07:01:47 -0700660 }
661 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200662 plot->AppendTimeSeries(std::move(time_series));
ivocaac9d6f2016-09-22 07:01:47 -0700663 }
664
Bjorn Terelius068fc352019-02-13 22:38:25 +0100665 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
666 "Time (s)", kLeftMargin, kRightMargin);
Yves Gerey665174f2018-06-19 15:03:05 +0200667 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200668 plot->SetTitle(GetDirectionAsString(direction) + " audio level");
ivocaac9d6f2016-09-22 07:01:47 -0700669}
670
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100671// For each SSRC, plot the sequence number difference between consecutive
672// incoming packets.
terelius54ce6802016-07-13 06:44:41 -0700673void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200674 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
675 // Filter on SSRC.
676 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700677 continue;
terelius54ce6802016-07-13 06:44:41 -0700678 }
terelius54ce6802016-07-13 06:44:41 -0700679
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200680 TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc),
681 LineStyle::kBar);
682 auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet,
683 const LoggedRtpPacketIncoming& new_packet) {
684 int64_t diff =
685 WrappingDifference(new_packet.rtp.header.sequenceNumber,
686 old_packet.rtp.header.sequenceNumber, 1ul << 16);
687 return diff;
688 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200689 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100690 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200691 };
692 ProcessPairs<LoggedRtpPacketIncoming, float>(
693 ToCallTime, GetSequenceNumberDiff, stream.incoming_packets,
694 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700695 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700696 }
697
Bjorn Terelius068fc352019-02-13 22:38:25 +0100698 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
699 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700700 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
701 kTopMargin);
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100702 plot->SetTitle("Incoming sequence number delta");
terelius54ce6802016-07-13 06:44:41 -0700703}
704
Stefan Holmer99f8e082016-09-09 13:37:50 +0200705void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200706 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
707 const std::vector<LoggedRtpPacketIncoming>& packets =
708 stream.incoming_packets;
709 // Filter on SSRC.
710 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200711 continue;
712 }
713
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200714 TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc),
715 LineStyle::kLine, PointStyle::kHighlight);
716 // TODO(terelius): Should the window and step size be read from the class
717 // instead?
718 const int64_t kWindowUs = 1000000;
719 const int64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100720 SeqNumUnwrapper<uint16_t> unwrapper_;
721 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800722 size_t window_index_begin = 0;
723 size_t window_index_end = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200724 uint64_t highest_seq_number =
725 unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
726 uint64_t highest_prior_seq_number =
727 prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
terelius4c9b4af2017-01-30 08:44:51 -0800728
Bjorn Terelius068fc352019-02-13 22:38:25 +0100729 for (int64_t t = config_.begin_time_; t < config_.end_time_ + kStep;
730 t += kStep) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200731 while (window_index_end < packets.size() &&
732 packets[window_index_end].rtp.log_time_us() < t) {
733 uint64_t sequence_number = unwrapper_.Unwrap(
734 packets[window_index_end].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800735 highest_seq_number = std::max(highest_seq_number, sequence_number);
736 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200737 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200738 while (window_index_begin < packets.size() &&
739 packets[window_index_begin].rtp.log_time_us() < t - kWindowUs) {
740 uint64_t sequence_number = prior_unwrapper_.Unwrap(
741 packets[window_index_begin].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800742 highest_prior_seq_number =
743 std::max(highest_prior_seq_number, sequence_number);
744 ++window_index_begin;
745 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100746 float x = config_.GetCallTimeSec(t);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200747 uint64_t expected_packets = highest_seq_number - highest_prior_seq_number;
terelius4c9b4af2017-01-30 08:44:51 -0800748 if (expected_packets > 0) {
749 int64_t received_packets = window_index_end - window_index_begin;
750 int64_t lost_packets = expected_packets - received_packets;
751 float y = static_cast<float>(lost_packets) / expected_packets * 100;
752 time_series.points.emplace_back(x, y);
753 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200754 }
philipel35ba9bd2017-04-19 05:58:51 -0700755 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200756 }
757
Bjorn Terelius068fc352019-02-13 22:38:25 +0100758 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
759 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100760 plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin);
761 plot->SetTitle("Incoming packet loss (derived from incoming packets)");
Stefan Holmer99f8e082016-09-09 13:37:50 +0200762}
763
terelius2ee076d2017-08-15 02:04:02 -0700764void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100765 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200766 // Filter on SSRC.
767 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200768 IsRtxSsrc(kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700769 continue;
770 }
terelius54ce6802016-07-13 06:44:41 -0700771
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100772 const std::vector<LoggedRtpPacketIncoming>& packets =
773 stream.incoming_packets;
774 if (packets.size() < 100) {
775 RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with "
776 << packets.size() << " packets in the stream.";
777 continue;
778 }
779 int64_t end_time_us = log_segments_.empty()
780 ? std::numeric_limits<int64_t>::max()
781 : log_segments_.front().second;
782 absl::optional<uint32_t> estimated_frequency =
783 EstimateRtpClockFrequency(packets, end_time_us);
784 if (!estimated_frequency)
785 continue;
786 const double frequency_hz = *estimated_frequency;
787 if (IsVideoSsrc(kIncomingPacket, stream.ssrc) && frequency_hz != 90000) {
788 RTC_LOG(LS_WARNING)
789 << "Video stream should use a 90 kHz clock but appears to use "
790 << frequency_hz / 1000 << ". Discarding.";
791 continue;
792 }
793
794 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100795 return this->config_.GetCallTimeSec(packet.log_time_us());
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100796 };
797 auto ToNetworkDelay = [frequency_hz](
798 const LoggedRtpPacketIncoming& old_packet,
799 const LoggedRtpPacketIncoming& new_packet) {
800 return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz);
801 };
802
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200803 TimeSeries capture_time_data(
804 GetStreamName(kIncomingPacket, stream.ssrc) + " capture-time",
805 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100806 AccumulatePairs<LoggedRtpPacketIncoming, double>(
807 ToCallTime, ToNetworkDelay, packets, &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700808 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700809
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200810 TimeSeries send_time_data(
811 GetStreamName(kIncomingPacket, stream.ssrc) + " abs-send-time",
812 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100813 AccumulatePairs<LoggedRtpPacketIncoming, double>(
814 ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data);
815 plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700816 }
817
Bjorn Terelius068fc352019-02-13 22:38:25 +0100818 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
819 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +0100820 plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin);
821 plot->SetTitle("Incoming network delay (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700822}
823
tereliusf736d232016-08-04 10:00:11 -0700824// Plot the fraction of packets lost (as perceived by the loss-based BWE).
825void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100826 TimeSeries time_series("Fraction lost", LineStyle::kLine,
827 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200828 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100829 float x = config_.GetCallTimeSec(bwe_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200830 float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700831 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700832 }
tereliusf736d232016-08-04 10:00:11 -0700833
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200834 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +0100835 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
836 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100837 plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin);
838 plot->SetTitle("Outgoing packet loss (as reported by BWE)");
tereliusf736d232016-08-04 10:00:11 -0700839}
840
terelius54ce6802016-07-13 06:44:41 -0700841// Plot the total bandwidth used by all RTP streams.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200842void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) {
843 // TODO(terelius): This could be provided by the parser.
844 std::multimap<int64_t, size_t> packets_in_order;
845 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
846 for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets)
847 packets_in_order.insert(
848 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
terelius54ce6802016-07-13 06:44:41 -0700849 }
850
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200851 auto window_begin = packets_in_order.begin();
852 auto window_end = packets_in_order.begin();
terelius54ce6802016-07-13 06:44:41 -0700853 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700854
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800855 if (!packets_in_order.empty()) {
856 // Calculate a moving average of the bitrate and store in a TimeSeries.
857 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
858 for (int64_t time = config_.begin_time_;
859 time < config_.end_time_ + config_.step_; time += config_.step_) {
860 while (window_end != packets_in_order.end() && window_end->first < time) {
861 bytes_in_window += window_end->second;
862 ++window_end;
863 }
864 while (window_begin != packets_in_order.end() &&
865 window_begin->first < time - config_.window_duration_) {
866 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
867 bytes_in_window -= window_begin->second;
868 ++window_begin;
869 }
870 float window_duration_in_seconds =
871 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
872 float x = config_.GetCallTimeSec(time);
873 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
874 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700875 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800876 plot->AppendTimeSeries(std::move(bitrate_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200877 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200878
879 // Overlay the outgoing REMB over incoming bitrate.
880 TimeSeries remb_series("Remb", LineStyle::kStep);
881 for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100882 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200883 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
884 remb_series.points.emplace_back(x, y);
885 }
886 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
887
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800888 if (!parsed_log_.generic_packets_received().empty()) {
889 TimeSeries time_series("Incoming generic bitrate", LineStyle::kLine);
890 auto GetPacketSizeKilobits = [](const LoggedGenericPacketReceived& packet) {
891 return packet.packet_length * 8.0 / 1000.0;
892 };
893 MovingAverage<LoggedGenericPacketReceived, double>(
894 GetPacketSizeKilobits, parsed_log_.generic_packets_received(), config_,
895 &time_series);
896 plot->AppendTimeSeries(std::move(time_series));
897 }
898
Bjorn Terelius068fc352019-02-13 22:38:25 +0100899 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
900 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200901 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
902 plot->SetTitle("Incoming RTP bitrate");
903}
904
905// Plot the total bandwidth used by all RTP streams.
906void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
907 bool show_detector_state,
908 bool show_alr_state) {
909 // TODO(terelius): This could be provided by the parser.
910 std::multimap<int64_t, size_t> packets_in_order;
911 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
912 for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets)
913 packets_in_order.insert(
914 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
915 }
916
917 auto window_begin = packets_in_order.begin();
918 auto window_end = packets_in_order.begin();
919 size_t bytes_in_window = 0;
920
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800921 if (!packets_in_order.empty()) {
922 // Calculate a moving average of the bitrate and store in a TimeSeries.
923 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
924 for (int64_t time = config_.begin_time_;
925 time < config_.end_time_ + config_.step_; time += config_.step_) {
926 while (window_end != packets_in_order.end() && window_end->first < time) {
927 bytes_in_window += window_end->second;
928 ++window_end;
929 }
930 while (window_begin != packets_in_order.end() &&
931 window_begin->first < time - config_.window_duration_) {
932 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
933 bytes_in_window -= window_begin->second;
934 ++window_begin;
935 }
936 float window_duration_in_seconds =
937 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
938 float x = config_.GetCallTimeSec(time);
939 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
940 bitrate_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200941 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800942 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700943 }
944
terelius8058e582016-07-25 01:32:41 -0700945 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200946 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
947 for (auto& loss_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100948 float x = config_.GetCallTimeSec(loss_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200949 float y = static_cast<float>(loss_update.bitrate_bps) / 1000;
950 loss_series.points.emplace_back(x, y);
951 }
philipel10fc0e62017-04-11 01:50:23 -0700952
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200953 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
954 IntervalSeries overusing_series("Overusing", "#ff8e82",
955 IntervalSeries::kHorizontal);
956 IntervalSeries underusing_series("Underusing", "#5092fc",
957 IntervalSeries::kHorizontal);
958 IntervalSeries normal_series("Normal", "#c4ffc4",
959 IntervalSeries::kHorizontal);
960 IntervalSeries* last_series = &normal_series;
961 double last_detector_switch = 0.0;
philipel23c7f252017-07-14 06:30:03 -0700962
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200963 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
philipel23c7f252017-07-14 06:30:03 -0700964
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200965 for (auto& delay_update : parsed_log_.bwe_delay_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100966 float x = config_.GetCallTimeSec(delay_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200967 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -0700968
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200969 if (last_detector_state != delay_update.detector_state) {
970 last_series->intervals.emplace_back(last_detector_switch, x);
971 last_detector_state = delay_update.detector_state;
972 last_detector_switch = x;
philipel23c7f252017-07-14 06:30:03 -0700973
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200974 switch (delay_update.detector_state) {
975 case BandwidthUsage::kBwNormal:
976 last_series = &normal_series;
977 break;
978 case BandwidthUsage::kBwUnderusing:
979 last_series = &underusing_series;
980 break;
981 case BandwidthUsage::kBwOverusing:
982 last_series = &overusing_series;
983 break;
984 case BandwidthUsage::kLast:
985 RTC_NOTREACHED();
philipele127e7a2017-03-29 16:28:53 +0200986 }
987 }
philipel23c7f252017-07-14 06:30:03 -0700988
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200989 delay_series.points.emplace_back(x, y);
990 }
Bjorn Terelius9e336ec2018-04-24 16:28:35 +0200991
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200992 RTC_CHECK(last_series);
Bjorn Terelius068fc352019-02-13 22:38:25 +0100993 last_series->intervals.emplace_back(last_detector_switch, config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200994
995 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
996 PointStyle::kHighlight);
997 for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100998 float x = config_.GetCallTimeSec(cluster.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200999 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
1000 created_series.points.emplace_back(x, y);
1001 }
1002
1003 TimeSeries result_series("Probing results.", LineStyle::kNone,
1004 PointStyle::kHighlight);
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001005 for (auto& result : parsed_log_.bwe_probe_success_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001006 float x = config_.GetCallTimeSec(result.log_time_us());
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001007 float y = static_cast<float>(result.bitrate_bps) / 1000;
1008 result_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001009 }
1010
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001011 TimeSeries probe_failures_series("Probe failed", LineStyle::kNone,
1012 PointStyle::kHighlight);
1013 for (auto& failure : parsed_log_.bwe_probe_failure_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001014 float x = config_.GetCallTimeSec(failure.log_time_us());
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001015 probe_failures_series.points.emplace_back(x, 0);
1016 }
1017
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001018 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
1019 bool previously_in_alr = false;
1020 int64_t alr_start = 0;
1021 for (auto& alr : parsed_log_.alr_state_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001022 float y = config_.GetCallTimeSec(alr.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001023 if (!previously_in_alr && alr.in_alr) {
1024 alr_start = alr.log_time_us();
1025 previously_in_alr = true;
1026 } else if (previously_in_alr && !alr.in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001027 float x = config_.GetCallTimeSec(alr_start);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001028 alr_state.intervals.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001029 previously_in_alr = false;
Björn Tereliusff612732018-04-25 14:23:01 +00001030 }
Björn Tereliusff612732018-04-25 14:23:01 +00001031 }
1032
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001033 if (previously_in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001034 float x = config_.GetCallTimeSec(alr_start);
1035 float y = config_.GetCallTimeSec(config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001036 alr_state.intervals.emplace_back(x, y);
1037 }
1038
1039 if (show_detector_state) {
1040 plot->AppendIntervalSeries(std::move(overusing_series));
1041 plot->AppendIntervalSeries(std::move(underusing_series));
1042 plot->AppendIntervalSeries(std::move(normal_series));
1043 }
1044
1045 if (show_alr_state) {
1046 plot->AppendIntervalSeries(std::move(alr_state));
1047 }
1048 plot->AppendTimeSeries(std::move(loss_series));
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001049 plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001050 plot->AppendTimeSeries(std::move(delay_series));
1051 plot->AppendTimeSeries(std::move(created_series));
1052 plot->AppendTimeSeries(std::move(result_series));
1053
1054 // Overlay the incoming REMB over the outgoing bitrate.
Björn Tereliusff612732018-04-25 14:23:01 +00001055 TimeSeries remb_series("Remb", LineStyle::kStep);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001056 for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001057 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001058 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
terelius2c8e8a32017-06-02 01:29:48 -07001059 remb_series.points.emplace_back(x, y);
1060 }
1061 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1062
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001063 if (!parsed_log_.generic_packets_sent().empty()) {
1064 {
1065 TimeSeries time_series("Outgoing generic total bitrate",
1066 LineStyle::kLine);
1067 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1068 return packet.packet_length() * 8.0 / 1000.0;
1069 };
1070 MovingAverage<LoggedGenericPacketSent, double>(
1071 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1072 &time_series);
1073 plot->AppendTimeSeries(std::move(time_series));
1074 }
1075
1076 {
1077 TimeSeries time_series("Outgoing generic payload bitrate",
1078 LineStyle::kLine);
1079 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1080 return packet.payload_length * 8.0 / 1000.0;
1081 };
1082 MovingAverage<LoggedGenericPacketSent, double>(
1083 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1084 &time_series);
1085 plot->AppendTimeSeries(std::move(time_series));
1086 }
1087 }
1088
Bjorn Terelius068fc352019-02-13 22:38:25 +01001089 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1090 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001091 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001092 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001093}
1094
1095// For each SSRC, plot the bandwidth used by that stream.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001096void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction,
1097 Plot* plot) {
1098 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1099 // Filter on SSRC.
1100 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -07001101 continue;
terelius54ce6802016-07-13 06:44:41 -07001102 }
1103
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001104 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
1105 LineStyle::kLine);
1106 auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) {
1107 return packet.total_length * 8.0 / 1000.0;
1108 };
terelius53dc23c2017-03-13 05:24:05 -07001109 MovingAverage<LoggedRtpPacket, double>(
Bjorn Terelius068fc352019-02-13 22:38:25 +01001110 GetPacketSizeKilobits, stream.packet_view, config_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001111 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001112 }
1113
Bjorn Terelius068fc352019-02-13 22:38:25 +01001114 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1115 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001116 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001117 plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001118}
1119
Bjorn Terelius9775a582019-02-15 17:29:58 +01001120// Plot the bitrate allocation for each temporal and spatial layer.
1121// Computed from RTCP XR target bitrate block, so the graph is only populated if
1122// those are sent.
1123void EventLogAnalyzer::CreateBitrateAllocationGraph(PacketDirection direction,
1124 Plot* plot) {
1125 std::map<LayerDescription, TimeSeries> time_series;
1126 const auto& xr_list = parsed_log_.extended_reports(direction);
1127 for (const auto& rtcp : xr_list) {
1128 const absl::optional<rtcp::TargetBitrate>& target_bitrate =
1129 rtcp.xr.target_bitrate();
1130 if (!target_bitrate.has_value())
1131 continue;
1132 for (const auto& bitrate_item : target_bitrate->GetTargetBitrates()) {
1133 LayerDescription layer(rtcp.xr.sender_ssrc(), bitrate_item.spatial_layer,
1134 bitrate_item.temporal_layer);
1135 auto time_series_it = time_series.find(layer);
1136 if (time_series_it == time_series.end()) {
1137 std::string layer_name = GetLayerName(layer);
1138 bool inserted;
1139 std::tie(time_series_it, inserted) = time_series.insert(
1140 std::make_pair(layer, TimeSeries(layer_name, LineStyle::kStep)));
1141 RTC_DCHECK(inserted);
1142 }
1143 float x = config_.GetCallTimeSec(rtcp.log_time_us());
1144 float y = bitrate_item.target_bitrate_kbps;
1145 time_series_it->second.points.emplace_back(x, y);
1146 }
1147 }
1148 for (auto& layer : time_series) {
1149 plot->AppendTimeSeries(std::move(layer.second));
1150 }
1151 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1152 "Time (s)", kLeftMargin, kRightMargin);
1153 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1154 if (direction == kIncomingPacket)
1155 plot->SetTitle("Target bitrate per incoming layer");
1156 else
1157 plot->SetTitle("Target bitrate per outgoing layer");
1158}
1159
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001160void EventLogAnalyzer::CreateGoogCcSimulationGraph(Plot* plot) {
1161 TimeSeries target_rates("Simulated target rate", LineStyle::kStep,
1162 PointStyle::kHighlight);
1163 TimeSeries delay_based("Logged delay-based estimate", LineStyle::kStep,
1164 PointStyle::kHighlight);
1165 TimeSeries loss_based("Logged loss-based estimate", LineStyle::kStep,
1166 PointStyle::kHighlight);
1167 TimeSeries probe_results("Logged probe success", LineStyle::kNone,
1168 PointStyle::kHighlight);
1169
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001170 LogBasedNetworkControllerSimulation simulation(
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001171 absl::make_unique<GoogCcNetworkControllerFactory>(),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001172 [&](const NetworkControlUpdate& update, Timestamp at_time) {
1173 if (update.target_rate) {
1174 target_rates.points.emplace_back(
1175 config_.GetCallTimeSec(at_time.us()),
1176 update.target_rate->target_rate.kbps<float>());
1177 }
1178 });
1179
1180 simulation.ProcessEventsInLog(parsed_log_);
1181 for (const auto& logged : parsed_log_.bwe_delay_updates())
1182 delay_based.points.emplace_back(
1183 config_.GetCallTimeSec(logged.log_time_us()),
1184 logged.bitrate_bps / 1000);
1185 for (const auto& logged : parsed_log_.bwe_probe_success_events())
1186 probe_results.points.emplace_back(
1187 config_.GetCallTimeSec(logged.log_time_us()),
1188 logged.bitrate_bps / 1000);
1189 for (const auto& logged : parsed_log_.bwe_loss_updates())
1190 loss_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time_us()),
1191 logged.bitrate_bps / 1000);
1192
1193 plot->AppendTimeSeries(std::move(delay_based));
1194 plot->AppendTimeSeries(std::move(loss_based));
1195 plot->AppendTimeSeries(std::move(probe_results));
1196 plot->AppendTimeSeries(std::move(target_rates));
1197
1198 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1199 "Time (s)", kLeftMargin, kRightMargin);
1200 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1201 plot->SetTitle("Simulated BWE behavior");
1202}
1203
Bjorn Terelius28db2662017-10-04 14:22:43 +02001204void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001205 using RtpPacketType = LoggedRtpPacketOutgoing;
1206 using TransportFeedbackType = LoggedRtcpPacketTransportFeedback;
Stefan Holmer13181032016-07-29 14:48:54 +02001207
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001208 // TODO(terelius): This could be provided by the parser.
1209 std::multimap<int64_t, const RtpPacketType*> outgoing_rtp;
1210 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1211 for (const RtpPacketType& rtp_packet : stream.outgoing_packets)
1212 outgoing_rtp.insert(
1213 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Stefan Holmer13181032016-07-29 14:48:54 +02001214 }
1215
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001216 const std::vector<TransportFeedbackType>& incoming_rtcp =
1217 parsed_log_.transport_feedbacks(kIncomingPacket);
Stefan Holmer13181032016-07-29 14:48:54 +02001218
1219 SimulatedClock clock(0);
1220 BitrateObserver observer;
1221 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001222 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001223 PacedSender pacer(&clock, &packet_router, &null_event_log);
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001224 TransportFeedbackAdapter transport_feedback;
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001225 auto factory = GoogCcNetworkControllerFactory();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001226 TimeDelta process_interval = factory.GetProcessInterval();
Stefan Holmer13181032016-07-29 14:48:54 +02001227 // TODO(holmer): Log the call config and use that here instead.
1228 static const uint32_t kDefaultStartBitrateBps = 300000;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001229 NetworkControllerConfig cc_config;
Sebastian Jansson78416b62018-10-18 13:08:17 +02001230 cc_config.constraints.at_time = Timestamp::us(clock.TimeInMicroseconds());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001231 cc_config.constraints.starting_rate = DataRate::bps(kDefaultStartBitrateBps);
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001232 cc_config.event_log = &null_event_log;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001233 auto goog_cc = factory.Create(cc_config);
Stefan Holmer13181032016-07-29 14:48:54 +02001234
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001235 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1236 PointStyle::kHighlight);
1237 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1238 PointStyle::kHighlight);
1239 TimeSeries acked_estimate_time_series(
1240 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001241
1242 auto rtp_iterator = outgoing_rtp.begin();
1243 auto rtcp_iterator = incoming_rtcp.begin();
1244
1245 auto NextRtpTime = [&]() {
1246 if (rtp_iterator != outgoing_rtp.end())
1247 return static_cast<int64_t>(rtp_iterator->first);
1248 return std::numeric_limits<int64_t>::max();
1249 };
1250
1251 auto NextRtcpTime = [&]() {
1252 if (rtcp_iterator != incoming_rtcp.end())
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001253 return static_cast<int64_t>(rtcp_iterator->log_time_us());
Stefan Holmer13181032016-07-29 14:48:54 +02001254 return std::numeric_limits<int64_t>::max();
1255 };
Bjorn Tereliusa728c912018-12-06 12:26:30 +01001256 int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()});
Stefan Holmer13181032016-07-29 14:48:54 +02001257
1258 auto NextProcessTime = [&]() {
1259 if (rtcp_iterator != incoming_rtcp.end() ||
1260 rtp_iterator != outgoing_rtp.end()) {
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001261 return next_process_time_us_;
Stefan Holmer13181032016-07-29 14:48:54 +02001262 }
1263 return std::numeric_limits<int64_t>::max();
1264 };
1265
Stefan Holmer492ee282016-10-27 17:19:20 +02001266 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001267#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson95edb032019-01-17 16:24:12 +01001268 FieldTrialBasedConfig field_trial_config_;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001269 // The event_log_visualizer should normally not be compiled with
1270 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
Mirko Bonadei604e75c2019-07-25 11:55:47 +02001271 // However, compiling with BWE_TEST_LOGGING, running with --plot_sendside_bwe
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001272 // and piping the output to plot_dynamics.py can be used as a hack to get the
1273 // internal state of various BWE components. In this case, it is important
1274 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
Sebastian Jansson4ad51d82019-06-11 11:24:40 +02001275 // GoogCcNetworkController since that would lead to duplicate outputs.
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001276 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
Sebastian Jansson95edb032019-01-17 16:24:12 +01001277 &field_trial_config_,
1278 absl::make_unique<BitrateEstimator>(&field_trial_config_));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001279#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001280 int64_t time_us =
1281 std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
Stefan Holmer492ee282016-10-27 17:19:20 +02001282 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001283 while (time_us != std::numeric_limits<int64_t>::max()) {
1284 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001285 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1286 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1287 const RtpPacketType& rtp_packet = *rtp_iterator->second;
1288 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
1289 RTC_DCHECK(rtp_packet.rtp.header.extension.hasTransportSequenceNumber);
Erik Språng30a276b2019-04-23 12:00:11 +02001290 RtpPacketSendInfo packet_info;
1291 packet_info.ssrc = rtp_packet.rtp.header.ssrc;
Bjorn Tereliusf2e9cab2019-05-27 16:44:09 +02001292 packet_info.transport_sequence_number =
Erik Språng30a276b2019-04-23 12:00:11 +02001293 rtp_packet.rtp.header.extension.transportSequenceNumber;
1294 packet_info.rtp_sequence_number = rtp_packet.rtp.header.sequenceNumber;
1295 packet_info.has_rtp_sequence_number = true;
1296 packet_info.length = rtp_packet.rtp.total_length;
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001297 transport_feedback.AddPacket(
Erik Språng30a276b2019-04-23 12:00:11 +02001298 packet_info,
1299 0u, // Per packet overhead bytes.
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001300 Timestamp::us(rtp_packet.rtp.log_time_us()));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001301 rtc::SentPacket sent_packet(
1302 rtp_packet.rtp.header.extension.transportSequenceNumber,
1303 rtp_packet.rtp.log_time_us() / 1000);
1304 auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet);
1305 if (sent_msg)
1306 observer.Update(goog_cc->OnSentPacket(*sent_msg));
1307 }
1308 ++rtp_iterator;
1309 }
Stefan Holmer13181032016-07-29 14:48:54 +02001310 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001311 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001312
1313 auto feedback_msg = transport_feedback.ProcessTransportFeedback(
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001314 rtcp_iterator->transport_feedback,
1315 Timestamp::ms(clock.TimeInMilliseconds()));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001316 absl::optional<uint32_t> bitrate_bps;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001317 if (feedback_msg) {
1318 observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg));
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001319 std::vector<PacketResult> feedback =
1320 feedback_msg->SortedByReceiveTime();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001321 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001322#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001323 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001324#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001325 for (const PacketResult& packet : feedback)
1326 acked_bitrate.Update(packet.sent_packet.size.bytes(),
1327 packet.receive_time.ms());
1328 bitrate_bps = acked_bitrate.Rate(feedback.back().receive_time.ms());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001329 }
Stefan Holmer13181032016-07-29 14:48:54 +02001330 }
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001331
Bjorn Terelius068fc352019-02-13 22:38:25 +01001332 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001333 float y = bitrate_bps.value_or(0) / 1000;
1334 acked_time_series.points.emplace_back(x, y);
1335#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001336 y = acknowledged_bitrate_estimator.bitrate()
1337 .value_or(DataRate::Zero())
1338 .kbps();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001339 acked_estimate_time_series.points.emplace_back(x, y);
1340#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001341 ++rtcp_iterator;
1342 }
stefanc3de0332016-08-02 07:22:17 -07001343 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1344 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001345 ProcessInterval msg;
1346 msg.at_time = Timestamp::us(clock.TimeInMicroseconds());
1347 observer.Update(goog_cc->OnProcessInterval(msg));
1348 next_process_time_us_ += process_interval.us();
stefanc3de0332016-08-02 07:22:17 -07001349 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001350 if (observer.GetAndResetBitrateUpdated() ||
1351 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001352 uint32_t y = observer.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001353 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Stefan Holmer13181032016-07-29 14:48:54 +02001354 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001355 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001356 }
1357 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1358 }
1359 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001360 plot->AppendTimeSeries(std::move(time_series));
1361 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001362 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001363
Bjorn Terelius068fc352019-02-13 22:38:25 +01001364 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1365 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001366 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001367 plot->SetTitle("Simulated send-side BWE behavior");
1368}
1369
1370void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001371 using RtpPacketType = LoggedRtpPacketIncoming;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001372 class RembInterceptingPacketRouter : public PacketRouter {
1373 public:
1374 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1375 uint32_t bitrate_bps) override {
1376 last_bitrate_bps_ = bitrate_bps;
1377 bitrate_updated_ = true;
1378 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1379 }
1380 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1381 bool GetAndResetBitrateUpdated() {
1382 bool bitrate_updated = bitrate_updated_;
1383 bitrate_updated_ = false;
1384 return bitrate_updated;
1385 }
1386
1387 private:
1388 uint32_t last_bitrate_bps_;
1389 bool bitrate_updated_;
1390 };
1391
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001392 std::multimap<int64_t, const RtpPacketType*> incoming_rtp;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001393
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001394 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
1395 if (IsVideoSsrc(kIncomingPacket, stream.ssrc)) {
1396 for (const auto& rtp_packet : stream.incoming_packets)
1397 incoming_rtp.insert(
1398 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Bjorn Terelius28db2662017-10-04 14:22:43 +02001399 }
1400 }
1401
1402 SimulatedClock clock(0);
1403 RembInterceptingPacketRouter packet_router;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001404 // TODO(terelius): The PacketRouter is used as the RemoteBitrateObserver.
Bjorn Terelius28db2662017-10-04 14:22:43 +02001405 // Is this intentional?
1406 ReceiveSideCongestionController rscc(&clock, &packet_router);
1407 // TODO(holmer): Log the call config and use that here instead.
1408 // static const uint32_t kDefaultStartBitrateBps = 300000;
1409 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1410
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001411 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1412 PointStyle::kHighlight);
1413 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001414
1415 RateStatistics acked_bitrate(250, 8000);
1416 int64_t last_update_us = 0;
1417 for (const auto& kv : incoming_rtp) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001418 const RtpPacketType& packet = *kv.second;
1419 int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000;
1420 size_t payload = packet.rtp.total_length; /*Should subtract header?*/
1421 clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() -
Bjorn Terelius28db2662017-10-04 14:22:43 +02001422 clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001423 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001424 acked_bitrate.Update(payload, arrival_time_ms);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001425 absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001426 if (bitrate_bps) {
1427 uint32_t y = *bitrate_bps / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001428 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001429 acked_time_series.points.emplace_back(x, y);
1430 }
1431 if (packet_router.GetAndResetBitrateUpdated() ||
1432 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1433 uint32_t y = packet_router.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001434 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001435 time_series.points.emplace_back(x, y);
1436 last_update_us = clock.TimeInMicroseconds();
1437 }
1438 }
1439 // Add the data set to the plot.
1440 plot->AppendTimeSeries(std::move(time_series));
1441 plot->AppendTimeSeries(std::move(acked_time_series));
1442
Bjorn Terelius068fc352019-02-13 22:38:25 +01001443 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1444 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001445 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1446 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001447}
1448
tereliuse34c19c2016-08-15 08:47:14 -07001449void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001450 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1451 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001452 TimeSeries time_series("Network delay", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001453 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001454 int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max();
1455 int64_t min_rtt_ms = std::numeric_limits<int64_t>::max();
stefanc3de0332016-08-02 07:22:17 -07001456
stefana0a8ed72017-09-06 02:06:32 -07001457 int64_t prev_y = 0;
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001458 for (auto packet : GetNetworkTrace(parsed_log_)) {
1459 if (packet.arrival_time_ms == PacketFeedback::kNotReceived)
1460 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001461 float x = config_.GetCallTimeSec(1000 * packet.feedback_arrival_time_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001462 if (packet.send_time_ms == PacketFeedback::kNoSendTime) {
1463 late_feedback_series.points.emplace_back(x, prev_y);
1464 continue;
stefanc3de0332016-08-02 07:22:17 -07001465 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001466 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1467 prev_y = y;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001468 int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms;
1469 min_rtt_ms = std::min(rtt_ms, min_rtt_ms);
1470 min_send_receive_diff_ms = std::min(y, min_send_receive_diff_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001471 time_series.points.emplace_back(x, y);
stefanc3de0332016-08-02 07:22:17 -07001472 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001473
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001474 // We assume that the base network delay (w/o queues) is equal to half
1475 // the minimum RTT. Therefore rescale the delays by subtracting the minimum
Mirko Bonadei604e75c2019-07-25 11:55:47 +02001476 // observed 1-ways delay and add half the minimum RTT.
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001477 const int64_t estimated_clock_offset_ms =
1478 min_send_receive_diff_ms - min_rtt_ms / 2;
stefanc3de0332016-08-02 07:22:17 -07001479 for (TimeSeriesPoint& point : time_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001480 point.y -= estimated_clock_offset_ms;
stefana0a8ed72017-09-06 02:06:32 -07001481 for (TimeSeriesPoint& point : late_feedback_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001482 point.y -= estimated_clock_offset_ms;
1483
stefanc3de0332016-08-02 07:22:17 -07001484 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001485 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1486 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001487
Bjorn Terelius068fc352019-02-13 22:38:25 +01001488 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1489 "Time (s)", kLeftMargin, kRightMargin);
stefanc3de0332016-08-02 07:22:17 -07001490 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +01001491 plot->SetTitle("Outgoing network delay (based on per-packet feedback)");
stefanc3de0332016-08-02 07:22:17 -07001492}
stefan08383272016-12-20 08:51:52 -08001493
Bjorn Terelius0295a962017-10-25 17:42:41 +02001494void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001495 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1496 const std::vector<LoggedRtpPacketOutgoing>& packets =
1497 stream.outgoing_packets;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001498
Konrad Hofbauerbfb735b2019-04-16 11:12:11 +02001499 if (IsRtxSsrc(kOutgoingPacket, stream.ssrc)) {
1500 continue;
1501 }
1502
Bjorn Terelius0295a962017-10-25 17:42:41 +02001503 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001504 RTC_LOG(LS_WARNING)
1505 << "Can't estimate a the RTP clock frequency or the "
1506 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001507 continue;
1508 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001509 int64_t end_time_us = log_segments_.empty()
1510 ? std::numeric_limits<int64_t>::max()
1511 : log_segments_.front().second;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001512 absl::optional<uint32_t> estimated_frequency =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001513 EstimateRtpClockFrequency(packets, end_time_us);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001514 if (!estimated_frequency)
1515 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001516 if (IsVideoSsrc(kOutgoingPacket, stream.ssrc) &&
1517 *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001518 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001519 << "Video stream should use a 90 kHz clock but appears to use "
1520 << *estimated_frequency / 1000 << ". Discarding.";
1521 continue;
1522 }
1523
1524 TimeSeries pacer_delay_series(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001525 GetStreamName(kOutgoingPacket, stream.ssrc) + "(" +
Bjorn Terelius0295a962017-10-25 17:42:41 +02001526 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001527 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001528 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1529 uint64_t first_capture_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001530 timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp);
1531 uint64_t first_send_timestamp = packets.front().rtp.log_time_us();
1532 for (const auto& packet : packets) {
Bjorn Terelius0295a962017-10-25 17:42:41 +02001533 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001534 packet.rtp.header.timestamp)) -
Bjorn Terelius0295a962017-10-25 17:42:41 +02001535 first_capture_timestamp) /
1536 *estimated_frequency * 1000;
1537 double send_time_ms =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001538 static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) /
1539 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001540 float x = config_.GetCallTimeSec(packet.rtp.log_time_us());
Bjorn Terelius0295a962017-10-25 17:42:41 +02001541 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
Bjorn Terelius068fc352019-02-13 22:38:25 +01001547 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1548 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001549 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1550 plot->SetTitle(
1551 "Delay from capture to send time. (First packet normalized to 0.)");
1552}
1553
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001554void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction,
1555 Plot* plot) {
1556 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1557 TimeSeries rtp_timestamps(
1558 GetStreamName(direction, stream.ssrc) + " capture-time",
1559 LineStyle::kLine, PointStyle::kHighlight);
1560 for (const auto& packet : stream.packet_view) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001561 float x = config_.GetCallTimeSec(packet.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001562 float y = packet.header.timestamp;
1563 rtp_timestamps.points.emplace_back(x, y);
stefane372d3c2017-02-02 08:04:18 -08001564 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001565 plot->AppendTimeSeries(std::move(rtp_timestamps));
Björn Tereliusff612732018-04-25 14:23:01 +00001566
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001567 TimeSeries rtcp_timestamps(
1568 GetStreamName(direction, stream.ssrc) + " rtcp capture-time",
1569 LineStyle::kLine, PointStyle::kHighlight);
1570 // TODO(terelius): Why only sender reports?
1571 const auto& sender_reports = parsed_log_.sender_reports(direction);
1572 for (const auto& rtcp : sender_reports) {
1573 if (rtcp.sr.sender_ssrc() != stream.ssrc)
1574 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001575 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001576 float y = rtcp.sr.rtp_timestamp();
1577 rtcp_timestamps.points.emplace_back(x, y);
Björn Tereliusff612732018-04-25 14:23:01 +00001578 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001579 plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps));
stefane372d3c2017-02-02 08:04:18 -08001580 }
1581
Bjorn Terelius068fc352019-02-13 22:38:25 +01001582 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1583 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001584 plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin);
1585 plot->SetTitle(GetDirectionAsString(direction) + " timestamps");
stefane372d3c2017-02-02 08:04:18 -08001586}
michaelt6e5b2192017-02-22 07:33:27 -08001587
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001588void EventLogAnalyzer::CreateSenderAndReceiverReportPlot(
1589 PacketDirection direction,
1590 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
1591 std::string title,
1592 std::string yaxis_label,
1593 Plot* plot) {
1594 std::map<uint32_t, TimeSeries> sr_reports_by_ssrc;
1595 const auto& sender_reports = parsed_log_.sender_reports(direction);
1596 for (const auto& rtcp : sender_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001597 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001598 uint32_t ssrc = rtcp.sr.sender_ssrc();
1599 for (const auto& block : rtcp.sr.report_blocks()) {
1600 float y = fy(block);
1601 auto sr_report_it = sr_reports_by_ssrc.find(ssrc);
1602 bool inserted;
1603 if (sr_report_it == sr_reports_by_ssrc.end()) {
1604 std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace(
1605 ssrc, TimeSeries(GetStreamName(direction, ssrc) + " Sender Reports",
1606 LineStyle::kLine, PointStyle::kHighlight));
1607 }
1608 sr_report_it->second.points.emplace_back(x, y);
1609 }
1610 }
1611 for (auto& kv : sr_reports_by_ssrc) {
1612 plot->AppendTimeSeries(std::move(kv.second));
1613 }
1614
1615 std::map<uint32_t, TimeSeries> rr_reports_by_ssrc;
1616 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
1617 for (const auto& rtcp : receiver_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001618 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001619 uint32_t ssrc = rtcp.rr.sender_ssrc();
1620 for (const auto& block : rtcp.rr.report_blocks()) {
1621 float y = fy(block);
1622 auto rr_report_it = rr_reports_by_ssrc.find(ssrc);
1623 bool inserted;
1624 if (rr_report_it == rr_reports_by_ssrc.end()) {
1625 std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace(
1626 ssrc,
1627 TimeSeries(GetStreamName(direction, ssrc) + " Receiver Reports",
1628 LineStyle::kLine, PointStyle::kHighlight));
1629 }
1630 rr_report_it->second.points.emplace_back(x, y);
1631 }
1632 }
1633 for (auto& kv : rr_reports_by_ssrc) {
1634 plot->AppendTimeSeries(std::move(kv.second));
1635 }
1636
Bjorn Terelius068fc352019-02-13 22:38:25 +01001637 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1638 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001639 plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin);
1640 plot->SetTitle(title);
1641}
1642
michaelt6e5b2192017-02-22 07:33:27 -08001643void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001644 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1645 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001646 auto GetAnaBitrateBps = [](const LoggedAudioNetworkAdaptationEvent& ana_event)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001647 -> absl::optional<float> {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001648 if (ana_event.config.bitrate_bps)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001649 return absl::optional<float>(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001650 static_cast<float>(*ana_event.config.bitrate_bps));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001651 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001652 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001653 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001654 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001655 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001656 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001657 ToCallTime, GetAnaBitrateBps,
1658 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001659 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001660 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1661 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001662 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1663 plot->SetTitle("Reported audio encoder target bitrate");
1664}
1665
1666void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001667 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1668 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001669 auto GetAnaFrameLengthMs =
1670 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001671 if (ana_event.config.frame_length_ms)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001672 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001673 static_cast<float>(*ana_event.config.frame_length_ms));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001674 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001675 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001676 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001677 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001678 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001679 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001680 ToCallTime, GetAnaFrameLengthMs,
1681 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001682 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001683 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1684 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001685 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1686 plot->SetTitle("Reported audio encoder frame length");
1687}
1688
terelius2ee076d2017-08-15 02:04:02 -07001689void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001690 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001691 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001692 auto GetAnaPacketLoss =
1693 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001694 if (ana_event.config.uplink_packet_loss_fraction)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001695 return absl::optional<float>(static_cast<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001696 *ana_event.config.uplink_packet_loss_fraction));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001697 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001698 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001699 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001700 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001701 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001702 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001703 ToCallTime, GetAnaPacketLoss,
1704 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001705 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001706 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1707 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001708 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1709 kTopMargin);
1710 plot->SetTitle("Reported audio encoder lost packets");
1711}
1712
1713void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001714 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1715 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001716 auto GetAnaFecEnabled =
1717 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001718 if (ana_event.config.enable_fec)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001719 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001720 static_cast<float>(*ana_event.config.enable_fec));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001721 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001722 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001723 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001724 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001725 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001726 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001727 ToCallTime, GetAnaFecEnabled,
1728 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001729 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001730 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1731 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001732 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1733 plot->SetTitle("Reported audio encoder FEC");
1734}
1735
1736void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001737 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1738 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001739 auto GetAnaDtxEnabled =
1740 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001741 if (ana_event.config.enable_dtx)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001742 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001743 static_cast<float>(*ana_event.config.enable_dtx));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001744 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001745 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001746 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001747 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001748 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001749 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001750 ToCallTime, GetAnaDtxEnabled,
1751 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001752 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001753 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1754 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001755 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1756 plot->SetTitle("Reported audio encoder DTX");
1757}
1758
1759void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001760 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1761 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001762 auto GetAnaNumChannels =
1763 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001764 if (ana_event.config.num_channels)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001765 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001766 static_cast<float>(*ana_event.config.num_channels));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001767 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001768 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001769 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001770 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001771 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001772 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001773 ToCallTime, GetAnaNumChannels,
1774 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001775 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001776 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1777 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001778 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1779 kBottomMargin, kTopMargin);
1780 plot->SetTitle("Reported audio encoder number of channels");
1781}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001782
1783class NetEqStreamInput : public test::NetEqInput {
1784 public:
1785 // Does not take any ownership, and all pointers must refer to valid objects
1786 // that outlive the one constructed.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001787 NetEqStreamInput(const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001788 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001789 absl::optional<int64_t> end_time_ms)
henrik.lundin3c938fc2017-06-14 06:09:58 -07001790 : packet_stream_(*packet_stream),
1791 packet_stream_it_(packet_stream_.begin()),
Minyue Li27e2b7d2018-05-07 15:20:24 +02001792 output_events_it_(output_events->begin()),
1793 output_events_end_(output_events->end()),
1794 end_time_ms_(end_time_ms) {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001795 RTC_DCHECK(packet_stream);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001796 RTC_DCHECK(output_events);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001797 }
1798
Danil Chapovalov431abd92018-06-18 12:54:17 +02001799 absl::optional<int64_t> NextPacketTime() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001800 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001801 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001802 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001803 if (end_time_ms_ && packet_stream_it_->rtp.log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001804 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001805 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001806 return packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001807 }
1808
Danil Chapovalov431abd92018-06-18 12:54:17 +02001809 absl::optional<int64_t> NextOutputEventTime() const override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001810 if (output_events_it_ == output_events_end_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001811 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001812 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001813 if (end_time_ms_ && output_events_it_->log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001814 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001815 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001816 return output_events_it_->log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001817 }
1818
1819 std::unique_ptr<PacketData> PopPacket() override {
1820 if (packet_stream_it_ == packet_stream_.end()) {
1821 return std::unique_ptr<PacketData>();
1822 }
1823 std::unique_ptr<PacketData> packet_data(new PacketData());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001824 packet_data->header = packet_stream_it_->rtp.header;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001825 packet_data->time_ms = packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001826
1827 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1828 // length according to the virtual length.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001829 packet_data->payload.SetSize(packet_stream_it_->rtp.total_length -
1830 packet_stream_it_->rtp.header_length);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001831 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1832
1833 ++packet_stream_it_;
1834 return packet_data;
1835 }
1836
1837 void AdvanceOutputEvent() override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001838 if (output_events_it_ != output_events_end_) {
1839 ++output_events_it_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001840 }
1841 }
1842
1843 bool ended() const override { return !NextEventTime(); }
1844
Danil Chapovalov431abd92018-06-18 12:54:17 +02001845 absl::optional<RTPHeader> NextHeader() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001846 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001847 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001848 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001849 return packet_stream_it_->rtp.header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001850 }
1851
1852 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001853 const std::vector<LoggedRtpPacketIncoming>& packet_stream_;
1854 std::vector<LoggedRtpPacketIncoming>::const_iterator packet_stream_it_;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001855 std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_it_;
1856 const std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_end_;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001857 const absl::optional<int64_t> end_time_ms_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001858};
1859
1860namespace {
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001861
1862// Factory to create a "replacement decoder" that produces the decoded audio
1863// by reading from a file rather than from the encoded payloads.
1864class ReplacementAudioDecoderFactory : public AudioDecoderFactory {
1865 public:
1866 ReplacementAudioDecoderFactory(const absl::string_view replacement_file_name,
1867 int file_sample_rate_hz)
1868 : replacement_file_name_(replacement_file_name),
1869 file_sample_rate_hz_(file_sample_rate_hz) {}
1870
1871 std::vector<AudioCodecSpec> GetSupportedDecoders() override {
1872 RTC_NOTREACHED();
1873 return {};
1874 }
1875
1876 bool IsSupportedDecoder(const SdpAudioFormat& format) override {
1877 return true;
1878 }
1879
1880 std::unique_ptr<AudioDecoder> MakeAudioDecoder(
1881 const SdpAudioFormat& format,
1882 absl::optional<AudioCodecPairId> codec_pair_id) override {
1883 auto replacement_file = absl::make_unique<test::ResampleInputAudioFile>(
1884 replacement_file_name_, file_sample_rate_hz_);
1885 replacement_file->set_output_rate_hz(48000);
1886 return absl::make_unique<test::FakeDecodeFromFile>(
1887 std::move(replacement_file), 48000, false);
1888 }
1889
1890 private:
1891 const std::string replacement_file_name_;
1892 const int file_sample_rate_hz_;
1893};
1894
henrik.lundin3c938fc2017-06-14 06:09:58 -07001895// Creates a NetEq test object and all necessary input and output helpers. Runs
1896// the test and returns the NetEqDelayAnalyzer object that was used to
1897// instrument the test.
Minyue Lic6ff7572018-05-04 09:46:44 +02001898std::unique_ptr<test::NetEqStatsGetter> CreateNetEqTestAndRun(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001899 const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001900 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001901 absl::optional<int64_t> end_time_ms,
henrik.lundin3c938fc2017-06-14 06:09:58 -07001902 const std::string& replacement_file_name,
1903 int file_sample_rate_hz) {
1904 std::unique_ptr<test::NetEqInput> input(
Minyue Li27e2b7d2018-05-07 15:20:24 +02001905 new NetEqStreamInput(packet_stream, output_events, end_time_ms));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001906
1907 constexpr int kReplacementPt = 127;
1908 std::set<uint8_t> cn_types;
1909 std::set<uint8_t> forbidden_types;
1910 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1911 cn_types, forbidden_types));
1912
1913 NetEq::Config config;
1914 config.max_packets_in_buffer = 200;
1915 config.enable_fast_accelerate = true;
1916
1917 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1918
Niels Möller3f651d82018-12-19 15:06:17 +01001919 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory =
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001920 new rtc::RefCountedObject<ReplacementAudioDecoderFactory>(
1921 replacement_file_name, file_sample_rate_hz);
Niels Möller3f651d82018-12-19 15:06:17 +01001922
Niels Möller05543682019-01-10 16:55:06 +01001923 test::NetEqTest::DecoderMap codecs = {
1924 {kReplacementPt, SdpAudioFormat("l16", 48000, 1)}};
henrik.lundin3c938fc2017-06-14 06:09:58 -07001925
1926 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1927 new test::NetEqDelayAnalyzer);
Minyue Lic6ff7572018-05-04 09:46:44 +02001928 std::unique_ptr<test::NetEqStatsGetter> neteq_stats_getter(
1929 new test::NetEqStatsGetter(std::move(delay_cb)));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001930 test::DefaultNetEqTestErrorCallback error_cb;
1931 test::NetEqTest::Callbacks callbacks;
1932 callbacks.error_callback = &error_cb;
Minyue Lic6ff7572018-05-04 09:46:44 +02001933 callbacks.post_insert_packet = neteq_stats_getter->delay_analyzer();
1934 callbacks.get_audio_callback = neteq_stats_getter.get();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001935
Niels Möllerbd6dee82019-01-02 09:39:47 +01001936 test::NetEqTest test(config, decoder_factory, codecs, nullptr,
Niels Möller3f651d82018-12-19 15:06:17 +01001937 std::move(input), std::move(output), callbacks);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001938 test.Run();
Minyue Lic6ff7572018-05-04 09:46:44 +02001939 return neteq_stats_getter;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001940}
1941} // namespace
1942
Minyue Lic6ff7572018-05-04 09:46:44 +02001943EventLogAnalyzer::NetEqStatsGetterMap EventLogAnalyzer::SimulateNetEq(
henrik.lundin3c938fc2017-06-14 06:09:58 -07001944 const std::string& replacement_file_name,
Minyue Lic6ff7572018-05-04 09:46:44 +02001945 int file_sample_rate_hz) const {
1946 NetEqStatsGetterMap neteq_stats;
1947
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001948 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001949 const uint32_t ssrc = stream.ssrc;
1950 if (!IsAudioSsrc(kIncomingPacket, ssrc))
1951 continue;
1952 const std::vector<LoggedRtpPacketIncoming>* audio_packets =
1953 &stream.incoming_packets;
1954 if (audio_packets == nullptr) {
1955 // No incoming audio stream found.
1956 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001957 }
henrik.lundin3c938fc2017-06-14 06:09:58 -07001958
Minyue Li27e2b7d2018-05-07 15:20:24 +02001959 RTC_DCHECK(neteq_stats.find(ssrc) == neteq_stats.end());
1960
1961 std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>::const_iterator
1962 output_events_it = parsed_log_.audio_playout_events().find(ssrc);
1963 if (output_events_it == parsed_log_.audio_playout_events().end()) {
1964 // Could not find output events with SSRC matching the input audio stream.
1965 // Using the first available stream of output events.
1966 output_events_it = parsed_log_.audio_playout_events().cbegin();
1967 }
1968
Danil Chapovalov431abd92018-06-18 12:54:17 +02001969 absl::optional<int64_t> end_time_ms =
Minyue Li27e2b7d2018-05-07 15:20:24 +02001970 log_segments_.empty()
Danil Chapovalov431abd92018-06-18 12:54:17 +02001971 ? absl::nullopt
1972 : absl::optional<int64_t>(log_segments_.front().second / 1000);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001973
1974 neteq_stats[ssrc] = CreateNetEqTestAndRun(
1975 audio_packets, &output_events_it->second, end_time_ms,
1976 replacement_file_name, file_sample_rate_hz);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001977 }
1978
Minyue Lic6ff7572018-05-04 09:46:44 +02001979 return neteq_stats;
1980}
1981
Minyue Lic97933f2018-08-10 12:51:15 +02001982// Given a NetEqStatsGetter and the SSRC that the NetEqStatsGetter was created
1983// for, this method generates a plot for the jitter buffer delay profile.
Minyue Lic6ff7572018-05-04 09:46:44 +02001984void EventLogAnalyzer::CreateAudioJitterBufferGraph(
Minyue Li01d2a672018-06-21 21:17:19 +02001985 uint32_t ssrc,
1986 const test::NetEqStatsGetter* stats_getter,
Minyue Lic6ff7572018-05-04 09:46:44 +02001987 Plot* plot) const {
Minyue Li45fc6df2018-06-21 11:47:14 +02001988 test::NetEqDelayAnalyzer::Delays arrival_delay_ms;
1989 test::NetEqDelayAnalyzer::Delays corrected_arrival_delay_ms;
1990 test::NetEqDelayAnalyzer::Delays playout_delay_ms;
1991 test::NetEqDelayAnalyzer::Delays target_delay_ms;
1992
Minyue Li01d2a672018-06-21 21:17:19 +02001993 stats_getter->delay_analyzer()->CreateGraphs(
Minyue Li45fc6df2018-06-21 11:47:14 +02001994 &arrival_delay_ms, &corrected_arrival_delay_ms, &playout_delay_ms,
1995 &target_delay_ms);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001996
Minyue Lic97933f2018-08-10 12:51:15 +02001997 TimeSeries time_series_packet_arrival("packet arrival delay",
1998 LineStyle::kLine);
1999 TimeSeries time_series_relative_packet_arrival(
2000 "Relative packet arrival delay", LineStyle::kLine);
2001 TimeSeries time_series_play_time("Playout delay", LineStyle::kLine);
2002 TimeSeries time_series_target_time("Target delay", LineStyle::kLine,
2003 PointStyle::kHighlight);
Minyue Li45fc6df2018-06-21 11:47:14 +02002004
2005 for (const auto& data : arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002006 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002007 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002008 time_series_packet_arrival.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02002009 }
2010 for (const auto& data : corrected_arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002011 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002012 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002013 time_series_relative_packet_arrival.points.emplace_back(
Minyue Li45fc6df2018-06-21 11:47:14 +02002014 TimeSeriesPoint(x, y));
2015 }
2016 for (const auto& data : playout_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002017 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002018 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002019 time_series_play_time.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02002020 }
2021 for (const auto& data : target_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002022 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002023 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002024 time_series_target_time.points.emplace_back(TimeSeriesPoint(x, y));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002025 }
2026
Minyue Lic97933f2018-08-10 12:51:15 +02002027 plot->AppendTimeSeries(std::move(time_series_packet_arrival));
2028 plot->AppendTimeSeries(std::move(time_series_relative_packet_arrival));
2029 plot->AppendTimeSeries(std::move(time_series_play_time));
2030 plot->AppendTimeSeries(std::move(time_series_target_time));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002031
Bjorn Terelius068fc352019-02-13 22:38:25 +01002032 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2033 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02002034 plot->SetSuggestedYAxis(0, 1, "Relative delay (ms)", kBottomMargin,
2035 kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002036 plot->SetTitle("NetEq timing for " + GetStreamName(kIncomingPacket, ssrc));
2037}
2038
Minyue Lic9ac93f2018-06-26 13:01:32 +02002039template <typename NetEqStatsType>
2040void EventLogAnalyzer::CreateNetEqStatsGraphInternal(
Minyue Li27e2b7d2018-05-07 15:20:24 +02002041 const NetEqStatsGetterMap& neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +02002042 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
2043 const test::NetEqStatsGetter*)> data_extractor,
2044 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
Minyue Li27e2b7d2018-05-07 15:20:24 +02002045 const std::string& plot_name,
2046 Plot* plot) const {
Minyue Li27e2b7d2018-05-07 15:20:24 +02002047 std::map<uint32_t, TimeSeries> time_series;
Minyue Li27e2b7d2018-05-07 15:20:24 +02002048
2049 for (const auto& st : neteq_stats) {
2050 const uint32_t ssrc = st.first;
Minyue Lic9ac93f2018-06-26 13:01:32 +02002051 const std::vector<std::pair<int64_t, NetEqStatsType>>* data_vector =
2052 data_extractor(st.second.get());
2053 for (const auto& data : *data_vector) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002054 const float time =
2055 config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Lic9ac93f2018-06-26 13:01:32 +02002056 const float value = stats_extractor(data.second);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002057 time_series[ssrc].points.emplace_back(TimeSeriesPoint(time, value));
Minyue Li27e2b7d2018-05-07 15:20:24 +02002058 }
2059 }
2060
2061 for (auto& series : time_series) {
2062 series.second.label = GetStreamName(kIncomingPacket, series.first);
2063 series.second.line_style = LineStyle::kLine;
2064 plot->AppendTimeSeries(std::move(series.second));
2065 }
2066
Bjorn Terelius068fc352019-02-13 22:38:25 +01002067 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2068 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02002069 plot->SetSuggestedYAxis(0, 1, plot_name, kBottomMargin, kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002070 plot->SetTitle(plot_name);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002071}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002072
Minyue Lic9ac93f2018-06-26 13:01:32 +02002073void EventLogAnalyzer::CreateNetEqNetworkStatsGraph(
2074 const NetEqStatsGetterMap& neteq_stats,
2075 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
2076 const std::string& plot_name,
2077 Plot* plot) const {
2078 CreateNetEqStatsGraphInternal<NetEqNetworkStatistics>(
2079 neteq_stats,
2080 [](const test::NetEqStatsGetter* stats_getter) {
2081 return stats_getter->stats();
2082 },
2083 stats_extractor, plot_name, plot);
2084}
2085
2086void EventLogAnalyzer::CreateNetEqLifetimeStatsGraph(
2087 const NetEqStatsGetterMap& neteq_stats,
2088 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
2089 const std::string& plot_name,
2090 Plot* plot) const {
2091 CreateNetEqStatsGraphInternal<NetEqLifetimeStatistics>(
2092 neteq_stats,
2093 [](const test::NetEqStatsGetter* stats_getter) {
2094 return stats_getter->lifetime_stats();
2095 },
2096 stats_extractor, plot_name, plot);
2097}
2098
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002099void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
2100 std::map<uint32_t, TimeSeries> configs_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002101 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002102 if (configs_by_cp_id.find(config.candidate_pair_id) ==
2103 configs_by_cp_id.end()) {
2104 const std::string candidate_pair_desc =
2105 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08002106 configs_by_cp_id[config.candidate_pair_id] =
2107 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
2108 candidate_pair_desc,
2109 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002110 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2111 candidate_pair_desc;
2112 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002113 float x = config_.GetCallTimeSec(config.log_time_us());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002114 float y = static_cast<float>(config.type);
2115 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
2116 }
2117
2118 // TODO(qingsi): There can be a large number of candidate pairs generated by
2119 // certain calls and the frontend cannot render the chart in this case due to
2120 // the failure of generating a palette with the same number of colors.
2121 for (auto& kv : configs_by_cp_id) {
2122 plot->AppendTimeSeries(std::move(kv.second));
2123 }
2124
Bjorn Terelius068fc352019-02-13 22:38:25 +01002125 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2126 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002127 plot->SetSuggestedYAxis(0, 3, "Config Type", kBottomMargin, kTopMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002128 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002129 plot->SetYAxisTickLabels(
2130 {{static_cast<float>(IceCandidatePairConfigType::kAdded), "ADDED"},
2131 {static_cast<float>(IceCandidatePairConfigType::kUpdated), "UPDATED"},
2132 {static_cast<float>(IceCandidatePairConfigType::kDestroyed),
2133 "DESTROYED"},
2134 {static_cast<float>(IceCandidatePairConfigType::kSelected),
2135 "SELECTED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002136}
2137
2138std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
2139 uint32_t candidate_pair_id) {
2140 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
2141 candidate_pair_desc_by_id_.end()) {
2142 return candidate_pair_desc_by_id_[candidate_pair_id];
2143 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002144 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002145 // TODO(qingsi): Add the handling of the "Updated" config event after the
2146 // visualization of property change for candidate pairs is introduced.
2147 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
2148 candidate_pair_desc_by_id_.end()) {
2149 const std::string candidate_pair_desc =
2150 GetCandidatePairLogDescriptionAsString(config);
2151 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2152 candidate_pair_desc;
2153 }
2154 }
2155 return candidate_pair_desc_by_id_[candidate_pair_id];
2156}
2157
2158void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002159 constexpr int kEventTypeOffset =
2160 static_cast<int>(IceCandidatePairConfigType::kNumValues);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002161 std::map<uint32_t, TimeSeries> checks_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002162 for (const auto& event : parsed_log_.ice_candidate_pair_events()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002163 if (checks_by_cp_id.find(event.candidate_pair_id) ==
2164 checks_by_cp_id.end()) {
2165 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08002166 "[" + std::to_string(event.candidate_pair_id) + "]" +
2167 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002168 LineStyle::kNone, PointStyle::kHighlight);
2169 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002170 float x = config_.GetCallTimeSec(event.log_time_us());
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002171 float y = static_cast<float>(event.type) + kEventTypeOffset;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002172 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
2173 }
2174
2175 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
2176 for (auto& kv : checks_by_cp_id) {
2177 plot->AppendTimeSeries(std::move(kv.second));
2178 }
2179
Bjorn Terelius068fc352019-02-13 22:38:25 +01002180 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2181 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002182 plot->SetSuggestedYAxis(0, 4, "Connectivity State", kBottomMargin,
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002183 kTopMargin);
2184 plot->SetTitle("[IceEventLog] ICE connectivity checks");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002185
2186 plot->SetYAxisTickLabels(
2187 {{static_cast<float>(IceCandidatePairEventType::kCheckSent) +
2188 kEventTypeOffset,
2189 "CHECK SENT"},
2190 {static_cast<float>(IceCandidatePairEventType::kCheckReceived) +
2191 kEventTypeOffset,
2192 "CHECK RECEIVED"},
2193 {static_cast<float>(IceCandidatePairEventType::kCheckResponseSent) +
2194 kEventTypeOffset,
2195 "RESPONSE SENT"},
2196 {static_cast<float>(IceCandidatePairEventType::kCheckResponseReceived) +
2197 kEventTypeOffset,
2198 "RESPONSE RECEIVED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002199}
2200
Zach Stein10a58012018-12-07 12:26:28 -08002201void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) {
2202 TimeSeries states("DTLS Transport State", LineStyle::kNone,
2203 PointStyle::kHighlight);
2204 for (const auto& event : parsed_log_.dtls_transport_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002205 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002206 float y = static_cast<float>(event.dtls_transport_state);
2207 states.points.emplace_back(x, y);
2208 }
2209 plot->AppendTimeSeries(std::move(states));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002210 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2211 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002212 plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues),
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002213 "Transport State", kBottomMargin, kTopMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002214 plot->SetTitle("DTLS Transport State");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002215 plot->SetYAxisTickLabels(
2216 {{static_cast<float>(DtlsTransportState::kNew), "NEW"},
2217 {static_cast<float>(DtlsTransportState::kConnecting), "CONNECTING"},
2218 {static_cast<float>(DtlsTransportState::kConnected), "CONNECTED"},
2219 {static_cast<float>(DtlsTransportState::kClosed), "CLOSED"},
2220 {static_cast<float>(DtlsTransportState::kFailed), "FAILED"}});
Zach Stein10a58012018-12-07 12:26:28 -08002221}
2222
2223void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) {
2224 TimeSeries writable("DTLS Writable", LineStyle::kNone,
2225 PointStyle::kHighlight);
2226 for (const auto& event : parsed_log_.dtls_writable_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002227 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002228 float y = static_cast<float>(event.writable);
2229 writable.points.emplace_back(x, y);
2230 }
2231 plot->AppendTimeSeries(std::move(writable));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002232 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2233 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002234 plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin);
2235 plot->SetTitle("DTLS Writable State");
2236}
2237
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002238void EventLogAnalyzer::PrintNotifications(FILE* file) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002239 fprintf(file, "========== TRIAGE NOTIFICATIONS ==========\n");
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002240 for (const auto& alert : incoming_rtp_recv_time_gaps_) {
2241 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2242 }
2243 for (const auto& alert : incoming_rtcp_recv_time_gaps_) {
2244 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2245 }
2246 for (const auto& alert : outgoing_rtp_send_time_gaps_) {
2247 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2248 }
2249 for (const auto& alert : outgoing_rtcp_send_time_gaps_) {
2250 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2251 }
2252 for (const auto& alert : incoming_seq_num_jumps_) {
2253 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2254 }
2255 for (const auto& alert : incoming_capture_time_jumps_) {
2256 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2257 }
2258 for (const auto& alert : outgoing_seq_num_jumps_) {
2259 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2260 }
2261 for (const auto& alert : outgoing_capture_time_jumps_) {
2262 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2263 }
2264 for (const auto& alert : outgoing_high_loss_alerts_) {
2265 fprintf(file, " : %s\n", alert.ToString().c_str());
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002266 }
2267 fprintf(file, "========== END TRIAGE NOTIFICATIONS ==========\n");
2268}
2269
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002270void EventLogAnalyzer::CreateStreamGapAlerts(PacketDirection direction) {
2271 // With 100 packets/s (~800kbps), false positives would require 10 s without
2272 // data.
2273 constexpr int64_t kMaxSeqNumJump = 1000;
2274 // With a 90 kHz clock, false positives would require 10 s without data.
2275 constexpr int64_t kMaxCaptureTimeJump = 900000;
2276
2277 int64_t end_time_us = log_segments_.empty()
2278 ? std::numeric_limits<int64_t>::max()
2279 : log_segments_.front().second;
2280
2281 SeqNumUnwrapper<uint16_t> seq_num_unwrapper;
Danil Chapovalov431abd92018-06-18 12:54:17 +02002282 absl::optional<int64_t> last_seq_num;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002283 SeqNumUnwrapper<uint32_t> capture_time_unwrapper;
Danil Chapovalov431abd92018-06-18 12:54:17 +02002284 absl::optional<int64_t> last_capture_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002285 // Check for gaps in sequence numbers and capture timestamps.
2286 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
2287 for (const auto& packet : stream.packet_view) {
2288 if (packet.log_time_us() > end_time_us) {
2289 // Only process the first (LOG_START, LOG_END) segment.
2290 break;
2291 }
2292
2293 int64_t seq_num = seq_num_unwrapper.Unwrap(packet.header.sequenceNumber);
2294 if (last_seq_num.has_value() &&
2295 std::abs(seq_num - last_seq_num.value()) > kMaxSeqNumJump) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002296 Alert_SeqNumJump(direction,
2297 config_.GetCallTimeSec(packet.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002298 packet.header.ssrc);
2299 }
2300 last_seq_num.emplace(seq_num);
2301
2302 int64_t capture_time =
2303 capture_time_unwrapper.Unwrap(packet.header.timestamp);
2304 if (last_capture_time.has_value() &&
2305 std::abs(capture_time - last_capture_time.value()) >
2306 kMaxCaptureTimeJump) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002307 Alert_CaptureTimeJump(direction,
2308 config_.GetCallTimeSec(packet.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002309 packet.header.ssrc);
2310 }
2311 last_capture_time.emplace(capture_time);
2312 }
2313 }
2314}
2315
2316void EventLogAnalyzer::CreateTransmissionGapAlerts(PacketDirection direction) {
2317 constexpr int64_t kMaxRtpTransmissionGap = 500000;
2318 constexpr int64_t kMaxRtcpTransmissionGap = 2000000;
2319 int64_t end_time_us = log_segments_.empty()
2320 ? std::numeric_limits<int64_t>::max()
2321 : log_segments_.front().second;
2322
2323 // TODO(terelius): The parser could provide a list of all packets, ordered
2324 // by time, for each direction.
2325 std::multimap<int64_t, const LoggedRtpPacket*> rtp_in_direction;
2326 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
2327 for (const LoggedRtpPacket& rtp_packet : stream.packet_view)
2328 rtp_in_direction.emplace(rtp_packet.log_time_us(), &rtp_packet);
2329 }
Danil Chapovalov431abd92018-06-18 12:54:17 +02002330 absl::optional<int64_t> last_rtp_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002331 for (const auto& kv : rtp_in_direction) {
2332 int64_t timestamp = kv.first;
2333 if (timestamp > end_time_us) {
2334 // Only process the first (LOG_START, LOG_END) segment.
2335 break;
2336 }
2337 int64_t duration = timestamp - last_rtp_time.value_or(0);
2338 if (last_rtp_time.has_value() && duration > kMaxRtpTransmissionGap) {
2339 // No packet sent/received for more than 500 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002340 Alert_RtpLogTimeGap(direction, config_.GetCallTimeSec(timestamp),
2341 duration / 1000);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002342 }
2343 last_rtp_time.emplace(timestamp);
2344 }
2345
Danil Chapovalov431abd92018-06-18 12:54:17 +02002346 absl::optional<int64_t> last_rtcp_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002347 if (direction == kIncomingPacket) {
2348 for (const auto& rtcp : parsed_log_.incoming_rtcp_packets()) {
2349 if (rtcp.log_time_us() > end_time_us) {
2350 // Only process the first (LOG_START, LOG_END) segment.
2351 break;
2352 }
2353 int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0);
2354 if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) {
2355 // No feedback sent/received for more than 2000 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002356 Alert_RtcpLogTimeGap(direction,
2357 config_.GetCallTimeSec(rtcp.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002358 duration / 1000);
2359 }
2360 last_rtcp_time.emplace(rtcp.log_time_us());
2361 }
2362 } else {
2363 for (const auto& rtcp : parsed_log_.outgoing_rtcp_packets()) {
2364 if (rtcp.log_time_us() > end_time_us) {
2365 // Only process the first (LOG_START, LOG_END) segment.
2366 break;
2367 }
2368 int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0);
2369 if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) {
2370 // No feedback sent/received for more than 2000 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002371 Alert_RtcpLogTimeGap(direction,
2372 config_.GetCallTimeSec(rtcp.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002373 duration / 1000);
2374 }
2375 last_rtcp_time.emplace(rtcp.log_time_us());
2376 }
2377 }
2378}
2379
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002380// TODO(terelius): Notifications could possibly be generated by the same code
2381// that produces the graphs. There is some code duplication that could be
2382// avoided, but that might be solved anyway when we move functionality from the
2383// analyzer to the parser.
2384void EventLogAnalyzer::CreateTriageNotifications() {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002385 CreateStreamGapAlerts(kIncomingPacket);
2386 CreateStreamGapAlerts(kOutgoingPacket);
2387 CreateTransmissionGapAlerts(kIncomingPacket);
2388 CreateTransmissionGapAlerts(kOutgoingPacket);
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002389
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002390 int64_t end_time_us = log_segments_.empty()
2391 ? std::numeric_limits<int64_t>::max()
2392 : log_segments_.front().second;
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002393
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002394 constexpr double kMaxLossFraction = 0.05;
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002395 // Loss feedback
2396 int64_t total_lost_packets = 0;
2397 int64_t total_expected_packets = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002398 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
2399 if (bwe_update.log_time_us() > end_time_us) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002400 // Only process the first (LOG_START, LOG_END) segment.
2401 break;
2402 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002403 int64_t lost_packets = static_cast<double>(bwe_update.fraction_lost) / 255 *
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002404 bwe_update.expected_packets;
2405 total_lost_packets += lost_packets;
2406 total_expected_packets += bwe_update.expected_packets;
2407 }
2408 double avg_outgoing_loss =
2409 static_cast<double>(total_lost_packets) / total_expected_packets;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002410 if (avg_outgoing_loss > kMaxLossFraction) {
2411 Alert_OutgoingHighLoss(avg_outgoing_loss);
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002412 }
2413}
2414
terelius54ce6802016-07-13 06:44:41 -07002415} // namespace webrtc