blob: b5b05dd218db29b3e4eb202be4a2adfb94a32c53 [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
11#include "webrtc/tools/event_log_visualizer/analyzer.h"
12
13#include <algorithm>
14#include <limits>
15#include <map>
16#include <sstream>
17#include <string>
18#include <utility>
19
terelius54ce6802016-07-13 06:44:41 -070020#include "webrtc/base/checks.h"
stefan6a850c32016-07-29 10:28:08 -070021#include "webrtc/base/logging.h"
terelius2c8e8a32017-06-02 01:29:48 -070022#include "webrtc/base/ptr_util.h"
Stefan Holmer60e43462016-09-07 09:58:20 +020023#include "webrtc/base/rate_statistics.h"
ossuf515ab82016-12-07 04:52:58 -080024#include "webrtc/call/audio_receive_stream.h"
25#include "webrtc/call/audio_send_stream.h"
26#include "webrtc/call/call.h"
terelius54ce6802016-07-13 06:44:41 -070027#include "webrtc/common_types.h"
Stefan Holmer13181032016-07-29 14:48:54 +020028#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
terelius4c9b4af2017-01-30 08:44:51 -080029#include "webrtc/modules/include/module_common_types.h"
terelius54ce6802016-07-13 06:44:41 -070030#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
31#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
danilchapbf369fe2016-10-07 07:39:54 -070032#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
stefane372d3c2017-02-02 08:04:18 -080033#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
terelius2c8e8a32017-06-02 01:29:48 -070034#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h"
stefane372d3c2017-02-02 08:04:18 -080035#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
Stefan Holmer13181032016-07-29 14:48:54 +020036#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
ossuf515ab82016-12-07 04:52:58 -080037#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
38#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
terelius54ce6802016-07-13 06:44:41 -070039#include "webrtc/video_receive_stream.h"
40#include "webrtc/video_send_stream.h"
41
tereliusdc35dcd2016-08-01 12:03:27 -070042namespace webrtc {
43namespace plotting {
44
terelius54ce6802016-07-13 06:44:41 -070045namespace {
46
elad.alonec304f92017-03-08 05:03:53 -080047class PacketFeedbackComparator {
48 public:
49 inline bool operator()(const webrtc::PacketFeedback& lhs,
50 const webrtc::PacketFeedback& rhs) {
51 if (lhs.arrival_time_ms != rhs.arrival_time_ms)
52 return lhs.arrival_time_ms < rhs.arrival_time_ms;
53 if (lhs.send_time_ms != rhs.send_time_ms)
54 return lhs.send_time_ms < rhs.send_time_ms;
55 return lhs.sequence_number < rhs.sequence_number;
56 }
57};
58
59void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
60 auto pred = [](const PacketFeedback& packet_feedback) {
61 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
62 };
63 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
64 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
65}
66
terelius54ce6802016-07-13 06:44:41 -070067std::string SsrcToString(uint32_t ssrc) {
68 std::stringstream ss;
69 ss << "SSRC " << ssrc;
70 return ss.str();
71}
72
73// Checks whether an SSRC is contained in the list of desired SSRCs.
74// Note that an empty SSRC list matches every SSRC.
75bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
76 if (desired_ssrc.size() == 0)
77 return true;
78 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
79 desired_ssrc.end();
80}
81
82double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
83 // The timestamp is a fixed point representation with 6 bits for seconds
84 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
85 // time in seconds and then multiply by 1000000 to convert to microseconds.
86 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070087 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070088 return abs_send_time * kTimestampToMicroSec;
89}
90
91// Computes the difference |later| - |earlier| where |later| and |earlier|
92// are counters that wrap at |modulus|. The difference is chosen to have the
93// least absolute value. For example if |modulus| is 8, then the difference will
94// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
95// be in [-4, 4].
96int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
97 RTC_DCHECK_LE(1, modulus);
98 RTC_DCHECK_LT(later, modulus);
99 RTC_DCHECK_LT(earlier, modulus);
100 int64_t difference =
101 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
102 int64_t max_difference = modulus / 2;
103 int64_t min_difference = max_difference - modulus + 1;
104 if (difference > max_difference) {
105 difference -= modulus;
106 }
107 if (difference < min_difference) {
108 difference += modulus;
109 }
terelius6addf492016-08-23 17:34:07 -0700110 if (difference > max_difference / 2 || difference < min_difference / 2) {
111 LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
112 << " expected to be in the range (" << min_difference / 2
113 << "," << max_difference / 2 << ") but is " << difference
114 << ". Correct unwrapping is uncertain.";
115 }
terelius54ce6802016-07-13 06:44:41 -0700116 return difference;
117}
118
ivocaac9d6f2016-09-22 07:01:47 -0700119// Return default values for header extensions, to use on streams without stored
120// mapping data. Currently this only applies to audio streams, since the mapping
121// is not stored in the event log.
122// TODO(ivoc): Remove this once this mapping is stored in the event log for
123// audio streams. Tracking bug: webrtc:6399
124webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
125 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800126 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
127 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700128 webrtc::RtpExtension::kAbsSendTimeDefaultId);
129 return default_map;
130}
131
tereliusdc35dcd2016-08-01 12:03:27 -0700132constexpr float kLeftMargin = 0.01f;
133constexpr float kRightMargin = 0.02f;
134constexpr float kBottomMargin = 0.02f;
135constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700136
terelius53dc23c2017-03-13 05:24:05 -0700137rtc::Optional<double> NetworkDelayDiff_AbsSendTime(
138 const LoggedRtpPacket& old_packet,
139 const LoggedRtpPacket& new_packet) {
140 if (old_packet.header.extension.hasAbsoluteSendTime &&
141 new_packet.header.extension.hasAbsoluteSendTime) {
142 int64_t send_time_diff = WrappingDifference(
143 new_packet.header.extension.absoluteSendTime,
144 old_packet.header.extension.absoluteSendTime, 1ul << 24);
145 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
146 double delay_change_us =
147 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
148 return rtc::Optional<double>(delay_change_us / 1000);
149 } else {
150 return rtc::Optional<double>();
terelius6addf492016-08-23 17:34:07 -0700151 }
152}
153
terelius53dc23c2017-03-13 05:24:05 -0700154rtc::Optional<double> NetworkDelayDiff_CaptureTime(
155 const LoggedRtpPacket& old_packet,
156 const LoggedRtpPacket& new_packet) {
157 int64_t send_time_diff = WrappingDifference(
158 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
159 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
160
161 const double kVideoSampleRate = 90000;
162 // TODO(terelius): We treat all streams as video for now, even though
163 // audio might be sampled at e.g. 16kHz, because it is really difficult to
164 // figure out the true sampling rate of a stream. The effect is that the
165 // delay will be scaled incorrectly for non-video streams.
166
167 double delay_change =
168 static_cast<double>(recv_time_diff) / 1000 -
169 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
170 if (delay_change < -10000 || 10000 < delay_change) {
171 LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
172 LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
173 << ", received time " << old_packet.timestamp;
174 LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
175 << ", received time " << new_packet.timestamp;
176 LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
177 << static_cast<double>(recv_time_diff) / 1000000 << "s";
178 LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
179 << static_cast<double>(send_time_diff) / kVideoSampleRate
180 << "s";
181 }
182 return rtc::Optional<double>(delay_change);
183}
184
185// For each element in data, use |get_y()| to extract a y-coordinate and
186// store the result in a TimeSeries.
187template <typename DataType>
188void ProcessPoints(
189 rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y,
190 const std::vector<DataType>& data,
191 uint64_t begin_time,
192 TimeSeries* result) {
193 for (size_t i = 0; i < data.size(); i++) {
194 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
195 rtc::Optional<float> y = get_y(data[i]);
196 if (y)
197 result->points.emplace_back(x, *y);
198 }
199}
200
201// For each pair of adjacent elements in |data|, use |get_y| to extract a
terelius6addf492016-08-23 17:34:07 -0700202// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
203// will be the time of the second element in the pair.
terelius53dc23c2017-03-13 05:24:05 -0700204template <typename DataType, typename ResultType>
205void ProcessPairs(
206 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
207 const DataType&)> get_y,
208 const std::vector<DataType>& data,
209 uint64_t begin_time,
210 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700211 for (size_t i = 1; i < data.size(); i++) {
212 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700213 rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]);
214 if (y)
215 result->points.emplace_back(x, static_cast<float>(*y));
216 }
217}
218
219// For each element in data, use |extract()| to extract a y-coordinate and
220// store the result in a TimeSeries.
221template <typename DataType, typename ResultType>
222void AccumulatePoints(
223 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
224 const std::vector<DataType>& data,
225 uint64_t begin_time,
226 TimeSeries* result) {
227 ResultType sum = 0;
228 for (size_t i = 0; i < data.size(); i++) {
229 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
230 rtc::Optional<ResultType> y = extract(data[i]);
231 if (y) {
232 sum += *y;
233 result->points.emplace_back(x, static_cast<float>(sum));
234 }
235 }
236}
237
238// For each pair of adjacent elements in |data|, use |extract()| to extract a
239// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
240// will be the time of the second element in the pair.
241template <typename DataType, typename ResultType>
242void AccumulatePairs(
243 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
244 const DataType&)> extract,
245 const std::vector<DataType>& data,
246 uint64_t begin_time,
247 TimeSeries* result) {
248 ResultType sum = 0;
249 for (size_t i = 1; i < data.size(); i++) {
250 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
251 rtc::Optional<ResultType> y = extract(data[i - 1], data[i]);
252 if (y)
253 sum += *y;
254 result->points.emplace_back(x, static_cast<float>(sum));
tereliusccbbf8d2016-08-10 07:34:28 -0700255 }
256}
257
terelius6addf492016-08-23 17:34:07 -0700258// Calculates a moving average of |data| and stores the result in a TimeSeries.
259// A data point is generated every |step| microseconds from |begin_time|
260// to |end_time|. The value of each data point is the average of the data
261// during the preceeding |window_duration_us| microseconds.
terelius53dc23c2017-03-13 05:24:05 -0700262template <typename DataType, typename ResultType>
263void MovingAverage(
264 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
265 const std::vector<DataType>& data,
266 uint64_t begin_time,
267 uint64_t end_time,
268 uint64_t window_duration_us,
269 uint64_t step,
270 webrtc::plotting::TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700271 size_t window_index_begin = 0;
272 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700273 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700274
275 for (uint64_t t = begin_time; t < end_time + step; t += step) {
276 while (window_index_end < data.size() &&
277 data[window_index_end].timestamp < t) {
terelius53dc23c2017-03-13 05:24:05 -0700278 rtc::Optional<ResultType> value = extract(data[window_index_end]);
279 if (value)
280 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700281 ++window_index_end;
282 }
283 while (window_index_begin < data.size() &&
284 data[window_index_begin].timestamp < t - window_duration_us) {
terelius53dc23c2017-03-13 05:24:05 -0700285 rtc::Optional<ResultType> value = extract(data[window_index_begin]);
286 if (value)
287 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700288 ++window_index_begin;
289 }
290 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
291 float x = static_cast<float>(t - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700292 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700293 result->points.emplace_back(x, y);
294 }
295}
296
terelius54ce6802016-07-13 06:44:41 -0700297} // namespace
298
terelius54ce6802016-07-13 06:44:41 -0700299EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
300 : parsed_log_(log), window_duration_(250000), step_(10000) {
301 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
302 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700303
Stefan Holmer13181032016-07-29 14:48:54 +0200304 // Maps a stream identifier consisting of ssrc and direction
terelius88e64e52016-07-19 01:51:06 -0700305 // to the header extensions used by that stream,
306 std::map<StreamId, RtpHeaderExtensionMap> extension_maps;
307
308 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700309 uint8_t header[IP_PACKET_SIZE];
310 size_t header_length;
311 size_t total_length;
312
perkjbbbad6d2017-05-19 06:30:28 -0700313 uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE];
314 uint8_t last_incoming_rtcp_packet_length = 0;
315
ivocaac9d6f2016-09-22 07:01:47 -0700316 // Make a default extension map for streams without configuration information.
317 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
318 // this can be removed. Tracking bug: webrtc:6399
319 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
320
terelius54ce6802016-07-13 06:44:41 -0700321 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
322 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700323 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
324 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
325 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700326 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
327 event_type != ParsedRtcEventLog::LOG_START &&
328 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700329 uint64_t timestamp = parsed_log_.GetTimestamp(i);
330 first_timestamp = std::min(first_timestamp, timestamp);
331 last_timestamp = std::max(last_timestamp, timestamp);
332 }
333
334 switch (parsed_log_.GetEventType(i)) {
335 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700336 rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i);
perkj09e71da2017-05-22 03:26:49 -0700337 StreamId stream(config.remote_ssrc, kIncomingPacket);
338 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
terelius0740a202016-08-08 10:21:04 -0700339 video_ssrcs_.insert(stream);
perkj09e71da2017-05-22 03:26:49 -0700340 StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket);
brandtr14742122017-01-27 04:53:07 -0800341 extension_maps[rtx_stream] =
perkj09e71da2017-05-22 03:26:49 -0700342 RtpHeaderExtensionMap(config.rtp_extensions);
brandtr14742122017-01-27 04:53:07 -0800343 video_ssrcs_.insert(rtx_stream);
344 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700345 break;
346 }
347 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700348 std::vector<rtclog::StreamConfig> configs =
349 parsed_log_.GetVideoSendConfig(i);
terelius405f90c2017-06-01 03:50:31 -0700350 for (const auto& config : configs) {
351 StreamId stream(config.local_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700352 extension_maps[stream] =
terelius405f90c2017-06-01 03:50:31 -0700353 RtpHeaderExtensionMap(config.rtp_extensions);
terelius8fbc7652017-05-31 02:03:16 -0700354 video_ssrcs_.insert(stream);
terelius405f90c2017-06-01 03:50:31 -0700355 StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700356 extension_maps[rtx_stream] =
terelius405f90c2017-06-01 03:50:31 -0700357 RtpHeaderExtensionMap(config.rtp_extensions);
terelius8fbc7652017-05-31 02:03:16 -0700358 video_ssrcs_.insert(rtx_stream);
359 rtx_ssrcs_.insert(rtx_stream);
360 }
terelius88e64e52016-07-19 01:51:06 -0700361 break;
362 }
363 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700364 rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i);
perkjac8f52d2017-05-22 09:36:28 -0700365 StreamId stream(config.remote_ssrc, kIncomingPacket);
366 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
ivoce0928d82016-10-10 05:12:51 -0700367 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700368 break;
369 }
370 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700371 rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i);
perkjf4726992017-05-22 10:12:26 -0700372 StreamId stream(config.local_ssrc, kOutgoingPacket);
373 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
ivoce0928d82016-10-10 05:12:51 -0700374 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700375 break;
376 }
377 case ParsedRtcEventLog::RTP_EVENT: {
perkj77cd58e2017-05-30 03:52:10 -0700378 parsed_log_.GetRtpHeader(i, &direction, header, &header_length,
379 &total_length);
terelius88e64e52016-07-19 01:51:06 -0700380 // Parse header to get SSRC.
381 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
382 RTPHeader parsed_header;
383 rtp_parser.Parse(&parsed_header);
Stefan Holmer13181032016-07-29 14:48:54 +0200384 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700385 // Look up the extension_map and parse it again to get the extensions.
386 if (extension_maps.count(stream) == 1) {
387 RtpHeaderExtensionMap* extension_map = &extension_maps[stream];
388 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700389 } else {
390 // Use the default extension map.
391 // TODO(ivoc): Once configuration of audio streams is stored in the
392 // event log, this can be removed.
393 // Tracking bug: webrtc:6399
394 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700395 }
396 uint64_t timestamp = parsed_log_.GetTimestamp(i);
397 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200398 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700399 break;
400 }
401 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200402 uint8_t packet[IP_PACKET_SIZE];
perkj77cd58e2017-05-30 03:52:10 -0700403 parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length);
perkjbbbad6d2017-05-19 06:30:28 -0700404 // Currently incoming RTCP packets are logged twice, both for audio and
405 // video. Only act on one of them. Compare against the previous parsed
406 // incoming RTCP packet.
407 if (direction == webrtc::kIncomingPacket) {
408 RTC_CHECK_LE(total_length, IP_PACKET_SIZE);
409 if (total_length == last_incoming_rtcp_packet_length &&
410 memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) {
411 continue;
412 } else {
413 memcpy(last_incoming_rtcp_packet, packet, total_length);
414 last_incoming_rtcp_packet_length = total_length;
415 }
416 }
417 rtcp::CommonHeader header;
418 const uint8_t* packet_end = packet + total_length;
419 for (const uint8_t* block = packet; block < packet_end;
420 block = header.NextPacket()) {
421 RTC_CHECK(header.Parse(block, packet_end - block));
422 if (header.type() == rtcp::TransportFeedback::kPacketType &&
423 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
424 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700425 rtc::MakeUnique<rtcp::TransportFeedback>());
perkjbbbad6d2017-05-19 06:30:28 -0700426 if (rtcp_packet->Parse(header)) {
427 uint32_t ssrc = rtcp_packet->sender_ssrc();
428 StreamId stream(ssrc, direction);
429 uint64_t timestamp = parsed_log_.GetTimestamp(i);
430 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
431 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
432 }
433 } else if (header.type() == rtcp::SenderReport::kPacketType) {
434 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700435 rtc::MakeUnique<rtcp::SenderReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700436 if (rtcp_packet->Parse(header)) {
437 uint32_t ssrc = rtcp_packet->sender_ssrc();
438 StreamId stream(ssrc, direction);
439 uint64_t timestamp = parsed_log_.GetTimestamp(i);
440 rtcp_packets_[stream].push_back(
441 LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet)));
442 }
443 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
444 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700445 rtc::MakeUnique<rtcp::ReceiverReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700446 if (rtcp_packet->Parse(header)) {
447 uint32_t ssrc = rtcp_packet->sender_ssrc();
448 StreamId stream(ssrc, direction);
449 uint64_t timestamp = parsed_log_.GetTimestamp(i);
450 rtcp_packets_[stream].push_back(
451 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet)));
Stefan Holmer13181032016-07-29 14:48:54 +0200452 }
terelius2c8e8a32017-06-02 01:29:48 -0700453 } else if (header.type() == rtcp::Remb::kPacketType &&
454 header.fmt() == rtcp::Remb::kFeedbackMessageType) {
455 std::unique_ptr<rtcp::Remb> rtcp_packet(
456 rtc::MakeUnique<rtcp::Remb>());
457 if (rtcp_packet->Parse(header)) {
458 uint32_t ssrc = rtcp_packet->sender_ssrc();
459 StreamId stream(ssrc, direction);
460 uint64_t timestamp = parsed_log_.GetTimestamp(i);
461 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
462 timestamp, kRtcpRemb, std::move(rtcp_packet)));
463 }
Stefan Holmer13181032016-07-29 14:48:54 +0200464 }
Stefan Holmer13181032016-07-29 14:48:54 +0200465 }
terelius88e64e52016-07-19 01:51:06 -0700466 break;
467 }
468 case ParsedRtcEventLog::LOG_START: {
469 break;
470 }
471 case ParsedRtcEventLog::LOG_END: {
472 break;
473 }
terelius424e6cf2017-02-20 05:14:41 -0800474 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
475 break;
476 }
477 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
478 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700479 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800480 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
481 &bwe_update.fraction_loss,
482 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700483 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700484 break;
485 }
terelius424e6cf2017-02-20 05:14:41 -0800486 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
philipel10fc0e62017-04-11 01:50:23 -0700487 bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i));
terelius424e6cf2017-02-20 05:14:41 -0800488 break;
489 }
minyue4b7c9522017-01-24 04:54:59 -0800490 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800491 AudioNetworkAdaptationEvent ana_event;
492 ana_event.timestamp = parsed_log_.GetTimestamp(i);
493 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
494 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800495 break;
496 }
philipel32d00102017-02-27 02:18:46 -0800497 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200498 bwe_probe_cluster_created_events_.push_back(
499 parsed_log_.GetBweProbeClusterCreated(i));
philipel32d00102017-02-27 02:18:46 -0800500 break;
501 }
502 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200503 bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i));
philipel32d00102017-02-27 02:18:46 -0800504 break;
505 }
terelius88e64e52016-07-19 01:51:06 -0700506 case ParsedRtcEventLog::UNKNOWN_EVENT: {
507 break;
508 }
509 }
terelius54ce6802016-07-13 06:44:41 -0700510 }
terelius88e64e52016-07-19 01:51:06 -0700511
terelius54ce6802016-07-13 06:44:41 -0700512 if (last_timestamp < first_timestamp) {
513 // No useful events in the log.
514 first_timestamp = last_timestamp = 0;
515 }
516 begin_time_ = first_timestamp;
517 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700518 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700519}
520
Stefan Holmer13181032016-07-29 14:48:54 +0200521class BitrateObserver : public CongestionController::Observer,
522 public RemoteBitrateObserver {
523 public:
524 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
525
minyue78b4d562016-11-30 04:47:39 -0800526 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
527 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
528 using CongestionController::Observer::OnNetworkChanged;
529
Stefan Holmer13181032016-07-29 14:48:54 +0200530 void OnNetworkChanged(uint32_t bitrate_bps,
531 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800532 int64_t rtt_ms,
533 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200534 last_bitrate_bps_ = bitrate_bps;
535 bitrate_updated_ = true;
536 }
537
538 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
539 uint32_t bitrate) override {}
540
541 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
542 bool GetAndResetBitrateUpdated() {
543 bool bitrate_updated = bitrate_updated_;
544 bitrate_updated_ = false;
545 return bitrate_updated;
546 }
547
548 private:
549 uint32_t last_bitrate_bps_;
550 bool bitrate_updated_;
551};
552
Stefan Holmer99f8e082016-09-09 13:37:50 +0200553bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700554 return rtx_ssrcs_.count(stream_id) == 1;
555}
556
Stefan Holmer99f8e082016-09-09 13:37:50 +0200557bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700558 return video_ssrcs_.count(stream_id) == 1;
559}
560
Stefan Holmer99f8e082016-09-09 13:37:50 +0200561bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700562 return audio_ssrcs_.count(stream_id) == 1;
563}
564
Stefan Holmer99f8e082016-09-09 13:37:50 +0200565std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
566 std::stringstream name;
567 if (IsAudioSsrc(stream_id)) {
568 name << "Audio ";
569 } else if (IsVideoSsrc(stream_id)) {
570 name << "Video ";
571 } else {
572 name << "Unknown ";
573 }
574 if (IsRtxSsrc(stream_id))
575 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700576 if (stream_id.GetDirection() == kIncomingPacket) {
577 name << "(In) ";
578 } else {
579 name << "(Out) ";
580 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200581 name << SsrcToString(stream_id.GetSsrc());
582 return name.str();
583}
584
terelius54ce6802016-07-13 06:44:41 -0700585void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
586 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700587 for (auto& kv : rtp_packets_) {
588 StreamId stream_id = kv.first;
589 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
590 // Filter on direction and SSRC.
591 if (stream_id.GetDirection() != desired_direction ||
592 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
593 continue;
terelius54ce6802016-07-13 06:44:41 -0700594 }
terelius54ce6802016-07-13 06:44:41 -0700595
terelius23c595a2017-03-15 01:59:12 -0700596 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700597 ProcessPoints<LoggedRtpPacket>(
598 [](const LoggedRtpPacket& packet) -> rtc::Optional<float> {
599 return rtc::Optional<float>(packet.total_length);
600 },
601 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700602 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700603 }
604
tereliusdc35dcd2016-08-01 12:03:27 -0700605 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
606 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
607 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700608 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700609 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700610 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700611 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700612 }
613}
614
philipelccd74892016-09-05 02:46:25 -0700615template <typename T>
616void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
617 PacketDirection desired_direction,
618 Plot* plot,
619 const std::map<StreamId, std::vector<T>>& packets,
620 const std::string& label_prefix) {
621 for (auto& kv : packets) {
622 StreamId stream_id = kv.first;
623 const std::vector<T>& packet_stream = kv.second;
624 // Filter on direction and SSRC.
625 if (stream_id.GetDirection() != desired_direction ||
626 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
627 continue;
628 }
629
terelius23c595a2017-03-15 01:59:12 -0700630 std::string label = label_prefix + " " + GetStreamName(stream_id);
631 TimeSeries time_series(label, LINE_STEP_GRAPH);
philipelccd74892016-09-05 02:46:25 -0700632 for (size_t i = 0; i < packet_stream.size(); i++) {
633 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
634 1000000;
philipelccd74892016-09-05 02:46:25 -0700635 time_series.points.emplace_back(x, i + 1);
636 }
637
philipel35ba9bd2017-04-19 05:58:51 -0700638 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700639 }
640}
641
642void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
643 PacketDirection desired_direction,
644 Plot* plot) {
645 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
646 "RTP");
647 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
648 "RTCP");
649
650 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
651 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
652 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
653 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
654 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
655 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
656 }
657}
658
terelius54ce6802016-07-13 06:44:41 -0700659// For each SSRC, plot the time between the consecutive playouts.
660void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
661 std::map<uint32_t, TimeSeries> time_series;
662 std::map<uint32_t, uint64_t> last_playout;
663
664 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700665
666 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
667 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
668 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
669 parsed_log_.GetAudioPlayout(i, &ssrc);
670 uint64_t timestamp = parsed_log_.GetTimestamp(i);
671 if (MatchingSsrc(ssrc, desired_ssrc_)) {
672 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
673 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
674 if (time_series[ssrc].points.size() == 0) {
675 // There were no previusly logged playout for this SSRC.
676 // Generate a point, but place it on the x-axis.
677 y = 0;
678 }
terelius54ce6802016-07-13 06:44:41 -0700679 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
680 last_playout[ssrc] = timestamp;
681 }
682 }
683 }
684
685 // Set labels and put in graph.
686 for (auto& kv : time_series) {
687 kv.second.label = SsrcToString(kv.first);
688 kv.second.style = BAR_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700689 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700690 }
691
tereliusdc35dcd2016-08-01 12:03:27 -0700692 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
693 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
694 kTopMargin);
695 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700696}
697
ivocaac9d6f2016-09-22 07:01:47 -0700698// For audio SSRCs, plot the audio level.
699void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
700 std::map<StreamId, TimeSeries> time_series;
701
702 for (auto& kv : rtp_packets_) {
703 StreamId stream_id = kv.first;
704 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
705 // TODO(ivoc): When audio send/receive configs are stored in the event
706 // log, a check should be added here to only process audio
707 // streams. Tracking bug: webrtc:6399
708 for (auto& packet : packet_stream) {
709 if (packet.header.extension.hasAudioLevel) {
710 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
711 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
712 // Here we convert it to dBov.
713 float y = static_cast<float>(-packet.header.extension.audioLevel);
714 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
715 }
716 }
717 }
718
719 for (auto& series : time_series) {
720 series.second.label = GetStreamName(series.first);
721 series.second.style = LINE_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700722 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700723 }
724
725 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800726 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700727 kTopMargin);
728 plot->SetTitle("Audio level");
729}
730
terelius54ce6802016-07-13 06:44:41 -0700731// For each SSRC, plot the time between the consecutive playouts.
732void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700733 for (auto& kv : rtp_packets_) {
734 StreamId stream_id = kv.first;
735 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
736 // Filter on direction and SSRC.
737 if (stream_id.GetDirection() != kIncomingPacket ||
738 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
739 continue;
terelius54ce6802016-07-13 06:44:41 -0700740 }
terelius54ce6802016-07-13 06:44:41 -0700741
terelius23c595a2017-03-15 01:59:12 -0700742 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700743 ProcessPairs<LoggedRtpPacket, float>(
744 [](const LoggedRtpPacket& old_packet,
745 const LoggedRtpPacket& new_packet) {
746 int64_t diff =
747 WrappingDifference(new_packet.header.sequenceNumber,
748 old_packet.header.sequenceNumber, 1ul << 16);
749 return rtc::Optional<float>(diff);
750 },
751 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700752 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700753 }
754
tereliusdc35dcd2016-08-01 12:03:27 -0700755 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
756 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
757 kTopMargin);
758 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700759}
760
Stefan Holmer99f8e082016-09-09 13:37:50 +0200761void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
762 for (auto& kv : rtp_packets_) {
763 StreamId stream_id = kv.first;
764 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
765 // Filter on direction and SSRC.
766 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800767 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
768 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200769 continue;
770 }
771
terelius23c595a2017-03-15 01:59:12 -0700772 TimeSeries time_series(GetStreamName(stream_id), LINE_DOT_GRAPH);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200773 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800774 const uint64_t kStep = 1000000;
775 SequenceNumberUnwrapper unwrapper_;
776 SequenceNumberUnwrapper prior_unwrapper_;
777 size_t window_index_begin = 0;
778 size_t window_index_end = 0;
779 int64_t highest_seq_number =
780 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
781 int64_t highest_prior_seq_number =
782 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
783
784 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
785 while (window_index_end < packet_stream.size() &&
786 packet_stream[window_index_end].timestamp < t) {
787 int64_t sequence_number = unwrapper_.Unwrap(
788 packet_stream[window_index_end].header.sequenceNumber);
789 highest_seq_number = std::max(highest_seq_number, sequence_number);
790 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200791 }
terelius4c9b4af2017-01-30 08:44:51 -0800792 while (window_index_begin < packet_stream.size() &&
793 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
794 int64_t sequence_number = prior_unwrapper_.Unwrap(
795 packet_stream[window_index_begin].header.sequenceNumber);
796 highest_prior_seq_number =
797 std::max(highest_prior_seq_number, sequence_number);
798 ++window_index_begin;
799 }
800 float x = static_cast<float>(t - begin_time_) / 1000000;
801 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
802 if (expected_packets > 0) {
803 int64_t received_packets = window_index_end - window_index_begin;
804 int64_t lost_packets = expected_packets - received_packets;
805 float y = static_cast<float>(lost_packets) / expected_packets * 100;
806 time_series.points.emplace_back(x, y);
807 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200808 }
philipel35ba9bd2017-04-19 05:58:51 -0700809 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200810 }
811
812 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
813 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
814 kTopMargin);
815 plot->SetTitle("Estimated incoming loss rate");
816}
817
terelius54ce6802016-07-13 06:44:41 -0700818void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700819 for (auto& kv : rtp_packets_) {
820 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700821 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700822 // Filter on direction and SSRC.
823 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200824 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
825 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
826 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700827 continue;
828 }
terelius54ce6802016-07-13 06:44:41 -0700829
terelius23c595a2017-03-15 01:59:12 -0700830 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
831 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700832 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
833 packet_stream, begin_time_,
834 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700835 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700836
terelius23c595a2017-03-15 01:59:12 -0700837 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
838 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700839 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
840 packet_stream, begin_time_,
841 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700842 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700843 }
844
tereliusdc35dcd2016-08-01 12:03:27 -0700845 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
846 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
847 kTopMargin);
848 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700849}
850
851void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700852 for (auto& kv : rtp_packets_) {
853 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700854 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700855 // Filter on direction and SSRC.
856 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200857 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
858 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
859 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700860 continue;
861 }
terelius54ce6802016-07-13 06:44:41 -0700862
terelius23c595a2017-03-15 01:59:12 -0700863 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
864 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700865 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
866 packet_stream, begin_time_,
867 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700868 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700869
terelius23c595a2017-03-15 01:59:12 -0700870 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
871 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700872 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
873 packet_stream, begin_time_,
874 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700875 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700876 }
877
tereliusdc35dcd2016-08-01 12:03:27 -0700878 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
879 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
880 kTopMargin);
881 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700882}
883
tereliusf736d232016-08-04 10:00:11 -0700884// Plot the fraction of packets lost (as perceived by the loss-based BWE).
885void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -0700886 TimeSeries time_series("Fraction lost", LINE_DOT_GRAPH);
tereliusf736d232016-08-04 10:00:11 -0700887 for (auto& bwe_update : bwe_loss_updates_) {
888 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
889 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700890 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700891 }
tereliusf736d232016-08-04 10:00:11 -0700892
893 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
894 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
895 kTopMargin);
896 plot->SetTitle("Reported packet loss");
philipel35ba9bd2017-04-19 05:58:51 -0700897 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700898}
899
terelius54ce6802016-07-13 06:44:41 -0700900// Plot the total bandwidth used by all RTP streams.
901void EventLogAnalyzer::CreateTotalBitrateGraph(
902 PacketDirection desired_direction,
903 Plot* plot) {
904 struct TimestampSize {
905 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
906 uint64_t timestamp;
907 size_t size;
908 };
909 std::vector<TimestampSize> packets;
910
911 PacketDirection direction;
912 size_t total_length;
913
914 // Extract timestamps and sizes for the relevant packets.
915 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
916 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
917 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
perkj77cd58e2017-05-30 03:52:10 -0700918 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length);
terelius54ce6802016-07-13 06:44:41 -0700919 if (direction == desired_direction) {
920 uint64_t timestamp = parsed_log_.GetTimestamp(i);
921 packets.push_back(TimestampSize(timestamp, total_length));
922 }
923 }
924 }
925
926 size_t window_index_begin = 0;
927 size_t window_index_end = 0;
928 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700929
930 // Calculate a moving average of the bitrate and store in a TimeSeries.
philipel35ba9bd2017-04-19 05:58:51 -0700931 TimeSeries bitrate_series("Bitrate", LINE_GRAPH);
terelius54ce6802016-07-13 06:44:41 -0700932 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
933 while (window_index_end < packets.size() &&
934 packets[window_index_end].timestamp < time) {
935 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700936 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700937 }
938 while (window_index_begin < packets.size() &&
939 packets[window_index_begin].timestamp < time - window_duration_) {
940 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
941 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700942 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700943 }
944 float window_duration_in_seconds =
945 static_cast<float>(window_duration_) / 1000000;
946 float x = static_cast<float>(time - begin_time_) / 1000000;
947 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700948 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700949 }
philipel35ba9bd2017-04-19 05:58:51 -0700950 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700951
terelius8058e582016-07-25 01:32:41 -0700952 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
953 if (desired_direction == kOutgoingPacket) {
philipel35ba9bd2017-04-19 05:58:51 -0700954 TimeSeries loss_series("Loss-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700955 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -0700956 float x =
philipel10fc0e62017-04-11 01:50:23 -0700957 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
958 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700959 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -0700960 }
961
philipel35ba9bd2017-04-19 05:58:51 -0700962 TimeSeries delay_series("Delay-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700963 for (auto& delay_update : bwe_delay_updates_) {
964 float x =
965 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
966 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700967 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700968 }
philipele127e7a2017-03-29 16:28:53 +0200969
philipel35ba9bd2017-04-19 05:58:51 -0700970 TimeSeries created_series("Probe cluster created.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +0200971 for (auto& cluster : bwe_probe_cluster_created_events_) {
972 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
973 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700974 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +0200975 }
976
philipel35ba9bd2017-04-19 05:58:51 -0700977 TimeSeries result_series("Probing results.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +0200978 for (auto& result : bwe_probe_result_events_) {
979 if (result.bitrate_bps) {
980 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
981 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700982 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +0200983 }
984 }
philipel35ba9bd2017-04-19 05:58:51 -0700985 plot->AppendTimeSeries(std::move(loss_series));
986 plot->AppendTimeSeries(std::move(delay_series));
987 plot->AppendTimeSeries(std::move(created_series));
988 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -0700989 }
philipele127e7a2017-03-29 16:28:53 +0200990
terelius2c8e8a32017-06-02 01:29:48 -0700991 // Overlay the incoming REMB over the outgoing bitrate
992 // and outgoing REMB over incoming bitrate.
993 PacketDirection remb_direction =
994 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
995 TimeSeries remb_series("Remb", LINE_STEP_GRAPH);
996 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
997 for (const auto& kv : rtcp_packets_) {
998 if (kv.first.GetDirection() == remb_direction) {
999 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
1000 if (rtcp_packet.type == kRtcpRemb) {
1001 remb_packets.insert(
1002 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1003 }
1004 }
1005 }
1006 }
1007
1008 for (const auto& kv : remb_packets) {
1009 const LoggedRtcpPacket* const rtcp = kv.second;
1010 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
1011 float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000;
1012 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
1013 remb_series.points.emplace_back(x, y);
1014 }
1015 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1016
tereliusdc35dcd2016-08-01 12:03:27 -07001017 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1018 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001019 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001020 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001021 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001022 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001023 }
1024}
1025
1026// For each SSRC, plot the bandwidth used by that stream.
1027void EventLogAnalyzer::CreateStreamBitrateGraph(
1028 PacketDirection desired_direction,
1029 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001030 for (auto& kv : rtp_packets_) {
1031 StreamId stream_id = kv.first;
1032 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1033 // Filter on direction and SSRC.
1034 if (stream_id.GetDirection() != desired_direction ||
1035 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1036 continue;
terelius54ce6802016-07-13 06:44:41 -07001037 }
1038
terelius23c595a2017-03-15 01:59:12 -07001039 TimeSeries time_series(GetStreamName(stream_id), LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001040 MovingAverage<LoggedRtpPacket, double>(
1041 [](const LoggedRtpPacket& packet) {
1042 return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0);
1043 },
1044 packet_stream, begin_time_, end_time_, window_duration_, step_,
1045 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001046 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001047 }
1048
tereliusdc35dcd2016-08-01 12:03:27 -07001049 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1050 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001051 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001052 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001053 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001054 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001055 }
1056}
1057
tereliuse34c19c2016-08-15 08:47:14 -07001058void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001059 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1060 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001061
1062 for (const auto& kv : rtp_packets_) {
1063 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1064 for (const LoggedRtpPacket& rtp_packet : kv.second)
1065 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1066 }
1067 }
1068
1069 for (const auto& kv : rtcp_packets_) {
1070 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1071 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1072 incoming_rtcp.insert(
1073 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1074 }
1075 }
1076
1077 SimulatedClock clock(0);
1078 BitrateObserver observer;
1079 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001080 PacketRouter packet_router;
1081 CongestionController cc(&clock, &observer, &observer, &null_event_log,
1082 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +02001083 // TODO(holmer): Log the call config and use that here instead.
1084 static const uint32_t kDefaultStartBitrateBps = 300000;
1085 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1086
terelius23c595a2017-03-15 01:59:12 -07001087 TimeSeries time_series("Delay-based estimate", LINE_DOT_GRAPH);
1088 TimeSeries acked_time_series("Acked bitrate", LINE_DOT_GRAPH);
Stefan Holmer13181032016-07-29 14:48:54 +02001089
1090 auto rtp_iterator = outgoing_rtp.begin();
1091 auto rtcp_iterator = incoming_rtcp.begin();
1092
1093 auto NextRtpTime = [&]() {
1094 if (rtp_iterator != outgoing_rtp.end())
1095 return static_cast<int64_t>(rtp_iterator->first);
1096 return std::numeric_limits<int64_t>::max();
1097 };
1098
1099 auto NextRtcpTime = [&]() {
1100 if (rtcp_iterator != incoming_rtcp.end())
1101 return static_cast<int64_t>(rtcp_iterator->first);
1102 return std::numeric_limits<int64_t>::max();
1103 };
1104
1105 auto NextProcessTime = [&]() {
1106 if (rtcp_iterator != incoming_rtcp.end() ||
1107 rtp_iterator != outgoing_rtp.end()) {
1108 return clock.TimeInMicroseconds() +
1109 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1110 }
1111 return std::numeric_limits<int64_t>::max();
1112 };
1113
Stefan Holmer492ee282016-10-27 17:19:20 +02001114 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001115
Stefan Holmer13181032016-07-29 14:48:54 +02001116 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001117 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001118 while (time_us != std::numeric_limits<int64_t>::max()) {
1119 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1120 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001121 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001122 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1123 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001124 cc.OnTransportFeedback(
1125 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1126 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001127 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001128 rtc::Optional<uint32_t> bitrate_bps;
1129 if (!feedback.empty()) {
elad.alonf9490002017-03-06 05:32:21 -08001130 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001131 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1132 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1133 }
1134 uint32_t y = 0;
1135 if (bitrate_bps)
1136 y = *bitrate_bps / 1000;
1137 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1138 1000000;
1139 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +02001140 }
1141 ++rtcp_iterator;
1142 }
1143 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001144 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001145 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1146 if (rtp.header.extension.hasTransportSequenceNumber) {
1147 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001148 cc.AddPacket(rtp.header.ssrc,
1149 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001150 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001151 rtc::SentPacket sent_packet(
1152 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1153 cc.OnSentPacket(sent_packet);
1154 }
1155 ++rtp_iterator;
1156 }
stefanc3de0332016-08-02 07:22:17 -07001157 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1158 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001159 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001160 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001161 if (observer.GetAndResetBitrateUpdated() ||
1162 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001163 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001164 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1165 1000000;
1166 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001167 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001168 }
1169 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1170 }
1171 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001172 plot->AppendTimeSeries(std::move(time_series));
1173 plot->AppendTimeSeries(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001174
tereliusdc35dcd2016-08-01 12:03:27 -07001175 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1176 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1177 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001178}
1179
tereliuse34c19c2016-08-15 08:47:14 -07001180void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001181 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1182 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001183
1184 for (const auto& kv : rtp_packets_) {
1185 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1186 for (const LoggedRtpPacket& rtp_packet : kv.second)
1187 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1188 }
1189 }
1190
1191 for (const auto& kv : rtcp_packets_) {
1192 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1193 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1194 incoming_rtcp.insert(
1195 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1196 }
1197 }
1198
1199 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001200 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001201
terelius23c595a2017-03-15 01:59:12 -07001202 TimeSeries time_series("Network Delay Change", LINE_DOT_GRAPH);
stefanc3de0332016-08-02 07:22:17 -07001203 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1204
1205 auto rtp_iterator = outgoing_rtp.begin();
1206 auto rtcp_iterator = incoming_rtcp.begin();
1207
1208 auto NextRtpTime = [&]() {
1209 if (rtp_iterator != outgoing_rtp.end())
1210 return static_cast<int64_t>(rtp_iterator->first);
1211 return std::numeric_limits<int64_t>::max();
1212 };
1213
1214 auto NextRtcpTime = [&]() {
1215 if (rtcp_iterator != incoming_rtcp.end())
1216 return static_cast<int64_t>(rtcp_iterator->first);
1217 return std::numeric_limits<int64_t>::max();
1218 };
1219
1220 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1221 while (time_us != std::numeric_limits<int64_t>::max()) {
1222 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1223 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1224 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1225 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1226 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001227 feedback_adapter.OnTransportFeedback(
1228 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001229 std::vector<PacketFeedback> feedback =
1230 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001231 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001232 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001233 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1234 float x =
1235 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1236 1000000;
1237 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1238 time_series.points.emplace_back(x, y);
1239 }
1240 }
1241 ++rtcp_iterator;
1242 }
1243 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1244 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1245 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1246 if (rtp.header.extension.hasTransportSequenceNumber) {
1247 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001248 feedback_adapter.AddPacket(rtp.header.ssrc,
1249 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001250 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001251 feedback_adapter.OnSentPacket(
1252 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1253 }
1254 ++rtp_iterator;
1255 }
1256 time_us = std::min(NextRtpTime(), NextRtcpTime());
1257 }
1258 // We assume that the base network delay (w/o queues) is the min delay
1259 // observed during the call.
1260 for (TimeSeriesPoint& point : time_series.points)
1261 point.y -= estimated_base_delay_ms;
1262 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001263 plot->AppendTimeSeries(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001264
1265 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1266 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1267 plot->SetTitle("Network Delay Change.");
1268}
stefan08383272016-12-20 08:51:52 -08001269
1270std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1271 const {
1272 std::vector<std::pair<int64_t, int64_t>> timestamps;
1273 size_t largest_stream_size = 0;
1274 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1275 // Find the incoming video stream with the most number of packets that is
1276 // not rtx.
1277 for (const auto& kv : rtp_packets_) {
1278 if (kv.first.GetDirection() == kIncomingPacket &&
1279 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1280 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1281 kv.second.size() > largest_stream_size) {
1282 largest_stream_size = kv.second.size();
1283 largest_video_stream = &kv.second;
1284 }
1285 }
1286 if (largest_video_stream == nullptr) {
1287 for (auto& packet : *largest_video_stream) {
1288 if (packet.header.markerBit) {
1289 int64_t capture_ms = packet.header.timestamp / 90.0;
1290 int64_t arrival_ms = packet.timestamp / 1000.0;
1291 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1292 }
1293 }
1294 }
1295 return timestamps;
1296}
stefane372d3c2017-02-02 08:04:18 -08001297
1298void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1299 for (const auto& kv : rtp_packets_) {
1300 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1301 StreamId stream_id = kv.first;
1302
1303 {
terelius23c595a2017-03-15 01:59:12 -07001304 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
1305 LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001306 for (LoggedRtpPacket packet : rtp_packets) {
1307 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1308 float y = packet.header.timestamp;
1309 timestamp_data.points.emplace_back(x, y);
1310 }
philipel35ba9bd2017-04-19 05:58:51 -07001311 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001312 }
1313
1314 {
1315 auto kv = rtcp_packets_.find(stream_id);
1316 if (kv != rtcp_packets_.end()) {
1317 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001318 TimeSeries timestamp_data(
1319 GetStreamName(stream_id) + " rtcp capture-time", LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001320 for (const LoggedRtcpPacket& rtcp : packets) {
1321 if (rtcp.type != kRtcpSr)
1322 continue;
1323 rtcp::SenderReport* sr;
1324 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1325 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1326 float y = sr->rtp_timestamp();
1327 timestamp_data.points.emplace_back(x, y);
1328 }
philipel35ba9bd2017-04-19 05:58:51 -07001329 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001330 }
1331 }
1332 }
1333
1334 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1335 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1336 plot->SetTitle("Timestamps");
1337}
michaelt6e5b2192017-02-22 07:33:27 -08001338
1339void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001340 TimeSeries time_series("Audio encoder target bitrate", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001341 ProcessPoints<AudioNetworkAdaptationEvent>(
1342 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001343 if (ana_event.config.bitrate_bps)
1344 return rtc::Optional<float>(
1345 static_cast<float>(*ana_event.config.bitrate_bps));
1346 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001347 },
philipel35ba9bd2017-04-19 05:58:51 -07001348 audio_network_adaptation_events_, begin_time_, &time_series);
1349 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001350 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1351 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1352 plot->SetTitle("Reported audio encoder target bitrate");
1353}
1354
1355void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001356 TimeSeries time_series("Audio encoder frame length", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001357 ProcessPoints<AudioNetworkAdaptationEvent>(
1358 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001359 if (ana_event.config.frame_length_ms)
1360 return rtc::Optional<float>(
1361 static_cast<float>(*ana_event.config.frame_length_ms));
1362 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001363 },
philipel35ba9bd2017-04-19 05:58:51 -07001364 audio_network_adaptation_events_, begin_time_, &time_series);
1365 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001366 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1367 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1368 plot->SetTitle("Reported audio encoder frame length");
1369}
1370
1371void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph(
1372 Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001373 TimeSeries time_series("Audio encoder uplink packet loss fraction",
1374 LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001375 ProcessPoints<AudioNetworkAdaptationEvent>(
1376 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001377 if (ana_event.config.uplink_packet_loss_fraction)
1378 return rtc::Optional<float>(static_cast<float>(
1379 *ana_event.config.uplink_packet_loss_fraction));
1380 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001381 },
philipel35ba9bd2017-04-19 05:58:51 -07001382 audio_network_adaptation_events_, begin_time_, &time_series);
1383 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001384 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1385 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1386 kTopMargin);
1387 plot->SetTitle("Reported audio encoder lost packets");
1388}
1389
1390void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001391 TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001392 ProcessPoints<AudioNetworkAdaptationEvent>(
1393 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001394 if (ana_event.config.enable_fec)
1395 return rtc::Optional<float>(
1396 static_cast<float>(*ana_event.config.enable_fec));
1397 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001398 },
philipel35ba9bd2017-04-19 05:58:51 -07001399 audio_network_adaptation_events_, begin_time_, &time_series);
1400 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001401 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1402 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1403 plot->SetTitle("Reported audio encoder FEC");
1404}
1405
1406void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001407 TimeSeries time_series("Audio encoder DTX", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001408 ProcessPoints<AudioNetworkAdaptationEvent>(
1409 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001410 if (ana_event.config.enable_dtx)
1411 return rtc::Optional<float>(
1412 static_cast<float>(*ana_event.config.enable_dtx));
1413 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001414 },
philipel35ba9bd2017-04-19 05:58:51 -07001415 audio_network_adaptation_events_, begin_time_, &time_series);
1416 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001417 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1418 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1419 plot->SetTitle("Reported audio encoder DTX");
1420}
1421
1422void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001423 TimeSeries time_series("Audio encoder number of channels", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001424 ProcessPoints<AudioNetworkAdaptationEvent>(
1425 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001426 if (ana_event.config.num_channels)
1427 return rtc::Optional<float>(
1428 static_cast<float>(*ana_event.config.num_channels));
1429 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001430 },
philipel35ba9bd2017-04-19 05:58:51 -07001431 audio_network_adaptation_events_, begin_time_, &time_series);
1432 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001433 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1434 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1435 kBottomMargin, kTopMargin);
1436 plot->SetTitle("Reported audio encoder number of channels");
1437}
terelius54ce6802016-07-13 06:44:41 -07001438} // namespace plotting
1439} // namespace webrtc