blob: d44d7a6f8774d249484f1ea7529c1bfcae38a414 [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
ivocaac9d6f2016-09-22 07:01:47 -0700311 // Make a default extension map for streams without configuration information.
312 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
313 // this can be removed. Tracking bug: webrtc:6399
314 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
315
terelius54ce6802016-07-13 06:44:41 -0700316 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
317 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700318 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
319 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
320 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700321 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
322 event_type != ParsedRtcEventLog::LOG_START &&
323 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700324 uint64_t timestamp = parsed_log_.GetTimestamp(i);
325 first_timestamp = std::min(first_timestamp, timestamp);
326 last_timestamp = std::max(last_timestamp, timestamp);
327 }
328
329 switch (parsed_log_.GetEventType(i)) {
330 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
331 VideoReceiveStream::Config config(nullptr);
332 parsed_log_.GetVideoReceiveConfig(i, &config);
Stefan Holmer13181032016-07-29 14:48:54 +0200333 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800334 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700335 video_ssrcs_.insert(stream);
brandtr14742122017-01-27 04:53:07 -0800336 StreamId rtx_stream(config.rtp.rtx_ssrc, kIncomingPacket);
337 extension_maps[rtx_stream] =
338 RtpHeaderExtensionMap(config.rtp.extensions);
339 video_ssrcs_.insert(rtx_stream);
340 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700341 break;
342 }
343 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
344 VideoSendStream::Config config(nullptr);
345 parsed_log_.GetVideoSendConfig(i, &config);
346 for (auto ssrc : config.rtp.ssrcs) {
Stefan Holmer13181032016-07-29 14:48:54 +0200347 StreamId stream(ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800348 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700349 video_ssrcs_.insert(stream);
stefan6a850c32016-07-29 10:28:08 -0700350 }
351 for (auto ssrc : config.rtp.rtx.ssrcs) {
terelius0740a202016-08-08 10:21:04 -0700352 StreamId rtx_stream(ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800353 extension_maps[rtx_stream] =
354 RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700355 video_ssrcs_.insert(rtx_stream);
356 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700357 }
358 break;
359 }
360 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
361 AudioReceiveStream::Config config;
ivoce0928d82016-10-10 05:12:51 -0700362 parsed_log_.GetAudioReceiveConfig(i, &config);
363 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800364 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
ivoce0928d82016-10-10 05:12:51 -0700365 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700366 break;
367 }
368 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
369 AudioSendStream::Config config(nullptr);
ivoce0928d82016-10-10 05:12:51 -0700370 parsed_log_.GetAudioSendConfig(i, &config);
371 StreamId stream(config.rtp.ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800372 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
ivoce0928d82016-10-10 05:12:51 -0700373 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700374 break;
375 }
376 case ParsedRtcEventLog::RTP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200377 MediaType media_type;
terelius88e64e52016-07-19 01:51:06 -0700378 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
379 &header_length, &total_length);
380 // Parse header to get SSRC.
381 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
382 RTPHeader parsed_header;
383 rtp_parser.Parse(&parsed_header);
Stefan Holmer13181032016-07-29 14:48:54 +0200384 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700385 // Look up the extension_map and parse it again to get the extensions.
386 if (extension_maps.count(stream) == 1) {
387 RtpHeaderExtensionMap* extension_map = &extension_maps[stream];
388 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700389 } else {
390 // Use the default extension map.
391 // TODO(ivoc): Once configuration of audio streams is stored in the
392 // event log, this can be removed.
393 // Tracking bug: webrtc:6399
394 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700395 }
396 uint64_t timestamp = parsed_log_.GetTimestamp(i);
397 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200398 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700399 break;
400 }
401 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200402 uint8_t packet[IP_PACKET_SIZE];
403 MediaType media_type;
404 parsed_log_.GetRtcpPacket(i, &direction, &media_type, packet,
405 &total_length);
406
danilchapbf369fe2016-10-07 07:39:54 -0700407 // Currently feedback is logged twice, both for audio and video.
408 // Only act on one of them.
stefane372d3c2017-02-02 08:04:18 -0800409 if (media_type == MediaType::AUDIO || media_type == MediaType::ANY) {
danilchapbf369fe2016-10-07 07:39:54 -0700410 rtcp::CommonHeader header;
411 const uint8_t* packet_end = packet + total_length;
412 for (const uint8_t* block = packet; block < packet_end;
413 block = header.NextPacket()) {
414 RTC_CHECK(header.Parse(block, packet_end - block));
415 if (header.type() == rtcp::TransportFeedback::kPacketType &&
416 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
417 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
418 new rtcp::TransportFeedback());
419 if (rtcp_packet->Parse(header)) {
420 uint32_t ssrc = rtcp_packet->sender_ssrc();
Stefan Holmer13181032016-07-29 14:48:54 +0200421 StreamId stream(ssrc, direction);
422 uint64_t timestamp = parsed_log_.GetTimestamp(i);
423 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
424 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
425 }
stefane372d3c2017-02-02 08:04:18 -0800426 } else if (header.type() == rtcp::SenderReport::kPacketType) {
427 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
428 new rtcp::SenderReport());
429 if (rtcp_packet->Parse(header)) {
430 uint32_t ssrc = rtcp_packet->sender_ssrc();
431 StreamId stream(ssrc, direction);
432 uint64_t timestamp = parsed_log_.GetTimestamp(i);
433 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
434 timestamp, kRtcpSr, std::move(rtcp_packet)));
435 }
436 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
437 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
438 new rtcp::ReceiverReport());
439 if (rtcp_packet->Parse(header)) {
440 uint32_t ssrc = rtcp_packet->sender_ssrc();
441 StreamId stream(ssrc, direction);
442 uint64_t timestamp = parsed_log_.GetTimestamp(i);
443 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
444 timestamp, kRtcpRr, std::move(rtcp_packet)));
445 }
Stefan Holmer13181032016-07-29 14:48:54 +0200446 }
Stefan Holmer13181032016-07-29 14:48:54 +0200447 }
Stefan Holmer13181032016-07-29 14:48:54 +0200448 }
terelius88e64e52016-07-19 01:51:06 -0700449 break;
450 }
451 case ParsedRtcEventLog::LOG_START: {
452 break;
453 }
454 case ParsedRtcEventLog::LOG_END: {
455 break;
456 }
terelius424e6cf2017-02-20 05:14:41 -0800457 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
458 break;
459 }
460 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
461 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700462 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800463 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
464 &bwe_update.fraction_loss,
465 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700466 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700467 break;
468 }
terelius424e6cf2017-02-20 05:14:41 -0800469 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
470 break;
471 }
minyue4b7c9522017-01-24 04:54:59 -0800472 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800473 AudioNetworkAdaptationEvent ana_event;
474 ana_event.timestamp = parsed_log_.GetTimestamp(i);
475 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
476 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800477 break;
478 }
philipel32d00102017-02-27 02:18:46 -0800479 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
480 break;
481 }
482 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
483 break;
484 }
terelius88e64e52016-07-19 01:51:06 -0700485 case ParsedRtcEventLog::UNKNOWN_EVENT: {
486 break;
487 }
488 }
terelius54ce6802016-07-13 06:44:41 -0700489 }
terelius88e64e52016-07-19 01:51:06 -0700490
terelius54ce6802016-07-13 06:44:41 -0700491 if (last_timestamp < first_timestamp) {
492 // No useful events in the log.
493 first_timestamp = last_timestamp = 0;
494 }
495 begin_time_ = first_timestamp;
496 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700497 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700498}
499
Stefan Holmer13181032016-07-29 14:48:54 +0200500class BitrateObserver : public CongestionController::Observer,
501 public RemoteBitrateObserver {
502 public:
503 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
504
minyue78b4d562016-11-30 04:47:39 -0800505 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
506 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
507 using CongestionController::Observer::OnNetworkChanged;
508
Stefan Holmer13181032016-07-29 14:48:54 +0200509 void OnNetworkChanged(uint32_t bitrate_bps,
510 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800511 int64_t rtt_ms,
512 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200513 last_bitrate_bps_ = bitrate_bps;
514 bitrate_updated_ = true;
515 }
516
517 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
518 uint32_t bitrate) override {}
519
520 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
521 bool GetAndResetBitrateUpdated() {
522 bool bitrate_updated = bitrate_updated_;
523 bitrate_updated_ = false;
524 return bitrate_updated;
525 }
526
527 private:
528 uint32_t last_bitrate_bps_;
529 bool bitrate_updated_;
530};
531
Stefan Holmer99f8e082016-09-09 13:37:50 +0200532bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700533 return rtx_ssrcs_.count(stream_id) == 1;
534}
535
Stefan Holmer99f8e082016-09-09 13:37:50 +0200536bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700537 return video_ssrcs_.count(stream_id) == 1;
538}
539
Stefan Holmer99f8e082016-09-09 13:37:50 +0200540bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700541 return audio_ssrcs_.count(stream_id) == 1;
542}
543
Stefan Holmer99f8e082016-09-09 13:37:50 +0200544std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
545 std::stringstream name;
546 if (IsAudioSsrc(stream_id)) {
547 name << "Audio ";
548 } else if (IsVideoSsrc(stream_id)) {
549 name << "Video ";
550 } else {
551 name << "Unknown ";
552 }
553 if (IsRtxSsrc(stream_id))
554 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700555 if (stream_id.GetDirection() == kIncomingPacket) {
556 name << "(In) ";
557 } else {
558 name << "(Out) ";
559 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200560 name << SsrcToString(stream_id.GetSsrc());
561 return name.str();
562}
563
terelius54ce6802016-07-13 06:44:41 -0700564void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
565 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700566 for (auto& kv : rtp_packets_) {
567 StreamId stream_id = kv.first;
568 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
569 // Filter on direction and SSRC.
570 if (stream_id.GetDirection() != desired_direction ||
571 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
572 continue;
terelius54ce6802016-07-13 06:44:41 -0700573 }
terelius54ce6802016-07-13 06:44:41 -0700574
terelius6addf492016-08-23 17:34:07 -0700575 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200576 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700577 time_series.style = BAR_GRAPH;
terelius53dc23c2017-03-13 05:24:05 -0700578 ProcessPoints<LoggedRtpPacket>(
579 [](const LoggedRtpPacket& packet) -> rtc::Optional<float> {
580 return rtc::Optional<float>(packet.total_length);
581 },
582 packet_stream, begin_time_, &time_series);
terelius6addf492016-08-23 17:34:07 -0700583 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700584 }
585
tereliusdc35dcd2016-08-01 12:03:27 -0700586 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
587 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
588 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700589 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700590 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700591 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700592 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700593 }
594}
595
philipelccd74892016-09-05 02:46:25 -0700596template <typename T>
597void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
598 PacketDirection desired_direction,
599 Plot* plot,
600 const std::map<StreamId, std::vector<T>>& packets,
601 const std::string& label_prefix) {
602 for (auto& kv : packets) {
603 StreamId stream_id = kv.first;
604 const std::vector<T>& packet_stream = kv.second;
605 // Filter on direction and SSRC.
606 if (stream_id.GetDirection() != desired_direction ||
607 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
608 continue;
609 }
610
611 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200612 time_series.label = label_prefix + " " + GetStreamName(stream_id);
terelius77f05802017-02-01 06:34:53 -0800613 time_series.style = LINE_STEP_GRAPH;
philipelccd74892016-09-05 02:46:25 -0700614
615 for (size_t i = 0; i < packet_stream.size(); i++) {
616 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
617 1000000;
philipelccd74892016-09-05 02:46:25 -0700618 time_series.points.emplace_back(x, i + 1);
619 }
620
621 plot->series_list_.push_back(std::move(time_series));
622 }
623}
624
625void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
626 PacketDirection desired_direction,
627 Plot* plot) {
628 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
629 "RTP");
630 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
631 "RTCP");
632
633 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
634 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
635 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
636 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
637 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
638 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
639 }
640}
641
terelius54ce6802016-07-13 06:44:41 -0700642// For each SSRC, plot the time between the consecutive playouts.
643void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
644 std::map<uint32_t, TimeSeries> time_series;
645 std::map<uint32_t, uint64_t> last_playout;
646
647 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700648
649 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
650 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
651 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
652 parsed_log_.GetAudioPlayout(i, &ssrc);
653 uint64_t timestamp = parsed_log_.GetTimestamp(i);
654 if (MatchingSsrc(ssrc, desired_ssrc_)) {
655 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
656 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
657 if (time_series[ssrc].points.size() == 0) {
658 // There were no previusly logged playout for this SSRC.
659 // Generate a point, but place it on the x-axis.
660 y = 0;
661 }
terelius54ce6802016-07-13 06:44:41 -0700662 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
663 last_playout[ssrc] = timestamp;
664 }
665 }
666 }
667
668 // Set labels and put in graph.
669 for (auto& kv : time_series) {
670 kv.second.label = SsrcToString(kv.first);
671 kv.second.style = BAR_GRAPH;
tereliusdc35dcd2016-08-01 12:03:27 -0700672 plot->series_list_.push_back(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700673 }
674
tereliusdc35dcd2016-08-01 12:03:27 -0700675 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
676 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
677 kTopMargin);
678 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700679}
680
ivocaac9d6f2016-09-22 07:01:47 -0700681// For audio SSRCs, plot the audio level.
682void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
683 std::map<StreamId, TimeSeries> time_series;
684
685 for (auto& kv : rtp_packets_) {
686 StreamId stream_id = kv.first;
687 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
688 // TODO(ivoc): When audio send/receive configs are stored in the event
689 // log, a check should be added here to only process audio
690 // streams. Tracking bug: webrtc:6399
691 for (auto& packet : packet_stream) {
692 if (packet.header.extension.hasAudioLevel) {
693 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
694 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
695 // Here we convert it to dBov.
696 float y = static_cast<float>(-packet.header.extension.audioLevel);
697 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
698 }
699 }
700 }
701
702 for (auto& series : time_series) {
703 series.second.label = GetStreamName(series.first);
704 series.second.style = LINE_GRAPH;
705 plot->series_list_.push_back(std::move(series.second));
706 }
707
708 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800709 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700710 kTopMargin);
711 plot->SetTitle("Audio level");
712}
713
terelius54ce6802016-07-13 06:44:41 -0700714// For each SSRC, plot the time between the consecutive playouts.
715void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700716 for (auto& kv : rtp_packets_) {
717 StreamId stream_id = kv.first;
718 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
719 // Filter on direction and SSRC.
720 if (stream_id.GetDirection() != kIncomingPacket ||
721 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
722 continue;
terelius54ce6802016-07-13 06:44:41 -0700723 }
terelius54ce6802016-07-13 06:44:41 -0700724
terelius6addf492016-08-23 17:34:07 -0700725 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200726 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700727 time_series.style = BAR_GRAPH;
terelius53dc23c2017-03-13 05:24:05 -0700728 ProcessPairs<LoggedRtpPacket, float>(
729 [](const LoggedRtpPacket& old_packet,
730 const LoggedRtpPacket& new_packet) {
731 int64_t diff =
732 WrappingDifference(new_packet.header.sequenceNumber,
733 old_packet.header.sequenceNumber, 1ul << 16);
734 return rtc::Optional<float>(diff);
735 },
736 packet_stream, begin_time_, &time_series);
terelius6addf492016-08-23 17:34:07 -0700737 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700738 }
739
tereliusdc35dcd2016-08-01 12:03:27 -0700740 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
741 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
742 kTopMargin);
743 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700744}
745
Stefan Holmer99f8e082016-09-09 13:37:50 +0200746void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
747 for (auto& kv : rtp_packets_) {
748 StreamId stream_id = kv.first;
749 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
750 // Filter on direction and SSRC.
751 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800752 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
753 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200754 continue;
755 }
756
757 TimeSeries time_series;
758 time_series.label = GetStreamName(stream_id);
759 time_series.style = LINE_DOT_GRAPH;
760 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800761 const uint64_t kStep = 1000000;
762 SequenceNumberUnwrapper unwrapper_;
763 SequenceNumberUnwrapper prior_unwrapper_;
764 size_t window_index_begin = 0;
765 size_t window_index_end = 0;
766 int64_t highest_seq_number =
767 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
768 int64_t highest_prior_seq_number =
769 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
770
771 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
772 while (window_index_end < packet_stream.size() &&
773 packet_stream[window_index_end].timestamp < t) {
774 int64_t sequence_number = unwrapper_.Unwrap(
775 packet_stream[window_index_end].header.sequenceNumber);
776 highest_seq_number = std::max(highest_seq_number, sequence_number);
777 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200778 }
terelius4c9b4af2017-01-30 08:44:51 -0800779 while (window_index_begin < packet_stream.size() &&
780 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
781 int64_t sequence_number = prior_unwrapper_.Unwrap(
782 packet_stream[window_index_begin].header.sequenceNumber);
783 highest_prior_seq_number =
784 std::max(highest_prior_seq_number, sequence_number);
785 ++window_index_begin;
786 }
787 float x = static_cast<float>(t - begin_time_) / 1000000;
788 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
789 if (expected_packets > 0) {
790 int64_t received_packets = window_index_end - window_index_begin;
791 int64_t lost_packets = expected_packets - received_packets;
792 float y = static_cast<float>(lost_packets) / expected_packets * 100;
793 time_series.points.emplace_back(x, y);
794 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200795 }
796 plot->series_list_.push_back(std::move(time_series));
797 }
798
799 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
800 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
801 kTopMargin);
802 plot->SetTitle("Estimated incoming loss rate");
803}
804
terelius54ce6802016-07-13 06:44:41 -0700805void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700806 for (auto& kv : rtp_packets_) {
807 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700808 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700809 // Filter on direction and SSRC.
810 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200811 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
812 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
813 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700814 continue;
815 }
terelius54ce6802016-07-13 06:44:41 -0700816
tereliusccbbf8d2016-08-10 07:34:28 -0700817 TimeSeries capture_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200818 capture_time_data.label = GetStreamName(stream_id) + " capture-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700819 capture_time_data.style = BAR_GRAPH;
terelius53dc23c2017-03-13 05:24:05 -0700820 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
821 packet_stream, begin_time_,
822 &capture_time_data);
tereliusccbbf8d2016-08-10 07:34:28 -0700823 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700824
tereliusccbbf8d2016-08-10 07:34:28 -0700825 TimeSeries send_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200826 send_time_data.label = GetStreamName(stream_id) + " abs-send-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700827 send_time_data.style = BAR_GRAPH;
terelius53dc23c2017-03-13 05:24:05 -0700828 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
829 packet_stream, begin_time_,
830 &send_time_data);
tereliusccbbf8d2016-08-10 07:34:28 -0700831 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700832 }
833
tereliusdc35dcd2016-08-01 12:03:27 -0700834 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
835 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
836 kTopMargin);
837 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700838}
839
840void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700841 for (auto& kv : rtp_packets_) {
842 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700843 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700844 // Filter on direction and SSRC.
845 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200846 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
847 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
848 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700849 continue;
850 }
terelius54ce6802016-07-13 06:44:41 -0700851
tereliusccbbf8d2016-08-10 07:34:28 -0700852 TimeSeries capture_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200853 capture_time_data.label = GetStreamName(stream_id) + " capture-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700854 capture_time_data.style = LINE_GRAPH;
terelius53dc23c2017-03-13 05:24:05 -0700855 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
856 packet_stream, begin_time_,
857 &capture_time_data);
tereliusccbbf8d2016-08-10 07:34:28 -0700858 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700859
tereliusccbbf8d2016-08-10 07:34:28 -0700860 TimeSeries send_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200861 send_time_data.label = GetStreamName(stream_id) + " abs-send-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700862 send_time_data.style = LINE_GRAPH;
terelius53dc23c2017-03-13 05:24:05 -0700863 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
864 packet_stream, begin_time_,
865 &send_time_data);
tereliusccbbf8d2016-08-10 07:34:28 -0700866 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700867 }
868
tereliusdc35dcd2016-08-01 12:03:27 -0700869 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
870 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
871 kTopMargin);
872 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700873}
874
tereliusf736d232016-08-04 10:00:11 -0700875// Plot the fraction of packets lost (as perceived by the loss-based BWE).
876void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
877 plot->series_list_.push_back(TimeSeries());
878 for (auto& bwe_update : bwe_loss_updates_) {
879 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
880 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
881 plot->series_list_.back().points.emplace_back(x, y);
882 }
883 plot->series_list_.back().label = "Fraction lost";
884 plot->series_list_.back().style = LINE_DOT_GRAPH;
885
886 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
887 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
888 kTopMargin);
889 plot->SetTitle("Reported packet loss");
890}
891
terelius54ce6802016-07-13 06:44:41 -0700892// Plot the total bandwidth used by all RTP streams.
893void EventLogAnalyzer::CreateTotalBitrateGraph(
894 PacketDirection desired_direction,
895 Plot* plot) {
896 struct TimestampSize {
897 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
898 uint64_t timestamp;
899 size_t size;
900 };
901 std::vector<TimestampSize> packets;
902
903 PacketDirection direction;
904 size_t total_length;
905
906 // Extract timestamps and sizes for the relevant packets.
907 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
908 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
909 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
910 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, nullptr,
911 &total_length);
912 if (direction == desired_direction) {
913 uint64_t timestamp = parsed_log_.GetTimestamp(i);
914 packets.push_back(TimestampSize(timestamp, total_length));
915 }
916 }
917 }
918
919 size_t window_index_begin = 0;
920 size_t window_index_end = 0;
921 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700922
923 // Calculate a moving average of the bitrate and store in a TimeSeries.
tereliusdc35dcd2016-08-01 12:03:27 -0700924 plot->series_list_.push_back(TimeSeries());
terelius54ce6802016-07-13 06:44:41 -0700925 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
926 while (window_index_end < packets.size() &&
927 packets[window_index_end].timestamp < time) {
928 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700929 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700930 }
931 while (window_index_begin < packets.size() &&
932 packets[window_index_begin].timestamp < time - window_duration_) {
933 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
934 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700935 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700936 }
937 float window_duration_in_seconds =
938 static_cast<float>(window_duration_) / 1000000;
939 float x = static_cast<float>(time - begin_time_) / 1000000;
940 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700941 plot->series_list_.back().points.push_back(TimeSeriesPoint(x, y));
terelius54ce6802016-07-13 06:44:41 -0700942 }
943
944 // Set labels.
945 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700946 plot->series_list_.back().label = "Incoming bitrate";
terelius54ce6802016-07-13 06:44:41 -0700947 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700948 plot->series_list_.back().label = "Outgoing bitrate";
terelius54ce6802016-07-13 06:44:41 -0700949 }
tereliusdc35dcd2016-08-01 12:03:27 -0700950 plot->series_list_.back().style = LINE_GRAPH;
terelius54ce6802016-07-13 06:44:41 -0700951
terelius8058e582016-07-25 01:32:41 -0700952 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
953 if (desired_direction == kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700954 plot->series_list_.push_back(TimeSeries());
terelius8058e582016-07-25 01:32:41 -0700955 for (auto& bwe_update : bwe_loss_updates_) {
956 float x =
957 static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
958 float y = static_cast<float>(bwe_update.new_bitrate) / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700959 plot->series_list_.back().points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700960 }
tereliusdc35dcd2016-08-01 12:03:27 -0700961 plot->series_list_.back().label = "Loss-based estimate";
terelius77f05802017-02-01 06:34:53 -0800962 plot->series_list_.back().style = LINE_STEP_GRAPH;
terelius8058e582016-07-25 01:32:41 -0700963 }
tereliusdc35dcd2016-08-01 12:03:27 -0700964 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
965 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700966 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700967 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700968 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700969 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700970 }
971}
972
973// For each SSRC, plot the bandwidth used by that stream.
974void EventLogAnalyzer::CreateStreamBitrateGraph(
975 PacketDirection desired_direction,
976 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700977 for (auto& kv : rtp_packets_) {
978 StreamId stream_id = kv.first;
979 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
980 // Filter on direction and SSRC.
981 if (stream_id.GetDirection() != desired_direction ||
982 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
983 continue;
terelius54ce6802016-07-13 06:44:41 -0700984 }
985
terelius6addf492016-08-23 17:34:07 -0700986 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200987 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700988 time_series.style = LINE_GRAPH;
terelius53dc23c2017-03-13 05:24:05 -0700989 MovingAverage<LoggedRtpPacket, double>(
990 [](const LoggedRtpPacket& packet) {
991 return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0);
992 },
993 packet_stream, begin_time_, end_time_, window_duration_, step_,
994 &time_series);
terelius6addf492016-08-23 17:34:07 -0700995 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700996 }
997
tereliusdc35dcd2016-08-01 12:03:27 -0700998 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
999 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001000 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001001 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001002 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001003 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001004 }
1005}
1006
tereliuse34c19c2016-08-15 08:47:14 -07001007void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
Stefan Holmer13181032016-07-29 14:48:54 +02001008 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1009 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
1010
1011 for (const auto& kv : rtp_packets_) {
1012 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1013 for (const LoggedRtpPacket& rtp_packet : kv.second)
1014 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1015 }
1016 }
1017
1018 for (const auto& kv : rtcp_packets_) {
1019 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1020 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1021 incoming_rtcp.insert(
1022 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1023 }
1024 }
1025
1026 SimulatedClock clock(0);
1027 BitrateObserver observer;
1028 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001029 PacketRouter packet_router;
1030 CongestionController cc(&clock, &observer, &observer, &null_event_log,
1031 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +02001032 // TODO(holmer): Log the call config and use that here instead.
1033 static const uint32_t kDefaultStartBitrateBps = 300000;
1034 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1035
1036 TimeSeries time_series;
tereliuse34c19c2016-08-15 08:47:14 -07001037 time_series.label = "Delay-based estimate";
Stefan Holmer13181032016-07-29 14:48:54 +02001038 time_series.style = LINE_DOT_GRAPH;
Stefan Holmer60e43462016-09-07 09:58:20 +02001039 TimeSeries acked_time_series;
1040 acked_time_series.label = "Acked bitrate";
1041 acked_time_series.style = LINE_DOT_GRAPH;
Stefan Holmer13181032016-07-29 14:48:54 +02001042
1043 auto rtp_iterator = outgoing_rtp.begin();
1044 auto rtcp_iterator = incoming_rtcp.begin();
1045
1046 auto NextRtpTime = [&]() {
1047 if (rtp_iterator != outgoing_rtp.end())
1048 return static_cast<int64_t>(rtp_iterator->first);
1049 return std::numeric_limits<int64_t>::max();
1050 };
1051
1052 auto NextRtcpTime = [&]() {
1053 if (rtcp_iterator != incoming_rtcp.end())
1054 return static_cast<int64_t>(rtcp_iterator->first);
1055 return std::numeric_limits<int64_t>::max();
1056 };
1057
1058 auto NextProcessTime = [&]() {
1059 if (rtcp_iterator != incoming_rtcp.end() ||
1060 rtp_iterator != outgoing_rtp.end()) {
1061 return clock.TimeInMicroseconds() +
1062 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1063 }
1064 return std::numeric_limits<int64_t>::max();
1065 };
1066
Stefan Holmer492ee282016-10-27 17:19:20 +02001067 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001068
Stefan Holmer13181032016-07-29 14:48:54 +02001069 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001070 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001071 while (time_us != std::numeric_limits<int64_t>::max()) {
1072 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1073 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001074 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001075 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1076 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001077 cc.OnTransportFeedback(
1078 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1079 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001080 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001081 rtc::Optional<uint32_t> bitrate_bps;
1082 if (!feedback.empty()) {
elad.alonf9490002017-03-06 05:32:21 -08001083 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001084 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1085 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1086 }
1087 uint32_t y = 0;
1088 if (bitrate_bps)
1089 y = *bitrate_bps / 1000;
1090 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1091 1000000;
1092 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +02001093 }
1094 ++rtcp_iterator;
1095 }
1096 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001097 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001098 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1099 if (rtp.header.extension.hasTransportSequenceNumber) {
1100 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alon5bbf43f2017-03-09 06:40:08 -08001101 cc.AddPacket(rtp.header.extension.transportSequenceNumber,
1102 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001103 rtc::SentPacket sent_packet(
1104 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1105 cc.OnSentPacket(sent_packet);
1106 }
1107 ++rtp_iterator;
1108 }
stefanc3de0332016-08-02 07:22:17 -07001109 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1110 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001111 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001112 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001113 if (observer.GetAndResetBitrateUpdated() ||
1114 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001115 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001116 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1117 1000000;
1118 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001119 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001120 }
1121 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1122 }
1123 // Add the data set to the plot.
tereliusdc35dcd2016-08-01 12:03:27 -07001124 plot->series_list_.push_back(std::move(time_series));
Stefan Holmer60e43462016-09-07 09:58:20 +02001125 plot->series_list_.push_back(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001126
tereliusdc35dcd2016-08-01 12:03:27 -07001127 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1128 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1129 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001130}
1131
tereliuse34c19c2016-08-15 08:47:14 -07001132void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanc3de0332016-08-02 07:22:17 -07001133 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1134 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
1135
1136 for (const auto& kv : rtp_packets_) {
1137 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1138 for (const LoggedRtpPacket& rtp_packet : kv.second)
1139 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1140 }
1141 }
1142
1143 for (const auto& kv : rtcp_packets_) {
1144 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1145 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1146 incoming_rtcp.insert(
1147 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1148 }
1149 }
1150
1151 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001152 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001153
1154 TimeSeries time_series;
1155 time_series.label = "Network Delay Change";
1156 time_series.style = LINE_DOT_GRAPH;
1157 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1158
1159 auto rtp_iterator = outgoing_rtp.begin();
1160 auto rtcp_iterator = incoming_rtcp.begin();
1161
1162 auto NextRtpTime = [&]() {
1163 if (rtp_iterator != outgoing_rtp.end())
1164 return static_cast<int64_t>(rtp_iterator->first);
1165 return std::numeric_limits<int64_t>::max();
1166 };
1167
1168 auto NextRtcpTime = [&]() {
1169 if (rtcp_iterator != incoming_rtcp.end())
1170 return static_cast<int64_t>(rtcp_iterator->first);
1171 return std::numeric_limits<int64_t>::max();
1172 };
1173
1174 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1175 while (time_us != std::numeric_limits<int64_t>::max()) {
1176 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1177 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1178 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1179 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1180 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001181 feedback_adapter.OnTransportFeedback(
1182 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001183 std::vector<PacketFeedback> feedback =
1184 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001185 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001186 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001187 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1188 float x =
1189 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1190 1000000;
1191 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1192 time_series.points.emplace_back(x, y);
1193 }
1194 }
1195 ++rtcp_iterator;
1196 }
1197 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1198 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1199 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1200 if (rtp.header.extension.hasTransportSequenceNumber) {
1201 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
1202 feedback_adapter.AddPacket(rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001203 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001204 feedback_adapter.OnSentPacket(
1205 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1206 }
1207 ++rtp_iterator;
1208 }
1209 time_us = std::min(NextRtpTime(), NextRtcpTime());
1210 }
1211 // We assume that the base network delay (w/o queues) is the min delay
1212 // observed during the call.
1213 for (TimeSeriesPoint& point : time_series.points)
1214 point.y -= estimated_base_delay_ms;
1215 // Add the data set to the plot.
1216 plot->series_list_.push_back(std::move(time_series));
1217
1218 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1219 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1220 plot->SetTitle("Network Delay Change.");
1221}
stefan08383272016-12-20 08:51:52 -08001222
1223std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1224 const {
1225 std::vector<std::pair<int64_t, int64_t>> timestamps;
1226 size_t largest_stream_size = 0;
1227 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1228 // Find the incoming video stream with the most number of packets that is
1229 // not rtx.
1230 for (const auto& kv : rtp_packets_) {
1231 if (kv.first.GetDirection() == kIncomingPacket &&
1232 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1233 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1234 kv.second.size() > largest_stream_size) {
1235 largest_stream_size = kv.second.size();
1236 largest_video_stream = &kv.second;
1237 }
1238 }
1239 if (largest_video_stream == nullptr) {
1240 for (auto& packet : *largest_video_stream) {
1241 if (packet.header.markerBit) {
1242 int64_t capture_ms = packet.header.timestamp / 90.0;
1243 int64_t arrival_ms = packet.timestamp / 1000.0;
1244 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1245 }
1246 }
1247 }
1248 return timestamps;
1249}
stefane372d3c2017-02-02 08:04:18 -08001250
1251void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1252 for (const auto& kv : rtp_packets_) {
1253 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1254 StreamId stream_id = kv.first;
1255
1256 {
1257 TimeSeries timestamp_data;
1258 timestamp_data.label = GetStreamName(stream_id) + " capture-time";
1259 timestamp_data.style = LINE_DOT_GRAPH;
1260 for (LoggedRtpPacket packet : rtp_packets) {
1261 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1262 float y = packet.header.timestamp;
1263 timestamp_data.points.emplace_back(x, y);
1264 }
1265 plot->series_list_.push_back(std::move(timestamp_data));
1266 }
1267
1268 {
1269 auto kv = rtcp_packets_.find(stream_id);
1270 if (kv != rtcp_packets_.end()) {
1271 const auto& packets = kv->second;
1272 TimeSeries timestamp_data;
1273 timestamp_data.label = GetStreamName(stream_id) + " rtcp capture-time";
1274 timestamp_data.style = LINE_DOT_GRAPH;
1275 for (const LoggedRtcpPacket& rtcp : packets) {
1276 if (rtcp.type != kRtcpSr)
1277 continue;
1278 rtcp::SenderReport* sr;
1279 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1280 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1281 float y = sr->rtp_timestamp();
1282 timestamp_data.points.emplace_back(x, y);
1283 }
1284 plot->series_list_.push_back(std::move(timestamp_data));
1285 }
1286 }
1287 }
1288
1289 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1290 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1291 plot->SetTitle("Timestamps");
1292}
michaelt6e5b2192017-02-22 07:33:27 -08001293
1294void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
terelius53dc23c2017-03-13 05:24:05 -07001295 plot->series_list_.push_back(TimeSeries());
1296 plot->series_list_.back().style = LINE_DOT_GRAPH;
1297 plot->series_list_.back().label = "Audio encoder target bitrate";
1298 ProcessPoints<AudioNetworkAdaptationEvent>(
1299 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001300 if (ana_event.config.bitrate_bps)
1301 return rtc::Optional<float>(
1302 static_cast<float>(*ana_event.config.bitrate_bps));
1303 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001304 },
1305 audio_network_adaptation_events_, begin_time_,
1306 &plot->series_list_.back());
michaelt6e5b2192017-02-22 07:33:27 -08001307 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1308 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1309 plot->SetTitle("Reported audio encoder target bitrate");
1310}
1311
1312void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
terelius53dc23c2017-03-13 05:24:05 -07001313 plot->series_list_.push_back(TimeSeries());
1314 plot->series_list_.back().style = LINE_DOT_GRAPH;
1315 plot->series_list_.back().label = "Audio encoder frame length";
1316 ProcessPoints<AudioNetworkAdaptationEvent>(
1317 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001318 if (ana_event.config.frame_length_ms)
1319 return rtc::Optional<float>(
1320 static_cast<float>(*ana_event.config.frame_length_ms));
1321 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001322 },
1323 audio_network_adaptation_events_, begin_time_,
1324 &plot->series_list_.back());
michaelt6e5b2192017-02-22 07:33:27 -08001325 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1326 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1327 plot->SetTitle("Reported audio encoder frame length");
1328}
1329
1330void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph(
1331 Plot* plot) {
terelius53dc23c2017-03-13 05:24:05 -07001332 plot->series_list_.push_back(TimeSeries());
1333 plot->series_list_.back().style = LINE_DOT_GRAPH;
1334 plot->series_list_.back().label = "Audio encoder uplink packet loss fraction";
1335 ProcessPoints<AudioNetworkAdaptationEvent>(
1336 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001337 if (ana_event.config.uplink_packet_loss_fraction)
1338 return rtc::Optional<float>(static_cast<float>(
1339 *ana_event.config.uplink_packet_loss_fraction));
1340 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001341 },
1342 audio_network_adaptation_events_, begin_time_,
1343 &plot->series_list_.back());
michaelt6e5b2192017-02-22 07:33:27 -08001344 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1345 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1346 kTopMargin);
1347 plot->SetTitle("Reported audio encoder lost packets");
1348}
1349
1350void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
terelius53dc23c2017-03-13 05:24:05 -07001351 plot->series_list_.push_back(TimeSeries());
1352 plot->series_list_.back().style = LINE_DOT_GRAPH;
1353 plot->series_list_.back().label = "Audio encoder FEC";
1354 ProcessPoints<AudioNetworkAdaptationEvent>(
1355 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001356 if (ana_event.config.enable_fec)
1357 return rtc::Optional<float>(
1358 static_cast<float>(*ana_event.config.enable_fec));
1359 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001360 },
1361 audio_network_adaptation_events_, begin_time_,
1362 &plot->series_list_.back());
michaelt6e5b2192017-02-22 07:33:27 -08001363 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1364 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1365 plot->SetTitle("Reported audio encoder FEC");
1366}
1367
1368void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
terelius53dc23c2017-03-13 05:24:05 -07001369 plot->series_list_.push_back(TimeSeries());
1370 plot->series_list_.back().style = LINE_DOT_GRAPH;
1371 plot->series_list_.back().label = "Audio encoder DTX";
1372 ProcessPoints<AudioNetworkAdaptationEvent>(
1373 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001374 if (ana_event.config.enable_dtx)
1375 return rtc::Optional<float>(
1376 static_cast<float>(*ana_event.config.enable_dtx));
1377 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001378 },
1379 audio_network_adaptation_events_, begin_time_,
1380 &plot->series_list_.back());
michaelt6e5b2192017-02-22 07:33:27 -08001381 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1382 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1383 plot->SetTitle("Reported audio encoder DTX");
1384}
1385
1386void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
terelius53dc23c2017-03-13 05:24:05 -07001387 plot->series_list_.push_back(TimeSeries());
1388 plot->series_list_.back().style = LINE_DOT_GRAPH;
1389 plot->series_list_.back().label = "Audio encoder number of channels";
1390 ProcessPoints<AudioNetworkAdaptationEvent>(
1391 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001392 if (ana_event.config.num_channels)
1393 return rtc::Optional<float>(
1394 static_cast<float>(*ana_event.config.num_channels));
1395 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001396 },
1397 audio_network_adaptation_events_, begin_time_,
1398 &plot->series_list_.back());
michaelt6e5b2192017-02-22 07:33:27 -08001399 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1400 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1401 kBottomMargin, kTopMargin);
1402 plot->SetTitle("Reported audio encoder number of channels");
1403}
terelius54ce6802016-07-13 06:44:41 -07001404} // namespace plotting
1405} // namespace webrtc