blob: 287fbe2eb8a778562b01fa200398c67a8c8d5ae8 [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_defines.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020049#include "modules/rtp_rtcp/source/rtcp_packet.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020050#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
51#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
52#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
53#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
54#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
55#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
Tomas Gunnarssonf25761d2020-06-03 22:55:33 +020056#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020057#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
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200468 RTC_LOG(LS_INFO) << "Log is "
469 << (parsed_log_.last_timestamp() -
470 parsed_log_.first_timestamp()) /
471 1000000
472 << " seconds long.";
Bjorn Terelius48b82792020-05-19 10:57:24 +0200473}
474
475EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log,
476 const AnalyzerConfig& config)
477 : parsed_log_(log), config_(config) {
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200478 RTC_LOG(LS_INFO) << "Log is "
479 << (parsed_log_.last_timestamp() -
480 parsed_log_.first_timestamp()) /
481 1000000
482 << " seconds long.";
terelius54ce6802016-07-13 06:44:41 -0700483}
484
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200485class BitrateObserver : public RemoteBitrateObserver {
Stefan Holmer13181032016-07-29 14:48:54 +0200486 public:
487 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
488
Sebastian Jansson5c94f552018-10-15 18:46:51 +0200489 void Update(NetworkControlUpdate update) {
490 if (update.target_rate) {
491 last_bitrate_bps_ = update.target_rate->target_rate.bps();
492 bitrate_updated_ = true;
493 }
Stefan Holmer13181032016-07-29 14:48:54 +0200494 }
495
496 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
497 uint32_t bitrate) override {}
498
499 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
500 bool GetAndResetBitrateUpdated() {
501 bool bitrate_updated = bitrate_updated_;
502 bitrate_updated_ = false;
503 return bitrate_updated;
504 }
505
506 private:
507 uint32_t last_bitrate_bps_;
508 bool bitrate_updated_;
509};
510
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200511void EventLogAnalyzer::CreatePacketGraph(PacketDirection direction,
terelius54ce6802016-07-13 06:44:41 -0700512 Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200513 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
514 // Filter on SSRC.
515 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700516 continue;
terelius54ce6802016-07-13 06:44:41 -0700517 }
terelius54ce6802016-07-13 06:44:41 -0700518
Bjorn Terelius48b82792020-05-19 10:57:24 +0200519 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200520 LineStyle::kBar);
521 auto GetPacketSize = [](const LoggedRtpPacket& packet) {
Danil Chapovalov431abd92018-06-18 12:54:17 +0200522 return absl::optional<float>(packet.total_length);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200523 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200524 auto ToCallTime = [this](const LoggedRtpPacket& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100525 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200526 };
527 ProcessPoints<LoggedRtpPacket>(ToCallTime, GetPacketSize,
528 stream.packet_view, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700529 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700530 }
531
Bjorn Terelius068fc352019-02-13 22:38:25 +0100532 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
533 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700534 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
535 kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200536 plot->SetTitle(GetDirectionAsString(direction) + " RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700537}
538
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100539void EventLogAnalyzer::CreateRtcpTypeGraph(PacketDirection direction,
540 Plot* plot) {
541 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
542 parsed_log_.transport_feedbacks(direction), config_, "TWCC", 1));
543 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
544 parsed_log_.receiver_reports(direction), config_, "RR", 2));
545 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
546 parsed_log_.sender_reports(direction), config_, "SR", 3));
547 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(
548 parsed_log_.extended_reports(direction), config_, "XR", 4));
549 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.nacks(direction),
550 config_, "NACK", 5));
551 plot->AppendTimeSeries(CreateRtcpTypeTimeSeries(parsed_log_.rembs(direction),
552 config_, "REMB", 6));
553 plot->AppendTimeSeries(
554 CreateRtcpTypeTimeSeries(parsed_log_.firs(direction), config_, "FIR", 7));
555 plot->AppendTimeSeries(
556 CreateRtcpTypeTimeSeries(parsed_log_.plis(direction), config_, "PLI", 8));
557 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
558 "Time (s)", kLeftMargin, kRightMargin);
559 plot->SetSuggestedYAxis(0, 1, "RTCP type", kBottomMargin, kTopMargin);
560 plot->SetTitle(GetDirectionAsString(direction) + " RTCP packets");
Bjorn Tereliusf640b872019-07-24 15:46:39 +0200561 plot->SetYAxisTickLabels({{1, "TWCC"},
562 {2, "RR"},
563 {3, "SR"},
564 {4, "XR"},
565 {5, "NACK"},
566 {6, "REMB"},
567 {7, "FIR"},
568 {8, "PLI"}});
Bjorn Terelius7c974e62019-02-15 17:20:12 +0100569}
570
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200571template <typename IterableType>
philipelccd74892016-09-05 02:46:25 -0700572void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
philipelccd74892016-09-05 02:46:25 -0700573 Plot* plot,
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200574 const IterableType& packets,
575 const std::string& label) {
576 TimeSeries time_series(label, LineStyle::kStep);
577 for (size_t i = 0; i < packets.size(); i++) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100578 float x = config_.GetCallTimeSec(packets[i].log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200579 time_series.points.emplace_back(x, i + 1);
philipelccd74892016-09-05 02:46:25 -0700580 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200581 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700582}
583
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200584void EventLogAnalyzer::CreateAccumulatedPacketsGraph(PacketDirection direction,
585 Plot* plot) {
586 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
587 if (!MatchingSsrc(stream.ssrc, desired_ssrc_))
588 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200589 std::string label = std::string("RTP ") +
590 GetStreamName(parsed_log_, direction, stream.ssrc);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200591 CreateAccumulatedPacketsTimeSeries(plot, stream.packet_view, label);
592 }
593 std::string label =
594 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")";
595 if (direction == kIncomingPacket) {
596 CreateAccumulatedPacketsTimeSeries(
597 plot, parsed_log_.incoming_rtcp_packets(), label);
598 } else {
599 CreateAccumulatedPacketsTimeSeries(
600 plot, parsed_log_.outgoing_rtcp_packets(), label);
601 }
philipelccd74892016-09-05 02:46:25 -0700602
Bjorn Terelius068fc352019-02-13 22:38:25 +0100603 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
604 "Time (s)", kLeftMargin, kRightMargin);
philipelccd74892016-09-05 02:46:25 -0700605 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200606 plot->SetTitle(std::string("Accumulated ") + GetDirectionAsString(direction) +
607 " RTP/RTCP packets");
philipelccd74892016-09-05 02:46:25 -0700608}
609
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200610void EventLogAnalyzer::CreatePacketRateGraph(PacketDirection direction,
611 Plot* plot) {
612 auto CountPackets = [](auto packet) { return 1.0; };
613 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
614 // Filter on SSRC.
615 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
616 continue;
617 }
618 TimeSeries time_series(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200619 std::string("RTP ") +
620 GetStreamName(parsed_log_, direction, stream.ssrc),
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200621 LineStyle::kLine);
622 MovingAverage<LoggedRtpPacket, double>(CountPackets, stream.packet_view,
623 config_, &time_series);
624 plot->AppendTimeSeries(std::move(time_series));
625 }
626 TimeSeries time_series(
627 std::string("RTCP ") + "(" + GetDirectionAsShortString(direction) + ")",
628 LineStyle::kLine);
629 if (direction == kIncomingPacket) {
630 MovingAverage<LoggedRtcpPacketIncoming, double>(
631 CountPackets, parsed_log_.incoming_rtcp_packets(), config_,
632 &time_series);
633 } else {
634 MovingAverage<LoggedRtcpPacketOutgoing, double>(
635 CountPackets, parsed_log_.outgoing_rtcp_packets(), config_,
636 &time_series);
637 }
638 plot->AppendTimeSeries(std::move(time_series));
639
640 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
641 "Time (s)", kLeftMargin, kRightMargin);
642 plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin,
643 kTopMargin);
644 plot->SetTitle("Rate of " + GetDirectionAsString(direction) +
645 " RTP/RTCP packets");
646}
647
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200648void EventLogAnalyzer::CreateTotalPacketRateGraph(PacketDirection direction,
649 Plot* plot) {
650 // Contains a log timestamp to enable counting logged events of different
651 // types using MovingAverage().
652 class LogTime {
653 public:
654 explicit LogTime(int64_t log_time_us) : log_time_us_(log_time_us) {}
655
656 int64_t log_time_us() const { return log_time_us_; }
657
658 private:
659 int64_t log_time_us_;
660 };
661
662 std::vector<LogTime> packet_times;
663 auto handle_rtp = [&](const LoggedRtpPacket& packet) {
664 packet_times.emplace_back(packet.log_time_us());
665 };
666 RtcEventProcessor process;
667 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
668 process.AddEvents(stream.packet_view, handle_rtp);
669 }
670 if (direction == kIncomingPacket) {
671 auto handle_incoming_rtcp = [&](const LoggedRtcpPacketIncoming& packet) {
672 packet_times.emplace_back(packet.log_time_us());
673 };
674 process.AddEvents(parsed_log_.incoming_rtcp_packets(),
675 handle_incoming_rtcp);
676 } else {
677 auto handle_outgoing_rtcp = [&](const LoggedRtcpPacketOutgoing& packet) {
678 packet_times.emplace_back(packet.log_time_us());
679 };
680 process.AddEvents(parsed_log_.outgoing_rtcp_packets(),
681 handle_outgoing_rtcp);
682 }
683 process.ProcessEventsInOrder();
684 TimeSeries time_series(std::string("Total ") + "(" +
685 GetDirectionAsShortString(direction) + ") packets",
686 LineStyle::kLine);
687 MovingAverage<LogTime, uint64_t>([](auto packet) { return 1; }, packet_times,
688 config_, &time_series);
689 plot->AppendTimeSeries(std::move(time_series));
690
691 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
692 "Time (s)", kLeftMargin, kRightMargin);
693 plot->SetSuggestedYAxis(0, 1, "Packet Rate (packets/s)", kBottomMargin,
694 kTopMargin);
695 plot->SetTitle("Rate of all " + GetDirectionAsString(direction) +
696 " RTP/RTCP packets");
697}
698
terelius54ce6802016-07-13 06:44:41 -0700699// For each SSRC, plot the time between the consecutive playouts.
700void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200701 for (const auto& playout_stream : parsed_log_.audio_playout_events()) {
702 uint32_t ssrc = playout_stream.first;
703 if (!MatchingSsrc(ssrc, desired_ssrc_))
704 continue;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200705 absl::optional<int64_t> last_playout_ms;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200706 TimeSeries time_series(SsrcToString(ssrc), LineStyle::kBar);
Minyue Li27e2b7d2018-05-07 15:20:24 +0200707 for (const auto& playout_event : playout_stream.second) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100708 float x = config_.GetCallTimeSec(playout_event.log_time_us());
Minyue Li27e2b7d2018-05-07 15:20:24 +0200709 int64_t playout_time_ms = playout_event.log_time_ms();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200710 // If there were no previous playouts, place the point on the x-axis.
Minyue Li27e2b7d2018-05-07 15:20:24 +0200711 float y = playout_time_ms - last_playout_ms.value_or(playout_time_ms);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200712 time_series.points.push_back(TimeSeriesPoint(x, y));
Minyue Li27e2b7d2018-05-07 15:20:24 +0200713 last_playout_ms.emplace(playout_time_ms);
terelius54ce6802016-07-13 06:44:41 -0700714 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200715 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700716 }
717
Bjorn Terelius068fc352019-02-13 22:38:25 +0100718 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
719 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700720 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
721 kTopMargin);
722 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700723}
724
ivocaac9d6f2016-09-22 07:01:47 -0700725// For audio SSRCs, plot the audio level.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200726void EventLogAnalyzer::CreateAudioLevelGraph(PacketDirection direction,
727 Plot* plot) {
728 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
Bjorn Terelius48b82792020-05-19 10:57:24 +0200729 if (!IsAudioSsrc(parsed_log_, direction, stream.ssrc))
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200730 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200731 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200732 LineStyle::kLine);
733 for (auto& packet : stream.packet_view) {
ivocaac9d6f2016-09-22 07:01:47 -0700734 if (packet.header.extension.hasAudioLevel) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100735 float x = config_.GetCallTimeSec(packet.log_time_us());
ivocaac9d6f2016-09-22 07:01:47 -0700736 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
737 // Here we convert it to dBov.
738 float y = static_cast<float>(-packet.header.extension.audioLevel);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200739 time_series.points.emplace_back(TimeSeriesPoint(x, y));
ivocaac9d6f2016-09-22 07:01:47 -0700740 }
741 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200742 plot->AppendTimeSeries(std::move(time_series));
ivocaac9d6f2016-09-22 07:01:47 -0700743 }
744
Bjorn Terelius068fc352019-02-13 22:38:25 +0100745 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
746 "Time (s)", kLeftMargin, kRightMargin);
Yves Gerey665174f2018-06-19 15:03:05 +0200747 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200748 plot->SetTitle(GetDirectionAsString(direction) + " audio level");
ivocaac9d6f2016-09-22 07:01:47 -0700749}
750
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100751// For each SSRC, plot the sequence number difference between consecutive
752// incoming packets.
terelius54ce6802016-07-13 06:44:41 -0700753void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200754 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
755 // Filter on SSRC.
756 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -0700757 continue;
terelius54ce6802016-07-13 06:44:41 -0700758 }
terelius54ce6802016-07-13 06:44:41 -0700759
Bjorn Terelius48b82792020-05-19 10:57:24 +0200760 TimeSeries time_series(
761 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc),
762 LineStyle::kBar);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200763 auto GetSequenceNumberDiff = [](const LoggedRtpPacketIncoming& old_packet,
764 const LoggedRtpPacketIncoming& new_packet) {
765 int64_t diff =
766 WrappingDifference(new_packet.rtp.header.sequenceNumber,
767 old_packet.rtp.header.sequenceNumber, 1ul << 16);
768 return diff;
769 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200770 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100771 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200772 };
773 ProcessPairs<LoggedRtpPacketIncoming, float>(
774 ToCallTime, GetSequenceNumberDiff, stream.incoming_packets,
775 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700776 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700777 }
778
Bjorn Terelius068fc352019-02-13 22:38:25 +0100779 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
780 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -0700781 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
782 kTopMargin);
Konrad Hofbauerca3c8012019-02-15 20:52:19 +0100783 plot->SetTitle("Incoming sequence number delta");
terelius54ce6802016-07-13 06:44:41 -0700784}
785
Stefan Holmer99f8e082016-09-09 13:37:50 +0200786void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200787 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
788 const std::vector<LoggedRtpPacketIncoming>& packets =
789 stream.incoming_packets;
790 // Filter on SSRC.
Mirko Bonadei1f173152019-07-25 15:28:14 +0200791 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) || packets.empty()) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200792 continue;
793 }
794
Bjorn Terelius48b82792020-05-19 10:57:24 +0200795 TimeSeries time_series(
796 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc),
797 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200798 // TODO(terelius): Should the window and step size be read from the class
799 // instead?
800 const int64_t kWindowUs = 1000000;
801 const int64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100802 SeqNumUnwrapper<uint16_t> unwrapper_;
803 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800804 size_t window_index_begin = 0;
805 size_t window_index_end = 0;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200806 uint64_t highest_seq_number =
807 unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
808 uint64_t highest_prior_seq_number =
809 prior_unwrapper_.Unwrap(packets[0].rtp.header.sequenceNumber) - 1;
terelius4c9b4af2017-01-30 08:44:51 -0800810
Bjorn Terelius068fc352019-02-13 22:38:25 +0100811 for (int64_t t = config_.begin_time_; t < config_.end_time_ + kStep;
812 t += kStep) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200813 while (window_index_end < packets.size() &&
814 packets[window_index_end].rtp.log_time_us() < t) {
815 uint64_t sequence_number = unwrapper_.Unwrap(
816 packets[window_index_end].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800817 highest_seq_number = std::max(highest_seq_number, sequence_number);
818 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200819 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200820 while (window_index_begin < packets.size() &&
821 packets[window_index_begin].rtp.log_time_us() < t - kWindowUs) {
822 uint64_t sequence_number = prior_unwrapper_.Unwrap(
823 packets[window_index_begin].rtp.header.sequenceNumber);
terelius4c9b4af2017-01-30 08:44:51 -0800824 highest_prior_seq_number =
825 std::max(highest_prior_seq_number, sequence_number);
826 ++window_index_begin;
827 }
Bjorn Terelius068fc352019-02-13 22:38:25 +0100828 float x = config_.GetCallTimeSec(t);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200829 uint64_t expected_packets = highest_seq_number - highest_prior_seq_number;
terelius4c9b4af2017-01-30 08:44:51 -0800830 if (expected_packets > 0) {
831 int64_t received_packets = window_index_end - window_index_begin;
832 int64_t lost_packets = expected_packets - received_packets;
833 float y = static_cast<float>(lost_packets) / expected_packets * 100;
834 time_series.points.emplace_back(x, y);
835 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200836 }
philipel35ba9bd2017-04-19 05:58:51 -0700837 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200838 }
839
Bjorn Terelius068fc352019-02-13 22:38:25 +0100840 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
841 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100842 plot->SetSuggestedYAxis(0, 1, "Loss rate (in %)", kBottomMargin, kTopMargin);
843 plot->SetTitle("Incoming packet loss (derived from incoming packets)");
Stefan Holmer99f8e082016-09-09 13:37:50 +0200844}
845
terelius2ee076d2017-08-15 02:04:02 -0700846void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100847 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200848 // Filter on SSRC.
849 if (!MatchingSsrc(stream.ssrc, desired_ssrc_) ||
Bjorn Terelius48b82792020-05-19 10:57:24 +0200850 IsRtxSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) {
terelius88e64e52016-07-19 01:51:06 -0700851 continue;
852 }
terelius54ce6802016-07-13 06:44:41 -0700853
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100854 const std::vector<LoggedRtpPacketIncoming>& packets =
855 stream.incoming_packets;
856 if (packets.size() < 100) {
857 RTC_LOG(LS_WARNING) << "Can't estimate the RTP clock frequency with "
858 << packets.size() << " packets in the stream.";
859 continue;
860 }
Björn Terelius0d1b28c2020-05-27 20:25:06 +0200861 int64_t segment_end_us = parsed_log_.first_log_segment().stop_time_us();
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100862 absl::optional<uint32_t> estimated_frequency =
Bjorn Terelius48b82792020-05-19 10:57:24 +0200863 EstimateRtpClockFrequency(packets, segment_end_us);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100864 if (!estimated_frequency)
865 continue;
866 const double frequency_hz = *estimated_frequency;
Bjorn Terelius48b82792020-05-19 10:57:24 +0200867 if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc) &&
868 frequency_hz != 90000) {
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100869 RTC_LOG(LS_WARNING)
870 << "Video stream should use a 90 kHz clock but appears to use "
871 << frequency_hz / 1000 << ". Discarding.";
872 continue;
873 }
874
875 auto ToCallTime = [this](const LoggedRtpPacketIncoming& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100876 return this->config_.GetCallTimeSec(packet.log_time_us());
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100877 };
878 auto ToNetworkDelay = [frequency_hz](
879 const LoggedRtpPacketIncoming& old_packet,
880 const LoggedRtpPacketIncoming& new_packet) {
881 return NetworkDelayDiff_CaptureTime(old_packet, new_packet, frequency_hz);
882 };
883
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200884 TimeSeries capture_time_data(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200885 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) +
886 " capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200887 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100888 AccumulatePairs<LoggedRtpPacketIncoming, double>(
889 ToCallTime, ToNetworkDelay, packets, &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700890 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700891
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200892 TimeSeries send_time_data(
Bjorn Terelius48b82792020-05-19 10:57:24 +0200893 GetStreamName(parsed_log_, kIncomingPacket, stream.ssrc) +
894 " abs-send-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200895 LineStyle::kLine);
Bjorn Terelius6c373cc2018-11-01 14:31:10 +0100896 AccumulatePairs<LoggedRtpPacketIncoming, double>(
897 ToCallTime, NetworkDelayDiff_AbsSendTime, packets, &send_time_data);
898 plot->AppendTimeSeriesIfNotEmpty(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700899 }
900
Bjorn Terelius068fc352019-02-13 22:38:25 +0100901 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
902 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +0100903 plot->SetSuggestedYAxis(0, 1, "Delay (ms)", kBottomMargin, kTopMargin);
904 plot->SetTitle("Incoming network delay (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700905}
906
tereliusf736d232016-08-04 10:00:11 -0700907// Plot the fraction of packets lost (as perceived by the loss-based BWE).
908void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100909 TimeSeries time_series("Fraction lost", LineStyle::kLine,
910 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200911 for (auto& bwe_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100912 float x = config_.GetCallTimeSec(bwe_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200913 float y = static_cast<float>(bwe_update.fraction_lost) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700914 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700915 }
tereliusf736d232016-08-04 10:00:11 -0700916
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200917 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +0100918 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
919 "Time (s)", kLeftMargin, kRightMargin);
Konrad Hofbauerd036c652019-02-14 16:17:28 +0100920 plot->SetSuggestedYAxis(0, 10, "Loss rate (in %)", kBottomMargin, kTopMargin);
921 plot->SetTitle("Outgoing packet loss (as reported by BWE)");
tereliusf736d232016-08-04 10:00:11 -0700922}
923
terelius54ce6802016-07-13 06:44:41 -0700924// Plot the total bandwidth used by all RTP streams.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200925void EventLogAnalyzer::CreateTotalIncomingBitrateGraph(Plot* plot) {
926 // TODO(terelius): This could be provided by the parser.
927 std::multimap<int64_t, size_t> packets_in_order;
928 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
929 for (const LoggedRtpPacketIncoming& packet : stream.incoming_packets)
930 packets_in_order.insert(
931 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
terelius54ce6802016-07-13 06:44:41 -0700932 }
933
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200934 auto window_begin = packets_in_order.begin();
935 auto window_end = packets_in_order.begin();
terelius54ce6802016-07-13 06:44:41 -0700936 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700937
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800938 if (!packets_in_order.empty()) {
939 // Calculate a moving average of the bitrate and store in a TimeSeries.
940 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
941 for (int64_t time = config_.begin_time_;
942 time < config_.end_time_ + config_.step_; time += config_.step_) {
943 while (window_end != packets_in_order.end() && window_end->first < time) {
944 bytes_in_window += window_end->second;
945 ++window_end;
946 }
947 while (window_begin != packets_in_order.end() &&
948 window_begin->first < time - config_.window_duration_) {
949 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
950 bytes_in_window -= window_begin->second;
951 ++window_begin;
952 }
953 float window_duration_in_seconds =
954 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
955 float x = config_.GetCallTimeSec(time);
956 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
957 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700958 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800959 plot->AppendTimeSeries(std::move(bitrate_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200960 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200961
962 // Overlay the outgoing REMB over incoming bitrate.
963 TimeSeries remb_series("Remb", LineStyle::kStep);
964 for (const auto& rtcp : parsed_log_.rembs(kOutgoingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +0100965 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200966 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
967 remb_series.points.emplace_back(x, y);
968 }
969 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
970
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -0800971 if (!parsed_log_.generic_packets_received().empty()) {
972 TimeSeries time_series("Incoming generic bitrate", LineStyle::kLine);
973 auto GetPacketSizeKilobits = [](const LoggedGenericPacketReceived& packet) {
974 return packet.packet_length * 8.0 / 1000.0;
975 };
976 MovingAverage<LoggedGenericPacketReceived, double>(
977 GetPacketSizeKilobits, parsed_log_.generic_packets_received(), config_,
978 &time_series);
979 plot->AppendTimeSeries(std::move(time_series));
980 }
981
Bjorn Terelius068fc352019-02-13 22:38:25 +0100982 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
983 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200984 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
985 plot->SetTitle("Incoming RTP bitrate");
986}
987
988// Plot the total bandwidth used by all RTP streams.
989void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
990 bool show_detector_state,
991 bool show_alr_state) {
992 // TODO(terelius): This could be provided by the parser.
993 std::multimap<int64_t, size_t> packets_in_order;
994 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
995 for (const LoggedRtpPacketOutgoing& packet : stream.outgoing_packets)
996 packets_in_order.insert(
997 std::make_pair(packet.rtp.log_time_us(), packet.rtp.total_length));
998 }
999
1000 auto window_begin = packets_in_order.begin();
1001 auto window_end = packets_in_order.begin();
1002 size_t bytes_in_window = 0;
1003
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001004 if (!packets_in_order.empty()) {
1005 // Calculate a moving average of the bitrate and store in a TimeSeries.
1006 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
1007 for (int64_t time = config_.begin_time_;
1008 time < config_.end_time_ + config_.step_; time += config_.step_) {
1009 while (window_end != packets_in_order.end() && window_end->first < time) {
1010 bytes_in_window += window_end->second;
1011 ++window_end;
1012 }
1013 while (window_begin != packets_in_order.end() &&
1014 window_begin->first < time - config_.window_duration_) {
1015 RTC_DCHECK_LE(window_begin->second, bytes_in_window);
1016 bytes_in_window -= window_begin->second;
1017 ++window_begin;
1018 }
1019 float window_duration_in_seconds =
1020 static_cast<float>(config_.window_duration_) / kNumMicrosecsPerSec;
1021 float x = config_.GetCallTimeSec(time);
1022 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
1023 bitrate_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001024 }
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001025 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -07001026 }
1027
terelius8058e582016-07-25 01:32:41 -07001028 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001029 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
1030 for (auto& loss_update : parsed_log_.bwe_loss_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001031 float x = config_.GetCallTimeSec(loss_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001032 float y = static_cast<float>(loss_update.bitrate_bps) / 1000;
1033 loss_series.points.emplace_back(x, y);
1034 }
philipel10fc0e62017-04-11 01:50:23 -07001035
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001036 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
1037 IntervalSeries overusing_series("Overusing", "#ff8e82",
1038 IntervalSeries::kHorizontal);
1039 IntervalSeries underusing_series("Underusing", "#5092fc",
1040 IntervalSeries::kHorizontal);
1041 IntervalSeries normal_series("Normal", "#c4ffc4",
1042 IntervalSeries::kHorizontal);
1043 IntervalSeries* last_series = &normal_series;
1044 double last_detector_switch = 0.0;
philipel23c7f252017-07-14 06:30:03 -07001045
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001046 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
philipel23c7f252017-07-14 06:30:03 -07001047
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001048 for (auto& delay_update : parsed_log_.bwe_delay_updates()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001049 float x = config_.GetCallTimeSec(delay_update.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001050 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -07001051
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001052 if (last_detector_state != delay_update.detector_state) {
1053 last_series->intervals.emplace_back(last_detector_switch, x);
1054 last_detector_state = delay_update.detector_state;
1055 last_detector_switch = x;
philipel23c7f252017-07-14 06:30:03 -07001056
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001057 switch (delay_update.detector_state) {
1058 case BandwidthUsage::kBwNormal:
1059 last_series = &normal_series;
1060 break;
1061 case BandwidthUsage::kBwUnderusing:
1062 last_series = &underusing_series;
1063 break;
1064 case BandwidthUsage::kBwOverusing:
1065 last_series = &overusing_series;
1066 break;
1067 case BandwidthUsage::kLast:
1068 RTC_NOTREACHED();
philipele127e7a2017-03-29 16:28:53 +02001069 }
1070 }
philipel23c7f252017-07-14 06:30:03 -07001071
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001072 delay_series.points.emplace_back(x, y);
1073 }
Bjorn Terelius9e336ec2018-04-24 16:28:35 +02001074
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001075 RTC_CHECK(last_series);
Bjorn Terelius068fc352019-02-13 22:38:25 +01001076 last_series->intervals.emplace_back(last_detector_switch, config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001077
1078 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
1079 PointStyle::kHighlight);
1080 for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001081 float x = config_.GetCallTimeSec(cluster.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001082 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
1083 created_series.points.emplace_back(x, y);
1084 }
1085
1086 TimeSeries result_series("Probing results.", LineStyle::kNone,
1087 PointStyle::kHighlight);
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001088 for (auto& result : parsed_log_.bwe_probe_success_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001089 float x = config_.GetCallTimeSec(result.log_time_us());
Bjorn Terelius7a0bb002018-05-29 14:45:53 +02001090 float y = static_cast<float>(result.bitrate_bps) / 1000;
1091 result_series.points.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001092 }
1093
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001094 TimeSeries probe_failures_series("Probe failed", LineStyle::kNone,
1095 PointStyle::kHighlight);
1096 for (auto& failure : parsed_log_.bwe_probe_failure_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001097 float x = config_.GetCallTimeSec(failure.log_time_us());
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001098 probe_failures_series.points.emplace_back(x, 0);
1099 }
1100
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001101 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
1102 bool previously_in_alr = false;
1103 int64_t alr_start = 0;
1104 for (auto& alr : parsed_log_.alr_state_events()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001105 float y = config_.GetCallTimeSec(alr.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001106 if (!previously_in_alr && alr.in_alr) {
1107 alr_start = alr.log_time_us();
1108 previously_in_alr = true;
1109 } else if (previously_in_alr && !alr.in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001110 float x = config_.GetCallTimeSec(alr_start);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001111 alr_state.intervals.emplace_back(x, y);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001112 previously_in_alr = false;
Björn Tereliusff612732018-04-25 14:23:01 +00001113 }
Björn Tereliusff612732018-04-25 14:23:01 +00001114 }
1115
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001116 if (previously_in_alr) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001117 float x = config_.GetCallTimeSec(alr_start);
1118 float y = config_.GetCallTimeSec(config_.end_time_);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001119 alr_state.intervals.emplace_back(x, y);
1120 }
1121
1122 if (show_detector_state) {
1123 plot->AppendIntervalSeries(std::move(overusing_series));
1124 plot->AppendIntervalSeries(std::move(underusing_series));
1125 plot->AppendIntervalSeries(std::move(normal_series));
1126 }
1127
1128 if (show_alr_state) {
1129 plot->AppendIntervalSeries(std::move(alr_state));
1130 }
1131 plot->AppendTimeSeries(std::move(loss_series));
Piotr (Peter) Slatalaf996c842019-01-04 06:54:22 -08001132 plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001133 plot->AppendTimeSeries(std::move(delay_series));
1134 plot->AppendTimeSeries(std::move(created_series));
1135 plot->AppendTimeSeries(std::move(result_series));
1136
1137 // Overlay the incoming REMB over the outgoing bitrate.
Björn Tereliusff612732018-04-25 14:23:01 +00001138 TimeSeries remb_series("Remb", LineStyle::kStep);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001139 for (const auto& rtcp : parsed_log_.rembs(kIncomingPacket)) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001140 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001141 float y = static_cast<float>(rtcp.remb.bitrate_bps()) / 1000;
terelius2c8e8a32017-06-02 01:29:48 -07001142 remb_series.points.emplace_back(x, y);
1143 }
1144 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1145
Piotr (Peter) Slatalacf8405e2019-02-14 13:44:57 -08001146 if (!parsed_log_.generic_packets_sent().empty()) {
1147 {
1148 TimeSeries time_series("Outgoing generic total bitrate",
1149 LineStyle::kLine);
1150 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1151 return packet.packet_length() * 8.0 / 1000.0;
1152 };
1153 MovingAverage<LoggedGenericPacketSent, double>(
1154 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1155 &time_series);
1156 plot->AppendTimeSeries(std::move(time_series));
1157 }
1158
1159 {
1160 TimeSeries time_series("Outgoing generic payload bitrate",
1161 LineStyle::kLine);
1162 auto GetPacketSizeKilobits = [](const LoggedGenericPacketSent& packet) {
1163 return packet.payload_length * 8.0 / 1000.0;
1164 };
1165 MovingAverage<LoggedGenericPacketSent, double>(
1166 GetPacketSizeKilobits, parsed_log_.generic_packets_sent(), config_,
1167 &time_series);
1168 plot->AppendTimeSeries(std::move(time_series));
1169 }
1170 }
1171
Bjorn Terelius068fc352019-02-13 22:38:25 +01001172 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1173 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001174 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001175 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001176}
1177
1178// For each SSRC, plot the bandwidth used by that stream.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001179void EventLogAnalyzer::CreateStreamBitrateGraph(PacketDirection direction,
1180 Plot* plot) {
1181 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1182 // Filter on SSRC.
1183 if (!MatchingSsrc(stream.ssrc, desired_ssrc_)) {
terelius6addf492016-08-23 17:34:07 -07001184 continue;
terelius54ce6802016-07-13 06:44:41 -07001185 }
1186
Bjorn Terelius48b82792020-05-19 10:57:24 +02001187 TimeSeries time_series(GetStreamName(parsed_log_, direction, stream.ssrc),
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001188 LineStyle::kLine);
1189 auto GetPacketSizeKilobits = [](const LoggedRtpPacket& packet) {
1190 return packet.total_length * 8.0 / 1000.0;
1191 };
terelius53dc23c2017-03-13 05:24:05 -07001192 MovingAverage<LoggedRtpPacket, double>(
Bjorn Terelius068fc352019-02-13 22:38:25 +01001193 GetPacketSizeKilobits, stream.packet_view, config_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001194 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001195 }
1196
Bjorn Terelius068fc352019-02-13 22:38:25 +01001197 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1198 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001199 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001200 plot->SetTitle(GetDirectionAsString(direction) + " bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001201}
1202
Bjorn Terelius9775a582019-02-15 17:29:58 +01001203// Plot the bitrate allocation for each temporal and spatial layer.
1204// Computed from RTCP XR target bitrate block, so the graph is only populated if
1205// those are sent.
1206void EventLogAnalyzer::CreateBitrateAllocationGraph(PacketDirection direction,
1207 Plot* plot) {
1208 std::map<LayerDescription, TimeSeries> time_series;
1209 const auto& xr_list = parsed_log_.extended_reports(direction);
1210 for (const auto& rtcp : xr_list) {
1211 const absl::optional<rtcp::TargetBitrate>& target_bitrate =
1212 rtcp.xr.target_bitrate();
1213 if (!target_bitrate.has_value())
1214 continue;
1215 for (const auto& bitrate_item : target_bitrate->GetTargetBitrates()) {
1216 LayerDescription layer(rtcp.xr.sender_ssrc(), bitrate_item.spatial_layer,
1217 bitrate_item.temporal_layer);
1218 auto time_series_it = time_series.find(layer);
1219 if (time_series_it == time_series.end()) {
1220 std::string layer_name = GetLayerName(layer);
1221 bool inserted;
1222 std::tie(time_series_it, inserted) = time_series.insert(
1223 std::make_pair(layer, TimeSeries(layer_name, LineStyle::kStep)));
1224 RTC_DCHECK(inserted);
1225 }
1226 float x = config_.GetCallTimeSec(rtcp.log_time_us());
1227 float y = bitrate_item.target_bitrate_kbps;
1228 time_series_it->second.points.emplace_back(x, y);
1229 }
1230 }
1231 for (auto& layer : time_series) {
1232 plot->AppendTimeSeries(std::move(layer.second));
1233 }
1234 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1235 "Time (s)", kLeftMargin, kRightMargin);
1236 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1237 if (direction == kIncomingPacket)
1238 plot->SetTitle("Target bitrate per incoming layer");
1239 else
1240 plot->SetTitle("Target bitrate per outgoing layer");
1241}
1242
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001243void EventLogAnalyzer::CreateGoogCcSimulationGraph(Plot* plot) {
1244 TimeSeries target_rates("Simulated target rate", LineStyle::kStep,
1245 PointStyle::kHighlight);
1246 TimeSeries delay_based("Logged delay-based estimate", LineStyle::kStep,
1247 PointStyle::kHighlight);
1248 TimeSeries loss_based("Logged loss-based estimate", LineStyle::kStep,
1249 PointStyle::kHighlight);
1250 TimeSeries probe_results("Logged probe success", LineStyle::kNone,
1251 PointStyle::kHighlight);
1252
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001253 LogBasedNetworkControllerSimulation simulation(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001254 std::make_unique<GoogCcNetworkControllerFactory>(),
Sebastian Jansson1175ae02019-03-13 08:56:58 +01001255 [&](const NetworkControlUpdate& update, Timestamp at_time) {
1256 if (update.target_rate) {
1257 target_rates.points.emplace_back(
1258 config_.GetCallTimeSec(at_time.us()),
1259 update.target_rate->target_rate.kbps<float>());
1260 }
1261 });
1262
1263 simulation.ProcessEventsInLog(parsed_log_);
1264 for (const auto& logged : parsed_log_.bwe_delay_updates())
1265 delay_based.points.emplace_back(
1266 config_.GetCallTimeSec(logged.log_time_us()),
1267 logged.bitrate_bps / 1000);
1268 for (const auto& logged : parsed_log_.bwe_probe_success_events())
1269 probe_results.points.emplace_back(
1270 config_.GetCallTimeSec(logged.log_time_us()),
1271 logged.bitrate_bps / 1000);
1272 for (const auto& logged : parsed_log_.bwe_loss_updates())
1273 loss_based.points.emplace_back(config_.GetCallTimeSec(logged.log_time_us()),
1274 logged.bitrate_bps / 1000);
1275
1276 plot->AppendTimeSeries(std::move(delay_based));
1277 plot->AppendTimeSeries(std::move(loss_based));
1278 plot->AppendTimeSeries(std::move(probe_results));
1279 plot->AppendTimeSeries(std::move(target_rates));
1280
1281 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1282 "Time (s)", kLeftMargin, kRightMargin);
1283 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1284 plot->SetTitle("Simulated BWE behavior");
1285}
1286
Bjorn Terelius28db2662017-10-04 14:22:43 +02001287void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001288 using RtpPacketType = LoggedRtpPacketOutgoing;
1289 using TransportFeedbackType = LoggedRtcpPacketTransportFeedback;
Stefan Holmer13181032016-07-29 14:48:54 +02001290
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001291 // TODO(terelius): This could be provided by the parser.
1292 std::multimap<int64_t, const RtpPacketType*> outgoing_rtp;
1293 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1294 for (const RtpPacketType& rtp_packet : stream.outgoing_packets)
1295 outgoing_rtp.insert(
1296 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Stefan Holmer13181032016-07-29 14:48:54 +02001297 }
1298
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001299 const std::vector<TransportFeedbackType>& incoming_rtcp =
1300 parsed_log_.transport_feedbacks(kIncomingPacket);
Stefan Holmer13181032016-07-29 14:48:54 +02001301
1302 SimulatedClock clock(0);
1303 BitrateObserver observer;
Danil Chapovalov83bbe912019-08-07 12:24:53 +02001304 RtcEventLogNull null_event_log;
nisse0245da02016-11-30 03:35:20 -08001305 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001306 PacedSender pacer(&clock, &packet_router, &null_event_log);
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001307 TransportFeedbackAdapter transport_feedback;
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001308 auto factory = GoogCcNetworkControllerFactory();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001309 TimeDelta process_interval = factory.GetProcessInterval();
Stefan Holmer13181032016-07-29 14:48:54 +02001310 // TODO(holmer): Log the call config and use that here instead.
1311 static const uint32_t kDefaultStartBitrateBps = 300000;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001312 NetworkControllerConfig cc_config;
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001313 cc_config.constraints.at_time = Timestamp::Micros(clock.TimeInMicroseconds());
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +01001314 cc_config.constraints.starting_rate =
1315 DataRate::BitsPerSec(kDefaultStartBitrateBps);
Sebastian Jansson2db5fc02019-04-30 14:17:45 +02001316 cc_config.event_log = &null_event_log;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001317 auto goog_cc = factory.Create(cc_config);
Stefan Holmer13181032016-07-29 14:48:54 +02001318
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001319 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1320 PointStyle::kHighlight);
1321 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1322 PointStyle::kHighlight);
1323 TimeSeries acked_estimate_time_series(
1324 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001325
1326 auto rtp_iterator = outgoing_rtp.begin();
1327 auto rtcp_iterator = incoming_rtcp.begin();
1328
1329 auto NextRtpTime = [&]() {
1330 if (rtp_iterator != outgoing_rtp.end())
1331 return static_cast<int64_t>(rtp_iterator->first);
1332 return std::numeric_limits<int64_t>::max();
1333 };
1334
1335 auto NextRtcpTime = [&]() {
1336 if (rtcp_iterator != incoming_rtcp.end())
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001337 return static_cast<int64_t>(rtcp_iterator->log_time_us());
Stefan Holmer13181032016-07-29 14:48:54 +02001338 return std::numeric_limits<int64_t>::max();
1339 };
Bjorn Tereliusa728c912018-12-06 12:26:30 +01001340 int64_t next_process_time_us_ = std::min({NextRtpTime(), NextRtcpTime()});
Stefan Holmer13181032016-07-29 14:48:54 +02001341
1342 auto NextProcessTime = [&]() {
1343 if (rtcp_iterator != incoming_rtcp.end() ||
1344 rtp_iterator != outgoing_rtp.end()) {
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001345 return next_process_time_us_;
Stefan Holmer13181032016-07-29 14:48:54 +02001346 }
1347 return std::numeric_limits<int64_t>::max();
1348 };
1349
Stefan Holmer492ee282016-10-27 17:19:20 +02001350 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001351#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson95edb032019-01-17 16:24:12 +01001352 FieldTrialBasedConfig field_trial_config_;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001353 // The event_log_visualizer should normally not be compiled with
1354 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
Björn Terelius251b0dc2019-11-11 21:00:18 +01001355 // However, compiling with BWE_TEST_LOGGING, running with --plot=sendside_bwe
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001356 // and piping the output to plot_dynamics.py can be used as a hack to get the
1357 // internal state of various BWE components. In this case, it is important
1358 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
Sebastian Jansson4ad51d82019-06-11 11:24:40 +02001359 // GoogCcNetworkController since that would lead to duplicate outputs.
Björn Terelius251b0dc2019-11-11 21:00:18 +01001360 std::unique_ptr<AcknowledgedBitrateEstimatorInterface>
1361 acknowledged_bitrate_estimator(
1362 AcknowledgedBitrateEstimatorInterface::Create(&field_trial_config_));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001363#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001364 int64_t time_us =
1365 std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
Stefan Holmer492ee282016-10-27 17:19:20 +02001366 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001367 while (time_us != std::numeric_limits<int64_t>::max()) {
1368 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001369 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1370 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1371 const RtpPacketType& rtp_packet = *rtp_iterator->second;
1372 if (rtp_packet.rtp.header.extension.hasTransportSequenceNumber) {
1373 RTC_DCHECK(rtp_packet.rtp.header.extension.hasTransportSequenceNumber);
Erik Språng30a276b2019-04-23 12:00:11 +02001374 RtpPacketSendInfo packet_info;
1375 packet_info.ssrc = rtp_packet.rtp.header.ssrc;
Bjorn Tereliusf2e9cab2019-05-27 16:44:09 +02001376 packet_info.transport_sequence_number =
Erik Språng30a276b2019-04-23 12:00:11 +02001377 rtp_packet.rtp.header.extension.transportSequenceNumber;
1378 packet_info.rtp_sequence_number = rtp_packet.rtp.header.sequenceNumber;
Erik Språng30a276b2019-04-23 12:00:11 +02001379 packet_info.length = rtp_packet.rtp.total_length;
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001380 transport_feedback.AddPacket(
Erik Språng30a276b2019-04-23 12:00:11 +02001381 packet_info,
1382 0u, // Per packet overhead bytes.
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001383 Timestamp::Micros(rtp_packet.rtp.log_time_us()));
Bjorn Tereliusc60a7772018-12-05 21:15:30 +01001384 rtc::SentPacket sent_packet(
1385 rtp_packet.rtp.header.extension.transportSequenceNumber,
1386 rtp_packet.rtp.log_time_us() / 1000);
1387 auto sent_msg = transport_feedback.ProcessSentPacket(sent_packet);
1388 if (sent_msg)
1389 observer.Update(goog_cc->OnSentPacket(*sent_msg));
1390 }
1391 ++rtp_iterator;
1392 }
Stefan Holmer13181032016-07-29 14:48:54 +02001393 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001394 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001395
1396 auto feedback_msg = transport_feedback.ProcessTransportFeedback(
Sebastian Jansson05acd2b2019-01-21 13:07:47 +01001397 rtcp_iterator->transport_feedback,
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001398 Timestamp::Millis(clock.TimeInMilliseconds()));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001399 absl::optional<uint32_t> bitrate_bps;
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001400 if (feedback_msg) {
1401 observer.Update(goog_cc->OnTransportPacketsFeedback(*feedback_msg));
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001402 std::vector<PacketResult> feedback =
1403 feedback_msg->SortedByReceiveTime();
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001404 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001405#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Björn Terelius251b0dc2019-11-11 21:00:18 +01001406 acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
1407 feedback);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001408#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001409 for (const PacketResult& packet : feedback)
1410 acked_bitrate.Update(packet.sent_packet.size.bytes(),
1411 packet.receive_time.ms());
1412 bitrate_bps = acked_bitrate.Rate(feedback.back().receive_time.ms());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001413 }
Stefan Holmer13181032016-07-29 14:48:54 +02001414 }
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001415
Bjorn Terelius068fc352019-02-13 22:38:25 +01001416 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001417 float y = bitrate_bps.value_or(0) / 1000;
1418 acked_time_series.points.emplace_back(x, y);
1419#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Björn Terelius251b0dc2019-11-11 21:00:18 +01001420 y = acknowledged_bitrate_estimator->bitrate()
Sebastian Jansson88290ae2019-06-20 12:26:31 +02001421 .value_or(DataRate::Zero())
1422 .kbps();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001423 acked_estimate_time_series.points.emplace_back(x, y);
1424#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001425 ++rtcp_iterator;
1426 }
stefanc3de0332016-08-02 07:22:17 -07001427 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1428 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001429 ProcessInterval msg;
Danil Chapovalov0c626af2020-02-10 11:16:00 +01001430 msg.at_time = Timestamp::Micros(clock.TimeInMicroseconds());
Sebastian Jansson5c94f552018-10-15 18:46:51 +02001431 observer.Update(goog_cc->OnProcessInterval(msg));
1432 next_process_time_us_ += process_interval.us();
stefanc3de0332016-08-02 07:22:17 -07001433 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001434 if (observer.GetAndResetBitrateUpdated() ||
1435 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001436 uint32_t y = observer.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001437 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Stefan Holmer13181032016-07-29 14:48:54 +02001438 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001439 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001440 }
1441 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1442 }
1443 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001444 plot->AppendTimeSeries(std::move(time_series));
1445 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001446 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001447
Bjorn Terelius068fc352019-02-13 22:38:25 +01001448 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1449 "Time (s)", kLeftMargin, kRightMargin);
tereliusdc35dcd2016-08-01 12:03:27 -07001450 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001451 plot->SetTitle("Simulated send-side BWE behavior");
1452}
1453
1454void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001455 using RtpPacketType = LoggedRtpPacketIncoming;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001456 class RembInterceptingPacketRouter : public PacketRouter {
1457 public:
1458 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1459 uint32_t bitrate_bps) override {
1460 last_bitrate_bps_ = bitrate_bps;
1461 bitrate_updated_ = true;
1462 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1463 }
1464 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1465 bool GetAndResetBitrateUpdated() {
1466 bool bitrate_updated = bitrate_updated_;
1467 bitrate_updated_ = false;
1468 return bitrate_updated;
1469 }
1470
1471 private:
Bjorn Terelius571e1302020-06-09 10:29:09 +02001472 // We don't know the start bitrate, but assume that it is the default 300
1473 // kbps.
1474 uint32_t last_bitrate_bps_ = 300000;
1475 bool bitrate_updated_ = false;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001476 };
1477
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001478 std::multimap<int64_t, const RtpPacketType*> incoming_rtp;
Bjorn Terelius28db2662017-10-04 14:22:43 +02001479
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001480 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Bjorn Terelius48b82792020-05-19 10:57:24 +02001481 if (IsVideoSsrc(parsed_log_, kIncomingPacket, stream.ssrc)) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001482 for (const auto& rtp_packet : stream.incoming_packets)
1483 incoming_rtp.insert(
1484 std::make_pair(rtp_packet.rtp.log_time_us(), &rtp_packet));
Bjorn Terelius28db2662017-10-04 14:22:43 +02001485 }
1486 }
1487
1488 SimulatedClock clock(0);
1489 RembInterceptingPacketRouter packet_router;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001490 // TODO(terelius): The PacketRouter is used as the RemoteBitrateObserver.
Bjorn Terelius28db2662017-10-04 14:22:43 +02001491 // Is this intentional?
1492 ReceiveSideCongestionController rscc(&clock, &packet_router);
1493 // TODO(holmer): Log the call config and use that here instead.
1494 // static const uint32_t kDefaultStartBitrateBps = 300000;
1495 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1496
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001497 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1498 PointStyle::kHighlight);
1499 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001500
1501 RateStatistics acked_bitrate(250, 8000);
1502 int64_t last_update_us = 0;
1503 for (const auto& kv : incoming_rtp) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001504 const RtpPacketType& packet = *kv.second;
1505 int64_t arrival_time_ms = packet.rtp.log_time_us() / 1000;
1506 size_t payload = packet.rtp.total_length; /*Should subtract header?*/
1507 clock.AdvanceTimeMicroseconds(packet.rtp.log_time_us() -
Bjorn Terelius28db2662017-10-04 14:22:43 +02001508 clock.TimeInMicroseconds());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001509 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.rtp.header);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001510 acked_bitrate.Update(payload, arrival_time_ms);
Danil Chapovalov431abd92018-06-18 12:54:17 +02001511 absl::optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001512 if (bitrate_bps) {
1513 uint32_t y = *bitrate_bps / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001514 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001515 acked_time_series.points.emplace_back(x, y);
1516 }
1517 if (packet_router.GetAndResetBitrateUpdated() ||
1518 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1519 uint32_t y = packet_router.last_bitrate_bps() / 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001520 float x = config_.GetCallTimeSec(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001521 time_series.points.emplace_back(x, y);
1522 last_update_us = clock.TimeInMicroseconds();
1523 }
1524 }
1525 // Add the data set to the plot.
1526 plot->AppendTimeSeries(std::move(time_series));
1527 plot->AppendTimeSeries(std::move(acked_time_series));
1528
Bjorn Terelius068fc352019-02-13 22:38:25 +01001529 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1530 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001531 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1532 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001533}
1534
tereliuse34c19c2016-08-15 08:47:14 -07001535void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001536 TimeSeries time_series("Network delay", LineStyle::kLine,
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001537 PointStyle::kHighlight);
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001538 int64_t min_send_receive_diff_ms = std::numeric_limits<int64_t>::max();
1539 int64_t min_rtt_ms = std::numeric_limits<int64_t>::max();
stefanc3de0332016-08-02 07:22:17 -07001540
stefana0a8ed72017-09-06 02:06:32 -07001541 int64_t prev_y = 0;
Björn Tereliusc69c1bb2019-10-11 15:06:58 +02001542 std::vector<MatchedSendArrivalTimes> matched_rtp_rtcp =
1543 GetNetworkTrace(parsed_log_);
1544 absl::c_stable_sort(matched_rtp_rtcp, [](const MatchedSendArrivalTimes& a,
1545 const MatchedSendArrivalTimes& b) {
philipel3574d052019-11-18 14:38:13 +01001546 return a.feedback_arrival_time_ms < b.feedback_arrival_time_ms ||
1547 (a.feedback_arrival_time_ms == b.feedback_arrival_time_ms &&
1548 a.arrival_time_ms < b.arrival_time_ms);
Björn Tereliusc69c1bb2019-10-11 15:06:58 +02001549 });
1550 for (const auto& packet : matched_rtp_rtcp) {
Sebastian Jansson74f96ec2019-10-29 12:57:54 +01001551 if (packet.arrival_time_ms == MatchedSendArrivalTimes::kNotReceived)
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001552 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001553 float x = config_.GetCallTimeSec(1000 * packet.feedback_arrival_time_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001554 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1555 prev_y = y;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001556 int64_t rtt_ms = packet.feedback_arrival_time_ms - packet.send_time_ms;
1557 min_rtt_ms = std::min(rtt_ms, min_rtt_ms);
1558 min_send_receive_diff_ms = std::min(y, min_send_receive_diff_ms);
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001559 time_series.points.emplace_back(x, y);
stefanc3de0332016-08-02 07:22:17 -07001560 }
Christoffer Rodbro89f64d32018-09-27 14:29:35 +02001561
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001562 // We assume that the base network delay (w/o queues) is equal to half
1563 // the minimum RTT. Therefore rescale the delays by subtracting the minimum
Mirko Bonadei604e75c2019-07-25 11:55:47 +02001564 // observed 1-ways delay and add half the minimum RTT.
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001565 const int64_t estimated_clock_offset_ms =
1566 min_send_receive_diff_ms - min_rtt_ms / 2;
stefanc3de0332016-08-02 07:22:17 -07001567 for (TimeSeriesPoint& point : time_series.points)
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001568 point.y -= estimated_clock_offset_ms;
Bjorn Terelius57ba7e12018-10-25 15:31:35 +02001569
stefanc3de0332016-08-02 07:22:17 -07001570 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001571 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001572
Bjorn Terelius068fc352019-02-13 22:38:25 +01001573 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1574 "Time (s)", kLeftMargin, kRightMargin);
stefanc3de0332016-08-02 07:22:17 -07001575 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
Konrad Hofbauer5be3bbd2019-01-21 12:31:07 +01001576 plot->SetTitle("Outgoing network delay (based on per-packet feedback)");
stefanc3de0332016-08-02 07:22:17 -07001577}
stefan08383272016-12-20 08:51:52 -08001578
Bjorn Terelius0295a962017-10-25 17:42:41 +02001579void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001580 for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
1581 const std::vector<LoggedRtpPacketOutgoing>& packets =
1582 stream.outgoing_packets;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001583
Bjorn Terelius48b82792020-05-19 10:57:24 +02001584 if (IsRtxSsrc(parsed_log_, kOutgoingPacket, stream.ssrc)) {
Konrad Hofbauerbfb735b2019-04-16 11:12:11 +02001585 continue;
1586 }
1587
Bjorn Terelius0295a962017-10-25 17:42:41 +02001588 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001589 RTC_LOG(LS_WARNING)
1590 << "Can't estimate a the RTP clock frequency or the "
1591 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001592 continue;
1593 }
Björn Terelius0d1b28c2020-05-27 20:25:06 +02001594 int64_t segment_end_us = parsed_log_.first_log_segment().stop_time_us();
Danil Chapovalov431abd92018-06-18 12:54:17 +02001595 absl::optional<uint32_t> estimated_frequency =
Bjorn Terelius48b82792020-05-19 10:57:24 +02001596 EstimateRtpClockFrequency(packets, segment_end_us);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001597 if (!estimated_frequency)
1598 continue;
Bjorn Terelius48b82792020-05-19 10:57:24 +02001599 if (IsVideoSsrc(parsed_log_, kOutgoingPacket, stream.ssrc) &&
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001600 *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001601 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001602 << "Video stream should use a 90 kHz clock but appears to use "
1603 << *estimated_frequency / 1000 << ". Discarding.";
1604 continue;
1605 }
1606
1607 TimeSeries pacer_delay_series(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001608 GetStreamName(parsed_log_, kOutgoingPacket, stream.ssrc) + "(" +
Bjorn Terelius0295a962017-10-25 17:42:41 +02001609 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001610 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001611 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1612 uint64_t first_capture_timestamp =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001613 timestamp_unwrapper.Unwrap(packets.front().rtp.header.timestamp);
1614 uint64_t first_send_timestamp = packets.front().rtp.log_time_us();
1615 for (const auto& packet : packets) {
Bjorn Terelius0295a962017-10-25 17:42:41 +02001616 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001617 packet.rtp.header.timestamp)) -
Bjorn Terelius0295a962017-10-25 17:42:41 +02001618 first_capture_timestamp) /
1619 *estimated_frequency * 1000;
1620 double send_time_ms =
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001621 static_cast<double>(packet.rtp.log_time_us() - first_send_timestamp) /
1622 1000;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001623 float x = config_.GetCallTimeSec(packet.rtp.log_time_us());
Bjorn Terelius0295a962017-10-25 17:42:41 +02001624 float y = send_time_ms - capture_time_ms;
1625 pacer_delay_series.points.emplace_back(x, y);
1626 }
1627 plot->AppendTimeSeries(std::move(pacer_delay_series));
1628 }
1629
Bjorn Terelius068fc352019-02-13 22:38:25 +01001630 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1631 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001632 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1633 plot->SetTitle(
1634 "Delay from capture to send time. (First packet normalized to 0.)");
1635}
1636
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001637void EventLogAnalyzer::CreateTimestampGraph(PacketDirection direction,
1638 Plot* plot) {
1639 for (const auto& stream : parsed_log_.rtp_packets_by_ssrc(direction)) {
1640 TimeSeries rtp_timestamps(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001641 GetStreamName(parsed_log_, direction, stream.ssrc) + " capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001642 LineStyle::kLine, PointStyle::kHighlight);
1643 for (const auto& packet : stream.packet_view) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001644 float x = config_.GetCallTimeSec(packet.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001645 float y = packet.header.timestamp;
1646 rtp_timestamps.points.emplace_back(x, y);
stefane372d3c2017-02-02 08:04:18 -08001647 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001648 plot->AppendTimeSeries(std::move(rtp_timestamps));
Björn Tereliusff612732018-04-25 14:23:01 +00001649
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001650 TimeSeries rtcp_timestamps(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001651 GetStreamName(parsed_log_, direction, stream.ssrc) +
1652 " rtcp capture-time",
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001653 LineStyle::kLine, PointStyle::kHighlight);
1654 // TODO(terelius): Why only sender reports?
1655 const auto& sender_reports = parsed_log_.sender_reports(direction);
1656 for (const auto& rtcp : sender_reports) {
1657 if (rtcp.sr.sender_ssrc() != stream.ssrc)
1658 continue;
Bjorn Terelius068fc352019-02-13 22:38:25 +01001659 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001660 float y = rtcp.sr.rtp_timestamp();
1661 rtcp_timestamps.points.emplace_back(x, y);
Björn Tereliusff612732018-04-25 14:23:01 +00001662 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001663 plot->AppendTimeSeriesIfNotEmpty(std::move(rtcp_timestamps));
stefane372d3c2017-02-02 08:04:18 -08001664 }
1665
Bjorn Terelius068fc352019-02-13 22:38:25 +01001666 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1667 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001668 plot->SetSuggestedYAxis(0, 1, "RTP timestamp", kBottomMargin, kTopMargin);
1669 plot->SetTitle(GetDirectionAsString(direction) + " timestamps");
stefane372d3c2017-02-02 08:04:18 -08001670}
michaelt6e5b2192017-02-22 07:33:27 -08001671
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001672void EventLogAnalyzer::CreateSenderAndReceiverReportPlot(
1673 PacketDirection direction,
1674 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
1675 std::string title,
1676 std::string yaxis_label,
1677 Plot* plot) {
1678 std::map<uint32_t, TimeSeries> sr_reports_by_ssrc;
1679 const auto& sender_reports = parsed_log_.sender_reports(direction);
1680 for (const auto& rtcp : sender_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001681 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001682 uint32_t ssrc = rtcp.sr.sender_ssrc();
1683 for (const auto& block : rtcp.sr.report_blocks()) {
1684 float y = fy(block);
1685 auto sr_report_it = sr_reports_by_ssrc.find(ssrc);
1686 bool inserted;
1687 if (sr_report_it == sr_reports_by_ssrc.end()) {
1688 std::tie(sr_report_it, inserted) = sr_reports_by_ssrc.emplace(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001689 ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) +
1690 " Sender Reports",
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001691 LineStyle::kLine, PointStyle::kHighlight));
1692 }
1693 sr_report_it->second.points.emplace_back(x, y);
1694 }
1695 }
1696 for (auto& kv : sr_reports_by_ssrc) {
1697 plot->AppendTimeSeries(std::move(kv.second));
1698 }
1699
1700 std::map<uint32_t, TimeSeries> rr_reports_by_ssrc;
1701 const auto& receiver_reports = parsed_log_.receiver_reports(direction);
1702 for (const auto& rtcp : receiver_reports) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001703 float x = config_.GetCallTimeSec(rtcp.log_time_us());
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001704 uint32_t ssrc = rtcp.rr.sender_ssrc();
1705 for (const auto& block : rtcp.rr.report_blocks()) {
1706 float y = fy(block);
1707 auto rr_report_it = rr_reports_by_ssrc.find(ssrc);
1708 bool inserted;
1709 if (rr_report_it == rr_reports_by_ssrc.end()) {
1710 std::tie(rr_report_it, inserted) = rr_reports_by_ssrc.emplace(
Bjorn Terelius48b82792020-05-19 10:57:24 +02001711 ssrc, TimeSeries(GetStreamName(parsed_log_, direction, ssrc) +
1712 " Receiver Reports",
1713 LineStyle::kLine, PointStyle::kHighlight));
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001714 }
1715 rr_report_it->second.points.emplace_back(x, y);
1716 }
1717 }
1718 for (auto& kv : rr_reports_by_ssrc) {
1719 plot->AppendTimeSeries(std::move(kv.second));
1720 }
1721
Bjorn Terelius068fc352019-02-13 22:38:25 +01001722 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1723 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +02001724 plot->SetSuggestedYAxis(0, 1, yaxis_label, kBottomMargin, kTopMargin);
1725 plot->SetTitle(title);
1726}
1727
michaelt6e5b2192017-02-22 07:33:27 -08001728void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001729 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1730 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001731 auto GetAnaBitrateBps = [](const LoggedAudioNetworkAdaptationEvent& ana_event)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001732 -> absl::optional<float> {
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001733 if (ana_event.config.bitrate_bps)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001734 return absl::optional<float>(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001735 static_cast<float>(*ana_event.config.bitrate_bps));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001736 return absl::nullopt;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001737 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001738 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001739 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001740 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001741 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001742 ToCallTime, GetAnaBitrateBps,
1743 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001744 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001745 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1746 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001747 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1748 plot->SetTitle("Reported audio encoder target bitrate");
1749}
1750
1751void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001752 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1753 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001754 auto GetAnaFrameLengthMs =
1755 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001756 if (ana_event.config.frame_length_ms)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001757 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001758 static_cast<float>(*ana_event.config.frame_length_ms));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001759 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001760 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001761 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001762 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001763 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001764 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001765 ToCallTime, GetAnaFrameLengthMs,
1766 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001767 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001768 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1769 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001770 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1771 plot->SetTitle("Reported audio encoder frame length");
1772}
1773
terelius2ee076d2017-08-15 02:04:02 -07001774void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001775 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001776 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001777 auto GetAnaPacketLoss =
1778 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001779 if (ana_event.config.uplink_packet_loss_fraction)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001780 return absl::optional<float>(static_cast<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001781 *ana_event.config.uplink_packet_loss_fraction));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001782 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001783 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001784 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001785 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001786 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001787 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001788 ToCallTime, GetAnaPacketLoss,
1789 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001790 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001791 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1792 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001793 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1794 kTopMargin);
1795 plot->SetTitle("Reported audio encoder lost packets");
1796}
1797
1798void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001799 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1800 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001801 auto GetAnaFecEnabled =
1802 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001803 if (ana_event.config.enable_fec)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001804 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001805 static_cast<float>(*ana_event.config.enable_fec));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001806 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001807 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001808 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001809 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001810 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001811 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001812 ToCallTime, GetAnaFecEnabled,
1813 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001814 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001815 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1816 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001817 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1818 plot->SetTitle("Reported audio encoder FEC");
1819}
1820
1821void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001822 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1823 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001824 auto GetAnaDtxEnabled =
1825 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001826 if (ana_event.config.enable_dtx)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001827 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001828 static_cast<float>(*ana_event.config.enable_dtx));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001829 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001830 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001831 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001832 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001833 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001834 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001835 ToCallTime, GetAnaDtxEnabled,
1836 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001837 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001838 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1839 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001840 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1841 plot->SetTitle("Reported audio encoder DTX");
1842}
1843
1844void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001845 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1846 PointStyle::kHighlight);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001847 auto GetAnaNumChannels =
1848 [](const LoggedAudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001849 if (ana_event.config.num_channels)
Danil Chapovalov431abd92018-06-18 12:54:17 +02001850 return absl::optional<float>(
michaelt6e5b2192017-02-22 07:33:27 -08001851 static_cast<float>(*ana_event.config.num_channels));
Danil Chapovalov431abd92018-06-18 12:54:17 +02001852 return absl::optional<float>();
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001853 };
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001854 auto ToCallTime = [this](const LoggedAudioNetworkAdaptationEvent& packet) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01001855 return this->config_.GetCallTimeSec(packet.log_time_us());
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001856 };
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001857 ProcessPoints<LoggedAudioNetworkAdaptationEvent>(
Stefan Holmer1d4a2272018-05-24 13:48:09 +02001858 ToCallTime, GetAnaNumChannels,
1859 parsed_log_.audio_network_adaptation_events(), &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001860 plot->AppendTimeSeries(std::move(time_series));
Bjorn Terelius068fc352019-02-13 22:38:25 +01001861 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
1862 "Time (s)", kLeftMargin, kRightMargin);
michaelt6e5b2192017-02-22 07:33:27 -08001863 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1864 kBottomMargin, kTopMargin);
1865 plot->SetTitle("Reported audio encoder number of channels");
1866}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001867
1868class NetEqStreamInput : public test::NetEqInput {
1869 public:
1870 // Does not take any ownership, and all pointers must refer to valid objects
1871 // that outlive the one constructed.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001872 NetEqStreamInput(const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001873 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001874 absl::optional<int64_t> end_time_ms)
henrik.lundin3c938fc2017-06-14 06:09:58 -07001875 : packet_stream_(*packet_stream),
1876 packet_stream_it_(packet_stream_.begin()),
Minyue Li27e2b7d2018-05-07 15:20:24 +02001877 output_events_it_(output_events->begin()),
1878 output_events_end_(output_events->end()),
1879 end_time_ms_(end_time_ms) {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001880 RTC_DCHECK(packet_stream);
Minyue Li27e2b7d2018-05-07 15:20:24 +02001881 RTC_DCHECK(output_events);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001882 }
1883
Danil Chapovalov431abd92018-06-18 12:54:17 +02001884 absl::optional<int64_t> NextPacketTime() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001885 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001886 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001887 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001888 if (end_time_ms_ && packet_stream_it_->rtp.log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001889 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001890 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001891 return packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001892 }
1893
Danil Chapovalov431abd92018-06-18 12:54:17 +02001894 absl::optional<int64_t> NextOutputEventTime() const override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001895 if (output_events_it_ == output_events_end_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001896 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001897 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001898 if (end_time_ms_ && output_events_it_->log_time_ms() > *end_time_ms_) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001899 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001900 }
Minyue Li27e2b7d2018-05-07 15:20:24 +02001901 return output_events_it_->log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001902 }
1903
1904 std::unique_ptr<PacketData> PopPacket() override {
1905 if (packet_stream_it_ == packet_stream_.end()) {
1906 return std::unique_ptr<PacketData>();
1907 }
1908 std::unique_ptr<PacketData> packet_data(new PacketData());
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001909 packet_data->header = packet_stream_it_->rtp.header;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001910 packet_data->time_ms = packet_stream_it_->rtp.log_time_ms();
henrik.lundin3c938fc2017-06-14 06:09:58 -07001911
1912 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1913 // length according to the virtual length.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001914 packet_data->payload.SetSize(packet_stream_it_->rtp.total_length -
1915 packet_stream_it_->rtp.header_length);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001916 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1917
1918 ++packet_stream_it_;
1919 return packet_data;
1920 }
1921
1922 void AdvanceOutputEvent() override {
Minyue Li27e2b7d2018-05-07 15:20:24 +02001923 if (output_events_it_ != output_events_end_) {
1924 ++output_events_it_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001925 }
1926 }
1927
1928 bool ended() const override { return !NextEventTime(); }
1929
Danil Chapovalov431abd92018-06-18 12:54:17 +02001930 absl::optional<RTPHeader> NextHeader() const override {
henrik.lundin3c938fc2017-06-14 06:09:58 -07001931 if (packet_stream_it_ == packet_stream_.end()) {
Danil Chapovalov431abd92018-06-18 12:54:17 +02001932 return absl::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001933 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001934 return packet_stream_it_->rtp.header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001935 }
1936
1937 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001938 const std::vector<LoggedRtpPacketIncoming>& packet_stream_;
1939 std::vector<LoggedRtpPacketIncoming>::const_iterator packet_stream_it_;
Minyue Li27e2b7d2018-05-07 15:20:24 +02001940 std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_it_;
1941 const std::vector<LoggedAudioPlayoutEvent>::const_iterator output_events_end_;
Danil Chapovalov431abd92018-06-18 12:54:17 +02001942 const absl::optional<int64_t> end_time_ms_;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001943};
1944
1945namespace {
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001946
1947// Factory to create a "replacement decoder" that produces the decoded audio
1948// by reading from a file rather than from the encoded payloads.
1949class ReplacementAudioDecoderFactory : public AudioDecoderFactory {
1950 public:
1951 ReplacementAudioDecoderFactory(const absl::string_view replacement_file_name,
1952 int file_sample_rate_hz)
1953 : replacement_file_name_(replacement_file_name),
1954 file_sample_rate_hz_(file_sample_rate_hz) {}
1955
1956 std::vector<AudioCodecSpec> GetSupportedDecoders() override {
1957 RTC_NOTREACHED();
1958 return {};
1959 }
1960
1961 bool IsSupportedDecoder(const SdpAudioFormat& format) override {
1962 return true;
1963 }
1964
1965 std::unique_ptr<AudioDecoder> MakeAudioDecoder(
1966 const SdpAudioFormat& format,
1967 absl::optional<AudioCodecPairId> codec_pair_id) override {
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001968 auto replacement_file = std::make_unique<test::ResampleInputAudioFile>(
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001969 replacement_file_name_, file_sample_rate_hz_);
1970 replacement_file->set_output_rate_hz(48000);
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001971 return std::make_unique<test::FakeDecodeFromFile>(
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01001972 std::move(replacement_file), 48000, false);
1973 }
1974
1975 private:
1976 const std::string replacement_file_name_;
1977 const int file_sample_rate_hz_;
1978};
1979
henrik.lundin3c938fc2017-06-14 06:09:58 -07001980// Creates a NetEq test object and all necessary input and output helpers. Runs
1981// the test and returns the NetEqDelayAnalyzer object that was used to
1982// instrument the test.
Minyue Lic6ff7572018-05-04 09:46:44 +02001983std::unique_ptr<test::NetEqStatsGetter> CreateNetEqTestAndRun(
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02001984 const std::vector<LoggedRtpPacketIncoming>* packet_stream,
Minyue Li27e2b7d2018-05-07 15:20:24 +02001985 const std::vector<LoggedAudioPlayoutEvent>* output_events,
Danil Chapovalov431abd92018-06-18 12:54:17 +02001986 absl::optional<int64_t> end_time_ms,
henrik.lundin3c938fc2017-06-14 06:09:58 -07001987 const std::string& replacement_file_name,
1988 int file_sample_rate_hz) {
1989 std::unique_ptr<test::NetEqInput> input(
Minyue Li27e2b7d2018-05-07 15:20:24 +02001990 new NetEqStreamInput(packet_stream, output_events, end_time_ms));
henrik.lundin3c938fc2017-06-14 06:09:58 -07001991
1992 constexpr int kReplacementPt = 127;
1993 std::set<uint8_t> cn_types;
1994 std::set<uint8_t> forbidden_types;
1995 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1996 cn_types, forbidden_types));
1997
1998 NetEq::Config config;
1999 config.max_packets_in_buffer = 200;
2000 config.enable_fast_accelerate = true;
2001
2002 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
2003
Niels Möller3f651d82018-12-19 15:06:17 +01002004 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory =
Bjorn Terelius6c4b1b72019-01-11 13:01:29 +01002005 new rtc::RefCountedObject<ReplacementAudioDecoderFactory>(
2006 replacement_file_name, file_sample_rate_hz);
Niels Möller3f651d82018-12-19 15:06:17 +01002007
Niels Möller05543682019-01-10 16:55:06 +01002008 test::NetEqTest::DecoderMap codecs = {
2009 {kReplacementPt, SdpAudioFormat("l16", 48000, 1)}};
henrik.lundin3c938fc2017-06-14 06:09:58 -07002010
2011 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
2012 new test::NetEqDelayAnalyzer);
Minyue Lic6ff7572018-05-04 09:46:44 +02002013 std::unique_ptr<test::NetEqStatsGetter> neteq_stats_getter(
2014 new test::NetEqStatsGetter(std::move(delay_cb)));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002015 test::DefaultNetEqTestErrorCallback error_cb;
2016 test::NetEqTest::Callbacks callbacks;
2017 callbacks.error_callback = &error_cb;
Minyue Lic6ff7572018-05-04 09:46:44 +02002018 callbacks.post_insert_packet = neteq_stats_getter->delay_analyzer();
2019 callbacks.get_audio_callback = neteq_stats_getter.get();
henrik.lundin3c938fc2017-06-14 06:09:58 -07002020
Ivo Creusencee751a2020-01-16 17:17:09 +01002021 test::NetEqTest test(config, decoder_factory, codecs, /*text_log=*/nullptr,
2022 /*factory=*/nullptr, std::move(input), std::move(output),
2023 callbacks);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002024 test.Run();
Minyue Lic6ff7572018-05-04 09:46:44 +02002025 return neteq_stats_getter;
henrik.lundin3c938fc2017-06-14 06:09:58 -07002026}
2027} // namespace
2028
Minyue Lic6ff7572018-05-04 09:46:44 +02002029EventLogAnalyzer::NetEqStatsGetterMap EventLogAnalyzer::SimulateNetEq(
henrik.lundin3c938fc2017-06-14 06:09:58 -07002030 const std::string& replacement_file_name,
Minyue Lic6ff7572018-05-04 09:46:44 +02002031 int file_sample_rate_hz) const {
2032 NetEqStatsGetterMap neteq_stats;
2033
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002034 for (const auto& stream : parsed_log_.incoming_rtp_packets_by_ssrc()) {
Minyue Li27e2b7d2018-05-07 15:20:24 +02002035 const uint32_t ssrc = stream.ssrc;
Bjorn Terelius48b82792020-05-19 10:57:24 +02002036 if (!IsAudioSsrc(parsed_log_, kIncomingPacket, ssrc))
Minyue Li27e2b7d2018-05-07 15:20:24 +02002037 continue;
2038 const std::vector<LoggedRtpPacketIncoming>* audio_packets =
2039 &stream.incoming_packets;
2040 if (audio_packets == nullptr) {
2041 // No incoming audio stream found.
2042 continue;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002043 }
henrik.lundin3c938fc2017-06-14 06:09:58 -07002044
Minyue Li27e2b7d2018-05-07 15:20:24 +02002045 RTC_DCHECK(neteq_stats.find(ssrc) == neteq_stats.end());
2046
2047 std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>::const_iterator
2048 output_events_it = parsed_log_.audio_playout_events().find(ssrc);
2049 if (output_events_it == parsed_log_.audio_playout_events().end()) {
2050 // Could not find output events with SSRC matching the input audio stream.
2051 // Using the first available stream of output events.
2052 output_events_it = parsed_log_.audio_playout_events().cbegin();
2053 }
2054
Björn Terelius0d1b28c2020-05-27 20:25:06 +02002055 int64_t end_time_ms = parsed_log_.first_log_segment().stop_time_ms();
Minyue Li27e2b7d2018-05-07 15:20:24 +02002056
2057 neteq_stats[ssrc] = CreateNetEqTestAndRun(
2058 audio_packets, &output_events_it->second, end_time_ms,
2059 replacement_file_name, file_sample_rate_hz);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002060 }
2061
Minyue Lic6ff7572018-05-04 09:46:44 +02002062 return neteq_stats;
2063}
2064
Minyue Lic97933f2018-08-10 12:51:15 +02002065// Given a NetEqStatsGetter and the SSRC that the NetEqStatsGetter was created
2066// for, this method generates a plot for the jitter buffer delay profile.
Minyue Lic6ff7572018-05-04 09:46:44 +02002067void EventLogAnalyzer::CreateAudioJitterBufferGraph(
Minyue Li01d2a672018-06-21 21:17:19 +02002068 uint32_t ssrc,
2069 const test::NetEqStatsGetter* stats_getter,
Minyue Lic6ff7572018-05-04 09:46:44 +02002070 Plot* plot) const {
Minyue Li45fc6df2018-06-21 11:47:14 +02002071 test::NetEqDelayAnalyzer::Delays arrival_delay_ms;
2072 test::NetEqDelayAnalyzer::Delays corrected_arrival_delay_ms;
2073 test::NetEqDelayAnalyzer::Delays playout_delay_ms;
2074 test::NetEqDelayAnalyzer::Delays target_delay_ms;
2075
Minyue Li01d2a672018-06-21 21:17:19 +02002076 stats_getter->delay_analyzer()->CreateGraphs(
Minyue Li45fc6df2018-06-21 11:47:14 +02002077 &arrival_delay_ms, &corrected_arrival_delay_ms, &playout_delay_ms,
2078 &target_delay_ms);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002079
Minyue Lic97933f2018-08-10 12:51:15 +02002080 TimeSeries time_series_packet_arrival("packet arrival delay",
2081 LineStyle::kLine);
2082 TimeSeries time_series_relative_packet_arrival(
2083 "Relative packet arrival delay", LineStyle::kLine);
2084 TimeSeries time_series_play_time("Playout delay", LineStyle::kLine);
2085 TimeSeries time_series_target_time("Target delay", LineStyle::kLine,
2086 PointStyle::kHighlight);
Minyue Li45fc6df2018-06-21 11:47:14 +02002087
2088 for (const auto& data : arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002089 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002090 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002091 time_series_packet_arrival.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02002092 }
2093 for (const auto& data : corrected_arrival_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002094 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002095 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002096 time_series_relative_packet_arrival.points.emplace_back(
Minyue Li45fc6df2018-06-21 11:47:14 +02002097 TimeSeriesPoint(x, y));
2098 }
2099 for (const auto& data : playout_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002100 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002101 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002102 time_series_play_time.points.emplace_back(TimeSeriesPoint(x, y));
Minyue Li45fc6df2018-06-21 11:47:14 +02002103 }
2104 for (const auto& data : target_delay_ms) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002105 const float x = config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Li45fc6df2018-06-21 11:47:14 +02002106 const float y = data.second;
Minyue Lic97933f2018-08-10 12:51:15 +02002107 time_series_target_time.points.emplace_back(TimeSeriesPoint(x, y));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002108 }
2109
Minyue Lic97933f2018-08-10 12:51:15 +02002110 plot->AppendTimeSeries(std::move(time_series_packet_arrival));
2111 plot->AppendTimeSeries(std::move(time_series_relative_packet_arrival));
2112 plot->AppendTimeSeries(std::move(time_series_play_time));
2113 plot->AppendTimeSeries(std::move(time_series_target_time));
henrik.lundin3c938fc2017-06-14 06:09:58 -07002114
Bjorn Terelius068fc352019-02-13 22:38:25 +01002115 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2116 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02002117 plot->SetSuggestedYAxis(0, 1, "Relative delay (ms)", kBottomMargin,
2118 kTopMargin);
Bjorn Terelius48b82792020-05-19 10:57:24 +02002119 plot->SetTitle("NetEq timing for " +
2120 GetStreamName(parsed_log_, kIncomingPacket, ssrc));
Minyue Li27e2b7d2018-05-07 15:20:24 +02002121}
2122
Minyue Lic9ac93f2018-06-26 13:01:32 +02002123template <typename NetEqStatsType>
2124void EventLogAnalyzer::CreateNetEqStatsGraphInternal(
Minyue Li27e2b7d2018-05-07 15:20:24 +02002125 const NetEqStatsGetterMap& neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +02002126 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
2127 const test::NetEqStatsGetter*)> data_extractor,
2128 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
Minyue Li27e2b7d2018-05-07 15:20:24 +02002129 const std::string& plot_name,
2130 Plot* plot) const {
Minyue Li27e2b7d2018-05-07 15:20:24 +02002131 std::map<uint32_t, TimeSeries> time_series;
Minyue Li27e2b7d2018-05-07 15:20:24 +02002132
2133 for (const auto& st : neteq_stats) {
2134 const uint32_t ssrc = st.first;
Minyue Lic9ac93f2018-06-26 13:01:32 +02002135 const std::vector<std::pair<int64_t, NetEqStatsType>>* data_vector =
2136 data_extractor(st.second.get());
2137 for (const auto& data : *data_vector) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002138 const float time =
2139 config_.GetCallTimeSec(data.first * 1000); // ms to us.
Minyue Lic9ac93f2018-06-26 13:01:32 +02002140 const float value = stats_extractor(data.second);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002141 time_series[ssrc].points.emplace_back(TimeSeriesPoint(time, value));
Minyue Li27e2b7d2018-05-07 15:20:24 +02002142 }
2143 }
2144
2145 for (auto& series : time_series) {
Bjorn Terelius48b82792020-05-19 10:57:24 +02002146 series.second.label =
2147 GetStreamName(parsed_log_, kIncomingPacket, series.first);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002148 series.second.line_style = LineStyle::kLine;
2149 plot->AppendTimeSeries(std::move(series.second));
2150 }
2151
Bjorn Terelius068fc352019-02-13 22:38:25 +01002152 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2153 "Time (s)", kLeftMargin, kRightMargin);
Minyue Li45fc6df2018-06-21 11:47:14 +02002154 plot->SetSuggestedYAxis(0, 1, plot_name, kBottomMargin, kTopMargin);
Minyue Li27e2b7d2018-05-07 15:20:24 +02002155 plot->SetTitle(plot_name);
henrik.lundin3c938fc2017-06-14 06:09:58 -07002156}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002157
Minyue Lic9ac93f2018-06-26 13:01:32 +02002158void EventLogAnalyzer::CreateNetEqNetworkStatsGraph(
2159 const NetEqStatsGetterMap& neteq_stats,
2160 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
2161 const std::string& plot_name,
2162 Plot* plot) const {
2163 CreateNetEqStatsGraphInternal<NetEqNetworkStatistics>(
2164 neteq_stats,
2165 [](const test::NetEqStatsGetter* stats_getter) {
2166 return stats_getter->stats();
2167 },
2168 stats_extractor, plot_name, plot);
2169}
2170
2171void EventLogAnalyzer::CreateNetEqLifetimeStatsGraph(
2172 const NetEqStatsGetterMap& neteq_stats,
2173 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
2174 const std::string& plot_name,
2175 Plot* plot) const {
2176 CreateNetEqStatsGraphInternal<NetEqLifetimeStatistics>(
2177 neteq_stats,
2178 [](const test::NetEqStatsGetter* stats_getter) {
2179 return stats_getter->lifetime_stats();
2180 },
2181 stats_extractor, plot_name, plot);
2182}
2183
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002184void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
2185 std::map<uint32_t, TimeSeries> configs_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002186 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002187 if (configs_by_cp_id.find(config.candidate_pair_id) ==
2188 configs_by_cp_id.end()) {
2189 const std::string candidate_pair_desc =
2190 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08002191 configs_by_cp_id[config.candidate_pair_id] =
2192 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
2193 candidate_pair_desc,
2194 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002195 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2196 candidate_pair_desc;
2197 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002198 float x = config_.GetCallTimeSec(config.log_time_us());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002199 float y = static_cast<float>(config.type);
2200 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
2201 }
2202
2203 // TODO(qingsi): There can be a large number of candidate pairs generated by
2204 // certain calls and the frontend cannot render the chart in this case due to
2205 // the failure of generating a palette with the same number of colors.
2206 for (auto& kv : configs_by_cp_id) {
2207 plot->AppendTimeSeries(std::move(kv.second));
2208 }
2209
Bjorn Terelius068fc352019-02-13 22:38:25 +01002210 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2211 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002212 plot->SetSuggestedYAxis(0, 3, "Config Type", kBottomMargin, kTopMargin);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002213 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002214 plot->SetYAxisTickLabels(
2215 {{static_cast<float>(IceCandidatePairConfigType::kAdded), "ADDED"},
2216 {static_cast<float>(IceCandidatePairConfigType::kUpdated), "UPDATED"},
2217 {static_cast<float>(IceCandidatePairConfigType::kDestroyed),
2218 "DESTROYED"},
2219 {static_cast<float>(IceCandidatePairConfigType::kSelected),
2220 "SELECTED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002221}
2222
2223std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
2224 uint32_t candidate_pair_id) {
2225 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
2226 candidate_pair_desc_by_id_.end()) {
2227 return candidate_pair_desc_by_id_[candidate_pair_id];
2228 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002229 for (const auto& config : parsed_log_.ice_candidate_pair_configs()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002230 // TODO(qingsi): Add the handling of the "Updated" config event after the
2231 // visualization of property change for candidate pairs is introduced.
2232 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
2233 candidate_pair_desc_by_id_.end()) {
2234 const std::string candidate_pair_desc =
2235 GetCandidatePairLogDescriptionAsString(config);
2236 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2237 candidate_pair_desc;
2238 }
2239 }
2240 return candidate_pair_desc_by_id_[candidate_pair_id];
2241}
2242
2243void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002244 constexpr int kEventTypeOffset =
2245 static_cast<int>(IceCandidatePairConfigType::kNumValues);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002246 std::map<uint32_t, TimeSeries> checks_by_cp_id;
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +02002247 for (const auto& event : parsed_log_.ice_candidate_pair_events()) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002248 if (checks_by_cp_id.find(event.candidate_pair_id) ==
2249 checks_by_cp_id.end()) {
2250 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08002251 "[" + std::to_string(event.candidate_pair_id) + "]" +
2252 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002253 LineStyle::kNone, PointStyle::kHighlight);
2254 }
Bjorn Terelius068fc352019-02-13 22:38:25 +01002255 float x = config_.GetCallTimeSec(event.log_time_us());
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002256 float y = static_cast<float>(event.type) + kEventTypeOffset;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002257 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
2258 }
2259
2260 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
2261 for (auto& kv : checks_by_cp_id) {
2262 plot->AppendTimeSeries(std::move(kv.second));
2263 }
2264
Bjorn Terelius068fc352019-02-13 22:38:25 +01002265 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2266 "Time (s)", kLeftMargin, kRightMargin);
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002267 plot->SetSuggestedYAxis(0, 4, "Connectivity State", kBottomMargin,
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002268 kTopMargin);
2269 plot->SetTitle("[IceEventLog] ICE connectivity checks");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002270
2271 plot->SetYAxisTickLabels(
2272 {{static_cast<float>(IceCandidatePairEventType::kCheckSent) +
2273 kEventTypeOffset,
2274 "CHECK SENT"},
2275 {static_cast<float>(IceCandidatePairEventType::kCheckReceived) +
2276 kEventTypeOffset,
2277 "CHECK RECEIVED"},
2278 {static_cast<float>(IceCandidatePairEventType::kCheckResponseSent) +
2279 kEventTypeOffset,
2280 "RESPONSE SENT"},
2281 {static_cast<float>(IceCandidatePairEventType::kCheckResponseReceived) +
2282 kEventTypeOffset,
2283 "RESPONSE RECEIVED"}});
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002284}
2285
Zach Stein10a58012018-12-07 12:26:28 -08002286void EventLogAnalyzer::CreateDtlsTransportStateGraph(Plot* plot) {
2287 TimeSeries states("DTLS Transport State", LineStyle::kNone,
2288 PointStyle::kHighlight);
2289 for (const auto& event : parsed_log_.dtls_transport_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002290 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002291 float y = static_cast<float>(event.dtls_transport_state);
2292 states.points.emplace_back(x, y);
2293 }
2294 plot->AppendTimeSeries(std::move(states));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002295 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2296 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002297 plot->SetSuggestedYAxis(0, static_cast<float>(DtlsTransportState::kNumValues),
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002298 "Transport State", kBottomMargin, kTopMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002299 plot->SetTitle("DTLS Transport State");
Bjorn Tereliusf640b872019-07-24 15:46:39 +02002300 plot->SetYAxisTickLabels(
2301 {{static_cast<float>(DtlsTransportState::kNew), "NEW"},
2302 {static_cast<float>(DtlsTransportState::kConnecting), "CONNECTING"},
2303 {static_cast<float>(DtlsTransportState::kConnected), "CONNECTED"},
2304 {static_cast<float>(DtlsTransportState::kClosed), "CLOSED"},
2305 {static_cast<float>(DtlsTransportState::kFailed), "FAILED"}});
Zach Stein10a58012018-12-07 12:26:28 -08002306}
2307
2308void EventLogAnalyzer::CreateDtlsWritableStateGraph(Plot* plot) {
2309 TimeSeries writable("DTLS Writable", LineStyle::kNone,
2310 PointStyle::kHighlight);
2311 for (const auto& event : parsed_log_.dtls_writable_states()) {
Bjorn Terelius068fc352019-02-13 22:38:25 +01002312 float x = config_.GetCallTimeSec(event.log_time_us());
Zach Stein10a58012018-12-07 12:26:28 -08002313 float y = static_cast<float>(event.writable);
2314 writable.points.emplace_back(x, y);
2315 }
2316 plot->AppendTimeSeries(std::move(writable));
Bjorn Terelius068fc352019-02-13 22:38:25 +01002317 plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
2318 "Time (s)", kLeftMargin, kRightMargin);
Zach Stein10a58012018-12-07 12:26:28 -08002319 plot->SetSuggestedYAxis(0, 1, "Writable", kBottomMargin, kTopMargin);
2320 plot->SetTitle("DTLS Writable State");
2321}
2322
terelius54ce6802016-07-13 06:44:41 -07002323} // namespace webrtc