blob: 3c6a074a0d8d859bfe12ce726965322cd968d1a5 [file] [log] [blame]
terelius54ce6802016-07-13 06:44:41 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_tools/event_log_visualizer/analyzer.h"
terelius54ce6802016-07-13 06:44:41 -070012
13#include <algorithm>
Oleh Prypin6581f212017-11-16 00:17:05 +010014#include <cmath>
terelius54ce6802016-07-13 06:44:41 -070015#include <limits>
16#include <map>
17#include <sstream>
18#include <string>
19#include <utility>
20
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "call/audio_receive_stream.h"
22#include "call/audio_send_stream.h"
23#include "call/call.h"
24#include "call/video_receive_stream.h"
25#include "call/video_send_stream.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020026#include "common_types.h" // NOLINT(build/include)
Elad Alon99a81b62017-09-21 10:25:29 +020027#include "logging/rtc_event_log/rtc_stream_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "modules/audio_coding/neteq/tools/audio_sink.h"
29#include "modules/audio_coding/neteq/tools/fake_decode_from_file.h"
30#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
31#include "modules/audio_coding/neteq/tools/neteq_replacement_input.h"
32#include "modules/audio_coding/neteq/tools/neteq_test.h"
33#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
Bjorn Terelius6984ad22017-10-24 12:19:45 +020034#include "modules/congestion_controller/acknowledged_bitrate_estimator.h"
35#include "modules/congestion_controller/bitrate_estimator.h"
Bjorn Terelius28db2662017-10-04 14:22:43 +020036#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "modules/congestion_controller/include/send_side_congestion_controller.h"
38#include "modules/include/module_common_types.h"
Niels Möllerfd6c0912017-10-31 10:19:10 +010039#include "modules/pacing/packet_router.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020040#include "modules/rtp_rtcp/include/rtp_rtcp.h"
41#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
42#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
43#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
44#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
45#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
46#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
47#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
48#include "modules/rtp_rtcp/source/rtp_utility.h"
49#include "rtc_base/checks.h"
50#include "rtc_base/format_macros.h"
51#include "rtc_base/logging.h"
Bjorn Terelius0295a962017-10-25 17:42:41 +020052#include "rtc_base/numerics/sequence_number_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020053#include "rtc_base/ptr_util.h"
54#include "rtc_base/rate_statistics.h"
terelius54ce6802016-07-13 06:44:41 -070055
Bjorn Terelius6984ad22017-10-24 12:19:45 +020056#ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
57#define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0
58#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
59
tereliusdc35dcd2016-08-01 12:03:27 -070060namespace webrtc {
61namespace plotting {
62
terelius54ce6802016-07-13 06:44:41 -070063namespace {
64
elad.alonec304f92017-03-08 05:03:53 -080065void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
66 auto pred = [](const PacketFeedback& packet_feedback) {
67 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
68 };
69 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
70 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
71}
72
terelius54ce6802016-07-13 06:44:41 -070073std::string SsrcToString(uint32_t ssrc) {
74 std::stringstream ss;
75 ss << "SSRC " << ssrc;
76 return ss.str();
77}
78
79// Checks whether an SSRC is contained in the list of desired SSRCs.
80// Note that an empty SSRC list matches every SSRC.
81bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
82 if (desired_ssrc.size() == 0)
83 return true;
84 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
85 desired_ssrc.end();
86}
87
88double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
89 // The timestamp is a fixed point representation with 6 bits for seconds
90 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
91 // time in seconds and then multiply by 1000000 to convert to microseconds.
92 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070093 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070094 return abs_send_time * kTimestampToMicroSec;
95}
96
97// Computes the difference |later| - |earlier| where |later| and |earlier|
98// are counters that wrap at |modulus|. The difference is chosen to have the
99// least absolute value. For example if |modulus| is 8, then the difference will
100// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
101// be in [-4, 4].
102int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
103 RTC_DCHECK_LE(1, modulus);
104 RTC_DCHECK_LT(later, modulus);
105 RTC_DCHECK_LT(earlier, modulus);
106 int64_t difference =
107 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
108 int64_t max_difference = modulus / 2;
109 int64_t min_difference = max_difference - modulus + 1;
110 if (difference > max_difference) {
111 difference -= modulus;
112 }
113 if (difference < min_difference) {
114 difference += modulus;
115 }
terelius6addf492016-08-23 17:34:07 -0700116 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100117 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
118 << " expected to be in the range ("
119 << min_difference / 2 << "," << max_difference / 2
120 << ") but is " << difference
121 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700122 }
terelius54ce6802016-07-13 06:44:41 -0700123 return difference;
124}
125
ivocaac9d6f2016-09-22 07:01:47 -0700126// Return default values for header extensions, to use on streams without stored
127// mapping data. Currently this only applies to audio streams, since the mapping
128// is not stored in the event log.
129// TODO(ivoc): Remove this once this mapping is stored in the event log for
130// audio streams. Tracking bug: webrtc:6399
131webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
132 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800133 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
terelius007d5622017-08-08 05:40:26 -0700134 default_map.Register<TransmissionOffset>(
135 webrtc::RtpExtension::kTimestampOffsetDefaultId);
danilchap4aecc582016-11-15 09:21:00 -0800136 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700137 webrtc::RtpExtension::kAbsSendTimeDefaultId);
terelius007d5622017-08-08 05:40:26 -0700138 default_map.Register<VideoOrientation>(
139 webrtc::RtpExtension::kVideoRotationDefaultId);
140 default_map.Register<VideoContentTypeExtension>(
141 webrtc::RtpExtension::kVideoContentTypeDefaultId);
142 default_map.Register<VideoTimingExtension>(
143 webrtc::RtpExtension::kVideoTimingDefaultId);
144 default_map.Register<TransportSequenceNumber>(
145 webrtc::RtpExtension::kTransportSequenceNumberDefaultId);
146 default_map.Register<PlayoutDelayLimits>(
147 webrtc::RtpExtension::kPlayoutDelayDefaultId);
ivocaac9d6f2016-09-22 07:01:47 -0700148 return default_map;
149}
150
tereliusdc35dcd2016-08-01 12:03:27 -0700151constexpr float kLeftMargin = 0.01f;
152constexpr float kRightMargin = 0.02f;
153constexpr float kBottomMargin = 0.02f;
154constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700155
terelius53dc23c2017-03-13 05:24:05 -0700156rtc::Optional<double> NetworkDelayDiff_AbsSendTime(
157 const LoggedRtpPacket& old_packet,
158 const LoggedRtpPacket& new_packet) {
159 if (old_packet.header.extension.hasAbsoluteSendTime &&
160 new_packet.header.extension.hasAbsoluteSendTime) {
161 int64_t send_time_diff = WrappingDifference(
162 new_packet.header.extension.absoluteSendTime,
163 old_packet.header.extension.absoluteSendTime, 1ul << 24);
164 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
165 double delay_change_us =
166 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100167 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700168 } else {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100169 return rtc::nullopt;
terelius6addf492016-08-23 17:34:07 -0700170 }
171}
172
terelius53dc23c2017-03-13 05:24:05 -0700173rtc::Optional<double> NetworkDelayDiff_CaptureTime(
174 const LoggedRtpPacket& old_packet,
175 const LoggedRtpPacket& new_packet) {
176 int64_t send_time_diff = WrappingDifference(
177 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
178 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
179
180 const double kVideoSampleRate = 90000;
181 // TODO(terelius): We treat all streams as video for now, even though
182 // audio might be sampled at e.g. 16kHz, because it is really difficult to
183 // figure out the true sampling rate of a stream. The effect is that the
184 // delay will be scaled incorrectly for non-video streams.
185
186 double delay_change =
187 static_cast<double>(recv_time_diff) / 1000 -
188 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
189 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100190 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
191 RTC_LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
192 << ", received time " << old_packet.timestamp;
193 RTC_LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
194 << ", received time " << new_packet.timestamp;
195 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
196 << static_cast<double>(recv_time_diff) / 1000000 << "s";
197 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
198 << static_cast<double>(send_time_diff) /
199 kVideoSampleRate
200 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700201 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100202 return delay_change;
terelius53dc23c2017-03-13 05:24:05 -0700203}
204
205// For each element in data, use |get_y()| to extract a y-coordinate and
206// store the result in a TimeSeries.
207template <typename DataType>
208void ProcessPoints(
209 rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y,
210 const std::vector<DataType>& data,
211 uint64_t begin_time,
212 TimeSeries* result) {
213 for (size_t i = 0; i < data.size(); i++) {
214 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
215 rtc::Optional<float> y = get_y(data[i]);
216 if (y)
217 result->points.emplace_back(x, *y);
218 }
219}
220
221// For each pair of adjacent elements in |data|, use |get_y| to extract a
terelius6addf492016-08-23 17:34:07 -0700222// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
223// will be the time of the second element in the pair.
terelius53dc23c2017-03-13 05:24:05 -0700224template <typename DataType, typename ResultType>
225void ProcessPairs(
226 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
227 const DataType&)> get_y,
228 const std::vector<DataType>& data,
229 uint64_t begin_time,
230 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700231 for (size_t i = 1; i < data.size(); i++) {
232 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700233 rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]);
234 if (y)
235 result->points.emplace_back(x, static_cast<float>(*y));
236 }
237}
238
239// For each element in data, use |extract()| to extract a y-coordinate and
240// store the result in a TimeSeries.
241template <typename DataType, typename ResultType>
242void AccumulatePoints(
243 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
244 const std::vector<DataType>& data,
245 uint64_t begin_time,
246 TimeSeries* result) {
247 ResultType sum = 0;
248 for (size_t i = 0; i < data.size(); i++) {
249 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
250 rtc::Optional<ResultType> y = extract(data[i]);
251 if (y) {
252 sum += *y;
253 result->points.emplace_back(x, static_cast<float>(sum));
254 }
255 }
256}
257
258// For each pair of adjacent elements in |data|, use |extract()| to extract a
259// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
260// will be the time of the second element in the pair.
261template <typename DataType, typename ResultType>
262void AccumulatePairs(
263 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
264 const DataType&)> extract,
265 const std::vector<DataType>& data,
266 uint64_t begin_time,
267 TimeSeries* result) {
268 ResultType sum = 0;
269 for (size_t i = 1; i < data.size(); i++) {
270 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
271 rtc::Optional<ResultType> y = extract(data[i - 1], data[i]);
272 if (y)
273 sum += *y;
274 result->points.emplace_back(x, static_cast<float>(sum));
tereliusccbbf8d2016-08-10 07:34:28 -0700275 }
276}
277
terelius6addf492016-08-23 17:34:07 -0700278// Calculates a moving average of |data| and stores the result in a TimeSeries.
279// A data point is generated every |step| microseconds from |begin_time|
280// to |end_time|. The value of each data point is the average of the data
281// during the preceeding |window_duration_us| microseconds.
terelius53dc23c2017-03-13 05:24:05 -0700282template <typename DataType, typename ResultType>
283void MovingAverage(
284 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
285 const std::vector<DataType>& data,
286 uint64_t begin_time,
287 uint64_t end_time,
288 uint64_t window_duration_us,
289 uint64_t step,
290 webrtc::plotting::TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700291 size_t window_index_begin = 0;
292 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700293 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700294
295 for (uint64_t t = begin_time; t < end_time + step; t += step) {
296 while (window_index_end < data.size() &&
297 data[window_index_end].timestamp < t) {
terelius53dc23c2017-03-13 05:24:05 -0700298 rtc::Optional<ResultType> value = extract(data[window_index_end]);
299 if (value)
300 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700301 ++window_index_end;
302 }
303 while (window_index_begin < data.size() &&
304 data[window_index_begin].timestamp < t - window_duration_us) {
terelius53dc23c2017-03-13 05:24:05 -0700305 rtc::Optional<ResultType> value = extract(data[window_index_begin]);
306 if (value)
307 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700308 ++window_index_begin;
309 }
310 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
311 float x = static_cast<float>(t - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700312 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700313 result->points.emplace_back(x, y);
314 }
315}
316
terelius54ce6802016-07-13 06:44:41 -0700317} // namespace
318
terelius54ce6802016-07-13 06:44:41 -0700319EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
320 : parsed_log_(log), window_duration_(250000), step_(10000) {
321 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
322 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700323
terelius88e64e52016-07-19 01:51:06 -0700324 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700325 uint8_t header[IP_PACKET_SIZE];
326 size_t header_length;
327 size_t total_length;
328
perkjbbbad6d2017-05-19 06:30:28 -0700329 uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE];
330 uint8_t last_incoming_rtcp_packet_length = 0;
331
ivocaac9d6f2016-09-22 07:01:47 -0700332 // Make a default extension map for streams without configuration information.
333 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
334 // this can be removed. Tracking bug: webrtc:6399
335 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
336
henrik.lundin3c938fc2017-06-14 06:09:58 -0700337 rtc::Optional<uint64_t> last_log_start;
338
terelius54ce6802016-07-13 06:44:41 -0700339 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
340 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700341 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
342 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
343 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700344 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
345 event_type != ParsedRtcEventLog::LOG_START &&
346 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700347 uint64_t timestamp = parsed_log_.GetTimestamp(i);
348 first_timestamp = std::min(first_timestamp, timestamp);
349 last_timestamp = std::max(last_timestamp, timestamp);
350 }
351
352 switch (parsed_log_.GetEventType(i)) {
353 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700354 rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i);
perkj09e71da2017-05-22 03:26:49 -0700355 StreamId stream(config.remote_ssrc, kIncomingPacket);
terelius0740a202016-08-08 10:21:04 -0700356 video_ssrcs_.insert(stream);
perkj09e71da2017-05-22 03:26:49 -0700357 StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket);
brandtr14742122017-01-27 04:53:07 -0800358 video_ssrcs_.insert(rtx_stream);
359 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700360 break;
361 }
362 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700363 std::vector<rtclog::StreamConfig> configs =
364 parsed_log_.GetVideoSendConfig(i);
terelius405f90c2017-06-01 03:50:31 -0700365 for (const auto& config : configs) {
366 StreamId stream(config.local_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700367 video_ssrcs_.insert(stream);
terelius405f90c2017-06-01 03:50:31 -0700368 StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700369 video_ssrcs_.insert(rtx_stream);
370 rtx_ssrcs_.insert(rtx_stream);
371 }
terelius88e64e52016-07-19 01:51:06 -0700372 break;
373 }
374 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700375 rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i);
perkjac8f52d2017-05-22 09:36:28 -0700376 StreamId stream(config.remote_ssrc, kIncomingPacket);
ivoce0928d82016-10-10 05:12:51 -0700377 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700378 break;
379 }
380 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700381 rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i);
perkjf4726992017-05-22 10:12:26 -0700382 StreamId stream(config.local_ssrc, kOutgoingPacket);
ivoce0928d82016-10-10 05:12:51 -0700383 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700384 break;
385 }
386 case ParsedRtcEventLog::RTP_EVENT: {
ilnika8e781a2017-06-12 01:02:46 -0700387 RtpHeaderExtensionMap* extension_map = parsed_log_.GetRtpHeader(
Elad Alon1d87b0e2017-10-03 15:01:03 +0200388 i, &direction, header, &header_length, &total_length, nullptr);
terelius88e64e52016-07-19 01:51:06 -0700389 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
390 RTPHeader parsed_header;
ilnika8e781a2017-06-12 01:02:46 -0700391 if (extension_map != nullptr) {
terelius88e64e52016-07-19 01:51:06 -0700392 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700393 } else {
394 // Use the default extension map.
395 // TODO(ivoc): Once configuration of audio streams is stored in the
396 // event log, this can be removed.
397 // Tracking bug: webrtc:6399
398 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700399 }
400 uint64_t timestamp = parsed_log_.GetTimestamp(i);
ilnika8e781a2017-06-12 01:02:46 -0700401 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700402 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200403 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700404 break;
405 }
406 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200407 uint8_t packet[IP_PACKET_SIZE];
perkj77cd58e2017-05-30 03:52:10 -0700408 parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length);
perkjbbbad6d2017-05-19 06:30:28 -0700409 // Currently incoming RTCP packets are logged twice, both for audio and
410 // video. Only act on one of them. Compare against the previous parsed
411 // incoming RTCP packet.
412 if (direction == webrtc::kIncomingPacket) {
413 RTC_CHECK_LE(total_length, IP_PACKET_SIZE);
414 if (total_length == last_incoming_rtcp_packet_length &&
415 memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) {
416 continue;
417 } else {
418 memcpy(last_incoming_rtcp_packet, packet, total_length);
419 last_incoming_rtcp_packet_length = total_length;
420 }
421 }
422 rtcp::CommonHeader header;
423 const uint8_t* packet_end = packet + total_length;
424 for (const uint8_t* block = packet; block < packet_end;
425 block = header.NextPacket()) {
426 RTC_CHECK(header.Parse(block, packet_end - block));
427 if (header.type() == rtcp::TransportFeedback::kPacketType &&
428 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
429 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700430 rtc::MakeUnique<rtcp::TransportFeedback>());
perkjbbbad6d2017-05-19 06:30:28 -0700431 if (rtcp_packet->Parse(header)) {
432 uint32_t ssrc = rtcp_packet->sender_ssrc();
433 StreamId stream(ssrc, direction);
434 uint64_t timestamp = parsed_log_.GetTimestamp(i);
435 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
436 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
437 }
438 } else if (header.type() == rtcp::SenderReport::kPacketType) {
439 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700440 rtc::MakeUnique<rtcp::SenderReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700441 if (rtcp_packet->Parse(header)) {
442 uint32_t ssrc = rtcp_packet->sender_ssrc();
443 StreamId stream(ssrc, direction);
444 uint64_t timestamp = parsed_log_.GetTimestamp(i);
445 rtcp_packets_[stream].push_back(
446 LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet)));
447 }
448 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
449 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700450 rtc::MakeUnique<rtcp::ReceiverReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700451 if (rtcp_packet->Parse(header)) {
452 uint32_t ssrc = rtcp_packet->sender_ssrc();
453 StreamId stream(ssrc, direction);
454 uint64_t timestamp = parsed_log_.GetTimestamp(i);
455 rtcp_packets_[stream].push_back(
456 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet)));
Stefan Holmer13181032016-07-29 14:48:54 +0200457 }
terelius2c8e8a32017-06-02 01:29:48 -0700458 } else if (header.type() == rtcp::Remb::kPacketType &&
459 header.fmt() == rtcp::Remb::kFeedbackMessageType) {
460 std::unique_ptr<rtcp::Remb> rtcp_packet(
461 rtc::MakeUnique<rtcp::Remb>());
462 if (rtcp_packet->Parse(header)) {
463 uint32_t ssrc = rtcp_packet->sender_ssrc();
464 StreamId stream(ssrc, direction);
465 uint64_t timestamp = parsed_log_.GetTimestamp(i);
466 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
467 timestamp, kRtcpRemb, std::move(rtcp_packet)));
468 }
Stefan Holmer13181032016-07-29 14:48:54 +0200469 }
Stefan Holmer13181032016-07-29 14:48:54 +0200470 }
terelius88e64e52016-07-19 01:51:06 -0700471 break;
472 }
473 case ParsedRtcEventLog::LOG_START: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700474 if (last_log_start) {
475 // A LOG_END event was missing. Use last_timestamp.
476 RTC_DCHECK_GE(last_timestamp, *last_log_start);
477 log_segments_.push_back(
478 std::make_pair(*last_log_start, last_timestamp));
479 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100480 last_log_start = parsed_log_.GetTimestamp(i);
terelius88e64e52016-07-19 01:51:06 -0700481 break;
482 }
483 case ParsedRtcEventLog::LOG_END: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700484 RTC_DCHECK(last_log_start);
485 log_segments_.push_back(
486 std::make_pair(*last_log_start, parsed_log_.GetTimestamp(i)));
487 last_log_start.reset();
terelius88e64e52016-07-19 01:51:06 -0700488 break;
489 }
terelius424e6cf2017-02-20 05:14:41 -0800490 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700491 uint32_t this_ssrc;
492 parsed_log_.GetAudioPlayout(i, &this_ssrc);
493 audio_playout_events_[this_ssrc].push_back(parsed_log_.GetTimestamp(i));
terelius424e6cf2017-02-20 05:14:41 -0800494 break;
495 }
496 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
497 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700498 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800499 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
500 &bwe_update.fraction_loss,
501 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700502 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700503 break;
504 }
terelius424e6cf2017-02-20 05:14:41 -0800505 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
philipel10fc0e62017-04-11 01:50:23 -0700506 bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i));
terelius424e6cf2017-02-20 05:14:41 -0800507 break;
508 }
minyue4b7c9522017-01-24 04:54:59 -0800509 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800510 AudioNetworkAdaptationEvent ana_event;
511 ana_event.timestamp = parsed_log_.GetTimestamp(i);
512 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
513 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800514 break;
515 }
philipel32d00102017-02-27 02:18:46 -0800516 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200517 bwe_probe_cluster_created_events_.push_back(
518 parsed_log_.GetBweProbeClusterCreated(i));
philipel32d00102017-02-27 02:18:46 -0800519 break;
520 }
521 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200522 bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i));
philipel32d00102017-02-27 02:18:46 -0800523 break;
524 }
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100525 case ParsedRtcEventLog::ALR_STATE_EVENT: {
526 alr_state_events_.push_back(parsed_log_.GetAlrState(i));
527 break;
528 }
terelius88e64e52016-07-19 01:51:06 -0700529 case ParsedRtcEventLog::UNKNOWN_EVENT: {
530 break;
531 }
532 }
terelius54ce6802016-07-13 06:44:41 -0700533 }
terelius88e64e52016-07-19 01:51:06 -0700534
terelius54ce6802016-07-13 06:44:41 -0700535 if (last_timestamp < first_timestamp) {
536 // No useful events in the log.
537 first_timestamp = last_timestamp = 0;
538 }
539 begin_time_ = first_timestamp;
540 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700541 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700542 if (last_log_start) {
543 // The log was missing the last LOG_END event. Fake it.
544 log_segments_.push_back(std::make_pair(*last_log_start, end_time_));
545 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100546 RTC_LOG(LS_INFO) << "Found " << log_segments_.size()
547 << " (LOG_START, LOG_END) segments in log.";
terelius54ce6802016-07-13 06:44:41 -0700548}
549
Niels Möller245f17e2017-08-21 10:45:07 +0200550class BitrateObserver : public SendSideCongestionController::Observer,
Stefan Holmer13181032016-07-29 14:48:54 +0200551 public RemoteBitrateObserver {
552 public:
553 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
554
555 void OnNetworkChanged(uint32_t bitrate_bps,
556 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800557 int64_t rtt_ms,
558 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200559 last_bitrate_bps_ = bitrate_bps;
560 bitrate_updated_ = true;
561 }
562
563 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
564 uint32_t bitrate) override {}
565
566 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
567 bool GetAndResetBitrateUpdated() {
568 bool bitrate_updated = bitrate_updated_;
569 bitrate_updated_ = false;
570 return bitrate_updated;
571 }
572
573 private:
574 uint32_t last_bitrate_bps_;
575 bool bitrate_updated_;
576};
577
Stefan Holmer99f8e082016-09-09 13:37:50 +0200578bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700579 return rtx_ssrcs_.count(stream_id) == 1;
580}
581
Stefan Holmer99f8e082016-09-09 13:37:50 +0200582bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700583 return video_ssrcs_.count(stream_id) == 1;
584}
585
Stefan Holmer99f8e082016-09-09 13:37:50 +0200586bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700587 return audio_ssrcs_.count(stream_id) == 1;
588}
589
Stefan Holmer99f8e082016-09-09 13:37:50 +0200590std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
591 std::stringstream name;
592 if (IsAudioSsrc(stream_id)) {
593 name << "Audio ";
594 } else if (IsVideoSsrc(stream_id)) {
595 name << "Video ";
596 } else {
597 name << "Unknown ";
598 }
599 if (IsRtxSsrc(stream_id))
600 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700601 if (stream_id.GetDirection() == kIncomingPacket) {
602 name << "(In) ";
603 } else {
604 name << "(Out) ";
605 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200606 name << SsrcToString(stream_id.GetSsrc());
607 return name.str();
608}
609
Bjorn Terelius0295a962017-10-25 17:42:41 +0200610// This is much more reliable for outgoing streams than for incoming streams.
611rtc::Optional<uint32_t> EventLogAnalyzer::EstimateRtpClockFrequency(
612 const std::vector<LoggedRtpPacket>& packets) const {
613 RTC_CHECK(packets.size() >= 2);
614 uint64_t end_time_us = log_segments_.empty()
615 ? std::numeric_limits<uint64_t>::max()
616 : log_segments_.front().second;
617 SeqNumUnwrapper<uint32_t> unwrapper;
618 uint64_t first_rtp_timestamp = unwrapper.Unwrap(packets[0].header.timestamp);
619 uint64_t first_log_timestamp = packets[0].timestamp;
620 uint64_t last_rtp_timestamp = first_rtp_timestamp;
621 uint64_t last_log_timestamp = first_log_timestamp;
622 for (size_t i = 1; i < packets.size(); i++) {
623 if (packets[i].timestamp > end_time_us)
624 break;
625 last_rtp_timestamp = unwrapper.Unwrap(packets[i].header.timestamp);
626 last_log_timestamp = packets[i].timestamp;
627 }
628 if (last_log_timestamp - first_log_timestamp < 1000000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100629 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +0200630 << "Failed to estimate RTP clock frequency: Stream too short. ("
631 << packets.size() << " packets, "
632 << last_log_timestamp - first_log_timestamp << " us)";
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100633 return rtc::nullopt;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200634 }
635 double duration =
636 static_cast<double>(last_log_timestamp - first_log_timestamp) / 1000000;
637 double estimated_frequency =
638 (last_rtp_timestamp - first_rtp_timestamp) / duration;
639 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
640 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100641 return f;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200642 }
643 }
Mirko Bonadei675513b2017-11-09 11:09:25 +0100644 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
645 << estimated_frequency
646 << "not close to any stardard RTP frequency.";
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100647 return rtc::nullopt;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200648}
649
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100650float EventLogAnalyzer::ToCallTime(int64_t timestamp) const {
651 return static_cast<float>(timestamp - begin_time_) / 1000000;
652}
653
terelius54ce6802016-07-13 06:44:41 -0700654void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
655 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700656 for (auto& kv : rtp_packets_) {
657 StreamId stream_id = kv.first;
658 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
659 // Filter on direction and SSRC.
660 if (stream_id.GetDirection() != desired_direction ||
661 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
662 continue;
terelius54ce6802016-07-13 06:44:41 -0700663 }
terelius54ce6802016-07-13 06:44:41 -0700664
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100665 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700666 ProcessPoints<LoggedRtpPacket>(
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100667 [](const LoggedRtpPacket& packet) {
terelius53dc23c2017-03-13 05:24:05 -0700668 return rtc::Optional<float>(packet.total_length);
669 },
670 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700671 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700672 }
673
tereliusdc35dcd2016-08-01 12:03:27 -0700674 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
675 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
676 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700677 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700678 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700679 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700680 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700681 }
682}
683
philipelccd74892016-09-05 02:46:25 -0700684template <typename T>
685void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
686 PacketDirection desired_direction,
687 Plot* plot,
688 const std::map<StreamId, std::vector<T>>& packets,
689 const std::string& label_prefix) {
690 for (auto& kv : packets) {
691 StreamId stream_id = kv.first;
692 const std::vector<T>& packet_stream = kv.second;
693 // Filter on direction and SSRC.
694 if (stream_id.GetDirection() != desired_direction ||
695 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
696 continue;
697 }
698
terelius23c595a2017-03-15 01:59:12 -0700699 std::string label = label_prefix + " " + GetStreamName(stream_id);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100700 TimeSeries time_series(label, LineStyle::kStep);
philipelccd74892016-09-05 02:46:25 -0700701 for (size_t i = 0; i < packet_stream.size(); i++) {
702 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
703 1000000;
philipelccd74892016-09-05 02:46:25 -0700704 time_series.points.emplace_back(x, i + 1);
705 }
706
philipel35ba9bd2017-04-19 05:58:51 -0700707 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700708 }
709}
710
711void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
712 PacketDirection desired_direction,
713 Plot* plot) {
714 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
715 "RTP");
716 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
717 "RTCP");
718
719 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
720 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
721 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
722 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
723 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
724 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
725 }
726}
727
terelius54ce6802016-07-13 06:44:41 -0700728// For each SSRC, plot the time between the consecutive playouts.
729void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
730 std::map<uint32_t, TimeSeries> time_series;
731 std::map<uint32_t, uint64_t> last_playout;
732
733 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700734
735 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
736 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
737 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
738 parsed_log_.GetAudioPlayout(i, &ssrc);
739 uint64_t timestamp = parsed_log_.GetTimestamp(i);
740 if (MatchingSsrc(ssrc, desired_ssrc_)) {
741 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
742 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
743 if (time_series[ssrc].points.size() == 0) {
744 // There were no previusly logged playout for this SSRC.
745 // Generate a point, but place it on the x-axis.
746 y = 0;
747 }
terelius54ce6802016-07-13 06:44:41 -0700748 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
749 last_playout[ssrc] = timestamp;
750 }
751 }
752 }
753
754 // Set labels and put in graph.
755 for (auto& kv : time_series) {
756 kv.second.label = SsrcToString(kv.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100757 kv.second.line_style = LineStyle::kBar;
philipel35ba9bd2017-04-19 05:58:51 -0700758 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700759 }
760
tereliusdc35dcd2016-08-01 12:03:27 -0700761 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
762 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
763 kTopMargin);
764 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700765}
766
ivocaac9d6f2016-09-22 07:01:47 -0700767// For audio SSRCs, plot the audio level.
768void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
769 std::map<StreamId, TimeSeries> time_series;
770
771 for (auto& kv : rtp_packets_) {
772 StreamId stream_id = kv.first;
773 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
774 // TODO(ivoc): When audio send/receive configs are stored in the event
775 // log, a check should be added here to only process audio
776 // streams. Tracking bug: webrtc:6399
777 for (auto& packet : packet_stream) {
778 if (packet.header.extension.hasAudioLevel) {
779 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
780 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
781 // Here we convert it to dBov.
782 float y = static_cast<float>(-packet.header.extension.audioLevel);
783 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
784 }
785 }
786 }
787
788 for (auto& series : time_series) {
789 series.second.label = GetStreamName(series.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100790 series.second.line_style = LineStyle::kLine;
philipel35ba9bd2017-04-19 05:58:51 -0700791 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700792 }
793
794 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800795 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700796 kTopMargin);
797 plot->SetTitle("Audio level");
798}
799
terelius54ce6802016-07-13 06:44:41 -0700800// For each SSRC, plot the time between the consecutive playouts.
801void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700802 for (auto& kv : rtp_packets_) {
803 StreamId stream_id = kv.first;
804 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
805 // Filter on direction and SSRC.
806 if (stream_id.GetDirection() != kIncomingPacket ||
807 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
808 continue;
terelius54ce6802016-07-13 06:44:41 -0700809 }
terelius54ce6802016-07-13 06:44:41 -0700810
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100811 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700812 ProcessPairs<LoggedRtpPacket, float>(
813 [](const LoggedRtpPacket& old_packet,
814 const LoggedRtpPacket& new_packet) {
815 int64_t diff =
816 WrappingDifference(new_packet.header.sequenceNumber,
817 old_packet.header.sequenceNumber, 1ul << 16);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100818 return diff;
terelius53dc23c2017-03-13 05:24:05 -0700819 },
820 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700821 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700822 }
823
tereliusdc35dcd2016-08-01 12:03:27 -0700824 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
825 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
826 kTopMargin);
827 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700828}
829
Stefan Holmer99f8e082016-09-09 13:37:50 +0200830void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
831 for (auto& kv : rtp_packets_) {
832 StreamId stream_id = kv.first;
833 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
834 // Filter on direction and SSRC.
835 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800836 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
837 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200838 continue;
839 }
840
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100841 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine,
842 PointStyle::kHighlight);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200843 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800844 const uint64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100845 SeqNumUnwrapper<uint16_t> unwrapper_;
846 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800847 size_t window_index_begin = 0;
848 size_t window_index_end = 0;
849 int64_t highest_seq_number =
850 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
851 int64_t highest_prior_seq_number =
852 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
853
854 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
855 while (window_index_end < packet_stream.size() &&
856 packet_stream[window_index_end].timestamp < t) {
857 int64_t sequence_number = unwrapper_.Unwrap(
858 packet_stream[window_index_end].header.sequenceNumber);
859 highest_seq_number = std::max(highest_seq_number, sequence_number);
860 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200861 }
terelius4c9b4af2017-01-30 08:44:51 -0800862 while (window_index_begin < packet_stream.size() &&
863 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
864 int64_t sequence_number = prior_unwrapper_.Unwrap(
865 packet_stream[window_index_begin].header.sequenceNumber);
866 highest_prior_seq_number =
867 std::max(highest_prior_seq_number, sequence_number);
868 ++window_index_begin;
869 }
870 float x = static_cast<float>(t - begin_time_) / 1000000;
871 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
872 if (expected_packets > 0) {
873 int64_t received_packets = window_index_end - window_index_begin;
874 int64_t lost_packets = expected_packets - received_packets;
875 float y = static_cast<float>(lost_packets) / expected_packets * 100;
876 time_series.points.emplace_back(x, y);
877 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200878 }
philipel35ba9bd2017-04-19 05:58:51 -0700879 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200880 }
881
882 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
883 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
884 kTopMargin);
885 plot->SetTitle("Estimated incoming loss rate");
886}
887
terelius2ee076d2017-08-15 02:04:02 -0700888void EventLogAnalyzer::CreateIncomingDelayDeltaGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700889 for (auto& kv : rtp_packets_) {
890 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700891 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700892 // Filter on direction and SSRC.
893 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200894 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
895 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
896 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700897 continue;
898 }
terelius54ce6802016-07-13 06:44:41 -0700899
terelius23c595a2017-03-15 01:59:12 -0700900 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100901 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700902 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
903 packet_stream, begin_time_,
904 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700905 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700906
terelius23c595a2017-03-15 01:59:12 -0700907 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100908 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700909 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
910 packet_stream, begin_time_,
911 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700912 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700913 }
914
tereliusdc35dcd2016-08-01 12:03:27 -0700915 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
916 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
917 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700918 plot->SetTitle("Network latency difference between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700919}
920
terelius2ee076d2017-08-15 02:04:02 -0700921void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700922 for (auto& kv : rtp_packets_) {
923 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700924 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700925 // Filter on direction and SSRC.
926 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200927 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
928 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
929 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700930 continue;
931 }
terelius54ce6802016-07-13 06:44:41 -0700932
terelius23c595a2017-03-15 01:59:12 -0700933 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100934 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -0700935 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
936 packet_stream, begin_time_,
937 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700938 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700939
terelius23c595a2017-03-15 01:59:12 -0700940 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100941 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -0700942 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
943 packet_stream, begin_time_,
944 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700945 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700946 }
947
tereliusdc35dcd2016-08-01 12:03:27 -0700948 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
949 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
950 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700951 plot->SetTitle("Network latency (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700952}
953
tereliusf736d232016-08-04 10:00:11 -0700954// Plot the fraction of packets lost (as perceived by the loss-based BWE).
955void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100956 TimeSeries time_series("Fraction lost", LineStyle::kLine,
957 PointStyle::kHighlight);
tereliusf736d232016-08-04 10:00:11 -0700958 for (auto& bwe_update : bwe_loss_updates_) {
959 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
960 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700961 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700962 }
tereliusf736d232016-08-04 10:00:11 -0700963
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200964 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700965 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
966 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
967 kTopMargin);
968 plot->SetTitle("Reported packet loss");
969}
970
terelius54ce6802016-07-13 06:44:41 -0700971// Plot the total bandwidth used by all RTP streams.
972void EventLogAnalyzer::CreateTotalBitrateGraph(
973 PacketDirection desired_direction,
philipel23c7f252017-07-14 06:30:03 -0700974 Plot* plot,
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100975 bool show_detector_state,
976 bool show_alr_state) {
terelius54ce6802016-07-13 06:44:41 -0700977 struct TimestampSize {
978 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
979 uint64_t timestamp;
980 size_t size;
981 };
982 std::vector<TimestampSize> packets;
983
984 PacketDirection direction;
985 size_t total_length;
986
987 // Extract timestamps and sizes for the relevant packets.
988 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
989 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
990 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
Elad Alon1d87b0e2017-10-03 15:01:03 +0200991 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length,
992 nullptr);
terelius54ce6802016-07-13 06:44:41 -0700993 if (direction == desired_direction) {
994 uint64_t timestamp = parsed_log_.GetTimestamp(i);
995 packets.push_back(TimestampSize(timestamp, total_length));
996 }
997 }
998 }
999
1000 size_t window_index_begin = 0;
1001 size_t window_index_end = 0;
1002 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -07001003
1004 // Calculate a moving average of the bitrate and store in a TimeSeries.
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001005 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
terelius54ce6802016-07-13 06:44:41 -07001006 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
1007 while (window_index_end < packets.size() &&
1008 packets[window_index_end].timestamp < time) {
1009 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -07001010 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -07001011 }
1012 while (window_index_begin < packets.size() &&
1013 packets[window_index_begin].timestamp < time - window_duration_) {
1014 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
1015 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -07001016 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -07001017 }
1018 float window_duration_in_seconds =
1019 static_cast<float>(window_duration_) / 1000000;
1020 float x = static_cast<float>(time - begin_time_) / 1000000;
1021 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001022 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -07001023 }
philipel35ba9bd2017-04-19 05:58:51 -07001024 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -07001025
terelius8058e582016-07-25 01:32:41 -07001026 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
1027 if (desired_direction == kOutgoingPacket) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001028 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
philipel10fc0e62017-04-11 01:50:23 -07001029 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -07001030 float x =
philipel10fc0e62017-04-11 01:50:23 -07001031 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
1032 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001033 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -07001034 }
1035
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001036 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
philipel23c7f252017-07-14 06:30:03 -07001037 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;
1045
1046 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
1047
philipel10fc0e62017-04-11 01:50:23 -07001048 for (auto& delay_update : bwe_delay_updates_) {
1049 float x =
1050 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
1051 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -07001052
1053 if (last_detector_state != delay_update.detector_state) {
1054 last_series->intervals.emplace_back(last_detector_switch, x);
1055 last_detector_state = delay_update.detector_state;
1056 last_detector_switch = x;
1057
1058 switch (delay_update.detector_state) {
1059 case BandwidthUsage::kBwNormal:
1060 last_series = &normal_series;
1061 break;
1062 case BandwidthUsage::kBwUnderusing:
1063 last_series = &underusing_series;
1064 break;
1065 case BandwidthUsage::kBwOverusing:
1066 last_series = &overusing_series;
1067 break;
Elad Alon1d87b0e2017-10-03 15:01:03 +02001068 case BandwidthUsage::kLast:
1069 RTC_NOTREACHED();
philipel23c7f252017-07-14 06:30:03 -07001070 }
1071 }
1072
philipel35ba9bd2017-04-19 05:58:51 -07001073 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -07001074 }
philipele127e7a2017-03-29 16:28:53 +02001075
philipel23c7f252017-07-14 06:30:03 -07001076 RTC_CHECK(last_series);
1077 last_series->intervals.emplace_back(last_detector_switch, end_time_);
1078
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001079 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
1080 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001081 for (auto& cluster : bwe_probe_cluster_created_events_) {
1082 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
1083 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001084 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001085 }
1086
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001087 TimeSeries result_series("Probing results.", LineStyle::kNone,
1088 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001089 for (auto& result : bwe_probe_result_events_) {
1090 if (result.bitrate_bps) {
1091 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
1092 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001093 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001094 }
1095 }
philipel23c7f252017-07-14 06:30:03 -07001096
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001097 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
1098 bool previously_in_alr = false;
1099 int64_t alr_start = 0;
1100 for (auto& alr : alr_state_events_) {
1101 float y = ToCallTime(alr.timestamp);
1102 if (!previously_in_alr && alr.in_alr) {
1103 alr_start = alr.timestamp;
1104 previously_in_alr = true;
1105 } else if (previously_in_alr && !alr.in_alr) {
1106 float x = ToCallTime(alr_start);
1107 alr_state.intervals.emplace_back(x, y);
1108 previously_in_alr = false;
1109 }
1110 }
1111
1112 if (previously_in_alr) {
1113 float x = ToCallTime(alr_start);
1114 float y = ToCallTime(end_time_);
1115 alr_state.intervals.emplace_back(x, y);
1116 }
1117
philipel23c7f252017-07-14 06:30:03 -07001118 if (show_detector_state) {
1119 plot->AppendIntervalSeries(std::move(overusing_series));
1120 plot->AppendIntervalSeries(std::move(underusing_series));
1121 plot->AppendIntervalSeries(std::move(normal_series));
1122 }
1123
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001124 if (show_alr_state) {
1125 plot->AppendIntervalSeries(std::move(alr_state));
1126 }
philipel35ba9bd2017-04-19 05:58:51 -07001127 plot->AppendTimeSeries(std::move(loss_series));
1128 plot->AppendTimeSeries(std::move(delay_series));
1129 plot->AppendTimeSeries(std::move(created_series));
1130 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -07001131 }
philipele127e7a2017-03-29 16:28:53 +02001132
terelius2c8e8a32017-06-02 01:29:48 -07001133 // Overlay the incoming REMB over the outgoing bitrate
1134 // and outgoing REMB over incoming bitrate.
1135 PacketDirection remb_direction =
1136 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001137 TimeSeries remb_series("Remb", LineStyle::kStep);
terelius2c8e8a32017-06-02 01:29:48 -07001138 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
1139 for (const auto& kv : rtcp_packets_) {
1140 if (kv.first.GetDirection() == remb_direction) {
1141 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
1142 if (rtcp_packet.type == kRtcpRemb) {
1143 remb_packets.insert(
1144 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1145 }
1146 }
1147 }
1148 }
1149
1150 for (const auto& kv : remb_packets) {
1151 const LoggedRtcpPacket* const rtcp = kv.second;
1152 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
1153 float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000;
1154 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
1155 remb_series.points.emplace_back(x, y);
1156 }
1157 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1158
tereliusdc35dcd2016-08-01 12:03:27 -07001159 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1160 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001161 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001162 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001163 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001164 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001165 }
1166}
1167
1168// For each SSRC, plot the bandwidth used by that stream.
1169void EventLogAnalyzer::CreateStreamBitrateGraph(
1170 PacketDirection desired_direction,
1171 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001172 for (auto& kv : rtp_packets_) {
1173 StreamId stream_id = kv.first;
1174 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1175 // Filter on direction and SSRC.
1176 if (stream_id.GetDirection() != desired_direction ||
1177 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1178 continue;
terelius54ce6802016-07-13 06:44:41 -07001179 }
1180
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001181 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -07001182 MovingAverage<LoggedRtpPacket, double>(
1183 [](const LoggedRtpPacket& packet) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001184 return packet.total_length * 8.0 / 1000.0;
terelius53dc23c2017-03-13 05:24:05 -07001185 },
1186 packet_stream, begin_time_, end_time_, window_duration_, step_,
1187 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001188 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001189 }
1190
tereliusdc35dcd2016-08-01 12:03:27 -07001191 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1192 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001193 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001194 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001195 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001196 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001197 }
1198}
1199
Bjorn Terelius28db2662017-10-04 14:22:43 +02001200void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001201 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1202 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001203
1204 for (const auto& kv : rtp_packets_) {
1205 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1206 for (const LoggedRtpPacket& rtp_packet : kv.second)
1207 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1208 }
1209 }
1210
1211 for (const auto& kv : rtcp_packets_) {
1212 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1213 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1214 incoming_rtcp.insert(
1215 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1216 }
1217 }
1218
1219 SimulatedClock clock(0);
1220 BitrateObserver observer;
1221 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001222 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001223 PacedSender pacer(&clock, &packet_router, &null_event_log);
1224 SendSideCongestionController cc(&clock, &observer, &null_event_log, &pacer);
Stefan Holmer13181032016-07-29 14:48:54 +02001225 // TODO(holmer): Log the call config and use that here instead.
1226 static const uint32_t kDefaultStartBitrateBps = 300000;
1227 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1228
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001229 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1230 PointStyle::kHighlight);
1231 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1232 PointStyle::kHighlight);
1233 TimeSeries acked_estimate_time_series(
1234 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001235
1236 auto rtp_iterator = outgoing_rtp.begin();
1237 auto rtcp_iterator = incoming_rtcp.begin();
1238
1239 auto NextRtpTime = [&]() {
1240 if (rtp_iterator != outgoing_rtp.end())
1241 return static_cast<int64_t>(rtp_iterator->first);
1242 return std::numeric_limits<int64_t>::max();
1243 };
1244
1245 auto NextRtcpTime = [&]() {
1246 if (rtcp_iterator != incoming_rtcp.end())
1247 return static_cast<int64_t>(rtcp_iterator->first);
1248 return std::numeric_limits<int64_t>::max();
1249 };
1250
1251 auto NextProcessTime = [&]() {
1252 if (rtcp_iterator != incoming_rtcp.end() ||
1253 rtp_iterator != outgoing_rtp.end()) {
1254 return clock.TimeInMicroseconds() +
1255 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1256 }
1257 return std::numeric_limits<int64_t>::max();
1258 };
1259
Stefan Holmer492ee282016-10-27 17:19:20 +02001260 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001261#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1262 // The event_log_visualizer should normally not be compiled with
1263 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
1264 // However, compiling with BWE_TEST_LOGGING, runnning with --plot_sendside_bwe
1265 // and piping the output to plot_dynamics.py can be used as a hack to get the
1266 // internal state of various BWE components. In this case, it is important
1267 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
1268 // SendSideCongestionController since that would lead to duplicate outputs.
1269 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
1270 rtc::MakeUnique<BitrateEstimator>());
1271#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001272 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001273 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001274 while (time_us != std::numeric_limits<int64_t>::max()) {
1275 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1276 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001277 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001278 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1279 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001280 cc.OnTransportFeedback(
1281 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1282 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001283 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001284 rtc::Optional<uint32_t> bitrate_bps;
1285 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001286#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1287 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
1288#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
elad.alonf9490002017-03-06 05:32:21 -08001289 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001290 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1291 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1292 }
Stefan Holmer60e43462016-09-07 09:58:20 +02001293 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1294 1000000;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001295 float y = bitrate_bps.value_or(0) / 1000;
Stefan Holmer60e43462016-09-07 09:58:20 +02001296 acked_time_series.points.emplace_back(x, y);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001297#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1298 y = acknowledged_bitrate_estimator.bitrate_bps().value_or(0) / 1000;
1299 acked_estimate_time_series.points.emplace_back(x, y);
1300#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001301 }
1302 ++rtcp_iterator;
1303 }
1304 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001305 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001306 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1307 if (rtp.header.extension.hasTransportSequenceNumber) {
1308 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001309 cc.AddPacket(rtp.header.ssrc,
1310 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001311 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001312 rtc::SentPacket sent_packet(
1313 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1314 cc.OnSentPacket(sent_packet);
1315 }
1316 ++rtp_iterator;
1317 }
stefanc3de0332016-08-02 07:22:17 -07001318 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1319 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001320 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001321 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001322 if (observer.GetAndResetBitrateUpdated() ||
1323 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001324 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001325 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1326 1000000;
1327 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001328 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001329 }
1330 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1331 }
1332 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001333 plot->AppendTimeSeries(std::move(time_series));
1334 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001335 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001336
tereliusdc35dcd2016-08-01 12:03:27 -07001337 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1338 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001339 plot->SetTitle("Simulated send-side BWE behavior");
1340}
1341
1342void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
1343 class RembInterceptingPacketRouter : public PacketRouter {
1344 public:
1345 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1346 uint32_t bitrate_bps) override {
1347 last_bitrate_bps_ = bitrate_bps;
1348 bitrate_updated_ = true;
1349 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1350 }
1351 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1352 bool GetAndResetBitrateUpdated() {
1353 bool bitrate_updated = bitrate_updated_;
1354 bitrate_updated_ = false;
1355 return bitrate_updated;
1356 }
1357
1358 private:
1359 uint32_t last_bitrate_bps_;
1360 bool bitrate_updated_;
1361 };
1362
1363 std::multimap<uint64_t, const LoggedRtpPacket*> incoming_rtp;
1364
1365 for (const auto& kv : rtp_packets_) {
1366 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket &&
1367 IsVideoSsrc(kv.first)) {
1368 for (const LoggedRtpPacket& rtp_packet : kv.second)
1369 incoming_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1370 }
1371 }
1372
1373 SimulatedClock clock(0);
1374 RembInterceptingPacketRouter packet_router;
1375 // TODO(terelius): The PacketRrouter is the used as the RemoteBitrateObserver.
1376 // Is this intentional?
1377 ReceiveSideCongestionController rscc(&clock, &packet_router);
1378 // TODO(holmer): Log the call config and use that here instead.
1379 // static const uint32_t kDefaultStartBitrateBps = 300000;
1380 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1381
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001382 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1383 PointStyle::kHighlight);
1384 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001385
1386 RateStatistics acked_bitrate(250, 8000);
1387 int64_t last_update_us = 0;
1388 for (const auto& kv : incoming_rtp) {
1389 const LoggedRtpPacket& packet = *kv.second;
1390 int64_t arrival_time_ms = packet.timestamp / 1000;
1391 size_t payload = packet.total_length; /*Should subtract header?*/
1392 clock.AdvanceTimeMicroseconds(packet.timestamp -
1393 clock.TimeInMicroseconds());
1394 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.header);
1395 acked_bitrate.Update(payload, arrival_time_ms);
1396 rtc::Optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
1397 if (bitrate_bps) {
1398 uint32_t y = *bitrate_bps / 1000;
1399 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1400 1000000;
1401 acked_time_series.points.emplace_back(x, y);
1402 }
1403 if (packet_router.GetAndResetBitrateUpdated() ||
1404 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1405 uint32_t y = packet_router.last_bitrate_bps() / 1000;
1406 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1407 1000000;
1408 time_series.points.emplace_back(x, y);
1409 last_update_us = clock.TimeInMicroseconds();
1410 }
1411 }
1412 // Add the data set to the plot.
1413 plot->AppendTimeSeries(std::move(time_series));
1414 plot->AppendTimeSeries(std::move(acked_time_series));
1415
1416 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1417 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1418 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001419}
1420
tereliuse34c19c2016-08-15 08:47:14 -07001421void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001422 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1423 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001424
1425 for (const auto& kv : rtp_packets_) {
1426 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1427 for (const LoggedRtpPacket& rtp_packet : kv.second)
1428 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1429 }
1430 }
1431
1432 for (const auto& kv : rtcp_packets_) {
1433 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1434 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1435 incoming_rtcp.insert(
1436 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1437 }
1438 }
1439
1440 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001441 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001442
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001443 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1444 PointStyle::kHighlight);
1445 TimeSeries time_series("Network Delay Change", LineStyle::kLine,
1446 PointStyle::kHighlight);
stefanc3de0332016-08-02 07:22:17 -07001447 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1448
1449 auto rtp_iterator = outgoing_rtp.begin();
1450 auto rtcp_iterator = incoming_rtcp.begin();
1451
1452 auto NextRtpTime = [&]() {
1453 if (rtp_iterator != outgoing_rtp.end())
1454 return static_cast<int64_t>(rtp_iterator->first);
1455 return std::numeric_limits<int64_t>::max();
1456 };
1457
1458 auto NextRtcpTime = [&]() {
1459 if (rtcp_iterator != incoming_rtcp.end())
1460 return static_cast<int64_t>(rtcp_iterator->first);
1461 return std::numeric_limits<int64_t>::max();
1462 };
1463
1464 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
stefana0a8ed72017-09-06 02:06:32 -07001465 int64_t prev_y = 0;
stefanc3de0332016-08-02 07:22:17 -07001466 while (time_us != std::numeric_limits<int64_t>::max()) {
1467 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1468 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1469 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1470 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1471 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001472 feedback_adapter.OnTransportFeedback(
1473 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001474 std::vector<PacketFeedback> feedback =
1475 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001476 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001477 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001478 float x =
1479 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1480 1000000;
srtee0572e52017-11-30 09:59:33 +01001481 if (packet.send_time_ms == PacketFeedback::kNoSendTime) {
stefana0a8ed72017-09-06 02:06:32 -07001482 late_feedback_series.points.emplace_back(x, prev_y);
1483 continue;
1484 }
1485 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1486 prev_y = y;
stefanc3de0332016-08-02 07:22:17 -07001487 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1488 time_series.points.emplace_back(x, y);
1489 }
1490 }
1491 ++rtcp_iterator;
1492 }
1493 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1494 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1495 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1496 if (rtp.header.extension.hasTransportSequenceNumber) {
1497 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001498 feedback_adapter.AddPacket(rtp.header.ssrc,
1499 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001500 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001501 feedback_adapter.OnSentPacket(
1502 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1503 }
1504 ++rtp_iterator;
1505 }
1506 time_us = std::min(NextRtpTime(), NextRtcpTime());
1507 }
1508 // We assume that the base network delay (w/o queues) is the min delay
1509 // observed during the call.
1510 for (TimeSeriesPoint& point : time_series.points)
1511 point.y -= estimated_base_delay_ms;
stefana0a8ed72017-09-06 02:06:32 -07001512 for (TimeSeriesPoint& point : late_feedback_series.points)
1513 point.y -= estimated_base_delay_ms;
stefanc3de0332016-08-02 07:22:17 -07001514 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001515 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1516 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001517
1518 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1519 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1520 plot->SetTitle("Network Delay Change.");
1521}
stefan08383272016-12-20 08:51:52 -08001522
1523std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1524 const {
1525 std::vector<std::pair<int64_t, int64_t>> timestamps;
1526 size_t largest_stream_size = 0;
1527 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1528 // Find the incoming video stream with the most number of packets that is
1529 // not rtx.
1530 for (const auto& kv : rtp_packets_) {
1531 if (kv.first.GetDirection() == kIncomingPacket &&
1532 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1533 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1534 kv.second.size() > largest_stream_size) {
1535 largest_stream_size = kv.second.size();
1536 largest_video_stream = &kv.second;
1537 }
1538 }
1539 if (largest_video_stream == nullptr) {
1540 for (auto& packet : *largest_video_stream) {
1541 if (packet.header.markerBit) {
1542 int64_t capture_ms = packet.header.timestamp / 90.0;
1543 int64_t arrival_ms = packet.timestamp / 1000.0;
1544 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1545 }
1546 }
1547 }
1548 return timestamps;
1549}
stefane372d3c2017-02-02 08:04:18 -08001550
Bjorn Terelius0295a962017-10-25 17:42:41 +02001551void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
1552 for (const auto& kv : rtp_packets_) {
1553 const std::vector<LoggedRtpPacket>& packets = kv.second;
1554 StreamId stream_id = kv.first;
Bjorn Tereliusb87c27e2017-11-09 11:55:51 +01001555 if (stream_id.GetDirection() == kIncomingPacket)
1556 continue;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001557
1558 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001559 RTC_LOG(LS_WARNING)
1560 << "Can't estimate a the RTP clock frequency or the "
1561 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001562 continue;
1563 }
1564 rtc::Optional<uint32_t> estimated_frequency =
1565 EstimateRtpClockFrequency(packets);
1566 if (!estimated_frequency)
1567 continue;
1568 if (IsVideoSsrc(stream_id) && *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001569 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001570 << "Video stream should use a 90 kHz clock but appears to use "
1571 << *estimated_frequency / 1000 << ". Discarding.";
1572 continue;
1573 }
1574
1575 TimeSeries pacer_delay_series(
1576 GetStreamName(stream_id) + "(" +
1577 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001578 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001579 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1580 uint64_t first_capture_timestamp =
1581 timestamp_unwrapper.Unwrap(packets.front().header.timestamp);
1582 uint64_t first_send_timestamp = packets.front().timestamp;
1583 for (LoggedRtpPacket packet : packets) {
1584 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
1585 packet.header.timestamp)) -
1586 first_capture_timestamp) /
1587 *estimated_frequency * 1000;
1588 double send_time_ms =
1589 static_cast<double>(packet.timestamp - first_send_timestamp) / 1000;
1590 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1591 float y = send_time_ms - capture_time_ms;
1592 pacer_delay_series.points.emplace_back(x, y);
1593 }
1594 plot->AppendTimeSeries(std::move(pacer_delay_series));
1595 }
1596
1597 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1598 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1599 plot->SetTitle(
1600 "Delay from capture to send time. (First packet normalized to 0.)");
1601}
1602
stefane372d3c2017-02-02 08:04:18 -08001603void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1604 for (const auto& kv : rtp_packets_) {
1605 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1606 StreamId stream_id = kv.first;
1607
1608 {
terelius23c595a2017-03-15 01:59:12 -07001609 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001610 LineStyle::kLine, PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001611 for (LoggedRtpPacket packet : rtp_packets) {
1612 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1613 float y = packet.header.timestamp;
1614 timestamp_data.points.emplace_back(x, y);
1615 }
philipel35ba9bd2017-04-19 05:58:51 -07001616 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001617 }
1618
1619 {
1620 auto kv = rtcp_packets_.find(stream_id);
1621 if (kv != rtcp_packets_.end()) {
1622 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001623 TimeSeries timestamp_data(
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001624 GetStreamName(stream_id) + " rtcp capture-time", LineStyle::kLine,
1625 PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001626 for (const LoggedRtcpPacket& rtcp : packets) {
1627 if (rtcp.type != kRtcpSr)
1628 continue;
1629 rtcp::SenderReport* sr;
1630 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1631 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1632 float y = sr->rtp_timestamp();
1633 timestamp_data.points.emplace_back(x, y);
1634 }
philipel35ba9bd2017-04-19 05:58:51 -07001635 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001636 }
1637 }
1638 }
1639
1640 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1641 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1642 plot->SetTitle("Timestamps");
1643}
michaelt6e5b2192017-02-22 07:33:27 -08001644
1645void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001646 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1647 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001648 ProcessPoints<AudioNetworkAdaptationEvent>(
1649 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001650 if (ana_event.config.bitrate_bps)
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001651 return static_cast<float>(*ana_event.config.bitrate_bps);
1652 return rtc::nullopt;
terelius53dc23c2017-03-13 05:24:05 -07001653 },
philipel35ba9bd2017-04-19 05:58:51 -07001654 audio_network_adaptation_events_, begin_time_, &time_series);
1655 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001656 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1657 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1658 plot->SetTitle("Reported audio encoder target bitrate");
1659}
1660
1661void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001662 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1663 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001664 ProcessPoints<AudioNetworkAdaptationEvent>(
1665 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001666 if (ana_event.config.frame_length_ms)
1667 return rtc::Optional<float>(
1668 static_cast<float>(*ana_event.config.frame_length_ms));
1669 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001670 },
philipel35ba9bd2017-04-19 05:58:51 -07001671 audio_network_adaptation_events_, begin_time_, &time_series);
1672 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001673 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1674 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1675 plot->SetTitle("Reported audio encoder frame length");
1676}
1677
terelius2ee076d2017-08-15 02:04:02 -07001678void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001679 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001680 LineStyle::kLine, PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001681 ProcessPoints<AudioNetworkAdaptationEvent>(
1682 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001683 if (ana_event.config.uplink_packet_loss_fraction)
1684 return rtc::Optional<float>(static_cast<float>(
1685 *ana_event.config.uplink_packet_loss_fraction));
1686 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001687 },
philipel35ba9bd2017-04-19 05:58:51 -07001688 audio_network_adaptation_events_, begin_time_, &time_series);
1689 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001690 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1691 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1692 kTopMargin);
1693 plot->SetTitle("Reported audio encoder lost packets");
1694}
1695
1696void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001697 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1698 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001699 ProcessPoints<AudioNetworkAdaptationEvent>(
1700 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001701 if (ana_event.config.enable_fec)
1702 return rtc::Optional<float>(
1703 static_cast<float>(*ana_event.config.enable_fec));
1704 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001705 },
philipel35ba9bd2017-04-19 05:58:51 -07001706 audio_network_adaptation_events_, begin_time_, &time_series);
1707 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001708 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1709 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1710 plot->SetTitle("Reported audio encoder FEC");
1711}
1712
1713void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001714 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1715 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001716 ProcessPoints<AudioNetworkAdaptationEvent>(
1717 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001718 if (ana_event.config.enable_dtx)
1719 return rtc::Optional<float>(
1720 static_cast<float>(*ana_event.config.enable_dtx));
1721 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001722 },
philipel35ba9bd2017-04-19 05:58:51 -07001723 audio_network_adaptation_events_, begin_time_, &time_series);
1724 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001725 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1726 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1727 plot->SetTitle("Reported audio encoder DTX");
1728}
1729
1730void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001731 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1732 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001733 ProcessPoints<AudioNetworkAdaptationEvent>(
1734 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001735 if (ana_event.config.num_channels)
1736 return rtc::Optional<float>(
1737 static_cast<float>(*ana_event.config.num_channels));
1738 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001739 },
philipel35ba9bd2017-04-19 05:58:51 -07001740 audio_network_adaptation_events_, begin_time_, &time_series);
1741 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001742 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1743 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1744 kBottomMargin, kTopMargin);
1745 plot->SetTitle("Reported audio encoder number of channels");
1746}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001747
1748class NetEqStreamInput : public test::NetEqInput {
1749 public:
1750 // Does not take any ownership, and all pointers must refer to valid objects
1751 // that outlive the one constructed.
1752 NetEqStreamInput(const std::vector<LoggedRtpPacket>* packet_stream,
1753 const std::vector<uint64_t>* output_events_us,
1754 rtc::Optional<uint64_t> end_time_us)
1755 : packet_stream_(*packet_stream),
1756 packet_stream_it_(packet_stream_.begin()),
1757 output_events_us_it_(output_events_us->begin()),
1758 output_events_us_end_(output_events_us->end()),
1759 end_time_us_(end_time_us) {
1760 RTC_DCHECK(packet_stream);
1761 RTC_DCHECK(output_events_us);
1762 }
1763
1764 rtc::Optional<int64_t> NextPacketTime() const override {
1765 if (packet_stream_it_ == packet_stream_.end()) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001766 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001767 }
1768 if (end_time_us_ && packet_stream_it_->timestamp > *end_time_us_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001769 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001770 }
1771 // Convert from us to ms.
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001772 return packet_stream_it_->timestamp / 1000;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001773 }
1774
1775 rtc::Optional<int64_t> NextOutputEventTime() const override {
1776 if (output_events_us_it_ == output_events_us_end_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001777 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001778 }
1779 if (end_time_us_ && *output_events_us_it_ > *end_time_us_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001780 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001781 }
1782 // Convert from us to ms.
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001783 return rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001784 }
1785
1786 std::unique_ptr<PacketData> PopPacket() override {
1787 if (packet_stream_it_ == packet_stream_.end()) {
1788 return std::unique_ptr<PacketData>();
1789 }
1790 std::unique_ptr<PacketData> packet_data(new PacketData());
1791 packet_data->header = packet_stream_it_->header;
1792 // Convert from us to ms.
1793 packet_data->time_ms = packet_stream_it_->timestamp / 1000.0;
1794
1795 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1796 // length according to the virtual length.
1797 packet_data->payload.SetSize(packet_stream_it_->total_length);
1798 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1799
1800 ++packet_stream_it_;
1801 return packet_data;
1802 }
1803
1804 void AdvanceOutputEvent() override {
1805 if (output_events_us_it_ != output_events_us_end_) {
1806 ++output_events_us_it_;
1807 }
1808 }
1809
1810 bool ended() const override { return !NextEventTime(); }
1811
1812 rtc::Optional<RTPHeader> NextHeader() const override {
1813 if (packet_stream_it_ == packet_stream_.end()) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001814 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001815 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001816 return packet_stream_it_->header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001817 }
1818
1819 private:
1820 const std::vector<LoggedRtpPacket>& packet_stream_;
1821 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_;
1822 std::vector<uint64_t>::const_iterator output_events_us_it_;
1823 const std::vector<uint64_t>::const_iterator output_events_us_end_;
1824 const rtc::Optional<uint64_t> end_time_us_;
1825};
1826
1827namespace {
1828// Creates a NetEq test object and all necessary input and output helpers. Runs
1829// the test and returns the NetEqDelayAnalyzer object that was used to
1830// instrument the test.
1831std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun(
1832 const std::vector<LoggedRtpPacket>* packet_stream,
1833 const std::vector<uint64_t>* output_events_us,
1834 rtc::Optional<uint64_t> end_time_us,
1835 const std::string& replacement_file_name,
1836 int file_sample_rate_hz) {
1837 std::unique_ptr<test::NetEqInput> input(
1838 new NetEqStreamInput(packet_stream, output_events_us, end_time_us));
1839
1840 constexpr int kReplacementPt = 127;
1841 std::set<uint8_t> cn_types;
1842 std::set<uint8_t> forbidden_types;
1843 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1844 cn_types, forbidden_types));
1845
1846 NetEq::Config config;
1847 config.max_packets_in_buffer = 200;
1848 config.enable_fast_accelerate = true;
1849
1850 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1851
1852 test::NetEqTest::DecoderMap codecs;
1853
1854 // Create a "replacement decoder" that produces the decoded audio by reading
1855 // from a file rather than from the encoded payloads.
1856 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1857 new test::ResampleInputAudioFile(replacement_file_name,
1858 file_sample_rate_hz));
1859 replacement_file->set_output_rate_hz(48000);
1860 std::unique_ptr<AudioDecoder> replacement_decoder(
1861 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1862 test::NetEqTest::ExtDecoderMap ext_codecs;
1863 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1864 NetEqDecoder::kDecoderArbitrary,
1865 "replacement codec"};
1866
1867 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1868 new test::NetEqDelayAnalyzer);
1869 test::DefaultNetEqTestErrorCallback error_cb;
1870 test::NetEqTest::Callbacks callbacks;
1871 callbacks.error_callback = &error_cb;
1872 callbacks.post_insert_packet = delay_cb.get();
1873 callbacks.get_audio_callback = delay_cb.get();
1874
1875 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1876 std::move(output), callbacks);
1877 test.Run();
1878 return delay_cb;
1879}
1880} // namespace
1881
1882// Plots the jitter buffer delay profile. This will plot only for the first
1883// incoming audio SSRC. If the stream contains more than one incoming audio
1884// SSRC, all but the first will be ignored.
1885void EventLogAnalyzer::CreateAudioJitterBufferGraph(
1886 const std::string& replacement_file_name,
1887 int file_sample_rate_hz,
1888 Plot* plot) {
1889 const auto& incoming_audio_kv = std::find_if(
1890 rtp_packets_.begin(), rtp_packets_.end(),
1891 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) {
1892 return kv.first.GetDirection() == kIncomingPacket &&
1893 this->IsAudioSsrc(kv.first);
1894 });
1895 if (incoming_audio_kv == rtp_packets_.end()) {
1896 // No incoming audio stream found.
1897 return;
1898 }
1899
1900 const uint32_t ssrc = incoming_audio_kv->first.GetSsrc();
1901
1902 std::map<uint32_t, std::vector<uint64_t>>::const_iterator output_events_it =
1903 audio_playout_events_.find(ssrc);
1904 if (output_events_it == audio_playout_events_.end()) {
1905 // Could not find output events with SSRC matching the input audio stream.
1906 // Using the first available stream of output events.
1907 output_events_it = audio_playout_events_.cbegin();
1908 }
1909
1910 rtc::Optional<uint64_t> end_time_us =
1911 log_segments_.empty()
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001912 ? rtc::nullopt
henrik.lundin3c938fc2017-06-14 06:09:58 -07001913 : rtc::Optional<uint64_t>(log_segments_.front().second);
1914
1915 auto delay_cb = CreateNetEqTestAndRun(
1916 &incoming_audio_kv->second, &output_events_it->second, end_time_us,
1917 replacement_file_name, file_sample_rate_hz);
1918
1919 std::vector<float> send_times_s;
1920 std::vector<float> arrival_delay_ms;
1921 std::vector<float> corrected_arrival_delay_ms;
1922 std::vector<rtc::Optional<float>> playout_delay_ms;
1923 std::vector<rtc::Optional<float>> target_delay_ms;
1924 delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms,
1925 &corrected_arrival_delay_ms, &playout_delay_ms,
1926 &target_delay_ms);
1927 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size());
1928 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size());
1929 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size());
1930 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size());
1931
1932 std::map<StreamId, TimeSeries> time_series_packet_arrival;
1933 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival;
1934 std::map<StreamId, TimeSeries> time_series_play_time;
1935 std::map<StreamId, TimeSeries> time_series_target_time;
1936 float min_y_axis = 0.f;
1937 float max_y_axis = 0.f;
1938 const StreamId stream_id = incoming_audio_kv->first;
1939 for (size_t i = 0; i < send_times_s.size(); ++i) {
1940 time_series_packet_arrival[stream_id].points.emplace_back(
1941 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i]));
1942 time_series_relative_packet_arrival[stream_id].points.emplace_back(
1943 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i]));
1944 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]);
1945 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]);
1946 if (playout_delay_ms[i]) {
1947 time_series_play_time[stream_id].points.emplace_back(
1948 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i]));
1949 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]);
1950 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]);
1951 }
1952 if (target_delay_ms[i]) {
1953 time_series_target_time[stream_id].points.emplace_back(
1954 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i]));
1955 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]);
1956 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]);
1957 }
1958 }
1959
1960 // This code is adapted for a single stream. The creation of the streams above
1961 // guarantee that no more than one steam is included. If multiple streams are
1962 // to be plotted, they should likely be given distinct labels below.
1963 RTC_DCHECK_EQ(time_series_relative_packet_arrival.size(), 1);
1964 for (auto& series : time_series_relative_packet_arrival) {
1965 series.second.label = "Relative packet arrival delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001966 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001967 plot->AppendTimeSeries(std::move(series.second));
1968 }
1969 RTC_DCHECK_EQ(time_series_play_time.size(), 1);
1970 for (auto& series : time_series_play_time) {
1971 series.second.label = "Playout delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001972 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001973 plot->AppendTimeSeries(std::move(series.second));
1974 }
1975 RTC_DCHECK_EQ(time_series_target_time.size(), 1);
1976 for (auto& series : time_series_target_time) {
1977 series.second.label = "Target delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001978 series.second.line_style = LineStyle::kLine;
1979 series.second.point_style = PointStyle::kHighlight;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001980 plot->AppendTimeSeries(std::move(series.second));
1981 }
1982
1983 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1984 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin,
1985 kTopMargin);
1986 plot->SetTitle("NetEq timing");
1987}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01001988
1989void EventLogAnalyzer::Notification(
1990 std::unique_ptr<TriageNotification> notification) {
1991 notifications_.push_back(std::move(notification));
1992}
1993
1994void EventLogAnalyzer::PrintNotifications(FILE* file) {
1995 if (notifications_.size() == 0)
1996 return;
1997 fprintf(file, "========== TRIAGE NOTIFICATIONS ==========\n");
1998 for (const auto& notification : notifications_) {
1999 rtc::Optional<float> call_timestamp = notification->Time();
2000 if (call_timestamp.has_value()) {
2001 fprintf(file, "%3.3lf s : %s\n", call_timestamp.value(),
2002 notification->ToString().c_str());
2003 } else {
2004 fprintf(file, " : %s\n", notification->ToString().c_str());
2005 }
2006 }
2007 fprintf(file, "========== END TRIAGE NOTIFICATIONS ==========\n");
2008}
2009
2010// TODO(terelius): Notifications could possibly be generated by the same code
2011// that produces the graphs. There is some code duplication that could be
2012// avoided, but that might be solved anyway when we move functionality from the
2013// analyzer to the parser.
2014void EventLogAnalyzer::CreateTriageNotifications() {
2015 uint64_t end_time_us = log_segments_.empty()
2016 ? std::numeric_limits<uint64_t>::max()
2017 : log_segments_.front().second;
2018 // Check for gaps in sequence numbers and capture timestamps.
2019 for (auto& kv : rtp_packets_) {
2020 StreamId stream_id = kv.first;
2021 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
2022
2023 SeqNumUnwrapper<uint16_t> seq_no_unwrapper;
2024 rtc::Optional<int64_t> last_seq_no;
2025 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
2026 rtc::Optional<int64_t> last_timestamp;
2027 for (const auto& packet : packet_stream) {
2028 if (packet.timestamp > end_time_us) {
2029 // Only process the first (LOG_START, LOG_END) segment.
2030 break;
2031 }
2032 int64_t seq_no = seq_no_unwrapper.Unwrap(packet.header.sequenceNumber);
2033 if (last_seq_no.has_value() &&
2034 std::abs(seq_no - last_seq_no.value()) > 1000) {
2035 // With roughly 100 packets per second (~800kbps), this would require 10
2036 // seconds without data to trigger incorrectly.
2037 if (stream_id.GetDirection() == kIncomingPacket) {
2038 Notification(rtc::MakeUnique<IncomingSeqNoJump>(
2039 ToCallTime(packet.timestamp), packet.header.ssrc));
2040 } else {
2041 Notification(rtc::MakeUnique<OutgoingSeqNoJump>(
2042 ToCallTime(packet.timestamp), packet.header.ssrc));
2043 }
2044 }
2045 last_seq_no.emplace(seq_no);
2046 int64_t timestamp = timestamp_unwrapper.Unwrap(packet.header.timestamp);
2047 if (last_timestamp.has_value() &&
2048 std::abs(timestamp - last_timestamp.value()) > 900000) {
2049 // With a 90 kHz clock, this would require 10 seconds without data to
2050 // trigger incorrectly.
2051 if (stream_id.GetDirection() == kIncomingPacket) {
2052 Notification(rtc::MakeUnique<IncomingCaptureTimeJump>(
2053 ToCallTime(packet.timestamp), packet.header.ssrc));
2054 } else {
2055 Notification(rtc::MakeUnique<OutgoingCaptureTimeJump>(
2056 ToCallTime(packet.timestamp), packet.header.ssrc));
2057 }
2058 }
2059 last_timestamp.emplace(timestamp);
2060 }
2061 }
2062
2063 // Check for gaps in RTP and RTCP streams
2064 for (const auto direction :
2065 {PacketDirection::kIncomingPacket, PacketDirection::kOutgoingPacket}) {
2066 // TODO(terelius): The parser could provide a list of all packets, ordered
2067 // by time, for each direction.
2068 std::multimap<uint64_t, const LoggedRtpPacket*> rtp_in_direction;
2069 for (const auto& kv : rtp_packets_) {
2070 if (kv.first.GetDirection() == direction) {
2071 for (const LoggedRtpPacket& rtp_packet : kv.second)
2072 rtp_in_direction.emplace(rtp_packet.timestamp, &rtp_packet);
2073 }
2074 }
2075 rtc::Optional<uint64_t> last_rtp_packet;
2076 for (const auto& kv : rtp_in_direction) {
2077 uint64_t timestamp = kv.first;
2078 if (timestamp > end_time_us) {
2079 // Only process the first (LOG_START, LOG_END) segment.
2080 break;
2081 }
2082 int64_t duration = timestamp - last_rtp_packet.value_or(0);
2083 if (last_rtp_packet.has_value() && duration > 500000) {
2084 // No incoming packet for more than 500 ms.
2085 if (direction == kIncomingPacket) {
2086 Notification(rtc::MakeUnique<IncomingRtpReceiveTimeGap>(
2087 ToCallTime(timestamp), duration / 1000));
2088 } else {
2089 Notification(rtc::MakeUnique<OutgoingRtpSendTimeGap>(
2090 ToCallTime(timestamp), duration / 1000));
2091 }
2092 }
2093 last_rtp_packet.emplace(timestamp);
2094 }
2095
2096 // TODO(terelius): The parser could provide a list of all packets, ordered
2097 // by time, for each direction.
2098 std::multimap<uint64_t, const LoggedRtcpPacket*> rtcp_in_direction;
2099 for (const auto& kv : rtcp_packets_) {
2100 if (kv.first.GetDirection() == direction) {
2101 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
2102 rtcp_in_direction.emplace(rtcp_packet.timestamp, &rtcp_packet);
2103 }
2104 }
2105 rtc::Optional<uint64_t> last_incoming_rtcp_packet;
2106 for (const auto& kv : rtcp_in_direction) {
2107 uint64_t timestamp = kv.first;
2108 if (timestamp > end_time_us) {
2109 // Only process the first (LOG_START, LOG_END) segment.
2110 break;
2111 }
2112 int64_t duration = timestamp - last_incoming_rtcp_packet.value_or(0);
2113 if (last_incoming_rtcp_packet.has_value() && duration > 2000000) {
2114 // No incoming feedback for more than 2000 ms.
2115 if (direction == kIncomingPacket) {
2116 Notification(rtc::MakeUnique<IncomingRtcpReceiveTimeGap>(
2117 ToCallTime(timestamp), duration / 1000));
2118 } else {
2119 Notification(rtc::MakeUnique<OutgoingRtcpSendTimeGap>(
2120 ToCallTime(timestamp), duration / 1000));
2121 }
2122 }
2123 last_incoming_rtcp_packet.emplace(timestamp);
2124 }
2125 }
2126
2127 // Loss feedback
2128 int64_t total_lost_packets = 0;
2129 int64_t total_expected_packets = 0;
2130 for (auto& bwe_update : bwe_loss_updates_) {
2131 if (bwe_update.timestamp > end_time_us) {
2132 // Only process the first (LOG_START, LOG_END) segment.
2133 break;
2134 }
2135 int64_t lost_packets = static_cast<double>(bwe_update.fraction_loss) / 255 *
2136 bwe_update.expected_packets;
2137 total_lost_packets += lost_packets;
2138 total_expected_packets += bwe_update.expected_packets;
2139 }
2140 double avg_outgoing_loss =
2141 static_cast<double>(total_lost_packets) / total_expected_packets;
2142 if (avg_outgoing_loss > 0.05) {
2143 Notification(rtc::MakeUnique<OutgoingHighLoss>(avg_outgoing_loss));
2144 }
2145}
2146
terelius54ce6802016-07-13 06:44:41 -07002147} // namespace plotting
2148} // namespace webrtc