blob: 71f89092f9226a072070d1b2b11207f19efc68ac [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"
Stefan Holmer60e43462016-09-07 09:58:20 +020022#include "webrtc/base/rate_statistics.h"
ossuf515ab82016-12-07 04:52:58 -080023#include "webrtc/call/audio_receive_stream.h"
24#include "webrtc/call/audio_send_stream.h"
25#include "webrtc/call/call.h"
terelius54ce6802016-07-13 06:44:41 -070026#include "webrtc/common_types.h"
Stefan Holmer13181032016-07-29 14:48:54 +020027#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
terelius4c9b4af2017-01-30 08:44:51 -080028#include "webrtc/modules/include/module_common_types.h"
terelius54ce6802016-07-13 06:44:41 -070029#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
30#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
danilchapbf369fe2016-10-07 07:39:54 -070031#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
stefane372d3c2017-02-02 08:04:18 -080032#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
33#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
Stefan Holmer13181032016-07-29 14:48:54 +020034#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
ossuf515ab82016-12-07 04:52:58 -080035#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
36#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
terelius54ce6802016-07-13 06:44:41 -070037#include "webrtc/video_receive_stream.h"
38#include "webrtc/video_send_stream.h"
39
tereliusdc35dcd2016-08-01 12:03:27 -070040namespace webrtc {
41namespace plotting {
42
terelius54ce6802016-07-13 06:44:41 -070043namespace {
44
elad.alonec304f92017-03-08 05:03:53 -080045class PacketFeedbackComparator {
46 public:
47 inline bool operator()(const webrtc::PacketFeedback& lhs,
48 const webrtc::PacketFeedback& rhs) {
49 if (lhs.arrival_time_ms != rhs.arrival_time_ms)
50 return lhs.arrival_time_ms < rhs.arrival_time_ms;
51 if (lhs.send_time_ms != rhs.send_time_ms)
52 return lhs.send_time_ms < rhs.send_time_ms;
53 return lhs.sequence_number < rhs.sequence_number;
54 }
55};
56
57void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
58 auto pred = [](const PacketFeedback& packet_feedback) {
59 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
60 };
61 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
62 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
63}
64
terelius54ce6802016-07-13 06:44:41 -070065std::string SsrcToString(uint32_t ssrc) {
66 std::stringstream ss;
67 ss << "SSRC " << ssrc;
68 return ss.str();
69}
70
71// Checks whether an SSRC is contained in the list of desired SSRCs.
72// Note that an empty SSRC list matches every SSRC.
73bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
74 if (desired_ssrc.size() == 0)
75 return true;
76 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
77 desired_ssrc.end();
78}
79
80double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
81 // The timestamp is a fixed point representation with 6 bits for seconds
82 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
83 // time in seconds and then multiply by 1000000 to convert to microseconds.
84 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070085 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070086 return abs_send_time * kTimestampToMicroSec;
87}
88
89// Computes the difference |later| - |earlier| where |later| and |earlier|
90// are counters that wrap at |modulus|. The difference is chosen to have the
91// least absolute value. For example if |modulus| is 8, then the difference will
92// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
93// be in [-4, 4].
94int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
95 RTC_DCHECK_LE(1, modulus);
96 RTC_DCHECK_LT(later, modulus);
97 RTC_DCHECK_LT(earlier, modulus);
98 int64_t difference =
99 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
100 int64_t max_difference = modulus / 2;
101 int64_t min_difference = max_difference - modulus + 1;
102 if (difference > max_difference) {
103 difference -= modulus;
104 }
105 if (difference < min_difference) {
106 difference += modulus;
107 }
terelius6addf492016-08-23 17:34:07 -0700108 if (difference > max_difference / 2 || difference < min_difference / 2) {
109 LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
110 << " expected to be in the range (" << min_difference / 2
111 << "," << max_difference / 2 << ") but is " << difference
112 << ". Correct unwrapping is uncertain.";
113 }
terelius54ce6802016-07-13 06:44:41 -0700114 return difference;
115}
116
ivocaac9d6f2016-09-22 07:01:47 -0700117// Return default values for header extensions, to use on streams without stored
118// mapping data. Currently this only applies to audio streams, since the mapping
119// is not stored in the event log.
120// TODO(ivoc): Remove this once this mapping is stored in the event log for
121// audio streams. Tracking bug: webrtc:6399
122webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
123 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800124 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
125 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700126 webrtc::RtpExtension::kAbsSendTimeDefaultId);
127 return default_map;
128}
129
tereliusdc35dcd2016-08-01 12:03:27 -0700130constexpr float kLeftMargin = 0.01f;
131constexpr float kRightMargin = 0.02f;
132constexpr float kBottomMargin = 0.02f;
133constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700134
terelius53dc23c2017-03-13 05:24:05 -0700135rtc::Optional<double> NetworkDelayDiff_AbsSendTime(
136 const LoggedRtpPacket& old_packet,
137 const LoggedRtpPacket& new_packet) {
138 if (old_packet.header.extension.hasAbsoluteSendTime &&
139 new_packet.header.extension.hasAbsoluteSendTime) {
140 int64_t send_time_diff = WrappingDifference(
141 new_packet.header.extension.absoluteSendTime,
142 old_packet.header.extension.absoluteSendTime, 1ul << 24);
143 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
144 double delay_change_us =
145 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
146 return rtc::Optional<double>(delay_change_us / 1000);
147 } else {
148 return rtc::Optional<double>();
terelius6addf492016-08-23 17:34:07 -0700149 }
150}
151
terelius53dc23c2017-03-13 05:24:05 -0700152rtc::Optional<double> NetworkDelayDiff_CaptureTime(
153 const LoggedRtpPacket& old_packet,
154 const LoggedRtpPacket& new_packet) {
155 int64_t send_time_diff = WrappingDifference(
156 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
157 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
158
159 const double kVideoSampleRate = 90000;
160 // TODO(terelius): We treat all streams as video for now, even though
161 // audio might be sampled at e.g. 16kHz, because it is really difficult to
162 // figure out the true sampling rate of a stream. The effect is that the
163 // delay will be scaled incorrectly for non-video streams.
164
165 double delay_change =
166 static_cast<double>(recv_time_diff) / 1000 -
167 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
168 if (delay_change < -10000 || 10000 < delay_change) {
169 LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
170 LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
171 << ", received time " << old_packet.timestamp;
172 LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
173 << ", received time " << new_packet.timestamp;
174 LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
175 << static_cast<double>(recv_time_diff) / 1000000 << "s";
176 LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
177 << static_cast<double>(send_time_diff) / kVideoSampleRate
178 << "s";
179 }
180 return rtc::Optional<double>(delay_change);
181}
182
183// For each element in data, use |get_y()| to extract a y-coordinate and
184// store the result in a TimeSeries.
185template <typename DataType>
186void ProcessPoints(
187 rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y,
188 const std::vector<DataType>& data,
189 uint64_t begin_time,
190 TimeSeries* result) {
191 for (size_t i = 0; i < data.size(); i++) {
192 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
193 rtc::Optional<float> y = get_y(data[i]);
194 if (y)
195 result->points.emplace_back(x, *y);
196 }
197}
198
199// For each pair of adjacent elements in |data|, use |get_y| to extract a
terelius6addf492016-08-23 17:34:07 -0700200// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
201// will be the time of the second element in the pair.
terelius53dc23c2017-03-13 05:24:05 -0700202template <typename DataType, typename ResultType>
203void ProcessPairs(
204 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
205 const DataType&)> get_y,
206 const std::vector<DataType>& data,
207 uint64_t begin_time,
208 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700209 for (size_t i = 1; i < data.size(); i++) {
210 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700211 rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]);
212 if (y)
213 result->points.emplace_back(x, static_cast<float>(*y));
214 }
215}
216
217// For each element in data, use |extract()| to extract a y-coordinate and
218// store the result in a TimeSeries.
219template <typename DataType, typename ResultType>
220void AccumulatePoints(
221 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
222 const std::vector<DataType>& data,
223 uint64_t begin_time,
224 TimeSeries* result) {
225 ResultType sum = 0;
226 for (size_t i = 0; i < data.size(); i++) {
227 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
228 rtc::Optional<ResultType> y = extract(data[i]);
229 if (y) {
230 sum += *y;
231 result->points.emplace_back(x, static_cast<float>(sum));
232 }
233 }
234}
235
236// For each pair of adjacent elements in |data|, use |extract()| to extract a
237// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
238// will be the time of the second element in the pair.
239template <typename DataType, typename ResultType>
240void AccumulatePairs(
241 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
242 const DataType&)> extract,
243 const std::vector<DataType>& data,
244 uint64_t begin_time,
245 TimeSeries* result) {
246 ResultType sum = 0;
247 for (size_t i = 1; i < data.size(); i++) {
248 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
249 rtc::Optional<ResultType> y = extract(data[i - 1], data[i]);
250 if (y)
251 sum += *y;
252 result->points.emplace_back(x, static_cast<float>(sum));
tereliusccbbf8d2016-08-10 07:34:28 -0700253 }
254}
255
terelius6addf492016-08-23 17:34:07 -0700256// Calculates a moving average of |data| and stores the result in a TimeSeries.
257// A data point is generated every |step| microseconds from |begin_time|
258// to |end_time|. The value of each data point is the average of the data
259// during the preceeding |window_duration_us| microseconds.
terelius53dc23c2017-03-13 05:24:05 -0700260template <typename DataType, typename ResultType>
261void MovingAverage(
262 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
263 const std::vector<DataType>& data,
264 uint64_t begin_time,
265 uint64_t end_time,
266 uint64_t window_duration_us,
267 uint64_t step,
268 webrtc::plotting::TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700269 size_t window_index_begin = 0;
270 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700271 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700272
273 for (uint64_t t = begin_time; t < end_time + step; t += step) {
274 while (window_index_end < data.size() &&
275 data[window_index_end].timestamp < t) {
terelius53dc23c2017-03-13 05:24:05 -0700276 rtc::Optional<ResultType> value = extract(data[window_index_end]);
277 if (value)
278 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700279 ++window_index_end;
280 }
281 while (window_index_begin < data.size() &&
282 data[window_index_begin].timestamp < t - window_duration_us) {
terelius53dc23c2017-03-13 05:24:05 -0700283 rtc::Optional<ResultType> value = extract(data[window_index_begin]);
284 if (value)
285 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700286 ++window_index_begin;
287 }
288 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
289 float x = static_cast<float>(t - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700290 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700291 result->points.emplace_back(x, y);
292 }
293}
294
terelius54ce6802016-07-13 06:44:41 -0700295} // namespace
296
terelius54ce6802016-07-13 06:44:41 -0700297EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
298 : parsed_log_(log), window_duration_(250000), step_(10000) {
299 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
300 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700301
Stefan Holmer13181032016-07-29 14:48:54 +0200302 // Maps a stream identifier consisting of ssrc and direction
terelius88e64e52016-07-19 01:51:06 -0700303 // to the header extensions used by that stream,
304 std::map<StreamId, RtpHeaderExtensionMap> extension_maps;
305
306 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700307 uint8_t header[IP_PACKET_SIZE];
308 size_t header_length;
309 size_t total_length;
310
perkjbbbad6d2017-05-19 06:30:28 -0700311 uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE];
312 uint8_t last_incoming_rtcp_packet_length = 0;
313
ivocaac9d6f2016-09-22 07:01:47 -0700314 // Make a default extension map for streams without configuration information.
315 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
316 // this can be removed. Tracking bug: webrtc:6399
317 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
318
terelius54ce6802016-07-13 06:44:41 -0700319 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
320 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700321 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
322 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
323 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700324 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
325 event_type != ParsedRtcEventLog::LOG_START &&
326 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700327 uint64_t timestamp = parsed_log_.GetTimestamp(i);
328 first_timestamp = std::min(first_timestamp, timestamp);
329 last_timestamp = std::max(last_timestamp, timestamp);
330 }
331
332 switch (parsed_log_.GetEventType(i)) {
333 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
perkj09e71da2017-05-22 03:26:49 -0700334 rtclog::StreamConfig config;
terelius88e64e52016-07-19 01:51:06 -0700335 parsed_log_.GetVideoReceiveConfig(i, &config);
perkj09e71da2017-05-22 03:26:49 -0700336 StreamId stream(config.remote_ssrc, kIncomingPacket);
337 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
terelius0740a202016-08-08 10:21:04 -0700338 video_ssrcs_.insert(stream);
perkj09e71da2017-05-22 03:26:49 -0700339 StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket);
brandtr14742122017-01-27 04:53:07 -0800340 extension_maps[rtx_stream] =
perkj09e71da2017-05-22 03:26:49 -0700341 RtpHeaderExtensionMap(config.rtp_extensions);
brandtr14742122017-01-27 04:53:07 -0800342 video_ssrcs_.insert(rtx_stream);
343 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700344 break;
345 }
346 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
perkjc0876aa2017-05-22 04:08:28 -0700347 rtclog::StreamConfig config;
terelius88e64e52016-07-19 01:51:06 -0700348 parsed_log_.GetVideoSendConfig(i, &config);
perkjc0876aa2017-05-22 04:08:28 -0700349 StreamId stream(config.local_ssrc, kOutgoingPacket);
350 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
351 video_ssrcs_.insert(stream);
352 StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket);
353 extension_maps[rtx_stream] =
354 RtpHeaderExtensionMap(config.rtp_extensions);
355 video_ssrcs_.insert(rtx_stream);
356 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700357 break;
358 }
359 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
perkjac8f52d2017-05-22 09:36:28 -0700360 rtclog::StreamConfig config;
ivoce0928d82016-10-10 05:12:51 -0700361 parsed_log_.GetAudioReceiveConfig(i, &config);
perkjac8f52d2017-05-22 09:36:28 -0700362 StreamId stream(config.remote_ssrc, kIncomingPacket);
363 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp_extensions);
ivoce0928d82016-10-10 05:12:51 -0700364 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700365 break;
366 }
367 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
368 AudioSendStream::Config config(nullptr);
ivoce0928d82016-10-10 05:12:51 -0700369 parsed_log_.GetAudioSendConfig(i, &config);
370 StreamId stream(config.rtp.ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800371 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
ivoce0928d82016-10-10 05:12:51 -0700372 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700373 break;
374 }
375 case ParsedRtcEventLog::RTP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200376 MediaType media_type;
terelius88e64e52016-07-19 01:51:06 -0700377 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
378 &header_length, &total_length);
379 // Parse header to get SSRC.
380 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
381 RTPHeader parsed_header;
382 rtp_parser.Parse(&parsed_header);
Stefan Holmer13181032016-07-29 14:48:54 +0200383 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700384 // Look up the extension_map and parse it again to get the extensions.
385 if (extension_maps.count(stream) == 1) {
386 RtpHeaderExtensionMap* extension_map = &extension_maps[stream];
387 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700388 } else {
389 // Use the default extension map.
390 // TODO(ivoc): Once configuration of audio streams is stored in the
391 // event log, this can be removed.
392 // Tracking bug: webrtc:6399
393 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700394 }
395 uint64_t timestamp = parsed_log_.GetTimestamp(i);
396 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200397 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700398 break;
399 }
400 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200401 uint8_t packet[IP_PACKET_SIZE];
402 MediaType media_type;
403 parsed_log_.GetRtcpPacket(i, &direction, &media_type, packet,
404 &total_length);
perkjbbbad6d2017-05-19 06:30:28 -0700405 // Currently incoming RTCP packets are logged twice, both for audio and
406 // video. Only act on one of them. Compare against the previous parsed
407 // incoming RTCP packet.
408 if (direction == webrtc::kIncomingPacket) {
409 RTC_CHECK_LE(total_length, IP_PACKET_SIZE);
410 if (total_length == last_incoming_rtcp_packet_length &&
411 memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) {
412 continue;
413 } else {
414 memcpy(last_incoming_rtcp_packet, packet, total_length);
415 last_incoming_rtcp_packet_length = total_length;
416 }
417 }
418 rtcp::CommonHeader header;
419 const uint8_t* packet_end = packet + total_length;
420 for (const uint8_t* block = packet; block < packet_end;
421 block = header.NextPacket()) {
422 RTC_CHECK(header.Parse(block, packet_end - block));
423 if (header.type() == rtcp::TransportFeedback::kPacketType &&
424 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
425 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
426 new rtcp::TransportFeedback());
427 if (rtcp_packet->Parse(header)) {
428 uint32_t ssrc = rtcp_packet->sender_ssrc();
429 StreamId stream(ssrc, direction);
430 uint64_t timestamp = parsed_log_.GetTimestamp(i);
431 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
432 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
433 }
434 } else if (header.type() == rtcp::SenderReport::kPacketType) {
435 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
436 new rtcp::SenderReport());
437 if (rtcp_packet->Parse(header)) {
438 uint32_t ssrc = rtcp_packet->sender_ssrc();
439 StreamId stream(ssrc, direction);
440 uint64_t timestamp = parsed_log_.GetTimestamp(i);
441 rtcp_packets_[stream].push_back(
442 LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet)));
443 }
444 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
445 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
446 new rtcp::ReceiverReport());
447 if (rtcp_packet->Parse(header)) {
448 uint32_t ssrc = rtcp_packet->sender_ssrc();
449 StreamId stream(ssrc, direction);
450 uint64_t timestamp = parsed_log_.GetTimestamp(i);
451 rtcp_packets_[stream].push_back(
452 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet)));
Stefan Holmer13181032016-07-29 14:48:54 +0200453 }
Stefan Holmer13181032016-07-29 14:48:54 +0200454 }
Stefan Holmer13181032016-07-29 14:48:54 +0200455 }
terelius88e64e52016-07-19 01:51:06 -0700456 break;
457 }
458 case ParsedRtcEventLog::LOG_START: {
459 break;
460 }
461 case ParsedRtcEventLog::LOG_END: {
462 break;
463 }
terelius424e6cf2017-02-20 05:14:41 -0800464 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
465 break;
466 }
467 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
468 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700469 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800470 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
471 &bwe_update.fraction_loss,
472 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700473 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700474 break;
475 }
terelius424e6cf2017-02-20 05:14:41 -0800476 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
philipel10fc0e62017-04-11 01:50:23 -0700477 bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i));
terelius424e6cf2017-02-20 05:14:41 -0800478 break;
479 }
minyue4b7c9522017-01-24 04:54:59 -0800480 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800481 AudioNetworkAdaptationEvent ana_event;
482 ana_event.timestamp = parsed_log_.GetTimestamp(i);
483 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
484 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800485 break;
486 }
philipel32d00102017-02-27 02:18:46 -0800487 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200488 bwe_probe_cluster_created_events_.push_back(
489 parsed_log_.GetBweProbeClusterCreated(i));
philipel32d00102017-02-27 02:18:46 -0800490 break;
491 }
492 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200493 bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i));
philipel32d00102017-02-27 02:18:46 -0800494 break;
495 }
terelius88e64e52016-07-19 01:51:06 -0700496 case ParsedRtcEventLog::UNKNOWN_EVENT: {
497 break;
498 }
499 }
terelius54ce6802016-07-13 06:44:41 -0700500 }
terelius88e64e52016-07-19 01:51:06 -0700501
terelius54ce6802016-07-13 06:44:41 -0700502 if (last_timestamp < first_timestamp) {
503 // No useful events in the log.
504 first_timestamp = last_timestamp = 0;
505 }
506 begin_time_ = first_timestamp;
507 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700508 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700509}
510
Stefan Holmer13181032016-07-29 14:48:54 +0200511class BitrateObserver : public CongestionController::Observer,
512 public RemoteBitrateObserver {
513 public:
514 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
515
minyue78b4d562016-11-30 04:47:39 -0800516 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
517 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
518 using CongestionController::Observer::OnNetworkChanged;
519
Stefan Holmer13181032016-07-29 14:48:54 +0200520 void OnNetworkChanged(uint32_t bitrate_bps,
521 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800522 int64_t rtt_ms,
523 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200524 last_bitrate_bps_ = bitrate_bps;
525 bitrate_updated_ = true;
526 }
527
528 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
529 uint32_t bitrate) override {}
530
531 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
532 bool GetAndResetBitrateUpdated() {
533 bool bitrate_updated = bitrate_updated_;
534 bitrate_updated_ = false;
535 return bitrate_updated;
536 }
537
538 private:
539 uint32_t last_bitrate_bps_;
540 bool bitrate_updated_;
541};
542
Stefan Holmer99f8e082016-09-09 13:37:50 +0200543bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700544 return rtx_ssrcs_.count(stream_id) == 1;
545}
546
Stefan Holmer99f8e082016-09-09 13:37:50 +0200547bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700548 return video_ssrcs_.count(stream_id) == 1;
549}
550
Stefan Holmer99f8e082016-09-09 13:37:50 +0200551bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700552 return audio_ssrcs_.count(stream_id) == 1;
553}
554
Stefan Holmer99f8e082016-09-09 13:37:50 +0200555std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
556 std::stringstream name;
557 if (IsAudioSsrc(stream_id)) {
558 name << "Audio ";
559 } else if (IsVideoSsrc(stream_id)) {
560 name << "Video ";
561 } else {
562 name << "Unknown ";
563 }
564 if (IsRtxSsrc(stream_id))
565 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700566 if (stream_id.GetDirection() == kIncomingPacket) {
567 name << "(In) ";
568 } else {
569 name << "(Out) ";
570 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200571 name << SsrcToString(stream_id.GetSsrc());
572 return name.str();
573}
574
terelius54ce6802016-07-13 06:44:41 -0700575void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
576 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700577 for (auto& kv : rtp_packets_) {
578 StreamId stream_id = kv.first;
579 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
580 // Filter on direction and SSRC.
581 if (stream_id.GetDirection() != desired_direction ||
582 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
583 continue;
terelius54ce6802016-07-13 06:44:41 -0700584 }
terelius54ce6802016-07-13 06:44:41 -0700585
terelius23c595a2017-03-15 01:59:12 -0700586 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700587 ProcessPoints<LoggedRtpPacket>(
588 [](const LoggedRtpPacket& packet) -> rtc::Optional<float> {
589 return rtc::Optional<float>(packet.total_length);
590 },
591 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700592 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700593 }
594
tereliusdc35dcd2016-08-01 12:03:27 -0700595 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
596 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
597 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700598 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700599 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700600 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700601 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700602 }
603}
604
philipelccd74892016-09-05 02:46:25 -0700605template <typename T>
606void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
607 PacketDirection desired_direction,
608 Plot* plot,
609 const std::map<StreamId, std::vector<T>>& packets,
610 const std::string& label_prefix) {
611 for (auto& kv : packets) {
612 StreamId stream_id = kv.first;
613 const std::vector<T>& packet_stream = kv.second;
614 // Filter on direction and SSRC.
615 if (stream_id.GetDirection() != desired_direction ||
616 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
617 continue;
618 }
619
terelius23c595a2017-03-15 01:59:12 -0700620 std::string label = label_prefix + " " + GetStreamName(stream_id);
621 TimeSeries time_series(label, LINE_STEP_GRAPH);
philipelccd74892016-09-05 02:46:25 -0700622 for (size_t i = 0; i < packet_stream.size(); i++) {
623 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
624 1000000;
philipelccd74892016-09-05 02:46:25 -0700625 time_series.points.emplace_back(x, i + 1);
626 }
627
philipel35ba9bd2017-04-19 05:58:51 -0700628 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700629 }
630}
631
632void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
633 PacketDirection desired_direction,
634 Plot* plot) {
635 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
636 "RTP");
637 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
638 "RTCP");
639
640 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
641 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
642 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
643 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
644 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
645 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
646 }
647}
648
terelius54ce6802016-07-13 06:44:41 -0700649// For each SSRC, plot the time between the consecutive playouts.
650void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
651 std::map<uint32_t, TimeSeries> time_series;
652 std::map<uint32_t, uint64_t> last_playout;
653
654 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700655
656 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
657 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
658 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
659 parsed_log_.GetAudioPlayout(i, &ssrc);
660 uint64_t timestamp = parsed_log_.GetTimestamp(i);
661 if (MatchingSsrc(ssrc, desired_ssrc_)) {
662 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
663 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
664 if (time_series[ssrc].points.size() == 0) {
665 // There were no previusly logged playout for this SSRC.
666 // Generate a point, but place it on the x-axis.
667 y = 0;
668 }
terelius54ce6802016-07-13 06:44:41 -0700669 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
670 last_playout[ssrc] = timestamp;
671 }
672 }
673 }
674
675 // Set labels and put in graph.
676 for (auto& kv : time_series) {
677 kv.second.label = SsrcToString(kv.first);
678 kv.second.style = BAR_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700679 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700680 }
681
tereliusdc35dcd2016-08-01 12:03:27 -0700682 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
683 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
684 kTopMargin);
685 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700686}
687
ivocaac9d6f2016-09-22 07:01:47 -0700688// For audio SSRCs, plot the audio level.
689void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
690 std::map<StreamId, TimeSeries> time_series;
691
692 for (auto& kv : rtp_packets_) {
693 StreamId stream_id = kv.first;
694 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
695 // TODO(ivoc): When audio send/receive configs are stored in the event
696 // log, a check should be added here to only process audio
697 // streams. Tracking bug: webrtc:6399
698 for (auto& packet : packet_stream) {
699 if (packet.header.extension.hasAudioLevel) {
700 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
701 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
702 // Here we convert it to dBov.
703 float y = static_cast<float>(-packet.header.extension.audioLevel);
704 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
705 }
706 }
707 }
708
709 for (auto& series : time_series) {
710 series.second.label = GetStreamName(series.first);
711 series.second.style = LINE_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700712 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700713 }
714
715 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800716 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700717 kTopMargin);
718 plot->SetTitle("Audio level");
719}
720
terelius54ce6802016-07-13 06:44:41 -0700721// For each SSRC, plot the time between the consecutive playouts.
722void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700723 for (auto& kv : rtp_packets_) {
724 StreamId stream_id = kv.first;
725 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
726 // Filter on direction and SSRC.
727 if (stream_id.GetDirection() != kIncomingPacket ||
728 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
729 continue;
terelius54ce6802016-07-13 06:44:41 -0700730 }
terelius54ce6802016-07-13 06:44:41 -0700731
terelius23c595a2017-03-15 01:59:12 -0700732 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700733 ProcessPairs<LoggedRtpPacket, float>(
734 [](const LoggedRtpPacket& old_packet,
735 const LoggedRtpPacket& new_packet) {
736 int64_t diff =
737 WrappingDifference(new_packet.header.sequenceNumber,
738 old_packet.header.sequenceNumber, 1ul << 16);
739 return rtc::Optional<float>(diff);
740 },
741 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700742 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700743 }
744
tereliusdc35dcd2016-08-01 12:03:27 -0700745 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
746 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
747 kTopMargin);
748 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700749}
750
Stefan Holmer99f8e082016-09-09 13:37:50 +0200751void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
752 for (auto& kv : rtp_packets_) {
753 StreamId stream_id = kv.first;
754 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
755 // Filter on direction and SSRC.
756 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800757 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
758 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200759 continue;
760 }
761
terelius23c595a2017-03-15 01:59:12 -0700762 TimeSeries time_series(GetStreamName(stream_id), LINE_DOT_GRAPH);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200763 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800764 const uint64_t kStep = 1000000;
765 SequenceNumberUnwrapper unwrapper_;
766 SequenceNumberUnwrapper prior_unwrapper_;
767 size_t window_index_begin = 0;
768 size_t window_index_end = 0;
769 int64_t highest_seq_number =
770 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
771 int64_t highest_prior_seq_number =
772 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
773
774 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
775 while (window_index_end < packet_stream.size() &&
776 packet_stream[window_index_end].timestamp < t) {
777 int64_t sequence_number = unwrapper_.Unwrap(
778 packet_stream[window_index_end].header.sequenceNumber);
779 highest_seq_number = std::max(highest_seq_number, sequence_number);
780 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200781 }
terelius4c9b4af2017-01-30 08:44:51 -0800782 while (window_index_begin < packet_stream.size() &&
783 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
784 int64_t sequence_number = prior_unwrapper_.Unwrap(
785 packet_stream[window_index_begin].header.sequenceNumber);
786 highest_prior_seq_number =
787 std::max(highest_prior_seq_number, sequence_number);
788 ++window_index_begin;
789 }
790 float x = static_cast<float>(t - begin_time_) / 1000000;
791 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
792 if (expected_packets > 0) {
793 int64_t received_packets = window_index_end - window_index_begin;
794 int64_t lost_packets = expected_packets - received_packets;
795 float y = static_cast<float>(lost_packets) / expected_packets * 100;
796 time_series.points.emplace_back(x, y);
797 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200798 }
philipel35ba9bd2017-04-19 05:58:51 -0700799 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200800 }
801
802 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
803 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
804 kTopMargin);
805 plot->SetTitle("Estimated incoming loss rate");
806}
807
terelius54ce6802016-07-13 06:44:41 -0700808void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700809 for (auto& kv : rtp_packets_) {
810 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700811 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700812 // Filter on direction and SSRC.
813 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200814 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
815 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
816 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700817 continue;
818 }
terelius54ce6802016-07-13 06:44:41 -0700819
terelius23c595a2017-03-15 01:59:12 -0700820 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
821 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700822 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
823 packet_stream, begin_time_,
824 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700825 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700826
terelius23c595a2017-03-15 01:59:12 -0700827 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
828 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700829 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
830 packet_stream, begin_time_,
831 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700832 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700833 }
834
tereliusdc35dcd2016-08-01 12:03:27 -0700835 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
836 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
837 kTopMargin);
838 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700839}
840
841void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700842 for (auto& kv : rtp_packets_) {
843 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700844 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700845 // Filter on direction and SSRC.
846 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200847 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
848 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
849 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700850 continue;
851 }
terelius54ce6802016-07-13 06:44:41 -0700852
terelius23c595a2017-03-15 01:59:12 -0700853 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
854 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700855 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
856 packet_stream, begin_time_,
857 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700858 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700859
terelius23c595a2017-03-15 01:59:12 -0700860 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
861 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700862 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
863 packet_stream, begin_time_,
864 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700865 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700866 }
867
tereliusdc35dcd2016-08-01 12:03:27 -0700868 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
869 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
870 kTopMargin);
871 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700872}
873
tereliusf736d232016-08-04 10:00:11 -0700874// Plot the fraction of packets lost (as perceived by the loss-based BWE).
875void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -0700876 TimeSeries time_series("Fraction lost", LINE_DOT_GRAPH);
tereliusf736d232016-08-04 10:00:11 -0700877 for (auto& bwe_update : bwe_loss_updates_) {
878 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
879 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700880 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700881 }
tereliusf736d232016-08-04 10:00:11 -0700882
883 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
884 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
885 kTopMargin);
886 plot->SetTitle("Reported packet loss");
philipel35ba9bd2017-04-19 05:58:51 -0700887 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700888}
889
terelius54ce6802016-07-13 06:44:41 -0700890// Plot the total bandwidth used by all RTP streams.
891void EventLogAnalyzer::CreateTotalBitrateGraph(
892 PacketDirection desired_direction,
893 Plot* plot) {
894 struct TimestampSize {
895 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
896 uint64_t timestamp;
897 size_t size;
898 };
899 std::vector<TimestampSize> packets;
900
901 PacketDirection direction;
902 size_t total_length;
903
904 // Extract timestamps and sizes for the relevant packets.
905 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
906 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
907 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
908 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, nullptr,
909 &total_length);
910 if (direction == desired_direction) {
911 uint64_t timestamp = parsed_log_.GetTimestamp(i);
912 packets.push_back(TimestampSize(timestamp, total_length));
913 }
914 }
915 }
916
917 size_t window_index_begin = 0;
918 size_t window_index_end = 0;
919 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700920
921 // Calculate a moving average of the bitrate and store in a TimeSeries.
philipel35ba9bd2017-04-19 05:58:51 -0700922 TimeSeries bitrate_series("Bitrate", LINE_GRAPH);
terelius54ce6802016-07-13 06:44:41 -0700923 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
924 while (window_index_end < packets.size() &&
925 packets[window_index_end].timestamp < time) {
926 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700927 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700928 }
929 while (window_index_begin < packets.size() &&
930 packets[window_index_begin].timestamp < time - window_duration_) {
931 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
932 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700933 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700934 }
935 float window_duration_in_seconds =
936 static_cast<float>(window_duration_) / 1000000;
937 float x = static_cast<float>(time - begin_time_) / 1000000;
938 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700939 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700940 }
philipel35ba9bd2017-04-19 05:58:51 -0700941 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700942
terelius8058e582016-07-25 01:32:41 -0700943 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
944 if (desired_direction == kOutgoingPacket) {
philipel35ba9bd2017-04-19 05:58:51 -0700945 TimeSeries loss_series("Loss-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700946 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -0700947 float x =
philipel10fc0e62017-04-11 01:50:23 -0700948 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
949 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700950 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -0700951 }
952
philipel35ba9bd2017-04-19 05:58:51 -0700953 TimeSeries delay_series("Delay-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700954 for (auto& delay_update : bwe_delay_updates_) {
955 float x =
956 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
957 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700958 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700959 }
philipele127e7a2017-03-29 16:28:53 +0200960
philipel35ba9bd2017-04-19 05:58:51 -0700961 TimeSeries created_series("Probe cluster created.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +0200962 for (auto& cluster : bwe_probe_cluster_created_events_) {
963 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
964 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700965 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +0200966 }
967
philipel35ba9bd2017-04-19 05:58:51 -0700968 TimeSeries result_series("Probing results.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +0200969 for (auto& result : bwe_probe_result_events_) {
970 if (result.bitrate_bps) {
971 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
972 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700973 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +0200974 }
975 }
philipel35ba9bd2017-04-19 05:58:51 -0700976 plot->AppendTimeSeries(std::move(loss_series));
977 plot->AppendTimeSeries(std::move(delay_series));
978 plot->AppendTimeSeries(std::move(created_series));
979 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -0700980 }
philipele127e7a2017-03-29 16:28:53 +0200981
tereliusdc35dcd2016-08-01 12:03:27 -0700982 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
983 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700984 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700985 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700986 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700987 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700988 }
989}
990
991// For each SSRC, plot the bandwidth used by that stream.
992void EventLogAnalyzer::CreateStreamBitrateGraph(
993 PacketDirection desired_direction,
994 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700995 for (auto& kv : rtp_packets_) {
996 StreamId stream_id = kv.first;
997 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
998 // Filter on direction and SSRC.
999 if (stream_id.GetDirection() != desired_direction ||
1000 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1001 continue;
terelius54ce6802016-07-13 06:44:41 -07001002 }
1003
terelius23c595a2017-03-15 01:59:12 -07001004 TimeSeries time_series(GetStreamName(stream_id), LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001005 MovingAverage<LoggedRtpPacket, double>(
1006 [](const LoggedRtpPacket& packet) {
1007 return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0);
1008 },
1009 packet_stream, begin_time_, end_time_, window_duration_, step_,
1010 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001011 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001012 }
1013
tereliusdc35dcd2016-08-01 12:03:27 -07001014 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1015 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001016 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001017 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001018 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001019 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001020 }
1021}
1022
tereliuse34c19c2016-08-15 08:47:14 -07001023void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001024 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1025 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001026
1027 for (const auto& kv : rtp_packets_) {
1028 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1029 for (const LoggedRtpPacket& rtp_packet : kv.second)
1030 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1031 }
1032 }
1033
1034 for (const auto& kv : rtcp_packets_) {
1035 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1036 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1037 incoming_rtcp.insert(
1038 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1039 }
1040 }
1041
1042 SimulatedClock clock(0);
1043 BitrateObserver observer;
1044 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001045 PacketRouter packet_router;
1046 CongestionController cc(&clock, &observer, &observer, &null_event_log,
1047 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +02001048 // TODO(holmer): Log the call config and use that here instead.
1049 static const uint32_t kDefaultStartBitrateBps = 300000;
1050 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1051
terelius23c595a2017-03-15 01:59:12 -07001052 TimeSeries time_series("Delay-based estimate", LINE_DOT_GRAPH);
1053 TimeSeries acked_time_series("Acked bitrate", LINE_DOT_GRAPH);
Stefan Holmer13181032016-07-29 14:48:54 +02001054
1055 auto rtp_iterator = outgoing_rtp.begin();
1056 auto rtcp_iterator = incoming_rtcp.begin();
1057
1058 auto NextRtpTime = [&]() {
1059 if (rtp_iterator != outgoing_rtp.end())
1060 return static_cast<int64_t>(rtp_iterator->first);
1061 return std::numeric_limits<int64_t>::max();
1062 };
1063
1064 auto NextRtcpTime = [&]() {
1065 if (rtcp_iterator != incoming_rtcp.end())
1066 return static_cast<int64_t>(rtcp_iterator->first);
1067 return std::numeric_limits<int64_t>::max();
1068 };
1069
1070 auto NextProcessTime = [&]() {
1071 if (rtcp_iterator != incoming_rtcp.end() ||
1072 rtp_iterator != outgoing_rtp.end()) {
1073 return clock.TimeInMicroseconds() +
1074 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1075 }
1076 return std::numeric_limits<int64_t>::max();
1077 };
1078
Stefan Holmer492ee282016-10-27 17:19:20 +02001079 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001080
Stefan Holmer13181032016-07-29 14:48:54 +02001081 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001082 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001083 while (time_us != std::numeric_limits<int64_t>::max()) {
1084 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1085 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001086 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001087 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1088 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001089 cc.OnTransportFeedback(
1090 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1091 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001092 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001093 rtc::Optional<uint32_t> bitrate_bps;
1094 if (!feedback.empty()) {
elad.alonf9490002017-03-06 05:32:21 -08001095 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001096 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1097 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1098 }
1099 uint32_t y = 0;
1100 if (bitrate_bps)
1101 y = *bitrate_bps / 1000;
1102 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1103 1000000;
1104 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +02001105 }
1106 ++rtcp_iterator;
1107 }
1108 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001109 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001110 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1111 if (rtp.header.extension.hasTransportSequenceNumber) {
1112 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001113 cc.AddPacket(rtp.header.ssrc,
1114 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001115 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001116 rtc::SentPacket sent_packet(
1117 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1118 cc.OnSentPacket(sent_packet);
1119 }
1120 ++rtp_iterator;
1121 }
stefanc3de0332016-08-02 07:22:17 -07001122 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1123 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001124 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001125 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001126 if (observer.GetAndResetBitrateUpdated() ||
1127 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001128 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001129 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1130 1000000;
1131 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001132 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001133 }
1134 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1135 }
1136 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001137 plot->AppendTimeSeries(std::move(time_series));
1138 plot->AppendTimeSeries(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001139
tereliusdc35dcd2016-08-01 12:03:27 -07001140 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1141 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1142 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001143}
1144
tereliuse34c19c2016-08-15 08:47:14 -07001145void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001146 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1147 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001148
1149 for (const auto& kv : rtp_packets_) {
1150 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1151 for (const LoggedRtpPacket& rtp_packet : kv.second)
1152 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1153 }
1154 }
1155
1156 for (const auto& kv : rtcp_packets_) {
1157 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1158 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1159 incoming_rtcp.insert(
1160 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1161 }
1162 }
1163
1164 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001165 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001166
terelius23c595a2017-03-15 01:59:12 -07001167 TimeSeries time_series("Network Delay Change", LINE_DOT_GRAPH);
stefanc3de0332016-08-02 07:22:17 -07001168 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1169
1170 auto rtp_iterator = outgoing_rtp.begin();
1171 auto rtcp_iterator = incoming_rtcp.begin();
1172
1173 auto NextRtpTime = [&]() {
1174 if (rtp_iterator != outgoing_rtp.end())
1175 return static_cast<int64_t>(rtp_iterator->first);
1176 return std::numeric_limits<int64_t>::max();
1177 };
1178
1179 auto NextRtcpTime = [&]() {
1180 if (rtcp_iterator != incoming_rtcp.end())
1181 return static_cast<int64_t>(rtcp_iterator->first);
1182 return std::numeric_limits<int64_t>::max();
1183 };
1184
1185 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1186 while (time_us != std::numeric_limits<int64_t>::max()) {
1187 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1188 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1189 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1190 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1191 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001192 feedback_adapter.OnTransportFeedback(
1193 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001194 std::vector<PacketFeedback> feedback =
1195 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001196 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001197 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001198 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1199 float x =
1200 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1201 1000000;
1202 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1203 time_series.points.emplace_back(x, y);
1204 }
1205 }
1206 ++rtcp_iterator;
1207 }
1208 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1209 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1210 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1211 if (rtp.header.extension.hasTransportSequenceNumber) {
1212 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001213 feedback_adapter.AddPacket(rtp.header.ssrc,
1214 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001215 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001216 feedback_adapter.OnSentPacket(
1217 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1218 }
1219 ++rtp_iterator;
1220 }
1221 time_us = std::min(NextRtpTime(), NextRtcpTime());
1222 }
1223 // We assume that the base network delay (w/o queues) is the min delay
1224 // observed during the call.
1225 for (TimeSeriesPoint& point : time_series.points)
1226 point.y -= estimated_base_delay_ms;
1227 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001228 plot->AppendTimeSeries(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001229
1230 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1231 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1232 plot->SetTitle("Network Delay Change.");
1233}
stefan08383272016-12-20 08:51:52 -08001234
1235std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1236 const {
1237 std::vector<std::pair<int64_t, int64_t>> timestamps;
1238 size_t largest_stream_size = 0;
1239 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1240 // Find the incoming video stream with the most number of packets that is
1241 // not rtx.
1242 for (const auto& kv : rtp_packets_) {
1243 if (kv.first.GetDirection() == kIncomingPacket &&
1244 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1245 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1246 kv.second.size() > largest_stream_size) {
1247 largest_stream_size = kv.second.size();
1248 largest_video_stream = &kv.second;
1249 }
1250 }
1251 if (largest_video_stream == nullptr) {
1252 for (auto& packet : *largest_video_stream) {
1253 if (packet.header.markerBit) {
1254 int64_t capture_ms = packet.header.timestamp / 90.0;
1255 int64_t arrival_ms = packet.timestamp / 1000.0;
1256 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1257 }
1258 }
1259 }
1260 return timestamps;
1261}
stefane372d3c2017-02-02 08:04:18 -08001262
1263void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1264 for (const auto& kv : rtp_packets_) {
1265 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1266 StreamId stream_id = kv.first;
1267
1268 {
terelius23c595a2017-03-15 01:59:12 -07001269 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
1270 LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001271 for (LoggedRtpPacket packet : rtp_packets) {
1272 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1273 float y = packet.header.timestamp;
1274 timestamp_data.points.emplace_back(x, y);
1275 }
philipel35ba9bd2017-04-19 05:58:51 -07001276 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001277 }
1278
1279 {
1280 auto kv = rtcp_packets_.find(stream_id);
1281 if (kv != rtcp_packets_.end()) {
1282 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001283 TimeSeries timestamp_data(
1284 GetStreamName(stream_id) + " rtcp capture-time", LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001285 for (const LoggedRtcpPacket& rtcp : packets) {
1286 if (rtcp.type != kRtcpSr)
1287 continue;
1288 rtcp::SenderReport* sr;
1289 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1290 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1291 float y = sr->rtp_timestamp();
1292 timestamp_data.points.emplace_back(x, y);
1293 }
philipel35ba9bd2017-04-19 05:58:51 -07001294 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001295 }
1296 }
1297 }
1298
1299 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1300 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1301 plot->SetTitle("Timestamps");
1302}
michaelt6e5b2192017-02-22 07:33:27 -08001303
1304void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001305 TimeSeries time_series("Audio encoder target bitrate", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001306 ProcessPoints<AudioNetworkAdaptationEvent>(
1307 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001308 if (ana_event.config.bitrate_bps)
1309 return rtc::Optional<float>(
1310 static_cast<float>(*ana_event.config.bitrate_bps));
1311 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001312 },
philipel35ba9bd2017-04-19 05:58:51 -07001313 audio_network_adaptation_events_, begin_time_, &time_series);
1314 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001315 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1316 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1317 plot->SetTitle("Reported audio encoder target bitrate");
1318}
1319
1320void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001321 TimeSeries time_series("Audio encoder frame length", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001322 ProcessPoints<AudioNetworkAdaptationEvent>(
1323 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001324 if (ana_event.config.frame_length_ms)
1325 return rtc::Optional<float>(
1326 static_cast<float>(*ana_event.config.frame_length_ms));
1327 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001328 },
philipel35ba9bd2017-04-19 05:58:51 -07001329 audio_network_adaptation_events_, begin_time_, &time_series);
1330 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001331 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1332 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1333 plot->SetTitle("Reported audio encoder frame length");
1334}
1335
1336void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph(
1337 Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001338 TimeSeries time_series("Audio encoder uplink packet loss fraction",
1339 LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001340 ProcessPoints<AudioNetworkAdaptationEvent>(
1341 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001342 if (ana_event.config.uplink_packet_loss_fraction)
1343 return rtc::Optional<float>(static_cast<float>(
1344 *ana_event.config.uplink_packet_loss_fraction));
1345 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001346 },
philipel35ba9bd2017-04-19 05:58:51 -07001347 audio_network_adaptation_events_, begin_time_, &time_series);
1348 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001349 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1350 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1351 kTopMargin);
1352 plot->SetTitle("Reported audio encoder lost packets");
1353}
1354
1355void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001356 TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001357 ProcessPoints<AudioNetworkAdaptationEvent>(
1358 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001359 if (ana_event.config.enable_fec)
1360 return rtc::Optional<float>(
1361 static_cast<float>(*ana_event.config.enable_fec));
1362 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001363 },
philipel35ba9bd2017-04-19 05:58:51 -07001364 audio_network_adaptation_events_, begin_time_, &time_series);
1365 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001366 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1367 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1368 plot->SetTitle("Reported audio encoder FEC");
1369}
1370
1371void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001372 TimeSeries time_series("Audio encoder DTX", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001373 ProcessPoints<AudioNetworkAdaptationEvent>(
1374 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001375 if (ana_event.config.enable_dtx)
1376 return rtc::Optional<float>(
1377 static_cast<float>(*ana_event.config.enable_dtx));
1378 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001379 },
philipel35ba9bd2017-04-19 05:58:51 -07001380 audio_network_adaptation_events_, begin_time_, &time_series);
1381 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001382 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1383 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1384 plot->SetTitle("Reported audio encoder DTX");
1385}
1386
1387void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001388 TimeSeries time_series("Audio encoder number of channels", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001389 ProcessPoints<AudioNetworkAdaptationEvent>(
1390 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001391 if (ana_event.config.num_channels)
1392 return rtc::Optional<float>(
1393 static_cast<float>(*ana_event.config.num_channels));
1394 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001395 },
philipel35ba9bd2017-04-19 05:58:51 -07001396 audio_network_adaptation_events_, begin_time_, &time_series);
1397 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001398 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1399 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1400 kBottomMargin, kTopMargin);
1401 plot->SetTitle("Reported audio encoder number of channels");
1402}
terelius54ce6802016-07-13 06:44:41 -07001403} // namespace plotting
1404} // namespace webrtc