blob: 792e6bbab5fb42578154c5674534aeddd9a00418 [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 }
terelius88e64e52016-07-19 01:51:06 -0700525 case ParsedRtcEventLog::UNKNOWN_EVENT: {
526 break;
527 }
528 }
terelius54ce6802016-07-13 06:44:41 -0700529 }
terelius88e64e52016-07-19 01:51:06 -0700530
terelius54ce6802016-07-13 06:44:41 -0700531 if (last_timestamp < first_timestamp) {
532 // No useful events in the log.
533 first_timestamp = last_timestamp = 0;
534 }
535 begin_time_ = first_timestamp;
536 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700537 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700538 if (last_log_start) {
539 // The log was missing the last LOG_END event. Fake it.
540 log_segments_.push_back(std::make_pair(*last_log_start, end_time_));
541 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100542 RTC_LOG(LS_INFO) << "Found " << log_segments_.size()
543 << " (LOG_START, LOG_END) segments in log.";
terelius54ce6802016-07-13 06:44:41 -0700544}
545
Niels Möller245f17e2017-08-21 10:45:07 +0200546class BitrateObserver : public SendSideCongestionController::Observer,
Stefan Holmer13181032016-07-29 14:48:54 +0200547 public RemoteBitrateObserver {
548 public:
549 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
550
551 void OnNetworkChanged(uint32_t bitrate_bps,
552 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800553 int64_t rtt_ms,
554 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200555 last_bitrate_bps_ = bitrate_bps;
556 bitrate_updated_ = true;
557 }
558
559 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
560 uint32_t bitrate) override {}
561
562 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
563 bool GetAndResetBitrateUpdated() {
564 bool bitrate_updated = bitrate_updated_;
565 bitrate_updated_ = false;
566 return bitrate_updated;
567 }
568
569 private:
570 uint32_t last_bitrate_bps_;
571 bool bitrate_updated_;
572};
573
Stefan Holmer99f8e082016-09-09 13:37:50 +0200574bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700575 return rtx_ssrcs_.count(stream_id) == 1;
576}
577
Stefan Holmer99f8e082016-09-09 13:37:50 +0200578bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700579 return video_ssrcs_.count(stream_id) == 1;
580}
581
Stefan Holmer99f8e082016-09-09 13:37:50 +0200582bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700583 return audio_ssrcs_.count(stream_id) == 1;
584}
585
Stefan Holmer99f8e082016-09-09 13:37:50 +0200586std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
587 std::stringstream name;
588 if (IsAudioSsrc(stream_id)) {
589 name << "Audio ";
590 } else if (IsVideoSsrc(stream_id)) {
591 name << "Video ";
592 } else {
593 name << "Unknown ";
594 }
595 if (IsRtxSsrc(stream_id))
596 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700597 if (stream_id.GetDirection() == kIncomingPacket) {
598 name << "(In) ";
599 } else {
600 name << "(Out) ";
601 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200602 name << SsrcToString(stream_id.GetSsrc());
603 return name.str();
604}
605
Bjorn Terelius0295a962017-10-25 17:42:41 +0200606// This is much more reliable for outgoing streams than for incoming streams.
607rtc::Optional<uint32_t> EventLogAnalyzer::EstimateRtpClockFrequency(
608 const std::vector<LoggedRtpPacket>& packets) const {
609 RTC_CHECK(packets.size() >= 2);
610 uint64_t end_time_us = log_segments_.empty()
611 ? std::numeric_limits<uint64_t>::max()
612 : log_segments_.front().second;
613 SeqNumUnwrapper<uint32_t> unwrapper;
614 uint64_t first_rtp_timestamp = unwrapper.Unwrap(packets[0].header.timestamp);
615 uint64_t first_log_timestamp = packets[0].timestamp;
616 uint64_t last_rtp_timestamp = first_rtp_timestamp;
617 uint64_t last_log_timestamp = first_log_timestamp;
618 for (size_t i = 1; i < packets.size(); i++) {
619 if (packets[i].timestamp > end_time_us)
620 break;
621 last_rtp_timestamp = unwrapper.Unwrap(packets[i].header.timestamp);
622 last_log_timestamp = packets[i].timestamp;
623 }
624 if (last_log_timestamp - first_log_timestamp < 1000000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100625 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +0200626 << "Failed to estimate RTP clock frequency: Stream too short. ("
627 << packets.size() << " packets, "
628 << last_log_timestamp - first_log_timestamp << " us)";
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100629 return rtc::nullopt;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200630 }
631 double duration =
632 static_cast<double>(last_log_timestamp - first_log_timestamp) / 1000000;
633 double estimated_frequency =
634 (last_rtp_timestamp - first_rtp_timestamp) / duration;
635 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
636 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100637 return f;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200638 }
639 }
Mirko Bonadei675513b2017-11-09 11:09:25 +0100640 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
641 << estimated_frequency
642 << "not close to any stardard RTP frequency.";
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100643 return rtc::nullopt;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200644}
645
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100646float EventLogAnalyzer::ToCallTime(int64_t timestamp) const {
647 return static_cast<float>(timestamp - begin_time_) / 1000000;
648}
649
terelius54ce6802016-07-13 06:44:41 -0700650void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
651 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700652 for (auto& kv : rtp_packets_) {
653 StreamId stream_id = kv.first;
654 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
655 // Filter on direction and SSRC.
656 if (stream_id.GetDirection() != desired_direction ||
657 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
658 continue;
terelius54ce6802016-07-13 06:44:41 -0700659 }
terelius54ce6802016-07-13 06:44:41 -0700660
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100661 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700662 ProcessPoints<LoggedRtpPacket>(
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100663 [](const LoggedRtpPacket& packet) {
terelius53dc23c2017-03-13 05:24:05 -0700664 return rtc::Optional<float>(packet.total_length);
665 },
666 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700667 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700668 }
669
tereliusdc35dcd2016-08-01 12:03:27 -0700670 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
671 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
672 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700673 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700674 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700675 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700676 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700677 }
678}
679
philipelccd74892016-09-05 02:46:25 -0700680template <typename T>
681void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
682 PacketDirection desired_direction,
683 Plot* plot,
684 const std::map<StreamId, std::vector<T>>& packets,
685 const std::string& label_prefix) {
686 for (auto& kv : packets) {
687 StreamId stream_id = kv.first;
688 const std::vector<T>& packet_stream = kv.second;
689 // Filter on direction and SSRC.
690 if (stream_id.GetDirection() != desired_direction ||
691 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
692 continue;
693 }
694
terelius23c595a2017-03-15 01:59:12 -0700695 std::string label = label_prefix + " " + GetStreamName(stream_id);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100696 TimeSeries time_series(label, LineStyle::kStep);
philipelccd74892016-09-05 02:46:25 -0700697 for (size_t i = 0; i < packet_stream.size(); i++) {
698 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
699 1000000;
philipelccd74892016-09-05 02:46:25 -0700700 time_series.points.emplace_back(x, i + 1);
701 }
702
philipel35ba9bd2017-04-19 05:58:51 -0700703 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700704 }
705}
706
707void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
708 PacketDirection desired_direction,
709 Plot* plot) {
710 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
711 "RTP");
712 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
713 "RTCP");
714
715 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
716 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
717 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
718 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
719 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
720 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
721 }
722}
723
terelius54ce6802016-07-13 06:44:41 -0700724// For each SSRC, plot the time between the consecutive playouts.
725void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
726 std::map<uint32_t, TimeSeries> time_series;
727 std::map<uint32_t, uint64_t> last_playout;
728
729 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700730
731 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
732 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
733 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
734 parsed_log_.GetAudioPlayout(i, &ssrc);
735 uint64_t timestamp = parsed_log_.GetTimestamp(i);
736 if (MatchingSsrc(ssrc, desired_ssrc_)) {
737 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
738 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
739 if (time_series[ssrc].points.size() == 0) {
740 // There were no previusly logged playout for this SSRC.
741 // Generate a point, but place it on the x-axis.
742 y = 0;
743 }
terelius54ce6802016-07-13 06:44:41 -0700744 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
745 last_playout[ssrc] = timestamp;
746 }
747 }
748 }
749
750 // Set labels and put in graph.
751 for (auto& kv : time_series) {
752 kv.second.label = SsrcToString(kv.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100753 kv.second.line_style = LineStyle::kBar;
philipel35ba9bd2017-04-19 05:58:51 -0700754 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700755 }
756
tereliusdc35dcd2016-08-01 12:03:27 -0700757 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
758 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
759 kTopMargin);
760 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700761}
762
ivocaac9d6f2016-09-22 07:01:47 -0700763// For audio SSRCs, plot the audio level.
764void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
765 std::map<StreamId, TimeSeries> time_series;
766
767 for (auto& kv : rtp_packets_) {
768 StreamId stream_id = kv.first;
769 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
770 // TODO(ivoc): When audio send/receive configs are stored in the event
771 // log, a check should be added here to only process audio
772 // streams. Tracking bug: webrtc:6399
773 for (auto& packet : packet_stream) {
774 if (packet.header.extension.hasAudioLevel) {
775 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
776 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
777 // Here we convert it to dBov.
778 float y = static_cast<float>(-packet.header.extension.audioLevel);
779 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
780 }
781 }
782 }
783
784 for (auto& series : time_series) {
785 series.second.label = GetStreamName(series.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100786 series.second.line_style = LineStyle::kLine;
philipel35ba9bd2017-04-19 05:58:51 -0700787 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700788 }
789
790 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800791 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700792 kTopMargin);
793 plot->SetTitle("Audio level");
794}
795
terelius54ce6802016-07-13 06:44:41 -0700796// For each SSRC, plot the time between the consecutive playouts.
797void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700798 for (auto& kv : rtp_packets_) {
799 StreamId stream_id = kv.first;
800 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
801 // Filter on direction and SSRC.
802 if (stream_id.GetDirection() != kIncomingPacket ||
803 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
804 continue;
terelius54ce6802016-07-13 06:44:41 -0700805 }
terelius54ce6802016-07-13 06:44:41 -0700806
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100807 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700808 ProcessPairs<LoggedRtpPacket, float>(
809 [](const LoggedRtpPacket& old_packet,
810 const LoggedRtpPacket& new_packet) {
811 int64_t diff =
812 WrappingDifference(new_packet.header.sequenceNumber,
813 old_packet.header.sequenceNumber, 1ul << 16);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100814 return diff;
terelius53dc23c2017-03-13 05:24:05 -0700815 },
816 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700817 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700818 }
819
tereliusdc35dcd2016-08-01 12:03:27 -0700820 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
821 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
822 kTopMargin);
823 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700824}
825
Stefan Holmer99f8e082016-09-09 13:37:50 +0200826void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
827 for (auto& kv : rtp_packets_) {
828 StreamId stream_id = kv.first;
829 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
830 // Filter on direction and SSRC.
831 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800832 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
833 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200834 continue;
835 }
836
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100837 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine,
838 PointStyle::kHighlight);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200839 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800840 const uint64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100841 SeqNumUnwrapper<uint16_t> unwrapper_;
842 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800843 size_t window_index_begin = 0;
844 size_t window_index_end = 0;
845 int64_t highest_seq_number =
846 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
847 int64_t highest_prior_seq_number =
848 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
849
850 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
851 while (window_index_end < packet_stream.size() &&
852 packet_stream[window_index_end].timestamp < t) {
853 int64_t sequence_number = unwrapper_.Unwrap(
854 packet_stream[window_index_end].header.sequenceNumber);
855 highest_seq_number = std::max(highest_seq_number, sequence_number);
856 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200857 }
terelius4c9b4af2017-01-30 08:44:51 -0800858 while (window_index_begin < packet_stream.size() &&
859 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
860 int64_t sequence_number = prior_unwrapper_.Unwrap(
861 packet_stream[window_index_begin].header.sequenceNumber);
862 highest_prior_seq_number =
863 std::max(highest_prior_seq_number, sequence_number);
864 ++window_index_begin;
865 }
866 float x = static_cast<float>(t - begin_time_) / 1000000;
867 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
868 if (expected_packets > 0) {
869 int64_t received_packets = window_index_end - window_index_begin;
870 int64_t lost_packets = expected_packets - received_packets;
871 float y = static_cast<float>(lost_packets) / expected_packets * 100;
872 time_series.points.emplace_back(x, y);
873 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200874 }
philipel35ba9bd2017-04-19 05:58:51 -0700875 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200876 }
877
878 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
879 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
880 kTopMargin);
881 plot->SetTitle("Estimated incoming loss rate");
882}
883
terelius2ee076d2017-08-15 02:04:02 -0700884void EventLogAnalyzer::CreateIncomingDelayDeltaGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700885 for (auto& kv : rtp_packets_) {
886 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700887 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700888 // Filter on direction and SSRC.
889 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200890 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
891 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
892 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700893 continue;
894 }
terelius54ce6802016-07-13 06:44:41 -0700895
terelius23c595a2017-03-15 01:59:12 -0700896 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100897 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700898 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
899 packet_stream, begin_time_,
900 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700901 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700902
terelius23c595a2017-03-15 01:59:12 -0700903 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100904 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700905 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
906 packet_stream, begin_time_,
907 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700908 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700909 }
910
tereliusdc35dcd2016-08-01 12:03:27 -0700911 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
912 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
913 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700914 plot->SetTitle("Network latency difference between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700915}
916
terelius2ee076d2017-08-15 02:04:02 -0700917void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700918 for (auto& kv : rtp_packets_) {
919 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700920 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700921 // Filter on direction and SSRC.
922 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200923 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
924 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
925 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700926 continue;
927 }
terelius54ce6802016-07-13 06:44:41 -0700928
terelius23c595a2017-03-15 01:59:12 -0700929 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100930 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -0700931 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
932 packet_stream, begin_time_,
933 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700934 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700935
terelius23c595a2017-03-15 01:59:12 -0700936 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100937 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -0700938 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
939 packet_stream, begin_time_,
940 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700941 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700942 }
943
tereliusdc35dcd2016-08-01 12:03:27 -0700944 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
945 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
946 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700947 plot->SetTitle("Network latency (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700948}
949
tereliusf736d232016-08-04 10:00:11 -0700950// Plot the fraction of packets lost (as perceived by the loss-based BWE).
951void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100952 TimeSeries time_series("Fraction lost", LineStyle::kLine,
953 PointStyle::kHighlight);
tereliusf736d232016-08-04 10:00:11 -0700954 for (auto& bwe_update : bwe_loss_updates_) {
955 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
956 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700957 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700958 }
tereliusf736d232016-08-04 10:00:11 -0700959
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200960 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700961 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
962 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
963 kTopMargin);
964 plot->SetTitle("Reported packet loss");
965}
966
terelius54ce6802016-07-13 06:44:41 -0700967// Plot the total bandwidth used by all RTP streams.
968void EventLogAnalyzer::CreateTotalBitrateGraph(
969 PacketDirection desired_direction,
philipel23c7f252017-07-14 06:30:03 -0700970 Plot* plot,
971 bool show_detector_state) {
terelius54ce6802016-07-13 06:44:41 -0700972 struct TimestampSize {
973 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
974 uint64_t timestamp;
975 size_t size;
976 };
977 std::vector<TimestampSize> packets;
978
979 PacketDirection direction;
980 size_t total_length;
981
982 // Extract timestamps and sizes for the relevant packets.
983 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
984 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
985 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
Elad Alon1d87b0e2017-10-03 15:01:03 +0200986 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length,
987 nullptr);
terelius54ce6802016-07-13 06:44:41 -0700988 if (direction == desired_direction) {
989 uint64_t timestamp = parsed_log_.GetTimestamp(i);
990 packets.push_back(TimestampSize(timestamp, total_length));
991 }
992 }
993 }
994
995 size_t window_index_begin = 0;
996 size_t window_index_end = 0;
997 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700998
999 // Calculate a moving average of the bitrate and store in a TimeSeries.
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001000 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
terelius54ce6802016-07-13 06:44:41 -07001001 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
1002 while (window_index_end < packets.size() &&
1003 packets[window_index_end].timestamp < time) {
1004 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -07001005 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -07001006 }
1007 while (window_index_begin < packets.size() &&
1008 packets[window_index_begin].timestamp < time - window_duration_) {
1009 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
1010 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -07001011 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -07001012 }
1013 float window_duration_in_seconds =
1014 static_cast<float>(window_duration_) / 1000000;
1015 float x = static_cast<float>(time - begin_time_) / 1000000;
1016 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001017 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -07001018 }
philipel35ba9bd2017-04-19 05:58:51 -07001019 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -07001020
terelius8058e582016-07-25 01:32:41 -07001021 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
1022 if (desired_direction == kOutgoingPacket) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001023 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
philipel10fc0e62017-04-11 01:50:23 -07001024 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -07001025 float x =
philipel10fc0e62017-04-11 01:50:23 -07001026 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
1027 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001028 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -07001029 }
1030
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001031 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
philipel23c7f252017-07-14 06:30:03 -07001032 IntervalSeries overusing_series("Overusing", "#ff8e82",
1033 IntervalSeries::kHorizontal);
1034 IntervalSeries underusing_series("Underusing", "#5092fc",
1035 IntervalSeries::kHorizontal);
1036 IntervalSeries normal_series("Normal", "#c4ffc4",
1037 IntervalSeries::kHorizontal);
1038 IntervalSeries* last_series = &normal_series;
1039 double last_detector_switch = 0.0;
1040
1041 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
1042
philipel10fc0e62017-04-11 01:50:23 -07001043 for (auto& delay_update : bwe_delay_updates_) {
1044 float x =
1045 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
1046 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -07001047
1048 if (last_detector_state != delay_update.detector_state) {
1049 last_series->intervals.emplace_back(last_detector_switch, x);
1050 last_detector_state = delay_update.detector_state;
1051 last_detector_switch = x;
1052
1053 switch (delay_update.detector_state) {
1054 case BandwidthUsage::kBwNormal:
1055 last_series = &normal_series;
1056 break;
1057 case BandwidthUsage::kBwUnderusing:
1058 last_series = &underusing_series;
1059 break;
1060 case BandwidthUsage::kBwOverusing:
1061 last_series = &overusing_series;
1062 break;
Elad Alon1d87b0e2017-10-03 15:01:03 +02001063 case BandwidthUsage::kLast:
1064 RTC_NOTREACHED();
philipel23c7f252017-07-14 06:30:03 -07001065 }
1066 }
1067
philipel35ba9bd2017-04-19 05:58:51 -07001068 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -07001069 }
philipele127e7a2017-03-29 16:28:53 +02001070
philipel23c7f252017-07-14 06:30:03 -07001071 RTC_CHECK(last_series);
1072 last_series->intervals.emplace_back(last_detector_switch, end_time_);
1073
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001074 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
1075 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001076 for (auto& cluster : bwe_probe_cluster_created_events_) {
1077 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
1078 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001079 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001080 }
1081
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001082 TimeSeries result_series("Probing results.", LineStyle::kNone,
1083 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001084 for (auto& result : bwe_probe_result_events_) {
1085 if (result.bitrate_bps) {
1086 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
1087 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001088 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001089 }
1090 }
philipel23c7f252017-07-14 06:30:03 -07001091
1092 if (show_detector_state) {
1093 plot->AppendIntervalSeries(std::move(overusing_series));
1094 plot->AppendIntervalSeries(std::move(underusing_series));
1095 plot->AppendIntervalSeries(std::move(normal_series));
1096 }
1097
philipel35ba9bd2017-04-19 05:58:51 -07001098 plot->AppendTimeSeries(std::move(loss_series));
1099 plot->AppendTimeSeries(std::move(delay_series));
1100 plot->AppendTimeSeries(std::move(created_series));
1101 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -07001102 }
philipele127e7a2017-03-29 16:28:53 +02001103
terelius2c8e8a32017-06-02 01:29:48 -07001104 // Overlay the incoming REMB over the outgoing bitrate
1105 // and outgoing REMB over incoming bitrate.
1106 PacketDirection remb_direction =
1107 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001108 TimeSeries remb_series("Remb", LineStyle::kStep);
terelius2c8e8a32017-06-02 01:29:48 -07001109 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
1110 for (const auto& kv : rtcp_packets_) {
1111 if (kv.first.GetDirection() == remb_direction) {
1112 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
1113 if (rtcp_packet.type == kRtcpRemb) {
1114 remb_packets.insert(
1115 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1116 }
1117 }
1118 }
1119 }
1120
1121 for (const auto& kv : remb_packets) {
1122 const LoggedRtcpPacket* const rtcp = kv.second;
1123 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
1124 float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000;
1125 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
1126 remb_series.points.emplace_back(x, y);
1127 }
1128 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1129
tereliusdc35dcd2016-08-01 12:03:27 -07001130 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1131 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001132 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001133 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001134 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001135 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001136 }
1137}
1138
1139// For each SSRC, plot the bandwidth used by that stream.
1140void EventLogAnalyzer::CreateStreamBitrateGraph(
1141 PacketDirection desired_direction,
1142 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001143 for (auto& kv : rtp_packets_) {
1144 StreamId stream_id = kv.first;
1145 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1146 // Filter on direction and SSRC.
1147 if (stream_id.GetDirection() != desired_direction ||
1148 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1149 continue;
terelius54ce6802016-07-13 06:44:41 -07001150 }
1151
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001152 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -07001153 MovingAverage<LoggedRtpPacket, double>(
1154 [](const LoggedRtpPacket& packet) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001155 return packet.total_length * 8.0 / 1000.0;
terelius53dc23c2017-03-13 05:24:05 -07001156 },
1157 packet_stream, begin_time_, end_time_, window_duration_, step_,
1158 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001159 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001160 }
1161
tereliusdc35dcd2016-08-01 12:03:27 -07001162 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1163 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001164 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001165 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001166 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001167 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001168 }
1169}
1170
Bjorn Terelius28db2662017-10-04 14:22:43 +02001171void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001172 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1173 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001174
1175 for (const auto& kv : rtp_packets_) {
1176 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1177 for (const LoggedRtpPacket& rtp_packet : kv.second)
1178 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1179 }
1180 }
1181
1182 for (const auto& kv : rtcp_packets_) {
1183 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1184 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1185 incoming_rtcp.insert(
1186 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1187 }
1188 }
1189
1190 SimulatedClock clock(0);
1191 BitrateObserver observer;
1192 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001193 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001194 PacedSender pacer(&clock, &packet_router, &null_event_log);
1195 SendSideCongestionController cc(&clock, &observer, &null_event_log, &pacer);
Stefan Holmer13181032016-07-29 14:48:54 +02001196 // TODO(holmer): Log the call config and use that here instead.
1197 static const uint32_t kDefaultStartBitrateBps = 300000;
1198 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1199
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001200 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1201 PointStyle::kHighlight);
1202 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1203 PointStyle::kHighlight);
1204 TimeSeries acked_estimate_time_series(
1205 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001206
1207 auto rtp_iterator = outgoing_rtp.begin();
1208 auto rtcp_iterator = incoming_rtcp.begin();
1209
1210 auto NextRtpTime = [&]() {
1211 if (rtp_iterator != outgoing_rtp.end())
1212 return static_cast<int64_t>(rtp_iterator->first);
1213 return std::numeric_limits<int64_t>::max();
1214 };
1215
1216 auto NextRtcpTime = [&]() {
1217 if (rtcp_iterator != incoming_rtcp.end())
1218 return static_cast<int64_t>(rtcp_iterator->first);
1219 return std::numeric_limits<int64_t>::max();
1220 };
1221
1222 auto NextProcessTime = [&]() {
1223 if (rtcp_iterator != incoming_rtcp.end() ||
1224 rtp_iterator != outgoing_rtp.end()) {
1225 return clock.TimeInMicroseconds() +
1226 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1227 }
1228 return std::numeric_limits<int64_t>::max();
1229 };
1230
Stefan Holmer492ee282016-10-27 17:19:20 +02001231 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001232#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1233 // The event_log_visualizer should normally not be compiled with
1234 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
1235 // However, compiling with BWE_TEST_LOGGING, runnning with --plot_sendside_bwe
1236 // and piping the output to plot_dynamics.py can be used as a hack to get the
1237 // internal state of various BWE components. In this case, it is important
1238 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
1239 // SendSideCongestionController since that would lead to duplicate outputs.
1240 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
1241 rtc::MakeUnique<BitrateEstimator>());
1242#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001243 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001244 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001245 while (time_us != std::numeric_limits<int64_t>::max()) {
1246 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1247 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001248 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001249 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1250 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001251 cc.OnTransportFeedback(
1252 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1253 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001254 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001255 rtc::Optional<uint32_t> bitrate_bps;
1256 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001257#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1258 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
1259#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
elad.alonf9490002017-03-06 05:32:21 -08001260 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001261 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1262 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1263 }
Stefan Holmer60e43462016-09-07 09:58:20 +02001264 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1265 1000000;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001266 float y = bitrate_bps.value_or(0) / 1000;
Stefan Holmer60e43462016-09-07 09:58:20 +02001267 acked_time_series.points.emplace_back(x, y);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001268#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1269 y = acknowledged_bitrate_estimator.bitrate_bps().value_or(0) / 1000;
1270 acked_estimate_time_series.points.emplace_back(x, y);
1271#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001272 }
1273 ++rtcp_iterator;
1274 }
1275 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001276 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001277 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1278 if (rtp.header.extension.hasTransportSequenceNumber) {
1279 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001280 cc.AddPacket(rtp.header.ssrc,
1281 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001282 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001283 rtc::SentPacket sent_packet(
1284 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1285 cc.OnSentPacket(sent_packet);
1286 }
1287 ++rtp_iterator;
1288 }
stefanc3de0332016-08-02 07:22:17 -07001289 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1290 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001291 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001292 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001293 if (observer.GetAndResetBitrateUpdated() ||
1294 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001295 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001296 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1297 1000000;
1298 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001299 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001300 }
1301 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1302 }
1303 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001304 plot->AppendTimeSeries(std::move(time_series));
1305 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001306 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001307
tereliusdc35dcd2016-08-01 12:03:27 -07001308 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1309 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001310 plot->SetTitle("Simulated send-side BWE behavior");
1311}
1312
1313void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
1314 class RembInterceptingPacketRouter : public PacketRouter {
1315 public:
1316 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1317 uint32_t bitrate_bps) override {
1318 last_bitrate_bps_ = bitrate_bps;
1319 bitrate_updated_ = true;
1320 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1321 }
1322 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1323 bool GetAndResetBitrateUpdated() {
1324 bool bitrate_updated = bitrate_updated_;
1325 bitrate_updated_ = false;
1326 return bitrate_updated;
1327 }
1328
1329 private:
1330 uint32_t last_bitrate_bps_;
1331 bool bitrate_updated_;
1332 };
1333
1334 std::multimap<uint64_t, const LoggedRtpPacket*> incoming_rtp;
1335
1336 for (const auto& kv : rtp_packets_) {
1337 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket &&
1338 IsVideoSsrc(kv.first)) {
1339 for (const LoggedRtpPacket& rtp_packet : kv.second)
1340 incoming_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1341 }
1342 }
1343
1344 SimulatedClock clock(0);
1345 RembInterceptingPacketRouter packet_router;
1346 // TODO(terelius): The PacketRrouter is the used as the RemoteBitrateObserver.
1347 // Is this intentional?
1348 ReceiveSideCongestionController rscc(&clock, &packet_router);
1349 // TODO(holmer): Log the call config and use that here instead.
1350 // static const uint32_t kDefaultStartBitrateBps = 300000;
1351 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1352
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001353 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1354 PointStyle::kHighlight);
1355 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001356
1357 RateStatistics acked_bitrate(250, 8000);
1358 int64_t last_update_us = 0;
1359 for (const auto& kv : incoming_rtp) {
1360 const LoggedRtpPacket& packet = *kv.second;
1361 int64_t arrival_time_ms = packet.timestamp / 1000;
1362 size_t payload = packet.total_length; /*Should subtract header?*/
1363 clock.AdvanceTimeMicroseconds(packet.timestamp -
1364 clock.TimeInMicroseconds());
1365 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.header);
1366 acked_bitrate.Update(payload, arrival_time_ms);
1367 rtc::Optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
1368 if (bitrate_bps) {
1369 uint32_t y = *bitrate_bps / 1000;
1370 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1371 1000000;
1372 acked_time_series.points.emplace_back(x, y);
1373 }
1374 if (packet_router.GetAndResetBitrateUpdated() ||
1375 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1376 uint32_t y = packet_router.last_bitrate_bps() / 1000;
1377 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1378 1000000;
1379 time_series.points.emplace_back(x, y);
1380 last_update_us = clock.TimeInMicroseconds();
1381 }
1382 }
1383 // Add the data set to the plot.
1384 plot->AppendTimeSeries(std::move(time_series));
1385 plot->AppendTimeSeries(std::move(acked_time_series));
1386
1387 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1388 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1389 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001390}
1391
tereliuse34c19c2016-08-15 08:47:14 -07001392void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001393 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1394 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001395
1396 for (const auto& kv : rtp_packets_) {
1397 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1398 for (const LoggedRtpPacket& rtp_packet : kv.second)
1399 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1400 }
1401 }
1402
1403 for (const auto& kv : rtcp_packets_) {
1404 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1405 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1406 incoming_rtcp.insert(
1407 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1408 }
1409 }
1410
1411 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001412 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001413
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001414 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1415 PointStyle::kHighlight);
1416 TimeSeries time_series("Network Delay Change", LineStyle::kLine,
1417 PointStyle::kHighlight);
stefanc3de0332016-08-02 07:22:17 -07001418 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1419
1420 auto rtp_iterator = outgoing_rtp.begin();
1421 auto rtcp_iterator = incoming_rtcp.begin();
1422
1423 auto NextRtpTime = [&]() {
1424 if (rtp_iterator != outgoing_rtp.end())
1425 return static_cast<int64_t>(rtp_iterator->first);
1426 return std::numeric_limits<int64_t>::max();
1427 };
1428
1429 auto NextRtcpTime = [&]() {
1430 if (rtcp_iterator != incoming_rtcp.end())
1431 return static_cast<int64_t>(rtcp_iterator->first);
1432 return std::numeric_limits<int64_t>::max();
1433 };
1434
1435 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
stefana0a8ed72017-09-06 02:06:32 -07001436 int64_t prev_y = 0;
stefanc3de0332016-08-02 07:22:17 -07001437 while (time_us != std::numeric_limits<int64_t>::max()) {
1438 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1439 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1440 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1441 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1442 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001443 feedback_adapter.OnTransportFeedback(
1444 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001445 std::vector<PacketFeedback> feedback =
1446 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001447 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001448 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001449 float x =
1450 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1451 1000000;
srtee0572e52017-11-30 09:59:33 +01001452 if (packet.send_time_ms == PacketFeedback::kNoSendTime) {
stefana0a8ed72017-09-06 02:06:32 -07001453 late_feedback_series.points.emplace_back(x, prev_y);
1454 continue;
1455 }
1456 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1457 prev_y = y;
stefanc3de0332016-08-02 07:22:17 -07001458 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1459 time_series.points.emplace_back(x, y);
1460 }
1461 }
1462 ++rtcp_iterator;
1463 }
1464 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1465 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1466 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1467 if (rtp.header.extension.hasTransportSequenceNumber) {
1468 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001469 feedback_adapter.AddPacket(rtp.header.ssrc,
1470 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001471 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001472 feedback_adapter.OnSentPacket(
1473 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1474 }
1475 ++rtp_iterator;
1476 }
1477 time_us = std::min(NextRtpTime(), NextRtcpTime());
1478 }
1479 // We assume that the base network delay (w/o queues) is the min delay
1480 // observed during the call.
1481 for (TimeSeriesPoint& point : time_series.points)
1482 point.y -= estimated_base_delay_ms;
stefana0a8ed72017-09-06 02:06:32 -07001483 for (TimeSeriesPoint& point : late_feedback_series.points)
1484 point.y -= estimated_base_delay_ms;
stefanc3de0332016-08-02 07:22:17 -07001485 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001486 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1487 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001488
1489 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1490 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1491 plot->SetTitle("Network Delay Change.");
1492}
stefan08383272016-12-20 08:51:52 -08001493
1494std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1495 const {
1496 std::vector<std::pair<int64_t, int64_t>> timestamps;
1497 size_t largest_stream_size = 0;
1498 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1499 // Find the incoming video stream with the most number of packets that is
1500 // not rtx.
1501 for (const auto& kv : rtp_packets_) {
1502 if (kv.first.GetDirection() == kIncomingPacket &&
1503 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1504 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1505 kv.second.size() > largest_stream_size) {
1506 largest_stream_size = kv.second.size();
1507 largest_video_stream = &kv.second;
1508 }
1509 }
1510 if (largest_video_stream == nullptr) {
1511 for (auto& packet : *largest_video_stream) {
1512 if (packet.header.markerBit) {
1513 int64_t capture_ms = packet.header.timestamp / 90.0;
1514 int64_t arrival_ms = packet.timestamp / 1000.0;
1515 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1516 }
1517 }
1518 }
1519 return timestamps;
1520}
stefane372d3c2017-02-02 08:04:18 -08001521
Bjorn Terelius0295a962017-10-25 17:42:41 +02001522void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
1523 for (const auto& kv : rtp_packets_) {
1524 const std::vector<LoggedRtpPacket>& packets = kv.second;
1525 StreamId stream_id = kv.first;
Bjorn Tereliusb87c27e2017-11-09 11:55:51 +01001526 if (stream_id.GetDirection() == kIncomingPacket)
1527 continue;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001528
1529 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001530 RTC_LOG(LS_WARNING)
1531 << "Can't estimate a the RTP clock frequency or the "
1532 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001533 continue;
1534 }
1535 rtc::Optional<uint32_t> estimated_frequency =
1536 EstimateRtpClockFrequency(packets);
1537 if (!estimated_frequency)
1538 continue;
1539 if (IsVideoSsrc(stream_id) && *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001540 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001541 << "Video stream should use a 90 kHz clock but appears to use "
1542 << *estimated_frequency / 1000 << ". Discarding.";
1543 continue;
1544 }
1545
1546 TimeSeries pacer_delay_series(
1547 GetStreamName(stream_id) + "(" +
1548 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001549 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001550 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1551 uint64_t first_capture_timestamp =
1552 timestamp_unwrapper.Unwrap(packets.front().header.timestamp);
1553 uint64_t first_send_timestamp = packets.front().timestamp;
1554 for (LoggedRtpPacket packet : packets) {
1555 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
1556 packet.header.timestamp)) -
1557 first_capture_timestamp) /
1558 *estimated_frequency * 1000;
1559 double send_time_ms =
1560 static_cast<double>(packet.timestamp - first_send_timestamp) / 1000;
1561 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1562 float y = send_time_ms - capture_time_ms;
1563 pacer_delay_series.points.emplace_back(x, y);
1564 }
1565 plot->AppendTimeSeries(std::move(pacer_delay_series));
1566 }
1567
1568 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1569 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1570 plot->SetTitle(
1571 "Delay from capture to send time. (First packet normalized to 0.)");
1572}
1573
stefane372d3c2017-02-02 08:04:18 -08001574void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1575 for (const auto& kv : rtp_packets_) {
1576 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1577 StreamId stream_id = kv.first;
1578
1579 {
terelius23c595a2017-03-15 01:59:12 -07001580 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001581 LineStyle::kLine, PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001582 for (LoggedRtpPacket packet : rtp_packets) {
1583 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1584 float y = packet.header.timestamp;
1585 timestamp_data.points.emplace_back(x, y);
1586 }
philipel35ba9bd2017-04-19 05:58:51 -07001587 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001588 }
1589
1590 {
1591 auto kv = rtcp_packets_.find(stream_id);
1592 if (kv != rtcp_packets_.end()) {
1593 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001594 TimeSeries timestamp_data(
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001595 GetStreamName(stream_id) + " rtcp capture-time", LineStyle::kLine,
1596 PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001597 for (const LoggedRtcpPacket& rtcp : packets) {
1598 if (rtcp.type != kRtcpSr)
1599 continue;
1600 rtcp::SenderReport* sr;
1601 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1602 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1603 float y = sr->rtp_timestamp();
1604 timestamp_data.points.emplace_back(x, y);
1605 }
philipel35ba9bd2017-04-19 05:58:51 -07001606 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001607 }
1608 }
1609 }
1610
1611 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1612 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1613 plot->SetTitle("Timestamps");
1614}
michaelt6e5b2192017-02-22 07:33:27 -08001615
1616void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001617 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1618 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001619 ProcessPoints<AudioNetworkAdaptationEvent>(
1620 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001621 if (ana_event.config.bitrate_bps)
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001622 return static_cast<float>(*ana_event.config.bitrate_bps);
1623 return rtc::nullopt;
terelius53dc23c2017-03-13 05:24:05 -07001624 },
philipel35ba9bd2017-04-19 05:58:51 -07001625 audio_network_adaptation_events_, begin_time_, &time_series);
1626 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001627 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1628 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1629 plot->SetTitle("Reported audio encoder target bitrate");
1630}
1631
1632void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001633 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1634 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001635 ProcessPoints<AudioNetworkAdaptationEvent>(
1636 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001637 if (ana_event.config.frame_length_ms)
1638 return rtc::Optional<float>(
1639 static_cast<float>(*ana_event.config.frame_length_ms));
1640 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001641 },
philipel35ba9bd2017-04-19 05:58:51 -07001642 audio_network_adaptation_events_, begin_time_, &time_series);
1643 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001644 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1645 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1646 plot->SetTitle("Reported audio encoder frame length");
1647}
1648
terelius2ee076d2017-08-15 02:04:02 -07001649void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001650 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001651 LineStyle::kLine, PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001652 ProcessPoints<AudioNetworkAdaptationEvent>(
1653 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001654 if (ana_event.config.uplink_packet_loss_fraction)
1655 return rtc::Optional<float>(static_cast<float>(
1656 *ana_event.config.uplink_packet_loss_fraction));
1657 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001658 },
philipel35ba9bd2017-04-19 05:58:51 -07001659 audio_network_adaptation_events_, begin_time_, &time_series);
1660 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001661 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1662 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1663 kTopMargin);
1664 plot->SetTitle("Reported audio encoder lost packets");
1665}
1666
1667void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001668 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1669 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001670 ProcessPoints<AudioNetworkAdaptationEvent>(
1671 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001672 if (ana_event.config.enable_fec)
1673 return rtc::Optional<float>(
1674 static_cast<float>(*ana_event.config.enable_fec));
1675 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001676 },
philipel35ba9bd2017-04-19 05:58:51 -07001677 audio_network_adaptation_events_, begin_time_, &time_series);
1678 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001679 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1680 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1681 plot->SetTitle("Reported audio encoder FEC");
1682}
1683
1684void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001685 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1686 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001687 ProcessPoints<AudioNetworkAdaptationEvent>(
1688 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001689 if (ana_event.config.enable_dtx)
1690 return rtc::Optional<float>(
1691 static_cast<float>(*ana_event.config.enable_dtx));
1692 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001693 },
philipel35ba9bd2017-04-19 05:58:51 -07001694 audio_network_adaptation_events_, begin_time_, &time_series);
1695 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001696 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1697 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1698 plot->SetTitle("Reported audio encoder DTX");
1699}
1700
1701void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001702 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1703 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001704 ProcessPoints<AudioNetworkAdaptationEvent>(
1705 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001706 if (ana_event.config.num_channels)
1707 return rtc::Optional<float>(
1708 static_cast<float>(*ana_event.config.num_channels));
1709 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001710 },
philipel35ba9bd2017-04-19 05:58:51 -07001711 audio_network_adaptation_events_, begin_time_, &time_series);
1712 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001713 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1714 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1715 kBottomMargin, kTopMargin);
1716 plot->SetTitle("Reported audio encoder number of channels");
1717}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001718
1719class NetEqStreamInput : public test::NetEqInput {
1720 public:
1721 // Does not take any ownership, and all pointers must refer to valid objects
1722 // that outlive the one constructed.
1723 NetEqStreamInput(const std::vector<LoggedRtpPacket>* packet_stream,
1724 const std::vector<uint64_t>* output_events_us,
1725 rtc::Optional<uint64_t> end_time_us)
1726 : packet_stream_(*packet_stream),
1727 packet_stream_it_(packet_stream_.begin()),
1728 output_events_us_it_(output_events_us->begin()),
1729 output_events_us_end_(output_events_us->end()),
1730 end_time_us_(end_time_us) {
1731 RTC_DCHECK(packet_stream);
1732 RTC_DCHECK(output_events_us);
1733 }
1734
1735 rtc::Optional<int64_t> NextPacketTime() const override {
1736 if (packet_stream_it_ == packet_stream_.end()) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001737 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001738 }
1739 if (end_time_us_ && packet_stream_it_->timestamp > *end_time_us_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001740 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001741 }
1742 // Convert from us to ms.
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001743 return packet_stream_it_->timestamp / 1000;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001744 }
1745
1746 rtc::Optional<int64_t> NextOutputEventTime() const override {
1747 if (output_events_us_it_ == output_events_us_end_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001748 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001749 }
1750 if (end_time_us_ && *output_events_us_it_ > *end_time_us_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001751 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001752 }
1753 // Convert from us to ms.
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001754 return rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001755 }
1756
1757 std::unique_ptr<PacketData> PopPacket() override {
1758 if (packet_stream_it_ == packet_stream_.end()) {
1759 return std::unique_ptr<PacketData>();
1760 }
1761 std::unique_ptr<PacketData> packet_data(new PacketData());
1762 packet_data->header = packet_stream_it_->header;
1763 // Convert from us to ms.
1764 packet_data->time_ms = packet_stream_it_->timestamp / 1000.0;
1765
1766 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1767 // length according to the virtual length.
1768 packet_data->payload.SetSize(packet_stream_it_->total_length);
1769 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1770
1771 ++packet_stream_it_;
1772 return packet_data;
1773 }
1774
1775 void AdvanceOutputEvent() override {
1776 if (output_events_us_it_ != output_events_us_end_) {
1777 ++output_events_us_it_;
1778 }
1779 }
1780
1781 bool ended() const override { return !NextEventTime(); }
1782
1783 rtc::Optional<RTPHeader> NextHeader() const override {
1784 if (packet_stream_it_ == packet_stream_.end()) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001785 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001786 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001787 return packet_stream_it_->header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001788 }
1789
1790 private:
1791 const std::vector<LoggedRtpPacket>& packet_stream_;
1792 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_;
1793 std::vector<uint64_t>::const_iterator output_events_us_it_;
1794 const std::vector<uint64_t>::const_iterator output_events_us_end_;
1795 const rtc::Optional<uint64_t> end_time_us_;
1796};
1797
1798namespace {
1799// Creates a NetEq test object and all necessary input and output helpers. Runs
1800// the test and returns the NetEqDelayAnalyzer object that was used to
1801// instrument the test.
1802std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun(
1803 const std::vector<LoggedRtpPacket>* packet_stream,
1804 const std::vector<uint64_t>* output_events_us,
1805 rtc::Optional<uint64_t> end_time_us,
1806 const std::string& replacement_file_name,
1807 int file_sample_rate_hz) {
1808 std::unique_ptr<test::NetEqInput> input(
1809 new NetEqStreamInput(packet_stream, output_events_us, end_time_us));
1810
1811 constexpr int kReplacementPt = 127;
1812 std::set<uint8_t> cn_types;
1813 std::set<uint8_t> forbidden_types;
1814 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1815 cn_types, forbidden_types));
1816
1817 NetEq::Config config;
1818 config.max_packets_in_buffer = 200;
1819 config.enable_fast_accelerate = true;
1820
1821 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1822
1823 test::NetEqTest::DecoderMap codecs;
1824
1825 // Create a "replacement decoder" that produces the decoded audio by reading
1826 // from a file rather than from the encoded payloads.
1827 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1828 new test::ResampleInputAudioFile(replacement_file_name,
1829 file_sample_rate_hz));
1830 replacement_file->set_output_rate_hz(48000);
1831 std::unique_ptr<AudioDecoder> replacement_decoder(
1832 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1833 test::NetEqTest::ExtDecoderMap ext_codecs;
1834 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1835 NetEqDecoder::kDecoderArbitrary,
1836 "replacement codec"};
1837
1838 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1839 new test::NetEqDelayAnalyzer);
1840 test::DefaultNetEqTestErrorCallback error_cb;
1841 test::NetEqTest::Callbacks callbacks;
1842 callbacks.error_callback = &error_cb;
1843 callbacks.post_insert_packet = delay_cb.get();
1844 callbacks.get_audio_callback = delay_cb.get();
1845
1846 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1847 std::move(output), callbacks);
1848 test.Run();
1849 return delay_cb;
1850}
1851} // namespace
1852
1853// Plots the jitter buffer delay profile. This will plot only for the first
1854// incoming audio SSRC. If the stream contains more than one incoming audio
1855// SSRC, all but the first will be ignored.
1856void EventLogAnalyzer::CreateAudioJitterBufferGraph(
1857 const std::string& replacement_file_name,
1858 int file_sample_rate_hz,
1859 Plot* plot) {
1860 const auto& incoming_audio_kv = std::find_if(
1861 rtp_packets_.begin(), rtp_packets_.end(),
1862 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) {
1863 return kv.first.GetDirection() == kIncomingPacket &&
1864 this->IsAudioSsrc(kv.first);
1865 });
1866 if (incoming_audio_kv == rtp_packets_.end()) {
1867 // No incoming audio stream found.
1868 return;
1869 }
1870
1871 const uint32_t ssrc = incoming_audio_kv->first.GetSsrc();
1872
1873 std::map<uint32_t, std::vector<uint64_t>>::const_iterator output_events_it =
1874 audio_playout_events_.find(ssrc);
1875 if (output_events_it == audio_playout_events_.end()) {
1876 // Could not find output events with SSRC matching the input audio stream.
1877 // Using the first available stream of output events.
1878 output_events_it = audio_playout_events_.cbegin();
1879 }
1880
1881 rtc::Optional<uint64_t> end_time_us =
1882 log_segments_.empty()
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001883 ? rtc::nullopt
henrik.lundin3c938fc2017-06-14 06:09:58 -07001884 : rtc::Optional<uint64_t>(log_segments_.front().second);
1885
1886 auto delay_cb = CreateNetEqTestAndRun(
1887 &incoming_audio_kv->second, &output_events_it->second, end_time_us,
1888 replacement_file_name, file_sample_rate_hz);
1889
1890 std::vector<float> send_times_s;
1891 std::vector<float> arrival_delay_ms;
1892 std::vector<float> corrected_arrival_delay_ms;
1893 std::vector<rtc::Optional<float>> playout_delay_ms;
1894 std::vector<rtc::Optional<float>> target_delay_ms;
1895 delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms,
1896 &corrected_arrival_delay_ms, &playout_delay_ms,
1897 &target_delay_ms);
1898 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size());
1899 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size());
1900 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size());
1901 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size());
1902
1903 std::map<StreamId, TimeSeries> time_series_packet_arrival;
1904 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival;
1905 std::map<StreamId, TimeSeries> time_series_play_time;
1906 std::map<StreamId, TimeSeries> time_series_target_time;
1907 float min_y_axis = 0.f;
1908 float max_y_axis = 0.f;
1909 const StreamId stream_id = incoming_audio_kv->first;
1910 for (size_t i = 0; i < send_times_s.size(); ++i) {
1911 time_series_packet_arrival[stream_id].points.emplace_back(
1912 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i]));
1913 time_series_relative_packet_arrival[stream_id].points.emplace_back(
1914 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i]));
1915 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]);
1916 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]);
1917 if (playout_delay_ms[i]) {
1918 time_series_play_time[stream_id].points.emplace_back(
1919 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i]));
1920 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]);
1921 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]);
1922 }
1923 if (target_delay_ms[i]) {
1924 time_series_target_time[stream_id].points.emplace_back(
1925 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i]));
1926 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]);
1927 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]);
1928 }
1929 }
1930
1931 // This code is adapted for a single stream. The creation of the streams above
1932 // guarantee that no more than one steam is included. If multiple streams are
1933 // to be plotted, they should likely be given distinct labels below.
1934 RTC_DCHECK_EQ(time_series_relative_packet_arrival.size(), 1);
1935 for (auto& series : time_series_relative_packet_arrival) {
1936 series.second.label = "Relative packet arrival delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001937 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001938 plot->AppendTimeSeries(std::move(series.second));
1939 }
1940 RTC_DCHECK_EQ(time_series_play_time.size(), 1);
1941 for (auto& series : time_series_play_time) {
1942 series.second.label = "Playout delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001943 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001944 plot->AppendTimeSeries(std::move(series.second));
1945 }
1946 RTC_DCHECK_EQ(time_series_target_time.size(), 1);
1947 for (auto& series : time_series_target_time) {
1948 series.second.label = "Target delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001949 series.second.line_style = LineStyle::kLine;
1950 series.second.point_style = PointStyle::kHighlight;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001951 plot->AppendTimeSeries(std::move(series.second));
1952 }
1953
1954 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1955 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin,
1956 kTopMargin);
1957 plot->SetTitle("NetEq timing");
1958}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01001959
1960void EventLogAnalyzer::Notification(
1961 std::unique_ptr<TriageNotification> notification) {
1962 notifications_.push_back(std::move(notification));
1963}
1964
1965void EventLogAnalyzer::PrintNotifications(FILE* file) {
1966 if (notifications_.size() == 0)
1967 return;
1968 fprintf(file, "========== TRIAGE NOTIFICATIONS ==========\n");
1969 for (const auto& notification : notifications_) {
1970 rtc::Optional<float> call_timestamp = notification->Time();
1971 if (call_timestamp.has_value()) {
1972 fprintf(file, "%3.3lf s : %s\n", call_timestamp.value(),
1973 notification->ToString().c_str());
1974 } else {
1975 fprintf(file, " : %s\n", notification->ToString().c_str());
1976 }
1977 }
1978 fprintf(file, "========== END TRIAGE NOTIFICATIONS ==========\n");
1979}
1980
1981// TODO(terelius): Notifications could possibly be generated by the same code
1982// that produces the graphs. There is some code duplication that could be
1983// avoided, but that might be solved anyway when we move functionality from the
1984// analyzer to the parser.
1985void EventLogAnalyzer::CreateTriageNotifications() {
1986 uint64_t end_time_us = log_segments_.empty()
1987 ? std::numeric_limits<uint64_t>::max()
1988 : log_segments_.front().second;
1989 // Check for gaps in sequence numbers and capture timestamps.
1990 for (auto& kv : rtp_packets_) {
1991 StreamId stream_id = kv.first;
1992 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1993
1994 SeqNumUnwrapper<uint16_t> seq_no_unwrapper;
1995 rtc::Optional<int64_t> last_seq_no;
1996 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1997 rtc::Optional<int64_t> last_timestamp;
1998 for (const auto& packet : packet_stream) {
1999 if (packet.timestamp > end_time_us) {
2000 // Only process the first (LOG_START, LOG_END) segment.
2001 break;
2002 }
2003 int64_t seq_no = seq_no_unwrapper.Unwrap(packet.header.sequenceNumber);
2004 if (last_seq_no.has_value() &&
2005 std::abs(seq_no - last_seq_no.value()) > 1000) {
2006 // With roughly 100 packets per second (~800kbps), this would require 10
2007 // seconds without data to trigger incorrectly.
2008 if (stream_id.GetDirection() == kIncomingPacket) {
2009 Notification(rtc::MakeUnique<IncomingSeqNoJump>(
2010 ToCallTime(packet.timestamp), packet.header.ssrc));
2011 } else {
2012 Notification(rtc::MakeUnique<OutgoingSeqNoJump>(
2013 ToCallTime(packet.timestamp), packet.header.ssrc));
2014 }
2015 }
2016 last_seq_no.emplace(seq_no);
2017 int64_t timestamp = timestamp_unwrapper.Unwrap(packet.header.timestamp);
2018 if (last_timestamp.has_value() &&
2019 std::abs(timestamp - last_timestamp.value()) > 900000) {
2020 // With a 90 kHz clock, this would require 10 seconds without data to
2021 // trigger incorrectly.
2022 if (stream_id.GetDirection() == kIncomingPacket) {
2023 Notification(rtc::MakeUnique<IncomingCaptureTimeJump>(
2024 ToCallTime(packet.timestamp), packet.header.ssrc));
2025 } else {
2026 Notification(rtc::MakeUnique<OutgoingCaptureTimeJump>(
2027 ToCallTime(packet.timestamp), packet.header.ssrc));
2028 }
2029 }
2030 last_timestamp.emplace(timestamp);
2031 }
2032 }
2033
2034 // Check for gaps in RTP and RTCP streams
2035 for (const auto direction :
2036 {PacketDirection::kIncomingPacket, PacketDirection::kOutgoingPacket}) {
2037 // TODO(terelius): The parser could provide a list of all packets, ordered
2038 // by time, for each direction.
2039 std::multimap<uint64_t, const LoggedRtpPacket*> rtp_in_direction;
2040 for (const auto& kv : rtp_packets_) {
2041 if (kv.first.GetDirection() == direction) {
2042 for (const LoggedRtpPacket& rtp_packet : kv.second)
2043 rtp_in_direction.emplace(rtp_packet.timestamp, &rtp_packet);
2044 }
2045 }
2046 rtc::Optional<uint64_t> last_rtp_packet;
2047 for (const auto& kv : rtp_in_direction) {
2048 uint64_t timestamp = kv.first;
2049 if (timestamp > end_time_us) {
2050 // Only process the first (LOG_START, LOG_END) segment.
2051 break;
2052 }
2053 int64_t duration = timestamp - last_rtp_packet.value_or(0);
2054 if (last_rtp_packet.has_value() && duration > 500000) {
2055 // No incoming packet for more than 500 ms.
2056 if (direction == kIncomingPacket) {
2057 Notification(rtc::MakeUnique<IncomingRtpReceiveTimeGap>(
2058 ToCallTime(timestamp), duration / 1000));
2059 } else {
2060 Notification(rtc::MakeUnique<OutgoingRtpSendTimeGap>(
2061 ToCallTime(timestamp), duration / 1000));
2062 }
2063 }
2064 last_rtp_packet.emplace(timestamp);
2065 }
2066
2067 // TODO(terelius): The parser could provide a list of all packets, ordered
2068 // by time, for each direction.
2069 std::multimap<uint64_t, const LoggedRtcpPacket*> rtcp_in_direction;
2070 for (const auto& kv : rtcp_packets_) {
2071 if (kv.first.GetDirection() == direction) {
2072 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
2073 rtcp_in_direction.emplace(rtcp_packet.timestamp, &rtcp_packet);
2074 }
2075 }
2076 rtc::Optional<uint64_t> last_incoming_rtcp_packet;
2077 for (const auto& kv : rtcp_in_direction) {
2078 uint64_t timestamp = kv.first;
2079 if (timestamp > end_time_us) {
2080 // Only process the first (LOG_START, LOG_END) segment.
2081 break;
2082 }
2083 int64_t duration = timestamp - last_incoming_rtcp_packet.value_or(0);
2084 if (last_incoming_rtcp_packet.has_value() && duration > 2000000) {
2085 // No incoming feedback for more than 2000 ms.
2086 if (direction == kIncomingPacket) {
2087 Notification(rtc::MakeUnique<IncomingRtcpReceiveTimeGap>(
2088 ToCallTime(timestamp), duration / 1000));
2089 } else {
2090 Notification(rtc::MakeUnique<OutgoingRtcpSendTimeGap>(
2091 ToCallTime(timestamp), duration / 1000));
2092 }
2093 }
2094 last_incoming_rtcp_packet.emplace(timestamp);
2095 }
2096 }
2097
2098 // Loss feedback
2099 int64_t total_lost_packets = 0;
2100 int64_t total_expected_packets = 0;
2101 for (auto& bwe_update : bwe_loss_updates_) {
2102 if (bwe_update.timestamp > end_time_us) {
2103 // Only process the first (LOG_START, LOG_END) segment.
2104 break;
2105 }
2106 int64_t lost_packets = static_cast<double>(bwe_update.fraction_loss) / 255 *
2107 bwe_update.expected_packets;
2108 total_lost_packets += lost_packets;
2109 total_expected_packets += bwe_update.expected_packets;
2110 }
2111 double avg_outgoing_loss =
2112 static_cast<double>(total_lost_packets) / total_expected_packets;
2113 if (avg_outgoing_loss > 0.05) {
2114 Notification(rtc::MakeUnique<OutgoingHighLoss>(avg_outgoing_loss));
2115 }
2116}
2117
terelius54ce6802016-07-13 06:44:41 -07002118} // namespace plotting
2119} // namespace webrtc