blob: c351b781d5f01815eed3c3c1126714518626e5fe [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>
14#include <limits>
15#include <map>
16#include <sstream>
17#include <string>
18#include <utility>
19
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "call/audio_receive_stream.h"
21#include "call/audio_send_stream.h"
22#include "call/call.h"
23#include "call/video_receive_stream.h"
24#include "call/video_send_stream.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020025#include "common_types.h" // NOLINT(build/include)
Elad Alon99a81b62017-09-21 10:25:29 +020026#include "logging/rtc_event_log/rtc_stream_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/audio_coding/neteq/tools/audio_sink.h"
28#include "modules/audio_coding/neteq/tools/fake_decode_from_file.h"
29#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
30#include "modules/audio_coding/neteq/tools/neteq_replacement_input.h"
31#include "modules/audio_coding/neteq/tools/neteq_test.h"
32#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
Bjorn Terelius6984ad22017-10-24 12:19:45 +020033#include "modules/congestion_controller/acknowledged_bitrate_estimator.h"
34#include "modules/congestion_controller/bitrate_estimator.h"
Bjorn Terelius28db2662017-10-04 14:22:43 +020035#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "modules/congestion_controller/include/send_side_congestion_controller.h"
37#include "modules/include/module_common_types.h"
Niels Möllerfd6c0912017-10-31 10:19:10 +010038#include "modules/pacing/packet_router.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "modules/rtp_rtcp/include/rtp_rtcp.h"
40#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
41#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
42#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
43#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
44#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
45#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
46#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
47#include "modules/rtp_rtcp/source/rtp_utility.h"
48#include "rtc_base/checks.h"
49#include "rtc_base/format_macros.h"
50#include "rtc_base/logging.h"
Bjorn Terelius0295a962017-10-25 17:42:41 +020051#include "rtc_base/numerics/sequence_number_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020052#include "rtc_base/ptr_util.h"
53#include "rtc_base/rate_statistics.h"
terelius54ce6802016-07-13 06:44:41 -070054
Bjorn Terelius6984ad22017-10-24 12:19:45 +020055#ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
56#define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0
57#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
58
tereliusdc35dcd2016-08-01 12:03:27 -070059namespace webrtc {
60namespace plotting {
61
terelius54ce6802016-07-13 06:44:41 -070062namespace {
63
elad.alonec304f92017-03-08 05:03:53 -080064void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
65 auto pred = [](const PacketFeedback& packet_feedback) {
66 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
67 };
68 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
69 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
70}
71
terelius54ce6802016-07-13 06:44:41 -070072std::string SsrcToString(uint32_t ssrc) {
73 std::stringstream ss;
74 ss << "SSRC " << ssrc;
75 return ss.str();
76}
77
78// Checks whether an SSRC is contained in the list of desired SSRCs.
79// Note that an empty SSRC list matches every SSRC.
80bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
81 if (desired_ssrc.size() == 0)
82 return true;
83 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
84 desired_ssrc.end();
85}
86
87double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
88 // The timestamp is a fixed point representation with 6 bits for seconds
89 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
90 // time in seconds and then multiply by 1000000 to convert to microseconds.
91 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070092 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070093 return abs_send_time * kTimestampToMicroSec;
94}
95
96// Computes the difference |later| - |earlier| where |later| and |earlier|
97// are counters that wrap at |modulus|. The difference is chosen to have the
98// least absolute value. For example if |modulus| is 8, then the difference will
99// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
100// be in [-4, 4].
101int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
102 RTC_DCHECK_LE(1, modulus);
103 RTC_DCHECK_LT(later, modulus);
104 RTC_DCHECK_LT(earlier, modulus);
105 int64_t difference =
106 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
107 int64_t max_difference = modulus / 2;
108 int64_t min_difference = max_difference - modulus + 1;
109 if (difference > max_difference) {
110 difference -= modulus;
111 }
112 if (difference < min_difference) {
113 difference += modulus;
114 }
terelius6addf492016-08-23 17:34:07 -0700115 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100116 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
117 << " expected to be in the range ("
118 << min_difference / 2 << "," << max_difference / 2
119 << ") but is " << difference
120 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700121 }
terelius54ce6802016-07-13 06:44:41 -0700122 return difference;
123}
124
ivocaac9d6f2016-09-22 07:01:47 -0700125// Return default values for header extensions, to use on streams without stored
126// mapping data. Currently this only applies to audio streams, since the mapping
127// is not stored in the event log.
128// TODO(ivoc): Remove this once this mapping is stored in the event log for
129// audio streams. Tracking bug: webrtc:6399
130webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
131 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800132 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
terelius007d5622017-08-08 05:40:26 -0700133 default_map.Register<TransmissionOffset>(
134 webrtc::RtpExtension::kTimestampOffsetDefaultId);
danilchap4aecc582016-11-15 09:21:00 -0800135 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700136 webrtc::RtpExtension::kAbsSendTimeDefaultId);
terelius007d5622017-08-08 05:40:26 -0700137 default_map.Register<VideoOrientation>(
138 webrtc::RtpExtension::kVideoRotationDefaultId);
139 default_map.Register<VideoContentTypeExtension>(
140 webrtc::RtpExtension::kVideoContentTypeDefaultId);
141 default_map.Register<VideoTimingExtension>(
142 webrtc::RtpExtension::kVideoTimingDefaultId);
143 default_map.Register<TransportSequenceNumber>(
144 webrtc::RtpExtension::kTransportSequenceNumberDefaultId);
145 default_map.Register<PlayoutDelayLimits>(
146 webrtc::RtpExtension::kPlayoutDelayDefaultId);
ivocaac9d6f2016-09-22 07:01:47 -0700147 return default_map;
148}
149
tereliusdc35dcd2016-08-01 12:03:27 -0700150constexpr float kLeftMargin = 0.01f;
151constexpr float kRightMargin = 0.02f;
152constexpr float kBottomMargin = 0.02f;
153constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700154
terelius53dc23c2017-03-13 05:24:05 -0700155rtc::Optional<double> NetworkDelayDiff_AbsSendTime(
156 const LoggedRtpPacket& old_packet,
157 const LoggedRtpPacket& new_packet) {
158 if (old_packet.header.extension.hasAbsoluteSendTime &&
159 new_packet.header.extension.hasAbsoluteSendTime) {
160 int64_t send_time_diff = WrappingDifference(
161 new_packet.header.extension.absoluteSendTime,
162 old_packet.header.extension.absoluteSendTime, 1ul << 24);
163 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
164 double delay_change_us =
165 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
166 return rtc::Optional<double>(delay_change_us / 1000);
167 } else {
168 return rtc::Optional<double>();
terelius6addf492016-08-23 17:34:07 -0700169 }
170}
171
terelius53dc23c2017-03-13 05:24:05 -0700172rtc::Optional<double> NetworkDelayDiff_CaptureTime(
173 const LoggedRtpPacket& old_packet,
174 const LoggedRtpPacket& new_packet) {
175 int64_t send_time_diff = WrappingDifference(
176 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
177 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
178
179 const double kVideoSampleRate = 90000;
180 // TODO(terelius): We treat all streams as video for now, even though
181 // audio might be sampled at e.g. 16kHz, because it is really difficult to
182 // figure out the true sampling rate of a stream. The effect is that the
183 // delay will be scaled incorrectly for non-video streams.
184
185 double delay_change =
186 static_cast<double>(recv_time_diff) / 1000 -
187 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
188 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100189 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
190 RTC_LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
191 << ", received time " << old_packet.timestamp;
192 RTC_LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
193 << ", received time " << new_packet.timestamp;
194 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
195 << static_cast<double>(recv_time_diff) / 1000000 << "s";
196 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
197 << static_cast<double>(send_time_diff) /
198 kVideoSampleRate
199 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700200 }
201 return rtc::Optional<double>(delay_change);
202}
203
204// For each element in data, use |get_y()| to extract a y-coordinate and
205// store the result in a TimeSeries.
206template <typename DataType>
207void ProcessPoints(
208 rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y,
209 const std::vector<DataType>& data,
210 uint64_t begin_time,
211 TimeSeries* result) {
212 for (size_t i = 0; i < data.size(); i++) {
213 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
214 rtc::Optional<float> y = get_y(data[i]);
215 if (y)
216 result->points.emplace_back(x, *y);
217 }
218}
219
220// For each pair of adjacent elements in |data|, use |get_y| to extract a
terelius6addf492016-08-23 17:34:07 -0700221// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
222// will be the time of the second element in the pair.
terelius53dc23c2017-03-13 05:24:05 -0700223template <typename DataType, typename ResultType>
224void ProcessPairs(
225 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
226 const DataType&)> get_y,
227 const std::vector<DataType>& data,
228 uint64_t begin_time,
229 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700230 for (size_t i = 1; i < data.size(); i++) {
231 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700232 rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]);
233 if (y)
234 result->points.emplace_back(x, static_cast<float>(*y));
235 }
236}
237
238// For each element in data, use |extract()| to extract a y-coordinate and
239// store the result in a TimeSeries.
240template <typename DataType, typename ResultType>
241void AccumulatePoints(
242 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
243 const std::vector<DataType>& data,
244 uint64_t begin_time,
245 TimeSeries* result) {
246 ResultType sum = 0;
247 for (size_t i = 0; i < data.size(); i++) {
248 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
249 rtc::Optional<ResultType> y = extract(data[i]);
250 if (y) {
251 sum += *y;
252 result->points.emplace_back(x, static_cast<float>(sum));
253 }
254 }
255}
256
257// For each pair of adjacent elements in |data|, use |extract()| to extract a
258// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
259// will be the time of the second element in the pair.
260template <typename DataType, typename ResultType>
261void AccumulatePairs(
262 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
263 const DataType&)> extract,
264 const std::vector<DataType>& data,
265 uint64_t begin_time,
266 TimeSeries* result) {
267 ResultType sum = 0;
268 for (size_t i = 1; i < data.size(); i++) {
269 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
270 rtc::Optional<ResultType> y = extract(data[i - 1], data[i]);
271 if (y)
272 sum += *y;
273 result->points.emplace_back(x, static_cast<float>(sum));
tereliusccbbf8d2016-08-10 07:34:28 -0700274 }
275}
276
terelius6addf492016-08-23 17:34:07 -0700277// Calculates a moving average of |data| and stores the result in a TimeSeries.
278// A data point is generated every |step| microseconds from |begin_time|
279// to |end_time|. The value of each data point is the average of the data
280// during the preceeding |window_duration_us| microseconds.
terelius53dc23c2017-03-13 05:24:05 -0700281template <typename DataType, typename ResultType>
282void MovingAverage(
283 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
284 const std::vector<DataType>& data,
285 uint64_t begin_time,
286 uint64_t end_time,
287 uint64_t window_duration_us,
288 uint64_t step,
289 webrtc::plotting::TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700290 size_t window_index_begin = 0;
291 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700292 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700293
294 for (uint64_t t = begin_time; t < end_time + step; t += step) {
295 while (window_index_end < data.size() &&
296 data[window_index_end].timestamp < t) {
terelius53dc23c2017-03-13 05:24:05 -0700297 rtc::Optional<ResultType> value = extract(data[window_index_end]);
298 if (value)
299 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700300 ++window_index_end;
301 }
302 while (window_index_begin < data.size() &&
303 data[window_index_begin].timestamp < t - window_duration_us) {
terelius53dc23c2017-03-13 05:24:05 -0700304 rtc::Optional<ResultType> value = extract(data[window_index_begin]);
305 if (value)
306 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700307 ++window_index_begin;
308 }
309 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
310 float x = static_cast<float>(t - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700311 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700312 result->points.emplace_back(x, y);
313 }
314}
315
terelius54ce6802016-07-13 06:44:41 -0700316} // namespace
317
terelius54ce6802016-07-13 06:44:41 -0700318EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
319 : parsed_log_(log), window_duration_(250000), step_(10000) {
320 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
321 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700322
terelius88e64e52016-07-19 01:51:06 -0700323 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700324 uint8_t header[IP_PACKET_SIZE];
325 size_t header_length;
326 size_t total_length;
327
perkjbbbad6d2017-05-19 06:30:28 -0700328 uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE];
329 uint8_t last_incoming_rtcp_packet_length = 0;
330
ivocaac9d6f2016-09-22 07:01:47 -0700331 // Make a default extension map for streams without configuration information.
332 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
333 // this can be removed. Tracking bug: webrtc:6399
334 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
335
henrik.lundin3c938fc2017-06-14 06:09:58 -0700336 rtc::Optional<uint64_t> last_log_start;
337
terelius54ce6802016-07-13 06:44:41 -0700338 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
339 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700340 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
341 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
342 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700343 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
344 event_type != ParsedRtcEventLog::LOG_START &&
345 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700346 uint64_t timestamp = parsed_log_.GetTimestamp(i);
347 first_timestamp = std::min(first_timestamp, timestamp);
348 last_timestamp = std::max(last_timestamp, timestamp);
349 }
350
351 switch (parsed_log_.GetEventType(i)) {
352 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700353 rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i);
perkj09e71da2017-05-22 03:26:49 -0700354 StreamId stream(config.remote_ssrc, kIncomingPacket);
terelius0740a202016-08-08 10:21:04 -0700355 video_ssrcs_.insert(stream);
perkj09e71da2017-05-22 03:26:49 -0700356 StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket);
brandtr14742122017-01-27 04:53:07 -0800357 video_ssrcs_.insert(rtx_stream);
358 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700359 break;
360 }
361 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700362 std::vector<rtclog::StreamConfig> configs =
363 parsed_log_.GetVideoSendConfig(i);
terelius405f90c2017-06-01 03:50:31 -0700364 for (const auto& config : configs) {
365 StreamId stream(config.local_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700366 video_ssrcs_.insert(stream);
terelius405f90c2017-06-01 03:50:31 -0700367 StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700368 video_ssrcs_.insert(rtx_stream);
369 rtx_ssrcs_.insert(rtx_stream);
370 }
terelius88e64e52016-07-19 01:51:06 -0700371 break;
372 }
373 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700374 rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i);
perkjac8f52d2017-05-22 09:36:28 -0700375 StreamId stream(config.remote_ssrc, kIncomingPacket);
ivoce0928d82016-10-10 05:12:51 -0700376 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700377 break;
378 }
379 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700380 rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i);
perkjf4726992017-05-22 10:12:26 -0700381 StreamId stream(config.local_ssrc, kOutgoingPacket);
ivoce0928d82016-10-10 05:12:51 -0700382 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700383 break;
384 }
385 case ParsedRtcEventLog::RTP_EVENT: {
ilnika8e781a2017-06-12 01:02:46 -0700386 RtpHeaderExtensionMap* extension_map = parsed_log_.GetRtpHeader(
Elad Alon1d87b0e2017-10-03 15:01:03 +0200387 i, &direction, header, &header_length, &total_length, nullptr);
terelius88e64e52016-07-19 01:51:06 -0700388 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
389 RTPHeader parsed_header;
ilnika8e781a2017-06-12 01:02:46 -0700390 if (extension_map != nullptr) {
terelius88e64e52016-07-19 01:51:06 -0700391 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700392 } else {
393 // Use the default extension map.
394 // TODO(ivoc): Once configuration of audio streams is stored in the
395 // event log, this can be removed.
396 // Tracking bug: webrtc:6399
397 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700398 }
399 uint64_t timestamp = parsed_log_.GetTimestamp(i);
ilnika8e781a2017-06-12 01:02:46 -0700400 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700401 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200402 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700403 break;
404 }
405 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200406 uint8_t packet[IP_PACKET_SIZE];
perkj77cd58e2017-05-30 03:52:10 -0700407 parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length);
perkjbbbad6d2017-05-19 06:30:28 -0700408 // Currently incoming RTCP packets are logged twice, both for audio and
409 // video. Only act on one of them. Compare against the previous parsed
410 // incoming RTCP packet.
411 if (direction == webrtc::kIncomingPacket) {
412 RTC_CHECK_LE(total_length, IP_PACKET_SIZE);
413 if (total_length == last_incoming_rtcp_packet_length &&
414 memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) {
415 continue;
416 } else {
417 memcpy(last_incoming_rtcp_packet, packet, total_length);
418 last_incoming_rtcp_packet_length = total_length;
419 }
420 }
421 rtcp::CommonHeader header;
422 const uint8_t* packet_end = packet + total_length;
423 for (const uint8_t* block = packet; block < packet_end;
424 block = header.NextPacket()) {
425 RTC_CHECK(header.Parse(block, packet_end - block));
426 if (header.type() == rtcp::TransportFeedback::kPacketType &&
427 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
428 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700429 rtc::MakeUnique<rtcp::TransportFeedback>());
perkjbbbad6d2017-05-19 06:30:28 -0700430 if (rtcp_packet->Parse(header)) {
431 uint32_t ssrc = rtcp_packet->sender_ssrc();
432 StreamId stream(ssrc, direction);
433 uint64_t timestamp = parsed_log_.GetTimestamp(i);
434 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
435 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
436 }
437 } else if (header.type() == rtcp::SenderReport::kPacketType) {
438 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700439 rtc::MakeUnique<rtcp::SenderReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700440 if (rtcp_packet->Parse(header)) {
441 uint32_t ssrc = rtcp_packet->sender_ssrc();
442 StreamId stream(ssrc, direction);
443 uint64_t timestamp = parsed_log_.GetTimestamp(i);
444 rtcp_packets_[stream].push_back(
445 LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet)));
446 }
447 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
448 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700449 rtc::MakeUnique<rtcp::ReceiverReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700450 if (rtcp_packet->Parse(header)) {
451 uint32_t ssrc = rtcp_packet->sender_ssrc();
452 StreamId stream(ssrc, direction);
453 uint64_t timestamp = parsed_log_.GetTimestamp(i);
454 rtcp_packets_[stream].push_back(
455 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet)));
Stefan Holmer13181032016-07-29 14:48:54 +0200456 }
terelius2c8e8a32017-06-02 01:29:48 -0700457 } else if (header.type() == rtcp::Remb::kPacketType &&
458 header.fmt() == rtcp::Remb::kFeedbackMessageType) {
459 std::unique_ptr<rtcp::Remb> rtcp_packet(
460 rtc::MakeUnique<rtcp::Remb>());
461 if (rtcp_packet->Parse(header)) {
462 uint32_t ssrc = rtcp_packet->sender_ssrc();
463 StreamId stream(ssrc, direction);
464 uint64_t timestamp = parsed_log_.GetTimestamp(i);
465 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
466 timestamp, kRtcpRemb, std::move(rtcp_packet)));
467 }
Stefan Holmer13181032016-07-29 14:48:54 +0200468 }
Stefan Holmer13181032016-07-29 14:48:54 +0200469 }
terelius88e64e52016-07-19 01:51:06 -0700470 break;
471 }
472 case ParsedRtcEventLog::LOG_START: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700473 if (last_log_start) {
474 // A LOG_END event was missing. Use last_timestamp.
475 RTC_DCHECK_GE(last_timestamp, *last_log_start);
476 log_segments_.push_back(
477 std::make_pair(*last_log_start, last_timestamp));
478 }
479 last_log_start = rtc::Optional<uint64_t>(parsed_log_.GetTimestamp(i));
terelius88e64e52016-07-19 01:51:06 -0700480 break;
481 }
482 case ParsedRtcEventLog::LOG_END: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700483 RTC_DCHECK(last_log_start);
484 log_segments_.push_back(
485 std::make_pair(*last_log_start, parsed_log_.GetTimestamp(i)));
486 last_log_start.reset();
terelius88e64e52016-07-19 01:51:06 -0700487 break;
488 }
terelius424e6cf2017-02-20 05:14:41 -0800489 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700490 uint32_t this_ssrc;
491 parsed_log_.GetAudioPlayout(i, &this_ssrc);
492 audio_playout_events_[this_ssrc].push_back(parsed_log_.GetTimestamp(i));
terelius424e6cf2017-02-20 05:14:41 -0800493 break;
494 }
495 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
496 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700497 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800498 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
499 &bwe_update.fraction_loss,
500 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700501 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700502 break;
503 }
terelius424e6cf2017-02-20 05:14:41 -0800504 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
philipel10fc0e62017-04-11 01:50:23 -0700505 bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i));
terelius424e6cf2017-02-20 05:14:41 -0800506 break;
507 }
minyue4b7c9522017-01-24 04:54:59 -0800508 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800509 AudioNetworkAdaptationEvent ana_event;
510 ana_event.timestamp = parsed_log_.GetTimestamp(i);
511 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
512 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800513 break;
514 }
philipel32d00102017-02-27 02:18:46 -0800515 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200516 bwe_probe_cluster_created_events_.push_back(
517 parsed_log_.GetBweProbeClusterCreated(i));
philipel32d00102017-02-27 02:18:46 -0800518 break;
519 }
520 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200521 bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i));
philipel32d00102017-02-27 02:18:46 -0800522 break;
523 }
terelius88e64e52016-07-19 01:51:06 -0700524 case ParsedRtcEventLog::UNKNOWN_EVENT: {
525 break;
526 }
527 }
terelius54ce6802016-07-13 06:44:41 -0700528 }
terelius88e64e52016-07-19 01:51:06 -0700529
terelius54ce6802016-07-13 06:44:41 -0700530 if (last_timestamp < first_timestamp) {
531 // No useful events in the log.
532 first_timestamp = last_timestamp = 0;
533 }
534 begin_time_ = first_timestamp;
535 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700536 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700537 if (last_log_start) {
538 // The log was missing the last LOG_END event. Fake it.
539 log_segments_.push_back(std::make_pair(*last_log_start, end_time_));
540 }
terelius54ce6802016-07-13 06:44:41 -0700541}
542
Niels Möller245f17e2017-08-21 10:45:07 +0200543class BitrateObserver : public SendSideCongestionController::Observer,
Stefan Holmer13181032016-07-29 14:48:54 +0200544 public RemoteBitrateObserver {
545 public:
546 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
547
548 void OnNetworkChanged(uint32_t bitrate_bps,
549 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800550 int64_t rtt_ms,
551 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200552 last_bitrate_bps_ = bitrate_bps;
553 bitrate_updated_ = true;
554 }
555
556 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
557 uint32_t bitrate) override {}
558
559 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
560 bool GetAndResetBitrateUpdated() {
561 bool bitrate_updated = bitrate_updated_;
562 bitrate_updated_ = false;
563 return bitrate_updated;
564 }
565
566 private:
567 uint32_t last_bitrate_bps_;
568 bool bitrate_updated_;
569};
570
Stefan Holmer99f8e082016-09-09 13:37:50 +0200571bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700572 return rtx_ssrcs_.count(stream_id) == 1;
573}
574
Stefan Holmer99f8e082016-09-09 13:37:50 +0200575bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700576 return video_ssrcs_.count(stream_id) == 1;
577}
578
Stefan Holmer99f8e082016-09-09 13:37:50 +0200579bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700580 return audio_ssrcs_.count(stream_id) == 1;
581}
582
Stefan Holmer99f8e082016-09-09 13:37:50 +0200583std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
584 std::stringstream name;
585 if (IsAudioSsrc(stream_id)) {
586 name << "Audio ";
587 } else if (IsVideoSsrc(stream_id)) {
588 name << "Video ";
589 } else {
590 name << "Unknown ";
591 }
592 if (IsRtxSsrc(stream_id))
593 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700594 if (stream_id.GetDirection() == kIncomingPacket) {
595 name << "(In) ";
596 } else {
597 name << "(Out) ";
598 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200599 name << SsrcToString(stream_id.GetSsrc());
600 return name.str();
601}
602
Bjorn Terelius0295a962017-10-25 17:42:41 +0200603// This is much more reliable for outgoing streams than for incoming streams.
604rtc::Optional<uint32_t> EventLogAnalyzer::EstimateRtpClockFrequency(
605 const std::vector<LoggedRtpPacket>& packets) const {
606 RTC_CHECK(packets.size() >= 2);
607 uint64_t end_time_us = log_segments_.empty()
608 ? std::numeric_limits<uint64_t>::max()
609 : log_segments_.front().second;
610 SeqNumUnwrapper<uint32_t> unwrapper;
611 uint64_t first_rtp_timestamp = unwrapper.Unwrap(packets[0].header.timestamp);
612 uint64_t first_log_timestamp = packets[0].timestamp;
613 uint64_t last_rtp_timestamp = first_rtp_timestamp;
614 uint64_t last_log_timestamp = first_log_timestamp;
615 for (size_t i = 1; i < packets.size(); i++) {
616 if (packets[i].timestamp > end_time_us)
617 break;
618 last_rtp_timestamp = unwrapper.Unwrap(packets[i].header.timestamp);
619 last_log_timestamp = packets[i].timestamp;
620 }
621 if (last_log_timestamp - first_log_timestamp < 1000000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100622 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +0200623 << "Failed to estimate RTP clock frequency: Stream too short. ("
624 << packets.size() << " packets, "
625 << last_log_timestamp - first_log_timestamp << " us)";
626 return rtc::Optional<uint32_t>();
627 }
628 double duration =
629 static_cast<double>(last_log_timestamp - first_log_timestamp) / 1000000;
630 double estimated_frequency =
631 (last_rtp_timestamp - first_rtp_timestamp) / duration;
632 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
633 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
634 return rtc::Optional<uint32_t>(f);
635 }
636 }
Mirko Bonadei675513b2017-11-09 11:09:25 +0100637 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
638 << estimated_frequency
639 << "not close to any stardard RTP frequency.";
Bjorn Terelius0295a962017-10-25 17:42:41 +0200640 return rtc::Optional<uint32_t>();
641}
642
terelius54ce6802016-07-13 06:44:41 -0700643void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
644 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700645 for (auto& kv : rtp_packets_) {
646 StreamId stream_id = kv.first;
647 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
648 // Filter on direction and SSRC.
649 if (stream_id.GetDirection() != desired_direction ||
650 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
651 continue;
terelius54ce6802016-07-13 06:44:41 -0700652 }
terelius54ce6802016-07-13 06:44:41 -0700653
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100654 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700655 ProcessPoints<LoggedRtpPacket>(
656 [](const LoggedRtpPacket& packet) -> rtc::Optional<float> {
657 return rtc::Optional<float>(packet.total_length);
658 },
659 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700660 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700661 }
662
tereliusdc35dcd2016-08-01 12:03:27 -0700663 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
664 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
665 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700666 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700667 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700668 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700669 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700670 }
671}
672
philipelccd74892016-09-05 02:46:25 -0700673template <typename T>
674void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
675 PacketDirection desired_direction,
676 Plot* plot,
677 const std::map<StreamId, std::vector<T>>& packets,
678 const std::string& label_prefix) {
679 for (auto& kv : packets) {
680 StreamId stream_id = kv.first;
681 const std::vector<T>& packet_stream = kv.second;
682 // Filter on direction and SSRC.
683 if (stream_id.GetDirection() != desired_direction ||
684 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
685 continue;
686 }
687
terelius23c595a2017-03-15 01:59:12 -0700688 std::string label = label_prefix + " " + GetStreamName(stream_id);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100689 TimeSeries time_series(label, LineStyle::kStep);
philipelccd74892016-09-05 02:46:25 -0700690 for (size_t i = 0; i < packet_stream.size(); i++) {
691 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
692 1000000;
philipelccd74892016-09-05 02:46:25 -0700693 time_series.points.emplace_back(x, i + 1);
694 }
695
philipel35ba9bd2017-04-19 05:58:51 -0700696 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700697 }
698}
699
700void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
701 PacketDirection desired_direction,
702 Plot* plot) {
703 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
704 "RTP");
705 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
706 "RTCP");
707
708 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
709 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
710 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
711 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
712 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
713 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
714 }
715}
716
terelius54ce6802016-07-13 06:44:41 -0700717// For each SSRC, plot the time between the consecutive playouts.
718void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
719 std::map<uint32_t, TimeSeries> time_series;
720 std::map<uint32_t, uint64_t> last_playout;
721
722 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700723
724 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
725 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
726 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
727 parsed_log_.GetAudioPlayout(i, &ssrc);
728 uint64_t timestamp = parsed_log_.GetTimestamp(i);
729 if (MatchingSsrc(ssrc, desired_ssrc_)) {
730 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
731 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
732 if (time_series[ssrc].points.size() == 0) {
733 // There were no previusly logged playout for this SSRC.
734 // Generate a point, but place it on the x-axis.
735 y = 0;
736 }
terelius54ce6802016-07-13 06:44:41 -0700737 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
738 last_playout[ssrc] = timestamp;
739 }
740 }
741 }
742
743 // Set labels and put in graph.
744 for (auto& kv : time_series) {
745 kv.second.label = SsrcToString(kv.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100746 kv.second.line_style = LineStyle::kBar;
philipel35ba9bd2017-04-19 05:58:51 -0700747 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700748 }
749
tereliusdc35dcd2016-08-01 12:03:27 -0700750 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
751 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
752 kTopMargin);
753 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700754}
755
ivocaac9d6f2016-09-22 07:01:47 -0700756// For audio SSRCs, plot the audio level.
757void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
758 std::map<StreamId, TimeSeries> time_series;
759
760 for (auto& kv : rtp_packets_) {
761 StreamId stream_id = kv.first;
762 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
763 // TODO(ivoc): When audio send/receive configs are stored in the event
764 // log, a check should be added here to only process audio
765 // streams. Tracking bug: webrtc:6399
766 for (auto& packet : packet_stream) {
767 if (packet.header.extension.hasAudioLevel) {
768 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
769 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
770 // Here we convert it to dBov.
771 float y = static_cast<float>(-packet.header.extension.audioLevel);
772 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
773 }
774 }
775 }
776
777 for (auto& series : time_series) {
778 series.second.label = GetStreamName(series.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100779 series.second.line_style = LineStyle::kLine;
philipel35ba9bd2017-04-19 05:58:51 -0700780 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700781 }
782
783 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800784 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700785 kTopMargin);
786 plot->SetTitle("Audio level");
787}
788
terelius54ce6802016-07-13 06:44:41 -0700789// For each SSRC, plot the time between the consecutive playouts.
790void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700791 for (auto& kv : rtp_packets_) {
792 StreamId stream_id = kv.first;
793 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
794 // Filter on direction and SSRC.
795 if (stream_id.GetDirection() != kIncomingPacket ||
796 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
797 continue;
terelius54ce6802016-07-13 06:44:41 -0700798 }
terelius54ce6802016-07-13 06:44:41 -0700799
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100800 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700801 ProcessPairs<LoggedRtpPacket, float>(
802 [](const LoggedRtpPacket& old_packet,
803 const LoggedRtpPacket& new_packet) {
804 int64_t diff =
805 WrappingDifference(new_packet.header.sequenceNumber,
806 old_packet.header.sequenceNumber, 1ul << 16);
807 return rtc::Optional<float>(diff);
808 },
809 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700810 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700811 }
812
tereliusdc35dcd2016-08-01 12:03:27 -0700813 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
814 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
815 kTopMargin);
816 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700817}
818
Stefan Holmer99f8e082016-09-09 13:37:50 +0200819void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
820 for (auto& kv : rtp_packets_) {
821 StreamId stream_id = kv.first;
822 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
823 // Filter on direction and SSRC.
824 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800825 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
826 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200827 continue;
828 }
829
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100830 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine,
831 PointStyle::kHighlight);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200832 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800833 const uint64_t kStep = 1000000;
834 SequenceNumberUnwrapper unwrapper_;
835 SequenceNumberUnwrapper prior_unwrapper_;
836 size_t window_index_begin = 0;
837 size_t window_index_end = 0;
838 int64_t highest_seq_number =
839 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
840 int64_t highest_prior_seq_number =
841 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
842
843 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
844 while (window_index_end < packet_stream.size() &&
845 packet_stream[window_index_end].timestamp < t) {
846 int64_t sequence_number = unwrapper_.Unwrap(
847 packet_stream[window_index_end].header.sequenceNumber);
848 highest_seq_number = std::max(highest_seq_number, sequence_number);
849 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200850 }
terelius4c9b4af2017-01-30 08:44:51 -0800851 while (window_index_begin < packet_stream.size() &&
852 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
853 int64_t sequence_number = prior_unwrapper_.Unwrap(
854 packet_stream[window_index_begin].header.sequenceNumber);
855 highest_prior_seq_number =
856 std::max(highest_prior_seq_number, sequence_number);
857 ++window_index_begin;
858 }
859 float x = static_cast<float>(t - begin_time_) / 1000000;
860 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
861 if (expected_packets > 0) {
862 int64_t received_packets = window_index_end - window_index_begin;
863 int64_t lost_packets = expected_packets - received_packets;
864 float y = static_cast<float>(lost_packets) / expected_packets * 100;
865 time_series.points.emplace_back(x, y);
866 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200867 }
philipel35ba9bd2017-04-19 05:58:51 -0700868 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200869 }
870
871 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
872 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
873 kTopMargin);
874 plot->SetTitle("Estimated incoming loss rate");
875}
876
terelius2ee076d2017-08-15 02:04:02 -0700877void EventLogAnalyzer::CreateIncomingDelayDeltaGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700878 for (auto& kv : rtp_packets_) {
879 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700880 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700881 // Filter on direction and SSRC.
882 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200883 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
884 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
885 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700886 continue;
887 }
terelius54ce6802016-07-13 06:44:41 -0700888
terelius23c595a2017-03-15 01:59:12 -0700889 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100890 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700891 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
892 packet_stream, begin_time_,
893 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700894 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700895
terelius23c595a2017-03-15 01:59:12 -0700896 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100897 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700898 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
899 packet_stream, begin_time_,
900 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700901 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700902 }
903
tereliusdc35dcd2016-08-01 12:03:27 -0700904 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
905 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
906 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700907 plot->SetTitle("Network latency difference between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700908}
909
terelius2ee076d2017-08-15 02:04:02 -0700910void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700911 for (auto& kv : rtp_packets_) {
912 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700913 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700914 // Filter on direction and SSRC.
915 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200916 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
917 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
918 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700919 continue;
920 }
terelius54ce6802016-07-13 06:44:41 -0700921
terelius23c595a2017-03-15 01:59:12 -0700922 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100923 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -0700924 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
925 packet_stream, begin_time_,
926 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700927 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700928
terelius23c595a2017-03-15 01:59:12 -0700929 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100930 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -0700931 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
932 packet_stream, begin_time_,
933 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700934 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700935 }
936
tereliusdc35dcd2016-08-01 12:03:27 -0700937 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
938 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
939 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -0700940 plot->SetTitle("Network latency (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -0700941}
942
tereliusf736d232016-08-04 10:00:11 -0700943// Plot the fraction of packets lost (as perceived by the loss-based BWE).
944void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100945 TimeSeries time_series("Fraction lost", LineStyle::kLine,
946 PointStyle::kHighlight);
tereliusf736d232016-08-04 10:00:11 -0700947 for (auto& bwe_update : bwe_loss_updates_) {
948 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
949 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700950 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700951 }
tereliusf736d232016-08-04 10:00:11 -0700952
Bjorn Terelius19f5be32017-10-18 12:39:49 +0200953 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700954 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
955 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
956 kTopMargin);
957 plot->SetTitle("Reported packet loss");
958}
959
terelius54ce6802016-07-13 06:44:41 -0700960// Plot the total bandwidth used by all RTP streams.
961void EventLogAnalyzer::CreateTotalBitrateGraph(
962 PacketDirection desired_direction,
philipel23c7f252017-07-14 06:30:03 -0700963 Plot* plot,
964 bool show_detector_state) {
terelius54ce6802016-07-13 06:44:41 -0700965 struct TimestampSize {
966 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
967 uint64_t timestamp;
968 size_t size;
969 };
970 std::vector<TimestampSize> packets;
971
972 PacketDirection direction;
973 size_t total_length;
974
975 // Extract timestamps and sizes for the relevant packets.
976 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
977 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
978 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
Elad Alon1d87b0e2017-10-03 15:01:03 +0200979 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length,
980 nullptr);
terelius54ce6802016-07-13 06:44:41 -0700981 if (direction == desired_direction) {
982 uint64_t timestamp = parsed_log_.GetTimestamp(i);
983 packets.push_back(TimestampSize(timestamp, total_length));
984 }
985 }
986 }
987
988 size_t window_index_begin = 0;
989 size_t window_index_end = 0;
990 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700991
992 // Calculate a moving average of the bitrate and store in a TimeSeries.
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100993 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
terelius54ce6802016-07-13 06:44:41 -0700994 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
995 while (window_index_end < packets.size() &&
996 packets[window_index_end].timestamp < time) {
997 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700998 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700999 }
1000 while (window_index_begin < packets.size() &&
1001 packets[window_index_begin].timestamp < time - window_duration_) {
1002 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
1003 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -07001004 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -07001005 }
1006 float window_duration_in_seconds =
1007 static_cast<float>(window_duration_) / 1000000;
1008 float x = static_cast<float>(time - begin_time_) / 1000000;
1009 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001010 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -07001011 }
philipel35ba9bd2017-04-19 05:58:51 -07001012 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -07001013
terelius8058e582016-07-25 01:32:41 -07001014 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
1015 if (desired_direction == kOutgoingPacket) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001016 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
philipel10fc0e62017-04-11 01:50:23 -07001017 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -07001018 float x =
philipel10fc0e62017-04-11 01:50:23 -07001019 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
1020 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001021 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -07001022 }
1023
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001024 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
philipel23c7f252017-07-14 06:30:03 -07001025 IntervalSeries overusing_series("Overusing", "#ff8e82",
1026 IntervalSeries::kHorizontal);
1027 IntervalSeries underusing_series("Underusing", "#5092fc",
1028 IntervalSeries::kHorizontal);
1029 IntervalSeries normal_series("Normal", "#c4ffc4",
1030 IntervalSeries::kHorizontal);
1031 IntervalSeries* last_series = &normal_series;
1032 double last_detector_switch = 0.0;
1033
1034 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
1035
philipel10fc0e62017-04-11 01:50:23 -07001036 for (auto& delay_update : bwe_delay_updates_) {
1037 float x =
1038 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
1039 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -07001040
1041 if (last_detector_state != delay_update.detector_state) {
1042 last_series->intervals.emplace_back(last_detector_switch, x);
1043 last_detector_state = delay_update.detector_state;
1044 last_detector_switch = x;
1045
1046 switch (delay_update.detector_state) {
1047 case BandwidthUsage::kBwNormal:
1048 last_series = &normal_series;
1049 break;
1050 case BandwidthUsage::kBwUnderusing:
1051 last_series = &underusing_series;
1052 break;
1053 case BandwidthUsage::kBwOverusing:
1054 last_series = &overusing_series;
1055 break;
Elad Alon1d87b0e2017-10-03 15:01:03 +02001056 case BandwidthUsage::kLast:
1057 RTC_NOTREACHED();
philipel23c7f252017-07-14 06:30:03 -07001058 }
1059 }
1060
philipel35ba9bd2017-04-19 05:58:51 -07001061 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -07001062 }
philipele127e7a2017-03-29 16:28:53 +02001063
philipel23c7f252017-07-14 06:30:03 -07001064 RTC_CHECK(last_series);
1065 last_series->intervals.emplace_back(last_detector_switch, end_time_);
1066
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001067 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
1068 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001069 for (auto& cluster : bwe_probe_cluster_created_events_) {
1070 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
1071 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001072 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001073 }
1074
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001075 TimeSeries result_series("Probing results.", LineStyle::kNone,
1076 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001077 for (auto& result : bwe_probe_result_events_) {
1078 if (result.bitrate_bps) {
1079 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
1080 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001081 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001082 }
1083 }
philipel23c7f252017-07-14 06:30:03 -07001084
1085 if (show_detector_state) {
1086 plot->AppendIntervalSeries(std::move(overusing_series));
1087 plot->AppendIntervalSeries(std::move(underusing_series));
1088 plot->AppendIntervalSeries(std::move(normal_series));
1089 }
1090
philipel35ba9bd2017-04-19 05:58:51 -07001091 plot->AppendTimeSeries(std::move(loss_series));
1092 plot->AppendTimeSeries(std::move(delay_series));
1093 plot->AppendTimeSeries(std::move(created_series));
1094 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -07001095 }
philipele127e7a2017-03-29 16:28:53 +02001096
terelius2c8e8a32017-06-02 01:29:48 -07001097 // Overlay the incoming REMB over the outgoing bitrate
1098 // and outgoing REMB over incoming bitrate.
1099 PacketDirection remb_direction =
1100 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001101 TimeSeries remb_series("Remb", LineStyle::kStep);
terelius2c8e8a32017-06-02 01:29:48 -07001102 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
1103 for (const auto& kv : rtcp_packets_) {
1104 if (kv.first.GetDirection() == remb_direction) {
1105 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
1106 if (rtcp_packet.type == kRtcpRemb) {
1107 remb_packets.insert(
1108 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1109 }
1110 }
1111 }
1112 }
1113
1114 for (const auto& kv : remb_packets) {
1115 const LoggedRtcpPacket* const rtcp = kv.second;
1116 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
1117 float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000;
1118 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
1119 remb_series.points.emplace_back(x, y);
1120 }
1121 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1122
tereliusdc35dcd2016-08-01 12:03:27 -07001123 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1124 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001125 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001126 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001127 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001128 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001129 }
1130}
1131
1132// For each SSRC, plot the bandwidth used by that stream.
1133void EventLogAnalyzer::CreateStreamBitrateGraph(
1134 PacketDirection desired_direction,
1135 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001136 for (auto& kv : rtp_packets_) {
1137 StreamId stream_id = kv.first;
1138 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1139 // Filter on direction and SSRC.
1140 if (stream_id.GetDirection() != desired_direction ||
1141 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1142 continue;
terelius54ce6802016-07-13 06:44:41 -07001143 }
1144
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001145 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -07001146 MovingAverage<LoggedRtpPacket, double>(
1147 [](const LoggedRtpPacket& packet) {
1148 return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0);
1149 },
1150 packet_stream, begin_time_, end_time_, window_duration_, step_,
1151 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001152 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001153 }
1154
tereliusdc35dcd2016-08-01 12:03:27 -07001155 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1156 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001157 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001158 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001159 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001160 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001161 }
1162}
1163
Bjorn Terelius28db2662017-10-04 14:22:43 +02001164void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001165 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1166 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001167
1168 for (const auto& kv : rtp_packets_) {
1169 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1170 for (const LoggedRtpPacket& rtp_packet : kv.second)
1171 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1172 }
1173 }
1174
1175 for (const auto& kv : rtcp_packets_) {
1176 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1177 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1178 incoming_rtcp.insert(
1179 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1180 }
1181 }
1182
1183 SimulatedClock clock(0);
1184 BitrateObserver observer;
1185 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001186 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001187 PacedSender pacer(&clock, &packet_router, &null_event_log);
1188 SendSideCongestionController cc(&clock, &observer, &null_event_log, &pacer);
Stefan Holmer13181032016-07-29 14:48:54 +02001189 // TODO(holmer): Log the call config and use that here instead.
1190 static const uint32_t kDefaultStartBitrateBps = 300000;
1191 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1192
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001193 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1194 PointStyle::kHighlight);
1195 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1196 PointStyle::kHighlight);
1197 TimeSeries acked_estimate_time_series(
1198 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001199
1200 auto rtp_iterator = outgoing_rtp.begin();
1201 auto rtcp_iterator = incoming_rtcp.begin();
1202
1203 auto NextRtpTime = [&]() {
1204 if (rtp_iterator != outgoing_rtp.end())
1205 return static_cast<int64_t>(rtp_iterator->first);
1206 return std::numeric_limits<int64_t>::max();
1207 };
1208
1209 auto NextRtcpTime = [&]() {
1210 if (rtcp_iterator != incoming_rtcp.end())
1211 return static_cast<int64_t>(rtcp_iterator->first);
1212 return std::numeric_limits<int64_t>::max();
1213 };
1214
1215 auto NextProcessTime = [&]() {
1216 if (rtcp_iterator != incoming_rtcp.end() ||
1217 rtp_iterator != outgoing_rtp.end()) {
1218 return clock.TimeInMicroseconds() +
1219 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1220 }
1221 return std::numeric_limits<int64_t>::max();
1222 };
1223
Stefan Holmer492ee282016-10-27 17:19:20 +02001224 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001225#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1226 // The event_log_visualizer should normally not be compiled with
1227 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
1228 // However, compiling with BWE_TEST_LOGGING, runnning with --plot_sendside_bwe
1229 // and piping the output to plot_dynamics.py can be used as a hack to get the
1230 // internal state of various BWE components. In this case, it is important
1231 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
1232 // SendSideCongestionController since that would lead to duplicate outputs.
1233 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
1234 rtc::MakeUnique<BitrateEstimator>());
1235#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001236 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001237 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001238 while (time_us != std::numeric_limits<int64_t>::max()) {
1239 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1240 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001241 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001242 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1243 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001244 cc.OnTransportFeedback(
1245 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1246 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001247 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001248 rtc::Optional<uint32_t> bitrate_bps;
1249 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001250#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1251 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
1252#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
elad.alonf9490002017-03-06 05:32:21 -08001253 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001254 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1255 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1256 }
Stefan Holmer60e43462016-09-07 09:58:20 +02001257 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1258 1000000;
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001259 float y = bitrate_bps.value_or(0) / 1000;
Stefan Holmer60e43462016-09-07 09:58:20 +02001260 acked_time_series.points.emplace_back(x, y);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001261#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1262 y = acknowledged_bitrate_estimator.bitrate_bps().value_or(0) / 1000;
1263 acked_estimate_time_series.points.emplace_back(x, y);
1264#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001265 }
1266 ++rtcp_iterator;
1267 }
1268 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001269 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001270 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1271 if (rtp.header.extension.hasTransportSequenceNumber) {
1272 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001273 cc.AddPacket(rtp.header.ssrc,
1274 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001275 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001276 rtc::SentPacket sent_packet(
1277 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1278 cc.OnSentPacket(sent_packet);
1279 }
1280 ++rtp_iterator;
1281 }
stefanc3de0332016-08-02 07:22:17 -07001282 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1283 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001284 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001285 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001286 if (observer.GetAndResetBitrateUpdated() ||
1287 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001288 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001289 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1290 1000000;
1291 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001292 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001293 }
1294 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1295 }
1296 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001297 plot->AppendTimeSeries(std::move(time_series));
1298 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001299 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001300
tereliusdc35dcd2016-08-01 12:03:27 -07001301 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1302 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001303 plot->SetTitle("Simulated send-side BWE behavior");
1304}
1305
1306void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
1307 class RembInterceptingPacketRouter : public PacketRouter {
1308 public:
1309 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1310 uint32_t bitrate_bps) override {
1311 last_bitrate_bps_ = bitrate_bps;
1312 bitrate_updated_ = true;
1313 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1314 }
1315 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1316 bool GetAndResetBitrateUpdated() {
1317 bool bitrate_updated = bitrate_updated_;
1318 bitrate_updated_ = false;
1319 return bitrate_updated;
1320 }
1321
1322 private:
1323 uint32_t last_bitrate_bps_;
1324 bool bitrate_updated_;
1325 };
1326
1327 std::multimap<uint64_t, const LoggedRtpPacket*> incoming_rtp;
1328
1329 for (const auto& kv : rtp_packets_) {
1330 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket &&
1331 IsVideoSsrc(kv.first)) {
1332 for (const LoggedRtpPacket& rtp_packet : kv.second)
1333 incoming_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1334 }
1335 }
1336
1337 SimulatedClock clock(0);
1338 RembInterceptingPacketRouter packet_router;
1339 // TODO(terelius): The PacketRrouter is the used as the RemoteBitrateObserver.
1340 // Is this intentional?
1341 ReceiveSideCongestionController rscc(&clock, &packet_router);
1342 // TODO(holmer): Log the call config and use that here instead.
1343 // static const uint32_t kDefaultStartBitrateBps = 300000;
1344 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1345
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001346 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1347 PointStyle::kHighlight);
1348 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001349
1350 RateStatistics acked_bitrate(250, 8000);
1351 int64_t last_update_us = 0;
1352 for (const auto& kv : incoming_rtp) {
1353 const LoggedRtpPacket& packet = *kv.second;
1354 int64_t arrival_time_ms = packet.timestamp / 1000;
1355 size_t payload = packet.total_length; /*Should subtract header?*/
1356 clock.AdvanceTimeMicroseconds(packet.timestamp -
1357 clock.TimeInMicroseconds());
1358 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.header);
1359 acked_bitrate.Update(payload, arrival_time_ms);
1360 rtc::Optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
1361 if (bitrate_bps) {
1362 uint32_t y = *bitrate_bps / 1000;
1363 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1364 1000000;
1365 acked_time_series.points.emplace_back(x, y);
1366 }
1367 if (packet_router.GetAndResetBitrateUpdated() ||
1368 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1369 uint32_t y = packet_router.last_bitrate_bps() / 1000;
1370 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1371 1000000;
1372 time_series.points.emplace_back(x, y);
1373 last_update_us = clock.TimeInMicroseconds();
1374 }
1375 }
1376 // Add the data set to the plot.
1377 plot->AppendTimeSeries(std::move(time_series));
1378 plot->AppendTimeSeries(std::move(acked_time_series));
1379
1380 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1381 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1382 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001383}
1384
tereliuse34c19c2016-08-15 08:47:14 -07001385void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001386 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1387 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001388
1389 for (const auto& kv : rtp_packets_) {
1390 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1391 for (const LoggedRtpPacket& rtp_packet : kv.second)
1392 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1393 }
1394 }
1395
1396 for (const auto& kv : rtcp_packets_) {
1397 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1398 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1399 incoming_rtcp.insert(
1400 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1401 }
1402 }
1403
1404 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001405 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001406
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001407 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1408 PointStyle::kHighlight);
1409 TimeSeries time_series("Network Delay Change", LineStyle::kLine,
1410 PointStyle::kHighlight);
stefanc3de0332016-08-02 07:22:17 -07001411 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1412
1413 auto rtp_iterator = outgoing_rtp.begin();
1414 auto rtcp_iterator = incoming_rtcp.begin();
1415
1416 auto NextRtpTime = [&]() {
1417 if (rtp_iterator != outgoing_rtp.end())
1418 return static_cast<int64_t>(rtp_iterator->first);
1419 return std::numeric_limits<int64_t>::max();
1420 };
1421
1422 auto NextRtcpTime = [&]() {
1423 if (rtcp_iterator != incoming_rtcp.end())
1424 return static_cast<int64_t>(rtcp_iterator->first);
1425 return std::numeric_limits<int64_t>::max();
1426 };
1427
1428 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
stefana0a8ed72017-09-06 02:06:32 -07001429 int64_t prev_y = 0;
stefanc3de0332016-08-02 07:22:17 -07001430 while (time_us != std::numeric_limits<int64_t>::max()) {
1431 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1432 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1433 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1434 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1435 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001436 feedback_adapter.OnTransportFeedback(
1437 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001438 std::vector<PacketFeedback> feedback =
1439 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001440 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001441 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001442 float x =
1443 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1444 1000000;
stefana0a8ed72017-09-06 02:06:32 -07001445 if (packet.send_time_ms == -1) {
1446 late_feedback_series.points.emplace_back(x, prev_y);
1447 continue;
1448 }
1449 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1450 prev_y = y;
stefanc3de0332016-08-02 07:22:17 -07001451 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1452 time_series.points.emplace_back(x, y);
1453 }
1454 }
1455 ++rtcp_iterator;
1456 }
1457 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1458 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1459 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1460 if (rtp.header.extension.hasTransportSequenceNumber) {
1461 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001462 feedback_adapter.AddPacket(rtp.header.ssrc,
1463 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001464 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001465 feedback_adapter.OnSentPacket(
1466 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1467 }
1468 ++rtp_iterator;
1469 }
1470 time_us = std::min(NextRtpTime(), NextRtcpTime());
1471 }
1472 // We assume that the base network delay (w/o queues) is the min delay
1473 // observed during the call.
1474 for (TimeSeriesPoint& point : time_series.points)
1475 point.y -= estimated_base_delay_ms;
stefana0a8ed72017-09-06 02:06:32 -07001476 for (TimeSeriesPoint& point : late_feedback_series.points)
1477 point.y -= estimated_base_delay_ms;
stefanc3de0332016-08-02 07:22:17 -07001478 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001479 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1480 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001481
1482 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1483 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1484 plot->SetTitle("Network Delay Change.");
1485}
stefan08383272016-12-20 08:51:52 -08001486
1487std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1488 const {
1489 std::vector<std::pair<int64_t, int64_t>> timestamps;
1490 size_t largest_stream_size = 0;
1491 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1492 // Find the incoming video stream with the most number of packets that is
1493 // not rtx.
1494 for (const auto& kv : rtp_packets_) {
1495 if (kv.first.GetDirection() == kIncomingPacket &&
1496 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1497 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1498 kv.second.size() > largest_stream_size) {
1499 largest_stream_size = kv.second.size();
1500 largest_video_stream = &kv.second;
1501 }
1502 }
1503 if (largest_video_stream == nullptr) {
1504 for (auto& packet : *largest_video_stream) {
1505 if (packet.header.markerBit) {
1506 int64_t capture_ms = packet.header.timestamp / 90.0;
1507 int64_t arrival_ms = packet.timestamp / 1000.0;
1508 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1509 }
1510 }
1511 }
1512 return timestamps;
1513}
stefane372d3c2017-02-02 08:04:18 -08001514
Bjorn Terelius0295a962017-10-25 17:42:41 +02001515void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
1516 for (const auto& kv : rtp_packets_) {
1517 const std::vector<LoggedRtpPacket>& packets = kv.second;
1518 StreamId stream_id = kv.first;
Bjorn Tereliusb87c27e2017-11-09 11:55:51 +01001519 if (stream_id.GetDirection() == kIncomingPacket)
1520 continue;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001521
1522 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001523 RTC_LOG(LS_WARNING)
1524 << "Can't estimate a the RTP clock frequency or the "
1525 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001526 continue;
1527 }
1528 rtc::Optional<uint32_t> estimated_frequency =
1529 EstimateRtpClockFrequency(packets);
1530 if (!estimated_frequency)
1531 continue;
1532 if (IsVideoSsrc(stream_id) && *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001533 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001534 << "Video stream should use a 90 kHz clock but appears to use "
1535 << *estimated_frequency / 1000 << ". Discarding.";
1536 continue;
1537 }
1538
1539 TimeSeries pacer_delay_series(
1540 GetStreamName(stream_id) + "(" +
1541 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001542 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001543 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1544 uint64_t first_capture_timestamp =
1545 timestamp_unwrapper.Unwrap(packets.front().header.timestamp);
1546 uint64_t first_send_timestamp = packets.front().timestamp;
1547 for (LoggedRtpPacket packet : packets) {
1548 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
1549 packet.header.timestamp)) -
1550 first_capture_timestamp) /
1551 *estimated_frequency * 1000;
1552 double send_time_ms =
1553 static_cast<double>(packet.timestamp - first_send_timestamp) / 1000;
1554 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1555 float y = send_time_ms - capture_time_ms;
1556 pacer_delay_series.points.emplace_back(x, y);
1557 }
1558 plot->AppendTimeSeries(std::move(pacer_delay_series));
1559 }
1560
1561 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1562 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1563 plot->SetTitle(
1564 "Delay from capture to send time. (First packet normalized to 0.)");
1565}
1566
stefane372d3c2017-02-02 08:04:18 -08001567void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1568 for (const auto& kv : rtp_packets_) {
1569 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1570 StreamId stream_id = kv.first;
1571
1572 {
terelius23c595a2017-03-15 01:59:12 -07001573 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001574 LineStyle::kLine, PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001575 for (LoggedRtpPacket packet : rtp_packets) {
1576 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1577 float y = packet.header.timestamp;
1578 timestamp_data.points.emplace_back(x, y);
1579 }
philipel35ba9bd2017-04-19 05:58:51 -07001580 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001581 }
1582
1583 {
1584 auto kv = rtcp_packets_.find(stream_id);
1585 if (kv != rtcp_packets_.end()) {
1586 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001587 TimeSeries timestamp_data(
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001588 GetStreamName(stream_id) + " rtcp capture-time", LineStyle::kLine,
1589 PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001590 for (const LoggedRtcpPacket& rtcp : packets) {
1591 if (rtcp.type != kRtcpSr)
1592 continue;
1593 rtcp::SenderReport* sr;
1594 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1595 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1596 float y = sr->rtp_timestamp();
1597 timestamp_data.points.emplace_back(x, y);
1598 }
philipel35ba9bd2017-04-19 05:58:51 -07001599 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001600 }
1601 }
1602 }
1603
1604 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1605 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1606 plot->SetTitle("Timestamps");
1607}
michaelt6e5b2192017-02-22 07:33:27 -08001608
1609void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001610 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1611 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001612 ProcessPoints<AudioNetworkAdaptationEvent>(
1613 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001614 if (ana_event.config.bitrate_bps)
1615 return rtc::Optional<float>(
1616 static_cast<float>(*ana_event.config.bitrate_bps));
1617 return rtc::Optional<float>();
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()) {
1731 return rtc::Optional<int64_t>();
1732 }
1733 if (end_time_us_ && packet_stream_it_->timestamp > *end_time_us_) {
1734 return rtc::Optional<int64_t>();
1735 }
1736 // Convert from us to ms.
1737 return rtc::Optional<int64_t>(packet_stream_it_->timestamp / 1000);
1738 }
1739
1740 rtc::Optional<int64_t> NextOutputEventTime() const override {
1741 if (output_events_us_it_ == output_events_us_end_) {
1742 return rtc::Optional<int64_t>();
1743 }
1744 if (end_time_us_ && *output_events_us_it_ > *end_time_us_) {
1745 return rtc::Optional<int64_t>();
1746 }
1747 // Convert from us to ms.
1748 return rtc::Optional<int64_t>(
1749 rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000));
1750 }
1751
1752 std::unique_ptr<PacketData> PopPacket() override {
1753 if (packet_stream_it_ == packet_stream_.end()) {
1754 return std::unique_ptr<PacketData>();
1755 }
1756 std::unique_ptr<PacketData> packet_data(new PacketData());
1757 packet_data->header = packet_stream_it_->header;
1758 // Convert from us to ms.
1759 packet_data->time_ms = packet_stream_it_->timestamp / 1000.0;
1760
1761 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1762 // length according to the virtual length.
1763 packet_data->payload.SetSize(packet_stream_it_->total_length);
1764 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1765
1766 ++packet_stream_it_;
1767 return packet_data;
1768 }
1769
1770 void AdvanceOutputEvent() override {
1771 if (output_events_us_it_ != output_events_us_end_) {
1772 ++output_events_us_it_;
1773 }
1774 }
1775
1776 bool ended() const override { return !NextEventTime(); }
1777
1778 rtc::Optional<RTPHeader> NextHeader() const override {
1779 if (packet_stream_it_ == packet_stream_.end()) {
1780 return rtc::Optional<RTPHeader>();
1781 }
1782 return rtc::Optional<RTPHeader>(packet_stream_it_->header);
1783 }
1784
1785 private:
1786 const std::vector<LoggedRtpPacket>& packet_stream_;
1787 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_;
1788 std::vector<uint64_t>::const_iterator output_events_us_it_;
1789 const std::vector<uint64_t>::const_iterator output_events_us_end_;
1790 const rtc::Optional<uint64_t> end_time_us_;
1791};
1792
1793namespace {
1794// Creates a NetEq test object and all necessary input and output helpers. Runs
1795// the test and returns the NetEqDelayAnalyzer object that was used to
1796// instrument the test.
1797std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun(
1798 const std::vector<LoggedRtpPacket>* packet_stream,
1799 const std::vector<uint64_t>* output_events_us,
1800 rtc::Optional<uint64_t> end_time_us,
1801 const std::string& replacement_file_name,
1802 int file_sample_rate_hz) {
1803 std::unique_ptr<test::NetEqInput> input(
1804 new NetEqStreamInput(packet_stream, output_events_us, end_time_us));
1805
1806 constexpr int kReplacementPt = 127;
1807 std::set<uint8_t> cn_types;
1808 std::set<uint8_t> forbidden_types;
1809 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1810 cn_types, forbidden_types));
1811
1812 NetEq::Config config;
1813 config.max_packets_in_buffer = 200;
1814 config.enable_fast_accelerate = true;
1815
1816 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1817
1818 test::NetEqTest::DecoderMap codecs;
1819
1820 // Create a "replacement decoder" that produces the decoded audio by reading
1821 // from a file rather than from the encoded payloads.
1822 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1823 new test::ResampleInputAudioFile(replacement_file_name,
1824 file_sample_rate_hz));
1825 replacement_file->set_output_rate_hz(48000);
1826 std::unique_ptr<AudioDecoder> replacement_decoder(
1827 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1828 test::NetEqTest::ExtDecoderMap ext_codecs;
1829 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1830 NetEqDecoder::kDecoderArbitrary,
1831 "replacement codec"};
1832
1833 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1834 new test::NetEqDelayAnalyzer);
1835 test::DefaultNetEqTestErrorCallback error_cb;
1836 test::NetEqTest::Callbacks callbacks;
1837 callbacks.error_callback = &error_cb;
1838 callbacks.post_insert_packet = delay_cb.get();
1839 callbacks.get_audio_callback = delay_cb.get();
1840
1841 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1842 std::move(output), callbacks);
1843 test.Run();
1844 return delay_cb;
1845}
1846} // namespace
1847
1848// Plots the jitter buffer delay profile. This will plot only for the first
1849// incoming audio SSRC. If the stream contains more than one incoming audio
1850// SSRC, all but the first will be ignored.
1851void EventLogAnalyzer::CreateAudioJitterBufferGraph(
1852 const std::string& replacement_file_name,
1853 int file_sample_rate_hz,
1854 Plot* plot) {
1855 const auto& incoming_audio_kv = std::find_if(
1856 rtp_packets_.begin(), rtp_packets_.end(),
1857 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) {
1858 return kv.first.GetDirection() == kIncomingPacket &&
1859 this->IsAudioSsrc(kv.first);
1860 });
1861 if (incoming_audio_kv == rtp_packets_.end()) {
1862 // No incoming audio stream found.
1863 return;
1864 }
1865
1866 const uint32_t ssrc = incoming_audio_kv->first.GetSsrc();
1867
1868 std::map<uint32_t, std::vector<uint64_t>>::const_iterator output_events_it =
1869 audio_playout_events_.find(ssrc);
1870 if (output_events_it == audio_playout_events_.end()) {
1871 // Could not find output events with SSRC matching the input audio stream.
1872 // Using the first available stream of output events.
1873 output_events_it = audio_playout_events_.cbegin();
1874 }
1875
1876 rtc::Optional<uint64_t> end_time_us =
1877 log_segments_.empty()
1878 ? rtc::Optional<uint64_t>()
1879 : rtc::Optional<uint64_t>(log_segments_.front().second);
1880
1881 auto delay_cb = CreateNetEqTestAndRun(
1882 &incoming_audio_kv->second, &output_events_it->second, end_time_us,
1883 replacement_file_name, file_sample_rate_hz);
1884
1885 std::vector<float> send_times_s;
1886 std::vector<float> arrival_delay_ms;
1887 std::vector<float> corrected_arrival_delay_ms;
1888 std::vector<rtc::Optional<float>> playout_delay_ms;
1889 std::vector<rtc::Optional<float>> target_delay_ms;
1890 delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms,
1891 &corrected_arrival_delay_ms, &playout_delay_ms,
1892 &target_delay_ms);
1893 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size());
1894 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size());
1895 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size());
1896 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size());
1897
1898 std::map<StreamId, TimeSeries> time_series_packet_arrival;
1899 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival;
1900 std::map<StreamId, TimeSeries> time_series_play_time;
1901 std::map<StreamId, TimeSeries> time_series_target_time;
1902 float min_y_axis = 0.f;
1903 float max_y_axis = 0.f;
1904 const StreamId stream_id = incoming_audio_kv->first;
1905 for (size_t i = 0; i < send_times_s.size(); ++i) {
1906 time_series_packet_arrival[stream_id].points.emplace_back(
1907 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i]));
1908 time_series_relative_packet_arrival[stream_id].points.emplace_back(
1909 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i]));
1910 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]);
1911 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]);
1912 if (playout_delay_ms[i]) {
1913 time_series_play_time[stream_id].points.emplace_back(
1914 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i]));
1915 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]);
1916 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]);
1917 }
1918 if (target_delay_ms[i]) {
1919 time_series_target_time[stream_id].points.emplace_back(
1920 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i]));
1921 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]);
1922 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]);
1923 }
1924 }
1925
1926 // This code is adapted for a single stream. The creation of the streams above
1927 // guarantee that no more than one steam is included. If multiple streams are
1928 // to be plotted, they should likely be given distinct labels below.
1929 RTC_DCHECK_EQ(time_series_relative_packet_arrival.size(), 1);
1930 for (auto& series : time_series_relative_packet_arrival) {
1931 series.second.label = "Relative packet arrival delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001932 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001933 plot->AppendTimeSeries(std::move(series.second));
1934 }
1935 RTC_DCHECK_EQ(time_series_play_time.size(), 1);
1936 for (auto& series : time_series_play_time) {
1937 series.second.label = "Playout delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001938 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001939 plot->AppendTimeSeries(std::move(series.second));
1940 }
1941 RTC_DCHECK_EQ(time_series_target_time.size(), 1);
1942 for (auto& series : time_series_target_time) {
1943 series.second.label = "Target delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001944 series.second.line_style = LineStyle::kLine;
1945 series.second.point_style = PointStyle::kHighlight;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001946 plot->AppendTimeSeries(std::move(series.second));
1947 }
1948
1949 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1950 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin,
1951 kTopMargin);
1952 plot->SetTitle("NetEq timing");
1953}
terelius54ce6802016-07-13 06:44:41 -07001954} // namespace plotting
1955} // namespace webrtc