blob: dcff92c9d280027b1ff4f937678b836df066189b [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
Stefan Holmer13181032016-07-29 14:48:54 +0200292 // Maps a stream identifier consisting of ssrc and direction
terelius88e64e52016-07-19 01:51:06 -0700293 // to the header extensions used by that stream,
294 std::map<StreamId, RtpHeaderExtensionMap> extension_maps;
295
296 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700297 uint8_t header[IP_PACKET_SIZE];
298 size_t header_length;
299 size_t total_length;
300
perkjbbbad6d2017-05-19 06:30:28 -0700301 uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE];
302 uint8_t last_incoming_rtcp_packet_length = 0;
303
ivocaac9d6f2016-09-22 07:01:47 -0700304 // Make a default extension map for streams without configuration information.
305 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
306 // this can be removed. Tracking bug: webrtc:6399
307 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
308
terelius54ce6802016-07-13 06:44:41 -0700309 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
310 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700311 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
312 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
313 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700314 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
315 event_type != ParsedRtcEventLog::LOG_START &&
316 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700317 uint64_t timestamp = parsed_log_.GetTimestamp(i);
318 first_timestamp = std::min(first_timestamp, timestamp);
319 last_timestamp = std::max(last_timestamp, timestamp);
320 }
321
322 switch (parsed_log_.GetEventType(i)) {
323 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700324 rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i);
perkj09e71da2017-05-22 03:26:49 -0700325 StreamId stream(config.remote_ssrc, kIncomingPacket);
326 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
terelius0740a202016-08-08 10:21:04 -0700327 video_ssrcs_.insert(stream);
perkj09e71da2017-05-22 03:26:49 -0700328 StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket);
brandtr14742122017-01-27 04:53:07 -0800329 extension_maps[rtx_stream] =
perkj09e71da2017-05-22 03:26:49 -0700330 RtpHeaderExtensionMap(config.rtp_extensions);
brandtr14742122017-01-27 04:53:07 -0800331 video_ssrcs_.insert(rtx_stream);
332 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700333 break;
334 }
335 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700336 std::vector<rtclog::StreamConfig> configs =
337 parsed_log_.GetVideoSendConfig(i);
terelius405f90c2017-06-01 03:50:31 -0700338 for (const auto& config : configs) {
339 StreamId stream(config.local_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700340 extension_maps[stream] =
terelius405f90c2017-06-01 03:50:31 -0700341 RtpHeaderExtensionMap(config.rtp_extensions);
terelius8fbc7652017-05-31 02:03:16 -0700342 video_ssrcs_.insert(stream);
terelius405f90c2017-06-01 03:50:31 -0700343 StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700344 extension_maps[rtx_stream] =
terelius405f90c2017-06-01 03:50:31 -0700345 RtpHeaderExtensionMap(config.rtp_extensions);
terelius8fbc7652017-05-31 02:03:16 -0700346 video_ssrcs_.insert(rtx_stream);
347 rtx_ssrcs_.insert(rtx_stream);
348 }
terelius88e64e52016-07-19 01:51:06 -0700349 break;
350 }
351 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700352 rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i);
perkjac8f52d2017-05-22 09:36:28 -0700353 StreamId stream(config.remote_ssrc, kIncomingPacket);
354 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
ivoce0928d82016-10-10 05:12:51 -0700355 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700356 break;
357 }
358 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700359 rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i);
perkjf4726992017-05-22 10:12:26 -0700360 StreamId stream(config.local_ssrc, kOutgoingPacket);
361 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
ivoce0928d82016-10-10 05:12:51 -0700362 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700363 break;
364 }
365 case ParsedRtcEventLog::RTP_EVENT: {
perkj77cd58e2017-05-30 03:52:10 -0700366 parsed_log_.GetRtpHeader(i, &direction, header, &header_length,
367 &total_length);
terelius88e64e52016-07-19 01:51:06 -0700368 // Parse header to get SSRC.
369 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
370 RTPHeader parsed_header;
371 rtp_parser.Parse(&parsed_header);
Stefan Holmer13181032016-07-29 14:48:54 +0200372 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700373 // Look up the extension_map and parse it again to get the extensions.
374 if (extension_maps.count(stream) == 1) {
375 RtpHeaderExtensionMap* extension_map = &extension_maps[stream];
376 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700377 } else {
378 // Use the default extension map.
379 // TODO(ivoc): Once configuration of audio streams is stored in the
380 // event log, this can be removed.
381 // Tracking bug: webrtc:6399
382 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700383 }
384 uint64_t timestamp = parsed_log_.GetTimestamp(i);
385 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200386 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700387 break;
388 }
389 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200390 uint8_t packet[IP_PACKET_SIZE];
perkj77cd58e2017-05-30 03:52:10 -0700391 parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length);
perkjbbbad6d2017-05-19 06:30:28 -0700392 // Currently incoming RTCP packets are logged twice, both for audio and
393 // video. Only act on one of them. Compare against the previous parsed
394 // incoming RTCP packet.
395 if (direction == webrtc::kIncomingPacket) {
396 RTC_CHECK_LE(total_length, IP_PACKET_SIZE);
397 if (total_length == last_incoming_rtcp_packet_length &&
398 memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) {
399 continue;
400 } else {
401 memcpy(last_incoming_rtcp_packet, packet, total_length);
402 last_incoming_rtcp_packet_length = total_length;
403 }
404 }
405 rtcp::CommonHeader header;
406 const uint8_t* packet_end = packet + total_length;
407 for (const uint8_t* block = packet; block < packet_end;
408 block = header.NextPacket()) {
409 RTC_CHECK(header.Parse(block, packet_end - block));
410 if (header.type() == rtcp::TransportFeedback::kPacketType &&
411 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
412 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700413 rtc::MakeUnique<rtcp::TransportFeedback>());
perkjbbbad6d2017-05-19 06:30:28 -0700414 if (rtcp_packet->Parse(header)) {
415 uint32_t ssrc = rtcp_packet->sender_ssrc();
416 StreamId stream(ssrc, direction);
417 uint64_t timestamp = parsed_log_.GetTimestamp(i);
418 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
419 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
420 }
421 } else if (header.type() == rtcp::SenderReport::kPacketType) {
422 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700423 rtc::MakeUnique<rtcp::SenderReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700424 if (rtcp_packet->Parse(header)) {
425 uint32_t ssrc = rtcp_packet->sender_ssrc();
426 StreamId stream(ssrc, direction);
427 uint64_t timestamp = parsed_log_.GetTimestamp(i);
428 rtcp_packets_[stream].push_back(
429 LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet)));
430 }
431 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
432 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700433 rtc::MakeUnique<rtcp::ReceiverReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700434 if (rtcp_packet->Parse(header)) {
435 uint32_t ssrc = rtcp_packet->sender_ssrc();
436 StreamId stream(ssrc, direction);
437 uint64_t timestamp = parsed_log_.GetTimestamp(i);
438 rtcp_packets_[stream].push_back(
439 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet)));
Stefan Holmer13181032016-07-29 14:48:54 +0200440 }
terelius2c8e8a32017-06-02 01:29:48 -0700441 } else if (header.type() == rtcp::Remb::kPacketType &&
442 header.fmt() == rtcp::Remb::kFeedbackMessageType) {
443 std::unique_ptr<rtcp::Remb> rtcp_packet(
444 rtc::MakeUnique<rtcp::Remb>());
445 if (rtcp_packet->Parse(header)) {
446 uint32_t ssrc = rtcp_packet->sender_ssrc();
447 StreamId stream(ssrc, direction);
448 uint64_t timestamp = parsed_log_.GetTimestamp(i);
449 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
450 timestamp, kRtcpRemb, std::move(rtcp_packet)));
451 }
Stefan Holmer13181032016-07-29 14:48:54 +0200452 }
Stefan Holmer13181032016-07-29 14:48:54 +0200453 }
terelius88e64e52016-07-19 01:51:06 -0700454 break;
455 }
456 case ParsedRtcEventLog::LOG_START: {
457 break;
458 }
459 case ParsedRtcEventLog::LOG_END: {
460 break;
461 }
terelius424e6cf2017-02-20 05:14:41 -0800462 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
463 break;
464 }
465 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
466 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700467 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800468 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
469 &bwe_update.fraction_loss,
470 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700471 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700472 break;
473 }
terelius424e6cf2017-02-20 05:14:41 -0800474 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
philipel10fc0e62017-04-11 01:50:23 -0700475 bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i));
terelius424e6cf2017-02-20 05:14:41 -0800476 break;
477 }
minyue4b7c9522017-01-24 04:54:59 -0800478 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800479 AudioNetworkAdaptationEvent ana_event;
480 ana_event.timestamp = parsed_log_.GetTimestamp(i);
481 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
482 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800483 break;
484 }
philipel32d00102017-02-27 02:18:46 -0800485 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200486 bwe_probe_cluster_created_events_.push_back(
487 parsed_log_.GetBweProbeClusterCreated(i));
philipel32d00102017-02-27 02:18:46 -0800488 break;
489 }
490 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200491 bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i));
philipel32d00102017-02-27 02:18:46 -0800492 break;
493 }
terelius88e64e52016-07-19 01:51:06 -0700494 case ParsedRtcEventLog::UNKNOWN_EVENT: {
495 break;
496 }
497 }
terelius54ce6802016-07-13 06:44:41 -0700498 }
terelius88e64e52016-07-19 01:51:06 -0700499
terelius54ce6802016-07-13 06:44:41 -0700500 if (last_timestamp < first_timestamp) {
501 // No useful events in the log.
502 first_timestamp = last_timestamp = 0;
503 }
504 begin_time_ = first_timestamp;
505 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700506 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700507}
508
Stefan Holmer13181032016-07-29 14:48:54 +0200509class BitrateObserver : public CongestionController::Observer,
510 public RemoteBitrateObserver {
511 public:
512 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
513
minyue78b4d562016-11-30 04:47:39 -0800514 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
515 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
516 using CongestionController::Observer::OnNetworkChanged;
517
Stefan Holmer13181032016-07-29 14:48:54 +0200518 void OnNetworkChanged(uint32_t bitrate_bps,
519 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800520 int64_t rtt_ms,
521 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200522 last_bitrate_bps_ = bitrate_bps;
523 bitrate_updated_ = true;
524 }
525
526 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
527 uint32_t bitrate) override {}
528
529 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
530 bool GetAndResetBitrateUpdated() {
531 bool bitrate_updated = bitrate_updated_;
532 bitrate_updated_ = false;
533 return bitrate_updated;
534 }
535
536 private:
537 uint32_t last_bitrate_bps_;
538 bool bitrate_updated_;
539};
540
Stefan Holmer99f8e082016-09-09 13:37:50 +0200541bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700542 return rtx_ssrcs_.count(stream_id) == 1;
543}
544
Stefan Holmer99f8e082016-09-09 13:37:50 +0200545bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700546 return video_ssrcs_.count(stream_id) == 1;
547}
548
Stefan Holmer99f8e082016-09-09 13:37:50 +0200549bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700550 return audio_ssrcs_.count(stream_id) == 1;
551}
552
Stefan Holmer99f8e082016-09-09 13:37:50 +0200553std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
554 std::stringstream name;
555 if (IsAudioSsrc(stream_id)) {
556 name << "Audio ";
557 } else if (IsVideoSsrc(stream_id)) {
558 name << "Video ";
559 } else {
560 name << "Unknown ";
561 }
562 if (IsRtxSsrc(stream_id))
563 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700564 if (stream_id.GetDirection() == kIncomingPacket) {
565 name << "(In) ";
566 } else {
567 name << "(Out) ";
568 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200569 name << SsrcToString(stream_id.GetSsrc());
570 return name.str();
571}
572
terelius54ce6802016-07-13 06:44:41 -0700573void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
574 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700575 for (auto& kv : rtp_packets_) {
576 StreamId stream_id = kv.first;
577 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
578 // Filter on direction and SSRC.
579 if (stream_id.GetDirection() != desired_direction ||
580 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
581 continue;
terelius54ce6802016-07-13 06:44:41 -0700582 }
terelius54ce6802016-07-13 06:44:41 -0700583
terelius23c595a2017-03-15 01:59:12 -0700584 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700585 ProcessPoints<LoggedRtpPacket>(
586 [](const LoggedRtpPacket& packet) -> rtc::Optional<float> {
587 return rtc::Optional<float>(packet.total_length);
588 },
589 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700590 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700591 }
592
tereliusdc35dcd2016-08-01 12:03:27 -0700593 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
594 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
595 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700596 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700597 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700598 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700599 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700600 }
601}
602
philipelccd74892016-09-05 02:46:25 -0700603template <typename T>
604void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
605 PacketDirection desired_direction,
606 Plot* plot,
607 const std::map<StreamId, std::vector<T>>& packets,
608 const std::string& label_prefix) {
609 for (auto& kv : packets) {
610 StreamId stream_id = kv.first;
611 const std::vector<T>& packet_stream = kv.second;
612 // Filter on direction and SSRC.
613 if (stream_id.GetDirection() != desired_direction ||
614 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
615 continue;
616 }
617
terelius23c595a2017-03-15 01:59:12 -0700618 std::string label = label_prefix + " " + GetStreamName(stream_id);
619 TimeSeries time_series(label, LINE_STEP_GRAPH);
philipelccd74892016-09-05 02:46:25 -0700620 for (size_t i = 0; i < packet_stream.size(); i++) {
621 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
622 1000000;
philipelccd74892016-09-05 02:46:25 -0700623 time_series.points.emplace_back(x, i + 1);
624 }
625
philipel35ba9bd2017-04-19 05:58:51 -0700626 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700627 }
628}
629
630void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
631 PacketDirection desired_direction,
632 Plot* plot) {
633 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
634 "RTP");
635 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
636 "RTCP");
637
638 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
639 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
640 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
641 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
642 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
643 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
644 }
645}
646
terelius54ce6802016-07-13 06:44:41 -0700647// For each SSRC, plot the time between the consecutive playouts.
648void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
649 std::map<uint32_t, TimeSeries> time_series;
650 std::map<uint32_t, uint64_t> last_playout;
651
652 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700653
654 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
655 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
656 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
657 parsed_log_.GetAudioPlayout(i, &ssrc);
658 uint64_t timestamp = parsed_log_.GetTimestamp(i);
659 if (MatchingSsrc(ssrc, desired_ssrc_)) {
660 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
661 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
662 if (time_series[ssrc].points.size() == 0) {
663 // There were no previusly logged playout for this SSRC.
664 // Generate a point, but place it on the x-axis.
665 y = 0;
666 }
terelius54ce6802016-07-13 06:44:41 -0700667 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
668 last_playout[ssrc] = timestamp;
669 }
670 }
671 }
672
673 // Set labels and put in graph.
674 for (auto& kv : time_series) {
675 kv.second.label = SsrcToString(kv.first);
676 kv.second.style = BAR_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700677 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700678 }
679
tereliusdc35dcd2016-08-01 12:03:27 -0700680 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
681 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
682 kTopMargin);
683 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700684}
685
ivocaac9d6f2016-09-22 07:01:47 -0700686// For audio SSRCs, plot the audio level.
687void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
688 std::map<StreamId, TimeSeries> time_series;
689
690 for (auto& kv : rtp_packets_) {
691 StreamId stream_id = kv.first;
692 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
693 // TODO(ivoc): When audio send/receive configs are stored in the event
694 // log, a check should be added here to only process audio
695 // streams. Tracking bug: webrtc:6399
696 for (auto& packet : packet_stream) {
697 if (packet.header.extension.hasAudioLevel) {
698 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
699 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
700 // Here we convert it to dBov.
701 float y = static_cast<float>(-packet.header.extension.audioLevel);
702 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
703 }
704 }
705 }
706
707 for (auto& series : time_series) {
708 series.second.label = GetStreamName(series.first);
709 series.second.style = LINE_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700710 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700711 }
712
713 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800714 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700715 kTopMargin);
716 plot->SetTitle("Audio level");
717}
718
terelius54ce6802016-07-13 06:44:41 -0700719// For each SSRC, plot the time between the consecutive playouts.
720void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700721 for (auto& kv : rtp_packets_) {
722 StreamId stream_id = kv.first;
723 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
724 // Filter on direction and SSRC.
725 if (stream_id.GetDirection() != kIncomingPacket ||
726 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
727 continue;
terelius54ce6802016-07-13 06:44:41 -0700728 }
terelius54ce6802016-07-13 06:44:41 -0700729
terelius23c595a2017-03-15 01:59:12 -0700730 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700731 ProcessPairs<LoggedRtpPacket, float>(
732 [](const LoggedRtpPacket& old_packet,
733 const LoggedRtpPacket& new_packet) {
734 int64_t diff =
735 WrappingDifference(new_packet.header.sequenceNumber,
736 old_packet.header.sequenceNumber, 1ul << 16);
737 return rtc::Optional<float>(diff);
738 },
739 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700740 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700741 }
742
tereliusdc35dcd2016-08-01 12:03:27 -0700743 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
744 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
745 kTopMargin);
746 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700747}
748
Stefan Holmer99f8e082016-09-09 13:37:50 +0200749void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
750 for (auto& kv : rtp_packets_) {
751 StreamId stream_id = kv.first;
752 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
753 // Filter on direction and SSRC.
754 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800755 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
756 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200757 continue;
758 }
759
terelius23c595a2017-03-15 01:59:12 -0700760 TimeSeries time_series(GetStreamName(stream_id), LINE_DOT_GRAPH);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200761 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800762 const uint64_t kStep = 1000000;
763 SequenceNumberUnwrapper unwrapper_;
764 SequenceNumberUnwrapper prior_unwrapper_;
765 size_t window_index_begin = 0;
766 size_t window_index_end = 0;
767 int64_t highest_seq_number =
768 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
769 int64_t highest_prior_seq_number =
770 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
771
772 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
773 while (window_index_end < packet_stream.size() &&
774 packet_stream[window_index_end].timestamp < t) {
775 int64_t sequence_number = unwrapper_.Unwrap(
776 packet_stream[window_index_end].header.sequenceNumber);
777 highest_seq_number = std::max(highest_seq_number, sequence_number);
778 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200779 }
terelius4c9b4af2017-01-30 08:44:51 -0800780 while (window_index_begin < packet_stream.size() &&
781 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
782 int64_t sequence_number = prior_unwrapper_.Unwrap(
783 packet_stream[window_index_begin].header.sequenceNumber);
784 highest_prior_seq_number =
785 std::max(highest_prior_seq_number, sequence_number);
786 ++window_index_begin;
787 }
788 float x = static_cast<float>(t - begin_time_) / 1000000;
789 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
790 if (expected_packets > 0) {
791 int64_t received_packets = window_index_end - window_index_begin;
792 int64_t lost_packets = expected_packets - received_packets;
793 float y = static_cast<float>(lost_packets) / expected_packets * 100;
794 time_series.points.emplace_back(x, y);
795 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200796 }
philipel35ba9bd2017-04-19 05:58:51 -0700797 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200798 }
799
800 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
801 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
802 kTopMargin);
803 plot->SetTitle("Estimated incoming loss rate");
804}
805
terelius54ce6802016-07-13 06:44:41 -0700806void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700807 for (auto& kv : rtp_packets_) {
808 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700809 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700810 // Filter on direction and SSRC.
811 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200812 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
813 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
814 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700815 continue;
816 }
terelius54ce6802016-07-13 06:44:41 -0700817
terelius23c595a2017-03-15 01:59:12 -0700818 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
819 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700820 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
821 packet_stream, begin_time_,
822 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700823 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700824
terelius23c595a2017-03-15 01:59:12 -0700825 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
826 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700827 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
828 packet_stream, begin_time_,
829 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700830 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700831 }
832
tereliusdc35dcd2016-08-01 12:03:27 -0700833 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
834 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
835 kTopMargin);
836 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700837}
838
839void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700840 for (auto& kv : rtp_packets_) {
841 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700842 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700843 // Filter on direction and SSRC.
844 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200845 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
846 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
847 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700848 continue;
849 }
terelius54ce6802016-07-13 06:44:41 -0700850
terelius23c595a2017-03-15 01:59:12 -0700851 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
852 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700853 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
854 packet_stream, begin_time_,
855 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700856 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700857
terelius23c595a2017-03-15 01:59:12 -0700858 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
859 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700860 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
861 packet_stream, begin_time_,
862 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700863 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700864 }
865
tereliusdc35dcd2016-08-01 12:03:27 -0700866 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
867 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
868 kTopMargin);
869 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700870}
871
tereliusf736d232016-08-04 10:00:11 -0700872// Plot the fraction of packets lost (as perceived by the loss-based BWE).
873void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -0700874 TimeSeries time_series("Fraction lost", LINE_DOT_GRAPH);
tereliusf736d232016-08-04 10:00:11 -0700875 for (auto& bwe_update : bwe_loss_updates_) {
876 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
877 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700878 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700879 }
tereliusf736d232016-08-04 10:00:11 -0700880
881 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
882 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
883 kTopMargin);
884 plot->SetTitle("Reported packet loss");
philipel35ba9bd2017-04-19 05:58:51 -0700885 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700886}
887
terelius54ce6802016-07-13 06:44:41 -0700888// Plot the total bandwidth used by all RTP streams.
889void EventLogAnalyzer::CreateTotalBitrateGraph(
890 PacketDirection desired_direction,
891 Plot* plot) {
892 struct TimestampSize {
893 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
894 uint64_t timestamp;
895 size_t size;
896 };
897 std::vector<TimestampSize> packets;
898
899 PacketDirection direction;
900 size_t total_length;
901
902 // Extract timestamps and sizes for the relevant packets.
903 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
904 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
905 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
perkj77cd58e2017-05-30 03:52:10 -0700906 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length);
terelius54ce6802016-07-13 06:44:41 -0700907 if (direction == desired_direction) {
908 uint64_t timestamp = parsed_log_.GetTimestamp(i);
909 packets.push_back(TimestampSize(timestamp, total_length));
910 }
911 }
912 }
913
914 size_t window_index_begin = 0;
915 size_t window_index_end = 0;
916 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700917
918 // Calculate a moving average of the bitrate and store in a TimeSeries.
philipel35ba9bd2017-04-19 05:58:51 -0700919 TimeSeries bitrate_series("Bitrate", LINE_GRAPH);
terelius54ce6802016-07-13 06:44:41 -0700920 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
921 while (window_index_end < packets.size() &&
922 packets[window_index_end].timestamp < time) {
923 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700924 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700925 }
926 while (window_index_begin < packets.size() &&
927 packets[window_index_begin].timestamp < time - window_duration_) {
928 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
929 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700930 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700931 }
932 float window_duration_in_seconds =
933 static_cast<float>(window_duration_) / 1000000;
934 float x = static_cast<float>(time - begin_time_) / 1000000;
935 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700936 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700937 }
philipel35ba9bd2017-04-19 05:58:51 -0700938 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700939
terelius8058e582016-07-25 01:32:41 -0700940 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
941 if (desired_direction == kOutgoingPacket) {
philipel35ba9bd2017-04-19 05:58:51 -0700942 TimeSeries loss_series("Loss-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700943 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -0700944 float x =
philipel10fc0e62017-04-11 01:50:23 -0700945 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
946 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700947 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -0700948 }
949
philipel35ba9bd2017-04-19 05:58:51 -0700950 TimeSeries delay_series("Delay-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700951 for (auto& delay_update : bwe_delay_updates_) {
952 float x =
953 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
954 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700955 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700956 }
philipele127e7a2017-03-29 16:28:53 +0200957
philipel35ba9bd2017-04-19 05:58:51 -0700958 TimeSeries created_series("Probe cluster created.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +0200959 for (auto& cluster : bwe_probe_cluster_created_events_) {
960 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
961 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700962 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +0200963 }
964
philipel35ba9bd2017-04-19 05:58:51 -0700965 TimeSeries result_series("Probing results.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +0200966 for (auto& result : bwe_probe_result_events_) {
967 if (result.bitrate_bps) {
968 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
969 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700970 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +0200971 }
972 }
philipel35ba9bd2017-04-19 05:58:51 -0700973 plot->AppendTimeSeries(std::move(loss_series));
974 plot->AppendTimeSeries(std::move(delay_series));
975 plot->AppendTimeSeries(std::move(created_series));
976 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -0700977 }
philipele127e7a2017-03-29 16:28:53 +0200978
terelius2c8e8a32017-06-02 01:29:48 -0700979 // Overlay the incoming REMB over the outgoing bitrate
980 // and outgoing REMB over incoming bitrate.
981 PacketDirection remb_direction =
982 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
983 TimeSeries remb_series("Remb", LINE_STEP_GRAPH);
984 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
985 for (const auto& kv : rtcp_packets_) {
986 if (kv.first.GetDirection() == remb_direction) {
987 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
988 if (rtcp_packet.type == kRtcpRemb) {
989 remb_packets.insert(
990 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
991 }
992 }
993 }
994 }
995
996 for (const auto& kv : remb_packets) {
997 const LoggedRtcpPacket* const rtcp = kv.second;
998 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
999 float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000;
1000 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
1001 remb_series.points.emplace_back(x, y);
1002 }
1003 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1004
tereliusdc35dcd2016-08-01 12:03:27 -07001005 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1006 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001007 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001008 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001009 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001010 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001011 }
1012}
1013
1014// For each SSRC, plot the bandwidth used by that stream.
1015void EventLogAnalyzer::CreateStreamBitrateGraph(
1016 PacketDirection desired_direction,
1017 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001018 for (auto& kv : rtp_packets_) {
1019 StreamId stream_id = kv.first;
1020 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1021 // Filter on direction and SSRC.
1022 if (stream_id.GetDirection() != desired_direction ||
1023 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1024 continue;
terelius54ce6802016-07-13 06:44:41 -07001025 }
1026
terelius23c595a2017-03-15 01:59:12 -07001027 TimeSeries time_series(GetStreamName(stream_id), LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001028 MovingAverage<LoggedRtpPacket, double>(
1029 [](const LoggedRtpPacket& packet) {
1030 return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0);
1031 },
1032 packet_stream, begin_time_, end_time_, window_duration_, step_,
1033 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001034 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001035 }
1036
tereliusdc35dcd2016-08-01 12:03:27 -07001037 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1038 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001039 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001040 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001041 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001042 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001043 }
1044}
1045
tereliuse34c19c2016-08-15 08:47:14 -07001046void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001047 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1048 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001049
1050 for (const auto& kv : rtp_packets_) {
1051 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1052 for (const LoggedRtpPacket& rtp_packet : kv.second)
1053 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1054 }
1055 }
1056
1057 for (const auto& kv : rtcp_packets_) {
1058 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1059 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1060 incoming_rtcp.insert(
1061 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1062 }
1063 }
1064
1065 SimulatedClock clock(0);
1066 BitrateObserver observer;
1067 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001068 PacketRouter packet_router;
1069 CongestionController cc(&clock, &observer, &observer, &null_event_log,
1070 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +02001071 // TODO(holmer): Log the call config and use that here instead.
1072 static const uint32_t kDefaultStartBitrateBps = 300000;
1073 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1074
terelius23c595a2017-03-15 01:59:12 -07001075 TimeSeries time_series("Delay-based estimate", LINE_DOT_GRAPH);
1076 TimeSeries acked_time_series("Acked bitrate", LINE_DOT_GRAPH);
Stefan Holmer13181032016-07-29 14:48:54 +02001077
1078 auto rtp_iterator = outgoing_rtp.begin();
1079 auto rtcp_iterator = incoming_rtcp.begin();
1080
1081 auto NextRtpTime = [&]() {
1082 if (rtp_iterator != outgoing_rtp.end())
1083 return static_cast<int64_t>(rtp_iterator->first);
1084 return std::numeric_limits<int64_t>::max();
1085 };
1086
1087 auto NextRtcpTime = [&]() {
1088 if (rtcp_iterator != incoming_rtcp.end())
1089 return static_cast<int64_t>(rtcp_iterator->first);
1090 return std::numeric_limits<int64_t>::max();
1091 };
1092
1093 auto NextProcessTime = [&]() {
1094 if (rtcp_iterator != incoming_rtcp.end() ||
1095 rtp_iterator != outgoing_rtp.end()) {
1096 return clock.TimeInMicroseconds() +
1097 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1098 }
1099 return std::numeric_limits<int64_t>::max();
1100 };
1101
Stefan Holmer492ee282016-10-27 17:19:20 +02001102 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001103
Stefan Holmer13181032016-07-29 14:48:54 +02001104 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001105 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001106 while (time_us != std::numeric_limits<int64_t>::max()) {
1107 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1108 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001109 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001110 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1111 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001112 cc.OnTransportFeedback(
1113 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1114 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001115 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001116 rtc::Optional<uint32_t> bitrate_bps;
1117 if (!feedback.empty()) {
elad.alonf9490002017-03-06 05:32:21 -08001118 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001119 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1120 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1121 }
1122 uint32_t y = 0;
1123 if (bitrate_bps)
1124 y = *bitrate_bps / 1000;
1125 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1126 1000000;
1127 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +02001128 }
1129 ++rtcp_iterator;
1130 }
1131 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001132 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001133 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1134 if (rtp.header.extension.hasTransportSequenceNumber) {
1135 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001136 cc.AddPacket(rtp.header.ssrc,
1137 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001138 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001139 rtc::SentPacket sent_packet(
1140 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1141 cc.OnSentPacket(sent_packet);
1142 }
1143 ++rtp_iterator;
1144 }
stefanc3de0332016-08-02 07:22:17 -07001145 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1146 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001147 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001148 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001149 if (observer.GetAndResetBitrateUpdated() ||
1150 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001151 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001152 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1153 1000000;
1154 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001155 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001156 }
1157 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1158 }
1159 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001160 plot->AppendTimeSeries(std::move(time_series));
1161 plot->AppendTimeSeries(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001162
tereliusdc35dcd2016-08-01 12:03:27 -07001163 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1164 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1165 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001166}
1167
tereliuse34c19c2016-08-15 08:47:14 -07001168void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001169 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1170 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001171
1172 for (const auto& kv : rtp_packets_) {
1173 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1174 for (const LoggedRtpPacket& rtp_packet : kv.second)
1175 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1176 }
1177 }
1178
1179 for (const auto& kv : rtcp_packets_) {
1180 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1181 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1182 incoming_rtcp.insert(
1183 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1184 }
1185 }
1186
1187 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001188 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001189
terelius23c595a2017-03-15 01:59:12 -07001190 TimeSeries time_series("Network Delay Change", LINE_DOT_GRAPH);
stefanc3de0332016-08-02 07:22:17 -07001191 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1192
1193 auto rtp_iterator = outgoing_rtp.begin();
1194 auto rtcp_iterator = incoming_rtcp.begin();
1195
1196 auto NextRtpTime = [&]() {
1197 if (rtp_iterator != outgoing_rtp.end())
1198 return static_cast<int64_t>(rtp_iterator->first);
1199 return std::numeric_limits<int64_t>::max();
1200 };
1201
1202 auto NextRtcpTime = [&]() {
1203 if (rtcp_iterator != incoming_rtcp.end())
1204 return static_cast<int64_t>(rtcp_iterator->first);
1205 return std::numeric_limits<int64_t>::max();
1206 };
1207
1208 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1209 while (time_us != std::numeric_limits<int64_t>::max()) {
1210 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1211 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1212 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1213 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1214 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001215 feedback_adapter.OnTransportFeedback(
1216 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001217 std::vector<PacketFeedback> feedback =
1218 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001219 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001220 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001221 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1222 float x =
1223 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1224 1000000;
1225 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1226 time_series.points.emplace_back(x, y);
1227 }
1228 }
1229 ++rtcp_iterator;
1230 }
1231 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1232 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1233 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1234 if (rtp.header.extension.hasTransportSequenceNumber) {
1235 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001236 feedback_adapter.AddPacket(rtp.header.ssrc,
1237 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001238 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001239 feedback_adapter.OnSentPacket(
1240 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1241 }
1242 ++rtp_iterator;
1243 }
1244 time_us = std::min(NextRtpTime(), NextRtcpTime());
1245 }
1246 // We assume that the base network delay (w/o queues) is the min delay
1247 // observed during the call.
1248 for (TimeSeriesPoint& point : time_series.points)
1249 point.y -= estimated_base_delay_ms;
1250 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001251 plot->AppendTimeSeries(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001252
1253 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1254 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1255 plot->SetTitle("Network Delay Change.");
1256}
stefan08383272016-12-20 08:51:52 -08001257
1258std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1259 const {
1260 std::vector<std::pair<int64_t, int64_t>> timestamps;
1261 size_t largest_stream_size = 0;
1262 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1263 // Find the incoming video stream with the most number of packets that is
1264 // not rtx.
1265 for (const auto& kv : rtp_packets_) {
1266 if (kv.first.GetDirection() == kIncomingPacket &&
1267 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1268 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1269 kv.second.size() > largest_stream_size) {
1270 largest_stream_size = kv.second.size();
1271 largest_video_stream = &kv.second;
1272 }
1273 }
1274 if (largest_video_stream == nullptr) {
1275 for (auto& packet : *largest_video_stream) {
1276 if (packet.header.markerBit) {
1277 int64_t capture_ms = packet.header.timestamp / 90.0;
1278 int64_t arrival_ms = packet.timestamp / 1000.0;
1279 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1280 }
1281 }
1282 }
1283 return timestamps;
1284}
stefane372d3c2017-02-02 08:04:18 -08001285
1286void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1287 for (const auto& kv : rtp_packets_) {
1288 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1289 StreamId stream_id = kv.first;
1290
1291 {
terelius23c595a2017-03-15 01:59:12 -07001292 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
1293 LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001294 for (LoggedRtpPacket packet : rtp_packets) {
1295 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1296 float y = packet.header.timestamp;
1297 timestamp_data.points.emplace_back(x, y);
1298 }
philipel35ba9bd2017-04-19 05:58:51 -07001299 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001300 }
1301
1302 {
1303 auto kv = rtcp_packets_.find(stream_id);
1304 if (kv != rtcp_packets_.end()) {
1305 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001306 TimeSeries timestamp_data(
1307 GetStreamName(stream_id) + " rtcp capture-time", LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001308 for (const LoggedRtcpPacket& rtcp : packets) {
1309 if (rtcp.type != kRtcpSr)
1310 continue;
1311 rtcp::SenderReport* sr;
1312 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1313 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1314 float y = sr->rtp_timestamp();
1315 timestamp_data.points.emplace_back(x, y);
1316 }
philipel35ba9bd2017-04-19 05:58:51 -07001317 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001318 }
1319 }
1320 }
1321
1322 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1323 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1324 plot->SetTitle("Timestamps");
1325}
michaelt6e5b2192017-02-22 07:33:27 -08001326
1327void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001328 TimeSeries time_series("Audio encoder target bitrate", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001329 ProcessPoints<AudioNetworkAdaptationEvent>(
1330 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001331 if (ana_event.config.bitrate_bps)
1332 return rtc::Optional<float>(
1333 static_cast<float>(*ana_event.config.bitrate_bps));
1334 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001335 },
philipel35ba9bd2017-04-19 05:58:51 -07001336 audio_network_adaptation_events_, begin_time_, &time_series);
1337 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001338 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1339 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1340 plot->SetTitle("Reported audio encoder target bitrate");
1341}
1342
1343void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001344 TimeSeries time_series("Audio encoder frame length", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001345 ProcessPoints<AudioNetworkAdaptationEvent>(
1346 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001347 if (ana_event.config.frame_length_ms)
1348 return rtc::Optional<float>(
1349 static_cast<float>(*ana_event.config.frame_length_ms));
1350 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001351 },
philipel35ba9bd2017-04-19 05:58:51 -07001352 audio_network_adaptation_events_, begin_time_, &time_series);
1353 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001354 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1355 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1356 plot->SetTitle("Reported audio encoder frame length");
1357}
1358
1359void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph(
1360 Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001361 TimeSeries time_series("Audio encoder uplink packet loss fraction",
1362 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.uplink_packet_loss_fraction)
1366 return rtc::Optional<float>(static_cast<float>(
1367 *ana_event.config.uplink_packet_loss_fraction));
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, 10, "Percent lost packets", kBottomMargin,
1374 kTopMargin);
1375 plot->SetTitle("Reported audio encoder lost packets");
1376}
1377
1378void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001379 TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001380 ProcessPoints<AudioNetworkAdaptationEvent>(
1381 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001382 if (ana_event.config.enable_fec)
1383 return rtc::Optional<float>(
1384 static_cast<float>(*ana_event.config.enable_fec));
1385 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001386 },
philipel35ba9bd2017-04-19 05:58:51 -07001387 audio_network_adaptation_events_, begin_time_, &time_series);
1388 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001389 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1390 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1391 plot->SetTitle("Reported audio encoder FEC");
1392}
1393
1394void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001395 TimeSeries time_series("Audio encoder DTX", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001396 ProcessPoints<AudioNetworkAdaptationEvent>(
1397 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001398 if (ana_event.config.enable_dtx)
1399 return rtc::Optional<float>(
1400 static_cast<float>(*ana_event.config.enable_dtx));
1401 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001402 },
philipel35ba9bd2017-04-19 05:58:51 -07001403 audio_network_adaptation_events_, begin_time_, &time_series);
1404 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001405 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1406 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1407 plot->SetTitle("Reported audio encoder DTX");
1408}
1409
1410void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001411 TimeSeries time_series("Audio encoder number of channels", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001412 ProcessPoints<AudioNetworkAdaptationEvent>(
1413 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001414 if (ana_event.config.num_channels)
1415 return rtc::Optional<float>(
1416 static_cast<float>(*ana_event.config.num_channels));
1417 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001418 },
philipel35ba9bd2017-04-19 05:58:51 -07001419 audio_network_adaptation_events_, begin_time_, &time_series);
1420 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001421 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1422 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1423 kBottomMargin, kTopMargin);
1424 plot->SetTitle("Reported audio encoder number of channels");
1425}
terelius54ce6802016-07-13 06:44:41 -07001426} // namespace plotting
1427} // namespace webrtc