blob: 1b52c308a2cb794d927f61a97bbd3737964d164f [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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_tools/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"
Sebastian Jansson95edb032019-01-17 16:24:12 +010022#include "api/transport/field_trial_based_config.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020023#include "api/transport/goog_cc_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "call/audio_receive_stream.h"
25#include "call/audio_send_stream.h"
26#include "call/call.h"
27#include "call/video_receive_stream.h"
28#include "call/video_send_stream.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020029#include "common_types.h" // NOLINT(build/include)
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"
Niels Möllerfd6c0912017-10-31 10:19:10 +010043#include "modules/pacing/packet_router.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020044#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020045#include "modules/rtp_rtcp/include/rtp_rtcp.h"
46#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020047#include "modules/rtp_rtcp/source/rtcp_packet.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
49#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
50#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
51#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
52#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
53#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
54#include "modules/rtp_rtcp/source/rtp_utility.h"
55#include "rtc_base/checks.h"
56#include "rtc_base/format_macros.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020057#include "rtc_base/function_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020058#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"
terelius54ce6802016-07-13 06:44:41 -070062
Bjorn Terelius6984ad22017-10-24 12:19:45 +020063#ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
64#define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0
65#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
66
tereliusdc35dcd2016-08-01 12:03:27 -070067namespace webrtc {
tereliusdc35dcd2016-08-01 12:03:27 -070068
terelius54ce6802016-07-13 06:44:41 -070069namespace {
70
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080071const int kNumMicrosecsPerSec = 1000000;
72
elad.alonec304f92017-03-08 05:03:53 -080073void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
74 auto pred = [](const PacketFeedback& packet_feedback) {
75 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
76 };
77 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
78 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
79}
80
terelius54ce6802016-07-13 06:44:41 -070081std::string SsrcToString(uint32_t ssrc) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020082 rtc::StringBuilder ss;
terelius54ce6802016-07-13 06:44:41 -070083 ss << "SSRC " << ssrc;
Jonas Olsson84df1c72018-09-14 16:59:32 +020084 return ss.Release();
terelius54ce6802016-07-13 06:44:41 -070085}
86
87// Checks whether an SSRC is contained in the list of desired SSRCs.
88// Note that an empty SSRC list matches every SSRC.
89bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
90 if (desired_ssrc.size() == 0)
91 return true;
92 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
93 desired_ssrc.end();
94}
95
96double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
97 // The timestamp is a fixed point representation with 6 bits for seconds
98 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080099 // time in seconds and then multiply by kNumMicrosecsPerSec to convert to
100 // microseconds.
terelius54ce6802016-07-13 06:44:41 -0700101 static constexpr double kTimestampToMicroSec =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800102 static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -0700103 return abs_send_time * kTimestampToMicroSec;
104}
105
106// Computes the difference |later| - |earlier| where |later| and |earlier|
107// are counters that wrap at |modulus|. The difference is chosen to have the
108// least absolute value. For example if |modulus| is 8, then the difference will
109// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
110// be in [-4, 4].
111int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
112 RTC_DCHECK_LE(1, modulus);
113 RTC_DCHECK_LT(later, modulus);
114 RTC_DCHECK_LT(earlier, modulus);
115 int64_t difference =
116 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
117 int64_t max_difference = modulus / 2;
118 int64_t min_difference = max_difference - modulus + 1;
119 if (difference > max_difference) {
120 difference -= modulus;
121 }
122 if (difference < min_difference) {
123 difference += modulus;
124 }
terelius6addf492016-08-23 17:34:07 -0700125 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100126 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
127 << " expected to be in the range ("
128 << min_difference / 2 << "," << max_difference / 2
129 << ") but is " << difference
130 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700131 }
terelius54ce6802016-07-13 06:44:41 -0700132 return difference;
133}
134
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200135// This is much more reliable for outgoing streams than for incoming streams.
136template <typename RtpPacketContainer>
Danil Chapovalov431abd92018-06-18 12:54:17 +0200137absl::optional<uint32_t> EstimateRtpClockFrequency(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200138 const RtpPacketContainer& packets,
139 int64_t end_time_us) {
140 RTC_CHECK(packets.size() >= 2);
141 SeqNumUnwrapper<uint32_t> unwrapper;
142 uint64_t first_rtp_timestamp =
143 unwrapper.Unwrap(packets[0].rtp.header.timestamp);
144 int64_t first_log_timestamp = packets[0].log_time_us();
145 uint64_t last_rtp_timestamp = first_rtp_timestamp;
146 int64_t last_log_timestamp = first_log_timestamp;
147 for (size_t i = 1; i < packets.size(); i++) {
148 if (packets[i].log_time_us() > end_time_us)
149 break;
150 last_rtp_timestamp = unwrapper.Unwrap(packets[i].rtp.header.timestamp);
151 last_log_timestamp = packets[i].log_time_us();
152 }
153 if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) {
154 RTC_LOG(LS_WARNING)
155 << "Failed to estimate RTP clock frequency: Stream too short. ("
156 << packets.size() << " packets, "
157 << last_log_timestamp - first_log_timestamp << " us)";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200158 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200159 }
160 double duration =
161 static_cast<double>(last_log_timestamp - first_log_timestamp) /
162 kNumMicrosecsPerSec;
163 double estimated_frequency =
164 (last_rtp_timestamp - first_rtp_timestamp) / duration;
165 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
166 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
167 return f;
168 }
169 }
170 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
171 << estimated_frequency
172 << "not close to any stardard RTP frequency.";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200173 return absl::nullopt;
ivocaac9d6f2016-09-22 07:01:47 -0700174}
175
tereliusdc35dcd2016-08-01 12:03:27 -0700176constexpr float kLeftMargin = 0.01f;
177constexpr float kRightMargin = 0.02f;
178constexpr float kBottomMargin = 0.02f;
179constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700180
Danil Chapovalov431abd92018-06-18 12:54:17 +0200181absl::optional<double> NetworkDelayDiff_AbsSendTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100182 const LoggedRtpPacketIncoming& old_packet,
183 const LoggedRtpPacketIncoming& new_packet) {
184 if (old_packet.rtp.header.extension.hasAbsoluteSendTime &&
185 new_packet.rtp.header.extension.hasAbsoluteSendTime) {
terelius53dc23c2017-03-13 05:24:05 -0700186 int64_t send_time_diff = WrappingDifference(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100187 new_packet.rtp.header.extension.absoluteSendTime,
188 old_packet.rtp.header.extension.absoluteSendTime, 1ul << 24);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200189 int64_t recv_time_diff =
190 new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700191 double delay_change_us =
192 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100193 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700194 } else {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200195 return absl::nullopt;
terelius6addf492016-08-23 17:34:07 -0700196 }
197}
198
Danil Chapovalov431abd92018-06-18 12:54:17 +0200199absl::optional<double> NetworkDelayDiff_CaptureTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100200 const LoggedRtpPacketIncoming& old_packet,
201 const LoggedRtpPacketIncoming& new_packet,
202 const double sample_rate) {
203 int64_t send_time_diff =
204 WrappingDifference(new_packet.rtp.header.timestamp,
205 old_packet.rtp.header.timestamp, 1ull << 32);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200206 int64_t recv_time_diff = new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700207
terelius53dc23c2017-03-13 05:24:05 -0700208 double delay_change =
209 static_cast<double>(recv_time_diff) / 1000 -
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100210 static_cast<double>(send_time_diff) / sample_rate * 1000;
terelius53dc23c2017-03-13 05:24:05 -0700211 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100212 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100213 RTC_LOG(LS_WARNING) << "Old capture time "
214 << old_packet.rtp.header.timestamp << ", received time "
215 << old_packet.log_time_us();
216 RTC_LOG(LS_WARNING) << "New capture time "
217 << new_packet.rtp.header.timestamp << ", received time "
218 << new_packet.log_time_us();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100219 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800220 << static_cast<double>(recv_time_diff) /
221 kNumMicrosecsPerSec
222 << "s";
Mirko Bonadei675513b2017-11-09 11:09:25 +0100223 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100224 << static_cast<double>(send_time_diff) / sample_rate
Mirko Bonadei675513b2017-11-09 11:09:25 +0100225 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700226 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100227 return delay_change;
terelius53dc23c2017-03-13 05:24:05 -0700228}
229
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200230// For each element in data_view, use |f()| to extract a y-coordinate and
terelius53dc23c2017-03-13 05:24:05 -0700231// store the result in a TimeSeries.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200232template <typename DataType, typename IterableType>
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200233void ProcessPoints(rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200234 rtc::FunctionView<absl::optional<float>(const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200235 const IterableType& data_view,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200236 TimeSeries* result) {
237 for (size_t i = 0; i < data_view.size(); i++) {
238 const DataType& elem = data_view[i];
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200239 float x = fx(elem);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200240 absl::optional<float> y = fy(elem);
terelius53dc23c2017-03-13 05:24:05 -0700241 if (y)
242 result->points.emplace_back(x, *y);
243 }
244}
245
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200246// For each pair of adjacent elements in |data|, use |f()| to extract a
terelius6addf492016-08-23 17:34:07 -0700247// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
248// will be the time of the second element in the pair.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200249template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700250void ProcessPairs(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200251 rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200252 rtc::FunctionView<absl::optional<ResultType>(const DataType&,
253 const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200254 const IterableType& data,
terelius53dc23c2017-03-13 05:24:05 -0700255 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700256 for (size_t i = 1; i < data.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200257 float x = fx(data[i]);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200258 absl::optional<ResultType> y = fy(data[i - 1], data[i]);
terelius53dc23c2017-03-13 05:24:05 -0700259 if (y)
260 result->points.emplace_back(x, static_cast<float>(*y));
261 }
262}
263
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200264// For each pair of adjacent elements in |data|, use |f()| to extract a
terelius53dc23c2017-03-13 05:24:05 -0700265// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
266// will be the time of the second element in the pair.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200267template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700268void AccumulatePairs(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200269 rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200270 rtc::FunctionView<absl::optional<ResultType>(const DataType&,
271 const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200272 const IterableType& data,
terelius53dc23c2017-03-13 05:24:05 -0700273 TimeSeries* result) {
274 ResultType sum = 0;
275 for (size_t i = 1; i < data.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200276 float x = fx(data[i]);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200277 absl::optional<ResultType> y = fy(data[i - 1], data[i]);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100278 if (y) {
terelius53dc23c2017-03-13 05:24:05 -0700279 sum += *y;
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100280 result->points.emplace_back(x, static_cast<float>(sum));
281 }
tereliusccbbf8d2016-08-10 07:34:28 -0700282 }
283}
284
terelius6addf492016-08-23 17:34:07 -0700285// Calculates a moving average of |data| and stores the result in a TimeSeries.
286// A data point is generated every |step| microseconds from |begin_time|
287// to |end_time|. The value of each data point is the average of the data
288// during the preceeding |window_duration_us| microseconds.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200289template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700290void MovingAverage(
Danil Chapovalov431abd92018-06-18 12:54:17 +0200291 rtc::FunctionView<absl::optional<ResultType>(const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200292 const IterableType& data_view,
Bjorn Terelius068fc352019-02-13 22:38:25 +0100293 AnalyzerConfig config,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200294 TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700295 size_t window_index_begin = 0;
296 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700297 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700298
Bjorn Terelius068fc352019-02-13 22:38:25 +0100299 for (int64_t t = config.begin_time_; t < config.end_time_ + config.step_;
300 t += config.step_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200301 while (window_index_end < data_view.size() &&
302 data_view[window_index_end].log_time_us() < t) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200303 absl::optional<ResultType> value = fy(data_view[window_index_end]);
terelius53dc23c2017-03-13 05:24:05 -0700304 if (value)
305 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700306 ++window_index_end;
307 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200308 while (window_index_begin < data_view.size() &&
309 data_view[window_index_begin].log_time_us() <
Bjorn Terelius068fc352019-02-13 22:38:25 +0100310 t - config.window_duration_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200311 absl::optional<ResultType> value = fy(data_view[window_index_begin]);
terelius53dc23c2017-03-13 05:24:05 -0700312 if (value)
313 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700314 ++window_index_begin;
315 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800316 float window_duration_s =
Bjorn Terelius068fc352019-02-13 22:38:25 +0100317 static_cast<float>(config.window_duration_) / kNumMicrosecsPerSec;
318 float x = config.GetCallTimeSec(t);
terelius53dc23c2017-03-13 05:24:05 -0700319 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700320 result->points.emplace_back(x, y);
321 }
322}
323
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100324template <typename T>
325TimeSeries CreateRtcpTypeTimeSeries(const std::vector<T>& rtcp_list,
326 AnalyzerConfig config,
327 std::string rtcp_name,
328 int category_id) {
329 TimeSeries time_series(rtcp_name, LineStyle::kNone, PointStyle::kHighlight);
330 for (const auto& rtcp : rtcp_list) {
331 float x = config.GetCallTimeSec(rtcp.log_time_us());
332 float y = category_id;
333 time_series.points.emplace_back(x, y);
334 }
335 return time_series;
336}
337
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800338const char kUnknownEnumValue[] = "unknown";
339
340const char kIceCandidateTypeLocal[] = "local";
341const char kIceCandidateTypeStun[] = "stun";
342const char kIceCandidateTypePrflx[] = "prflx";
343const char kIceCandidateTypeRelay[] = "relay";
344
345const char kProtocolUdp[] = "udp";
346const char kProtocolTcp[] = "tcp";
347const char kProtocolSsltcp[] = "ssltcp";
348const char kProtocolTls[] = "tls";
349
350const char kAddressFamilyIpv4[] = "ipv4";
351const char kAddressFamilyIpv6[] = "ipv6";
352
353const char kNetworkTypeEthernet[] = "ethernet";
354const char kNetworkTypeLoopback[] = "loopback";
355const char kNetworkTypeWifi[] = "wifi";
356const char kNetworkTypeVpn[] = "vpn";
357const char kNetworkTypeCellular[] = "cellular";
358
359std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) {
360 switch (type) {
361 case webrtc::IceCandidateType::kLocal:
362 return kIceCandidateTypeLocal;
363 case webrtc::IceCandidateType::kStun:
364 return kIceCandidateTypeStun;
365 case webrtc::IceCandidateType::kPrflx:
366 return kIceCandidateTypePrflx;
367 case webrtc::IceCandidateType::kRelay:
368 return kIceCandidateTypeRelay;
369 default:
370 return kUnknownEnumValue;
371 }
372}
373
374std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) {
375 switch (protocol) {
376 case webrtc::IceCandidatePairProtocol::kUdp:
377 return kProtocolUdp;
378 case webrtc::IceCandidatePairProtocol::kTcp:
379 return kProtocolTcp;
380 case webrtc::IceCandidatePairProtocol::kSsltcp:
381 return kProtocolSsltcp;
382 case webrtc::IceCandidatePairProtocol::kTls:
383 return kProtocolTls;
384 default:
385 return kUnknownEnumValue;
386 }
387}
388
389std::string GetAddressFamilyAsString(
390 webrtc::IceCandidatePairAddressFamily family) {
391 switch (family) {
392 case webrtc::IceCandidatePairAddressFamily::kIpv4:
393 return kAddressFamilyIpv4;
394 case webrtc::IceCandidatePairAddressFamily::kIpv6:
395 return kAddressFamilyIpv6;
396 default:
397 return kUnknownEnumValue;
398 }
399}
400
401std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) {
402 switch (type) {
403 case webrtc::IceCandidateNetworkType::kEthernet:
404 return kNetworkTypeEthernet;
405 case webrtc::IceCandidateNetworkType::kLoopback:
406 return kNetworkTypeLoopback;
407 case webrtc::IceCandidateNetworkType::kWifi:
408 return kNetworkTypeWifi;
409 case webrtc::IceCandidateNetworkType::kVpn:
410 return kNetworkTypeVpn;
411 case webrtc::IceCandidateNetworkType::kCellular:
412 return kNetworkTypeCellular;
413 default:
414 return kUnknownEnumValue;
415 }
416}
417
418std::string GetCandidatePairLogDescriptionAsString(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200419 const LoggedIceCandidatePairConfig& config) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800420 // Example: stun:wifi->relay(tcp):cellular@udp:ipv4
421 // represents a pair of a local server-reflexive candidate on a WiFi network
422 // and a remote relay candidate using TCP as the relay protocol on a cell
423 // network, when the candidate pair communicates over UDP using IPv4.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200424 rtc::StringBuilder ss;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800425 std::string local_candidate_type =
426 GetIceCandidateTypeAsString(config.local_candidate_type);
427 std::string remote_candidate_type =
428 GetIceCandidateTypeAsString(config.remote_candidate_type);
429 if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) {
430 local_candidate_type +=
431 "(" + GetProtocolAsString(config.local_relay_protocol) + ")";
432 }
433 ss << local_candidate_type << ":"
434 << GetNetworkTypeAsString(config.local_network_type) << ":"
435 << GetAddressFamilyAsString(config.local_address_family) << "->"
436 << remote_candidate_type << ":"
437 << GetAddressFamilyAsString(config.remote_address_family) << "@"
438 << GetProtocolAsString(config.candidate_pair_protocol);
Jonas Olsson84df1c72018-09-14 16:59:32 +0200439 return ss.Release();
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800440}
441
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200442std::string GetDirectionAsString(PacketDirection direction) {
443 if (direction == kIncomingPacket) {
444 return "Incoming";
445 } else {
446 return "Outgoing";
447 }
448}
449
450std::string GetDirectionAsShortString(PacketDirection direction) {
451 if (direction == kIncomingPacket) {
452 return "In";
453 } else {
454 return "Out";
455 }
456}
457
terelius54ce6802016-07-13 06:44:41 -0700458} // namespace
459
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100460EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200461 bool normalize_time)
Bjorn Terelius068fc352019-02-13 22:38:25 +0100462 : parsed_log_(log) {
463 config_.window_duration_ = 250000;
464 config_.step_ = 10000;
465 config_.normalize_time_ = normalize_time;
466 config_.begin_time_ = parsed_log_.first_timestamp();
467 config_.end_time_ = parsed_log_.last_timestamp();
468 if (config_.end_time_ < config_.begin_time_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200469 RTC_LOG(LS_WARNING) << "No useful events in the log.";
Bjorn Terelius068fc352019-02-13 22:38:25 +0100470 config_.begin_time_ = config_.end_time_ = 0;
Björn Tereliusff612732018-04-25 14:23:01 +0000471 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200472
473 const auto& log_start_events = parsed_log_.start_log_events();
474 const auto& log_end_events = parsed_log_.stop_log_events();
475 auto start_iter = log_start_events.begin();
476 auto end_iter = log_end_events.begin();
477 while (start_iter != log_start_events.end()) {
478 int64_t start = start_iter->log_time_us();
479 ++start_iter;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200480 absl::optional<int64_t> next_start;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200481 if (start_iter != log_start_events.end())
482 next_start.emplace(start_iter->log_time_us());
483 if (end_iter != log_end_events.end() &&
484 end_iter->log_time_us() <=
485 next_start.value_or(std::numeric_limits<int64_t>::max())) {
486 int64_t end = end_iter->log_time_us();
487 RTC_DCHECK_LE(start, end);
488 log_segments_.push_back(std::make_pair(start, end));
489 ++end_iter;
490 } else {
491 // we're missing an end event. Assume that it occurred just before the
492 // next start.
493 log_segments_.push_back(
Bjorn Terelius068fc352019-02-13 22:38:25 +0100494 std::make_pair(start, next_start.value_or(config_.end_time_)));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200495 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700496 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100497 RTC_LOG(LS_INFO) << "Found " << log_segments_.size()
Yves Gerey665174f2018-06-19 15:03:05 +0200498 << " (LOG_START, LOG_END) segments in log.";
terelius54ce6802016-07-13 06:44:41 -0700499}
500
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200501class BitrateObserver : public RemoteBitrateObserver {
Stefan Holmer13181032016-07-29 14:48:54 +0200502 public:
503 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
504
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200505 void Update(NetworkControlUpdate update) {
506 if (update.target_rate) {
507 last_bitrate_bps_ = update.target_rate->target_rate.bps();
508 bitrate_updated_ = true;
509 }
Stefan Holmer13181032016-07-29 14:48:54 +0200510 }
511
512 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
513 uint32_t bitrate) override {}
514
515 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
516 bool GetAndResetBitrateUpdated() {
517 bool bitrate_updated = bitrate_updated_;
518 bitrate_updated_ = false;
519 return bitrate_updated;
520 }
521
522 private:
523 uint32_t last_bitrate_bps_;
524 bool bitrate_updated_;
525};
526
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200527void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction,
terelius54ce6802016-07-13 06:44:41 -0700528 Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200529 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
530 // Filter on SSRC.
531 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700532 continue;
terelius54ce6802016-07-13 06:44:41 -0700533 }
terelius54ce6802016-07-13 06:44:41 -0700534
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200535 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
536 LineStyle::kBar);
537 auto GetPacketSize = [](const LoggedRtpPacket& packet) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200538 return absl::optional<float>(packet.total_length);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200539 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200540 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100541 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200542 };
543 ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize,
544 stream.packet_view, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700545 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700546 }
547
Bjorn Terelius068fc352019-02-13 22:38:25 +0100548 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
549 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700550 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
551 kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200552 plot->SetTitle(GetDirectionAsString(direction) + " RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700553}
554
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100555void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction,
556 Plot* plot) {
557 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
558 parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1));
559 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
560 parsed_log_.receiver_reports(direction), config_, "RR", 2));
561 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
562 parsed_log_.sender_reports(direction), config_, "SR", 3));
563 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
564 parsed_log_.extended_reports(direction), config_, "XR", 4));
565 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction),
566 config_, "NACK", 5));
567 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction),
568 config_, "REMB", 6));
569 plot->AppendTimeSeries(
570 CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7));
571 plot->AppendTimeSeries(
572 CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8));
573 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
574 "Time (s)", kLeftMargin, kRightMargin);
575 plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin);
576 plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets");
577}
578
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200579template <typename IterableType>
philipelccd74892016-09-05 02:46:25 -0700580void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
philipelccd74892016-09-05 02:46:25 -0700581 Plot* plot,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200582 const IterableType& packets,
583 const std::string& label) {
584 TimeSeries time_series(label, LineStyle::kStep);
585 for (size_t i = 0; i < packets.size(); i++) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100586 float x = config_.GetCallTimeSec(packets[i].log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200587 time_series.points.emplace_back(x, i + 1);
philipelccd74892016-09-05 02:46:25 -0700588 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200589 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700590}
591
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200592void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction,
593 Plot* plot) {
594 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
595 if (!MatchingSsrc(stream.ssrc, desired_ssrc_))
596 continue;
597 std::string label =
598 std::string("RTP ") + GetStreamName(direction, stream.ssrc);
599 CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label);
600 }
601 std::string label =
602 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")";
603 if (direction == kIncomingPacket) {
604 CreateAccumulatedPacketsTimeSeries(
605 plot, parsed_log_.incoming_rtcp_packets(), label);
606 } else {
607 CreateAccumulatedPacketsTimeSeries(
608 plot, parsed_log_.outgoing_rtcp_packets(), label);
609 }
philipelccd74892016-09-05 02:46:25 -0700610
Bjorn Terelius068fc352019-02-13 22:38:25 +0100611 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
612 "Time (s)", kLeftMargin, kRightMargin);
philipelccd74892016-09-05 02:46:25 -0700613 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200614 plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) +
615 " RTP/RTCP packets");
philipelccd74892016-09-05 02:46:25 -0700616}
617
terelius54ce6802016-07-13 06:44:41 -0700618// For each SSRC, plot the time between the consecutive playouts.
619void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200620 for (const auto& playout_stream : parsed_log_.audio_playout_events()) {
621 uint32_t ssrc = playout_stream.first;
622 if (!MatchingSsrc(ssrc, desired_ssrc_))
623 continue;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200624 absl::optional<int64_t> last_playout_ms;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200625 TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar);
Minyue Li27e2b7d2018-05-07 15:20:24 +0200626 for (const auto& playout_event : playout_stream.second) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100627 float x = config_.GetCallTimeSec(playout_event.log_time_us());
Minyue Li27e2b7d2018-05-07 15:20:24 +0200628 int64_t playout_time_ms = playout_event.log_time_ms();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200629 // If there were no previous playouts, place the point on the x-axis.
Minyue Li27e2b7d2018-05-07 15:20:24 +0200630 float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200631 time_series.points.push_back(TimeSeriesPoint(x, y));
Minyue Li27e2b7d2018-05-07 15:20:24 +0200632 last_playout_ms.emplace(playout_time_ms);
terelius54ce6802016-07-13 06:44:41 -0700633 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200634 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700635 }
636
Bjorn Terelius068fc352019-02-13 22:38:25 +0100637 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
638 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700639 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
640 kTopMargin);
641 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700642}
643
ivocaac9d6f2016-09-22 07:01:47 -0700644// For audio SSRCs, plot the audio level.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200645void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction,
646 Plot* plot) {
647 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
648 if (!IsAudioSsrc(direction, stream.ssrc))
649 continue;
650 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
651 LineStyle::kLine);
652 for (auto& packet : stream.packet_view) {
ivocaac9d6f2016-09-22 07:01:47 -0700653 if (packet.header.extension.hasAudioLevel) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100654 float x = config_.GetCallTimeSec(packet.log_time_us());
ivocaac9d6f2016-09-22 07:01:47 -0700655 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
656 // Here we convert it to dBov.
657 float y = static_cast<float>(-packet.header.extension.audioLevel);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200658 time_series.points.emplace_back(TimeSeriesPoint(x, y));
ivocaac9d6f2016-09-22 07:01:47 -0700659 }
660 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200661 plot->AppendTimeSeries(std::move(time_series));
ivocaac9d6f2016-09-22 07:01:47 -0700662 }
663
Bjorn Terelius068fc352019-02-13 22:38:25 +0100664 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
665 "Time (s)", kLeftMargin, kRightMargin);
Yves Gerey665174f2018-06-19 15:03:05 +0200666 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200667 plot->SetTitle(GetDirectionAsString(direction) + " audio level");
ivocaac9d6f2016-09-22 07:01:47 -0700668}
669
terelius54ce6802016-07-13 06:44:41 -0700670// For each SSRC, plot the time between the consecutive playouts.
671void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200672 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
673 // Filter on SSRC.
674 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700675 continue;
terelius54ce6802016-07-13 06:44:41 -0700676 }
terelius54ce6802016-07-13 06:44:41 -0700677
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200678 TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc),
679 LineStyle::kBar);
680 auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet,
681 const LoggedRtpPacketIncoming& new_packet) {
682 int64_t diff =
683 WrappingDifference(new_packet.rtp.header.sequenceNumber,
684 old_packet.rtp.header.sequenceNumber, 1ul << 16);
685 return diff;
686 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200687 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100688 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200689 };
690 ProcessPairs<LoggedRtpPacketIncoming, float>(
691 ToCallTime, GetSequenceNumberDiff, stream.incoming_packets,
692 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700693 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700694 }
695
Bjorn Terelius068fc352019-02-13 22:38:25 +0100696 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
697 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700698 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
699 kTopMargin);
700 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700701}
702
Stefan Holmer99f8e082016-09-09 13:37:50 +0200703void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200704 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
705 const std::vector<LoggedRtpPacketIncoming>& packets =
706 stream.incoming_packets;
707 // Filter on SSRC.
708 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200709 continue;
710 }
711
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200712 TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc),
713 LineStyle::kLine, PointStyle::kHighlight);
714 // TODO(terelius): Should the window and step size be read from the class
715 // instead?
716 const int64_t kWindowUs = 1000000;
717 const int64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100718 SeqNumUnwrapper<uint16_t> unwrapper_;
719 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800720 size_t window_index_begin = 0;
721 size_t window_index_end = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200722 uint64_t highest_seq_number =
723 unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
724 uint64_t highest_prior_seq_number =
725 prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
terelius4c9b4af2017-01-30 08:44:51 -0800726
Bjorn Terelius068fc352019-02-13 22:38:25 +0100727 for (int64_t t = config_.begin_time_; t < config_.end_time_ + kStep;
728 t += kStep) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200729 while (window_index_end < packets.size() &&
730 packets[window_index_end].rtp.log_time_us() < t) {
731 uint64_t sequence_number = unwrapper_.Unwrap(
732 packets[window_index_end].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800733 highest_seq_number = std::max(highest_seq_number, sequence_number);
734 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200735 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200736 while (window_index_begin < packets.size() &&
737 packets[window_index_begin].rtp.log_time_us() < t - kWindowUs) {
738 uint64_t sequence_number = prior_unwrapper_.Unwrap(
739 packets[window_index_begin].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800740 highest_prior_seq_number =
741 std::max(highest_prior_seq_number, sequence_number);
742 ++window_index_begin;
743 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100744 float x = config_.GetCallTimeSec(t);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200745 uint64_t expected_packets = highest_seq_number - highest_prior_seq_number;
terelius4c9b4af2017-01-30 08:44:51 -0800746 if (expected_packets > 0) {
747 int64_t received_packets = window_index_end - window_index_begin;
748 int64_t lost_packets = expected_packets - received_packets;
749 float y = static_cast<float>(lost_packets) / expected_packets * 100;
750 time_series.points.emplace_back(x, y);
751 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200752 }
philipel35ba9bd2017-04-19 05:58:51 -0700753 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200754 }
755
Bjorn Terelius068fc352019-02-13 22:38:25 +0100756 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
757 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100758 plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin);
759 plot->SetTitle("Incoming packet loss (derived from incoming packets)");
Stefan Holmer99f8e082016-09-09 13:37:50 +0200760}
761
terelius2ee076d2017-08-15 02:04:02 -0700762void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100763 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200764 // Filter on SSRC.
765 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200766 IsRtxSsrc(kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700767 continue;
768 }
terelius54ce6802016-07-13 06:44:41 -0700769
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100770 const std::vector<LoggedRtpPacketIncoming>& packets =
771 stream.incoming_packets;
772 if (packets.size() < 100) {
773 RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with "
774 << packets.size() << " packets in the stream.";
775 continue;
776 }
777 int64_t end_time_us = log_segments_.empty()
778 ? std::numeric_limits<int64_t>::max()
779 : log_segments_.front().second;
780 absl::optional<uint32_t> estimated_frequency =
781 EstimateRtpClockFrequency(packets, end_time_us);
782 if (!estimated_frequency)
783 continue;
784 const double frequency_hz = *estimated_frequency;
785 if (IsVideoSsrc(kIncomingPacket, stream.ssrc) && frequency_hz != 90000) {
786 RTC_LOG(LS_WARNING)
787 << "Video stream should use a 90 kHz clock but appears to use "
788 << frequency_hz / 1000 << ". Discarding.";
789 continue;
790 }
791
792 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100793 return this->config_.GetCallTimeSec(packet.log_time_us());
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100794 };
795 auto ToNetworkDelay = [frequency_hz](
796 const LoggedRtpPacketIncoming& old_packet,
797 const LoggedRtpPacketIncoming& new_packet) {
798 return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz);
799 };
800
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200801 TimeSeries capture_time_data(
802 GetStreamName(kIncomingPacket, stream.ssrc) + " capture-time",
803 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100804 AccumulatePairs<LoggedRtpPacketIncoming, double>(
805 ToCallTime, ToNetworkDelay, packets, &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700806 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700807
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200808 TimeSeries send_time_data(
809 GetStreamName(kIncomingPacket, stream.ssrc) + " abs-send-time",
810 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100811 AccumulatePairs<LoggedRtpPacketIncoming, double>(
812 ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data);
813 plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700814 }
815
Bjorn Terelius068fc352019-02-13 22:38:25 +0100816 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
817 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +0100818 plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin);
819 plot->SetTitle("Incoming network delay (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700820}
821
tereliusf736d232016-08-04 10:00:11 -0700822// Plot the fraction of packets lost (as perceived by the loss-based BWE).
823void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100824 TimeSeries time_series("Fraction lost", LineStyle::kLine,
825 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200826 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100827 float x = config_.GetCallTimeSec(bwe_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200828 float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700829 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700830 }
tereliusf736d232016-08-04 10:00:11 -0700831
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200832 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +0100833 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
834 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100835 plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin);
836 plot->SetTitle("Outgoing packet loss (as reported by BWE)");
tereliusf736d232016-08-04 10:00:11 -0700837}
838
terelius54ce6802016-07-13 06:44:41 -0700839// Plot the total bandwidth used by all RTP streams.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200840void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) {
841 // TODO(terelius): This could be provided by the parser.
842 std::multimap<int64_t, size_t> packets_in_order;
843 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
844 for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets)
845 packets_in_order.insert(
846 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
terelius54ce6802016-07-13 06:44:41 -0700847 }
848
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200849 auto window_begin = packets_in_order.begin();
850 auto window_end = packets_in_order.begin();
terelius54ce6802016-07-13 06:44:41 -0700851 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700852
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800853 if (!packets_in_order.empty()) {
854 // Calculate a moving average of the bitrate and store in a TimeSeries.
855 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
856 for (int64_t time = config_.begin_time_;
857 time < config_.end_time_ + config_.step_; time += config_.step_) {
858 while (window_end != packets_in_order.end() && window_end->first < time) {
859 bytes_in_window += window_end->second;
860 ++window_end;
861 }
862 while (window_begin != packets_in_order.end() &&
863 window_begin->first < time - config_.window_duration_) {
864 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
865 bytes_in_window -= window_begin->second;
866 ++window_begin;
867 }
868 float window_duration_in_seconds =
869 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
870 float x = config_.GetCallTimeSec(time);
871 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
872 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700873 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800874 plot->AppendTimeSeries(std::move(bitrate_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200875 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200876
877 // Overlay the outgoing REMB over incoming bitrate.
878 TimeSeries remb_series("Remb", LineStyle::kStep);
879 for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100880 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200881 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
882 remb_series.points.emplace_back(x, y);
883 }
884 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
885
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800886 if (!parsed_log_.generic_packets_received().empty()) {
887 TimeSeries time_series("Incoming generic bitrate", LineStyle::kLine);
888 auto GetPacketSizeKilobits = [](const LoggedGenericPacketReceived& packet) {
889 return packet.packet_length * 8.0 / 1000.0;
890 };
891 MovingAverage<LoggedGenericPacketReceived, double>(
892 GetPacketSizeKilobits, parsed_log_.generic_packets_received(), config_,
893 &time_series);
894 plot->AppendTimeSeries(std::move(time_series));
895 }
896
Bjorn Terelius068fc352019-02-13 22:38:25 +0100897 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
898 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200899 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
900 plot->SetTitle("Incoming RTP bitrate");
901}
902
903// Plot the total bandwidth used by all RTP streams.
904void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
905 bool show_detector_state,
906 bool show_alr_state) {
907 // TODO(terelius): This could be provided by the parser.
908 std::multimap<int64_t, size_t> packets_in_order;
909 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
910 for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets)
911 packets_in_order.insert(
912 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
913 }
914
915 auto window_begin = packets_in_order.begin();
916 auto window_end = packets_in_order.begin();
917 size_t bytes_in_window = 0;
918
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800919 if (!packets_in_order.empty()) {
920 // Calculate a moving average of the bitrate and store in a TimeSeries.
921 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
922 for (int64_t time = config_.begin_time_;
923 time < config_.end_time_ + config_.step_; time += config_.step_) {
924 while (window_end != packets_in_order.end() && window_end->first < time) {
925 bytes_in_window += window_end->second;
926 ++window_end;
927 }
928 while (window_begin != packets_in_order.end() &&
929 window_begin->first < time - config_.window_duration_) {
930 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
931 bytes_in_window -= window_begin->second;
932 ++window_begin;
933 }
934 float window_duration_in_seconds =
935 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
936 float x = config_.GetCallTimeSec(time);
937 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
938 bitrate_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200939 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800940 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700941 }
942
terelius8058e582016-07-25 01:32:41 -0700943 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200944 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
945 for (auto& loss_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100946 float x = config_.GetCallTimeSec(loss_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200947 float y = static_cast<float>(loss_update.bitrate_bps) / 1000;
948 loss_series.points.emplace_back(x, y);
949 }
philipel10fc0e62017-04-11 01:50:23 -0700950
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200951 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
952 IntervalSeries overusing_series("Overusing", "#ff8e82",
953 IntervalSeries::kHorizontal);
954 IntervalSeries underusing_series("Underusing", "#5092fc",
955 IntervalSeries::kHorizontal);
956 IntervalSeries normal_series("Normal", "#c4ffc4",
957 IntervalSeries::kHorizontal);
958 IntervalSeries* last_series = &normal_series;
959 double last_detector_switch = 0.0;
philipel23c7f252017-07-14 06:30:03 -0700960
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200961 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
philipel23c7f252017-07-14 06:30:03 -0700962
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200963 for (auto& delay_update : parsed_log_.bwe_delay_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100964 float x = config_.GetCallTimeSec(delay_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200965 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -0700966
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200967 if (last_detector_state != delay_update.detector_state) {
968 last_series->intervals.emplace_back(last_detector_switch, x);
969 last_detector_state = delay_update.detector_state;
970 last_detector_switch = x;
philipel23c7f252017-07-14 06:30:03 -0700971
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200972 switch (delay_update.detector_state) {
973 case BandwidthUsage::kBwNormal:
974 last_series = &normal_series;
975 break;
976 case BandwidthUsage::kBwUnderusing:
977 last_series = &underusing_series;
978 break;
979 case BandwidthUsage::kBwOverusing:
980 last_series = &overusing_series;
981 break;
982 case BandwidthUsage::kLast:
983 RTC_NOTREACHED();
philipele127e7a2017-03-29 16:28:53 +0200984 }
985 }
philipel23c7f252017-07-14 06:30:03 -0700986
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200987 delay_series.points.emplace_back(x, y);
988 }
Bjorn Terelius9e336ec2018-04-24 16:28:35 +0200989
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200990 RTC_CHECK(last_series);
Bjorn Terelius068fc352019-02-13 22:38:25 +0100991 last_series->intervals.emplace_back(last_detector_switch, config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200992
993 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
994 PointStyle::kHighlight);
995 for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100996 float x = config_.GetCallTimeSec(cluster.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200997 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
998 created_series.points.emplace_back(x, y);
999 }
1000
1001 TimeSeries result_series("Probing results.", LineStyle::kNone,
1002 PointStyle::kHighlight);
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001003 for (auto& result : parsed_log_.bwe_probe_success_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001004 float x = config_.GetCallTimeSec(result.log_time_us());
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001005 float y = static_cast<float>(result.bitrate_bps) / 1000;
1006 result_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001007 }
1008
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001009 TimeSeries probe_failures_series("Probe failed", LineStyle::kNone,
1010 PointStyle::kHighlight);
1011 for (auto& failure : parsed_log_.bwe_probe_failure_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001012 float x = config_.GetCallTimeSec(failure.log_time_us());
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001013 probe_failures_series.points.emplace_back(x, 0);
1014 }
1015
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001016 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
1017 bool previously_in_alr = false;
1018 int64_t alr_start = 0;
1019 for (auto& alr : parsed_log_.alr_state_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001020 float y = config_.GetCallTimeSec(alr.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001021 if (!previously_in_alr && alr.in_alr) {
1022 alr_start = alr.log_time_us();
1023 previously_in_alr = true;
1024 } else if (previously_in_alr && !alr.in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001025 float x = config_.GetCallTimeSec(alr_start);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001026 alr_state.intervals.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001027 previously_in_alr = false;
Björn Tereliusff612732018-04-25 14:23:01 +00001028 }
Björn Tereliusff612732018-04-25 14:23:01 +00001029 }
1030
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001031 if (previously_in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001032 float x = config_.GetCallTimeSec(alr_start);
1033 float y = config_.GetCallTimeSec(config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001034 alr_state.intervals.emplace_back(x, y);
1035 }
1036
1037 if (show_detector_state) {
1038 plot->AppendIntervalSeries(std::move(overusing_series));
1039 plot->AppendIntervalSeries(std::move(underusing_series));
1040 plot->AppendIntervalSeries(std::move(normal_series));
1041 }
1042
1043 if (show_alr_state) {
1044 plot->AppendIntervalSeries(std::move(alr_state));
1045 }
1046 plot->AppendTimeSeries(std::move(loss_series));
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001047 plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001048 plot->AppendTimeSeries(std::move(delay_series));
1049 plot->AppendTimeSeries(std::move(created_series));
1050 plot->AppendTimeSeries(std::move(result_series));
1051
1052 // Overlay the incoming REMB over the outgoing bitrate.
Björn Tereliusff612732018-04-25 14:23:01 +00001053 TimeSeries remb_series("Remb", LineStyle::kStep);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001054 for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001055 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001056 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
terelius2c8e8a32017-06-02 01:29:48 -07001057 remb_series.points.emplace_back(x, y);
1058 }
1059 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1060
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001061 if (!parsed_log_.generic_packets_sent().empty()) {
1062 {
1063 TimeSeries time_series("Outgoing generic total bitrate",
1064 LineStyle::kLine);
1065 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1066 return packet.packet_length() * 8.0 / 1000.0;
1067 };
1068 MovingAverage<LoggedGenericPacketSent, double>(
1069 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1070 &time_series);
1071 plot->AppendTimeSeries(std::move(time_series));
1072 }
1073
1074 {
1075 TimeSeries time_series("Outgoing generic payload bitrate",
1076 LineStyle::kLine);
1077 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1078 return packet.payload_length * 8.0 / 1000.0;
1079 };
1080 MovingAverage<LoggedGenericPacketSent, double>(
1081 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1082 &time_series);
1083 plot->AppendTimeSeries(std::move(time_series));
1084 }
1085 }
1086
Bjorn Terelius068fc352019-02-13 22:38:25 +01001087 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1088 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001089 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001090 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001091}
1092
1093// For each SSRC, plot the bandwidth used by that stream.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001094void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction,
1095 Plot* plot) {
1096 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1097 // Filter on SSRC.
1098 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -07001099 continue;
terelius54ce6802016-07-13 06:44:41 -07001100 }
1101
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001102 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
1103 LineStyle::kLine);
1104 auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) {
1105 return packet.total_length * 8.0 / 1000.0;
1106 };
terelius53dc23c2017-03-13 05:24:05 -07001107 MovingAverage<LoggedRtpPacket, double>(
Bjorn Terelius068fc352019-02-13 22:38:25 +01001108 GetPacketSizeKilobits, stream.packet_view, config_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001109 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001110 }
1111
Bjorn Terelius068fc352019-02-13 22:38:25 +01001112 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1113 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001114 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001115 plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001116}
1117
Bjorn Terelius28db2662017-10-04 14:22:43 +02001118void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001119 using RtpPacketType = LoggedRtpPacketOutgoing;
1120 using TransportFeedbackType = LoggedRtcpPacketTransportFeedback;
Stefan Holmer13181032016-07-29 14:48:54 +02001121
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001122 // TODO(terelius): This could be provided by the parser.
1123 std::multimap<int64_t, const RtpPacketType*> outgoing_rtp;
1124 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1125 for (const RtpPacketType& rtp_packet : stream.outgoing_packets)
1126 outgoing_rtp.insert(
1127 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Stefan Holmer13181032016-07-29 14:48:54 +02001128 }
1129
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001130 const std::vector<TransportFeedbackType>& incoming_rtcp =
1131 parsed_log_.transport_feedbacks(kIncomingPacket);
Stefan Holmer13181032016-07-29 14:48:54 +02001132
1133 SimulatedClock clock(0);
1134 BitrateObserver observer;
1135 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001136 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001137 PacedSender pacer(&clock, &packet_router, &null_event_log);
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001138 TransportFeedbackAdapter transport_feedback;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001139 auto factory = GoogCcNetworkControllerFactory(&null_event_log);
1140 TimeDelta process_interval = factory.GetProcessInterval();
Stefan Holmer13181032016-07-29 14:48:54 +02001141 // TODO(holmer): Log the call config and use that here instead.
1142 static const uint32_t kDefaultStartBitrateBps = 300000;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001143 NetworkControllerConfig cc_config;
Sebastian Jansson78416b62018-10-18 13:08:17 +02001144 cc_config.constraints.at_time = Timestamp::us(clock.TimeInMicroseconds());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001145 cc_config.constraints.starting_rate = DataRate::bps(kDefaultStartBitrateBps);
1146 auto goog_cc = factory.Create(cc_config);
Stefan Holmer13181032016-07-29 14:48:54 +02001147
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001148 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1149 PointStyle::kHighlight);
1150 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1151 PointStyle::kHighlight);
1152 TimeSeries acked_estimate_time_series(
1153 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001154
1155 auto rtp_iterator = outgoing_rtp.begin();
1156 auto rtcp_iterator = incoming_rtcp.begin();
1157
1158 auto NextRtpTime = [&]() {
1159 if (rtp_iterator != outgoing_rtp.end())
1160 return static_cast<int64_t>(rtp_iterator->first);
1161 return std::numeric_limits<int64_t>::max();
1162 };
1163
1164 auto NextRtcpTime = [&]() {
1165 if (rtcp_iterator != incoming_rtcp.end())
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001166 return static_cast<int64_t>(rtcp_iterator->log_time_us());
Stefan Holmer13181032016-07-29 14:48:54 +02001167 return std::numeric_limits<int64_t>::max();
1168 };
Bjorn Tereliusa728c912018-12-06 12:26:30 +01001169 int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()});
Stefan Holmer13181032016-07-29 14:48:54 +02001170
1171 auto NextProcessTime = [&]() {
1172 if (rtcp_iterator != incoming_rtcp.end() ||
1173 rtp_iterator != outgoing_rtp.end()) {
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001174 return next_process_time_us_;
Stefan Holmer13181032016-07-29 14:48:54 +02001175 }
1176 return std::numeric_limits<int64_t>::max();
1177 };
1178
Stefan Holmer492ee282016-10-27 17:19:20 +02001179 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001180#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson95edb032019-01-17 16:24:12 +01001181 FieldTrialBasedConfig field_trial_config_;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001182 // The event_log_visualizer should normally not be compiled with
1183 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
1184 // However, compiling with BWE_TEST_LOGGING, runnning with --plot_sendside_bwe
1185 // and piping the output to plot_dynamics.py can be used as a hack to get the
1186 // internal state of various BWE components. In this case, it is important
1187 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
1188 // SendSideCongestionController since that would lead to duplicate outputs.
1189 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
Sebastian Jansson95edb032019-01-17 16:24:12 +01001190 &field_trial_config_,
1191 absl::make_unique<BitrateEstimator>(&field_trial_config_));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001192#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001193 int64_t time_us =
1194 std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
Stefan Holmer492ee282016-10-27 17:19:20 +02001195 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001196 while (time_us != std::numeric_limits<int64_t>::max()) {
1197 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001198 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1199 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1200 const RtpPacketType& rtp_packet = *rtp_iterator->second;
1201 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
1202 RTC_DCHECK(rtp_packet.rtp.header.extension.hasTransportSequenceNumber);
1203 transport_feedback.AddPacket(
1204 rtp_packet.rtp.header.ssrc,
1205 rtp_packet.rtp.header.extension.transportSequenceNumber,
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001206 rtp_packet.rtp.total_length, PacedPacketInfo(),
1207 Timestamp::us(rtp_packet.rtp.log_time_us()));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001208 rtc::SentPacket sent_packet(
1209 rtp_packet.rtp.header.extension.transportSequenceNumber,
1210 rtp_packet.rtp.log_time_us() / 1000);
1211 auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet);
1212 if (sent_msg)
1213 observer.Update(goog_cc->OnSentPacket(*sent_msg));
1214 }
1215 ++rtp_iterator;
1216 }
Stefan Holmer13181032016-07-29 14:48:54 +02001217 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001218 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001219
1220 auto feedback_msg = transport_feedback.ProcessTransportFeedback(
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001221 rtcp_iterator->transport_feedback,
1222 Timestamp::ms(clock.TimeInMilliseconds()));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001223 absl::optional<uint32_t> bitrate_bps;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001224 if (feedback_msg) {
1225 observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg));
1226 std::vector<PacketFeedback> feedback =
1227 transport_feedback.GetTransportFeedbackVector();
1228 SortPacketFeedbackVector(&feedback);
1229 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001230#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001231 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001232#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001233 for (const PacketFeedback& packet : feedback)
1234 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1235 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1236 }
Stefan Holmer13181032016-07-29 14:48:54 +02001237 }
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001238
Bjorn Terelius068fc352019-02-13 22:38:25 +01001239 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001240 float y = bitrate_bps.value_or(0) / 1000;
1241 acked_time_series.points.emplace_back(x, y);
1242#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1243 y = acknowledged_bitrate_estimator.bitrate_bps().value_or(0) / 1000;
1244 acked_estimate_time_series.points.emplace_back(x, y);
1245#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001246 ++rtcp_iterator;
1247 }
stefanc3de0332016-08-02 07:22:17 -07001248 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1249 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001250 ProcessInterval msg;
1251 msg.at_time = Timestamp::us(clock.TimeInMicroseconds());
1252 observer.Update(goog_cc->OnProcessInterval(msg));
1253 next_process_time_us_ += process_interval.us();
stefanc3de0332016-08-02 07:22:17 -07001254 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001255 if (observer.GetAndResetBitrateUpdated() ||
1256 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001257 uint32_t y = observer.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001258 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Stefan Holmer13181032016-07-29 14:48:54 +02001259 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001260 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001261 }
1262 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1263 }
1264 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001265 plot->AppendTimeSeries(std::move(time_series));
1266 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001267 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001268
Bjorn Terelius068fc352019-02-13 22:38:25 +01001269 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1270 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001271 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001272 plot->SetTitle("Simulated send-side BWE behavior");
1273}
1274
1275void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001276 using RtpPacketType = LoggedRtpPacketIncoming;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001277 class RembInterceptingPacketRouter : public PacketRouter {
1278 public:
1279 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1280 uint32_t bitrate_bps) override {
1281 last_bitrate_bps_ = bitrate_bps;
1282 bitrate_updated_ = true;
1283 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1284 }
1285 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1286 bool GetAndResetBitrateUpdated() {
1287 bool bitrate_updated = bitrate_updated_;
1288 bitrate_updated_ = false;
1289 return bitrate_updated;
1290 }
1291
1292 private:
1293 uint32_t last_bitrate_bps_;
1294 bool bitrate_updated_;
1295 };
1296
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001297 std::multimap<int64_t, const RtpPacketType*> incoming_rtp;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001298
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001299 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
1300 if (IsVideoSsrc(kIncomingPacket, stream.ssrc)) {
1301 for (const auto& rtp_packet : stream.incoming_packets)
1302 incoming_rtp.insert(
1303 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Bjorn Terelius28db2662017-10-04 14:22:43 +02001304 }
1305 }
1306
1307 SimulatedClock clock(0);
1308 RembInterceptingPacketRouter packet_router;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001309 // TODO(terelius): The PacketRouter is used as the RemoteBitrateObserver.
Bjorn Terelius28db2662017-10-04 14:22:43 +02001310 // Is this intentional?
1311 ReceiveSideCongestionController rscc(&clock, &packet_router);
1312 // TODO(holmer): Log the call config and use that here instead.
1313 // static const uint32_t kDefaultStartBitrateBps = 300000;
1314 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1315
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001316 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1317 PointStyle::kHighlight);
1318 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001319
1320 RateStatistics acked_bitrate(250, 8000);
1321 int64_t last_update_us = 0;
1322 for (const auto& kv : incoming_rtp) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001323 const RtpPacketType& packet = *kv.second;
1324 int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000;
1325 size_t payload = packet.rtp.total_length; /*Should subtract header?*/
1326 clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() -
Bjorn Terelius28db2662017-10-04 14:22:43 +02001327 clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001328 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001329 acked_bitrate.Update(payload, arrival_time_ms);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001330 absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001331 if (bitrate_bps) {
1332 uint32_t y = *bitrate_bps / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001333 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001334 acked_time_series.points.emplace_back(x, y);
1335 }
1336 if (packet_router.GetAndResetBitrateUpdated() ||
1337 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1338 uint32_t y = packet_router.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001339 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001340 time_series.points.emplace_back(x, y);
1341 last_update_us = clock.TimeInMicroseconds();
1342 }
1343 }
1344 // Add the data set to the plot.
1345 plot->AppendTimeSeries(std::move(time_series));
1346 plot->AppendTimeSeries(std::move(acked_time_series));
1347
Bjorn Terelius068fc352019-02-13 22:38:25 +01001348 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1349 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001350 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1351 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001352}
1353
tereliuse34c19c2016-08-15 08:47:14 -07001354void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001355 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1356 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001357 TimeSeries time_series("Network delay", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001358 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001359 int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max();
1360 int64_t min_rtt_ms = std::numeric_limits<int64_t>::max();
stefanc3de0332016-08-02 07:22:17 -07001361
stefana0a8ed72017-09-06 02:06:32 -07001362 int64_t prev_y = 0;
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001363 for (auto packet : GetNetworkTrace(parsed_log_)) {
1364 if (packet.arrival_time_ms == PacketFeedback::kNotReceived)
1365 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001366 float x = config_.GetCallTimeSec(1000 * packet.feedback_arrival_time_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001367 if (packet.send_time_ms == PacketFeedback::kNoSendTime) {
1368 late_feedback_series.points.emplace_back(x, prev_y);
1369 continue;
stefanc3de0332016-08-02 07:22:17 -07001370 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001371 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1372 prev_y = y;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001373 int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms;
1374 min_rtt_ms = std::min(rtt_ms, min_rtt_ms);
1375 min_send_receive_diff_ms = std::min(y, min_send_receive_diff_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001376 time_series.points.emplace_back(x, y);
stefanc3de0332016-08-02 07:22:17 -07001377 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001378
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001379 // We assume that the base network delay (w/o queues) is equal to half
1380 // the minimum RTT. Therefore rescale the delays by subtracting the minimum
1381 // observed 1-ways delay and add half the minumum RTT.
1382 const int64_t estimated_clock_offset_ms =
1383 min_send_receive_diff_ms - min_rtt_ms / 2;
stefanc3de0332016-08-02 07:22:17 -07001384 for (TimeSeriesPoint& point : time_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001385 point.y -= estimated_clock_offset_ms;
stefana0a8ed72017-09-06 02:06:32 -07001386 for (TimeSeriesPoint& point : late_feedback_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001387 point.y -= estimated_clock_offset_ms;
1388
stefanc3de0332016-08-02 07:22:17 -07001389 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001390 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1391 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001392
Bjorn Terelius068fc352019-02-13 22:38:25 +01001393 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1394 "Time (s)", kLeftMargin, kRightMargin);
stefanc3de0332016-08-02 07:22:17 -07001395 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +01001396 plot->SetTitle("Outgoing network delay (based on per-packet feedback)");
stefanc3de0332016-08-02 07:22:17 -07001397}
stefan08383272016-12-20 08:51:52 -08001398
Bjorn Terelius0295a962017-10-25 17:42:41 +02001399void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001400 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1401 const std::vector<LoggedRtpPacketOutgoing>& packets =
1402 stream.outgoing_packets;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001403
1404 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001405 RTC_LOG(LS_WARNING)
1406 << "Can't estimate a the RTP clock frequency or the "
1407 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001408 continue;
1409 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001410 int64_t end_time_us = log_segments_.empty()
1411 ? std::numeric_limits<int64_t>::max()
1412 : log_segments_.front().second;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001413 absl::optional<uint32_t> estimated_frequency =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001414 EstimateRtpClockFrequency(packets, end_time_us);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001415 if (!estimated_frequency)
1416 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001417 if (IsVideoSsrc(kOutgoingPacket, stream.ssrc) &&
1418 *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001419 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001420 << "Video stream should use a 90 kHz clock but appears to use "
1421 << *estimated_frequency / 1000 << ". Discarding.";
1422 continue;
1423 }
1424
1425 TimeSeries pacer_delay_series(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001426 GetStreamName(kOutgoingPacket, stream.ssrc) + "(" +
Bjorn Terelius0295a962017-10-25 17:42:41 +02001427 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001428 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001429 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1430 uint64_t first_capture_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001431 timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp);
1432 uint64_t first_send_timestamp = packets.front().rtp.log_time_us();
1433 for (const auto& packet : packets) {
Bjorn Terelius0295a962017-10-25 17:42:41 +02001434 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001435 packet.rtp.header.timestamp)) -
Bjorn Terelius0295a962017-10-25 17:42:41 +02001436 first_capture_timestamp) /
1437 *estimated_frequency * 1000;
1438 double send_time_ms =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001439 static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) /
1440 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001441 float x = config_.GetCallTimeSec(packet.rtp.log_time_us());
Bjorn Terelius0295a962017-10-25 17:42:41 +02001442 float y = send_time_ms - capture_time_ms;
1443 pacer_delay_series.points.emplace_back(x, y);
1444 }
1445 plot->AppendTimeSeries(std::move(pacer_delay_series));
1446 }
1447
Bjorn Terelius068fc352019-02-13 22:38:25 +01001448 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1449 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001450 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1451 plot->SetTitle(
1452 "Delay from capture to send time. (First packet normalized to 0.)");
1453}
1454
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001455void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction,
1456 Plot* plot) {
1457 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1458 TimeSeries rtp_timestamps(
1459 GetStreamName(direction, stream.ssrc) + " capture-time",
1460 LineStyle::kLine, PointStyle::kHighlight);
1461 for (const auto& packet : stream.packet_view) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001462 float x = config_.GetCallTimeSec(packet.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001463 float y = packet.header.timestamp;
1464 rtp_timestamps.points.emplace_back(x, y);
stefane372d3c2017-02-02 08:04:18 -08001465 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001466 plot->AppendTimeSeries(std::move(rtp_timestamps));
Björn Tereliusff612732018-04-25 14:23:01 +00001467
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001468 TimeSeries rtcp_timestamps(
1469 GetStreamName(direction, stream.ssrc) + " rtcp capture-time",
1470 LineStyle::kLine, PointStyle::kHighlight);
1471 // TODO(terelius): Why only sender reports?
1472 const auto& sender_reports = parsed_log_.sender_reports(direction);
1473 for (const auto& rtcp : sender_reports) {
1474 if (rtcp.sr.sender_ssrc() != stream.ssrc)
1475 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001476 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001477 float y = rtcp.sr.rtp_timestamp();
1478 rtcp_timestamps.points.emplace_back(x, y);
Björn Tereliusff612732018-04-25 14:23:01 +00001479 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001480 plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps));
stefane372d3c2017-02-02 08:04:18 -08001481 }
1482
Bjorn Terelius068fc352019-02-13 22:38:25 +01001483 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1484 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001485 plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin);
1486 plot->SetTitle(GetDirectionAsString(direction) + " timestamps");
stefane372d3c2017-02-02 08:04:18 -08001487}
michaelt6e5b2192017-02-22 07:33:27 -08001488
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001489void EventLogAnalyzer::CreateSenderAndReceiverReportPlot(
1490 PacketDirection direction,
1491 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
1492 std::string title,
1493 std::string yaxis_label,
1494 Plot* plot) {
1495 std::map<uint32_t, TimeSeries> sr_reports_by_ssrc;
1496 const auto& sender_reports = parsed_log_.sender_reports(direction);
1497 for (const auto& rtcp : sender_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001498 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001499 uint32_t ssrc = rtcp.sr.sender_ssrc();
1500 for (const auto& block : rtcp.sr.report_blocks()) {
1501 float y = fy(block);
1502 auto sr_report_it = sr_reports_by_ssrc.find(ssrc);
1503 bool inserted;
1504 if (sr_report_it == sr_reports_by_ssrc.end()) {
1505 std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace(
1506 ssrc, TimeSeries(GetStreamName(direction, ssrc) + " Sender Reports",
1507 LineStyle::kLine, PointStyle::kHighlight));
1508 }
1509 sr_report_it->second.points.emplace_back(x, y);
1510 }
1511 }
1512 for (auto& kv : sr_reports_by_ssrc) {
1513 plot->AppendTimeSeries(std::move(kv.second));
1514 }
1515
1516 std::map<uint32_t, TimeSeries> rr_reports_by_ssrc;
1517 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
1518 for (const auto& rtcp : receiver_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001519 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001520 uint32_t ssrc = rtcp.rr.sender_ssrc();
1521 for (const auto& block : rtcp.rr.report_blocks()) {
1522 float y = fy(block);
1523 auto rr_report_it = rr_reports_by_ssrc.find(ssrc);
1524 bool inserted;
1525 if (rr_report_it == rr_reports_by_ssrc.end()) {
1526 std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace(
1527 ssrc,
1528 TimeSeries(GetStreamName(direction, ssrc) + " Receiver Reports",
1529 LineStyle::kLine, PointStyle::kHighlight));
1530 }
1531 rr_report_it->second.points.emplace_back(x, y);
1532 }
1533 }
1534 for (auto& kv : rr_reports_by_ssrc) {
1535 plot->AppendTimeSeries(std::move(kv.second));
1536 }
1537
Bjorn Terelius068fc352019-02-13 22:38:25 +01001538 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1539 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001540 plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin);
1541 plot->SetTitle(title);
1542}
1543
michaelt6e5b2192017-02-22 07:33:27 -08001544void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001545 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1546 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001547 auto GetAnaBitrateBps = [](const LoggedAudioNetworkAdaptationEvent& ana_event)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001548 -> absl::optional<float> {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001549 if (ana_event.config.bitrate_bps)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001550 return absl::optional<float>(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001551 static_cast<float>(*ana_event.config.bitrate_bps));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001552 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001553 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001554 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001555 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001556 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001557 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001558 ToCallTime, GetAnaBitrateBps,
1559 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001560 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001561 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1562 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001563 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1564 plot->SetTitle("Reported audio encoder target bitrate");
1565}
1566
1567void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001568 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1569 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001570 auto GetAnaFrameLengthMs =
1571 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001572 if (ana_event.config.frame_length_ms)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001573 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001574 static_cast<float>(*ana_event.config.frame_length_ms));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001575 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001576 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001577 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001578 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001579 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001580 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001581 ToCallTime, GetAnaFrameLengthMs,
1582 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001583 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001584 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1585 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001586 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1587 plot->SetTitle("Reported audio encoder frame length");
1588}
1589
terelius2ee076d2017-08-15 02:04:02 -07001590void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001591 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001592 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001593 auto GetAnaPacketLoss =
1594 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001595 if (ana_event.config.uplink_packet_loss_fraction)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001596 return absl::optional<float>(static_cast<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001597 *ana_event.config.uplink_packet_loss_fraction));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001598 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001599 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001600 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001601 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001602 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001603 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001604 ToCallTime, GetAnaPacketLoss,
1605 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001606 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001607 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1608 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001609 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1610 kTopMargin);
1611 plot->SetTitle("Reported audio encoder lost packets");
1612}
1613
1614void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001615 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1616 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001617 auto GetAnaFecEnabled =
1618 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001619 if (ana_event.config.enable_fec)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001620 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001621 static_cast<float>(*ana_event.config.enable_fec));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001622 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001623 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001624 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001625 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001626 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001627 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001628 ToCallTime, GetAnaFecEnabled,
1629 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001630 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001631 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1632 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001633 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1634 plot->SetTitle("Reported audio encoder FEC");
1635}
1636
1637void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001638 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1639 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001640 auto GetAnaDtxEnabled =
1641 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001642 if (ana_event.config.enable_dtx)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001643 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001644 static_cast<float>(*ana_event.config.enable_dtx));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001645 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001646 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001647 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001648 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001649 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001650 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001651 ToCallTime, GetAnaDtxEnabled,
1652 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001653 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001654 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1655 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001656 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1657 plot->SetTitle("Reported audio encoder DTX");
1658}
1659
1660void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001661 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1662 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001663 auto GetAnaNumChannels =
1664 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001665 if (ana_event.config.num_channels)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001666 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001667 static_cast<float>(*ana_event.config.num_channels));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001668 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001669 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001670 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001671 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001672 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001673 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001674 ToCallTime, GetAnaNumChannels,
1675 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001676 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001677 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1678 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001679 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1680 kBottomMargin, kTopMargin);
1681 plot->SetTitle("Reported audio encoder number of channels");
1682}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001683
1684class NetEqStreamInput : public test::NetEqInput {
1685 public:
1686 // Does not take any ownership, and all pointers must refer to valid objects
1687 // that outlive the one constructed.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001688 NetEqStreamInput(const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001689 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001690 absl::optional<int64_t> end_time_ms)
henrik.lundin3c938fc2017-06-14 06:09:58 -07001691 : packet_stream_(*packet_stream),
1692 packet_stream_it_(packet_stream_.begin()),
Minyue Li27e2b7d2018-05-07 15:20:24 +02001693 output_events_it_(output_events->begin()),
1694 output_events_end_(output_events->end()),
1695 end_time_ms_(end_time_ms) {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001696 RTC_DCHECK(packet_stream);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001697 RTC_DCHECK(output_events);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001698 }
1699
Danil Chapovalov431abd92018-06-18 12:54:17 +02001700 absl::optional<int64_t> NextPacketTime() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001701 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001702 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001703 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001704 if (end_time_ms_ && packet_stream_it_->rtp.log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001705 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001706 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001707 return packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001708 }
1709
Danil Chapovalov431abd92018-06-18 12:54:17 +02001710 absl::optional<int64_t> NextOutputEventTime() const override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001711 if (output_events_it_ == output_events_end_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001712 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001713 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001714 if (end_time_ms_ && output_events_it_->log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001715 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001716 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001717 return output_events_it_->log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001718 }
1719
1720 std::unique_ptr<PacketData> PopPacket() override {
1721 if (packet_stream_it_ == packet_stream_.end()) {
1722 return std::unique_ptr<PacketData>();
1723 }
1724 std::unique_ptr<PacketData> packet_data(new PacketData());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001725 packet_data->header = packet_stream_it_->rtp.header;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001726 packet_data->time_ms = packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001727
1728 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1729 // length according to the virtual length.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001730 packet_data->payload.SetSize(packet_stream_it_->rtp.total_length -
1731 packet_stream_it_->rtp.header_length);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001732 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1733
1734 ++packet_stream_it_;
1735 return packet_data;
1736 }
1737
1738 void AdvanceOutputEvent() override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001739 if (output_events_it_ != output_events_end_) {
1740 ++output_events_it_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001741 }
1742 }
1743
1744 bool ended() const override { return !NextEventTime(); }
1745
Danil Chapovalov431abd92018-06-18 12:54:17 +02001746 absl::optional<RTPHeader> NextHeader() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001747 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001748 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001749 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001750 return packet_stream_it_->rtp.header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001751 }
1752
1753 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001754 const std::vector<LoggedRtpPacketIncoming>& packet_stream_;
1755 std::vector<LoggedRtpPacketIncoming>::const_iterator packet_stream_it_;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001756 std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_it_;
1757 const std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_end_;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001758 const absl::optional<int64_t> end_time_ms_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001759};
1760
1761namespace {
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001762
1763// Factory to create a "replacement decoder" that produces the decoded audio
1764// by reading from a file rather than from the encoded payloads.
1765class ReplacementAudioDecoderFactory : public AudioDecoderFactory {
1766 public:
1767 ReplacementAudioDecoderFactory(const absl::string_view replacement_file_name,
1768 int file_sample_rate_hz)
1769 : replacement_file_name_(replacement_file_name),
1770 file_sample_rate_hz_(file_sample_rate_hz) {}
1771
1772 std::vector<AudioCodecSpec> GetSupportedDecoders() override {
1773 RTC_NOTREACHED();
1774 return {};
1775 }
1776
1777 bool IsSupportedDecoder(const SdpAudioFormat& format) override {
1778 return true;
1779 }
1780
1781 std::unique_ptr<AudioDecoder> MakeAudioDecoder(
1782 const SdpAudioFormat& format,
1783 absl::optional<AudioCodecPairId> codec_pair_id) override {
1784 auto replacement_file = absl::make_unique<test::ResampleInputAudioFile>(
1785 replacement_file_name_, file_sample_rate_hz_);
1786 replacement_file->set_output_rate_hz(48000);
1787 return absl::make_unique<test::FakeDecodeFromFile>(
1788 std::move(replacement_file), 48000, false);
1789 }
1790
1791 private:
1792 const std::string replacement_file_name_;
1793 const int file_sample_rate_hz_;
1794};
1795
henrik.lundin3c938fc2017-06-14 06:09:58 -07001796// Creates a NetEq test object and all necessary input and output helpers. Runs
1797// the test and returns the NetEqDelayAnalyzer object that was used to
1798// instrument the test.
Minyue Lic6ff7572018-05-04 09:46:44 +02001799std::unique_ptr<test::NetEqStatsGetter> CreateNetEqTestAndRun(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001800 const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001801 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001802 absl::optional<int64_t> end_time_ms,
henrik.lundin3c938fc2017-06-14 06:09:58 -07001803 const std::string& replacement_file_name,
1804 int file_sample_rate_hz) {
1805 std::unique_ptr<test::NetEqInput> input(
Minyue Li27e2b7d2018-05-07 15:20:24 +02001806 new NetEqStreamInput(packet_stream, output_events, end_time_ms));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001807
1808 constexpr int kReplacementPt = 127;
1809 std::set<uint8_t> cn_types;
1810 std::set<uint8_t> forbidden_types;
1811 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1812 cn_types, forbidden_types));
1813
1814 NetEq::Config config;
1815 config.max_packets_in_buffer = 200;
1816 config.enable_fast_accelerate = true;
1817
1818 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1819
Niels Möller3f651d82018-12-19 15:06:17 +01001820 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory =
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001821 new rtc::RefCountedObject<ReplacementAudioDecoderFactory>(
1822 replacement_file_name, file_sample_rate_hz);
Niels Möller3f651d82018-12-19 15:06:17 +01001823
Niels Möller05543682019-01-10 16:55:06 +01001824 test::NetEqTest::DecoderMap codecs = {
1825 {kReplacementPt, SdpAudioFormat("l16", 48000, 1)}};
henrik.lundin3c938fc2017-06-14 06:09:58 -07001826
1827 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1828 new test::NetEqDelayAnalyzer);
Minyue Lic6ff7572018-05-04 09:46:44 +02001829 std::unique_ptr<test::NetEqStatsGetter> neteq_stats_getter(
1830 new test::NetEqStatsGetter(std::move(delay_cb)));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001831 test::DefaultNetEqTestErrorCallback error_cb;
1832 test::NetEqTest::Callbacks callbacks;
1833 callbacks.error_callback = &error_cb;
Minyue Lic6ff7572018-05-04 09:46:44 +02001834 callbacks.post_insert_packet = neteq_stats_getter->delay_analyzer();
1835 callbacks.get_audio_callback = neteq_stats_getter.get();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001836
Niels Möllerbd6dee82019-01-02 09:39:47 +01001837 test::NetEqTest test(config, decoder_factory, codecs, nullptr,
Niels Möller3f651d82018-12-19 15:06:17 +01001838 std::move(input), std::move(output), callbacks);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001839 test.Run();
Minyue Lic6ff7572018-05-04 09:46:44 +02001840 return neteq_stats_getter;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001841}
1842} // namespace
1843
Minyue Lic6ff7572018-05-04 09:46:44 +02001844EventLogAnalyzer::NetEqStatsGetterMap EventLogAnalyzer::SimulateNetEq(
henrik.lundin3c938fc2017-06-14 06:09:58 -07001845 const std::string& replacement_file_name,
Minyue Lic6ff7572018-05-04 09:46:44 +02001846 int file_sample_rate_hz) const {
1847 NetEqStatsGetterMap neteq_stats;
1848
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001849 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001850 const uint32_t ssrc = stream.ssrc;
1851 if (!IsAudioSsrc(kIncomingPacket, ssrc))
1852 continue;
1853 const std::vector<LoggedRtpPacketIncoming>* audio_packets =
1854 &stream.incoming_packets;
1855 if (audio_packets == nullptr) {
1856 // No incoming audio stream found.
1857 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001858 }
henrik.lundin3c938fc2017-06-14 06:09:58 -07001859
Minyue Li27e2b7d2018-05-07 15:20:24 +02001860 RTC_DCHECK(neteq_stats.find(ssrc) == neteq_stats.end());
1861
1862 std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>::const_iterator
1863 output_events_it = parsed_log_.audio_playout_events().find(ssrc);
1864 if (output_events_it == parsed_log_.audio_playout_events().end()) {
1865 // Could not find output events with SSRC matching the input audio stream.
1866 // Using the first available stream of output events.
1867 output_events_it = parsed_log_.audio_playout_events().cbegin();
1868 }
1869
Danil Chapovalov431abd92018-06-18 12:54:17 +02001870 absl::optional<int64_t> end_time_ms =
Minyue Li27e2b7d2018-05-07 15:20:24 +02001871 log_segments_.empty()
Danil Chapovalov431abd92018-06-18 12:54:17 +02001872 ? absl::nullopt
1873 : absl::optional<int64_t>(log_segments_.front().second / 1000);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001874
1875 neteq_stats[ssrc] = CreateNetEqTestAndRun(
1876 audio_packets, &output_events_it->second, end_time_ms,
1877 replacement_file_name, file_sample_rate_hz);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001878 }
1879
Minyue Lic6ff7572018-05-04 09:46:44 +02001880 return neteq_stats;
1881}
1882
Minyue Lic97933f2018-08-10 12:51:15 +02001883// Given a NetEqStatsGetter and the SSRC that the NetEqStatsGetter was created
1884// for, this method generates a plot for the jitter buffer delay profile.
Minyue Lic6ff7572018-05-04 09:46:44 +02001885void EventLogAnalyzer::CreateAudioJitterBufferGraph(
Minyue Li01d2a672018-06-21 21:17:19 +02001886 uint32_t ssrc,
1887 const test::NetEqStatsGetter* stats_getter,
Minyue Lic6ff7572018-05-04 09:46:44 +02001888 Plot* plot) const {
Minyue Li45fc6df2018-06-21 11:47:14 +02001889 test::NetEqDelayAnalyzer::Delays arrival_delay_ms;
1890 test::NetEqDelayAnalyzer::Delays corrected_arrival_delay_ms;
1891 test::NetEqDelayAnalyzer::Delays playout_delay_ms;
1892 test::NetEqDelayAnalyzer::Delays target_delay_ms;
1893
Minyue Li01d2a672018-06-21 21:17:19 +02001894 stats_getter->delay_analyzer()->CreateGraphs(
Minyue Li45fc6df2018-06-21 11:47:14 +02001895 &arrival_delay_ms, &corrected_arrival_delay_ms, &playout_delay_ms,
1896 &target_delay_ms);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001897
Minyue Lic97933f2018-08-10 12:51:15 +02001898 TimeSeries time_series_packet_arrival("packet arrival delay",
1899 LineStyle::kLine);
1900 TimeSeries time_series_relative_packet_arrival(
1901 "Relative packet arrival delay", LineStyle::kLine);
1902 TimeSeries time_series_play_time("Playout delay", LineStyle::kLine);
1903 TimeSeries time_series_target_time("Target delay", LineStyle::kLine,
1904 PointStyle::kHighlight);
Minyue Li45fc6df2018-06-21 11:47:14 +02001905
1906 for (const auto& data : arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001907 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02001908 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02001909 time_series_packet_arrival.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02001910 }
1911 for (const auto& data : corrected_arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001912 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02001913 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02001914 time_series_relative_packet_arrival.points.emplace_back(
Minyue Li45fc6df2018-06-21 11:47:14 +02001915 TimeSeriesPoint(x, y));
1916 }
1917 for (const auto& data : playout_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001918 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02001919 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02001920 time_series_play_time.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02001921 }
1922 for (const auto& data : target_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001923 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02001924 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02001925 time_series_target_time.points.emplace_back(TimeSeriesPoint(x, y));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001926 }
1927
Minyue Lic97933f2018-08-10 12:51:15 +02001928 plot->AppendTimeSeries(std::move(time_series_packet_arrival));
1929 plot->AppendTimeSeries(std::move(time_series_relative_packet_arrival));
1930 plot->AppendTimeSeries(std::move(time_series_play_time));
1931 plot->AppendTimeSeries(std::move(time_series_target_time));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001932
Bjorn Terelius068fc352019-02-13 22:38:25 +01001933 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1934 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02001935 plot->SetSuggestedYAxis(0, 1, "Relative delay (ms)", kBottomMargin,
1936 kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001937 plot->SetTitle("NetEq timing for " + GetStreamName(kIncomingPacket, ssrc));
1938}
1939
Minyue Lic9ac93f2018-06-26 13:01:32 +02001940template <typename NetEqStatsType>
1941void EventLogAnalyzer::CreateNetEqStatsGraphInternal(
Minyue Li27e2b7d2018-05-07 15:20:24 +02001942 const NetEqStatsGetterMap& neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +02001943 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
1944 const test::NetEqStatsGetter*)> data_extractor,
1945 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001946 const std::string& plot_name,
1947 Plot* plot) const {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001948 std::map<uint32_t, TimeSeries> time_series;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001949
1950 for (const auto& st : neteq_stats) {
1951 const uint32_t ssrc = st.first;
Minyue Lic9ac93f2018-06-26 13:01:32 +02001952 const std::vector<std::pair<int64_t, NetEqStatsType>>* data_vector =
1953 data_extractor(st.second.get());
1954 for (const auto& data : *data_vector) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001955 const float time =
1956 config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Lic9ac93f2018-06-26 13:01:32 +02001957 const float value = stats_extractor(data.second);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001958 time_series[ssrc].points.emplace_back(TimeSeriesPoint(time, value));
Minyue Li27e2b7d2018-05-07 15:20:24 +02001959 }
1960 }
1961
1962 for (auto& series : time_series) {
1963 series.second.label = GetStreamName(kIncomingPacket, series.first);
1964 series.second.line_style = LineStyle::kLine;
1965 plot->AppendTimeSeries(std::move(series.second));
1966 }
1967
Bjorn Terelius068fc352019-02-13 22:38:25 +01001968 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1969 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02001970 plot->SetSuggestedYAxis(0, 1, plot_name, kBottomMargin, kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001971 plot->SetTitle(plot_name);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001972}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01001973
Minyue Lic9ac93f2018-06-26 13:01:32 +02001974void EventLogAnalyzer::CreateNetEqNetworkStatsGraph(
1975 const NetEqStatsGetterMap& neteq_stats,
1976 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
1977 const std::string& plot_name,
1978 Plot* plot) const {
1979 CreateNetEqStatsGraphInternal<NetEqNetworkStatistics>(
1980 neteq_stats,
1981 [](const test::NetEqStatsGetter* stats_getter) {
1982 return stats_getter->stats();
1983 },
1984 stats_extractor, plot_name, plot);
1985}
1986
1987void EventLogAnalyzer::CreateNetEqLifetimeStatsGraph(
1988 const NetEqStatsGetterMap& neteq_stats,
1989 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
1990 const std::string& plot_name,
1991 Plot* plot) const {
1992 CreateNetEqStatsGraphInternal<NetEqLifetimeStatistics>(
1993 neteq_stats,
1994 [](const test::NetEqStatsGetter* stats_getter) {
1995 return stats_getter->lifetime_stats();
1996 },
1997 stats_extractor, plot_name, plot);
1998}
1999
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002000void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
2001 std::map<uint32_t, TimeSeries> configs_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002002 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002003 if (configs_by_cp_id.find(config.candidate_pair_id) ==
2004 configs_by_cp_id.end()) {
2005 const std::string candidate_pair_desc =
2006 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08002007 configs_by_cp_id[config.candidate_pair_id] =
2008 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
2009 candidate_pair_desc,
2010 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002011 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2012 candidate_pair_desc;
2013 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002014 float x = config_.GetCallTimeSec(config.log_time_us());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002015 float y = static_cast<float>(config.type);
2016 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
2017 }
2018
2019 // TODO(qingsi): There can be a large number of candidate pairs generated by
2020 // certain calls and the frontend cannot render the chart in this case due to
2021 // the failure of generating a palette with the same number of colors.
2022 for (auto& kv : configs_by_cp_id) {
2023 plot->AppendTimeSeries(std::move(kv.second));
2024 }
2025
Bjorn Terelius068fc352019-02-13 22:38:25 +01002026 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2027 "Time (s)", kLeftMargin, kRightMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002028 plot->SetSuggestedYAxis(0, 3, "Numeric Config Type", kBottomMargin,
2029 kTopMargin);
2030 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
2031}
2032
2033std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
2034 uint32_t candidate_pair_id) {
2035 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
2036 candidate_pair_desc_by_id_.end()) {
2037 return candidate_pair_desc_by_id_[candidate_pair_id];
2038 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002039 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002040 // TODO(qingsi): Add the handling of the "Updated" config event after the
2041 // visualization of property change for candidate pairs is introduced.
2042 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
2043 candidate_pair_desc_by_id_.end()) {
2044 const std::string candidate_pair_desc =
2045 GetCandidatePairLogDescriptionAsString(config);
2046 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2047 candidate_pair_desc;
2048 }
2049 }
2050 return candidate_pair_desc_by_id_[candidate_pair_id];
2051}
2052
2053void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
2054 std::map<uint32_t, TimeSeries> checks_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002055 for (const auto& event : parsed_log_.ice_candidate_pair_events()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002056 if (checks_by_cp_id.find(event.candidate_pair_id) ==
2057 checks_by_cp_id.end()) {
2058 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08002059 "[" + std::to_string(event.candidate_pair_id) + "]" +
2060 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002061 LineStyle::kNone, PointStyle::kHighlight);
2062 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002063 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein6353fbc2018-12-03 14:35:59 -08002064 constexpr int kIceCandidatePairEventTypeOffset =
2065 static_cast<int>(IceCandidatePairConfigType::kNumValues);
2066 float y = static_cast<float>(event.type) + kIceCandidatePairEventTypeOffset;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002067 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
2068 }
2069
2070 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
2071 for (auto& kv : checks_by_cp_id) {
2072 plot->AppendTimeSeries(std::move(kv.second));
2073 }
2074
Bjorn Terelius068fc352019-02-13 22:38:25 +01002075 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2076 "Time (s)", kLeftMargin, kRightMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002077 plot->SetSuggestedYAxis(0, 4, "Numeric Connectivity State", kBottomMargin,
2078 kTopMargin);
2079 plot->SetTitle("[IceEventLog] ICE connectivity checks");
2080}
2081
Zach Stein10a58012018-12-07 12:26:28 -08002082void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) {
2083 TimeSeries states("DTLS Transport State", LineStyle::kNone,
2084 PointStyle::kHighlight);
2085 for (const auto& event : parsed_log_.dtls_transport_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002086 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002087 float y = static_cast<float>(event.dtls_transport_state);
2088 states.points.emplace_back(x, y);
2089 }
2090 plot->AppendTimeSeries(std::move(states));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002091 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2092 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002093 plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues),
2094 "Numeric Transport State", kBottomMargin, kTopMargin);
2095 plot->SetTitle("DTLS Transport State");
2096}
2097
2098void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) {
2099 TimeSeries writable("DTLS Writable", LineStyle::kNone,
2100 PointStyle::kHighlight);
2101 for (const auto& event : parsed_log_.dtls_writable_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002102 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002103 float y = static_cast<float>(event.writable);
2104 writable.points.emplace_back(x, y);
2105 }
2106 plot->AppendTimeSeries(std::move(writable));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002107 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2108 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002109 plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin);
2110 plot->SetTitle("DTLS Writable State");
2111}
2112
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002113void EventLogAnalyzer::PrintNotifications(FILE* file) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002114 fprintf(file, "========== TRIAGE NOTIFICATIONS ==========\n");
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002115 for (const auto& alert : incoming_rtp_recv_time_gaps_) {
2116 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2117 }
2118 for (const auto& alert : incoming_rtcp_recv_time_gaps_) {
2119 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2120 }
2121 for (const auto& alert : outgoing_rtp_send_time_gaps_) {
2122 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2123 }
2124 for (const auto& alert : outgoing_rtcp_send_time_gaps_) {
2125 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2126 }
2127 for (const auto& alert : incoming_seq_num_jumps_) {
2128 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2129 }
2130 for (const auto& alert : incoming_capture_time_jumps_) {
2131 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2132 }
2133 for (const auto& alert : outgoing_seq_num_jumps_) {
2134 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2135 }
2136 for (const auto& alert : outgoing_capture_time_jumps_) {
2137 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2138 }
2139 for (const auto& alert : outgoing_high_loss_alerts_) {
2140 fprintf(file, " : %s\n", alert.ToString().c_str());
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002141 }
2142 fprintf(file, "========== END TRIAGE NOTIFICATIONS ==========\n");
2143}
2144
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002145void EventLogAnalyzer::CreateStreamGapAlerts(PacketDirection direction) {
2146 // With 100 packets/s (~800kbps), false positives would require 10 s without
2147 // data.
2148 constexpr int64_t kMaxSeqNumJump = 1000;
2149 // With a 90 kHz clock, false positives would require 10 s without data.
2150 constexpr int64_t kMaxCaptureTimeJump = 900000;
2151
2152 int64_t end_time_us = log_segments_.empty()
2153 ? std::numeric_limits<int64_t>::max()
2154 : log_segments_.front().second;
2155
2156 SeqNumUnwrapper<uint16_t> seq_num_unwrapper;
Danil Chapovalov431abd92018-06-18 12:54:17 +02002157 absl::optional<int64_t> last_seq_num;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002158 SeqNumUnwrapper<uint32_t> capture_time_unwrapper;
Danil Chapovalov431abd92018-06-18 12:54:17 +02002159 absl::optional<int64_t> last_capture_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002160 // Check for gaps in sequence numbers and capture timestamps.
2161 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
2162 for (const auto& packet : stream.packet_view) {
2163 if (packet.log_time_us() > end_time_us) {
2164 // Only process the first (LOG_START, LOG_END) segment.
2165 break;
2166 }
2167
2168 int64_t seq_num = seq_num_unwrapper.Unwrap(packet.header.sequenceNumber);
2169 if (last_seq_num.has_value() &&
2170 std::abs(seq_num - last_seq_num.value()) > kMaxSeqNumJump) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002171 Alert_SeqNumJump(direction,
2172 config_.GetCallTimeSec(packet.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002173 packet.header.ssrc);
2174 }
2175 last_seq_num.emplace(seq_num);
2176
2177 int64_t capture_time =
2178 capture_time_unwrapper.Unwrap(packet.header.timestamp);
2179 if (last_capture_time.has_value() &&
2180 std::abs(capture_time - last_capture_time.value()) >
2181 kMaxCaptureTimeJump) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002182 Alert_CaptureTimeJump(direction,
2183 config_.GetCallTimeSec(packet.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002184 packet.header.ssrc);
2185 }
2186 last_capture_time.emplace(capture_time);
2187 }
2188 }
2189}
2190
2191void EventLogAnalyzer::CreateTransmissionGapAlerts(PacketDirection direction) {
2192 constexpr int64_t kMaxRtpTransmissionGap = 500000;
2193 constexpr int64_t kMaxRtcpTransmissionGap = 2000000;
2194 int64_t end_time_us = log_segments_.empty()
2195 ? std::numeric_limits<int64_t>::max()
2196 : log_segments_.front().second;
2197
2198 // TODO(terelius): The parser could provide a list of all packets, ordered
2199 // by time, for each direction.
2200 std::multimap<int64_t, const LoggedRtpPacket*> rtp_in_direction;
2201 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
2202 for (const LoggedRtpPacket& rtp_packet : stream.packet_view)
2203 rtp_in_direction.emplace(rtp_packet.log_time_us(), &rtp_packet);
2204 }
Danil Chapovalov431abd92018-06-18 12:54:17 +02002205 absl::optional<int64_t> last_rtp_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002206 for (const auto& kv : rtp_in_direction) {
2207 int64_t timestamp = kv.first;
2208 if (timestamp > end_time_us) {
2209 // Only process the first (LOG_START, LOG_END) segment.
2210 break;
2211 }
2212 int64_t duration = timestamp - last_rtp_time.value_or(0);
2213 if (last_rtp_time.has_value() && duration > kMaxRtpTransmissionGap) {
2214 // No packet sent/received for more than 500 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002215 Alert_RtpLogTimeGap(direction, config_.GetCallTimeSec(timestamp),
2216 duration / 1000);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002217 }
2218 last_rtp_time.emplace(timestamp);
2219 }
2220
Danil Chapovalov431abd92018-06-18 12:54:17 +02002221 absl::optional<int64_t> last_rtcp_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002222 if (direction == kIncomingPacket) {
2223 for (const auto& rtcp : parsed_log_.incoming_rtcp_packets()) {
2224 if (rtcp.log_time_us() > end_time_us) {
2225 // Only process the first (LOG_START, LOG_END) segment.
2226 break;
2227 }
2228 int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0);
2229 if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) {
2230 // No feedback sent/received for more than 2000 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002231 Alert_RtcpLogTimeGap(direction,
2232 config_.GetCallTimeSec(rtcp.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002233 duration / 1000);
2234 }
2235 last_rtcp_time.emplace(rtcp.log_time_us());
2236 }
2237 } else {
2238 for (const auto& rtcp : parsed_log_.outgoing_rtcp_packets()) {
2239 if (rtcp.log_time_us() > end_time_us) {
2240 // Only process the first (LOG_START, LOG_END) segment.
2241 break;
2242 }
2243 int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0);
2244 if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) {
2245 // No feedback sent/received for more than 2000 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002246 Alert_RtcpLogTimeGap(direction,
2247 config_.GetCallTimeSec(rtcp.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002248 duration / 1000);
2249 }
2250 last_rtcp_time.emplace(rtcp.log_time_us());
2251 }
2252 }
2253}
2254
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002255// TODO(terelius): Notifications could possibly be generated by the same code
2256// that produces the graphs. There is some code duplication that could be
2257// avoided, but that might be solved anyway when we move functionality from the
2258// analyzer to the parser.
2259void EventLogAnalyzer::CreateTriageNotifications() {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002260 CreateStreamGapAlerts(kIncomingPacket);
2261 CreateStreamGapAlerts(kOutgoingPacket);
2262 CreateTransmissionGapAlerts(kIncomingPacket);
2263 CreateTransmissionGapAlerts(kOutgoingPacket);
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002264
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002265 int64_t end_time_us = log_segments_.empty()
2266 ? std::numeric_limits<int64_t>::max()
2267 : log_segments_.front().second;
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002268
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002269 constexpr double kMaxLossFraction = 0.05;
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002270 // Loss feedback
2271 int64_t total_lost_packets = 0;
2272 int64_t total_expected_packets = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002273 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
2274 if (bwe_update.log_time_us() > end_time_us) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002275 // Only process the first (LOG_START, LOG_END) segment.
2276 break;
2277 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002278 int64_t lost_packets = static_cast<double>(bwe_update.fraction_lost) / 255 *
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002279 bwe_update.expected_packets;
2280 total_lost_packets += lost_packets;
2281 total_expected_packets += bwe_update.expected_packets;
2282 }
2283 double avg_outgoing_loss =
2284 static_cast<double>(total_lost_packets) / total_expected_packets;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002285 if (avg_outgoing_loss > kMaxLossFraction) {
2286 Alert_OutgoingHighLoss(avg_outgoing_loss);
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002287 }
2288}
2289
terelius54ce6802016-07-13 06:44:41 -07002290} // namespace webrtc