blob: 74acd62b58593f32dc07ba70e6b60ff287c13309 [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"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020021#include "api/transport/goog_cc_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "call/audio_receive_stream.h"
23#include "call/audio_send_stream.h"
24#include "call/call.h"
25#include "call/video_receive_stream.h"
26#include "call/video_send_stream.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020027#include "common_types.h" // NOLINT(build/include)
Elad Alon99a81b62017-09-21 10:25:29 +020028#include "logging/rtc_event_log/rtc_stream_config.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020029#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "modules/audio_coding/neteq/tools/audio_sink.h"
31#include "modules/audio_coding/neteq/tools/fake_decode_from_file.h"
32#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
33#include "modules/audio_coding/neteq/tools/neteq_replacement_input.h"
34#include "modules/audio_coding/neteq/tools/neteq_test.h"
35#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
Sebastian Jansson172fd852018-05-24 14:17:06 +020036#include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h"
37#include "modules/congestion_controller/goog_cc/bitrate_estimator.h"
Sebastian Jansson04b18cb2018-07-02 09:25:25 +020038#include "modules/congestion_controller/goog_cc/delay_based_bwe.h"
Bjorn Terelius28db2662017-10-04 14:22:43 +020039#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020040#include "modules/congestion_controller/rtp/transport_feedback_adapter.h"
Niels Möllerfd6c0912017-10-31 10:19:10 +010041#include "modules/pacing/packet_router.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020042#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020043#include "modules/rtp_rtcp/include/rtp_rtcp.h"
44#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020045#include "modules/rtp_rtcp/source/rtcp_packet.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
47#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
48#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
49#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
50#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
51#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
52#include "modules/rtp_rtcp/source/rtp_utility.h"
53#include "rtc_base/checks.h"
54#include "rtc_base/format_macros.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020055#include "rtc_base/function_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020056#include "rtc_base/logging.h"
Bjorn Terelius0295a962017-10-25 17:42:41 +020057#include "rtc_base/numerics/sequence_number_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020058#include "rtc_base/rate_statistics.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020059#include "rtc_base/strings/string_builder.h"
terelius54ce6802016-07-13 06:44:41 -070060
Bjorn Terelius6984ad22017-10-24 12:19:45 +020061#ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
62#define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0
63#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
64
tereliusdc35dcd2016-08-01 12:03:27 -070065namespace webrtc {
tereliusdc35dcd2016-08-01 12:03:27 -070066
terelius54ce6802016-07-13 06:44:41 -070067namespace {
68
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080069const int kNumMicrosecsPerSec = 1000000;
70
elad.alonec304f92017-03-08 05:03:53 -080071void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
72 auto pred = [](const PacketFeedback& packet_feedback) {
73 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
74 };
75 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
76 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
77}
78
terelius54ce6802016-07-13 06:44:41 -070079std::string SsrcToString(uint32_t ssrc) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020080 rtc::StringBuilder ss;
terelius54ce6802016-07-13 06:44:41 -070081 ss << "SSRC " << ssrc;
Jonas Olsson84df1c72018-09-14 16:59:32 +020082 return ss.Release();
terelius54ce6802016-07-13 06:44:41 -070083}
84
85// Checks whether an SSRC is contained in the list of desired SSRCs.
86// Note that an empty SSRC list matches every SSRC.
87bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
88 if (desired_ssrc.size() == 0)
89 return true;
90 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
91 desired_ssrc.end();
92}
93
94double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
95 // The timestamp is a fixed point representation with 6 bits for seconds
96 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080097 // time in seconds and then multiply by kNumMicrosecsPerSec to convert to
98 // microseconds.
terelius54ce6802016-07-13 06:44:41 -070099 static constexpr double kTimestampToMicroSec =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800100 static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -0700101 return abs_send_time * kTimestampToMicroSec;
102}
103
104// Computes the difference |later| - |earlier| where |later| and |earlier|
105// are counters that wrap at |modulus|. The difference is chosen to have the
106// least absolute value. For example if |modulus| is 8, then the difference will
107// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
108// be in [-4, 4].
109int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
110 RTC_DCHECK_LE(1, modulus);
111 RTC_DCHECK_LT(later, modulus);
112 RTC_DCHECK_LT(earlier, modulus);
113 int64_t difference =
114 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
115 int64_t max_difference = modulus / 2;
116 int64_t min_difference = max_difference - modulus + 1;
117 if (difference > max_difference) {
118 difference -= modulus;
119 }
120 if (difference < min_difference) {
121 difference += modulus;
122 }
terelius6addf492016-08-23 17:34:07 -0700123 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100124 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
125 << " expected to be in the range ("
126 << min_difference / 2 << "," << max_difference / 2
127 << ") but is " << difference
128 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700129 }
terelius54ce6802016-07-13 06:44:41 -0700130 return difference;
131}
132
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200133// This is much more reliable for outgoing streams than for incoming streams.
134template <typename RtpPacketContainer>
Danil Chapovalov431abd92018-06-18 12:54:17 +0200135absl::optional<uint32_t> EstimateRtpClockFrequency(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200136 const RtpPacketContainer& packets,
137 int64_t end_time_us) {
138 RTC_CHECK(packets.size() >= 2);
139 SeqNumUnwrapper<uint32_t> unwrapper;
140 uint64_t first_rtp_timestamp =
141 unwrapper.Unwrap(packets[0].rtp.header.timestamp);
142 int64_t first_log_timestamp = packets[0].log_time_us();
143 uint64_t last_rtp_timestamp = first_rtp_timestamp;
144 int64_t last_log_timestamp = first_log_timestamp;
145 for (size_t i = 1; i < packets.size(); i++) {
146 if (packets[i].log_time_us() > end_time_us)
147 break;
148 last_rtp_timestamp = unwrapper.Unwrap(packets[i].rtp.header.timestamp);
149 last_log_timestamp = packets[i].log_time_us();
150 }
151 if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) {
152 RTC_LOG(LS_WARNING)
153 << "Failed to estimate RTP clock frequency: Stream too short. ("
154 << packets.size() << " packets, "
155 << last_log_timestamp - first_log_timestamp << " us)";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200156 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200157 }
158 double duration =
159 static_cast<double>(last_log_timestamp - first_log_timestamp) /
160 kNumMicrosecsPerSec;
161 double estimated_frequency =
162 (last_rtp_timestamp - first_rtp_timestamp) / duration;
163 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
164 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
165 return f;
166 }
167 }
168 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
169 << estimated_frequency
170 << "not close to any stardard RTP frequency.";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200171 return absl::nullopt;
ivocaac9d6f2016-09-22 07:01:47 -0700172}
173
tereliusdc35dcd2016-08-01 12:03:27 -0700174constexpr float kLeftMargin = 0.01f;
175constexpr float kRightMargin = 0.02f;
176constexpr float kBottomMargin = 0.02f;
177constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700178
Danil Chapovalov431abd92018-06-18 12:54:17 +0200179absl::optional<double> NetworkDelayDiff_AbsSendTime(
terelius53dc23c2017-03-13 05:24:05 -0700180 const LoggedRtpPacket& old_packet,
181 const LoggedRtpPacket& new_packet) {
182 if (old_packet.header.extension.hasAbsoluteSendTime &&
183 new_packet.header.extension.hasAbsoluteSendTime) {
184 int64_t send_time_diff = WrappingDifference(
185 new_packet.header.extension.absoluteSendTime,
186 old_packet.header.extension.absoluteSendTime, 1ul << 24);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200187 int64_t recv_time_diff =
188 new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700189 double delay_change_us =
190 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100191 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700192 } else {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200193 return absl::nullopt;
terelius6addf492016-08-23 17:34:07 -0700194 }
195}
196
Danil Chapovalov431abd92018-06-18 12:54:17 +0200197absl::optional<double> NetworkDelayDiff_CaptureTime(
terelius53dc23c2017-03-13 05:24:05 -0700198 const LoggedRtpPacket& old_packet,
199 const LoggedRtpPacket& new_packet) {
200 int64_t send_time_diff = WrappingDifference(
201 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200202 int64_t recv_time_diff = new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700203
204 const double kVideoSampleRate = 90000;
205 // TODO(terelius): We treat all streams as video for now, even though
206 // audio might be sampled at e.g. 16kHz, because it is really difficult to
207 // figure out the true sampling rate of a stream. The effect is that the
208 // delay will be scaled incorrectly for non-video streams.
209
210 double delay_change =
211 static_cast<double>(recv_time_diff) / 1000 -
212 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
213 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100214 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
215 RTC_LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200216 << ", received time " << old_packet.log_time_us();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100217 RTC_LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200218 << ", received time " << new_packet.log_time_us();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100219 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800220 << static_cast<double>(recv_time_diff) /
221 kNumMicrosecsPerSec
222 << "s";
Mirko Bonadei675513b2017-11-09 11:09:25 +0100223 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
224 << static_cast<double>(send_time_diff) /
225 kVideoSampleRate
226 << "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]);
terelius53dc23c2017-03-13 05:24:05 -0700279 if (y)
280 sum += *y;
281 result->points.emplace_back(x, static_cast<float>(sum));
tereliusccbbf8d2016-08-10 07:34:28 -0700282 }
283}
284
terelius6addf492016-08-23 17:34:07 -0700285// Calculates a moving average of |data| and stores the result in a TimeSeries.
286// A data point is generated every |step| microseconds from |begin_time|
287// to |end_time|. The value of each data point is the average of the data
288// during the preceeding |window_duration_us| microseconds.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200289template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700290void MovingAverage(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200291 rtc::FunctionView<float(int64_t)> fx,
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,
294 int64_t begin_time,
295 int64_t end_time,
296 int64_t window_duration_us,
297 int64_t step,
298 TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700299 size_t window_index_begin = 0;
300 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700301 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700302
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200303 for (int64_t t = begin_time; t < end_time + step; t += step) {
304 while (window_index_end < data_view.size() &&
305 data_view[window_index_end].log_time_us() < t) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200306 absl::optional<ResultType> value = fy(data_view[window_index_end]);
terelius53dc23c2017-03-13 05:24:05 -0700307 if (value)
308 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700309 ++window_index_end;
310 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200311 while (window_index_begin < data_view.size() &&
312 data_view[window_index_begin].log_time_us() <
313 t - window_duration_us) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200314 absl::optional<ResultType> value = fy(data_view[window_index_begin]);
terelius53dc23c2017-03-13 05:24:05 -0700315 if (value)
316 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700317 ++window_index_begin;
318 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800319 float window_duration_s =
320 static_cast<float>(window_duration_us) / kNumMicrosecsPerSec;
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200321 float x = fx(t);
terelius53dc23c2017-03-13 05:24:05 -0700322 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700323 result->points.emplace_back(x, y);
324 }
325}
326
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800327const char kUnknownEnumValue[] = "unknown";
328
329const char kIceCandidateTypeLocal[] = "local";
330const char kIceCandidateTypeStun[] = "stun";
331const char kIceCandidateTypePrflx[] = "prflx";
332const char kIceCandidateTypeRelay[] = "relay";
333
334const char kProtocolUdp[] = "udp";
335const char kProtocolTcp[] = "tcp";
336const char kProtocolSsltcp[] = "ssltcp";
337const char kProtocolTls[] = "tls";
338
339const char kAddressFamilyIpv4[] = "ipv4";
340const char kAddressFamilyIpv6[] = "ipv6";
341
342const char kNetworkTypeEthernet[] = "ethernet";
343const char kNetworkTypeLoopback[] = "loopback";
344const char kNetworkTypeWifi[] = "wifi";
345const char kNetworkTypeVpn[] = "vpn";
346const char kNetworkTypeCellular[] = "cellular";
347
348std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) {
349 switch (type) {
350 case webrtc::IceCandidateType::kLocal:
351 return kIceCandidateTypeLocal;
352 case webrtc::IceCandidateType::kStun:
353 return kIceCandidateTypeStun;
354 case webrtc::IceCandidateType::kPrflx:
355 return kIceCandidateTypePrflx;
356 case webrtc::IceCandidateType::kRelay:
357 return kIceCandidateTypeRelay;
358 default:
359 return kUnknownEnumValue;
360 }
361}
362
363std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) {
364 switch (protocol) {
365 case webrtc::IceCandidatePairProtocol::kUdp:
366 return kProtocolUdp;
367 case webrtc::IceCandidatePairProtocol::kTcp:
368 return kProtocolTcp;
369 case webrtc::IceCandidatePairProtocol::kSsltcp:
370 return kProtocolSsltcp;
371 case webrtc::IceCandidatePairProtocol::kTls:
372 return kProtocolTls;
373 default:
374 return kUnknownEnumValue;
375 }
376}
377
378std::string GetAddressFamilyAsString(
379 webrtc::IceCandidatePairAddressFamily family) {
380 switch (family) {
381 case webrtc::IceCandidatePairAddressFamily::kIpv4:
382 return kAddressFamilyIpv4;
383 case webrtc::IceCandidatePairAddressFamily::kIpv6:
384 return kAddressFamilyIpv6;
385 default:
386 return kUnknownEnumValue;
387 }
388}
389
390std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) {
391 switch (type) {
392 case webrtc::IceCandidateNetworkType::kEthernet:
393 return kNetworkTypeEthernet;
394 case webrtc::IceCandidateNetworkType::kLoopback:
395 return kNetworkTypeLoopback;
396 case webrtc::IceCandidateNetworkType::kWifi:
397 return kNetworkTypeWifi;
398 case webrtc::IceCandidateNetworkType::kVpn:
399 return kNetworkTypeVpn;
400 case webrtc::IceCandidateNetworkType::kCellular:
401 return kNetworkTypeCellular;
402 default:
403 return kUnknownEnumValue;
404 }
405}
406
407std::string GetCandidatePairLogDescriptionAsString(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200408 const LoggedIceCandidatePairConfig& config) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800409 // Example: stun:wifi->relay(tcp):cellular@udp:ipv4
410 // represents a pair of a local server-reflexive candidate on a WiFi network
411 // and a remote relay candidate using TCP as the relay protocol on a cell
412 // network, when the candidate pair communicates over UDP using IPv4.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200413 rtc::StringBuilder ss;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800414 std::string local_candidate_type =
415 GetIceCandidateTypeAsString(config.local_candidate_type);
416 std::string remote_candidate_type =
417 GetIceCandidateTypeAsString(config.remote_candidate_type);
418 if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) {
419 local_candidate_type +=
420 "(" + GetProtocolAsString(config.local_relay_protocol) + ")";
421 }
422 ss << local_candidate_type << ":"
423 << GetNetworkTypeAsString(config.local_network_type) << ":"
424 << GetAddressFamilyAsString(config.local_address_family) << "->"
425 << remote_candidate_type << ":"
426 << GetAddressFamilyAsString(config.remote_address_family) << "@"
427 << GetProtocolAsString(config.candidate_pair_protocol);
Jonas Olsson84df1c72018-09-14 16:59:32 +0200428 return ss.Release();
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800429}
430
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200431std::string GetDirectionAsString(PacketDirection direction) {
432 if (direction == kIncomingPacket) {
433 return "Incoming";
434 } else {
435 return "Outgoing";
436 }
437}
438
439std::string GetDirectionAsShortString(PacketDirection direction) {
440 if (direction == kIncomingPacket) {
441 return "In";
442 } else {
443 return "Out";
444 }
445}
446
terelius54ce6802016-07-13 06:44:41 -0700447} // namespace
448
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200449EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLogNew& log,
450 bool normalize_time)
451 : parsed_log_(log),
452 window_duration_(250000),
453 step_(10000),
454 normalize_time_(normalize_time) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200455 begin_time_ = parsed_log_.first_timestamp();
456 end_time_ = parsed_log_.last_timestamp();
457 if (end_time_ < begin_time_) {
458 RTC_LOG(LS_WARNING) << "No useful events in the log.";
459 begin_time_ = end_time_ = 0;
Björn Tereliusff612732018-04-25 14:23:01 +0000460 }
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200461 call_duration_s_ = ToCallTimeSec(end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200462
463 const auto& log_start_events = parsed_log_.start_log_events();
464 const auto& log_end_events = parsed_log_.stop_log_events();
465 auto start_iter = log_start_events.begin();
466 auto end_iter = log_end_events.begin();
467 while (start_iter != log_start_events.end()) {
468 int64_t start = start_iter->log_time_us();
469 ++start_iter;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200470 absl::optional<int64_t> next_start;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200471 if (start_iter != log_start_events.end())
472 next_start.emplace(start_iter->log_time_us());
473 if (end_iter != log_end_events.end() &&
474 end_iter->log_time_us() <=
475 next_start.value_or(std::numeric_limits<int64_t>::max())) {
476 int64_t end = end_iter->log_time_us();
477 RTC_DCHECK_LE(start, end);
478 log_segments_.push_back(std::make_pair(start, end));
479 ++end_iter;
480 } else {
481 // we're missing an end event. Assume that it occurred just before the
482 // next start.
483 log_segments_.push_back(
484 std::make_pair(start, next_start.value_or(end_time_)));
485 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700486 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100487 RTC_LOG(LS_INFO) << "Found " << log_segments_.size()
Yves Gerey665174f2018-06-19 15:03:05 +0200488 << " (LOG_START, LOG_END) segments in log.";
terelius54ce6802016-07-13 06:44:41 -0700489}
490
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200491class BitrateObserver : public RemoteBitrateObserver {
Stefan Holmer13181032016-07-29 14:48:54 +0200492 public:
493 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
494
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200495 void Update(NetworkControlUpdate update) {
496 if (update.target_rate) {
497 last_bitrate_bps_ = update.target_rate->target_rate.bps();
498 bitrate_updated_ = true;
499 }
Stefan Holmer13181032016-07-29 14:48:54 +0200500 }
501
502 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
503 uint32_t bitrate) override {}
504
505 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
506 bool GetAndResetBitrateUpdated() {
507 bool bitrate_updated = bitrate_updated_;
508 bitrate_updated_ = false;
509 return bitrate_updated;
510 }
511
512 private:
513 uint32_t last_bitrate_bps_;
514 bool bitrate_updated_;
515};
516
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200517int64_t EventLogAnalyzer::ToCallTimeUs(int64_t timestamp) const {
518 int64_t begin_time = 0;
519 if (normalize_time_) {
520 begin_time = begin_time_;
521 }
522 return timestamp - begin_time;
523}
524
525float EventLogAnalyzer::ToCallTimeSec(int64_t timestamp) const {
526 return static_cast<float>(ToCallTimeUs(timestamp)) / kNumMicrosecsPerSec;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100527}
528
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200529void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction,
terelius54ce6802016-07-13 06:44:41 -0700530 Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200531 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
532 // Filter on SSRC.
533 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700534 continue;
terelius54ce6802016-07-13 06:44:41 -0700535 }
terelius54ce6802016-07-13 06:44:41 -0700536
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200537 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
538 LineStyle::kBar);
539 auto GetPacketSize = [](const LoggedRtpPacket& packet) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200540 return absl::optional<float>(packet.total_length);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200541 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200542 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
543 return this->ToCallTimeSec(packet.log_time_us());
544 };
545 ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize,
546 stream.packet_view, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700547 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700548 }
549
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200550 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
551 kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700552 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
553 kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200554 plot->SetTitle(GetDirectionAsString(direction) + " RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700555}
556
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200557template <typename IterableType>
philipelccd74892016-09-05 02:46:25 -0700558void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
philipelccd74892016-09-05 02:46:25 -0700559 Plot* plot,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200560 const IterableType& packets,
561 const std::string& label) {
562 TimeSeries time_series(label, LineStyle::kStep);
563 for (size_t i = 0; i < packets.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200564 float x = ToCallTimeSec(packets[i].log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200565 time_series.points.emplace_back(x, i + 1);
philipelccd74892016-09-05 02:46:25 -0700566 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200567 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700568}
569
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200570void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction,
571 Plot* plot) {
572 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
573 if (!MatchingSsrc(stream.ssrc, desired_ssrc_))
574 continue;
575 std::string label =
576 std::string("RTP ") + GetStreamName(direction, stream.ssrc);
577 CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label);
578 }
579 std::string label =
580 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")";
581 if (direction == kIncomingPacket) {
582 CreateAccumulatedPacketsTimeSeries(
583 plot, parsed_log_.incoming_rtcp_packets(), label);
584 } else {
585 CreateAccumulatedPacketsTimeSeries(
586 plot, parsed_log_.outgoing_rtcp_packets(), label);
587 }
philipelccd74892016-09-05 02:46:25 -0700588
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200589 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
590 kLeftMargin, kRightMargin);
philipelccd74892016-09-05 02:46:25 -0700591 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200592 plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) +
593 " RTP/RTCP packets");
philipelccd74892016-09-05 02:46:25 -0700594}
595
terelius54ce6802016-07-13 06:44:41 -0700596// For each SSRC, plot the time between the consecutive playouts.
597void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200598 for (const auto& playout_stream : parsed_log_.audio_playout_events()) {
599 uint32_t ssrc = playout_stream.first;
600 if (!MatchingSsrc(ssrc, desired_ssrc_))
601 continue;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200602 absl::optional<int64_t> last_playout_ms;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200603 TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar);
Minyue Li27e2b7d2018-05-07 15:20:24 +0200604 for (const auto& playout_event : playout_stream.second) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200605 float x = ToCallTimeSec(playout_event.log_time_us());
Minyue Li27e2b7d2018-05-07 15:20:24 +0200606 int64_t playout_time_ms = playout_event.log_time_ms();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200607 // If there were no previous playouts, place the point on the x-axis.
Minyue Li27e2b7d2018-05-07 15:20:24 +0200608 float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200609 time_series.points.push_back(TimeSeriesPoint(x, y));
Minyue Li27e2b7d2018-05-07 15:20:24 +0200610 last_playout_ms.emplace(playout_time_ms);
terelius54ce6802016-07-13 06:44:41 -0700611 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200612 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700613 }
614
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200615 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
616 kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700617 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
618 kTopMargin);
619 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700620}
621
ivocaac9d6f2016-09-22 07:01:47 -0700622// For audio SSRCs, plot the audio level.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200623void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction,
624 Plot* plot) {
625 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
626 if (!IsAudioSsrc(direction, stream.ssrc))
627 continue;
628 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
629 LineStyle::kLine);
630 for (auto& packet : stream.packet_view) {
ivocaac9d6f2016-09-22 07:01:47 -0700631 if (packet.header.extension.hasAudioLevel) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200632 float x = ToCallTimeSec(packet.log_time_us());
ivocaac9d6f2016-09-22 07:01:47 -0700633 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
634 // Here we convert it to dBov.
635 float y = static_cast<float>(-packet.header.extension.audioLevel);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200636 time_series.points.emplace_back(TimeSeriesPoint(x, y));
ivocaac9d6f2016-09-22 07:01:47 -0700637 }
638 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200639 plot->AppendTimeSeries(std::move(time_series));
ivocaac9d6f2016-09-22 07:01:47 -0700640 }
641
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200642 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
643 kLeftMargin, kRightMargin);
Yves Gerey665174f2018-06-19 15:03:05 +0200644 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200645 plot->SetTitle(GetDirectionAsString(direction) + " audio level");
ivocaac9d6f2016-09-22 07:01:47 -0700646}
647
terelius54ce6802016-07-13 06:44:41 -0700648// For each SSRC, plot the time between the consecutive playouts.
649void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200650 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
651 // Filter on SSRC.
652 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700653 continue;
terelius54ce6802016-07-13 06:44:41 -0700654 }
terelius54ce6802016-07-13 06:44:41 -0700655
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200656 TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc),
657 LineStyle::kBar);
658 auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet,
659 const LoggedRtpPacketIncoming& new_packet) {
660 int64_t diff =
661 WrappingDifference(new_packet.rtp.header.sequenceNumber,
662 old_packet.rtp.header.sequenceNumber, 1ul << 16);
663 return diff;
664 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200665 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
666 return this->ToCallTimeSec(packet.log_time_us());
667 };
668 ProcessPairs<LoggedRtpPacketIncoming, float>(
669 ToCallTime, GetSequenceNumberDiff, stream.incoming_packets,
670 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700671 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700672 }
673
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200674 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
675 kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700676 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
677 kTopMargin);
678 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700679}
680
Stefan Holmer99f8e082016-09-09 13:37:50 +0200681void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200682 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
683 const std::vector<LoggedRtpPacketIncoming>& packets =
684 stream.incoming_packets;
685 // Filter on SSRC.
686 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200687 continue;
688 }
689
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200690 TimeSeries time_series(GetStreamName(kIncomingPacket, stream.ssrc),
691 LineStyle::kLine, PointStyle::kHighlight);
692 // TODO(terelius): Should the window and step size be read from the class
693 // instead?
694 const int64_t kWindowUs = 1000000;
695 const int64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100696 SeqNumUnwrapper<uint16_t> unwrapper_;
697 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800698 size_t window_index_begin = 0;
699 size_t window_index_end = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200700 uint64_t highest_seq_number =
701 unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
702 uint64_t highest_prior_seq_number =
703 prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
terelius4c9b4af2017-01-30 08:44:51 -0800704
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200705 for (int64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
706 while (window_index_end < packets.size() &&
707 packets[window_index_end].rtp.log_time_us() < t) {
708 uint64_t sequence_number = unwrapper_.Unwrap(
709 packets[window_index_end].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800710 highest_seq_number = std::max(highest_seq_number, sequence_number);
711 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200712 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200713 while (window_index_begin < packets.size() &&
714 packets[window_index_begin].rtp.log_time_us() < t - kWindowUs) {
715 uint64_t sequence_number = prior_unwrapper_.Unwrap(
716 packets[window_index_begin].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800717 highest_prior_seq_number =
718 std::max(highest_prior_seq_number, sequence_number);
719 ++window_index_begin;
720 }
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200721 float x = ToCallTimeSec(t);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200722 uint64_t expected_packets = highest_seq_number - highest_prior_seq_number;
terelius4c9b4af2017-01-30 08:44:51 -0800723 if (expected_packets > 0) {
724 int64_t received_packets = window_index_end - window_index_begin;
725 int64_t lost_packets = expected_packets - received_packets;
726 float y = static_cast<float>(lost_packets) / expected_packets * 100;
727 time_series.points.emplace_back(x, y);
728 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200729 }
philipel35ba9bd2017-04-19 05:58:51 -0700730 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200731 }
732
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200733 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
734 kLeftMargin, kRightMargin);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200735 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
736 kTopMargin);
737 plot->SetTitle("Estimated incoming loss rate");
738}
739
terelius2ee076d2017-08-15 02:04:02 -0700740void EventLogAnalyzer::CreateIncomingDelayDeltaGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200741 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(kIncomingPacket)) {
742 // Filter on SSRC.
743 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
744 IsAudioSsrc(kIncomingPacket, stream.ssrc) ||
745 !IsVideoSsrc(kIncomingPacket, stream.ssrc) ||
746 IsRtxSsrc(kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700747 continue;
748 }
terelius54ce6802016-07-13 06:44:41 -0700749
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200750 TimeSeries capture_time_data(
751 GetStreamName(kIncomingPacket, stream.ssrc) + " capture-time",
752 LineStyle::kBar);
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200753 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
754 return this->ToCallTimeSec(packet.log_time_us());
755 };
756 ProcessPairs<LoggedRtpPacket, double>(
757 ToCallTime, NetworkDelayDiff_CaptureTime, stream.packet_view,
758 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700759 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700760
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200761 TimeSeries send_time_data(
762 GetStreamName(kIncomingPacket, stream.ssrc) + " abs-send-time",
763 LineStyle::kBar);
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200764 ProcessPairs<LoggedRtpPacket, double>(ToCallTime,
765 NetworkDelayDiff_AbsSendTime,
766 stream.packet_view, &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700767 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700768 }
769
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200770 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
771 kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700772 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
773 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700774 plot->SetTitle("Network latency difference between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700775}
776
terelius2ee076d2017-08-15 02:04:02 -0700777void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200778 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(kIncomingPacket)) {
779 // Filter on SSRC.
780 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
781 IsAudioSsrc(kIncomingPacket, stream.ssrc) ||
782 !IsVideoSsrc(kIncomingPacket, stream.ssrc) ||
783 IsRtxSsrc(kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700784 continue;
785 }
terelius54ce6802016-07-13 06:44:41 -0700786
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200787 TimeSeries capture_time_data(
788 GetStreamName(kIncomingPacket, stream.ssrc) + " capture-time",
789 LineStyle::kLine);
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200790 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
791 return this->ToCallTimeSec(packet.log_time_us());
792 };
793 AccumulatePairs<LoggedRtpPacket, double>(
794 ToCallTime, NetworkDelayDiff_CaptureTime, stream.packet_view,
795 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700796 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700797
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200798 TimeSeries send_time_data(
799 GetStreamName(kIncomingPacket, stream.ssrc) + " abs-send-time",
800 LineStyle::kLine);
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200801 AccumulatePairs<LoggedRtpPacket, double>(
802 ToCallTime, NetworkDelayDiff_AbsSendTime, stream.packet_view,
803 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700804 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700805 }
806
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200807 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
808 kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700809 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
810 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700811 plot->SetTitle("Network latency (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700812}
813
tereliusf736d232016-08-04 10:00:11 -0700814// Plot the fraction of packets lost (as perceived by the loss-based BWE).
815void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100816 TimeSeries time_series("Fraction lost", LineStyle::kLine,
817 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200818 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200819 float x = ToCallTimeSec(bwe_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200820 float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700821 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700822 }
tereliusf736d232016-08-04 10:00:11 -0700823
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200824 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200825 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
826 kLeftMargin, kRightMargin);
tereliusf736d232016-08-04 10:00:11 -0700827 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
828 kTopMargin);
829 plot->SetTitle("Reported packet loss");
830}
831
terelius54ce6802016-07-13 06:44:41 -0700832// Plot the total bandwidth used by all RTP streams.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200833void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) {
834 // TODO(terelius): This could be provided by the parser.
835 std::multimap<int64_t, size_t> packets_in_order;
836 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
837 for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets)
838 packets_in_order.insert(
839 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
terelius54ce6802016-07-13 06:44:41 -0700840 }
841
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200842 auto window_begin = packets_in_order.begin();
843 auto window_end = packets_in_order.begin();
terelius54ce6802016-07-13 06:44:41 -0700844 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700845
846 // Calculate a moving average of the bitrate and store in a TimeSeries.
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100847 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200848 for (int64_t time = begin_time_; time < end_time_ + step_; time += step_) {
849 while (window_end != packets_in_order.end() && window_end->first < time) {
850 bytes_in_window += window_end->second;
851 ++window_end;
terelius54ce6802016-07-13 06:44:41 -0700852 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200853 while (window_begin != packets_in_order.end() &&
854 window_begin->first < time - window_duration_) {
855 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
856 bytes_in_window -= window_begin->second;
857 ++window_begin;
858 }
859 float window_duration_in_seconds =
860 static_cast<float>(window_duration_) / kNumMicrosecsPerSec;
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200861 float x = ToCallTimeSec(time);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200862 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
863 bitrate_series.points.emplace_back(x, y);
864 }
865 plot->AppendTimeSeries(std::move(bitrate_series));
866
867 // Overlay the outgoing REMB over incoming bitrate.
868 TimeSeries remb_series("Remb", LineStyle::kStep);
869 for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200870 float x = ToCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200871 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
872 remb_series.points.emplace_back(x, y);
873 }
874 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
875
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200876 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
877 kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200878 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
879 plot->SetTitle("Incoming RTP bitrate");
880}
881
882// Plot the total bandwidth used by all RTP streams.
883void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
884 bool show_detector_state,
885 bool show_alr_state) {
886 // TODO(terelius): This could be provided by the parser.
887 std::multimap<int64_t, size_t> packets_in_order;
888 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
889 for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets)
890 packets_in_order.insert(
891 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
892 }
893
894 auto window_begin = packets_in_order.begin();
895 auto window_end = packets_in_order.begin();
896 size_t bytes_in_window = 0;
897
898 // Calculate a moving average of the bitrate and store in a TimeSeries.
899 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
900 for (int64_t time = begin_time_; time < end_time_ + step_; time += step_) {
901 while (window_end != packets_in_order.end() && window_end->first < time) {
902 bytes_in_window += window_end->second;
903 ++window_end;
904 }
905 while (window_begin != packets_in_order.end() &&
906 window_begin->first < time - window_duration_) {
907 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
908 bytes_in_window -= window_begin->second;
909 ++window_begin;
terelius54ce6802016-07-13 06:44:41 -0700910 }
911 float window_duration_in_seconds =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800912 static_cast<float>(window_duration_) / kNumMicrosecsPerSec;
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200913 float x = ToCallTimeSec(time);
terelius54ce6802016-07-13 06:44:41 -0700914 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700915 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700916 }
philipel35ba9bd2017-04-19 05:58:51 -0700917 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700918
terelius8058e582016-07-25 01:32:41 -0700919 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200920 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
921 for (auto& loss_update : parsed_log_.bwe_loss_updates()) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200922 float x = ToCallTimeSec(loss_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200923 float y = static_cast<float>(loss_update.bitrate_bps) / 1000;
924 loss_series.points.emplace_back(x, y);
925 }
philipel10fc0e62017-04-11 01:50:23 -0700926
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200927 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
928 IntervalSeries overusing_series("Overusing", "#ff8e82",
929 IntervalSeries::kHorizontal);
930 IntervalSeries underusing_series("Underusing", "#5092fc",
931 IntervalSeries::kHorizontal);
932 IntervalSeries normal_series("Normal", "#c4ffc4",
933 IntervalSeries::kHorizontal);
934 IntervalSeries* last_series = &normal_series;
935 double last_detector_switch = 0.0;
philipel23c7f252017-07-14 06:30:03 -0700936
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200937 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
philipel23c7f252017-07-14 06:30:03 -0700938
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200939 for (auto& delay_update : parsed_log_.bwe_delay_updates()) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200940 float x = ToCallTimeSec(delay_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200941 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -0700942
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200943 if (last_detector_state != delay_update.detector_state) {
944 last_series->intervals.emplace_back(last_detector_switch, x);
945 last_detector_state = delay_update.detector_state;
946 last_detector_switch = x;
philipel23c7f252017-07-14 06:30:03 -0700947
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200948 switch (delay_update.detector_state) {
949 case BandwidthUsage::kBwNormal:
950 last_series = &normal_series;
951 break;
952 case BandwidthUsage::kBwUnderusing:
953 last_series = &underusing_series;
954 break;
955 case BandwidthUsage::kBwOverusing:
956 last_series = &overusing_series;
957 break;
958 case BandwidthUsage::kLast:
959 RTC_NOTREACHED();
philipele127e7a2017-03-29 16:28:53 +0200960 }
961 }
philipel23c7f252017-07-14 06:30:03 -0700962
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200963 delay_series.points.emplace_back(x, y);
964 }
Bjorn Terelius9e336ec2018-04-24 16:28:35 +0200965
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200966 RTC_CHECK(last_series);
967 last_series->intervals.emplace_back(last_detector_switch, end_time_);
968
969 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
970 PointStyle::kHighlight);
971 for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200972 float x = ToCallTimeSec(cluster.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200973 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
974 created_series.points.emplace_back(x, y);
975 }
976
977 TimeSeries result_series("Probing results.", LineStyle::kNone,
978 PointStyle::kHighlight);
Bjorn Terelius7a0bb002018-05-29 14:45:53 +0200979 for (auto& result : parsed_log_.bwe_probe_success_events()) {
980 float x = ToCallTimeSec(result.log_time_us());
981 float y = static_cast<float>(result.bitrate_bps) / 1000;
982 result_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200983 }
984
985 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
986 bool previously_in_alr = false;
987 int64_t alr_start = 0;
988 for (auto& alr : parsed_log_.alr_state_events()) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200989 float y = ToCallTimeSec(alr.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200990 if (!previously_in_alr && alr.in_alr) {
991 alr_start = alr.log_time_us();
992 previously_in_alr = true;
993 } else if (previously_in_alr && !alr.in_alr) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200994 float x = ToCallTimeSec(alr_start);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100995 alr_state.intervals.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200996 previously_in_alr = false;
Björn Tereliusff612732018-04-25 14:23:01 +0000997 }
Björn Tereliusff612732018-04-25 14:23:01 +0000998 }
999
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001000 if (previously_in_alr) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001001 float x = ToCallTimeSec(alr_start);
1002 float y = ToCallTimeSec(end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001003 alr_state.intervals.emplace_back(x, y);
1004 }
1005
1006 if (show_detector_state) {
1007 plot->AppendIntervalSeries(std::move(overusing_series));
1008 plot->AppendIntervalSeries(std::move(underusing_series));
1009 plot->AppendIntervalSeries(std::move(normal_series));
1010 }
1011
1012 if (show_alr_state) {
1013 plot->AppendIntervalSeries(std::move(alr_state));
1014 }
1015 plot->AppendTimeSeries(std::move(loss_series));
1016 plot->AppendTimeSeries(std::move(delay_series));
1017 plot->AppendTimeSeries(std::move(created_series));
1018 plot->AppendTimeSeries(std::move(result_series));
1019
1020 // Overlay the incoming REMB over the outgoing bitrate.
Björn Tereliusff612732018-04-25 14:23:01 +00001021 TimeSeries remb_series("Remb", LineStyle::kStep);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001022 for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001023 float x = ToCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001024 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
terelius2c8e8a32017-06-02 01:29:48 -07001025 remb_series.points.emplace_back(x, y);
1026 }
1027 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1028
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001029 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1030 kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001031 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001032 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001033}
1034
1035// For each SSRC, plot the bandwidth used by that stream.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001036void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction,
1037 Plot* plot) {
1038 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1039 // Filter on SSRC.
1040 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -07001041 continue;
terelius54ce6802016-07-13 06:44:41 -07001042 }
1043
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001044 TimeSeries time_series(GetStreamName(direction, stream.ssrc),
1045 LineStyle::kLine);
1046 auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) {
1047 return packet.total_length * 8.0 / 1000.0;
1048 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001049 auto ToCallTime = [this](int64_t time) {
1050 return this->ToCallTimeSec(time);
1051 };
terelius53dc23c2017-03-13 05:24:05 -07001052 MovingAverage<LoggedRtpPacket, double>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001053 ToCallTime, GetPacketSizeKilobits, stream.packet_view, begin_time_,
1054 end_time_, window_duration_, step_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001055 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001056 }
1057
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001058 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1059 kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001060 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001061 plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001062}
1063
Bjorn Terelius28db2662017-10-04 14:22:43 +02001064void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001065 using RtpPacketType = LoggedRtpPacketOutgoing;
1066 using TransportFeedbackType = LoggedRtcpPacketTransportFeedback;
Stefan Holmer13181032016-07-29 14:48:54 +02001067
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001068 // TODO(terelius): This could be provided by the parser.
1069 std::multimap<int64_t, const RtpPacketType*> outgoing_rtp;
1070 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1071 for (const RtpPacketType& rtp_packet : stream.outgoing_packets)
1072 outgoing_rtp.insert(
1073 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Stefan Holmer13181032016-07-29 14:48:54 +02001074 }
1075
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001076 const std::vector<TransportFeedbackType>& incoming_rtcp =
1077 parsed_log_.transport_feedbacks(kIncomingPacket);
Stefan Holmer13181032016-07-29 14:48:54 +02001078
1079 SimulatedClock clock(0);
1080 BitrateObserver observer;
1081 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001082 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001083 PacedSender pacer(&clock, &packet_router, &null_event_log);
Sebastian Janssona39a0072018-10-15 20:59:07 +02001084 TransportFeedbackAdapter transport_feedback(&clock);
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001085 auto factory = GoogCcNetworkControllerFactory(&null_event_log);
1086 TimeDelta process_interval = factory.GetProcessInterval();
Stefan Holmer13181032016-07-29 14:48:54 +02001087 // TODO(holmer): Log the call config and use that here instead.
1088 static const uint32_t kDefaultStartBitrateBps = 300000;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001089 NetworkControllerConfig cc_config;
1090 cc_config.constraints.starting_rate = DataRate::bps(kDefaultStartBitrateBps);
1091 auto goog_cc = factory.Create(cc_config);
Stefan Holmer13181032016-07-29 14:48:54 +02001092
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001093 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1094 PointStyle::kHighlight);
1095 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1096 PointStyle::kHighlight);
1097 TimeSeries acked_estimate_time_series(
1098 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001099
1100 auto rtp_iterator = outgoing_rtp.begin();
1101 auto rtcp_iterator = incoming_rtcp.begin();
1102
1103 auto NextRtpTime = [&]() {
1104 if (rtp_iterator != outgoing_rtp.end())
1105 return static_cast<int64_t>(rtp_iterator->first);
1106 return std::numeric_limits<int64_t>::max();
1107 };
1108
1109 auto NextRtcpTime = [&]() {
1110 if (rtcp_iterator != incoming_rtcp.end())
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001111 return static_cast<int64_t>(rtcp_iterator->log_time_us());
Stefan Holmer13181032016-07-29 14:48:54 +02001112 return std::numeric_limits<int64_t>::max();
1113 };
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001114 int64_t next_process_time_us_ = clock.TimeInMicroseconds();
Stefan Holmer13181032016-07-29 14:48:54 +02001115
1116 auto NextProcessTime = [&]() {
1117 if (rtcp_iterator != incoming_rtcp.end() ||
1118 rtp_iterator != outgoing_rtp.end()) {
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001119 return next_process_time_us_;
Stefan Holmer13181032016-07-29 14:48:54 +02001120 }
1121 return std::numeric_limits<int64_t>::max();
1122 };
1123
Stefan Holmer492ee282016-10-27 17:19:20 +02001124 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001125#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1126 // The event_log_visualizer should normally not be compiled with
1127 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
1128 // However, compiling with BWE_TEST_LOGGING, runnning with --plot_sendside_bwe
1129 // and piping the output to plot_dynamics.py can be used as a hack to get the
1130 // internal state of various BWE components. In this case, it is important
1131 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
1132 // SendSideCongestionController since that would lead to duplicate outputs.
1133 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
Karl Wiberg918f50c2018-07-05 11:40:33 +02001134 absl::make_unique<BitrateEstimator>());
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001135#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001136 int64_t time_us =
1137 std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
Stefan Holmer492ee282016-10-27 17:19:20 +02001138 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001139 while (time_us != std::numeric_limits<int64_t>::max()) {
1140 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1141 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001142 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001143
1144 auto feedback_msg = transport_feedback.ProcessTransportFeedback(
1145 rtcp_iterator->transport_feedback);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001146 absl::optional<uint32_t> bitrate_bps;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001147 if (feedback_msg) {
1148 observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg));
1149 std::vector<PacketFeedback> feedback =
1150 transport_feedback.GetTransportFeedbackVector();
1151 SortPacketFeedbackVector(&feedback);
1152 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001153#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001154 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001155#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001156 for (const PacketFeedback& packet : feedback)
1157 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1158 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1159 }
Stefan Holmer13181032016-07-29 14:48:54 +02001160 }
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001161
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001162 float x = ToCallTimeSec(clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001163 float y = bitrate_bps.value_or(0) / 1000;
1164 acked_time_series.points.emplace_back(x, y);
1165#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1166 y = acknowledged_bitrate_estimator.bitrate_bps().value_or(0) / 1000;
1167 acked_estimate_time_series.points.emplace_back(x, y);
1168#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001169 ++rtcp_iterator;
1170 }
1171 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001172 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001173 const RtpPacketType& rtp_packet = *rtp_iterator->second;
1174 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
1175 RTC_DCHECK(rtp_packet.rtp.header.extension.hasTransportSequenceNumber);
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001176 transport_feedback.AddPacket(
1177 rtp_packet.rtp.header.ssrc,
1178 rtp_packet.rtp.header.extension.transportSequenceNumber,
1179 rtp_packet.rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001180 rtc::SentPacket sent_packet(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001181 rtp_packet.rtp.header.extension.transportSequenceNumber,
1182 rtp_packet.rtp.log_time_us() / 1000);
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001183 auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet);
1184 if (sent_msg)
1185 observer.Update(goog_cc->OnSentPacket(*sent_msg));
Stefan Holmer13181032016-07-29 14:48:54 +02001186 }
1187 ++rtp_iterator;
1188 }
stefanc3de0332016-08-02 07:22:17 -07001189 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1190 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001191 ProcessInterval msg;
1192 msg.at_time = Timestamp::us(clock.TimeInMicroseconds());
1193 observer.Update(goog_cc->OnProcessInterval(msg));
1194 next_process_time_us_ += process_interval.us();
stefanc3de0332016-08-02 07:22:17 -07001195 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001196 if (observer.GetAndResetBitrateUpdated() ||
1197 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001198 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001199 float x = ToCallTimeSec(clock.TimeInMicroseconds());
Stefan Holmer13181032016-07-29 14:48:54 +02001200 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001201 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001202 }
1203 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1204 }
1205 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001206 plot->AppendTimeSeries(std::move(time_series));
1207 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001208 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001209
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001210 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1211 kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001212 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001213 plot->SetTitle("Simulated send-side BWE behavior");
1214}
1215
1216void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001217 using RtpPacketType = LoggedRtpPacketIncoming;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001218 class RembInterceptingPacketRouter : public PacketRouter {
1219 public:
1220 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1221 uint32_t bitrate_bps) override {
1222 last_bitrate_bps_ = bitrate_bps;
1223 bitrate_updated_ = true;
1224 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1225 }
1226 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1227 bool GetAndResetBitrateUpdated() {
1228 bool bitrate_updated = bitrate_updated_;
1229 bitrate_updated_ = false;
1230 return bitrate_updated;
1231 }
1232
1233 private:
1234 uint32_t last_bitrate_bps_;
1235 bool bitrate_updated_;
1236 };
1237
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001238 std::multimap<int64_t, const RtpPacketType*> incoming_rtp;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001239
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001240 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
1241 if (IsVideoSsrc(kIncomingPacket, stream.ssrc)) {
1242 for (const auto& rtp_packet : stream.incoming_packets)
1243 incoming_rtp.insert(
1244 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Bjorn Terelius28db2662017-10-04 14:22:43 +02001245 }
1246 }
1247
1248 SimulatedClock clock(0);
1249 RembInterceptingPacketRouter packet_router;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001250 // TODO(terelius): The PacketRouter is used as the RemoteBitrateObserver.
Bjorn Terelius28db2662017-10-04 14:22:43 +02001251 // Is this intentional?
1252 ReceiveSideCongestionController rscc(&clock, &packet_router);
1253 // TODO(holmer): Log the call config and use that here instead.
1254 // static const uint32_t kDefaultStartBitrateBps = 300000;
1255 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1256
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001257 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1258 PointStyle::kHighlight);
1259 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001260
1261 RateStatistics acked_bitrate(250, 8000);
1262 int64_t last_update_us = 0;
1263 for (const auto& kv : incoming_rtp) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001264 const RtpPacketType& packet = *kv.second;
1265 int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000;
1266 size_t payload = packet.rtp.total_length; /*Should subtract header?*/
1267 clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() -
Bjorn Terelius28db2662017-10-04 14:22:43 +02001268 clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001269 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001270 acked_bitrate.Update(payload, arrival_time_ms);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001271 absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001272 if (bitrate_bps) {
1273 uint32_t y = *bitrate_bps / 1000;
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001274 float x = ToCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001275 acked_time_series.points.emplace_back(x, y);
1276 }
1277 if (packet_router.GetAndResetBitrateUpdated() ||
1278 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1279 uint32_t y = packet_router.last_bitrate_bps() / 1000;
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001280 float x = ToCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001281 time_series.points.emplace_back(x, y);
1282 last_update_us = clock.TimeInMicroseconds();
1283 }
1284 }
1285 // Add the data set to the plot.
1286 plot->AppendTimeSeries(std::move(time_series));
1287 plot->AppendTimeSeries(std::move(acked_time_series));
1288
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001289 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1290 kLeftMargin, kRightMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001291 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1292 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001293}
1294
tereliuse34c19c2016-08-15 08:47:14 -07001295void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001296 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1297 PointStyle::kHighlight);
1298 TimeSeries time_series("Network Delay Change", LineStyle::kLine,
1299 PointStyle::kHighlight);
stefanc3de0332016-08-02 07:22:17 -07001300 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1301
stefana0a8ed72017-09-06 02:06:32 -07001302 int64_t prev_y = 0;
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001303 for (auto packet : GetNetworkTrace(parsed_log_)) {
1304 if (packet.arrival_time_ms == PacketFeedback::kNotReceived)
1305 continue;
1306 float x = ToCallTimeSec(1000 * packet.feedback_arrival_time_ms);
1307 if (packet.send_time_ms == PacketFeedback::kNoSendTime) {
1308 late_feedback_series.points.emplace_back(x, prev_y);
1309 continue;
stefanc3de0332016-08-02 07:22:17 -07001310 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001311 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1312 prev_y = y;
1313 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1314 time_series.points.emplace_back(x, y);
stefanc3de0332016-08-02 07:22:17 -07001315 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001316
stefanc3de0332016-08-02 07:22:17 -07001317 // We assume that the base network delay (w/o queues) is the min delay
1318 // observed during the call.
1319 for (TimeSeriesPoint& point : time_series.points)
1320 point.y -= estimated_base_delay_ms;
stefana0a8ed72017-09-06 02:06:32 -07001321 for (TimeSeriesPoint& point : late_feedback_series.points)
1322 point.y -= estimated_base_delay_ms;
stefanc3de0332016-08-02 07:22:17 -07001323 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001324 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1325 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001326
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001327 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1328 kLeftMargin, kRightMargin);
stefanc3de0332016-08-02 07:22:17 -07001329 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1330 plot->SetTitle("Network Delay Change.");
1331}
stefan08383272016-12-20 08:51:52 -08001332
Bjorn Terelius0295a962017-10-25 17:42:41 +02001333void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001334 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1335 const std::vector<LoggedRtpPacketOutgoing>& packets =
1336 stream.outgoing_packets;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001337
1338 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001339 RTC_LOG(LS_WARNING)
1340 << "Can't estimate a the RTP clock frequency or the "
1341 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001342 continue;
1343 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001344 int64_t end_time_us = log_segments_.empty()
1345 ? std::numeric_limits<int64_t>::max()
1346 : log_segments_.front().second;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001347 absl::optional<uint32_t> estimated_frequency =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001348 EstimateRtpClockFrequency(packets, end_time_us);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001349 if (!estimated_frequency)
1350 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001351 if (IsVideoSsrc(kOutgoingPacket, stream.ssrc) &&
1352 *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001353 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001354 << "Video stream should use a 90 kHz clock but appears to use "
1355 << *estimated_frequency / 1000 << ". Discarding.";
1356 continue;
1357 }
1358
1359 TimeSeries pacer_delay_series(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001360 GetStreamName(kOutgoingPacket, stream.ssrc) + "(" +
Bjorn Terelius0295a962017-10-25 17:42:41 +02001361 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001362 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001363 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1364 uint64_t first_capture_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001365 timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp);
1366 uint64_t first_send_timestamp = packets.front().rtp.log_time_us();
1367 for (const auto& packet : packets) {
Bjorn Terelius0295a962017-10-25 17:42:41 +02001368 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001369 packet.rtp.header.timestamp)) -
Bjorn Terelius0295a962017-10-25 17:42:41 +02001370 first_capture_timestamp) /
1371 *estimated_frequency * 1000;
1372 double send_time_ms =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001373 static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) /
1374 1000;
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001375 float x = ToCallTimeSec(packet.rtp.log_time_us());
Bjorn Terelius0295a962017-10-25 17:42:41 +02001376 float y = send_time_ms - capture_time_ms;
1377 pacer_delay_series.points.emplace_back(x, y);
1378 }
1379 plot->AppendTimeSeries(std::move(pacer_delay_series));
1380 }
1381
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001382 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1383 kLeftMargin, kRightMargin);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001384 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1385 plot->SetTitle(
1386 "Delay from capture to send time. (First packet normalized to 0.)");
1387}
1388
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001389void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction,
1390 Plot* plot) {
1391 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1392 TimeSeries rtp_timestamps(
1393 GetStreamName(direction, stream.ssrc) + " capture-time",
1394 LineStyle::kLine, PointStyle::kHighlight);
1395 for (const auto& packet : stream.packet_view) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001396 float x = ToCallTimeSec(packet.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001397 float y = packet.header.timestamp;
1398 rtp_timestamps.points.emplace_back(x, y);
stefane372d3c2017-02-02 08:04:18 -08001399 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001400 plot->AppendTimeSeries(std::move(rtp_timestamps));
Björn Tereliusff612732018-04-25 14:23:01 +00001401
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001402 TimeSeries rtcp_timestamps(
1403 GetStreamName(direction, stream.ssrc) + " rtcp capture-time",
1404 LineStyle::kLine, PointStyle::kHighlight);
1405 // TODO(terelius): Why only sender reports?
1406 const auto& sender_reports = parsed_log_.sender_reports(direction);
1407 for (const auto& rtcp : sender_reports) {
1408 if (rtcp.sr.sender_ssrc() != stream.ssrc)
1409 continue;
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001410 float x = ToCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001411 float y = rtcp.sr.rtp_timestamp();
1412 rtcp_timestamps.points.emplace_back(x, y);
Björn Tereliusff612732018-04-25 14:23:01 +00001413 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001414 plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps));
stefane372d3c2017-02-02 08:04:18 -08001415 }
1416
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001417 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1418 kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001419 plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin);
1420 plot->SetTitle(GetDirectionAsString(direction) + " timestamps");
stefane372d3c2017-02-02 08:04:18 -08001421}
michaelt6e5b2192017-02-22 07:33:27 -08001422
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001423void EventLogAnalyzer::CreateSenderAndReceiverReportPlot(
1424 PacketDirection direction,
1425 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
1426 std::string title,
1427 std::string yaxis_label,
1428 Plot* plot) {
1429 std::map<uint32_t, TimeSeries> sr_reports_by_ssrc;
1430 const auto& sender_reports = parsed_log_.sender_reports(direction);
1431 for (const auto& rtcp : sender_reports) {
1432 float x = ToCallTimeSec(rtcp.log_time_us());
1433 uint32_t ssrc = rtcp.sr.sender_ssrc();
1434 for (const auto& block : rtcp.sr.report_blocks()) {
1435 float y = fy(block);
1436 auto sr_report_it = sr_reports_by_ssrc.find(ssrc);
1437 bool inserted;
1438 if (sr_report_it == sr_reports_by_ssrc.end()) {
1439 std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace(
1440 ssrc, TimeSeries(GetStreamName(direction, ssrc) + " Sender Reports",
1441 LineStyle::kLine, PointStyle::kHighlight));
1442 }
1443 sr_report_it->second.points.emplace_back(x, y);
1444 }
1445 }
1446 for (auto& kv : sr_reports_by_ssrc) {
1447 plot->AppendTimeSeries(std::move(kv.second));
1448 }
1449
1450 std::map<uint32_t, TimeSeries> rr_reports_by_ssrc;
1451 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
1452 for (const auto& rtcp : receiver_reports) {
1453 float x = ToCallTimeSec(rtcp.log_time_us());
1454 uint32_t ssrc = rtcp.rr.sender_ssrc();
1455 for (const auto& block : rtcp.rr.report_blocks()) {
1456 float y = fy(block);
1457 auto rr_report_it = rr_reports_by_ssrc.find(ssrc);
1458 bool inserted;
1459 if (rr_report_it == rr_reports_by_ssrc.end()) {
1460 std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace(
1461 ssrc,
1462 TimeSeries(GetStreamName(direction, ssrc) + " Receiver Reports",
1463 LineStyle::kLine, PointStyle::kHighlight));
1464 }
1465 rr_report_it->second.points.emplace_back(x, y);
1466 }
1467 }
1468 for (auto& kv : rr_reports_by_ssrc) {
1469 plot->AppendTimeSeries(std::move(kv.second));
1470 }
1471
1472 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1473 kLeftMargin, kRightMargin);
1474 plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin);
1475 plot->SetTitle(title);
1476}
1477
michaelt6e5b2192017-02-22 07:33:27 -08001478void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001479 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1480 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001481 auto GetAnaBitrateBps = [](const LoggedAudioNetworkAdaptationEvent& ana_event)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001482 -> absl::optional<float> {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001483 if (ana_event.config.bitrate_bps)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001484 return absl::optional<float>(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001485 static_cast<float>(*ana_event.config.bitrate_bps));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001486 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001487 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001488 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
1489 return this->ToCallTimeSec(packet.log_time_us());
1490 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001491 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001492 ToCallTime, GetAnaBitrateBps,
1493 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001494 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001495 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1496 kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001497 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1498 plot->SetTitle("Reported audio encoder target bitrate");
1499}
1500
1501void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001502 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1503 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001504 auto GetAnaFrameLengthMs =
1505 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001506 if (ana_event.config.frame_length_ms)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001507 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001508 static_cast<float>(*ana_event.config.frame_length_ms));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001509 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001510 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001511 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
1512 return this->ToCallTimeSec(packet.log_time_us());
1513 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001514 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001515 ToCallTime, GetAnaFrameLengthMs,
1516 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001517 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001518 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1519 kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001520 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1521 plot->SetTitle("Reported audio encoder frame length");
1522}
1523
terelius2ee076d2017-08-15 02:04:02 -07001524void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001525 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001526 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001527 auto GetAnaPacketLoss =
1528 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001529 if (ana_event.config.uplink_packet_loss_fraction)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001530 return absl::optional<float>(static_cast<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001531 *ana_event.config.uplink_packet_loss_fraction));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001532 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001533 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001534 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
1535 return this->ToCallTimeSec(packet.log_time_us());
1536 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001537 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001538 ToCallTime, GetAnaPacketLoss,
1539 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001540 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001541 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1542 kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001543 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1544 kTopMargin);
1545 plot->SetTitle("Reported audio encoder lost packets");
1546}
1547
1548void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001549 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1550 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001551 auto GetAnaFecEnabled =
1552 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001553 if (ana_event.config.enable_fec)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001554 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001555 static_cast<float>(*ana_event.config.enable_fec));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001556 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001557 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001558 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
1559 return this->ToCallTimeSec(packet.log_time_us());
1560 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001561 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001562 ToCallTime, GetAnaFecEnabled,
1563 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001564 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001565 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1566 kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001567 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1568 plot->SetTitle("Reported audio encoder FEC");
1569}
1570
1571void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001572 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1573 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001574 auto GetAnaDtxEnabled =
1575 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001576 if (ana_event.config.enable_dtx)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001577 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001578 static_cast<float>(*ana_event.config.enable_dtx));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001579 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001580 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001581 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
1582 return this->ToCallTimeSec(packet.log_time_us());
1583 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001584 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001585 ToCallTime, GetAnaDtxEnabled,
1586 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001587 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001588 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1589 kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001590 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1591 plot->SetTitle("Reported audio encoder DTX");
1592}
1593
1594void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001595 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1596 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001597 auto GetAnaNumChannels =
1598 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001599 if (ana_event.config.num_channels)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001600 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001601 static_cast<float>(*ana_event.config.num_channels));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001602 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001603 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001604 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
1605 return this->ToCallTimeSec(packet.log_time_us());
1606 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001607 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001608 ToCallTime, GetAnaNumChannels,
1609 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001610 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001611 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1612 kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001613 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1614 kBottomMargin, kTopMargin);
1615 plot->SetTitle("Reported audio encoder number of channels");
1616}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001617
1618class NetEqStreamInput : public test::NetEqInput {
1619 public:
1620 // Does not take any ownership, and all pointers must refer to valid objects
1621 // that outlive the one constructed.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001622 NetEqStreamInput(const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001623 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001624 absl::optional<int64_t> end_time_ms)
henrik.lundin3c938fc2017-06-14 06:09:58 -07001625 : packet_stream_(*packet_stream),
1626 packet_stream_it_(packet_stream_.begin()),
Minyue Li27e2b7d2018-05-07 15:20:24 +02001627 output_events_it_(output_events->begin()),
1628 output_events_end_(output_events->end()),
1629 end_time_ms_(end_time_ms) {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001630 RTC_DCHECK(packet_stream);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001631 RTC_DCHECK(output_events);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001632 }
1633
Danil Chapovalov431abd92018-06-18 12:54:17 +02001634 absl::optional<int64_t> NextPacketTime() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001635 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001636 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001637 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001638 if (end_time_ms_ && packet_stream_it_->rtp.log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001639 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001640 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001641 return packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001642 }
1643
Danil Chapovalov431abd92018-06-18 12:54:17 +02001644 absl::optional<int64_t> NextOutputEventTime() const override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001645 if (output_events_it_ == output_events_end_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001646 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001647 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001648 if (end_time_ms_ && output_events_it_->log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001649 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001650 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001651 return output_events_it_->log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001652 }
1653
1654 std::unique_ptr<PacketData> PopPacket() override {
1655 if (packet_stream_it_ == packet_stream_.end()) {
1656 return std::unique_ptr<PacketData>();
1657 }
1658 std::unique_ptr<PacketData> packet_data(new PacketData());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001659 packet_data->header = packet_stream_it_->rtp.header;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001660 packet_data->time_ms = packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001661
1662 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1663 // length according to the virtual length.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001664 packet_data->payload.SetSize(packet_stream_it_->rtp.total_length -
1665 packet_stream_it_->rtp.header_length);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001666 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1667
1668 ++packet_stream_it_;
1669 return packet_data;
1670 }
1671
1672 void AdvanceOutputEvent() override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001673 if (output_events_it_ != output_events_end_) {
1674 ++output_events_it_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001675 }
1676 }
1677
1678 bool ended() const override { return !NextEventTime(); }
1679
Danil Chapovalov431abd92018-06-18 12:54:17 +02001680 absl::optional<RTPHeader> NextHeader() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001681 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001682 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001683 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001684 return packet_stream_it_->rtp.header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001685 }
1686
1687 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001688 const std::vector<LoggedRtpPacketIncoming>& packet_stream_;
1689 std::vector<LoggedRtpPacketIncoming>::const_iterator packet_stream_it_;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001690 std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_it_;
1691 const std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_end_;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001692 const absl::optional<int64_t> end_time_ms_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001693};
1694
1695namespace {
1696// Creates a NetEq test object and all necessary input and output helpers. Runs
1697// the test and returns the NetEqDelayAnalyzer object that was used to
1698// instrument the test.
Minyue Lic6ff7572018-05-04 09:46:44 +02001699std::unique_ptr<test::NetEqStatsGetter> CreateNetEqTestAndRun(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001700 const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001701 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001702 absl::optional<int64_t> end_time_ms,
henrik.lundin3c938fc2017-06-14 06:09:58 -07001703 const std::string& replacement_file_name,
1704 int file_sample_rate_hz) {
1705 std::unique_ptr<test::NetEqInput> input(
Minyue Li27e2b7d2018-05-07 15:20:24 +02001706 new NetEqStreamInput(packet_stream, output_events, end_time_ms));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001707
1708 constexpr int kReplacementPt = 127;
1709 std::set<uint8_t> cn_types;
1710 std::set<uint8_t> forbidden_types;
1711 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1712 cn_types, forbidden_types));
1713
1714 NetEq::Config config;
1715 config.max_packets_in_buffer = 200;
1716 config.enable_fast_accelerate = true;
1717
1718 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1719
1720 test::NetEqTest::DecoderMap codecs;
1721
1722 // Create a "replacement decoder" that produces the decoded audio by reading
1723 // from a file rather than from the encoded payloads.
1724 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1725 new test::ResampleInputAudioFile(replacement_file_name,
1726 file_sample_rate_hz));
1727 replacement_file->set_output_rate_hz(48000);
1728 std::unique_ptr<AudioDecoder> replacement_decoder(
1729 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1730 test::NetEqTest::ExtDecoderMap ext_codecs;
1731 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1732 NetEqDecoder::kDecoderArbitrary,
1733 "replacement codec"};
1734
1735 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1736 new test::NetEqDelayAnalyzer);
Minyue Lic6ff7572018-05-04 09:46:44 +02001737 std::unique_ptr<test::NetEqStatsGetter> neteq_stats_getter(
1738 new test::NetEqStatsGetter(std::move(delay_cb)));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001739 test::DefaultNetEqTestErrorCallback error_cb;
1740 test::NetEqTest::Callbacks callbacks;
1741 callbacks.error_callback = &error_cb;
Minyue Lic6ff7572018-05-04 09:46:44 +02001742 callbacks.post_insert_packet = neteq_stats_getter->delay_analyzer();
1743 callbacks.get_audio_callback = neteq_stats_getter.get();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001744
1745 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1746 std::move(output), callbacks);
1747 test.Run();
Minyue Lic6ff7572018-05-04 09:46:44 +02001748 return neteq_stats_getter;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001749}
1750} // namespace
1751
Minyue Lic6ff7572018-05-04 09:46:44 +02001752EventLogAnalyzer::NetEqStatsGetterMap EventLogAnalyzer::SimulateNetEq(
henrik.lundin3c938fc2017-06-14 06:09:58 -07001753 const std::string& replacement_file_name,
Minyue Lic6ff7572018-05-04 09:46:44 +02001754 int file_sample_rate_hz) const {
1755 NetEqStatsGetterMap neteq_stats;
1756
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001757 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001758 const uint32_t ssrc = stream.ssrc;
1759 if (!IsAudioSsrc(kIncomingPacket, ssrc))
1760 continue;
1761 const std::vector<LoggedRtpPacketIncoming>* audio_packets =
1762 &stream.incoming_packets;
1763 if (audio_packets == nullptr) {
1764 // No incoming audio stream found.
1765 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001766 }
henrik.lundin3c938fc2017-06-14 06:09:58 -07001767
Minyue Li27e2b7d2018-05-07 15:20:24 +02001768 RTC_DCHECK(neteq_stats.find(ssrc) == neteq_stats.end());
1769
1770 std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>::const_iterator
1771 output_events_it = parsed_log_.audio_playout_events().find(ssrc);
1772 if (output_events_it == parsed_log_.audio_playout_events().end()) {
1773 // Could not find output events with SSRC matching the input audio stream.
1774 // Using the first available stream of output events.
1775 output_events_it = parsed_log_.audio_playout_events().cbegin();
1776 }
1777
Danil Chapovalov431abd92018-06-18 12:54:17 +02001778 absl::optional<int64_t> end_time_ms =
Minyue Li27e2b7d2018-05-07 15:20:24 +02001779 log_segments_.empty()
Danil Chapovalov431abd92018-06-18 12:54:17 +02001780 ? absl::nullopt
1781 : absl::optional<int64_t>(log_segments_.front().second / 1000);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001782
1783 neteq_stats[ssrc] = CreateNetEqTestAndRun(
1784 audio_packets, &output_events_it->second, end_time_ms,
1785 replacement_file_name, file_sample_rate_hz);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001786 }
1787
Minyue Lic6ff7572018-05-04 09:46:44 +02001788 return neteq_stats;
1789}
1790
Minyue Lic97933f2018-08-10 12:51:15 +02001791// Given a NetEqStatsGetter and the SSRC that the NetEqStatsGetter was created
1792// for, this method generates a plot for the jitter buffer delay profile.
Minyue Lic6ff7572018-05-04 09:46:44 +02001793void EventLogAnalyzer::CreateAudioJitterBufferGraph(
Minyue Li01d2a672018-06-21 21:17:19 +02001794 uint32_t ssrc,
1795 const test::NetEqStatsGetter* stats_getter,
Minyue Lic6ff7572018-05-04 09:46:44 +02001796 Plot* plot) const {
Minyue Li45fc6df2018-06-21 11:47:14 +02001797 test::NetEqDelayAnalyzer::Delays arrival_delay_ms;
1798 test::NetEqDelayAnalyzer::Delays corrected_arrival_delay_ms;
1799 test::NetEqDelayAnalyzer::Delays playout_delay_ms;
1800 test::NetEqDelayAnalyzer::Delays target_delay_ms;
1801
Minyue Li01d2a672018-06-21 21:17:19 +02001802 stats_getter->delay_analyzer()->CreateGraphs(
Minyue Li45fc6df2018-06-21 11:47:14 +02001803 &arrival_delay_ms, &corrected_arrival_delay_ms, &playout_delay_ms,
1804 &target_delay_ms);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001805
Minyue Lic97933f2018-08-10 12:51:15 +02001806 TimeSeries time_series_packet_arrival("packet arrival delay",
1807 LineStyle::kLine);
1808 TimeSeries time_series_relative_packet_arrival(
1809 "Relative packet arrival delay", LineStyle::kLine);
1810 TimeSeries time_series_play_time("Playout delay", LineStyle::kLine);
1811 TimeSeries time_series_target_time("Target delay", LineStyle::kLine,
1812 PointStyle::kHighlight);
Minyue Li45fc6df2018-06-21 11:47:14 +02001813
1814 for (const auto& data : arrival_delay_ms) {
1815 const float x = ToCallTimeSec(data.first * 1000); // ms to us.
1816 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02001817 time_series_packet_arrival.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02001818 }
1819 for (const auto& data : corrected_arrival_delay_ms) {
1820 const float x = ToCallTimeSec(data.first * 1000); // ms to us.
1821 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02001822 time_series_relative_packet_arrival.points.emplace_back(
Minyue Li45fc6df2018-06-21 11:47:14 +02001823 TimeSeriesPoint(x, y));
1824 }
1825 for (const auto& data : playout_delay_ms) {
1826 const float x = ToCallTimeSec(data.first * 1000); // ms to us.
1827 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02001828 time_series_play_time.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02001829 }
1830 for (const auto& data : target_delay_ms) {
1831 const float x = ToCallTimeSec(data.first * 1000); // ms to us.
1832 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02001833 time_series_target_time.points.emplace_back(TimeSeriesPoint(x, y));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001834 }
1835
Minyue Lic97933f2018-08-10 12:51:15 +02001836 plot->AppendTimeSeries(std::move(time_series_packet_arrival));
1837 plot->AppendTimeSeries(std::move(time_series_relative_packet_arrival));
1838 plot->AppendTimeSeries(std::move(time_series_play_time));
1839 plot->AppendTimeSeries(std::move(time_series_target_time));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001840
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001841 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1842 kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02001843 plot->SetSuggestedYAxis(0, 1, "Relative delay (ms)", kBottomMargin,
1844 kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001845 plot->SetTitle("NetEq timing for " + GetStreamName(kIncomingPacket, ssrc));
1846}
1847
Minyue Lic9ac93f2018-06-26 13:01:32 +02001848template <typename NetEqStatsType>
1849void EventLogAnalyzer::CreateNetEqStatsGraphInternal(
Minyue Li27e2b7d2018-05-07 15:20:24 +02001850 const NetEqStatsGetterMap& neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +02001851 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
1852 const test::NetEqStatsGetter*)> data_extractor,
1853 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001854 const std::string& plot_name,
1855 Plot* plot) const {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001856 std::map<uint32_t, TimeSeries> time_series;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001857
1858 for (const auto& st : neteq_stats) {
1859 const uint32_t ssrc = st.first;
Minyue Lic9ac93f2018-06-26 13:01:32 +02001860 const std::vector<std::pair<int64_t, NetEqStatsType>>* data_vector =
1861 data_extractor(st.second.get());
1862 for (const auto& data : *data_vector) {
1863 const float time = ToCallTimeSec(data.first * 1000); // ms to us.
1864 const float value = stats_extractor(data.second);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001865 time_series[ssrc].points.emplace_back(TimeSeriesPoint(time, value));
Minyue Li27e2b7d2018-05-07 15:20:24 +02001866 }
1867 }
1868
1869 for (auto& series : time_series) {
1870 series.second.label = GetStreamName(kIncomingPacket, series.first);
1871 series.second.line_style = LineStyle::kLine;
1872 plot->AppendTimeSeries(std::move(series.second));
1873 }
1874
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001875 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1876 kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02001877 plot->SetSuggestedYAxis(0, 1, plot_name, kBottomMargin, kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001878 plot->SetTitle(plot_name);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001879}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01001880
Minyue Lic9ac93f2018-06-26 13:01:32 +02001881void EventLogAnalyzer::CreateNetEqNetworkStatsGraph(
1882 const NetEqStatsGetterMap& neteq_stats,
1883 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
1884 const std::string& plot_name,
1885 Plot* plot) const {
1886 CreateNetEqStatsGraphInternal<NetEqNetworkStatistics>(
1887 neteq_stats,
1888 [](const test::NetEqStatsGetter* stats_getter) {
1889 return stats_getter->stats();
1890 },
1891 stats_extractor, plot_name, plot);
1892}
1893
1894void EventLogAnalyzer::CreateNetEqLifetimeStatsGraph(
1895 const NetEqStatsGetterMap& neteq_stats,
1896 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
1897 const std::string& plot_name,
1898 Plot* plot) const {
1899 CreateNetEqStatsGraphInternal<NetEqLifetimeStatistics>(
1900 neteq_stats,
1901 [](const test::NetEqStatsGetter* stats_getter) {
1902 return stats_getter->lifetime_stats();
1903 },
1904 stats_extractor, plot_name, plot);
1905}
1906
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001907void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
1908 std::map<uint32_t, TimeSeries> configs_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001909 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001910 if (configs_by_cp_id.find(config.candidate_pair_id) ==
1911 configs_by_cp_id.end()) {
1912 const std::string candidate_pair_desc =
1913 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08001914 configs_by_cp_id[config.candidate_pair_id] =
1915 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
1916 candidate_pair_desc,
1917 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001918 candidate_pair_desc_by_id_[config.candidate_pair_id] =
1919 candidate_pair_desc;
1920 }
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001921 float x = ToCallTimeSec(config.log_time_us());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001922 float y = static_cast<float>(config.type);
1923 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
1924 }
1925
1926 // TODO(qingsi): There can be a large number of candidate pairs generated by
1927 // certain calls and the frontend cannot render the chart in this case due to
1928 // the failure of generating a palette with the same number of colors.
1929 for (auto& kv : configs_by_cp_id) {
1930 plot->AppendTimeSeries(std::move(kv.second));
1931 }
1932
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001933 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1934 kLeftMargin, kRightMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001935 plot->SetSuggestedYAxis(0, 3, "Numeric Config Type", kBottomMargin,
1936 kTopMargin);
1937 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
1938}
1939
1940std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
1941 uint32_t candidate_pair_id) {
1942 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
1943 candidate_pair_desc_by_id_.end()) {
1944 return candidate_pair_desc_by_id_[candidate_pair_id];
1945 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001946 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001947 // TODO(qingsi): Add the handling of the "Updated" config event after the
1948 // visualization of property change for candidate pairs is introduced.
1949 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
1950 candidate_pair_desc_by_id_.end()) {
1951 const std::string candidate_pair_desc =
1952 GetCandidatePairLogDescriptionAsString(config);
1953 candidate_pair_desc_by_id_[config.candidate_pair_id] =
1954 candidate_pair_desc;
1955 }
1956 }
1957 return candidate_pair_desc_by_id_[candidate_pair_id];
1958}
1959
1960void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
1961 std::map<uint32_t, TimeSeries> checks_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001962 for (const auto& event : parsed_log_.ice_candidate_pair_events()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001963 if (checks_by_cp_id.find(event.candidate_pair_id) ==
1964 checks_by_cp_id.end()) {
1965 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08001966 "[" + std::to_string(event.candidate_pair_id) + "]" +
1967 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001968 LineStyle::kNone, PointStyle::kHighlight);
1969 }
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001970 float x = ToCallTimeSec(event.log_time_us());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001971 float y = static_cast<float>(event.type);
1972 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
1973 }
1974
1975 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
1976 for (auto& kv : checks_by_cp_id) {
1977 plot->AppendTimeSeries(std::move(kv.second));
1978 }
1979
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001980 plot->SetXAxis(ToCallTimeSec(begin_time_), call_duration_s_, "Time (s)",
1981 kLeftMargin, kRightMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001982 plot->SetSuggestedYAxis(0, 4, "Numeric Connectivity State", kBottomMargin,
1983 kTopMargin);
1984 plot->SetTitle("[IceEventLog] ICE connectivity checks");
1985}
1986
Bjorn Terelius2eb31882017-11-30 15:15:25 +01001987void EventLogAnalyzer::PrintNotifications(FILE* file) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +01001988 fprintf(file, "========== TRIAGE NOTIFICATIONS ==========\n");
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001989 for (const auto& alert : incoming_rtp_recv_time_gaps_) {
1990 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
1991 }
1992 for (const auto& alert : incoming_rtcp_recv_time_gaps_) {
1993 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
1994 }
1995 for (const auto& alert : outgoing_rtp_send_time_gaps_) {
1996 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
1997 }
1998 for (const auto& alert : outgoing_rtcp_send_time_gaps_) {
1999 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2000 }
2001 for (const auto& alert : incoming_seq_num_jumps_) {
2002 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2003 }
2004 for (const auto& alert : incoming_capture_time_jumps_) {
2005 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2006 }
2007 for (const auto& alert : outgoing_seq_num_jumps_) {
2008 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2009 }
2010 for (const auto& alert : outgoing_capture_time_jumps_) {
2011 fprintf(file, "%3.3lf s : %s\n", alert.Time(), alert.ToString().c_str());
2012 }
2013 for (const auto& alert : outgoing_high_loss_alerts_) {
2014 fprintf(file, " : %s\n", alert.ToString().c_str());
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002015 }
2016 fprintf(file, "========== END TRIAGE NOTIFICATIONS ==========\n");
2017}
2018
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002019void EventLogAnalyzer::CreateStreamGapAlerts(PacketDirection direction) {
2020 // With 100 packets/s (~800kbps), false positives would require 10 s without
2021 // data.
2022 constexpr int64_t kMaxSeqNumJump = 1000;
2023 // With a 90 kHz clock, false positives would require 10 s without data.
2024 constexpr int64_t kMaxCaptureTimeJump = 900000;
2025
2026 int64_t end_time_us = log_segments_.empty()
2027 ? std::numeric_limits<int64_t>::max()
2028 : log_segments_.front().second;
2029
2030 SeqNumUnwrapper<uint16_t> seq_num_unwrapper;
Danil Chapovalov431abd92018-06-18 12:54:17 +02002031 absl::optional<int64_t> last_seq_num;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002032 SeqNumUnwrapper<uint32_t> capture_time_unwrapper;
Danil Chapovalov431abd92018-06-18 12:54:17 +02002033 absl::optional<int64_t> last_capture_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002034 // Check for gaps in sequence numbers and capture timestamps.
2035 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
2036 for (const auto& packet : stream.packet_view) {
2037 if (packet.log_time_us() > end_time_us) {
2038 // Only process the first (LOG_START, LOG_END) segment.
2039 break;
2040 }
2041
2042 int64_t seq_num = seq_num_unwrapper.Unwrap(packet.header.sequenceNumber);
2043 if (last_seq_num.has_value() &&
2044 std::abs(seq_num - last_seq_num.value()) > kMaxSeqNumJump) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +02002045 Alert_SeqNumJump(direction, ToCallTimeSec(packet.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002046 packet.header.ssrc);
2047 }
2048 last_seq_num.emplace(seq_num);
2049
2050 int64_t capture_time =
2051 capture_time_unwrapper.Unwrap(packet.header.timestamp);
2052 if (last_capture_time.has_value() &&
2053 std::abs(capture_time - last_capture_time.value()) >
2054 kMaxCaptureTimeJump) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +02002055 Alert_CaptureTimeJump(direction, ToCallTimeSec(packet.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002056 packet.header.ssrc);
2057 }
2058 last_capture_time.emplace(capture_time);
2059 }
2060 }
2061}
2062
2063void EventLogAnalyzer::CreateTransmissionGapAlerts(PacketDirection direction) {
2064 constexpr int64_t kMaxRtpTransmissionGap = 500000;
2065 constexpr int64_t kMaxRtcpTransmissionGap = 2000000;
2066 int64_t end_time_us = log_segments_.empty()
2067 ? std::numeric_limits<int64_t>::max()
2068 : log_segments_.front().second;
2069
2070 // TODO(terelius): The parser could provide a list of all packets, ordered
2071 // by time, for each direction.
2072 std::multimap<int64_t, const LoggedRtpPacket*> rtp_in_direction;
2073 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
2074 for (const LoggedRtpPacket& rtp_packet : stream.packet_view)
2075 rtp_in_direction.emplace(rtp_packet.log_time_us(), &rtp_packet);
2076 }
Danil Chapovalov431abd92018-06-18 12:54:17 +02002077 absl::optional<int64_t> last_rtp_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002078 for (const auto& kv : rtp_in_direction) {
2079 int64_t timestamp = kv.first;
2080 if (timestamp > end_time_us) {
2081 // Only process the first (LOG_START, LOG_END) segment.
2082 break;
2083 }
2084 int64_t duration = timestamp - last_rtp_time.value_or(0);
2085 if (last_rtp_time.has_value() && duration > kMaxRtpTransmissionGap) {
2086 // No packet sent/received for more than 500 ms.
Stefan Holmer1d4a2272018-05-24 13:48:09 +02002087 Alert_RtpLogTimeGap(direction, ToCallTimeSec(timestamp), duration / 1000);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002088 }
2089 last_rtp_time.emplace(timestamp);
2090 }
2091
Danil Chapovalov431abd92018-06-18 12:54:17 +02002092 absl::optional<int64_t> last_rtcp_time;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002093 if (direction == kIncomingPacket) {
2094 for (const auto& rtcp : parsed_log_.incoming_rtcp_packets()) {
2095 if (rtcp.log_time_us() > end_time_us) {
2096 // Only process the first (LOG_START, LOG_END) segment.
2097 break;
2098 }
2099 int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0);
2100 if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) {
2101 // No feedback sent/received for more than 2000 ms.
Stefan Holmer1d4a2272018-05-24 13:48:09 +02002102 Alert_RtcpLogTimeGap(direction, ToCallTimeSec(rtcp.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002103 duration / 1000);
2104 }
2105 last_rtcp_time.emplace(rtcp.log_time_us());
2106 }
2107 } else {
2108 for (const auto& rtcp : parsed_log_.outgoing_rtcp_packets()) {
2109 if (rtcp.log_time_us() > end_time_us) {
2110 // Only process the first (LOG_START, LOG_END) segment.
2111 break;
2112 }
2113 int64_t duration = rtcp.log_time_us() - last_rtcp_time.value_or(0);
2114 if (last_rtcp_time.has_value() && duration > kMaxRtcpTransmissionGap) {
2115 // No feedback sent/received for more than 2000 ms.
Stefan Holmer1d4a2272018-05-24 13:48:09 +02002116 Alert_RtcpLogTimeGap(direction, ToCallTimeSec(rtcp.log_time_us()),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002117 duration / 1000);
2118 }
2119 last_rtcp_time.emplace(rtcp.log_time_us());
2120 }
2121 }
2122}
2123
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002124// TODO(terelius): Notifications could possibly be generated by the same code
2125// that produces the graphs. There is some code duplication that could be
2126// avoided, but that might be solved anyway when we move functionality from the
2127// analyzer to the parser.
2128void EventLogAnalyzer::CreateTriageNotifications() {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002129 CreateStreamGapAlerts(kIncomingPacket);
2130 CreateStreamGapAlerts(kOutgoingPacket);
2131 CreateTransmissionGapAlerts(kIncomingPacket);
2132 CreateTransmissionGapAlerts(kOutgoingPacket);
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002133
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002134 int64_t end_time_us = log_segments_.empty()
2135 ? std::numeric_limits<int64_t>::max()
2136 : log_segments_.front().second;
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002137
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002138 constexpr double kMaxLossFraction = 0.05;
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002139 // Loss feedback
2140 int64_t total_lost_packets = 0;
2141 int64_t total_expected_packets = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002142 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
2143 if (bwe_update.log_time_us() > end_time_us) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002144 // Only process the first (LOG_START, LOG_END) segment.
2145 break;
2146 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002147 int64_t lost_packets = static_cast<double>(bwe_update.fraction_lost) / 255 *
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002148 bwe_update.expected_packets;
2149 total_lost_packets += lost_packets;
2150 total_expected_packets += bwe_update.expected_packets;
2151 }
2152 double avg_outgoing_loss =
2153 static_cast<double>(total_lost_packets) / total_expected_packets;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002154 if (avg_outgoing_loss > kMaxLossFraction) {
2155 Alert_OutgoingHighLoss(avg_outgoing_loss);
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002156 }
2157}
2158
terelius54ce6802016-07-13 06:44:41 -07002159} // namespace webrtc