blob: 21bc5808e1b3df9185ab7ed3aeac3d9f6ba3b0b4 [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 }
terelius54ce6802016-07-13 06:44:41 -0700542}
543
Niels Möller245f17e2017-08-21 10:45:07 +0200544class BitrateObserver : public SendSideCongestionController::Observer,
Stefan Holmer13181032016-07-29 14:48:54 +0200545 public RemoteBitrateObserver {
546 public:
547 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
548
549 void OnNetworkChanged(uint32_t bitrate_bps,
550 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800551 int64_t rtt_ms,
552 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200553 last_bitrate_bps_ = bitrate_bps;
554 bitrate_updated_ = true;
555 }
556
557 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
558 uint32_t bitrate) override {}
559
560 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
561 bool GetAndResetBitrateUpdated() {
562 bool bitrate_updated = bitrate_updated_;
563 bitrate_updated_ = false;
564 return bitrate_updated;
565 }
566
567 private:
568 uint32_t last_bitrate_bps_;
569 bool bitrate_updated_;
570};
571
Stefan Holmer99f8e082016-09-09 13:37:50 +0200572bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700573 return rtx_ssrcs_.count(stream_id) == 1;
574}
575
Stefan Holmer99f8e082016-09-09 13:37:50 +0200576bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700577 return video_ssrcs_.count(stream_id) == 1;
578}
579
Stefan Holmer99f8e082016-09-09 13:37:50 +0200580bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700581 return audio_ssrcs_.count(stream_id) == 1;
582}
583
Stefan Holmer99f8e082016-09-09 13:37:50 +0200584std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
585 std::stringstream name;
586 if (IsAudioSsrc(stream_id)) {
587 name << "Audio ";
588 } else if (IsVideoSsrc(stream_id)) {
589 name << "Video ";
590 } else {
591 name << "Unknown ";
592 }
593 if (IsRtxSsrc(stream_id))
594 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700595 if (stream_id.GetDirection() == kIncomingPacket) {
596 name << "(In) ";
597 } else {
598 name << "(Out) ";
599 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200600 name << SsrcToString(stream_id.GetSsrc());
601 return name.str();
602}
603
Bjorn Terelius0295a962017-10-25 17:42:41 +0200604// This is much more reliable for outgoing streams than for incoming streams.
605rtc::Optional<uint32_t> EventLogAnalyzer::EstimateRtpClockFrequency(
606 const std::vector<LoggedRtpPacket>& packets) const {
607 RTC_CHECK(packets.size() >= 2);
608 uint64_t end_time_us = log_segments_.empty()
609 ? std::numeric_limits<uint64_t>::max()
610 : log_segments_.front().second;
611 SeqNumUnwrapper<uint32_t> unwrapper;
612 uint64_t first_rtp_timestamp = unwrapper.Unwrap(packets[0].header.timestamp);
613 uint64_t first_log_timestamp = packets[0].timestamp;
614 uint64_t last_rtp_timestamp = first_rtp_timestamp;
615 uint64_t last_log_timestamp = first_log_timestamp;
616 for (size_t i = 1; i < packets.size(); i++) {
617 if (packets[i].timestamp > end_time_us)
618 break;
619 last_rtp_timestamp = unwrapper.Unwrap(packets[i].header.timestamp);
620 last_log_timestamp = packets[i].timestamp;
621 }
622 if (last_log_timestamp - first_log_timestamp < 1000000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100623 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +0200624 << "Failed to estimate RTP clock frequency: Stream too short. ("
625 << packets.size() << " packets, "
626 << last_log_timestamp - first_log_timestamp << " us)";
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100627 return rtc::nullopt;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200628 }
629 double duration =
630 static_cast<double>(last_log_timestamp - first_log_timestamp) / 1000000;
631 double estimated_frequency =
632 (last_rtp_timestamp - first_rtp_timestamp) / duration;
633 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
634 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100635 return f;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200636 }
637 }
Mirko Bonadei675513b2017-11-09 11:09:25 +0100638 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
639 << estimated_frequency
640 << "not close to any stardard RTP frequency.";
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100641 return rtc::nullopt;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200642}
643
terelius54ce6802016-07-13 06:44:41 -0700644void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
645 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700646 for (auto& kv : rtp_packets_) {
647 StreamId stream_id = kv.first;
648 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
649 // Filter on direction and SSRC.
650 if (stream_id.GetDirection() != desired_direction ||
651 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
652 continue;
terelius54ce6802016-07-13 06:44:41 -0700653 }
terelius54ce6802016-07-13 06:44:41 -0700654
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100655 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700656 ProcessPoints<LoggedRtpPacket>(
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100657 [](const LoggedRtpPacket& packet) {
terelius53dc23c2017-03-13 05:24:05 -0700658 return rtc::Optional<float>(packet.total_length);
659 },
660 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700661 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700662 }
663
tereliusdc35dcd2016-08-01 12:03:27 -0700664 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
665 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
666 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700667 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700668 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700669 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700670 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700671 }
672}
673
philipelccd74892016-09-05 02:46:25 -0700674template <typename T>
675void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
676 PacketDirection desired_direction,
677 Plot* plot,
678 const std::map<StreamId, std::vector<T>>& packets,
679 const std::string& label_prefix) {
680 for (auto& kv : packets) {
681 StreamId stream_id = kv.first;
682 const std::vector<T>& packet_stream = kv.second;
683 // Filter on direction and SSRC.
684 if (stream_id.GetDirection() != desired_direction ||
685 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
686 continue;
687 }
688
terelius23c595a2017-03-15 01:59:12 -0700689 std::string label = label_prefix + " " + GetStreamName(stream_id);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100690 TimeSeries time_series(label, LineStyle::kStep);
philipelccd74892016-09-05 02:46:25 -0700691 for (size_t i = 0; i < packet_stream.size(); i++) {
692 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
693 1000000;
philipelccd74892016-09-05 02:46:25 -0700694 time_series.points.emplace_back(x, i + 1);
695 }
696
philipel35ba9bd2017-04-19 05:58:51 -0700697 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700698 }
699}
700
701void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
702 PacketDirection desired_direction,
703 Plot* plot) {
704 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
705 "RTP");
706 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
707 "RTCP");
708
709 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
710 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
711 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
712 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
713 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
714 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
715 }
716}
717
terelius54ce6802016-07-13 06:44:41 -0700718// For each SSRC, plot the time between the consecutive playouts.
719void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
720 std::map<uint32_t, TimeSeries> time_series;
721 std::map<uint32_t, uint64_t> last_playout;
722
723 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700724
725 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
726 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
727 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
728 parsed_log_.GetAudioPlayout(i, &ssrc);
729 uint64_t timestamp = parsed_log_.GetTimestamp(i);
730 if (MatchingSsrc(ssrc, desired_ssrc_)) {
731 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
732 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
733 if (time_series[ssrc].points.size() == 0) {
734 // There were no previusly logged playout for this SSRC.
735 // Generate a point, but place it on the x-axis.
736 y = 0;
737 }
terelius54ce6802016-07-13 06:44:41 -0700738 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
739 last_playout[ssrc] = timestamp;
740 }
741 }
742 }
743
744 // Set labels and put in graph.
745 for (auto& kv : time_series) {
746 kv.second.label = SsrcToString(kv.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100747 kv.second.line_style = LineStyle::kBar;
philipel35ba9bd2017-04-19 05:58:51 -0700748 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700749 }
750
tereliusdc35dcd2016-08-01 12:03:27 -0700751 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
752 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
753 kTopMargin);
754 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700755}
756
ivocaac9d6f2016-09-22 07:01:47 -0700757// For audio SSRCs, plot the audio level.
758void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
759 std::map<StreamId, TimeSeries> time_series;
760
761 for (auto& kv : rtp_packets_) {
762 StreamId stream_id = kv.first;
763 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
764 // TODO(ivoc): When audio send/receive configs are stored in the event
765 // log, a check should be added here to only process audio
766 // streams. Tracking bug: webrtc:6399
767 for (auto& packet : packet_stream) {
768 if (packet.header.extension.hasAudioLevel) {
769 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
770 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
771 // Here we convert it to dBov.
772 float y = static_cast<float>(-packet.header.extension.audioLevel);
773 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
774 }
775 }
776 }
777
778 for (auto& series : time_series) {
779 series.second.label = GetStreamName(series.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100780 series.second.line_style = LineStyle::kLine;
philipel35ba9bd2017-04-19 05:58:51 -0700781 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700782 }
783
784 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800785 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700786 kTopMargin);
787 plot->SetTitle("Audio level");
788}
789
terelius54ce6802016-07-13 06:44:41 -0700790// For each SSRC, plot the time between the consecutive playouts.
791void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700792 for (auto& kv : rtp_packets_) {
793 StreamId stream_id = kv.first;
794 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
795 // Filter on direction and SSRC.
796 if (stream_id.GetDirection() != kIncomingPacket ||
797 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
798 continue;
terelius54ce6802016-07-13 06:44:41 -0700799 }
terelius54ce6802016-07-13 06:44:41 -0700800
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100801 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700802 ProcessPairs<LoggedRtpPacket, float>(
803 [](const LoggedRtpPacket& old_packet,
804 const LoggedRtpPacket& new_packet) {
805 int64_t diff =
806 WrappingDifference(new_packet.header.sequenceNumber,
807 old_packet.header.sequenceNumber, 1ul << 16);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100808 return diff;
terelius53dc23c2017-03-13 05:24:05 -0700809 },
810 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700811 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700812 }
813
tereliusdc35dcd2016-08-01 12:03:27 -0700814 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
815 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
816 kTopMargin);
817 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700818}
819
Stefan Holmer99f8e082016-09-09 13:37:50 +0200820void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
821 for (auto& kv : rtp_packets_) {
822 StreamId stream_id = kv.first;
823 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
824 // Filter on direction and SSRC.
825 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800826 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
827 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200828 continue;
829 }
830
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100831 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine,
832 PointStyle::kHighlight);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200833 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800834 const uint64_t kStep = 1000000;
835 SequenceNumberUnwrapper unwrapper_;
836 SequenceNumberUnwrapper prior_unwrapper_;
837 size_t window_index_begin = 0;
838 size_t window_index_end = 0;
839 int64_t highest_seq_number =
840 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
841 int64_t highest_prior_seq_number =
842 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
843
844 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
845 while (window_index_end < packet_stream.size() &&
846 packet_stream[window_index_end].timestamp < t) {
847 int64_t sequence_number = unwrapper_.Unwrap(
848 packet_stream[window_index_end].header.sequenceNumber);
849 highest_seq_number = std::max(highest_seq_number, sequence_number);
850 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200851 }
terelius4c9b4af2017-01-30 08:44:51 -0800852 while (window_index_begin < packet_stream.size() &&
853 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
854 int64_t sequence_number = prior_unwrapper_.Unwrap(
855 packet_stream[window_index_begin].header.sequenceNumber);
856 highest_prior_seq_number =
857 std::max(highest_prior_seq_number, sequence_number);
858 ++window_index_begin;
859 }
860 float x = static_cast<float>(t - begin_time_) / 1000000;
861 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
862 if (expected_packets > 0) {
863 int64_t received_packets = window_index_end - window_index_begin;
864 int64_t lost_packets = expected_packets - received_packets;
865 float y = static_cast<float>(lost_packets) / expected_packets * 100;
866 time_series.points.emplace_back(x, y);
867 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200868 }
philipel35ba9bd2017-04-19 05:58:51 -0700869 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200870 }
871
872 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
873 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
874 kTopMargin);
875 plot->SetTitle("Estimated incoming loss rate");
876}
877
terelius2ee076d2017-08-15 02:04:02 -0700878void EventLogAnalyzer::CreateIncomingDelayDeltaGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700879 for (auto& kv : rtp_packets_) {
880 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700881 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700882 // Filter on direction and SSRC.
883 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200884 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
885 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
886 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700887 continue;
888 }
terelius54ce6802016-07-13 06:44:41 -0700889
terelius23c595a2017-03-15 01:59:12 -0700890 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100891 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700892 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
893 packet_stream, begin_time_,
894 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700895 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700896
terelius23c595a2017-03-15 01:59:12 -0700897 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100898 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700899 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
900 packet_stream, begin_time_,
901 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700902 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700903 }
904
tereliusdc35dcd2016-08-01 12:03:27 -0700905 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
906 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
907 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700908 plot->SetTitle("Network latency difference between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700909}
910
terelius2ee076d2017-08-15 02:04:02 -0700911void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700912 for (auto& kv : rtp_packets_) {
913 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700914 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700915 // Filter on direction and SSRC.
916 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200917 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
918 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
919 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700920 continue;
921 }
terelius54ce6802016-07-13 06:44:41 -0700922
terelius23c595a2017-03-15 01:59:12 -0700923 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100924 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -0700925 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
926 packet_stream, begin_time_,
927 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700928 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700929
terelius23c595a2017-03-15 01:59:12 -0700930 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100931 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -0700932 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
933 packet_stream, begin_time_,
934 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700935 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700936 }
937
tereliusdc35dcd2016-08-01 12:03:27 -0700938 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
939 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
940 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700941 plot->SetTitle("Network latency (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700942}
943
tereliusf736d232016-08-04 10:00:11 -0700944// Plot the fraction of packets lost (as perceived by the loss-based BWE).
945void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100946 TimeSeries time_series("Fraction lost", LineStyle::kLine,
947 PointStyle::kHighlight);
tereliusf736d232016-08-04 10:00:11 -0700948 for (auto& bwe_update : bwe_loss_updates_) {
949 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
950 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700951 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700952 }
tereliusf736d232016-08-04 10:00:11 -0700953
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200954 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700955 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
956 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
957 kTopMargin);
958 plot->SetTitle("Reported packet loss");
959}
960
terelius54ce6802016-07-13 06:44:41 -0700961// Plot the total bandwidth used by all RTP streams.
962void EventLogAnalyzer::CreateTotalBitrateGraph(
963 PacketDirection desired_direction,
philipel23c7f252017-07-14 06:30:03 -0700964 Plot* plot,
965 bool show_detector_state) {
terelius54ce6802016-07-13 06:44:41 -0700966 struct TimestampSize {
967 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
968 uint64_t timestamp;
969 size_t size;
970 };
971 std::vector<TimestampSize> packets;
972
973 PacketDirection direction;
974 size_t total_length;
975
976 // Extract timestamps and sizes for the relevant packets.
977 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
978 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
979 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
Elad Alon1d87b0e2017-10-03 15:01:03 +0200980 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length,
981 nullptr);
terelius54ce6802016-07-13 06:44:41 -0700982 if (direction == desired_direction) {
983 uint64_t timestamp = parsed_log_.GetTimestamp(i);
984 packets.push_back(TimestampSize(timestamp, total_length));
985 }
986 }
987 }
988
989 size_t window_index_begin = 0;
990 size_t window_index_end = 0;
991 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700992
993 // Calculate a moving average of the bitrate and store in a TimeSeries.
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100994 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
terelius54ce6802016-07-13 06:44:41 -0700995 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
996 while (window_index_end < packets.size() &&
997 packets[window_index_end].timestamp < time) {
998 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700999 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -07001000 }
1001 while (window_index_begin < packets.size() &&
1002 packets[window_index_begin].timestamp < time - window_duration_) {
1003 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
1004 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -07001005 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -07001006 }
1007 float window_duration_in_seconds =
1008 static_cast<float>(window_duration_) / 1000000;
1009 float x = static_cast<float>(time - begin_time_) / 1000000;
1010 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001011 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -07001012 }
philipel35ba9bd2017-04-19 05:58:51 -07001013 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -07001014
terelius8058e582016-07-25 01:32:41 -07001015 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
1016 if (desired_direction == kOutgoingPacket) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001017 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
philipel10fc0e62017-04-11 01:50:23 -07001018 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -07001019 float x =
philipel10fc0e62017-04-11 01:50:23 -07001020 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
1021 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001022 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -07001023 }
1024
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001025 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
philipel23c7f252017-07-14 06:30:03 -07001026 IntervalSeries overusing_series("Overusing", "#ff8e82",
1027 IntervalSeries::kHorizontal);
1028 IntervalSeries underusing_series("Underusing", "#5092fc",
1029 IntervalSeries::kHorizontal);
1030 IntervalSeries normal_series("Normal", "#c4ffc4",
1031 IntervalSeries::kHorizontal);
1032 IntervalSeries* last_series = &normal_series;
1033 double last_detector_switch = 0.0;
1034
1035 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
1036
philipel10fc0e62017-04-11 01:50:23 -07001037 for (auto& delay_update : bwe_delay_updates_) {
1038 float x =
1039 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
1040 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -07001041
1042 if (last_detector_state != delay_update.detector_state) {
1043 last_series->intervals.emplace_back(last_detector_switch, x);
1044 last_detector_state = delay_update.detector_state;
1045 last_detector_switch = x;
1046
1047 switch (delay_update.detector_state) {
1048 case BandwidthUsage::kBwNormal:
1049 last_series = &normal_series;
1050 break;
1051 case BandwidthUsage::kBwUnderusing:
1052 last_series = &underusing_series;
1053 break;
1054 case BandwidthUsage::kBwOverusing:
1055 last_series = &overusing_series;
1056 break;
Elad Alon1d87b0e2017-10-03 15:01:03 +02001057 case BandwidthUsage::kLast:
1058 RTC_NOTREACHED();
philipel23c7f252017-07-14 06:30:03 -07001059 }
1060 }
1061
philipel35ba9bd2017-04-19 05:58:51 -07001062 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -07001063 }
philipele127e7a2017-03-29 16:28:53 +02001064
philipel23c7f252017-07-14 06:30:03 -07001065 RTC_CHECK(last_series);
1066 last_series->intervals.emplace_back(last_detector_switch, end_time_);
1067
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001068 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
1069 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001070 for (auto& cluster : bwe_probe_cluster_created_events_) {
1071 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
1072 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001073 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001074 }
1075
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001076 TimeSeries result_series("Probing results.", LineStyle::kNone,
1077 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001078 for (auto& result : bwe_probe_result_events_) {
1079 if (result.bitrate_bps) {
1080 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
1081 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001082 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001083 }
1084 }
philipel23c7f252017-07-14 06:30:03 -07001085
1086 if (show_detector_state) {
1087 plot->AppendIntervalSeries(std::move(overusing_series));
1088 plot->AppendIntervalSeries(std::move(underusing_series));
1089 plot->AppendIntervalSeries(std::move(normal_series));
1090 }
1091
philipel35ba9bd2017-04-19 05:58:51 -07001092 plot->AppendTimeSeries(std::move(loss_series));
1093 plot->AppendTimeSeries(std::move(delay_series));
1094 plot->AppendTimeSeries(std::move(created_series));
1095 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -07001096 }
philipele127e7a2017-03-29 16:28:53 +02001097
terelius2c8e8a32017-06-02 01:29:48 -07001098 // Overlay the incoming REMB over the outgoing bitrate
1099 // and outgoing REMB over incoming bitrate.
1100 PacketDirection remb_direction =
1101 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001102 TimeSeries remb_series("Remb", LineStyle::kStep);
terelius2c8e8a32017-06-02 01:29:48 -07001103 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
1104 for (const auto& kv : rtcp_packets_) {
1105 if (kv.first.GetDirection() == remb_direction) {
1106 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
1107 if (rtcp_packet.type == kRtcpRemb) {
1108 remb_packets.insert(
1109 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1110 }
1111 }
1112 }
1113 }
1114
1115 for (const auto& kv : remb_packets) {
1116 const LoggedRtcpPacket* const rtcp = kv.second;
1117 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
1118 float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000;
1119 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
1120 remb_series.points.emplace_back(x, y);
1121 }
1122 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1123
tereliusdc35dcd2016-08-01 12:03:27 -07001124 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1125 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001126 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001127 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001128 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001129 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001130 }
1131}
1132
1133// For each SSRC, plot the bandwidth used by that stream.
1134void EventLogAnalyzer::CreateStreamBitrateGraph(
1135 PacketDirection desired_direction,
1136 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001137 for (auto& kv : rtp_packets_) {
1138 StreamId stream_id = kv.first;
1139 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1140 // Filter on direction and SSRC.
1141 if (stream_id.GetDirection() != desired_direction ||
1142 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1143 continue;
terelius54ce6802016-07-13 06:44:41 -07001144 }
1145
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001146 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -07001147 MovingAverage<LoggedRtpPacket, double>(
1148 [](const LoggedRtpPacket& packet) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001149 return packet.total_length * 8.0 / 1000.0;
terelius53dc23c2017-03-13 05:24:05 -07001150 },
1151 packet_stream, begin_time_, end_time_, window_duration_, step_,
1152 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001153 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001154 }
1155
tereliusdc35dcd2016-08-01 12:03:27 -07001156 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1157 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001158 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001159 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001160 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001161 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001162 }
1163}
1164
Bjorn Terelius28db2662017-10-04 14:22:43 +02001165void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001166 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1167 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001168
1169 for (const auto& kv : rtp_packets_) {
1170 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1171 for (const LoggedRtpPacket& rtp_packet : kv.second)
1172 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1173 }
1174 }
1175
1176 for (const auto& kv : rtcp_packets_) {
1177 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1178 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1179 incoming_rtcp.insert(
1180 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1181 }
1182 }
1183
1184 SimulatedClock clock(0);
1185 BitrateObserver observer;
1186 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001187 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001188 PacedSender pacer(&clock, &packet_router, &null_event_log);
1189 SendSideCongestionController cc(&clock, &observer, &null_event_log, &pacer);
Stefan Holmer13181032016-07-29 14:48:54 +02001190 // TODO(holmer): Log the call config and use that here instead.
1191 static const uint32_t kDefaultStartBitrateBps = 300000;
1192 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1193
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001194 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1195 PointStyle::kHighlight);
1196 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1197 PointStyle::kHighlight);
1198 TimeSeries acked_estimate_time_series(
1199 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001200
1201 auto rtp_iterator = outgoing_rtp.begin();
1202 auto rtcp_iterator = incoming_rtcp.begin();
1203
1204 auto NextRtpTime = [&]() {
1205 if (rtp_iterator != outgoing_rtp.end())
1206 return static_cast<int64_t>(rtp_iterator->first);
1207 return std::numeric_limits<int64_t>::max();
1208 };
1209
1210 auto NextRtcpTime = [&]() {
1211 if (rtcp_iterator != incoming_rtcp.end())
1212 return static_cast<int64_t>(rtcp_iterator->first);
1213 return std::numeric_limits<int64_t>::max();
1214 };
1215
1216 auto NextProcessTime = [&]() {
1217 if (rtcp_iterator != incoming_rtcp.end() ||
1218 rtp_iterator != outgoing_rtp.end()) {
1219 return clock.TimeInMicroseconds() +
1220 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1221 }
1222 return std::numeric_limits<int64_t>::max();
1223 };
1224
Stefan Holmer492ee282016-10-27 17:19:20 +02001225 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001226#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1227 // The event_log_visualizer should normally not be compiled with
1228 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
1229 // However, compiling with BWE_TEST_LOGGING, runnning with --plot_sendside_bwe
1230 // and piping the output to plot_dynamics.py can be used as a hack to get the
1231 // internal state of various BWE components. In this case, it is important
1232 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
1233 // SendSideCongestionController since that would lead to duplicate outputs.
1234 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
1235 rtc::MakeUnique<BitrateEstimator>());
1236#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001237 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001238 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001239 while (time_us != std::numeric_limits<int64_t>::max()) {
1240 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1241 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001242 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001243 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1244 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001245 cc.OnTransportFeedback(
1246 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1247 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001248 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001249 rtc::Optional<uint32_t> bitrate_bps;
1250 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001251#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1252 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
1253#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
elad.alonf9490002017-03-06 05:32:21 -08001254 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001255 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1256 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1257 }
Stefan Holmer60e43462016-09-07 09:58:20 +02001258 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1259 1000000;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001260 float y = bitrate_bps.value_or(0) / 1000;
Stefan Holmer60e43462016-09-07 09:58:20 +02001261 acked_time_series.points.emplace_back(x, y);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001262#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1263 y = acknowledged_bitrate_estimator.bitrate_bps().value_or(0) / 1000;
1264 acked_estimate_time_series.points.emplace_back(x, y);
1265#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001266 }
1267 ++rtcp_iterator;
1268 }
1269 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001270 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001271 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1272 if (rtp.header.extension.hasTransportSequenceNumber) {
1273 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001274 cc.AddPacket(rtp.header.ssrc,
1275 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001276 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001277 rtc::SentPacket sent_packet(
1278 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1279 cc.OnSentPacket(sent_packet);
1280 }
1281 ++rtp_iterator;
1282 }
stefanc3de0332016-08-02 07:22:17 -07001283 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1284 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001285 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001286 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001287 if (observer.GetAndResetBitrateUpdated() ||
1288 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001289 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001290 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1291 1000000;
1292 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001293 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001294 }
1295 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1296 }
1297 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001298 plot->AppendTimeSeries(std::move(time_series));
1299 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001300 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001301
tereliusdc35dcd2016-08-01 12:03:27 -07001302 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1303 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001304 plot->SetTitle("Simulated send-side BWE behavior");
1305}
1306
1307void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
1308 class RembInterceptingPacketRouter : public PacketRouter {
1309 public:
1310 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1311 uint32_t bitrate_bps) override {
1312 last_bitrate_bps_ = bitrate_bps;
1313 bitrate_updated_ = true;
1314 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1315 }
1316 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1317 bool GetAndResetBitrateUpdated() {
1318 bool bitrate_updated = bitrate_updated_;
1319 bitrate_updated_ = false;
1320 return bitrate_updated;
1321 }
1322
1323 private:
1324 uint32_t last_bitrate_bps_;
1325 bool bitrate_updated_;
1326 };
1327
1328 std::multimap<uint64_t, const LoggedRtpPacket*> incoming_rtp;
1329
1330 for (const auto& kv : rtp_packets_) {
1331 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket &&
1332 IsVideoSsrc(kv.first)) {
1333 for (const LoggedRtpPacket& rtp_packet : kv.second)
1334 incoming_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1335 }
1336 }
1337
1338 SimulatedClock clock(0);
1339 RembInterceptingPacketRouter packet_router;
1340 // TODO(terelius): The PacketRrouter is the used as the RemoteBitrateObserver.
1341 // Is this intentional?
1342 ReceiveSideCongestionController rscc(&clock, &packet_router);
1343 // TODO(holmer): Log the call config and use that here instead.
1344 // static const uint32_t kDefaultStartBitrateBps = 300000;
1345 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1346
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001347 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1348 PointStyle::kHighlight);
1349 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001350
1351 RateStatistics acked_bitrate(250, 8000);
1352 int64_t last_update_us = 0;
1353 for (const auto& kv : incoming_rtp) {
1354 const LoggedRtpPacket& packet = *kv.second;
1355 int64_t arrival_time_ms = packet.timestamp / 1000;
1356 size_t payload = packet.total_length; /*Should subtract header?*/
1357 clock.AdvanceTimeMicroseconds(packet.timestamp -
1358 clock.TimeInMicroseconds());
1359 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.header);
1360 acked_bitrate.Update(payload, arrival_time_ms);
1361 rtc::Optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
1362 if (bitrate_bps) {
1363 uint32_t y = *bitrate_bps / 1000;
1364 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1365 1000000;
1366 acked_time_series.points.emplace_back(x, y);
1367 }
1368 if (packet_router.GetAndResetBitrateUpdated() ||
1369 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1370 uint32_t y = packet_router.last_bitrate_bps() / 1000;
1371 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1372 1000000;
1373 time_series.points.emplace_back(x, y);
1374 last_update_us = clock.TimeInMicroseconds();
1375 }
1376 }
1377 // Add the data set to the plot.
1378 plot->AppendTimeSeries(std::move(time_series));
1379 plot->AppendTimeSeries(std::move(acked_time_series));
1380
1381 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1382 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1383 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001384}
1385
tereliuse34c19c2016-08-15 08:47:14 -07001386void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001387 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1388 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001389
1390 for (const auto& kv : rtp_packets_) {
1391 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1392 for (const LoggedRtpPacket& rtp_packet : kv.second)
1393 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1394 }
1395 }
1396
1397 for (const auto& kv : rtcp_packets_) {
1398 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1399 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1400 incoming_rtcp.insert(
1401 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1402 }
1403 }
1404
1405 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001406 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001407
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001408 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1409 PointStyle::kHighlight);
1410 TimeSeries time_series("Network Delay Change", LineStyle::kLine,
1411 PointStyle::kHighlight);
stefanc3de0332016-08-02 07:22:17 -07001412 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1413
1414 auto rtp_iterator = outgoing_rtp.begin();
1415 auto rtcp_iterator = incoming_rtcp.begin();
1416
1417 auto NextRtpTime = [&]() {
1418 if (rtp_iterator != outgoing_rtp.end())
1419 return static_cast<int64_t>(rtp_iterator->first);
1420 return std::numeric_limits<int64_t>::max();
1421 };
1422
1423 auto NextRtcpTime = [&]() {
1424 if (rtcp_iterator != incoming_rtcp.end())
1425 return static_cast<int64_t>(rtcp_iterator->first);
1426 return std::numeric_limits<int64_t>::max();
1427 };
1428
1429 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
stefana0a8ed72017-09-06 02:06:32 -07001430 int64_t prev_y = 0;
stefanc3de0332016-08-02 07:22:17 -07001431 while (time_us != std::numeric_limits<int64_t>::max()) {
1432 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1433 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1434 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1435 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1436 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001437 feedback_adapter.OnTransportFeedback(
1438 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001439 std::vector<PacketFeedback> feedback =
1440 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001441 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001442 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001443 float x =
1444 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1445 1000000;
srte37b52232017-11-29 16:52:28 +01001446 if (packet.send_time_ms == PacketFeedback::kNoSendTime) {
stefana0a8ed72017-09-06 02:06:32 -07001447 late_feedback_series.points.emplace_back(x, prev_y);
1448 continue;
1449 }
1450 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1451 prev_y = y;
stefanc3de0332016-08-02 07:22:17 -07001452 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1453 time_series.points.emplace_back(x, y);
1454 }
1455 }
1456 ++rtcp_iterator;
1457 }
1458 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1459 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1460 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1461 if (rtp.header.extension.hasTransportSequenceNumber) {
1462 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001463 feedback_adapter.AddPacket(rtp.header.ssrc,
1464 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001465 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001466 feedback_adapter.OnSentPacket(
1467 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1468 }
1469 ++rtp_iterator;
1470 }
1471 time_us = std::min(NextRtpTime(), NextRtcpTime());
1472 }
1473 // We assume that the base network delay (w/o queues) is the min delay
1474 // observed during the call.
1475 for (TimeSeriesPoint& point : time_series.points)
1476 point.y -= estimated_base_delay_ms;
stefana0a8ed72017-09-06 02:06:32 -07001477 for (TimeSeriesPoint& point : late_feedback_series.points)
1478 point.y -= estimated_base_delay_ms;
stefanc3de0332016-08-02 07:22:17 -07001479 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001480 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1481 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001482
1483 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1484 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1485 plot->SetTitle("Network Delay Change.");
1486}
stefan08383272016-12-20 08:51:52 -08001487
1488std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1489 const {
1490 std::vector<std::pair<int64_t, int64_t>> timestamps;
1491 size_t largest_stream_size = 0;
1492 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1493 // Find the incoming video stream with the most number of packets that is
1494 // not rtx.
1495 for (const auto& kv : rtp_packets_) {
1496 if (kv.first.GetDirection() == kIncomingPacket &&
1497 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1498 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1499 kv.second.size() > largest_stream_size) {
1500 largest_stream_size = kv.second.size();
1501 largest_video_stream = &kv.second;
1502 }
1503 }
1504 if (largest_video_stream == nullptr) {
1505 for (auto& packet : *largest_video_stream) {
1506 if (packet.header.markerBit) {
1507 int64_t capture_ms = packet.header.timestamp / 90.0;
1508 int64_t arrival_ms = packet.timestamp / 1000.0;
1509 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1510 }
1511 }
1512 }
1513 return timestamps;
1514}
stefane372d3c2017-02-02 08:04:18 -08001515
Bjorn Terelius0295a962017-10-25 17:42:41 +02001516void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
1517 for (const auto& kv : rtp_packets_) {
1518 const std::vector<LoggedRtpPacket>& packets = kv.second;
1519 StreamId stream_id = kv.first;
Bjorn Tereliusb87c27e2017-11-09 11:55:51 +01001520 if (stream_id.GetDirection() == kIncomingPacket)
1521 continue;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001522
1523 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001524 RTC_LOG(LS_WARNING)
1525 << "Can't estimate a the RTP clock frequency or the "
1526 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001527 continue;
1528 }
1529 rtc::Optional<uint32_t> estimated_frequency =
1530 EstimateRtpClockFrequency(packets);
1531 if (!estimated_frequency)
1532 continue;
1533 if (IsVideoSsrc(stream_id) && *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001534 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001535 << "Video stream should use a 90 kHz clock but appears to use "
1536 << *estimated_frequency / 1000 << ". Discarding.";
1537 continue;
1538 }
1539
1540 TimeSeries pacer_delay_series(
1541 GetStreamName(stream_id) + "(" +
1542 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001543 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001544 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1545 uint64_t first_capture_timestamp =
1546 timestamp_unwrapper.Unwrap(packets.front().header.timestamp);
1547 uint64_t first_send_timestamp = packets.front().timestamp;
1548 for (LoggedRtpPacket packet : packets) {
1549 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
1550 packet.header.timestamp)) -
1551 first_capture_timestamp) /
1552 *estimated_frequency * 1000;
1553 double send_time_ms =
1554 static_cast<double>(packet.timestamp - first_send_timestamp) / 1000;
1555 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1556 float y = send_time_ms - capture_time_ms;
1557 pacer_delay_series.points.emplace_back(x, y);
1558 }
1559 plot->AppendTimeSeries(std::move(pacer_delay_series));
1560 }
1561
1562 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1563 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1564 plot->SetTitle(
1565 "Delay from capture to send time. (First packet normalized to 0.)");
1566}
1567
stefane372d3c2017-02-02 08:04:18 -08001568void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1569 for (const auto& kv : rtp_packets_) {
1570 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1571 StreamId stream_id = kv.first;
1572
1573 {
terelius23c595a2017-03-15 01:59:12 -07001574 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001575 LineStyle::kLine, PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001576 for (LoggedRtpPacket packet : rtp_packets) {
1577 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1578 float y = packet.header.timestamp;
1579 timestamp_data.points.emplace_back(x, y);
1580 }
philipel35ba9bd2017-04-19 05:58:51 -07001581 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001582 }
1583
1584 {
1585 auto kv = rtcp_packets_.find(stream_id);
1586 if (kv != rtcp_packets_.end()) {
1587 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001588 TimeSeries timestamp_data(
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001589 GetStreamName(stream_id) + " rtcp capture-time", LineStyle::kLine,
1590 PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001591 for (const LoggedRtcpPacket& rtcp : packets) {
1592 if (rtcp.type != kRtcpSr)
1593 continue;
1594 rtcp::SenderReport* sr;
1595 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1596 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1597 float y = sr->rtp_timestamp();
1598 timestamp_data.points.emplace_back(x, y);
1599 }
philipel35ba9bd2017-04-19 05:58:51 -07001600 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001601 }
1602 }
1603 }
1604
1605 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1606 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1607 plot->SetTitle("Timestamps");
1608}
michaelt6e5b2192017-02-22 07:33:27 -08001609
1610void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001611 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1612 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001613 ProcessPoints<AudioNetworkAdaptationEvent>(
1614 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001615 if (ana_event.config.bitrate_bps)
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001616 return static_cast<float>(*ana_event.config.bitrate_bps);
1617 return rtc::nullopt;
terelius53dc23c2017-03-13 05:24:05 -07001618 },
philipel35ba9bd2017-04-19 05:58:51 -07001619 audio_network_adaptation_events_, begin_time_, &time_series);
1620 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001621 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1622 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1623 plot->SetTitle("Reported audio encoder target bitrate");
1624}
1625
1626void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001627 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1628 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001629 ProcessPoints<AudioNetworkAdaptationEvent>(
1630 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001631 if (ana_event.config.frame_length_ms)
1632 return rtc::Optional<float>(
1633 static_cast<float>(*ana_event.config.frame_length_ms));
1634 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001635 },
philipel35ba9bd2017-04-19 05:58:51 -07001636 audio_network_adaptation_events_, begin_time_, &time_series);
1637 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001638 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1639 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1640 plot->SetTitle("Reported audio encoder frame length");
1641}
1642
terelius2ee076d2017-08-15 02:04:02 -07001643void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001644 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001645 LineStyle::kLine, PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001646 ProcessPoints<AudioNetworkAdaptationEvent>(
1647 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001648 if (ana_event.config.uplink_packet_loss_fraction)
1649 return rtc::Optional<float>(static_cast<float>(
1650 *ana_event.config.uplink_packet_loss_fraction));
1651 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001652 },
philipel35ba9bd2017-04-19 05:58:51 -07001653 audio_network_adaptation_events_, begin_time_, &time_series);
1654 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001655 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1656 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1657 kTopMargin);
1658 plot->SetTitle("Reported audio encoder lost packets");
1659}
1660
1661void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001662 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1663 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001664 ProcessPoints<AudioNetworkAdaptationEvent>(
1665 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001666 if (ana_event.config.enable_fec)
1667 return rtc::Optional<float>(
1668 static_cast<float>(*ana_event.config.enable_fec));
1669 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001670 },
philipel35ba9bd2017-04-19 05:58:51 -07001671 audio_network_adaptation_events_, begin_time_, &time_series);
1672 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001673 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1674 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1675 plot->SetTitle("Reported audio encoder FEC");
1676}
1677
1678void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001679 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1680 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001681 ProcessPoints<AudioNetworkAdaptationEvent>(
1682 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001683 if (ana_event.config.enable_dtx)
1684 return rtc::Optional<float>(
1685 static_cast<float>(*ana_event.config.enable_dtx));
1686 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001687 },
philipel35ba9bd2017-04-19 05:58:51 -07001688 audio_network_adaptation_events_, begin_time_, &time_series);
1689 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001690 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1691 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1692 plot->SetTitle("Reported audio encoder DTX");
1693}
1694
1695void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001696 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1697 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001698 ProcessPoints<AudioNetworkAdaptationEvent>(
1699 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001700 if (ana_event.config.num_channels)
1701 return rtc::Optional<float>(
1702 static_cast<float>(*ana_event.config.num_channels));
1703 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001704 },
philipel35ba9bd2017-04-19 05:58:51 -07001705 audio_network_adaptation_events_, begin_time_, &time_series);
1706 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001707 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1708 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1709 kBottomMargin, kTopMargin);
1710 plot->SetTitle("Reported audio encoder number of channels");
1711}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001712
1713class NetEqStreamInput : public test::NetEqInput {
1714 public:
1715 // Does not take any ownership, and all pointers must refer to valid objects
1716 // that outlive the one constructed.
1717 NetEqStreamInput(const std::vector<LoggedRtpPacket>* packet_stream,
1718 const std::vector<uint64_t>* output_events_us,
1719 rtc::Optional<uint64_t> end_time_us)
1720 : packet_stream_(*packet_stream),
1721 packet_stream_it_(packet_stream_.begin()),
1722 output_events_us_it_(output_events_us->begin()),
1723 output_events_us_end_(output_events_us->end()),
1724 end_time_us_(end_time_us) {
1725 RTC_DCHECK(packet_stream);
1726 RTC_DCHECK(output_events_us);
1727 }
1728
1729 rtc::Optional<int64_t> NextPacketTime() const override {
1730 if (packet_stream_it_ == packet_stream_.end()) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001731 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001732 }
1733 if (end_time_us_ && packet_stream_it_->timestamp > *end_time_us_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001734 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001735 }
1736 // Convert from us to ms.
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001737 return packet_stream_it_->timestamp / 1000;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001738 }
1739
1740 rtc::Optional<int64_t> NextOutputEventTime() const override {
1741 if (output_events_us_it_ == output_events_us_end_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001742 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001743 }
1744 if (end_time_us_ && *output_events_us_it_ > *end_time_us_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001745 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001746 }
1747 // Convert from us to ms.
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001748 return rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001749 }
1750
1751 std::unique_ptr<PacketData> PopPacket() override {
1752 if (packet_stream_it_ == packet_stream_.end()) {
1753 return std::unique_ptr<PacketData>();
1754 }
1755 std::unique_ptr<PacketData> packet_data(new PacketData());
1756 packet_data->header = packet_stream_it_->header;
1757 // Convert from us to ms.
1758 packet_data->time_ms = packet_stream_it_->timestamp / 1000.0;
1759
1760 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1761 // length according to the virtual length.
1762 packet_data->payload.SetSize(packet_stream_it_->total_length);
1763 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1764
1765 ++packet_stream_it_;
1766 return packet_data;
1767 }
1768
1769 void AdvanceOutputEvent() override {
1770 if (output_events_us_it_ != output_events_us_end_) {
1771 ++output_events_us_it_;
1772 }
1773 }
1774
1775 bool ended() const override { return !NextEventTime(); }
1776
1777 rtc::Optional<RTPHeader> NextHeader() const override {
1778 if (packet_stream_it_ == packet_stream_.end()) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001779 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001780 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001781 return packet_stream_it_->header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001782 }
1783
1784 private:
1785 const std::vector<LoggedRtpPacket>& packet_stream_;
1786 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_;
1787 std::vector<uint64_t>::const_iterator output_events_us_it_;
1788 const std::vector<uint64_t>::const_iterator output_events_us_end_;
1789 const rtc::Optional<uint64_t> end_time_us_;
1790};
1791
1792namespace {
1793// Creates a NetEq test object and all necessary input and output helpers. Runs
1794// the test and returns the NetEqDelayAnalyzer object that was used to
1795// instrument the test.
1796std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun(
1797 const std::vector<LoggedRtpPacket>* packet_stream,
1798 const std::vector<uint64_t>* output_events_us,
1799 rtc::Optional<uint64_t> end_time_us,
1800 const std::string& replacement_file_name,
1801 int file_sample_rate_hz) {
1802 std::unique_ptr<test::NetEqInput> input(
1803 new NetEqStreamInput(packet_stream, output_events_us, end_time_us));
1804
1805 constexpr int kReplacementPt = 127;
1806 std::set<uint8_t> cn_types;
1807 std::set<uint8_t> forbidden_types;
1808 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1809 cn_types, forbidden_types));
1810
1811 NetEq::Config config;
1812 config.max_packets_in_buffer = 200;
1813 config.enable_fast_accelerate = true;
1814
1815 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1816
1817 test::NetEqTest::DecoderMap codecs;
1818
1819 // Create a "replacement decoder" that produces the decoded audio by reading
1820 // from a file rather than from the encoded payloads.
1821 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1822 new test::ResampleInputAudioFile(replacement_file_name,
1823 file_sample_rate_hz));
1824 replacement_file->set_output_rate_hz(48000);
1825 std::unique_ptr<AudioDecoder> replacement_decoder(
1826 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1827 test::NetEqTest::ExtDecoderMap ext_codecs;
1828 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1829 NetEqDecoder::kDecoderArbitrary,
1830 "replacement codec"};
1831
1832 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1833 new test::NetEqDelayAnalyzer);
1834 test::DefaultNetEqTestErrorCallback error_cb;
1835 test::NetEqTest::Callbacks callbacks;
1836 callbacks.error_callback = &error_cb;
1837 callbacks.post_insert_packet = delay_cb.get();
1838 callbacks.get_audio_callback = delay_cb.get();
1839
1840 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1841 std::move(output), callbacks);
1842 test.Run();
1843 return delay_cb;
1844}
1845} // namespace
1846
1847// Plots the jitter buffer delay profile. This will plot only for the first
1848// incoming audio SSRC. If the stream contains more than one incoming audio
1849// SSRC, all but the first will be ignored.
1850void EventLogAnalyzer::CreateAudioJitterBufferGraph(
1851 const std::string& replacement_file_name,
1852 int file_sample_rate_hz,
1853 Plot* plot) {
1854 const auto& incoming_audio_kv = std::find_if(
1855 rtp_packets_.begin(), rtp_packets_.end(),
1856 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) {
1857 return kv.first.GetDirection() == kIncomingPacket &&
1858 this->IsAudioSsrc(kv.first);
1859 });
1860 if (incoming_audio_kv == rtp_packets_.end()) {
1861 // No incoming audio stream found.
1862 return;
1863 }
1864
1865 const uint32_t ssrc = incoming_audio_kv->first.GetSsrc();
1866
1867 std::map<uint32_t, std::vector<uint64_t>>::const_iterator output_events_it =
1868 audio_playout_events_.find(ssrc);
1869 if (output_events_it == audio_playout_events_.end()) {
1870 // Could not find output events with SSRC matching the input audio stream.
1871 // Using the first available stream of output events.
1872 output_events_it = audio_playout_events_.cbegin();
1873 }
1874
1875 rtc::Optional<uint64_t> end_time_us =
1876 log_segments_.empty()
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001877 ? rtc::nullopt
henrik.lundin3c938fc2017-06-14 06:09:58 -07001878 : rtc::Optional<uint64_t>(log_segments_.front().second);
1879
1880 auto delay_cb = CreateNetEqTestAndRun(
1881 &incoming_audio_kv->second, &output_events_it->second, end_time_us,
1882 replacement_file_name, file_sample_rate_hz);
1883
1884 std::vector<float> send_times_s;
1885 std::vector<float> arrival_delay_ms;
1886 std::vector<float> corrected_arrival_delay_ms;
1887 std::vector<rtc::Optional<float>> playout_delay_ms;
1888 std::vector<rtc::Optional<float>> target_delay_ms;
1889 delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms,
1890 &corrected_arrival_delay_ms, &playout_delay_ms,
1891 &target_delay_ms);
1892 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size());
1893 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size());
1894 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size());
1895 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size());
1896
1897 std::map<StreamId, TimeSeries> time_series_packet_arrival;
1898 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival;
1899 std::map<StreamId, TimeSeries> time_series_play_time;
1900 std::map<StreamId, TimeSeries> time_series_target_time;
1901 float min_y_axis = 0.f;
1902 float max_y_axis = 0.f;
1903 const StreamId stream_id = incoming_audio_kv->first;
1904 for (size_t i = 0; i < send_times_s.size(); ++i) {
1905 time_series_packet_arrival[stream_id].points.emplace_back(
1906 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i]));
1907 time_series_relative_packet_arrival[stream_id].points.emplace_back(
1908 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i]));
1909 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]);
1910 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]);
1911 if (playout_delay_ms[i]) {
1912 time_series_play_time[stream_id].points.emplace_back(
1913 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i]));
1914 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]);
1915 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]);
1916 }
1917 if (target_delay_ms[i]) {
1918 time_series_target_time[stream_id].points.emplace_back(
1919 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i]));
1920 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]);
1921 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]);
1922 }
1923 }
1924
1925 // This code is adapted for a single stream. The creation of the streams above
1926 // guarantee that no more than one steam is included. If multiple streams are
1927 // to be plotted, they should likely be given distinct labels below.
1928 RTC_DCHECK_EQ(time_series_relative_packet_arrival.size(), 1);
1929 for (auto& series : time_series_relative_packet_arrival) {
1930 series.second.label = "Relative packet arrival delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001931 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001932 plot->AppendTimeSeries(std::move(series.second));
1933 }
1934 RTC_DCHECK_EQ(time_series_play_time.size(), 1);
1935 for (auto& series : time_series_play_time) {
1936 series.second.label = "Playout 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_target_time.size(), 1);
1941 for (auto& series : time_series_target_time) {
1942 series.second.label = "Target delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001943 series.second.line_style = LineStyle::kLine;
1944 series.second.point_style = PointStyle::kHighlight;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001945 plot->AppendTimeSeries(std::move(series.second));
1946 }
1947
1948 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1949 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin,
1950 kTopMargin);
1951 plot->SetTitle("NetEq timing");
1952}
terelius54ce6802016-07-13 06:44:41 -07001953} // namespace plotting
1954} // namespace webrtc