blob: 428300dbe2753026a867eeb996802240ffd569db [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"
Artem Titov741daaf2019-03-21 14:37:36 +010022#include "api/function_view.h"
Sebastian Jansson95edb032019-01-17 16:24:12 +010023#include "api/transport/field_trial_based_config.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020024#include "api/transport/goog_cc_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "call/audio_receive_stream.h"
26#include "call/audio_send_stream.h"
27#include "call/call.h"
28#include "call/video_receive_stream.h"
29#include "call/video_send_stream.h"
Elad Alon99a81b62017-09-21 10:25:29 +020030#include "logging/rtc_event_log/rtc_stream_config.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020031#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "modules/audio_coding/neteq/tools/audio_sink.h"
33#include "modules/audio_coding/neteq/tools/fake_decode_from_file.h"
34#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
35#include "modules/audio_coding/neteq/tools/neteq_replacement_input.h"
36#include "modules/audio_coding/neteq/tools/neteq_test.h"
37#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
Sebastian Jansson172fd852018-05-24 14:17:06 +020038#include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h"
39#include "modules/congestion_controller/goog_cc/bitrate_estimator.h"
Sebastian Jansson04b18cb2018-07-02 09:25:25 +020040#include "modules/congestion_controller/goog_cc/delay_based_bwe.h"
Bjorn Terelius28db2662017-10-04 14:22:43 +020041#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020042#include "modules/congestion_controller/rtp/transport_feedback_adapter.h"
Erik Språnge7942432019-06-12 13:30:02 +020043#include "modules/pacing/paced_sender.h"
Niels Möllerfd6c0912017-10-31 10:19:10 +010044#include "modules/pacing/packet_router.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020045#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "modules/rtp_rtcp/include/rtp_rtcp.h"
47#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020048#include "modules/rtp_rtcp/source/rtcp_packet.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020049#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
50#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
51#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
52#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
53#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
54#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
55#include "modules/rtp_rtcp/source/rtp_utility.h"
56#include "rtc_base/checks.h"
57#include "rtc_base/format_macros.h"
58#include "rtc_base/logging.h"
Bjorn Terelius0295a962017-10-25 17:42:41 +020059#include "rtc_base/numerics/sequence_number_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020060#include "rtc_base/rate_statistics.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020061#include "rtc_base/strings/string_builder.h"
Sebastian Jansson1175ae02019-03-13 08:56:58 +010062#include "rtc_tools/event_log_visualizer/log_simulation.h"
terelius54ce6802016-07-13 06:44:41 -070063
Bjorn Terelius6984ad22017-10-24 12:19:45 +020064#ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
65#define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0
66#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
67
tereliusdc35dcd2016-08-01 12:03:27 -070068namespace webrtc {
tereliusdc35dcd2016-08-01 12:03:27 -070069
terelius54ce6802016-07-13 06:44:41 -070070namespace {
71
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080072const int kNumMicrosecsPerSec = 1000000;
73
elad.alonec304f92017-03-08 05:03:53 -080074void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
75 auto pred = [](const PacketFeedback& packet_feedback) {
76 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
77 };
78 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
79 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
80}
81
terelius54ce6802016-07-13 06:44:41 -070082std::string SsrcToString(uint32_t ssrc) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020083 rtc::StringBuilder ss;
terelius54ce6802016-07-13 06:44:41 -070084 ss << "SSRC " << ssrc;
Jonas Olsson84df1c72018-09-14 16:59:32 +020085 return ss.Release();
terelius54ce6802016-07-13 06:44:41 -070086}
87
88// Checks whether an SSRC is contained in the list of desired SSRCs.
89// Note that an empty SSRC list matches every SSRC.
90bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
91 if (desired_ssrc.size() == 0)
92 return true;
93 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
94 desired_ssrc.end();
95}
96
97double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
98 // The timestamp is a fixed point representation with 6 bits for seconds
99 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800100 // time in seconds and then multiply by kNumMicrosecsPerSec to convert to
101 // microseconds.
terelius54ce6802016-07-13 06:44:41 -0700102 static constexpr double kTimestampToMicroSec =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800103 static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -0700104 return abs_send_time * kTimestampToMicroSec;
105}
106
107// Computes the difference |later| - |earlier| where |later| and |earlier|
108// are counters that wrap at |modulus|. The difference is chosen to have the
109// least absolute value. For example if |modulus| is 8, then the difference will
110// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
111// be in [-4, 4].
112int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
113 RTC_DCHECK_LE(1, modulus);
114 RTC_DCHECK_LT(later, modulus);
115 RTC_DCHECK_LT(earlier, modulus);
116 int64_t difference =
117 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
118 int64_t max_difference = modulus / 2;
119 int64_t min_difference = max_difference - modulus + 1;
120 if (difference > max_difference) {
121 difference -= modulus;
122 }
123 if (difference < min_difference) {
124 difference += modulus;
125 }
terelius6addf492016-08-23 17:34:07 -0700126 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100127 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
128 << " expected to be in the range ("
129 << min_difference / 2 << "," << max_difference / 2
130 << ") but is " << difference
131 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700132 }
terelius54ce6802016-07-13 06:44:41 -0700133 return difference;
134}
135
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200136// This is much more reliable for outgoing streams than for incoming streams.
137template <typename RtpPacketContainer>
Danil Chapovalov431abd92018-06-18 12:54:17 +0200138absl::optional<uint32_t> EstimateRtpClockFrequency(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200139 const RtpPacketContainer& packets,
140 int64_t end_time_us) {
141 RTC_CHECK(packets.size() >= 2);
142 SeqNumUnwrapper<uint32_t> unwrapper;
Philip Eliasson1f850a62019-03-19 12:15:00 +0000143 int64_t first_rtp_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200144 unwrapper.Unwrap(packets[0].rtp.header.timestamp);
145 int64_t first_log_timestamp = packets[0].log_time_us();
Philip Eliasson1f850a62019-03-19 12:15:00 +0000146 int64_t last_rtp_timestamp = first_rtp_timestamp;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200147 int64_t last_log_timestamp = first_log_timestamp;
148 for (size_t i = 1; i < packets.size(); i++) {
149 if (packets[i].log_time_us() > end_time_us)
150 break;
151 last_rtp_timestamp = unwrapper.Unwrap(packets[i].rtp.header.timestamp);
152 last_log_timestamp = packets[i].log_time_us();
153 }
154 if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) {
155 RTC_LOG(LS_WARNING)
156 << "Failed to estimate RTP clock frequency: Stream too short. ("
157 << packets.size() << " packets, "
158 << last_log_timestamp - first_log_timestamp << " us)";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200159 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200160 }
161 double duration =
162 static_cast<double>(last_log_timestamp - first_log_timestamp) /
163 kNumMicrosecsPerSec;
164 double estimated_frequency =
165 (last_rtp_timestamp - first_rtp_timestamp) / duration;
166 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
167 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
168 return f;
169 }
170 }
171 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
172 << estimated_frequency
173 << "not close to any stardard RTP frequency.";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200174 return absl::nullopt;
ivocaac9d6f2016-09-22 07:01:47 -0700175}
176
tereliusdc35dcd2016-08-01 12:03:27 -0700177constexpr float kLeftMargin = 0.01f;
178constexpr float kRightMargin = 0.02f;
179constexpr float kBottomMargin = 0.02f;
180constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700181
Danil Chapovalov431abd92018-06-18 12:54:17 +0200182absl::optional<double> NetworkDelayDiff_AbsSendTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100183 const LoggedRtpPacketIncoming& old_packet,
184 const LoggedRtpPacketIncoming& new_packet) {
185 if (old_packet.rtp.header.extension.hasAbsoluteSendTime &&
186 new_packet.rtp.header.extension.hasAbsoluteSendTime) {
terelius53dc23c2017-03-13 05:24:05 -0700187 int64_t send_time_diff = WrappingDifference(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100188 new_packet.rtp.header.extension.absoluteSendTime,
189 old_packet.rtp.header.extension.absoluteSendTime, 1ul << 24);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200190 int64_t recv_time_diff =
191 new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700192 double delay_change_us =
193 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100194 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700195 } else {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200196 return absl::nullopt;
terelius6addf492016-08-23 17:34:07 -0700197 }
198}
199
Danil Chapovalov431abd92018-06-18 12:54:17 +0200200absl::optional<double> NetworkDelayDiff_CaptureTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100201 const LoggedRtpPacketIncoming& old_packet,
202 const LoggedRtpPacketIncoming& new_packet,
203 const double sample_rate) {
204 int64_t send_time_diff =
205 WrappingDifference(new_packet.rtp.header.timestamp,
206 old_packet.rtp.header.timestamp, 1ull << 32);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200207 int64_t recv_time_diff = new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700208
terelius53dc23c2017-03-13 05:24:05 -0700209 double delay_change =
210 static_cast<double>(recv_time_diff) / 1000 -
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100211 static_cast<double>(send_time_diff) / sample_rate * 1000;
terelius53dc23c2017-03-13 05:24:05 -0700212 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100213 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100214 RTC_LOG(LS_WARNING) << "Old capture time "
215 << old_packet.rtp.header.timestamp << ", received time "
216 << old_packet.log_time_us();
217 RTC_LOG(LS_WARNING) << "New capture time "
218 << new_packet.rtp.header.timestamp << ", received time "
219 << new_packet.log_time_us();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100220 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800221 << static_cast<double>(recv_time_diff) /
222 kNumMicrosecsPerSec
223 << "s";
Mirko Bonadei675513b2017-11-09 11:09:25 +0100224 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100225 << static_cast<double>(send_time_diff) / sample_rate
Mirko Bonadei675513b2017-11-09 11:09:25 +0100226 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700227 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100228 return delay_change;
terelius53dc23c2017-03-13 05:24:05 -0700229}
230
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200231// For each element in data_view, use |f()| to extract a y-coordinate and
terelius53dc23c2017-03-13 05:24:05 -0700232// store the result in a TimeSeries.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200233template <typename DataType, typename IterableType>
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200234void ProcessPoints(rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200235 rtc::FunctionView<absl::optional<float>(const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200236 const IterableType& data_view,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200237 TimeSeries* result) {
238 for (size_t i = 0; i < data_view.size(); i++) {
239 const DataType& elem = data_view[i];
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200240 float x = fx(elem);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200241 absl::optional<float> y = fy(elem);
terelius53dc23c2017-03-13 05:24:05 -0700242 if (y)
243 result->points.emplace_back(x, *y);
244 }
245}
246
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200247// For each pair of adjacent elements in |data|, use |f()| to extract a
terelius6addf492016-08-23 17:34:07 -0700248// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
249// will be the time of the second element in the pair.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200250template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700251void ProcessPairs(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200252 rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200253 rtc::FunctionView<absl::optional<ResultType>(const DataType&,
254 const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200255 const IterableType& data,
terelius53dc23c2017-03-13 05:24:05 -0700256 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700257 for (size_t i = 1; i < data.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200258 float x = fx(data[i]);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200259 absl::optional<ResultType> y = fy(data[i - 1], data[i]);
terelius53dc23c2017-03-13 05:24:05 -0700260 if (y)
261 result->points.emplace_back(x, static_cast<float>(*y));
262 }
263}
264
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200265// For each pair of adjacent elements in |data|, use |f()| to extract a
terelius53dc23c2017-03-13 05:24:05 -0700266// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
267// will be the time of the second element in the pair.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200268template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700269void AccumulatePairs(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200270 rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200271 rtc::FunctionView<absl::optional<ResultType>(const DataType&,
272 const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200273 const IterableType& data,
terelius53dc23c2017-03-13 05:24:05 -0700274 TimeSeries* result) {
275 ResultType sum = 0;
276 for (size_t i = 1; i < data.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200277 float x = fx(data[i]);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200278 absl::optional<ResultType> y = fy(data[i - 1], data[i]);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100279 if (y) {
terelius53dc23c2017-03-13 05:24:05 -0700280 sum += *y;
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100281 result->points.emplace_back(x, static_cast<float>(sum));
282 }
tereliusccbbf8d2016-08-10 07:34:28 -0700283 }
284}
285
terelius6addf492016-08-23 17:34:07 -0700286// Calculates a moving average of |data| and stores the result in a TimeSeries.
287// A data point is generated every |step| microseconds from |begin_time|
288// to |end_time|. The value of each data point is the average of the data
289// during the preceeding |window_duration_us| microseconds.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200290template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700291void MovingAverage(
Danil Chapovalov431abd92018-06-18 12:54:17 +0200292 rtc::FunctionView<absl::optional<ResultType>(const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200293 const IterableType& data_view,
Bjorn Terelius068fc352019-02-13 22:38:25 +0100294 AnalyzerConfig config,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200295 TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700296 size_t window_index_begin = 0;
297 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700298 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700299
Bjorn Terelius068fc352019-02-13 22:38:25 +0100300 for (int64_t t = config.begin_time_; t < config.end_time_ + config.step_;
301 t += config.step_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200302 while (window_index_end < data_view.size() &&
303 data_view[window_index_end].log_time_us() < t) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200304 absl::optional<ResultType> value = fy(data_view[window_index_end]);
terelius53dc23c2017-03-13 05:24:05 -0700305 if (value)
306 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700307 ++window_index_end;
308 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200309 while (window_index_begin < data_view.size() &&
310 data_view[window_index_begin].log_time_us() <
Bjorn Terelius068fc352019-02-13 22:38:25 +0100311 t - config.window_duration_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200312 absl::optional<ResultType> value = fy(data_view[window_index_begin]);
terelius53dc23c2017-03-13 05:24:05 -0700313 if (value)
314 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700315 ++window_index_begin;
316 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800317 float window_duration_s =
Bjorn Terelius068fc352019-02-13 22:38:25 +0100318 static_cast<float>(config.window_duration_) / kNumMicrosecsPerSec;
319 float x = config.GetCallTimeSec(t);
terelius53dc23c2017-03-13 05:24:05 -0700320 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700321 result->points.emplace_back(x, y);
322 }
323}
324
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100325template <typename T>
326TimeSeries CreateRtcpTypeTimeSeries(const std::vector<T>& rtcp_list,
327 AnalyzerConfig config,
328 std::string rtcp_name,
329 int category_id) {
330 TimeSeries time_series(rtcp_name, LineStyle::kNone, PointStyle::kHighlight);
331 for (const auto& rtcp : rtcp_list) {
332 float x = config.GetCallTimeSec(rtcp.log_time_us());
333 float y = category_id;
334 time_series.points.emplace_back(x, y);
335 }
336 return time_series;
337}
338
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800339const char kUnknownEnumValue[] = "unknown";
340
341const char kIceCandidateTypeLocal[] = "local";
342const char kIceCandidateTypeStun[] = "stun";
343const char kIceCandidateTypePrflx[] = "prflx";
344const char kIceCandidateTypeRelay[] = "relay";
345
346const char kProtocolUdp[] = "udp";
347const char kProtocolTcp[] = "tcp";
348const char kProtocolSsltcp[] = "ssltcp";
349const char kProtocolTls[] = "tls";
350
351const char kAddressFamilyIpv4[] = "ipv4";
352const char kAddressFamilyIpv6[] = "ipv6";
353
354const char kNetworkTypeEthernet[] = "ethernet";
355const char kNetworkTypeLoopback[] = "loopback";
356const char kNetworkTypeWifi[] = "wifi";
357const char kNetworkTypeVpn[] = "vpn";
358const char kNetworkTypeCellular[] = "cellular";
359
360std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) {
361 switch (type) {
362 case webrtc::IceCandidateType::kLocal:
363 return kIceCandidateTypeLocal;
364 case webrtc::IceCandidateType::kStun:
365 return kIceCandidateTypeStun;
366 case webrtc::IceCandidateType::kPrflx:
367 return kIceCandidateTypePrflx;
368 case webrtc::IceCandidateType::kRelay:
369 return kIceCandidateTypeRelay;
370 default:
371 return kUnknownEnumValue;
372 }
373}
374
375std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) {
376 switch (protocol) {
377 case webrtc::IceCandidatePairProtocol::kUdp:
378 return kProtocolUdp;
379 case webrtc::IceCandidatePairProtocol::kTcp:
380 return kProtocolTcp;
381 case webrtc::IceCandidatePairProtocol::kSsltcp:
382 return kProtocolSsltcp;
383 case webrtc::IceCandidatePairProtocol::kTls:
384 return kProtocolTls;
385 default:
386 return kUnknownEnumValue;
387 }
388}
389
390std::string GetAddressFamilyAsString(
391 webrtc::IceCandidatePairAddressFamily family) {
392 switch (family) {
393 case webrtc::IceCandidatePairAddressFamily::kIpv4:
394 return kAddressFamilyIpv4;
395 case webrtc::IceCandidatePairAddressFamily::kIpv6:
396 return kAddressFamilyIpv6;
397 default:
398 return kUnknownEnumValue;
399 }
400}
401
402std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) {
403 switch (type) {
404 case webrtc::IceCandidateNetworkType::kEthernet:
405 return kNetworkTypeEthernet;
406 case webrtc::IceCandidateNetworkType::kLoopback:
407 return kNetworkTypeLoopback;
408 case webrtc::IceCandidateNetworkType::kWifi:
409 return kNetworkTypeWifi;
410 case webrtc::IceCandidateNetworkType::kVpn:
411 return kNetworkTypeVpn;
412 case webrtc::IceCandidateNetworkType::kCellular:
413 return kNetworkTypeCellular;
414 default:
415 return kUnknownEnumValue;
416 }
417}
418
419std::string GetCandidatePairLogDescriptionAsString(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200420 const LoggedIceCandidatePairConfig& config) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800421 // Example: stun:wifi->relay(tcp):cellular@udp:ipv4
422 // represents a pair of a local server-reflexive candidate on a WiFi network
423 // and a remote relay candidate using TCP as the relay protocol on a cell
424 // network, when the candidate pair communicates over UDP using IPv4.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200425 rtc::StringBuilder ss;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800426 std::string local_candidate_type =
427 GetIceCandidateTypeAsString(config.local_candidate_type);
428 std::string remote_candidate_type =
429 GetIceCandidateTypeAsString(config.remote_candidate_type);
430 if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) {
431 local_candidate_type +=
432 "(" + GetProtocolAsString(config.local_relay_protocol) + ")";
433 }
434 ss << local_candidate_type << ":"
435 << GetNetworkTypeAsString(config.local_network_type) << ":"
436 << GetAddressFamilyAsString(config.local_address_family) << "->"
437 << remote_candidate_type << ":"
438 << GetAddressFamilyAsString(config.remote_address_family) << "@"
439 << GetProtocolAsString(config.candidate_pair_protocol);
Jonas Olsson84df1c72018-09-14 16:59:32 +0200440 return ss.Release();
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800441}
442
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200443std::string GetDirectionAsString(PacketDirection direction) {
444 if (direction == kIncomingPacket) {
445 return "Incoming";
446 } else {
447 return "Outgoing";
448 }
449}
450
451std::string GetDirectionAsShortString(PacketDirection direction) {
452 if (direction == kIncomingPacket) {
453 return "In";
454 } else {
455 return "Out";
456 }
457}
458
terelius54ce6802016-07-13 06:44:41 -0700459} // namespace
460
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100461EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200462 bool normalize_time)
Bjorn Terelius068fc352019-02-13 22:38:25 +0100463 : parsed_log_(log) {
464 config_.window_duration_ = 250000;
465 config_.step_ = 10000;
466 config_.normalize_time_ = normalize_time;
467 config_.begin_time_ = parsed_log_.first_timestamp();
468 config_.end_time_ = parsed_log_.last_timestamp();
469 if (config_.end_time_ < config_.begin_time_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200470 RTC_LOG(LS_WARNING) << "No useful events in the log.";
Bjorn Terelius068fc352019-02-13 22:38:25 +0100471 config_.begin_time_ = config_.end_time_ = 0;
Björn Tereliusff612732018-04-25 14:23:01 +0000472 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200473
474 const auto& log_start_events = parsed_log_.start_log_events();
475 const auto& log_end_events = parsed_log_.stop_log_events();
476 auto start_iter = log_start_events.begin();
477 auto end_iter = log_end_events.begin();
478 while (start_iter != log_start_events.end()) {
479 int64_t start = start_iter->log_time_us();
480 ++start_iter;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200481 absl::optional<int64_t> next_start;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200482 if (start_iter != log_start_events.end())
483 next_start.emplace(start_iter->log_time_us());
484 if (end_iter != log_end_events.end() &&
485 end_iter->log_time_us() <=
486 next_start.value_or(std::numeric_limits<int64_t>::max())) {
487 int64_t end = end_iter->log_time_us();
488 RTC_DCHECK_LE(start, end);
489 log_segments_.push_back(std::make_pair(start, end));
490 ++end_iter;
491 } else {
492 // we're missing an end event. Assume that it occurred just before the
493 // next start.
494 log_segments_.push_back(
Bjorn Terelius068fc352019-02-13 22:38:25 +0100495 std::make_pair(start, next_start.value_or(config_.end_time_)));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200496 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700497 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100498 RTC_LOG(LS_INFO) << "Found " << log_segments_.size()
Yves Gerey665174f2018-06-19 15:03:05 +0200499 << " (LOG_START, LOG_END) segments in log.";
terelius54ce6802016-07-13 06:44:41 -0700500}
501
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200502class BitrateObserver : public RemoteBitrateObserver {
Stefan Holmer13181032016-07-29 14:48:54 +0200503 public:
504 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
505
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200506 void Update(NetworkControlUpdate update) {
507 if (update.target_rate) {
508 last_bitrate_bps_ = update.target_rate->target_rate.bps();
509 bitrate_updated_ = true;
510 }
Stefan Holmer13181032016-07-29 14:48:54 +0200511 }
512
513 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
514 uint32_t bitrate) override {}
515
516 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
517 bool GetAndResetBitrateUpdated() {
518 bool bitrate_updated = bitrate_updated_;
519 bitrate_updated_ = false;
520 return bitrate_updated;
521 }
522
523 private:
524 uint32_t last_bitrate_bps_;
525 bool bitrate_updated_;
526};
527
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200528void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction,
terelius54ce6802016-07-13 06:44:41 -0700529 Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200530 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
531 // Filter on SSRC.
532 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700533 continue;
terelius54ce6802016-07-13 06:44:41 -0700534 }
terelius54ce6802016-07-13 06:44:41 -0700535
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200536 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
537 LineStyle::kBar);
538 auto GetPacketSize = [](const LoggedRtpPacket& packet) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200539 return absl::optional<float>(packet.total_length);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200540 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200541 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100542 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200543 };
544 ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize,
545 stream.packet_view, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700546 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700547 }
548
Bjorn Terelius068fc352019-02-13 22:38:25 +0100549 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
550 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700551 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
552 kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200553 plot->SetTitle(GetDirectionAsString(direction) + " RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700554}
555
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100556void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction,
557 Plot* plot) {
558 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
559 parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1));
560 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
561 parsed_log_.receiver_reports(direction), config_, "RR", 2));
562 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
563 parsed_log_.sender_reports(direction), config_, "SR", 3));
564 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
565 parsed_log_.extended_reports(direction), config_, "XR", 4));
566 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction),
567 config_, "NACK", 5));
568 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction),
569 config_, "REMB", 6));
570 plot->AppendTimeSeries(
571 CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7));
572 plot->AppendTimeSeries(
573 CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8));
574 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
575 "Time (s)", kLeftMargin, kRightMargin);
576 plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin);
577 plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets");
578}
579
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200580template <typename IterableType>
philipelccd74892016-09-05 02:46:25 -0700581void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
philipelccd74892016-09-05 02:46:25 -0700582 Plot* plot,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200583 const IterableType& packets,
584 const std::string& label) {
585 TimeSeries time_series(label, LineStyle::kStep);
586 for (size_t i = 0; i < packets.size(); i++) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100587 float x = config_.GetCallTimeSec(packets[i].log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200588 time_series.points.emplace_back(x, i + 1);
philipelccd74892016-09-05 02:46:25 -0700589 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200590 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700591}
592
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200593void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction,
594 Plot* plot) {
595 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
596 if (!MatchingSsrc(stream.ssrc, desired_ssrc_))
597 continue;
598 std::string label =
599 std::string("RTP ") + GetStreamName(direction, stream.ssrc);
600 CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label);
601 }
602 std::string label =
603 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")";
604 if (direction == kIncomingPacket) {
605 CreateAccumulatedPacketsTimeSeries(
606 plot, parsed_log_.incoming_rtcp_packets(), label);
607 } else {
608 CreateAccumulatedPacketsTimeSeries(
609 plot, parsed_log_.outgoing_rtcp_packets(), label);
610 }
philipelccd74892016-09-05 02:46:25 -0700611
Bjorn Terelius068fc352019-02-13 22:38:25 +0100612 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
613 "Time (s)", kLeftMargin, kRightMargin);
philipelccd74892016-09-05 02:46:25 -0700614 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200615 plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) +
616 " RTP/RTCP packets");
philipelccd74892016-09-05 02:46:25 -0700617}
618
terelius54ce6802016-07-13 06:44:41 -0700619// For each SSRC, plot the time between the consecutive playouts.
620void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200621 for (const auto& playout_stream : parsed_log_.audio_playout_events()) {
622 uint32_t ssrc = playout_stream.first;
623 if (!MatchingSsrc(ssrc, desired_ssrc_))
624 continue;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200625 absl::optional<int64_t> last_playout_ms;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200626 TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar);
Minyue Li27e2b7d2018-05-07 15:20:24 +0200627 for (const auto& playout_event : playout_stream.second) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100628 float x = config_.GetCallTimeSec(playout_event.log_time_us());
Minyue Li27e2b7d2018-05-07 15:20:24 +0200629 int64_t playout_time_ms = playout_event.log_time_ms();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200630 // If there were no previous playouts, place the point on the x-axis.
Minyue Li27e2b7d2018-05-07 15:20:24 +0200631 float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200632 time_series.points.push_back(TimeSeriesPoint(x, y));
Minyue Li27e2b7d2018-05-07 15:20:24 +0200633 last_playout_ms.emplace(playout_time_ms);
terelius54ce6802016-07-13 06:44:41 -0700634 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200635 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700636 }
637
Bjorn Terelius068fc352019-02-13 22:38:25 +0100638 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
639 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700640 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
641 kTopMargin);
642 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700643}
644
ivocaac9d6f2016-09-22 07:01:47 -0700645// For audio SSRCs, plot the audio level.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200646void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction,
647 Plot* plot) {
648 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
649 if (!IsAudioSsrc(direction, stream.ssrc))
650 continue;
651 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
652 LineStyle::kLine);
653 for (auto& packet : stream.packet_view) {
ivocaac9d6f2016-09-22 07:01:47 -0700654 if (packet.header.extension.hasAudioLevel) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100655 float x = config_.GetCallTimeSec(packet.log_time_us());
ivocaac9d6f2016-09-22 07:01:47 -0700656 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
657 // Here we convert it to dBov.
658 float y = static_cast<float>(-packet.header.extension.audioLevel);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200659 time_series.points.emplace_back(TimeSeriesPoint(x, y));
ivocaac9d6f2016-09-22 07:01:47 -0700660 }
661 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200662 plot->AppendTimeSeries(std::move(time_series));
ivocaac9d6f2016-09-22 07:01:47 -0700663 }
664
Bjorn Terelius068fc352019-02-13 22:38:25 +0100665 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
666 "Time (s)", kLeftMargin, kRightMargin);
Yves Gerey665174f2018-06-19 15:03:05 +0200667 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200668 plot->SetTitle(GetDirectionAsString(direction) + " audio level");
ivocaac9d6f2016-09-22 07:01:47 -0700669}
670
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100671// For each SSRC, plot the sequence number difference between consecutive
672// incoming packets.
terelius54ce6802016-07-13 06:44:41 -0700673void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200674 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
675 // Filter on SSRC.
676 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700677 continue;
terelius54ce6802016-07-13 06:44:41 -0700678 }
terelius54ce6802016-07-13 06:44:41 -0700679
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200680 TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc),
681 LineStyle::kBar);
682 auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet,
683 const LoggedRtpPacketIncoming& new_packet) {
684 int64_t diff =
685 WrappingDifference(new_packet.rtp.header.sequenceNumber,
686 old_packet.rtp.header.sequenceNumber, 1ul << 16);
687 return diff;
688 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200689 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100690 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200691 };
692 ProcessPairs<LoggedRtpPacketIncoming, float>(
693 ToCallTime, GetSequenceNumberDiff, stream.incoming_packets,
694 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700695 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700696 }
697
Bjorn Terelius068fc352019-02-13 22:38:25 +0100698 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
699 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700700 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
701 kTopMargin);
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100702 plot->SetTitle("Incoming sequence number delta");
terelius54ce6802016-07-13 06:44:41 -0700703}
704
Stefan Holmer99f8e082016-09-09 13:37:50 +0200705void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200706 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
707 const std::vector<LoggedRtpPacketIncoming>& packets =
708 stream.incoming_packets;
709 // Filter on SSRC.
710 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200711 continue;
712 }
713
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200714 TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc),
715 LineStyle::kLine, PointStyle::kHighlight);
716 // TODO(terelius): Should the window and step size be read from the class
717 // instead?
718 const int64_t kWindowUs = 1000000;
719 const int64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100720 SeqNumUnwrapper<uint16_t> unwrapper_;
721 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800722 size_t window_index_begin = 0;
723 size_t window_index_end = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200724 uint64_t highest_seq_number =
725 unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
726 uint64_t highest_prior_seq_number =
727 prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
terelius4c9b4af2017-01-30 08:44:51 -0800728
Bjorn Terelius068fc352019-02-13 22:38:25 +0100729 for (int64_t t = config_.begin_time_; t < config_.end_time_ + kStep;
730 t += kStep) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200731 while (window_index_end < packets.size() &&
732 packets[window_index_end].rtp.log_time_us() < t) {
733 uint64_t sequence_number = unwrapper_.Unwrap(
734 packets[window_index_end].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800735 highest_seq_number = std::max(highest_seq_number, sequence_number);
736 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200737 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200738 while (window_index_begin < packets.size() &&
739 packets[window_index_begin].rtp.log_time_us() < t - kWindowUs) {
740 uint64_t sequence_number = prior_unwrapper_.Unwrap(
741 packets[window_index_begin].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800742 highest_prior_seq_number =
743 std::max(highest_prior_seq_number, sequence_number);
744 ++window_index_begin;
745 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100746 float x = config_.GetCallTimeSec(t);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200747 uint64_t expected_packets = highest_seq_number - highest_prior_seq_number;
terelius4c9b4af2017-01-30 08:44:51 -0800748 if (expected_packets > 0) {
749 int64_t received_packets = window_index_end - window_index_begin;
750 int64_t lost_packets = expected_packets - received_packets;
751 float y = static_cast<float>(lost_packets) / expected_packets * 100;
752 time_series.points.emplace_back(x, y);
753 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200754 }
philipel35ba9bd2017-04-19 05:58:51 -0700755 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200756 }
757
Bjorn Terelius068fc352019-02-13 22:38:25 +0100758 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
759 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100760 plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin);
761 plot->SetTitle("Incoming packet loss (derived from incoming packets)");
Stefan Holmer99f8e082016-09-09 13:37:50 +0200762}
763
terelius2ee076d2017-08-15 02:04:02 -0700764void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100765 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200766 // Filter on SSRC.
767 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200768 IsRtxSsrc(kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700769 continue;
770 }
terelius54ce6802016-07-13 06:44:41 -0700771
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100772 const std::vector<LoggedRtpPacketIncoming>& packets =
773 stream.incoming_packets;
774 if (packets.size() < 100) {
775 RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with "
776 << packets.size() << " packets in the stream.";
777 continue;
778 }
779 int64_t end_time_us = log_segments_.empty()
780 ? std::numeric_limits<int64_t>::max()
781 : log_segments_.front().second;
782 absl::optional<uint32_t> estimated_frequency =
783 EstimateRtpClockFrequency(packets, end_time_us);
784 if (!estimated_frequency)
785 continue;
786 const double frequency_hz = *estimated_frequency;
787 if (IsVideoSsrc(kIncomingPacket, stream.ssrc) && frequency_hz != 90000) {
788 RTC_LOG(LS_WARNING)
789 << "Video stream should use a 90 kHz clock but appears to use "
790 << frequency_hz / 1000 << ". Discarding.";
791 continue;
792 }
793
794 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100795 return this->config_.GetCallTimeSec(packet.log_time_us());
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100796 };
797 auto ToNetworkDelay = [frequency_hz](
798 const LoggedRtpPacketIncoming& old_packet,
799 const LoggedRtpPacketIncoming& new_packet) {
800 return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz);
801 };
802
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200803 TimeSeries capture_time_data(
804 GetStreamName(kIncomingPacket, stream.ssrc) + " capture-time",
805 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100806 AccumulatePairs<LoggedRtpPacketIncoming, double>(
807 ToCallTime, ToNetworkDelay, packets, &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700808 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700809
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200810 TimeSeries send_time_data(
811 GetStreamName(kIncomingPacket, stream.ssrc) + " abs-send-time",
812 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100813 AccumulatePairs<LoggedRtpPacketIncoming, double>(
814 ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data);
815 plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700816 }
817
Bjorn Terelius068fc352019-02-13 22:38:25 +0100818 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
819 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +0100820 plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin);
821 plot->SetTitle("Incoming network delay (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700822}
823
tereliusf736d232016-08-04 10:00:11 -0700824// Plot the fraction of packets lost (as perceived by the loss-based BWE).
825void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100826 TimeSeries time_series("Fraction lost", LineStyle::kLine,
827 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200828 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100829 float x = config_.GetCallTimeSec(bwe_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200830 float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700831 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700832 }
tereliusf736d232016-08-04 10:00:11 -0700833
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200834 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +0100835 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
836 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100837 plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin);
838 plot->SetTitle("Outgoing packet loss (as reported by BWE)");
tereliusf736d232016-08-04 10:00:11 -0700839}
840
terelius54ce6802016-07-13 06:44:41 -0700841// Plot the total bandwidth used by all RTP streams.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200842void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) {
843 // TODO(terelius): This could be provided by the parser.
844 std::multimap<int64_t, size_t> packets_in_order;
845 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
846 for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets)
847 packets_in_order.insert(
848 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
terelius54ce6802016-07-13 06:44:41 -0700849 }
850
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200851 auto window_begin = packets_in_order.begin();
852 auto window_end = packets_in_order.begin();
terelius54ce6802016-07-13 06:44:41 -0700853 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700854
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800855 if (!packets_in_order.empty()) {
856 // Calculate a moving average of the bitrate and store in a TimeSeries.
857 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
858 for (int64_t time = config_.begin_time_;
859 time < config_.end_time_ + config_.step_; time += config_.step_) {
860 while (window_end != packets_in_order.end() && window_end->first < time) {
861 bytes_in_window += window_end->second;
862 ++window_end;
863 }
864 while (window_begin != packets_in_order.end() &&
865 window_begin->first < time - config_.window_duration_) {
866 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
867 bytes_in_window -= window_begin->second;
868 ++window_begin;
869 }
870 float window_duration_in_seconds =
871 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
872 float x = config_.GetCallTimeSec(time);
873 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
874 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700875 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800876 plot->AppendTimeSeries(std::move(bitrate_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200877 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200878
879 // Overlay the outgoing REMB over incoming bitrate.
880 TimeSeries remb_series("Remb", LineStyle::kStep);
881 for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100882 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200883 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
884 remb_series.points.emplace_back(x, y);
885 }
886 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
887
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800888 if (!parsed_log_.generic_packets_received().empty()) {
889 TimeSeries time_series("Incoming generic bitrate", LineStyle::kLine);
890 auto GetPacketSizeKilobits = [](const LoggedGenericPacketReceived& packet) {
891 return packet.packet_length * 8.0 / 1000.0;
892 };
893 MovingAverage<LoggedGenericPacketReceived, double>(
894 GetPacketSizeKilobits, parsed_log_.generic_packets_received(), config_,
895 &time_series);
896 plot->AppendTimeSeries(std::move(time_series));
897 }
898
Bjorn Terelius068fc352019-02-13 22:38:25 +0100899 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
900 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200901 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
902 plot->SetTitle("Incoming RTP bitrate");
903}
904
905// Plot the total bandwidth used by all RTP streams.
906void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
907 bool show_detector_state,
908 bool show_alr_state) {
909 // TODO(terelius): This could be provided by the parser.
910 std::multimap<int64_t, size_t> packets_in_order;
911 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
912 for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets)
913 packets_in_order.insert(
914 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
915 }
916
917 auto window_begin = packets_in_order.begin();
918 auto window_end = packets_in_order.begin();
919 size_t bytes_in_window = 0;
920
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800921 if (!packets_in_order.empty()) {
922 // Calculate a moving average of the bitrate and store in a TimeSeries.
923 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
924 for (int64_t time = config_.begin_time_;
925 time < config_.end_time_ + config_.step_; time += config_.step_) {
926 while (window_end != packets_in_order.end() && window_end->first < time) {
927 bytes_in_window += window_end->second;
928 ++window_end;
929 }
930 while (window_begin != packets_in_order.end() &&
931 window_begin->first < time - config_.window_duration_) {
932 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
933 bytes_in_window -= window_begin->second;
934 ++window_begin;
935 }
936 float window_duration_in_seconds =
937 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
938 float x = config_.GetCallTimeSec(time);
939 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
940 bitrate_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200941 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800942 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700943 }
944
terelius8058e582016-07-25 01:32:41 -0700945 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200946 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
947 for (auto& loss_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100948 float x = config_.GetCallTimeSec(loss_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200949 float y = static_cast<float>(loss_update.bitrate_bps) / 1000;
950 loss_series.points.emplace_back(x, y);
951 }
philipel10fc0e62017-04-11 01:50:23 -0700952
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200953 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
954 IntervalSeries overusing_series("Overusing", "#ff8e82",
955 IntervalSeries::kHorizontal);
956 IntervalSeries underusing_series("Underusing", "#5092fc",
957 IntervalSeries::kHorizontal);
958 IntervalSeries normal_series("Normal", "#c4ffc4",
959 IntervalSeries::kHorizontal);
960 IntervalSeries* last_series = &normal_series;
961 double last_detector_switch = 0.0;
philipel23c7f252017-07-14 06:30:03 -0700962
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200963 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
philipel23c7f252017-07-14 06:30:03 -0700964
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200965 for (auto& delay_update : parsed_log_.bwe_delay_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100966 float x = config_.GetCallTimeSec(delay_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200967 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -0700968
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200969 if (last_detector_state != delay_update.detector_state) {
970 last_series->intervals.emplace_back(last_detector_switch, x);
971 last_detector_state = delay_update.detector_state;
972 last_detector_switch = x;
philipel23c7f252017-07-14 06:30:03 -0700973
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200974 switch (delay_update.detector_state) {
975 case BandwidthUsage::kBwNormal:
976 last_series = &normal_series;
977 break;
978 case BandwidthUsage::kBwUnderusing:
979 last_series = &underusing_series;
980 break;
981 case BandwidthUsage::kBwOverusing:
982 last_series = &overusing_series;
983 break;
984 case BandwidthUsage::kLast:
985 RTC_NOTREACHED();
philipele127e7a2017-03-29 16:28:53 +0200986 }
987 }
philipel23c7f252017-07-14 06:30:03 -0700988
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200989 delay_series.points.emplace_back(x, y);
990 }
Bjorn Terelius9e336ec2018-04-24 16:28:35 +0200991
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200992 RTC_CHECK(last_series);
Bjorn Terelius068fc352019-02-13 22:38:25 +0100993 last_series->intervals.emplace_back(last_detector_switch, config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200994
995 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
996 PointStyle::kHighlight);
997 for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100998 float x = config_.GetCallTimeSec(cluster.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200999 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
1000 created_series.points.emplace_back(x, y);
1001 }
1002
1003 TimeSeries result_series("Probing results.", LineStyle::kNone,
1004 PointStyle::kHighlight);
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001005 for (auto& result : parsed_log_.bwe_probe_success_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001006 float x = config_.GetCallTimeSec(result.log_time_us());
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001007 float y = static_cast<float>(result.bitrate_bps) / 1000;
1008 result_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001009 }
1010
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001011 TimeSeries probe_failures_series("Probe failed", LineStyle::kNone,
1012 PointStyle::kHighlight);
1013 for (auto& failure : parsed_log_.bwe_probe_failure_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001014 float x = config_.GetCallTimeSec(failure.log_time_us());
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001015 probe_failures_series.points.emplace_back(x, 0);
1016 }
1017
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001018 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
1019 bool previously_in_alr = false;
1020 int64_t alr_start = 0;
1021 for (auto& alr : parsed_log_.alr_state_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001022 float y = config_.GetCallTimeSec(alr.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001023 if (!previously_in_alr && alr.in_alr) {
1024 alr_start = alr.log_time_us();
1025 previously_in_alr = true;
1026 } else if (previously_in_alr && !alr.in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001027 float x = config_.GetCallTimeSec(alr_start);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001028 alr_state.intervals.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001029 previously_in_alr = false;
Björn Tereliusff612732018-04-25 14:23:01 +00001030 }
Björn Tereliusff612732018-04-25 14:23:01 +00001031 }
1032
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001033 if (previously_in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001034 float x = config_.GetCallTimeSec(alr_start);
1035 float y = config_.GetCallTimeSec(config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001036 alr_state.intervals.emplace_back(x, y);
1037 }
1038
1039 if (show_detector_state) {
1040 plot->AppendIntervalSeries(std::move(overusing_series));
1041 plot->AppendIntervalSeries(std::move(underusing_series));
1042 plot->AppendIntervalSeries(std::move(normal_series));
1043 }
1044
1045 if (show_alr_state) {
1046 plot->AppendIntervalSeries(std::move(alr_state));
1047 }
1048 plot->AppendTimeSeries(std::move(loss_series));
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001049 plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001050 plot->AppendTimeSeries(std::move(delay_series));
1051 plot->AppendTimeSeries(std::move(created_series));
1052 plot->AppendTimeSeries(std::move(result_series));
1053
1054 // Overlay the incoming REMB over the outgoing bitrate.
Björn Tereliusff612732018-04-25 14:23:01 +00001055 TimeSeries remb_series("Remb", LineStyle::kStep);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001056 for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001057 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001058 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
terelius2c8e8a32017-06-02 01:29:48 -07001059 remb_series.points.emplace_back(x, y);
1060 }
1061 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1062
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001063 if (!parsed_log_.generic_packets_sent().empty()) {
1064 {
1065 TimeSeries time_series("Outgoing generic total bitrate",
1066 LineStyle::kLine);
1067 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1068 return packet.packet_length() * 8.0 / 1000.0;
1069 };
1070 MovingAverage<LoggedGenericPacketSent, double>(
1071 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1072 &time_series);
1073 plot->AppendTimeSeries(std::move(time_series));
1074 }
1075
1076 {
1077 TimeSeries time_series("Outgoing generic payload bitrate",
1078 LineStyle::kLine);
1079 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1080 return packet.payload_length * 8.0 / 1000.0;
1081 };
1082 MovingAverage<LoggedGenericPacketSent, double>(
1083 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1084 &time_series);
1085 plot->AppendTimeSeries(std::move(time_series));
1086 }
1087 }
1088
Bjorn Terelius068fc352019-02-13 22:38:25 +01001089 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1090 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001091 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001092 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001093}
1094
1095// For each SSRC, plot the bandwidth used by that stream.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001096void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction,
1097 Plot* plot) {
1098 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1099 // Filter on SSRC.
1100 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -07001101 continue;
terelius54ce6802016-07-13 06:44:41 -07001102 }
1103
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001104 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
1105 LineStyle::kLine);
1106 auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) {
1107 return packet.total_length * 8.0 / 1000.0;
1108 };
terelius53dc23c2017-03-13 05:24:05 -07001109 MovingAverage<LoggedRtpPacket, double>(
Bjorn Terelius068fc352019-02-13 22:38:25 +01001110 GetPacketSizeKilobits, stream.packet_view, config_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001111 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001112 }
1113
Bjorn Terelius068fc352019-02-13 22:38:25 +01001114 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1115 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001116 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001117 plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001118}
1119
Bjorn Terelius9775a582019-02-15 17:29:58 +01001120// Plot the bitrate allocation for each temporal and spatial layer.
1121// Computed from RTCP XR target bitrate block, so the graph is only populated if
1122// those are sent.
1123void EventLogAnalyzer::CreateBitrateAllocationGraph(PacketDirection direction,
1124 Plot* plot) {
1125 std::map<LayerDescription, TimeSeries> time_series;
1126 const auto& xr_list = parsed_log_.extended_reports(direction);
1127 for (const auto& rtcp : xr_list) {
1128 const absl::optional<rtcp::TargetBitrate>& target_bitrate =
1129 rtcp.xr.target_bitrate();
1130 if (!target_bitrate.has_value())
1131 continue;
1132 for (const auto& bitrate_item : target_bitrate->GetTargetBitrates()) {
1133 LayerDescription layer(rtcp.xr.sender_ssrc(), bitrate_item.spatial_layer,
1134 bitrate_item.temporal_layer);
1135 auto time_series_it = time_series.find(layer);
1136 if (time_series_it == time_series.end()) {
1137 std::string layer_name = GetLayerName(layer);
1138 bool inserted;
1139 std::tie(time_series_it, inserted) = time_series.insert(
1140 std::make_pair(layer, TimeSeries(layer_name, LineStyle::kStep)));
1141 RTC_DCHECK(inserted);
1142 }
1143 float x = config_.GetCallTimeSec(rtcp.log_time_us());
1144 float y = bitrate_item.target_bitrate_kbps;
1145 time_series_it->second.points.emplace_back(x, y);
1146 }
1147 }
1148 for (auto& layer : time_series) {
1149 plot->AppendTimeSeries(std::move(layer.second));
1150 }
1151 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1152 "Time (s)", kLeftMargin, kRightMargin);
1153 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1154 if (direction == kIncomingPacket)
1155 plot->SetTitle("Target bitrate per incoming layer");
1156 else
1157 plot->SetTitle("Target bitrate per outgoing layer");
1158}
1159
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001160void EventLogAnalyzer::CreateGoogCcSimulationGraph(Plot* plot) {
1161 TimeSeries target_rates("Simulated target rate", LineStyle::kStep,
1162 PointStyle::kHighlight);
1163 TimeSeries delay_based("Logged delay-based estimate", LineStyle::kStep,
1164 PointStyle::kHighlight);
1165 TimeSeries loss_based("Logged loss-based estimate", LineStyle::kStep,
1166 PointStyle::kHighlight);
1167 TimeSeries probe_results("Logged probe success", LineStyle::kNone,
1168 PointStyle::kHighlight);
1169
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001170 LogBasedNetworkControllerSimulation simulation(
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001171 absl::make_unique<GoogCcNetworkControllerFactory>(),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001172 [&](const NetworkControlUpdate& update, Timestamp at_time) {
1173 if (update.target_rate) {
1174 target_rates.points.emplace_back(
1175 config_.GetCallTimeSec(at_time.us()),
1176 update.target_rate->target_rate.kbps<float>());
1177 }
1178 });
1179
1180 simulation.ProcessEventsInLog(parsed_log_);
1181 for (const auto& logged : parsed_log_.bwe_delay_updates())
1182 delay_based.points.emplace_back(
1183 config_.GetCallTimeSec(logged.log_time_us()),
1184 logged.bitrate_bps / 1000);
1185 for (const auto& logged : parsed_log_.bwe_probe_success_events())
1186 probe_results.points.emplace_back(
1187 config_.GetCallTimeSec(logged.log_time_us()),
1188 logged.bitrate_bps / 1000);
1189 for (const auto& logged : parsed_log_.bwe_loss_updates())
1190 loss_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time_us()),
1191 logged.bitrate_bps / 1000);
1192
1193 plot->AppendTimeSeries(std::move(delay_based));
1194 plot->AppendTimeSeries(std::move(loss_based));
1195 plot->AppendTimeSeries(std::move(probe_results));
1196 plot->AppendTimeSeries(std::move(target_rates));
1197
1198 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1199 "Time (s)", kLeftMargin, kRightMargin);
1200 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1201 plot->SetTitle("Simulated BWE behavior");
1202}
1203
Bjorn Terelius28db2662017-10-04 14:22:43 +02001204void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001205 using RtpPacketType = LoggedRtpPacketOutgoing;
1206 using TransportFeedbackType = LoggedRtcpPacketTransportFeedback;
Stefan Holmer13181032016-07-29 14:48:54 +02001207
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001208 // TODO(terelius): This could be provided by the parser.
1209 std::multimap<int64_t, const RtpPacketType*> outgoing_rtp;
1210 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1211 for (const RtpPacketType& rtp_packet : stream.outgoing_packets)
1212 outgoing_rtp.insert(
1213 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Stefan Holmer13181032016-07-29 14:48:54 +02001214 }
1215
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001216 const std::vector<TransportFeedbackType>& incoming_rtcp =
1217 parsed_log_.transport_feedbacks(kIncomingPacket);
Stefan Holmer13181032016-07-29 14:48:54 +02001218
1219 SimulatedClock clock(0);
1220 BitrateObserver observer;
1221 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001222 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001223 PacedSender pacer(&clock, &packet_router, &null_event_log);
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001224 TransportFeedbackAdapter transport_feedback;
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001225 auto factory = GoogCcNetworkControllerFactory();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001226 TimeDelta process_interval = factory.GetProcessInterval();
Stefan Holmer13181032016-07-29 14:48:54 +02001227 // TODO(holmer): Log the call config and use that here instead.
1228 static const uint32_t kDefaultStartBitrateBps = 300000;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001229 NetworkControllerConfig cc_config;
Sebastian Jansson78416b62018-10-18 13:08:17 +02001230 cc_config.constraints.at_time = Timestamp::us(clock.TimeInMicroseconds());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001231 cc_config.constraints.starting_rate = DataRate::bps(kDefaultStartBitrateBps);
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001232 cc_config.event_log = &null_event_log;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001233 auto goog_cc = factory.Create(cc_config);
Stefan Holmer13181032016-07-29 14:48:54 +02001234
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001235 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1236 PointStyle::kHighlight);
1237 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1238 PointStyle::kHighlight);
1239 TimeSeries acked_estimate_time_series(
1240 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001241
1242 auto rtp_iterator = outgoing_rtp.begin();
1243 auto rtcp_iterator = incoming_rtcp.begin();
1244
1245 auto NextRtpTime = [&]() {
1246 if (rtp_iterator != outgoing_rtp.end())
1247 return static_cast<int64_t>(rtp_iterator->first);
1248 return std::numeric_limits<int64_t>::max();
1249 };
1250
1251 auto NextRtcpTime = [&]() {
1252 if (rtcp_iterator != incoming_rtcp.end())
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001253 return static_cast<int64_t>(rtcp_iterator->log_time_us());
Stefan Holmer13181032016-07-29 14:48:54 +02001254 return std::numeric_limits<int64_t>::max();
1255 };
Bjorn Tereliusa728c912018-12-06 12:26:30 +01001256 int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()});
Stefan Holmer13181032016-07-29 14:48:54 +02001257
1258 auto NextProcessTime = [&]() {
1259 if (rtcp_iterator != incoming_rtcp.end() ||
1260 rtp_iterator != outgoing_rtp.end()) {
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001261 return next_process_time_us_;
Stefan Holmer13181032016-07-29 14:48:54 +02001262 }
1263 return std::numeric_limits<int64_t>::max();
1264 };
1265
Stefan Holmer492ee282016-10-27 17:19:20 +02001266 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001267#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson95edb032019-01-17 16:24:12 +01001268 FieldTrialBasedConfig field_trial_config_;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001269 // The event_log_visualizer should normally not be compiled with
1270 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
1271 // However, compiling with BWE_TEST_LOGGING, runnning with --plot_sendside_bwe
1272 // and piping the output to plot_dynamics.py can be used as a hack to get the
1273 // internal state of various BWE components. In this case, it is important
1274 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
Sebastian Jansson4ad51d82019-06-11 11:24:40 +02001275 // GoogCcNetworkController since that would lead to duplicate outputs.
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001276 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
Sebastian Jansson95edb032019-01-17 16:24:12 +01001277 &field_trial_config_,
1278 absl::make_unique<BitrateEstimator>(&field_trial_config_));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001279#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001280 int64_t time_us =
1281 std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
Stefan Holmer492ee282016-10-27 17:19:20 +02001282 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001283 while (time_us != std::numeric_limits<int64_t>::max()) {
1284 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001285 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1286 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1287 const RtpPacketType& rtp_packet = *rtp_iterator->second;
1288 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
1289 RTC_DCHECK(rtp_packet.rtp.header.extension.hasTransportSequenceNumber);
Erik Språng30a276b2019-04-23 12:00:11 +02001290 RtpPacketSendInfo packet_info;
1291 packet_info.ssrc = rtp_packet.rtp.header.ssrc;
Bjorn Tereliusf2e9cab2019-05-27 16:44:09 +02001292 packet_info.transport_sequence_number =
Erik Språng30a276b2019-04-23 12:00:11 +02001293 rtp_packet.rtp.header.extension.transportSequenceNumber;
1294 packet_info.rtp_sequence_number = rtp_packet.rtp.header.sequenceNumber;
1295 packet_info.has_rtp_sequence_number = true;
1296 packet_info.length = rtp_packet.rtp.total_length;
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001297 transport_feedback.AddPacket(
Erik Språng30a276b2019-04-23 12:00:11 +02001298 packet_info,
1299 0u, // Per packet overhead bytes.
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001300 Timestamp::us(rtp_packet.rtp.log_time_us()));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001301 rtc::SentPacket sent_packet(
1302 rtp_packet.rtp.header.extension.transportSequenceNumber,
1303 rtp_packet.rtp.log_time_us() / 1000);
1304 auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet);
1305 if (sent_msg)
1306 observer.Update(goog_cc->OnSentPacket(*sent_msg));
1307 }
1308 ++rtp_iterator;
1309 }
Stefan Holmer13181032016-07-29 14:48:54 +02001310 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001311 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001312
1313 auto feedback_msg = transport_feedback.ProcessTransportFeedback(
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001314 rtcp_iterator->transport_feedback,
1315 Timestamp::ms(clock.TimeInMilliseconds()));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001316 absl::optional<uint32_t> bitrate_bps;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001317 if (feedback_msg) {
1318 observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg));
1319 std::vector<PacketFeedback> feedback =
1320 transport_feedback.GetTransportFeedbackVector();
1321 SortPacketFeedbackVector(&feedback);
1322 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001323#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001324 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001325#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001326 for (const PacketFeedback& packet : feedback)
1327 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1328 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1329 }
Stefan Holmer13181032016-07-29 14:48:54 +02001330 }
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001331
Bjorn Terelius068fc352019-02-13 22:38:25 +01001332 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001333 float y = bitrate_bps.value_or(0) / 1000;
1334 acked_time_series.points.emplace_back(x, y);
1335#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1336 y = acknowledged_bitrate_estimator.bitrate_bps().value_or(0) / 1000;
1337 acked_estimate_time_series.points.emplace_back(x, y);
1338#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001339 ++rtcp_iterator;
1340 }
stefanc3de0332016-08-02 07:22:17 -07001341 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1342 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001343 ProcessInterval msg;
1344 msg.at_time = Timestamp::us(clock.TimeInMicroseconds());
1345 observer.Update(goog_cc->OnProcessInterval(msg));
1346 next_process_time_us_ += process_interval.us();
stefanc3de0332016-08-02 07:22:17 -07001347 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001348 if (observer.GetAndResetBitrateUpdated() ||
1349 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001350 uint32_t y = observer.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001351 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Stefan Holmer13181032016-07-29 14:48:54 +02001352 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001353 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001354 }
1355 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1356 }
1357 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001358 plot->AppendTimeSeries(std::move(time_series));
1359 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001360 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001361
Bjorn Terelius068fc352019-02-13 22:38:25 +01001362 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1363 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001364 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001365 plot->SetTitle("Simulated send-side BWE behavior");
1366}
1367
1368void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001369 using RtpPacketType = LoggedRtpPacketIncoming;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001370 class RembInterceptingPacketRouter : public PacketRouter {
1371 public:
1372 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1373 uint32_t bitrate_bps) override {
1374 last_bitrate_bps_ = bitrate_bps;
1375 bitrate_updated_ = true;
1376 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1377 }
1378 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1379 bool GetAndResetBitrateUpdated() {
1380 bool bitrate_updated = bitrate_updated_;
1381 bitrate_updated_ = false;
1382 return bitrate_updated;
1383 }
1384
1385 private:
1386 uint32_t last_bitrate_bps_;
1387 bool bitrate_updated_;
1388 };
1389
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001390 std::multimap<int64_t, const RtpPacketType*> incoming_rtp;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001391
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001392 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
1393 if (IsVideoSsrc(kIncomingPacket, stream.ssrc)) {
1394 for (const auto& rtp_packet : stream.incoming_packets)
1395 incoming_rtp.insert(
1396 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Bjorn Terelius28db2662017-10-04 14:22:43 +02001397 }
1398 }
1399
1400 SimulatedClock clock(0);
1401 RembInterceptingPacketRouter packet_router;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001402 // TODO(terelius): The PacketRouter is used as the RemoteBitrateObserver.
Bjorn Terelius28db2662017-10-04 14:22:43 +02001403 // Is this intentional?
1404 ReceiveSideCongestionController rscc(&clock, &packet_router);
1405 // TODO(holmer): Log the call config and use that here instead.
1406 // static const uint32_t kDefaultStartBitrateBps = 300000;
1407 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1408
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001409 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1410 PointStyle::kHighlight);
1411 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001412
1413 RateStatistics acked_bitrate(250, 8000);
1414 int64_t last_update_us = 0;
1415 for (const auto& kv : incoming_rtp) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001416 const RtpPacketType& packet = *kv.second;
1417 int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000;
1418 size_t payload = packet.rtp.total_length; /*Should subtract header?*/
1419 clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() -
Bjorn Terelius28db2662017-10-04 14:22:43 +02001420 clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001421 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001422 acked_bitrate.Update(payload, arrival_time_ms);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001423 absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001424 if (bitrate_bps) {
1425 uint32_t y = *bitrate_bps / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001426 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001427 acked_time_series.points.emplace_back(x, y);
1428 }
1429 if (packet_router.GetAndResetBitrateUpdated() ||
1430 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1431 uint32_t y = packet_router.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001432 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001433 time_series.points.emplace_back(x, y);
1434 last_update_us = clock.TimeInMicroseconds();
1435 }
1436 }
1437 // Add the data set to the plot.
1438 plot->AppendTimeSeries(std::move(time_series));
1439 plot->AppendTimeSeries(std::move(acked_time_series));
1440
Bjorn Terelius068fc352019-02-13 22:38:25 +01001441 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1442 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001443 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1444 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001445}
1446
tereliuse34c19c2016-08-15 08:47:14 -07001447void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001448 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1449 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001450 TimeSeries time_series("Network delay", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001451 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001452 int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max();
1453 int64_t min_rtt_ms = std::numeric_limits<int64_t>::max();
stefanc3de0332016-08-02 07:22:17 -07001454
stefana0a8ed72017-09-06 02:06:32 -07001455 int64_t prev_y = 0;
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001456 for (auto packet : GetNetworkTrace(parsed_log_)) {
1457 if (packet.arrival_time_ms == PacketFeedback::kNotReceived)
1458 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001459 float x = config_.GetCallTimeSec(1000 * packet.feedback_arrival_time_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001460 if (packet.send_time_ms == PacketFeedback::kNoSendTime) {
1461 late_feedback_series.points.emplace_back(x, prev_y);
1462 continue;
stefanc3de0332016-08-02 07:22:17 -07001463 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001464 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1465 prev_y = y;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001466 int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms;
1467 min_rtt_ms = std::min(rtt_ms, min_rtt_ms);
1468 min_send_receive_diff_ms = std::min(y, min_send_receive_diff_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001469 time_series.points.emplace_back(x, y);
stefanc3de0332016-08-02 07:22:17 -07001470 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001471
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001472 // We assume that the base network delay (w/o queues) is equal to half
1473 // the minimum RTT. Therefore rescale the delays by subtracting the minimum
1474 // observed 1-ways delay and add half the minumum RTT.
1475 const int64_t estimated_clock_offset_ms =
1476 min_send_receive_diff_ms - min_rtt_ms / 2;
stefanc3de0332016-08-02 07:22:17 -07001477 for (TimeSeriesPoint& point : time_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001478 point.y -= estimated_clock_offset_ms;
stefana0a8ed72017-09-06 02:06:32 -07001479 for (TimeSeriesPoint& point : late_feedback_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001480 point.y -= estimated_clock_offset_ms;
1481
stefanc3de0332016-08-02 07:22:17 -07001482 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001483 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1484 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001485
Bjorn Terelius068fc352019-02-13 22:38:25 +01001486 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1487 "Time (s)", kLeftMargin, kRightMargin);
stefanc3de0332016-08-02 07:22:17 -07001488 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +01001489 plot->SetTitle("Outgoing network delay (based on per-packet feedback)");
stefanc3de0332016-08-02 07:22:17 -07001490}
stefan08383272016-12-20 08:51:52 -08001491
Bjorn Terelius0295a962017-10-25 17:42:41 +02001492void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001493 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1494 const std::vector<LoggedRtpPacketOutgoing>& packets =
1495 stream.outgoing_packets;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001496
Konrad Hofbauerbfb735b2019-04-16 11:12:11 +02001497 if (IsRtxSsrc(kOutgoingPacket, stream.ssrc)) {
1498 continue;
1499 }
1500
Bjorn Terelius0295a962017-10-25 17:42:41 +02001501 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001502 RTC_LOG(LS_WARNING)
1503 << "Can't estimate a the RTP clock frequency or the "
1504 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001505 continue;
1506 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001507 int64_t end_time_us = log_segments_.empty()
1508 ? std::numeric_limits<int64_t>::max()
1509 : log_segments_.front().second;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001510 absl::optional<uint32_t> estimated_frequency =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001511 EstimateRtpClockFrequency(packets, end_time_us);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001512 if (!estimated_frequency)
1513 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001514 if (IsVideoSsrc(kOutgoingPacket, stream.ssrc) &&
1515 *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001516 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001517 << "Video stream should use a 90 kHz clock but appears to use "
1518 << *estimated_frequency / 1000 << ". Discarding.";
1519 continue;
1520 }
1521
1522 TimeSeries pacer_delay_series(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001523 GetStreamName(kOutgoingPacket, stream.ssrc) + "(" +
Bjorn Terelius0295a962017-10-25 17:42:41 +02001524 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001525 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001526 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1527 uint64_t first_capture_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001528 timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp);
1529 uint64_t first_send_timestamp = packets.front().rtp.log_time_us();
1530 for (const auto& packet : packets) {
Bjorn Terelius0295a962017-10-25 17:42:41 +02001531 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001532 packet.rtp.header.timestamp)) -
Bjorn Terelius0295a962017-10-25 17:42:41 +02001533 first_capture_timestamp) /
1534 *estimated_frequency * 1000;
1535 double send_time_ms =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001536 static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) /
1537 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001538 float x = config_.GetCallTimeSec(packet.rtp.log_time_us());
Bjorn Terelius0295a962017-10-25 17:42:41 +02001539 float y = send_time_ms - capture_time_ms;
1540 pacer_delay_series.points.emplace_back(x, y);
1541 }
1542 plot->AppendTimeSeries(std::move(pacer_delay_series));
1543 }
1544
Bjorn Terelius068fc352019-02-13 22:38:25 +01001545 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1546 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001547 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1548 plot->SetTitle(
1549 "Delay from capture to send time. (First packet normalized to 0.)");
1550}
1551
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001552void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction,
1553 Plot* plot) {
1554 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1555 TimeSeries rtp_timestamps(
1556 GetStreamName(direction, stream.ssrc) + " capture-time",
1557 LineStyle::kLine, PointStyle::kHighlight);
1558 for (const auto& packet : stream.packet_view) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001559 float x = config_.GetCallTimeSec(packet.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001560 float y = packet.header.timestamp;
1561 rtp_timestamps.points.emplace_back(x, y);
stefane372d3c2017-02-02 08:04:18 -08001562 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001563 plot->AppendTimeSeries(std::move(rtp_timestamps));
Björn Tereliusff612732018-04-25 14:23:01 +00001564
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001565 TimeSeries rtcp_timestamps(
1566 GetStreamName(direction, stream.ssrc) + " rtcp capture-time",
1567 LineStyle::kLine, PointStyle::kHighlight);
1568 // TODO(terelius): Why only sender reports?
1569 const auto& sender_reports = parsed_log_.sender_reports(direction);
1570 for (const auto& rtcp : sender_reports) {
1571 if (rtcp.sr.sender_ssrc() != stream.ssrc)
1572 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001573 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001574 float y = rtcp.sr.rtp_timestamp();
1575 rtcp_timestamps.points.emplace_back(x, y);
Björn Tereliusff612732018-04-25 14:23:01 +00001576 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001577 plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps));
stefane372d3c2017-02-02 08:04:18 -08001578 }
1579
Bjorn Terelius068fc352019-02-13 22:38:25 +01001580 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1581 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001582 plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin);
1583 plot->SetTitle(GetDirectionAsString(direction) + " timestamps");
stefane372d3c2017-02-02 08:04:18 -08001584}
michaelt6e5b2192017-02-22 07:33:27 -08001585
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001586void EventLogAnalyzer::CreateSenderAndReceiverReportPlot(
1587 PacketDirection direction,
1588 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
1589 std::string title,
1590 std::string yaxis_label,
1591 Plot* plot) {
1592 std::map<uint32_t, TimeSeries> sr_reports_by_ssrc;
1593 const auto& sender_reports = parsed_log_.sender_reports(direction);
1594 for (const auto& rtcp : sender_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001595 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001596 uint32_t ssrc = rtcp.sr.sender_ssrc();
1597 for (const auto& block : rtcp.sr.report_blocks()) {
1598 float y = fy(block);
1599 auto sr_report_it = sr_reports_by_ssrc.find(ssrc);
1600 bool inserted;
1601 if (sr_report_it == sr_reports_by_ssrc.end()) {
1602 std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace(
1603 ssrc, TimeSeries(GetStreamName(direction, ssrc) + " Sender Reports",
1604 LineStyle::kLine, PointStyle::kHighlight));
1605 }
1606 sr_report_it->second.points.emplace_back(x, y);
1607 }
1608 }
1609 for (auto& kv : sr_reports_by_ssrc) {
1610 plot->AppendTimeSeries(std::move(kv.second));
1611 }
1612
1613 std::map<uint32_t, TimeSeries> rr_reports_by_ssrc;
1614 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
1615 for (const auto& rtcp : receiver_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001616 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001617 uint32_t ssrc = rtcp.rr.sender_ssrc();
1618 for (const auto& block : rtcp.rr.report_blocks()) {
1619 float y = fy(block);
1620 auto rr_report_it = rr_reports_by_ssrc.find(ssrc);
1621 bool inserted;
1622 if (rr_report_it == rr_reports_by_ssrc.end()) {
1623 std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace(
1624 ssrc,
1625 TimeSeries(GetStreamName(direction, ssrc) + " Receiver Reports",
1626 LineStyle::kLine, PointStyle::kHighlight));
1627 }
1628 rr_report_it->second.points.emplace_back(x, y);
1629 }
1630 }
1631 for (auto& kv : rr_reports_by_ssrc) {
1632 plot->AppendTimeSeries(std::move(kv.second));
1633 }
1634
Bjorn Terelius068fc352019-02-13 22:38:25 +01001635 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1636 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001637 plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin);
1638 plot->SetTitle(title);
1639}
1640
michaelt6e5b2192017-02-22 07:33:27 -08001641void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001642 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1643 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001644 auto GetAnaBitrateBps = [](const LoggedAudioNetworkAdaptationEvent& ana_event)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001645 -> absl::optional<float> {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001646 if (ana_event.config.bitrate_bps)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001647 return absl::optional<float>(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001648 static_cast<float>(*ana_event.config.bitrate_bps));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001649 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001650 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001651 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001652 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001653 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001654 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001655 ToCallTime, GetAnaBitrateBps,
1656 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001657 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001658 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1659 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001660 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1661 plot->SetTitle("Reported audio encoder target bitrate");
1662}
1663
1664void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001665 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1666 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001667 auto GetAnaFrameLengthMs =
1668 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001669 if (ana_event.config.frame_length_ms)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001670 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001671 static_cast<float>(*ana_event.config.frame_length_ms));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001672 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001673 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001674 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001675 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001676 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001677 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001678 ToCallTime, GetAnaFrameLengthMs,
1679 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001680 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001681 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1682 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001683 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1684 plot->SetTitle("Reported audio encoder frame length");
1685}
1686
terelius2ee076d2017-08-15 02:04:02 -07001687void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001688 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001689 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001690 auto GetAnaPacketLoss =
1691 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001692 if (ana_event.config.uplink_packet_loss_fraction)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001693 return absl::optional<float>(static_cast<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001694 *ana_event.config.uplink_packet_loss_fraction));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001695 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001696 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001697 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001698 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001699 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001700 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001701 ToCallTime, GetAnaPacketLoss,
1702 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001703 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001704 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1705 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001706 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1707 kTopMargin);
1708 plot->SetTitle("Reported audio encoder lost packets");
1709}
1710
1711void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001712 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1713 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001714 auto GetAnaFecEnabled =
1715 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001716 if (ana_event.config.enable_fec)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001717 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001718 static_cast<float>(*ana_event.config.enable_fec));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001719 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001720 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001721 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001722 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001723 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001724 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001725 ToCallTime, GetAnaFecEnabled,
1726 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001727 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001728 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1729 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001730 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1731 plot->SetTitle("Reported audio encoder FEC");
1732}
1733
1734void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001735 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1736 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001737 auto GetAnaDtxEnabled =
1738 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001739 if (ana_event.config.enable_dtx)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001740 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001741 static_cast<float>(*ana_event.config.enable_dtx));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001742 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001743 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001744 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001745 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001746 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001747 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001748 ToCallTime, GetAnaDtxEnabled,
1749 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001750 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001751 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1752 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001753 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1754 plot->SetTitle("Reported audio encoder DTX");
1755}
1756
1757void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001758 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1759 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001760 auto GetAnaNumChannels =
1761 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001762 if (ana_event.config.num_channels)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001763 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001764 static_cast<float>(*ana_event.config.num_channels));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001765 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001766 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001767 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001768 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001769 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001770 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001771 ToCallTime, GetAnaNumChannels,
1772 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001773 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001774 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1775 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001776 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1777 kBottomMargin, kTopMargin);
1778 plot->SetTitle("Reported audio encoder number of channels");
1779}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001780
1781class NetEqStreamInput : public test::NetEqInput {
1782 public:
1783 // Does not take any ownership, and all pointers must refer to valid objects
1784 // that outlive the one constructed.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001785 NetEqStreamInput(const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001786 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001787 absl::optional<int64_t> end_time_ms)
henrik.lundin3c938fc2017-06-14 06:09:58 -07001788 : packet_stream_(*packet_stream),
1789 packet_stream_it_(packet_stream_.begin()),
Minyue Li27e2b7d2018-05-07 15:20:24 +02001790 output_events_it_(output_events->begin()),
1791 output_events_end_(output_events->end()),
1792 end_time_ms_(end_time_ms) {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001793 RTC_DCHECK(packet_stream);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001794 RTC_DCHECK(output_events);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001795 }
1796
Danil Chapovalov431abd92018-06-18 12:54:17 +02001797 absl::optional<int64_t> NextPacketTime() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001798 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001799 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001800 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001801 if (end_time_ms_ && packet_stream_it_->rtp.log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001802 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001803 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001804 return packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001805 }
1806
Danil Chapovalov431abd92018-06-18 12:54:17 +02001807 absl::optional<int64_t> NextOutputEventTime() const override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001808 if (output_events_it_ == output_events_end_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001809 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001810 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001811 if (end_time_ms_ && output_events_it_->log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001812 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001813 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001814 return output_events_it_->log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001815 }
1816
1817 std::unique_ptr<PacketData> PopPacket() override {
1818 if (packet_stream_it_ == packet_stream_.end()) {
1819 return std::unique_ptr<PacketData>();
1820 }
1821 std::unique_ptr<PacketData> packet_data(new PacketData());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001822 packet_data->header = packet_stream_it_->rtp.header;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001823 packet_data->time_ms = packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001824
1825 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1826 // length according to the virtual length.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001827 packet_data->payload.SetSize(packet_stream_it_->rtp.total_length -
1828 packet_stream_it_->rtp.header_length);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001829 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1830
1831 ++packet_stream_it_;
1832 return packet_data;
1833 }
1834
1835 void AdvanceOutputEvent() override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001836 if (output_events_it_ != output_events_end_) {
1837 ++output_events_it_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001838 }
1839 }
1840
1841 bool ended() const override { return !NextEventTime(); }
1842
Danil Chapovalov431abd92018-06-18 12:54:17 +02001843 absl::optional<RTPHeader> NextHeader() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001844 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001845 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001846 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001847 return packet_stream_it_->rtp.header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001848 }
1849
1850 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001851 const std::vector<LoggedRtpPacketIncoming>& packet_stream_;
1852 std::vector<LoggedRtpPacketIncoming>::const_iterator packet_stream_it_;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001853 std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_it_;
1854 const std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_end_;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001855 const absl::optional<int64_t> end_time_ms_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001856};
1857
1858namespace {
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001859
1860// Factory to create a "replacement decoder" that produces the decoded audio
1861// by reading from a file rather than from the encoded payloads.
1862class ReplacementAudioDecoderFactory : public AudioDecoderFactory {
1863 public:
1864 ReplacementAudioDecoderFactory(const absl::string_view replacement_file_name,
1865 int file_sample_rate_hz)
1866 : replacement_file_name_(replacement_file_name),
1867 file_sample_rate_hz_(file_sample_rate_hz) {}
1868
1869 std::vector<AudioCodecSpec> GetSupportedDecoders() override {
1870 RTC_NOTREACHED();
1871 return {};
1872 }
1873
1874 bool IsSupportedDecoder(const SdpAudioFormat& format) override {
1875 return true;
1876 }
1877
1878 std::unique_ptr<AudioDecoder> MakeAudioDecoder(
1879 const SdpAudioFormat& format,
1880 absl::optional<AudioCodecPairId> codec_pair_id) override {
1881 auto replacement_file = absl::make_unique<test::ResampleInputAudioFile>(
1882 replacement_file_name_, file_sample_rate_hz_);
1883 replacement_file->set_output_rate_hz(48000);
1884 return absl::make_unique<test::FakeDecodeFromFile>(
1885 std::move(replacement_file), 48000, false);
1886 }
1887
1888 private:
1889 const std::string replacement_file_name_;
1890 const int file_sample_rate_hz_;
1891};
1892
henrik.lundin3c938fc2017-06-14 06:09:58 -07001893// Creates a NetEq test object and all necessary input and output helpers. Runs
1894// the test and returns the NetEqDelayAnalyzer object that was used to
1895// instrument the test.
Minyue Lic6ff7572018-05-04 09:46:44 +02001896std::unique_ptr<test::NetEqStatsGetter> CreateNetEqTestAndRun(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001897 const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001898 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001899 absl::optional<int64_t> end_time_ms,
henrik.lundin3c938fc2017-06-14 06:09:58 -07001900 const std::string& replacement_file_name,
1901 int file_sample_rate_hz) {
1902 std::unique_ptr<test::NetEqInput> input(
Minyue Li27e2b7d2018-05-07 15:20:24 +02001903 new NetEqStreamInput(packet_stream, output_events, end_time_ms));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001904
1905 constexpr int kReplacementPt = 127;
1906 std::set<uint8_t> cn_types;
1907 std::set<uint8_t> forbidden_types;
1908 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1909 cn_types, forbidden_types));
1910
1911 NetEq::Config config;
1912 config.max_packets_in_buffer = 200;
1913 config.enable_fast_accelerate = true;
1914
1915 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1916
Niels Möller3f651d82018-12-19 15:06:17 +01001917 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory =
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001918 new rtc::RefCountedObject<ReplacementAudioDecoderFactory>(
1919 replacement_file_name, file_sample_rate_hz);
Niels Möller3f651d82018-12-19 15:06:17 +01001920
Niels Möller05543682019-01-10 16:55:06 +01001921 test::NetEqTest::DecoderMap codecs = {
1922 {kReplacementPt, SdpAudioFormat("l16", 48000, 1)}};
henrik.lundin3c938fc2017-06-14 06:09:58 -07001923
1924 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1925 new test::NetEqDelayAnalyzer);
Minyue Lic6ff7572018-05-04 09:46:44 +02001926 std::unique_ptr<test::NetEqStatsGetter> neteq_stats_getter(
1927 new test::NetEqStatsGetter(std::move(delay_cb)));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001928 test::DefaultNetEqTestErrorCallback error_cb;
1929 test::NetEqTest::Callbacks callbacks;
1930 callbacks.error_callback = &error_cb;
Minyue Lic6ff7572018-05-04 09:46:44 +02001931 callbacks.post_insert_packet = neteq_stats_getter->delay_analyzer();
1932 callbacks.get_audio_callback = neteq_stats_getter.get();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001933
Niels Möllerbd6dee82019-01-02 09:39:47 +01001934 test::NetEqTest test(config, decoder_factory, codecs, nullptr,
Niels Möller3f651d82018-12-19 15:06:17 +01001935 std::move(input), std::move(output), callbacks);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001936 test.Run();
Minyue Lic6ff7572018-05-04 09:46:44 +02001937 return neteq_stats_getter;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001938}
1939} // namespace
1940
Minyue Lic6ff7572018-05-04 09:46:44 +02001941EventLogAnalyzer::NetEqStatsGetterMap EventLogAnalyzer::SimulateNetEq(
henrik.lundin3c938fc2017-06-14 06:09:58 -07001942 const std::string& replacement_file_name,
Minyue Lic6ff7572018-05-04 09:46:44 +02001943 int file_sample_rate_hz) const {
1944 NetEqStatsGetterMap neteq_stats;
1945
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001946 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001947 const uint32_t ssrc = stream.ssrc;
1948 if (!IsAudioSsrc(kIncomingPacket, ssrc))
1949 continue;
1950 const std::vector<LoggedRtpPacketIncoming>* audio_packets =
1951 &stream.incoming_packets;
1952 if (audio_packets == nullptr) {
1953 // No incoming audio stream found.
1954 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001955 }
henrik.lundin3c938fc2017-06-14 06:09:58 -07001956
Minyue Li27e2b7d2018-05-07 15:20:24 +02001957 RTC_DCHECK(neteq_stats.find(ssrc) == neteq_stats.end());
1958
1959 std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>::const_iterator
1960 output_events_it = parsed_log_.audio_playout_events().find(ssrc);
1961 if (output_events_it == parsed_log_.audio_playout_events().end()) {
1962 // Could not find output events with SSRC matching the input audio stream.
1963 // Using the first available stream of output events.
1964 output_events_it = parsed_log_.audio_playout_events().cbegin();
1965 }
1966
Danil Chapovalov431abd92018-06-18 12:54:17 +02001967 absl::optional<int64_t> end_time_ms =
Minyue Li27e2b7d2018-05-07 15:20:24 +02001968 log_segments_.empty()
Danil Chapovalov431abd92018-06-18 12:54:17 +02001969 ? absl::nullopt
1970 : absl::optional<int64_t>(log_segments_.front().second / 1000);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001971
1972 neteq_stats[ssrc] = CreateNetEqTestAndRun(
1973 audio_packets, &output_events_it->second, end_time_ms,
1974 replacement_file_name, file_sample_rate_hz);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001975 }
1976
Minyue Lic6ff7572018-05-04 09:46:44 +02001977 return neteq_stats;
1978}
1979
Minyue Lic97933f2018-08-10 12:51:15 +02001980// Given a NetEqStatsGetter and the SSRC that the NetEqStatsGetter was created
1981// for, this method generates a plot for the jitter buffer delay profile.
Minyue Lic6ff7572018-05-04 09:46:44 +02001982void EventLogAnalyzer::CreateAudioJitterBufferGraph(
Minyue Li01d2a672018-06-21 21:17:19 +02001983 uint32_t ssrc,
1984 const test::NetEqStatsGetter* stats_getter,
Minyue Lic6ff7572018-05-04 09:46:44 +02001985 Plot* plot) const {
Minyue Li45fc6df2018-06-21 11:47:14 +02001986 test::NetEqDelayAnalyzer::Delays arrival_delay_ms;
1987 test::NetEqDelayAnalyzer::Delays corrected_arrival_delay_ms;
1988 test::NetEqDelayAnalyzer::Delays playout_delay_ms;
1989 test::NetEqDelayAnalyzer::Delays target_delay_ms;
1990
Minyue Li01d2a672018-06-21 21:17:19 +02001991 stats_getter->delay_analyzer()->CreateGraphs(
Minyue Li45fc6df2018-06-21 11:47:14 +02001992 &arrival_delay_ms, &corrected_arrival_delay_ms, &playout_delay_ms,
1993 &target_delay_ms);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001994
Minyue Lic97933f2018-08-10 12:51:15 +02001995 TimeSeries time_series_packet_arrival("packet arrival delay",
1996 LineStyle::kLine);
1997 TimeSeries time_series_relative_packet_arrival(
1998 "Relative packet arrival delay", LineStyle::kLine);
1999 TimeSeries time_series_play_time("Playout delay", LineStyle::kLine);
2000 TimeSeries time_series_target_time("Target delay", LineStyle::kLine,
2001 PointStyle::kHighlight);
Minyue Li45fc6df2018-06-21 11:47:14 +02002002
2003 for (const auto& data : arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002004 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002005 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002006 time_series_packet_arrival.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02002007 }
2008 for (const auto& data : corrected_arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002009 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002010 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002011 time_series_relative_packet_arrival.points.emplace_back(
Minyue Li45fc6df2018-06-21 11:47:14 +02002012 TimeSeriesPoint(x, y));
2013 }
2014 for (const auto& data : playout_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002015 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002016 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002017 time_series_play_time.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02002018 }
2019 for (const auto& data : target_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002020 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002021 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002022 time_series_target_time.points.emplace_back(TimeSeriesPoint(x, y));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002023 }
2024
Minyue Lic97933f2018-08-10 12:51:15 +02002025 plot->AppendTimeSeries(std::move(time_series_packet_arrival));
2026 plot->AppendTimeSeries(std::move(time_series_relative_packet_arrival));
2027 plot->AppendTimeSeries(std::move(time_series_play_time));
2028 plot->AppendTimeSeries(std::move(time_series_target_time));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002029
Bjorn Terelius068fc352019-02-13 22:38:25 +01002030 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2031 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02002032 plot->SetSuggestedYAxis(0, 1, "Relative delay (ms)", kBottomMargin,
2033 kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002034 plot->SetTitle("NetEq timing for " + GetStreamName(kIncomingPacket, ssrc));
2035}
2036
Minyue Lic9ac93f2018-06-26 13:01:32 +02002037template <typename NetEqStatsType>
2038void EventLogAnalyzer::CreateNetEqStatsGraphInternal(
Minyue Li27e2b7d2018-05-07 15:20:24 +02002039 const NetEqStatsGetterMap& neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +02002040 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
2041 const test::NetEqStatsGetter*)> data_extractor,
2042 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
Minyue Li27e2b7d2018-05-07 15:20:24 +02002043 const std::string& plot_name,
2044 Plot* plot) const {
Minyue Li27e2b7d2018-05-07 15:20:24 +02002045 std::map<uint32_t, TimeSeries> time_series;
Minyue Li27e2b7d2018-05-07 15:20:24 +02002046
2047 for (const auto& st : neteq_stats) {
2048 const uint32_t ssrc = st.first;
Minyue Lic9ac93f2018-06-26 13:01:32 +02002049 const std::vector<std::pair<int64_t, NetEqStatsType>>* data_vector =
2050 data_extractor(st.second.get());
2051 for (const auto& data : *data_vector) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002052 const float time =
2053 config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Lic9ac93f2018-06-26 13:01:32 +02002054 const float value = stats_extractor(data.second);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002055 time_series[ssrc].points.emplace_back(TimeSeriesPoint(time, value));
Minyue Li27e2b7d2018-05-07 15:20:24 +02002056 }
2057 }
2058
2059 for (auto& series : time_series) {
2060 series.second.label = GetStreamName(kIncomingPacket, series.first);
2061 series.second.line_style = LineStyle::kLine;
2062 plot->AppendTimeSeries(std::move(series.second));
2063 }
2064
Bjorn Terelius068fc352019-02-13 22:38:25 +01002065 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2066 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02002067 plot->SetSuggestedYAxis(0, 1, plot_name, kBottomMargin, kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002068 plot->SetTitle(plot_name);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002069}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002070
Minyue Lic9ac93f2018-06-26 13:01:32 +02002071void EventLogAnalyzer::CreateNetEqNetworkStatsGraph(
2072 const NetEqStatsGetterMap& neteq_stats,
2073 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
2074 const std::string& plot_name,
2075 Plot* plot) const {
2076 CreateNetEqStatsGraphInternal<NetEqNetworkStatistics>(
2077 neteq_stats,
2078 [](const test::NetEqStatsGetter* stats_getter) {
2079 return stats_getter->stats();
2080 },
2081 stats_extractor, plot_name, plot);
2082}
2083
2084void EventLogAnalyzer::CreateNetEqLifetimeStatsGraph(
2085 const NetEqStatsGetterMap& neteq_stats,
2086 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
2087 const std::string& plot_name,
2088 Plot* plot) const {
2089 CreateNetEqStatsGraphInternal<NetEqLifetimeStatistics>(
2090 neteq_stats,
2091 [](const test::NetEqStatsGetter* stats_getter) {
2092 return stats_getter->lifetime_stats();
2093 },
2094 stats_extractor, plot_name, plot);
2095}
2096
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002097void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
2098 std::map<uint32_t, TimeSeries> configs_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002099 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002100 if (configs_by_cp_id.find(config.candidate_pair_id) ==
2101 configs_by_cp_id.end()) {
2102 const std::string candidate_pair_desc =
2103 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08002104 configs_by_cp_id[config.candidate_pair_id] =
2105 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
2106 candidate_pair_desc,
2107 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002108 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2109 candidate_pair_desc;
2110 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002111 float x = config_.GetCallTimeSec(config.log_time_us());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002112 float y = static_cast<float>(config.type);
2113 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
2114 }
2115
2116 // TODO(qingsi): There can be a large number of candidate pairs generated by
2117 // certain calls and the frontend cannot render the chart in this case due to
2118 // the failure of generating a palette with the same number of colors.
2119 for (auto& kv : configs_by_cp_id) {
2120 plot->AppendTimeSeries(std::move(kv.second));
2121 }
2122
Bjorn Terelius068fc352019-02-13 22:38:25 +01002123 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2124 "Time (s)", kLeftMargin, kRightMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002125 plot->SetSuggestedYAxis(0, 3, "Numeric Config Type", kBottomMargin,
2126 kTopMargin);
2127 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
2128}
2129
2130std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
2131 uint32_t candidate_pair_id) {
2132 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
2133 candidate_pair_desc_by_id_.end()) {
2134 return candidate_pair_desc_by_id_[candidate_pair_id];
2135 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002136 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002137 // TODO(qingsi): Add the handling of the "Updated" config event after the
2138 // visualization of property change for candidate pairs is introduced.
2139 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
2140 candidate_pair_desc_by_id_.end()) {
2141 const std::string candidate_pair_desc =
2142 GetCandidatePairLogDescriptionAsString(config);
2143 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2144 candidate_pair_desc;
2145 }
2146 }
2147 return candidate_pair_desc_by_id_[candidate_pair_id];
2148}
2149
2150void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
2151 std::map<uint32_t, TimeSeries> checks_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002152 for (const auto& event : parsed_log_.ice_candidate_pair_events()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002153 if (checks_by_cp_id.find(event.candidate_pair_id) ==
2154 checks_by_cp_id.end()) {
2155 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08002156 "[" + std::to_string(event.candidate_pair_id) + "]" +
2157 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002158 LineStyle::kNone, PointStyle::kHighlight);
2159 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002160 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein6353fbc2018-12-03 14:35:59 -08002161 constexpr int kIceCandidatePairEventTypeOffset =
2162 static_cast<int>(IceCandidatePairConfigType::kNumValues);
2163 float y = static_cast<float>(event.type) + kIceCandidatePairEventTypeOffset;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002164 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
2165 }
2166
2167 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
2168 for (auto& kv : checks_by_cp_id) {
2169 plot->AppendTimeSeries(std::move(kv.second));
2170 }
2171
Bjorn Terelius068fc352019-02-13 22:38:25 +01002172 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2173 "Time (s)", kLeftMargin, kRightMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002174 plot->SetSuggestedYAxis(0, 4, "Numeric Connectivity State", kBottomMargin,
2175 kTopMargin);
2176 plot->SetTitle("[IceEventLog] ICE connectivity checks");
2177}
2178
Zach Stein10a58012018-12-07 12:26:28 -08002179void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) {
2180 TimeSeries states("DTLS Transport State", LineStyle::kNone,
2181 PointStyle::kHighlight);
2182 for (const auto& event : parsed_log_.dtls_transport_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002183 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002184 float y = static_cast<float>(event.dtls_transport_state);
2185 states.points.emplace_back(x, y);
2186 }
2187 plot->AppendTimeSeries(std::move(states));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002188 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2189 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002190 plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues),
2191 "Numeric Transport State", kBottomMargin, kTopMargin);
2192 plot->SetTitle("DTLS Transport State");
2193}
2194
2195void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) {
2196 TimeSeries writable("DTLS Writable", LineStyle::kNone,
2197 PointStyle::kHighlight);
2198 for (const auto& event : parsed_log_.dtls_writable_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002199 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002200 float y = static_cast<float>(event.writable);
2201 writable.points.emplace_back(x, y);
2202 }
2203 plot->AppendTimeSeries(std::move(writable));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002204 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2205 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002206 plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin);
2207 plot->SetTitle("DTLS Writable State");
2208}
2209
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002210void EventLogAnalyzer::PrintNotifications(FILE* file) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002211 fprintf(file, "========== TRIAGE NOTIFICATIONS ==========\n");
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002212 for (const auto& alert : incoming_rtp_recv_time_gaps_) {
2213 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2214 }
2215 for (const auto& alert : incoming_rtcp_recv_time_gaps_) {
2216 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2217 }
2218 for (const auto& alert : outgoing_rtp_send_time_gaps_) {
2219 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2220 }
2221 for (const auto& alert : outgoing_rtcp_send_time_gaps_) {
2222 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2223 }
2224 for (const auto& alert : incoming_seq_num_jumps_) {
2225 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2226 }
2227 for (const auto& alert : incoming_capture_time_jumps_) {
2228 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2229 }
2230 for (const auto& alert : outgoing_seq_num_jumps_) {
2231 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2232 }
2233 for (const auto& alert : outgoing_capture_time_jumps_) {
2234 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2235 }
2236 for (const auto& alert : outgoing_high_loss_alerts_) {
2237 fprintf(file, " : %s\n", alert.ToString().c_str());
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002238 }
2239 fprintf(file, "========== END TRIAGE NOTIFICATIONS ==========\n");
2240}
2241
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002242void EventLogAnalyzer::CreateStreamGapAlerts(PacketDirection direction) {
2243 // With 100 packets/s (~800kbps), false positives would require 10 s without
2244 // data.
2245 constexpr int64_t kMaxSeqNumJump = 1000;
2246 // With a 90 kHz clock, false positives would require 10 s without data.
2247 constexpr int64_t kMaxCaptureTimeJump = 900000;
2248
2249 int64_t end_time_us = log_segments_.empty()
2250 ? std::numeric_limits<int64_t>::max()
2251 : log_segments_.front().second;
2252
2253 SeqNumUnwrapper<uint16_t> seq_num_unwrapper;
Danil Chapovalov431abd92018-06-18 12:54:17 +02002254 absl::optional<int64_t> last_seq_num;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002255 SeqNumUnwrapper<uint32_t> capture_time_unwrapper;
Danil Chapovalov431abd92018-06-18 12:54:17 +02002256 absl::optional<int64_t> last_capture_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002257 // Check for gaps in sequence numbers and capture timestamps.
2258 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
2259 for (const auto& packet : stream.packet_view) {
2260 if (packet.log_time_us() > end_time_us) {
2261 // Only process the first (LOG_START, LOG_END) segment.
2262 break;
2263 }
2264
2265 int64_t seq_num = seq_num_unwrapper.Unwrap(packet.header.sequenceNumber);
2266 if (last_seq_num.has_value() &&
2267 std::abs(seq_num - last_seq_num.value()) > kMaxSeqNumJump) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002268 Alert_SeqNumJump(direction,
2269 config_.GetCallTimeSec(packet.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002270 packet.header.ssrc);
2271 }
2272 last_seq_num.emplace(seq_num);
2273
2274 int64_t capture_time =
2275 capture_time_unwrapper.Unwrap(packet.header.timestamp);
2276 if (last_capture_time.has_value() &&
2277 std::abs(capture_time - last_capture_time.value()) >
2278 kMaxCaptureTimeJump) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002279 Alert_CaptureTimeJump(direction,
2280 config_.GetCallTimeSec(packet.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002281 packet.header.ssrc);
2282 }
2283 last_capture_time.emplace(capture_time);
2284 }
2285 }
2286}
2287
2288void EventLogAnalyzer::CreateTransmissionGapAlerts(PacketDirection direction) {
2289 constexpr int64_t kMaxRtpTransmissionGap = 500000;
2290 constexpr int64_t kMaxRtcpTransmissionGap = 2000000;
2291 int64_t end_time_us = log_segments_.empty()
2292 ? std::numeric_limits<int64_t>::max()
2293 : log_segments_.front().second;
2294
2295 // TODO(terelius): The parser could provide a list of all packets, ordered
2296 // by time, for each direction.
2297 std::multimap<int64_t, const LoggedRtpPacket*> rtp_in_direction;
2298 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
2299 for (const LoggedRtpPacket& rtp_packet : stream.packet_view)
2300 rtp_in_direction.emplace(rtp_packet.log_time_us(), &rtp_packet);
2301 }
Danil Chapovalov431abd92018-06-18 12:54:17 +02002302 absl::optional<int64_t> last_rtp_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002303 for (const auto& kv : rtp_in_direction) {
2304 int64_t timestamp = kv.first;
2305 if (timestamp > end_time_us) {
2306 // Only process the first (LOG_START, LOG_END) segment.
2307 break;
2308 }
2309 int64_t duration = timestamp - last_rtp_time.value_or(0);
2310 if (last_rtp_time.has_value() && duration > kMaxRtpTransmissionGap) {
2311 // No packet sent/received for more than 500 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002312 Alert_RtpLogTimeGap(direction, config_.GetCallTimeSec(timestamp),
2313 duration / 1000);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002314 }
2315 last_rtp_time.emplace(timestamp);
2316 }
2317
Danil Chapovalov431abd92018-06-18 12:54:17 +02002318 absl::optional<int64_t> last_rtcp_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002319 if (direction == kIncomingPacket) {
2320 for (const auto& rtcp : parsed_log_.incoming_rtcp_packets()) {
2321 if (rtcp.log_time_us() > end_time_us) {
2322 // Only process the first (LOG_START, LOG_END) segment.
2323 break;
2324 }
2325 int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0);
2326 if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) {
2327 // No feedback sent/received for more than 2000 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002328 Alert_RtcpLogTimeGap(direction,
2329 config_.GetCallTimeSec(rtcp.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002330 duration / 1000);
2331 }
2332 last_rtcp_time.emplace(rtcp.log_time_us());
2333 }
2334 } else {
2335 for (const auto& rtcp : parsed_log_.outgoing_rtcp_packets()) {
2336 if (rtcp.log_time_us() > end_time_us) {
2337 // Only process the first (LOG_START, LOG_END) segment.
2338 break;
2339 }
2340 int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0);
2341 if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) {
2342 // No feedback sent/received for more than 2000 ms.
Bjorn Terelius068fc352019-02-13 22:38:25 +01002343 Alert_RtcpLogTimeGap(direction,
2344 config_.GetCallTimeSec(rtcp.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002345 duration / 1000);
2346 }
2347 last_rtcp_time.emplace(rtcp.log_time_us());
2348 }
2349 }
2350}
2351
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002352// TODO(terelius): Notifications could possibly be generated by the same code
2353// that produces the graphs. There is some code duplication that could be
2354// avoided, but that might be solved anyway when we move functionality from the
2355// analyzer to the parser.
2356void EventLogAnalyzer::CreateTriageNotifications() {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002357 CreateStreamGapAlerts(kIncomingPacket);
2358 CreateStreamGapAlerts(kOutgoingPacket);
2359 CreateTransmissionGapAlerts(kIncomingPacket);
2360 CreateTransmissionGapAlerts(kOutgoingPacket);
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002361
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002362 int64_t end_time_us = log_segments_.empty()
2363 ? std::numeric_limits<int64_t>::max()
2364 : log_segments_.front().second;
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002365
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002366 constexpr double kMaxLossFraction = 0.05;
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002367 // Loss feedback
2368 int64_t total_lost_packets = 0;
2369 int64_t total_expected_packets = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002370 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
2371 if (bwe_update.log_time_us() > end_time_us) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002372 // Only process the first (LOG_START, LOG_END) segment.
2373 break;
2374 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002375 int64_t lost_packets = static_cast<double>(bwe_update.fraction_lost) / 255 *
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002376 bwe_update.expected_packets;
2377 total_lost_packets += lost_packets;
2378 total_expected_packets += bwe_update.expected_packets;
2379 }
2380 double avg_outgoing_loss =
2381 static_cast<double>(total_lost_packets) / total_expected_packets;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002382 if (avg_outgoing_loss > kMaxLossFraction) {
2383 Alert_OutgoingHighLoss(avg_outgoing_loss);
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002384 }
2385}
2386
terelius54ce6802016-07-13 06:44:41 -07002387} // namespace webrtc