blob: 15b3e821b843f9647f92e0be053d68025964f4b2 [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 Holmer280de9e2016-09-30 10:06:51 +020027#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
Stefan Holmer13181032016-07-29 14:48:54 +020028#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
terelius4c9b4af2017-01-30 08:44:51 -080029#include "webrtc/modules/include/module_common_types.h"
terelius54ce6802016-07-13 06:44:41 -070030#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
31#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
danilchapbf369fe2016-10-07 07:39:54 -070032#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
stefane372d3c2017-02-02 08:04:18 -080033#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
34#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
Stefan Holmer13181032016-07-29 14:48:54 +020035#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
ossuf515ab82016-12-07 04:52:58 -080036#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
37#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
terelius54ce6802016-07-13 06:44:41 -070038#include "webrtc/video_receive_stream.h"
39#include "webrtc/video_send_stream.h"
40
tereliusdc35dcd2016-08-01 12:03:27 -070041namespace webrtc {
42namespace plotting {
43
terelius54ce6802016-07-13 06:44:41 -070044namespace {
45
elad.alonec304f92017-03-08 05:03:53 -080046class PacketFeedbackComparator {
47 public:
48 inline bool operator()(const webrtc::PacketFeedback& lhs,
49 const webrtc::PacketFeedback& rhs) {
50 if (lhs.arrival_time_ms != rhs.arrival_time_ms)
51 return lhs.arrival_time_ms < rhs.arrival_time_ms;
52 if (lhs.send_time_ms != rhs.send_time_ms)
53 return lhs.send_time_ms < rhs.send_time_ms;
54 return lhs.sequence_number < rhs.sequence_number;
55 }
56};
57
58void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
59 auto pred = [](const PacketFeedback& packet_feedback) {
60 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
61 };
62 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
63 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
64}
65
terelius54ce6802016-07-13 06:44:41 -070066std::string SsrcToString(uint32_t ssrc) {
67 std::stringstream ss;
68 ss << "SSRC " << ssrc;
69 return ss.str();
70}
71
72// Checks whether an SSRC is contained in the list of desired SSRCs.
73// Note that an empty SSRC list matches every SSRC.
74bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
75 if (desired_ssrc.size() == 0)
76 return true;
77 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
78 desired_ssrc.end();
79}
80
81double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
82 // The timestamp is a fixed point representation with 6 bits for seconds
83 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
84 // time in seconds and then multiply by 1000000 to convert to microseconds.
85 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070086 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070087 return abs_send_time * kTimestampToMicroSec;
88}
89
90// Computes the difference |later| - |earlier| where |later| and |earlier|
91// are counters that wrap at |modulus|. The difference is chosen to have the
92// least absolute value. For example if |modulus| is 8, then the difference will
93// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
94// be in [-4, 4].
95int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
96 RTC_DCHECK_LE(1, modulus);
97 RTC_DCHECK_LT(later, modulus);
98 RTC_DCHECK_LT(earlier, modulus);
99 int64_t difference =
100 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
101 int64_t max_difference = modulus / 2;
102 int64_t min_difference = max_difference - modulus + 1;
103 if (difference > max_difference) {
104 difference -= modulus;
105 }
106 if (difference < min_difference) {
107 difference += modulus;
108 }
terelius6addf492016-08-23 17:34:07 -0700109 if (difference > max_difference / 2 || difference < min_difference / 2) {
110 LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
111 << " expected to be in the range (" << min_difference / 2
112 << "," << max_difference / 2 << ") but is " << difference
113 << ". Correct unwrapping is uncertain.";
114 }
terelius54ce6802016-07-13 06:44:41 -0700115 return difference;
116}
117
ivocaac9d6f2016-09-22 07:01:47 -0700118// Return default values for header extensions, to use on streams without stored
119// mapping data. Currently this only applies to audio streams, since the mapping
120// is not stored in the event log.
121// TODO(ivoc): Remove this once this mapping is stored in the event log for
122// audio streams. Tracking bug: webrtc:6399
123webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
124 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800125 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
126 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700127 webrtc::RtpExtension::kAbsSendTimeDefaultId);
128 return default_map;
129}
130
tereliusdc35dcd2016-08-01 12:03:27 -0700131constexpr float kLeftMargin = 0.01f;
132constexpr float kRightMargin = 0.02f;
133constexpr float kBottomMargin = 0.02f;
134constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700135
terelius6addf492016-08-23 17:34:07 -0700136class PacketSizeBytes {
137 public:
138 using DataType = LoggedRtpPacket;
139 using ResultType = size_t;
140 size_t operator()(const LoggedRtpPacket& packet) {
141 return packet.total_length;
142 }
143};
144
145class SequenceNumberDiff {
146 public:
147 using DataType = LoggedRtpPacket;
148 using ResultType = int64_t;
149 int64_t operator()(const LoggedRtpPacket& old_packet,
150 const LoggedRtpPacket& new_packet) {
151 return WrappingDifference(new_packet.header.sequenceNumber,
152 old_packet.header.sequenceNumber, 1ul << 16);
153 }
154};
155
tereliusccbbf8d2016-08-10 07:34:28 -0700156class NetworkDelayDiff {
157 public:
158 class AbsSendTime {
159 public:
160 using DataType = LoggedRtpPacket;
161 using ResultType = double;
162 double operator()(const LoggedRtpPacket& old_packet,
163 const LoggedRtpPacket& new_packet) {
164 if (old_packet.header.extension.hasAbsoluteSendTime &&
165 new_packet.header.extension.hasAbsoluteSendTime) {
166 int64_t send_time_diff = WrappingDifference(
167 new_packet.header.extension.absoluteSendTime,
168 old_packet.header.extension.absoluteSendTime, 1ul << 24);
169 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
170 return static_cast<double>(recv_time_diff -
171 AbsSendTimeToMicroseconds(send_time_diff)) /
172 1000;
173 } else {
174 return 0;
175 }
176 }
177 };
178
179 class CaptureTime {
180 public:
181 using DataType = LoggedRtpPacket;
182 using ResultType = double;
183 double operator()(const LoggedRtpPacket& old_packet,
184 const LoggedRtpPacket& new_packet) {
185 int64_t send_time_diff = WrappingDifference(
186 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
187 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
188
189 const double kVideoSampleRate = 90000;
190 // TODO(terelius): We treat all streams as video for now, even though
191 // audio might be sampled at e.g. 16kHz, because it is really difficult to
192 // figure out the true sampling rate of a stream. The effect is that the
193 // delay will be scaled incorrectly for non-video streams.
194
195 double delay_change =
196 static_cast<double>(recv_time_diff) / 1000 -
197 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
terelius6addf492016-08-23 17:34:07 -0700198 if (delay_change < -10000 || 10000 < delay_change) {
199 LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
200 LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
201 << ", received time " << old_packet.timestamp;
202 LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
203 << ", received time " << new_packet.timestamp;
204 LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
205 << static_cast<double>(recv_time_diff) / 1000000 << "s";
206 LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
207 << static_cast<double>(send_time_diff) /
208 kVideoSampleRate
209 << "s";
210 }
tereliusccbbf8d2016-08-10 07:34:28 -0700211 return delay_change;
212 }
213 };
214};
215
216template <typename Extractor>
217class Accumulated {
218 public:
219 using DataType = typename Extractor::DataType;
220 using ResultType = typename Extractor::ResultType;
221 ResultType operator()(const DataType& old_packet,
222 const DataType& new_packet) {
223 sum += extract(old_packet, new_packet);
224 return sum;
225 }
226
227 private:
228 Extractor extract;
229 ResultType sum = 0;
230};
231
terelius6addf492016-08-23 17:34:07 -0700232// For each element in data, use |Extractor| to extract a y-coordinate and
233// store the result in a TimeSeries.
234template <typename Extractor>
235void Pointwise(const std::vector<typename Extractor::DataType>& data,
236 uint64_t begin_time,
237 TimeSeries* result) {
238 Extractor extract;
239 for (size_t i = 0; i < data.size(); i++) {
240 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
241 float y = extract(data[i]);
242 result->points.emplace_back(x, y);
243 }
244}
245
246// For each pair of adjacent elements in |data|, use |Extractor| to extract a
247// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
248// will be the time of the second element in the pair.
tereliusccbbf8d2016-08-10 07:34:28 -0700249template <typename Extractor>
250void Pairwise(const std::vector<typename Extractor::DataType>& data,
251 uint64_t begin_time,
252 TimeSeries* result) {
253 Extractor extract;
254 for (size_t i = 1; i < data.size(); i++) {
255 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
256 float y = extract(data[i - 1], data[i]);
257 result->points.emplace_back(x, y);
258 }
259}
260
terelius6addf492016-08-23 17:34:07 -0700261// Calculates a moving average of |data| and stores the result in a TimeSeries.
262// A data point is generated every |step| microseconds from |begin_time|
263// to |end_time|. The value of each data point is the average of the data
264// during the preceeding |window_duration_us| microseconds.
265template <typename Extractor>
266void MovingAverage(const std::vector<typename Extractor::DataType>& data,
267 uint64_t begin_time,
268 uint64_t end_time,
269 uint64_t window_duration_us,
270 uint64_t step,
271 float y_scaling,
272 webrtc::plotting::TimeSeries* result) {
273 size_t window_index_begin = 0;
274 size_t window_index_end = 0;
275 typename Extractor::ResultType sum_in_window = 0;
276 Extractor extract;
277
278 for (uint64_t t = begin_time; t < end_time + step; t += step) {
279 while (window_index_end < data.size() &&
280 data[window_index_end].timestamp < t) {
281 sum_in_window += extract(data[window_index_end]);
282 ++window_index_end;
283 }
284 while (window_index_begin < data.size() &&
285 data[window_index_begin].timestamp < t - window_duration_us) {
286 sum_in_window -= extract(data[window_index_begin]);
287 ++window_index_begin;
288 }
289 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
290 float x = static_cast<float>(t - begin_time) / 1000000;
291 float y = sum_in_window / window_duration_s * y_scaling;
292 result->points.emplace_back(x, y);
293 }
294}
295
terelius54ce6802016-07-13 06:44:41 -0700296} // namespace
297
terelius54ce6802016-07-13 06:44:41 -0700298EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
299 : parsed_log_(log), window_duration_(250000), step_(10000) {
300 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
301 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700302
Stefan Holmer13181032016-07-29 14:48:54 +0200303 // Maps a stream identifier consisting of ssrc and direction
terelius88e64e52016-07-19 01:51:06 -0700304 // to the header extensions used by that stream,
305 std::map<StreamId, RtpHeaderExtensionMap> extension_maps;
306
307 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700308 uint8_t header[IP_PACKET_SIZE];
309 size_t header_length;
310 size_t total_length;
311
ivocaac9d6f2016-09-22 07:01:47 -0700312 // Make a default extension map for streams without configuration information.
313 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
314 // this can be removed. Tracking bug: webrtc:6399
315 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
316
terelius54ce6802016-07-13 06:44:41 -0700317 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
318 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700319 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
320 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
321 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700322 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
323 event_type != ParsedRtcEventLog::LOG_START &&
324 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700325 uint64_t timestamp = parsed_log_.GetTimestamp(i);
326 first_timestamp = std::min(first_timestamp, timestamp);
327 last_timestamp = std::max(last_timestamp, timestamp);
328 }
329
330 switch (parsed_log_.GetEventType(i)) {
331 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
332 VideoReceiveStream::Config config(nullptr);
333 parsed_log_.GetVideoReceiveConfig(i, &config);
Stefan Holmer13181032016-07-29 14:48:54 +0200334 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800335 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700336 video_ssrcs_.insert(stream);
brandtr14742122017-01-27 04:53:07 -0800337 StreamId rtx_stream(config.rtp.rtx_ssrc, kIncomingPacket);
338 extension_maps[rtx_stream] =
339 RtpHeaderExtensionMap(config.rtp.extensions);
340 video_ssrcs_.insert(rtx_stream);
341 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700342 break;
343 }
344 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
345 VideoSendStream::Config config(nullptr);
346 parsed_log_.GetVideoSendConfig(i, &config);
347 for (auto ssrc : config.rtp.ssrcs) {
Stefan Holmer13181032016-07-29 14:48:54 +0200348 StreamId stream(ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800349 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700350 video_ssrcs_.insert(stream);
stefan6a850c32016-07-29 10:28:08 -0700351 }
352 for (auto ssrc : config.rtp.rtx.ssrcs) {
terelius0740a202016-08-08 10:21:04 -0700353 StreamId rtx_stream(ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800354 extension_maps[rtx_stream] =
355 RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700356 video_ssrcs_.insert(rtx_stream);
357 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700358 }
359 break;
360 }
361 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
362 AudioReceiveStream::Config config;
ivoce0928d82016-10-10 05:12:51 -0700363 parsed_log_.GetAudioReceiveConfig(i, &config);
364 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800365 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
ivoce0928d82016-10-10 05:12:51 -0700366 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700367 break;
368 }
369 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
370 AudioSendStream::Config config(nullptr);
ivoce0928d82016-10-10 05:12:51 -0700371 parsed_log_.GetAudioSendConfig(i, &config);
372 StreamId stream(config.rtp.ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800373 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
ivoce0928d82016-10-10 05:12:51 -0700374 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700375 break;
376 }
377 case ParsedRtcEventLog::RTP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200378 MediaType media_type;
terelius88e64e52016-07-19 01:51:06 -0700379 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
380 &header_length, &total_length);
381 // Parse header to get SSRC.
382 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
383 RTPHeader parsed_header;
384 rtp_parser.Parse(&parsed_header);
Stefan Holmer13181032016-07-29 14:48:54 +0200385 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700386 // Look up the extension_map and parse it again to get the extensions.
387 if (extension_maps.count(stream) == 1) {
388 RtpHeaderExtensionMap* extension_map = &extension_maps[stream];
389 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700390 } else {
391 // Use the default extension map.
392 // TODO(ivoc): Once configuration of audio streams is stored in the
393 // event log, this can be removed.
394 // Tracking bug: webrtc:6399
395 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700396 }
397 uint64_t timestamp = parsed_log_.GetTimestamp(i);
398 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200399 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700400 break;
401 }
402 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200403 uint8_t packet[IP_PACKET_SIZE];
404 MediaType media_type;
405 parsed_log_.GetRtcpPacket(i, &direction, &media_type, packet,
406 &total_length);
407
danilchapbf369fe2016-10-07 07:39:54 -0700408 // Currently feedback is logged twice, both for audio and video.
409 // Only act on one of them.
stefane372d3c2017-02-02 08:04:18 -0800410 if (media_type == MediaType::AUDIO || media_type == MediaType::ANY) {
danilchapbf369fe2016-10-07 07:39:54 -0700411 rtcp::CommonHeader header;
412 const uint8_t* packet_end = packet + total_length;
413 for (const uint8_t* block = packet; block < packet_end;
414 block = header.NextPacket()) {
415 RTC_CHECK(header.Parse(block, packet_end - block));
416 if (header.type() == rtcp::TransportFeedback::kPacketType &&
417 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
418 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
419 new rtcp::TransportFeedback());
420 if (rtcp_packet->Parse(header)) {
421 uint32_t ssrc = rtcp_packet->sender_ssrc();
Stefan Holmer13181032016-07-29 14:48:54 +0200422 StreamId stream(ssrc, direction);
423 uint64_t timestamp = parsed_log_.GetTimestamp(i);
424 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
425 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
426 }
stefane372d3c2017-02-02 08:04:18 -0800427 } else if (header.type() == rtcp::SenderReport::kPacketType) {
428 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
429 new rtcp::SenderReport());
430 if (rtcp_packet->Parse(header)) {
431 uint32_t ssrc = rtcp_packet->sender_ssrc();
432 StreamId stream(ssrc, direction);
433 uint64_t timestamp = parsed_log_.GetTimestamp(i);
434 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
435 timestamp, kRtcpSr, std::move(rtcp_packet)));
436 }
437 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
438 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
439 new rtcp::ReceiverReport());
440 if (rtcp_packet->Parse(header)) {
441 uint32_t ssrc = rtcp_packet->sender_ssrc();
442 StreamId stream(ssrc, direction);
443 uint64_t timestamp = parsed_log_.GetTimestamp(i);
444 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
445 timestamp, kRtcpRr, std::move(rtcp_packet)));
446 }
Stefan Holmer13181032016-07-29 14:48:54 +0200447 }
Stefan Holmer13181032016-07-29 14:48:54 +0200448 }
Stefan Holmer13181032016-07-29 14:48:54 +0200449 }
terelius88e64e52016-07-19 01:51:06 -0700450 break;
451 }
452 case ParsedRtcEventLog::LOG_START: {
453 break;
454 }
455 case ParsedRtcEventLog::LOG_END: {
456 break;
457 }
terelius424e6cf2017-02-20 05:14:41 -0800458 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
459 break;
460 }
461 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
462 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700463 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800464 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
465 &bwe_update.fraction_loss,
466 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700467 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700468 break;
469 }
terelius424e6cf2017-02-20 05:14:41 -0800470 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
471 break;
472 }
minyue4b7c9522017-01-24 04:54:59 -0800473 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800474 AudioNetworkAdaptationEvent ana_event;
475 ana_event.timestamp = parsed_log_.GetTimestamp(i);
476 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
477 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800478 break;
479 }
philipel32d00102017-02-27 02:18:46 -0800480 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
481 break;
482 }
483 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
484 break;
485 }
terelius88e64e52016-07-19 01:51:06 -0700486 case ParsedRtcEventLog::UNKNOWN_EVENT: {
487 break;
488 }
489 }
terelius54ce6802016-07-13 06:44:41 -0700490 }
terelius88e64e52016-07-19 01:51:06 -0700491
terelius54ce6802016-07-13 06:44:41 -0700492 if (last_timestamp < first_timestamp) {
493 // No useful events in the log.
494 first_timestamp = last_timestamp = 0;
495 }
496 begin_time_ = first_timestamp;
497 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700498 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700499}
500
Stefan Holmer13181032016-07-29 14:48:54 +0200501class BitrateObserver : public CongestionController::Observer,
502 public RemoteBitrateObserver {
503 public:
504 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
505
minyue78b4d562016-11-30 04:47:39 -0800506 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
507 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
508 using CongestionController::Observer::OnNetworkChanged;
509
Stefan Holmer13181032016-07-29 14:48:54 +0200510 void OnNetworkChanged(uint32_t bitrate_bps,
511 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800512 int64_t rtt_ms,
513 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200514 last_bitrate_bps_ = bitrate_bps;
515 bitrate_updated_ = true;
516 }
517
518 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
519 uint32_t bitrate) override {}
520
521 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
522 bool GetAndResetBitrateUpdated() {
523 bool bitrate_updated = bitrate_updated_;
524 bitrate_updated_ = false;
525 return bitrate_updated;
526 }
527
528 private:
529 uint32_t last_bitrate_bps_;
530 bool bitrate_updated_;
531};
532
Stefan Holmer99f8e082016-09-09 13:37:50 +0200533bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700534 return rtx_ssrcs_.count(stream_id) == 1;
535}
536
Stefan Holmer99f8e082016-09-09 13:37:50 +0200537bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700538 return video_ssrcs_.count(stream_id) == 1;
539}
540
Stefan Holmer99f8e082016-09-09 13:37:50 +0200541bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700542 return audio_ssrcs_.count(stream_id) == 1;
543}
544
Stefan Holmer99f8e082016-09-09 13:37:50 +0200545std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
546 std::stringstream name;
547 if (IsAudioSsrc(stream_id)) {
548 name << "Audio ";
549 } else if (IsVideoSsrc(stream_id)) {
550 name << "Video ";
551 } else {
552 name << "Unknown ";
553 }
554 if (IsRtxSsrc(stream_id))
555 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700556 if (stream_id.GetDirection() == kIncomingPacket) {
557 name << "(In) ";
558 } else {
559 name << "(Out) ";
560 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200561 name << SsrcToString(stream_id.GetSsrc());
562 return name.str();
563}
564
michaelt6e5b2192017-02-22 07:33:27 -0800565void EventLogAnalyzer::FillAudioEncoderTimeSeries(
566 Plot* plot,
567 rtc::FunctionView<rtc::Optional<float>(
568 const AudioNetworkAdaptationEvent& ana_event)> get_y) const {
569 plot->series_list_.push_back(TimeSeries());
570 plot->series_list_.back().style = LINE_DOT_GRAPH;
571 for (auto& ana_event : audio_network_adaptation_events_) {
572 rtc::Optional<float> y = get_y(ana_event);
573 if (y) {
574 float x = static_cast<float>(ana_event.timestamp - begin_time_) / 1000000;
575 plot->series_list_.back().points.emplace_back(x, *y);
576 }
577 }
578}
579
terelius54ce6802016-07-13 06:44:41 -0700580void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
581 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700582 for (auto& kv : rtp_packets_) {
583 StreamId stream_id = kv.first;
584 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
585 // Filter on direction and SSRC.
586 if (stream_id.GetDirection() != desired_direction ||
587 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
588 continue;
terelius54ce6802016-07-13 06:44:41 -0700589 }
terelius54ce6802016-07-13 06:44:41 -0700590
terelius6addf492016-08-23 17:34:07 -0700591 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200592 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700593 time_series.style = BAR_GRAPH;
594 Pointwise<PacketSizeBytes>(packet_stream, begin_time_, &time_series);
595 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700596 }
597
tereliusdc35dcd2016-08-01 12:03:27 -0700598 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
599 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
600 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700601 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700602 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700603 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700604 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700605 }
606}
607
philipelccd74892016-09-05 02:46:25 -0700608template <typename T>
609void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
610 PacketDirection desired_direction,
611 Plot* plot,
612 const std::map<StreamId, std::vector<T>>& packets,
613 const std::string& label_prefix) {
614 for (auto& kv : packets) {
615 StreamId stream_id = kv.first;
616 const std::vector<T>& packet_stream = kv.second;
617 // Filter on direction and SSRC.
618 if (stream_id.GetDirection() != desired_direction ||
619 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
620 continue;
621 }
622
623 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200624 time_series.label = label_prefix + " " + GetStreamName(stream_id);
terelius77f05802017-02-01 06:34:53 -0800625 time_series.style = LINE_STEP_GRAPH;
philipelccd74892016-09-05 02:46:25 -0700626
627 for (size_t i = 0; i < packet_stream.size(); i++) {
628 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
629 1000000;
philipelccd74892016-09-05 02:46:25 -0700630 time_series.points.emplace_back(x, i + 1);
631 }
632
633 plot->series_list_.push_back(std::move(time_series));
634 }
635}
636
637void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
638 PacketDirection desired_direction,
639 Plot* plot) {
640 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
641 "RTP");
642 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
643 "RTCP");
644
645 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
646 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
647 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
648 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
649 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
650 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
651 }
652}
653
terelius54ce6802016-07-13 06:44:41 -0700654// For each SSRC, plot the time between the consecutive playouts.
655void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
656 std::map<uint32_t, TimeSeries> time_series;
657 std::map<uint32_t, uint64_t> last_playout;
658
659 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700660
661 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
662 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
663 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
664 parsed_log_.GetAudioPlayout(i, &ssrc);
665 uint64_t timestamp = parsed_log_.GetTimestamp(i);
666 if (MatchingSsrc(ssrc, desired_ssrc_)) {
667 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
668 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
669 if (time_series[ssrc].points.size() == 0) {
670 // There were no previusly logged playout for this SSRC.
671 // Generate a point, but place it on the x-axis.
672 y = 0;
673 }
terelius54ce6802016-07-13 06:44:41 -0700674 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
675 last_playout[ssrc] = timestamp;
676 }
677 }
678 }
679
680 // Set labels and put in graph.
681 for (auto& kv : time_series) {
682 kv.second.label = SsrcToString(kv.first);
683 kv.second.style = BAR_GRAPH;
tereliusdc35dcd2016-08-01 12:03:27 -0700684 plot->series_list_.push_back(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700685 }
686
tereliusdc35dcd2016-08-01 12:03:27 -0700687 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
688 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
689 kTopMargin);
690 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700691}
692
ivocaac9d6f2016-09-22 07:01:47 -0700693// For audio SSRCs, plot the audio level.
694void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
695 std::map<StreamId, TimeSeries> time_series;
696
697 for (auto& kv : rtp_packets_) {
698 StreamId stream_id = kv.first;
699 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
700 // TODO(ivoc): When audio send/receive configs are stored in the event
701 // log, a check should be added here to only process audio
702 // streams. Tracking bug: webrtc:6399
703 for (auto& packet : packet_stream) {
704 if (packet.header.extension.hasAudioLevel) {
705 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
706 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
707 // Here we convert it to dBov.
708 float y = static_cast<float>(-packet.header.extension.audioLevel);
709 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
710 }
711 }
712 }
713
714 for (auto& series : time_series) {
715 series.second.label = GetStreamName(series.first);
716 series.second.style = LINE_GRAPH;
717 plot->series_list_.push_back(std::move(series.second));
718 }
719
720 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800721 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700722 kTopMargin);
723 plot->SetTitle("Audio level");
724}
725
terelius54ce6802016-07-13 06:44:41 -0700726// For each SSRC, plot the time between the consecutive playouts.
727void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700728 for (auto& kv : rtp_packets_) {
729 StreamId stream_id = kv.first;
730 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
731 // Filter on direction and SSRC.
732 if (stream_id.GetDirection() != kIncomingPacket ||
733 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
734 continue;
terelius54ce6802016-07-13 06:44:41 -0700735 }
terelius54ce6802016-07-13 06:44:41 -0700736
terelius6addf492016-08-23 17:34:07 -0700737 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200738 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700739 time_series.style = BAR_GRAPH;
740 Pairwise<SequenceNumberDiff>(packet_stream, begin_time_, &time_series);
741 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700742 }
743
tereliusdc35dcd2016-08-01 12:03:27 -0700744 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
745 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
746 kTopMargin);
747 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700748}
749
Stefan Holmer99f8e082016-09-09 13:37:50 +0200750void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
751 for (auto& kv : rtp_packets_) {
752 StreamId stream_id = kv.first;
753 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
754 // Filter on direction and SSRC.
755 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800756 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
757 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200758 continue;
759 }
760
761 TimeSeries time_series;
762 time_series.label = GetStreamName(stream_id);
763 time_series.style = LINE_DOT_GRAPH;
764 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800765 const uint64_t kStep = 1000000;
766 SequenceNumberUnwrapper unwrapper_;
767 SequenceNumberUnwrapper prior_unwrapper_;
768 size_t window_index_begin = 0;
769 size_t window_index_end = 0;
770 int64_t highest_seq_number =
771 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
772 int64_t highest_prior_seq_number =
773 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
774
775 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
776 while (window_index_end < packet_stream.size() &&
777 packet_stream[window_index_end].timestamp < t) {
778 int64_t sequence_number = unwrapper_.Unwrap(
779 packet_stream[window_index_end].header.sequenceNumber);
780 highest_seq_number = std::max(highest_seq_number, sequence_number);
781 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200782 }
terelius4c9b4af2017-01-30 08:44:51 -0800783 while (window_index_begin < packet_stream.size() &&
784 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
785 int64_t sequence_number = prior_unwrapper_.Unwrap(
786 packet_stream[window_index_begin].header.sequenceNumber);
787 highest_prior_seq_number =
788 std::max(highest_prior_seq_number, sequence_number);
789 ++window_index_begin;
790 }
791 float x = static_cast<float>(t - begin_time_) / 1000000;
792 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
793 if (expected_packets > 0) {
794 int64_t received_packets = window_index_end - window_index_begin;
795 int64_t lost_packets = expected_packets - received_packets;
796 float y = static_cast<float>(lost_packets) / expected_packets * 100;
797 time_series.points.emplace_back(x, y);
798 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200799 }
800 plot->series_list_.push_back(std::move(time_series));
801 }
802
803 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
804 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
805 kTopMargin);
806 plot->SetTitle("Estimated incoming loss rate");
807}
808
terelius54ce6802016-07-13 06:44:41 -0700809void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700810 for (auto& kv : rtp_packets_) {
811 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700812 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700813 // Filter on direction and SSRC.
814 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200815 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
816 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
817 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700818 continue;
819 }
terelius54ce6802016-07-13 06:44:41 -0700820
tereliusccbbf8d2016-08-10 07:34:28 -0700821 TimeSeries capture_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200822 capture_time_data.label = GetStreamName(stream_id) + " capture-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700823 capture_time_data.style = BAR_GRAPH;
824 Pairwise<NetworkDelayDiff::CaptureTime>(packet_stream, begin_time_,
825 &capture_time_data);
826 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700827
tereliusccbbf8d2016-08-10 07:34:28 -0700828 TimeSeries send_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200829 send_time_data.label = GetStreamName(stream_id) + " abs-send-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700830 send_time_data.style = BAR_GRAPH;
831 Pairwise<NetworkDelayDiff::AbsSendTime>(packet_stream, begin_time_,
832 &send_time_data);
833 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700834 }
835
tereliusdc35dcd2016-08-01 12:03:27 -0700836 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
837 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
838 kTopMargin);
839 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700840}
841
842void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700843 for (auto& kv : rtp_packets_) {
844 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700845 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700846 // Filter on direction and SSRC.
847 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200848 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
849 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
850 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700851 continue;
852 }
terelius54ce6802016-07-13 06:44:41 -0700853
tereliusccbbf8d2016-08-10 07:34:28 -0700854 TimeSeries capture_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200855 capture_time_data.label = GetStreamName(stream_id) + " capture-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700856 capture_time_data.style = LINE_GRAPH;
857 Pairwise<Accumulated<NetworkDelayDiff::CaptureTime>>(
858 packet_stream, begin_time_, &capture_time_data);
859 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700860
tereliusccbbf8d2016-08-10 07:34:28 -0700861 TimeSeries send_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200862 send_time_data.label = GetStreamName(stream_id) + " abs-send-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700863 send_time_data.style = LINE_GRAPH;
864 Pairwise<Accumulated<NetworkDelayDiff::AbsSendTime>>(
865 packet_stream, begin_time_, &send_time_data);
866 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;
989 double bytes_to_kilobits = 8.0 / 1000;
990 MovingAverage<PacketSizeBytes>(packet_stream, begin_time_, end_time_,
991 window_duration_, step_, bytes_to_kilobits,
992 &time_series);
993 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700994 }
995
tereliusdc35dcd2016-08-01 12:03:27 -0700996 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
997 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700998 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700999 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001000 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001001 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001002 }
1003}
1004
tereliuse34c19c2016-08-15 08:47:14 -07001005void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
Stefan Holmer13181032016-07-29 14:48:54 +02001006 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1007 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
1008
1009 for (const auto& kv : rtp_packets_) {
1010 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1011 for (const LoggedRtpPacket& rtp_packet : kv.second)
1012 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1013 }
1014 }
1015
1016 for (const auto& kv : rtcp_packets_) {
1017 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1018 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1019 incoming_rtcp.insert(
1020 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1021 }
1022 }
1023
1024 SimulatedClock clock(0);
1025 BitrateObserver observer;
1026 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001027 PacketRouter packet_router;
1028 CongestionController cc(&clock, &observer, &observer, &null_event_log,
1029 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +02001030 // TODO(holmer): Log the call config and use that here instead.
1031 static const uint32_t kDefaultStartBitrateBps = 300000;
1032 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1033
1034 TimeSeries time_series;
tereliuse34c19c2016-08-15 08:47:14 -07001035 time_series.label = "Delay-based estimate";
Stefan Holmer13181032016-07-29 14:48:54 +02001036 time_series.style = LINE_DOT_GRAPH;
Stefan Holmer60e43462016-09-07 09:58:20 +02001037 TimeSeries acked_time_series;
1038 acked_time_series.label = "Acked bitrate";
1039 acked_time_series.style = LINE_DOT_GRAPH;
Stefan Holmer13181032016-07-29 14:48:54 +02001040
1041 auto rtp_iterator = outgoing_rtp.begin();
1042 auto rtcp_iterator = incoming_rtcp.begin();
1043
1044 auto NextRtpTime = [&]() {
1045 if (rtp_iterator != outgoing_rtp.end())
1046 return static_cast<int64_t>(rtp_iterator->first);
1047 return std::numeric_limits<int64_t>::max();
1048 };
1049
1050 auto NextRtcpTime = [&]() {
1051 if (rtcp_iterator != incoming_rtcp.end())
1052 return static_cast<int64_t>(rtcp_iterator->first);
1053 return std::numeric_limits<int64_t>::max();
1054 };
1055
1056 auto NextProcessTime = [&]() {
1057 if (rtcp_iterator != incoming_rtcp.end() ||
1058 rtp_iterator != outgoing_rtp.end()) {
1059 return clock.TimeInMicroseconds() +
1060 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1061 }
1062 return std::numeric_limits<int64_t>::max();
1063 };
1064
Stefan Holmer492ee282016-10-27 17:19:20 +02001065 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001066
Stefan Holmer13181032016-07-29 14:48:54 +02001067 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001068 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001069 while (time_us != std::numeric_limits<int64_t>::max()) {
1070 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1071 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001072 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001073 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1074 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001075 TransportFeedbackObserver* observer = cc.GetTransportFeedbackObserver();
1076 observer->OnTransportFeedback(*static_cast<rtcp::TransportFeedback*>(
1077 rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001078 std::vector<PacketFeedback> feedback =
Stefan Holmer60e43462016-09-07 09:58:20 +02001079 observer->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);
1101 cc.GetTransportFeedbackObserver()->AddPacket(
stefana93d5ac2016-08-17 02:14:32 -07001102 rtp.header.extension.transportSequenceNumber, rtp.total_length,
philipel8aadd502017-02-23 02:56:13 -08001103 PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001104 rtc::SentPacket sent_packet(
1105 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1106 cc.OnSentPacket(sent_packet);
1107 }
1108 ++rtp_iterator;
1109 }
stefanc3de0332016-08-02 07:22:17 -07001110 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1111 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001112 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001113 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001114 if (observer.GetAndResetBitrateUpdated() ||
1115 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001116 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001117 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1118 1000000;
1119 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001120 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001121 }
1122 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1123 }
1124 // Add the data set to the plot.
tereliusdc35dcd2016-08-01 12:03:27 -07001125 plot->series_list_.push_back(std::move(time_series));
Stefan Holmer60e43462016-09-07 09:58:20 +02001126 plot->series_list_.push_back(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001127
tereliusdc35dcd2016-08-01 12:03:27 -07001128 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1129 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1130 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001131}
1132
Stefan Holmer280de9e2016-09-30 10:06:51 +02001133// TODO(holmer): Remove once TransportFeedbackAdapter no longer needs a
1134// BitrateController.
1135class NullBitrateController : public BitrateController {
1136 public:
1137 ~NullBitrateController() override {}
1138 RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override {
1139 return nullptr;
1140 }
1141 void SetStartBitrate(int start_bitrate_bps) override {}
1142 void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) override {}
1143 void SetBitrates(int start_bitrate_bps,
1144 int min_bitrate_bps,
1145 int max_bitrate_bps) override {}
1146 void ResetBitrates(int bitrate_bps,
1147 int min_bitrate_bps,
1148 int max_bitrate_bps) override {}
1149 void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) override {}
1150 bool AvailableBandwidth(uint32_t* bandwidth) const override { return false; }
1151 void SetReservedBitrate(uint32_t reserved_bitrate_bps) override {}
1152 bool GetNetworkParameters(uint32_t* bitrate,
1153 uint8_t* fraction_loss,
1154 int64_t* rtt) override {
1155 return false;
1156 }
1157 int64_t TimeUntilNextProcess() override { return 0; }
1158 void Process() override {}
1159};
1160
tereliuse34c19c2016-08-15 08:47:14 -07001161void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanc3de0332016-08-02 07:22:17 -07001162 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1163 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
1164
1165 for (const auto& kv : rtp_packets_) {
1166 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1167 for (const LoggedRtpPacket& rtp_packet : kv.second)
1168 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1169 }
1170 }
1171
1172 for (const auto& kv : rtcp_packets_) {
1173 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1174 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1175 incoming_rtcp.insert(
1176 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1177 }
1178 }
1179
1180 SimulatedClock clock(0);
Stefan Holmer280de9e2016-09-30 10:06:51 +02001181 NullBitrateController null_controller;
terelius0baf55d2017-02-17 03:38:28 -08001182 TransportFeedbackAdapter feedback_adapter(nullptr, &clock, &null_controller);
stefan41aab322016-10-10 08:16:30 -07001183 feedback_adapter.InitBwe();
stefanc3de0332016-08-02 07:22:17 -07001184
1185 TimeSeries time_series;
1186 time_series.label = "Network Delay Change";
1187 time_series.style = LINE_DOT_GRAPH;
1188 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1189
1190 auto rtp_iterator = outgoing_rtp.begin();
1191 auto rtcp_iterator = incoming_rtcp.begin();
1192
1193 auto NextRtpTime = [&]() {
1194 if (rtp_iterator != outgoing_rtp.end())
1195 return static_cast<int64_t>(rtp_iterator->first);
1196 return std::numeric_limits<int64_t>::max();
1197 };
1198
1199 auto NextRtcpTime = [&]() {
1200 if (rtcp_iterator != incoming_rtcp.end())
1201 return static_cast<int64_t>(rtcp_iterator->first);
1202 return std::numeric_limits<int64_t>::max();
1203 };
1204
1205 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1206 while (time_us != std::numeric_limits<int64_t>::max()) {
1207 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1208 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1209 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1210 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1211 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001212 feedback_adapter.OnTransportFeedback(
1213 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001214 std::vector<PacketFeedback> feedback =
1215 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001216 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001217 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001218 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1219 float x =
1220 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1221 1000000;
1222 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1223 time_series.points.emplace_back(x, y);
1224 }
1225 }
1226 ++rtcp_iterator;
1227 }
1228 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1229 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1230 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1231 if (rtp.header.extension.hasTransportSequenceNumber) {
1232 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
1233 feedback_adapter.AddPacket(rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001234 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001235 feedback_adapter.OnSentPacket(
1236 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1237 }
1238 ++rtp_iterator;
1239 }
1240 time_us = std::min(NextRtpTime(), NextRtcpTime());
1241 }
1242 // We assume that the base network delay (w/o queues) is the min delay
1243 // observed during the call.
1244 for (TimeSeriesPoint& point : time_series.points)
1245 point.y -= estimated_base_delay_ms;
1246 // Add the data set to the plot.
1247 plot->series_list_.push_back(std::move(time_series));
1248
1249 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1250 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1251 plot->SetTitle("Network Delay Change.");
1252}
stefan08383272016-12-20 08:51:52 -08001253
1254std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1255 const {
1256 std::vector<std::pair<int64_t, int64_t>> timestamps;
1257 size_t largest_stream_size = 0;
1258 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1259 // Find the incoming video stream with the most number of packets that is
1260 // not rtx.
1261 for (const auto& kv : rtp_packets_) {
1262 if (kv.first.GetDirection() == kIncomingPacket &&
1263 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1264 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1265 kv.second.size() > largest_stream_size) {
1266 largest_stream_size = kv.second.size();
1267 largest_video_stream = &kv.second;
1268 }
1269 }
1270 if (largest_video_stream == nullptr) {
1271 for (auto& packet : *largest_video_stream) {
1272 if (packet.header.markerBit) {
1273 int64_t capture_ms = packet.header.timestamp / 90.0;
1274 int64_t arrival_ms = packet.timestamp / 1000.0;
1275 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1276 }
1277 }
1278 }
1279 return timestamps;
1280}
stefane372d3c2017-02-02 08:04:18 -08001281
1282void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1283 for (const auto& kv : rtp_packets_) {
1284 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1285 StreamId stream_id = kv.first;
1286
1287 {
1288 TimeSeries timestamp_data;
1289 timestamp_data.label = GetStreamName(stream_id) + " capture-time";
1290 timestamp_data.style = LINE_DOT_GRAPH;
1291 for (LoggedRtpPacket packet : rtp_packets) {
1292 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1293 float y = packet.header.timestamp;
1294 timestamp_data.points.emplace_back(x, y);
1295 }
1296 plot->series_list_.push_back(std::move(timestamp_data));
1297 }
1298
1299 {
1300 auto kv = rtcp_packets_.find(stream_id);
1301 if (kv != rtcp_packets_.end()) {
1302 const auto& packets = kv->second;
1303 TimeSeries timestamp_data;
1304 timestamp_data.label = GetStreamName(stream_id) + " rtcp capture-time";
1305 timestamp_data.style = LINE_DOT_GRAPH;
1306 for (const LoggedRtcpPacket& rtcp : packets) {
1307 if (rtcp.type != kRtcpSr)
1308 continue;
1309 rtcp::SenderReport* sr;
1310 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1311 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1312 float y = sr->rtp_timestamp();
1313 timestamp_data.points.emplace_back(x, y);
1314 }
1315 plot->series_list_.push_back(std::move(timestamp_data));
1316 }
1317 }
1318 }
1319
1320 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1321 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1322 plot->SetTitle("Timestamps");
1323}
michaelt6e5b2192017-02-22 07:33:27 -08001324
1325void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
1326 FillAudioEncoderTimeSeries(
1327 plot, [](const AudioNetworkAdaptationEvent& ana_event) {
1328 if (ana_event.config.bitrate_bps)
1329 return rtc::Optional<float>(
1330 static_cast<float>(*ana_event.config.bitrate_bps));
1331 return rtc::Optional<float>();
1332 });
1333 plot->series_list_.back().label = "Audio encoder target bitrate";
1334 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1335 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1336 plot->SetTitle("Reported audio encoder target bitrate");
1337}
1338
1339void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
1340 FillAudioEncoderTimeSeries(
1341 plot, [](const AudioNetworkAdaptationEvent& ana_event) {
1342 if (ana_event.config.frame_length_ms)
1343 return rtc::Optional<float>(
1344 static_cast<float>(*ana_event.config.frame_length_ms));
1345 return rtc::Optional<float>();
1346 });
1347 plot->series_list_.back().label = "Audio encoder frame length";
1348 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1349 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1350 plot->SetTitle("Reported audio encoder frame length");
1351}
1352
1353void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph(
1354 Plot* plot) {
1355 FillAudioEncoderTimeSeries(
1356 plot, [&](const AudioNetworkAdaptationEvent& ana_event) {
1357 if (ana_event.config.uplink_packet_loss_fraction)
1358 return rtc::Optional<float>(static_cast<float>(
1359 *ana_event.config.uplink_packet_loss_fraction));
1360 return rtc::Optional<float>();
1361 });
1362 plot->series_list_.back().label = "Audio encoder uplink packet loss fraction";
1363 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1364 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1365 kTopMargin);
1366 plot->SetTitle("Reported audio encoder lost packets");
1367}
1368
1369void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
1370 FillAudioEncoderTimeSeries(
1371 plot, [&](const AudioNetworkAdaptationEvent& ana_event) {
1372 if (ana_event.config.enable_fec)
1373 return rtc::Optional<float>(
1374 static_cast<float>(*ana_event.config.enable_fec));
1375 return rtc::Optional<float>();
1376 });
1377 plot->series_list_.back().label = "Audio encoder FEC";
1378 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1379 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1380 plot->SetTitle("Reported audio encoder FEC");
1381}
1382
1383void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
1384 FillAudioEncoderTimeSeries(
1385 plot, [&](const AudioNetworkAdaptationEvent& ana_event) {
1386 if (ana_event.config.enable_dtx)
1387 return rtc::Optional<float>(
1388 static_cast<float>(*ana_event.config.enable_dtx));
1389 return rtc::Optional<float>();
1390 });
1391 plot->series_list_.back().label = "Audio encoder DTX";
1392 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1393 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1394 plot->SetTitle("Reported audio encoder DTX");
1395}
1396
1397void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
1398 FillAudioEncoderTimeSeries(
1399 plot, [&](const AudioNetworkAdaptationEvent& ana_event) {
1400 if (ana_event.config.num_channels)
1401 return rtc::Optional<float>(
1402 static_cast<float>(*ana_event.config.num_channels));
1403 return rtc::Optional<float>();
1404 });
1405 plot->series_list_.back().label = "Audio encoder number of channels";
1406 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1407 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1408 kBottomMargin, kTopMargin);
1409 plot->SetTitle("Reported audio encoder number of channels");
1410}
terelius54ce6802016-07-13 06:44:41 -07001411} // namespace plotting
1412} // namespace webrtc