blob: 9a9a4553f830c07b0071c99ff41bfcebab347590 [file] [log] [blame]
terelius54ce6802016-07-13 06:44:41 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei575998c2019-07-25 13:57:41 +020011#include "rtc_tools/rtc_event_log_visualizer/analyzer.h"
terelius54ce6802016-07-13 06:44:41 -070012
13#include <algorithm>
Oleh Prypin6581f212017-11-16 00:17:05 +010014#include <cmath>
terelius54ce6802016-07-13 06:44:41 -070015#include <limits>
16#include <map>
Mirko Bonadei317a1f02019-09-17 17:06:18 +020017#include <memory>
terelius54ce6802016-07-13 06:44:41 -070018#include <string>
19#include <utility>
20
Björn Tereliusc69c1bb2019-10-11 15:06:58 +020021#include "absl/algorithm/container.h"
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +010022#include "absl/strings/string_view.h"
Artem Titov741daaf2019-03-21 14:37:36 +010023#include "api/function_view.h"
Sebastian Jansson95edb032019-01-17 16:24:12 +010024#include "api/transport/field_trial_based_config.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020025#include "api/transport/goog_cc_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "call/audio_receive_stream.h"
27#include "call/audio_send_stream.h"
28#include "call/call.h"
29#include "call/video_receive_stream.h"
30#include "call/video_send_stream.h"
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +020031#include "logging/rtc_event_log/rtc_event_processor.h"
Elad Alon99a81b62017-09-21 10:25:29 +020032#include "logging/rtc_event_log/rtc_stream_config.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020033#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#include "modules/audio_coding/neteq/tools/audio_sink.h"
35#include "modules/audio_coding/neteq/tools/fake_decode_from_file.h"
36#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
37#include "modules/audio_coding/neteq/tools/neteq_replacement_input.h"
38#include "modules/audio_coding/neteq/tools/neteq_test.h"
39#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
Sebastian Jansson172fd852018-05-24 14:17:06 +020040#include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h"
41#include "modules/congestion_controller/goog_cc/bitrate_estimator.h"
Sebastian Jansson04b18cb2018-07-02 09:25:25 +020042#include "modules/congestion_controller/goog_cc/delay_based_bwe.h"
Bjorn Terelius28db2662017-10-04 14:22:43 +020043#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020044#include "modules/congestion_controller/rtp/transport_feedback_adapter.h"
Erik Språnge7942432019-06-12 13:30:02 +020045#include "modules/pacing/paced_sender.h"
Niels Möllerfd6c0912017-10-31 10:19:10 +010046#include "modules/pacing/packet_router.h"
Sebastian Jansson5c94f552018-10-15 18:46:51 +020047#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "modules/rtp_rtcp/include/rtp_rtcp.h"
49#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020050#include "modules/rtp_rtcp/source/rtcp_packet.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020051#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
52#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
53#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
54#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
55#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
56#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
57#include "modules/rtp_rtcp/source/rtp_utility.h"
58#include "rtc_base/checks.h"
59#include "rtc_base/format_macros.h"
60#include "rtc_base/logging.h"
Bjorn Terelius0295a962017-10-25 17:42:41 +020061#include "rtc_base/numerics/sequence_number_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020062#include "rtc_base/rate_statistics.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020063#include "rtc_base/strings/string_builder.h"
Mirko Bonadei575998c2019-07-25 13:57:41 +020064#include "rtc_tools/rtc_event_log_visualizer/log_simulation.h"
terelius54ce6802016-07-13 06:44:41 -070065
Bjorn Terelius6984ad22017-10-24 12:19:45 +020066#ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
67#define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0
68#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
69
tereliusdc35dcd2016-08-01 12:03:27 -070070namespace webrtc {
tereliusdc35dcd2016-08-01 12:03:27 -070071
terelius54ce6802016-07-13 06:44:41 -070072namespace {
73
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080074const int kNumMicrosecsPerSec = 1000000;
75
terelius54ce6802016-07-13 06:44:41 -070076std::string SsrcToString(uint32_t ssrc) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020077 rtc::StringBuilder ss;
terelius54ce6802016-07-13 06:44:41 -070078 ss << "SSRC " << ssrc;
Jonas Olsson84df1c72018-09-14 16:59:32 +020079 return ss.Release();
terelius54ce6802016-07-13 06:44:41 -070080}
81
82// Checks whether an SSRC is contained in the list of desired SSRCs.
83// Note that an empty SSRC list matches every SSRC.
84bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
Mirko Bonadei1f173152019-07-25 15:28:14 +020085 if (desired_ssrc.empty())
terelius54ce6802016-07-13 06:44:41 -070086 return true;
87 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
88 desired_ssrc.end();
89}
90
91double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
92 // The timestamp is a fixed point representation with 6 bits for seconds
93 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080094 // time in seconds and then multiply by kNumMicrosecsPerSec to convert to
95 // microseconds.
terelius54ce6802016-07-13 06:44:41 -070096 static constexpr double kTimestampToMicroSec =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080097 static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070098 return abs_send_time * kTimestampToMicroSec;
99}
100
101// Computes the difference |later| - |earlier| where |later| and |earlier|
102// are counters that wrap at |modulus|. The difference is chosen to have the
103// least absolute value. For example if |modulus| is 8, then the difference will
104// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
105// be in [-4, 4].
106int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
107 RTC_DCHECK_LE(1, modulus);
108 RTC_DCHECK_LT(later, modulus);
109 RTC_DCHECK_LT(earlier, modulus);
110 int64_t difference =
111 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
112 int64_t max_difference = modulus / 2;
113 int64_t min_difference = max_difference - modulus + 1;
114 if (difference > max_difference) {
115 difference -= modulus;
116 }
117 if (difference < min_difference) {
118 difference += modulus;
119 }
terelius6addf492016-08-23 17:34:07 -0700120 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100121 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
122 << " expected to be in the range ("
123 << min_difference / 2 << "," << max_difference / 2
124 << ") but is " << difference
125 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700126 }
terelius54ce6802016-07-13 06:44:41 -0700127 return difference;
128}
129
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200130// This is much more reliable for outgoing streams than for incoming streams.
131template <typename RtpPacketContainer>
Danil Chapovalov431abd92018-06-18 12:54:17 +0200132absl::optional<uint32_t> EstimateRtpClockFrequency(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200133 const RtpPacketContainer& packets,
134 int64_t end_time_us) {
135 RTC_CHECK(packets.size() >= 2);
136 SeqNumUnwrapper<uint32_t> unwrapper;
Philip Eliasson1f850a62019-03-19 12:15:00 +0000137 int64_t first_rtp_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200138 unwrapper.Unwrap(packets[0].rtp.header.timestamp);
139 int64_t first_log_timestamp = packets[0].log_time_us();
Philip Eliasson1f850a62019-03-19 12:15:00 +0000140 int64_t last_rtp_timestamp = first_rtp_timestamp;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200141 int64_t last_log_timestamp = first_log_timestamp;
142 for (size_t i = 1; i < packets.size(); i++) {
143 if (packets[i].log_time_us() > end_time_us)
144 break;
145 last_rtp_timestamp = unwrapper.Unwrap(packets[i].rtp.header.timestamp);
146 last_log_timestamp = packets[i].log_time_us();
147 }
148 if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) {
149 RTC_LOG(LS_WARNING)
150 << "Failed to estimate RTP clock frequency: Stream too short. ("
151 << packets.size() << " packets, "
152 << last_log_timestamp - first_log_timestamp << " us)";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200153 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200154 }
155 double duration =
156 static_cast<double>(last_log_timestamp - first_log_timestamp) /
157 kNumMicrosecsPerSec;
158 double estimated_frequency =
159 (last_rtp_timestamp - first_rtp_timestamp) / duration;
160 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
philipel3fa49382019-08-20 15:59:57 +0200161 if (std::fabs(estimated_frequency - f) < 0.15 * f) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200162 return f;
163 }
164 }
165 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
166 << estimated_frequency
philipel3fa49382019-08-20 15:59:57 +0200167 << " not close to any stardard RTP frequency.";
Danil Chapovalov431abd92018-06-18 12:54:17 +0200168 return absl::nullopt;
ivocaac9d6f2016-09-22 07:01:47 -0700169}
170
tereliusdc35dcd2016-08-01 12:03:27 -0700171constexpr float kLeftMargin = 0.01f;
172constexpr float kRightMargin = 0.02f;
173constexpr float kBottomMargin = 0.02f;
174constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700175
Danil Chapovalov431abd92018-06-18 12:54:17 +0200176absl::optional<double> NetworkDelayDiff_AbsSendTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100177 const LoggedRtpPacketIncoming& old_packet,
178 const LoggedRtpPacketIncoming& new_packet) {
179 if (old_packet.rtp.header.extension.hasAbsoluteSendTime &&
180 new_packet.rtp.header.extension.hasAbsoluteSendTime) {
terelius53dc23c2017-03-13 05:24:05 -0700181 int64_t send_time_diff = WrappingDifference(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100182 new_packet.rtp.header.extension.absoluteSendTime,
183 old_packet.rtp.header.extension.absoluteSendTime, 1ul << 24);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200184 int64_t recv_time_diff =
185 new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700186 double delay_change_us =
187 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100188 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700189 } else {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200190 return absl::nullopt;
terelius6addf492016-08-23 17:34:07 -0700191 }
192}
193
Danil Chapovalov431abd92018-06-18 12:54:17 +0200194absl::optional<double> NetworkDelayDiff_CaptureTime(
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100195 const LoggedRtpPacketIncoming& old_packet,
196 const LoggedRtpPacketIncoming& new_packet,
197 const double sample_rate) {
198 int64_t send_time_diff =
199 WrappingDifference(new_packet.rtp.header.timestamp,
200 old_packet.rtp.header.timestamp, 1ull << 32);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200201 int64_t recv_time_diff = new_packet.log_time_us() - old_packet.log_time_us();
terelius53dc23c2017-03-13 05:24:05 -0700202
terelius53dc23c2017-03-13 05:24:05 -0700203 double delay_change =
204 static_cast<double>(recv_time_diff) / 1000 -
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100205 static_cast<double>(send_time_diff) / sample_rate * 1000;
terelius53dc23c2017-03-13 05:24:05 -0700206 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100207 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100208 RTC_LOG(LS_WARNING) << "Old capture time "
209 << old_packet.rtp.header.timestamp << ", received time "
210 << old_packet.log_time_us();
211 RTC_LOG(LS_WARNING) << "New capture time "
212 << new_packet.rtp.header.timestamp << ", received time "
213 << new_packet.log_time_us();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100214 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800215 << static_cast<double>(recv_time_diff) /
216 kNumMicrosecsPerSec
217 << "s";
Mirko Bonadei675513b2017-11-09 11:09:25 +0100218 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100219 << static_cast<double>(send_time_diff) / sample_rate
Mirko Bonadei675513b2017-11-09 11:09:25 +0100220 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700221 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100222 return delay_change;
terelius53dc23c2017-03-13 05:24:05 -0700223}
224
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200225// For each element in data_view, use |f()| to extract a y-coordinate and
terelius53dc23c2017-03-13 05:24:05 -0700226// store the result in a TimeSeries.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200227template <typename DataType, typename IterableType>
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200228void ProcessPoints(rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200229 rtc::FunctionView<absl::optional<float>(const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200230 const IterableType& data_view,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200231 TimeSeries* result) {
232 for (size_t i = 0; i < data_view.size(); i++) {
233 const DataType& elem = data_view[i];
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200234 float x = fx(elem);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200235 absl::optional<float> y = fy(elem);
terelius53dc23c2017-03-13 05:24:05 -0700236 if (y)
237 result->points.emplace_back(x, *y);
238 }
239}
240
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200241// For each pair of adjacent elements in |data|, use |f()| to extract a
terelius6addf492016-08-23 17:34:07 -0700242// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
243// will be the time of the second element in the pair.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200244template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700245void ProcessPairs(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200246 rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200247 rtc::FunctionView<absl::optional<ResultType>(const DataType&,
248 const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200249 const IterableType& data,
terelius53dc23c2017-03-13 05:24:05 -0700250 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700251 for (size_t i = 1; i < data.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200252 float x = fx(data[i]);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200253 absl::optional<ResultType> y = fy(data[i - 1], data[i]);
terelius53dc23c2017-03-13 05:24:05 -0700254 if (y)
255 result->points.emplace_back(x, static_cast<float>(*y));
256 }
257}
258
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200259// For each pair of adjacent elements in |data|, use |f()| to extract a
terelius53dc23c2017-03-13 05:24:05 -0700260// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
261// will be the time of the second element in the pair.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200262template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700263void AccumulatePairs(
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200264 rtc::FunctionView<float(const DataType&)> fx,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200265 rtc::FunctionView<absl::optional<ResultType>(const DataType&,
266 const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200267 const IterableType& data,
terelius53dc23c2017-03-13 05:24:05 -0700268 TimeSeries* result) {
269 ResultType sum = 0;
270 for (size_t i = 1; i < data.size(); i++) {
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200271 float x = fx(data[i]);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200272 absl::optional<ResultType> y = fy(data[i - 1], data[i]);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100273 if (y) {
terelius53dc23c2017-03-13 05:24:05 -0700274 sum += *y;
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100275 result->points.emplace_back(x, static_cast<float>(sum));
276 }
tereliusccbbf8d2016-08-10 07:34:28 -0700277 }
278}
279
terelius6addf492016-08-23 17:34:07 -0700280// Calculates a moving average of |data| and stores the result in a TimeSeries.
281// A data point is generated every |step| microseconds from |begin_time|
282// to |end_time|. The value of each data point is the average of the data
Mirko Bonadei604e75c2019-07-25 11:55:47 +0200283// during the preceding |window_duration_us| microseconds.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200284template <typename DataType, typename ResultType, typename IterableType>
terelius53dc23c2017-03-13 05:24:05 -0700285void MovingAverage(
Danil Chapovalov431abd92018-06-18 12:54:17 +0200286 rtc::FunctionView<absl::optional<ResultType>(const DataType&)> fy,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200287 const IterableType& data_view,
Bjorn Terelius068fc352019-02-13 22:38:25 +0100288 AnalyzerConfig config,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200289 TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700290 size_t window_index_begin = 0;
291 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700292 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700293
Bjorn Terelius068fc352019-02-13 22:38:25 +0100294 for (int64_t t = config.begin_time_; t < config.end_time_ + config.step_;
295 t += config.step_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200296 while (window_index_end < data_view.size() &&
297 data_view[window_index_end].log_time_us() < t) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200298 absl::optional<ResultType> value = fy(data_view[window_index_end]);
terelius53dc23c2017-03-13 05:24:05 -0700299 if (value)
300 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700301 ++window_index_end;
302 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200303 while (window_index_begin < data_view.size() &&
304 data_view[window_index_begin].log_time_us() <
Bjorn Terelius068fc352019-02-13 22:38:25 +0100305 t - config.window_duration_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200306 absl::optional<ResultType> value = fy(data_view[window_index_begin]);
terelius53dc23c2017-03-13 05:24:05 -0700307 if (value)
308 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700309 ++window_index_begin;
310 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800311 float window_duration_s =
Bjorn Terelius068fc352019-02-13 22:38:25 +0100312 static_cast<float>(config.window_duration_) / kNumMicrosecsPerSec;
313 float x = config.GetCallTimeSec(t);
terelius53dc23c2017-03-13 05:24:05 -0700314 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700315 result->points.emplace_back(x, y);
316 }
317}
318
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100319template <typename T>
320TimeSeries CreateRtcpTypeTimeSeries(const std::vector<T>& rtcp_list,
321 AnalyzerConfig config,
322 std::string rtcp_name,
323 int category_id) {
324 TimeSeries time_series(rtcp_name, LineStyle::kNone, PointStyle::kHighlight);
325 for (const auto& rtcp : rtcp_list) {
326 float x = config.GetCallTimeSec(rtcp.log_time_us());
327 float y = category_id;
328 time_series.points.emplace_back(x, y);
329 }
330 return time_series;
331}
332
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800333const char kUnknownEnumValue[] = "unknown";
334
335const char kIceCandidateTypeLocal[] = "local";
336const char kIceCandidateTypeStun[] = "stun";
337const char kIceCandidateTypePrflx[] = "prflx";
338const char kIceCandidateTypeRelay[] = "relay";
339
340const char kProtocolUdp[] = "udp";
341const char kProtocolTcp[] = "tcp";
342const char kProtocolSsltcp[] = "ssltcp";
343const char kProtocolTls[] = "tls";
344
345const char kAddressFamilyIpv4[] = "ipv4";
346const char kAddressFamilyIpv6[] = "ipv6";
347
348const char kNetworkTypeEthernet[] = "ethernet";
349const char kNetworkTypeLoopback[] = "loopback";
350const char kNetworkTypeWifi[] = "wifi";
351const char kNetworkTypeVpn[] = "vpn";
352const char kNetworkTypeCellular[] = "cellular";
353
354std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) {
355 switch (type) {
356 case webrtc::IceCandidateType::kLocal:
357 return kIceCandidateTypeLocal;
358 case webrtc::IceCandidateType::kStun:
359 return kIceCandidateTypeStun;
360 case webrtc::IceCandidateType::kPrflx:
361 return kIceCandidateTypePrflx;
362 case webrtc::IceCandidateType::kRelay:
363 return kIceCandidateTypeRelay;
364 default:
365 return kUnknownEnumValue;
366 }
367}
368
369std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) {
370 switch (protocol) {
371 case webrtc::IceCandidatePairProtocol::kUdp:
372 return kProtocolUdp;
373 case webrtc::IceCandidatePairProtocol::kTcp:
374 return kProtocolTcp;
375 case webrtc::IceCandidatePairProtocol::kSsltcp:
376 return kProtocolSsltcp;
377 case webrtc::IceCandidatePairProtocol::kTls:
378 return kProtocolTls;
379 default:
380 return kUnknownEnumValue;
381 }
382}
383
384std::string GetAddressFamilyAsString(
385 webrtc::IceCandidatePairAddressFamily family) {
386 switch (family) {
387 case webrtc::IceCandidatePairAddressFamily::kIpv4:
388 return kAddressFamilyIpv4;
389 case webrtc::IceCandidatePairAddressFamily::kIpv6:
390 return kAddressFamilyIpv6;
391 default:
392 return kUnknownEnumValue;
393 }
394}
395
396std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) {
397 switch (type) {
398 case webrtc::IceCandidateNetworkType::kEthernet:
399 return kNetworkTypeEthernet;
400 case webrtc::IceCandidateNetworkType::kLoopback:
401 return kNetworkTypeLoopback;
402 case webrtc::IceCandidateNetworkType::kWifi:
403 return kNetworkTypeWifi;
404 case webrtc::IceCandidateNetworkType::kVpn:
405 return kNetworkTypeVpn;
406 case webrtc::IceCandidateNetworkType::kCellular:
407 return kNetworkTypeCellular;
408 default:
409 return kUnknownEnumValue;
410 }
411}
412
413std::string GetCandidatePairLogDescriptionAsString(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200414 const LoggedIceCandidatePairConfig& config) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800415 // Example: stun:wifi->relay(tcp):cellular@udp:ipv4
416 // represents a pair of a local server-reflexive candidate on a WiFi network
417 // and a remote relay candidate using TCP as the relay protocol on a cell
418 // network, when the candidate pair communicates over UDP using IPv4.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200419 rtc::StringBuilder ss;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800420 std::string local_candidate_type =
421 GetIceCandidateTypeAsString(config.local_candidate_type);
422 std::string remote_candidate_type =
423 GetIceCandidateTypeAsString(config.remote_candidate_type);
424 if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) {
425 local_candidate_type +=
426 "(" + GetProtocolAsString(config.local_relay_protocol) + ")";
427 }
428 ss << local_candidate_type << ":"
429 << GetNetworkTypeAsString(config.local_network_type) << ":"
430 << GetAddressFamilyAsString(config.local_address_family) << "->"
431 << remote_candidate_type << ":"
432 << GetAddressFamilyAsString(config.remote_address_family) << "@"
433 << GetProtocolAsString(config.candidate_pair_protocol);
Jonas Olsson84df1c72018-09-14 16:59:32 +0200434 return ss.Release();
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800435}
436
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200437std::string GetDirectionAsString(PacketDirection direction) {
438 if (direction == kIncomingPacket) {
439 return "Incoming";
440 } else {
441 return "Outgoing";
442 }
443}
444
445std::string GetDirectionAsShortString(PacketDirection direction) {
446 if (direction == kIncomingPacket) {
447 return "In";
448 } else {
449 return "Out";
450 }
451}
452
terelius54ce6802016-07-13 06:44:41 -0700453} // namespace
454
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100455EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200456 bool normalize_time)
Bjorn Terelius068fc352019-02-13 22:38:25 +0100457 : parsed_log_(log) {
458 config_.window_duration_ = 250000;
459 config_.step_ = 10000;
460 config_.normalize_time_ = normalize_time;
461 config_.begin_time_ = parsed_log_.first_timestamp();
462 config_.end_time_ = parsed_log_.last_timestamp();
463 if (config_.end_time_ < config_.begin_time_) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200464 RTC_LOG(LS_WARNING) << "No useful events in the log.";
Bjorn Terelius068fc352019-02-13 22:38:25 +0100465 config_.begin_time_ = config_.end_time_ = 0;
Björn Tereliusff612732018-04-25 14:23:01 +0000466 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200467
Bjorn Terelius48b82792020-05-19 10:57:24 +0200468 RTC_LOG(LS_INFO) << "Found " << parsed_log_.log_segments().size()
469 << " (LOG_START, LOG_END) segments in log.";
470}
471
472EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
473 const AnalyzerConfig& config)
474 : parsed_log_(log), config_(config) {
475 RTC_LOG(LS_INFO) << "Found " << parsed_log_.log_segments().size()
Yves Gerey665174f2018-06-19 15:03:05 +0200476 << " (LOG_START, LOG_END) segments in log.";
terelius54ce6802016-07-13 06:44:41 -0700477}
478
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200479class BitrateObserver : public RemoteBitrateObserver {
Stefan Holmer13181032016-07-29 14:48:54 +0200480 public:
481 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
482
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200483 void Update(NetworkControlUpdate update) {
484 if (update.target_rate) {
485 last_bitrate_bps_ = update.target_rate->target_rate.bps();
486 bitrate_updated_ = true;
487 }
Stefan Holmer13181032016-07-29 14:48:54 +0200488 }
489
490 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
491 uint32_t bitrate) override {}
492
493 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
494 bool GetAndResetBitrateUpdated() {
495 bool bitrate_updated = bitrate_updated_;
496 bitrate_updated_ = false;
497 return bitrate_updated;
498 }
499
500 private:
501 uint32_t last_bitrate_bps_;
502 bool bitrate_updated_;
503};
504
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200505void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction,
terelius54ce6802016-07-13 06:44:41 -0700506 Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200507 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
508 // Filter on SSRC.
509 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700510 continue;
terelius54ce6802016-07-13 06:44:41 -0700511 }
terelius54ce6802016-07-13 06:44:41 -0700512
Bjorn Terelius48b82792020-05-19 10:57:24 +0200513 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200514 LineStyle::kBar);
515 auto GetPacketSize = [](const LoggedRtpPacket& packet) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200516 return absl::optional<float>(packet.total_length);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200517 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200518 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100519 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200520 };
521 ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize,
522 stream.packet_view, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700523 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700524 }
525
Bjorn Terelius068fc352019-02-13 22:38:25 +0100526 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
527 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700528 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
529 kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200530 plot->SetTitle(GetDirectionAsString(direction) + " RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700531}
532
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100533void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction,
534 Plot* plot) {
535 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
536 parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1));
537 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
538 parsed_log_.receiver_reports(direction), config_, "RR", 2));
539 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
540 parsed_log_.sender_reports(direction), config_, "SR", 3));
541 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
542 parsed_log_.extended_reports(direction), config_, "XR", 4));
543 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction),
544 config_, "NACK", 5));
545 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction),
546 config_, "REMB", 6));
547 plot->AppendTimeSeries(
548 CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7));
549 plot->AppendTimeSeries(
550 CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8));
551 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
552 "Time (s)", kLeftMargin, kRightMargin);
553 plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin);
554 plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets");
Bjorn Tereliusf640b872019-07-24 15:46:39 +0200555 plot->SetYAxisTickLabels({{1, "TWCC"},
556 {2, "RR"},
557 {3, "SR"},
558 {4, "XR"},
559 {5, "NACK"},
560 {6, "REMB"},
561 {7, "FIR"},
562 {8, "PLI"}});
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100563}
564
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200565template <typename IterableType>
philipelccd74892016-09-05 02:46:25 -0700566void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
philipelccd74892016-09-05 02:46:25 -0700567 Plot* plot,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200568 const IterableType& packets,
569 const std::string& label) {
570 TimeSeries time_series(label, LineStyle::kStep);
571 for (size_t i = 0; i < packets.size(); i++) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100572 float x = config_.GetCallTimeSec(packets[i].log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200573 time_series.points.emplace_back(x, i + 1);
philipelccd74892016-09-05 02:46:25 -0700574 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200575 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700576}
577
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200578void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction,
579 Plot* plot) {
580 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
581 if (!MatchingSsrc(stream.ssrc, desired_ssrc_))
582 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200583 std::string label = std::string("RTP ") +
584 GetStreamName(parsed_log_, direction, stream.ssrc);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200585 CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label);
586 }
587 std::string label =
588 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")";
589 if (direction == kIncomingPacket) {
590 CreateAccumulatedPacketsTimeSeries(
591 plot, parsed_log_.incoming_rtcp_packets(), label);
592 } else {
593 CreateAccumulatedPacketsTimeSeries(
594 plot, parsed_log_.outgoing_rtcp_packets(), label);
595 }
philipelccd74892016-09-05 02:46:25 -0700596
Bjorn Terelius068fc352019-02-13 22:38:25 +0100597 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
598 "Time (s)", kLeftMargin, kRightMargin);
philipelccd74892016-09-05 02:46:25 -0700599 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200600 plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) +
601 " RTP/RTCP packets");
philipelccd74892016-09-05 02:46:25 -0700602}
603
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200604void EventLogAnalyzer::CreatePacketRateGraph(PacketDirection direction,
605 Plot* plot) {
606 auto CountPackets = [](auto packet) { return 1.0; };
607 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
608 // Filter on SSRC.
609 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
610 continue;
611 }
612 TimeSeries time_series(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200613 std::string("RTP ") +
614 GetStreamName(parsed_log_, direction, stream.ssrc),
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200615 LineStyle::kLine);
616 MovingAverage<LoggedRtpPacket, double>(CountPackets, stream.packet_view,
617 config_, &time_series);
618 plot->AppendTimeSeries(std::move(time_series));
619 }
620 TimeSeries time_series(
621 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")",
622 LineStyle::kLine);
623 if (direction == kIncomingPacket) {
624 MovingAverage<LoggedRtcpPacketIncoming, double>(
625 CountPackets, parsed_log_.incoming_rtcp_packets(), config_,
626 &time_series);
627 } else {
628 MovingAverage<LoggedRtcpPacketOutgoing, double>(
629 CountPackets, parsed_log_.outgoing_rtcp_packets(), config_,
630 &time_series);
631 }
632 plot->AppendTimeSeries(std::move(time_series));
633
634 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
635 "Time (s)", kLeftMargin, kRightMargin);
636 plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin,
637 kTopMargin);
638 plot->SetTitle("Rate of " + GetDirectionAsString(direction) +
639 " RTP/RTCP packets");
640}
641
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200642void EventLogAnalyzer::CreateTotalPacketRateGraph(PacketDirection direction,
643 Plot* plot) {
644 // Contains a log timestamp to enable counting logged events of different
645 // types using MovingAverage().
646 class LogTime {
647 public:
648 explicit LogTime(int64_t log_time_us) : log_time_us_(log_time_us) {}
649
650 int64_t log_time_us() const { return log_time_us_; }
651
652 private:
653 int64_t log_time_us_;
654 };
655
656 std::vector<LogTime> packet_times;
657 auto handle_rtp = [&](const LoggedRtpPacket& packet) {
658 packet_times.emplace_back(packet.log_time_us());
659 };
660 RtcEventProcessor process;
661 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
662 process.AddEvents(stream.packet_view, handle_rtp);
663 }
664 if (direction == kIncomingPacket) {
665 auto handle_incoming_rtcp = [&](const LoggedRtcpPacketIncoming& packet) {
666 packet_times.emplace_back(packet.log_time_us());
667 };
668 process.AddEvents(parsed_log_.incoming_rtcp_packets(),
669 handle_incoming_rtcp);
670 } else {
671 auto handle_outgoing_rtcp = [&](const LoggedRtcpPacketOutgoing& packet) {
672 packet_times.emplace_back(packet.log_time_us());
673 };
674 process.AddEvents(parsed_log_.outgoing_rtcp_packets(),
675 handle_outgoing_rtcp);
676 }
677 process.ProcessEventsInOrder();
678 TimeSeries time_series(std::string("Total ") + "(" +
679 GetDirectionAsShortString(direction) + ") packets",
680 LineStyle::kLine);
681 MovingAverage<LogTime, uint64_t>([](auto packet) { return 1; }, packet_times,
682 config_, &time_series);
683 plot->AppendTimeSeries(std::move(time_series));
684
685 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
686 "Time (s)", kLeftMargin, kRightMargin);
687 plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin,
688 kTopMargin);
689 plot->SetTitle("Rate of all " + GetDirectionAsString(direction) +
690 " RTP/RTCP packets");
691}
692
terelius54ce6802016-07-13 06:44:41 -0700693// For each SSRC, plot the time between the consecutive playouts.
694void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200695 for (const auto& playout_stream : parsed_log_.audio_playout_events()) {
696 uint32_t ssrc = playout_stream.first;
697 if (!MatchingSsrc(ssrc, desired_ssrc_))
698 continue;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200699 absl::optional<int64_t> last_playout_ms;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200700 TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar);
Minyue Li27e2b7d2018-05-07 15:20:24 +0200701 for (const auto& playout_event : playout_stream.second) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100702 float x = config_.GetCallTimeSec(playout_event.log_time_us());
Minyue Li27e2b7d2018-05-07 15:20:24 +0200703 int64_t playout_time_ms = playout_event.log_time_ms();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200704 // If there were no previous playouts, place the point on the x-axis.
Minyue Li27e2b7d2018-05-07 15:20:24 +0200705 float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200706 time_series.points.push_back(TimeSeriesPoint(x, y));
Minyue Li27e2b7d2018-05-07 15:20:24 +0200707 last_playout_ms.emplace(playout_time_ms);
terelius54ce6802016-07-13 06:44:41 -0700708 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200709 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700710 }
711
Bjorn Terelius068fc352019-02-13 22:38:25 +0100712 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
713 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700714 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
715 kTopMargin);
716 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700717}
718
ivocaac9d6f2016-09-22 07:01:47 -0700719// For audio SSRCs, plot the audio level.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200720void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction,
721 Plot* plot) {
722 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
Bjorn Terelius48b82792020-05-19 10:57:24 +0200723 if (!IsAudioSsrc(parsed_log_, direction, stream.ssrc))
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200724 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200725 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200726 LineStyle::kLine);
727 for (auto& packet : stream.packet_view) {
ivocaac9d6f2016-09-22 07:01:47 -0700728 if (packet.header.extension.hasAudioLevel) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100729 float x = config_.GetCallTimeSec(packet.log_time_us());
ivocaac9d6f2016-09-22 07:01:47 -0700730 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
731 // Here we convert it to dBov.
732 float y = static_cast<float>(-packet.header.extension.audioLevel);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200733 time_series.points.emplace_back(TimeSeriesPoint(x, y));
ivocaac9d6f2016-09-22 07:01:47 -0700734 }
735 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200736 plot->AppendTimeSeries(std::move(time_series));
ivocaac9d6f2016-09-22 07:01:47 -0700737 }
738
Bjorn Terelius068fc352019-02-13 22:38:25 +0100739 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
740 "Time (s)", kLeftMargin, kRightMargin);
Yves Gerey665174f2018-06-19 15:03:05 +0200741 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200742 plot->SetTitle(GetDirectionAsString(direction) + " audio level");
ivocaac9d6f2016-09-22 07:01:47 -0700743}
744
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100745// For each SSRC, plot the sequence number difference between consecutive
746// incoming packets.
terelius54ce6802016-07-13 06:44:41 -0700747void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200748 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
749 // Filter on SSRC.
750 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700751 continue;
terelius54ce6802016-07-13 06:44:41 -0700752 }
terelius54ce6802016-07-13 06:44:41 -0700753
Bjorn Terelius48b82792020-05-19 10:57:24 +0200754 TimeSeries time_series(
755 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc),
756 LineStyle::kBar);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200757 auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet,
758 const LoggedRtpPacketIncoming& new_packet) {
759 int64_t diff =
760 WrappingDifference(new_packet.rtp.header.sequenceNumber,
761 old_packet.rtp.header.sequenceNumber, 1ul << 16);
762 return diff;
763 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200764 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100765 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200766 };
767 ProcessPairs<LoggedRtpPacketIncoming, float>(
768 ToCallTime, GetSequenceNumberDiff, stream.incoming_packets,
769 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700770 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700771 }
772
Bjorn Terelius068fc352019-02-13 22:38:25 +0100773 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
774 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700775 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
776 kTopMargin);
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100777 plot->SetTitle("Incoming sequence number delta");
terelius54ce6802016-07-13 06:44:41 -0700778}
779
Stefan Holmer99f8e082016-09-09 13:37:50 +0200780void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200781 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
782 const std::vector<LoggedRtpPacketIncoming>& packets =
783 stream.incoming_packets;
784 // Filter on SSRC.
Mirko Bonadei1f173152019-07-25 15:28:14 +0200785 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.empty()) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200786 continue;
787 }
788
Bjorn Terelius48b82792020-05-19 10:57:24 +0200789 TimeSeries time_series(
790 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc),
791 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200792 // TODO(terelius): Should the window and step size be read from the class
793 // instead?
794 const int64_t kWindowUs = 1000000;
795 const int64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100796 SeqNumUnwrapper<uint16_t> unwrapper_;
797 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800798 size_t window_index_begin = 0;
799 size_t window_index_end = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200800 uint64_t highest_seq_number =
801 unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
802 uint64_t highest_prior_seq_number =
803 prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
terelius4c9b4af2017-01-30 08:44:51 -0800804
Bjorn Terelius068fc352019-02-13 22:38:25 +0100805 for (int64_t t = config_.begin_time_; t < config_.end_time_ + kStep;
806 t += kStep) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200807 while (window_index_end < packets.size() &&
808 packets[window_index_end].rtp.log_time_us() < t) {
809 uint64_t sequence_number = unwrapper_.Unwrap(
810 packets[window_index_end].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800811 highest_seq_number = std::max(highest_seq_number, sequence_number);
812 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200813 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200814 while (window_index_begin < packets.size() &&
815 packets[window_index_begin].rtp.log_time_us() < t - kWindowUs) {
816 uint64_t sequence_number = prior_unwrapper_.Unwrap(
817 packets[window_index_begin].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800818 highest_prior_seq_number =
819 std::max(highest_prior_seq_number, sequence_number);
820 ++window_index_begin;
821 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100822 float x = config_.GetCallTimeSec(t);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200823 uint64_t expected_packets = highest_seq_number - highest_prior_seq_number;
terelius4c9b4af2017-01-30 08:44:51 -0800824 if (expected_packets > 0) {
825 int64_t received_packets = window_index_end - window_index_begin;
826 int64_t lost_packets = expected_packets - received_packets;
827 float y = static_cast<float>(lost_packets) / expected_packets * 100;
828 time_series.points.emplace_back(x, y);
829 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200830 }
philipel35ba9bd2017-04-19 05:58:51 -0700831 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200832 }
833
Bjorn Terelius068fc352019-02-13 22:38:25 +0100834 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
835 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100836 plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin);
837 plot->SetTitle("Incoming packet loss (derived from incoming packets)");
Stefan Holmer99f8e082016-09-09 13:37:50 +0200838}
839
terelius2ee076d2017-08-15 02:04:02 -0700840void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100841 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200842 // Filter on SSRC.
843 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
Bjorn Terelius48b82792020-05-19 10:57:24 +0200844 IsRtxSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700845 continue;
846 }
terelius54ce6802016-07-13 06:44:41 -0700847
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100848 const std::vector<LoggedRtpPacketIncoming>& packets =
849 stream.incoming_packets;
850 if (packets.size() < 100) {
851 RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with "
852 << packets.size() << " packets in the stream.";
853 continue;
854 }
Bjorn Terelius48b82792020-05-19 10:57:24 +0200855 int64_t segment_end_us =
856 parsed_log_.log_segments().empty()
857 ? std::numeric_limits<int64_t>::max()
858 : parsed_log_.log_segments().front().stop_time_us();
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100859 absl::optional<uint32_t> estimated_frequency =
Bjorn Terelius48b82792020-05-19 10:57:24 +0200860 EstimateRtpClockFrequency(packets, segment_end_us);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100861 if (!estimated_frequency)
862 continue;
863 const double frequency_hz = *estimated_frequency;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200864 if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc) &&
865 frequency_hz != 90000) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100866 RTC_LOG(LS_WARNING)
867 << "Video stream should use a 90 kHz clock but appears to use "
868 << frequency_hz / 1000 << ". Discarding.";
869 continue;
870 }
871
872 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100873 return this->config_.GetCallTimeSec(packet.log_time_us());
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100874 };
875 auto ToNetworkDelay = [frequency_hz](
876 const LoggedRtpPacketIncoming& old_packet,
877 const LoggedRtpPacketIncoming& new_packet) {
878 return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz);
879 };
880
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200881 TimeSeries capture_time_data(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200882 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) +
883 " capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200884 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100885 AccumulatePairs<LoggedRtpPacketIncoming, double>(
886 ToCallTime, ToNetworkDelay, packets, &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700887 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700888
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200889 TimeSeries send_time_data(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200890 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) +
891 " abs-send-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200892 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100893 AccumulatePairs<LoggedRtpPacketIncoming, double>(
894 ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data);
895 plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700896 }
897
Bjorn Terelius068fc352019-02-13 22:38:25 +0100898 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
899 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +0100900 plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin);
901 plot->SetTitle("Incoming network delay (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700902}
903
tereliusf736d232016-08-04 10:00:11 -0700904// Plot the fraction of packets lost (as perceived by the loss-based BWE).
905void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100906 TimeSeries time_series("Fraction lost", LineStyle::kLine,
907 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200908 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100909 float x = config_.GetCallTimeSec(bwe_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200910 float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700911 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700912 }
tereliusf736d232016-08-04 10:00:11 -0700913
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200914 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +0100915 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
916 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100917 plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin);
918 plot->SetTitle("Outgoing packet loss (as reported by BWE)");
tereliusf736d232016-08-04 10:00:11 -0700919}
920
terelius54ce6802016-07-13 06:44:41 -0700921// Plot the total bandwidth used by all RTP streams.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200922void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) {
923 // TODO(terelius): This could be provided by the parser.
924 std::multimap<int64_t, size_t> packets_in_order;
925 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
926 for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets)
927 packets_in_order.insert(
928 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
terelius54ce6802016-07-13 06:44:41 -0700929 }
930
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200931 auto window_begin = packets_in_order.begin();
932 auto window_end = packets_in_order.begin();
terelius54ce6802016-07-13 06:44:41 -0700933 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700934
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800935 if (!packets_in_order.empty()) {
936 // Calculate a moving average of the bitrate and store in a TimeSeries.
937 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
938 for (int64_t time = config_.begin_time_;
939 time < config_.end_time_ + config_.step_; time += config_.step_) {
940 while (window_end != packets_in_order.end() && window_end->first < time) {
941 bytes_in_window += window_end->second;
942 ++window_end;
943 }
944 while (window_begin != packets_in_order.end() &&
945 window_begin->first < time - config_.window_duration_) {
946 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
947 bytes_in_window -= window_begin->second;
948 ++window_begin;
949 }
950 float window_duration_in_seconds =
951 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
952 float x = config_.GetCallTimeSec(time);
953 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
954 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700955 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800956 plot->AppendTimeSeries(std::move(bitrate_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200957 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200958
959 // Overlay the outgoing REMB over incoming bitrate.
960 TimeSeries remb_series("Remb", LineStyle::kStep);
961 for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100962 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200963 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
964 remb_series.points.emplace_back(x, y);
965 }
966 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
967
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800968 if (!parsed_log_.generic_packets_received().empty()) {
969 TimeSeries time_series("Incoming generic bitrate", LineStyle::kLine);
970 auto GetPacketSizeKilobits = [](const LoggedGenericPacketReceived& packet) {
971 return packet.packet_length * 8.0 / 1000.0;
972 };
973 MovingAverage<LoggedGenericPacketReceived, double>(
974 GetPacketSizeKilobits, parsed_log_.generic_packets_received(), config_,
975 &time_series);
976 plot->AppendTimeSeries(std::move(time_series));
977 }
978
Bjorn Terelius068fc352019-02-13 22:38:25 +0100979 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
980 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200981 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
982 plot->SetTitle("Incoming RTP bitrate");
983}
984
985// Plot the total bandwidth used by all RTP streams.
986void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
987 bool show_detector_state,
988 bool show_alr_state) {
989 // TODO(terelius): This could be provided by the parser.
990 std::multimap<int64_t, size_t> packets_in_order;
991 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
992 for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets)
993 packets_in_order.insert(
994 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
995 }
996
997 auto window_begin = packets_in_order.begin();
998 auto window_end = packets_in_order.begin();
999 size_t bytes_in_window = 0;
1000
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001001 if (!packets_in_order.empty()) {
1002 // Calculate a moving average of the bitrate and store in a TimeSeries.
1003 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
1004 for (int64_t time = config_.begin_time_;
1005 time < config_.end_time_ + config_.step_; time += config_.step_) {
1006 while (window_end != packets_in_order.end() && window_end->first < time) {
1007 bytes_in_window += window_end->second;
1008 ++window_end;
1009 }
1010 while (window_begin != packets_in_order.end() &&
1011 window_begin->first < time - config_.window_duration_) {
1012 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
1013 bytes_in_window -= window_begin->second;
1014 ++window_begin;
1015 }
1016 float window_duration_in_seconds =
1017 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
1018 float x = config_.GetCallTimeSec(time);
1019 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
1020 bitrate_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001021 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001022 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -07001023 }
1024
terelius8058e582016-07-25 01:32:41 -07001025 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001026 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
1027 for (auto& loss_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001028 float x = config_.GetCallTimeSec(loss_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001029 float y = static_cast<float>(loss_update.bitrate_bps) / 1000;
1030 loss_series.points.emplace_back(x, y);
1031 }
philipel10fc0e62017-04-11 01:50:23 -07001032
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001033 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
1034 IntervalSeries overusing_series("Overusing", "#ff8e82",
1035 IntervalSeries::kHorizontal);
1036 IntervalSeries underusing_series("Underusing", "#5092fc",
1037 IntervalSeries::kHorizontal);
1038 IntervalSeries normal_series("Normal", "#c4ffc4",
1039 IntervalSeries::kHorizontal);
1040 IntervalSeries* last_series = &normal_series;
1041 double last_detector_switch = 0.0;
philipel23c7f252017-07-14 06:30:03 -07001042
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001043 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
philipel23c7f252017-07-14 06:30:03 -07001044
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001045 for (auto& delay_update : parsed_log_.bwe_delay_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001046 float x = config_.GetCallTimeSec(delay_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001047 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -07001048
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001049 if (last_detector_state != delay_update.detector_state) {
1050 last_series->intervals.emplace_back(last_detector_switch, x);
1051 last_detector_state = delay_update.detector_state;
1052 last_detector_switch = x;
philipel23c7f252017-07-14 06:30:03 -07001053
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001054 switch (delay_update.detector_state) {
1055 case BandwidthUsage::kBwNormal:
1056 last_series = &normal_series;
1057 break;
1058 case BandwidthUsage::kBwUnderusing:
1059 last_series = &underusing_series;
1060 break;
1061 case BandwidthUsage::kBwOverusing:
1062 last_series = &overusing_series;
1063 break;
1064 case BandwidthUsage::kLast:
1065 RTC_NOTREACHED();
philipele127e7a2017-03-29 16:28:53 +02001066 }
1067 }
philipel23c7f252017-07-14 06:30:03 -07001068
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001069 delay_series.points.emplace_back(x, y);
1070 }
Bjorn Terelius9e336ec2018-04-24 16:28:35 +02001071
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001072 RTC_CHECK(last_series);
Bjorn Terelius068fc352019-02-13 22:38:25 +01001073 last_series->intervals.emplace_back(last_detector_switch, config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001074
1075 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
1076 PointStyle::kHighlight);
1077 for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001078 float x = config_.GetCallTimeSec(cluster.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001079 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
1080 created_series.points.emplace_back(x, y);
1081 }
1082
1083 TimeSeries result_series("Probing results.", LineStyle::kNone,
1084 PointStyle::kHighlight);
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001085 for (auto& result : parsed_log_.bwe_probe_success_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001086 float x = config_.GetCallTimeSec(result.log_time_us());
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001087 float y = static_cast<float>(result.bitrate_bps) / 1000;
1088 result_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001089 }
1090
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001091 TimeSeries probe_failures_series("Probe failed", LineStyle::kNone,
1092 PointStyle::kHighlight);
1093 for (auto& failure : parsed_log_.bwe_probe_failure_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001094 float x = config_.GetCallTimeSec(failure.log_time_us());
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001095 probe_failures_series.points.emplace_back(x, 0);
1096 }
1097
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001098 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
1099 bool previously_in_alr = false;
1100 int64_t alr_start = 0;
1101 for (auto& alr : parsed_log_.alr_state_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001102 float y = config_.GetCallTimeSec(alr.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001103 if (!previously_in_alr && alr.in_alr) {
1104 alr_start = alr.log_time_us();
1105 previously_in_alr = true;
1106 } else if (previously_in_alr && !alr.in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001107 float x = config_.GetCallTimeSec(alr_start);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001108 alr_state.intervals.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001109 previously_in_alr = false;
Björn Tereliusff612732018-04-25 14:23:01 +00001110 }
Björn Tereliusff612732018-04-25 14:23:01 +00001111 }
1112
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001113 if (previously_in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001114 float x = config_.GetCallTimeSec(alr_start);
1115 float y = config_.GetCallTimeSec(config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001116 alr_state.intervals.emplace_back(x, y);
1117 }
1118
1119 if (show_detector_state) {
1120 plot->AppendIntervalSeries(std::move(overusing_series));
1121 plot->AppendIntervalSeries(std::move(underusing_series));
1122 plot->AppendIntervalSeries(std::move(normal_series));
1123 }
1124
1125 if (show_alr_state) {
1126 plot->AppendIntervalSeries(std::move(alr_state));
1127 }
1128 plot->AppendTimeSeries(std::move(loss_series));
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001129 plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001130 plot->AppendTimeSeries(std::move(delay_series));
1131 plot->AppendTimeSeries(std::move(created_series));
1132 plot->AppendTimeSeries(std::move(result_series));
1133
1134 // Overlay the incoming REMB over the outgoing bitrate.
Björn Tereliusff612732018-04-25 14:23:01 +00001135 TimeSeries remb_series("Remb", LineStyle::kStep);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001136 for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001137 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001138 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
terelius2c8e8a32017-06-02 01:29:48 -07001139 remb_series.points.emplace_back(x, y);
1140 }
1141 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1142
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001143 if (!parsed_log_.generic_packets_sent().empty()) {
1144 {
1145 TimeSeries time_series("Outgoing generic total bitrate",
1146 LineStyle::kLine);
1147 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1148 return packet.packet_length() * 8.0 / 1000.0;
1149 };
1150 MovingAverage<LoggedGenericPacketSent, double>(
1151 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1152 &time_series);
1153 plot->AppendTimeSeries(std::move(time_series));
1154 }
1155
1156 {
1157 TimeSeries time_series("Outgoing generic payload bitrate",
1158 LineStyle::kLine);
1159 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1160 return packet.payload_length * 8.0 / 1000.0;
1161 };
1162 MovingAverage<LoggedGenericPacketSent, double>(
1163 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1164 &time_series);
1165 plot->AppendTimeSeries(std::move(time_series));
1166 }
1167 }
1168
Bjorn Terelius068fc352019-02-13 22:38:25 +01001169 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1170 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001171 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001172 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001173}
1174
1175// For each SSRC, plot the bandwidth used by that stream.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001176void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction,
1177 Plot* plot) {
1178 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1179 // Filter on SSRC.
1180 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -07001181 continue;
terelius54ce6802016-07-13 06:44:41 -07001182 }
1183
Bjorn Terelius48b82792020-05-19 10:57:24 +02001184 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001185 LineStyle::kLine);
1186 auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) {
1187 return packet.total_length * 8.0 / 1000.0;
1188 };
terelius53dc23c2017-03-13 05:24:05 -07001189 MovingAverage<LoggedRtpPacket, double>(
Bjorn Terelius068fc352019-02-13 22:38:25 +01001190 GetPacketSizeKilobits, stream.packet_view, config_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001191 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001192 }
1193
Bjorn Terelius068fc352019-02-13 22:38:25 +01001194 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1195 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001196 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001197 plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001198}
1199
Bjorn Terelius9775a582019-02-15 17:29:58 +01001200// Plot the bitrate allocation for each temporal and spatial layer.
1201// Computed from RTCP XR target bitrate block, so the graph is only populated if
1202// those are sent.
1203void EventLogAnalyzer::CreateBitrateAllocationGraph(PacketDirection direction,
1204 Plot* plot) {
1205 std::map<LayerDescription, TimeSeries> time_series;
1206 const auto& xr_list = parsed_log_.extended_reports(direction);
1207 for (const auto& rtcp : xr_list) {
1208 const absl::optional<rtcp::TargetBitrate>& target_bitrate =
1209 rtcp.xr.target_bitrate();
1210 if (!target_bitrate.has_value())
1211 continue;
1212 for (const auto& bitrate_item : target_bitrate->GetTargetBitrates()) {
1213 LayerDescription layer(rtcp.xr.sender_ssrc(), bitrate_item.spatial_layer,
1214 bitrate_item.temporal_layer);
1215 auto time_series_it = time_series.find(layer);
1216 if (time_series_it == time_series.end()) {
1217 std::string layer_name = GetLayerName(layer);
1218 bool inserted;
1219 std::tie(time_series_it, inserted) = time_series.insert(
1220 std::make_pair(layer, TimeSeries(layer_name, LineStyle::kStep)));
1221 RTC_DCHECK(inserted);
1222 }
1223 float x = config_.GetCallTimeSec(rtcp.log_time_us());
1224 float y = bitrate_item.target_bitrate_kbps;
1225 time_series_it->second.points.emplace_back(x, y);
1226 }
1227 }
1228 for (auto& layer : time_series) {
1229 plot->AppendTimeSeries(std::move(layer.second));
1230 }
1231 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1232 "Time (s)", kLeftMargin, kRightMargin);
1233 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1234 if (direction == kIncomingPacket)
1235 plot->SetTitle("Target bitrate per incoming layer");
1236 else
1237 plot->SetTitle("Target bitrate per outgoing layer");
1238}
1239
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001240void EventLogAnalyzer::CreateGoogCcSimulationGraph(Plot* plot) {
1241 TimeSeries target_rates("Simulated target rate", LineStyle::kStep,
1242 PointStyle::kHighlight);
1243 TimeSeries delay_based("Logged delay-based estimate", LineStyle::kStep,
1244 PointStyle::kHighlight);
1245 TimeSeries loss_based("Logged loss-based estimate", LineStyle::kStep,
1246 PointStyle::kHighlight);
1247 TimeSeries probe_results("Logged probe success", LineStyle::kNone,
1248 PointStyle::kHighlight);
1249
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001250 LogBasedNetworkControllerSimulation simulation(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001251 std::make_unique<GoogCcNetworkControllerFactory>(),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001252 [&](const NetworkControlUpdate& update, Timestamp at_time) {
1253 if (update.target_rate) {
1254 target_rates.points.emplace_back(
1255 config_.GetCallTimeSec(at_time.us()),
1256 update.target_rate->target_rate.kbps<float>());
1257 }
1258 });
1259
1260 simulation.ProcessEventsInLog(parsed_log_);
1261 for (const auto& logged : parsed_log_.bwe_delay_updates())
1262 delay_based.points.emplace_back(
1263 config_.GetCallTimeSec(logged.log_time_us()),
1264 logged.bitrate_bps / 1000);
1265 for (const auto& logged : parsed_log_.bwe_probe_success_events())
1266 probe_results.points.emplace_back(
1267 config_.GetCallTimeSec(logged.log_time_us()),
1268 logged.bitrate_bps / 1000);
1269 for (const auto& logged : parsed_log_.bwe_loss_updates())
1270 loss_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time_us()),
1271 logged.bitrate_bps / 1000);
1272
1273 plot->AppendTimeSeries(std::move(delay_based));
1274 plot->AppendTimeSeries(std::move(loss_based));
1275 plot->AppendTimeSeries(std::move(probe_results));
1276 plot->AppendTimeSeries(std::move(target_rates));
1277
1278 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1279 "Time (s)", kLeftMargin, kRightMargin);
1280 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1281 plot->SetTitle("Simulated BWE behavior");
1282}
1283
Bjorn Terelius28db2662017-10-04 14:22:43 +02001284void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001285 using RtpPacketType = LoggedRtpPacketOutgoing;
1286 using TransportFeedbackType = LoggedRtcpPacketTransportFeedback;
Stefan Holmer13181032016-07-29 14:48:54 +02001287
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001288 // TODO(terelius): This could be provided by the parser.
1289 std::multimap<int64_t, const RtpPacketType*> outgoing_rtp;
1290 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1291 for (const RtpPacketType& rtp_packet : stream.outgoing_packets)
1292 outgoing_rtp.insert(
1293 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Stefan Holmer13181032016-07-29 14:48:54 +02001294 }
1295
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001296 const std::vector<TransportFeedbackType>& incoming_rtcp =
1297 parsed_log_.transport_feedbacks(kIncomingPacket);
Stefan Holmer13181032016-07-29 14:48:54 +02001298
1299 SimulatedClock clock(0);
1300 BitrateObserver observer;
Danil Chapovalov83bbe912019-08-07 12:24:53 +02001301 RtcEventLogNull null_event_log;
nisse0245da02016-11-30 03:35:20 -08001302 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001303 PacedSender pacer(&clock, &packet_router, &null_event_log);
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001304 TransportFeedbackAdapter transport_feedback;
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001305 auto factory = GoogCcNetworkControllerFactory();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001306 TimeDelta process_interval = factory.GetProcessInterval();
Stefan Holmer13181032016-07-29 14:48:54 +02001307 // TODO(holmer): Log the call config and use that here instead.
1308 static const uint32_t kDefaultStartBitrateBps = 300000;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001309 NetworkControllerConfig cc_config;
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001310 cc_config.constraints.at_time = Timestamp::Micros(clock.TimeInMicroseconds());
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +01001311 cc_config.constraints.starting_rate =
1312 DataRate::BitsPerSec(kDefaultStartBitrateBps);
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001313 cc_config.event_log = &null_event_log;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001314 auto goog_cc = factory.Create(cc_config);
Stefan Holmer13181032016-07-29 14:48:54 +02001315
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001316 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1317 PointStyle::kHighlight);
1318 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1319 PointStyle::kHighlight);
1320 TimeSeries acked_estimate_time_series(
1321 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001322
1323 auto rtp_iterator = outgoing_rtp.begin();
1324 auto rtcp_iterator = incoming_rtcp.begin();
1325
1326 auto NextRtpTime = [&]() {
1327 if (rtp_iterator != outgoing_rtp.end())
1328 return static_cast<int64_t>(rtp_iterator->first);
1329 return std::numeric_limits<int64_t>::max();
1330 };
1331
1332 auto NextRtcpTime = [&]() {
1333 if (rtcp_iterator != incoming_rtcp.end())
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001334 return static_cast<int64_t>(rtcp_iterator->log_time_us());
Stefan Holmer13181032016-07-29 14:48:54 +02001335 return std::numeric_limits<int64_t>::max();
1336 };
Bjorn Tereliusa728c912018-12-06 12:26:30 +01001337 int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()});
Stefan Holmer13181032016-07-29 14:48:54 +02001338
1339 auto NextProcessTime = [&]() {
1340 if (rtcp_iterator != incoming_rtcp.end() ||
1341 rtp_iterator != outgoing_rtp.end()) {
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001342 return next_process_time_us_;
Stefan Holmer13181032016-07-29 14:48:54 +02001343 }
1344 return std::numeric_limits<int64_t>::max();
1345 };
1346
Stefan Holmer492ee282016-10-27 17:19:20 +02001347 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001348#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson95edb032019-01-17 16:24:12 +01001349 FieldTrialBasedConfig field_trial_config_;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001350 // The event_log_visualizer should normally not be compiled with
1351 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
Björn Terelius251b0dc2019-11-11 21:00:18 +01001352 // However, compiling with BWE_TEST_LOGGING, running with --plot=sendside_bwe
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001353 // and piping the output to plot_dynamics.py can be used as a hack to get the
1354 // internal state of various BWE components. In this case, it is important
1355 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
Sebastian Jansson4ad51d82019-06-11 11:24:40 +02001356 // GoogCcNetworkController since that would lead to duplicate outputs.
Björn Terelius251b0dc2019-11-11 21:00:18 +01001357 std::unique_ptr<AcknowledgedBitrateEstimatorInterface>
1358 acknowledged_bitrate_estimator(
1359 AcknowledgedBitrateEstimatorInterface::Create(&field_trial_config_));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001360#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001361 int64_t time_us =
1362 std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
Stefan Holmer492ee282016-10-27 17:19:20 +02001363 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001364 while (time_us != std::numeric_limits<int64_t>::max()) {
1365 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001366 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1367 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1368 const RtpPacketType& rtp_packet = *rtp_iterator->second;
1369 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
1370 RTC_DCHECK(rtp_packet.rtp.header.extension.hasTransportSequenceNumber);
Erik Språng30a276b2019-04-23 12:00:11 +02001371 RtpPacketSendInfo packet_info;
1372 packet_info.ssrc = rtp_packet.rtp.header.ssrc;
Bjorn Tereliusf2e9cab2019-05-27 16:44:09 +02001373 packet_info.transport_sequence_number =
Erik Språng30a276b2019-04-23 12:00:11 +02001374 rtp_packet.rtp.header.extension.transportSequenceNumber;
1375 packet_info.rtp_sequence_number = rtp_packet.rtp.header.sequenceNumber;
Erik Språng30a276b2019-04-23 12:00:11 +02001376 packet_info.length = rtp_packet.rtp.total_length;
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001377 transport_feedback.AddPacket(
Erik Språng30a276b2019-04-23 12:00:11 +02001378 packet_info,
1379 0u, // Per packet overhead bytes.
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001380 Timestamp::Micros(rtp_packet.rtp.log_time_us()));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001381 rtc::SentPacket sent_packet(
1382 rtp_packet.rtp.header.extension.transportSequenceNumber,
1383 rtp_packet.rtp.log_time_us() / 1000);
1384 auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet);
1385 if (sent_msg)
1386 observer.Update(goog_cc->OnSentPacket(*sent_msg));
1387 }
1388 ++rtp_iterator;
1389 }
Stefan Holmer13181032016-07-29 14:48:54 +02001390 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001391 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001392
1393 auto feedback_msg = transport_feedback.ProcessTransportFeedback(
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001394 rtcp_iterator->transport_feedback,
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001395 Timestamp::Millis(clock.TimeInMilliseconds()));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001396 absl::optional<uint32_t> bitrate_bps;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001397 if (feedback_msg) {
1398 observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg));
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001399 std::vector<PacketResult> feedback =
1400 feedback_msg->SortedByReceiveTime();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001401 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001402#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Björn Terelius251b0dc2019-11-11 21:00:18 +01001403 acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
1404 feedback);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001405#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001406 for (const PacketResult& packet : feedback)
1407 acked_bitrate.Update(packet.sent_packet.size.bytes(),
1408 packet.receive_time.ms());
1409 bitrate_bps = acked_bitrate.Rate(feedback.back().receive_time.ms());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001410 }
Stefan Holmer13181032016-07-29 14:48:54 +02001411 }
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001412
Bjorn Terelius068fc352019-02-13 22:38:25 +01001413 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001414 float y = bitrate_bps.value_or(0) / 1000;
1415 acked_time_series.points.emplace_back(x, y);
1416#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Björn Terelius251b0dc2019-11-11 21:00:18 +01001417 y = acknowledged_bitrate_estimator->bitrate()
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001418 .value_or(DataRate::Zero())
1419 .kbps();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001420 acked_estimate_time_series.points.emplace_back(x, y);
1421#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001422 ++rtcp_iterator;
1423 }
stefanc3de0332016-08-02 07:22:17 -07001424 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1425 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001426 ProcessInterval msg;
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001427 msg.at_time = Timestamp::Micros(clock.TimeInMicroseconds());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001428 observer.Update(goog_cc->OnProcessInterval(msg));
1429 next_process_time_us_ += process_interval.us();
stefanc3de0332016-08-02 07:22:17 -07001430 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001431 if (observer.GetAndResetBitrateUpdated() ||
1432 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001433 uint32_t y = observer.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001434 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Stefan Holmer13181032016-07-29 14:48:54 +02001435 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001436 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001437 }
1438 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1439 }
1440 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001441 plot->AppendTimeSeries(std::move(time_series));
1442 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001443 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001444
Bjorn Terelius068fc352019-02-13 22:38:25 +01001445 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1446 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001447 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001448 plot->SetTitle("Simulated send-side BWE behavior");
1449}
1450
1451void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001452 using RtpPacketType = LoggedRtpPacketIncoming;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001453 class RembInterceptingPacketRouter : public PacketRouter {
1454 public:
1455 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1456 uint32_t bitrate_bps) override {
1457 last_bitrate_bps_ = bitrate_bps;
1458 bitrate_updated_ = true;
1459 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1460 }
1461 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1462 bool GetAndResetBitrateUpdated() {
1463 bool bitrate_updated = bitrate_updated_;
1464 bitrate_updated_ = false;
1465 return bitrate_updated;
1466 }
1467
1468 private:
1469 uint32_t last_bitrate_bps_;
1470 bool bitrate_updated_;
1471 };
1472
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001473 std::multimap<int64_t, const RtpPacketType*> incoming_rtp;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001474
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001475 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Terelius48b82792020-05-19 10:57:24 +02001476 if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001477 for (const auto& rtp_packet : stream.incoming_packets)
1478 incoming_rtp.insert(
1479 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Bjorn Terelius28db2662017-10-04 14:22:43 +02001480 }
1481 }
1482
1483 SimulatedClock clock(0);
1484 RembInterceptingPacketRouter packet_router;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001485 // TODO(terelius): The PacketRouter is used as the RemoteBitrateObserver.
Bjorn Terelius28db2662017-10-04 14:22:43 +02001486 // Is this intentional?
1487 ReceiveSideCongestionController rscc(&clock, &packet_router);
1488 // TODO(holmer): Log the call config and use that here instead.
1489 // static const uint32_t kDefaultStartBitrateBps = 300000;
1490 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1491
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001492 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1493 PointStyle::kHighlight);
1494 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001495
1496 RateStatistics acked_bitrate(250, 8000);
1497 int64_t last_update_us = 0;
1498 for (const auto& kv : incoming_rtp) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001499 const RtpPacketType& packet = *kv.second;
1500 int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000;
1501 size_t payload = packet.rtp.total_length; /*Should subtract header?*/
1502 clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() -
Bjorn Terelius28db2662017-10-04 14:22:43 +02001503 clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001504 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001505 acked_bitrate.Update(payload, arrival_time_ms);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001506 absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001507 if (bitrate_bps) {
1508 uint32_t y = *bitrate_bps / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001509 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001510 acked_time_series.points.emplace_back(x, y);
1511 }
1512 if (packet_router.GetAndResetBitrateUpdated() ||
1513 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1514 uint32_t y = packet_router.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001515 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001516 time_series.points.emplace_back(x, y);
1517 last_update_us = clock.TimeInMicroseconds();
1518 }
1519 }
1520 // Add the data set to the plot.
1521 plot->AppendTimeSeries(std::move(time_series));
1522 plot->AppendTimeSeries(std::move(acked_time_series));
1523
Bjorn Terelius068fc352019-02-13 22:38:25 +01001524 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1525 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001526 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1527 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001528}
1529
tereliuse34c19c2016-08-15 08:47:14 -07001530void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001531 TimeSeries time_series("Network delay", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001532 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001533 int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max();
1534 int64_t min_rtt_ms = std::numeric_limits<int64_t>::max();
stefanc3de0332016-08-02 07:22:17 -07001535
stefana0a8ed72017-09-06 02:06:32 -07001536 int64_t prev_y = 0;
Björn Tereliusc69c1bb2019-10-11 15:06:58 +02001537 std::vector<MatchedSendArrivalTimes> matched_rtp_rtcp =
1538 GetNetworkTrace(parsed_log_);
1539 absl::c_stable_sort(matched_rtp_rtcp, [](const MatchedSendArrivalTimes& a,
1540 const MatchedSendArrivalTimes& b) {
philipel3574d052019-11-18 14:38:13 +01001541 return a.feedback_arrival_time_ms < b.feedback_arrival_time_ms ||
1542 (a.feedback_arrival_time_ms == b.feedback_arrival_time_ms &&
1543 a.arrival_time_ms < b.arrival_time_ms);
Björn Tereliusc69c1bb2019-10-11 15:06:58 +02001544 });
1545 for (const auto& packet : matched_rtp_rtcp) {
Sebastian Jansson74f96ec2019-10-29 12:57:54 +01001546 if (packet.arrival_time_ms == MatchedSendArrivalTimes::kNotReceived)
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001547 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001548 float x = config_.GetCallTimeSec(1000 * packet.feedback_arrival_time_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001549 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1550 prev_y = y;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001551 int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms;
1552 min_rtt_ms = std::min(rtt_ms, min_rtt_ms);
1553 min_send_receive_diff_ms = std::min(y, min_send_receive_diff_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001554 time_series.points.emplace_back(x, y);
stefanc3de0332016-08-02 07:22:17 -07001555 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001556
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001557 // We assume that the base network delay (w/o queues) is equal to half
1558 // the minimum RTT. Therefore rescale the delays by subtracting the minimum
Mirko Bonadei604e75c2019-07-25 11:55:47 +02001559 // observed 1-ways delay and add half the minimum RTT.
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001560 const int64_t estimated_clock_offset_ms =
1561 min_send_receive_diff_ms - min_rtt_ms / 2;
stefanc3de0332016-08-02 07:22:17 -07001562 for (TimeSeriesPoint& point : time_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001563 point.y -= estimated_clock_offset_ms;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001564
stefanc3de0332016-08-02 07:22:17 -07001565 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001566 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001567
Bjorn Terelius068fc352019-02-13 22:38:25 +01001568 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1569 "Time (s)", kLeftMargin, kRightMargin);
stefanc3de0332016-08-02 07:22:17 -07001570 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +01001571 plot->SetTitle("Outgoing network delay (based on per-packet feedback)");
stefanc3de0332016-08-02 07:22:17 -07001572}
stefan08383272016-12-20 08:51:52 -08001573
Bjorn Terelius0295a962017-10-25 17:42:41 +02001574void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001575 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1576 const std::vector<LoggedRtpPacketOutgoing>& packets =
1577 stream.outgoing_packets;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001578
Bjorn Terelius48b82792020-05-19 10:57:24 +02001579 if (IsRtxSsrc(parsed_log_, kOutgoingPacket, stream.ssrc)) {
Konrad Hofbauerbfb735b2019-04-16 11:12:11 +02001580 continue;
1581 }
1582
Bjorn Terelius0295a962017-10-25 17:42:41 +02001583 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001584 RTC_LOG(LS_WARNING)
1585 << "Can't estimate a the RTP clock frequency or the "
1586 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001587 continue;
1588 }
Bjorn Terelius48b82792020-05-19 10:57:24 +02001589 int64_t segment_end_us =
1590 parsed_log_.log_segments().empty()
1591 ? std::numeric_limits<int64_t>::max()
1592 : parsed_log_.log_segments().front().stop_time_us();
Danil Chapovalov431abd92018-06-18 12:54:17 +02001593 absl::optional<uint32_t> estimated_frequency =
Bjorn Terelius48b82792020-05-19 10:57:24 +02001594 EstimateRtpClockFrequency(packets, segment_end_us);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001595 if (!estimated_frequency)
1596 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +02001597 if (IsVideoSsrc(parsed_log_, kOutgoingPacket, stream.ssrc) &&
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001598 *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001599 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001600 << "Video stream should use a 90 kHz clock but appears to use "
1601 << *estimated_frequency / 1000 << ". Discarding.";
1602 continue;
1603 }
1604
1605 TimeSeries pacer_delay_series(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001606 GetStreamName(parsed_log_, kOutgoingPacket, stream.ssrc) + "(" +
Bjorn Terelius0295a962017-10-25 17:42:41 +02001607 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001608 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001609 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1610 uint64_t first_capture_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001611 timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp);
1612 uint64_t first_send_timestamp = packets.front().rtp.log_time_us();
1613 for (const auto& packet : packets) {
Bjorn Terelius0295a962017-10-25 17:42:41 +02001614 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001615 packet.rtp.header.timestamp)) -
Bjorn Terelius0295a962017-10-25 17:42:41 +02001616 first_capture_timestamp) /
1617 *estimated_frequency * 1000;
1618 double send_time_ms =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001619 static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) /
1620 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001621 float x = config_.GetCallTimeSec(packet.rtp.log_time_us());
Bjorn Terelius0295a962017-10-25 17:42:41 +02001622 float y = send_time_ms - capture_time_ms;
1623 pacer_delay_series.points.emplace_back(x, y);
1624 }
1625 plot->AppendTimeSeries(std::move(pacer_delay_series));
1626 }
1627
Bjorn Terelius068fc352019-02-13 22:38:25 +01001628 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1629 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001630 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1631 plot->SetTitle(
1632 "Delay from capture to send time. (First packet normalized to 0.)");
1633}
1634
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001635void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction,
1636 Plot* plot) {
1637 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1638 TimeSeries rtp_timestamps(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001639 GetStreamName(parsed_log_, direction, stream.ssrc) + " capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001640 LineStyle::kLine, PointStyle::kHighlight);
1641 for (const auto& packet : stream.packet_view) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001642 float x = config_.GetCallTimeSec(packet.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001643 float y = packet.header.timestamp;
1644 rtp_timestamps.points.emplace_back(x, y);
stefane372d3c2017-02-02 08:04:18 -08001645 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001646 plot->AppendTimeSeries(std::move(rtp_timestamps));
Björn Tereliusff612732018-04-25 14:23:01 +00001647
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001648 TimeSeries rtcp_timestamps(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001649 GetStreamName(parsed_log_, direction, stream.ssrc) +
1650 " rtcp capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001651 LineStyle::kLine, PointStyle::kHighlight);
1652 // TODO(terelius): Why only sender reports?
1653 const auto& sender_reports = parsed_log_.sender_reports(direction);
1654 for (const auto& rtcp : sender_reports) {
1655 if (rtcp.sr.sender_ssrc() != stream.ssrc)
1656 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001657 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001658 float y = rtcp.sr.rtp_timestamp();
1659 rtcp_timestamps.points.emplace_back(x, y);
Björn Tereliusff612732018-04-25 14:23:01 +00001660 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001661 plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps));
stefane372d3c2017-02-02 08:04:18 -08001662 }
1663
Bjorn Terelius068fc352019-02-13 22:38:25 +01001664 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1665 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001666 plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin);
1667 plot->SetTitle(GetDirectionAsString(direction) + " timestamps");
stefane372d3c2017-02-02 08:04:18 -08001668}
michaelt6e5b2192017-02-22 07:33:27 -08001669
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001670void EventLogAnalyzer::CreateSenderAndReceiverReportPlot(
1671 PacketDirection direction,
1672 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
1673 std::string title,
1674 std::string yaxis_label,
1675 Plot* plot) {
1676 std::map<uint32_t, TimeSeries> sr_reports_by_ssrc;
1677 const auto& sender_reports = parsed_log_.sender_reports(direction);
1678 for (const auto& rtcp : sender_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001679 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001680 uint32_t ssrc = rtcp.sr.sender_ssrc();
1681 for (const auto& block : rtcp.sr.report_blocks()) {
1682 float y = fy(block);
1683 auto sr_report_it = sr_reports_by_ssrc.find(ssrc);
1684 bool inserted;
1685 if (sr_report_it == sr_reports_by_ssrc.end()) {
1686 std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001687 ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) +
1688 " Sender Reports",
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001689 LineStyle::kLine, PointStyle::kHighlight));
1690 }
1691 sr_report_it->second.points.emplace_back(x, y);
1692 }
1693 }
1694 for (auto& kv : sr_reports_by_ssrc) {
1695 plot->AppendTimeSeries(std::move(kv.second));
1696 }
1697
1698 std::map<uint32_t, TimeSeries> rr_reports_by_ssrc;
1699 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
1700 for (const auto& rtcp : receiver_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001701 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001702 uint32_t ssrc = rtcp.rr.sender_ssrc();
1703 for (const auto& block : rtcp.rr.report_blocks()) {
1704 float y = fy(block);
1705 auto rr_report_it = rr_reports_by_ssrc.find(ssrc);
1706 bool inserted;
1707 if (rr_report_it == rr_reports_by_ssrc.end()) {
1708 std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001709 ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) +
1710 " Receiver Reports",
1711 LineStyle::kLine, PointStyle::kHighlight));
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001712 }
1713 rr_report_it->second.points.emplace_back(x, y);
1714 }
1715 }
1716 for (auto& kv : rr_reports_by_ssrc) {
1717 plot->AppendTimeSeries(std::move(kv.second));
1718 }
1719
Bjorn Terelius068fc352019-02-13 22:38:25 +01001720 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1721 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001722 plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin);
1723 plot->SetTitle(title);
1724}
1725
michaelt6e5b2192017-02-22 07:33:27 -08001726void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001727 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1728 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001729 auto GetAnaBitrateBps = [](const LoggedAudioNetworkAdaptationEvent& ana_event)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001730 -> absl::optional<float> {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001731 if (ana_event.config.bitrate_bps)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001732 return absl::optional<float>(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001733 static_cast<float>(*ana_event.config.bitrate_bps));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001734 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001735 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001736 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001737 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001738 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001739 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001740 ToCallTime, GetAnaBitrateBps,
1741 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001742 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001743 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1744 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001745 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1746 plot->SetTitle("Reported audio encoder target bitrate");
1747}
1748
1749void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001750 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1751 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001752 auto GetAnaFrameLengthMs =
1753 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001754 if (ana_event.config.frame_length_ms)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001755 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001756 static_cast<float>(*ana_event.config.frame_length_ms));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001757 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001758 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001759 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001760 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001761 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001762 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001763 ToCallTime, GetAnaFrameLengthMs,
1764 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001765 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001766 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1767 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001768 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1769 plot->SetTitle("Reported audio encoder frame length");
1770}
1771
terelius2ee076d2017-08-15 02:04:02 -07001772void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001773 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001774 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001775 auto GetAnaPacketLoss =
1776 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001777 if (ana_event.config.uplink_packet_loss_fraction)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001778 return absl::optional<float>(static_cast<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001779 *ana_event.config.uplink_packet_loss_fraction));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001780 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001781 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001782 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001783 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001784 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001785 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001786 ToCallTime, GetAnaPacketLoss,
1787 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001788 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001789 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1790 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001791 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1792 kTopMargin);
1793 plot->SetTitle("Reported audio encoder lost packets");
1794}
1795
1796void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001797 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1798 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001799 auto GetAnaFecEnabled =
1800 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001801 if (ana_event.config.enable_fec)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001802 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001803 static_cast<float>(*ana_event.config.enable_fec));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001804 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001805 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001806 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001807 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001808 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001809 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001810 ToCallTime, GetAnaFecEnabled,
1811 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001812 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001813 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1814 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001815 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1816 plot->SetTitle("Reported audio encoder FEC");
1817}
1818
1819void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001820 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1821 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001822 auto GetAnaDtxEnabled =
1823 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001824 if (ana_event.config.enable_dtx)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001825 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001826 static_cast<float>(*ana_event.config.enable_dtx));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001827 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001828 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001829 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001830 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001831 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001832 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001833 ToCallTime, GetAnaDtxEnabled,
1834 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001835 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001836 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1837 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001838 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1839 plot->SetTitle("Reported audio encoder DTX");
1840}
1841
1842void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001843 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1844 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001845 auto GetAnaNumChannels =
1846 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001847 if (ana_event.config.num_channels)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001848 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001849 static_cast<float>(*ana_event.config.num_channels));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001850 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001851 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001852 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001853 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001854 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001855 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001856 ToCallTime, GetAnaNumChannels,
1857 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001858 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001859 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1860 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001861 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1862 kBottomMargin, kTopMargin);
1863 plot->SetTitle("Reported audio encoder number of channels");
1864}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001865
1866class NetEqStreamInput : public test::NetEqInput {
1867 public:
1868 // Does not take any ownership, and all pointers must refer to valid objects
1869 // that outlive the one constructed.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001870 NetEqStreamInput(const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001871 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001872 absl::optional<int64_t> end_time_ms)
henrik.lundin3c938fc2017-06-14 06:09:58 -07001873 : packet_stream_(*packet_stream),
1874 packet_stream_it_(packet_stream_.begin()),
Minyue Li27e2b7d2018-05-07 15:20:24 +02001875 output_events_it_(output_events->begin()),
1876 output_events_end_(output_events->end()),
1877 end_time_ms_(end_time_ms) {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001878 RTC_DCHECK(packet_stream);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001879 RTC_DCHECK(output_events);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001880 }
1881
Danil Chapovalov431abd92018-06-18 12:54:17 +02001882 absl::optional<int64_t> NextPacketTime() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001883 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001884 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001885 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001886 if (end_time_ms_ && packet_stream_it_->rtp.log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001887 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001888 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001889 return packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001890 }
1891
Danil Chapovalov431abd92018-06-18 12:54:17 +02001892 absl::optional<int64_t> NextOutputEventTime() const override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001893 if (output_events_it_ == output_events_end_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001894 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001895 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001896 if (end_time_ms_ && output_events_it_->log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001897 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001898 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001899 return output_events_it_->log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001900 }
1901
1902 std::unique_ptr<PacketData> PopPacket() override {
1903 if (packet_stream_it_ == packet_stream_.end()) {
1904 return std::unique_ptr<PacketData>();
1905 }
1906 std::unique_ptr<PacketData> packet_data(new PacketData());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001907 packet_data->header = packet_stream_it_->rtp.header;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001908 packet_data->time_ms = packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001909
1910 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1911 // length according to the virtual length.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001912 packet_data->payload.SetSize(packet_stream_it_->rtp.total_length -
1913 packet_stream_it_->rtp.header_length);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001914 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1915
1916 ++packet_stream_it_;
1917 return packet_data;
1918 }
1919
1920 void AdvanceOutputEvent() override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001921 if (output_events_it_ != output_events_end_) {
1922 ++output_events_it_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001923 }
1924 }
1925
1926 bool ended() const override { return !NextEventTime(); }
1927
Danil Chapovalov431abd92018-06-18 12:54:17 +02001928 absl::optional<RTPHeader> NextHeader() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001929 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001930 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001931 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001932 return packet_stream_it_->rtp.header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001933 }
1934
1935 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001936 const std::vector<LoggedRtpPacketIncoming>& packet_stream_;
1937 std::vector<LoggedRtpPacketIncoming>::const_iterator packet_stream_it_;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001938 std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_it_;
1939 const std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_end_;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001940 const absl::optional<int64_t> end_time_ms_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001941};
1942
1943namespace {
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001944
1945// Factory to create a "replacement decoder" that produces the decoded audio
1946// by reading from a file rather than from the encoded payloads.
1947class ReplacementAudioDecoderFactory : public AudioDecoderFactory {
1948 public:
1949 ReplacementAudioDecoderFactory(const absl::string_view replacement_file_name,
1950 int file_sample_rate_hz)
1951 : replacement_file_name_(replacement_file_name),
1952 file_sample_rate_hz_(file_sample_rate_hz) {}
1953
1954 std::vector<AudioCodecSpec> GetSupportedDecoders() override {
1955 RTC_NOTREACHED();
1956 return {};
1957 }
1958
1959 bool IsSupportedDecoder(const SdpAudioFormat& format) override {
1960 return true;
1961 }
1962
1963 std::unique_ptr<AudioDecoder> MakeAudioDecoder(
1964 const SdpAudioFormat& format,
1965 absl::optional<AudioCodecPairId> codec_pair_id) override {
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001966 auto replacement_file = std::make_unique<test::ResampleInputAudioFile>(
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001967 replacement_file_name_, file_sample_rate_hz_);
1968 replacement_file->set_output_rate_hz(48000);
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001969 return std::make_unique<test::FakeDecodeFromFile>(
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001970 std::move(replacement_file), 48000, false);
1971 }
1972
1973 private:
1974 const std::string replacement_file_name_;
1975 const int file_sample_rate_hz_;
1976};
1977
henrik.lundin3c938fc2017-06-14 06:09:58 -07001978// Creates a NetEq test object and all necessary input and output helpers. Runs
1979// the test and returns the NetEqDelayAnalyzer object that was used to
1980// instrument the test.
Minyue Lic6ff7572018-05-04 09:46:44 +02001981std::unique_ptr<test::NetEqStatsGetter> CreateNetEqTestAndRun(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001982 const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001983 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001984 absl::optional<int64_t> end_time_ms,
henrik.lundin3c938fc2017-06-14 06:09:58 -07001985 const std::string& replacement_file_name,
1986 int file_sample_rate_hz) {
1987 std::unique_ptr<test::NetEqInput> input(
Minyue Li27e2b7d2018-05-07 15:20:24 +02001988 new NetEqStreamInput(packet_stream, output_events, end_time_ms));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001989
1990 constexpr int kReplacementPt = 127;
1991 std::set<uint8_t> cn_types;
1992 std::set<uint8_t> forbidden_types;
1993 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1994 cn_types, forbidden_types));
1995
1996 NetEq::Config config;
1997 config.max_packets_in_buffer = 200;
1998 config.enable_fast_accelerate = true;
1999
2000 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
2001
Niels Möller3f651d82018-12-19 15:06:17 +01002002 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory =
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01002003 new rtc::RefCountedObject<ReplacementAudioDecoderFactory>(
2004 replacement_file_name, file_sample_rate_hz);
Niels Möller3f651d82018-12-19 15:06:17 +01002005
Niels Möller05543682019-01-10 16:55:06 +01002006 test::NetEqTest::DecoderMap codecs = {
2007 {kReplacementPt, SdpAudioFormat("l16", 48000, 1)}};
henrik.lundin3c938fc2017-06-14 06:09:58 -07002008
2009 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
2010 new test::NetEqDelayAnalyzer);
Minyue Lic6ff7572018-05-04 09:46:44 +02002011 std::unique_ptr<test::NetEqStatsGetter> neteq_stats_getter(
2012 new test::NetEqStatsGetter(std::move(delay_cb)));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002013 test::DefaultNetEqTestErrorCallback error_cb;
2014 test::NetEqTest::Callbacks callbacks;
2015 callbacks.error_callback = &error_cb;
Minyue Lic6ff7572018-05-04 09:46:44 +02002016 callbacks.post_insert_packet = neteq_stats_getter->delay_analyzer();
2017 callbacks.get_audio_callback = neteq_stats_getter.get();
henrik.lundin3c938fc2017-06-14 06:09:58 -07002018
Ivo Creusencee751a2020-01-16 17:17:09 +01002019 test::NetEqTest test(config, decoder_factory, codecs, /*text_log=*/nullptr,
2020 /*factory=*/nullptr, std::move(input), std::move(output),
2021 callbacks);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002022 test.Run();
Minyue Lic6ff7572018-05-04 09:46:44 +02002023 return neteq_stats_getter;
henrik.lundin3c938fc2017-06-14 06:09:58 -07002024}
2025} // namespace
2026
Minyue Lic6ff7572018-05-04 09:46:44 +02002027EventLogAnalyzer::NetEqStatsGetterMap EventLogAnalyzer::SimulateNetEq(
henrik.lundin3c938fc2017-06-14 06:09:58 -07002028 const std::string& replacement_file_name,
Minyue Lic6ff7572018-05-04 09:46:44 +02002029 int file_sample_rate_hz) const {
2030 NetEqStatsGetterMap neteq_stats;
2031
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002032 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Minyue Li27e2b7d2018-05-07 15:20:24 +02002033 const uint32_t ssrc = stream.ssrc;
Bjorn Terelius48b82792020-05-19 10:57:24 +02002034 if (!IsAudioSsrc(parsed_log_, kIncomingPacket, ssrc))
Minyue Li27e2b7d2018-05-07 15:20:24 +02002035 continue;
2036 const std::vector<LoggedRtpPacketIncoming>* audio_packets =
2037 &stream.incoming_packets;
2038 if (audio_packets == nullptr) {
2039 // No incoming audio stream found.
2040 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002041 }
henrik.lundin3c938fc2017-06-14 06:09:58 -07002042
Minyue Li27e2b7d2018-05-07 15:20:24 +02002043 RTC_DCHECK(neteq_stats.find(ssrc) == neteq_stats.end());
2044
2045 std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>::const_iterator
2046 output_events_it = parsed_log_.audio_playout_events().find(ssrc);
2047 if (output_events_it == parsed_log_.audio_playout_events().end()) {
2048 // Could not find output events with SSRC matching the input audio stream.
2049 // Using the first available stream of output events.
2050 output_events_it = parsed_log_.audio_playout_events().cbegin();
2051 }
2052
Danil Chapovalov431abd92018-06-18 12:54:17 +02002053 absl::optional<int64_t> end_time_ms =
Bjorn Terelius48b82792020-05-19 10:57:24 +02002054 parsed_log_.log_segments().empty()
Danil Chapovalov431abd92018-06-18 12:54:17 +02002055 ? absl::nullopt
Bjorn Terelius48b82792020-05-19 10:57:24 +02002056 : absl::optional<int64_t>(
2057 parsed_log_.log_segments().front().stop_time_ms());
Minyue Li27e2b7d2018-05-07 15:20:24 +02002058
2059 neteq_stats[ssrc] = CreateNetEqTestAndRun(
2060 audio_packets, &output_events_it->second, end_time_ms,
2061 replacement_file_name, file_sample_rate_hz);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002062 }
2063
Minyue Lic6ff7572018-05-04 09:46:44 +02002064 return neteq_stats;
2065}
2066
Minyue Lic97933f2018-08-10 12:51:15 +02002067// Given a NetEqStatsGetter and the SSRC that the NetEqStatsGetter was created
2068// for, this method generates a plot for the jitter buffer delay profile.
Minyue Lic6ff7572018-05-04 09:46:44 +02002069void EventLogAnalyzer::CreateAudioJitterBufferGraph(
Minyue Li01d2a672018-06-21 21:17:19 +02002070 uint32_t ssrc,
2071 const test::NetEqStatsGetter* stats_getter,
Minyue Lic6ff7572018-05-04 09:46:44 +02002072 Plot* plot) const {
Minyue Li45fc6df2018-06-21 11:47:14 +02002073 test::NetEqDelayAnalyzer::Delays arrival_delay_ms;
2074 test::NetEqDelayAnalyzer::Delays corrected_arrival_delay_ms;
2075 test::NetEqDelayAnalyzer::Delays playout_delay_ms;
2076 test::NetEqDelayAnalyzer::Delays target_delay_ms;
2077
Minyue Li01d2a672018-06-21 21:17:19 +02002078 stats_getter->delay_analyzer()->CreateGraphs(
Minyue Li45fc6df2018-06-21 11:47:14 +02002079 &arrival_delay_ms, &corrected_arrival_delay_ms, &playout_delay_ms,
2080 &target_delay_ms);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002081
Minyue Lic97933f2018-08-10 12:51:15 +02002082 TimeSeries time_series_packet_arrival("packet arrival delay",
2083 LineStyle::kLine);
2084 TimeSeries time_series_relative_packet_arrival(
2085 "Relative packet arrival delay", LineStyle::kLine);
2086 TimeSeries time_series_play_time("Playout delay", LineStyle::kLine);
2087 TimeSeries time_series_target_time("Target delay", LineStyle::kLine,
2088 PointStyle::kHighlight);
Minyue Li45fc6df2018-06-21 11:47:14 +02002089
2090 for (const auto& data : arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002091 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002092 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002093 time_series_packet_arrival.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02002094 }
2095 for (const auto& data : corrected_arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002096 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002097 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002098 time_series_relative_packet_arrival.points.emplace_back(
Minyue Li45fc6df2018-06-21 11:47:14 +02002099 TimeSeriesPoint(x, y));
2100 }
2101 for (const auto& data : playout_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002102 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002103 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002104 time_series_play_time.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02002105 }
2106 for (const auto& data : target_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002107 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002108 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002109 time_series_target_time.points.emplace_back(TimeSeriesPoint(x, y));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002110 }
2111
Minyue Lic97933f2018-08-10 12:51:15 +02002112 plot->AppendTimeSeries(std::move(time_series_packet_arrival));
2113 plot->AppendTimeSeries(std::move(time_series_relative_packet_arrival));
2114 plot->AppendTimeSeries(std::move(time_series_play_time));
2115 plot->AppendTimeSeries(std::move(time_series_target_time));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002116
Bjorn Terelius068fc352019-02-13 22:38:25 +01002117 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2118 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02002119 plot->SetSuggestedYAxis(0, 1, "Relative delay (ms)", kBottomMargin,
2120 kTopMargin);
Bjorn Terelius48b82792020-05-19 10:57:24 +02002121 plot->SetTitle("NetEq timing for " +
2122 GetStreamName(parsed_log_, kIncomingPacket, ssrc));
Minyue Li27e2b7d2018-05-07 15:20:24 +02002123}
2124
Minyue Lic9ac93f2018-06-26 13:01:32 +02002125template <typename NetEqStatsType>
2126void EventLogAnalyzer::CreateNetEqStatsGraphInternal(
Minyue Li27e2b7d2018-05-07 15:20:24 +02002127 const NetEqStatsGetterMap& neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +02002128 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
2129 const test::NetEqStatsGetter*)> data_extractor,
2130 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
Minyue Li27e2b7d2018-05-07 15:20:24 +02002131 const std::string& plot_name,
2132 Plot* plot) const {
Minyue Li27e2b7d2018-05-07 15:20:24 +02002133 std::map<uint32_t, TimeSeries> time_series;
Minyue Li27e2b7d2018-05-07 15:20:24 +02002134
2135 for (const auto& st : neteq_stats) {
2136 const uint32_t ssrc = st.first;
Minyue Lic9ac93f2018-06-26 13:01:32 +02002137 const std::vector<std::pair<int64_t, NetEqStatsType>>* data_vector =
2138 data_extractor(st.second.get());
2139 for (const auto& data : *data_vector) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002140 const float time =
2141 config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Lic9ac93f2018-06-26 13:01:32 +02002142 const float value = stats_extractor(data.second);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002143 time_series[ssrc].points.emplace_back(TimeSeriesPoint(time, value));
Minyue Li27e2b7d2018-05-07 15:20:24 +02002144 }
2145 }
2146
2147 for (auto& series : time_series) {
Bjorn Terelius48b82792020-05-19 10:57:24 +02002148 series.second.label =
2149 GetStreamName(parsed_log_, kIncomingPacket, series.first);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002150 series.second.line_style = LineStyle::kLine;
2151 plot->AppendTimeSeries(std::move(series.second));
2152 }
2153
Bjorn Terelius068fc352019-02-13 22:38:25 +01002154 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2155 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02002156 plot->SetSuggestedYAxis(0, 1, plot_name, kBottomMargin, kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002157 plot->SetTitle(plot_name);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002158}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002159
Minyue Lic9ac93f2018-06-26 13:01:32 +02002160void EventLogAnalyzer::CreateNetEqNetworkStatsGraph(
2161 const NetEqStatsGetterMap& neteq_stats,
2162 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
2163 const std::string& plot_name,
2164 Plot* plot) const {
2165 CreateNetEqStatsGraphInternal<NetEqNetworkStatistics>(
2166 neteq_stats,
2167 [](const test::NetEqStatsGetter* stats_getter) {
2168 return stats_getter->stats();
2169 },
2170 stats_extractor, plot_name, plot);
2171}
2172
2173void EventLogAnalyzer::CreateNetEqLifetimeStatsGraph(
2174 const NetEqStatsGetterMap& neteq_stats,
2175 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
2176 const std::string& plot_name,
2177 Plot* plot) const {
2178 CreateNetEqStatsGraphInternal<NetEqLifetimeStatistics>(
2179 neteq_stats,
2180 [](const test::NetEqStatsGetter* stats_getter) {
2181 return stats_getter->lifetime_stats();
2182 },
2183 stats_extractor, plot_name, plot);
2184}
2185
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002186void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
2187 std::map<uint32_t, TimeSeries> configs_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002188 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002189 if (configs_by_cp_id.find(config.candidate_pair_id) ==
2190 configs_by_cp_id.end()) {
2191 const std::string candidate_pair_desc =
2192 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08002193 configs_by_cp_id[config.candidate_pair_id] =
2194 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
2195 candidate_pair_desc,
2196 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002197 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2198 candidate_pair_desc;
2199 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002200 float x = config_.GetCallTimeSec(config.log_time_us());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002201 float y = static_cast<float>(config.type);
2202 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
2203 }
2204
2205 // TODO(qingsi): There can be a large number of candidate pairs generated by
2206 // certain calls and the frontend cannot render the chart in this case due to
2207 // the failure of generating a palette with the same number of colors.
2208 for (auto& kv : configs_by_cp_id) {
2209 plot->AppendTimeSeries(std::move(kv.second));
2210 }
2211
Bjorn Terelius068fc352019-02-13 22:38:25 +01002212 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2213 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002214 plot->SetSuggestedYAxis(0, 3, "Config Type", kBottomMargin, kTopMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002215 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002216 plot->SetYAxisTickLabels(
2217 {{static_cast<float>(IceCandidatePairConfigType::kAdded), "ADDED"},
2218 {static_cast<float>(IceCandidatePairConfigType::kUpdated), "UPDATED"},
2219 {static_cast<float>(IceCandidatePairConfigType::kDestroyed),
2220 "DESTROYED"},
2221 {static_cast<float>(IceCandidatePairConfigType::kSelected),
2222 "SELECTED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002223}
2224
2225std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
2226 uint32_t candidate_pair_id) {
2227 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
2228 candidate_pair_desc_by_id_.end()) {
2229 return candidate_pair_desc_by_id_[candidate_pair_id];
2230 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002231 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002232 // TODO(qingsi): Add the handling of the "Updated" config event after the
2233 // visualization of property change for candidate pairs is introduced.
2234 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
2235 candidate_pair_desc_by_id_.end()) {
2236 const std::string candidate_pair_desc =
2237 GetCandidatePairLogDescriptionAsString(config);
2238 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2239 candidate_pair_desc;
2240 }
2241 }
2242 return candidate_pair_desc_by_id_[candidate_pair_id];
2243}
2244
2245void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002246 constexpr int kEventTypeOffset =
2247 static_cast<int>(IceCandidatePairConfigType::kNumValues);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002248 std::map<uint32_t, TimeSeries> checks_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002249 for (const auto& event : parsed_log_.ice_candidate_pair_events()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002250 if (checks_by_cp_id.find(event.candidate_pair_id) ==
2251 checks_by_cp_id.end()) {
2252 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08002253 "[" + std::to_string(event.candidate_pair_id) + "]" +
2254 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002255 LineStyle::kNone, PointStyle::kHighlight);
2256 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002257 float x = config_.GetCallTimeSec(event.log_time_us());
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002258 float y = static_cast<float>(event.type) + kEventTypeOffset;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002259 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
2260 }
2261
2262 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
2263 for (auto& kv : checks_by_cp_id) {
2264 plot->AppendTimeSeries(std::move(kv.second));
2265 }
2266
Bjorn Terelius068fc352019-02-13 22:38:25 +01002267 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2268 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002269 plot->SetSuggestedYAxis(0, 4, "Connectivity State", kBottomMargin,
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002270 kTopMargin);
2271 plot->SetTitle("[IceEventLog] ICE connectivity checks");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002272
2273 plot->SetYAxisTickLabels(
2274 {{static_cast<float>(IceCandidatePairEventType::kCheckSent) +
2275 kEventTypeOffset,
2276 "CHECK SENT"},
2277 {static_cast<float>(IceCandidatePairEventType::kCheckReceived) +
2278 kEventTypeOffset,
2279 "CHECK RECEIVED"},
2280 {static_cast<float>(IceCandidatePairEventType::kCheckResponseSent) +
2281 kEventTypeOffset,
2282 "RESPONSE SENT"},
2283 {static_cast<float>(IceCandidatePairEventType::kCheckResponseReceived) +
2284 kEventTypeOffset,
2285 "RESPONSE RECEIVED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002286}
2287
Zach Stein10a58012018-12-07 12:26:28 -08002288void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) {
2289 TimeSeries states("DTLS Transport State", LineStyle::kNone,
2290 PointStyle::kHighlight);
2291 for (const auto& event : parsed_log_.dtls_transport_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002292 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002293 float y = static_cast<float>(event.dtls_transport_state);
2294 states.points.emplace_back(x, y);
2295 }
2296 plot->AppendTimeSeries(std::move(states));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002297 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2298 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002299 plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues),
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002300 "Transport State", kBottomMargin, kTopMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002301 plot->SetTitle("DTLS Transport State");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002302 plot->SetYAxisTickLabels(
2303 {{static_cast<float>(DtlsTransportState::kNew), "NEW"},
2304 {static_cast<float>(DtlsTransportState::kConnecting), "CONNECTING"},
2305 {static_cast<float>(DtlsTransportState::kConnected), "CONNECTED"},
2306 {static_cast<float>(DtlsTransportState::kClosed), "CLOSED"},
2307 {static_cast<float>(DtlsTransportState::kFailed), "FAILED"}});
Zach Stein10a58012018-12-07 12:26:28 -08002308}
2309
2310void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) {
2311 TimeSeries writable("DTLS Writable", LineStyle::kNone,
2312 PointStyle::kHighlight);
2313 for (const auto& event : parsed_log_.dtls_writable_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002314 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002315 float y = static_cast<float>(event.writable);
2316 writable.points.emplace_back(x, y);
2317 }
2318 plot->AppendTimeSeries(std::move(writable));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002319 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2320 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002321 plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin);
2322 plot->SetTitle("DTLS Writable State");
2323}
2324
terelius54ce6802016-07-13 06:44:41 -07002325} // namespace webrtc