blob: c4f5c7b3bf5540166c0ea737b4dd816fb5a9eec4 [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 -080047void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
48 auto pred = [](const PacketFeedback& packet_feedback) {
49 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
50 };
51 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
52 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
53}
54
terelius54ce6802016-07-13 06:44:41 -070055std::string SsrcToString(uint32_t ssrc) {
56 std::stringstream ss;
57 ss << "SSRC " << ssrc;
58 return ss.str();
59}
60
61// Checks whether an SSRC is contained in the list of desired SSRCs.
62// Note that an empty SSRC list matches every SSRC.
63bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
64 if (desired_ssrc.size() == 0)
65 return true;
66 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
67 desired_ssrc.end();
68}
69
70double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
71 // The timestamp is a fixed point representation with 6 bits for seconds
72 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
73 // time in seconds and then multiply by 1000000 to convert to microseconds.
74 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070075 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070076 return abs_send_time * kTimestampToMicroSec;
77}
78
79// Computes the difference |later| - |earlier| where |later| and |earlier|
80// are counters that wrap at |modulus|. The difference is chosen to have the
81// least absolute value. For example if |modulus| is 8, then the difference will
82// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
83// be in [-4, 4].
84int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
85 RTC_DCHECK_LE(1, modulus);
86 RTC_DCHECK_LT(later, modulus);
87 RTC_DCHECK_LT(earlier, modulus);
88 int64_t difference =
89 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
90 int64_t max_difference = modulus / 2;
91 int64_t min_difference = max_difference - modulus + 1;
92 if (difference > max_difference) {
93 difference -= modulus;
94 }
95 if (difference < min_difference) {
96 difference += modulus;
97 }
terelius6addf492016-08-23 17:34:07 -070098 if (difference > max_difference / 2 || difference < min_difference / 2) {
99 LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
100 << " expected to be in the range (" << min_difference / 2
101 << "," << max_difference / 2 << ") but is " << difference
102 << ". Correct unwrapping is uncertain.";
103 }
terelius54ce6802016-07-13 06:44:41 -0700104 return difference;
105}
106
ivocaac9d6f2016-09-22 07:01:47 -0700107// Return default values for header extensions, to use on streams without stored
108// mapping data. Currently this only applies to audio streams, since the mapping
109// is not stored in the event log.
110// TODO(ivoc): Remove this once this mapping is stored in the event log for
111// audio streams. Tracking bug: webrtc:6399
112webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
113 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800114 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
115 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700116 webrtc::RtpExtension::kAbsSendTimeDefaultId);
117 return default_map;
118}
119
tereliusdc35dcd2016-08-01 12:03:27 -0700120constexpr float kLeftMargin = 0.01f;
121constexpr float kRightMargin = 0.02f;
122constexpr float kBottomMargin = 0.02f;
123constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700124
terelius53dc23c2017-03-13 05:24:05 -0700125rtc::Optional<double> NetworkDelayDiff_AbsSendTime(
126 const LoggedRtpPacket& old_packet,
127 const LoggedRtpPacket& new_packet) {
128 if (old_packet.header.extension.hasAbsoluteSendTime &&
129 new_packet.header.extension.hasAbsoluteSendTime) {
130 int64_t send_time_diff = WrappingDifference(
131 new_packet.header.extension.absoluteSendTime,
132 old_packet.header.extension.absoluteSendTime, 1ul << 24);
133 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
134 double delay_change_us =
135 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
136 return rtc::Optional<double>(delay_change_us / 1000);
137 } else {
138 return rtc::Optional<double>();
terelius6addf492016-08-23 17:34:07 -0700139 }
140}
141
terelius53dc23c2017-03-13 05:24:05 -0700142rtc::Optional<double> NetworkDelayDiff_CaptureTime(
143 const LoggedRtpPacket& old_packet,
144 const LoggedRtpPacket& new_packet) {
145 int64_t send_time_diff = WrappingDifference(
146 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
147 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
148
149 const double kVideoSampleRate = 90000;
150 // TODO(terelius): We treat all streams as video for now, even though
151 // audio might be sampled at e.g. 16kHz, because it is really difficult to
152 // figure out the true sampling rate of a stream. The effect is that the
153 // delay will be scaled incorrectly for non-video streams.
154
155 double delay_change =
156 static_cast<double>(recv_time_diff) / 1000 -
157 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
158 if (delay_change < -10000 || 10000 < delay_change) {
159 LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
160 LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
161 << ", received time " << old_packet.timestamp;
162 LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
163 << ", received time " << new_packet.timestamp;
164 LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
165 << static_cast<double>(recv_time_diff) / 1000000 << "s";
166 LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
167 << static_cast<double>(send_time_diff) / kVideoSampleRate
168 << "s";
169 }
170 return rtc::Optional<double>(delay_change);
171}
172
173// For each element in data, use |get_y()| to extract a y-coordinate and
174// store the result in a TimeSeries.
175template <typename DataType>
176void ProcessPoints(
177 rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y,
178 const std::vector<DataType>& data,
179 uint64_t begin_time,
180 TimeSeries* result) {
181 for (size_t i = 0; i < data.size(); i++) {
182 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
183 rtc::Optional<float> y = get_y(data[i]);
184 if (y)
185 result->points.emplace_back(x, *y);
186 }
187}
188
189// For each pair of adjacent elements in |data|, use |get_y| to extract a
terelius6addf492016-08-23 17:34:07 -0700190// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
191// will be the time of the second element in the pair.
terelius53dc23c2017-03-13 05:24:05 -0700192template <typename DataType, typename ResultType>
193void ProcessPairs(
194 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
195 const DataType&)> get_y,
196 const std::vector<DataType>& data,
197 uint64_t begin_time,
198 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700199 for (size_t i = 1; i < data.size(); i++) {
200 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700201 rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]);
202 if (y)
203 result->points.emplace_back(x, static_cast<float>(*y));
204 }
205}
206
207// For each element in data, use |extract()| to extract a y-coordinate and
208// store the result in a TimeSeries.
209template <typename DataType, typename ResultType>
210void AccumulatePoints(
211 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
212 const std::vector<DataType>& data,
213 uint64_t begin_time,
214 TimeSeries* result) {
215 ResultType sum = 0;
216 for (size_t i = 0; i < data.size(); i++) {
217 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
218 rtc::Optional<ResultType> y = extract(data[i]);
219 if (y) {
220 sum += *y;
221 result->points.emplace_back(x, static_cast<float>(sum));
222 }
223 }
224}
225
226// For each pair of adjacent elements in |data|, use |extract()| to extract a
227// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
228// will be the time of the second element in the pair.
229template <typename DataType, typename ResultType>
230void AccumulatePairs(
231 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
232 const DataType&)> extract,
233 const std::vector<DataType>& data,
234 uint64_t begin_time,
235 TimeSeries* result) {
236 ResultType sum = 0;
237 for (size_t i = 1; i < data.size(); i++) {
238 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
239 rtc::Optional<ResultType> y = extract(data[i - 1], data[i]);
240 if (y)
241 sum += *y;
242 result->points.emplace_back(x, static_cast<float>(sum));
tereliusccbbf8d2016-08-10 07:34:28 -0700243 }
244}
245
terelius6addf492016-08-23 17:34:07 -0700246// Calculates a moving average of |data| and stores the result in a TimeSeries.
247// A data point is generated every |step| microseconds from |begin_time|
248// to |end_time|. The value of each data point is the average of the data
249// during the preceeding |window_duration_us| microseconds.
terelius53dc23c2017-03-13 05:24:05 -0700250template <typename DataType, typename ResultType>
251void MovingAverage(
252 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
253 const std::vector<DataType>& data,
254 uint64_t begin_time,
255 uint64_t end_time,
256 uint64_t window_duration_us,
257 uint64_t step,
258 webrtc::plotting::TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700259 size_t window_index_begin = 0;
260 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700261 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700262
263 for (uint64_t t = begin_time; t < end_time + step; t += step) {
264 while (window_index_end < data.size() &&
265 data[window_index_end].timestamp < t) {
terelius53dc23c2017-03-13 05:24:05 -0700266 rtc::Optional<ResultType> value = extract(data[window_index_end]);
267 if (value)
268 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700269 ++window_index_end;
270 }
271 while (window_index_begin < data.size() &&
272 data[window_index_begin].timestamp < t - window_duration_us) {
terelius53dc23c2017-03-13 05:24:05 -0700273 rtc::Optional<ResultType> value = extract(data[window_index_begin]);
274 if (value)
275 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700276 ++window_index_begin;
277 }
278 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
279 float x = static_cast<float>(t - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700280 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700281 result->points.emplace_back(x, y);
282 }
283}
284
terelius54ce6802016-07-13 06:44:41 -0700285} // namespace
286
terelius54ce6802016-07-13 06:44:41 -0700287EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
288 : parsed_log_(log), window_duration_(250000), step_(10000) {
289 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
290 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700291
terelius88e64e52016-07-19 01:51:06 -0700292 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700293 uint8_t header[IP_PACKET_SIZE];
294 size_t header_length;
295 size_t total_length;
296
perkjbbbad6d2017-05-19 06:30:28 -0700297 uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE];
298 uint8_t last_incoming_rtcp_packet_length = 0;
299
ivocaac9d6f2016-09-22 07:01:47 -0700300 // Make a default extension map for streams without configuration information.
301 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
302 // this can be removed. Tracking bug: webrtc:6399
303 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
304
terelius54ce6802016-07-13 06:44:41 -0700305 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
306 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700307 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
308 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
309 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700310 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
311 event_type != ParsedRtcEventLog::LOG_START &&
312 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700313 uint64_t timestamp = parsed_log_.GetTimestamp(i);
314 first_timestamp = std::min(first_timestamp, timestamp);
315 last_timestamp = std::max(last_timestamp, timestamp);
316 }
317
318 switch (parsed_log_.GetEventType(i)) {
319 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700320 rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i);
perkj09e71da2017-05-22 03:26:49 -0700321 StreamId stream(config.remote_ssrc, kIncomingPacket);
terelius0740a202016-08-08 10:21:04 -0700322 video_ssrcs_.insert(stream);
perkj09e71da2017-05-22 03:26:49 -0700323 StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket);
brandtr14742122017-01-27 04:53:07 -0800324 video_ssrcs_.insert(rtx_stream);
325 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700326 break;
327 }
328 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700329 std::vector<rtclog::StreamConfig> configs =
330 parsed_log_.GetVideoSendConfig(i);
terelius405f90c2017-06-01 03:50:31 -0700331 for (const auto& config : configs) {
332 StreamId stream(config.local_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700333 video_ssrcs_.insert(stream);
terelius405f90c2017-06-01 03:50:31 -0700334 StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700335 video_ssrcs_.insert(rtx_stream);
336 rtx_ssrcs_.insert(rtx_stream);
337 }
terelius88e64e52016-07-19 01:51:06 -0700338 break;
339 }
340 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700341 rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i);
perkjac8f52d2017-05-22 09:36:28 -0700342 StreamId stream(config.remote_ssrc, kIncomingPacket);
ivoce0928d82016-10-10 05:12:51 -0700343 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700344 break;
345 }
346 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700347 rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i);
perkjf4726992017-05-22 10:12:26 -0700348 StreamId stream(config.local_ssrc, kOutgoingPacket);
ivoce0928d82016-10-10 05:12:51 -0700349 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700350 break;
351 }
352 case ParsedRtcEventLog::RTP_EVENT: {
ilnika8e781a2017-06-12 01:02:46 -0700353 RtpHeaderExtensionMap* extension_map = parsed_log_.GetRtpHeader(
354 i, &direction, header, &header_length, &total_length);
terelius88e64e52016-07-19 01:51:06 -0700355 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
356 RTPHeader parsed_header;
ilnika8e781a2017-06-12 01:02:46 -0700357 if (extension_map != nullptr) {
terelius88e64e52016-07-19 01:51:06 -0700358 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700359 } else {
360 // Use the default extension map.
361 // TODO(ivoc): Once configuration of audio streams is stored in the
362 // event log, this can be removed.
363 // Tracking bug: webrtc:6399
364 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700365 }
366 uint64_t timestamp = parsed_log_.GetTimestamp(i);
ilnika8e781a2017-06-12 01:02:46 -0700367 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700368 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200369 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700370 break;
371 }
372 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200373 uint8_t packet[IP_PACKET_SIZE];
perkj77cd58e2017-05-30 03:52:10 -0700374 parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length);
perkjbbbad6d2017-05-19 06:30:28 -0700375 // Currently incoming RTCP packets are logged twice, both for audio and
376 // video. Only act on one of them. Compare against the previous parsed
377 // incoming RTCP packet.
378 if (direction == webrtc::kIncomingPacket) {
379 RTC_CHECK_LE(total_length, IP_PACKET_SIZE);
380 if (total_length == last_incoming_rtcp_packet_length &&
381 memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) {
382 continue;
383 } else {
384 memcpy(last_incoming_rtcp_packet, packet, total_length);
385 last_incoming_rtcp_packet_length = total_length;
386 }
387 }
388 rtcp::CommonHeader header;
389 const uint8_t* packet_end = packet + total_length;
390 for (const uint8_t* block = packet; block < packet_end;
391 block = header.NextPacket()) {
392 RTC_CHECK(header.Parse(block, packet_end - block));
393 if (header.type() == rtcp::TransportFeedback::kPacketType &&
394 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
395 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700396 rtc::MakeUnique<rtcp::TransportFeedback>());
perkjbbbad6d2017-05-19 06:30:28 -0700397 if (rtcp_packet->Parse(header)) {
398 uint32_t ssrc = rtcp_packet->sender_ssrc();
399 StreamId stream(ssrc, direction);
400 uint64_t timestamp = parsed_log_.GetTimestamp(i);
401 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
402 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
403 }
404 } else if (header.type() == rtcp::SenderReport::kPacketType) {
405 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700406 rtc::MakeUnique<rtcp::SenderReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700407 if (rtcp_packet->Parse(header)) {
408 uint32_t ssrc = rtcp_packet->sender_ssrc();
409 StreamId stream(ssrc, direction);
410 uint64_t timestamp = parsed_log_.GetTimestamp(i);
411 rtcp_packets_[stream].push_back(
412 LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet)));
413 }
414 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
415 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700416 rtc::MakeUnique<rtcp::ReceiverReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700417 if (rtcp_packet->Parse(header)) {
418 uint32_t ssrc = rtcp_packet->sender_ssrc();
419 StreamId stream(ssrc, direction);
420 uint64_t timestamp = parsed_log_.GetTimestamp(i);
421 rtcp_packets_[stream].push_back(
422 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet)));
Stefan Holmer13181032016-07-29 14:48:54 +0200423 }
terelius2c8e8a32017-06-02 01:29:48 -0700424 } else if (header.type() == rtcp::Remb::kPacketType &&
425 header.fmt() == rtcp::Remb::kFeedbackMessageType) {
426 std::unique_ptr<rtcp::Remb> rtcp_packet(
427 rtc::MakeUnique<rtcp::Remb>());
428 if (rtcp_packet->Parse(header)) {
429 uint32_t ssrc = rtcp_packet->sender_ssrc();
430 StreamId stream(ssrc, direction);
431 uint64_t timestamp = parsed_log_.GetTimestamp(i);
432 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
433 timestamp, kRtcpRemb, std::move(rtcp_packet)));
434 }
Stefan Holmer13181032016-07-29 14:48:54 +0200435 }
Stefan Holmer13181032016-07-29 14:48:54 +0200436 }
terelius88e64e52016-07-19 01:51:06 -0700437 break;
438 }
439 case ParsedRtcEventLog::LOG_START: {
440 break;
441 }
442 case ParsedRtcEventLog::LOG_END: {
443 break;
444 }
terelius424e6cf2017-02-20 05:14:41 -0800445 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
446 break;
447 }
448 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
449 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700450 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800451 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
452 &bwe_update.fraction_loss,
453 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700454 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700455 break;
456 }
terelius424e6cf2017-02-20 05:14:41 -0800457 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
philipel10fc0e62017-04-11 01:50:23 -0700458 bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i));
terelius424e6cf2017-02-20 05:14:41 -0800459 break;
460 }
minyue4b7c9522017-01-24 04:54:59 -0800461 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800462 AudioNetworkAdaptationEvent ana_event;
463 ana_event.timestamp = parsed_log_.GetTimestamp(i);
464 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
465 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800466 break;
467 }
philipel32d00102017-02-27 02:18:46 -0800468 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200469 bwe_probe_cluster_created_events_.push_back(
470 parsed_log_.GetBweProbeClusterCreated(i));
philipel32d00102017-02-27 02:18:46 -0800471 break;
472 }
473 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200474 bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i));
philipel32d00102017-02-27 02:18:46 -0800475 break;
476 }
terelius88e64e52016-07-19 01:51:06 -0700477 case ParsedRtcEventLog::UNKNOWN_EVENT: {
478 break;
479 }
480 }
terelius54ce6802016-07-13 06:44:41 -0700481 }
terelius88e64e52016-07-19 01:51:06 -0700482
terelius54ce6802016-07-13 06:44:41 -0700483 if (last_timestamp < first_timestamp) {
484 // No useful events in the log.
485 first_timestamp = last_timestamp = 0;
486 }
487 begin_time_ = first_timestamp;
488 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700489 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700490}
491
Stefan Holmer13181032016-07-29 14:48:54 +0200492class BitrateObserver : public CongestionController::Observer,
493 public RemoteBitrateObserver {
494 public:
495 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
496
minyue78b4d562016-11-30 04:47:39 -0800497 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
498 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
499 using CongestionController::Observer::OnNetworkChanged;
500
Stefan Holmer13181032016-07-29 14:48:54 +0200501 void OnNetworkChanged(uint32_t bitrate_bps,
502 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800503 int64_t rtt_ms,
504 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200505 last_bitrate_bps_ = bitrate_bps;
506 bitrate_updated_ = true;
507 }
508
509 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
510 uint32_t bitrate) override {}
511
512 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
513 bool GetAndResetBitrateUpdated() {
514 bool bitrate_updated = bitrate_updated_;
515 bitrate_updated_ = false;
516 return bitrate_updated;
517 }
518
519 private:
520 uint32_t last_bitrate_bps_;
521 bool bitrate_updated_;
522};
523
Stefan Holmer99f8e082016-09-09 13:37:50 +0200524bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700525 return rtx_ssrcs_.count(stream_id) == 1;
526}
527
Stefan Holmer99f8e082016-09-09 13:37:50 +0200528bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700529 return video_ssrcs_.count(stream_id) == 1;
530}
531
Stefan Holmer99f8e082016-09-09 13:37:50 +0200532bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700533 return audio_ssrcs_.count(stream_id) == 1;
534}
535
Stefan Holmer99f8e082016-09-09 13:37:50 +0200536std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
537 std::stringstream name;
538 if (IsAudioSsrc(stream_id)) {
539 name << "Audio ";
540 } else if (IsVideoSsrc(stream_id)) {
541 name << "Video ";
542 } else {
543 name << "Unknown ";
544 }
545 if (IsRtxSsrc(stream_id))
546 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700547 if (stream_id.GetDirection() == kIncomingPacket) {
548 name << "(In) ";
549 } else {
550 name << "(Out) ";
551 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200552 name << SsrcToString(stream_id.GetSsrc());
553 return name.str();
554}
555
terelius54ce6802016-07-13 06:44:41 -0700556void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
557 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700558 for (auto& kv : rtp_packets_) {
559 StreamId stream_id = kv.first;
560 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
561 // Filter on direction and SSRC.
562 if (stream_id.GetDirection() != desired_direction ||
563 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
564 continue;
terelius54ce6802016-07-13 06:44:41 -0700565 }
terelius54ce6802016-07-13 06:44:41 -0700566
terelius23c595a2017-03-15 01:59:12 -0700567 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700568 ProcessPoints<LoggedRtpPacket>(
569 [](const LoggedRtpPacket& packet) -> rtc::Optional<float> {
570 return rtc::Optional<float>(packet.total_length);
571 },
572 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700573 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700574 }
575
tereliusdc35dcd2016-08-01 12:03:27 -0700576 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
577 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
578 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700579 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700580 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700581 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700582 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700583 }
584}
585
philipelccd74892016-09-05 02:46:25 -0700586template <typename T>
587void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
588 PacketDirection desired_direction,
589 Plot* plot,
590 const std::map<StreamId, std::vector<T>>& packets,
591 const std::string& label_prefix) {
592 for (auto& kv : packets) {
593 StreamId stream_id = kv.first;
594 const std::vector<T>& packet_stream = kv.second;
595 // Filter on direction and SSRC.
596 if (stream_id.GetDirection() != desired_direction ||
597 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
598 continue;
599 }
600
terelius23c595a2017-03-15 01:59:12 -0700601 std::string label = label_prefix + " " + GetStreamName(stream_id);
602 TimeSeries time_series(label, LINE_STEP_GRAPH);
philipelccd74892016-09-05 02:46:25 -0700603 for (size_t i = 0; i < packet_stream.size(); i++) {
604 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
605 1000000;
philipelccd74892016-09-05 02:46:25 -0700606 time_series.points.emplace_back(x, i + 1);
607 }
608
philipel35ba9bd2017-04-19 05:58:51 -0700609 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700610 }
611}
612
613void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
614 PacketDirection desired_direction,
615 Plot* plot) {
616 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
617 "RTP");
618 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
619 "RTCP");
620
621 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
622 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
623 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
624 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
625 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
626 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
627 }
628}
629
terelius54ce6802016-07-13 06:44:41 -0700630// For each SSRC, plot the time between the consecutive playouts.
631void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
632 std::map<uint32_t, TimeSeries> time_series;
633 std::map<uint32_t, uint64_t> last_playout;
634
635 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700636
637 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
638 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
639 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
640 parsed_log_.GetAudioPlayout(i, &ssrc);
641 uint64_t timestamp = parsed_log_.GetTimestamp(i);
642 if (MatchingSsrc(ssrc, desired_ssrc_)) {
643 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
644 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
645 if (time_series[ssrc].points.size() == 0) {
646 // There were no previusly logged playout for this SSRC.
647 // Generate a point, but place it on the x-axis.
648 y = 0;
649 }
terelius54ce6802016-07-13 06:44:41 -0700650 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
651 last_playout[ssrc] = timestamp;
652 }
653 }
654 }
655
656 // Set labels and put in graph.
657 for (auto& kv : time_series) {
658 kv.second.label = SsrcToString(kv.first);
659 kv.second.style = BAR_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700660 plot->AppendTimeSeries(std::move(kv.second));
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, "Time since last playout (ms)", kBottomMargin,
665 kTopMargin);
666 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700667}
668
ivocaac9d6f2016-09-22 07:01:47 -0700669// For audio SSRCs, plot the audio level.
670void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
671 std::map<StreamId, TimeSeries> time_series;
672
673 for (auto& kv : rtp_packets_) {
674 StreamId stream_id = kv.first;
675 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
676 // TODO(ivoc): When audio send/receive configs are stored in the event
677 // log, a check should be added here to only process audio
678 // streams. Tracking bug: webrtc:6399
679 for (auto& packet : packet_stream) {
680 if (packet.header.extension.hasAudioLevel) {
681 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
682 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
683 // Here we convert it to dBov.
684 float y = static_cast<float>(-packet.header.extension.audioLevel);
685 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
686 }
687 }
688 }
689
690 for (auto& series : time_series) {
691 series.second.label = GetStreamName(series.first);
692 series.second.style = LINE_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700693 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700694 }
695
696 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800697 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700698 kTopMargin);
699 plot->SetTitle("Audio level");
700}
701
terelius54ce6802016-07-13 06:44:41 -0700702// For each SSRC, plot the time between the consecutive playouts.
703void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700704 for (auto& kv : rtp_packets_) {
705 StreamId stream_id = kv.first;
706 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
707 // Filter on direction and SSRC.
708 if (stream_id.GetDirection() != kIncomingPacket ||
709 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
710 continue;
terelius54ce6802016-07-13 06:44:41 -0700711 }
terelius54ce6802016-07-13 06:44:41 -0700712
terelius23c595a2017-03-15 01:59:12 -0700713 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700714 ProcessPairs<LoggedRtpPacket, float>(
715 [](const LoggedRtpPacket& old_packet,
716 const LoggedRtpPacket& new_packet) {
717 int64_t diff =
718 WrappingDifference(new_packet.header.sequenceNumber,
719 old_packet.header.sequenceNumber, 1ul << 16);
720 return rtc::Optional<float>(diff);
721 },
722 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700723 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700724 }
725
tereliusdc35dcd2016-08-01 12:03:27 -0700726 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
727 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
728 kTopMargin);
729 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700730}
731
Stefan Holmer99f8e082016-09-09 13:37:50 +0200732void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
733 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 ||
terelius4c9b4af2017-01-30 08:44:51 -0800738 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
739 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200740 continue;
741 }
742
terelius23c595a2017-03-15 01:59:12 -0700743 TimeSeries time_series(GetStreamName(stream_id), LINE_DOT_GRAPH);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200744 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800745 const uint64_t kStep = 1000000;
746 SequenceNumberUnwrapper unwrapper_;
747 SequenceNumberUnwrapper prior_unwrapper_;
748 size_t window_index_begin = 0;
749 size_t window_index_end = 0;
750 int64_t highest_seq_number =
751 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
752 int64_t highest_prior_seq_number =
753 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
754
755 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
756 while (window_index_end < packet_stream.size() &&
757 packet_stream[window_index_end].timestamp < t) {
758 int64_t sequence_number = unwrapper_.Unwrap(
759 packet_stream[window_index_end].header.sequenceNumber);
760 highest_seq_number = std::max(highest_seq_number, sequence_number);
761 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200762 }
terelius4c9b4af2017-01-30 08:44:51 -0800763 while (window_index_begin < packet_stream.size() &&
764 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
765 int64_t sequence_number = prior_unwrapper_.Unwrap(
766 packet_stream[window_index_begin].header.sequenceNumber);
767 highest_prior_seq_number =
768 std::max(highest_prior_seq_number, sequence_number);
769 ++window_index_begin;
770 }
771 float x = static_cast<float>(t - begin_time_) / 1000000;
772 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
773 if (expected_packets > 0) {
774 int64_t received_packets = window_index_end - window_index_begin;
775 int64_t lost_packets = expected_packets - received_packets;
776 float y = static_cast<float>(lost_packets) / expected_packets * 100;
777 time_series.points.emplace_back(x, y);
778 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200779 }
philipel35ba9bd2017-04-19 05:58:51 -0700780 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200781 }
782
783 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
784 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
785 kTopMargin);
786 plot->SetTitle("Estimated incoming loss rate");
787}
788
terelius54ce6802016-07-13 06:44:41 -0700789void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700790 for (auto& kv : rtp_packets_) {
791 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700792 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700793 // Filter on direction and SSRC.
794 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200795 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
796 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
797 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700798 continue;
799 }
terelius54ce6802016-07-13 06:44:41 -0700800
terelius23c595a2017-03-15 01:59:12 -0700801 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
802 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700803 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
804 packet_stream, begin_time_,
805 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700806 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700807
terelius23c595a2017-03-15 01:59:12 -0700808 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
809 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700810 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
811 packet_stream, begin_time_,
812 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700813 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700814 }
815
tereliusdc35dcd2016-08-01 12:03:27 -0700816 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
817 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
818 kTopMargin);
819 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700820}
821
822void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700823 for (auto& kv : rtp_packets_) {
824 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700825 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700826 // Filter on direction and SSRC.
827 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200828 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
829 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
830 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700831 continue;
832 }
terelius54ce6802016-07-13 06:44:41 -0700833
terelius23c595a2017-03-15 01:59:12 -0700834 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
835 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700836 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
837 packet_stream, begin_time_,
838 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700839 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700840
terelius23c595a2017-03-15 01:59:12 -0700841 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
842 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700843 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
844 packet_stream, begin_time_,
845 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700846 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700847 }
848
tereliusdc35dcd2016-08-01 12:03:27 -0700849 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
850 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
851 kTopMargin);
852 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700853}
854
tereliusf736d232016-08-04 10:00:11 -0700855// Plot the fraction of packets lost (as perceived by the loss-based BWE).
856void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -0700857 TimeSeries time_series("Fraction lost", LINE_DOT_GRAPH);
tereliusf736d232016-08-04 10:00:11 -0700858 for (auto& bwe_update : bwe_loss_updates_) {
859 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
860 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700861 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700862 }
tereliusf736d232016-08-04 10:00:11 -0700863
864 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
865 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
866 kTopMargin);
867 plot->SetTitle("Reported packet loss");
philipel35ba9bd2017-04-19 05:58:51 -0700868 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700869}
870
terelius54ce6802016-07-13 06:44:41 -0700871// Plot the total bandwidth used by all RTP streams.
872void EventLogAnalyzer::CreateTotalBitrateGraph(
873 PacketDirection desired_direction,
874 Plot* plot) {
875 struct TimestampSize {
876 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
877 uint64_t timestamp;
878 size_t size;
879 };
880 std::vector<TimestampSize> packets;
881
882 PacketDirection direction;
883 size_t total_length;
884
885 // Extract timestamps and sizes for the relevant packets.
886 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
887 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
888 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
perkj77cd58e2017-05-30 03:52:10 -0700889 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length);
terelius54ce6802016-07-13 06:44:41 -0700890 if (direction == desired_direction) {
891 uint64_t timestamp = parsed_log_.GetTimestamp(i);
892 packets.push_back(TimestampSize(timestamp, total_length));
893 }
894 }
895 }
896
897 size_t window_index_begin = 0;
898 size_t window_index_end = 0;
899 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700900
901 // Calculate a moving average of the bitrate and store in a TimeSeries.
philipel35ba9bd2017-04-19 05:58:51 -0700902 TimeSeries bitrate_series("Bitrate", LINE_GRAPH);
terelius54ce6802016-07-13 06:44:41 -0700903 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
904 while (window_index_end < packets.size() &&
905 packets[window_index_end].timestamp < time) {
906 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700907 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700908 }
909 while (window_index_begin < packets.size() &&
910 packets[window_index_begin].timestamp < time - window_duration_) {
911 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
912 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700913 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700914 }
915 float window_duration_in_seconds =
916 static_cast<float>(window_duration_) / 1000000;
917 float x = static_cast<float>(time - begin_time_) / 1000000;
918 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700919 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700920 }
philipel35ba9bd2017-04-19 05:58:51 -0700921 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700922
terelius8058e582016-07-25 01:32:41 -0700923 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
924 if (desired_direction == kOutgoingPacket) {
philipel35ba9bd2017-04-19 05:58:51 -0700925 TimeSeries loss_series("Loss-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700926 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -0700927 float x =
philipel10fc0e62017-04-11 01:50:23 -0700928 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
929 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700930 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -0700931 }
932
philipel35ba9bd2017-04-19 05:58:51 -0700933 TimeSeries delay_series("Delay-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700934 for (auto& delay_update : bwe_delay_updates_) {
935 float x =
936 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
937 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700938 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700939 }
philipele127e7a2017-03-29 16:28:53 +0200940
philipel35ba9bd2017-04-19 05:58:51 -0700941 TimeSeries created_series("Probe cluster created.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +0200942 for (auto& cluster : bwe_probe_cluster_created_events_) {
943 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
944 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700945 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +0200946 }
947
philipel35ba9bd2017-04-19 05:58:51 -0700948 TimeSeries result_series("Probing results.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +0200949 for (auto& result : bwe_probe_result_events_) {
950 if (result.bitrate_bps) {
951 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
952 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700953 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +0200954 }
955 }
philipel35ba9bd2017-04-19 05:58:51 -0700956 plot->AppendTimeSeries(std::move(loss_series));
957 plot->AppendTimeSeries(std::move(delay_series));
958 plot->AppendTimeSeries(std::move(created_series));
959 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -0700960 }
philipele127e7a2017-03-29 16:28:53 +0200961
terelius2c8e8a32017-06-02 01:29:48 -0700962 // Overlay the incoming REMB over the outgoing bitrate
963 // and outgoing REMB over incoming bitrate.
964 PacketDirection remb_direction =
965 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
966 TimeSeries remb_series("Remb", LINE_STEP_GRAPH);
967 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
968 for (const auto& kv : rtcp_packets_) {
969 if (kv.first.GetDirection() == remb_direction) {
970 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
971 if (rtcp_packet.type == kRtcpRemb) {
972 remb_packets.insert(
973 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
974 }
975 }
976 }
977 }
978
979 for (const auto& kv : remb_packets) {
980 const LoggedRtcpPacket* const rtcp = kv.second;
981 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
982 float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000;
983 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
984 remb_series.points.emplace_back(x, y);
985 }
986 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
987
tereliusdc35dcd2016-08-01 12:03:27 -0700988 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
989 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700990 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700991 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700992 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700993 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700994 }
995}
996
997// For each SSRC, plot the bandwidth used by that stream.
998void EventLogAnalyzer::CreateStreamBitrateGraph(
999 PacketDirection desired_direction,
1000 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001001 for (auto& kv : rtp_packets_) {
1002 StreamId stream_id = kv.first;
1003 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1004 // Filter on direction and SSRC.
1005 if (stream_id.GetDirection() != desired_direction ||
1006 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1007 continue;
terelius54ce6802016-07-13 06:44:41 -07001008 }
1009
terelius23c595a2017-03-15 01:59:12 -07001010 TimeSeries time_series(GetStreamName(stream_id), LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001011 MovingAverage<LoggedRtpPacket, double>(
1012 [](const LoggedRtpPacket& packet) {
1013 return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0);
1014 },
1015 packet_stream, begin_time_, end_time_, window_duration_, step_,
1016 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001017 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001018 }
1019
tereliusdc35dcd2016-08-01 12:03:27 -07001020 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1021 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001022 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001023 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001024 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001025 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001026 }
1027}
1028
tereliuse34c19c2016-08-15 08:47:14 -07001029void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001030 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1031 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001032
1033 for (const auto& kv : rtp_packets_) {
1034 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1035 for (const LoggedRtpPacket& rtp_packet : kv.second)
1036 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1037 }
1038 }
1039
1040 for (const auto& kv : rtcp_packets_) {
1041 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1042 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1043 incoming_rtcp.insert(
1044 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1045 }
1046 }
1047
1048 SimulatedClock clock(0);
1049 BitrateObserver observer;
1050 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001051 PacketRouter packet_router;
1052 CongestionController cc(&clock, &observer, &observer, &null_event_log,
1053 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +02001054 // TODO(holmer): Log the call config and use that here instead.
1055 static const uint32_t kDefaultStartBitrateBps = 300000;
1056 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1057
terelius23c595a2017-03-15 01:59:12 -07001058 TimeSeries time_series("Delay-based estimate", LINE_DOT_GRAPH);
1059 TimeSeries acked_time_series("Acked bitrate", LINE_DOT_GRAPH);
Stefan Holmer13181032016-07-29 14:48:54 +02001060
1061 auto rtp_iterator = outgoing_rtp.begin();
1062 auto rtcp_iterator = incoming_rtcp.begin();
1063
1064 auto NextRtpTime = [&]() {
1065 if (rtp_iterator != outgoing_rtp.end())
1066 return static_cast<int64_t>(rtp_iterator->first);
1067 return std::numeric_limits<int64_t>::max();
1068 };
1069
1070 auto NextRtcpTime = [&]() {
1071 if (rtcp_iterator != incoming_rtcp.end())
1072 return static_cast<int64_t>(rtcp_iterator->first);
1073 return std::numeric_limits<int64_t>::max();
1074 };
1075
1076 auto NextProcessTime = [&]() {
1077 if (rtcp_iterator != incoming_rtcp.end() ||
1078 rtp_iterator != outgoing_rtp.end()) {
1079 return clock.TimeInMicroseconds() +
1080 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1081 }
1082 return std::numeric_limits<int64_t>::max();
1083 };
1084
Stefan Holmer492ee282016-10-27 17:19:20 +02001085 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001086
Stefan Holmer13181032016-07-29 14:48:54 +02001087 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001088 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001089 while (time_us != std::numeric_limits<int64_t>::max()) {
1090 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1091 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001092 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001093 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1094 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001095 cc.OnTransportFeedback(
1096 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1097 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001098 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001099 rtc::Optional<uint32_t> bitrate_bps;
1100 if (!feedback.empty()) {
elad.alonf9490002017-03-06 05:32:21 -08001101 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001102 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1103 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1104 }
1105 uint32_t y = 0;
1106 if (bitrate_bps)
1107 y = *bitrate_bps / 1000;
1108 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1109 1000000;
1110 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +02001111 }
1112 ++rtcp_iterator;
1113 }
1114 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001115 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001116 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1117 if (rtp.header.extension.hasTransportSequenceNumber) {
1118 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001119 cc.AddPacket(rtp.header.ssrc,
1120 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001121 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001122 rtc::SentPacket sent_packet(
1123 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1124 cc.OnSentPacket(sent_packet);
1125 }
1126 ++rtp_iterator;
1127 }
stefanc3de0332016-08-02 07:22:17 -07001128 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1129 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001130 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001131 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001132 if (observer.GetAndResetBitrateUpdated() ||
1133 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001134 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001135 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1136 1000000;
1137 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001138 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001139 }
1140 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1141 }
1142 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001143 plot->AppendTimeSeries(std::move(time_series));
1144 plot->AppendTimeSeries(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001145
tereliusdc35dcd2016-08-01 12:03:27 -07001146 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1147 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1148 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001149}
1150
tereliuse34c19c2016-08-15 08:47:14 -07001151void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001152 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1153 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001154
1155 for (const auto& kv : rtp_packets_) {
1156 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1157 for (const LoggedRtpPacket& rtp_packet : kv.second)
1158 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1159 }
1160 }
1161
1162 for (const auto& kv : rtcp_packets_) {
1163 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1164 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1165 incoming_rtcp.insert(
1166 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1167 }
1168 }
1169
1170 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001171 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001172
terelius23c595a2017-03-15 01:59:12 -07001173 TimeSeries time_series("Network Delay Change", LINE_DOT_GRAPH);
stefanc3de0332016-08-02 07:22:17 -07001174 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1175
1176 auto rtp_iterator = outgoing_rtp.begin();
1177 auto rtcp_iterator = incoming_rtcp.begin();
1178
1179 auto NextRtpTime = [&]() {
1180 if (rtp_iterator != outgoing_rtp.end())
1181 return static_cast<int64_t>(rtp_iterator->first);
1182 return std::numeric_limits<int64_t>::max();
1183 };
1184
1185 auto NextRtcpTime = [&]() {
1186 if (rtcp_iterator != incoming_rtcp.end())
1187 return static_cast<int64_t>(rtcp_iterator->first);
1188 return std::numeric_limits<int64_t>::max();
1189 };
1190
1191 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1192 while (time_us != std::numeric_limits<int64_t>::max()) {
1193 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1194 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1195 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1196 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1197 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001198 feedback_adapter.OnTransportFeedback(
1199 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001200 std::vector<PacketFeedback> feedback =
1201 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001202 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001203 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001204 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1205 float x =
1206 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1207 1000000;
1208 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1209 time_series.points.emplace_back(x, y);
1210 }
1211 }
1212 ++rtcp_iterator;
1213 }
1214 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1215 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1216 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1217 if (rtp.header.extension.hasTransportSequenceNumber) {
1218 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001219 feedback_adapter.AddPacket(rtp.header.ssrc,
1220 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001221 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001222 feedback_adapter.OnSentPacket(
1223 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1224 }
1225 ++rtp_iterator;
1226 }
1227 time_us = std::min(NextRtpTime(), NextRtcpTime());
1228 }
1229 // We assume that the base network delay (w/o queues) is the min delay
1230 // observed during the call.
1231 for (TimeSeriesPoint& point : time_series.points)
1232 point.y -= estimated_base_delay_ms;
1233 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001234 plot->AppendTimeSeries(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001235
1236 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1237 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1238 plot->SetTitle("Network Delay Change.");
1239}
stefan08383272016-12-20 08:51:52 -08001240
1241std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1242 const {
1243 std::vector<std::pair<int64_t, int64_t>> timestamps;
1244 size_t largest_stream_size = 0;
1245 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1246 // Find the incoming video stream with the most number of packets that is
1247 // not rtx.
1248 for (const auto& kv : rtp_packets_) {
1249 if (kv.first.GetDirection() == kIncomingPacket &&
1250 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1251 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1252 kv.second.size() > largest_stream_size) {
1253 largest_stream_size = kv.second.size();
1254 largest_video_stream = &kv.second;
1255 }
1256 }
1257 if (largest_video_stream == nullptr) {
1258 for (auto& packet : *largest_video_stream) {
1259 if (packet.header.markerBit) {
1260 int64_t capture_ms = packet.header.timestamp / 90.0;
1261 int64_t arrival_ms = packet.timestamp / 1000.0;
1262 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1263 }
1264 }
1265 }
1266 return timestamps;
1267}
stefane372d3c2017-02-02 08:04:18 -08001268
1269void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1270 for (const auto& kv : rtp_packets_) {
1271 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1272 StreamId stream_id = kv.first;
1273
1274 {
terelius23c595a2017-03-15 01:59:12 -07001275 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
1276 LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001277 for (LoggedRtpPacket packet : rtp_packets) {
1278 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1279 float y = packet.header.timestamp;
1280 timestamp_data.points.emplace_back(x, y);
1281 }
philipel35ba9bd2017-04-19 05:58:51 -07001282 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001283 }
1284
1285 {
1286 auto kv = rtcp_packets_.find(stream_id);
1287 if (kv != rtcp_packets_.end()) {
1288 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001289 TimeSeries timestamp_data(
1290 GetStreamName(stream_id) + " rtcp capture-time", LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001291 for (const LoggedRtcpPacket& rtcp : packets) {
1292 if (rtcp.type != kRtcpSr)
1293 continue;
1294 rtcp::SenderReport* sr;
1295 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1296 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1297 float y = sr->rtp_timestamp();
1298 timestamp_data.points.emplace_back(x, y);
1299 }
philipel35ba9bd2017-04-19 05:58:51 -07001300 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001301 }
1302 }
1303 }
1304
1305 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1306 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1307 plot->SetTitle("Timestamps");
1308}
michaelt6e5b2192017-02-22 07:33:27 -08001309
1310void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001311 TimeSeries time_series("Audio encoder target bitrate", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001312 ProcessPoints<AudioNetworkAdaptationEvent>(
1313 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001314 if (ana_event.config.bitrate_bps)
1315 return rtc::Optional<float>(
1316 static_cast<float>(*ana_event.config.bitrate_bps));
1317 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001318 },
philipel35ba9bd2017-04-19 05:58:51 -07001319 audio_network_adaptation_events_, begin_time_, &time_series);
1320 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001321 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1322 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1323 plot->SetTitle("Reported audio encoder target bitrate");
1324}
1325
1326void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001327 TimeSeries time_series("Audio encoder frame length", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001328 ProcessPoints<AudioNetworkAdaptationEvent>(
1329 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001330 if (ana_event.config.frame_length_ms)
1331 return rtc::Optional<float>(
1332 static_cast<float>(*ana_event.config.frame_length_ms));
1333 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001334 },
philipel35ba9bd2017-04-19 05:58:51 -07001335 audio_network_adaptation_events_, begin_time_, &time_series);
1336 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001337 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1338 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1339 plot->SetTitle("Reported audio encoder frame length");
1340}
1341
1342void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph(
1343 Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001344 TimeSeries time_series("Audio encoder uplink packet loss fraction",
1345 LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001346 ProcessPoints<AudioNetworkAdaptationEvent>(
1347 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001348 if (ana_event.config.uplink_packet_loss_fraction)
1349 return rtc::Optional<float>(static_cast<float>(
1350 *ana_event.config.uplink_packet_loss_fraction));
1351 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001352 },
philipel35ba9bd2017-04-19 05:58:51 -07001353 audio_network_adaptation_events_, begin_time_, &time_series);
1354 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001355 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1356 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1357 kTopMargin);
1358 plot->SetTitle("Reported audio encoder lost packets");
1359}
1360
1361void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001362 TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001363 ProcessPoints<AudioNetworkAdaptationEvent>(
1364 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001365 if (ana_event.config.enable_fec)
1366 return rtc::Optional<float>(
1367 static_cast<float>(*ana_event.config.enable_fec));
1368 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001369 },
philipel35ba9bd2017-04-19 05:58:51 -07001370 audio_network_adaptation_events_, begin_time_, &time_series);
1371 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001372 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1373 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1374 plot->SetTitle("Reported audio encoder FEC");
1375}
1376
1377void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001378 TimeSeries time_series("Audio encoder DTX", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001379 ProcessPoints<AudioNetworkAdaptationEvent>(
1380 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001381 if (ana_event.config.enable_dtx)
1382 return rtc::Optional<float>(
1383 static_cast<float>(*ana_event.config.enable_dtx));
1384 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001385 },
philipel35ba9bd2017-04-19 05:58:51 -07001386 audio_network_adaptation_events_, begin_time_, &time_series);
1387 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001388 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1389 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1390 plot->SetTitle("Reported audio encoder DTX");
1391}
1392
1393void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001394 TimeSeries time_series("Audio encoder number of channels", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001395 ProcessPoints<AudioNetworkAdaptationEvent>(
1396 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001397 if (ana_event.config.num_channels)
1398 return rtc::Optional<float>(
1399 static_cast<float>(*ana_event.config.num_channels));
1400 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001401 },
philipel35ba9bd2017-04-19 05:58:51 -07001402 audio_network_adaptation_events_, begin_time_, &time_series);
1403 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001404 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1405 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1406 kBottomMargin, kTopMargin);
1407 plot->SetTitle("Reported audio encoder number of channels");
1408}
terelius54ce6802016-07-13 06:44:41 -07001409} // namespace plotting
1410} // namespace webrtc